mirror of https://github.com/status-im/go-waku.git
fix: handle discv5 udp port 0 (#1069)
This commit is contained in:
parent
6f1280e704
commit
327391a9b4
|
@ -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)
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue