update error messages

pull/432/head
Darien Raymond 2017-04-06 22:00:32 +02:00
parent 67956b9120
commit b4cd497abf
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
10 changed files with 50 additions and 50 deletions

View File

@ -238,7 +238,7 @@ func (w *udpWorker) callback(b *buf.Buffer, source v2net.Destination, originalDe
ctx = proxy.ContextWithSource(ctx, source) ctx = proxy.ContextWithSource(ctx, source)
ctx = proxy.ContextWithInboundEntryPoint(ctx, v2net.UDPDestination(w.address, w.port)) ctx = proxy.ContextWithInboundEntryPoint(ctx, v2net.UDPDestination(w.address, w.port))
if err := w.proxy.Process(ctx, v2net.Network_UDP, conn, w.dispatcher); err != nil { if err := w.proxy.Process(ctx, v2net.Network_UDP, conn, w.dispatcher); err != nil {
log.Trace(errors.New("connection ends").Base(err).Path("Proxymann|UDPWorker")) log.Trace(errors.New("connection ends").Base(err).Path("App", "Proxymann", "Inbound", "UDPWorker"))
} }
w.removeConn(source) w.removeConn(source)
cancel() cancel()

View File

@ -30,7 +30,7 @@ func (r *Reader) ReadMetadata() (*FrameMetadata, error) {
} }
metaLen := serial.BytesToUint16(b.Bytes()) metaLen := serial.BytesToUint16(b.Bytes())
if metaLen > 512 { if metaLen > 512 {
return nil, errors.New("Proxyman|Mux|Reader: Invalid metalen ", metaLen) return nil, errors.New("invalid metalen ", metaLen).Path("App", "Proxyman", "Mux", "Reader")
} }
b.Clear() b.Clear()
if err := b.AppendSupplier(buf.ReadFullFrom(r.reader, int(metaLen))); err != nil { if err := b.AppendSupplier(buf.ReadFullFrom(r.reader, int(metaLen))); err != nil {

View File

@ -32,12 +32,12 @@ func NewHandler(ctx context.Context, config *proxyman.OutboundHandlerConfig) (*H
} }
space := app.SpaceFromContext(ctx) space := app.SpaceFromContext(ctx)
if space == nil { if space == nil {
return nil, errors.New("Proxyman|OutboundHandler: No space in context.") return nil, errors.New("no space in context").Path("App", "Proxyman", "Outbound", "Handler")
} }
space.OnInitialize(func() error { space.OnInitialize(func() error {
ohm := proxyman.OutboundHandlerManagerFromSpace(space) ohm := proxyman.OutboundHandlerManagerFromSpace(space)
if ohm == nil { if ohm == nil {
return errors.New("Proxyman|OutboundHandler: No OutboundManager in space.") return errors.New("no OutboundManager in space").Path("App", "Proxyman", "Outbound", "Handler")
} }
h.outboundManager = ohm h.outboundManager = ohm
return nil return nil
@ -52,7 +52,7 @@ func NewHandler(ctx context.Context, config *proxyman.OutboundHandlerConfig) (*H
case *proxyman.SenderConfig: case *proxyman.SenderConfig:
h.senderSettings = s h.senderSettings = s
default: default:
return nil, errors.New("Proxyman|DefaultOutboundHandler: settings is not SenderConfig.") return nil, errors.New("settings is not SenderConfig").Path("App", "Proxyman", "Outbound", "Handler")
} }
} }
@ -73,13 +73,13 @@ func (h *Handler) Dispatch(ctx context.Context, outboundRay ray.OutboundRay) {
if h.mux != nil { if h.mux != nil {
err := h.mux.Dispatch(ctx, outboundRay) err := h.mux.Dispatch(ctx, outboundRay)
if err != nil { if err != nil {
log.Trace(errors.New("failed to process outbound traffic").Base(err).Path("Proxyman", "OutboundHandler")) log.Trace(errors.New("failed to process outbound traffic").Base(err).Path("App", "Proxyman", "Outbound", "Handler"))
} }
} else { } else {
err := h.proxy.Process(ctx, outboundRay, h) err := h.proxy.Process(ctx, outboundRay, h)
// Ensure outbound ray is properly closed. // Ensure outbound ray is properly closed.
if err != nil && errors.Cause(err) != io.EOF { if err != nil && errors.Cause(err) != io.EOF {
log.Trace(errors.New("failed to process outbound traffic").Base(err).Path("Proxyman", "OutboundHandler")) log.Trace(errors.New("failed to process outbound traffic").Base(err).Path("App", "Proxyman", "Outbound", "Handler"))
outboundRay.OutboundOutput().CloseError() outboundRay.OutboundOutput().CloseError()
} else { } else {
outboundRay.OutboundOutput().Close() outboundRay.OutboundOutput().Close()
@ -95,14 +95,14 @@ func (h *Handler) Dial(ctx context.Context, dest v2net.Destination) (internet.Co
tag := h.senderSettings.ProxySettings.Tag tag := h.senderSettings.ProxySettings.Tag
handler := h.outboundManager.GetHandler(tag) handler := h.outboundManager.GetHandler(tag)
if handler != nil { if handler != nil {
log.Trace(errors.New("proxying to ", tag).AtDebug().Path("App", "Proxyman", "OutboundHandler")) log.Trace(errors.New("proxying to ", tag).AtDebug().Path("App", "Proxyman", "Outbound", "Handler"))
ctx = proxy.ContextWithTarget(ctx, dest) ctx = proxy.ContextWithTarget(ctx, dest)
stream := ray.NewRay(ctx) stream := ray.NewRay(ctx)
go handler.Dispatch(ctx, stream) go handler.Dispatch(ctx, stream)
return NewConnection(stream), nil return NewConnection(stream), nil
} }
log.Trace(errors.New("Proxyman|OutboundHandler: Failed to get outbound handler with tag: ", tag).AtWarning()) log.Trace(errors.New("failed to get outbound handler with tag: ", tag).AtWarning().Path("App", "Proxyman", "Outbound", "Handler"))
} }
if h.senderSettings.Via != nil { if h.senderSettings.Via != nil {

View File

@ -97,7 +97,7 @@ func (v *ChunkReader) Read() (*buf.Buffer, error) {
v.auth.Authenticate(payload)(actualAuthBytes) v.auth.Authenticate(payload)(actualAuthBytes)
if !bytes.Equal(authBytes, actualAuthBytes) { if !bytes.Equal(authBytes, actualAuthBytes) {
buffer.Release() buffer.Release()
return nil, errors.New("Shadowsocks|AuthenticationReader: Invalid auth.") return nil, errors.New("invalid auth").Path("Proxy", "Shadowsocks", "ChunkReader")
} }
buffer.SliceFrom(AuthSize) buffer.SliceFrom(AuthSize)

View File

@ -36,7 +36,7 @@ func NewClient(ctx context.Context, config *ClientConfig) (*Client, error) {
func (c *Client) Process(ctx context.Context, ray ray.OutboundRay, dialer proxy.Dialer) error { func (c *Client) Process(ctx context.Context, ray ray.OutboundRay, dialer proxy.Dialer) error {
destination, ok := proxy.TargetFromContext(ctx) destination, ok := proxy.TargetFromContext(ctx)
if !ok { if !ok {
return errors.New("Socks|Client: Target not specified.") return errors.New("target not specified.").Path("Proxy", "Socks", "Client")
} }
var server *protocol.ServerSpec var server *protocol.ServerSpec
@ -55,7 +55,7 @@ func (c *Client) Process(ctx context.Context, ray ray.OutboundRay, dialer proxy.
}) })
if err != nil { if err != nil {
return errors.New("failed to find an available destination").Base(err).Path("Socks", "Client") return errors.New("failed to find an available destination").Base(err).Path("Proxy", "Socks", "Client")
} }
defer conn.Close() defer conn.Close()
@ -78,7 +78,7 @@ func (c *Client) Process(ctx context.Context, ray ray.OutboundRay, dialer proxy.
udpRequest, err := ClientHandshake(request, conn, conn) udpRequest, err := ClientHandshake(request, conn, conn)
if err != nil { if err != nil {
return errors.New("failed to establish connection to server").AtWarning().Base(err).Path("Socks", "Client") return errors.New("failed to establish connection to server").AtWarning().Base(err).Path("Proxy", "Socks", "Client")
} }
ctx, timer := signal.CancelAfterInactivity(ctx, time.Minute*2) ctx, timer := signal.CancelAfterInactivity(ctx, time.Minute*2)
@ -96,7 +96,7 @@ func (c *Client) Process(ctx context.Context, ray ray.OutboundRay, dialer proxy.
} else if request.Command == protocol.RequestCommandUDP { } else if request.Command == protocol.RequestCommandUDP {
udpConn, err := dialer.Dial(ctx, udpRequest.Destination()) udpConn, err := dialer.Dial(ctx, udpRequest.Destination())
if err != nil { if err != nil {
return errors.New("failed to create UDP connection").Base(err).Path("Socks", "Client") return errors.New("failed to create UDP connection").Base(err).Path("Proxy", "Socks", "Client")
} }
defer udpConn.Close() defer udpConn.Close()
requestFunc = func() error { requestFunc = func() error {
@ -112,7 +112,7 @@ func (c *Client) Process(ctx context.Context, ray ray.OutboundRay, dialer proxy.
requestDone := signal.ExecuteAsync(requestFunc) requestDone := signal.ExecuteAsync(requestFunc)
responseDone := signal.ExecuteAsync(responseFunc) responseDone := signal.ExecuteAsync(responseFunc)
if err := signal.ErrorOrFinish2(ctx, requestDone, responseDone); err != nil { if err := signal.ErrorOrFinish2(ctx, requestDone, responseDone); err != nil {
return errors.New("connection ends").Base(err).Path("Socks", "Client") return errors.New("connection ends").Base(err).Path("Proxy", "Socks", "Client")
} }
runtime.KeepAlive(timer) runtime.KeepAlive(timer)

View File

@ -29,7 +29,7 @@ type Server struct {
func NewServer(ctx context.Context, config *ServerConfig) (*Server, error) { func NewServer(ctx context.Context, config *ServerConfig) (*Server, error) {
space := app.SpaceFromContext(ctx) space := app.SpaceFromContext(ctx)
if space == nil { if space == nil {
return nil, errors.New("Socks|Server: No space in context.").AtWarning() return nil, errors.New("no space in context").AtWarning().Path("Proxy", "Socks", "Server")
} }
s := &Server{ s := &Server{
config: config, config: config,
@ -56,7 +56,7 @@ func (s *Server) Process(ctx context.Context, network net.Network, conn internet
case net.Network_UDP: case net.Network_UDP:
return s.handleUDPPayload(ctx, conn, dispatcher) return s.handleUDPPayload(ctx, conn, dispatcher)
default: default:
return errors.New("Socks|Server: Unknown network: ", network) return errors.New("unknown network: ", network).Path("Proxy", "Socks", "Server")
} }
} }
@ -66,7 +66,7 @@ func (s *Server) processTCP(ctx context.Context, conn internet.Connection, dispa
inboundDest, ok := proxy.InboundEntryPointFromContext(ctx) inboundDest, ok := proxy.InboundEntryPointFromContext(ctx)
if !ok { if !ok {
return errors.New("Socks|Server: inbound entry point not specified.") return errors.New("inbound entry point not specified").Path("Proxy", "Socks", "Server")
} }
session := &ServerSession{ session := &ServerSession{
config: s.config, config: s.config,
@ -78,14 +78,14 @@ func (s *Server) processTCP(ctx context.Context, conn internet.Connection, dispa
if source, ok := proxy.SourceFromContext(ctx); ok { if source, ok := proxy.SourceFromContext(ctx); ok {
log.Access(source, "", log.AccessRejected, err) log.Access(source, "", log.AccessRejected, err)
} }
log.Trace(errors.New("Socks|Server: Failed to read request: ", err)) log.Trace(errors.New("failed to read request").Base(err).Path("Proxy", "Socks", "Server"))
return err return err
} }
conn.SetReadDeadline(time.Time{}) conn.SetReadDeadline(time.Time{})
if request.Command == protocol.RequestCommandTCP { if request.Command == protocol.RequestCommandTCP {
dest := request.Destination() dest := request.Destination()
log.Trace(errors.New("Socks|Server: TCP Connect request to ", dest)) log.Trace(errors.New("TCP Connect request to ", dest).Path("Proxy", "Socks", "Server"))
if source, ok := proxy.SourceFromContext(ctx); ok { if source, ok := proxy.SourceFromContext(ctx); ok {
log.Access(source, dest, log.AccessAccepted, "") log.Access(source, dest, log.AccessAccepted, "")
} }
@ -129,7 +129,7 @@ func (v *Server) transport(ctx context.Context, reader io.Reader, writer io.Writ
v2reader := buf.NewReader(reader) v2reader := buf.NewReader(reader)
if err := buf.PipeUntilEOF(timer, v2reader, input); err != nil { if err := buf.PipeUntilEOF(timer, v2reader, input); err != nil {
return errors.New("failed to transport all TCP request").Base(err).Path("Socks", "Server") return errors.New("failed to transport all TCP request").Base(err).Path("Proxy", "Socks", "Server")
} }
return nil return nil
}) })
@ -137,7 +137,7 @@ func (v *Server) transport(ctx context.Context, reader io.Reader, writer io.Writ
responseDone := signal.ExecuteAsync(func() error { responseDone := signal.ExecuteAsync(func() error {
v2writer := buf.NewWriter(writer) v2writer := buf.NewWriter(writer)
if err := buf.PipeUntilEOF(timer, output, v2writer); err != nil { if err := buf.PipeUntilEOF(timer, output, v2writer); err != nil {
return errors.New("failed to transport all TCP response").Base(err).Path("Socks", "Server") return errors.New("failed to transport all TCP response").Base(err).Path("Proxy", "Socks", "Server")
} }
return nil return nil
}) })
@ -145,7 +145,7 @@ func (v *Server) transport(ctx context.Context, reader io.Reader, writer io.Writ
if err := signal.ErrorOrFinish2(ctx, requestDone, responseDone); err != nil { if err := signal.ErrorOrFinish2(ctx, requestDone, responseDone); err != nil {
input.CloseError() input.CloseError()
output.CloseError() output.CloseError()
return errors.New("connection ends").Base(err).Path("Socks", "Server") return errors.New("connection ends").Base(err).Path("Proxy", "Socks", "Server")
} }
runtime.KeepAlive(timer) runtime.KeepAlive(timer)
@ -157,7 +157,7 @@ func (v *Server) handleUDPPayload(ctx context.Context, conn internet.Connection,
udpServer := udp.NewDispatcher(dispatcher) udpServer := udp.NewDispatcher(dispatcher)
if source, ok := proxy.SourceFromContext(ctx); ok { if source, ok := proxy.SourceFromContext(ctx); ok {
log.Trace(errors.New("client UDP connection from ", source).Path("Socks", "Server")) log.Trace(errors.New("client UDP connection from ", source).Path("Proxy", "Socks", "Server"))
} }
reader := buf.NewReader(conn) reader := buf.NewReader(conn)
@ -169,7 +169,7 @@ func (v *Server) handleUDPPayload(ctx context.Context, conn internet.Connection,
request, data, err := DecodeUDPPacket(payload.Bytes()) request, data, err := DecodeUDPPacket(payload.Bytes())
if err != nil { if err != nil {
log.Trace(errors.New("Socks|Server: Failed to parse UDP request: ", err)) log.Trace(errors.New("failed to parse UDP request").Base(err).Path("Proxy", "Socks", "Server"))
continue continue
} }
@ -177,7 +177,7 @@ func (v *Server) handleUDPPayload(ctx context.Context, conn internet.Connection,
continue continue
} }
log.Trace(errors.New("Socks: Send packet to ", request.Destination(), " with ", len(data), " bytes")) log.Trace(errors.New("send packet to ", request.Destination(), " with ", len(data), " bytes").Path("Proxy", "Socks", "Server").AtDebug())
if source, ok := proxy.SourceFromContext(ctx); ok { if source, ok := proxy.SourceFromContext(ctx); ok {
log.Access(source, request.Destination, log.AccessAccepted, "") log.Access(source, request.Destination, log.AccessAccepted, "")
} }
@ -187,7 +187,7 @@ func (v *Server) handleUDPPayload(ctx context.Context, conn internet.Connection,
udpServer.Dispatch(ctx, request.Destination(), dataBuf, func(payload *buf.Buffer) { udpServer.Dispatch(ctx, request.Destination(), dataBuf, func(payload *buf.Buffer) {
defer payload.Release() defer payload.Release()
log.Trace(errors.New("Socks|Server: Writing back UDP response with ", payload.Len(), " bytes")) log.Trace(errors.New("writing back UDP response with ", payload.Len(), " bytes").Path("Proxy", "Socks", "Server").AtDebug())
udpMessage := EncodeUDPPacket(request, payload.Bytes()) udpMessage := EncodeUDPPacket(request, payload.Bytes())
defer udpMessage.Release() defer udpMessage.Release()

View File

@ -2,9 +2,9 @@ package encoding
import ( import (
"crypto/md5" "crypto/md5"
"errors"
"hash/fnv" "hash/fnv"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/serial" "v2ray.com/core/common/serial"
) )
@ -58,7 +58,7 @@ func (v *FnvAuthenticator) Seal(dst, nonce, plaintext, additionalData []byte) []
// Open implements AEAD.Open(). // Open implements AEAD.Open().
func (v *FnvAuthenticator) Open(dst, nonce, ciphertext, additionalData []byte) ([]byte, error) { func (v *FnvAuthenticator) Open(dst, nonce, ciphertext, additionalData []byte) ([]byte, error) {
if serial.BytesToUint32(ciphertext[:4]) != Authenticate(ciphertext[4:]) { if serial.BytesToUint32(ciphertext[:4]) != Authenticate(ciphertext[4:]) {
return dst, errors.New("VMess|FNV: Invalid authentication.") return dst, errors.New("invalid authentication").Path("Proxy", "VMess", "Encoding", "FnvAuthenticator")
} }
return append(dst, ciphertext[4:]...), nil return append(dst, ciphertext[4:]...), nil
} }

View File

@ -63,7 +63,7 @@ func (v *ClientSession) EncodeRequestHeader(header *protocol.RequestHeader, writ
timestamp := protocol.NewTimestampGenerator(protocol.NowTime(), 30)() timestamp := protocol.NewTimestampGenerator(protocol.NowTime(), 30)()
account, err := header.User.GetTypedAccount() account, err := header.User.GetTypedAccount()
if err != nil { if err != nil {
log.Trace(errors.New("VMess: Failed to get user account: ", err).AtError()) log.Trace(errors.New("failed to get user account: ", err).AtError().Path("Proxy", "VMess", "Encoding", "ClientSession"))
return return
} }
idHash := v.idHash(account.(*vmess.InternalAccount).AnyValidID().Bytes()) idHash := v.idHash(account.(*vmess.InternalAccount).AnyValidID().Bytes())
@ -186,12 +186,12 @@ func (v *ClientSession) DecodeResponseHeader(reader io.Reader) (*protocol.Respon
_, err := io.ReadFull(v.responseReader, buffer[:4]) _, err := io.ReadFull(v.responseReader, buffer[:4])
if err != nil { if err != nil {
log.Trace(errors.New("VMess|Client: Failed to read response header: ", err)) log.Trace(errors.New("failed to read response header").Base(err).Path("Proxy", "VMess", "Encoding", "ClientSession"))
return nil, err return nil, err
} }
if buffer[0] != v.responseHeader { if buffer[0] != v.responseHeader {
return nil, errors.Format("VMess|Client: Unexpected response header. Expecting %d but actually %d", v.responseHeader, buffer[0]) return nil, errors.Format("unexpected response header. Expecting %d but actually %d", v.responseHeader, buffer[0]).Path("Proxy", "VMess", "Encoding", "ClientSession")
} }
header := &protocol.ResponseHeader{ header := &protocol.ResponseHeader{
@ -203,7 +203,7 @@ func (v *ClientSession) DecodeResponseHeader(reader io.Reader) (*protocol.Respon
dataLen := int(buffer[3]) dataLen := int(buffer[3])
_, err := io.ReadFull(v.responseReader, buffer[:dataLen]) _, err := io.ReadFull(v.responseReader, buffer[:dataLen])
if err != nil { if err != nil {
log.Trace(errors.New("VMess|Client: Failed to read response command: ", err)) log.Trace(errors.New("failed to read response command").Base(err).Path("Proxy", "VMess", "Encoding", "ClientSession"))
return nil, err return nil, err
} }
data := buffer[:dataLen] data := buffer[:dataLen]

View File

@ -53,12 +53,12 @@ func MarshalCommand(command interface{}, writer io.Writer) error {
func UnmarshalCommand(cmdID byte, data []byte) (protocol.ResponseCommand, error) { func UnmarshalCommand(cmdID byte, data []byte) (protocol.ResponseCommand, error) {
if len(data) <= 4 { if len(data) <= 4 {
return nil, errors.New("VMess|Command: Insufficient length.") return nil, errors.New("insufficient length").Path("Proxy", "VMess", "Encoding", "Command")
} }
expectedAuth := Authenticate(data[4:]) expectedAuth := Authenticate(data[4:])
actualAuth := serial.BytesToUint32(data[:4]) actualAuth := serial.BytesToUint32(data[:4])
if expectedAuth != actualAuth { if expectedAuth != actualAuth {
return nil, errors.New("VMess|Command: Invalid auth.") return nil, errors.New("invalid auth").Path("Proxy", "VMess", "Encoding", "Command")
} }
var factory CommandFactory var factory CommandFactory

View File

@ -123,12 +123,12 @@ func (v *ServerSession) DecodeRequestHeader(reader io.Reader) (*protocol.Request
_, err := io.ReadFull(reader, buffer[:protocol.IDBytesLen]) _, err := io.ReadFull(reader, buffer[:protocol.IDBytesLen])
if err != nil { if err != nil {
return nil, errors.New("failed to read request header").Base(err).Path("VMess", "Server") return nil, errors.New("failed to read request header").Base(err).Path("Proxy", "VMess", "Encoding", "ServerSession")
} }
user, timestamp, valid := v.userValidator.Get(buffer[:protocol.IDBytesLen]) user, timestamp, valid := v.userValidator.Get(buffer[:protocol.IDBytesLen])
if !valid { if !valid {
return nil, errors.New("VMess|Server: Invalid user.") return nil, errors.New("invalid user").Path("Proxy", "VMess", "Encoding", "ServerSession")
} }
timestampHash := md5.New() timestampHash := md5.New()
@ -136,7 +136,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("failed to get user account").Base(err).Path("VMess", "Server") return nil, errors.New("failed to get user account").Base(err).Path("Proxy", "VMess", "Encoding", "ServerSession")
} }
vmessAccount := account.(*vmess.InternalAccount) vmessAccount := account.(*vmess.InternalAccount)
@ -145,7 +145,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("failed to read request header").Base(err).Path("VMess", "Server") return nil, errors.New("failed to read request header").Base(err).Path("Proxy", "VMess", "Encoding", "ServerSession")
} }
bufferLen := nBytes bufferLen := nBytes
@ -155,7 +155,7 @@ func (v *ServerSession) DecodeRequestHeader(reader io.Reader) (*protocol.Request
} }
if request.Version != Version { if request.Version != Version {
return nil, errors.New("invalid protocol version ", request.Version).Path("VMess", "Server") return nil, errors.New("invalid protocol version ", request.Version).Path("Proxy", "VMess", "Encoding", "ServerSession")
} }
v.requestBodyIV = append([]byte(nil), buffer[1:17]...) // 16 bytes v.requestBodyIV = append([]byte(nil), buffer[1:17]...) // 16 bytes
@ -165,7 +165,7 @@ func (v *ServerSession) DecodeRequestHeader(reader io.Reader) (*protocol.Request
copy(sid.key[:], v.requestBodyKey) copy(sid.key[:], v.requestBodyKey)
copy(sid.nonce[:], v.requestBodyIV) copy(sid.nonce[:], v.requestBodyIV)
if v.sessionHistory.has(sid) { if v.sessionHistory.has(sid) {
return nil, errors.New("duplicated session id, possibly under replay attack").Path("VMess", "Server") return nil, errors.New("duplicated session id, possibly under replay attack").Path("Proxy", "VMess", "Encoding", "ServerSession")
} }
v.sessionHistory.add(sid) v.sessionHistory.add(sid)
@ -183,28 +183,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("failed to read IPv4 address").Base(err).Path("VMess", "Server") return nil, errors.New("failed to read IPv4 address").Base(err).Path("Proxy", "VMess", "Encoding", "ServerSession")
} }
request.Address = net.IPAddress(buffer[41:45]) request.Address = net.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("failed to read IPv6 address").Base(err).Path("VMess", "Server") return nil, errors.New("failed to read IPv6 address").Base(err).Path("Proxy", "VMess", "Encoding", "ServerSession")
} }
request.Address = net.IPAddress(buffer[41:57]) request.Address = net.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("failed to read domain address").Base(err).Path("VMess", "Server") return nil, errors.New("failed to read domain address").Base(err).Path("Proxy", "VMess", "Encoding", "ServerSession")
} }
domainLength := int(buffer[41]) domainLength := int(buffer[41])
if domainLength == 0 { if domainLength == 0 {
return nil, errors.New("zero length domain").Base(err).Path("VMess", "Server") return nil, errors.New("zero length domain").Base(err).Path("Proxy", "VMess", "Encoding", "ServerSession")
} }
_, 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("failed to read domain address").Base(err).Path("VMess", "Server") return nil, errors.New("failed to read domain address").Base(err).Path("Proxy", "VMess", "Encoding", "ServerSession")
} }
bufferLen += 1 + domainLength bufferLen += 1 + domainLength
request.Address = net.DomainAddress(string(buffer[42 : 42+domainLength])) request.Address = net.DomainAddress(string(buffer[42 : 42+domainLength]))
@ -213,14 +213,14 @@ func (v *ServerSession) DecodeRequestHeader(reader io.Reader) (*protocol.Request
if padingLen > 0 { if padingLen > 0 {
_, err = io.ReadFull(decryptor, buffer[bufferLen:bufferLen+padingLen]) _, err = io.ReadFull(decryptor, buffer[bufferLen:bufferLen+padingLen])
if err != nil { if err != nil {
return nil, errors.New("failed to read padding").Base(err).Path("VMess", "Server") return nil, errors.New("failed to read padding").Base(err).Path("Proxy", "VMess", "Encoding", "ServerSession")
} }
bufferLen += padingLen bufferLen += padingLen
} }
_, 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("failed to read checksum").Base(err).Path("VMess", "Server") return nil, errors.New("failed to read checksum").Base(err).Path("Proxy", "VMess", "Encoding", "ServerSession")
} }
fnv1a := fnv.New32a() fnv1a := fnv.New32a()
@ -229,11 +229,11 @@ func (v *ServerSession) DecodeRequestHeader(reader io.Reader) (*protocol.Request
expectedHash := serial.BytesToUint32(buffer[bufferLen : bufferLen+4]) expectedHash := serial.BytesToUint32(buffer[bufferLen : bufferLen+4])
if actualHash != expectedHash { if actualHash != expectedHash {
return nil, errors.New("VMess|Server: Invalid auth.") return nil, errors.New("invalid auth").Path("Proxy", "VMess", "Encoding", "ServerSession")
} }
if request.Address == nil { if request.Address == nil {
return nil, errors.New("VMess|Server: Invalid remote address.") return nil, errors.New("invalid remote address").Path("Proxy", "VMess", "Encoding", "ServerSession")
} }
return request, nil return request, nil