mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-30 09:18:34 +00:00
Refactor log (#3446)
* Refactor log * Add new log methods * Fix logger test * Change all logging code * Clean up pathObj * Rebase to latest main * Remove invoking method name after the dot
This commit is contained in:
parent
8320732743
commit
079d0bd8a9
291 changed files with 1837 additions and 2368 deletions
|
@ -1,9 +0,0 @@
|
|||
package blackhole
|
||||
|
||||
import "github.com/xtls/xray-core/common/errors"
|
||||
|
||||
type errPathObjHolder struct{}
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).WithPathObj(errPathObjHolder{})
|
||||
}
|
|
@ -74,14 +74,14 @@ func parseIPQuery(b []byte) (r bool, domain string, id uint16, qType dnsmessage.
|
|||
var parser dnsmessage.Parser
|
||||
header, err := parser.Start(b)
|
||||
if err != nil {
|
||||
newError("parser start").Base(err).WriteToLog()
|
||||
errors.LogInfoInner(context.Background(), err, "parser start")
|
||||
return
|
||||
}
|
||||
|
||||
id = header.ID
|
||||
q, err := parser.Question()
|
||||
if err != nil {
|
||||
newError("question").Base(err).WriteToLog()
|
||||
errors.LogInfoInner(context.Background(), err, "question")
|
||||
return
|
||||
}
|
||||
qType = q.Type
|
||||
|
@ -97,9 +97,9 @@ func parseIPQuery(b []byte) (r bool, domain string, id uint16, qType dnsmessage.
|
|||
// Process implements proxy.Outbound.
|
||||
func (h *Handler) Process(ctx context.Context, link *transport.Link, d internet.Dialer) error {
|
||||
outbounds := session.OutboundsFromContext(ctx)
|
||||
ob := outbounds[len(outbounds) - 1]
|
||||
ob := outbounds[len(outbounds)-1]
|
||||
if !ob.Target.IsValid() {
|
||||
return newError("invalid outbound")
|
||||
return errors.New("invalid outbound")
|
||||
}
|
||||
ob.Name = "dns"
|
||||
|
||||
|
@ -116,7 +116,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, d internet.
|
|||
dest.Port = h.server.Port
|
||||
}
|
||||
|
||||
newError("handling DNS traffic to ", dest).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfo(ctx, "handling DNS traffic to ", dest)
|
||||
|
||||
conn := &outboundConn{
|
||||
dialer: func() (stat.Connection, error) {
|
||||
|
@ -216,7 +216,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, d internet.
|
|||
}
|
||||
|
||||
if err := task.Run(ctx, request, response); err != nil {
|
||||
return newError("connection ends").Base(err)
|
||||
return errors.New("connection ends").Base(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -245,7 +245,7 @@ func (h *Handler) handleIPQuery(id uint16, qType dnsmessage.Type, domain string,
|
|||
|
||||
rcode := dns.RCodeFromError(err)
|
||||
if rcode == 0 && len(ips) == 0 && !errors.AllEqual(dns.ErrEmptyResponse, errors.Cause(err)) {
|
||||
newError("ip query").Base(err).WriteToLog()
|
||||
errors.LogInfoInner(context.Background(), err, "ip query")
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -297,14 +297,14 @@ func (h *Handler) handleIPQuery(id uint16, qType dnsmessage.Type, domain string,
|
|||
}
|
||||
msgBytes, err := builder.Finish()
|
||||
if err != nil {
|
||||
newError("pack message").Base(err).WriteToLog()
|
||||
errors.LogInfoInner(context.Background(), err, "pack message")
|
||||
b.Release()
|
||||
return
|
||||
}
|
||||
b.Resize(0, int32(len(msgBytes)))
|
||||
|
||||
if err := writer.WriteMessage(b); err != nil {
|
||||
newError("write IP answer").Base(err).WriteToLog()
|
||||
errors.LogInfoInner(context.Background(), err, "write IP answer")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -332,7 +332,7 @@ func (c *outboundConn) Write(b []byte) (int, error) {
|
|||
if c.conn == nil {
|
||||
if err := c.dial(); err != nil {
|
||||
c.access.Unlock()
|
||||
newError("failed to dial outbound connection").Base(err).AtWarning().WriteToLog()
|
||||
errors.LogWarningInner(context.Background(), err, "failed to dial outbound connection")
|
||||
return len(b), nil
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
package dns
|
||||
|
||||
import "github.com/xtls/xray-core/common/errors"
|
||||
|
||||
type errPathObjHolder struct{}
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).WithPathObj(errPathObjHolder{})
|
||||
}
|
|
@ -9,6 +9,7 @@ import (
|
|||
|
||||
"github.com/xtls/xray-core/common"
|
||||
"github.com/xtls/xray-core/common/buf"
|
||||
"github.com/xtls/xray-core/common/errors"
|
||||
"github.com/xtls/xray-core/common/log"
|
||||
"github.com/xtls/xray-core/common/net"
|
||||
"github.com/xtls/xray-core/common/protocol"
|
||||
|
@ -42,7 +43,7 @@ type DokodemoDoor struct {
|
|||
// Init initializes the DokodemoDoor instance with necessary parameters.
|
||||
func (d *DokodemoDoor) Init(config *Config, pm policy.Manager, sockopt *session.Sockopt) error {
|
||||
if (config.NetworkList == nil || len(config.NetworkList.Network) == 0) && len(config.Networks) == 0 {
|
||||
return newError("no network specified")
|
||||
return errors.New("no network specified")
|
||||
}
|
||||
d.config = config
|
||||
d.address = config.GetPredefinedAddress()
|
||||
|
@ -77,7 +78,7 @@ type hasHandshakeAddressContext interface {
|
|||
|
||||
// Process implements proxy.Inbound.
|
||||
func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn stat.Connection, dispatcher routing.Dispatcher) error {
|
||||
newError("processing connection from: ", conn.RemoteAddr()).AtDebug().WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogDebug(ctx, "processing connection from: ", conn.RemoteAddr())
|
||||
dest := net.Destination{
|
||||
Network: network,
|
||||
Address: d.address,
|
||||
|
@ -88,7 +89,7 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn st
|
|||
if d.config.FollowRedirect {
|
||||
outbounds := session.OutboundsFromContext(ctx)
|
||||
if len(outbounds) > 0 {
|
||||
ob := outbounds[len(outbounds) - 1]
|
||||
ob := outbounds[len(outbounds)-1]
|
||||
if ob.Target.IsValid() {
|
||||
dest = ob.Target
|
||||
destinationOverridden = true
|
||||
|
@ -103,7 +104,7 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn st
|
|||
}
|
||||
}
|
||||
if !dest.IsValid() || dest.Address == nil {
|
||||
return newError("unable to get destination")
|
||||
return errors.New("unable to get destination")
|
||||
}
|
||||
|
||||
inbound := session.InboundFromContext(ctx)
|
||||
|
@ -119,7 +120,7 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn st
|
|||
Status: log.AccessAccepted,
|
||||
Reason: "",
|
||||
})
|
||||
newError("received request for ", conn.RemoteAddr()).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfo(ctx, "received request for ", conn.RemoteAddr())
|
||||
|
||||
plcy := d.policy()
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
|
@ -132,7 +133,7 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn st
|
|||
ctx = policy.ContextWithBufferPolicy(ctx, plcy.Buffer)
|
||||
link, err := dispatcher.Dispatch(ctx, dest)
|
||||
if err != nil {
|
||||
return newError("failed to dispatch request").Base(err)
|
||||
return errors.New("failed to dispatch request").Base(err)
|
||||
}
|
||||
|
||||
requestCount := int32(1)
|
||||
|
@ -150,7 +151,7 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn st
|
|||
reader = buf.NewReader(conn)
|
||||
}
|
||||
if err := buf.Copy(reader, link.Writer, buf.UpdateActivity(timer)); err != nil {
|
||||
return newError("failed to transport request").Base(err)
|
||||
return errors.New("failed to transport request").Base(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -217,7 +218,7 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn st
|
|||
}
|
||||
}()
|
||||
if err := buf.Copy(tReader, link.Writer, buf.UpdateActivity(timer)); err != nil {
|
||||
return newError("failed to transport request (TPROXY conn)").Base(err)
|
||||
return errors.New("failed to transport request (TPROXY conn)").Base(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -229,7 +230,7 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn st
|
|||
defer timer.SetTimeout(plcy.Timeouts.UplinkOnly)
|
||||
|
||||
if err := buf.Copy(link.Reader, writer, buf.UpdateActivity(timer)); err != nil {
|
||||
return newError("failed to transport response").Base(err)
|
||||
return errors.New("failed to transport response").Base(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -239,7 +240,7 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn st
|
|||
}, task.Close(link.Writer)), responseDone); err != nil {
|
||||
common.Interrupt(link.Reader)
|
||||
common.Interrupt(link.Writer)
|
||||
return newError("connection ends").Base(err)
|
||||
return errors.New("connection ends").Base(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -282,7 +283,7 @@ func (w *PacketWriter) WriteMultiBuffer(mb buf.MultiBuffer) error {
|
|||
w.mark,
|
||||
)
|
||||
if err != nil {
|
||||
newError(err).WriteToLog()
|
||||
errors.LogInfo(context.Background(), err.Error())
|
||||
b.Release()
|
||||
continue
|
||||
}
|
||||
|
@ -290,7 +291,7 @@ func (w *PacketWriter) WriteMultiBuffer(mb buf.MultiBuffer) error {
|
|||
}
|
||||
_, err = conn.WriteTo(b.Bytes(), w.back)
|
||||
if err != nil {
|
||||
newError(err).WriteToLog()
|
||||
errors.LogInfo(context.Background(), err.Error())
|
||||
w.conns[*b.UDP] = nil
|
||||
conn.Close()
|
||||
}
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
package dokodemo
|
||||
|
||||
import "github.com/xtls/xray-core/common/errors"
|
||||
|
||||
type errPathObjHolder struct{}
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).WithPathObj(errPathObjHolder{})
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
package proxy
|
||||
|
||||
import "github.com/xtls/xray-core/common/errors"
|
||||
|
||||
type errPathObjHolder struct{}
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).WithPathObj(errPathObjHolder{})
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
package freedom
|
||||
|
||||
import "github.com/xtls/xray-core/common/errors"
|
||||
|
||||
type errPathObjHolder struct{}
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).WithPathObj(errPathObjHolder{})
|
||||
}
|
|
@ -13,6 +13,7 @@ import (
|
|||
"github.com/xtls/xray-core/common"
|
||||
"github.com/xtls/xray-core/common/buf"
|
||||
"github.com/xtls/xray-core/common/dice"
|
||||
"github.com/xtls/xray-core/common/errors"
|
||||
"github.com/xtls/xray-core/common/net"
|
||||
"github.com/xtls/xray-core/common/platform"
|
||||
"github.com/xtls/xray-core/common/retry"
|
||||
|
@ -87,7 +88,7 @@ func (h *Handler) resolveIP(ctx context.Context, domain string, localAddr net.Ad
|
|||
}
|
||||
}
|
||||
if err != nil {
|
||||
newError("failed to get IP address for domain ", domain).Base(err).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfoInner(ctx, err, "failed to get IP address for domain ", domain)
|
||||
}
|
||||
if len(ips) == 0 {
|
||||
return nil
|
||||
|
@ -107,9 +108,9 @@ func isValidAddress(addr *net.IPOrDomain) bool {
|
|||
// Process implements proxy.Outbound.
|
||||
func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer internet.Dialer) error {
|
||||
outbounds := session.OutboundsFromContext(ctx)
|
||||
ob := outbounds[len(outbounds) - 1]
|
||||
ob := outbounds[len(outbounds)-1]
|
||||
if !ob.Target.IsValid() {
|
||||
return newError("target not specified.")
|
||||
return errors.New("target not specified.")
|
||||
}
|
||||
ob.Name = "freedom"
|
||||
ob.CanSpliceCopy = 1
|
||||
|
@ -143,7 +144,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
|||
Address: ip,
|
||||
Port: dialDest.Port,
|
||||
}
|
||||
newError("dialing to ", dialDest).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfo(ctx, "dialing to ", dialDest)
|
||||
} else if h.config.forceIP() {
|
||||
return dns.ErrEmptyResponse
|
||||
}
|
||||
|
@ -169,10 +170,10 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
|||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return newError("failed to open connection to ", destination).Base(err)
|
||||
return errors.New("failed to open connection to ", destination).Base(err)
|
||||
}
|
||||
defer conn.Close()
|
||||
newError("connection opened to ", destination, ", local endpoint ", conn.LocalAddr(), ", remote endpoint ", conn.RemoteAddr()).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfo(ctx, "connection opened to ", destination, ", local endpoint ", conn.LocalAddr(), ", remote endpoint ", conn.RemoteAddr())
|
||||
|
||||
var newCtx context.Context
|
||||
var newCancel context.CancelFunc
|
||||
|
@ -195,8 +196,8 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
|||
var writer buf.Writer
|
||||
if destination.Network == net.Network_TCP {
|
||||
if h.config.Fragment != nil {
|
||||
newError("FRAGMENT", h.config.Fragment.PacketsFrom, h.config.Fragment.PacketsTo, h.config.Fragment.LengthMin, h.config.Fragment.LengthMax,
|
||||
h.config.Fragment.IntervalMin, h.config.Fragment.IntervalMax).AtDebug().WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogDebug(ctx, "FRAGMENT", h.config.Fragment.PacketsFrom, h.config.Fragment.PacketsTo, h.config.Fragment.LengthMin, h.config.Fragment.LengthMax,
|
||||
h.config.Fragment.IntervalMin, h.config.Fragment.IntervalMax)
|
||||
writer = buf.NewWriter(&FragmentWriter{
|
||||
fragment: h.config.Fragment,
|
||||
writer: conn,
|
||||
|
@ -209,7 +210,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
|||
}
|
||||
|
||||
if err := buf.Copy(input, writer, buf.UpdateActivity(timer)); err != nil {
|
||||
return newError("failed to process request").Base(err)
|
||||
return errors.New("failed to process request").Base(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -228,7 +229,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
|||
}
|
||||
reader := NewPacketReader(conn, UDPOverride)
|
||||
if err := buf.Copy(reader, output, buf.UpdateActivity(timer)); err != nil {
|
||||
return newError("failed to process response").Base(err)
|
||||
return errors.New("failed to process response").Base(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -238,7 +239,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
|||
}
|
||||
|
||||
if err := task.Run(ctx, requestDone, task.OnSuccess(responseDone, task.Close(output))); err != nil {
|
||||
return newError("connection ends").Base(err)
|
||||
return errors.New("connection ends").Base(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -14,6 +14,7 @@ import (
|
|||
"github.com/xtls/xray-core/common"
|
||||
"github.com/xtls/xray-core/common/buf"
|
||||
"github.com/xtls/xray-core/common/bytespool"
|
||||
"github.com/xtls/xray-core/common/errors"
|
||||
"github.com/xtls/xray-core/common/net"
|
||||
"github.com/xtls/xray-core/common/protocol"
|
||||
"github.com/xtls/xray-core/common/retry"
|
||||
|
@ -51,12 +52,12 @@ func NewClient(ctx context.Context, config *ClientConfig) (*Client, error) {
|
|||
for _, rec := range config.Server {
|
||||
s, err := protocol.NewServerSpecFromPB(rec)
|
||||
if err != nil {
|
||||
return nil, newError("failed to get server spec").Base(err)
|
||||
return nil, errors.New("failed to get server spec").Base(err)
|
||||
}
|
||||
serverList.AddServer(s)
|
||||
}
|
||||
if serverList.Size() == 0 {
|
||||
return nil, newError("0 target server")
|
||||
return nil, errors.New("0 target server")
|
||||
}
|
||||
|
||||
v := core.MustFromContext(ctx)
|
||||
|
@ -70,9 +71,9 @@ func NewClient(ctx context.Context, config *ClientConfig) (*Client, error) {
|
|||
// Process implements proxy.Outbound.Process. We first create a socket tunnel via HTTP CONNECT method, then redirect all inbound traffic to that tunnel.
|
||||
func (c *Client) Process(ctx context.Context, link *transport.Link, dialer internet.Dialer) error {
|
||||
outbounds := session.OutboundsFromContext(ctx)
|
||||
ob := outbounds[len(outbounds) - 1]
|
||||
ob := outbounds[len(outbounds)-1]
|
||||
if !ob.Target.IsValid() {
|
||||
return newError("target not specified.")
|
||||
return errors.New("target not specified.")
|
||||
}
|
||||
ob.Name = "http"
|
||||
ob.CanSpliceCopy = 2
|
||||
|
@ -80,7 +81,7 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter
|
|||
targetAddr := target.NetAddr()
|
||||
|
||||
if target.Network == net.Network_UDP {
|
||||
return newError("UDP is not supported by HTTP outbound")
|
||||
return errors.New("UDP is not supported by HTTP outbound")
|
||||
}
|
||||
|
||||
var user *protocol.MemoryUser
|
||||
|
@ -97,7 +98,7 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter
|
|||
|
||||
header, err := fillRequestHeader(ctx, c.header)
|
||||
if err != nil {
|
||||
return newError("failed to fill out header").Base(err)
|
||||
return errors.New("failed to fill out header").Base(err)
|
||||
}
|
||||
|
||||
if err := retry.ExponentialBackoff(5, 100).On(func() error {
|
||||
|
@ -117,12 +118,12 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter
|
|||
}
|
||||
return err
|
||||
}); err != nil {
|
||||
return newError("failed to find an available destination").Base(err)
|
||||
return errors.New("failed to find an available destination").Base(err)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if err := conn.Close(); err != nil {
|
||||
newError("failed to closed connection").Base(err).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfoInner(ctx, err, "failed to closed connection")
|
||||
}
|
||||
}()
|
||||
|
||||
|
@ -160,7 +161,7 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter
|
|||
|
||||
responseDonePost := task.OnSuccess(responseFunc, task.Close(link.Writer))
|
||||
if err := task.Run(ctx, requestFunc, responseDonePost); err != nil {
|
||||
return newError("connection ends").Base(err)
|
||||
return errors.New("connection ends").Base(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -174,10 +175,10 @@ func fillRequestHeader(ctx context.Context, header []*Header) ([]*Header, error)
|
|||
|
||||
inbound := session.InboundFromContext(ctx)
|
||||
outbounds := session.OutboundsFromContext(ctx)
|
||||
ob := outbounds[len(outbounds) - 1]
|
||||
ob := outbounds[len(outbounds)-1]
|
||||
|
||||
if inbound == nil || ob == nil {
|
||||
return nil, newError("missing inbound or outbound metadata from context")
|
||||
return nil, errors.New("missing inbound or outbound metadata from context")
|
||||
}
|
||||
|
||||
data := struct {
|
||||
|
@ -242,7 +243,7 @@ func setUpHTTPTunnel(ctx context.Context, dest net.Destination, target string, u
|
|||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
rawConn.Close()
|
||||
return nil, newError("Proxy responded with non 200 code: " + resp.Status)
|
||||
return nil, errors.New("Proxy responded with non 200 code: " + resp.Status)
|
||||
}
|
||||
return rawConn, nil
|
||||
}
|
||||
|
@ -274,7 +275,7 @@ func setUpHTTPTunnel(ctx context.Context, dest net.Destination, target string, u
|
|||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
rawConn.Close()
|
||||
return nil, newError("Proxy responded with non 200 code: " + resp.Status)
|
||||
return nil, errors.New("Proxy responded with non 200 code: " + resp.Status)
|
||||
}
|
||||
return newHTTP2Conn(rawConn, pw, resp.Body), nil
|
||||
}
|
||||
|
@ -344,7 +345,7 @@ func setUpHTTPTunnel(ctx context.Context, dest net.Destination, target string, u
|
|||
|
||||
return proxyConn, err
|
||||
default:
|
||||
return nil, newError("negotiated unsupported application layer protocol: " + nextProto)
|
||||
return nil, errors.New("negotiated unsupported application layer protocol: " + nextProto)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
package http
|
||||
|
||||
import "github.com/xtls/xray-core/common/errors"
|
||||
|
||||
type errPathObjHolder struct{}
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).WithPathObj(errPathObjHolder{})
|
||||
}
|
|
@ -94,12 +94,12 @@ func (s *Server) Process(ctx context.Context, network net.Network, conn stat.Con
|
|||
|
||||
Start:
|
||||
if err := conn.SetReadDeadline(time.Now().Add(s.policy().Timeouts.Handshake)); err != nil {
|
||||
newError("failed to set read deadline").Base(err).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfoInner(ctx, err, "failed to set read deadline")
|
||||
}
|
||||
|
||||
request, err := http.ReadRequest(reader)
|
||||
if err != nil {
|
||||
trace := newError("failed to read http request").Base(err)
|
||||
trace := errors.New("failed to read http request").Base(err)
|
||||
if errors.Cause(err) != io.EOF && !isTimeout(errors.Cause(err)) {
|
||||
trace.AtWarning()
|
||||
}
|
||||
|
@ -116,9 +116,9 @@ Start:
|
|||
}
|
||||
}
|
||||
|
||||
newError("request to Method [", request.Method, "] Host [", request.Host, "] with URL [", request.URL, "]").WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfo(ctx, "request to Method [", request.Method, "] Host [", request.Host, "] with URL [", request.URL, "]")
|
||||
if err := conn.SetReadDeadline(time.Time{}); err != nil {
|
||||
newError("failed to clear read deadline").Base(err).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogDebugInner(ctx, err, "failed to clear read deadline")
|
||||
}
|
||||
|
||||
defaultPort := net.Port(80)
|
||||
|
@ -131,7 +131,7 @@ Start:
|
|||
}
|
||||
dest, err := http_proto.ParseHost(host, defaultPort)
|
||||
if err != nil {
|
||||
return newError("malformed proxy host: ", host).AtWarning().Base(err)
|
||||
return errors.New("malformed proxy host: ", host).AtWarning().Base(err)
|
||||
}
|
||||
ctx = log.ContextWithAccessMessage(ctx, &log.AccessMessage{
|
||||
From: conn.RemoteAddr(),
|
||||
|
@ -160,7 +160,7 @@ Start:
|
|||
func (s *Server) handleConnect(ctx context.Context, _ *http.Request, reader *bufio.Reader, conn stat.Connection, dest net.Destination, dispatcher routing.Dispatcher, inbound *session.Inbound) error {
|
||||
_, err := conn.Write([]byte("HTTP/1.1 200 Connection established\r\n\r\n"))
|
||||
if err != nil {
|
||||
return newError("failed to write back OK response").Base(err)
|
||||
return errors.New("failed to write back OK response").Base(err)
|
||||
}
|
||||
|
||||
plcy := s.policy()
|
||||
|
@ -209,13 +209,13 @@ func (s *Server) handleConnect(ctx context.Context, _ *http.Request, reader *buf
|
|||
if err := task.Run(ctx, closeWriter, responseDone); err != nil {
|
||||
common.Interrupt(link.Reader)
|
||||
common.Interrupt(link.Writer)
|
||||
return newError("connection ends").Base(err)
|
||||
return errors.New("connection ends").Base(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var errWaitAnother = newError("keep alive")
|
||||
var errWaitAnother = errors.New("keep alive")
|
||||
|
||||
func (s *Server) handlePlainHTTP(ctx context.Context, request *http.Request, writer io.Writer, dest net.Destination, dispatcher routing.Dispatcher) error {
|
||||
if !s.config.AllowTransparent && request.URL.Host == "" {
|
||||
|
@ -274,7 +274,7 @@ func (s *Server) handlePlainHTTP(ctx context.Context, request *http.Request, wri
|
|||
requestWriter := buf.NewBufferedWriter(link.Writer)
|
||||
common.Must(requestWriter.SetBuffered(false))
|
||||
if err := request.Write(requestWriter); err != nil {
|
||||
return newError("failed to write whole request").Base(err).AtWarning()
|
||||
return errors.New("failed to write whole request").Base(err).AtWarning()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -295,7 +295,7 @@ func (s *Server) handlePlainHTTP(ctx context.Context, request *http.Request, wri
|
|||
}
|
||||
defer response.Body.Close()
|
||||
} else {
|
||||
newError("failed to read response from ", request.Host).Base(err).AtWarning().WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogWarningInner(ctx, err, "failed to read response from ", request.Host)
|
||||
response = &http.Response{
|
||||
Status: "Service Unavailable",
|
||||
StatusCode: 503,
|
||||
|
@ -311,7 +311,7 @@ func (s *Server) handlePlainHTTP(ctx context.Context, request *http.Request, wri
|
|||
response.Header.Set("Proxy-Connection", "close")
|
||||
}
|
||||
if err := response.Write(writer); err != nil {
|
||||
return newError("failed to write response").Base(err).AtWarning()
|
||||
return errors.New("failed to write response").Base(err).AtWarning()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -319,7 +319,7 @@ func (s *Server) handlePlainHTTP(ctx context.Context, request *http.Request, wri
|
|||
if err := task.Run(ctx, requestDone, responseDone); err != nil {
|
||||
common.Interrupt(link.Reader)
|
||||
common.Interrupt(link.Writer)
|
||||
return newError("connection ends").Base(err)
|
||||
return errors.New("connection ends").Base(err)
|
||||
}
|
||||
|
||||
return result
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
package loopback
|
||||
|
||||
import "github.com/xtls/xray-core/common/errors"
|
||||
|
||||
type errPathObjHolder struct{}
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).WithPathObj(errPathObjHolder{})
|
||||
}
|
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
"github.com/xtls/xray-core/common"
|
||||
"github.com/xtls/xray-core/common/buf"
|
||||
"github.com/xtls/xray-core/common/errors"
|
||||
"github.com/xtls/xray-core/common/net"
|
||||
"github.com/xtls/xray-core/common/net/cnc"
|
||||
"github.com/xtls/xray-core/common/retry"
|
||||
|
@ -23,14 +24,14 @@ type Loopback struct {
|
|||
|
||||
func (l *Loopback) Process(ctx context.Context, link *transport.Link, _ internet.Dialer) error {
|
||||
outbounds := session.OutboundsFromContext(ctx)
|
||||
ob := outbounds[len(outbounds) - 1]
|
||||
ob := outbounds[len(outbounds)-1]
|
||||
if !ob.Target.IsValid() {
|
||||
return newError("target not specified.")
|
||||
return errors.New("target not specified.")
|
||||
}
|
||||
ob.Name = "loopback"
|
||||
destination := ob.Target
|
||||
|
||||
newError("opening connection to ", destination).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfo(ctx, "opening connection to ", destination)
|
||||
|
||||
input := link.Reader
|
||||
output := link.Writer
|
||||
|
@ -66,7 +67,7 @@ func (l *Loopback) Process(ctx context.Context, link *transport.Link, _ internet
|
|||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return newError("failed to open connection to ", destination).Base(err)
|
||||
return errors.New("failed to open connection to ", destination).Base(err)
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
|
@ -79,7 +80,7 @@ func (l *Loopback) Process(ctx context.Context, link *transport.Link, _ internet
|
|||
}
|
||||
|
||||
if err := buf.Copy(input, writer); err != nil {
|
||||
return newError("failed to process request").Base(err)
|
||||
return errors.New("failed to process request").Base(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -93,14 +94,14 @@ func (l *Loopback) Process(ctx context.Context, link *transport.Link, _ internet
|
|||
reader = buf.NewPacketReader(conn)
|
||||
}
|
||||
if err := buf.Copy(reader, output); err != nil {
|
||||
return newError("failed to process response").Base(err)
|
||||
return errors.New("failed to process response").Base(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := task.Run(ctx, requestDone, task.OnSuccess(responseDone, task.Close(output))); err != nil {
|
||||
return newError("connection ends").Base(err)
|
||||
return errors.New("connection ends").Base(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -102,7 +102,7 @@ type TrafficState struct {
|
|||
// reader link state
|
||||
WithinPaddingBuffers bool
|
||||
ReaderSwitchToDirectCopy bool
|
||||
RemainingCommand int32
|
||||
RemainingCommand int32
|
||||
RemainingContent int32
|
||||
RemainingPadding int32
|
||||
CurrentCommand int
|
||||
|
@ -168,7 +168,7 @@ func (w *VisionReader) ReadMultiBuffer() (buf.MultiBuffer, error) {
|
|||
w.trafficState.WithinPaddingBuffers = false
|
||||
w.trafficState.ReaderSwitchToDirectCopy = true
|
||||
} else {
|
||||
newError("XtlsRead unknown command ", w.trafficState.CurrentCommand, buffer.Len()).WriteToLog(session.ExportIDToError(w.ctx))
|
||||
errors.LogInfo(w.ctx, "XtlsRead unknown command ", w.trafficState.CurrentCommand, buffer.Len())
|
||||
}
|
||||
}
|
||||
if w.trafficState.NumberOfPacketToFilter > 0 {
|
||||
|
@ -215,7 +215,7 @@ func (w *VisionWriter) WriteMultiBuffer(mb buf.MultiBuffer) error {
|
|||
w.trafficState.WriterSwitchToDirectCopy = true
|
||||
}
|
||||
var command byte = CommandPaddingContinue
|
||||
if i == len(mb) - 1 {
|
||||
if i == len(mb)-1 {
|
||||
command = CommandPaddingEnd
|
||||
if w.trafficState.EnableXtls {
|
||||
command = CommandPaddingDirect
|
||||
|
@ -231,7 +231,7 @@ func (w *VisionWriter) WriteMultiBuffer(mb buf.MultiBuffer) error {
|
|||
break
|
||||
}
|
||||
var command byte = CommandPaddingContinue
|
||||
if i == len(mb) - 1 && !w.trafficState.IsPadding {
|
||||
if i == len(mb)-1 && !w.trafficState.IsPadding {
|
||||
command = CommandPaddingEnd
|
||||
if w.trafficState.EnableXtls {
|
||||
command = CommandPaddingDirect
|
||||
|
@ -274,7 +274,7 @@ func ReshapeMultiBuffer(ctx context.Context, buffer buf.MultiBuffer) buf.MultiBu
|
|||
buffer[i] = nil
|
||||
}
|
||||
buffer = buffer[:0]
|
||||
newError("ReshapeMultiBuffer ", toPrint).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfo(ctx, "ReshapeMultiBuffer ", toPrint)
|
||||
return mb2
|
||||
}
|
||||
|
||||
|
@ -288,13 +288,13 @@ func XtlsPadding(b *buf.Buffer, command byte, userUUID *[]byte, longPadding bool
|
|||
if contentLen < 900 && longPadding {
|
||||
l, err := rand.Int(rand.Reader, big.NewInt(500))
|
||||
if err != nil {
|
||||
newError("failed to generate padding").Base(err).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogDebugInner(ctx, err, "failed to generate padding")
|
||||
}
|
||||
paddingLen = int32(l.Int64()) + 900 - contentLen
|
||||
} else {
|
||||
l, err := rand.Int(rand.Reader, big.NewInt(256))
|
||||
if err != nil {
|
||||
newError("failed to generate padding").Base(err).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogDebugInner(ctx, err, "failed to generate padding")
|
||||
}
|
||||
paddingLen = int32(l.Int64())
|
||||
}
|
||||
|
@ -313,7 +313,7 @@ func XtlsPadding(b *buf.Buffer, command byte, userUUID *[]byte, longPadding bool
|
|||
b = nil
|
||||
}
|
||||
newbuffer.Extend(paddingLen)
|
||||
newError("XtlsPadding ", contentLen, " ", paddingLen, " ", command).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfo(ctx, "XtlsPadding ", contentLen, " ", paddingLen, " ", command)
|
||||
return newbuffer
|
||||
}
|
||||
|
||||
|
@ -338,14 +338,14 @@ func XtlsUnpadding(b *buf.Buffer, s *TrafficState, ctx context.Context) *buf.Buf
|
|||
case 5:
|
||||
s.CurrentCommand = int(data)
|
||||
case 4:
|
||||
s.RemainingContent = int32(data)<<8
|
||||
s.RemainingContent = int32(data) << 8
|
||||
case 3:
|
||||
s.RemainingContent = s.RemainingContent | int32(data)
|
||||
case 2:
|
||||
s.RemainingPadding = int32(data)<<8
|
||||
s.RemainingPadding = int32(data) << 8
|
||||
case 1:
|
||||
s.RemainingPadding = s.RemainingPadding | int32(data)
|
||||
newError("Xtls Unpadding new block, content ", s.RemainingContent, " padding ", s.RemainingPadding, " command ", s.CurrentCommand).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfo(ctx, "Xtls Unpadding new block, content ", s.RemainingContent, " padding ", s.RemainingPadding, " command ", s.CurrentCommand)
|
||||
}
|
||||
s.RemainingCommand--
|
||||
} else if s.RemainingContent > 0 {
|
||||
|
@ -404,11 +404,11 @@ func XtlsFilterTls(buffer buf.MultiBuffer, trafficState *TrafficState, ctx conte
|
|||
cipherSuite := b.BytesRange(43+sessionIdLen+1, 43+sessionIdLen+3)
|
||||
trafficState.Cipher = uint16(cipherSuite[0])<<8 | uint16(cipherSuite[1])
|
||||
} else {
|
||||
newError("XtlsFilterTls short server hello, tls 1.2 or older? ", b.Len(), " ", trafficState.RemainingServerHello).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfo(ctx, "XtlsFilterTls short server hello, tls 1.2 or older? ", b.Len(), " ", trafficState.RemainingServerHello)
|
||||
}
|
||||
} else if bytes.Equal(TlsClientHandShakeStart, startsBytes[:2]) && startsBytes[5] == TlsHandshakeTypeClientHello {
|
||||
trafficState.IsTLS = true
|
||||
newError("XtlsFilterTls found tls client hello! ", buffer.Len()).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfo(ctx, "XtlsFilterTls found tls client hello! ", buffer.Len())
|
||||
}
|
||||
}
|
||||
if trafficState.RemainingServerHello > 0 {
|
||||
|
@ -424,18 +424,18 @@ func XtlsFilterTls(buffer buf.MultiBuffer, trafficState *TrafficState, ctx conte
|
|||
} else if v != "TLS_AES_128_CCM_8_SHA256" {
|
||||
trafficState.EnableXtls = true
|
||||
}
|
||||
newError("XtlsFilterTls found tls 1.3! ", b.Len(), " ", v).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfo(ctx, "XtlsFilterTls found tls 1.3! ", b.Len(), " ", v)
|
||||
trafficState.NumberOfPacketToFilter = 0
|
||||
return
|
||||
} else if trafficState.RemainingServerHello <= 0 {
|
||||
newError("XtlsFilterTls found tls 1.2! ", b.Len()).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfo(ctx, "XtlsFilterTls found tls 1.2! ", b.Len())
|
||||
trafficState.NumberOfPacketToFilter = 0
|
||||
return
|
||||
}
|
||||
newError("XtlsFilterTls inconclusive server hello ", b.Len(), " ", trafficState.RemainingServerHello).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfo(ctx, "XtlsFilterTls inconclusive server hello ", b.Len(), " ", trafficState.RemainingServerHello)
|
||||
}
|
||||
if trafficState.NumberOfPacketToFilter <= 0 {
|
||||
newError("XtlsFilterTls stop filtering", buffer.Len()).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfo(ctx, "XtlsFilterTls stop filtering", buffer.Len())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -505,10 +505,10 @@ func CopyRawConnIfExist(ctx context.Context, readerConn net.Conn, writerConn net
|
|||
}
|
||||
}
|
||||
if splice {
|
||||
newError("CopyRawConn splice").WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfo(ctx, "CopyRawConn splice")
|
||||
statWriter, _ := writer.(*dispatcher.SizeStatWriter)
|
||||
//runtime.Gosched() // necessary
|
||||
time.Sleep(time.Millisecond) // without this, there will be a rare ssl error for freedom splice
|
||||
time.Sleep(time.Millisecond) // without this, there will be a rare ssl error for freedom splice
|
||||
timer.SetTimeout(8 * time.Hour) // prevent leak, just in case
|
||||
if inTimer != nil {
|
||||
inTimer.SetTimeout(8 * time.Hour)
|
||||
|
@ -545,9 +545,9 @@ func CopyRawConnIfExist(ctx context.Context, readerConn net.Conn, writerConn net
|
|||
}
|
||||
|
||||
func readV(ctx context.Context, reader buf.Reader, writer buf.Writer, timer signal.ActivityUpdater, readCounter stats.Counter) error {
|
||||
newError("CopyRawConn readv").WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfo(ctx, "CopyRawConn readv")
|
||||
if err := buf.Copy(reader, writer, buf.UpdateActivity(timer), buf.AddToStatCounter(readCounter)); err != nil {
|
||||
return newError("failed to process response").Base(err)
|
||||
return errors.New("failed to process response").Base(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
|
||||
"github.com/xtls/xray-core/common"
|
||||
"github.com/xtls/xray-core/common/buf"
|
||||
"github.com/xtls/xray-core/common/errors"
|
||||
"github.com/xtls/xray-core/common/net"
|
||||
"github.com/xtls/xray-core/common/protocol"
|
||||
"github.com/xtls/xray-core/common/retry"
|
||||
|
@ -31,12 +32,12 @@ func NewClient(ctx context.Context, config *ClientConfig) (*Client, error) {
|
|||
for _, rec := range config.Server {
|
||||
s, err := protocol.NewServerSpecFromPB(rec)
|
||||
if err != nil {
|
||||
return nil, newError("failed to parse server spec").Base(err)
|
||||
return nil, errors.New("failed to parse server spec").Base(err)
|
||||
}
|
||||
serverList.AddServer(s)
|
||||
}
|
||||
if serverList.Size() == 0 {
|
||||
return nil, newError("0 server")
|
||||
return nil, errors.New("0 server")
|
||||
}
|
||||
|
||||
v := core.MustFromContext(ctx)
|
||||
|
@ -50,9 +51,9 @@ func NewClient(ctx context.Context, config *ClientConfig) (*Client, error) {
|
|||
// Process implements OutboundHandler.Process().
|
||||
func (c *Client) Process(ctx context.Context, link *transport.Link, dialer internet.Dialer) error {
|
||||
outbounds := session.OutboundsFromContext(ctx)
|
||||
ob := outbounds[len(outbounds) - 1]
|
||||
ob := outbounds[len(outbounds)-1]
|
||||
if !ob.Target.IsValid() {
|
||||
return newError("target not specified")
|
||||
return errors.New("target not specified")
|
||||
}
|
||||
ob.Name = "shadowsocks"
|
||||
ob.CanSpliceCopy = 3
|
||||
|
@ -75,9 +76,9 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter
|
|||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return newError("failed to find an available destination").AtWarning().Base(err)
|
||||
return errors.New("failed to find an available destination").AtWarning().Base(err)
|
||||
}
|
||||
newError("tunneling request to ", destination, " via ", network, ":", server.Destination().NetAddr()).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfo(ctx, "tunneling request to ", destination, " via ", network, ":", server.Destination().NetAddr())
|
||||
|
||||
defer conn.Close()
|
||||
|
||||
|
@ -95,7 +96,7 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter
|
|||
user := server.PickUser()
|
||||
_, ok := user.Account.(*MemoryAccount)
|
||||
if !ok {
|
||||
return newError("user account is not valid")
|
||||
return errors.New("user account is not valid")
|
||||
}
|
||||
request.User = user
|
||||
|
||||
|
@ -124,11 +125,11 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter
|
|||
bufferedWriter := buf.NewBufferedWriter(buf.NewWriter(conn))
|
||||
bodyWriter, err := WriteTCPRequest(request, bufferedWriter)
|
||||
if err != nil {
|
||||
return newError("failed to write request").Base(err)
|
||||
return errors.New("failed to write request").Base(err)
|
||||
}
|
||||
|
||||
if err = buf.CopyOnceTimeout(link.Reader, bodyWriter, time.Millisecond*100); err != nil && err != buf.ErrNotTimeoutReader && err != buf.ErrReadTimeout {
|
||||
return newError("failed to write A request payload").Base(err).AtWarning()
|
||||
return errors.New("failed to write A request payload").Base(err).AtWarning()
|
||||
}
|
||||
|
||||
if err := bufferedWriter.SetBuffered(false); err != nil {
|
||||
|
@ -151,7 +152,7 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter
|
|||
|
||||
responseDoneAndCloseWriter := task.OnSuccess(responseDone, task.Close(link.Writer))
|
||||
if err := task.Run(ctx, requestDone, responseDoneAndCloseWriter); err != nil {
|
||||
return newError("connection ends").Base(err)
|
||||
return errors.New("connection ends").Base(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -168,7 +169,7 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter
|
|||
}
|
||||
|
||||
if err := buf.Copy(link.Reader, writer, buf.UpdateActivity(timer)); err != nil {
|
||||
return newError("failed to transport all UDP request").Base(err)
|
||||
return errors.New("failed to transport all UDP request").Base(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -182,14 +183,14 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter
|
|||
}
|
||||
|
||||
if err := buf.Copy(reader, link.Writer, buf.UpdateActivity(timer)); err != nil {
|
||||
return newError("failed to transport all UDP response").Base(err)
|
||||
return errors.New("failed to transport all UDP response").Base(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
responseDoneAndCloseWriter := task.OnSuccess(responseDone, task.Close(link.Writer))
|
||||
if err := task.Run(ctx, requestDone, responseDoneAndCloseWriter); err != nil {
|
||||
return newError("connection ends").Base(err)
|
||||
return errors.New("connection ends").Base(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
"github.com/xtls/xray-core/common/antireplay"
|
||||
"github.com/xtls/xray-core/common/buf"
|
||||
"github.com/xtls/xray-core/common/crypto"
|
||||
"github.com/xtls/xray-core/common/errors"
|
||||
"github.com/xtls/xray-core/common/protocol"
|
||||
"golang.org/x/crypto/chacha20poly1305"
|
||||
"golang.org/x/crypto/hkdf"
|
||||
|
@ -25,7 +26,7 @@ type MemoryAccount struct {
|
|||
replayFilter antireplay.GeneralizedReplayFilter
|
||||
}
|
||||
|
||||
var ErrIVNotUnique = newError("IV is not unique")
|
||||
var ErrIVNotUnique = errors.New("IV is not unique")
|
||||
|
||||
// Equals implements protocol.Account.Equals().
|
||||
func (a *MemoryAccount) Equals(another protocol.Account) bool {
|
||||
|
@ -94,7 +95,7 @@ func (a *Account) getCipher() (Cipher, error) {
|
|||
case CipherType_NONE:
|
||||
return NoneCipher{}, nil
|
||||
default:
|
||||
return nil, newError("Unsupported cipher.")
|
||||
return nil, errors.New("Unsupported cipher.")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,7 +103,7 @@ func (a *Account) getCipher() (Cipher, error) {
|
|||
func (a *Account) AsAccount() (protocol.Account, error) {
|
||||
Cipher, err := a.getCipher()
|
||||
if err != nil {
|
||||
return nil, newError("failed to get cipher").Base(err)
|
||||
return nil, errors.New("failed to get cipher").Base(err)
|
||||
}
|
||||
return &MemoryAccount{
|
||||
Cipher: Cipher,
|
||||
|
@ -182,7 +183,7 @@ func (c *AEADCipher) EncodePacket(key []byte, b *buf.Buffer) error {
|
|||
|
||||
func (c *AEADCipher) DecodePacket(key []byte, b *buf.Buffer) error {
|
||||
if b.Len() <= c.IVSize() {
|
||||
return newError("insufficient data: ", b.Len())
|
||||
return errors.New("insufficient data: ", b.Len())
|
||||
}
|
||||
ivLen := c.IVSize()
|
||||
payloadLen := b.Len()
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
package shadowsocks
|
||||
|
||||
import "github.com/xtls/xray-core/common/errors"
|
||||
|
||||
type errPathObjHolder struct{}
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).WithPathObj(errPathObjHolder{})
|
||||
}
|
|
@ -4,12 +4,13 @@ import (
|
|||
"crypto/hmac"
|
||||
"crypto/rand"
|
||||
"crypto/sha256"
|
||||
"errors"
|
||||
goerrors "errors"
|
||||
"hash/crc32"
|
||||
"io"
|
||||
|
||||
"github.com/xtls/xray-core/common"
|
||||
"github.com/xtls/xray-core/common/buf"
|
||||
"github.com/xtls/xray-core/common/errors"
|
||||
"github.com/xtls/xray-core/common/crypto"
|
||||
"github.com/xtls/xray-core/common/drain"
|
||||
"github.com/xtls/xray-core/common/net"
|
||||
|
@ -58,7 +59,7 @@ func ReadTCPSession(validator *Validator, reader io.Reader) (*protocol.RequestHe
|
|||
drainer, errDrain := drain.NewBehaviorSeedLimitedDrainer(int64(behaviorSeed), 16+38, 3266, 64)
|
||||
|
||||
if errDrain != nil {
|
||||
return nil, nil, newError("failed to initialize drainer").Base(errDrain)
|
||||
return nil, nil, errors.New("failed to initialize drainer").Base(errDrain)
|
||||
}
|
||||
|
||||
var r buf.Reader
|
||||
|
@ -67,7 +68,7 @@ func ReadTCPSession(validator *Validator, reader io.Reader) (*protocol.RequestHe
|
|||
|
||||
if _, err := buffer.ReadFullFrom(reader, 50); err != nil {
|
||||
drainer.AcknowledgeReceive(int(buffer.Len()))
|
||||
return nil, nil, drain.WithError(drainer, reader, newError("failed to read 50 bytes").Base(err))
|
||||
return nil, nil, drain.WithError(drainer, reader, errors.New("failed to read 50 bytes").Base(err))
|
||||
}
|
||||
|
||||
bs := buffer.Bytes()
|
||||
|
@ -76,10 +77,10 @@ func ReadTCPSession(validator *Validator, reader io.Reader) (*protocol.RequestHe
|
|||
switch err {
|
||||
case ErrNotFound:
|
||||
drainer.AcknowledgeReceive(int(buffer.Len()))
|
||||
return nil, nil, drain.WithError(drainer, reader, newError("failed to match an user").Base(err))
|
||||
return nil, nil, drain.WithError(drainer, reader, errors.New("failed to match an user").Base(err))
|
||||
case ErrIVNotUnique:
|
||||
drainer.AcknowledgeReceive(int(buffer.Len()))
|
||||
return nil, nil, drain.WithError(drainer, reader, newError("failed iv check").Base(err))
|
||||
return nil, nil, drain.WithError(drainer, reader, errors.New("failed iv check").Base(err))
|
||||
default:
|
||||
reader = &FullReader{reader, bs[ivLen:]}
|
||||
drainer.AcknowledgeReceive(int(ivLen))
|
||||
|
@ -97,7 +98,7 @@ func ReadTCPSession(validator *Validator, reader io.Reader) (*protocol.RequestHe
|
|||
iv := append([]byte(nil), buffer.BytesTo(ivLen)...)
|
||||
r, err = account.Cipher.NewDecryptionReader(account.Key, iv, reader)
|
||||
if err != nil {
|
||||
return nil, nil, drain.WithError(drainer, reader, newError("failed to initialize decoding stream").Base(err).AtError())
|
||||
return nil, nil, drain.WithError(drainer, reader, errors.New("failed to initialize decoding stream").Base(err).AtError())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -115,7 +116,7 @@ func ReadTCPSession(validator *Validator, reader io.Reader) (*protocol.RequestHe
|
|||
addr, port, err := addrParser.ReadAddressPort(buffer, br)
|
||||
if err != nil {
|
||||
drainer.AcknowledgeReceive(int(buffer.Len()))
|
||||
return nil, nil, drain.WithError(drainer, reader, newError("failed to read address").Base(err))
|
||||
return nil, nil, drain.WithError(drainer, reader, errors.New("failed to read address").Base(err))
|
||||
}
|
||||
|
||||
request.Address = addr
|
||||
|
@ -123,7 +124,7 @@ func ReadTCPSession(validator *Validator, reader io.Reader) (*protocol.RequestHe
|
|||
|
||||
if request.Address == nil {
|
||||
drainer.AcknowledgeReceive(int(buffer.Len()))
|
||||
return nil, nil, drain.WithError(drainer, reader, newError("invalid remote address."))
|
||||
return nil, nil, drain.WithError(drainer, reader, errors.New("invalid remote address."))
|
||||
}
|
||||
|
||||
return request, br, nil
|
||||
|
@ -139,26 +140,26 @@ func WriteTCPRequest(request *protocol.RequestHeader, writer io.Writer) (buf.Wri
|
|||
iv = make([]byte, account.Cipher.IVSize())
|
||||
common.Must2(rand.Read(iv))
|
||||
if ivError := account.CheckIV(iv); ivError != nil {
|
||||
return nil, newError("failed to mark outgoing iv").Base(ivError)
|
||||
return nil, errors.New("failed to mark outgoing iv").Base(ivError)
|
||||
}
|
||||
if err := buf.WriteAllBytes(writer, iv, nil); err != nil {
|
||||
return nil, newError("failed to write IV")
|
||||
return nil, errors.New("failed to write IV")
|
||||
}
|
||||
}
|
||||
|
||||
w, err := account.Cipher.NewEncryptionWriter(account.Key, iv, writer)
|
||||
if err != nil {
|
||||
return nil, newError("failed to create encoding stream").Base(err).AtError()
|
||||
return nil, errors.New("failed to create encoding stream").Base(err).AtError()
|
||||
}
|
||||
|
||||
header := buf.New()
|
||||
|
||||
if err := addrParser.WriteAddressPort(header, request.Address, request.Port); err != nil {
|
||||
return nil, newError("failed to write address").Base(err)
|
||||
return nil, errors.New("failed to write address").Base(err)
|
||||
}
|
||||
|
||||
if err := w.WriteMultiBuffer(buf.MultiBuffer{header}); err != nil {
|
||||
return nil, newError("failed to write header").Base(err)
|
||||
return nil, errors.New("failed to write header").Base(err)
|
||||
}
|
||||
|
||||
return w, nil
|
||||
|
@ -174,21 +175,21 @@ func ReadTCPResponse(user *protocol.MemoryUser, reader io.Reader) (buf.Reader, e
|
|||
|
||||
drainer, err := drain.NewBehaviorSeedLimitedDrainer(int64(behaviorSeed), 16+38, 3266, 64)
|
||||
if err != nil {
|
||||
return nil, newError("failed to initialize drainer").Base(err)
|
||||
return nil, errors.New("failed to initialize drainer").Base(err)
|
||||
}
|
||||
|
||||
var iv []byte
|
||||
if account.Cipher.IVSize() > 0 {
|
||||
iv = make([]byte, account.Cipher.IVSize())
|
||||
if n, err := io.ReadFull(reader, iv); err != nil {
|
||||
return nil, newError("failed to read IV").Base(err)
|
||||
return nil, errors.New("failed to read IV").Base(err)
|
||||
} else { // nolint: golint
|
||||
drainer.AcknowledgeReceive(n)
|
||||
}
|
||||
}
|
||||
|
||||
if ivError := account.CheckIV(iv); ivError != nil {
|
||||
return nil, drain.WithError(drainer, reader, newError("failed iv check").Base(ivError))
|
||||
return nil, drain.WithError(drainer, reader, errors.New("failed iv check").Base(ivError))
|
||||
}
|
||||
|
||||
return account.Cipher.NewDecryptionReader(account.Key, iv, reader)
|
||||
|
@ -203,10 +204,10 @@ func WriteTCPResponse(request *protocol.RequestHeader, writer io.Writer) (buf.Wr
|
|||
iv = make([]byte, account.Cipher.IVSize())
|
||||
common.Must2(rand.Read(iv))
|
||||
if ivError := account.CheckIV(iv); ivError != nil {
|
||||
return nil, newError("failed to mark outgoing iv").Base(ivError)
|
||||
return nil, errors.New("failed to mark outgoing iv").Base(ivError)
|
||||
}
|
||||
if err := buf.WriteAllBytes(writer, iv, nil); err != nil {
|
||||
return nil, newError("failed to write IV.").Base(err)
|
||||
return nil, errors.New("failed to write IV.").Base(err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -224,13 +225,13 @@ func EncodeUDPPacket(request *protocol.RequestHeader, payload []byte) (*buf.Buff
|
|||
}
|
||||
|
||||
if err := addrParser.WriteAddressPort(buffer, request.Address, request.Port); err != nil {
|
||||
return nil, newError("failed to write address").Base(err)
|
||||
return nil, errors.New("failed to write address").Base(err)
|
||||
}
|
||||
|
||||
buffer.Write(payload)
|
||||
|
||||
if err := account.Cipher.EncodePacket(account.Key, buffer); err != nil {
|
||||
return nil, newError("failed to encrypt UDP payload").Base(err)
|
||||
return nil, errors.New("failed to encrypt UDP payload").Base(err)
|
||||
}
|
||||
|
||||
return buffer, nil
|
||||
|
@ -240,21 +241,21 @@ func DecodeUDPPacket(validator *Validator, payload *buf.Buffer) (*protocol.Reque
|
|||
rawPayload := payload.Bytes()
|
||||
user, _, d, _, err := validator.Get(rawPayload, protocol.RequestCommandUDP)
|
||||
|
||||
if errors.Is(err, ErrIVNotUnique) {
|
||||
return nil, nil, newError("failed iv check").Base(err)
|
||||
if goerrors.Is(err, ErrIVNotUnique) {
|
||||
return nil, nil, errors.New("failed iv check").Base(err)
|
||||
}
|
||||
|
||||
if errors.Is(err, ErrNotFound) {
|
||||
return nil, nil, newError("failed to match an user").Base(err)
|
||||
if goerrors.Is(err, ErrNotFound) {
|
||||
return nil, nil, errors.New("failed to match an user").Base(err)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, nil, newError("unexpected error").Base(err)
|
||||
return nil, nil, errors.New("unexpected error").Base(err)
|
||||
}
|
||||
|
||||
account, ok := user.Account.(*MemoryAccount)
|
||||
if !ok {
|
||||
return nil, nil, newError("expected MemoryAccount returned from validator")
|
||||
return nil, nil, errors.New("expected MemoryAccount returned from validator")
|
||||
}
|
||||
|
||||
if account.Cipher.IsAEAD() {
|
||||
|
@ -266,7 +267,7 @@ func DecodeUDPPacket(validator *Validator, payload *buf.Buffer) (*protocol.Reque
|
|||
copy(iv, payload.BytesTo(account.Cipher.IVSize()))
|
||||
}
|
||||
if err = account.Cipher.DecodePacket(account.Key, payload); err != nil {
|
||||
return nil, nil, newError("failed to decrypt UDP payload").Base(err)
|
||||
return nil, nil, errors.New("failed to decrypt UDP payload").Base(err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -274,7 +275,7 @@ func DecodeUDPPacket(validator *Validator, payload *buf.Buffer) (*protocol.Reque
|
|||
|
||||
addr, port, err := addrParser.ReadAddressPort(nil, payload)
|
||||
if err != nil {
|
||||
return nil, nil, newError("failed to parse address").Base(err)
|
||||
return nil, nil, errors.New("failed to parse address").Base(err)
|
||||
}
|
||||
|
||||
request := &protocol.RequestHeader{
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
|
||||
"github.com/xtls/xray-core/common"
|
||||
"github.com/xtls/xray-core/common/buf"
|
||||
"github.com/xtls/xray-core/common/errors"
|
||||
"github.com/xtls/xray-core/common/log"
|
||||
"github.com/xtls/xray-core/common/net"
|
||||
"github.com/xtls/xray-core/common/protocol"
|
||||
|
@ -33,11 +34,11 @@ func NewServer(ctx context.Context, config *ServerConfig) (*Server, error) {
|
|||
for _, user := range config.Users {
|
||||
u, err := user.ToMemoryUser()
|
||||
if err != nil {
|
||||
return nil, newError("failed to get shadowsocks user").Base(err).AtError()
|
||||
return nil, errors.New("failed to get shadowsocks user").Base(err).AtError()
|
||||
}
|
||||
|
||||
if err := validator.Add(u); err != nil {
|
||||
return nil, newError("failed to add user").Base(err).AtError()
|
||||
return nil, errors.New("failed to add user").Base(err).AtError()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,14 +75,14 @@ func (s *Server) Process(ctx context.Context, network net.Network, conn stat.Con
|
|||
inbound := session.InboundFromContext(ctx)
|
||||
inbound.Name = "shadowsocks"
|
||||
inbound.CanSpliceCopy = 3
|
||||
|
||||
|
||||
switch network {
|
||||
case net.Network_TCP:
|
||||
return s.handleConnection(ctx, conn, dispatcher)
|
||||
case net.Network_UDP:
|
||||
return s.handleUDPPayload(ctx, conn, dispatcher)
|
||||
default:
|
||||
return newError("unknown network: ", network)
|
||||
return errors.New("unknown network: ", network)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,7 +106,7 @@ func (s *Server) handleUDPPayload(ctx context.Context, conn stat.Connection, dis
|
|||
data, err := EncodeUDPPacket(request, payload.Bytes())
|
||||
payload.Release()
|
||||
if err != nil {
|
||||
newError("failed to encode UDP packet").Base(err).AtWarning().WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogWarningInner(ctx, err, "failed to encode UDP packet")
|
||||
return
|
||||
}
|
||||
defer data.Release()
|
||||
|
@ -140,7 +141,7 @@ func (s *Server) handleUDPPayload(ctx context.Context, conn stat.Connection, dis
|
|||
|
||||
if err != nil {
|
||||
if inbound.Source.IsValid() {
|
||||
newError("dropping invalid UDP packet from: ", inbound.Source).Base(err).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfoInner(ctx, err, "dropping invalid UDP packet from: ", inbound.Source)
|
||||
log.Record(&log.AccessMessage{
|
||||
From: inbound.Source,
|
||||
To: "",
|
||||
|
@ -164,7 +165,7 @@ func (s *Server) handleUDPPayload(ctx context.Context, conn stat.Connection, dis
|
|||
Email: request.User.Email,
|
||||
})
|
||||
}
|
||||
newError("tunnelling request to ", destination).WriteToLog(session.ExportIDToError(currentPacketCtx))
|
||||
errors.LogInfo(ctx, "tunnelling request to ", destination)
|
||||
|
||||
data.UDP = &destination
|
||||
|
||||
|
@ -183,7 +184,7 @@ func (s *Server) handleUDPPayload(ctx context.Context, conn stat.Connection, dis
|
|||
func (s *Server) handleConnection(ctx context.Context, conn stat.Connection, dispatcher routing.Dispatcher) error {
|
||||
sessionPolicy := s.policyManager.ForLevel(0)
|
||||
if err := conn.SetReadDeadline(time.Now().Add(sessionPolicy.Timeouts.Handshake)); err != nil {
|
||||
return newError("unable to set read deadline").Base(err).AtWarning()
|
||||
return errors.New("unable to set read deadline").Base(err).AtWarning()
|
||||
}
|
||||
|
||||
bufferedReader := buf.BufferedReader{Reader: buf.NewReader(conn)}
|
||||
|
@ -195,7 +196,7 @@ func (s *Server) handleConnection(ctx context.Context, conn stat.Connection, dis
|
|||
Status: log.AccessRejected,
|
||||
Reason: err,
|
||||
})
|
||||
return newError("failed to create request from: ", conn.RemoteAddr()).Base(err)
|
||||
return errors.New("failed to create request from: ", conn.RemoteAddr()).Base(err)
|
||||
}
|
||||
conn.SetReadDeadline(time.Time{})
|
||||
|
||||
|
@ -213,7 +214,7 @@ func (s *Server) handleConnection(ctx context.Context, conn stat.Connection, dis
|
|||
Reason: "",
|
||||
Email: request.User.Email,
|
||||
})
|
||||
newError("tunnelling request to ", dest).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfo(ctx, "tunnelling request to ", dest)
|
||||
|
||||
sessionPolicy = s.policyManager.ForLevel(request.User.Level)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
|
@ -231,7 +232,7 @@ func (s *Server) handleConnection(ctx context.Context, conn stat.Connection, dis
|
|||
bufferedWriter := buf.NewBufferedWriter(buf.NewWriter(conn))
|
||||
responseWriter, err := WriteTCPResponse(request, bufferedWriter)
|
||||
if err != nil {
|
||||
return newError("failed to write response").Base(err)
|
||||
return errors.New("failed to write response").Base(err)
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -249,7 +250,7 @@ func (s *Server) handleConnection(ctx context.Context, conn stat.Connection, dis
|
|||
}
|
||||
|
||||
if err := buf.Copy(link.Reader, responseWriter, buf.UpdateActivity(timer)); err != nil {
|
||||
return newError("failed to transport all TCP response").Base(err)
|
||||
return errors.New("failed to transport all TCP response").Base(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -259,7 +260,7 @@ func (s *Server) handleConnection(ctx context.Context, conn stat.Connection, dis
|
|||
defer timer.SetTimeout(sessionPolicy.Timeouts.DownlinkOnly)
|
||||
|
||||
if err := buf.Copy(bodyReader, link.Writer, buf.UpdateActivity(timer)); err != nil {
|
||||
return newError("failed to transport all TCP request").Base(err)
|
||||
return errors.New("failed to transport all TCP request").Base(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -269,7 +270,7 @@ func (s *Server) handleConnection(ctx context.Context, conn stat.Connection, dis
|
|||
if err := task.Run(ctx, requestDoneAndCloseWriter, responseDone); err != nil {
|
||||
common.Interrupt(link.Reader)
|
||||
common.Interrupt(link.Writer)
|
||||
return newError("connection ends").Base(err)
|
||||
return errors.New("connection ends").Base(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"sync"
|
||||
|
||||
"github.com/xtls/xray-core/common/dice"
|
||||
"github.com/xtls/xray-core/common/errors"
|
||||
"github.com/xtls/xray-core/common/protocol"
|
||||
)
|
||||
|
||||
|
@ -21,7 +22,7 @@ type Validator struct {
|
|||
behaviorFused bool
|
||||
}
|
||||
|
||||
var ErrNotFound = newError("Not Found")
|
||||
var ErrNotFound = errors.New("Not Found")
|
||||
|
||||
// Add a Shadowsocks user.
|
||||
func (v *Validator) Add(u *protocol.MemoryUser) error {
|
||||
|
@ -30,7 +31,7 @@ func (v *Validator) Add(u *protocol.MemoryUser) error {
|
|||
|
||||
account := u.Account.(*MemoryAccount)
|
||||
if !account.Cipher.IsAEAD() && len(v.users) > 0 {
|
||||
return newError("The cipher is not support Single-port Multi-user")
|
||||
return errors.New("The cipher is not support Single-port Multi-user")
|
||||
}
|
||||
v.users = append(v.users, u)
|
||||
|
||||
|
@ -46,7 +47,7 @@ func (v *Validator) Add(u *protocol.MemoryUser) error {
|
|||
// Del a Shadowsocks user with a non-empty Email.
|
||||
func (v *Validator) Del(email string) error {
|
||||
if email == "" {
|
||||
return newError("Email must not be empty.")
|
||||
return errors.New("Email must not be empty.")
|
||||
}
|
||||
|
||||
v.Lock()
|
||||
|
@ -62,7 +63,7 @@ func (v *Validator) Del(email string) error {
|
|||
}
|
||||
|
||||
if idx == -1 {
|
||||
return newError("User ", email, " not found.")
|
||||
return errors.New("User ", email, " not found.")
|
||||
}
|
||||
ulen := len(v.users)
|
||||
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
package shadowsocks_2022
|
||||
|
||||
import "github.com/xtls/xray-core/common/errors"
|
||||
|
||||
type errPathObjHolder struct{}
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).WithPathObj(errPathObjHolder{})
|
||||
}
|
|
@ -13,6 +13,7 @@ import (
|
|||
N "github.com/sagernet/sing/common/network"
|
||||
"github.com/xtls/xray-core/common"
|
||||
"github.com/xtls/xray-core/common/buf"
|
||||
"github.com/xtls/xray-core/common/errors"
|
||||
"github.com/xtls/xray-core/common/log"
|
||||
"github.com/xtls/xray-core/common/net"
|
||||
"github.com/xtls/xray-core/common/protocol"
|
||||
|
@ -49,11 +50,11 @@ func NewServer(ctx context.Context, config *ServerConfig) (*Inbound, error) {
|
|||
level: int(config.Level),
|
||||
}
|
||||
if !C.Contains(shadowaead_2022.List, config.Method) {
|
||||
return nil, newError("unsupported method ", config.Method)
|
||||
return nil, errors.New("unsupported method ", config.Method)
|
||||
}
|
||||
service, err := shadowaead_2022.NewServiceWithPassword(config.Method, config.Key, 500, inbound, nil)
|
||||
if err != nil {
|
||||
return nil, newError("create service").Base(err)
|
||||
return nil, errors.New("create service").Base(err)
|
||||
}
|
||||
inbound.service = service
|
||||
return inbound, nil
|
||||
|
@ -112,7 +113,7 @@ func (i *Inbound) NewConnection(ctx context.Context, conn net.Conn, metadata M.M
|
|||
Status: log.AccessAccepted,
|
||||
Email: i.email,
|
||||
})
|
||||
newError("tunnelling request to tcp:", metadata.Destination).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfo(ctx, "tunnelling request to tcp:", metadata.Destination)
|
||||
dispatcher := session.DispatcherFromContext(ctx)
|
||||
link, err := dispatcher.Dispatch(ctx, singbridge.ToDestination(metadata.Destination, net.Network_TCP))
|
||||
if err != nil {
|
||||
|
@ -133,7 +134,7 @@ func (i *Inbound) NewPacketConnection(ctx context.Context, conn N.PacketConn, me
|
|||
Status: log.AccessAccepted,
|
||||
Email: i.email,
|
||||
})
|
||||
newError("tunnelling request to udp:", metadata.Destination).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfo(ctx, "tunnelling request to udp:", metadata.Destination)
|
||||
dispatcher := session.DispatcherFromContext(ctx)
|
||||
destination := singbridge.ToDestination(metadata.Destination, net.Network_UDP)
|
||||
link, err := dispatcher.Dispatch(ctx, destination)
|
||||
|
@ -152,7 +153,7 @@ func (i *Inbound) NewError(ctx context.Context, err error) {
|
|||
if E.IsClosed(err) {
|
||||
return
|
||||
}
|
||||
newError(err).AtWarning().WriteToLog()
|
||||
errors.LogWarning(ctx, err.Error())
|
||||
}
|
||||
|
||||
type natPacketConn struct {
|
||||
|
|
|
@ -17,6 +17,7 @@ import (
|
|||
N "github.com/sagernet/sing/common/network"
|
||||
"github.com/xtls/xray-core/common"
|
||||
"github.com/xtls/xray-core/common/buf"
|
||||
"github.com/xtls/xray-core/common/errors"
|
||||
"github.com/xtls/xray-core/common/log"
|
||||
"github.com/xtls/xray-core/common/net"
|
||||
"github.com/xtls/xray-core/common/protocol"
|
||||
|
@ -53,15 +54,15 @@ func NewMultiServer(ctx context.Context, config *MultiUserServerConfig) (*MultiU
|
|||
users: config.Users,
|
||||
}
|
||||
if config.Key == "" {
|
||||
return nil, newError("missing key")
|
||||
return nil, errors.New("missing key")
|
||||
}
|
||||
psk, err := base64.StdEncoding.DecodeString(config.Key)
|
||||
if err != nil {
|
||||
return nil, newError("parse config").Base(err)
|
||||
return nil, errors.New("parse config").Base(err)
|
||||
}
|
||||
service, err := shadowaead_2022.NewMultiService[int](config.Method, psk, 500, inbound, nil)
|
||||
if err != nil {
|
||||
return nil, newError("create service").Base(err)
|
||||
return nil, errors.New("create service").Base(err)
|
||||
}
|
||||
|
||||
for i, user := range config.Users {
|
||||
|
@ -75,7 +76,7 @@ func NewMultiServer(ctx context.Context, config *MultiUserServerConfig) (*MultiU
|
|||
C.Map(config.Users, func(it *User) string { return it.Key }),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, newError("create service").Base(err)
|
||||
return nil, errors.New("create service").Base(err)
|
||||
}
|
||||
|
||||
inbound.service = service
|
||||
|
@ -91,7 +92,7 @@ func (i *MultiUserInbound) AddUser(ctx context.Context, u *protocol.MemoryUser)
|
|||
if account.Email != "" {
|
||||
for idx := range i.users {
|
||||
if i.users[idx].Email == account.Email {
|
||||
return newError("User ", account.Email, " already exists.")
|
||||
return errors.New("User ", account.Email, " already exists.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -114,7 +115,7 @@ func (i *MultiUserInbound) AddUser(ctx context.Context, u *protocol.MemoryUser)
|
|||
// RemoveUser implements proxy.UserManager.RemoveUser().
|
||||
func (i *MultiUserInbound) RemoveUser(ctx context.Context, email string) error {
|
||||
if email == "" {
|
||||
return newError("Email must not be empty.")
|
||||
return errors.New("Email must not be empty.")
|
||||
}
|
||||
|
||||
i.Lock()
|
||||
|
@ -129,7 +130,7 @@ func (i *MultiUserInbound) RemoveUser(ctx context.Context, email string) error {
|
|||
}
|
||||
|
||||
if idx == -1 {
|
||||
return newError("User ", email, " not found.")
|
||||
return errors.New("User ", email, " not found.")
|
||||
}
|
||||
|
||||
ulen := len(i.users)
|
||||
|
@ -203,11 +204,11 @@ func (i *MultiUserInbound) NewConnection(ctx context.Context, conn net.Conn, met
|
|||
Status: log.AccessAccepted,
|
||||
Email: user.Email,
|
||||
})
|
||||
newError("tunnelling request to tcp:", metadata.Destination).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfo(ctx, "tunnelling request to tcp:", metadata.Destination)
|
||||
dispatcher := session.DispatcherFromContext(ctx)
|
||||
destination := singbridge.ToDestination(metadata.Destination, net.Network_TCP)
|
||||
if !destination.IsValid() {
|
||||
return newError("invalid destination")
|
||||
return errors.New("invalid destination")
|
||||
}
|
||||
|
||||
link, err := dispatcher.Dispatch(ctx, destination)
|
||||
|
@ -231,7 +232,7 @@ func (i *MultiUserInbound) NewPacketConnection(ctx context.Context, conn N.Packe
|
|||
Status: log.AccessAccepted,
|
||||
Email: user.Email,
|
||||
})
|
||||
newError("tunnelling request to udp:", metadata.Destination).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfo(ctx, "tunnelling request to udp:", metadata.Destination)
|
||||
dispatcher := session.DispatcherFromContext(ctx)
|
||||
destination := singbridge.ToDestination(metadata.Destination, net.Network_UDP)
|
||||
link, err := dispatcher.Dispatch(ctx, destination)
|
||||
|
@ -250,5 +251,5 @@ func (i *MultiUserInbound) NewError(ctx context.Context, err error) {
|
|||
if E.IsClosed(err) {
|
||||
return
|
||||
}
|
||||
newError(err).AtWarning().WriteToLog()
|
||||
errors.LogWarning(ctx, err.Error())
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import (
|
|||
N "github.com/sagernet/sing/common/network"
|
||||
"github.com/xtls/xray-core/common"
|
||||
"github.com/xtls/xray-core/common/buf"
|
||||
"github.com/xtls/xray-core/common/errors"
|
||||
"github.com/xtls/xray-core/common/log"
|
||||
"github.com/xtls/xray-core/common/net"
|
||||
"github.com/xtls/xray-core/common/protocol"
|
||||
|
@ -50,11 +51,11 @@ func NewRelayServer(ctx context.Context, config *RelayServerConfig) (*RelayInbou
|
|||
destinations: config.Destinations,
|
||||
}
|
||||
if !C.Contains(shadowaead_2022.List, config.Method) || !strings.Contains(config.Method, "aes") {
|
||||
return nil, newError("unsupported method ", config.Method)
|
||||
return nil, errors.New("unsupported method ", config.Method)
|
||||
}
|
||||
service, err := shadowaead_2022.NewRelayServiceWithPassword[int](config.Method, config.Key, 500, inbound)
|
||||
if err != nil {
|
||||
return nil, newError("create service").Base(err)
|
||||
return nil, errors.New("create service").Base(err)
|
||||
}
|
||||
|
||||
for i, destination := range config.Destinations {
|
||||
|
@ -74,7 +75,7 @@ func NewRelayServer(ctx context.Context, config *RelayServerConfig) (*RelayInbou
|
|||
}),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, newError("create service").Base(err)
|
||||
return nil, errors.New("create service").Base(err)
|
||||
}
|
||||
inbound.service = service
|
||||
return inbound, nil
|
||||
|
@ -135,7 +136,7 @@ func (i *RelayInbound) NewConnection(ctx context.Context, conn net.Conn, metadat
|
|||
Status: log.AccessAccepted,
|
||||
Email: user.Email,
|
||||
})
|
||||
newError("tunnelling request to tcp:", metadata.Destination).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfo(ctx, "tunnelling request to tcp:", metadata.Destination)
|
||||
dispatcher := session.DispatcherFromContext(ctx)
|
||||
link, err := dispatcher.Dispatch(ctx, singbridge.ToDestination(metadata.Destination, net.Network_TCP))
|
||||
if err != nil {
|
||||
|
@ -158,7 +159,7 @@ func (i *RelayInbound) NewPacketConnection(ctx context.Context, conn N.PacketCon
|
|||
Status: log.AccessAccepted,
|
||||
Email: user.Email,
|
||||
})
|
||||
newError("tunnelling request to udp:", metadata.Destination).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfo(ctx, "tunnelling request to udp:", metadata.Destination)
|
||||
dispatcher := session.DispatcherFromContext(ctx)
|
||||
destination := singbridge.ToDestination(metadata.Destination, net.Network_UDP)
|
||||
link, err := dispatcher.Dispatch(ctx, destination)
|
||||
|
@ -177,5 +178,5 @@ func (i *RelayInbound) NewError(ctx context.Context, err error) {
|
|||
if E.IsClosed(err) {
|
||||
return
|
||||
}
|
||||
newError(err).AtWarning().WriteToLog()
|
||||
errors.LogWarning(ctx, err.Error())
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
"github.com/sagernet/sing/common/uot"
|
||||
"github.com/xtls/xray-core/common"
|
||||
"github.com/xtls/xray-core/common/buf"
|
||||
"github.com/xtls/xray-core/common/errors"
|
||||
"github.com/xtls/xray-core/common/net"
|
||||
"github.com/xtls/xray-core/common/session"
|
||||
"github.com/xtls/xray-core/common/singbridge"
|
||||
|
@ -44,15 +45,15 @@ func NewClient(ctx context.Context, config *ClientConfig) (*Outbound, error) {
|
|||
}
|
||||
if C.Contains(shadowaead_2022.List, config.Method) {
|
||||
if config.Key == "" {
|
||||
return nil, newError("missing psk")
|
||||
return nil, errors.New("missing psk")
|
||||
}
|
||||
method, err := shadowaead_2022.NewWithPassword(config.Method, config.Key, nil)
|
||||
if err != nil {
|
||||
return nil, newError("create method").Base(err)
|
||||
return nil, errors.New("create method").Base(err)
|
||||
}
|
||||
o.method = method
|
||||
} else {
|
||||
return nil, newError("unknown method ", config.Method)
|
||||
return nil, errors.New("unknown method ", config.Method)
|
||||
}
|
||||
if config.UdpOverTcp {
|
||||
o.uotClient = &uot.Client{Version: uint8(config.UdpOverTcpVersion)}
|
||||
|
@ -68,16 +69,16 @@ func (o *Outbound) Process(ctx context.Context, link *transport.Link, dialer int
|
|||
}
|
||||
|
||||
outbounds := session.OutboundsFromContext(ctx)
|
||||
ob := outbounds[len(outbounds) - 1]
|
||||
ob := outbounds[len(outbounds)-1]
|
||||
if !ob.Target.IsValid() {
|
||||
return newError("target not specified")
|
||||
return errors.New("target not specified")
|
||||
}
|
||||
ob.Name = "shadowsocks-2022"
|
||||
ob.CanSpliceCopy = 3
|
||||
destination := ob.Target
|
||||
network := destination.Network
|
||||
|
||||
newError("tunneling request to ", destination, " via ", o.server.NetAddr()).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfo(ctx, "tunneling request to ", destination, " via ", o.server.NetAddr())
|
||||
|
||||
serverDestination := o.server
|
||||
if o.uotClient != nil {
|
||||
|
@ -87,7 +88,7 @@ func (o *Outbound) Process(ctx context.Context, link *transport.Link, dialer int
|
|||
}
|
||||
connection, err := dialer.Dial(ctx, serverDestination)
|
||||
if err != nil {
|
||||
return newError("failed to connect to server").Base(err)
|
||||
return errors.New("failed to connect to server").Base(err)
|
||||
}
|
||||
|
||||
if session.TimeoutOnlyFromContext(ctx) {
|
||||
|
@ -100,7 +101,7 @@ func (o *Outbound) Process(ctx context.Context, link *transport.Link, dialer int
|
|||
if timeoutReader, isTimeoutReader := link.Reader.(buf.TimeoutReader); isTimeoutReader {
|
||||
mb, err := timeoutReader.ReadMultiBufferTimeout(time.Millisecond * 100)
|
||||
if err != nil && err != buf.ErrNotTimeoutReader && err != buf.ErrReadTimeout {
|
||||
return newError("read payload").Base(err)
|
||||
return errors.New("read payload").Base(err)
|
||||
}
|
||||
payload := B.New()
|
||||
for {
|
||||
|
@ -111,7 +112,7 @@ func (o *Outbound) Process(ctx context.Context, link *transport.Link, dialer int
|
|||
_, err = serverConn.Write(payload.Bytes())
|
||||
if err != nil {
|
||||
payload.Release()
|
||||
return newError("write payload").Base(err)
|
||||
return errors.New("write payload").Base(err)
|
||||
}
|
||||
handshake = true
|
||||
}
|
||||
|
@ -125,7 +126,7 @@ func (o *Outbound) Process(ctx context.Context, link *transport.Link, dialer int
|
|||
if !handshake {
|
||||
_, err = serverConn.Write(nil)
|
||||
if err != nil {
|
||||
return newError("client handshake").Base(err)
|
||||
return errors.New("client handshake").Base(err)
|
||||
}
|
||||
}
|
||||
return singbridge.CopyConn(ctx, inboundConn, link, serverConn)
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
|
||||
"github.com/xtls/xray-core/common"
|
||||
"github.com/xtls/xray-core/common/buf"
|
||||
"github.com/xtls/xray-core/common/errors"
|
||||
"github.com/xtls/xray-core/common/net"
|
||||
"github.com/xtls/xray-core/common/protocol"
|
||||
"github.com/xtls/xray-core/common/retry"
|
||||
|
@ -34,12 +35,12 @@ func NewClient(ctx context.Context, config *ClientConfig) (*Client, error) {
|
|||
for _, rec := range config.Server {
|
||||
s, err := protocol.NewServerSpecFromPB(rec)
|
||||
if err != nil {
|
||||
return nil, newError("failed to get server spec").Base(err)
|
||||
return nil, errors.New("failed to get server spec").Base(err)
|
||||
}
|
||||
serverList.AddServer(s)
|
||||
}
|
||||
if serverList.Size() == 0 {
|
||||
return nil, newError("0 target server")
|
||||
return nil, errors.New("0 target server")
|
||||
}
|
||||
|
||||
v := core.MustFromContext(ctx)
|
||||
|
@ -58,9 +59,9 @@ func NewClient(ctx context.Context, config *ClientConfig) (*Client, error) {
|
|||
// Process implements proxy.Outbound.Process.
|
||||
func (c *Client) Process(ctx context.Context, link *transport.Link, dialer internet.Dialer) error {
|
||||
outbounds := session.OutboundsFromContext(ctx)
|
||||
ob := outbounds[len(outbounds) - 1]
|
||||
ob := outbounds[len(outbounds)-1]
|
||||
if !ob.Target.IsValid() {
|
||||
return newError("target not specified.")
|
||||
return errors.New("target not specified.")
|
||||
}
|
||||
ob.Name = "socks"
|
||||
ob.CanSpliceCopy = 2
|
||||
|
@ -85,12 +86,12 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter
|
|||
|
||||
return nil
|
||||
}); err != nil {
|
||||
return newError("failed to find an available destination").Base(err)
|
||||
return errors.New("failed to find an available destination").Base(err)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if err := conn.Close(); err != nil {
|
||||
newError("failed to closed connection").Base(err).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfoInner(ctx, err, "failed to closed connection")
|
||||
}
|
||||
}()
|
||||
|
||||
|
@ -121,9 +122,9 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter
|
|||
request.Version = socks4Version
|
||||
|
||||
if destination.Network == net.Network_UDP {
|
||||
return newError("udp is not supported in socks4")
|
||||
return errors.New("udp is not supported in socks4")
|
||||
} else if destination.Address.Family().IsIPv6() {
|
||||
return newError("ipv6 is not supported in socks4")
|
||||
return errors.New("ipv6 is not supported in socks4")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -138,11 +139,11 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter
|
|||
}
|
||||
|
||||
if err := conn.SetDeadline(time.Now().Add(p.Timeouts.Handshake)); err != nil {
|
||||
newError("failed to set deadline for handshake").Base(err).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfoInner(ctx, err, "failed to set deadline for handshake")
|
||||
}
|
||||
udpRequest, err := ClientHandshake(request, conn, conn)
|
||||
if err != nil {
|
||||
return newError("failed to establish connection to server").AtWarning().Base(err)
|
||||
return errors.New("failed to establish connection to server").AtWarning().Base(err)
|
||||
}
|
||||
if udpRequest != nil {
|
||||
if udpRequest.Address == net.AnyIP || udpRequest.Address == net.AnyIPv6 {
|
||||
|
@ -151,7 +152,7 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter
|
|||
}
|
||||
|
||||
if err := conn.SetDeadline(time.Time{}); err != nil {
|
||||
newError("failed to clear deadline after handshake").Base(err).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfoInner(ctx, err, "failed to clear deadline after handshake")
|
||||
}
|
||||
|
||||
var newCtx context.Context
|
||||
|
@ -182,7 +183,7 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter
|
|||
} else if request.Command == protocol.RequestCommandUDP {
|
||||
udpConn, err := dialer.Dial(ctx, udpRequest.Destination())
|
||||
if err != nil {
|
||||
return newError("failed to create UDP connection").Base(err)
|
||||
return errors.New("failed to create UDP connection").Base(err)
|
||||
}
|
||||
defer udpConn.Close()
|
||||
requestFunc = func() error {
|
||||
|
@ -203,7 +204,7 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter
|
|||
|
||||
responseDonePost := task.OnSuccess(responseFunc, task.Close(link.Writer))
|
||||
if err := task.Run(ctx, requestFunc, responseDonePost); err != nil {
|
||||
return newError("connection ends").Base(err)
|
||||
return errors.New("connection ends").Base(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
package socks
|
||||
|
||||
import "github.com/xtls/xray-core/common/errors"
|
||||
|
||||
type errPathObjHolder struct{}
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).WithPathObj(errPathObjHolder{})
|
||||
}
|
|
@ -6,6 +6,7 @@ import (
|
|||
|
||||
"github.com/xtls/xray-core/common"
|
||||
"github.com/xtls/xray-core/common/buf"
|
||||
"github.com/xtls/xray-core/common/errors"
|
||||
"github.com/xtls/xray-core/common/net"
|
||||
"github.com/xtls/xray-core/common/protocol"
|
||||
)
|
||||
|
@ -48,7 +49,7 @@ type ServerSession struct {
|
|||
func (s *ServerSession) handshake4(cmd byte, reader io.Reader, writer io.Writer) (*protocol.RequestHeader, error) {
|
||||
if s.config.AuthType == AuthType_PASSWORD {
|
||||
writeSocks4Response(writer, socks4RequestRejected, net.AnyIP, net.Port(0))
|
||||
return nil, newError("socks 4 is not allowed when auth is required.")
|
||||
return nil, errors.New("socks 4 is not allowed when auth is required.")
|
||||
}
|
||||
|
||||
var port net.Port
|
||||
|
@ -58,7 +59,7 @@ func (s *ServerSession) handshake4(cmd byte, reader io.Reader, writer io.Writer)
|
|||
buffer := buf.StackNew()
|
||||
if _, err := buffer.ReadFullFrom(reader, 6); err != nil {
|
||||
buffer.Release()
|
||||
return nil, newError("insufficient header").Base(err)
|
||||
return nil, errors.New("insufficient header").Base(err)
|
||||
}
|
||||
port = net.PortFromBytes(buffer.BytesRange(0, 2))
|
||||
address = net.IPAddress(buffer.BytesRange(2, 6))
|
||||
|
@ -71,7 +72,7 @@ func (s *ServerSession) handshake4(cmd byte, reader io.Reader, writer io.Writer)
|
|||
if address.IP()[0] == 0x00 {
|
||||
domain, err := ReadUntilNull(reader)
|
||||
if err != nil {
|
||||
return nil, newError("failed to read domain for socks 4a").Base(err)
|
||||
return nil, errors.New("failed to read domain for socks 4a").Base(err)
|
||||
}
|
||||
address = net.DomainAddress(domain)
|
||||
}
|
||||
|
@ -90,7 +91,7 @@ func (s *ServerSession) handshake4(cmd byte, reader io.Reader, writer io.Writer)
|
|||
return request, nil
|
||||
default:
|
||||
writeSocks4Response(writer, socks4RequestRejected, net.AnyIP, net.Port(0))
|
||||
return nil, newError("unsupported command: ", cmd)
|
||||
return nil, errors.New("unsupported command: ", cmd)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -99,7 +100,7 @@ func (s *ServerSession) auth5(nMethod byte, reader io.Reader, writer io.Writer)
|
|||
defer buffer.Release()
|
||||
|
||||
if _, err = buffer.ReadFullFrom(reader, int32(nMethod)); err != nil {
|
||||
return "", newError("failed to read auth methods").Base(err)
|
||||
return "", errors.New("failed to read auth methods").Base(err)
|
||||
}
|
||||
|
||||
var expectedAuth byte = authNotRequired
|
||||
|
@ -109,26 +110,26 @@ func (s *ServerSession) auth5(nMethod byte, reader io.Reader, writer io.Writer)
|
|||
|
||||
if !hasAuthMethod(expectedAuth, buffer.BytesRange(0, int32(nMethod))) {
|
||||
writeSocks5AuthenticationResponse(writer, socks5Version, authNoMatchingMethod)
|
||||
return "", newError("no matching auth method")
|
||||
return "", errors.New("no matching auth method")
|
||||
}
|
||||
|
||||
if err := writeSocks5AuthenticationResponse(writer, socks5Version, expectedAuth); err != nil {
|
||||
return "", newError("failed to write auth response").Base(err)
|
||||
return "", errors.New("failed to write auth response").Base(err)
|
||||
}
|
||||
|
||||
if expectedAuth == authPassword {
|
||||
username, password, err := ReadUsernamePassword(reader)
|
||||
if err != nil {
|
||||
return "", newError("failed to read username and password for authentication").Base(err)
|
||||
return "", errors.New("failed to read username and password for authentication").Base(err)
|
||||
}
|
||||
|
||||
if !s.config.HasAccount(username, password) {
|
||||
writeSocks5AuthenticationResponse(writer, 0x01, 0xFF)
|
||||
return "", newError("invalid username or password")
|
||||
return "", errors.New("invalid username or password")
|
||||
}
|
||||
|
||||
if err := writeSocks5AuthenticationResponse(writer, 0x01, 0x00); err != nil {
|
||||
return "", newError("failed to write auth response").Base(err)
|
||||
return "", errors.New("failed to write auth response").Base(err)
|
||||
}
|
||||
return username, nil
|
||||
}
|
||||
|
@ -150,7 +151,7 @@ func (s *ServerSession) handshake5(nMethod byte, reader io.Reader, writer io.Wri
|
|||
buffer := buf.StackNew()
|
||||
if _, err := buffer.ReadFullFrom(reader, 3); err != nil {
|
||||
buffer.Release()
|
||||
return nil, newError("failed to read request").Base(err)
|
||||
return nil, errors.New("failed to read request").Base(err)
|
||||
}
|
||||
cmd = buffer.Byte(1)
|
||||
buffer.Release()
|
||||
|
@ -167,22 +168,22 @@ func (s *ServerSession) handshake5(nMethod byte, reader io.Reader, writer io.Wri
|
|||
case cmdUDPAssociate:
|
||||
if !s.config.UdpEnabled {
|
||||
writeSocks5Response(writer, statusCmdNotSupport, net.AnyIP, net.Port(0))
|
||||
return nil, newError("UDP is not enabled.")
|
||||
return nil, errors.New("UDP is not enabled.")
|
||||
}
|
||||
request.Command = protocol.RequestCommandUDP
|
||||
case cmdTCPBind:
|
||||
writeSocks5Response(writer, statusCmdNotSupport, net.AnyIP, net.Port(0))
|
||||
return nil, newError("TCP bind is not supported.")
|
||||
return nil, errors.New("TCP bind is not supported.")
|
||||
default:
|
||||
writeSocks5Response(writer, statusCmdNotSupport, net.AnyIP, net.Port(0))
|
||||
return nil, newError("unknown command ", cmd)
|
||||
return nil, errors.New("unknown command ", cmd)
|
||||
}
|
||||
|
||||
request.Version = socks5Version
|
||||
|
||||
addr, port, err := addrParser.ReadAddressPort(nil, reader)
|
||||
if err != nil {
|
||||
return nil, newError("failed to read address").Base(err)
|
||||
return nil, errors.New("failed to read address").Base(err)
|
||||
}
|
||||
request.Address = addr
|
||||
request.Port = port
|
||||
|
@ -211,7 +212,7 @@ func (s *ServerSession) Handshake(reader io.Reader, writer io.Writer) (*protocol
|
|||
buffer := buf.StackNew()
|
||||
if _, err := buffer.ReadFullFrom(reader, 2); err != nil {
|
||||
buffer.Release()
|
||||
return nil, newError("insufficient header").Base(err)
|
||||
return nil, errors.New("insufficient header").Base(err)
|
||||
}
|
||||
|
||||
version := buffer.Byte(0)
|
||||
|
@ -224,7 +225,7 @@ func (s *ServerSession) Handshake(reader io.Reader, writer io.Writer) (*protocol
|
|||
case socks5Version:
|
||||
return s.handshake5(cmd, reader, writer)
|
||||
default:
|
||||
return nil, newError("unknown Socks version: ", version)
|
||||
return nil, errors.New("unknown Socks version: ", version)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -278,7 +279,7 @@ func ReadUntilNull(reader io.Reader) (string, error) {
|
|||
return b.String(), nil
|
||||
}
|
||||
if b.IsFull() {
|
||||
return "", newError("buffer overrun")
|
||||
return "", errors.New("buffer overrun")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -322,7 +323,7 @@ func writeSocks4Response(writer io.Writer, errCode byte, address net.Address, po
|
|||
|
||||
func DecodeUDPPacket(packet *buf.Buffer) (*protocol.RequestHeader, error) {
|
||||
if packet.Len() < 5 {
|
||||
return nil, newError("insufficient length of packet.")
|
||||
return nil, errors.New("insufficient length of packet.")
|
||||
}
|
||||
request := &protocol.RequestHeader{
|
||||
Version: socks5Version,
|
||||
|
@ -331,14 +332,14 @@ func DecodeUDPPacket(packet *buf.Buffer) (*protocol.RequestHeader, error) {
|
|||
|
||||
// packet[0] and packet[1] are reserved
|
||||
if packet.Byte(2) != 0 /* fragments */ {
|
||||
return nil, newError("discarding fragmented payload.")
|
||||
return nil, errors.New("discarding fragmented payload.")
|
||||
}
|
||||
|
||||
packet.Advance(3)
|
||||
|
||||
addr, port, err := addrParser.ReadAddressPort(nil, packet)
|
||||
if err != nil {
|
||||
return nil, newError("failed to read UDP header").Base(err)
|
||||
return nil, errors.New("failed to read UDP header").Base(err)
|
||||
}
|
||||
request.Address = addr
|
||||
request.Port = port
|
||||
|
@ -432,10 +433,10 @@ func ClientHandshake(request *protocol.RequestHeader, reader io.Reader, writer i
|
|||
}
|
||||
|
||||
if b.Byte(0) != socks5Version {
|
||||
return nil, newError("unexpected server version: ", b.Byte(0)).AtWarning()
|
||||
return nil, errors.New("unexpected server version: ", b.Byte(0)).AtWarning()
|
||||
}
|
||||
if b.Byte(1) != authByte {
|
||||
return nil, newError("auth method not supported.").AtWarning()
|
||||
return nil, errors.New("auth method not supported.").AtWarning()
|
||||
}
|
||||
|
||||
if authByte == authPassword {
|
||||
|
@ -455,7 +456,7 @@ func ClientHandshake(request *protocol.RequestHeader, reader io.Reader, writer i
|
|||
return nil, err
|
||||
}
|
||||
if b.Byte(1) != 0x00 {
|
||||
return nil, newError("server rejects account: ", b.Byte(1))
|
||||
return nil, errors.New("server rejects account: ", b.Byte(1))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -485,7 +486,7 @@ func ClientHandshake(request *protocol.RequestHeader, reader io.Reader, writer i
|
|||
|
||||
resp := b.Byte(1)
|
||||
if resp != 0x00 {
|
||||
return nil, newError("server rejects request: ", resp)
|
||||
return nil, errors.New("server rejects request: ", resp)
|
||||
}
|
||||
|
||||
b.Clear()
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
|
||||
"github.com/xtls/xray-core/common"
|
||||
"github.com/xtls/xray-core/common/buf"
|
||||
"github.com/xtls/xray-core/common/errors"
|
||||
"github.com/xtls/xray-core/common/log"
|
||||
"github.com/xtls/xray-core/common/net"
|
||||
"github.com/xtls/xray-core/common/protocol"
|
||||
|
@ -80,19 +81,19 @@ func (s *Server) Process(ctx context.Context, network net.Network, conn stat.Con
|
|||
case net.Network_UDP:
|
||||
return s.handleUDPPayload(ctx, conn, dispatcher)
|
||||
default:
|
||||
return newError("unknown network: ", network)
|
||||
return errors.New("unknown network: ", network)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) processTCP(ctx context.Context, conn stat.Connection, dispatcher routing.Dispatcher) error {
|
||||
plcy := s.policy()
|
||||
if err := conn.SetReadDeadline(time.Now().Add(plcy.Timeouts.Handshake)); err != nil {
|
||||
newError("failed to set deadline").Base(err).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfoInner(ctx, err, "failed to set deadline")
|
||||
}
|
||||
|
||||
inbound := session.InboundFromContext(ctx)
|
||||
if inbound == nil || !inbound.Gateway.IsValid() {
|
||||
return newError("inbound gateway not specified")
|
||||
return errors.New("inbound gateway not specified")
|
||||
}
|
||||
|
||||
svrSession := &ServerSession{
|
||||
|
@ -113,19 +114,19 @@ func (s *Server) processTCP(ctx context.Context, conn stat.Connection, dispatche
|
|||
Reason: err,
|
||||
})
|
||||
}
|
||||
return newError("failed to read request").Base(err)
|
||||
return errors.New("failed to read request").Base(err)
|
||||
}
|
||||
if request.User != nil {
|
||||
inbound.User.Email = request.User.Email
|
||||
}
|
||||
|
||||
if err := conn.SetReadDeadline(time.Time{}); err != nil {
|
||||
newError("failed to clear deadline").Base(err).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfoInner(ctx, err, "failed to clear deadline")
|
||||
}
|
||||
|
||||
if request.Command == protocol.RequestCommandTCP {
|
||||
dest := request.Destination()
|
||||
newError("TCP Connect request to ", dest).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfo(ctx, "TCP Connect request to ", dest)
|
||||
if inbound.Source.IsValid() {
|
||||
ctx = log.ContextWithAccessMessage(ctx, &log.AccessMessage{
|
||||
From: inbound.Source,
|
||||
|
@ -172,7 +173,7 @@ func (s *Server) transport(ctx context.Context, reader io.Reader, writer io.Writ
|
|||
requestDone := func() error {
|
||||
defer timer.SetTimeout(plcy.Timeouts.DownlinkOnly)
|
||||
if err := buf.Copy(buf.NewReader(reader), link.Writer, buf.UpdateActivity(timer)); err != nil {
|
||||
return newError("failed to transport all TCP request").Base(err)
|
||||
return errors.New("failed to transport all TCP request").Base(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -183,7 +184,7 @@ func (s *Server) transport(ctx context.Context, reader io.Reader, writer io.Writ
|
|||
|
||||
v2writer := buf.NewWriter(writer)
|
||||
if err := buf.Copy(link.Reader, v2writer, buf.UpdateActivity(timer)); err != nil {
|
||||
return newError("failed to transport all TCP response").Base(err)
|
||||
return errors.New("failed to transport all TCP response").Base(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -193,7 +194,7 @@ func (s *Server) transport(ctx context.Context, reader io.Reader, writer io.Writ
|
|||
if err := task.Run(ctx, requestDonePost, responseDone); err != nil {
|
||||
common.Interrupt(link.Reader)
|
||||
common.Interrupt(link.Writer)
|
||||
return newError("connection ends").Base(err)
|
||||
return errors.New("connection ends").Base(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -201,12 +202,12 @@ func (s *Server) transport(ctx context.Context, reader io.Reader, writer io.Writ
|
|||
|
||||
func (s *Server) handleUDPPayload(ctx context.Context, conn stat.Connection, dispatcher routing.Dispatcher) error {
|
||||
if s.udpFilter != nil && !s.udpFilter.Check(conn.RemoteAddr()) {
|
||||
newError("Unauthorized UDP access from ", conn.RemoteAddr().String()).AtDebug().WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogDebug(ctx, "Unauthorized UDP access from ", conn.RemoteAddr().String())
|
||||
return nil
|
||||
}
|
||||
udpServer := udp.NewDispatcher(dispatcher, func(ctx context.Context, packet *udp_proto.Packet) {
|
||||
payload := packet.Payload
|
||||
newError("writing back UDP response with ", payload.Len(), " bytes").AtDebug().WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogDebug(ctx, "writing back UDP response with ", payload.Len(), " bytes")
|
||||
|
||||
request := protocol.RequestHeaderFromContext(ctx)
|
||||
if request == nil {
|
||||
|
@ -226,7 +227,7 @@ func (s *Server) handleUDPPayload(ctx context.Context, conn stat.Connection, dis
|
|||
|
||||
defer udpMessage.Release()
|
||||
if err != nil {
|
||||
newError("failed to write UDP response").AtWarning().Base(err).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogWarningInner(ctx, err, "failed to write UDP response")
|
||||
}
|
||||
|
||||
conn.Write(udpMessage.Bytes())
|
||||
|
@ -234,7 +235,7 @@ func (s *Server) handleUDPPayload(ctx context.Context, conn stat.Connection, dis
|
|||
|
||||
inbound := session.InboundFromContext(ctx)
|
||||
if inbound != nil && inbound.Source.IsValid() {
|
||||
newError("client UDP connection from ", inbound.Source).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfo(ctx, "client UDP connection from ", inbound.Source)
|
||||
}
|
||||
|
||||
var dest *net.Destination
|
||||
|
@ -249,7 +250,7 @@ func (s *Server) handleUDPPayload(ctx context.Context, conn stat.Connection, dis
|
|||
for _, payload := range mpayload {
|
||||
request, err := DecodeUDPPacket(payload)
|
||||
if err != nil {
|
||||
newError("failed to parse UDP request").Base(err).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfoInner(ctx, err, "failed to parse UDP request")
|
||||
payload.Release()
|
||||
continue
|
||||
}
|
||||
|
@ -262,7 +263,7 @@ func (s *Server) handleUDPPayload(ctx context.Context, conn stat.Connection, dis
|
|||
destination := request.Destination()
|
||||
|
||||
currentPacketCtx := ctx
|
||||
newError("send packet to ", destination, " with ", payload.Len(), " bytes").AtDebug().WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogDebug(ctx, "send packet to ", destination, " with ", payload.Len(), " bytes")
|
||||
if inbound != nil && inbound.Source.IsValid() {
|
||||
currentPacketCtx = log.ContextWithAccessMessage(ctx, &log.AccessMessage{
|
||||
From: inbound.Source,
|
||||
|
|
|
@ -32,12 +32,12 @@ func NewClient(ctx context.Context, config *ClientConfig) (*Client, error) {
|
|||
for _, rec := range config.Server {
|
||||
s, err := protocol.NewServerSpecFromPB(rec)
|
||||
if err != nil {
|
||||
return nil, newError("failed to parse server spec").Base(err)
|
||||
return nil, errors.New("failed to parse server spec").Base(err)
|
||||
}
|
||||
serverList.AddServer(s)
|
||||
}
|
||||
if serverList.Size() == 0 {
|
||||
return nil, newError("0 server")
|
||||
return nil, errors.New("0 server")
|
||||
}
|
||||
|
||||
v := core.MustFromContext(ctx)
|
||||
|
@ -51,9 +51,9 @@ func NewClient(ctx context.Context, config *ClientConfig) (*Client, error) {
|
|||
// Process implements OutboundHandler.Process().
|
||||
func (c *Client) Process(ctx context.Context, link *transport.Link, dialer internet.Dialer) error {
|
||||
outbounds := session.OutboundsFromContext(ctx)
|
||||
ob := outbounds[len(outbounds) - 1]
|
||||
ob := outbounds[len(outbounds)-1]
|
||||
if !ob.Target.IsValid() {
|
||||
return newError("target not specified")
|
||||
return errors.New("target not specified")
|
||||
}
|
||||
ob.Name = "trojan"
|
||||
ob.CanSpliceCopy = 3
|
||||
|
@ -74,16 +74,16 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter
|
|||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return newError("failed to find an available destination").AtWarning().Base(err)
|
||||
return errors.New("failed to find an available destination").AtWarning().Base(err)
|
||||
}
|
||||
newError("tunneling request to ", destination, " via ", server.Destination().NetAddr()).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfo(ctx, "tunneling request to ", destination, " via ", server.Destination().NetAddr())
|
||||
|
||||
defer conn.Close()
|
||||
|
||||
user := server.PickUser()
|
||||
account, ok := user.Account.(*MemoryAccount)
|
||||
if !ok {
|
||||
return newError("user account is not valid")
|
||||
return errors.New("user account is not valid")
|
||||
}
|
||||
|
||||
var newCtx context.Context
|
||||
|
@ -121,12 +121,12 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter
|
|||
|
||||
// write some request payload to buffer
|
||||
if err = buf.CopyOnceTimeout(link.Reader, bodyWriter, time.Millisecond*100); err != nil && err != buf.ErrNotTimeoutReader && err != buf.ErrReadTimeout {
|
||||
return newError("failed to write A request payload").Base(err).AtWarning()
|
||||
return errors.New("failed to write A request payload").Base(err).AtWarning()
|
||||
}
|
||||
|
||||
// Flush; bufferWriter.WriteMultiBufer now is bufferWriter.writer.WriteMultiBuffer
|
||||
if err = bufferWriter.SetBuffered(false); err != nil {
|
||||
return newError("failed to flush payload").Base(err).AtWarning()
|
||||
return errors.New("failed to flush payload").Base(err).AtWarning()
|
||||
}
|
||||
|
||||
// Send header if not sent yet
|
||||
|
@ -135,7 +135,7 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter
|
|||
}
|
||||
|
||||
if err = buf.Copy(link.Reader, bodyWriter, buf.UpdateActivity(timer)); err != nil {
|
||||
return newError("failed to transfer request payload").Base(err).AtInfo()
|
||||
return errors.New("failed to transfer request payload").Base(err).AtInfo()
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -161,7 +161,7 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter
|
|||
|
||||
responseDoneAndCloseWriter := task.OnSuccess(getResponse, task.Close(link.Writer))
|
||||
if err := task.Run(ctx, postRequest, responseDoneAndCloseWriter); err != nil {
|
||||
return newError("connection ends").Base(err)
|
||||
return errors.New("connection ends").Base(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
package trojan
|
||||
|
||||
import "github.com/xtls/xray-core/common/errors"
|
||||
|
||||
type errPathObjHolder struct{}
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).WithPathObj(errPathObjHolder{})
|
||||
}
|
|
@ -5,6 +5,7 @@ import (
|
|||
"io"
|
||||
|
||||
"github.com/xtls/xray-core/common/buf"
|
||||
"github.com/xtls/xray-core/common/errors"
|
||||
"github.com/xtls/xray-core/common/net"
|
||||
"github.com/xtls/xray-core/common/protocol"
|
||||
)
|
||||
|
@ -38,7 +39,7 @@ type ConnWriter struct {
|
|||
func (c *ConnWriter) Write(p []byte) (n int, err error) {
|
||||
if !c.headerSent {
|
||||
if err := c.writeHeader(); err != nil {
|
||||
return 0, newError("failed to write request header").Base(err)
|
||||
return 0, errors.New("failed to write request header").Base(err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -160,15 +161,15 @@ func (c *ConnReader) ParseHeader() error {
|
|||
var command [1]byte
|
||||
var hash [56]byte
|
||||
if _, err := io.ReadFull(c.Reader, hash[:]); err != nil {
|
||||
return newError("failed to read user hash").Base(err)
|
||||
return errors.New("failed to read user hash").Base(err)
|
||||
}
|
||||
|
||||
if _, err := io.ReadFull(c.Reader, crlf[:]); err != nil {
|
||||
return newError("failed to read crlf").Base(err)
|
||||
return errors.New("failed to read crlf").Base(err)
|
||||
}
|
||||
|
||||
if _, err := io.ReadFull(c.Reader, command[:]); err != nil {
|
||||
return newError("failed to read command").Base(err)
|
||||
return errors.New("failed to read command").Base(err)
|
||||
}
|
||||
|
||||
network := net.Network_TCP
|
||||
|
@ -178,12 +179,12 @@ func (c *ConnReader) ParseHeader() error {
|
|||
|
||||
addr, port, err := addrParser.ReadAddressPort(nil, c.Reader)
|
||||
if err != nil {
|
||||
return newError("failed to read address and port").Base(err)
|
||||
return errors.New("failed to read address and port").Base(err)
|
||||
}
|
||||
c.Target = net.Destination{Network: network, Address: addr, Port: port}
|
||||
|
||||
if _, err := io.ReadFull(c.Reader, crlf[:]); err != nil {
|
||||
return newError("failed to read crlf").Base(err)
|
||||
return errors.New("failed to read crlf").Base(err)
|
||||
}
|
||||
|
||||
c.headerParsed = true
|
||||
|
@ -217,22 +218,22 @@ type PacketReader struct {
|
|||
func (r *PacketReader) ReadMultiBuffer() (buf.MultiBuffer, error) {
|
||||
addr, port, err := addrParser.ReadAddressPort(nil, r)
|
||||
if err != nil {
|
||||
return nil, newError("failed to read address and port").Base(err)
|
||||
return nil, errors.New("failed to read address and port").Base(err)
|
||||
}
|
||||
|
||||
var lengthBuf [2]byte
|
||||
if _, err := io.ReadFull(r, lengthBuf[:]); err != nil {
|
||||
return nil, newError("failed to read payload length").Base(err)
|
||||
return nil, errors.New("failed to read payload length").Base(err)
|
||||
}
|
||||
|
||||
remain := int(binary.BigEndian.Uint16(lengthBuf[:]))
|
||||
if remain > maxLength {
|
||||
return nil, newError("oversize payload")
|
||||
return nil, errors.New("oversize payload")
|
||||
}
|
||||
|
||||
var crlf [2]byte
|
||||
if _, err := io.ReadFull(r, crlf[:]); err != nil {
|
||||
return nil, newError("failed to read crlf").Base(err)
|
||||
return nil, errors.New("failed to read crlf").Base(err)
|
||||
}
|
||||
|
||||
dest := net.UDPDestination(addr, port)
|
||||
|
@ -249,7 +250,7 @@ func (r *PacketReader) ReadMultiBuffer() (buf.MultiBuffer, error) {
|
|||
n, err := b.ReadFullFrom(r, int32(length))
|
||||
if err != nil {
|
||||
buf.ReleaseMulti(mb)
|
||||
return nil, newError("failed to read payload").Base(err)
|
||||
return nil, errors.New("failed to read payload").Base(err)
|
||||
}
|
||||
|
||||
remain -= int(n)
|
||||
|
|
|
@ -47,11 +47,11 @@ func NewServer(ctx context.Context, config *ServerConfig) (*Server, error) {
|
|||
for _, user := range config.Users {
|
||||
u, err := user.ToMemoryUser()
|
||||
if err != nil {
|
||||
return nil, newError("failed to get trojan user").Base(err).AtError()
|
||||
return nil, errors.New("failed to get trojan user").Base(err).AtError()
|
||||
}
|
||||
|
||||
if err := validator.Add(u); err != nil {
|
||||
return nil, newError("failed to add user").Base(err).AtError()
|
||||
return nil, errors.New("failed to add user").Base(err).AtError()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -132,8 +132,6 @@ func (s *Server) Network() []net.Network {
|
|||
|
||||
// Process implements proxy.Inbound.Process().
|
||||
func (s *Server) Process(ctx context.Context, network net.Network, conn stat.Connection, dispatcher routing.Dispatcher) error {
|
||||
sid := session.ExportIDToError(ctx)
|
||||
|
||||
iConn := conn
|
||||
statConn, ok := iConn.(*stat.CounterConnection)
|
||||
if ok {
|
||||
|
@ -142,16 +140,16 @@ func (s *Server) Process(ctx context.Context, network net.Network, conn stat.Con
|
|||
|
||||
sessionPolicy := s.policyManager.ForLevel(0)
|
||||
if err := conn.SetReadDeadline(time.Now().Add(sessionPolicy.Timeouts.Handshake)); err != nil {
|
||||
return newError("unable to set read deadline").Base(err).AtWarning()
|
||||
return errors.New("unable to set read deadline").Base(err).AtWarning()
|
||||
}
|
||||
|
||||
first := buf.FromBytes(make([]byte, buf.Size))
|
||||
first.Clear()
|
||||
firstLen, err := first.ReadFrom(conn)
|
||||
if err != nil {
|
||||
return newError("failed to read first request").Base(err)
|
||||
return errors.New("failed to read first request").Base(err)
|
||||
}
|
||||
newError("firstLen = ", firstLen).AtInfo().WriteToLog(sid)
|
||||
errors.LogInfo(ctx, "firstLen = ", firstLen)
|
||||
|
||||
bufferedReader := &buf.BufferedReader{
|
||||
Reader: buf.NewReader(conn),
|
||||
|
@ -166,7 +164,7 @@ func (s *Server) Process(ctx context.Context, network net.Network, conn stat.Con
|
|||
shouldFallback := false
|
||||
if firstLen < 58 || first.Byte(56) != '\r' {
|
||||
// invalid protocol
|
||||
err = newError("not trojan protocol")
|
||||
err = errors.New("not trojan protocol")
|
||||
log.Record(&log.AccessMessage{
|
||||
From: conn.RemoteAddr(),
|
||||
To: "",
|
||||
|
@ -179,7 +177,7 @@ func (s *Server) Process(ctx context.Context, network net.Network, conn stat.Con
|
|||
user = s.validator.Get(hexString(first.BytesTo(56)))
|
||||
if user == nil {
|
||||
// invalid user, let's fallback
|
||||
err = newError("not a valid user")
|
||||
err = errors.New("not a valid user")
|
||||
log.Record(&log.AccessMessage{
|
||||
From: conn.RemoteAddr(),
|
||||
To: "",
|
||||
|
@ -192,9 +190,9 @@ func (s *Server) Process(ctx context.Context, network net.Network, conn stat.Con
|
|||
}
|
||||
|
||||
if isfb && shouldFallback {
|
||||
return s.fallback(ctx, sid, err, sessionPolicy, conn, iConn, napfb, first, firstLen, bufferedReader)
|
||||
return s.fallback(ctx, err, sessionPolicy, conn, iConn, napfb, first, firstLen, bufferedReader)
|
||||
} else if shouldFallback {
|
||||
return newError("invalid protocol or invalid user")
|
||||
return errors.New("invalid protocol or invalid user")
|
||||
}
|
||||
|
||||
clientReader := &ConnReader{Reader: bufferedReader}
|
||||
|
@ -205,12 +203,12 @@ func (s *Server) Process(ctx context.Context, network net.Network, conn stat.Con
|
|||
Status: log.AccessRejected,
|
||||
Reason: err,
|
||||
})
|
||||
return newError("failed to create request from: ", conn.RemoteAddr()).Base(err)
|
||||
return errors.New("failed to create request from: ", conn.RemoteAddr()).Base(err)
|
||||
}
|
||||
|
||||
destination := clientReader.Target
|
||||
if err := conn.SetReadDeadline(time.Time{}); err != nil {
|
||||
return newError("unable to set read deadline").Base(err).AtWarning()
|
||||
return errors.New("unable to set read deadline").Base(err).AtWarning()
|
||||
}
|
||||
|
||||
inbound := session.InboundFromContext(ctx)
|
||||
|
@ -231,7 +229,7 @@ func (s *Server) Process(ctx context.Context, network net.Network, conn stat.Con
|
|||
Email: user.Email,
|
||||
})
|
||||
|
||||
newError("received request for ", destination).WriteToLog(sid)
|
||||
errors.LogInfo(ctx, "received request for ", destination)
|
||||
return s.handleConnection(ctx, sessionPolicy, destination, clientReader, buf.NewWriter(conn), dispatcher)
|
||||
}
|
||||
|
||||
|
@ -243,7 +241,7 @@ func (s *Server) handleUDPPayload(ctx context.Context, clientReader *PacketReade
|
|||
}
|
||||
|
||||
if err := clientWriter.WriteMultiBuffer(buf.MultiBuffer{udpPayload}); err != nil {
|
||||
newError("failed to write response").Base(err).AtWarning().WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogWarningInner(ctx, err, "failed to write response")
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -260,7 +258,7 @@ func (s *Server) handleUDPPayload(ctx context.Context, clientReader *PacketReade
|
|||
mb, err := clientReader.ReadMultiBuffer()
|
||||
if err != nil {
|
||||
if errors.Cause(err) != io.EOF {
|
||||
return newError("unexpected EOF").Base(err)
|
||||
return errors.New("unexpected EOF").Base(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -281,7 +279,7 @@ func (s *Server) handleUDPPayload(ctx context.Context, clientReader *PacketReade
|
|||
Email: user.Email,
|
||||
})
|
||||
}
|
||||
newError("tunnelling request to ", destination).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfo(ctx, "tunnelling request to ", destination)
|
||||
|
||||
if !s.cone || dest == nil {
|
||||
dest = &destination
|
||||
|
@ -306,13 +304,13 @@ func (s *Server) handleConnection(ctx context.Context, sessionPolicy policy.Sess
|
|||
|
||||
link, err := dispatcher.Dispatch(ctx, destination)
|
||||
if err != nil {
|
||||
return newError("failed to dispatch request to ", destination).Base(err)
|
||||
return errors.New("failed to dispatch request to ", destination).Base(err)
|
||||
}
|
||||
|
||||
requestDone := func() error {
|
||||
defer timer.SetTimeout(sessionPolicy.Timeouts.DownlinkOnly)
|
||||
if buf.Copy(clientReader, link.Writer, buf.UpdateActivity(timer)) != nil {
|
||||
return newError("failed to transfer request").Base(err)
|
||||
return errors.New("failed to transfer request").Base(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -321,7 +319,7 @@ func (s *Server) handleConnection(ctx context.Context, sessionPolicy policy.Sess
|
|||
defer timer.SetTimeout(sessionPolicy.Timeouts.UplinkOnly)
|
||||
|
||||
if err := buf.Copy(link.Reader, clientWriter, buf.UpdateActivity(timer)); err != nil {
|
||||
return newError("failed to write response").Base(err)
|
||||
return errors.New("failed to write response").Base(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -330,17 +328,17 @@ func (s *Server) handleConnection(ctx context.Context, sessionPolicy policy.Sess
|
|||
if err := task.Run(ctx, requestDonePost, responseDone); err != nil {
|
||||
common.Must(common.Interrupt(link.Reader))
|
||||
common.Must(common.Interrupt(link.Writer))
|
||||
return newError("connection ends").Base(err)
|
||||
return errors.New("connection ends").Base(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Server) fallback(ctx context.Context, sid errors.ExportOption, err error, sessionPolicy policy.Session, connection stat.Connection, iConn stat.Connection, napfb map[string]map[string]map[string]*Fallback, first *buf.Buffer, firstLen int64, reader buf.Reader) error {
|
||||
func (s *Server) fallback(ctx context.Context, err error, sessionPolicy policy.Session, connection stat.Connection, iConn stat.Connection, napfb map[string]map[string]map[string]*Fallback, first *buf.Buffer, firstLen int64, reader buf.Reader) error {
|
||||
if err := connection.SetReadDeadline(time.Time{}); err != nil {
|
||||
newError("unable to set back read deadline").Base(err).AtWarning().WriteToLog(sid)
|
||||
errors.LogWarningInner(ctx, err, "unable to set back read deadline")
|
||||
}
|
||||
newError("fallback starts").Base(err).AtInfo().WriteToLog(sid)
|
||||
errors.LogInfoInner(ctx, err, "fallback starts")
|
||||
|
||||
name := ""
|
||||
alpn := ""
|
||||
|
@ -348,14 +346,14 @@ func (s *Server) fallback(ctx context.Context, sid errors.ExportOption, err erro
|
|||
cs := tlsConn.ConnectionState()
|
||||
name = cs.ServerName
|
||||
alpn = cs.NegotiatedProtocol
|
||||
newError("realName = " + name).AtInfo().WriteToLog(sid)
|
||||
newError("realAlpn = " + alpn).AtInfo().WriteToLog(sid)
|
||||
errors.LogInfo(ctx, "realName = " + name)
|
||||
errors.LogInfo(ctx, "realAlpn = " + alpn)
|
||||
} else if realityConn, ok := iConn.(*reality.Conn); ok {
|
||||
cs := realityConn.ConnectionState()
|
||||
name = cs.ServerName
|
||||
alpn = cs.NegotiatedProtocol
|
||||
newError("realName = " + name).AtInfo().WriteToLog(sid)
|
||||
newError("realAlpn = " + alpn).AtInfo().WriteToLog(sid)
|
||||
errors.LogInfo(ctx, "realName = " + name)
|
||||
errors.LogInfo(ctx, "realAlpn = " + alpn)
|
||||
}
|
||||
name = strings.ToLower(name)
|
||||
alpn = strings.ToLower(alpn)
|
||||
|
@ -377,7 +375,7 @@ func (s *Server) fallback(ctx context.Context, sid errors.ExportOption, err erro
|
|||
}
|
||||
apfb := napfb[name]
|
||||
if apfb == nil {
|
||||
return newError(`failed to find the default "name" config`).AtWarning()
|
||||
return errors.New(`failed to find the default "name" config`).AtWarning()
|
||||
}
|
||||
|
||||
if apfb[alpn] == nil {
|
||||
|
@ -385,7 +383,7 @@ func (s *Server) fallback(ctx context.Context, sid errors.ExportOption, err erro
|
|||
}
|
||||
pfb := apfb[alpn]
|
||||
if pfb == nil {
|
||||
return newError(`failed to find the default "alpn" config`).AtWarning()
|
||||
return errors.New(`failed to find the default "alpn" config`).AtWarning()
|
||||
}
|
||||
|
||||
path := ""
|
||||
|
@ -405,7 +403,7 @@ func (s *Server) fallback(ctx context.Context, sid errors.ExportOption, err erro
|
|||
}
|
||||
if k == '?' || k == ' ' {
|
||||
path = string(firstBytes[i:j])
|
||||
newError("realPath = " + path).AtInfo().WriteToLog(sid)
|
||||
errors.LogInfo(ctx, "realPath = " + path)
|
||||
if pfb[path] == nil {
|
||||
path = ""
|
||||
}
|
||||
|
@ -419,7 +417,7 @@ func (s *Server) fallback(ctx context.Context, sid errors.ExportOption, err erro
|
|||
}
|
||||
fb := pfb[path]
|
||||
if fb == nil {
|
||||
return newError(`failed to find the default "path" config`).AtWarning()
|
||||
return errors.New(`failed to find the default "path" config`).AtWarning()
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
|
@ -435,7 +433,7 @@ func (s *Server) fallback(ctx context.Context, sid errors.ExportOption, err erro
|
|||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
return newError("failed to dial to " + fb.Dest).Base(err).AtWarning()
|
||||
return errors.New("failed to dial to " + fb.Dest).Base(err).AtWarning()
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
|
@ -495,11 +493,11 @@ func (s *Server) fallback(ctx context.Context, sid errors.ExportOption, err erro
|
|||
common.Must2(pro.Write([]byte{byte(p1 >> 8), byte(p1), byte(p2 >> 8), byte(p2)}))
|
||||
}
|
||||
if err := serverWriter.WriteMultiBuffer(buf.MultiBuffer{pro}); err != nil {
|
||||
return newError("failed to set PROXY protocol v", fb.Xver).Base(err).AtWarning()
|
||||
return errors.New("failed to set PROXY protocol v", fb.Xver).Base(err).AtWarning()
|
||||
}
|
||||
}
|
||||
if err := buf.Copy(reader, serverWriter, buf.UpdateActivity(timer)); err != nil {
|
||||
return newError("failed to fallback request payload").Base(err).AtInfo()
|
||||
return errors.New("failed to fallback request payload").Base(err).AtInfo()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -509,7 +507,7 @@ func (s *Server) fallback(ctx context.Context, sid errors.ExportOption, err erro
|
|||
getResponse := func() error {
|
||||
defer timer.SetTimeout(sessionPolicy.Timeouts.UplinkOnly)
|
||||
if err := buf.Copy(serverReader, writer, buf.UpdateActivity(timer)); err != nil {
|
||||
return newError("failed to deliver response payload").Base(err).AtInfo()
|
||||
return errors.New("failed to deliver response payload").Base(err).AtInfo()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -517,7 +515,7 @@ func (s *Server) fallback(ctx context.Context, sid errors.ExportOption, err erro
|
|||
if err := task.Run(ctx, task.OnSuccess(postRequest, task.Close(serverWriter)), task.OnSuccess(getResponse, task.Close(writer))); err != nil {
|
||||
common.Must(common.Interrupt(serverReader))
|
||||
common.Must(common.Interrupt(serverWriter))
|
||||
return newError("fallback ends").Base(err).AtInfo()
|
||||
return errors.New("fallback ends").Base(err).AtInfo()
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/xtls/xray-core/common/errors"
|
||||
"github.com/xtls/xray-core/common/protocol"
|
||||
)
|
||||
|
||||
|
@ -19,7 +20,7 @@ func (v *Validator) Add(u *protocol.MemoryUser) error {
|
|||
if u.Email != "" {
|
||||
_, loaded := v.email.LoadOrStore(strings.ToLower(u.Email), u)
|
||||
if loaded {
|
||||
return newError("User ", u.Email, " already exists.")
|
||||
return errors.New("User ", u.Email, " already exists.")
|
||||
}
|
||||
}
|
||||
v.users.Store(hexString(u.Account.(*MemoryAccount).Key), u)
|
||||
|
@ -29,12 +30,12 @@ func (v *Validator) Add(u *protocol.MemoryUser) error {
|
|||
// Del a trojan user with a non-empty Email.
|
||||
func (v *Validator) Del(e string) error {
|
||||
if e == "" {
|
||||
return newError("Email must not be empty.")
|
||||
return errors.New("Email must not be empty.")
|
||||
}
|
||||
le := strings.ToLower(e)
|
||||
u, _ := v.email.Load(le)
|
||||
if u == nil {
|
||||
return newError("User ", e, " not found.")
|
||||
return errors.New("User ", e, " not found.")
|
||||
}
|
||||
v.email.Delete(le)
|
||||
v.users.Delete(hexString(u.(*protocol.MemoryUser).Account.(*MemoryAccount).Key))
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package vless
|
||||
|
||||
import (
|
||||
"github.com/xtls/xray-core/common/errors"
|
||||
"github.com/xtls/xray-core/common/protocol"
|
||||
"github.com/xtls/xray-core/common/uuid"
|
||||
)
|
||||
|
@ -9,7 +10,7 @@ import (
|
|||
func (a *Account) AsAccount() (protocol.Account, error) {
|
||||
id, err := uuid.ParseString(a.Id)
|
||||
if err != nil {
|
||||
return nil, newError("failed to parse ID").Base(err).AtError()
|
||||
return nil, errors.New("failed to parse ID").Base(err).AtError()
|
||||
}
|
||||
return &MemoryAccount{
|
||||
ID: protocol.NewID(id),
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"io"
|
||||
|
||||
"github.com/xtls/xray-core/common/buf"
|
||||
"github.com/xtls/xray-core/common/errors"
|
||||
"github.com/xtls/xray-core/common/protocol"
|
||||
"github.com/xtls/xray-core/proxy"
|
||||
"github.com/xtls/xray-core/proxy/vless"
|
||||
|
@ -16,17 +17,17 @@ func EncodeHeaderAddons(buffer *buf.Buffer, addons *Addons) error {
|
|||
case vless.XRV:
|
||||
bytes, err := proto.Marshal(addons)
|
||||
if err != nil {
|
||||
return newError("failed to marshal addons protobuf value").Base(err)
|
||||
return errors.New("failed to marshal addons protobuf value").Base(err)
|
||||
}
|
||||
if err := buffer.WriteByte(byte(len(bytes))); err != nil {
|
||||
return newError("failed to write addons protobuf length").Base(err)
|
||||
return errors.New("failed to write addons protobuf length").Base(err)
|
||||
}
|
||||
if _, err := buffer.Write(bytes); err != nil {
|
||||
return newError("failed to write addons protobuf value").Base(err)
|
||||
return errors.New("failed to write addons protobuf value").Base(err)
|
||||
}
|
||||
default:
|
||||
if err := buffer.WriteByte(0); err != nil {
|
||||
return newError("failed to write addons protobuf length").Base(err)
|
||||
return errors.New("failed to write addons protobuf length").Base(err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,17 +38,17 @@ func DecodeHeaderAddons(buffer *buf.Buffer, reader io.Reader) (*Addons, error) {
|
|||
addons := new(Addons)
|
||||
buffer.Clear()
|
||||
if _, err := buffer.ReadFullFrom(reader, 1); err != nil {
|
||||
return nil, newError("failed to read addons protobuf length").Base(err)
|
||||
return nil, errors.New("failed to read addons protobuf length").Base(err)
|
||||
}
|
||||
|
||||
if length := int32(buffer.Byte(0)); length != 0 {
|
||||
buffer.Clear()
|
||||
if _, err := buffer.ReadFullFrom(reader, length); err != nil {
|
||||
return nil, newError("failed to read addons protobuf value").Base(err)
|
||||
return nil, errors.New("failed to read addons protobuf value").Base(err)
|
||||
}
|
||||
|
||||
if err := proto.Unmarshal(buffer.Bytes(), addons); err != nil {
|
||||
return nil, newError("failed to unmarshal addons protobuf value").Base(err)
|
||||
return nil, errors.New("failed to unmarshal addons protobuf value").Base(err)
|
||||
}
|
||||
|
||||
// Verification.
|
||||
|
@ -149,7 +150,7 @@ func (w *LengthPacketWriter) WriteMultiBuffer(mb buf.MultiBuffer) error {
|
|||
mb[i] = nil
|
||||
}
|
||||
if _, err := w.Write(w.cache); err != nil {
|
||||
return newError("failed to write a packet").Base(err)
|
||||
return errors.New("failed to write a packet").Base(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -168,7 +169,7 @@ type LengthPacketReader struct {
|
|||
|
||||
func (r *LengthPacketReader) ReadMultiBuffer() (buf.MultiBuffer, error) {
|
||||
if _, err := io.ReadFull(r.Reader, r.cache); err != nil { // maybe EOF
|
||||
return nil, newError("failed to read packet length").Base(err)
|
||||
return nil, errors.New("failed to read packet length").Base(err)
|
||||
}
|
||||
length := int32(r.cache[0])<<8 | int32(r.cache[1])
|
||||
// fmt.Println("Read", length)
|
||||
|
@ -181,7 +182,7 @@ func (r *LengthPacketReader) ReadMultiBuffer() (buf.MultiBuffer, error) {
|
|||
length -= size
|
||||
b := buf.New()
|
||||
if _, err := b.ReadFullFrom(r.Reader, size); err != nil {
|
||||
return nil, newError("failed to read packet payload").Base(err)
|
||||
return nil, errors.New("failed to read packet payload").Base(err)
|
||||
}
|
||||
mb = append(mb, b)
|
||||
}
|
||||
|
|
|
@ -35,29 +35,29 @@ func EncodeRequestHeader(writer io.Writer, request *protocol.RequestHeader, requ
|
|||
defer buffer.Release()
|
||||
|
||||
if err := buffer.WriteByte(request.Version); err != nil {
|
||||
return newError("failed to write request version").Base(err)
|
||||
return errors.New("failed to write request version").Base(err)
|
||||
}
|
||||
|
||||
if _, err := buffer.Write(request.User.Account.(*vless.MemoryAccount).ID.Bytes()); err != nil {
|
||||
return newError("failed to write request user id").Base(err)
|
||||
return errors.New("failed to write request user id").Base(err)
|
||||
}
|
||||
|
||||
if err := EncodeHeaderAddons(&buffer, requestAddons); err != nil {
|
||||
return newError("failed to encode request header addons").Base(err)
|
||||
return errors.New("failed to encode request header addons").Base(err)
|
||||
}
|
||||
|
||||
if err := buffer.WriteByte(byte(request.Command)); err != nil {
|
||||
return newError("failed to write request command").Base(err)
|
||||
return errors.New("failed to write request command").Base(err)
|
||||
}
|
||||
|
||||
if request.Command != protocol.RequestCommandMux {
|
||||
if err := addrParser.WriteAddressPort(&buffer, request.Address, request.Port); err != nil {
|
||||
return newError("failed to write request address and port").Base(err)
|
||||
return errors.New("failed to write request address and port").Base(err)
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := writer.Write(buffer.Bytes()); err != nil {
|
||||
return newError("failed to write request header").Base(err)
|
||||
return errors.New("failed to write request header").Base(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -74,7 +74,7 @@ func DecodeRequestHeader(isfb bool, first *buf.Buffer, reader io.Reader, validat
|
|||
request.Version = first.Byte(0)
|
||||
} else {
|
||||
if _, err := buffer.ReadFullFrom(reader, 1); err != nil {
|
||||
return nil, nil, false, newError("failed to read request version").Base(err)
|
||||
return nil, nil, false, errors.New("failed to read request version").Base(err)
|
||||
}
|
||||
request.Version = buffer.Byte(0)
|
||||
}
|
||||
|
@ -89,13 +89,13 @@ func DecodeRequestHeader(isfb bool, first *buf.Buffer, reader io.Reader, validat
|
|||
} else {
|
||||
buffer.Clear()
|
||||
if _, err := buffer.ReadFullFrom(reader, 16); err != nil {
|
||||
return nil, nil, false, newError("failed to read request user id").Base(err)
|
||||
return nil, nil, false, errors.New("failed to read request user id").Base(err)
|
||||
}
|
||||
copy(id[:], buffer.Bytes())
|
||||
}
|
||||
|
||||
if request.User = validator.Get(id); request.User == nil {
|
||||
return nil, nil, isfb, newError("invalid request user id")
|
||||
return nil, nil, isfb, errors.New("invalid request user id")
|
||||
}
|
||||
|
||||
if isfb {
|
||||
|
@ -104,12 +104,12 @@ func DecodeRequestHeader(isfb bool, first *buf.Buffer, reader io.Reader, validat
|
|||
|
||||
requestAddons, err := DecodeHeaderAddons(&buffer, reader)
|
||||
if err != nil {
|
||||
return nil, nil, false, newError("failed to decode request header addons").Base(err)
|
||||
return nil, nil, false, errors.New("failed to decode request header addons").Base(err)
|
||||
}
|
||||
|
||||
buffer.Clear()
|
||||
if _, err := buffer.ReadFullFrom(reader, 1); err != nil {
|
||||
return nil, nil, false, newError("failed to read request command").Base(err)
|
||||
return nil, nil, false, errors.New("failed to read request command").Base(err)
|
||||
}
|
||||
|
||||
request.Command = protocol.RequestCommand(buffer.Byte(0))
|
||||
|
@ -124,11 +124,11 @@ func DecodeRequestHeader(isfb bool, first *buf.Buffer, reader io.Reader, validat
|
|||
}
|
||||
}
|
||||
if request.Address == nil {
|
||||
return nil, nil, false, newError("invalid request address")
|
||||
return nil, nil, false, errors.New("invalid request address")
|
||||
}
|
||||
return request, requestAddons, false, nil
|
||||
default:
|
||||
return nil, nil, isfb, newError("invalid request version")
|
||||
return nil, nil, isfb, errors.New("invalid request version")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -138,15 +138,15 @@ func EncodeResponseHeader(writer io.Writer, request *protocol.RequestHeader, res
|
|||
defer buffer.Release()
|
||||
|
||||
if err := buffer.WriteByte(request.Version); err != nil {
|
||||
return newError("failed to write response version").Base(err)
|
||||
return errors.New("failed to write response version").Base(err)
|
||||
}
|
||||
|
||||
if err := EncodeHeaderAddons(&buffer, responseAddons); err != nil {
|
||||
return newError("failed to encode response header addons").Base(err)
|
||||
return errors.New("failed to encode response header addons").Base(err)
|
||||
}
|
||||
|
||||
if _, err := writer.Write(buffer.Bytes()); err != nil {
|
||||
return newError("failed to write response header").Base(err)
|
||||
return errors.New("failed to write response header").Base(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -158,16 +158,16 @@ func DecodeResponseHeader(reader io.Reader, request *protocol.RequestHeader) (*A
|
|||
defer buffer.Release()
|
||||
|
||||
if _, err := buffer.ReadFullFrom(reader, 1); err != nil {
|
||||
return nil, newError("failed to read response version").Base(err)
|
||||
return nil, errors.New("failed to read response version").Base(err)
|
||||
}
|
||||
|
||||
if buffer.Byte(0) != request.Version {
|
||||
return nil, newError("unexpected response version. Expecting ", int(request.Version), " but actually ", int(buffer.Byte(0)))
|
||||
return nil, errors.New("unexpected response version. Expecting ", int(request.Version), " but actually ", int(buffer.Byte(0)))
|
||||
}
|
||||
|
||||
responseAddons, err := DecodeHeaderAddons(&buffer, reader)
|
||||
if err != nil {
|
||||
return nil, newError("failed to decode response header addons").Base(err)
|
||||
return nil, errors.New("failed to decode response header addons").Base(err)
|
||||
}
|
||||
|
||||
return responseAddons, nil
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
package encoding
|
||||
|
||||
import "github.com/xtls/xray-core/common/errors"
|
||||
|
||||
type errPathObjHolder struct{}
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).WithPathObj(errPathObjHolder{})
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
package vless
|
||||
|
||||
import "github.com/xtls/xray-core/common/errors"
|
||||
|
||||
type errPathObjHolder struct{}
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).WithPathObj(errPathObjHolder{})
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
package inbound
|
||||
|
||||
import "github.com/xtls/xray-core/common/errors"
|
||||
|
||||
type errPathObjHolder struct{}
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).WithPathObj(errPathObjHolder{})
|
||||
}
|
|
@ -72,10 +72,10 @@ func New(ctx context.Context, config *Config, dc dns.Client) (*Handler, error) {
|
|||
for _, user := range config.Clients {
|
||||
u, err := user.ToMemoryUser()
|
||||
if err != nil {
|
||||
return nil, newError("failed to get VLESS user").Base(err).AtError()
|
||||
return nil, errors.New("failed to get VLESS user").Base(err).AtError()
|
||||
}
|
||||
if err := handler.AddUser(ctx, u); err != nil {
|
||||
return nil, newError("failed to initiate user").Base(err).AtError()
|
||||
return nil, errors.New("failed to initiate user").Base(err).AtError()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -93,7 +93,7 @@ func New(ctx context.Context, config *Config, dc dns.Client) (*Handler, error) {
|
|||
/*
|
||||
if fb.Path != "" {
|
||||
if r, err := regexp.Compile(fb.Path); err != nil {
|
||||
return nil, newError("invalid path regexp").Base(err).AtError()
|
||||
return nil, errors.New("invalid path regexp").Base(err).AtError()
|
||||
} else {
|
||||
handler.regexps[fb.Path] = r
|
||||
}
|
||||
|
@ -177,8 +177,6 @@ func (*Handler) Network() []net.Network {
|
|||
|
||||
// Process implements proxy.Inbound.Process().
|
||||
func (h *Handler) Process(ctx context.Context, network net.Network, connection stat.Connection, dispatcher routing.Dispatcher) error {
|
||||
sid := session.ExportIDToError(ctx)
|
||||
|
||||
iConn := connection
|
||||
if statConn, ok := iConn.(*stat.CounterConnection); ok {
|
||||
iConn = statConn.Connection
|
||||
|
@ -186,13 +184,13 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection s
|
|||
|
||||
sessionPolicy := h.policyManager.ForLevel(0)
|
||||
if err := connection.SetReadDeadline(time.Now().Add(sessionPolicy.Timeouts.Handshake)); err != nil {
|
||||
return newError("unable to set read deadline").Base(err).AtWarning()
|
||||
return errors.New("unable to set read deadline").Base(err).AtWarning()
|
||||
}
|
||||
|
||||
first := buf.FromBytes(make([]byte, buf.Size))
|
||||
first.Clear()
|
||||
firstLen, _ := first.ReadFrom(connection)
|
||||
newError("firstLen = ", firstLen).AtInfo().WriteToLog(sid)
|
||||
errors.LogInfo(ctx, "firstLen = ", firstLen)
|
||||
|
||||
reader := &buf.BufferedReader{
|
||||
Reader: buf.NewReader(connection),
|
||||
|
@ -207,7 +205,7 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection s
|
|||
isfb := napfb != nil
|
||||
|
||||
if isfb && firstLen < 18 {
|
||||
err = newError("fallback directly")
|
||||
err = errors.New("fallback directly")
|
||||
} else {
|
||||
request, requestAddons, isfb, err = encoding.DecodeRequestHeader(isfb, first, reader, h.validator)
|
||||
}
|
||||
|
@ -215,9 +213,9 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection s
|
|||
if err != nil {
|
||||
if isfb {
|
||||
if err := connection.SetReadDeadline(time.Time{}); err != nil {
|
||||
newError("unable to set back read deadline").Base(err).AtWarning().WriteToLog(sid)
|
||||
errors.LogWarningInner(ctx, err, "unable to set back read deadline")
|
||||
}
|
||||
newError("fallback starts").Base(err).AtInfo().WriteToLog(sid)
|
||||
errors.LogInfoInner(ctx, err, "fallback starts")
|
||||
|
||||
name := ""
|
||||
alpn := ""
|
||||
|
@ -225,14 +223,14 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection s
|
|||
cs := tlsConn.ConnectionState()
|
||||
name = cs.ServerName
|
||||
alpn = cs.NegotiatedProtocol
|
||||
newError("realName = " + name).AtInfo().WriteToLog(sid)
|
||||
newError("realAlpn = " + alpn).AtInfo().WriteToLog(sid)
|
||||
errors.LogInfo(ctx, "realName = " + name)
|
||||
errors.LogInfo(ctx, "realAlpn = " + alpn)
|
||||
} else if realityConn, ok := iConn.(*reality.Conn); ok {
|
||||
cs := realityConn.ConnectionState()
|
||||
name = cs.ServerName
|
||||
alpn = cs.NegotiatedProtocol
|
||||
newError("realName = " + name).AtInfo().WriteToLog(sid)
|
||||
newError("realAlpn = " + alpn).AtInfo().WriteToLog(sid)
|
||||
errors.LogInfo(ctx, "realName = " + name)
|
||||
errors.LogInfo(ctx, "realAlpn = " + alpn)
|
||||
}
|
||||
name = strings.ToLower(name)
|
||||
alpn = strings.ToLower(alpn)
|
||||
|
@ -254,7 +252,7 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection s
|
|||
}
|
||||
apfb := napfb[name]
|
||||
if apfb == nil {
|
||||
return newError(`failed to find the default "name" config`).AtWarning()
|
||||
return errors.New(`failed to find the default "name" config`).AtWarning()
|
||||
}
|
||||
|
||||
if apfb[alpn] == nil {
|
||||
|
@ -262,7 +260,7 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection s
|
|||
}
|
||||
pfb := apfb[alpn]
|
||||
if pfb == nil {
|
||||
return newError(`failed to find the default "alpn" config`).AtWarning()
|
||||
return errors.New(`failed to find the default "alpn" config`).AtWarning()
|
||||
}
|
||||
|
||||
path := ""
|
||||
|
@ -271,7 +269,7 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection s
|
|||
if lines := bytes.Split(firstBytes, []byte{'\r', '\n'}); len(lines) > 1 {
|
||||
if s := bytes.Split(lines[0], []byte{' '}); len(s) == 3 {
|
||||
if len(s[0]) < 8 && len(s[1]) > 0 && len(s[2]) == 8 {
|
||||
newError("realPath = " + string(s[1])).AtInfo().WriteToLog(sid)
|
||||
errors.New("realPath = " + string(s[1])).AtInfo().WriteToLog(sid)
|
||||
for _, fb := range pfb {
|
||||
if fb.Path != "" && h.regexps[fb.Path].Match(s[1]) {
|
||||
path = fb.Path
|
||||
|
@ -297,7 +295,7 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection s
|
|||
}
|
||||
if k == '?' || k == ' ' {
|
||||
path = string(firstBytes[i:j])
|
||||
newError("realPath = " + path).AtInfo().WriteToLog(sid)
|
||||
errors.LogInfo(ctx, "realPath = " + path)
|
||||
if pfb[path] == nil {
|
||||
path = ""
|
||||
}
|
||||
|
@ -311,7 +309,7 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection s
|
|||
}
|
||||
fb := pfb[path]
|
||||
if fb == nil {
|
||||
return newError(`failed to find the default "path" config`).AtWarning()
|
||||
return errors.New(`failed to find the default "path" config`).AtWarning()
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
|
@ -327,7 +325,7 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection s
|
|||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
return newError("failed to dial to " + fb.Dest).Base(err).AtWarning()
|
||||
return errors.New("failed to dial to " + fb.Dest).Base(err).AtWarning()
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
|
@ -387,11 +385,11 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection s
|
|||
pro.Write([]byte{byte(p1 >> 8), byte(p1), byte(p2 >> 8), byte(p2)})
|
||||
}
|
||||
if err := serverWriter.WriteMultiBuffer(buf.MultiBuffer{pro}); err != nil {
|
||||
return newError("failed to set PROXY protocol v", fb.Xver).Base(err).AtWarning()
|
||||
return errors.New("failed to set PROXY protocol v", fb.Xver).Base(err).AtWarning()
|
||||
}
|
||||
}
|
||||
if err := buf.Copy(reader, serverWriter, buf.UpdateActivity(timer)); err != nil {
|
||||
return newError("failed to fallback request payload").Base(err).AtInfo()
|
||||
return errors.New("failed to fallback request payload").Base(err).AtInfo()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -401,7 +399,7 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection s
|
|||
getResponse := func() error {
|
||||
defer timer.SetTimeout(sessionPolicy.Timeouts.UplinkOnly)
|
||||
if err := buf.Copy(serverReader, writer, buf.UpdateActivity(timer)); err != nil {
|
||||
return newError("failed to deliver response payload").Base(err).AtInfo()
|
||||
return errors.New("failed to deliver response payload").Base(err).AtInfo()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -409,7 +407,7 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection s
|
|||
if err := task.Run(ctx, task.OnSuccess(postRequest, task.Close(serverWriter)), task.OnSuccess(getResponse, task.Close(writer))); err != nil {
|
||||
common.Interrupt(serverReader)
|
||||
common.Interrupt(serverWriter)
|
||||
return newError("fallback ends").Base(err).AtInfo()
|
||||
return errors.New("fallback ends").Base(err).AtInfo()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -421,15 +419,15 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection s
|
|||
Status: log.AccessRejected,
|
||||
Reason: err,
|
||||
})
|
||||
err = newError("invalid request from ", connection.RemoteAddr()).Base(err).AtInfo()
|
||||
err = errors.New("invalid request from ", connection.RemoteAddr()).Base(err).AtInfo()
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
if err := connection.SetReadDeadline(time.Time{}); err != nil {
|
||||
newError("unable to set back read deadline").Base(err).AtWarning().WriteToLog(sid)
|
||||
errors.LogWarningInner(ctx, err, "unable to set back read deadline")
|
||||
}
|
||||
newError("received request for ", request.Destination()).AtInfo().WriteToLog(sid)
|
||||
errors.LogInfo(ctx, "received request for ", request.Destination())
|
||||
|
||||
inbound := session.InboundFromContext(ctx)
|
||||
if inbound == nil {
|
||||
|
@ -452,7 +450,7 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection s
|
|||
inbound.CanSpliceCopy = 2
|
||||
switch request.Command {
|
||||
case protocol.RequestCommandUDP:
|
||||
return newError(requestAddons.Flow + " doesn't support UDP").AtWarning()
|
||||
return errors.New(requestAddons.Flow + " doesn't support UDP").AtWarning()
|
||||
case protocol.RequestCommandMux:
|
||||
fallthrough // we will break Mux connections that contain TCP requests
|
||||
case protocol.RequestCommandTCP:
|
||||
|
@ -460,7 +458,7 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection s
|
|||
var p uintptr
|
||||
if tlsConn, ok := iConn.(*tls.Conn); ok {
|
||||
if tlsConn.ConnectionState().Version != gotls.VersionTLS13 {
|
||||
return newError(`failed to use `+requestAddons.Flow+`, found outer tls version `, tlsConn.ConnectionState().Version).AtWarning()
|
||||
return errors.New(`failed to use `+requestAddons.Flow+`, found outer tls version `, tlsConn.ConnectionState().Version).AtWarning()
|
||||
}
|
||||
t = reflect.TypeOf(tlsConn.Conn).Elem()
|
||||
p = uintptr(unsafe.Pointer(tlsConn.Conn))
|
||||
|
@ -468,7 +466,7 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection s
|
|||
t = reflect.TypeOf(realityConn.Conn).Elem()
|
||||
p = uintptr(unsafe.Pointer(realityConn.Conn))
|
||||
} else {
|
||||
return newError("XTLS only supports TLS and REALITY directly for now.").AtWarning()
|
||||
return errors.New("XTLS only supports TLS and REALITY directly for now.").AtWarning()
|
||||
}
|
||||
i, _ := t.FieldByName("input")
|
||||
r, _ := t.FieldByName("rawInput")
|
||||
|
@ -476,15 +474,15 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection s
|
|||
rawInput = (*bytes.Buffer)(unsafe.Pointer(p + r.Offset))
|
||||
}
|
||||
} else {
|
||||
return newError(account.ID.String() + " is not able to use " + requestAddons.Flow).AtWarning()
|
||||
return errors.New(account.ID.String() + " is not able to use " + requestAddons.Flow).AtWarning()
|
||||
}
|
||||
case "":
|
||||
inbound.CanSpliceCopy = 3
|
||||
if account.Flow == vless.XRV && (request.Command == protocol.RequestCommandTCP || isMuxAndNotXUDP(request, first)) {
|
||||
return newError(account.ID.String() + " is not able to use \"\". Note that the pure TLS proxy has certain TLS in TLS characters.").AtWarning()
|
||||
return errors.New(account.ID.String() + " is not able to use \"\". Note that the pure TLS proxy has certain TLS in TLS characters.").AtWarning()
|
||||
}
|
||||
default:
|
||||
return newError("unknown request flow " + requestAddons.Flow).AtWarning()
|
||||
return errors.New("unknown request flow " + requestAddons.Flow).AtWarning()
|
||||
}
|
||||
|
||||
if request.Command != protocol.RequestCommandMux {
|
||||
|
@ -507,7 +505,7 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection s
|
|||
|
||||
link, err := dispatcher.Dispatch(ctx, request.Destination())
|
||||
if err != nil {
|
||||
return newError("failed to dispatch request to ", request.Destination()).Base(err).AtWarning()
|
||||
return errors.New("failed to dispatch request to ", request.Destination()).Base(err).AtWarning()
|
||||
}
|
||||
|
||||
serverReader := link.Reader // .(*pipe.Reader)
|
||||
|
@ -531,7 +529,7 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection s
|
|||
}
|
||||
|
||||
if err != nil {
|
||||
return newError("failed to transfer request payload").Base(err).AtInfo()
|
||||
return errors.New("failed to transfer request payload").Base(err).AtInfo()
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -542,7 +540,7 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection s
|
|||
|
||||
bufferWriter := buf.NewBufferedWriter(buf.NewWriter(connection))
|
||||
if err := encoding.EncodeResponseHeader(bufferWriter, request, responseAddons); err != nil {
|
||||
return newError("failed to encode response header").Base(err).AtWarning()
|
||||
return errors.New("failed to encode response header").Base(err).AtWarning()
|
||||
}
|
||||
|
||||
// default: clientWriter := bufferWriter
|
||||
|
@ -556,7 +554,7 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection s
|
|||
}
|
||||
// Flush; bufferWriter.WriteMultiBufer now is bufferWriter.writer.WriteMultiBuffer
|
||||
if err := bufferWriter.SetBuffered(false); err != nil {
|
||||
return newError("failed to write A response payload").Base(err).AtWarning()
|
||||
return errors.New("failed to write A response payload").Base(err).AtWarning()
|
||||
}
|
||||
|
||||
var err error
|
||||
|
@ -567,7 +565,7 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection s
|
|||
err = buf.Copy(serverReader, clientWriter, buf.UpdateActivity(timer))
|
||||
}
|
||||
if err != nil {
|
||||
return newError("failed to transfer response payload").Base(err).AtInfo()
|
||||
return errors.New("failed to transfer response payload").Base(err).AtInfo()
|
||||
}
|
||||
// Indicates the end of response payload.
|
||||
switch responseAddons.Flow {
|
||||
|
@ -580,7 +578,7 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection s
|
|||
if err := task.Run(ctx, task.OnSuccess(postRequest, task.Close(serverWriter)), getResponse); err != nil {
|
||||
common.Interrupt(serverReader)
|
||||
common.Interrupt(serverWriter)
|
||||
return newError("connection ends").Base(err).AtInfo()
|
||||
return errors.New("connection ends").Base(err).AtInfo()
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
package outbound
|
||||
|
||||
import "github.com/xtls/xray-core/common/errors"
|
||||
|
||||
type errPathObjHolder struct{}
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).WithPathObj(errPathObjHolder{})
|
||||
}
|
|
@ -13,6 +13,7 @@ import (
|
|||
utls "github.com/refraction-networking/utls"
|
||||
"github.com/xtls/xray-core/common"
|
||||
"github.com/xtls/xray-core/common/buf"
|
||||
"github.com/xtls/xray-core/common/errors"
|
||||
"github.com/xtls/xray-core/common/net"
|
||||
"github.com/xtls/xray-core/common/protocol"
|
||||
"github.com/xtls/xray-core/common/retry"
|
||||
|
@ -52,7 +53,7 @@ func New(ctx context.Context, config *Config) (*Handler, error) {
|
|||
for _, rec := range config.Vnext {
|
||||
s, err := protocol.NewServerSpecFromPB(rec)
|
||||
if err != nil {
|
||||
return nil, newError("failed to parse server spec").Base(err).AtError()
|
||||
return nil, errors.New("failed to parse server spec").Base(err).AtError()
|
||||
}
|
||||
serverList.AddServer(s)
|
||||
}
|
||||
|
@ -71,9 +72,9 @@ func New(ctx context.Context, config *Config) (*Handler, error) {
|
|||
// Process implements proxy.Outbound.Process().
|
||||
func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer internet.Dialer) error {
|
||||
outbounds := session.OutboundsFromContext(ctx)
|
||||
ob := outbounds[len(outbounds) - 1]
|
||||
ob := outbounds[len(outbounds)-1]
|
||||
if !ob.Target.IsValid() {
|
||||
return newError("target not specified").AtError()
|
||||
return errors.New("target not specified").AtError()
|
||||
}
|
||||
ob.Name = "vless"
|
||||
|
||||
|
@ -88,7 +89,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
|||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
return newError("failed to find an available destination").Base(err).AtWarning()
|
||||
return errors.New("failed to find an available destination").Base(err).AtWarning()
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
|
@ -97,7 +98,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
|||
iConn = statConn.Connection
|
||||
}
|
||||
target := ob.Target
|
||||
newError("tunneling request to ", target, " via ", rec.Destination().NetAddr()).AtInfo().WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfo(ctx, "tunneling request to ", target, " via ", rec.Destination().NetAddr())
|
||||
|
||||
command := protocol.RequestCommandTCP
|
||||
if target.Network == net.Network_UDP {
|
||||
|
@ -134,7 +135,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
|||
switch request.Command {
|
||||
case protocol.RequestCommandUDP:
|
||||
if !allowUDP443 && request.Port == 443 {
|
||||
return newError("XTLS rejected UDP/443 traffic").AtInfo()
|
||||
return errors.New("XTLS rejected UDP/443 traffic").AtInfo()
|
||||
}
|
||||
case protocol.RequestCommandMux:
|
||||
fallthrough // let server break Mux connections that contain TCP requests
|
||||
|
@ -151,7 +152,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
|||
t = reflect.TypeOf(realityConn.Conn).Elem()
|
||||
p = uintptr(unsafe.Pointer(realityConn.Conn))
|
||||
} else {
|
||||
return newError("XTLS only supports TLS and REALITY directly for now.").AtWarning()
|
||||
return errors.New("XTLS only supports TLS and REALITY directly for now.").AtWarning()
|
||||
}
|
||||
i, _ := t.FieldByName("input")
|
||||
r, _ := t.FieldByName("rawInput")
|
||||
|
@ -191,7 +192,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
|||
|
||||
bufferWriter := buf.NewBufferedWriter(buf.NewWriter(conn))
|
||||
if err := encoding.EncodeRequestHeader(bufferWriter, request, requestAddons); err != nil {
|
||||
return newError("failed to encode request header").Base(err).AtWarning()
|
||||
return errors.New("failed to encode request header").Base(err).AtWarning()
|
||||
}
|
||||
|
||||
// default: serverWriter := bufferWriter
|
||||
|
@ -210,28 +211,28 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
|||
return err1
|
||||
} else if requestAddons.Flow == vless.XRV {
|
||||
mb := make(buf.MultiBuffer, 1)
|
||||
newError("Insert padding with empty content to camouflage VLESS header ", mb.Len()).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfo(ctx, "Insert padding with empty content to camouflage VLESS header ", mb.Len())
|
||||
if err := serverWriter.WriteMultiBuffer(mb); err != nil {
|
||||
return err // ...
|
||||
}
|
||||
}
|
||||
} else {
|
||||
newError("Reader is not timeout reader, will send out vless header separately from first payload").AtDebug().WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogDebug(ctx, "Reader is not timeout reader, will send out vless header separately from first payload")
|
||||
}
|
||||
// Flush; bufferWriter.WriteMultiBufer now is bufferWriter.writer.WriteMultiBuffer
|
||||
if err := bufferWriter.SetBuffered(false); err != nil {
|
||||
return newError("failed to write A request payload").Base(err).AtWarning()
|
||||
return errors.New("failed to write A request payload").Base(err).AtWarning()
|
||||
}
|
||||
|
||||
var err error
|
||||
if requestAddons.Flow == vless.XRV {
|
||||
if tlsConn, ok := iConn.(*tls.Conn); ok {
|
||||
if tlsConn.ConnectionState().Version != gotls.VersionTLS13 {
|
||||
return newError(`failed to use `+requestAddons.Flow+`, found outer tls version `, tlsConn.ConnectionState().Version).AtWarning()
|
||||
return errors.New(`failed to use `+requestAddons.Flow+`, found outer tls version `, tlsConn.ConnectionState().Version).AtWarning()
|
||||
}
|
||||
} else if utlsConn, ok := iConn.(*tls.UConn); ok {
|
||||
if utlsConn.ConnectionState().Version != utls.VersionTLS13 {
|
||||
return newError(`failed to use `+requestAddons.Flow+`, found outer tls version `, utlsConn.ConnectionState().Version).AtWarning()
|
||||
return errors.New(`failed to use `+requestAddons.Flow+`, found outer tls version `, utlsConn.ConnectionState().Version).AtWarning()
|
||||
}
|
||||
}
|
||||
ctx1 := session.ContextWithInbound(ctx, nil) // TODO enable splice
|
||||
|
@ -241,7 +242,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
|||
err = buf.Copy(clientReader, serverWriter, buf.UpdateActivity(timer))
|
||||
}
|
||||
if err != nil {
|
||||
return newError("failed to transfer request payload").Base(err).AtInfo()
|
||||
return errors.New("failed to transfer request payload").Base(err).AtInfo()
|
||||
}
|
||||
|
||||
// Indicates the end of request payload.
|
||||
|
@ -256,7 +257,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
|||
|
||||
responseAddons, err := encoding.DecodeResponseHeader(conn, request)
|
||||
if err != nil {
|
||||
return newError("failed to decode response header").Base(err).AtInfo()
|
||||
return errors.New("failed to decode response header").Base(err).AtInfo()
|
||||
}
|
||||
|
||||
// default: serverReader := buf.NewReader(conn)
|
||||
|
@ -280,7 +281,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
|||
}
|
||||
|
||||
if err != nil {
|
||||
return newError("failed to transfer response payload").Base(err).AtInfo()
|
||||
return errors.New("failed to transfer response payload").Base(err).AtInfo()
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -291,7 +292,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
|||
}
|
||||
|
||||
if err := task.Run(ctx, postRequest, task.OnSuccess(getResponse, task.Close(clientWriter))); err != nil {
|
||||
return newError("connection ends").Base(err).AtInfo()
|
||||
return errors.New("connection ends").Base(err).AtInfo()
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/xtls/xray-core/common/errors"
|
||||
"github.com/xtls/xray-core/common/protocol"
|
||||
"github.com/xtls/xray-core/common/uuid"
|
||||
)
|
||||
|
@ -20,7 +21,7 @@ func (v *Validator) Add(u *protocol.MemoryUser) error {
|
|||
if u.Email != "" {
|
||||
_, loaded := v.email.LoadOrStore(strings.ToLower(u.Email), u)
|
||||
if loaded {
|
||||
return newError("User ", u.Email, " already exists.")
|
||||
return errors.New("User ", u.Email, " already exists.")
|
||||
}
|
||||
}
|
||||
v.users.Store(u.Account.(*MemoryAccount).ID.UUID(), u)
|
||||
|
@ -30,12 +31,12 @@ func (v *Validator) Add(u *protocol.MemoryUser) error {
|
|||
// Del a VLESS user with a non-empty Email.
|
||||
func (v *Validator) Del(e string) error {
|
||||
if e == "" {
|
||||
return newError("Email must not be empty.")
|
||||
return errors.New("Email must not be empty.")
|
||||
}
|
||||
le := strings.ToLower(e)
|
||||
u, _ := v.email.Load(le)
|
||||
if u == nil {
|
||||
return newError("User ", e, " not found.")
|
||||
return errors.New("User ", e, " not found.")
|
||||
}
|
||||
v.email.Delete(le)
|
||||
v.users.Delete(u.(*protocol.MemoryUser).Account.(*MemoryAccount).ID.UUID())
|
||||
|
|
|
@ -3,6 +3,7 @@ package vmess
|
|||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/xtls/xray-core/common/errors"
|
||||
"github.com/xtls/xray-core/common/protocol"
|
||||
"github.com/xtls/xray-core/common/uuid"
|
||||
)
|
||||
|
@ -31,7 +32,7 @@ func (a *MemoryAccount) Equals(account protocol.Account) bool {
|
|||
func (a *Account) AsAccount() (protocol.Account, error) {
|
||||
id, err := uuid.ParseString(a.Id)
|
||||
if err != nil {
|
||||
return nil, newError("failed to parse ID").Base(err).AtError()
|
||||
return nil, errors.New("failed to parse ID").Base(err).AtError()
|
||||
}
|
||||
protoID := protocol.NewID(id)
|
||||
var AuthenticatedLength, NoTerminationSignal bool
|
||||
|
|
|
@ -17,6 +17,7 @@ import (
|
|||
"github.com/xtls/xray-core/common/crypto"
|
||||
"github.com/xtls/xray-core/common/dice"
|
||||
"github.com/xtls/xray-core/common/drain"
|
||||
"github.com/xtls/xray-core/common/errors"
|
||||
"github.com/xtls/xray-core/common/protocol"
|
||||
"github.com/xtls/xray-core/proxy/vmess"
|
||||
vmessaead "github.com/xtls/xray-core/proxy/vmess/aead"
|
||||
|
@ -53,7 +54,7 @@ func NewClientSession(ctx context.Context, behaviorSeed int64) *ClientSession {
|
|||
var err error
|
||||
session.readDrainer, err = drain.NewBehaviorSeedLimitedDrainer(behaviorSeed, 18, 3266, 64)
|
||||
if err != nil {
|
||||
newError("unable to initialize drainer").Base(err).WriteToLog()
|
||||
errors.LogInfoInner(ctx, err, "unable to initialize drainer")
|
||||
session.readDrainer = drain.NewNopDrainer()
|
||||
}
|
||||
}
|
||||
|
@ -79,7 +80,7 @@ func (c *ClientSession) EncodeRequestHeader(header *protocol.RequestHeader, writ
|
|||
|
||||
if header.Command != protocol.RequestCommandMux {
|
||||
if err := addrParser.WriteAddressPort(buffer, header.Address, header.Port); err != nil {
|
||||
return newError("failed to writer address and port").Base(err)
|
||||
return errors.New("failed to writer address and port").Base(err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -112,7 +113,7 @@ func (c *ClientSession) EncodeRequestBody(request *protocol.RequestHeader, write
|
|||
var ok bool
|
||||
padding, ok = sizeParser.(crypto.PaddingLengthGenerator)
|
||||
if !ok {
|
||||
return nil, newError("invalid option: RequestOptionGlobalPadding")
|
||||
return nil, errors.New("invalid option: RequestOptionGlobalPadding")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -173,7 +174,7 @@ func (c *ClientSession) EncodeRequestBody(request *protocol.RequestHeader, write
|
|||
}
|
||||
return crypto.NewAuthenticationWriter(auth, sizeParser, writer, request.Command.TransferType(), padding), nil
|
||||
default:
|
||||
return nil, newError("invalid option: Security")
|
||||
return nil, errors.New("invalid option: Security")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -190,12 +191,12 @@ func (c *ClientSession) DecodeResponseHeader(reader io.Reader) (*protocol.Respon
|
|||
|
||||
if n, err := io.ReadFull(reader, aeadEncryptedResponseHeaderLength[:]); err != nil {
|
||||
c.readDrainer.AcknowledgeReceive(n)
|
||||
return nil, drain.WithError(c.readDrainer, reader, newError("Unable to Read Header Len").Base(err))
|
||||
return nil, drain.WithError(c.readDrainer, reader, errors.New("Unable to Read Header Len").Base(err))
|
||||
} else { // nolint: golint
|
||||
c.readDrainer.AcknowledgeReceive(n)
|
||||
}
|
||||
if decryptedResponseHeaderLengthBinaryBuffer, err := aeadResponseHeaderLengthEncryptionAEAD.Open(nil, aeadResponseHeaderLengthEncryptionIV, aeadEncryptedResponseHeaderLength[:], nil); err != nil {
|
||||
return nil, drain.WithError(c.readDrainer, reader, newError("Failed To Decrypt Length").Base(err))
|
||||
return nil, drain.WithError(c.readDrainer, reader, errors.New("Failed To Decrypt Length").Base(err))
|
||||
} else { // nolint: golint
|
||||
common.Must(binary.Read(bytes.NewReader(decryptedResponseHeaderLengthBinaryBuffer), binary.BigEndian, &decryptedResponseHeaderLengthBinaryDeserializeBuffer))
|
||||
decryptedResponseHeaderLength = int(decryptedResponseHeaderLengthBinaryDeserializeBuffer)
|
||||
|
@ -211,13 +212,13 @@ func (c *ClientSession) DecodeResponseHeader(reader io.Reader) (*protocol.Respon
|
|||
|
||||
if n, err := io.ReadFull(reader, encryptedResponseHeaderBuffer); err != nil {
|
||||
c.readDrainer.AcknowledgeReceive(n)
|
||||
return nil, drain.WithError(c.readDrainer, reader, newError("Unable to Read Header Data").Base(err))
|
||||
return nil, drain.WithError(c.readDrainer, reader, errors.New("Unable to Read Header Data").Base(err))
|
||||
} else { // nolint: golint
|
||||
c.readDrainer.AcknowledgeReceive(n)
|
||||
}
|
||||
|
||||
if decryptedResponseHeaderBuffer, err := aeadResponseHeaderPayloadEncryptionAEAD.Open(nil, aeadResponseHeaderPayloadEncryptionIV, encryptedResponseHeaderBuffer, nil); err != nil {
|
||||
return nil, drain.WithError(c.readDrainer, reader, newError("Failed To Decrypt Payload").Base(err))
|
||||
return nil, drain.WithError(c.readDrainer, reader, errors.New("Failed To Decrypt Payload").Base(err))
|
||||
} else { // nolint: golint
|
||||
c.responseReader = bytes.NewReader(decryptedResponseHeaderBuffer)
|
||||
}
|
||||
|
@ -226,11 +227,11 @@ func (c *ClientSession) DecodeResponseHeader(reader io.Reader) (*protocol.Respon
|
|||
defer buffer.Release()
|
||||
|
||||
if _, err := buffer.ReadFullFrom(c.responseReader, 4); err != nil {
|
||||
return nil, newError("failed to read response header").Base(err).AtWarning()
|
||||
return nil, errors.New("failed to read response header").Base(err).AtWarning()
|
||||
}
|
||||
|
||||
if buffer.Byte(0) != c.responseHeader {
|
||||
return nil, newError("unexpected response header. Expecting ", int(c.responseHeader), " but actually ", int(buffer.Byte(0)))
|
||||
return nil, errors.New("unexpected response header. Expecting ", int(c.responseHeader), " but actually ", int(buffer.Byte(0)))
|
||||
}
|
||||
|
||||
header := &protocol.ResponseHeader{
|
||||
|
@ -243,7 +244,7 @@ func (c *ClientSession) DecodeResponseHeader(reader io.Reader) (*protocol.Respon
|
|||
|
||||
buffer.Clear()
|
||||
if _, err := buffer.ReadFullFrom(c.responseReader, dataLen); err != nil {
|
||||
return nil, newError("failed to read response command").Base(err)
|
||||
return nil, errors.New("failed to read response command").Base(err)
|
||||
}
|
||||
command, err := UnmarshalCommand(cmdID, buffer.Bytes())
|
||||
if err == nil {
|
||||
|
@ -265,7 +266,7 @@ func (c *ClientSession) DecodeResponseBody(request *protocol.RequestHeader, read
|
|||
var ok bool
|
||||
padding, ok = sizeParser.(crypto.PaddingLengthGenerator)
|
||||
if !ok {
|
||||
return nil, newError("invalid option: RequestOptionGlobalPadding")
|
||||
return nil, errors.New("invalid option: RequestOptionGlobalPadding")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -328,7 +329,7 @@ func (c *ClientSession) DecodeResponseBody(request *protocol.RequestHeader, read
|
|||
}
|
||||
return crypto.NewAuthenticationReader(auth, sizeParser, reader, request.Command.TransferType(), padding), nil
|
||||
default:
|
||||
return nil, newError("invalid option: Security")
|
||||
return nil, errors.New("invalid option: Security")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
|
||||
"github.com/xtls/xray-core/common"
|
||||
"github.com/xtls/xray-core/common/buf"
|
||||
"github.com/xtls/xray-core/common/errors"
|
||||
"github.com/xtls/xray-core/common/net"
|
||||
"github.com/xtls/xray-core/common/protocol"
|
||||
"github.com/xtls/xray-core/common/serial"
|
||||
|
@ -13,11 +14,11 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
ErrCommandTooLarge = newError("Command too large.")
|
||||
ErrCommandTypeMismatch = newError("Command type mismatch.")
|
||||
ErrInvalidAuth = newError("Invalid auth.")
|
||||
ErrInsufficientLength = newError("Insufficient length.")
|
||||
ErrUnknownCommand = newError("Unknown command.")
|
||||
ErrCommandTooLarge = errors.New("Command too large.")
|
||||
ErrCommandTypeMismatch = errors.New("Command type mismatch.")
|
||||
ErrInvalidAuth = errors.New("Invalid auth.")
|
||||
ErrInsufficientLength = errors.New("Insufficient length.")
|
||||
ErrUnknownCommand = errors.New("Unknown command.")
|
||||
)
|
||||
|
||||
func MarshalCommand(command interface{}, writer io.Writer) error {
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
package encoding
|
||||
|
||||
import "github.com/xtls/xray-core/common/errors"
|
||||
|
||||
type errPathObjHolder struct{}
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).WithPathObj(errPathObjHolder{})
|
||||
}
|
|
@ -16,6 +16,7 @@ import (
|
|||
"github.com/xtls/xray-core/common/buf"
|
||||
"github.com/xtls/xray-core/common/crypto"
|
||||
"github.com/xtls/xray-core/common/drain"
|
||||
"github.com/xtls/xray-core/common/errors"
|
||||
"github.com/xtls/xray-core/common/net"
|
||||
"github.com/xtls/xray-core/common/protocol"
|
||||
"github.com/xtls/xray-core/common/task"
|
||||
|
@ -75,7 +76,7 @@ func (h *SessionHistory) removeExpiredEntries() error {
|
|||
defer h.Unlock()
|
||||
|
||||
if len(h.cache) == 0 {
|
||||
return newError("nothing to do")
|
||||
return errors.New("nothing to do")
|
||||
}
|
||||
|
||||
for session, expire := range h.cache {
|
||||
|
@ -130,7 +131,7 @@ func (s *ServerSession) DecodeRequestHeader(reader io.Reader, isDrain bool) (*pr
|
|||
|
||||
drainer, err := drain.NewBehaviorSeedLimitedDrainer(int64(s.userValidator.GetBehaviorSeed()), 16+38, 3266, 64)
|
||||
if err != nil {
|
||||
return nil, newError("failed to initialize drainer").Base(err)
|
||||
return nil, errors.New("failed to initialize drainer").Base(err)
|
||||
}
|
||||
|
||||
drainConnection := func(e error) error {
|
||||
|
@ -147,7 +148,7 @@ func (s *ServerSession) DecodeRequestHeader(reader io.Reader, isDrain bool) (*pr
|
|||
}()
|
||||
|
||||
if _, err := buffer.ReadFullFrom(reader, protocol.IDBytesLen); err != nil {
|
||||
return nil, newError("failed to read request header").Base(err)
|
||||
return nil, errors.New("failed to read request header").Base(err)
|
||||
}
|
||||
|
||||
var decryptor io.Reader
|
||||
|
@ -167,20 +168,20 @@ func (s *ServerSession) DecodeRequestHeader(reader io.Reader, isDrain bool) (*pr
|
|||
if errorReason != nil {
|
||||
if shouldDrain {
|
||||
drainer.AcknowledgeReceive(bytesRead)
|
||||
return nil, drainConnection(newError("AEAD read failed").Base(errorReason))
|
||||
return nil, drainConnection(errors.New("AEAD read failed").Base(errorReason))
|
||||
} else {
|
||||
return nil, drainConnection(newError("AEAD read failed, drain skipped").Base(errorReason))
|
||||
return nil, drainConnection(errors.New("AEAD read failed, drain skipped").Base(errorReason))
|
||||
}
|
||||
}
|
||||
decryptor = bytes.NewReader(aeadData)
|
||||
default:
|
||||
return nil, drainConnection(newError("invalid user").Base(errorAEAD))
|
||||
return nil, drainConnection(errors.New("invalid user").Base(errorAEAD))
|
||||
}
|
||||
|
||||
drainer.AcknowledgeReceive(int(buffer.Len()))
|
||||
buffer.Clear()
|
||||
if _, err := buffer.ReadFullFrom(decryptor, 38); err != nil {
|
||||
return nil, newError("failed to read request header").Base(err)
|
||||
return nil, errors.New("failed to read request header").Base(err)
|
||||
}
|
||||
|
||||
request := &protocol.RequestHeader{
|
||||
|
@ -195,7 +196,7 @@ func (s *ServerSession) DecodeRequestHeader(reader io.Reader, isDrain bool) (*pr
|
|||
sid.key = s.requestBodyKey
|
||||
sid.nonce = s.requestBodyIV
|
||||
if !s.sessionHistory.addIfNotExits(sid) {
|
||||
return nil, newError("duplicated session id, possibly under replay attack, but this is a AEAD request")
|
||||
return nil, errors.New("duplicated session id, possibly under replay attack, but this is a AEAD request")
|
||||
}
|
||||
|
||||
s.responseHeader = buffer.Byte(33) // 1 byte
|
||||
|
@ -219,12 +220,12 @@ func (s *ServerSession) DecodeRequestHeader(reader io.Reader, isDrain bool) (*pr
|
|||
|
||||
if paddingLen > 0 {
|
||||
if _, err := buffer.ReadFullFrom(decryptor, int32(paddingLen)); err != nil {
|
||||
return nil, newError("failed to read padding").Base(err)
|
||||
return nil, errors.New("failed to read padding").Base(err)
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := buffer.ReadFullFrom(decryptor, 4); err != nil {
|
||||
return nil, newError("failed to read checksum").Base(err)
|
||||
return nil, errors.New("failed to read checksum").Base(err)
|
||||
}
|
||||
|
||||
fnv1a := fnv.New32a()
|
||||
|
@ -233,15 +234,15 @@ func (s *ServerSession) DecodeRequestHeader(reader io.Reader, isDrain bool) (*pr
|
|||
expectedHash := binary.BigEndian.Uint32(buffer.BytesFrom(-4))
|
||||
|
||||
if actualHash != expectedHash {
|
||||
return nil, newError("invalid auth, but this is a AEAD request")
|
||||
return nil, errors.New("invalid auth, but this is a AEAD request")
|
||||
}
|
||||
|
||||
if request.Address == nil {
|
||||
return nil, newError("invalid remote address")
|
||||
return nil, errors.New("invalid remote address")
|
||||
}
|
||||
|
||||
if request.Security == protocol.SecurityType_UNKNOWN || request.Security == protocol.SecurityType_AUTO {
|
||||
return nil, newError("unknown security type: ", request.Security)
|
||||
return nil, errors.New("unknown security type: ", request.Security)
|
||||
}
|
||||
|
||||
return request, nil
|
||||
|
@ -258,7 +259,7 @@ func (s *ServerSession) DecodeRequestBody(request *protocol.RequestHeader, reade
|
|||
var ok bool
|
||||
padding, ok = sizeParser.(crypto.PaddingLengthGenerator)
|
||||
if !ok {
|
||||
return nil, newError("invalid option: RequestOptionGlobalPadding")
|
||||
return nil, errors.New("invalid option: RequestOptionGlobalPadding")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -321,7 +322,7 @@ func (s *ServerSession) DecodeRequestBody(request *protocol.RequestHeader, reade
|
|||
return crypto.NewAuthenticationReader(auth, sizeParser, reader, request.Command.TransferType(), padding), nil
|
||||
|
||||
default:
|
||||
return nil, newError("invalid option: Security")
|
||||
return nil, errors.New("invalid option: Security")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -382,7 +383,7 @@ func (s *ServerSession) EncodeResponseBody(request *protocol.RequestHeader, writ
|
|||
var ok bool
|
||||
padding, ok = sizeParser.(crypto.PaddingLengthGenerator)
|
||||
if !ok {
|
||||
return nil, newError("invalid option: RequestOptionGlobalPadding")
|
||||
return nil, errors.New("invalid option: RequestOptionGlobalPadding")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -445,6 +446,6 @@ func (s *ServerSession) EncodeResponseBody(request *protocol.RequestHeader, writ
|
|||
return crypto.NewAuthenticationWriter(auth, sizeParser, writer, request.Command.TransferType(), padding), nil
|
||||
|
||||
default:
|
||||
return nil, newError("invalid option: Security")
|
||||
return nil, errors.New("invalid option: Security")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
package vmess
|
||||
|
||||
import "github.com/xtls/xray-core/common/errors"
|
||||
|
||||
type errPathObjHolder struct{}
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).WithPathObj(errPathObjHolder{})
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
package inbound
|
||||
|
||||
import "github.com/xtls/xray-core/common/errors"
|
||||
|
||||
type errPathObjHolder struct{}
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).WithPathObj(errPathObjHolder{})
|
||||
}
|
|
@ -120,11 +120,11 @@ func New(ctx context.Context, config *Config) (*Handler, error) {
|
|||
for _, user := range config.User {
|
||||
mUser, err := user.ToMemoryUser()
|
||||
if err != nil {
|
||||
return nil, newError("failed to get VMess user").Base(err)
|
||||
return nil, errors.New("failed to get VMess user").Base(err)
|
||||
}
|
||||
|
||||
if err := handler.AddUser(ctx, mUser); err != nil {
|
||||
return nil, newError("failed to initiate user").Base(err)
|
||||
return nil, errors.New("failed to initiate user").Base(err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -153,17 +153,17 @@ func (h *Handler) GetUser(email string) *protocol.MemoryUser {
|
|||
|
||||
func (h *Handler) AddUser(ctx context.Context, user *protocol.MemoryUser) error {
|
||||
if len(user.Email) > 0 && !h.usersByEmail.Add(user) {
|
||||
return newError("User ", user.Email, " already exists.")
|
||||
return errors.New("User ", user.Email, " already exists.")
|
||||
}
|
||||
return h.clients.Add(user)
|
||||
}
|
||||
|
||||
func (h *Handler) RemoveUser(ctx context.Context, email string) error {
|
||||
if email == "" {
|
||||
return newError("Email must not be empty.")
|
||||
return errors.New("Email must not be empty.")
|
||||
}
|
||||
if !h.usersByEmail.Remove(email) {
|
||||
return newError("User ", email, " not found.")
|
||||
return errors.New("User ", email, " not found.")
|
||||
}
|
||||
h.clients.Remove(email)
|
||||
return nil
|
||||
|
@ -174,7 +174,7 @@ func transferResponse(timer signal.ActivityUpdater, session *encoding.ServerSess
|
|||
|
||||
bodyWriter, err := session.EncodeResponseBody(request, output)
|
||||
if err != nil {
|
||||
return newError("failed to start decoding response").Base(err)
|
||||
return errors.New("failed to start decoding response").Base(err)
|
||||
}
|
||||
{
|
||||
// Optimize for small response packet
|
||||
|
@ -211,7 +211,7 @@ func transferResponse(timer signal.ActivityUpdater, session *encoding.ServerSess
|
|||
func (h *Handler) Process(ctx context.Context, network net.Network, connection stat.Connection, dispatcher routing.Dispatcher) error {
|
||||
sessionPolicy := h.policyManager.ForLevel(0)
|
||||
if err := connection.SetReadDeadline(time.Now().Add(sessionPolicy.Timeouts.Handshake)); err != nil {
|
||||
return newError("unable to set read deadline").Base(err).AtWarning()
|
||||
return errors.New("unable to set read deadline").Base(err).AtWarning()
|
||||
}
|
||||
|
||||
iConn := connection
|
||||
|
@ -234,7 +234,7 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection s
|
|||
Status: log.AccessRejected,
|
||||
Reason: err,
|
||||
})
|
||||
err = newError("invalid request from ", connection.RemoteAddr()).Base(err).AtInfo()
|
||||
err = errors.New("invalid request from ", connection.RemoteAddr()).Base(err).AtInfo()
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
@ -249,10 +249,10 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection s
|
|||
})
|
||||
}
|
||||
|
||||
newError("received request for ", request.Destination()).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfo(ctx, "received request for ", request.Destination())
|
||||
|
||||
if err := connection.SetReadDeadline(time.Time{}); err != nil {
|
||||
newError("unable to set back read deadline").Base(err).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfoInner(ctx, err, "unable to set back read deadline")
|
||||
}
|
||||
|
||||
inbound := session.InboundFromContext(ctx)
|
||||
|
@ -268,7 +268,7 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection s
|
|||
ctx = policy.ContextWithBufferPolicy(ctx, sessionPolicy.Buffer)
|
||||
link, err := dispatcher.Dispatch(ctx, request.Destination())
|
||||
if err != nil {
|
||||
return newError("failed to dispatch request to ", request.Destination()).Base(err)
|
||||
return errors.New("failed to dispatch request to ", request.Destination()).Base(err)
|
||||
}
|
||||
|
||||
requestDone := func() error {
|
||||
|
@ -276,10 +276,10 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection s
|
|||
|
||||
bodyReader, err := svrSession.DecodeRequestBody(request, reader)
|
||||
if err != nil {
|
||||
return newError("failed to start decoding").Base(err)
|
||||
return errors.New("failed to start decoding").Base(err)
|
||||
}
|
||||
if err := buf.Copy(bodyReader, link.Writer, buf.UpdateActivity(timer)); err != nil {
|
||||
return newError("failed to transfer request").Base(err)
|
||||
return errors.New("failed to transfer request").Base(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -300,7 +300,7 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection s
|
|||
if err := task.Run(ctx, requestDonePost, responseDone); err != nil {
|
||||
common.Interrupt(link.Reader)
|
||||
common.Interrupt(link.Writer)
|
||||
return newError("connection ends").Base(err)
|
||||
return errors.New("connection ends").Base(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -312,7 +312,7 @@ func (h *Handler) generateCommand(ctx context.Context, request *protocol.Request
|
|||
if h.inboundHandlerManager != nil {
|
||||
handler, err := h.inboundHandlerManager.GetHandler(ctx, tag)
|
||||
if err != nil {
|
||||
newError("failed to get detour handler: ", tag).Base(err).AtWarning().WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogWarningInner(ctx, err, "failed to get detour handler: ", tag)
|
||||
return nil
|
||||
}
|
||||
proxyHandler, port, availableMin := handler.GetRandomInboundProxy()
|
||||
|
@ -322,7 +322,7 @@ func (h *Handler) generateCommand(ctx context.Context, request *protocol.Request
|
|||
availableMin = 255
|
||||
}
|
||||
|
||||
newError("pick detour handler for port ", port, " for ", availableMin, " minutes.").AtDebug().WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogDebug(ctx, "pick detour handler for port ", port, " for ", availableMin, " minutes.")
|
||||
user := inboundHandler.GetUser(request.User.Email)
|
||||
if user == nil {
|
||||
return nil
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
package outbound
|
||||
|
||||
import "github.com/xtls/xray-core/common/errors"
|
||||
|
||||
type errPathObjHolder struct{}
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).WithPathObj(errPathObjHolder{})
|
||||
}
|
|
@ -11,6 +11,7 @@ import (
|
|||
|
||||
"github.com/xtls/xray-core/common"
|
||||
"github.com/xtls/xray-core/common/buf"
|
||||
"github.com/xtls/xray-core/common/errors"
|
||||
"github.com/xtls/xray-core/common/net"
|
||||
"github.com/xtls/xray-core/common/platform"
|
||||
"github.com/xtls/xray-core/common/protocol"
|
||||
|
@ -42,7 +43,7 @@ func New(ctx context.Context, config *Config) (*Handler, error) {
|
|||
for _, rec := range config.Receiver {
|
||||
s, err := protocol.NewServerSpecFromPB(rec)
|
||||
if err != nil {
|
||||
return nil, newError("failed to parse server spec").Base(err)
|
||||
return nil, errors.New("failed to parse server spec").Base(err)
|
||||
}
|
||||
serverList.AddServer(s)
|
||||
}
|
||||
|
@ -61,9 +62,9 @@ func New(ctx context.Context, config *Config) (*Handler, error) {
|
|||
// Process implements proxy.Outbound.Process().
|
||||
func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer internet.Dialer) error {
|
||||
outbounds := session.OutboundsFromContext(ctx)
|
||||
ob := outbounds[len(outbounds) - 1]
|
||||
ob := outbounds[len(outbounds)-1]
|
||||
if !ob.Target.IsValid() {
|
||||
return newError("target not specified").AtError()
|
||||
return errors.New("target not specified").AtError()
|
||||
}
|
||||
ob.Name = "vmess"
|
||||
ob.CanSpliceCopy = 3
|
||||
|
@ -81,12 +82,12 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
|||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return newError("failed to find an available destination").Base(err).AtWarning()
|
||||
return errors.New("failed to find an available destination").Base(err).AtWarning()
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
target := ob.Target
|
||||
newError("tunneling request to ", target, " via ", rec.Destination().NetAddr()).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfo(ctx, "tunneling request to ", target, " via ", rec.Destination().NetAddr())
|
||||
|
||||
command := protocol.RequestCommandTCP
|
||||
if target.Network == net.Network_UDP {
|
||||
|
@ -163,19 +164,19 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
|||
|
||||
writer := buf.NewBufferedWriter(buf.NewWriter(conn))
|
||||
if err := session.EncodeRequestHeader(request, writer); err != nil {
|
||||
return newError("failed to encode request").Base(err).AtWarning()
|
||||
return errors.New("failed to encode request").Base(err).AtWarning()
|
||||
}
|
||||
|
||||
bodyWriter, err := session.EncodeRequestBody(request, writer)
|
||||
if err != nil {
|
||||
return newError("failed to start encoding").Base(err)
|
||||
return errors.New("failed to start encoding").Base(err)
|
||||
}
|
||||
bodyWriter2 := bodyWriter
|
||||
if request.Command == protocol.RequestCommandMux && request.Port == 666 {
|
||||
bodyWriter = xudp.NewPacketWriter(bodyWriter, target, xudp.GetGlobalID(ctx))
|
||||
}
|
||||
if err := buf.CopyOnceTimeout(input, bodyWriter, time.Millisecond*100); err != nil && err != buf.ErrNotTimeoutReader && err != buf.ErrReadTimeout {
|
||||
return newError("failed to write first payload").Base(err)
|
||||
return errors.New("failed to write first payload").Base(err)
|
||||
}
|
||||
|
||||
if err := writer.SetBuffered(false); err != nil {
|
||||
|
@ -201,13 +202,13 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
|||
reader := &buf.BufferedReader{Reader: buf.NewReader(conn)}
|
||||
header, err := session.DecodeResponseHeader(reader)
|
||||
if err != nil {
|
||||
return newError("failed to read header").Base(err)
|
||||
return errors.New("failed to read header").Base(err)
|
||||
}
|
||||
h.handleCommand(rec.Destination(), header.Command)
|
||||
|
||||
bodyReader, err := session.DecodeResponseBody(request, reader)
|
||||
if err != nil {
|
||||
return newError("failed to start encoding response").Base(err)
|
||||
return errors.New("failed to start encoding response").Base(err)
|
||||
}
|
||||
if request.Command == protocol.RequestCommandMux && request.Port == 666 {
|
||||
bodyReader = xudp.NewPacketReader(&buf.BufferedReader{Reader: bodyReader})
|
||||
|
@ -222,7 +223,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
|||
|
||||
responseDonePost := task.OnSuccess(responseDone, task.Close(output))
|
||||
if err := task.Run(ctx, requestDone, responseDonePost); err != nil {
|
||||
return newError("connection ends").Base(err)
|
||||
return errors.New("connection ends").Base(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"sync"
|
||||
|
||||
"github.com/xtls/xray-core/common/dice"
|
||||
"github.com/xtls/xray-core/common/errors"
|
||||
"github.com/xtls/xray-core/common/protocol"
|
||||
"github.com/xtls/xray-core/proxy/vmess/aead"
|
||||
)
|
||||
|
@ -104,6 +105,6 @@ func (v *TimedUserValidator) GetBehaviorSeed() uint64 {
|
|||
return v.behaviorSeed
|
||||
}
|
||||
|
||||
var ErrNotFound = newError("Not Found")
|
||||
var ErrNotFound = errors.New("Not Found")
|
||||
|
||||
var ErrTainted = newError("ErrTainted")
|
||||
var ErrTainted = errors.New("ErrTainted")
|
||||
|
|
|
@ -202,7 +202,7 @@ func (bind *netBindServer) Send(buff [][]byte, endpoint conn.Endpoint) error {
|
|||
}
|
||||
|
||||
if nend.conn == nil {
|
||||
return newError("connection not open yet")
|
||||
return errors.New("connection not open yet")
|
||||
}
|
||||
|
||||
for _, buff := range buff {
|
||||
|
|
|
@ -29,6 +29,7 @@ import (
|
|||
|
||||
"github.com/xtls/xray-core/common"
|
||||
"github.com/xtls/xray-core/common/buf"
|
||||
"github.com/xtls/xray-core/common/errors"
|
||||
"github.com/xtls/xray-core/common/dice"
|
||||
"github.com/xtls/xray-core/common/log"
|
||||
"github.com/xtls/xray-core/common/net"
|
||||
|
@ -120,7 +121,7 @@ func (h *Handler) processWireGuard(ctx context.Context, dialer internet.Dialer)
|
|||
|
||||
h.net, err = h.makeVirtualTun(bind)
|
||||
if err != nil {
|
||||
return newError("failed to create virtual tun interface").Base(err)
|
||||
return errors.New("failed to create virtual tun interface").Base(err)
|
||||
}
|
||||
h.bind = bind
|
||||
return nil
|
||||
|
@ -129,9 +130,9 @@ func (h *Handler) processWireGuard(ctx context.Context, dialer internet.Dialer)
|
|||
// Process implements OutboundHandler.Dispatch().
|
||||
func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer internet.Dialer) error {
|
||||
outbounds := session.OutboundsFromContext(ctx)
|
||||
ob := outbounds[len(outbounds) - 1]
|
||||
ob := outbounds[len(outbounds)-1]
|
||||
if !ob.Target.IsValid() {
|
||||
return newError("target not specified")
|
||||
return errors.New("target not specified")
|
||||
}
|
||||
ob.Name = "wireguard"
|
||||
ob.CanSpliceCopy = 3
|
||||
|
@ -163,7 +164,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
|||
}
|
||||
}
|
||||
if err != nil {
|
||||
return newError("failed to lookup DNS").Base(err)
|
||||
return errors.New("failed to lookup DNS").Base(err)
|
||||
} else if len(ips) == 0 {
|
||||
return dns.ErrEmptyResponse
|
||||
}
|
||||
|
@ -193,7 +194,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
|||
if command == protocol.RequestCommandTCP {
|
||||
conn, err := h.net.DialContextTCPAddrPort(ctx, addrPort)
|
||||
if err != nil {
|
||||
return newError("failed to create TCP connection").Base(err)
|
||||
return errors.New("failed to create TCP connection").Base(err)
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
|
@ -208,7 +209,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
|||
} else if command == protocol.RequestCommandUDP {
|
||||
conn, err := h.net.DialUDPAddrPort(netip.AddrPort{}, addrPort)
|
||||
if err != nil {
|
||||
return newError("failed to create UDP connection").Base(err)
|
||||
return errors.New("failed to create UDP connection").Base(err)
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
|
@ -230,7 +231,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
|||
if err := task.Run(ctx, requestFunc, responseDonePost); err != nil {
|
||||
common.Interrupt(link.Reader)
|
||||
common.Interrupt(link.Writer)
|
||||
return newError("connection ends").Base(err)
|
||||
return errors.New("connection ends").Base(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -275,14 +276,14 @@ func (h *Handler) createIPCRequest(bind *netBindClient, conf *DeviceConfig) stri
|
|||
|
||||
address, port, err := net.SplitHostPort(peer.Endpoint)
|
||||
if err != nil {
|
||||
newError("failed to split endpoint ", peer.Endpoint, " into address and port").AtError().WriteToLog()
|
||||
errors.LogError(h.bind.ctx, "failed to split endpoint ", peer.Endpoint, " into address and port")
|
||||
}
|
||||
addr := net.ParseAddress(address)
|
||||
if addr.Family().IsDomain() {
|
||||
dialerIp := bind.dialer.DestIpAddress()
|
||||
if dialerIp != nil {
|
||||
addr = net.ParseAddress(dialerIp.String())
|
||||
newError("createIPCRequest use dialer dest ip: ", addr).WriteToLog()
|
||||
errors.LogInfo(h.bind.ctx, "createIPCRequest use dialer dest ip: ", addr)
|
||||
} else {
|
||||
ips, err := h.dns.LookupIP(addr.Domain(), dns.IPOption{
|
||||
IPv4Enable: h.hasIPv4 && h.conf.preferIP4(),
|
||||
|
@ -297,9 +298,9 @@ func (h *Handler) createIPCRequest(bind *netBindClient, conf *DeviceConfig) stri
|
|||
}
|
||||
}
|
||||
if err != nil {
|
||||
newError("createIPCRequest failed to lookup DNS").Base(err).WriteToLog()
|
||||
errors.LogInfoInner(h.bind.ctx, err, "createIPCRequest failed to lookup DNS")
|
||||
} else if len(ips) == 0 {
|
||||
newError("createIPCRequest empty lookup DNS").WriteToLog()
|
||||
errors.LogInfo(h.bind.ctx, "createIPCRequest empty lookup DNS")
|
||||
} else {
|
||||
addr = net.IPAddress(ips[dice.Roll(len(ips))])
|
||||
}
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
package wireguard
|
||||
|
||||
import "github.com/xtls/xray-core/common/errors"
|
||||
|
||||
type errPathObjHolder struct{}
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).WithPathObj(errPathObjHolder{})
|
||||
}
|
|
@ -2,11 +2,12 @@ package wireguard
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
goerrors "errors"
|
||||
"io"
|
||||
|
||||
"github.com/xtls/xray-core/common"
|
||||
"github.com/xtls/xray-core/common/buf"
|
||||
"github.com/xtls/xray-core/common/errors"
|
||||
"github.com/xtls/xray-core/common/log"
|
||||
"github.com/xtls/xray-core/common/net"
|
||||
"github.com/xtls/xray-core/common/session"
|
||||
|
@ -81,7 +82,7 @@ func (s *Server) Process(ctx context.Context, network net.Network, conn stat.Con
|
|||
inbound.Name = "wireguard"
|
||||
inbound.CanSpliceCopy = 3
|
||||
outbounds := session.OutboundsFromContext(ctx)
|
||||
ob := outbounds[len(outbounds) - 1]
|
||||
ob := outbounds[len(outbounds)-1]
|
||||
|
||||
s.info = routingInfo{
|
||||
ctx: core.ToBackgroundDetachedContext(ctx),
|
||||
|
@ -117,7 +118,7 @@ func (s *Server) Process(ctx context.Context, network net.Network, conn stat.Con
|
|||
v.endpoint = nep
|
||||
v.err = err
|
||||
v.waiter.Done()
|
||||
if err != nil && errors.Is(err, io.EOF) {
|
||||
if err != nil && goerrors.Is(err, io.EOF) {
|
||||
nep.conn = nil
|
||||
return nil
|
||||
}
|
||||
|
@ -127,7 +128,7 @@ func (s *Server) Process(ctx context.Context, network net.Network, conn stat.Con
|
|||
|
||||
func (s *Server) forwardConnection(dest net.Destination, conn net.Conn) {
|
||||
if s.info.dispatcher == nil {
|
||||
newError("unexpected: dispatcher == nil").AtError().WriteToLog()
|
||||
errors.LogError(s.info.ctx, "unexpected: dispatcher == nil")
|
||||
return
|
||||
}
|
||||
defer conn.Close()
|
||||
|
@ -155,14 +156,14 @@ func (s *Server) forwardConnection(dest net.Destination, conn net.Conn) {
|
|||
|
||||
link, err := s.info.dispatcher.Dispatch(ctx, dest)
|
||||
if err != nil {
|
||||
newError("dispatch connection").Base(err).AtError().WriteToLog()
|
||||
errors.LogErrorInner(s.info.ctx, err, "dispatch connection")
|
||||
}
|
||||
defer cancel()
|
||||
|
||||
requestDone := func() error {
|
||||
defer timer.SetTimeout(plcy.Timeouts.DownlinkOnly)
|
||||
if err := buf.Copy(buf.NewReader(conn), link.Writer, buf.UpdateActivity(timer)); err != nil {
|
||||
return newError("failed to transport all TCP request").Base(err)
|
||||
return errors.New("failed to transport all TCP request").Base(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -171,7 +172,7 @@ func (s *Server) forwardConnection(dest net.Destination, conn net.Conn) {
|
|||
responseDone := func() error {
|
||||
defer timer.SetTimeout(plcy.Timeouts.UplinkOnly)
|
||||
if err := buf.Copy(link.Reader, buf.NewWriter(conn), buf.UpdateActivity(timer)); err != nil {
|
||||
return newError("failed to transport all TCP response").Base(err)
|
||||
return errors.New("failed to transport all TCP response").Base(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -181,7 +182,7 @@ func (s *Server) forwardConnection(dest net.Destination, conn net.Conn) {
|
|||
if err := task.Run(ctx, requestDonePost, responseDone); err != nil {
|
||||
common.Interrupt(link.Reader)
|
||||
common.Interrupt(link.Writer)
|
||||
newError("connection ends").Base(err).AtDebug().WriteToLog()
|
||||
errors.LogDebugInner(s.info.ctx, err, "connection ends")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package wireguard
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/netip"
|
||||
|
@ -12,6 +11,7 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/xtls/xray-core/common/errors"
|
||||
"github.com/xtls/xray-core/common/log"
|
||||
xnet "github.com/xtls/xray-core/common/net"
|
||||
"github.com/xtls/xray-core/proxy/wireguard/gvisortun"
|
||||
|
@ -158,7 +158,7 @@ func createGVisorTun(localAddresses []netip.Addr, mtu int, handler promiscuousMo
|
|||
// Perform a TCP three-way handshake.
|
||||
ep, err := r.CreateEndpoint(&wq)
|
||||
if err != nil {
|
||||
newError(err.String()).AtError().WriteToLog()
|
||||
errors.LogError(context.Background(), err.String())
|
||||
r.Complete(true)
|
||||
return
|
||||
}
|
||||
|
@ -183,7 +183,7 @@ func createGVisorTun(localAddresses []netip.Addr, mtu int, handler promiscuousMo
|
|||
|
||||
ep, err := r.CreateEndpoint(&wq)
|
||||
if err != nil {
|
||||
newError(err.String()).AtError().WriteToLog()
|
||||
errors.LogError(context.Background(), err.String())
|
||||
return
|
||||
}
|
||||
defer ep.Close()
|
||||
|
|
|
@ -73,7 +73,7 @@ func (d *deviceNet) Close() (err error) {
|
|||
|
||||
func createKernelTun(localAddresses []netip.Addr, mtu int, handler promiscuousModeHandler) (t Tunnel, err error) {
|
||||
if handler != nil {
|
||||
return nil, newError("TODO: support promiscuous mode")
|
||||
return nil, errors.New("TODO: support promiscuous mode")
|
||||
}
|
||||
|
||||
var v4, v6 *netip.Addr
|
||||
|
|
|
@ -2,6 +2,7 @@ package wireguard
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/netip"
|
||||
"strings"
|
||||
|
@ -53,7 +54,7 @@ func parseEndpoints(conf *DeviceConfig) ([]netip.Addr, bool, bool, error) {
|
|||
}
|
||||
addr = prefix.Addr()
|
||||
if prefix.Bits() != addr.BitLen() {
|
||||
return nil, false, false, newError("interface address subnet should be /32 for IPv4 and /128 for IPv6")
|
||||
return nil, false, false, errors.New("interface address subnet should be /32 for IPv4 and /128 for IPv6")
|
||||
}
|
||||
} else {
|
||||
var err error
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue