diff --git a/app/proxyman/mux/reader.go b/app/proxyman/mux/reader.go index 3443dd80..641f074c 100644 --- a/app/proxyman/mux/reader.go +++ b/app/proxyman/mux/reader.go @@ -89,7 +89,7 @@ func (r *StreamReader) ReadMultiBuffer() (buf.MultiBuffer, error) { r.leftOver = int32(size) } - mb, err := r.reader.ReadAtMost(int(r.leftOver)) - r.leftOver -= int32(mb.Len()) + mb, err := r.reader.ReadAtMost(r.leftOver) + r.leftOver -= mb.Len() return mb, err } diff --git a/app/proxyman/mux/writer.go b/app/proxyman/mux/writer.go index b7ecfa4e..b043909f 100644 --- a/app/proxyman/mux/writer.go +++ b/app/proxyman/mux/writer.go @@ -71,7 +71,7 @@ func (w *Writer) writeData(mb buf.MultiBuffer) error { return err } - mb2 := buf.NewMultiBufferCap(len(mb) + 1) + mb2 := buf.NewMultiBufferCap(int32(len(mb)) + 1) mb2.Append(frame) mb2.AppendMulti(mb) return w.writer.WriteMultiBuffer(mb2) diff --git a/common/buf/buffer.go b/common/buf/buffer.go index d2ca828e..340cdf76 100644 --- a/common/buf/buffer.go +++ b/common/buf/buffer.go @@ -56,13 +56,13 @@ func (b *Buffer) AppendSupplier(writer Supplier) error { } // Byte returns the bytes at index. -func (b *Buffer) Byte(index int) byte { - return b.v[b.start+int32(index)] +func (b *Buffer) Byte(index int32) byte { + return b.v[b.start+index] } // SetByte sets the byte value at index. -func (b *Buffer) SetByte(index int, value byte) { - b.v[b.start+int32(index)] = value +func (b *Buffer) SetByte(index int32, value byte) { + b.v[b.start+index] = value } // Bytes returns the content bytes of this Buffer. @@ -79,34 +79,34 @@ func (b *Buffer) Reset(writer Supplier) error { } // BytesRange returns a slice of this buffer with given from and to boundary. -func (b *Buffer) BytesRange(from, to int) []byte { +func (b *Buffer) BytesRange(from, to int32) []byte { if from < 0 { from += b.Len() } if to < 0 { to += b.Len() } - return b.v[b.start+int32(from) : b.start+int32(to)] + return b.v[b.start+from : b.start+to] } // BytesFrom returns a slice of this Buffer starting from the given position. -func (b *Buffer) BytesFrom(from int) []byte { +func (b *Buffer) BytesFrom(from int32) []byte { if from < 0 { from += b.Len() } - return b.v[b.start+int32(from) : b.end] + return b.v[b.start+from : b.end] } // BytesTo returns a slice of this Buffer from start to the given position. -func (b *Buffer) BytesTo(to int) []byte { +func (b *Buffer) BytesTo(to int32) []byte { if to < 0 { to += b.Len() } - return b.v[b.start : b.start+int32(to)] + return b.v[b.start : b.start+to] } // Slice cuts the buffer at the given position. -func (b *Buffer) Slice(from, to int) { +func (b *Buffer) Slice(from, to int32) { if from < 0 { from += b.Len() } @@ -116,24 +116,24 @@ func (b *Buffer) Slice(from, to int) { if to < from { panic("Invalid slice") } - b.end = b.start + int32(to) - b.start += int32(from) + b.end = b.start + to + b.start += from } // SliceFrom cuts the buffer at the given position. -func (b *Buffer) SliceFrom(from int) { +func (b *Buffer) SliceFrom(from int32) { if from < 0 { from += b.Len() } - b.start += int32(from) + b.start += from } // Len returns the length of the buffer content. -func (b *Buffer) Len() int { +func (b *Buffer) Len() int32 { if b == nil { return 0 } - return int(b.end - b.start) + return b.end - b.start } // IsEmpty returns true if the buffer is empty. @@ -159,7 +159,7 @@ func (b *Buffer) Read(data []byte) (int, error) { return 0, io.EOF } nBytes := copy(data, b.v[b.start:b.end]) - if nBytes == b.Len() { + if int32(nBytes) == b.Len() { b.Clear() } else { b.start += int32(nBytes) diff --git a/common/buf/buffer_test.go b/common/buf/buffer_test.go index a51687d6..e00ba28f 100644 --- a/common/buf/buffer_test.go +++ b/common/buf/buffer_test.go @@ -16,10 +16,10 @@ func TestBufferClear(t *testing.T) { payload := "Bytes" buffer.Append([]byte(payload)) - assert(buffer.Len(), Equals, len(payload)) + assert(buffer.Len(), Equals, int32(len(payload))) buffer.Clear() - assert(buffer.Len(), Equals, 0) + assert(buffer.Len(), Equals, int32(0)) } func TestBufferIsEmpty(t *testing.T) { diff --git a/common/buf/multi_buffer.go b/common/buf/multi_buffer.go index ade8630c..60b7ce8e 100644 --- a/common/buf/multi_buffer.go +++ b/common/buf/multi_buffer.go @@ -66,7 +66,7 @@ func ReadAllToBytes(reader io.Reader) ([]byte, error) { type MultiBuffer []*Buffer // NewMultiBufferCap creates a new MultiBuffer instance. -func NewMultiBufferCap(capacity int) MultiBuffer { +func NewMultiBufferCap(capacity int32) MultiBuffer { return MultiBuffer(make([]*Buffer, 0, capacity)) } @@ -93,7 +93,7 @@ func (mb MultiBuffer) Copy(b []byte) int { for _, bb := range mb { nBytes := copy(b[total:], bb.Bytes()) total += nBytes - if nBytes < bb.Len() { + if int32(nBytes) < bb.Len() { break } } @@ -137,8 +137,8 @@ func (mb *MultiBuffer) Write(b []byte) { } // Len returns the total number of bytes in the MultiBuffer. -func (mb MultiBuffer) Len() int { - size := 0 +func (mb MultiBuffer) Len() int32 { + size := int32(0) for _, b := range mb { size += b.Len() } @@ -176,10 +176,10 @@ func (mb MultiBuffer) ToNetBuffers() net.Buffers { // SliceBySize splits the beginning of this MultiBuffer into another one, for at most size bytes. func (mb *MultiBuffer) SliceBySize(size int32) MultiBuffer { slice := NewMultiBufferCap(10) - sliceSize := 0 + sliceSize := int32(0) endIndex := len(*mb) for i, b := range *mb { - if int32(b.Len()+sliceSize) > size { + if b.Len()+sliceSize > size { endIndex = i break } diff --git a/common/buf/multi_buffer_test.go b/common/buf/multi_buffer_test.go index e78918f4..656d0656 100644 --- a/common/buf/multi_buffer_test.go +++ b/common/buf/multi_buffer_test.go @@ -33,7 +33,7 @@ func TestMultiBufferAppend(t *testing.T) { b := New() b.AppendBytes('a', 'b') mb.Append(b) - assert(mb.Len(), Equals, 2) + assert(mb.Len(), Equals, int32(2)) } func TestMultiBufferSliceBySizeLarge(t *testing.T) { @@ -46,5 +46,5 @@ func TestMultiBufferSliceBySizeLarge(t *testing.T) { mb.Append(lb) mb2 := mb.SliceBySize(4 * 1024) - assert(mb2.Len(), Equals, 4*1024) + assert(mb2.Len(), Equals, int32(4*1024)) } diff --git a/common/buf/reader.go b/common/buf/reader.go index 72d95500..df7af923 100644 --- a/common/buf/reader.go +++ b/common/buf/reader.go @@ -51,7 +51,7 @@ func (r *BytesToBufferReader) ReadMultiBuffer() (MultiBuffer, error) { nBytes, err := r.Reader.Read(r.buffer) if nBytes > 0 { - mb := NewMultiBufferCap(nBytes/Size + 1) + mb := NewMultiBufferCap(int32(nBytes/Size) + 1) mb.Write(r.buffer[:nBytes]) if nBytes == len(r.buffer) && nBytes < int(largeSize) { freeBytes(r.buffer) @@ -99,7 +99,7 @@ func (r *BufferedReader) IsBuffered() bool { // BufferedBytes returns the number of bytes that is cached in this reader. func (r *BufferedReader) BufferedBytes() int32 { - return int32(r.leftOver.Len()) + return r.leftOver.Len() } // ReadByte implements io.ByteReader. @@ -149,7 +149,7 @@ func (r *BufferedReader) ReadMultiBuffer() (MultiBuffer, error) { } // ReadAtMost returns a MultiBuffer with at most size. -func (r *BufferedReader) ReadAtMost(size int) (MultiBuffer, error) { +func (r *BufferedReader) ReadAtMost(size int32) (MultiBuffer, error) { if r.leftOver == nil { mb, err := r.stream.ReadMultiBuffer() if mb.IsEmpty() && err != nil { @@ -158,7 +158,7 @@ func (r *BufferedReader) ReadAtMost(size int) (MultiBuffer, error) { r.leftOver = mb } - mb := r.leftOver.SliceBySize(int32(size)) + mb := r.leftOver.SliceBySize(size) if r.leftOver.IsEmpty() { r.leftOver = nil } diff --git a/common/buf/reader_test.go b/common/buf/reader_test.go index 36cd003b..6086a730 100644 --- a/common/buf/reader_test.go +++ b/common/buf/reader_test.go @@ -17,23 +17,23 @@ func TestAdaptiveReader(t *testing.T) { reader := NewReader(bytes.NewReader(make([]byte, 1024*1024))) b, err := reader.ReadMultiBuffer() assert(err, IsNil) - assert(b.Len(), Equals, 2*1024) + assert(b.Len(), Equals, int32(2*1024)) b, err = reader.ReadMultiBuffer() assert(err, IsNil) - assert(b.Len(), Equals, 8*1024) + assert(b.Len(), Equals, int32(8*1024)) b, err = reader.ReadMultiBuffer() assert(err, IsNil) - assert(b.Len(), Equals, 32*1024) + assert(b.Len(), Equals, int32(32*1024)) b, err = reader.ReadMultiBuffer() assert(err, IsNil) - assert(b.Len(), Equals, 128*1024) + assert(b.Len(), Equals, int32(128*1024)) b, err = reader.ReadMultiBuffer() assert(err, IsNil) - assert(b.Len(), Equals, 512*1024) + assert(b.Len(), Equals, int32(512*1024)) } func TestBytesReaderWriteTo(t *testing.T) { diff --git a/common/buf/writer_test.go b/common/buf/writer_test.go index 1dbe2f22..b90f84c9 100644 --- a/common/buf/writer_test.go +++ b/common/buf/writer_test.go @@ -47,7 +47,7 @@ func TestBytesWriterReadFrom(t *testing.T) { mb, err := cache.ReadMultiBuffer() assert(err, IsNil) - assert(mb.Len(), Equals, size) + assert(mb.Len(), Equals, int32(size)) } func TestDiscardBytes(t *testing.T) { diff --git a/common/crypto/auth.go b/common/crypto/auth.go index 7aecea41..7ea682d9 100644 --- a/common/crypto/auth.go +++ b/common/crypto/auth.go @@ -149,12 +149,12 @@ func (r *AuthenticationReader) readInternal(soft bool) (*buf.Buffer, error) { return nil, err } - rb, err := r.auth.Open(b.BytesTo(0), b.BytesTo(int(size))) + rb, err := r.auth.Open(b.BytesTo(0), b.BytesTo(size)) if err != nil { b.Release() return nil, err } - b.Slice(0, len(rb)) + b.Slice(0, int32(len(rb))) return b, nil } @@ -200,7 +200,7 @@ func NewAuthenticationWriter(auth Authenticator, sizeParser ChunkSizeEncoder, wr } func (w *AuthenticationWriter) seal(b *buf.Buffer) (*buf.Buffer, error) { - encryptedSize := b.Len() + w.auth.Overhead() + encryptedSize := int(b.Len()) + w.auth.Overhead() eb := buf.New() common.Must(eb.Reset(func(bb []byte) (int, error) { @@ -222,7 +222,7 @@ func (w *AuthenticationWriter) writeStream(mb buf.MultiBuffer) error { defer mb.Release() payloadSize := buf.Size - w.auth.Overhead() - w.sizeParser.SizeBytes() - mb2Write := buf.NewMultiBufferCap(len(mb) + 10) + mb2Write := buf.NewMultiBufferCap(int32(len(mb) + 10)) for { b := buf.New() @@ -256,7 +256,7 @@ func (w *AuthenticationWriter) writePacket(mb buf.MultiBuffer) error { return w.writer.WriteMultiBuffer(buf.NewMultiBufferValue(eb)) } - mb2Write := buf.NewMultiBufferCap(len(mb) + 1) + mb2Write := buf.NewMultiBufferCap(int32(len(mb)) + 1) for !mb.IsEmpty() { b := mb.SplitFirst() diff --git a/common/crypto/auth_test.go b/common/crypto/auth_test.go index b3cbe4f6..702ddbb3 100644 --- a/common/crypto/auth_test.go +++ b/common/crypto/auth_test.go @@ -30,7 +30,7 @@ func TestAuthenticationReaderWriter(t *testing.T) { payload := buf.NewSize(payloadSize) payload.Append(rawPayload) - assert(payload.Len(), Equals, payloadSize) + assert(payload.Len(), Equals, int32(payloadSize)) cache := buf.NewSize(160 * 1024) iv := make([]byte, 12) @@ -45,7 +45,7 @@ func TestAuthenticationReaderWriter(t *testing.T) { }, PlainChunkSizeParser{}, cache, protocol.TransferTypeStream) assert(writer.WriteMultiBuffer(buf.NewMultiBufferValue(payload)), IsNil) - assert(cache.Len(), Equals, 82658) + assert(cache.Len(), Equals, int32(82658)) assert(writer.WriteMultiBuffer(buf.MultiBuffer{}), IsNil) reader := NewAuthenticationReader(&AEADAuthenticator{ @@ -65,7 +65,7 @@ func TestAuthenticationReaderWriter(t *testing.T) { mb.AppendMulti(mb2) } - assert(mb.Len(), Equals, payloadSize) + assert(mb.Len(), Equals, int32(payloadSize)) mbContent := make([]byte, payloadSize) mb.Read(mbContent) @@ -108,7 +108,7 @@ func TestAuthenticationReaderWriterPacket(t *testing.T) { payload.Append(pb2) assert(writer.WriteMultiBuffer(payload), IsNil) - assert(cache.Len(), GreaterThan, 0) + assert(cache.Len(), GreaterThan, int32(0)) assert(writer.WriteMultiBuffer(buf.MultiBuffer{}), IsNil) assert(err, IsNil) diff --git a/common/crypto/chunk.go b/common/crypto/chunk.go index e5411998..e58078d4 100644 --- a/common/crypto/chunk.go +++ b/common/crypto/chunk.go @@ -62,7 +62,7 @@ type ChunkStreamReader struct { reader *buf.BufferedReader buffer []byte - leftOverSize int + leftOverSize int32 } func NewChunkStreamReader(sizeDecoder ChunkSizeDecoder, reader io.Reader) *ChunkStreamReader { @@ -90,7 +90,7 @@ func (r *ChunkStreamReader) ReadMultiBuffer() (buf.MultiBuffer, error) { if nextSize == 0 { return nil, io.EOF } - size = int(nextSize) + size = int32(nextSize) } r.leftOverSize = size diff --git a/common/crypto/chunk_test.go b/common/crypto/chunk_test.go index d5d8c9e5..f1ef5d28 100644 --- a/common/crypto/chunk_test.go +++ b/common/crypto/chunk_test.go @@ -27,16 +27,16 @@ func TestChunkStreamIO(t *testing.T) { assert(writer.WriteMultiBuffer(buf.MultiBuffer{}), IsNil) - assert(cache.Len(), Equals, 13) + assert(cache.Len(), Equals, int32(13)) mb, err := reader.ReadMultiBuffer() assert(err, IsNil) - assert(mb.Len(), Equals, 4) + assert(mb.Len(), Equals, int32(4)) assert(mb[0].Bytes(), Equals, []byte("abcd")) mb, err = reader.ReadMultiBuffer() assert(err, IsNil) - assert(mb.Len(), Equals, 3) + assert(mb.Len(), Equals, int32(3)) assert(mb[0].Bytes(), Equals, []byte("efg")) _, err = reader.ReadMultiBuffer() diff --git a/common/protocol/address.go b/common/protocol/address.go index 9534c5b5..48daf761 100644 --- a/common/protocol/address.go +++ b/common/protocol/address.go @@ -98,7 +98,7 @@ func (p *AddressParser) readAddress(b *buf.Buffer, reader io.Reader) (net.Addres if err := b.AppendSupplier(buf.ReadFullFrom(reader, 1)); err != nil { return nil, err } - domainLength := int(b.Byte(b.Len() - 1)) + domainLength := int32(b.Byte(b.Len() - 1)) if err := b.AppendSupplier(buf.ReadFullFrom(reader, int32(domainLength))); err != nil { return nil, err } diff --git a/proxy/shadowsocks/config.go b/proxy/shadowsocks/config.go index 4d67b02b..3c30a1c0 100644 --- a/proxy/shadowsocks/config.go +++ b/proxy/shadowsocks/config.go @@ -96,8 +96,8 @@ func (a *Account) AsAccount() (protocol.Account, error) { // Cipher is an interface for all Shadowsocks ciphers. type Cipher interface { - KeySize() int - IVSize() int + KeySize() int32 + IVSize() int32 NewEncryptionWriter(key []byte, iv []byte, writer io.Writer) (buf.Writer, error) NewDecryptionReader(key []byte, iv []byte, reader io.Reader) (buf.Reader, error) IsAEAD() bool @@ -107,18 +107,18 @@ type Cipher interface { // AesCfb represents all AES-CFB ciphers. type AesCfb struct { - KeyBytes int + KeyBytes int32 } func (*AesCfb) IsAEAD() bool { return false } -func (v *AesCfb) KeySize() int { +func (v *AesCfb) KeySize() int32 { return v.KeyBytes } -func (v *AesCfb) IVSize() int { +func (v *AesCfb) IVSize() int32 { return 16 } @@ -151,8 +151,8 @@ func (v *AesCfb) DecodePacket(key []byte, b *buf.Buffer) error { } type AEADCipher struct { - KeyBytes int - IVBytes int + KeyBytes int32 + IVBytes int32 AEADAuthCreator func(key []byte) cipher.AEAD } @@ -160,11 +160,11 @@ func (*AEADCipher) IsAEAD() bool { return true } -func (c *AEADCipher) KeySize() int { +func (c *AEADCipher) KeySize() int32 { return c.KeyBytes } -func (c *AEADCipher) IVSize() int { +func (c *AEADCipher) IVSize() int32 { return c.IVBytes } @@ -226,18 +226,18 @@ func (c *AEADCipher) DecodePacket(key []byte, b *buf.Buffer) error { } type ChaCha20 struct { - IVBytes int + IVBytes int32 } func (*ChaCha20) IsAEAD() bool { return false } -func (v *ChaCha20) KeySize() int { +func (v *ChaCha20) KeySize() int32 { return 32 } -func (v *ChaCha20) IVSize() int { +func (v *ChaCha20) IVSize() int32 { return v.IVBytes } @@ -271,8 +271,8 @@ func (v *ChaCha20) DecodePacket(key []byte, b *buf.Buffer) error { type NoneCipher struct{} -func (NoneCipher) KeySize() int { return 0 } -func (NoneCipher) IVSize() int { return 0 } +func (NoneCipher) KeySize() int32 { return 0 } +func (NoneCipher) IVSize() int32 { return 0 } func (NoneCipher) IsAEAD() bool { return true // to avoid OTA } @@ -293,13 +293,13 @@ func (NoneCipher) DecodePacket(key []byte, b *buf.Buffer) error { return nil } -func passwordToCipherKey(password []byte, keySize int) []byte { +func passwordToCipherKey(password []byte, keySize int32) []byte { key := make([]byte, 0, keySize) md5Sum := md5.Sum(password) key = append(key, md5Sum[:]...) - for len(key) < keySize { + for int32(len(key)) < keySize { md5Hash := md5.New() common.Must2(md5Hash.Write(md5Sum[:])) common.Must2(md5Hash.Write(password)) diff --git a/proxy/socks/protocol.go b/proxy/socks/protocol.go index 8715e30c..bd3a1182 100644 --- a/proxy/socks/protocol.go +++ b/proxy/socks/protocol.go @@ -26,10 +26,6 @@ const ( authPassword = 0x02 authNoMatchingMethod = 0xFF - addrTypeIPv4 = 0x01 - addrTypeIPv6 = 0x04 - addrTypeDomain = 0x03 - statusSuccess = 0x00 statusCmdNotSupport = 0x07 ) @@ -96,8 +92,8 @@ func (s *ServerSession) Handshake(reader io.Reader, writer io.Writer) (*protocol } if version == socks5Version { - nMethod := int(buffer.Byte(1)) - if err := buffer.AppendSupplier(buf.ReadFullFrom(reader, int32(nMethod))); err != nil { + nMethod := int32(buffer.Byte(1)) + if err := buffer.AppendSupplier(buf.ReadFullFrom(reader, nMethod)); err != nil { return nil, newError("failed to read auth methods").Base(err) } diff --git a/testing/scenarios/shadowsocks_test.go b/testing/scenarios/shadowsocks_test.go index c93d3923..6a803157 100644 --- a/testing/scenarios/shadowsocks_test.go +++ b/testing/scenarios/shadowsocks_test.go @@ -883,7 +883,7 @@ func TestShadowsocksChacha20Poly1305UDPConformance(t *testing.T) { Port: int(serverPort), }) assert(err, IsNil) - assert(nBytes, Equals, payload.Len()) + assert(int32(nBytes), Equals, payload.Len()) conn.SetReadDeadline(time.Now().Add(time.Second * 10)) response := make([]byte, 10240) diff --git a/transport/internet/header.go b/transport/internet/header.go index 20c86d88..c6bde925 100644 --- a/transport/internet/header.go +++ b/transport/internet/header.go @@ -8,7 +8,7 @@ import ( ) type PacketHeader interface { - Size() int + Size() int32 Write([]byte) (int, error) } diff --git a/transport/internet/headers/http/http.go b/transport/internet/headers/http/http.go index 397b5497..0a2f9e27 100644 --- a/transport/internet/headers/http/http.go +++ b/transport/internet/headers/http/http.go @@ -57,7 +57,7 @@ type HeaderReader struct { func (*HeaderReader) Read(reader io.Reader) (*buf.Buffer, error) { buffer := buf.New() - totalBytes := 0 + totalBytes := int32(0) endingDetected := false for totalBytes < maxHeaderLength { err := buffer.AppendSupplier(buf.ReadFrom(reader)) @@ -66,13 +66,13 @@ func (*HeaderReader) Read(reader io.Reader) (*buf.Buffer, error) { return nil, err } if n := bytes.Index(buffer.Bytes(), []byte(ENDING)); n != -1 { - buffer.SliceFrom(n + len(ENDING)) + buffer.SliceFrom(int32(n + len(ENDING))) endingDetected = true break } - if buffer.Len() >= len(ENDING) { - totalBytes += buffer.Len() - len(ENDING) - leftover := buffer.BytesFrom(-len(ENDING)) + if buffer.Len() >= int32(len(ENDING)) { + totalBytes += buffer.Len() - int32(len(ENDING)) + leftover := buffer.BytesFrom(-int32(len(ENDING))) buffer.Reset(func(b []byte) (int, error) { return copy(b, leftover), nil }) diff --git a/transport/internet/headers/http/http_test.go b/transport/internet/headers/http/http_test.go index 315cad76..ff8b9c54 100644 --- a/transport/internet/headers/http/http_test.go +++ b/transport/internet/headers/http/http_test.go @@ -21,7 +21,7 @@ func TestReaderWriter(t *testing.T) { writer := NewHeaderWriter(b) err := writer.Write(cache) assert(err, IsNil) - assert(cache.Len(), Equals, 8) + assert(cache.Len(), Equals, int32(8)) _, err = cache.Write([]byte{'e', 'f', 'g'}) assert(err, IsNil) diff --git a/transport/internet/headers/noop/noop.go b/transport/internet/headers/noop/noop.go index 9d1dd711..a9c87385 100644 --- a/transport/internet/headers/noop/noop.go +++ b/transport/internet/headers/noop/noop.go @@ -9,7 +9,7 @@ import ( type NoOpHeader struct{} -func (NoOpHeader) Size() int { +func (NoOpHeader) Size() int32 { return 0 } diff --git a/transport/internet/headers/srtp/srtp.go b/transport/internet/headers/srtp/srtp.go index 69e08b4b..4d5cacf4 100644 --- a/transport/internet/headers/srtp/srtp.go +++ b/transport/internet/headers/srtp/srtp.go @@ -13,7 +13,7 @@ type SRTP struct { number uint16 } -func (*SRTP) Size() int { +func (*SRTP) Size() int32 { return 4 } diff --git a/transport/internet/headers/srtp/srtp_test.go b/transport/internet/headers/srtp/srtp_test.go index 1b08dae4..8856df80 100644 --- a/transport/internet/headers/srtp/srtp_test.go +++ b/transport/internet/headers/srtp/srtp_test.go @@ -22,5 +22,5 @@ func TestSRTPWrite(t *testing.T) { payload.AppendSupplier(srtp.Write) payload.Append(content) - assert(payload.Len(), Equals, len(content)+srtp.Size()) + assert(payload.Len(), Equals, int32(len(content))+srtp.Size()) } diff --git a/transport/internet/headers/utp/utp.go b/transport/internet/headers/utp/utp.go index c76c5fe0..e556bf52 100644 --- a/transport/internet/headers/utp/utp.go +++ b/transport/internet/headers/utp/utp.go @@ -14,7 +14,7 @@ type UTP struct { connectionId uint16 } -func (*UTP) Size() int { +func (*UTP) Size() int32 { return 4 } diff --git a/transport/internet/headers/utp/utp_test.go b/transport/internet/headers/utp/utp_test.go index a41480e2..845f8b1f 100644 --- a/transport/internet/headers/utp/utp_test.go +++ b/transport/internet/headers/utp/utp_test.go @@ -22,5 +22,5 @@ func TestUTPWrite(t *testing.T) { payload.AppendSupplier(utp.Write) payload.Append(content) - assert(payload.Len(), Equals, len(content)+utp.Size()) + assert(payload.Len(), Equals, int32(len(content))+utp.Size()) } diff --git a/transport/internet/headers/wechat/wechat.go b/transport/internet/headers/wechat/wechat.go index 2d0473c9..5baa3e85 100644 --- a/transport/internet/headers/wechat/wechat.go +++ b/transport/internet/headers/wechat/wechat.go @@ -12,7 +12,7 @@ type VideoChat struct { sn int } -func (vc *VideoChat) Size() int { +func (vc *VideoChat) Size() int32 { return 13 } diff --git a/transport/internet/kcp/io.go b/transport/internet/kcp/io.go index 8548b7e2..27e85bc9 100644 --- a/transport/internet/kcp/io.go +++ b/transport/internet/kcp/io.go @@ -57,7 +57,7 @@ type KCPPacketWriter struct { func (w *KCPPacketWriter) Overhead() int { overhead := 0 if w.Header != nil { - overhead += w.Header.Size() + overhead += int(w.Header.Size()) } if w.Security != nil { overhead += w.Security.Overhead() diff --git a/transport/internet/kcp/segment.go b/transport/internet/kcp/segment.go index 9af1629d..c689f939 100644 --- a/transport/internet/kcp/segment.go +++ b/transport/internet/kcp/segment.go @@ -29,7 +29,7 @@ type Segment interface { Release() Conversation() uint16 Command() Command - ByteSize() int + ByteSize() int32 Bytes() buf.Supplier parse(conv uint16, cmd Command, opt SegmentOption, buf []byte) (bool, []byte) } @@ -116,7 +116,7 @@ func (s *DataSegment) Bytes() buf.Supplier { } } -func (s *DataSegment) ByteSize() int { +func (s *DataSegment) ByteSize() int32 { return 2 + 1 + 1 + 4 + 4 + 4 + 2 + s.payload.Len() } @@ -198,8 +198,8 @@ func (s *AckSegment) IsEmpty() bool { return len(s.NumberList) == 0 } -func (s *AckSegment) ByteSize() int { - return 2 + 1 + 1 + 4 + 4 + 4 + 1 + len(s.NumberList)*4 +func (s *AckSegment) ByteSize() int32 { + return 2 + 1 + 1 + 4 + 4 + 4 + 1 + int32(len(s.NumberList)*4) } func (s *AckSegment) Bytes() buf.Supplier { @@ -214,7 +214,7 @@ func (s *AckSegment) Bytes() buf.Supplier { for _, number := range s.NumberList { b = serial.Uint32ToBytes(number, b) } - return s.ByteSize(), nil + return int(s.ByteSize()), nil } } @@ -264,7 +264,7 @@ func (s *CmdOnlySegment) Command() Command { return s.Cmd } -func (*CmdOnlySegment) ByteSize() int { +func (*CmdOnlySegment) ByteSize() int32 { return 2 + 1 + 1 + 4 + 4 + 4 } diff --git a/transport/internet/kcp/segment_test.go b/transport/internet/kcp/segment_test.go index f12d488e..2f1ba70a 100644 --- a/transport/internet/kcp/segment_test.go +++ b/transport/internet/kcp/segment_test.go @@ -30,7 +30,7 @@ func TestDataSegment(t *testing.T) { bytes := make([]byte, nBytes) seg.Bytes()(bytes) - assert(len(bytes), Equals, nBytes) + assert(int32(len(bytes)), Equals, nBytes) iseg, _ := ReadSegment(bytes) seg2 := iseg.(*DataSegment) @@ -56,7 +56,7 @@ func Test1ByteDataSegment(t *testing.T) { bytes := make([]byte, nBytes) seg.Bytes()(bytes) - assert(len(bytes), Equals, nBytes) + assert(int32(len(bytes)), Equals, nBytes) iseg, _ := ReadSegment(bytes) seg2 := iseg.(*DataSegment) @@ -82,7 +82,7 @@ func TestACKSegment(t *testing.T) { bytes := make([]byte, nBytes) seg.Bytes()(bytes) - assert(len(bytes), Equals, nBytes) + assert(int32(len(bytes)), Equals, nBytes) iseg, _ := ReadSegment(bytes) seg2 := iseg.(*AckSegment) @@ -112,7 +112,7 @@ func TestCmdSegment(t *testing.T) { bytes := make([]byte, nBytes) seg.Bytes()(bytes) - assert(len(bytes), Equals, nBytes) + assert(int32(len(bytes)), Equals, nBytes) iseg, _ := ReadSegment(bytes) seg2 := iseg.(*CmdOnlySegment) diff --git a/transport/ray/connection.go b/transport/ray/connection.go index 2bc4d39b..dbf36d5f 100644 --- a/transport/ray/connection.go +++ b/transport/ray/connection.go @@ -79,7 +79,7 @@ func (c *connection) Write(b []byte) (int, error) { } l := len(b) - mb := buf.NewMultiBufferCap(l/buf.Size + 1) + mb := buf.NewMultiBufferCap(int32(l)/buf.Size + 1) mb.Write(b) return l, c.output.WriteMultiBuffer(mb) }