fix(handler/socks5): accumulate UDP traffic metrics into recorder (issue #45)
The SOCKS5 handler recorder only tracked TCP traffic metrics. UDP
associations (CmdUdp) overwrote TCP byte counts with UDP counts, and
UDP tunnels (CmdUDPTun) recorded zero bytes.
Changes:
- udp.go: change UDP stats assignment (=) to accumulation (+=) so the
TCP control connection bytes tracked by Handle() are preserved.
- udp_tun.go: add xstats.Stats{} wrapper around the PacketConn with
deferred accumulation into HandlerRecorderObject, mirroring the
handleUDP pattern.
This commit is contained in:
@@ -97,8 +97,8 @@ func (h *socks5Handler) handleUDP(ctx context.Context, conn net.Conn, network st
|
|||||||
cc = stats_wrapper.WrapPacketConn(cc, &pStats)
|
cc = stats_wrapper.WrapPacketConn(cc, &pStats)
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
ro.InputBytes = pStats.Get(stats.KindInputBytes)
|
ro.InputBytes += pStats.Get(stats.KindInputBytes)
|
||||||
ro.OutputBytes = pStats.Get(stats.KindOutputBytes)
|
ro.OutputBytes += pStats.Get(stats.KindOutputBytes)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
clientID := ctxvalue.ClientIDFromContext(ctx)
|
clientID := ctxvalue.ClientIDFromContext(ctx)
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import (
|
|||||||
"github.com/go-gost/x/internal/net/udp"
|
"github.com/go-gost/x/internal/net/udp"
|
||||||
"github.com/go-gost/x/internal/util/socks"
|
"github.com/go-gost/x/internal/util/socks"
|
||||||
traffic_wrapper "github.com/go-gost/x/limiter/traffic/wrapper"
|
traffic_wrapper "github.com/go-gost/x/limiter/traffic/wrapper"
|
||||||
|
xstats "github.com/go-gost/x/observer/stats"
|
||||||
stats_wrapper "github.com/go-gost/x/observer/stats/wrapper"
|
stats_wrapper "github.com/go-gost/x/observer/stats/wrapper"
|
||||||
xrecorder "github.com/go-gost/x/recorder"
|
xrecorder "github.com/go-gost/x/recorder"
|
||||||
)
|
)
|
||||||
@@ -108,6 +109,16 @@ func (h *socks5Handler) handleUDPTun(ctx context.Context, conn net.Conn, network
|
|||||||
}
|
}
|
||||||
defer pc.Close()
|
defer pc.Close()
|
||||||
|
|
||||||
|
{
|
||||||
|
pStats := xstats.Stats{}
|
||||||
|
pc = stats_wrapper.WrapPacketConn(pc, &pStats)
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
ro.InputBytes += pStats.Get(stats.KindInputBytes)
|
||||||
|
ro.OutputBytes += pStats.Get(stats.KindOutputBytes)
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
log = log.WithFields(map[string]any{
|
log = log.WithFields(map[string]any{
|
||||||
"src": pc.LocalAddr().String(),
|
"src": pc.LocalAddr().String(),
|
||||||
"bind": pc.LocalAddr().String(),
|
"bind": pc.LocalAddr().String(),
|
||||||
|
|||||||
Reference in New Issue
Block a user