mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-30 05:56:54 -05:00
update error messages
This commit is contained in:
parent
b4cd497abf
commit
2668954c12
@ -5,6 +5,7 @@ import (
|
||||
"io"
|
||||
|
||||
"golang.org/x/crypto/sha3"
|
||||
|
||||
"v2ray.com/core/common"
|
||||
"v2ray.com/core/common/buf"
|
||||
"v2ray.com/core/common/errors"
|
||||
@ -12,7 +13,7 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
errInsufficientBuffer = errors.New("Insufficient buffer.")
|
||||
errInsufficientBuffer = errors.New("insufficient buffer")
|
||||
)
|
||||
|
||||
type BytesGenerator interface {
|
||||
@ -127,13 +128,13 @@ func (v *AuthenticationReader) nextChunk(mask uint16) error {
|
||||
return errInsufficientBuffer
|
||||
}
|
||||
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() {
|
||||
return io.EOF
|
||||
}
|
||||
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)
|
||||
plainChunk, err := v.auth.Open(cipherChunk[:0], cipherChunk)
|
||||
|
@ -31,7 +31,7 @@ type Server struct {
|
||||
func NewServer(ctx context.Context, config *ServerConfig) (*Server, error) {
|
||||
space := app.SpaceFromContext(ctx)
|
||||
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{
|
||||
config: config,
|
||||
@ -77,7 +77,7 @@ func (s *Server) Process(ctx context.Context, network v2net.Network, conn intern
|
||||
request, err := http.ReadRequest(reader)
|
||||
if err != nil {
|
||||
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
|
||||
}
|
||||
@ -94,7 +94,7 @@ func (s *Server) Process(ctx context.Context, network v2net.Network, conn intern
|
||||
}
|
||||
dest, err := parseHost(host, defaultPort)
|
||||
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, "")
|
||||
|
||||
@ -118,7 +118,7 @@ func (s *Server) handleConnect(ctx context.Context, request *http.Request, reade
|
||||
Close: false,
|
||||
}
|
||||
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)
|
||||
@ -152,7 +152,7 @@ func (s *Server) handleConnect(ctx context.Context, request *http.Request, reade
|
||||
if err := signal.ErrorOrFinish2(ctx, requestDone, responseDone); err != nil {
|
||||
ray.InboundInput().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)
|
||||
@ -234,7 +234,7 @@ func (s *Server) handlePlainHTTP(ctx context.Context, request *http.Request, rea
|
||||
responseReader := bufio.NewReader(buf.ToBytesReader(ray.InboundOutput()))
|
||||
response, err := http.ReadResponse(responseReader, request)
|
||||
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")
|
||||
}
|
||||
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 {
|
||||
input.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
|
||||
|
@ -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 {
|
||||
destination, ok := proxy.TargetFromContext(ctx)
|
||||
if !ok {
|
||||
return errors.New("Shadowsocks|Client: Target not specified.")
|
||||
return errors.New("target not specified").Path("Proxy", "Shadowsocks", "Client")
|
||||
}
|
||||
network := destination.Network
|
||||
|
||||
@ -60,9 +60,9 @@ func (v *Client) Process(ctx context.Context, outboundRay ray.OutboundRay, diale
|
||||
return 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()
|
||||
conn.SetReusable(false)
|
||||
@ -81,7 +81,7 @@ func (v *Client) Process(ctx context.Context, outboundRay ray.OutboundRay, diale
|
||||
user := server.PickUser()
|
||||
rawAccount, err := user.GetTypedAccount()
|
||||
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)
|
||||
request.User = user
|
||||
@ -96,7 +96,7 @@ func (v *Client) Process(ctx context.Context, outboundRay ray.OutboundRay, diale
|
||||
bufferedWriter := buf.NewBufferedWriter(conn)
|
||||
bodyWriter, err := WriteTCPRequest(request, bufferedWriter)
|
||||
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 {
|
||||
@ -127,7 +127,7 @@ func (v *Client) Process(ctx context.Context, outboundRay ray.OutboundRay, diale
|
||||
})
|
||||
|
||||
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
|
||||
@ -142,7 +142,7 @@ func (v *Client) Process(ctx context.Context, outboundRay ray.OutboundRay, diale
|
||||
|
||||
requestDone := signal.ExecuteAsync(func() error {
|
||||
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
|
||||
})
|
||||
@ -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 {
|
||||
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
|
||||
})
|
||||
|
||||
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
|
||||
|
@ -14,7 +14,7 @@ var (
|
||||
|
||||
func RegisterTransportListener(protocol TransportProtocol, listener ListenFunc) error {
|
||||
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
|
||||
return nil
|
||||
@ -44,11 +44,11 @@ func ListenTCP(ctx context.Context, address v2net.Address, port v2net.Port, conn
|
||||
}
|
||||
listenFunc := transportListenerCache[protocol]
|
||||
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)
|
||||
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
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ func (v *Dispatcher) getInboundRay(ctx context.Context, dest v2net.Destination)
|
||||
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)
|
||||
v.conns[dest] = inboundRay
|
||||
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) {
|
||||
// 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)
|
||||
outputStream := inboundRay.InboundInput()
|
||||
|
Loading…
Reference in New Issue
Block a user