Skip to content

Commit 750519d

Browse files
ngotchacmask-pp
authored andcommitted
p2p/discover: fix Write method in metered connection (ethereum#30355)
`WriteToUDP` was never called, since `meteredUdpConn` exposed directly all the methods from the underlying `UDPConn` interface. This fixes the `discover/egress` metric never being updated.
1 parent 4b4aa39 commit 750519d

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

p2p/discover/metrics.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package discover
1818

1919
import (
2020
"fmt"
21+
"net"
2122
"net/netip"
2223

2324
"github.com/ethereum/go-ethereum/metrics"
@@ -47,27 +48,35 @@ func init() {
4748
// meteredUdpConn is a wrapper around a net.UDPConn that meters both the
4849
// inbound and outbound network traffic.
4950
type meteredUdpConn struct {
50-
UDPConn
51+
udpConn UDPConn
5152
}
5253

5354
func newMeteredConn(conn UDPConn) UDPConn {
5455
// Short circuit if metrics are disabled
5556
if !metrics.Enabled {
5657
return conn
5758
}
58-
return &meteredUdpConn{UDPConn: conn}
59+
return &meteredUdpConn{udpConn: conn}
60+
}
61+
62+
func (c *meteredUdpConn) Close() error {
63+
return c.udpConn.Close()
64+
}
65+
66+
func (c *meteredUdpConn) LocalAddr() net.Addr {
67+
return c.udpConn.LocalAddr()
5968
}
6069

6170
// ReadFromUDPAddrPort delegates a network read to the underlying connection, bumping the udp ingress traffic meter along the way.
6271
func (c *meteredUdpConn) ReadFromUDPAddrPort(b []byte) (n int, addr netip.AddrPort, err error) {
63-
n, addr, err = c.UDPConn.ReadFromUDPAddrPort(b)
72+
n, addr, err = c.udpConn.ReadFromUDPAddrPort(b)
6473
ingressTrafficMeter.Mark(int64(n))
6574
return n, addr, err
6675
}
6776

68-
// WriteToUDP delegates a network write to the underlying connection, bumping the udp egress traffic meter along the way.
69-
func (c *meteredUdpConn) WriteToUDP(b []byte, addr netip.AddrPort) (n int, err error) {
70-
n, err = c.UDPConn.WriteToUDPAddrPort(b, addr)
77+
// WriteToUDPAddrPort delegates a network write to the underlying connection, bumping the udp egress traffic meter along the way.
78+
func (c *meteredUdpConn) WriteToUDPAddrPort(b []byte, addr netip.AddrPort) (n int, err error) {
79+
n, err = c.udpConn.WriteToUDPAddrPort(b, addr)
7180
egressTrafficMeter.Mark(int64(n))
7281
return n, err
7382
}

0 commit comments

Comments
 (0)