fix traffic logging for socks5 udp
This commit is contained in:
@@ -6,10 +6,15 @@ import (
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/go-gost/core/limiter"
|
||||
"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"
|
||||
xnet "github.com/go-gost/x/internal/net"
|
||||
"github.com/go-gost/x/internal/util/mux"
|
||||
traffic_wrapper "github.com/go-gost/x/limiter/traffic/wrapper"
|
||||
stats_wrapper "github.com/go-gost/x/observer/stats/wrapper"
|
||||
)
|
||||
|
||||
func (h *socks5Handler) handleMuxBind(ctx context.Context, conn net.Conn, network, address string, log logger.Logger) error {
|
||||
@@ -27,6 +32,30 @@ func (h *socks5Handler) handleMuxBind(ctx context.Context, conn net.Conn, networ
|
||||
return reply.Write(conn)
|
||||
}
|
||||
|
||||
{
|
||||
clientID := ctxvalue.ClientIDFromContext(ctx)
|
||||
rw := traffic_wrapper.WrapReadWriter(
|
||||
h.limiter,
|
||||
conn,
|
||||
string(clientID),
|
||||
limiter.ServiceOption(h.options.Service),
|
||||
limiter.ScopeOption(limiter.ScopeClient),
|
||||
limiter.NetworkOption(network),
|
||||
limiter.AddrOption(address),
|
||||
limiter.ClientOption(string(clientID)),
|
||||
limiter.SrcOption(conn.RemoteAddr().String()),
|
||||
)
|
||||
if h.options.Observer != nil {
|
||||
pstats := h.stats.Stats(string(clientID))
|
||||
pstats.Add(stats.KindTotalConns, 1)
|
||||
pstats.Add(stats.KindCurrentConns, 1)
|
||||
defer pstats.Add(stats.KindCurrentConns, -1)
|
||||
rw = stats_wrapper.WrapReadWriter(rw, pstats)
|
||||
}
|
||||
|
||||
conn = xnet.NewReadWriteConn(rw, rw, conn)
|
||||
}
|
||||
|
||||
return h.muxBindLocal(ctx, conn, network, address, log)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user