From cf6c4ae8fecc3b56dd0572b848bed0a287619582 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Tue, 8 Mar 2022 08:58:32 -0400 Subject: [PATCH] fix: extract multiaddress from enode key if available (#199) --- waku/v2/discv5/discover.go | 13 ++++++++----- waku/v2/utils/enr.go | 9 +++++++-- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/waku/v2/discv5/discover.go b/waku/v2/discv5/discover.go index 0f4de41c..05071c6a 100644 --- a/waku/v2/discv5/discover.go +++ b/waku/v2/discv5/discover.go @@ -362,22 +362,25 @@ func (d *DiscoveryV5) iterate(ctx context.Context, iterator enode.Iterator, limi break } - address, err := utils.EnodeToMultiAddr(iterator.Node()) + addresses, err := utils.Multiaddress(iterator.Node()) if err != nil { d.log.Error(err) continue } - peerInfo, err := peer.AddrInfoFromP2pAddr(address) + peerAddrs, err := peer.AddrInfosFromP2pAddrs(addresses...) if err != nil { d.log.Error(err) continue } - d.peerCache.recs[peerInfo.ID] = peerRecord{ - expire: time.Now().Unix() + 3600, // Expires in 1hr - peer: *peerInfo, + for _, p := range peerAddrs { + d.peerCache.recs[p.ID] = peerRecord{ + expire: time.Now().Unix() + 3600, // Expires in 1hr + peer: p, + } } + } close(doneCh) diff --git a/waku/v2/utils/enr.go b/waku/v2/utils/enr.go index 2ff67ed1..c8fa4a6a 100644 --- a/waku/v2/utils/enr.go +++ b/waku/v2/utils/enr.go @@ -144,8 +144,13 @@ func Multiaddress(node *enode.Node) ([]ma.Multiaddr, error) { var multiaddrRaw []byte if err := node.Record().Load(enr.WithEntry(MultiaddrENRField, &multiaddrRaw)); err != nil { - if !enr.IsNotFound(err) { - Logger().Error("could not retrieve multiaddress field for node ", zap.Any("enode", node)) + if enr.IsNotFound(err) { + Logger().Debug("Trying to convert enode to multiaddress, since I could not retrieve multiaddress field for node ", zap.Any("enode", node)) + addr, err := EnodeToMultiAddr(node) + if err != nil { + return nil, err + } + return []ma.Multiaddr{addr}, nil } return nil, err }