Skip to content

Commit

Permalink
Merge pull request #802 from cortze/feat/return-providers-with-maddrs
Browse files Browse the repository at this point in the history
Adjust PeerSet logic in the DHT lookup process
  • Loading branch information
guillaumemichel authored Mar 13, 2023
2 parents 1103b68 + f0f2434 commit 0239a32
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,14 +486,14 @@ func (dht *IpfsDHT) findProvidersAsyncRoutine(ctx context.Context, key multihash

findAll := count == 0

ps := make(map[peer.ID]struct{})
ps := make(map[peer.ID]peer.AddrInfo)
psLock := &sync.Mutex{}
psTryAdd := func(p peer.ID) bool {
psTryAdd := func(p peer.AddrInfo) bool {
psLock.Lock()
defer psLock.Unlock()
_, ok := ps[p]
if !ok && (len(ps) < count || findAll) {
ps[p] = struct{}{}
pi, ok := ps[p.ID]
if (!ok || ((len(pi.Addrs) == 0) && len(p.Addrs) > 0)) && (len(ps) < count || findAll) {
ps[p.ID] = p
return true
}
return false
Expand All @@ -510,7 +510,7 @@ func (dht *IpfsDHT) findProvidersAsyncRoutine(ctx context.Context, key multihash
}
for _, p := range provs {
// NOTE: Assuming that this list of peers is unique
if psTryAdd(p.ID) {
if psTryAdd(p) {
select {
case peerOut <- p:
case <-ctx.Done():
Expand Down Expand Up @@ -544,7 +544,7 @@ func (dht *IpfsDHT) findProvidersAsyncRoutine(ctx context.Context, key multihash
for _, prov := range provs {
dht.maybeAddAddrs(prov.ID, prov.Addrs, peerstore.TempAddrTTL)
logger.Debugf("got provider: %s", prov)
if psTryAdd(prov.ID) {
if psTryAdd(*prov) {
logger.Debugf("using provider: %s", prov)
select {
case peerOut <- *prov:
Expand Down

0 comments on commit 0239a32

Please sign in to comment.