From 106b04340abb28fc9c536c3349132ff9647fcdeb Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Wed, 5 Oct 2022 10:01:21 -0600 Subject: [PATCH] Remove local providers (#268) * add remove provider method * remove failed providers * bumping dht to latest master --- codex/blockexchange/engine/discovery.nim | 10 ++++++++-- codex/discovery.nim | 7 +++++++ vendor/nim-libp2p-dht | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/codex/blockexchange/engine/discovery.nim b/codex/blockexchange/engine/discovery.nim index 5672d263..90009241 100644 --- a/codex/blockexchange/engine/discovery.nim +++ b/codex/blockexchange/engine/discovery.nim @@ -152,8 +152,14 @@ proc discoveryTaskLoop(b: DiscoveryEngine) {.async.} = peers = await request trace "Discovered peers", peers = peers.len - checkFutures( - await allFinished(peers.mapIt( b.network.dialPeer(it.data)))) + let + dialed = await allFinished( + peers.mapIt( b.network.dialPeer(it.data) )) + + for i, f in dialed: + if f.failed: + await b.discovery.removeProvider(peers[i].data.peerId) + finally: b.inFlightDiscReqs.del(cid) codex_inflight_discovery.set(b.inFlightAdvReqs.len.int64) diff --git a/codex/discovery.nim b/codex/discovery.nim index 944ad821..2f9917f3 100644 --- a/codex/discovery.nim +++ b/codex/discovery.nim @@ -137,6 +137,13 @@ method provide*(d: Discovery, host: ca.Address) {.async, base.} = if nodes.len > 0: trace "Provided to nodes", nodes = nodes.len +method removeProvider*(d: Discovery, peerId: PeerId): Future[void] = + ## Remove provider from providers table + ## + + trace "Removing provider", peerId + d.protocol.removeProvidersLocal(peerId) + proc start*(d: Discovery) {.async.} = d.protocol.updateRecord( d.localInfo.signedPeerRecord.some) diff --git a/vendor/nim-libp2p-dht b/vendor/nim-libp2p-dht index 4b9fa035..08928e57 160000 --- a/vendor/nim-libp2p-dht +++ b/vendor/nim-libp2p-dht @@ -1 +1 @@ -Subproject commit 4b9fa0356e6cefbbbcedcf21a914cda575229774 +Subproject commit 08928e57d82736ab9524010a3bd59a707f2e0769