mirror of
https://github.com/libp2p/go-libp2p-core.git
synced 2025-02-05 05:50:08 +08:00
feat: add helper functions for working with addr infos (#202)
Specifically, move them _here_ from the peerstore. That way
packages (like the DHT) that currently directly rely on the peerstore,
can just use go-libp2p-core.
Moved from f7f22569f7/peerstore.go (L79-L93)
With some small modifications.
This commit is contained in:
parent
ef6e277df7
commit
8c04ed1323
@ -106,3 +106,12 @@ func (pi *AddrInfo) Loggable() map[string]interface{} {
|
||||
"addrs": pi.Addrs,
|
||||
}
|
||||
}
|
||||
|
||||
// AddrInfosToIDs extracts the peer IDs from the passed AddrInfos and returns them in-order.
|
||||
func AddrInfosToIDs(pis []AddrInfo) []ID {
|
||||
ps := make([]ID, len(pis))
|
||||
for i, pi := range pis {
|
||||
ps[i] = pi.ID
|
||||
}
|
||||
return ps
|
||||
}
|
||||
|
14
peerstore/helpers.go
Normal file
14
peerstore/helpers.go
Normal file
@ -0,0 +1,14 @@
|
||||
package peerstore
|
||||
|
||||
import (
|
||||
"github.com/libp2p/go-libp2p-core/peer"
|
||||
)
|
||||
|
||||
// AddrInfos returns an AddrInfo for each specified peer ID, in-order.
|
||||
func AddrInfos(ps Peerstore, peers []peer.ID) []peer.AddrInfo {
|
||||
pi := make([]peer.AddrInfo, len(peers))
|
||||
for i, p := range peers {
|
||||
pi[i] = ps.PeerInfo(p)
|
||||
}
|
||||
return pi
|
||||
}
|
Loading…
Reference in New Issue
Block a user