mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-09-02 00:11:56 +03:00
Remove pools from faketls
This commit is contained in:
@@ -2,6 +2,7 @@ package faketls
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -63,9 +64,7 @@ func (c *ClientProtocol) tlsHandshake(conn io.ReadWriter) error {
|
|||||||
return fmt.Errorf("cannot read initial record: %w", err)
|
return fmt.Errorf("cannot read initial record: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
buf := acquireBytesBuffer()
|
buf := &bytes.Buffer{}
|
||||||
defer releaseBytesBuffer(buf)
|
|
||||||
|
|
||||||
helloRecord.Data.WriteBytes(buf)
|
helloRecord.Data.WriteBytes(buf)
|
||||||
|
|
||||||
clientHello, err := tlstypes.ParseClientHello(buf.Bytes())
|
clientHello, err := tlstypes.ParseClientHello(buf.Bytes())
|
||||||
|
|||||||
+1
-4
@@ -67,8 +67,5 @@ func cloak(one, another io.ReadWriteCloser) {
|
|||||||
func cloakPipe(one io.Writer, another io.Reader, wg *sync.WaitGroup) {
|
func cloakPipe(one io.Writer, another io.Reader, wg *sync.WaitGroup) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
|
||||||
buf := acquireCloakBuffer()
|
io.Copy(one, another) // nolint: errcheck
|
||||||
defer releaseCloakBuffer(buf)
|
|
||||||
|
|
||||||
io.CopyBuffer(one, another, *buf) // nolint: errcheck
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
package faketls
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"sync"
|
|
||||||
)
|
|
||||||
|
|
||||||
const cloakBufferSize = 1024
|
|
||||||
|
|
||||||
var (
|
|
||||||
poolBytesBuffer = sync.Pool{
|
|
||||||
New: func() interface{} {
|
|
||||||
return &bytes.Buffer{}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
poolCloakBuffer = sync.Pool{
|
|
||||||
New: func() interface{} {
|
|
||||||
rv := make([]byte, cloakBufferSize)
|
|
||||||
return &rv
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
func acquireBytesBuffer() *bytes.Buffer {
|
|
||||||
return poolBytesBuffer.Get().(*bytes.Buffer)
|
|
||||||
}
|
|
||||||
|
|
||||||
func acquireCloakBuffer() *[]byte {
|
|
||||||
return poolCloakBuffer.Get().(*[]byte)
|
|
||||||
}
|
|
||||||
|
|
||||||
func releaseBytesBuffer(buf *bytes.Buffer) {
|
|
||||||
buf.Reset()
|
|
||||||
poolBytesBuffer.Put(buf)
|
|
||||||
}
|
|
||||||
|
|
||||||
func releaseCloakBuffer(buf *[]byte) {
|
|
||||||
poolCloakBuffer.Put(buf)
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user