mirror of https://github.com/status-im/go-waku.git
fix: extract multiaddress from enode key if available (#199)
This commit is contained in:
parent
f4f307db87
commit
cf6c4ae8fe
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue