Skip to content
This repository has been archived by the owner on Sep 6, 2022. It is now read-only.

feat: add helper functions for working with addr infos #202

Merged
merged 1 commit into from
Jul 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions peer/addrinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 14 additions & 0 deletions peerstore/helpers.go
Original file line number Diff line number Diff line change
@@ -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
}