From 201d434d50b7936f01b9db4ebf0f3e0d326b944e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?rich=CE=9Brd?= Date: Mon, 1 Jul 2024 09:03:34 -0400 Subject: [PATCH] fix: ignore ws from circuit relay addresses, and allow non multiaddresses in `multiaddrs` ENR key (#1141) --- waku/v2/node/localnode.go | 9 ++++++++- waku/v2/protocol/enr/enr.go | 3 ++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/waku/v2/node/localnode.go b/waku/v2/node/localnode.go index 6259fa18..aa10ce0d 100644 --- a/waku/v2/node/localnode.go +++ b/waku/v2/node/localnode.go @@ -234,18 +234,25 @@ func selectWSListenAddresses(addresses []ma.Multiaddr) ([]ma.Multiaddr, error) { func selectCircuitRelayListenAddresses(ctx context.Context, addresses []ma.Multiaddr) ([]ma.Multiaddr, error) { var result []ma.Multiaddr + for _, addr := range addresses { addr, err := decapsulateCircuitRelayAddr(ctx, addr) if err != nil { continue } + + _, noWS := addr.ValueForProtocol(ma.P_WSS) + _, noWSS := addr.ValueForProtocol(ma.P_WS) + if noWS == nil || noWSS == nil { // WS or WSS found + continue + } + result = append(result, addr) } return result, nil } - func filter0Port(addresses []ma.Multiaddr) ([]ma.Multiaddr, error) { var result []ma.Multiaddr for _, addr := range addresses { diff --git a/waku/v2/protocol/enr/enr.go b/waku/v2/protocol/enr/enr.go index 1ff1265c..fe1e5462 100644 --- a/waku/v2/protocol/enr/enr.go +++ b/waku/v2/protocol/enr/enr.go @@ -120,7 +120,8 @@ func Multiaddress(node *enode.Node) (peer.ID, []multiaddr.Multiaddr, error) { maRaw := multiaddrRaw[offset+2 : offset+2+int(maSize)] addr, err := multiaddr.NewMultiaddrBytes(maRaw) if err != nil { - return "", nil, fmt.Errorf("invalid multiaddress field length") + // The value is not a multiaddress. Ignoring... + continue } hostInfoStr := fmt.Sprintf("/p2p/%s", peerID.String())