libp2p 0.35.3 → 0.35.7
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/index.d.ts.map +1 -1
- package/dist/src/dialer/index.d.ts +18 -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/index.d.ts +9 -10
- package/dist/src/metrics/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/index.js +10 -3
- package/src/dialer/index.js +23 -7
- package/src/index.js +13 -9
- package/src/metrics/index.js +18 -8
- package/src/metrics/stats.js +1 -0
- package/src/metrics/tracked-map.js +62 -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":"index.d.ts","sourceRoot":"","sources":["../../../src/connection-manager/index.js"],"names":[],"mappings":";
|
|
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"}
|
|
@@ -20,14 +20,15 @@ export = Dialer;
|
|
|
20
20
|
* @property {number} [maxDialsPerPeer = MAX_PER_PEER_DIALS] - Number of max concurrent dials per peer.
|
|
21
21
|
* @property {number} [dialTimeout = DIAL_TIMEOUT] - How long a dial attempt is allowed to take.
|
|
22
22
|
* @property {Record<string, Resolver>} [resolvers = {}] - multiaddr resolvers to use when dialing
|
|
23
|
+
* @property {import('../metrics')} [metrics]
|
|
23
24
|
*
|
|
24
25
|
* @typedef DialTarget
|
|
25
26
|
* @property {string} id
|
|
26
27
|
* @property {Multiaddr[]} addrs
|
|
27
28
|
*
|
|
28
29
|
* @typedef PendingDial
|
|
29
|
-
* @property {
|
|
30
|
-
* @property {TimeoutController} controller
|
|
30
|
+
* @property {import('./dial-request')} dialRequest
|
|
31
|
+
* @property {import('timeout-abort-controller').TimeoutController} controller
|
|
31
32
|
* @property {Promise<Connection>} promise
|
|
32
33
|
* @property {function():void} destroy
|
|
33
34
|
*/
|
|
@@ -36,7 +37,7 @@ declare class Dialer {
|
|
|
36
37
|
* @class
|
|
37
38
|
* @param {DialerProperties & DialerOptions} options
|
|
38
39
|
*/
|
|
39
|
-
constructor({ transportManager, peerStore, addressSorter, maxParallelDials, maxAddrsToDial, dialTimeout, maxDialsPerPeer, resolvers }: DialerProperties & DialerOptions);
|
|
40
|
+
constructor({ transportManager, peerStore, addressSorter, maxParallelDials, maxAddrsToDial, dialTimeout, maxDialsPerPeer, resolvers, metrics }: DialerProperties & DialerOptions);
|
|
40
41
|
transportManager: import("../transport-manager");
|
|
41
42
|
peerStore: import("../peer-store");
|
|
42
43
|
addressSorter: (addresses: Address[]) => Address[];
|
|
@@ -45,8 +46,13 @@ declare class Dialer {
|
|
|
45
46
|
timeout: number;
|
|
46
47
|
maxDialsPerPeer: number;
|
|
47
48
|
tokens: number[];
|
|
48
|
-
|
|
49
|
-
|
|
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
|
+
}>;
|
|
50
56
|
/**
|
|
51
57
|
* Clears any pending dials
|
|
52
58
|
*/
|
|
@@ -120,6 +126,12 @@ declare class Dialer {
|
|
|
120
126
|
declare namespace Dialer {
|
|
121
127
|
export { Connection, PeerId, PeerStore, Address, TransportManager, DialerProperties, Resolver, DialerOptions, DialTarget, PendingDial };
|
|
122
128
|
}
|
|
129
|
+
type PendingDial = {
|
|
130
|
+
dialRequest: import('./dial-request');
|
|
131
|
+
controller: import('timeout-abort-controller').TimeoutController;
|
|
132
|
+
promise: Promise<Connection>;
|
|
133
|
+
destroy: () => void;
|
|
134
|
+
};
|
|
123
135
|
type PeerId = import('peer-id');
|
|
124
136
|
import { Multiaddr } from "multiaddr";
|
|
125
137
|
type Connection = import("libp2p-interfaces/src/connection/connection");
|
|
@@ -156,15 +168,10 @@ type DialerOptions = {
|
|
|
156
168
|
* - multiaddr resolvers to use when dialing
|
|
157
169
|
*/
|
|
158
170
|
resolvers?: Record<string, Resolver> | undefined;
|
|
171
|
+
metrics?: import("../metrics") | undefined;
|
|
159
172
|
};
|
|
160
173
|
type PeerStore = import('../peer-store');
|
|
161
174
|
type Address = import('../peer-store/address-book').Address;
|
|
162
175
|
type TransportManager = import('../transport-manager');
|
|
163
176
|
type Resolver = (addr: Multiaddr) => Promise<string[]>;
|
|
164
|
-
type PendingDial = {
|
|
165
|
-
dialRequest: DialRequest;
|
|
166
|
-
controller: TimeoutController;
|
|
167
|
-
promise: Promise<Connection>;
|
|
168
|
-
destroy: () => void;
|
|
169
|
-
};
|
|
170
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,2BAsCC;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;;;;;iBA5Ra,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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"}
|
|
@@ -4,9 +4,6 @@ export = Metrics;
|
|
|
4
4
|
* @typedef {import('libp2p-interfaces/src/transport/types').MultiaddrConnection} MultiaddrConnection
|
|
5
5
|
*/
|
|
6
6
|
/**
|
|
7
|
-
* @typedef MetricsProperties
|
|
8
|
-
* @property {import('../connection-manager')} connectionManager
|
|
9
|
-
*
|
|
10
7
|
* @typedef MetricsOptions
|
|
11
8
|
* @property {number} [computeThrottleMaxQueueSize = defaultOptions.computeThrottleMaxQueueSize]
|
|
12
9
|
* @property {number} [computeThrottleTimeout = defaultOptions.computeThrottleTimeout]
|
|
@@ -25,9 +22,9 @@ declare class Metrics {
|
|
|
25
22
|
static mergeStats(target: Stats, other: Stats): Stats;
|
|
26
23
|
/**
|
|
27
24
|
* @class
|
|
28
|
-
* @param {
|
|
25
|
+
* @param {MetricsOptions} options
|
|
29
26
|
*/
|
|
30
|
-
constructor(options:
|
|
27
|
+
constructor(options: MetricsOptions);
|
|
31
28
|
_options: any;
|
|
32
29
|
_globalStats: Stats;
|
|
33
30
|
_peerStats: Map<any, any>;
|
|
@@ -48,7 +45,7 @@ declare class Metrics {
|
|
|
48
45
|
* @returns {void}
|
|
49
46
|
*/
|
|
50
47
|
private _onMessage;
|
|
51
|
-
|
|
48
|
+
_componentMetrics: Map<any, any>;
|
|
52
49
|
/**
|
|
53
50
|
* Must be called for stats to saved. Any data pushed for tracking
|
|
54
51
|
* will be ignored.
|
|
@@ -71,6 +68,11 @@ declare class Metrics {
|
|
|
71
68
|
* @returns {string[]}
|
|
72
69
|
*/
|
|
73
70
|
get peers(): string[];
|
|
71
|
+
/**
|
|
72
|
+
* @returns {Map}
|
|
73
|
+
*/
|
|
74
|
+
getComponentMetrics(): Map<any, any>;
|
|
75
|
+
updateComponentMetric(component: any, metric: any, value: any): void;
|
|
74
76
|
/**
|
|
75
77
|
* Returns the `Stats` object for the given `PeerId` whether it
|
|
76
78
|
* is a live peer, or in the disconnected peer LRU cache.
|
|
@@ -130,14 +132,11 @@ declare class Metrics {
|
|
|
130
132
|
}): MultiaddrConnection;
|
|
131
133
|
}
|
|
132
134
|
declare namespace Metrics {
|
|
133
|
-
export { PeerId, MultiaddrConnection,
|
|
135
|
+
export { PeerId, MultiaddrConnection, MetricsOptions };
|
|
134
136
|
}
|
|
135
137
|
import Stats = require("./stats");
|
|
136
138
|
type PeerId = import('peer-id');
|
|
137
139
|
type MultiaddrConnection = import('libp2p-interfaces/src/transport/types').MultiaddrConnection;
|
|
138
|
-
type MetricsProperties = {
|
|
139
|
-
connectionManager: import('../connection-manager');
|
|
140
|
-
};
|
|
141
140
|
type MetricsOptions = {
|
|
142
141
|
computeThrottleMaxQueueSize?: number | undefined;
|
|
143
142
|
computeThrottleTimeout?: number | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/metrics/index.js"],"names":[],"mappings":";AAoBA;;;GAGG;AAEH
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/metrics/index.js"],"names":[],"mappings":";AAoBA;;;GAGG;AAEH;;;;;;GAMG;AAEH;IAqOE;;;;;;;OAOG;IACH,0BAJW,KAAK,SACL,KAAK,GACH,KAAK,CAWjB;IArPD;;;OAGG;IACH,qBAFW,cAAc,EAWxB;IARC,cAAqD;IACrD,oBAA6D;IAC7D,0BAA2B;IAC3B,8BAA+B;IAC/B,eAA+D;IAC/D,kBAAqB;IA8GvB;;;;;;;;;;;;OAYG;IACH,mBAwBC;IAjJC,iCAAkC;IAGpC;;;OAGG;IACH,cAEC;IAED;;;OAGG;IACH,aASC;IAED;;;;OAIG;IACH,oBAEC;IAED;;;;OAIG;IACH,sBAEC;IAED;;OAEG;IACH,qCAEC;IAED,qEAOC;IAED;;;;;;OAMG;IACH,gBAHW,MAAM,GACJ,KAAK,CAKjB;IAED;;;;OAIG;IACH,0BAEC;IAED;;;;;OAKG;IACH,sBAHW,MAAM,GACJ,KAAK,CAIjB;IAED;;;;;;OAMG;IACH,2BAFW,MAAM,QAUhB;IAyCD;;;;;;;;OAQG;IACH,+BAJW,MAAM,UACN,MAAM,GACJ,IAAI,CAoBhB;IAED;;;;;;;;;;;;OAYG;IACH;QALwC,MAAM,EAAnC,mBAAmB;QACF,UAAU;QACV,QAAQ;QACvB,mBAAmB,CA2B/B;CAoBF;;;;;cAnQY,OAAO,SAAS,CAAC;2BACjB,OAAO,uCAAuC,EAAE,mBAAmB"}
|
|
@@ -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":"AAkDiB,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.7",
|
|
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",
|
|
@@ -181,9 +181,9 @@
|
|
|
181
181
|
"Friedel Ziegelmayer <dignifiedquire@gmail.com>",
|
|
182
182
|
"Maciej Krüger <mkg20001@gmail.com>",
|
|
183
183
|
"Hugo Dias <mail@hugodias.me>",
|
|
184
|
-
"dirkmc <dirkmdev@gmail.com>",
|
|
185
|
-
"Chris Dostert <chrisdostert@users.noreply.github.com>",
|
|
186
184
|
"Volker Mische <volker.mische@gmail.com>",
|
|
185
|
+
"Chris Dostert <chrisdostert@users.noreply.github.com>",
|
|
186
|
+
"dirkmc <dirkmdev@gmail.com>",
|
|
187
187
|
"Robert Kiel <robert.kiel@hoprnet.org>",
|
|
188
188
|
"Richard Littauer <richard.littauer@gmail.com>",
|
|
189
189
|
"zeim839 <50573884+zeim839@users.noreply.github.com>",
|
|
@@ -193,22 +193,23 @@
|
|
|
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 {
|
|
@@ -32,6 +32,10 @@ const defaultOptions = {
|
|
|
32
32
|
defaultPeerValue: 1
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
const METRICS_COMPONENT = 'connection-manager'
|
|
36
|
+
const METRICS_PEER_CONNECTIONS = 'peer-connections'
|
|
37
|
+
const METRICS_PEER_VALUES = 'peer-values'
|
|
38
|
+
|
|
35
39
|
/**
|
|
36
40
|
* @typedef {import('../')} Libp2p
|
|
37
41
|
* @typedef {import('libp2p-interfaces/src/connection').Connection} Connection
|
|
@@ -83,14 +87,14 @@ class ConnectionManager extends EventEmitter {
|
|
|
83
87
|
*
|
|
84
88
|
* @type {Map<string, number>}
|
|
85
89
|
*/
|
|
86
|
-
this._peerValues =
|
|
90
|
+
this._peerValues = trackedMap(METRICS_COMPONENT, METRICS_PEER_VALUES, this._libp2p.metrics)
|
|
87
91
|
|
|
88
92
|
/**
|
|
89
93
|
* Map of connections per peer
|
|
90
94
|
*
|
|
91
95
|
* @type {Map<string, Connection[]>}
|
|
92
96
|
*/
|
|
93
|
-
this.connections =
|
|
97
|
+
this.connections = trackedMap(METRICS_COMPONENT, METRICS_PEER_CONNECTIONS, this._libp2p.metrics)
|
|
94
98
|
|
|
95
99
|
this._started = false
|
|
96
100
|
this._timer = null
|
|
@@ -211,6 +215,7 @@ class ConnectionManager extends EventEmitter {
|
|
|
211
215
|
const storedConn = this.connections.get(peerIdStr)
|
|
212
216
|
|
|
213
217
|
this.emit('peer:connect', connection)
|
|
218
|
+
|
|
214
219
|
if (storedConn) {
|
|
215
220
|
storedConn.push(connection)
|
|
216
221
|
} else {
|
|
@@ -243,6 +248,8 @@ class ConnectionManager extends EventEmitter {
|
|
|
243
248
|
this.connections.delete(peerId)
|
|
244
249
|
this._peerValues.delete(connection.remotePeer.toB58String())
|
|
245
250
|
this.emit('peer:disconnect', connection)
|
|
251
|
+
|
|
252
|
+
this._libp2p.metrics && this._libp2p.metrics.onPeerDisconnected(connection.remotePeer)
|
|
246
253
|
}
|
|
247
254
|
}
|
|
248
255
|
|
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,
|
|
@@ -22,6 +23,10 @@ const {
|
|
|
22
23
|
MAX_ADDRS_TO_DIAL
|
|
23
24
|
} = require('../constants')
|
|
24
25
|
|
|
26
|
+
const METRICS_COMPONENT = 'dialler'
|
|
27
|
+
const METRICS_PENDING_DIALS = 'pending-dials'
|
|
28
|
+
const METRICS_PENDING_DIAL_TARGETS = 'pending-dial-targets'
|
|
29
|
+
|
|
25
30
|
/**
|
|
26
31
|
* @typedef {import('libp2p-interfaces/src/connection').Connection} Connection
|
|
27
32
|
* @typedef {import('peer-id')} PeerId
|
|
@@ -44,14 +49,15 @@ const {
|
|
|
44
49
|
* @property {number} [maxDialsPerPeer = MAX_PER_PEER_DIALS] - Number of max concurrent dials per peer.
|
|
45
50
|
* @property {number} [dialTimeout = DIAL_TIMEOUT] - How long a dial attempt is allowed to take.
|
|
46
51
|
* @property {Record<string, Resolver>} [resolvers = {}] - multiaddr resolvers to use when dialing
|
|
52
|
+
* @property {import('../metrics')} [metrics]
|
|
47
53
|
*
|
|
48
54
|
* @typedef DialTarget
|
|
49
55
|
* @property {string} id
|
|
50
56
|
* @property {Multiaddr[]} addrs
|
|
51
57
|
*
|
|
52
58
|
* @typedef PendingDial
|
|
53
|
-
* @property {
|
|
54
|
-
* @property {TimeoutController} controller
|
|
59
|
+
* @property {import('./dial-request')} dialRequest
|
|
60
|
+
* @property {import('timeout-abort-controller').TimeoutController} controller
|
|
55
61
|
* @property {Promise<Connection>} promise
|
|
56
62
|
* @property {function():void} destroy
|
|
57
63
|
*/
|
|
@@ -69,7 +75,8 @@ class Dialer {
|
|
|
69
75
|
maxAddrsToDial = MAX_ADDRS_TO_DIAL,
|
|
70
76
|
dialTimeout = DIAL_TIMEOUT,
|
|
71
77
|
maxDialsPerPeer = MAX_PER_PEER_DIALS,
|
|
72
|
-
resolvers = {}
|
|
78
|
+
resolvers = {},
|
|
79
|
+
metrics
|
|
73
80
|
}) {
|
|
74
81
|
this.transportManager = transportManager
|
|
75
82
|
this.peerStore = peerStore
|
|
@@ -79,8 +86,12 @@ class Dialer {
|
|
|
79
86
|
this.timeout = dialTimeout
|
|
80
87
|
this.maxDialsPerPeer = maxDialsPerPeer
|
|
81
88
|
this.tokens = [...new Array(maxParallelDials)].map((_, index) => index)
|
|
82
|
-
|
|
83
|
-
|
|
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)
|
|
84
95
|
|
|
85
96
|
for (const [key, value] of Object.entries(resolvers)) {
|
|
86
97
|
Multiaddr.resolvers.set(key, value)
|
|
@@ -241,6 +252,10 @@ class Dialer {
|
|
|
241
252
|
|
|
242
253
|
// Combine the timeout signal and options.signal, if provided
|
|
243
254
|
const timeoutController = new TimeoutController(this.timeout)
|
|
255
|
+
// this controller will potentially be used while dialing lots of
|
|
256
|
+
// peers so prevent MaxListenersExceededWarning appearing in the console
|
|
257
|
+
setMaxListeners && setMaxListeners(Infinity, timeoutController.signal)
|
|
258
|
+
|
|
244
259
|
const signals = [timeoutController.signal]
|
|
245
260
|
options.signal && signals.push(options.signal)
|
|
246
261
|
const signal = anySignal(signals)
|
|
@@ -255,6 +270,7 @@ class Dialer {
|
|
|
255
270
|
}
|
|
256
271
|
}
|
|
257
272
|
this._pendingDials.set(dialTarget.id, pendingDial)
|
|
273
|
+
|
|
258
274
|
return pendingDial
|
|
259
275
|
}
|
|
260
276
|
|
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,14 +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
|
-
this.metrics = new Metrics({
|
|
201
|
-
...this._options.metrics,
|
|
202
|
-
connectionManager: this.connectionManager
|
|
203
|
-
})
|
|
204
|
-
}
|
|
205
|
-
|
|
206
209
|
// Create keychain
|
|
207
210
|
if (this._options.keychain && this._options.keychain.datastore) {
|
|
208
211
|
log('creating keychain')
|
|
@@ -262,6 +265,7 @@ class Libp2p extends EventEmitter {
|
|
|
262
265
|
this.dialer = new Dialer({
|
|
263
266
|
transportManager: this.transportManager,
|
|
264
267
|
peerStore: this.peerStore,
|
|
268
|
+
metrics: this.metrics,
|
|
265
269
|
...this._options.dialer
|
|
266
270
|
})
|
|
267
271
|
|
package/src/metrics/index.js
CHANGED
|
@@ -24,9 +24,6 @@ const directionToEvent = {
|
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
|
-
* @typedef MetricsProperties
|
|
28
|
-
* @property {import('../connection-manager')} connectionManager
|
|
29
|
-
*
|
|
30
27
|
* @typedef MetricsOptions
|
|
31
28
|
* @property {number} [computeThrottleMaxQueueSize = defaultOptions.computeThrottleMaxQueueSize]
|
|
32
29
|
* @property {number} [computeThrottleTimeout = defaultOptions.computeThrottleTimeout]
|
|
@@ -37,7 +34,7 @@ const directionToEvent = {
|
|
|
37
34
|
class Metrics {
|
|
38
35
|
/**
|
|
39
36
|
* @class
|
|
40
|
-
* @param {
|
|
37
|
+
* @param {MetricsOptions} options
|
|
41
38
|
*/
|
|
42
39
|
constructor (options) {
|
|
43
40
|
this._options = mergeOptions(defaultOptions, options)
|
|
@@ -47,10 +44,7 @@ class Metrics {
|
|
|
47
44
|
this._oldPeers = oldPeerLRU(this._options.maxOldPeersRetention)
|
|
48
45
|
this._running = false
|
|
49
46
|
this._onMessage = this._onMessage.bind(this)
|
|
50
|
-
this.
|
|
51
|
-
this._connectionManager.on('peer:disconnect', (connection) => {
|
|
52
|
-
this.onPeerDisconnected(connection.remotePeer)
|
|
53
|
-
})
|
|
47
|
+
this._componentMetrics = new Map()
|
|
54
48
|
}
|
|
55
49
|
|
|
56
50
|
/**
|
|
@@ -94,6 +88,22 @@ class Metrics {
|
|
|
94
88
|
return Array.from(this._peerStats.keys())
|
|
95
89
|
}
|
|
96
90
|
|
|
91
|
+
/**
|
|
92
|
+
* @returns {Map}
|
|
93
|
+
*/
|
|
94
|
+
getComponentMetrics () {
|
|
95
|
+
return this._componentMetrics
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
updateComponentMetric (component, metric, value) {
|
|
99
|
+
if (!this._componentMetrics.has(component)) {
|
|
100
|
+
this._componentMetrics.set(component, new Map())
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const map = this._componentMetrics.get(component)
|
|
104
|
+
map.set(metric, value)
|
|
105
|
+
}
|
|
106
|
+
|
|
97
107
|
/**
|
|
98
108
|
* Returns the `Stats` object for the given `PeerId` whether it
|
|
99
109
|
* is a live peer, or in the disconnected peer LRU cache.
|
package/src/metrics/stats.js
CHANGED
|
@@ -0,0 +1,62 @@
|
|
|
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
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @template K
|
|
45
|
+
* @template V
|
|
46
|
+
* @param {string} component
|
|
47
|
+
* @param {string} name
|
|
48
|
+
* @param {import('.')} [metrics]
|
|
49
|
+
* @returns {Map<K, V>}
|
|
50
|
+
*/
|
|
51
|
+
module.exports = (component, name, metrics) => {
|
|
52
|
+
/** @type {Map<K, V>} */
|
|
53
|
+
let map
|
|
54
|
+
|
|
55
|
+
if (metrics) {
|
|
56
|
+
map = new TrackedMap(component, name, metrics)
|
|
57
|
+
} else {
|
|
58
|
+
map = new Map()
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return map
|
|
62
|
+
}
|
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(
|