From 3997d13b97c6e4e91eda3f2221d4257bbc73acc8 Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Thu, 19 Apr 2018 23:48:38 +0200 Subject: [PATCH] rename Slice and Slice from to Resize and Advance --- app/proxyman/mux/frame.go | 2 +- common/buf/buffer.go | 8 ++++---- common/crypto/auth.go | 2 +- proxy/shadowsocks/config.go | 6 +++--- proxy/shadowsocks/ota.go | 2 +- proxy/shadowsocks/protocol.go | 2 +- proxy/socks/protocol.go | 2 +- transport/internet/headers/http/http.go | 2 +- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/proxyman/mux/frame.go b/app/proxyman/mux/frame.go index 958aa740..8b78846d 100644 --- a/app/proxyman/mux/frame.go +++ b/app/proxyman/mux/frame.go @@ -98,7 +98,7 @@ func ReadFrameFrom(b *buf.Buffer) (*FrameMetadata, error) { if f.SessionStatus == SessionStatusNew { network := TargetNetwork(b.Byte(4)) - b.SliceFrom(5) + b.Advance(5) addr, port, err := addrParser.ReadAddressPort(nil, b) if err != nil { diff --git a/common/buf/buffer.go b/common/buf/buffer.go index 4346eb33..3f728703 100644 --- a/common/buf/buffer.go +++ b/common/buf/buffer.go @@ -97,8 +97,8 @@ func (b *Buffer) BytesTo(to int32) []byte { return b.v[b.start : b.start+to] } -// Slice cuts the buffer at the given position. -func (b *Buffer) Slice(from, to int32) { +// Resize cuts the buffer at the given position. +func (b *Buffer) Resize(from, to int32) { if from < 0 { from += b.Len() } @@ -112,8 +112,8 @@ func (b *Buffer) Slice(from, to int32) { b.start += from } -// SliceFrom cuts the buffer at the given position. -func (b *Buffer) SliceFrom(from int32) { +// Advance cuts the buffer at the given position. +func (b *Buffer) Advance(from int32) { if from < 0 { from += b.Len() } diff --git a/common/crypto/auth.go b/common/crypto/auth.go index 7a6d74fa..9661c861 100644 --- a/common/crypto/auth.go +++ b/common/crypto/auth.go @@ -145,7 +145,7 @@ func (r *AuthenticationReader) readInternal(soft bool) (*buf.Buffer, error) { b.Release() return nil, err } - b.Slice(0, int32(len(rb))) + b.Resize(0, int32(len(rb))) return b, nil } diff --git a/proxy/shadowsocks/config.go b/proxy/shadowsocks/config.go index d08ec312..39ad222c 100644 --- a/proxy/shadowsocks/config.go +++ b/proxy/shadowsocks/config.go @@ -146,7 +146,7 @@ func (v *AesCfb) DecodePacket(key []byte, b *buf.Buffer) error { iv := b.BytesTo(v.IVSize()) stream := crypto.NewAesDecryptionStream(key, iv) stream.XORKeyStream(b.BytesFrom(v.IVSize()), b.BytesFrom(v.IVSize())) - b.SliceFrom(v.IVSize()) + b.Advance(v.IVSize()) return nil } @@ -221,7 +221,7 @@ func (c *AEADCipher) DecodePacket(key []byte, b *buf.Buffer) error { }); err != nil { return err } - b.SliceFrom(ivLen) + b.Advance(ivLen) return nil } @@ -265,7 +265,7 @@ func (v *ChaCha20) DecodePacket(key []byte, b *buf.Buffer) error { iv := b.BytesTo(v.IVSize()) stream := crypto.NewChaCha20Stream(key, iv) stream.XORKeyStream(b.BytesFrom(v.IVSize()), b.BytesFrom(v.IVSize())) - b.SliceFrom(v.IVSize()) + b.Advance(v.IVSize()) return nil } diff --git a/proxy/shadowsocks/ota.go b/proxy/shadowsocks/ota.go index 500ccec3..7128ef3e 100644 --- a/proxy/shadowsocks/ota.go +++ b/proxy/shadowsocks/ota.go @@ -91,7 +91,7 @@ func (v *ChunkReader) ReadMultiBuffer() (buf.MultiBuffer, error) { buffer.Release() return nil, newError("invalid auth") } - buffer.SliceFrom(AuthSize) + buffer.Advance(AuthSize) return buf.NewMultiBufferValue(buffer), nil } diff --git a/proxy/shadowsocks/protocol.go b/proxy/shadowsocks/protocol.go index cd1ba64d..00d76efc 100644 --- a/proxy/shadowsocks/protocol.go +++ b/proxy/shadowsocks/protocol.go @@ -295,7 +295,7 @@ func DecodeUDPPacket(user *protocol.User, payload *buf.Buffer) (*protocol.Reques return nil, nil, newError("invalid OTA") } - payload.Slice(0, payloadLen) + payload.Resize(0, payloadLen) } } diff --git a/proxy/socks/protocol.go b/proxy/socks/protocol.go index c91d5866..c52d488b 100644 --- a/proxy/socks/protocol.go +++ b/proxy/socks/protocol.go @@ -274,7 +274,7 @@ func DecodeUDPPacket(packet *buf.Buffer) (*protocol.RequestHeader, error) { return nil, newError("discarding fragmented payload.") } - packet.SliceFrom(3) + packet.Advance(3) addr, port, err := addrParser.ReadAddressPort(nil, packet) if err != nil { diff --git a/transport/internet/headers/http/http.go b/transport/internet/headers/http/http.go index 0a2f9e27..ac4df9c8 100644 --- a/transport/internet/headers/http/http.go +++ b/transport/internet/headers/http/http.go @@ -66,7 +66,7 @@ func (*HeaderReader) Read(reader io.Reader) (*buf.Buffer, error) { return nil, err } if n := bytes.Index(buffer.Bytes(), []byte(ENDING)); n != -1 { - buffer.SliceFrom(int32(n + len(ENDING))) + buffer.Advance(int32(n + len(ENDING))) endingDetected = true break }