add context for conn

This commit is contained in:
ginuerzh
2025-08-04 19:29:38 +08:00
parent ad5cf6fd61
commit b597467858
90 changed files with 889 additions and 917 deletions
+6 -5
View File
@@ -11,7 +11,8 @@ import (
"github.com/go-gost/core/logger"
"github.com/go-gost/core/observer/stats"
"github.com/go-gost/gosocks5"
ctxvalue "github.com/go-gost/x/ctx"
xctx "github.com/go-gost/x/ctx"
ictx "github.com/go-gost/x/internal/ctx"
xnet "github.com/go-gost/x/internal/net"
"github.com/go-gost/x/internal/net/udp"
"github.com/go-gost/x/internal/util/socks"
@@ -27,7 +28,7 @@ func (h *socks5Handler) handleUDPTun(ctx context.Context, conn net.Conn, network
})
{
clientID := ctxvalue.ClientIDFromContext(ctx)
clientID := xctx.ClientIDFromContext(ctx)
rw := traffic_wrapper.WrapReadWriter(
h.limiter,
conn,
@@ -67,7 +68,7 @@ func (h *socks5Handler) handleUDPTun(ctx context.Context, conn net.Conn, network
// obtain a udp connection
var buf bytes.Buffer
c, err := h.options.Router.Dial(ctxvalue.ContextWithBuffer(ctx, &buf), network, "") // UDP association
c, err := h.options.Router.Dial(ictx.ContextWithBuffer(ctx, &buf), network, "") // UDP association
ro.Route = buf.String()
if err != nil {
log.Error(err)
@@ -111,7 +112,7 @@ func (h *socks5Handler) handleUDPTun(ctx context.Context, conn net.Conn, network
"src": pc.LocalAddr().String(),
"bind": pc.LocalAddr().String(),
})
ro.Src = pc.LocalAddr().String()
ro.SrcAddr = pc.LocalAddr().String()
saddr := gosocks5.Addr{}
saddr.ParseFrom(pc.LocalAddr().String())
@@ -123,7 +124,7 @@ func (h *socks5Handler) handleUDPTun(ctx context.Context, conn net.Conn, network
}
log.Debugf("bind on %s OK", pc.LocalAddr())
clientID := ctxvalue.ClientIDFromContext(ctx)
clientID := xctx.ClientIDFromContext(ctx)
if h.options.Observer != nil {
pstats := h.stats.Stats(string(clientID))
pstats.Add(stats.KindTotalConns, 1)