fix: extract multiaddress from enode key if available (#199)

This commit is contained in:
Richard Ramos 2022-03-08 08:58:32 -04:00 committed by GitHub
parent f4f307db87
commit cf6c4ae8fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 7 deletions

View File

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

View File

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