p2p/discover: fix Write method in metered connection (#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.
pull/30361/head
Nicolas Gotchac 2 months ago committed by GitHub
parent 9b5d1412cc
commit 87377c58bc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 21
      p2p/discover/metrics.go

@ -18,6 +18,7 @@ package discover
import ( import (
"fmt" "fmt"
"net"
"net/netip" "net/netip"
"github.com/ethereum/go-ethereum/metrics" "github.com/ethereum/go-ethereum/metrics"
@ -47,7 +48,7 @@ func init() {
// meteredUdpConn is a wrapper around a net.UDPConn that meters both the // meteredUdpConn is a wrapper around a net.UDPConn that meters both the
// inbound and outbound network traffic. // inbound and outbound network traffic.
type meteredUdpConn struct { type meteredUdpConn struct {
UDPConn udpConn UDPConn
} }
func newMeteredConn(conn UDPConn) UDPConn { func newMeteredConn(conn UDPConn) UDPConn {
@ -55,19 +56,27 @@ func newMeteredConn(conn UDPConn) UDPConn {
if !metrics.Enabled { if !metrics.Enabled {
return conn return conn
} }
return &meteredUdpConn{UDPConn: conn} return &meteredUdpConn{udpConn: conn}
}
func (c *meteredUdpConn) Close() error {
return c.udpConn.Close()
}
func (c *meteredUdpConn) LocalAddr() net.Addr {
return c.udpConn.LocalAddr()
} }
// ReadFromUDPAddrPort delegates a network read to the underlying connection, bumping the udp ingress traffic meter along the way. // ReadFromUDPAddrPort delegates a network read to the underlying connection, bumping the udp ingress traffic meter along the way.
func (c *meteredUdpConn) ReadFromUDPAddrPort(b []byte) (n int, addr netip.AddrPort, err error) { func (c *meteredUdpConn) ReadFromUDPAddrPort(b []byte) (n int, addr netip.AddrPort, err error) {
n, addr, err = c.UDPConn.ReadFromUDPAddrPort(b) n, addr, err = c.udpConn.ReadFromUDPAddrPort(b)
ingressTrafficMeter.Mark(int64(n)) ingressTrafficMeter.Mark(int64(n))
return n, addr, err return n, addr, err
} }
// WriteToUDP delegates a network write to the underlying connection, bumping the udp egress traffic meter along the way. // WriteToUDPAddrPort delegates a network write to the underlying connection, bumping the udp egress traffic meter along the way.
func (c *meteredUdpConn) WriteToUDP(b []byte, addr netip.AddrPort) (n int, err error) { func (c *meteredUdpConn) WriteToUDPAddrPort(b []byte, addr netip.AddrPort) (n int, err error) {
n, err = c.UDPConn.WriteToUDPAddrPort(b, addr) n, err = c.udpConn.WriteToUDPAddrPort(b, addr)
egressTrafficMeter.Mark(int64(n)) egressTrafficMeter.Mark(int64(n))
return n, err return n, err
} }

Loading…
Cancel
Save