format errors

pull/314/head
Darien Raymond 2016-12-04 09:43:33 +01:00
parent efb24a4d21
commit e46bad3f18
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
12 changed files with 61 additions and 62 deletions

View File

@ -105,7 +105,7 @@ func ReadTCPSession(user *protocol.User, reader io.Reader) (*protocol.RequestHea
_, err = io.ReadFull(reader, buffer.Value[lenBuffer:lenBuffer+2]) _, err = io.ReadFull(reader, buffer.Value[lenBuffer:lenBuffer+2])
if err != nil { if err != nil {
return nil, nil, errors.New("Shadowsocks|TCP: Failed to read port: " + err.Error()) return nil, nil, errors.Base(err).Message("Shadowsocks|TCP: Failed to read port.")
} }
request.Port = v2net.PortFromBytes(buffer.Value[lenBuffer : lenBuffer+2]) request.Port = v2net.PortFromBytes(buffer.Value[lenBuffer : lenBuffer+2])
@ -115,7 +115,7 @@ func ReadTCPSession(user *protocol.User, reader io.Reader) (*protocol.RequestHea
authBytes := buffer.Value[lenBuffer : lenBuffer+AuthSize] authBytes := buffer.Value[lenBuffer : lenBuffer+AuthSize]
_, err = io.ReadFull(reader, authBytes) _, err = io.ReadFull(reader, authBytes)
if err != nil { if err != nil {
return nil, nil, errors.New("Shadowsocks|TCP: Failed to read OTA: " + err.Error()) return nil, nil, errors.Base(err).Message("Shadowsocks|TCP: Failed to read OTA.")
} }
actualAuth := authenticator.Authenticate(nil, buffer.Value[0:lenBuffer]) actualAuth := authenticator.Authenticate(nil, buffer.Value[0:lenBuffer])
@ -199,19 +199,19 @@ func WriteTCPRequest(request *protocol.RequestHeader, writer io.Writer) (v2io.Wr
func ReadTCPResponse(user *protocol.User, reader io.Reader) (v2io.Reader, error) { func ReadTCPResponse(user *protocol.User, reader io.Reader) (v2io.Reader, error) {
rawAccount, err := user.GetTypedAccount() rawAccount, err := user.GetTypedAccount()
if err != nil { if err != nil {
return nil, errors.New("Shadowsocks|TCP: Failed to parse account: " + err.Error()) return nil, errors.Base(err).Message("Shadowsocks|TCP: Failed to parse account.")
} }
account := rawAccount.(*ShadowsocksAccount) account := rawAccount.(*ShadowsocksAccount)
iv := make([]byte, account.Cipher.IVSize()) iv := make([]byte, account.Cipher.IVSize())
_, err = io.ReadFull(reader, iv) _, err = io.ReadFull(reader, iv)
if err != nil { if err != nil {
return nil, errors.New("Shadowsocks|TCP: Failed to read IV: " + err.Error()) return nil, errors.Base(err).Message("Shadowsocks|TCP: Failed to read IV.")
} }
stream, err := account.Cipher.NewDecodingStream(account.Key, iv) stream, err := account.Cipher.NewDecodingStream(account.Key, iv)
if err != nil { if err != nil {
return nil, errors.New("Shadowsocks|TCP: Failed to initialize decoding stream: " + err.Error()) return nil, errors.Base(err).Message("Shadowsocks|TCP: Failed to initialize decoding stream.")
} }
return v2io.NewAdaptiveReader(crypto.NewCryptionReader(stream, reader)), nil return v2io.NewAdaptiveReader(crypto.NewCryptionReader(stream, reader)), nil
} }
@ -220,7 +220,7 @@ func WriteTCPResponse(request *protocol.RequestHeader, writer io.Writer) (v2io.W
user := request.User user := request.User
rawAccount, err := user.GetTypedAccount() rawAccount, err := user.GetTypedAccount()
if err != nil { if err != nil {
return nil, errors.New("Shadowsocks|TCP: Failed to parse account: " + err.Error()) return nil, errors.Base(err).Message("Shadowsocks|TCP: Failed to parse account.")
} }
account := rawAccount.(*ShadowsocksAccount) account := rawAccount.(*ShadowsocksAccount)
@ -228,12 +228,12 @@ func WriteTCPResponse(request *protocol.RequestHeader, writer io.Writer) (v2io.W
rand.Read(iv) rand.Read(iv)
_, err = writer.Write(iv) _, err = writer.Write(iv)
if err != nil { if err != nil {
return nil, errors.New("Shadowsocks|TCP: Failed to write IV: " + err.Error()) return nil, errors.Base(err).Message("Shadowsocks|TCP: Failed to write IV.")
} }
stream, err := account.Cipher.NewEncodingStream(account.Key, iv) stream, err := account.Cipher.NewEncodingStream(account.Key, iv)
if err != nil { if err != nil {
return nil, errors.New("Shadowsocks|TCP: Failed to create encoding stream: " + err.Error()) return nil, errors.Base(err).Message("Shadowsocks|TCP: Failed to create encoding stream.")
} }
return v2io.NewAdaptiveWriter(crypto.NewCryptionWriter(stream, writer)), nil return v2io.NewAdaptiveWriter(crypto.NewCryptionWriter(stream, writer)), nil
@ -243,7 +243,7 @@ func EncodeUDPPacket(request *protocol.RequestHeader, payload *alloc.Buffer) (*a
user := request.User user := request.User
rawAccount, err := user.GetTypedAccount() rawAccount, err := user.GetTypedAccount()
if err != nil { if err != nil {
return nil, errors.New("Shadowsocks|UDP: Failed to parse account: " + err.Error()) return nil, errors.Base(err).Message("Shadowsocks|UDP: Failed to parse account.")
} }
account := rawAccount.(*ShadowsocksAccount) account := rawAccount.(*ShadowsocksAccount)
@ -264,7 +264,7 @@ func EncodeUDPPacket(request *protocol.RequestHeader, payload *alloc.Buffer) (*a
buffer.AppendBytes(AddrTypeDomain, byte(len(request.Address.Domain()))) buffer.AppendBytes(AddrTypeDomain, byte(len(request.Address.Domain())))
buffer.Append([]byte(request.Address.Domain())) buffer.Append([]byte(request.Address.Domain()))
default: default:
return nil, errors.New("Shadowsocks|UDP: Unsupported address type. ") return nil, errors.New("Shadowsocks|UDP: Unsupported address type: ", request.Address.Family())
} }
buffer.AppendUint16(uint16(request.Port)) buffer.AppendUint16(uint16(request.Port))
@ -279,7 +279,7 @@ func EncodeUDPPacket(request *protocol.RequestHeader, payload *alloc.Buffer) (*a
stream, err := account.Cipher.NewEncodingStream(account.Key, iv) stream, err := account.Cipher.NewEncodingStream(account.Key, iv)
if err != nil { if err != nil {
return nil, errors.New("Shadowsocks|TCP: Failed to create encoding stream: " + err.Error()) return nil, errors.Base(err).Message("Shadowsocks|TCP: Failed to create encoding stream.")
} }
stream.XORKeyStream(buffer.Value[ivLen:], buffer.Value[ivLen:]) stream.XORKeyStream(buffer.Value[ivLen:], buffer.Value[ivLen:])
@ -289,7 +289,7 @@ func EncodeUDPPacket(request *protocol.RequestHeader, payload *alloc.Buffer) (*a
func DecodeUDPPacket(user *protocol.User, payload *alloc.Buffer) (*protocol.RequestHeader, *alloc.Buffer, error) { func DecodeUDPPacket(user *protocol.User, payload *alloc.Buffer) (*protocol.RequestHeader, *alloc.Buffer, error) {
rawAccount, err := user.GetTypedAccount() rawAccount, err := user.GetTypedAccount()
if err != nil { if err != nil {
return nil, nil, errors.New("Shadowsocks|UDP: Failed to parse account: " + err.Error()) return nil, nil, errors.Base(err).Message("Shadowsocks|UDP: Failed to parse account.")
} }
account := rawAccount.(*ShadowsocksAccount) account := rawAccount.(*ShadowsocksAccount)
@ -299,7 +299,7 @@ func DecodeUDPPacket(user *protocol.User, payload *alloc.Buffer) (*protocol.Requ
stream, err := account.Cipher.NewDecodingStream(account.Key, iv) stream, err := account.Cipher.NewDecodingStream(account.Key, iv)
if err != nil { if err != nil {
return nil, nil, errors.New("Shadowsocks|UDP: Failed to initialize decoding stream: " + err.Error()) return nil, nil, errors.Base(err).Message("Shadowsocks|UDP: Failed to initialize decoding stream.")
} }
stream.XORKeyStream(payload.Value, payload.Value) stream.XORKeyStream(payload.Value, payload.Value)
@ -349,7 +349,7 @@ func DecodeUDPPacket(user *protocol.User, payload *alloc.Buffer) (*protocol.Requ
request.Address = v2net.DomainAddress(string(payload.Value[1 : 1+domainLength])) request.Address = v2net.DomainAddress(string(payload.Value[1 : 1+domainLength]))
payload.SliceFrom(1 + domainLength) payload.SliceFrom(1 + domainLength)
default: default:
return nil, nil, errors.New("Shadowsocks|UDP: Unknown address type") return nil, nil, errors.New("Shadowsocks|UDP: Unknown address type: ", addrType)
} }
request.Port = v2net.PortFromBytes(payload.Value[:2]) request.Port = v2net.PortFromBytes(payload.Value[:2])

View File

@ -36,7 +36,7 @@ func NewServer(config *ServerConfig, space app.Space, meta *proxy.InboundHandler
rawAccount, err := config.User.GetTypedAccount() rawAccount, err := config.User.GetTypedAccount()
if err != nil { if err != nil {
return nil, errors.New("Shadowsocks|Server: Failed to get user account: " + err.Error()) return nil, errors.Base(err).Message("Shadowsocks|Server: Failed to get user account.")
} }
account := rawAccount.(*ShadowsocksAccount) account := rawAccount.(*ShadowsocksAccount)

View File

@ -60,7 +60,7 @@ func (v *ServerSession) DecodeRequestHeader(reader io.Reader) (*protocol.Request
iv := timestampHash.Sum(nil) iv := timestampHash.Sum(nil)
account, err := user.GetTypedAccount() account, err := user.GetTypedAccount()
if err != nil { if err != nil {
return nil, errors.New("VMess|Server: Failed to get user account: " + err.Error()) return nil, errors.Base(err).Message("VMess|Server: Failed to get user account.")
} }
aesStream := crypto.NewAesDecryptionStream(account.(*vmess.InternalAccount).ID.CmdKey(), iv) aesStream := crypto.NewAesDecryptionStream(account.(*vmess.InternalAccount).ID.CmdKey(), iv)
@ -68,7 +68,7 @@ func (v *ServerSession) DecodeRequestHeader(reader io.Reader) (*protocol.Request
nBytes, err := io.ReadFull(decryptor, buffer[:41]) nBytes, err := io.ReadFull(decryptor, buffer[:41])
if err != nil { if err != nil {
return nil, errors.New("VMess|Server: Failed to read request header: " + err.Error()) return nil, errors.Base(err).Message("VMess|Server: Failed to read request header.")
} }
bufferLen := nBytes bufferLen := nBytes
@ -78,8 +78,7 @@ func (v *ServerSession) DecodeRequestHeader(reader io.Reader) (*protocol.Request
} }
if request.Version != Version { if request.Version != Version {
log.Info("VMess|Server: Invalid protocol version ", request.Version) return nil, errors.New("VMess|Server: Invalid protocol version ", request.Version)
return nil, protocol.ErrInvalidVersion
} }
v.requestBodyIV = append([]byte(nil), buffer[1:17]...) // 16 bytes v.requestBodyIV = append([]byte(nil), buffer[1:17]...) // 16 bytes
@ -95,28 +94,28 @@ func (v *ServerSession) DecodeRequestHeader(reader io.Reader) (*protocol.Request
_, err = io.ReadFull(decryptor, buffer[41:45]) // 4 bytes _, err = io.ReadFull(decryptor, buffer[41:45]) // 4 bytes
bufferLen += 4 bufferLen += 4
if err != nil { if err != nil {
return nil, errors.New("VMess|Server: Failed to read IPv4: " + err.Error()) return nil, errors.Base(err).Message("VMess|Server: Failed to read IPv4.")
} }
request.Address = v2net.IPAddress(buffer[41:45]) request.Address = v2net.IPAddress(buffer[41:45])
case AddrTypeIPv6: case AddrTypeIPv6:
_, err = io.ReadFull(decryptor, buffer[41:57]) // 16 bytes _, err = io.ReadFull(decryptor, buffer[41:57]) // 16 bytes
bufferLen += 16 bufferLen += 16
if err != nil { if err != nil {
return nil, errors.New("VMess|Server: Failed to read IPv6 address: " + err.Error()) return nil, errors.Base(err).Message("VMess|Server: Failed to read IPv6 address.")
} }
request.Address = v2net.IPAddress(buffer[41:57]) request.Address = v2net.IPAddress(buffer[41:57])
case AddrTypeDomain: case AddrTypeDomain:
_, err = io.ReadFull(decryptor, buffer[41:42]) _, err = io.ReadFull(decryptor, buffer[41:42])
if err != nil { if err != nil {
return nil, errors.New("VMess:Server: Failed to read domain: " + err.Error()) return nil, errors.Base(err).Message("VMess:Server: Failed to read domain.")
} }
domainLength := int(buffer[41]) domainLength := int(buffer[41])
if domainLength == 0 { if domainLength == 0 {
return nil, errors.New("VMess|Server: Zero domain length.") return nil, errors.New("VMess|Server: Zero length domain.")
} }
_, err = io.ReadFull(decryptor, buffer[42:42+domainLength]) _, err = io.ReadFull(decryptor, buffer[42:42+domainLength])
if err != nil { if err != nil {
return nil, errors.New("VMess|Server: Failed to read domain: " + err.Error()) return nil, errors.Base(err).Message("VMess|Server: Failed to read domain.")
} }
bufferLen += 1 + domainLength bufferLen += 1 + domainLength
request.Address = v2net.DomainAddress(string(buffer[42 : 42+domainLength])) request.Address = v2net.DomainAddress(string(buffer[42 : 42+domainLength]))
@ -124,7 +123,7 @@ func (v *ServerSession) DecodeRequestHeader(reader io.Reader) (*protocol.Request
_, err = io.ReadFull(decryptor, buffer[bufferLen:bufferLen+4]) _, err = io.ReadFull(decryptor, buffer[bufferLen:bufferLen+4])
if err != nil { if err != nil {
return nil, errors.New("VMess|Server: Failed to read checksum: " + err.Error()) return nil, errors.Base(err).Message("VMess|Server: Failed to read checksum.")
} }
fnv1a := fnv.New32a() fnv1a := fnv.New32a()

View File

@ -28,7 +28,7 @@ func (v *BlackholeConfig) Build() (*loader.TypedSettings, error) {
if v.Response != nil { if v.Response != nil {
response, _, err := configLoader.Load(v.Response) response, _, err := configLoader.Load(v.Response)
if err != nil { if err != nil {
return nil, errors.New("Blackhole: Failed to parse response config: " + err.Error()) return nil, errors.Base(err).Message("Blackhole: Failed to parse response config.")
} }
responseSettings, err := response.(Buildable).Build() responseSettings, err := response.(Buildable).Build()
if err != nil { if err != nil {

View File

@ -79,11 +79,11 @@ func (v *SocksClientConfig) Build() (*loader.TypedSettings, error) {
for _, rawUser := range serverConfig.Users { for _, rawUser := range serverConfig.Users {
user := new(protocol.User) user := new(protocol.User)
if err := json.Unmarshal(rawUser, user); err != nil { if err := json.Unmarshal(rawUser, user); err != nil {
return nil, errors.New("Socks|Client: Failed to parse user: " + err.Error()) return nil, errors.Base(err).Message("Socks|Client: Failed to parse user.")
} }
account := new(SocksAccount) account := new(SocksAccount)
if err := json.Unmarshal(rawUser, account); err != nil { if err := json.Unmarshal(rawUser, account); err != nil {
return nil, errors.New("Socks|Client: Failed to parse socks account: " + err.Error()) return nil, errors.Base(err).Message("Socks|Client: Failed to parse socks account.")
} }
user.Account = loader.NewTypedSettings(account.Build()) user.Account = loader.NewTypedSettings(account.Build())
server.User = append(server.User, user) server.User = append(server.User, user)

View File

@ -19,7 +19,7 @@ func (v *TransportConfig) Build() (*transport.Config, error) {
if v.TCPConfig != nil { if v.TCPConfig != nil {
ts, err := v.TCPConfig.Build() ts, err := v.TCPConfig.Build()
if err != nil { if err != nil {
return nil, errors.New("Failed to build TCP config: " + err.Error()) return nil, errors.Base(err).Message("Failed to build TCP config.")
} }
config.NetworkSettings = append(config.NetworkSettings, &internet.NetworkSettings{ config.NetworkSettings = append(config.NetworkSettings, &internet.NetworkSettings{
Network: v2net.Network_TCP, Network: v2net.Network_TCP,
@ -30,7 +30,7 @@ func (v *TransportConfig) Build() (*transport.Config, error) {
if v.KCPConfig != nil { if v.KCPConfig != nil {
ts, err := v.KCPConfig.Build() ts, err := v.KCPConfig.Build()
if err != nil { if err != nil {
return nil, errors.New("Failed to build KCP config: " + err.Error()) return nil, errors.Base(err).Message("Failed to build mKCP config.")
} }
config.NetworkSettings = append(config.NetworkSettings, &internet.NetworkSettings{ config.NetworkSettings = append(config.NetworkSettings, &internet.NetworkSettings{
Network: v2net.Network_KCP, Network: v2net.Network_KCP,
@ -41,7 +41,7 @@ func (v *TransportConfig) Build() (*transport.Config, error) {
if v.WSConfig != nil { if v.WSConfig != nil {
ts, err := v.WSConfig.Build() ts, err := v.WSConfig.Build()
if err != nil { if err != nil {
return nil, errors.New("Failed to build WebSocket config: " + err.Error()) return nil, errors.Base(err).Message("Failed to build WebSocket config.")
} }
config.NetworkSettings = append(config.NetworkSettings, &internet.NetworkSettings{ config.NetworkSettings = append(config.NetworkSettings, &internet.NetworkSettings{
Network: v2net.Network_WebSocket, Network: v2net.Network_WebSocket,

View File

@ -84,11 +84,11 @@ func (v *KCPConfig) Build() (*loader.TypedSettings, error) {
if len(v.HeaderConfig) > 0 { if len(v.HeaderConfig) > 0 {
headerConfig, _, err := kcpHeaderLoader.Load(v.HeaderConfig) headerConfig, _, err := kcpHeaderLoader.Load(v.HeaderConfig)
if err != nil { if err != nil {
return nil, errors.New("KCP|Config: Failed to parse header config: " + err.Error()) return nil, errors.Base(err).Message("Invalid mKCP header config.")
} }
ts, err := headerConfig.(Buildable).Build() ts, err := headerConfig.(Buildable).Build()
if err != nil { if err != nil {
return nil, errors.New("Failed to get KCP authenticator config: " + err.Error()) return nil, errors.Base(err).Message("Invalid mKCP header config.")
} }
config.HeaderConfig = ts config.HeaderConfig = ts
} }
@ -111,11 +111,11 @@ func (v *TCPConfig) Build() (*loader.TypedSettings, error) {
if len(v.HeaderConfig) > 0 { if len(v.HeaderConfig) > 0 {
headerConfig, _, err := tcpHeaderLoader.Load(v.HeaderConfig) headerConfig, _, err := tcpHeaderLoader.Load(v.HeaderConfig)
if err != nil { if err != nil {
return nil, errors.New("TCP|Config: Failed to parse header config: " + err.Error()) return nil, errors.Base(err).Message("Invalid TCP header config.")
} }
ts, err := headerConfig.(Buildable).Build() ts, err := headerConfig.(Buildable).Build()
if err != nil { if err != nil {
return nil, errors.New("Failed to get TCP authenticator config: " + err.Error()) return nil, errors.Base(err).Message("Invalid TCP header config.")
} }
config.HeaderSettings = ts config.HeaderSettings = ts
} }
@ -155,11 +155,11 @@ func (v *TLSConfig) Build() (*loader.TypedSettings, error) {
for idx, certConf := range v.Certs { for idx, certConf := range v.Certs {
cert, err := ioutil.ReadFile(certConf.CertFile) cert, err := ioutil.ReadFile(certConf.CertFile)
if err != nil { if err != nil {
return nil, errors.New("TLS: Failed to load certificate file: " + err.Error()) return nil, errors.Base(err).Message("Failed to load TLS certificate file: ", certConf.CertFile)
} }
key, err := ioutil.ReadFile(certConf.KeyFile) key, err := ioutil.ReadFile(certConf.KeyFile)
if err != nil { if err != nil {
return nil, errors.New("TLS: Failed to load key file: " + err.Error()) return nil, errors.Base(err).Message("Failed to load TLS key file: ", certConf.KeyFile)
} }
config.Certificate[idx] = &tls.Certificate{ config.Certificate[idx] = &tls.Certificate{
Key: key, Key: key,
@ -193,14 +193,14 @@ func (v *StreamConfig) Build() (*internet.StreamConfig, error) {
} }
ts, err := tlsSettings.Build() ts, err := tlsSettings.Build()
if err != nil { if err != nil {
return nil, errors.New("Failed to build TLS config: " + err.Error()) return nil, errors.Base(err).Message("Failed to build TLS config.")
} }
config.SecuritySettings = append(config.SecuritySettings, ts) config.SecuritySettings = append(config.SecuritySettings, ts)
} }
if v.TCPSettings != nil { if v.TCPSettings != nil {
ts, err := v.TCPSettings.Build() ts, err := v.TCPSettings.Build()
if err != nil { if err != nil {
return nil, errors.New("Failed to build TCP config: " + err.Error()) return nil, errors.Base(err).Message("Failed to build TCP config.")
} }
config.NetworkSettings = append(config.NetworkSettings, &internet.NetworkSettings{ config.NetworkSettings = append(config.NetworkSettings, &internet.NetworkSettings{
Network: v2net.Network_TCP, Network: v2net.Network_TCP,
@ -210,7 +210,7 @@ func (v *StreamConfig) Build() (*internet.StreamConfig, error) {
if v.KCPSettings != nil { if v.KCPSettings != nil {
ts, err := v.KCPSettings.Build() ts, err := v.KCPSettings.Build()
if err != nil { if err != nil {
return nil, errors.New("Failed to build KCP config: " + err.Error()) return nil, errors.Base(err).Message("Failed to build mKCP config.")
} }
config.NetworkSettings = append(config.NetworkSettings, &internet.NetworkSettings{ config.NetworkSettings = append(config.NetworkSettings, &internet.NetworkSettings{
Network: v2net.Network_KCP, Network: v2net.Network_KCP,
@ -220,7 +220,7 @@ func (v *StreamConfig) Build() (*internet.StreamConfig, error) {
if v.WSSettings != nil { if v.WSSettings != nil {
ts, err := v.WSSettings.Build() ts, err := v.WSSettings.Build()
if err != nil { if err != nil {
return nil, errors.New("Failed to build WebSocket config: " + err.Error()) return nil, errors.Base(err).Message("Failed to build WebSocket config.")
} }
config.NetworkSettings = append(config.NetworkSettings, &internet.NetworkSettings{ config.NetworkSettings = append(config.NetworkSettings, &internet.NetworkSettings{
Network: v2net.Network_WebSocket, Network: v2net.Network_WebSocket,

View File

@ -60,7 +60,7 @@ func (v *InboundConnectionConfig) Build() (*core.InboundConnectionConfig, error)
jsonConfig, err := inboundConfigLoader.LoadWithID(v.Settings, v.Protocol) jsonConfig, err := inboundConfigLoader.LoadWithID(v.Settings, v.Protocol)
if err != nil { if err != nil {
return nil, errors.New("Failed to load inbound config: " + err.Error()) return nil, errors.Base(err).Message("Failed to load inbound config.")
} }
ts, err := jsonConfig.(Buildable).Build() ts, err := jsonConfig.(Buildable).Build()
if err != nil { if err != nil {
@ -86,7 +86,7 @@ func (v *OutboundConnectionConfig) Build() (*core.OutboundConnectionConfig, erro
config := new(core.OutboundConnectionConfig) config := new(core.OutboundConnectionConfig)
rawConfig, err := outboundConfigLoader.LoadWithID(v.Settings, v.Protocol) rawConfig, err := outboundConfigLoader.LoadWithID(v.Settings, v.Protocol)
if err != nil { if err != nil {
return nil, errors.New("Failed to parse outbound config: " + err.Error()) return nil, errors.Base(err).Message("Failed to parse outbound config.")
} }
ts, err := rawConfig.(Buildable).Build() ts, err := rawConfig.(Buildable).Build()
if err != nil { if err != nil {
@ -97,7 +97,7 @@ func (v *OutboundConnectionConfig) Build() (*core.OutboundConnectionConfig, erro
if v.SendThrough != nil { if v.SendThrough != nil {
address := v.SendThrough address := v.SendThrough
if address.Family().IsDomain() { if address.Family().IsDomain() {
return nil, errors.New("Point: Unable to send through: " + address.String()) return nil, errors.New("Invalid sendThrough address: " + address.String())
} }
config.SendThrough = address.Build() config.SendThrough = address.Build()
} }
@ -111,7 +111,7 @@ func (v *OutboundConnectionConfig) Build() (*core.OutboundConnectionConfig, erro
if v.ProxySettings != nil { if v.ProxySettings != nil {
ps, err := v.ProxySettings.Build() ps, err := v.ProxySettings.Build()
if err != nil { if err != nil {
return nil, errors.New("Outbound: invalid proxy settings: " + err.Error()) return nil, errors.Base(err).Message("Invalid outbound proxy settings.")
} }
config.ProxySettings = ps config.ProxySettings = ps
} }
@ -137,7 +137,7 @@ func (v *InboundDetourAllocationConfig) Build() (*core.AllocationStrategy, error
case "external": case "external":
config.Type = core.AllocationStrategy_External config.Type = core.AllocationStrategy_External
default: default:
return nil, errors.New("Unknown allocation strategy: " + v.Strategy) return nil, errors.New("Unknown allocation strategy: ", v.Strategy)
} }
if v.Concurrency != nil { if v.Concurrency != nil {
config.Concurrency = &core.AllocationStrategyConcurrency{ config.Concurrency = &core.AllocationStrategyConcurrency{
@ -168,13 +168,13 @@ type InboundDetourConfig struct {
func (v *InboundDetourConfig) Build() (*core.InboundConnectionConfig, error) { func (v *InboundDetourConfig) Build() (*core.InboundConnectionConfig, error) {
config := new(core.InboundConnectionConfig) config := new(core.InboundConnectionConfig)
if v.PortRange == nil { if v.PortRange == nil {
return nil, errors.New("Point: Port range not specified in InboundDetour.") return nil, errors.New("Port range not specified in InboundDetour.")
} }
config.PortRange = v.PortRange.Build() config.PortRange = v.PortRange.Build()
if v.ListenOn != nil { if v.ListenOn != nil {
if v.ListenOn.Family().IsDomain() { if v.ListenOn.Family().IsDomain() {
return nil, errors.New("Point: Unable to listen on domain address: " + v.ListenOn.Domain()) return nil, errors.New("Unable to listen on domain address: ", v.ListenOn.Domain())
} }
config.ListenOn = v.ListenOn.Build() config.ListenOn = v.ListenOn.Build()
} }
@ -197,7 +197,7 @@ func (v *InboundDetourConfig) Build() (*core.InboundConnectionConfig, error) {
rawConfig, err := inboundConfigLoader.LoadWithID(v.Settings, v.Protocol) rawConfig, err := inboundConfigLoader.LoadWithID(v.Settings, v.Protocol)
if err != nil { if err != nil {
return nil, errors.New("Failed to load inbound detour config: " + err.Error()) return nil, errors.Base(err).Message("Failed to load inbound detour config.")
} }
ts, err := rawConfig.(Buildable).Build() ts, err := rawConfig.(Buildable).Build()
if err != nil { if err != nil {
@ -238,7 +238,7 @@ func (v *OutboundDetourConfig) Build() (*core.OutboundConnectionConfig, error) {
rawConfig, err := outboundConfigLoader.LoadWithID(v.Settings, v.Protocol) rawConfig, err := outboundConfigLoader.LoadWithID(v.Settings, v.Protocol)
if err != nil { if err != nil {
return nil, errors.New("Failed to parse to outbound detour config: " + err.Error()) return nil, errors.Base(err).Message("Failed to parse to outbound detour config.")
} }
ts, err := rawConfig.(Buildable).Build() ts, err := rawConfig.(Buildable).Build()
if err != nil { if err != nil {
@ -248,7 +248,7 @@ func (v *OutboundDetourConfig) Build() (*core.OutboundConnectionConfig, error) {
if v.ProxySettings != nil { if v.ProxySettings != nil {
ps, err := v.ProxySettings.Build() ps, err := v.ProxySettings.Build()
if err != nil { if err != nil {
return nil, errors.New("OutboundDetour: invalid proxy settings: " + err.Error()) return nil, errors.Base(err).Message("Invalid outbound detour proxy settings.")
} }
config.ProxySettings = ps config.ProxySettings = ps
} }
@ -340,7 +340,7 @@ func init() {
decoder := json.NewDecoder(input) decoder := json.NewDecoder(input)
err := decoder.Decode(jsonConfig) err := decoder.Decode(jsonConfig)
if err != nil { if err != nil {
return nil, errors.New("Point: Failed to load server config: " + err.Error()) return nil, errors.Base(err).Message("Invalid V2Ray config.")
} }
return jsonConfig.Build() return jsonConfig.Build()

View File

@ -77,11 +77,11 @@ func (v *VMessInboundConfig) Build() (*loader.TypedSettings, error) {
for idx, rawData := range v.Users { for idx, rawData := range v.Users {
user := new(protocol.User) user := new(protocol.User)
if err := json.Unmarshal(rawData, user); err != nil { if err := json.Unmarshal(rawData, user); err != nil {
return nil, errors.New("VMess|Inbound: Invalid user: " + err.Error()) return nil, errors.Base(err).Message("Invalid VMess user.")
} }
account := new(VMessAccount) account := new(VMessAccount)
if err := json.Unmarshal(rawData, account); err != nil { if err := json.Unmarshal(rawData, account); err != nil {
return nil, errors.New("VMess|Inbound: Invalid user: " + err.Error()) return nil, errors.Base(err).Message("Invalid VMess user.")
} }
user.Account = loader.NewTypedSettings(account.Build()) user.Account = loader.NewTypedSettings(account.Build())
config.User[idx] = user config.User[idx] = user
@ -123,11 +123,11 @@ func (v *VMessOutboundConfig) Build() (*loader.TypedSettings, error) {
for _, rawUser := range rec.Users { for _, rawUser := range rec.Users {
user := new(protocol.User) user := new(protocol.User)
if err := json.Unmarshal(rawUser, user); err != nil { if err := json.Unmarshal(rawUser, user); err != nil {
return nil, errors.New("VMess|Outbound: Invalid user: " + err.Error()) return nil, errors.Base(err).Message("Invalid VMess user.")
} }
account := new(VMessAccount) account := new(VMessAccount)
if err := json.Unmarshal(rawUser, account); err != nil { if err := json.Unmarshal(rawUser, account); err != nil {
return nil, errors.New("VMess|Outbound: Invalid user: " + err.Error()) return nil, errors.Base(err).Message("Invalid VMess user.")
} }
user.Account = loader.NewTypedSettings(account.Build()) user.Account = loader.NewTypedSettings(account.Build())
spec.User = append(spec.User, user) spec.User = append(spec.User, user)

View File

@ -55,11 +55,11 @@ func Dial(src v2net.Address, dest v2net.Destination, options internet.DialerOpti
if tcpSettings.HeaderSettings != nil { if tcpSettings.HeaderSettings != nil {
headerConfig, err := tcpSettings.HeaderSettings.GetInstance() headerConfig, err := tcpSettings.HeaderSettings.GetInstance()
if err != nil { if err != nil {
return nil, errors.New("TCP: Failed to get header settings: " + err.Error()) return nil, errors.Base(err).Message("Interent|TCP: Failed to get header settings.")
} }
auth, err := internet.CreateConnectionAuthenticator(tcpSettings.HeaderSettings.Type, headerConfig) auth, err := internet.CreateConnectionAuthenticator(tcpSettings.HeaderSettings.Type, headerConfig)
if err != nil { if err != nil {
return nil, errors.New("TCP: Failed to create header authenticator: " + err.Error()) return nil, errors.Base(err).Message("Internet|TCP: Failed to create header authenticator.")
} }
conn = auth.Client(conn) conn = auth.Client(conn)
} }

View File

@ -66,11 +66,11 @@ func ListenTCP(address v2net.Address, port v2net.Port, options internet.ListenOp
if tcpSettings.HeaderSettings != nil { if tcpSettings.HeaderSettings != nil {
headerConfig, err := tcpSettings.HeaderSettings.GetInstance() headerConfig, err := tcpSettings.HeaderSettings.GetInstance()
if err != nil { if err != nil {
return nil, errors.New("TCP: Failed to get header settings: " + err.Error()) return nil, errors.Base(err).Message("Internet|TCP: Invalid header settings.")
} }
auth, err := internet.CreateConnectionAuthenticator(tcpSettings.HeaderSettings.Type, headerConfig) auth, err := internet.CreateConnectionAuthenticator(tcpSettings.HeaderSettings.Type, headerConfig)
if err != nil { if err != nil {
return nil, errors.New("TCP: Failed to create header authenticator: " + err.Error()) return nil, errors.Base(err).Message("Internet|TCP: Invalid header settings.")
} }
l.authConfig = auth l.authConfig = auth
} }

View File

@ -42,7 +42,7 @@ func (ws *wsconn) read(b []byte) (n int, err error) {
func (ws *wsconn) getNewReadBuffer() error { func (ws *wsconn) getNewReadBuffer() error {
_, r, err := ws.wsc.NextReader() _, r, err := ws.wsc.NextReader()
if err != nil { if err != nil {
log.Warning("WS transport: ws connection NewFrameReader return " + err.Error()) log.Warning("WS transport: ws connection NewFrameReader return ", err)
ws.connClosing = true ws.connClosing = true
ws.Close() ws.Close()
return err return err
@ -90,7 +90,7 @@ func (ws *wsconn) Write(b []byte) (n int, err error) {
func (ws *wsconn) write(b []byte) (n int, err error) { func (ws *wsconn) write(b []byte) (n int, err error) {
wr, err := ws.wsc.NextWriter(websocket.BinaryMessage) wr, err := ws.wsc.NextWriter(websocket.BinaryMessage)
if err != nil { if err != nil {
log.Warning("WS transport: ws connection NewFrameReader return " + err.Error()) log.Warning("WS transport: ws connection NewFrameReader return ", err)
ws.connClosing = true ws.connClosing = true
ws.Close() ws.Close()
return 0, err return 0, err