mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-30 05:56:54 -05:00
rename CorruptedPacket to ErrorCorruptedPacket
This commit is contained in:
parent
1e79a3b75a
commit
383eb57487
@ -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
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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])
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -5,5 +5,5 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
CorruptedPacket = errors.New("Packet is corrupted.")
|
||||
ErrorCorruptedPacket = errors.New("Packet is corrupted.")
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user