mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-02 15:36:41 -05:00
remove use of prepend
This commit is contained in:
parent
12bce36693
commit
0ad629ca31
@ -1,6 +1,7 @@
|
||||
package testing
|
||||
|
||||
import (
|
||||
"v2ray.com/core/common/alloc"
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/proxy"
|
||||
"v2ray.com/core/transport/ray"
|
||||
@ -19,8 +20,11 @@ func NewTestPacketDispatcher(handler func(destination v2net.Destination, traffic
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
payload.Prepend([]byte("Processed: "))
|
||||
traffic.OutboundOutput().Write(payload)
|
||||
output := alloc.NewBuffer()
|
||||
output.Append([]byte("Processed: "))
|
||||
output.Append(payload.Bytes())
|
||||
payload.Release()
|
||||
traffic.OutboundOutput().Write(output)
|
||||
}
|
||||
traffic.OutboundOutput().Close()
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"crypto/hmac"
|
||||
"crypto/sha1"
|
||||
"io"
|
||||
|
||||
"v2ray.com/core/common/alloc"
|
||||
"v2ray.com/core/common/errors"
|
||||
"v2ray.com/core/common/serial"
|
||||
@ -111,12 +112,14 @@ func (v *ChunkReader) Read() (*alloc.Buffer, error) {
|
||||
type ChunkWriter struct {
|
||||
writer io.Writer
|
||||
auth *Authenticator
|
||||
buffer []byte
|
||||
}
|
||||
|
||||
func NewChunkWriter(writer io.Writer, auth *Authenticator) *ChunkWriter {
|
||||
return &ChunkWriter{
|
||||
writer: writer,
|
||||
auth: auth,
|
||||
buffer: make([]byte, 32*1024),
|
||||
}
|
||||
}
|
||||
|
||||
@ -127,8 +130,9 @@ func (v *ChunkWriter) Release() {
|
||||
|
||||
func (v *ChunkWriter) Write(payload *alloc.Buffer) error {
|
||||
totalLength := payload.Len()
|
||||
payload.PrependFunc(AuthSize, v.auth.Authenticate(payload.Bytes()))
|
||||
payload.PrependFunc(2, serial.WriteUint16(uint16(totalLength)))
|
||||
_, err := v.writer.Write(payload.Bytes())
|
||||
serial.Uint16ToBytes(uint16(totalLength), v.buffer[:0])
|
||||
v.auth.Authenticate(payload.Bytes())(v.buffer[2:])
|
||||
copy(v.buffer[2+AuthSize:], payload.Bytes())
|
||||
_, err := v.writer.Write(v.buffer[:2+AuthSize+payload.Len()])
|
||||
return err
|
||||
}
|
||||
|
@ -19,9 +19,6 @@ func TestNormalChunkReading(t *testing.T) {
|
||||
payload, err := reader.Read()
|
||||
assert.Error(err).IsNil()
|
||||
assert.Bytes(payload.Bytes()).Equals([]byte{11, 12, 13, 14, 15, 16, 17, 18})
|
||||
|
||||
payload.PrependBytes(3, 4)
|
||||
assert.Bytes(payload.Bytes()).Equals([]byte{3, 4, 11, 12, 13, 14, 15, 16, 17, 18})
|
||||
}
|
||||
|
||||
func TestNormalChunkWriting(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user