diff --git a/app/proxyman/mux/reader.go b/app/proxyman/mux/reader.go index f3a2574b6..33453b715 100644 --- a/app/proxyman/mux/reader.go +++ b/app/proxyman/mux/reader.go @@ -55,7 +55,7 @@ func (r *PacketReader) ReadMultiBuffer() (buf.MultiBuffer, error) { if size <= buf.Size { b = buf.New() } else { - b = buf.NewLocal(uint32(size)) + b = buf.NewSize(uint32(size)) } if err := b.AppendSupplier(buf.ReadFullFrom(r.reader, int(size))); err != nil { b.Release() diff --git a/common/buf/buffer.go b/common/buf/buffer.go index 4128cb325..1b94936ff 100644 --- a/common/buf/buffer.go +++ b/common/buf/buffer.go @@ -172,15 +172,15 @@ func (b *Buffer) String() string { return string(b.Bytes()) } -// New creates a Buffer with 0 length and 8K capacity. +// New creates a Buffer with 0 length and 2K capacity. func New() *Buffer { return &Buffer{ v: pool2k.Get().([]byte), } } -// NewLocal creates and returns a buffer with 0 length and given capacity on current thread. -func NewLocal(size uint32) *Buffer { +// NewSize creates and returns a buffer given capacity. +func NewSize(size uint32) *Buffer { return &Buffer{ v: NewBytes(size), } diff --git a/common/buf/buffer_test.go b/common/buf/buffer_test.go index be0ae42ef..a51687d64 100644 --- a/common/buf/buffer_test.go +++ b/common/buf/buffer_test.go @@ -50,7 +50,7 @@ func BenchmarkNewBuffer(b *testing.B) { func BenchmarkNewLocalBuffer(b *testing.B) { for i := 0; i < b.N; i++ { - buffer := NewLocal(Size) + buffer := NewSize(Size) buffer.Release() } } diff --git a/common/crypto/auth.go b/common/crypto/auth.go index e1bf8d0d9..ecdb0189f 100644 --- a/common/crypto/auth.go +++ b/common/crypto/auth.go @@ -128,7 +128,7 @@ func (r *AuthenticationReader) ReadMultiBuffer() (buf.MultiBuffer, error) { if size <= buf.Size { b = buf.New() } else { - b = buf.NewLocal(uint32(size)) + b = buf.NewSize(uint32(size)) } if err := b.Reset(buf.ReadFullFrom(r.reader, size)); err != nil { b.Release() diff --git a/common/crypto/auth_test.go b/common/crypto/auth_test.go index 3bc35fa3f..ada4181c5 100644 --- a/common/crypto/auth_test.go +++ b/common/crypto/auth_test.go @@ -27,10 +27,10 @@ func TestAuthenticationReaderWriter(t *testing.T) { rawPayload := make([]byte, 8192*10) rand.Read(rawPayload) - payload := buf.NewLocal(8192 * 10) + payload := buf.NewSize(8192 * 10) payload.Append(rawPayload) - cache := buf.NewLocal(160 * 1024) + cache := buf.NewSize(160 * 1024) iv := make([]byte, 12) rand.Read(iv) @@ -83,7 +83,7 @@ func TestAuthenticationReaderWriterPacket(t *testing.T) { aead, err := cipher.NewGCM(block) assert(err, IsNil) - cache := buf.NewLocal(1024) + cache := buf.NewSize(1024) iv := make([]byte, 12) rand.Read(iv) diff --git a/common/crypto/chunk_test.go b/common/crypto/chunk_test.go index 4131ebfb2..d5d8c9e5b 100644 --- a/common/crypto/chunk_test.go +++ b/common/crypto/chunk_test.go @@ -12,7 +12,7 @@ import ( func TestChunkStreamIO(t *testing.T) { assert := With(t) - cache := buf.NewLocal(8192) + cache := buf.NewSize(8192) writer := NewChunkStreamWriter(PlainChunkSizeParser{}, cache) reader := NewChunkStreamReader(PlainChunkSizeParser{}, cache) diff --git a/proxy/shadowsocks/ota.go b/proxy/shadowsocks/ota.go index bca2eaca7..d1015e0f5 100644 --- a/proxy/shadowsocks/ota.go +++ b/proxy/shadowsocks/ota.go @@ -81,7 +81,7 @@ func (v *ChunkReader) ReadMultiBuffer() (buf.MultiBuffer, error) { if length > buf.Size { // Theoretically the size of a chunk is 64K, but most Shadowsocks implementations used <4K buffer. buffer.Release() - buffer = buf.NewLocal(uint32(length) + 128) + buffer = buf.NewSize(uint32(length) + 128) } buffer.Clear() diff --git a/proxy/shadowsocks/ota_test.go b/proxy/shadowsocks/ota_test.go index 95064444f..106466389 100644 --- a/proxy/shadowsocks/ota_test.go +++ b/proxy/shadowsocks/ota_test.go @@ -24,11 +24,11 @@ func TestNormalChunkReading(t *testing.T) { func TestNormalChunkWriting(t *testing.T) { assert := With(t) - buffer := buf.NewLocal(512) + buffer := buf.NewSize(512) writer := NewChunkWriter(buffer, NewAuthenticator(ChunkKeyGenerator( []byte{21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36}))) - b := buf.NewLocal(256) + b := buf.NewSize(256) b.Append([]byte{11, 12, 13, 14, 15, 16, 17, 18}) err := writer.WriteMultiBuffer(buf.NewMultiBufferValue(b)) assert(err, IsNil) diff --git a/proxy/shadowsocks/protocol_test.go b/proxy/shadowsocks/protocol_test.go index 6c28370f7..65f72a139 100644 --- a/proxy/shadowsocks/protocol_test.go +++ b/proxy/shadowsocks/protocol_test.go @@ -29,7 +29,7 @@ func TestUDPEncoding(t *testing.T) { }, } - data := buf.NewLocal(256) + data := buf.NewSize(256) data.AppendSupplier(serial.WriteString("test string")) encodedData, err := EncodeUDPPacket(request, data.Bytes()) assert(err, IsNil) diff --git a/transport/internet/headers/http/http_test.go b/transport/internet/headers/http/http_test.go index dbe6d3f85..315cad762 100644 --- a/transport/internet/headers/http/http_test.go +++ b/transport/internet/headers/http/http_test.go @@ -16,7 +16,7 @@ func TestReaderWriter(t *testing.T) { assert := With(t) cache := buf.New() - b := buf.NewLocal(256) + b := buf.NewSize(256) b.AppendSupplier(serial.WriteString("abcd" + ENDING)) writer := NewHeaderWriter(b) err := writer.Write(cache) diff --git a/transport/internet/headers/srtp/srtp_test.go b/transport/internet/headers/srtp/srtp_test.go index b4f498d88..b959c8b1e 100644 --- a/transport/internet/headers/srtp/srtp_test.go +++ b/transport/internet/headers/srtp/srtp_test.go @@ -18,7 +18,7 @@ func TestSRTPWrite(t *testing.T) { srtp := srtpRaw.(*SRTP) - payload := buf.NewLocal(2048) + payload := buf.NewSize(2048) payload.AppendSupplier(srtp.Write) payload.Append(content) diff --git a/transport/internet/headers/utp/utp_test.go b/transport/internet/headers/utp/utp_test.go index a8b637dcb..4736001da 100644 --- a/transport/internet/headers/utp/utp_test.go +++ b/transport/internet/headers/utp/utp_test.go @@ -18,7 +18,7 @@ func TestUTPWrite(t *testing.T) { utp := utpRaw.(*UTP) - payload := buf.NewLocal(2048) + payload := buf.NewSize(2048) payload.AppendSupplier(utp.Write) payload.Append(content) diff --git a/transport/internet/headers/wechat/wechat_test.go b/transport/internet/headers/wechat/wechat_test.go index 2afc94665..6fde0bfd5 100644 --- a/transport/internet/headers/wechat/wechat_test.go +++ b/transport/internet/headers/wechat/wechat_test.go @@ -17,7 +17,7 @@ func TestUTPWrite(t *testing.T) { video := videoRaw.(*VideoChat) - payload := buf.NewLocal(2048) + payload := buf.NewSize(2048) payload.AppendSupplier(video.Write) assert(payload.Len(), Equals, video.Size())