diff --git a/waku/v2/discv5/discover.go b/waku/v2/discv5/discover.go index 4a2096fd..9df590bf 100644 --- a/waku/v2/discv5/discover.go +++ b/waku/v2/discv5/discover.go @@ -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) diff --git a/waku/v2/protocol/enr/localnode.go b/waku/v2/protocol/enr/localnode.go index 08f98c3d..a297d54c 100644 --- a/waku/v2/protocol/enr/localnode.go +++ b/waku/v2/protocol/enr/localnode.go @@ -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") } diff --git a/waku/v2/protocol/metadata/waku_metadata_test.go b/waku/v2/protocol/metadata/waku_metadata_test.go index b384d6d5..1b5f1b70 100644 --- a/waku/v2/protocol/metadata/waku_metadata_test.go +++ b/waku/v2/protocol/metadata/waku_metadata_test.go @@ -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) {