From dbd94ebb81ba25641d2423f6fc0e8afe9c474196 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Fri, 30 Jun 2023 11:26:04 -0400 Subject: [PATCH] fix: add p2p-circuit component to multiaddresses that use circuit-relay --- waku/v2/protocol/enr/enr.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/waku/v2/protocol/enr/enr.go b/waku/v2/protocol/enr/enr.go index df22d2c0..03e70eed 100644 --- a/waku/v2/protocol/enr/enr.go +++ b/waku/v2/protocol/enr/enr.go @@ -102,11 +102,6 @@ func Multiaddress(node *enode.Node) (peer.ID, []multiaddr.Multiaddr, error) { return peerID, result, nil } - hostInfo, err := multiaddr.NewMultiaddr(fmt.Sprintf("/p2p/%s", peerID.Pretty())) - if err != nil { - return "", nil, err - } - offset := 0 for { maSize := binary.BigEndian.Uint16(multiaddrRaw[offset : offset+2]) @@ -119,6 +114,17 @@ func Multiaddress(node *enode.Node) (peer.ID, []multiaddr.Multiaddr, error) { return "", nil, fmt.Errorf("invalid multiaddress field length") } + hostInfoStr := fmt.Sprintf("/p2p/%s", peerID.Pretty()) + _, pID := peer.SplitAddr(addr) + if pID != "" && pID != peerID { + // Addresses in the ENR that contain a p2p component are circuit relay addr + hostInfoStr = "/p2p-circuit" + hostInfoStr + } + + hostInfo, err := multiaddr.NewMultiaddr(hostInfoStr) + if err != nil { + return "", nil, err + } result = append(result, addr.Encapsulate(hostInfo)) offset += 2 + int(maSize)