fix ws listener

This commit is contained in:
ginuerzh
2025-08-05 00:13:48 +08:00
parent b597467858
commit fd9dc6408a
4 changed files with 10 additions and 10 deletions
+1 -1
View File
@@ -38,7 +38,7 @@ func (*defaultRoute) Dial(ctx context.Context, network, address string, opts ...
netd := dialer.Dialer{ netd := dialer.Dialer{
Interface: options.Interface, Interface: options.Interface,
Netns: options.Netns, Netns: options.Netns,
Logger: options.Logger, Log: options.Logger,
} }
if options.SockOpts != nil { if options.SockOpts != nil {
netd.Mark = options.SockOpts.Mark netd.Mark = options.SockOpts.Mark
+2 -2
View File
@@ -28,7 +28,7 @@ type Dialer struct {
Netns string Netns string
Mark int Mark int
DialFunc func(ctx context.Context, network, addr string) (net.Conn, error) DialFunc func(ctx context.Context, network, addr string) (net.Conn, error)
Logger logger.Logger Log logger.Logger
} }
func (d *Dialer) Dial(ctx context.Context, network, addr string) (conn net.Conn, err error) { func (d *Dialer) Dial(ctx context.Context, network, addr string) (conn net.Conn, err error) {
@@ -36,7 +36,7 @@ func (d *Dialer) Dial(ctx context.Context, network, addr string) (conn net.Conn,
d = DefaultNetDialer d = DefaultNetDialer
} }
log := d.Logger log := d.Log
if log == nil { if log == nil {
log = logger.Default() log = logger.Default()
} }
+1 -1
View File
@@ -185,7 +185,7 @@ func (l *mwsListener) upgrade(w http.ResponseWriter, r *http.Request) {
return return
} }
ctx := r.Context() ctx := context.Background()
if cc, ok := conn.NetConn().(xctx.Context); ok { if cc, ok := conn.NetConn().(xctx.Context); ok {
if cv := cc.Context(); cv != nil { if cv := cc.Context(); cv != nil {
ctx = cv ctx = cv
+6 -6
View File
@@ -38,7 +38,7 @@ type wsListener struct {
tlsEnabled bool tlsEnabled bool
cqueue chan net.Conn cqueue chan net.Conn
errChan chan error errChan chan error
logger logger.Logger log logger.Logger
md metadata md metadata
options listener.Options options listener.Options
} }
@@ -49,7 +49,7 @@ func NewListener(opts ...listener.Option) listener.Listener {
opt(&options) opt(&options)
} }
return &wsListener{ return &wsListener{
logger: options.Logger, log: options.Logger,
options: options, options: options,
} }
} }
@@ -61,7 +61,7 @@ func NewTLSListener(opts ...listener.Option) listener.Listener {
} }
return &wsListener{ return &wsListener{
tlsEnabled: true, tlsEnabled: true,
logger: options.Logger, log: options.Logger,
options: options, options: options,
} }
} }
@@ -98,7 +98,7 @@ func (l *wsListener) Init(md md.Metadata) (err error) {
lc := net.ListenConfig{} lc := net.ListenConfig{}
if l.md.mptcp { if l.md.mptcp {
lc.SetMultipathTCP(true) lc.SetMultipathTCP(true)
l.logger.Debugf("mptcp enabled: %v", lc.MultipathTCP()) l.log.Debugf("mptcp enabled: %v", lc.MultipathTCP())
} }
ln, err := lc.Listen(context.Background(), network, l.options.Addr) ln, err := lc.Listen(context.Background(), network, l.options.Addr)
if err != nil { if err != nil {
@@ -164,7 +164,7 @@ func (l *wsListener) upgrade(w http.ResponseWriter, r *http.Request) {
if clientIP != nil { if clientIP != nil {
cip = clientIP.String() cip = clientIP.String()
} }
log := l.logger.WithFields(map[string]any{ log := l.log.WithFields(map[string]any{
"local": l.addr.String(), "local": l.addr.String(),
"remote": r.RemoteAddr, "remote": r.RemoteAddr,
"client": cip, "client": cip,
@@ -180,7 +180,7 @@ func (l *wsListener) upgrade(w http.ResponseWriter, r *http.Request) {
return return
} }
ctx := r.Context() ctx := context.Background()
if cc, ok := conn.NetConn().(xctx.Context); ok { if cc, ok := conn.NetConn().(xctx.Context); ok {
if cv := cc.Context(); cv != nil { if cv := cc.Context(); cv != nil {
ctx = cv ctx = cv