fix: handle discv5 udp port 0

This will update the UDP port used in the params with whatever value is obtained from ListenUDP
This commit is contained in:
Richard Ramos 2024-03-22 14:13:20 -04:00
parent 3aa391058a
commit dd81e1d469
No known key found for this signature in database
GPG Key ID: 1CE87DB518195760
2 changed files with 5 additions and 0 deletions

View File

@ -178,6 +178,7 @@ func (d *DiscoveryV5) listen(ctx context.Context) error {
}
d.params.udpPort = uint(d.udpAddr.Port)
d.localnode.SetFallbackUDP(d.udpAddr.Port)
listener, err := discover.ListenV5(ctx, conn, d.localnode, d.config)

View File

@ -79,6 +79,10 @@ func WithIP(ipAddr *net.TCPAddr) ENROption {
func WithUDPPort(udpPort uint) ENROption {
return func(localnode *enode.LocalNode) (err error) {
if udpPort == 0 {
return nil
}
if udpPort > math.MaxUint16 {
return errors.New("invalid udp port number")
}