From 47137997c1b12de546231f118a21821fcfb0a89e Mon Sep 17 00:00:00 2001 From: cortze Date: Wed, 7 Dec 2022 16:29:09 +0100 Subject: [PATCH 1/3] update PeerSet to notify of PRs that come with MAddr --- routing.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/routing.go b/routing.go index 4f3efffab..7485d245b 100644 --- a/routing.go +++ b/routing.go @@ -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(ps) < count || findAll)) || ((len(pi.Addrs) == 0) && len(p.Addrs) > 0){ + ps[p.ID] = p return true } return false @@ -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(): @@ -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: From 0428dec26010861c1c94d4d7ac90e3f7c4c5e808 Mon Sep 17 00:00:00 2001 From: cortze Date: Wed, 7 Dec 2022 16:33:11 +0100 Subject: [PATCH 2/3] format changes --- routing.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routing.go b/routing.go index 7485d245b..c33bd64fc 100644 --- a/routing.go +++ b/routing.go @@ -492,7 +492,7 @@ func (dht *IpfsDHT) findProvidersAsyncRoutine(ctx context.Context, key multihash psLock.Lock() defer psLock.Unlock() pi, ok := ps[p.ID] - if (!ok && (len(ps) < count || findAll)) || ((len(pi.Addrs) == 0) && len(p.Addrs) > 0){ + if (!ok && (len(ps) < count || findAll)) || ((len(pi.Addrs) == 0) && len(p.Addrs) > 0) { ps[p.ID] = p return true } From f0f2434516e6a58ff9db5d0fc48b9cee175517d4 Mon Sep 17 00:00:00 2001 From: cortze Date: Wed, 7 Dec 2022 18:12:07 +0100 Subject: [PATCH 3/3] adjust logic to respect size of the array --- routing.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routing.go b/routing.go index c33bd64fc..076056cf0 100644 --- a/routing.go +++ b/routing.go @@ -492,7 +492,7 @@ func (dht *IpfsDHT) findProvidersAsyncRoutine(ctx context.Context, key multihash psLock.Lock() defer psLock.Unlock() pi, ok := ps[p.ID] - if (!ok && (len(ps) < count || findAll)) || ((len(pi.Addrs) == 0) && len(p.Addrs) > 0) { + if (!ok || ((len(pi.Addrs) == 0) && len(p.Addrs) > 0)) && (len(ps) < count || findAll) { ps[p.ID] = p return true }