1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-01-02 07:26:24 -05:00

update error messages

This commit is contained in:
Darien Raymond 2017-04-06 22:17:13 +02:00
parent b4cd497abf
commit 2668954c12
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
5 changed files with 25 additions and 24 deletions

View File

@ -5,6 +5,7 @@ import (
"io" "io"
"golang.org/x/crypto/sha3" "golang.org/x/crypto/sha3"
"v2ray.com/core/common" "v2ray.com/core/common"
"v2ray.com/core/common/buf" "v2ray.com/core/common/buf"
"v2ray.com/core/common/errors" "v2ray.com/core/common/errors"
@ -12,7 +13,7 @@ import (
) )
var ( var (
errInsufficientBuffer = errors.New("Insufficient buffer.") errInsufficientBuffer = errors.New("insufficient buffer")
) )
type BytesGenerator interface { type BytesGenerator interface {
@ -127,13 +128,13 @@ func (v *AuthenticationReader) nextChunk(mask uint16) error {
return errInsufficientBuffer return errInsufficientBuffer
} }
if size > readerBufferSize-2 { if size > readerBufferSize-2 {
return errors.New("Crypto|AuthenticationReader: Size too large: ", size) return errors.New("size too large: ", size).Path("Common", "Crypto", "AuthenticationReader")
} }
if size == v.auth.Overhead() { if size == v.auth.Overhead() {
return io.EOF return io.EOF
} }
if size < v.auth.Overhead() { if size < v.auth.Overhead() {
return errors.New("Crypto|AuthenticationReader: invalid packet size:", size) return errors.New("invalid packet size: ", size).Path("Common", "Crypto", "AuthenticationReader")
} }
cipherChunk := v.buffer.BytesRange(2, size+2) cipherChunk := v.buffer.BytesRange(2, size+2)
plainChunk, err := v.auth.Open(cipherChunk[:0], cipherChunk) plainChunk, err := v.auth.Open(cipherChunk[:0], cipherChunk)

View File

@ -31,7 +31,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("HTTP|Server: No space in context.") return nil, errors.New("no space in context.").Path("Proxy", "HTTP", "Server")
} }
s := &Server{ s := &Server{
config: config, config: config,
@ -77,7 +77,7 @@ func (s *Server) Process(ctx context.Context, network v2net.Network, conn intern
request, err := http.ReadRequest(reader) request, err := http.ReadRequest(reader)
if err != nil { if err != nil {
if errors.Cause(err) != io.EOF { if errors.Cause(err) != io.EOF {
log.Trace(errors.New("HTTP: Failed to read http request: ", err).AtWarning()) log.Trace(errors.New("failed to read http request").Base(err).AtWarning().Path("Proxy", "HTTP", "Server"))
} }
return err return err
} }
@ -94,7 +94,7 @@ func (s *Server) Process(ctx context.Context, network v2net.Network, conn intern
} }
dest, err := parseHost(host, defaultPort) dest, err := parseHost(host, defaultPort)
if err != nil { if err != nil {
return errors.New("malformed proxy host: ", host).AtWarning().Base(err).Path("HTTP") return errors.New("malformed proxy host: ", host).AtWarning().Base(err).Path("Proxy", "HTTP", "Server")
} }
log.Access(conn.RemoteAddr(), request.URL, log.AccessAccepted, "") log.Access(conn.RemoteAddr(), request.URL, log.AccessAccepted, "")
@ -118,7 +118,7 @@ func (s *Server) handleConnect(ctx context.Context, request *http.Request, reade
Close: false, Close: false,
} }
if err := response.Write(writer); err != nil { if err := response.Write(writer); err != nil {
return errors.New("failed to write back OK response").Base(err).Path("HTTP", "Server") return errors.New("failed to write back OK response").Base(err).Path("Proxy", "HTTP", "Server")
} }
timeout := time.Second * time.Duration(s.config.Timeout) timeout := time.Second * time.Duration(s.config.Timeout)
@ -152,7 +152,7 @@ func (s *Server) handleConnect(ctx context.Context, request *http.Request, reade
if err := signal.ErrorOrFinish2(ctx, requestDone, responseDone); err != nil { if err := signal.ErrorOrFinish2(ctx, requestDone, responseDone); err != nil {
ray.InboundInput().CloseError() ray.InboundInput().CloseError()
ray.InboundOutput().CloseError() ray.InboundOutput().CloseError()
return errors.New("connection ends").Base(err).Path("HTTP", "Server") return errors.New("connection ends").Base(err).Path("Proxy", "HTTP", "Server")
} }
runtime.KeepAlive(timer) runtime.KeepAlive(timer)
@ -234,7 +234,7 @@ func (s *Server) handlePlainHTTP(ctx context.Context, request *http.Request, rea
responseReader := bufio.NewReader(buf.ToBytesReader(ray.InboundOutput())) responseReader := bufio.NewReader(buf.ToBytesReader(ray.InboundOutput()))
response, err := http.ReadResponse(responseReader, request) response, err := http.ReadResponse(responseReader, request)
if err != nil { if err != nil {
log.Trace(errors.New("HTTP: Failed to read response: ", err).AtWarning()) log.Trace(errors.New("failed to read response").Base(err).AtWarning().Path("Proxy", "HTTP", "Server"))
response = generateResponse(503, "Service Unavailable") response = generateResponse(503, "Service Unavailable")
} }
responseWriter := buf.NewBufferedWriter(writer) responseWriter := buf.NewBufferedWriter(writer)
@ -251,7 +251,7 @@ func (s *Server) handlePlainHTTP(ctx context.Context, request *http.Request, rea
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("HTTP", "Server") return errors.New("connection ends").Base(err).Path("Proxy", "HTTP", "Server")
} }
return nil return nil

View File

@ -40,7 +40,7 @@ func NewClient(ctx context.Context, config *ClientConfig) (*Client, error) {
func (v *Client) Process(ctx context.Context, outboundRay ray.OutboundRay, dialer proxy.Dialer) error { func (v *Client) Process(ctx context.Context, outboundRay ray.OutboundRay, dialer proxy.Dialer) error {
destination, ok := proxy.TargetFromContext(ctx) destination, ok := proxy.TargetFromContext(ctx)
if !ok { if !ok {
return errors.New("Shadowsocks|Client: Target not specified.") return errors.New("target not specified").Path("Proxy", "Shadowsocks", "Client")
} }
network := destination.Network network := destination.Network
@ -60,9 +60,9 @@ func (v *Client) Process(ctx context.Context, outboundRay ray.OutboundRay, diale
return nil return nil
}) })
if err != nil { if err != nil {
return errors.New("failed to find an available destination").AtWarning().Base(err).Path("Shadowsocks", "Client") return errors.New("failed to find an available destination").AtWarning().Base(err).Path("Proxy", "Shadowsocks", "Client")
} }
log.Trace(errors.New("Shadowsocks|Client: Tunneling request to ", destination, " via ", server.Destination())) log.Trace(errors.New("tunneling request to ", destination, " via ", server.Destination()).Path("Proxy", "Shadowsocks", "Client"))
defer conn.Close() defer conn.Close()
conn.SetReusable(false) conn.SetReusable(false)
@ -81,7 +81,7 @@ func (v *Client) Process(ctx context.Context, outboundRay ray.OutboundRay, diale
user := server.PickUser() user := server.PickUser()
rawAccount, err := user.GetTypedAccount() rawAccount, err := user.GetTypedAccount()
if err != nil { if err != nil {
return errors.New("failed to get a valid user account").AtWarning().Base(err).Path("Shadowsocks", "Client") return errors.New("failed to get a valid user account").AtWarning().Base(err).Path("Proxy", "Shadowsocks", "Client")
} }
account := rawAccount.(*ShadowsocksAccount) account := rawAccount.(*ShadowsocksAccount)
request.User = user request.User = user
@ -96,7 +96,7 @@ func (v *Client) Process(ctx context.Context, outboundRay ray.OutboundRay, diale
bufferedWriter := buf.NewBufferedWriter(conn) bufferedWriter := buf.NewBufferedWriter(conn)
bodyWriter, err := WriteTCPRequest(request, bufferedWriter) bodyWriter, err := WriteTCPRequest(request, bufferedWriter)
if err != nil { if err != nil {
return errors.New("failed to write request").Base(err).Path("Shadowsocks", "Client") return errors.New("failed to write request").Base(err).Path("Proxy", "Shadowsocks", "Client")
} }
if err := bufferedWriter.SetBuffered(false); err != nil { if err := bufferedWriter.SetBuffered(false); err != nil {
@ -127,7 +127,7 @@ func (v *Client) Process(ctx context.Context, outboundRay ray.OutboundRay, diale
}) })
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("Shadowsocks", "Client") return errors.New("connection ends").Base(err).Path("Proxy", "Shadowsocks", "Client")
} }
return nil return nil
@ -142,7 +142,7 @@ func (v *Client) Process(ctx context.Context, outboundRay ray.OutboundRay, diale
requestDone := signal.ExecuteAsync(func() error { requestDone := signal.ExecuteAsync(func() error {
if err := buf.PipeUntilEOF(timer, outboundRay.OutboundInput(), writer); err != nil { if err := buf.PipeUntilEOF(timer, outboundRay.OutboundInput(), writer); err != nil {
return errors.New("failed to transport all UDP request").Base(err).Path("Shadowsocks", "Client") return errors.New("failed to transport all UDP request").Base(err).Path("Proxy", "Shadowsocks", "Client")
} }
return nil return nil
}) })
@ -156,13 +156,13 @@ func (v *Client) Process(ctx context.Context, outboundRay ray.OutboundRay, diale
} }
if err := buf.PipeUntilEOF(timer, reader, outboundRay.OutboundOutput()); err != nil { if err := buf.PipeUntilEOF(timer, reader, outboundRay.OutboundOutput()); err != nil {
return errors.New("failed to transport all UDP response").Base(err).Path("Shadowsocks", "Client") return errors.New("failed to transport all UDP response").Base(err).Path("Proxy", "Shadowsocks", "Client")
} }
return nil return nil
}) })
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("Shadowsocks", "Client") return errors.New("connection ends").Base(err).Path("Proxy", "Shadowsocks", "Client")
} }
return nil return nil

View File

@ -14,7 +14,7 @@ var (
func RegisterTransportListener(protocol TransportProtocol, listener ListenFunc) error { func RegisterTransportListener(protocol TransportProtocol, listener ListenFunc) error {
if _, found := transportListenerCache[protocol]; found { if _, found := transportListenerCache[protocol]; found {
return errors.New("Internet|TCPHub: ", protocol, " listener already registered.") return errors.New(protocol, " listener already registered.").AtError().Path("Transport", "Internet")
} }
transportListenerCache[protocol] = listener transportListenerCache[protocol] = listener
return nil return nil
@ -44,11 +44,11 @@ func ListenTCP(ctx context.Context, address v2net.Address, port v2net.Port, conn
} }
listenFunc := transportListenerCache[protocol] listenFunc := transportListenerCache[protocol]
if listenFunc == nil { if listenFunc == nil {
return nil, errors.New("Internet|TCPHub: ", protocol, " listener not registered.") return nil, errors.New(protocol, " listener not registered.").AtError().Path("Transport", "Internet")
} }
listener, err := listenFunc(ctx, address, port, conns) listener, err := listenFunc(ctx, address, port, conns)
if err != nil { if err != nil {
return nil, errors.New("failed to listen on address: ", address, ":", port).Base(err).Path("Internet", "TCPHub") return nil, errors.New("failed to listen on address: ", address, ":", port).Base(err).Path("Transport", "Internet")
} }
return listener, nil return listener, nil
} }

View File

@ -45,7 +45,7 @@ func (v *Dispatcher) getInboundRay(ctx context.Context, dest v2net.Destination)
return entry, true return entry, true
} }
log.Trace(errors.New("UDP|Server: establishing new connection for ", dest)) log.Trace(errors.New("establishing new connection for ", dest).Path("Transport", "Internet", "UDP", "Dispatcher"))
inboundRay, _ := v.dispatcher.Dispatch(ctx, dest) inboundRay, _ := v.dispatcher.Dispatch(ctx, dest)
v.conns[dest] = inboundRay v.conns[dest] = inboundRay
return inboundRay, false return inboundRay, false
@ -53,7 +53,7 @@ func (v *Dispatcher) getInboundRay(ctx context.Context, dest v2net.Destination)
func (v *Dispatcher) Dispatch(ctx context.Context, destination v2net.Destination, payload *buf.Buffer, callback ResponseCallback) { func (v *Dispatcher) Dispatch(ctx context.Context, destination v2net.Destination, payload *buf.Buffer, callback ResponseCallback) {
// TODO: Add user to destString // TODO: Add user to destString
log.Trace(errors.New("UDP|Server: Dispatch request: ", destination).AtDebug()) log.Trace(errors.New("dispatch request to: ", destination).AtDebug().Path("Transport", "Internet", "UDP", "Dispatcher"))
inboundRay, existing := v.getInboundRay(ctx, destination) inboundRay, existing := v.getInboundRay(ctx, destination)
outputStream := inboundRay.InboundInput() outputStream := inboundRay.InboundInput()