From 05d24d6827f313d5a2a2a633e3b83a8cac7d26a5 Mon Sep 17 00:00:00 2001 From: yuhan6665 <1588741+yuhan6665@users.noreply.github.com> Date: Sat, 8 Apr 2023 20:56:54 -0400 Subject: [PATCH] Amend XUDP related logs - Useful for debug XUDP improvements - Move XUDP log in core log - Freedom connection log show local port --- common/mux/server.go | 19 ++++--------------- common/mux/session.go | 10 ++-------- proxy/freedom/freedom.go | 2 +- 3 files changed, 7 insertions(+), 24 deletions(-) diff --git a/common/mux/server.go b/common/mux/server.go index b3c22a61..55e3a674 100644 --- a/common/mux/server.go +++ b/common/mux/server.go @@ -2,7 +2,6 @@ package mux import ( "context" - "fmt" "io" "github.com/xtls/xray-core/common" @@ -12,7 +11,6 @@ import ( "github.com/xtls/xray-core/common/net" "github.com/xtls/xray-core/common/protocol" "github.com/xtls/xray-core/common/session" - "github.com/xtls/xray-core/common/xudp" "github.com/xtls/xray-core/core" "github.com/xtls/xray-core/features/routing" "github.com/xtls/xray-core/transport" @@ -148,9 +146,7 @@ func (w *ServerWorker) handleStatusNew(ctx context.Context, meta *FrameMetadata, } else { if x.Status == Initializing { // nearly impossible XUDPManager.Unlock() - if xudp.Show { - fmt.Printf("XUDP hit: %v err: conflict\n", meta.GlobalID) - } + newError("XUDP hit ", meta.GlobalID).Base(errors.New("conflict")).AtWarning().WriteToLog(session.ExportIDToError(ctx)) // It's not a good idea to return an err here, so just let client wait. // Client will receive an End frame after sending a Keep frame. return nil @@ -168,9 +164,7 @@ func (w *ServerWorker) handleStatusNew(ctx context.Context, meta *FrameMetadata, b.Release() mb = nil } - if xudp.Show { - fmt.Printf("XUDP hit: %v err: %v\n", meta.GlobalID, err) - } + newError("XUDP hit ", meta.GlobalID).Base(err).WriteToLog(session.ExportIDToError(ctx)) } if mb != nil { ctx = session.ContextWithTimeoutOnly(ctx, true) @@ -180,10 +174,7 @@ func (w *ServerWorker) handleStatusNew(ctx context.Context, meta *FrameMetadata, XUDPManager.Lock() delete(XUDPManager.Map, x.GlobalID) XUDPManager.Unlock() - err = newError("failed to dispatch request to ", meta.Target).Base(err) - if xudp.Show { - fmt.Printf("XUDP new: %v err: %v\n", meta.GlobalID, err) - } + err = newError("XUDP new ", meta.GlobalID).Base(errors.New("failed to dispatch request to ", meta.Target).Base(err)) return err // it will break the whole Mux connection } link.Writer.WriteMultiBuffer(mb) // it's meaningless to test a new pipe @@ -191,9 +182,7 @@ func (w *ServerWorker) handleStatusNew(ctx context.Context, meta *FrameMetadata, input: link.Reader, output: link.Writer, } - if xudp.Show { - fmt.Printf("XUDP new: %v err: %v\n", meta.GlobalID, err) - } + newError("XUDP new ", meta.GlobalID).Base(err).WriteToLog(session.ExportIDToError(ctx)) } x.Mux = &Session{ input: x.Mux.input, diff --git a/common/mux/session.go b/common/mux/session.go index 650e3545..69597440 100644 --- a/common/mux/session.go +++ b/common/mux/session.go @@ -1,7 +1,6 @@ package mux import ( - "fmt" "io" "runtime" "sync" @@ -11,7 +10,6 @@ import ( "github.com/xtls/xray-core/common/buf" "github.com/xtls/xray-core/common/net" "github.com/xtls/xray-core/common/protocol" - "github.com/xtls/xray-core/common/xudp" "github.com/xtls/xray-core/transport/pipe" ) @@ -182,9 +180,7 @@ func (s *Session) Close(locked bool) error { if s.XUDP.Status == Active { s.XUDP.Expire = time.Now().Add(time.Minute) s.XUDP.Status = Expiring - if xudp.Show { - fmt.Printf("XUDP put: %v\n", s.XUDP.GlobalID) - } + newError("XUDP put ", s.XUDP.GlobalID).AtDebug().WriteToLog() } XUDPManager.Unlock() } @@ -234,9 +230,7 @@ func init() { if x.Status == Expiring && now.After(x.Expire) { x.Interrupt() delete(XUDPManager.Map, id) - if xudp.Show { - fmt.Printf("XUDP del: %v\n", id) - } + newError("XUDP del ", id).AtDebug().WriteToLog() } } XUDPManager.Unlock() diff --git a/proxy/freedom/freedom.go b/proxy/freedom/freedom.go index 8630ab9c..93804a81 100644 --- a/proxy/freedom/freedom.go +++ b/proxy/freedom/freedom.go @@ -117,7 +117,6 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte UDPOverride.Port = destination.Port } } - newError("opening connection to ", destination).WriteToLog(session.ExportIDToError(ctx)) input := link.Reader output := link.Writer @@ -148,6 +147,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte return newError("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)) var newCtx context.Context var newCancel context.CancelFunc