|
|
@@ -168,7 +168,7 @@ func WriteTCPRequest(request *protocol.RequestHeader, writer io.Writer) (buf.Wri
|
|
|
header.AppendBytes(AddrTypeDomain, byte(len(request.Address.Domain())))
|
|
|
header.Append([]byte(request.Address.Domain()))
|
|
|
default:
|
|
|
- return nil, newError("Shadowsocks|TCP: Unsupported address type: ", request.Address.Family())
|
|
|
+ return nil, newError("unsupported address type: ", request.Address.Family())
|
|
|
}
|
|
|
|
|
|
header.AppendSupplier(serial.WriteUint16(uint16(request.Port)))
|
|
|
@@ -182,7 +182,7 @@ func WriteTCPRequest(request *protocol.RequestHeader, writer io.Writer) (buf.Wri
|
|
|
|
|
|
_, err = writer.Write(header.Bytes())
|
|
|
if err != nil {
|
|
|
- return nil, newError("Shadowsocks|TCP: Failed to write header.").Base(err)
|
|
|
+ return nil, newError("failed to write header").Base(err)
|
|
|
}
|
|
|
|
|
|
var chunkWriter buf.Writer
|
|
|
@@ -198,19 +198,19 @@ func WriteTCPRequest(request *protocol.RequestHeader, writer io.Writer) (buf.Wri
|
|
|
func ReadTCPResponse(user *protocol.User, reader io.Reader) (buf.Reader, error) {
|
|
|
rawAccount, err := user.GetTypedAccount()
|
|
|
if err != nil {
|
|
|
- return nil, newError("Shadowsocks|TCP: Failed to parse account.").Base(err)
|
|
|
+ return nil, newError("failed to parse account").Base(err).AtError()
|
|
|
}
|
|
|
account := rawAccount.(*ShadowsocksAccount)
|
|
|
|
|
|
iv := make([]byte, account.Cipher.IVSize())
|
|
|
_, err = io.ReadFull(reader, iv)
|
|
|
if err != nil {
|
|
|
- return nil, newError("Shadowsocks|TCP: Failed to read IV.").Base(err)
|
|
|
+ return nil, newError("failed to read IV").Base(err)
|
|
|
}
|
|
|
|
|
|
stream, err := account.Cipher.NewDecodingStream(account.Key, iv)
|
|
|
if err != nil {
|
|
|
- return nil, newError("Shadowsocks|TCP: Failed to initialize decoding stream.").Base(err)
|
|
|
+ return nil, newError("failed to initialize decoding stream").Base(err).AtError()
|
|
|
}
|
|
|
return buf.NewReader(crypto.NewCryptionReader(stream, reader)), nil
|
|
|
}
|
|
|
@@ -219,7 +219,7 @@ func WriteTCPResponse(request *protocol.RequestHeader, writer io.Writer) (buf.Wr
|
|
|
user := request.User
|
|
|
rawAccount, err := user.GetTypedAccount()
|
|
|
if err != nil {
|
|
|
- return nil, newError("Shadowsocks|TCP: Failed to parse account.").Base(err)
|
|
|
+ return nil, newError("failed to parse account.").Base(err).AtError()
|
|
|
}
|
|
|
account := rawAccount.(*ShadowsocksAccount)
|
|
|
|
|
|
@@ -227,12 +227,12 @@ func WriteTCPResponse(request *protocol.RequestHeader, writer io.Writer) (buf.Wr
|
|
|
rand.Read(iv)
|
|
|
_, err = writer.Write(iv)
|
|
|
if err != nil {
|
|
|
- return nil, newError("Shadowsocks|TCP: Failed to write IV.").Base(err)
|
|
|
+ return nil, newError("failed to write IV.").Base(err)
|
|
|
}
|
|
|
|
|
|
stream, err := account.Cipher.NewEncodingStream(account.Key, iv)
|
|
|
if err != nil {
|
|
|
- return nil, newError("Shadowsocks|TCP: Failed to create encoding stream.").Base(err)
|
|
|
+ return nil, newError("failed to create encoding stream.").Base(err).AtError()
|
|
|
}
|
|
|
|
|
|
return buf.NewWriter(crypto.NewCryptionWriter(stream, writer)), nil
|
|
|
@@ -242,7 +242,7 @@ func EncodeUDPPacket(request *protocol.RequestHeader, payload *buf.Buffer) (*buf
|
|
|
user := request.User
|
|
|
rawAccount, err := user.GetTypedAccount()
|
|
|
if err != nil {
|
|
|
- return nil, newError("Shadowsocks|UDP: Failed to parse account.").Base(err)
|
|
|
+ return nil, newError("failed to parse account.").Base(err).AtError()
|
|
|
}
|
|
|
account := rawAccount.(*ShadowsocksAccount)
|
|
|
|
|
|
@@ -262,7 +262,7 @@ func EncodeUDPPacket(request *protocol.RequestHeader, payload *buf.Buffer) (*buf
|
|
|
buffer.AppendBytes(AddrTypeDomain, byte(len(request.Address.Domain())))
|
|
|
buffer.Append([]byte(request.Address.Domain()))
|
|
|
default:
|
|
|
- return nil, newError("Shadowsocks|UDP: Unsupported address type: ", request.Address.Family())
|
|
|
+ return nil, newError("unsupported address type: ", request.Address.Family())
|
|
|
}
|
|
|
|
|
|
buffer.AppendSupplier(serial.WriteUint16(uint16(request.Port)))
|
|
|
@@ -277,7 +277,7 @@ func EncodeUDPPacket(request *protocol.RequestHeader, payload *buf.Buffer) (*buf
|
|
|
|
|
|
stream, err := account.Cipher.NewEncodingStream(account.Key, iv)
|
|
|
if err != nil {
|
|
|
- return nil, newError("Shadowsocks|TCP: Failed to create encoding stream.").Base(err)
|
|
|
+ return nil, newError("failed to create encoding stream").Base(err).AtError()
|
|
|
}
|
|
|
|
|
|
stream.XORKeyStream(buffer.BytesFrom(ivLen), buffer.BytesFrom(ivLen))
|
|
|
@@ -287,7 +287,7 @@ func EncodeUDPPacket(request *protocol.RequestHeader, payload *buf.Buffer) (*buf
|
|
|
func DecodeUDPPacket(user *protocol.User, payload *buf.Buffer) (*protocol.RequestHeader, *buf.Buffer, error) {
|
|
|
rawAccount, err := user.GetTypedAccount()
|
|
|
if err != nil {
|
|
|
- return nil, nil, newError("Shadowsocks|UDP: Failed to parse account.").Base(err)
|
|
|
+ return nil, nil, newError("failed to parse account").Base(err).AtError()
|
|
|
}
|
|
|
account := rawAccount.(*ShadowsocksAccount)
|
|
|
|
|
|
@@ -297,7 +297,7 @@ func DecodeUDPPacket(user *protocol.User, payload *buf.Buffer) (*protocol.Reques
|
|
|
|
|
|
stream, err := account.Cipher.NewDecodingStream(account.Key, iv)
|
|
|
if err != nil {
|
|
|
- return nil, nil, newError("Shadowsocks|UDP: Failed to initialize decoding stream.").Base(err)
|
|
|
+ return nil, nil, newError("failed to initialize decoding stream").Base(err).AtError()
|
|
|
}
|
|
|
stream.XORKeyStream(payload.Bytes(), payload.Bytes())
|
|
|
|
|
|
@@ -314,11 +314,11 @@ func DecodeUDPPacket(user *protocol.User, payload *buf.Buffer) (*protocol.Reques
|
|
|
}
|
|
|
|
|
|
if request.Option.Has(RequestOptionOneTimeAuth) && account.OneTimeAuth == Account_Disabled {
|
|
|
- return nil, nil, newError("Shadowsocks|UDP: Rejecting packet with OTA enabled, while server disables OTA.")
|
|
|
+ return nil, nil, newError("rejecting packet with OTA enabled, while server disables OTA")
|
|
|
}
|
|
|
|
|
|
if !request.Option.Has(RequestOptionOneTimeAuth) && account.OneTimeAuth == Account_Enabled {
|
|
|
- return nil, nil, newError("Shadowsocks|UDP: Rejecting packet with OTA disabled, while server enables OTA.")
|
|
|
+ return nil, nil, newError("rejecting packet with OTA disabled, while server enables OTA")
|
|
|
}
|
|
|
|
|
|
if request.Option.Has(RequestOptionOneTimeAuth) {
|
|
|
@@ -328,7 +328,7 @@ func DecodeUDPPacket(user *protocol.User, payload *buf.Buffer) (*protocol.Reques
|
|
|
actualAuth := make([]byte, AuthSize)
|
|
|
authenticator.Authenticate(payload.BytesTo(payloadLen))(actualAuth)
|
|
|
if !bytes.Equal(actualAuth, authBytes) {
|
|
|
- return nil, nil, newError("Shadowsocks|UDP: Invalid OTA.")
|
|
|
+ return nil, nil, newError("invalid OTA")
|
|
|
}
|
|
|
|
|
|
payload.Slice(0, payloadLen)
|
|
|
@@ -348,7 +348,7 @@ func DecodeUDPPacket(user *protocol.User, payload *buf.Buffer) (*protocol.Reques
|
|
|
request.Address = v2net.DomainAddress(string(payload.BytesRange(1, 1+domainLength)))
|
|
|
payload.SliceFrom(1 + domainLength)
|
|
|
default:
|
|
|
- return nil, nil, newError("Shadowsocks|UDP: Unknown address type: ", addrType)
|
|
|
+ return nil, nil, newError("unknown address type: ", addrType)
|
|
|
}
|
|
|
|
|
|
request.Port = v2net.PortFromBytes(payload.BytesTo(2))
|