libp2p 0.35.0 → 0.35.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -9,6 +9,7 @@ export = PeerRouting;
|
|
|
9
9
|
* @property {boolean} [enabled = true] - Whether to enable the Refresh manager
|
|
10
10
|
* @property {number} [bootDelay = 6e5] - Boot delay to start the Refresh Manager (in ms)
|
|
11
11
|
* @property {number} [interval = 10e3] - Interval between each Refresh Manager run (in ms)
|
|
12
|
+
* @property {number} [timeout = 10e3] - How long to let each refresh run (in ms)
|
|
12
13
|
*
|
|
13
14
|
* @typedef {Object} PeerRoutingOptions
|
|
14
15
|
* @property {RefreshManagerOptions} [refreshManager]
|
|
@@ -60,11 +61,13 @@ declare class PeerRouting {
|
|
|
60
61
|
*
|
|
61
62
|
* @param {Uint8Array} key - A CID like key
|
|
62
63
|
* @param {Object} [options]
|
|
63
|
-
* @param {number} [options.timeout=30e3] - How long the query can take
|
|
64
|
+
* @param {number} [options.timeout=30e3] - How long the query can take
|
|
65
|
+
* @param {AbortSignal} [options.signal] - An AbortSignal to abort the request
|
|
64
66
|
* @returns {AsyncIterable<{ id: PeerId, multiaddrs: Multiaddr[] }>}
|
|
65
67
|
*/
|
|
66
68
|
getClosestPeers(key: Uint8Array, options?: {
|
|
67
69
|
timeout?: number | undefined;
|
|
70
|
+
signal?: AbortSignal | undefined;
|
|
68
71
|
} | undefined): AsyncIterable<{
|
|
69
72
|
id: PeerId;
|
|
70
73
|
multiaddrs: Multiaddr[];
|
|
@@ -87,6 +90,10 @@ type RefreshManagerOptions = {
|
|
|
87
90
|
* - Interval between each Refresh Manager run (in ms)
|
|
88
91
|
*/
|
|
89
92
|
interval?: number | undefined;
|
|
93
|
+
/**
|
|
94
|
+
* - How long to let each refresh run (in ms)
|
|
95
|
+
*/
|
|
96
|
+
timeout?: number | undefined;
|
|
90
97
|
};
|
|
91
98
|
type PeerId = import('peer-id');
|
|
92
99
|
type Multiaddr = import('multiaddr').Multiaddr;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"peer-routing.d.ts","sourceRoot":"","sources":["../../src/peer-routing.js"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"peer-routing.d.ts","sourceRoot":"","sources":["../../src/peer-routing.js"],"names":[],"mappings":";AA0BA;;;;GAIG;AAEH;;;;;;;;;GASG;AAEH;IACE;;;OAGG;IACH,oBAFW,OAAO,IAAI,CAAC,EAgBtB;IAbC,2BAA4B;IAC5B,mCAAkC;IAClC,kCAAkC;IAClC,UADW,iBAAiB,EAAE,CACmB;IAOjD;;;;8BAAwE;IAkB1E;;OAEG;IACH,uCAOC;IAvBD;;OAEG;IACH,cAQC;IAHC,gBAEC;IAeH;;OAEG;IACH,aAEC;IAED;;;;;;;OAOG;IACH,aALW,MAAM;;oBAGJ,QAAQ;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,SAAS,EAAE,CAAA;KAAE,CAAC,CA0B5D;IAED;;;;;;;;OAQG;IACH,qBANW,UAAU;;;oBAIR,cAAc;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,SAAS,EAAE,CAAA;KAAE,CAAC,CAmBlE;CACF;;;;yBAhIY,OAAO,0CAA0C,EAAE,WAAW;;;;;;;;;;;;;;;;;;;cAF9D,OAAO,SAAS,CAAC;iBACjB,OAAO,WAAW,EAAE,SAAS"}
|
package/package.json
CHANGED
package/src/peer-routing.js
CHANGED
|
@@ -10,6 +10,7 @@ const {
|
|
|
10
10
|
uniquePeers,
|
|
11
11
|
requirePeers
|
|
12
12
|
} = require('./content-routing/utils')
|
|
13
|
+
const { TimeoutController } = require('timeout-abort-controller')
|
|
13
14
|
|
|
14
15
|
const merge = require('it-merge')
|
|
15
16
|
const { pipe } = require('it-pipe')
|
|
@@ -34,6 +35,7 @@ const { DHTPeerRouting } = require('./dht/dht-peer-routing')
|
|
|
34
35
|
* @property {boolean} [enabled = true] - Whether to enable the Refresh manager
|
|
35
36
|
* @property {number} [bootDelay = 6e5] - Boot delay to start the Refresh Manager (in ms)
|
|
36
37
|
* @property {number} [interval = 10e3] - Interval between each Refresh Manager run (in ms)
|
|
38
|
+
* @property {number} [timeout = 10e3] - How long to let each refresh run (in ms)
|
|
37
39
|
*
|
|
38
40
|
* @typedef {Object} PeerRoutingOptions
|
|
39
41
|
* @property {RefreshManagerOptions} [refreshManager]
|
|
@@ -79,7 +81,7 @@ class PeerRouting {
|
|
|
79
81
|
async _findClosestPeersTask () {
|
|
80
82
|
try {
|
|
81
83
|
// nb getClosestPeers adds the addresses to the address book
|
|
82
|
-
await drain(this.getClosestPeers(this._peerId.id))
|
|
84
|
+
await drain(this.getClosestPeers(this._peerId.id, { timeout: this._refreshManagerOptions.timeout || 10e3 }))
|
|
83
85
|
} catch (/** @type {any} */ err) {
|
|
84
86
|
log.error(err)
|
|
85
87
|
}
|
|
@@ -131,7 +133,8 @@ class PeerRouting {
|
|
|
131
133
|
*
|
|
132
134
|
* @param {Uint8Array} key - A CID like key
|
|
133
135
|
* @param {Object} [options]
|
|
134
|
-
* @param {number} [options.timeout=30e3] - How long the query can take
|
|
136
|
+
* @param {number} [options.timeout=30e3] - How long the query can take
|
|
137
|
+
* @param {AbortSignal} [options.signal] - An AbortSignal to abort the request
|
|
135
138
|
* @returns {AsyncIterable<{ id: PeerId, multiaddrs: Multiaddr[] }>}
|
|
136
139
|
*/
|
|
137
140
|
async * getClosestPeers (key, options = { timeout: 30e3 }) {
|
|
@@ -139,6 +142,10 @@ class PeerRouting {
|
|
|
139
142
|
throw errCode(new Error('No peer routers available'), 'NO_ROUTERS_AVAILABLE')
|
|
140
143
|
}
|
|
141
144
|
|
|
145
|
+
if (options.timeout) {
|
|
146
|
+
options.signal = new TimeoutController(options.timeout).signal
|
|
147
|
+
}
|
|
148
|
+
|
|
142
149
|
yield * pipe(
|
|
143
150
|
merge(
|
|
144
151
|
...this._routers.map(router => router.getClosestPeers(key, options))
|