mirror of https://github.com/v2ray/v2ray-core
rename Slice and Slice from to Resize and Advance
parent
1425fd2ba9
commit
3997d13b97
|
@ -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 {
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue