Improve power report attribution and sampling

This commit is contained in:
世界
2026-10-02 18:00:09 +08:00
parent fd9a076d25
commit eb7deeae8a
16 changed files with 588 additions and 43 deletions
+12
View File
@@ -431,9 +431,15 @@ func (d *DefaultDialer) trackConn(ctx context.Context, destination M.Socksaddr,
if recorder != nil {
recorder.CountConnectionOpened()
attribution := d.dialAttribution(ctx, destination)
outboundCounter := recorder.TrafficCounter(powerreport.TrafficOutbound, attribution.Outbound)
dnsCounter := recorder.TrafficCounter(powerreport.TrafficDNSTransport, attribution.DNS)
conn = bufio.NewCounterConn(conn, []N.CountFunc{func(n int64) {
outboundCounter.CountIn(n)
dnsCounter.CountIn(n)
recorder.Touch(powerreport.DirectionInbound, int(n), attribution)
}}, []N.CountFunc{func(n int64) {
outboundCounter.CountOut(n)
dnsCounter.CountOut(n)
recorder.Touch(powerreport.DirectionOutbound, int(n), attribution)
}})
}
@@ -453,9 +459,15 @@ func (d *DefaultDialer) trackPacketConn(ctx context.Context, destination M.Socks
if recorder != nil {
recorder.CountConnectionOpened()
attribution := d.dialAttribution(ctx, destination)
outboundCounter := recorder.TrafficCounter(powerreport.TrafficOutbound, attribution.Outbound)
dnsCounter := recorder.TrafficCounter(powerreport.TrafficDNSTransport, attribution.DNS)
conn = bufio.NewNetPacketConn(bufio.NewCounterPacketConn(bufio.NewPacketConn(conn), []N.CountFunc{func(n int64) {
outboundCounter.CountIn(n)
dnsCounter.CountIn(n)
recorder.Touch(powerreport.DirectionInbound, int(n), attribution)
}}, []N.CountFunc{func(n int64) {
outboundCounter.CountOut(n)
dnsCounter.CountOut(n)
recorder.Touch(powerreport.DirectionOutbound, int(n), attribution)
}}))
}
+2 -2
View File
@@ -51,9 +51,9 @@ type clientDialer struct {
}
func (d *clientDialer) DialContext(ctx context.Context, network string, destination M.Socksaddr) (net.Conn, error) {
return d.Dialer.DialContext(adapter.OverrideContext(ctx), network, destination)
return d.Dialer.DialContext(adapter.ContextForMultiplexSession(ctx), network, destination)
}
func (d *clientDialer) ListenPacket(ctx context.Context, destination M.Socksaddr) (net.PacketConn, error) {
return d.Dialer.ListenPacket(adapter.OverrideContext(ctx), destination)
return d.Dialer.ListenPacket(adapter.ContextForMultiplexSession(ctx), destination)
}