Skip to content

Commit

Permalink
Amend XUDP related logs
Browse files Browse the repository at this point in the history
- Useful for debug XUDP improvements
- Move XUDP log in core log
- Freedom connection log show local port
  • Loading branch information
yuhan6665 committed Apr 9, 2023
1 parent 76b27a3 commit a6df210
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 18 deletions.
19 changes: 4 additions & 15 deletions common/mux/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package mux

import (
"context"
"fmt"
"io"

"github.com/xtls/xray-core/common"
Expand All @@ -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"
Expand Down Expand Up @@ -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(newError("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
Expand All @@ -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)
Expand All @@ -180,20 +174,15 @@ 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(newError("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
x.Mux = &Session{
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,
Expand Down
4 changes: 2 additions & 2 deletions common/mux/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func (s *Session) Close(locked bool) error {
s.XUDP.Expire = time.Now().Add(time.Minute)
s.XUDP.Status = Expiring
if xudp.Show {
fmt.Printf("XUDP put: %v\n", s.XUDP.GlobalID)
fmt.Printf("XUDP put %v\n", s.XUDP.GlobalID)
}
}
XUDPManager.Unlock()
Expand Down Expand Up @@ -235,7 +235,7 @@ func init() {
x.Interrupt()
delete(XUDPManager.Map, id)
if xudp.Show {
fmt.Printf("XUDP del: %v\n", id)
fmt.Printf("XUDP del %v\n", id)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion proxy/freedom/freedom.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a6df210

Please sign in to comment.