fix: exclude dht from search-for-self

The peer routing module starts a recurring process that searches for
peers close to our peer id.

This makes the DHT module query the network for peers.  Thing is the
DHT module is already doing this because periodically searching for
peers close to us is in the DHT spec so this ends up making redundant
queries.

This PR excludes the DHT from the search-for-self task
This commit is contained in:
achingbrain 2021-12-07 14:36:29 +00:00
parent cbaa5a2ef3
commit 1650d7b7a3

View File

@ -15,7 +15,6 @@ const { TimeoutController } = require('timeout-abort-controller')
const merge = require('it-merge') const merge = require('it-merge')
const { pipe } = require('it-pipe') const { pipe } = require('it-pipe')
const first = require('it-first') const first = require('it-first')
const drain = require('it-drain')
const filter = require('it-filter') const filter = require('it-filter')
const { const {
setDelayedInterval, setDelayedInterval,
@ -77,13 +76,25 @@ class PeerRouting {
/** /**
* Recurrent task to find closest peers and add their addresses to the Address Book. * Recurrent task to find closest peers and add their addresses to the Address Book.
* Does not include the DHT (if present) as it has it's own method of periodically
* finding the closest peers
*/ */
async _findClosestPeersTask () { async _findClosestPeersTask () {
const timeout = new TimeoutController(this._refreshManagerOptions.timeout || 10e3)
try { try {
// nb getClosestPeers adds the addresses to the address book const routers = this._routers.filter(router => !(router instanceof DHTPeerRouting))
await drain(this.getClosestPeers(this._peerId.id, { timeout: this._refreshManagerOptions.timeout || 10e3 }))
await pipe(
merge(
...routers.map(router => router.getClosestPeers(this._peerId.id, { signal: timeout.signal }))
),
(source) => storeAddresses(source, this._peerStore)
)
} catch (/** @type {any} */ err) { } catch (/** @type {any} */ err) {
log.error(err) log.error(err)
} finally {
timeout.clear()
} }
} }