diff --git a/proxy/testing/mocks/outboundhandler.go b/proxy/testing/mocks/outboundhandler.go index 2b837f9bf..668268707 100644 --- a/proxy/testing/mocks/outboundhandler.go +++ b/proxy/testing/mocks/outboundhandler.go @@ -24,7 +24,7 @@ func (v *OutboundConnectionHandler) Dispatch(destination v2net.Destination, payl v.Destination = destination if !payload.IsEmpty() { - v.ConnOutput.Write(payload.Value) + v.ConnOutput.Write(payload.Bytes()) } payload.Release() diff --git a/proxy/vmess/encoding/commands.go b/proxy/vmess/encoding/commands.go index 1a888fa00..f26abc3c2 100644 --- a/proxy/vmess/encoding/commands.go +++ b/proxy/vmess/encoding/commands.go @@ -40,14 +40,14 @@ func MarshalCommand(command interface{}, writer io.Writer) error { return err } - auth := Authenticate(buffer.Value) + auth := Authenticate(buffer.Bytes()) len := buffer.Len() + 4 if len > 255 { return ErrCommandTooLarge } writer.Write([]byte{cmdId, byte(len), byte(auth >> 24), byte(auth >> 16), byte(auth >> 8), byte(auth)}) - writer.Write(buffer.Value) + writer.Write(buffer.Bytes()) return nil } diff --git a/proxy/vmess/encoding/commands_test.go b/proxy/vmess/encoding/commands_test.go index f57099e2d..8382dc04b 100644 --- a/proxy/vmess/encoding/commands_test.go +++ b/proxy/vmess/encoding/commands_test.go @@ -25,7 +25,7 @@ func TestSwitchAccount(t *testing.T) { err := MarshalCommand(sa, buffer) assert.Error(err).IsNil() - cmd, err := UnmarshalCommand(1, buffer.Value[2:]) + cmd, err := UnmarshalCommand(1, buffer.BytesFrom(2)) assert.Error(err).IsNil() sa2, ok := cmd.(*protocol.CommandSwitchAccount) diff --git a/proxy/vmess/io/io_test.go b/proxy/vmess/io/io_test.go index 4bb8363bb..2d1cd2a5c 100644 --- a/proxy/vmess/io/io_test.go +++ b/proxy/vmess/io/io_test.go @@ -19,11 +19,11 @@ func TestAuthenticate(t *testing.T) { buffer := alloc.NewBuffer().Clear() buffer.AppendBytes(1, 2, 3, 4) Authenticate(buffer) - assert.Bytes(buffer.Value).Equals([]byte{0, 8, 87, 52, 168, 125, 1, 2, 3, 4}) + assert.Bytes(buffer.Bytes()).Equals([]byte{0, 8, 87, 52, 168, 125, 1, 2, 3, 4}) b2, err := NewAuthChunkReader(buffer).Read() assert.Error(err).IsNil() - assert.Bytes(b2.Value).Equals([]byte{1, 2, 3, 4}) + assert.Bytes(b2.Bytes()).Equals([]byte{1, 2, 3, 4}) } func TestSingleIO(t *testing.T) { @@ -39,7 +39,7 @@ func TestSingleIO(t *testing.T) { reader := NewAuthChunkReader(content) buffer, err := reader.Read() assert.Error(err).IsNil() - assert.Bytes(buffer.Value).Equals([]byte("abcd")) + assert.String(buffer.String()).Equals("abcd") } func TestLargeIO(t *testing.T) { @@ -73,7 +73,7 @@ func TestLargeIO(t *testing.T) { break } assert.Error(err).IsNil() - actualContent = append(actualContent, buffer.Value...) + actualContent = append(actualContent, buffer.Bytes()...) } assert.Int(len(actualContent)).Equals(len(content)) diff --git a/proxy/vmess/io/reader.go b/proxy/vmess/io/reader.go index 92ad184b7..c71ddd721 100644 --- a/proxy/vmess/io/reader.go +++ b/proxy/vmess/io/reader.go @@ -61,9 +61,9 @@ func (v *AuthChunkReader) Read() (*alloc.Buffer, error) { return nil, io.ErrUnexpectedEOF } } - length := serial.BytesToUint16(buffer.Value[:2]) + length := serial.BytesToUint16(buffer.BytesTo(2)) v.chunkLength = int(length) - 4 - v.validator = NewValidator(serial.BytesToUint32(buffer.Value[2:6])) + v.validator = NewValidator(serial.BytesToUint32(buffer.BytesRange(2, 6))) buffer.SliceFrom(6) if buffer.Len() < v.chunkLength && v.chunkLength <= 2048 { _, err := buffer.FillFrom(v.reader) @@ -86,10 +86,10 @@ func (v *AuthChunkReader) Read() (*alloc.Buffer, error) { } if buffer.Len() < v.chunkLength { - v.validator.Consume(buffer.Value) + v.validator.Consume(buffer.Bytes()) v.chunkLength -= buffer.Len() } else { - v.validator.Consume(buffer.Value[:v.chunkLength]) + v.validator.Consume(buffer.BytesTo(v.chunkLength)) if !v.validator.Validate() { buffer.Release() return nil, errors.New("VMess|AuthChunkReader: Invalid auth.") @@ -97,7 +97,7 @@ func (v *AuthChunkReader) Read() (*alloc.Buffer, error) { leftLength := buffer.Len() - v.chunkLength if leftLength > 0 { v.last = alloc.NewBuffer().Clear() - v.last.Append(buffer.Value[v.chunkLength:]) + v.last.Append(buffer.BytesFrom(v.chunkLength)) buffer.Slice(0, v.chunkLength) } diff --git a/proxy/vmess/io/writer.go b/proxy/vmess/io/writer.go index ffda61387..5798cd966 100644 --- a/proxy/vmess/io/writer.go +++ b/proxy/vmess/io/writer.go @@ -29,7 +29,7 @@ func (v *AuthChunkWriter) Release() { func Authenticate(buffer *alloc.Buffer) { fnvHash := fnv.New32a() - fnvHash.Write(buffer.Value) + fnvHash.Write(buffer.Bytes()) buffer.PrependHash(fnvHash) buffer.PrependUint16(uint16(buffer.Len())) diff --git a/transport/internet/kcp/crypt.go b/transport/internet/kcp/crypt.go index 0bcf598b6..d0877bb9b 100644 --- a/transport/internet/kcp/crypt.go +++ b/transport/internet/kcp/crypt.go @@ -21,7 +21,7 @@ func (v *SimpleAuthenticator) Overhead() int { func (v *SimpleAuthenticator) Seal(buffer *alloc.Buffer) { buffer.PrependUint16(uint16(buffer.Len())) fnvHash := fnv.New32a() - fnvHash.Write(buffer.Value) + fnvHash.Write(buffer.Bytes()) buffer.PrependHash(fnvHash) len := buffer.Len() @@ -29,7 +29,7 @@ func (v *SimpleAuthenticator) Seal(buffer *alloc.Buffer) { if xtra != 0 { buffer.Slice(0, len+xtra) } - xorfwd(buffer.Value) + xorfwd(buffer.Bytes()) if xtra != 0 { buffer.Slice(0, len) } @@ -41,7 +41,7 @@ func (v *SimpleAuthenticator) Open(buffer *alloc.Buffer) bool { if xtra != 0 { buffer.Slice(0, len+xtra) } - xorbkd(buffer.Value) + xorbkd(buffer.Bytes()) if xtra != 0 { buffer.Slice(0, len) } diff --git a/transport/internet/kcp/crypt_test.go b/transport/internet/kcp/crypt_test.go index a91e57d16..28028bab6 100644 --- a/transport/internet/kcp/crypt_test.go +++ b/transport/internet/kcp/crypt_test.go @@ -19,7 +19,7 @@ func TestSimpleAuthenticator(t *testing.T) { auth.Seal(buffer) assert.Bool(auth.Open(buffer)).IsTrue() - assert.Bytes(buffer.Value).Equals([]byte{'a', 'b', 'c', 'd', 'e', 'f', 'g'}) + assert.Bytes(buffer.Bytes()).Equals([]byte{'a', 'b', 'c', 'd', 'e', 'f', 'g'}) } func TestSimpleAuthenticator2(t *testing.T) { @@ -37,8 +37,7 @@ func TestSimpleAuthenticator2(t *testing.T) { func BenchmarkSimpleAuthenticator(b *testing.B) { buffer := alloc.NewLocalBuffer(2048).Clear() - buffer.Slice(0, 1024) - rand.Read(buffer.Value) + buffer.FillFullFrom(rand.Reader, 1024) auth := NewSimpleAuthenticator() b.SetBytes(int64(buffer.Len())) diff --git a/transport/internet/kcp/segment_test.go b/transport/internet/kcp/segment_test.go index c071cdb53..4fda45ff4 100644 --- a/transport/internet/kcp/segment_test.go +++ b/transport/internet/kcp/segment_test.go @@ -38,7 +38,7 @@ func TestDataSegment(t *testing.T) { assert.Uint32(seg2.Timestamp).Equals(seg.Timestamp) assert.Uint32(seg2.SendingNext).Equals(seg.SendingNext) assert.Uint32(seg2.Number).Equals(seg.Number) - assert.Bytes(seg2.Data.Value).Equals(seg.Data.Value) + assert.Bytes(seg2.Data.Bytes()).Equals(seg.Data.Bytes()) } func TestACKSegment(t *testing.T) { diff --git a/transport/internet/udp/hub.go b/transport/internet/udp/hub.go index 2a1783779..9b125e6a2 100644 --- a/transport/internet/udp/hub.go +++ b/transport/internet/udp/hub.go @@ -136,7 +136,7 @@ func (v *UDPHub) start() { oobBytes := make([]byte, 256) for v.Running() { buffer := alloc.NewSmallBuffer() - nBytes, noob, _, addr, err := ReadUDPMsg(v.conn, buffer.Value, oobBytes) + nBytes, noob, _, addr, err := ReadUDPMsg(v.conn, buffer.Bytes(), oobBytes) if err != nil { log.Info("UDP|Hub: Failed to read UDP msg: ", err) buffer.Release()