From 383eb574879b22096f87809a464a08a76bc48768 Mon Sep 17 00:00:00 2001 From: v2ray Date: Sat, 30 Jan 2016 17:20:30 +0100 Subject: [PATCH] rename CorruptedPacket to ErrorCorruptedPacket --- proxy/shadowsocks/ota.go | 2 +- proxy/shadowsocks/protocol.go | 18 +++++++++--------- proxy/socks/protocol/socks.go | 18 +++++++++--------- proxy/socks/protocol/socks_test.go | 2 +- proxy/socks/protocol/udp.go | 8 ++++---- proxy/socks/protocol/udp_test.go | 2 +- proxy/vmess/command/accounts.go | 14 +++++++------- proxy/vmess/command/dns.go | 8 ++++---- proxy/vmess/protocol/io/validation.go | 2 +- proxy/vmess/protocol/vmess.go | 4 ++-- transport/errors.go | 2 +- 11 files changed, 40 insertions(+), 40 deletions(-) diff --git a/proxy/shadowsocks/ota.go b/proxy/shadowsocks/ota.go index 6b0fa2e9a..ed2c7adae 100644 --- a/proxy/shadowsocks/ota.go +++ b/proxy/shadowsocks/ota.go @@ -88,7 +88,7 @@ func (this *ChunkReader) Read() (*alloc.Buffer, error) { if !serial.BytesLiteral(authBytes).Equals(serial.BytesLiteral(actualAuthBytes)) { alloc.Release(buffer) log.Debug("AuthenticationReader: Unexpected auth: ", authBytes) - return nil, transport.CorruptedPacket + return nil, transport.ErrorCorruptedPacket } buffer.Value = payload diff --git a/proxy/shadowsocks/protocol.go b/proxy/shadowsocks/protocol.go index a8391b0ae..2ec1febfd 100644 --- a/proxy/shadowsocks/protocol.go +++ b/proxy/shadowsocks/protocol.go @@ -30,7 +30,7 @@ func ReadRequest(reader io.Reader, auth *Authenticator, udp bool) (*Request, err _, err := io.ReadFull(reader, buffer.Value[:1]) if err != nil { log.Error("Shadowsocks: Failed to read address type: ", err) - return nil, transport.CorruptedPacket + return nil, transport.ErrorCorruptedPacket } lenBuffer := 1 @@ -45,7 +45,7 @@ func ReadRequest(reader io.Reader, auth *Authenticator, udp bool) (*Request, err _, err := io.ReadFull(reader, buffer.Value[lenBuffer:lenBuffer+4]) if err != nil { log.Error("Shadowsocks: Failed to read IPv4 address: ", err) - return nil, transport.CorruptedPacket + return nil, transport.ErrorCorruptedPacket } request.Address = v2net.IPAddress(buffer.Value[lenBuffer : lenBuffer+4]) lenBuffer += 4 @@ -53,7 +53,7 @@ func ReadRequest(reader io.Reader, auth *Authenticator, udp bool) (*Request, err _, err := io.ReadFull(reader, buffer.Value[lenBuffer:lenBuffer+16]) if err != nil { log.Error("Shadowsocks: Failed to read IPv6 address: ", err) - return nil, transport.CorruptedPacket + return nil, transport.ErrorCorruptedPacket } request.Address = v2net.IPAddress(buffer.Value[lenBuffer : lenBuffer+16]) lenBuffer += 16 @@ -61,26 +61,26 @@ func ReadRequest(reader io.Reader, auth *Authenticator, udp bool) (*Request, err _, err := io.ReadFull(reader, buffer.Value[lenBuffer:lenBuffer+1]) if err != nil { log.Error("Shadowsocks: Failed to read domain lenth: ", err) - return nil, transport.CorruptedPacket + return nil, transport.ErrorCorruptedPacket } domainLength := int(buffer.Value[lenBuffer]) lenBuffer++ _, err = io.ReadFull(reader, buffer.Value[lenBuffer:lenBuffer+domainLength]) if err != nil { log.Error("Shadowsocks: Failed to read domain: ", err) - return nil, transport.CorruptedPacket + return nil, transport.ErrorCorruptedPacket } request.Address = v2net.DomainAddress(string(buffer.Value[lenBuffer : lenBuffer+domainLength])) lenBuffer += domainLength default: log.Error("Shadowsocks: Unknown address type: ", addrType) - return nil, transport.CorruptedPacket + return nil, transport.ErrorCorruptedPacket } _, err = io.ReadFull(reader, buffer.Value[lenBuffer:lenBuffer+2]) if err != nil { log.Error("Shadowsocks: Failed to read port: ", err) - return nil, transport.CorruptedPacket + return nil, transport.ErrorCorruptedPacket } request.Port = v2net.PortFromBytes(buffer.Value[lenBuffer : lenBuffer+2]) @@ -107,7 +107,7 @@ func ReadRequest(reader io.Reader, auth *Authenticator, udp bool) (*Request, err _, err = io.ReadFull(reader, authBytes) if err != nil { log.Error("Shadowsocks: Failed to read OTA: ", err) - return nil, transport.CorruptedPacket + return nil, transport.ErrorCorruptedPacket } } } @@ -116,7 +116,7 @@ func ReadRequest(reader io.Reader, auth *Authenticator, udp bool) (*Request, err actualAuth := auth.Authenticate(nil, buffer.Value[0:lenBuffer]) if !serial.BytesLiteral(actualAuth).Equals(serial.BytesLiteral(authBytes)) { log.Error("Shadowsocks: Invalid OTA: ", actualAuth) - return nil, transport.CorruptedPacket + return nil, transport.ErrorCorruptedPacket } } diff --git a/proxy/socks/protocol/socks.go b/proxy/socks/protocol/socks.go index 0212e77ed..09e3fdf20 100644 --- a/proxy/socks/protocol/socks.go +++ b/proxy/socks/protocol/socks.go @@ -50,7 +50,7 @@ func ReadAuthentication(reader io.Reader) (auth Socks5AuthenticationRequest, aut } if nBytes < 2 { log.Warning("Socks: expected 2 bytes read, but only ", nBytes, " bytes read") - err = transport.CorruptedPacket + err = transport.ErrorCorruptedPacket return } @@ -73,13 +73,13 @@ func ReadAuthentication(reader io.Reader) (auth Socks5AuthenticationRequest, aut auth.nMethods = buffer.Value[1] if auth.nMethods <= 0 { log.Warning("Socks: Zero length of authentication methods") - err = transport.CorruptedPacket + err = transport.ErrorCorruptedPacket return } if nBytes-2 != int(auth.nMethods) { log.Warning("Socks: Unmatching number of auth methods, expecting ", auth.nMethods, ", but got ", nBytes) - err = transport.CorruptedPacket + err = transport.ErrorCorruptedPacket return } copy(auth.authMethods[:], buffer.Value[2:nBytes]) @@ -196,7 +196,7 @@ func ReadRequest(reader io.Reader) (request *Socks5Request, err error) { return } if nBytes < 4 { - err = transport.CorruptedPacket + err = transport.ErrorCorruptedPacket return } request = &Socks5Request{ @@ -212,7 +212,7 @@ func ReadRequest(reader io.Reader) (request *Socks5Request, err error) { return } if nBytes != 4 { - err = transport.CorruptedPacket + err = transport.ErrorCorruptedPacket return } case AddrTypeDomain: @@ -228,7 +228,7 @@ func ReadRequest(reader io.Reader) (request *Socks5Request, err error) { if nBytes != int(domainLength) { log.Warning("Socks: Unable to read domain with ", nBytes, " bytes, expecting ", domainLength, " bytes") - err = transport.CorruptedPacket + err = transport.ErrorCorruptedPacket return } request.Domain = string(append([]byte(nil), buffer.Value[:domainLength]...)) @@ -238,12 +238,12 @@ func ReadRequest(reader io.Reader) (request *Socks5Request, err error) { return } if nBytes != 16 { - err = transport.CorruptedPacket + err = transport.ErrorCorruptedPacket return } default: log.Warning("Socks: Unexpected address type ", request.AddrType) - err = transport.CorruptedPacket + err = transport.ErrorCorruptedPacket return } @@ -252,7 +252,7 @@ func ReadRequest(reader io.Reader) (request *Socks5Request, err error) { return } if nBytes != 2 { - err = transport.CorruptedPacket + err = transport.ErrorCorruptedPacket return } diff --git a/proxy/socks/protocol/socks_test.go b/proxy/socks/protocol/socks_test.go index 875c9c1a8..d0278ab49 100644 --- a/proxy/socks/protocol/socks_test.go +++ b/proxy/socks/protocol/socks_test.go @@ -137,5 +137,5 @@ func TestSignleByte(t *testing.T) { v2testing.Current(t) _, _, err := ReadAuthentication(bytes.NewReader(make([]byte, 1))) - assert.Error(err).Equals(transport.CorruptedPacket) + assert.Error(err).Equals(transport.ErrorCorruptedPacket) } diff --git a/proxy/socks/protocol/udp.go b/proxy/socks/protocol/udp.go index 596e38faf..11cbceff8 100644 --- a/proxy/socks/protocol/udp.go +++ b/proxy/socks/protocol/udp.go @@ -41,7 +41,7 @@ func (request *Socks5UDPRequest) Write(buffer *alloc.Buffer) { func ReadUDPRequest(packet []byte) (*Socks5UDPRequest, error) { if len(packet) < 5 { - return nil, transport.CorruptedPacket + return nil, transport.ErrorCorruptedPacket } request := new(Socks5UDPRequest) @@ -54,7 +54,7 @@ func ReadUDPRequest(packet []byte) (*Socks5UDPRequest, error) { switch addrType { case AddrTypeIPv4: if len(packet) < 10 { - return nil, transport.CorruptedPacket + return nil, transport.ErrorCorruptedPacket } ip := packet[4:8] request.Port = v2net.PortFromBytes(packet[8:10]) @@ -62,7 +62,7 @@ func ReadUDPRequest(packet []byte) (*Socks5UDPRequest, error) { dataBegin = 10 case AddrTypeIPv6: if len(packet) < 22 { - return nil, transport.CorruptedPacket + return nil, transport.ErrorCorruptedPacket } ip := packet[4:20] request.Port = v2net.PortFromBytes(packet[20:22]) @@ -71,7 +71,7 @@ func ReadUDPRequest(packet []byte) (*Socks5UDPRequest, error) { case AddrTypeDomain: domainLength := int(packet[4]) if len(packet) < 5+domainLength+2 { - return nil, transport.CorruptedPacket + return nil, transport.ErrorCorruptedPacket } domain := string(packet[5 : 5+domainLength]) request.Port = v2net.PortFromBytes(packet[5+domainLength : 5+domainLength+2]) diff --git a/proxy/socks/protocol/udp_test.go b/proxy/socks/protocol/udp_test.go index 58fdd5510..ee377318e 100644 --- a/proxy/socks/protocol/udp_test.go +++ b/proxy/socks/protocol/udp_test.go @@ -17,7 +17,7 @@ func TestSingleByteRequest(t *testing.T) { if request != nil { t.Fail() } - assert.Error(err).Equals(transport.CorruptedPacket) + assert.Error(err).Equals(transport.ErrorCorruptedPacket) } func TestDomainAddressRequest(t *testing.T) { diff --git a/proxy/vmess/command/accounts.go b/proxy/vmess/command/accounts.go index 04516cc98..deb9df729 100644 --- a/proxy/vmess/command/accounts.go +++ b/proxy/vmess/command/accounts.go @@ -55,38 +55,38 @@ func (this *SwitchAccount) Marshal(writer io.Writer) { func (this *SwitchAccount) Unmarshal(data []byte) error { if len(data) == 0 { - return transport.CorruptedPacket + return transport.ErrorCorruptedPacket } lenHost := int(data[0]) if len(data) < lenHost+1 { - return transport.CorruptedPacket + return transport.ErrorCorruptedPacket } if lenHost > 0 { this.Host = v2net.ParseAddress(string(data[1 : 1+lenHost])) } portStart := 1 + lenHost if len(data) < portStart+2 { - return transport.CorruptedPacket + return transport.ErrorCorruptedPacket } this.Port = v2net.PortFromBytes(data[portStart : portStart+2]) idStart := portStart + 2 if len(data) < idStart+16 { - return transport.CorruptedPacket + return transport.ErrorCorruptedPacket } this.ID, _ = uuid.ParseBytes(data[idStart : idStart+16]) alterIdStart := idStart + 16 if len(data) < alterIdStart+2 { - return transport.CorruptedPacket + return transport.ErrorCorruptedPacket } this.AlterIds = serial.BytesLiteral(data[alterIdStart : alterIdStart+2]).Uint16() levelStart := alterIdStart + 2 if len(data) < levelStart+1 { - return transport.CorruptedPacket + return transport.ErrorCorruptedPacket } this.Level = vmess.UserLevel(data[levelStart]) timeStart := levelStart + 1 if len(data) < timeStart { - return transport.CorruptedPacket + return transport.ErrorCorruptedPacket } this.ValidMin = data[timeStart] return nil diff --git a/proxy/vmess/command/dns.go b/proxy/vmess/command/dns.go index 75ee38f96..754015419 100644 --- a/proxy/vmess/command/dns.go +++ b/proxy/vmess/command/dns.go @@ -40,14 +40,14 @@ func (this *CacheDns) Marshal(writer io.Writer) { func (this *CacheDns) Unmarshal(data []byte) error { if len(data) == 0 { - return transport.CorruptedPacket + return transport.ErrorCorruptedPacket } typeIP := data[0] data = data[1:] if typeIP == typeIPv4 { if len(data) < 4 { - return transport.CorruptedPacket + return transport.ErrorCorruptedPacket } this.Address = v2net.IPAddress(data[0:4]) return nil @@ -55,11 +55,11 @@ func (this *CacheDns) Unmarshal(data []byte) error { if typeIP == typeIPv6 { if len(data) < 16 { - return transport.CorruptedPacket + return transport.ErrorCorruptedPacket } this.Address = v2net.IPAddress(data[0:16]) return nil } - return transport.CorruptedPacket + return transport.ErrorCorruptedPacket } diff --git a/proxy/vmess/protocol/io/validation.go b/proxy/vmess/protocol/io/validation.go index ea47cf909..8ec5d3fc4 100644 --- a/proxy/vmess/protocol/io/validation.go +++ b/proxy/vmess/protocol/io/validation.go @@ -68,7 +68,7 @@ func parsePayload(data []byte) (payload []byte, rest []byte, err error) { actualHash := fnv1a.Sum32() expectedHash := uint32(data[2])<<24 + uint32(data[3])<<16 + uint32(data[4])<<8 + uint32(data[5]) if actualHash != expectedHash { - err = transport.CorruptedPacket + err = transport.ErrorCorruptedPacket return } return diff --git a/proxy/vmess/protocol/vmess.go b/proxy/vmess/protocol/vmess.go index 118045734..58e9d129a 100644 --- a/proxy/vmess/protocol/vmess.go +++ b/proxy/vmess/protocol/vmess.go @@ -140,7 +140,7 @@ func (this *VMessRequestReader) Read(reader io.Reader) (*VMessRequest, error) { } domainLength := int(buffer.Value[41]) if domainLength == 0 { - return nil, transport.CorruptedPacket + return nil, transport.ErrorCorruptedPacket } nBytes, err = io.ReadFull(decryptor, buffer.Value[42:42+domainLength]) if err != nil { @@ -164,7 +164,7 @@ func (this *VMessRequestReader) Read(reader io.Reader) (*VMessRequest, error) { expectedHash := binary.BigEndian.Uint32(buffer.Value[bufferLen : bufferLen+4]) if actualHash != expectedHash { - return nil, transport.CorruptedPacket + return nil, transport.ErrorCorruptedPacket } return request, nil diff --git a/transport/errors.go b/transport/errors.go index 557d730c0..258f230f9 100644 --- a/transport/errors.go +++ b/transport/errors.go @@ -5,5 +5,5 @@ import ( ) var ( - CorruptedPacket = errors.New("Packet is corrupted.") + ErrorCorruptedPacket = errors.New("Packet is corrupted.") )