mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-30 01:08:33 +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
|
@ -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)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue