mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-04-25 10:32:14 +00:00
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:
parent
cbaa5a2ef3
commit
1650d7b7a3
@ -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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user