fix: add p2p-circuit component to multiaddresses that use circuit-relay

This commit is contained in:
Richard Ramos 2023-06-30 11:26:04 -04:00 committed by richΛrd
parent 7781e850d5
commit dbd94ebb81
1 changed files with 11 additions and 5 deletions

View File

@ -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)