Skip to content

Commit a6df210

Browse files
committed
Amend XUDP related logs
- Useful for debug XUDP improvements - Move XUDP log in core log - Freedom connection log show local port
1 parent 76b27a3 commit a6df210

File tree

3 files changed

+7
-18
lines changed

3 files changed

+7
-18
lines changed

common/mux/server.go

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package mux
22

33
import (
44
"context"
5-
"fmt"
65
"io"
76

87
"github.com/xtls/xray-core/common"
@@ -12,7 +11,6 @@ import (
1211
"github.com/xtls/xray-core/common/net"
1312
"github.com/xtls/xray-core/common/protocol"
1413
"github.com/xtls/xray-core/common/session"
15-
"github.com/xtls/xray-core/common/xudp"
1614
"github.com/xtls/xray-core/core"
1715
"github.com/xtls/xray-core/features/routing"
1816
"github.com/xtls/xray-core/transport"
@@ -148,9 +146,7 @@ func (w *ServerWorker) handleStatusNew(ctx context.Context, meta *FrameMetadata,
148146
} else {
149147
if x.Status == Initializing { // nearly impossible
150148
XUDPManager.Unlock()
151-
if xudp.Show {
152-
fmt.Printf("XUDP hit: %v err: conflict\n", meta.GlobalID)
153-
}
149+
newError("XUDP hit ", meta.GlobalID).Base(newError("conflict")).AtWarning().WriteToLog(session.ExportIDToError(ctx))
154150
// It's not a good idea to return an err here, so just let client wait.
155151
// Client will receive an End frame after sending a Keep frame.
156152
return nil
@@ -168,9 +164,7 @@ func (w *ServerWorker) handleStatusNew(ctx context.Context, meta *FrameMetadata,
168164
b.Release()
169165
mb = nil
170166
}
171-
if xudp.Show {
172-
fmt.Printf("XUDP hit: %v err: %v\n", meta.GlobalID, err)
173-
}
167+
newError("XUDP hit ", meta.GlobalID).Base(err).WriteToLog(session.ExportIDToError(ctx))
174168
}
175169
if mb != nil {
176170
ctx = session.ContextWithTimeoutOnly(ctx, true)
@@ -180,20 +174,15 @@ func (w *ServerWorker) handleStatusNew(ctx context.Context, meta *FrameMetadata,
180174
XUDPManager.Lock()
181175
delete(XUDPManager.Map, x.GlobalID)
182176
XUDPManager.Unlock()
183-
err = newError("failed to dispatch request to ", meta.Target).Base(err)
184-
if xudp.Show {
185-
fmt.Printf("XUDP new: %v err: %v\n", meta.GlobalID, err)
186-
}
177+
err = newError("XUDP new ", meta.GlobalID).Base(newError("failed to dispatch request to ", meta.Target).Base(err))
187178
return err // it will break the whole Mux connection
188179
}
189180
link.Writer.WriteMultiBuffer(mb) // it's meaningless to test a new pipe
190181
x.Mux = &Session{
191182
input: link.Reader,
192183
output: link.Writer,
193184
}
194-
if xudp.Show {
195-
fmt.Printf("XUDP new: %v err: %v\n", meta.GlobalID, err)
196-
}
185+
newError("XUDP new ", meta.GlobalID).Base(err).WriteToLog(session.ExportIDToError(ctx))
197186
}
198187
x.Mux = &Session{
199188
input: x.Mux.input,

common/mux/session.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func (s *Session) Close(locked bool) error {
183183
s.XUDP.Expire = time.Now().Add(time.Minute)
184184
s.XUDP.Status = Expiring
185185
if xudp.Show {
186-
fmt.Printf("XUDP put: %v\n", s.XUDP.GlobalID)
186+
fmt.Printf("XUDP put %v\n", s.XUDP.GlobalID)
187187
}
188188
}
189189
XUDPManager.Unlock()
@@ -235,7 +235,7 @@ func init() {
235235
x.Interrupt()
236236
delete(XUDPManager.Map, id)
237237
if xudp.Show {
238-
fmt.Printf("XUDP del: %v\n", id)
238+
fmt.Printf("XUDP del %v\n", id)
239239
}
240240
}
241241
}

proxy/freedom/freedom.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
117117
UDPOverride.Port = destination.Port
118118
}
119119
}
120-
newError("opening connection to ", destination).WriteToLog(session.ExportIDToError(ctx))
121120

122121
input := link.Reader
123122
output := link.Writer
@@ -148,6 +147,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
148147
return newError("failed to open connection to ", destination).Base(err)
149148
}
150149
defer conn.Close()
150+
newError("connection opened to ", destination, ", local endpoint ", conn.LocalAddr(), ", remote endpoint ", conn.RemoteAddr()).WriteToLog(session.ExportIDToError(ctx))
151151

152152
var newCtx context.Context
153153
var newCancel context.CancelFunc

0 commit comments

Comments
 (0)