fix: handle discv5 udp port 0 (#1069)

This commit is contained in:
richΛrd 2024-03-25 14:11:41 -04:00 committed by GitHub
parent 6f1280e704
commit 327391a9b4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 1 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(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")
}

View File

@ -4,6 +4,7 @@ import (
"context"
"crypto/rand"
"errors"
"strings"
"testing"
"time"
@ -50,6 +51,10 @@ func isProtocolNotSupported(err error) bool {
return errors.Is(err, notSupportedErr)
}
func isStreamReset(err error) bool {
return strings.Contains(err.Error(), "stream reset")
}
func TestWakuMetadataRequest(t *testing.T) {
testShard16 := uint16(16)
@ -84,7 +89,7 @@ func TestWakuMetadataRequest(t *testing.T) {
// Query a peer not subscribed to any shard
_, err = m16_1.Request(context.Background(), m_noRS.h.ID())
require.True(t, isProtocolNotSupported(err))
require.True(t, isProtocolNotSupported(err) || isStreamReset(err))
}
func TestNoNetwork(t *testing.T) {