libp2p 0.35.4 → 0.35.8
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.
- package/README.md +2 -2
- package/dist/src/connection-manager/auto-dialler.d.ts.map +1 -1
- package/dist/src/connection-manager/index.d.ts.map +1 -1
- package/dist/src/dht/dht-peer-routing.d.ts.map +1 -1
- package/dist/src/dialer/index.d.ts +15 -11
- package/dist/src/dialer/index.d.ts.map +1 -1
- package/dist/src/index.d.ts +10 -5
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/metrics/stats.d.ts +3 -1
- package/dist/src/metrics/stats.d.ts.map +1 -1
- package/dist/src/metrics/tracked-map.d.ts +3 -0
- package/dist/src/metrics/tracked-map.d.ts.map +1 -0
- package/dist/src/peer-routing.d.ts.map +1 -1
- package/package.json +12 -9
- package/src/connection-manager/auto-dialler.js +3 -1
- package/src/connection-manager/index.js +4 -11
- package/src/dht/dht-peer-routing.js +2 -6
- package/src/dialer/index.js +17 -16
- package/src/index.js +12 -10
- package/src/metrics/stats.js +1 -0
- package/src/metrics/tracked-map.js +68 -0
- package/src/peer-routing.js +8 -1
package/README.md
CHANGED
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
<a href="https://david-dm.org/libp2p/js-libp2p"><img src="https://david-dm.org/libp2p/js-libp2p.svg?style=flat-square" /></a>
|
|
24
24
|
<a href="https://github.com/feross/standard"><img src="https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square"></a>
|
|
25
25
|
<a href="https://github.com/RichardLitt/standard-readme"><img src="https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square" /></a>
|
|
26
|
-
<a href=""><img src="https://img.shields.io/badge/npm-%3E%
|
|
27
|
-
<a href=""><img src="https://img.shields.io/badge/Node.js-%3E%
|
|
26
|
+
<a href=""><img src="https://img.shields.io/badge/npm-%3E%3D7.0.0-orange.svg?style=flat-square" /></a>
|
|
27
|
+
<a href=""><img src="https://img.shields.io/badge/Node.js-%3E%3D15.0.0-orange.svg?style=flat-square" /></a>
|
|
28
28
|
<br>
|
|
29
29
|
</p>
|
|
30
30
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auto-dialler.d.ts","sourceRoot":"","sources":["../../../src/connection-manager/auto-dialler.js"],"names":[],"mappings":";AAiBA;;;GAGG;AAEH;;;;;GAKG;AAEH;IACE;;;;;;;;OAQG;IACH,oBAHW,MAAM,YACN,kBAAkB,EAU5B;IAPC,cAAqF;IACrF,4BAAqB;IACrB,kBAAqB;IACrB,sBAA4B;
|
|
1
|
+
{"version":3,"file":"auto-dialler.d.ts","sourceRoot":"","sources":["../../../src/connection-manager/auto-dialler.js"],"names":[],"mappings":";AAiBA;;;GAGG;AAEH;;;;;GAKG;AAEH;IACE;;;;;;;;OAQG;IACH,oBAHW,MAAM,YACN,kBAAkB,EAU5B;IAPC,cAAqF;IACrF,4BAAqB;IACrB,kBAAqB;IACrB,sBAA4B;IAoC9B,2BAqCC;IAnED;;OAEG;IACH,cAWC;IAED;;OAEG;IACH,sBASC;CAwCF;;;;cAnGY,OAAO,UAAU,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/connection-manager/index.js"],"names":[],"mappings":";AAsCA;;;GAGG;AAEH;;;;;;;;;;;;;GAaG;AAEH;;;;GAIG;AACH;IACE;;;;;;OAMG;IACH,oBAHW,MAAM,YACN,wBAAwB,EAqClC;IAhCC,uBAAqB;IACrB,gBAA0C;IAE1C,cAAqF;IAOrF;;;;OAIG;IACH,aAFU,IAAI,MAAM,EAAE,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/connection-manager/index.js"],"names":[],"mappings":";AAsCA;;;GAGG;AAEH;;;;;;;;;;;;;GAaG;AAEH;;;;GAIG;AACH;IACE;;;;;;OAMG;IACH,oBAHW,MAAM,YACN,wBAAwB,EAqClC;IAhCC,uBAAqB;IACrB,gBAA0C;IAE1C,cAAqF;IAOrF;;;;OAIG;IACH,aAFU,IAAI,MAAM,EAAE,MAAM,CAAC,CAE8D;IAE3F;;;;OAIG;IACH,aAFU,IAAI,MAAM,EAAE,UAAU,EAAE,CAAC,CAE6D;IAEhG,kBAAqB;IACrB,YAAkB;IAoFpB;;;;;OAKG;IACH,sBAcC;IArGC,gCAGE;IAGJ;;OAEG;IACH,mBAGC;IAED;;;OAGG;IACH,cAYC;IA8JD;;;;;OAKG;IACH,0BAEC;IApKD;;;;OAIG;IACH,sBASC;IAED;;;;OAIG;IACH,wBAWC;IAED;;;;;;;OAOG;IACH,qBAJW,MAAM,SACN,MAAM,GACJ,IAAI,CAOhB;IAwBD;;;;;OAKG;IACH,sBAHW,UAAU,GACR,IAAI,CAsBhB;IAED;;;;;OAKG;IACH,yBAHW,UAAU,GACR,IAAI,CAgBhB;IAED;;;;;OAKG;IACH,YAHW,MAAM,GACJ,UAAU,GAAC,IAAI,CAQ3B;IAED;;;;;OAKG;IACH,eAHW,MAAM,GACJ,UAAU,EAAE,CAexB;IAYD;;;;;;OAMG;IACH,uBAOC;IAED;;;;;OAKG;IACH,4BAiBC;CACF;;;;;;;;cA7SY,OAAO,KAAK,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dht-peer-routing.d.ts","sourceRoot":"","sources":["../../../src/dht/dht-peer-routing.js"],"names":[],"mappings":"qBAMa,OAAO,SAAS,CAAC;gCACjB,OAAO,0CAA0C,EAAE,WAAW;AAF3E;;;GAGG;AAEH;;;;GAIG;AACH;IACE;;OAEG;IACH,iBAFW,OAAO,gBAAgB,EAAE,GAAG,EAItC;IADC,kDAAe;IAGjB;;;OAGG;IACH,iBAHW,MAAM,YACN,GAAG,
|
|
1
|
+
{"version":3,"file":"dht-peer-routing.d.ts","sourceRoot":"","sources":["../../../src/dht/dht-peer-routing.js"],"names":[],"mappings":"qBAMa,OAAO,SAAS,CAAC;gCACjB,OAAO,0CAA0C,EAAE,WAAW;AAF3E;;;GAGG;AAEH;;;;GAIG;AACH;IACE;;OAEG;IACH,iBAFW,OAAO,gBAAgB,EAAE,GAAG,EAItC;IADC,kDAAe;IAGjB;;;OAGG;IACH,iBAHW,MAAM,YACN,GAAG,6DAUb;IAED;;;OAGG;IACH,qBAHW,UAAU,YACV,GAAG,qFAQb;CACF"}
|
|
@@ -27,8 +27,8 @@ export = Dialer;
|
|
|
27
27
|
* @property {Multiaddr[]} addrs
|
|
28
28
|
*
|
|
29
29
|
* @typedef PendingDial
|
|
30
|
-
* @property {
|
|
31
|
-
* @property {TimeoutController} controller
|
|
30
|
+
* @property {import('./dial-request')} dialRequest
|
|
31
|
+
* @property {import('timeout-abort-controller').TimeoutController} controller
|
|
32
32
|
* @property {Promise<Connection>} promise
|
|
33
33
|
* @property {function():void} destroy
|
|
34
34
|
*/
|
|
@@ -46,9 +46,13 @@ declare class Dialer {
|
|
|
46
46
|
timeout: number;
|
|
47
47
|
maxDialsPerPeer: number;
|
|
48
48
|
tokens: number[];
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
/** @type {Map<string, PendingDial>} */
|
|
50
|
+
_pendingDials: Map<string, PendingDial>;
|
|
51
|
+
/** @type {Map<string, { resolve: (value: any) => void, reject: (err: Error) => void}>} */
|
|
52
|
+
_pendingDialTargets: Map<string, {
|
|
53
|
+
resolve: (value: any) => void;
|
|
54
|
+
reject: (err: Error) => void;
|
|
55
|
+
}>;
|
|
52
56
|
/**
|
|
53
57
|
* Clears any pending dials
|
|
54
58
|
*/
|
|
@@ -122,6 +126,12 @@ declare class Dialer {
|
|
|
122
126
|
declare namespace Dialer {
|
|
123
127
|
export { Connection, PeerId, PeerStore, Address, TransportManager, DialerProperties, Resolver, DialerOptions, DialTarget, PendingDial };
|
|
124
128
|
}
|
|
129
|
+
type PendingDial = {
|
|
130
|
+
dialRequest: import('./dial-request');
|
|
131
|
+
controller: import('timeout-abort-controller').TimeoutController;
|
|
132
|
+
promise: Promise<Connection>;
|
|
133
|
+
destroy: () => void;
|
|
134
|
+
};
|
|
125
135
|
type PeerId = import('peer-id');
|
|
126
136
|
import { Multiaddr } from "multiaddr";
|
|
127
137
|
type Connection = import("libp2p-interfaces/src/connection/connection");
|
|
@@ -164,10 +174,4 @@ type PeerStore = import('../peer-store');
|
|
|
164
174
|
type Address = import('../peer-store/address-book').Address;
|
|
165
175
|
type TransportManager = import('../transport-manager');
|
|
166
176
|
type Resolver = (addr: Multiaddr) => Promise<string[]>;
|
|
167
|
-
type PendingDial = {
|
|
168
|
-
dialRequest: DialRequest;
|
|
169
|
-
controller: TimeoutController;
|
|
170
|
-
promise: Promise<Connection>;
|
|
171
|
-
destroy: () => void;
|
|
172
|
-
};
|
|
173
177
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/dialer/index.js"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/dialer/index.js"],"names":[],"mappings":";AA6BA;;;;;;GAMG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH;IACE;;;OAGG;IACH,gJAFW,gBAAgB,GAAG,aAAa,EA+B1C;IAlBC,iDAAwC;IACxC,mCAA0B;IAC1B,2BArCsB,OAAO,EAAE,KAAK,OAAO,EAAE,CAqCX;IAClC,yBAAwC;IACxC,uBAAoC;IACpC,gBAA0B;IAC1B,wBAAsC;IACtC,iBAAuE;IAEvE,uCAAuC;IACvC,eADW,IAAI,MAAM,EAAE,WAAW,CAAC,CAC+C;IAElF,0FAA0F;IAC1F;yBAD0C,GAAG,KAAK,IAAI;sBAAgB,KAAK,KAAK,IAAI;OACW;IAOjG;;OAEG;IACH,gBAcC;IAED;;;;;;;;;OASG;IACH,oBALW,MAAM,GAAC,SAAS,GAAC,MAAM;;oBAGrB,QAAQ,UAAU,CAAC,CAwB/B;IAED;;;;;;;OAOG;IACH,mCAHW,MAAM,GAAC,SAAS,GAAC,MAAM,GACrB,QAAQ,UAAU,CAAC,CAmB/B;IAED;;;;;;;;;OASG;IACH,0BAmCC;IAED;;;;;;;;OAQG;IACH,2BAuCC;IAED;;OAEG;IACH,eAFW,MAAM,YAOhB;IAED;;OAEG;IACH,oBAFW,MAAM,QAOhB;IAED;;;;;OAKG;IACH,aAHW,SAAS,GACP,QAAQ,SAAS,EAAE,CAAC,CAwBhC;IAED;;;;;OAKG;IACH,mBAHW,SAAS,GACP,QAAQ,SAAS,EAAE,CAAC,CAWhC;CACF;;;;;iBA7Ra,OAAO,gBAAgB,CAAC;gBACxB,OAAO,0BAA0B,EAAE,iBAAiB;aACpD,QAAQ,UAAU,CAAC;mBACR,IAAI;;cA9BhB,OAAO,SAAS,CAAC;;;;QAuBhB,MAAM;WACN,SAAS,EAAE;;;eAhBX,SAAS;sBACT,gBAAgB;;;;;;iCAKJ,OAAO,EAAE,KAAK,OAAO,EAAE;;;;;;;;;;;;;;;;;;;;;;;iBAbpC,OAAO,eAAe,CAAC;eACvB,OAAO,4BAA4B,EAAE,OAAO;wBAC5C,OAAO,sBAAsB,CAAC;uBAQxB,SAAS,KAAK,QAAQ,MAAM,EAAE,CAAC"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -12,6 +12,8 @@ export = Libp2p;
|
|
|
12
12
|
* @typedef {import('libp2p-interfaces/src/pubsub').PubsubOptions} PubsubOptions
|
|
13
13
|
* @typedef {import('interface-datastore').Datastore} Datastore
|
|
14
14
|
* @typedef {import('./pnet')} Protector
|
|
15
|
+
* @typedef {Object} PersistentPeerStoreOptions
|
|
16
|
+
* @property {number} [threshold]
|
|
15
17
|
*/
|
|
16
18
|
/**
|
|
17
19
|
* @typedef {Object} HandlerProps
|
|
@@ -73,7 +75,7 @@ export = Libp2p;
|
|
|
73
75
|
* @property {KeychainOptions & import('./keychain/index').KeychainOptions} [keychain]
|
|
74
76
|
* @property {MetricsOptions & import('./metrics').MetricsOptions} [metrics]
|
|
75
77
|
* @property {import('./peer-routing').PeerRoutingOptions} [peerRouting]
|
|
76
|
-
* @property {PeerStoreOptions &
|
|
78
|
+
* @property {PeerStoreOptions & PersistentPeerStoreOptions} [peerStore]
|
|
77
79
|
* @property {import('./transport-manager').TransportManagerOptions} [transportManager]
|
|
78
80
|
* @property {Libp2pConfig} [config]
|
|
79
81
|
*
|
|
@@ -186,6 +188,7 @@ declare class Libp2p extends EventEmitter {
|
|
|
186
188
|
/** @type {PeerId} */
|
|
187
189
|
peerId: PeerId;
|
|
188
190
|
datastore: import("interface-datastore").Datastore | undefined;
|
|
191
|
+
metrics: Metrics | undefined;
|
|
189
192
|
peerStore: PeerStore;
|
|
190
193
|
addresses: {
|
|
191
194
|
listen: never[];
|
|
@@ -239,7 +242,6 @@ declare class Libp2p extends EventEmitter {
|
|
|
239
242
|
_discovery: Map<any, any>;
|
|
240
243
|
connectionManager: ConnectionManager;
|
|
241
244
|
_autodialler: AutoDialler;
|
|
242
|
-
metrics: Metrics | undefined;
|
|
243
245
|
keychain: Keychain | undefined;
|
|
244
246
|
upgrader: Upgrader;
|
|
245
247
|
transportManager: TransportManager;
|
|
@@ -391,7 +393,7 @@ declare class Libp2p extends EventEmitter {
|
|
|
391
393
|
private _setupPeerDiscovery;
|
|
392
394
|
}
|
|
393
395
|
declare namespace Libp2p {
|
|
394
|
-
export { Connection, MuxedStream, TransportFactory, MuxerFactory, ContentRoutingModule, PeerDiscoveryFactory, PeerRoutingModule, Crypto, Pubsub, PubsubOptions, Datastore, Protector, HandlerProps, DhtOptions, KeychainOptions, PeerStoreOptions, PubsubLocalOptions, MetricsOptions, RelayOptions, Libp2pConfig, Libp2pModules, Libp2pOptions, constructorOptions, CreateOptions };
|
|
396
|
+
export { Connection, MuxedStream, TransportFactory, MuxerFactory, ContentRoutingModule, PeerDiscoveryFactory, PeerRoutingModule, Crypto, Pubsub, PubsubOptions, Datastore, Protector, PersistentPeerStoreOptions, HandlerProps, DhtOptions, KeychainOptions, PeerStoreOptions, PubsubLocalOptions, MetricsOptions, RelayOptions, Libp2pConfig, Libp2pModules, Libp2pOptions, constructorOptions, CreateOptions };
|
|
395
397
|
}
|
|
396
398
|
import { EventEmitter } from "events";
|
|
397
399
|
type Libp2pOptions = {
|
|
@@ -410,7 +412,7 @@ type Libp2pOptions = {
|
|
|
410
412
|
keychain?: (KeychainOptions & Keychain.KeychainOptions) | undefined;
|
|
411
413
|
metrics?: (MetricsOptions & Metrics.MetricsOptions) | undefined;
|
|
412
414
|
peerRouting?: PeerRouting.PeerRoutingOptions | undefined;
|
|
413
|
-
peerStore?: (PeerStoreOptions &
|
|
415
|
+
peerStore?: (PeerStoreOptions & PersistentPeerStoreOptions) | undefined;
|
|
414
416
|
transportManager?: TransportManager.TransportManagerOptions | undefined;
|
|
415
417
|
config?: Libp2pConfig | undefined;
|
|
416
418
|
};
|
|
@@ -418,6 +420,7 @@ type constructorOptions = {
|
|
|
418
420
|
peerId: PeerId;
|
|
419
421
|
};
|
|
420
422
|
import PeerId = require("peer-id");
|
|
423
|
+
import Metrics = require("./metrics");
|
|
421
424
|
import PeerStore = require("./peer-store");
|
|
422
425
|
import AddressManager = require("./address-manager");
|
|
423
426
|
type Libp2pModules = {
|
|
@@ -450,7 +453,6 @@ type Libp2pConfig = {
|
|
|
450
453
|
};
|
|
451
454
|
import ConnectionManager = require("./connection-manager");
|
|
452
455
|
import AutoDialler = require("./connection-manager/auto-dialler");
|
|
453
|
-
import Metrics = require("./metrics");
|
|
454
456
|
import Keychain = require("./keychain");
|
|
455
457
|
import Upgrader = require("./upgrader");
|
|
456
458
|
import TransportManager = require("./transport-manager");
|
|
@@ -482,6 +484,9 @@ type Pubsub = import('libp2p-interfaces/src/pubsub');
|
|
|
482
484
|
type PubsubOptions = import('libp2p-interfaces/src/pubsub').PubsubOptions;
|
|
483
485
|
type Datastore = import('interface-datastore').Datastore;
|
|
484
486
|
type Protector = import('./pnet');
|
|
487
|
+
type PersistentPeerStoreOptions = {
|
|
488
|
+
threshold?: number | undefined;
|
|
489
|
+
};
|
|
485
490
|
type DhtOptions = {
|
|
486
491
|
enabled?: boolean | undefined;
|
|
487
492
|
kBucketSize?: number | undefined;
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.js"],"names":[],"mappings":";AAqCA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.js"],"names":[],"mappings":"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"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export = Stats;
|
|
2
2
|
/**
|
|
3
3
|
* @typedef {import('@vascosantos/moving-average').IMovingAverage} IMovingAverage
|
|
4
|
+
* @typedef {import('bignumber.js').BigNumber} Big
|
|
4
5
|
*/
|
|
5
6
|
declare class Stats extends EventEmitter {
|
|
6
7
|
/**
|
|
@@ -130,8 +131,9 @@ declare class Stats extends EventEmitter {
|
|
|
130
131
|
private _applyOp;
|
|
131
132
|
}
|
|
132
133
|
declare namespace Stats {
|
|
133
|
-
export { IMovingAverage };
|
|
134
|
+
export { IMovingAverage, Big };
|
|
134
135
|
}
|
|
135
136
|
import { EventEmitter } from "events";
|
|
136
137
|
type IMovingAverage = import('@vascosantos/moving-average').IMovingAverage;
|
|
138
|
+
type Big = import('bignumber.js').BigNumber;
|
|
137
139
|
//# sourceMappingURL=stats.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stats.d.ts","sourceRoot":"","sources":["../../../src/metrics/stats.js"],"names":[],"mappings":";AAQA
|
|
1
|
+
{"version":3,"file":"stats.d.ts","sourceRoot":"","sources":["../../../src/metrics/stats.js"],"names":[],"mappings":";AAQA;;;GAGG;AAEH;IACE;;;;;;OAMG;IACH,6BAHW,MAAM,EAAE,WACR,GAAG,EAkCb;IA7BC,cAAuB;IACvB,cAAgB;IAEhB,mDAAmD;IACnD;sBAD2B,GAAG;kBAAY,GAAG;MAI5C;IAED,2BAAoC;IACpC,2BAAgC;IAEhC,6EAA6E;IAC7E;sBAD2B,cAAc,EAAE;kBAAY,cAAc,EAAE;MAC9C;IAwH3B;;;;;;;;;;OAUG;IACH,gBAaC;IA9HD;;;;;;OAMG;IACH,SAFa,IAAI,CAMhB;IAED;;;;;OAKG;IACH,QAFa,IAAI,CAOhB;IAFG,cAAoB;IAIxB;;OAEG;IACH;sBAzD6B,GAAG;kBAAY,GAAG;MA2D9C;IAED;;OAEG;IACH;sBAvD6B,cAAc,EAAE;kBAAY,cAAc,EAAE;MAyDxE;IAED;;;;OAIG;IACH,cAkBC;IAED;;;;;;;OAOG;IACH,cAJW,MAAM,OACN,MAAM,GACJ,IAAI,CAKhB;IAED;;;;;OAKG;IACH,6BAEC;IAED;;;;;;OAMG;IACH,qBAKC;IA4BD;;;;;;;;OAQG;IACH,yBAQC;IAED;;;;;;;;;OASG;IACH,4BAsBC;IAED;;;;;;;;OAQG;IACH,iBAqBC;CACF;;;;;sBAlQY,OAAO,6BAA6B,EAAE,cAAc;WACpD,OAAO,cAAc,EAAE,SAAS"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tracked-map.d.ts","sourceRoot":"","sources":["../../../src/metrics/tracked-map.js"],"names":[],"mappings":"AAwDiB,2CALN,MAAM,QACN,MAAM,gDAehB"}
|
|
@@ -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":";AA6BA;;;;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,CA+B5D;IAED;;;;;;;;OAQG;IACH,qBANW,UAAU;;;oBAIR,cAAc;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,SAAS,EAAE,CAAA;KAAE,CAAC,CAwBlE;CACF;;;;yBA1IY,OAAO,0CAA0C,EAAE,WAAW;;;;;;;;;;;;;;;;;;;cAF9D,OAAO,SAAS,CAAC;iBACjB,OAAO,WAAW,EAAE,SAAS"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "libp2p",
|
|
3
|
-
"version": "0.35.
|
|
3
|
+
"version": "0.35.8",
|
|
4
4
|
"description": "JavaScript implementation of libp2p, a modular peer to peer network stack",
|
|
5
5
|
"leadMaintainer": "Jacob Heun <jacobheun@gmail.com>",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -152,7 +152,7 @@
|
|
|
152
152
|
"libp2p-bootstrap": "^0.14.0",
|
|
153
153
|
"libp2p-delegated-content-routing": "^0.11.0",
|
|
154
154
|
"libp2p-delegated-peer-routing": "^0.11.1",
|
|
155
|
-
"libp2p-floodsub": "^0.
|
|
155
|
+
"libp2p-floodsub": "^0.28.0",
|
|
156
156
|
"libp2p-gossipsub": "^0.12.1",
|
|
157
157
|
"libp2p-interfaces-compliance-tests": "^2.0.1",
|
|
158
158
|
"libp2p-interop": "^0.5.0",
|
|
@@ -182,33 +182,34 @@
|
|
|
182
182
|
"Maciej Krüger <mkg20001@gmail.com>",
|
|
183
183
|
"Hugo Dias <mail@hugodias.me>",
|
|
184
184
|
"dirkmc <dirkmdev@gmail.com>",
|
|
185
|
-
"Chris Dostert <chrisdostert@users.noreply.github.com>",
|
|
186
185
|
"Volker Mische <volker.mische@gmail.com>",
|
|
186
|
+
"Chris Dostert <chrisdostert@users.noreply.github.com>",
|
|
187
|
+
"zeim839 <50573884+zeim839@users.noreply.github.com>",
|
|
187
188
|
"Robert Kiel <robert.kiel@hoprnet.org>",
|
|
188
189
|
"Richard Littauer <richard.littauer@gmail.com>",
|
|
189
|
-
"zeim839 <50573884+zeim839@users.noreply.github.com>",
|
|
190
190
|
"a1300 <matthias-knopp@gmx.net>",
|
|
191
191
|
"Ryan Bell <ryan@piing.net>",
|
|
192
192
|
"ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ <victorbjelkholm@gmail.com>",
|
|
193
193
|
"Andrew Nesbitt <andrewnez@gmail.com>",
|
|
194
194
|
"Franck Royer <franck@royer.one>",
|
|
195
195
|
"Thomas Eizinger <thomas@eizinger.io>",
|
|
196
|
+
"Vít Habada <vithabada93@gmail.com>",
|
|
196
197
|
"Giovanni T. Parra <fiatjaf@gmail.com>",
|
|
197
198
|
"acolytec3 <17355484+acolytec3@users.noreply.github.com>",
|
|
198
199
|
"Alan Smithee <ggnore.alan.smithee@gmail.com>",
|
|
199
200
|
"Elven <mon.samuel@qq.com>",
|
|
200
201
|
"Samlior <samlior@foxmail.com>",
|
|
201
202
|
"Didrik Nordström <didrik.nordstrom@gmail.com>",
|
|
202
|
-
"
|
|
203
|
-
"Sönke Hahn <soenkehahn@gmail.com>",
|
|
203
|
+
"Aditya Bose <13054902+adbose@users.noreply.github.com>",
|
|
204
204
|
"TJKoury <TJKoury@gmail.com>",
|
|
205
205
|
"TheStarBoys <41286328+TheStarBoys@users.noreply.github.com>",
|
|
206
206
|
"Tiago Alves <alvesjtiago@gmail.com>",
|
|
207
|
+
"Tim Daubenschütz <tim@daubenschuetz.de>",
|
|
207
208
|
"XiaoZhang <zxinmyth@gmail.com>",
|
|
208
209
|
"Yusef Napora <yusef@napora.org>",
|
|
209
210
|
"Zane Starr <zcstarr@gmail.com>",
|
|
210
211
|
"ebinks <elizabethjbinks@gmail.com>",
|
|
211
|
-
"
|
|
212
|
+
"greenSnot <greenSnot@users.noreply.github.com>",
|
|
212
213
|
"isan_rivkin <isanrivkin@gmail.com>",
|
|
213
214
|
"mayerwin <mayerwin@users.noreply.github.com>",
|
|
214
215
|
"mcclure <andi.m.mcclure@gmail.com>",
|
|
@@ -217,7 +218,8 @@
|
|
|
217
218
|
"robertkiel <robert.kiel@validitylabs.org>",
|
|
218
219
|
"shresthagrawal <34920931+shresthagrawal@users.noreply.github.com>",
|
|
219
220
|
"swedneck <40505480+swedneck@users.noreply.github.com>",
|
|
220
|
-
"
|
|
221
|
+
"tuyennhv <vutuyen2636@gmail.com>",
|
|
222
|
+
"Sönke Hahn <soenkehahn@gmail.com>",
|
|
221
223
|
"Aleksei <vozhdb@gmail.com>",
|
|
222
224
|
"Bernd Strehl <bernd.strehl@gmail.com>",
|
|
223
225
|
"Chris Bratlien <chrisbratlien@gmail.com>",
|
|
@@ -248,6 +250,7 @@
|
|
|
248
250
|
"Nuno Nogueira <nunofmn@gmail.com>",
|
|
249
251
|
"Philipp Muens <raute1337@gmx.de>",
|
|
250
252
|
"RasmusErik Voel Jensen <github@solsort.com>",
|
|
251
|
-
"Smite Chow <xiaopengyou@live.com>"
|
|
253
|
+
"Smite Chow <xiaopengyou@live.com>",
|
|
254
|
+
"Soeren <nikorpoulsen@gmail.com>"
|
|
252
255
|
]
|
|
253
256
|
}
|
|
@@ -12,7 +12,7 @@ const LatencyMonitor = require('./latency-monitor')
|
|
|
12
12
|
const retimer = require('retimer')
|
|
13
13
|
|
|
14
14
|
const { EventEmitter } = require('events')
|
|
15
|
-
|
|
15
|
+
const trackedMap = require('../metrics/tracked-map')
|
|
16
16
|
const PeerId = require('peer-id')
|
|
17
17
|
|
|
18
18
|
const {
|
|
@@ -34,7 +34,7 @@ const defaultOptions = {
|
|
|
34
34
|
|
|
35
35
|
const METRICS_COMPONENT = 'connection-manager'
|
|
36
36
|
const METRICS_PEER_CONNECTIONS = 'peer-connections'
|
|
37
|
-
const
|
|
37
|
+
const METRICS_PEER_VALUES = 'peer-values'
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
40
|
* @typedef {import('../')} Libp2p
|
|
@@ -87,14 +87,14 @@ class ConnectionManager extends EventEmitter {
|
|
|
87
87
|
*
|
|
88
88
|
* @type {Map<string, number>}
|
|
89
89
|
*/
|
|
90
|
-
this._peerValues =
|
|
90
|
+
this._peerValues = trackedMap(METRICS_COMPONENT, METRICS_PEER_VALUES, this._libp2p.metrics)
|
|
91
91
|
|
|
92
92
|
/**
|
|
93
93
|
* Map of connections per peer
|
|
94
94
|
*
|
|
95
95
|
* @type {Map<string, Connection[]>}
|
|
96
96
|
*/
|
|
97
|
-
this.connections =
|
|
97
|
+
this.connections = trackedMap(METRICS_COMPONENT, METRICS_PEER_CONNECTIONS, this._libp2p.metrics)
|
|
98
98
|
|
|
99
99
|
this._started = false
|
|
100
100
|
this._timer = null
|
|
@@ -164,8 +164,6 @@ class ConnectionManager extends EventEmitter {
|
|
|
164
164
|
|
|
165
165
|
await Promise.all(tasks)
|
|
166
166
|
this.connections.clear()
|
|
167
|
-
this._libp2p.metrics && this._libp2p.metrics.updateComponentMetric(METRICS_COMPONENT, METRICS_PEER_CONNECTIONS, 0)
|
|
168
|
-
this._libp2p.metrics && this._libp2p.metrics.updateComponentMetric(METRICS_COMPONENT, METRICS_ALL_CONNECTIONS, 0)
|
|
169
167
|
}
|
|
170
168
|
|
|
171
169
|
/**
|
|
@@ -222,8 +220,6 @@ class ConnectionManager extends EventEmitter {
|
|
|
222
220
|
storedConn.push(connection)
|
|
223
221
|
} else {
|
|
224
222
|
this.connections.set(peerIdStr, [connection])
|
|
225
|
-
this._libp2p.metrics && this._libp2p.metrics.updateComponentMetric(METRICS_COMPONENT, METRICS_PEER_CONNECTIONS, this.connections.size)
|
|
226
|
-
this._libp2p.metrics && this._libp2p.metrics.updateComponentMetric(METRICS_COMPONENT, METRICS_ALL_CONNECTIONS, this.size)
|
|
227
223
|
}
|
|
228
224
|
|
|
229
225
|
this._libp2p.peerStore.keyBook.set(peerId, peerId.pubKey)
|
|
@@ -255,9 +251,6 @@ class ConnectionManager extends EventEmitter {
|
|
|
255
251
|
|
|
256
252
|
this._libp2p.metrics && this._libp2p.metrics.onPeerDisconnected(connection.remotePeer)
|
|
257
253
|
}
|
|
258
|
-
|
|
259
|
-
this._libp2p.metrics && this._libp2p.metrics.updateComponentMetric(METRICS_COMPONENT, METRICS_PEER_CONNECTIONS, this.connections.size)
|
|
260
|
-
this._libp2p.metrics && this._libp2p.metrics.updateComponentMetric(METRICS_COMPONENT, METRICS_ALL_CONNECTIONS, this.size)
|
|
261
254
|
}
|
|
262
255
|
|
|
263
256
|
/**
|
|
@@ -27,12 +27,8 @@ class DHTPeerRouting {
|
|
|
27
27
|
*/
|
|
28
28
|
async findPeer (peerId, options = {}) {
|
|
29
29
|
for await (const event of this._dht.findPeer(peerId, options)) {
|
|
30
|
-
if (event.name === '
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (peer) {
|
|
34
|
-
return peer
|
|
35
|
-
}
|
|
30
|
+
if (event.name === 'FINAL_PEER') {
|
|
31
|
+
return event.peer
|
|
36
32
|
}
|
|
37
33
|
}
|
|
38
34
|
|
package/src/dialer/index.js
CHANGED
|
@@ -9,11 +9,12 @@ const { Multiaddr } = require('multiaddr')
|
|
|
9
9
|
const { TimeoutController } = require('timeout-abort-controller')
|
|
10
10
|
const { AbortError } = require('abortable-iterator')
|
|
11
11
|
const { anySignal } = require('any-signal')
|
|
12
|
-
|
|
12
|
+
// @ts-expect-error setMaxListeners is missing from the types
|
|
13
|
+
const { setMaxListeners } = require('events')
|
|
13
14
|
const DialRequest = require('./dial-request')
|
|
14
15
|
const { publicAddressesFirst } = require('libp2p-utils/src/address-sort')
|
|
15
16
|
const getPeer = require('../get-peer')
|
|
16
|
-
|
|
17
|
+
const trackedMap = require('../metrics/tracked-map')
|
|
17
18
|
const { codes } = require('../errors')
|
|
18
19
|
const {
|
|
19
20
|
DIAL_TIMEOUT,
|
|
@@ -24,7 +25,7 @@ const {
|
|
|
24
25
|
|
|
25
26
|
const METRICS_COMPONENT = 'dialler'
|
|
26
27
|
const METRICS_PENDING_DIALS = 'pending-dials'
|
|
27
|
-
const METRICS_PENDING_DIAL_TARGETS = 'pending-
|
|
28
|
+
const METRICS_PENDING_DIAL_TARGETS = 'pending-dial-targets'
|
|
28
29
|
|
|
29
30
|
/**
|
|
30
31
|
* @typedef {import('libp2p-interfaces/src/connection').Connection} Connection
|
|
@@ -55,8 +56,8 @@ const METRICS_PENDING_DIAL_TARGETS = 'pending-dials-targers'
|
|
|
55
56
|
* @property {Multiaddr[]} addrs
|
|
56
57
|
*
|
|
57
58
|
* @typedef PendingDial
|
|
58
|
-
* @property {
|
|
59
|
-
* @property {TimeoutController} controller
|
|
59
|
+
* @property {import('./dial-request')} dialRequest
|
|
60
|
+
* @property {import('timeout-abort-controller').TimeoutController} controller
|
|
60
61
|
* @property {Promise<Connection>} promise
|
|
61
62
|
* @property {function():void} destroy
|
|
62
63
|
*/
|
|
@@ -85,9 +86,12 @@ class Dialer {
|
|
|
85
86
|
this.timeout = dialTimeout
|
|
86
87
|
this.maxDialsPerPeer = maxDialsPerPeer
|
|
87
88
|
this.tokens = [...new Array(maxParallelDials)].map((_, index) => index)
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
this.
|
|
89
|
+
|
|
90
|
+
/** @type {Map<string, PendingDial>} */
|
|
91
|
+
this._pendingDials = trackedMap(METRICS_COMPONENT, METRICS_PENDING_DIALS, metrics)
|
|
92
|
+
|
|
93
|
+
/** @type {Map<string, { resolve: (value: any) => void, reject: (err: Error) => void}>} */
|
|
94
|
+
this._pendingDialTargets = trackedMap(METRICS_COMPONENT, METRICS_PENDING_DIAL_TARGETS, metrics)
|
|
91
95
|
|
|
92
96
|
for (const [key, value] of Object.entries(resolvers)) {
|
|
93
97
|
Multiaddr.resolvers.set(key, value)
|
|
@@ -111,9 +115,6 @@ class Dialer {
|
|
|
111
115
|
pendingTarget.reject(new AbortError('Dialer was destroyed'))
|
|
112
116
|
}
|
|
113
117
|
this._pendingDialTargets.clear()
|
|
114
|
-
|
|
115
|
-
this._metrics && this._metrics.updateComponentMetric(METRICS_COMPONENT, METRICS_PENDING_DIALS, 0)
|
|
116
|
-
this._metrics && this._metrics.updateComponentMetric(METRICS_COMPONENT, METRICS_PENDING_DIAL_TARGETS, 0)
|
|
117
118
|
}
|
|
118
119
|
|
|
119
120
|
/**
|
|
@@ -163,7 +164,6 @@ class Dialer {
|
|
|
163
164
|
const id = `${(parseInt(String(Math.random() * 1e9), 10)).toString() + Date.now()}`
|
|
164
165
|
const cancellablePromise = new Promise((resolve, reject) => {
|
|
165
166
|
this._pendingDialTargets.set(id, { resolve, reject })
|
|
166
|
-
this._metrics && this._metrics.updateComponentMetric(METRICS_COMPONENT, METRICS_PENDING_DIAL_TARGETS, this._pendingDialTargets.size)
|
|
167
167
|
})
|
|
168
168
|
|
|
169
169
|
try {
|
|
@@ -175,7 +175,6 @@ class Dialer {
|
|
|
175
175
|
return dialTarget
|
|
176
176
|
} finally {
|
|
177
177
|
this._pendingDialTargets.delete(id)
|
|
178
|
-
this._metrics && this._metrics.updateComponentMetric(METRICS_COMPONENT, METRICS_PENDING_DIAL_TARGETS, this._pendingDialTargets.size)
|
|
179
178
|
}
|
|
180
179
|
}
|
|
181
180
|
|
|
@@ -253,10 +252,15 @@ class Dialer {
|
|
|
253
252
|
|
|
254
253
|
// Combine the timeout signal and options.signal, if provided
|
|
255
254
|
const timeoutController = new TimeoutController(this.timeout)
|
|
255
|
+
|
|
256
256
|
const signals = [timeoutController.signal]
|
|
257
257
|
options.signal && signals.push(options.signal)
|
|
258
258
|
const signal = anySignal(signals)
|
|
259
259
|
|
|
260
|
+
// this signal will potentially be used while dialing lots of
|
|
261
|
+
// peers so prevent MaxListenersExceededWarning appearing in the console
|
|
262
|
+
setMaxListeners && setMaxListeners(Infinity, signal)
|
|
263
|
+
|
|
260
264
|
const pendingDial = {
|
|
261
265
|
dialRequest,
|
|
262
266
|
controller: timeoutController,
|
|
@@ -264,13 +268,10 @@ class Dialer {
|
|
|
264
268
|
destroy: () => {
|
|
265
269
|
timeoutController.clear()
|
|
266
270
|
this._pendingDials.delete(dialTarget.id)
|
|
267
|
-
this._metrics && this._metrics.updateComponentMetric(METRICS_COMPONENT, METRICS_PENDING_DIALS, this._pendingDials.size)
|
|
268
271
|
}
|
|
269
272
|
}
|
|
270
273
|
this._pendingDials.set(dialTarget.id, pendingDial)
|
|
271
274
|
|
|
272
|
-
this._metrics && this._metrics.updateComponentMetric(METRICS_COMPONENT, METRICS_PENDING_DIALS, this._pendingDials.size)
|
|
273
|
-
|
|
274
275
|
return pendingDial
|
|
275
276
|
}
|
|
276
277
|
|
package/src/index.js
CHANGED
|
@@ -48,6 +48,8 @@ const { updateSelfPeerRecord } = require('./record/utils')
|
|
|
48
48
|
* @typedef {import('libp2p-interfaces/src/pubsub').PubsubOptions} PubsubOptions
|
|
49
49
|
* @typedef {import('interface-datastore').Datastore} Datastore
|
|
50
50
|
* @typedef {import('./pnet')} Protector
|
|
51
|
+
* @typedef {Object} PersistentPeerStoreOptions
|
|
52
|
+
* @property {number} [threshold]
|
|
51
53
|
*/
|
|
52
54
|
|
|
53
55
|
/**
|
|
@@ -110,7 +112,7 @@ const { updateSelfPeerRecord } = require('./record/utils')
|
|
|
110
112
|
* @property {KeychainOptions & import('./keychain/index').KeychainOptions} [keychain]
|
|
111
113
|
* @property {MetricsOptions & import('./metrics').MetricsOptions} [metrics]
|
|
112
114
|
* @property {import('./peer-routing').PeerRoutingOptions} [peerRouting]
|
|
113
|
-
* @property {PeerStoreOptions &
|
|
115
|
+
* @property {PeerStoreOptions & PersistentPeerStoreOptions} [peerStore]
|
|
114
116
|
* @property {import('./transport-manager').TransportManagerOptions} [transportManager]
|
|
115
117
|
* @property {Libp2pConfig} [config]
|
|
116
118
|
*
|
|
@@ -161,6 +163,15 @@ class Libp2p extends EventEmitter {
|
|
|
161
163
|
this.peerId = this._options.peerId
|
|
162
164
|
this.datastore = this._options.datastore
|
|
163
165
|
|
|
166
|
+
// Create Metrics
|
|
167
|
+
if (this._options.metrics.enabled) {
|
|
168
|
+
const metrics = new Metrics({
|
|
169
|
+
...this._options.metrics
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
this.metrics = metrics
|
|
173
|
+
}
|
|
174
|
+
|
|
164
175
|
this.peerStore = (this.datastore && this._options.peerStore.persistence)
|
|
165
176
|
? new PersistentPeerStore({
|
|
166
177
|
peerId: this.peerId,
|
|
@@ -195,15 +206,6 @@ class Libp2p extends EventEmitter {
|
|
|
195
206
|
autoDialInterval: this._options.connectionManager.autoDialInterval
|
|
196
207
|
})
|
|
197
208
|
|
|
198
|
-
// Create Metrics
|
|
199
|
-
if (this._options.metrics.enabled) {
|
|
200
|
-
const metrics = new Metrics({
|
|
201
|
-
...this._options.metrics
|
|
202
|
-
})
|
|
203
|
-
|
|
204
|
-
this.metrics = metrics
|
|
205
|
-
}
|
|
206
|
-
|
|
207
209
|
// Create keychain
|
|
208
210
|
if (this._options.keychain && this._options.keychain.datastore) {
|
|
209
211
|
log('creating keychain')
|
package/src/metrics/stats.js
CHANGED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @template K
|
|
5
|
+
* @template V
|
|
6
|
+
*/
|
|
7
|
+
class TrackedMap extends Map {
|
|
8
|
+
/**
|
|
9
|
+
* @param {string} component
|
|
10
|
+
* @param {string} name
|
|
11
|
+
* @param {import('.')} metrics
|
|
12
|
+
*/
|
|
13
|
+
constructor (component, name, metrics) {
|
|
14
|
+
super()
|
|
15
|
+
|
|
16
|
+
this._component = component
|
|
17
|
+
this._name = name
|
|
18
|
+
this._metrics = metrics
|
|
19
|
+
|
|
20
|
+
this._metrics.updateComponentMetric(this._component, this._name, this.size)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @param {K} key
|
|
25
|
+
* @param {V} value
|
|
26
|
+
*/
|
|
27
|
+
set (key, value) {
|
|
28
|
+
super.set(key, value)
|
|
29
|
+
this._metrics.updateComponentMetric(this._component, this._name, this.size)
|
|
30
|
+
return this
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @param {K} key
|
|
35
|
+
*/
|
|
36
|
+
delete (key) {
|
|
37
|
+
const deleted = super.delete(key)
|
|
38
|
+
this._metrics.updateComponentMetric(this._component, this._name, this.size)
|
|
39
|
+
return deleted
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
clear () {
|
|
43
|
+
super.clear()
|
|
44
|
+
|
|
45
|
+
this._metrics.updateComponentMetric(this._component, this._name, this.size)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @template K
|
|
51
|
+
* @template V
|
|
52
|
+
* @param {string} component
|
|
53
|
+
* @param {string} name
|
|
54
|
+
* @param {import('.')} [metrics]
|
|
55
|
+
* @returns {Map<K, V>}
|
|
56
|
+
*/
|
|
57
|
+
module.exports = (component, name, metrics) => {
|
|
58
|
+
/** @type {Map<K, V>} */
|
|
59
|
+
let map
|
|
60
|
+
|
|
61
|
+
if (metrics) {
|
|
62
|
+
map = new TrackedMap(component, name, metrics)
|
|
63
|
+
} else {
|
|
64
|
+
map = new Map()
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return map
|
|
68
|
+
}
|
package/src/peer-routing.js
CHANGED
|
@@ -24,6 +24,8 @@ const {
|
|
|
24
24
|
// @ts-ignore module with no types
|
|
25
25
|
} = require('set-delayed-interval')
|
|
26
26
|
const { DHTPeerRouting } = require('./dht/dht-peer-routing')
|
|
27
|
+
// @ts-expect-error setMaxListeners is missing from the types
|
|
28
|
+
const { setMaxListeners } = require('events')
|
|
27
29
|
|
|
28
30
|
/**
|
|
29
31
|
* @typedef {import('peer-id')} PeerId
|
|
@@ -149,7 +151,12 @@ class PeerRouting {
|
|
|
149
151
|
}
|
|
150
152
|
|
|
151
153
|
if (options.timeout) {
|
|
152
|
-
|
|
154
|
+
const controller = new TimeoutController(options.timeout)
|
|
155
|
+
// this controller will potentially be used while dialing lots of
|
|
156
|
+
// peers so prevent MaxListenersExceededWarning appearing in the console
|
|
157
|
+
setMaxListeners && setMaxListeners(Infinity, controller.signal)
|
|
158
|
+
|
|
159
|
+
options.signal = controller.signal
|
|
153
160
|
}
|
|
154
161
|
|
|
155
162
|
yield * pipe(
|