diff --git a/core/peer/addrinfo.go b/core/peer/addrinfo.go index 175b93e4..6c579fc8 100644 --- a/core/peer/addrinfo.go +++ b/core/peer/addrinfo.go @@ -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 +} diff --git a/core/peerstore/helpers.go b/core/peerstore/helpers.go new file mode 100644 index 00000000..e41cf781 --- /dev/null +++ b/core/peerstore/helpers.go @@ -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 +}