stop using the peer.Set (#201)

This commit is contained in:
Marten Seemann 2022-06-27 19:12:14 +02:00 committed by GitHub
parent 9f3a96b88d
commit c80216f8a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -147,17 +147,21 @@ func (mab *memoryAddrBook) gc() {
func (mab *memoryAddrBook) PeersWithAddrs() peer.IDSlice { func (mab *memoryAddrBook) PeersWithAddrs() peer.IDSlice {
// deduplicate, since the same peer could have both signed & unsigned addrs // deduplicate, since the same peer could have both signed & unsigned addrs
pidSet := peer.NewSet() set := make(map[peer.ID]struct{})
for _, s := range mab.segments { for _, s := range mab.segments {
s.RLock() s.RLock()
for pid, amap := range s.addrs { for pid, amap := range s.addrs {
if len(amap) > 0 { if len(amap) > 0 {
pidSet.Add(pid) set[pid] = struct{}{}
} }
} }
s.RUnlock() s.RUnlock()
} }
return pidSet.Peers() peers := make(peer.IDSlice, 0, len(set))
for pid := range set {
peers = append(peers, pid)
}
return peers
} }
// AddAddr calls AddAddrs(p, []ma.Multiaddr{addr}, ttl) // AddAddr calls AddAddrs(p, []ma.Multiaddr{addr}, ttl)