libp2p 0.35.2 → 0.35.6

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.
@@ -42,12 +42,6 @@ export function validate(opts: Libp2pOptions): {
42
42
  dht: {
43
43
  enabled: boolean;
44
44
  kBucketSize: number;
45
- randomWalk: {
46
- enabled: boolean;
47
- queriesPerPeriod: number;
48
- interval: number;
49
- timeout: number;
50
- };
51
45
  };
52
46
  nat: {
53
47
  enabled: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.js"],"names":[],"mappings":"AA8G0B,+BAHf,aAAa,GACX;;;;;qCApFmB,SAAS,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAoFd,aAAa,GAAG,kBAAkB,CAS9D;wBAvGY,OAAO,WAAW,EAAE,SAAS;4BAC7B,OAAO,GAAG,EAAE,aAAa;iCACzB,OAAO,GAAG,EAAE,kBAAkB"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.js"],"names":[],"mappings":"AAwG0B,+BAHf,aAAa,GACX;;;;;qCA9EmB,SAAS,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA8Ed,aAAa,GAAG,kBAAkB,CAS9D;wBAjGY,OAAO,WAAW,EAAE,SAAS;4BAC7B,OAAO,GAAG,EAAE,aAAa;iCACzB,OAAO,GAAG,EAAE,kBAAkB"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/connection-manager/index.js"],"names":[],"mappings":";AAkCA;;;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,CAED;IAE5B;;;;OAIG;IACH,aAFU,IAAI,MAAM,EAAE,UAAU,EAAE,CAAC,CAEP;IAE5B,kBAAqB;IACrB,YAAkB;IAoFpB;;;;;OAKG;IACH,sBAcC;IArGC,gCAGE;IAGJ;;OAEG;IACH,mBAGC;IAED;;;OAGG;IACH,cAYC;IA2JD;;;;;OAKG;IACH,0BAEC;IAjKD;;;;OAIG;IACH,sBASC;IAED;;;;OAIG;IACH,wBAWC;IAED;;;;;;;OAOG;IACH,qBAJW,MAAM,SACN,MAAM,GACJ,IAAI,CAOhB;IAwBD;;;;;OAKG;IACH,sBAHW,UAAU,GACR,IAAI,CAqBhB;IAED;;;;;OAKG;IACH,yBAHW,UAAU,GACR,IAAI,CAchB;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;;;;;;;;cA1SY,OAAO,KAAK,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,CAED;IAE5B;;;;OAIG;IACH,aAFU,IAAI,MAAM,EAAE,UAAU,EAAE,CAAC,CAEP;IAE5B,kBAAqB;IACrB,YAAkB;IAsFpB;;;;;OAKG;IACH,sBAcC;IAvGC,gCAGE;IAGJ;;OAEG;IACH,mBAGC;IAED;;;OAGG;IACH,cAYC;IAqKD;;;;;OAKG;IACH,0BAEC;IA3KD;;;;OAIG;IACH,sBASC;IAED;;;;OAIG;IACH,wBAaC;IAED;;;;;;;OAOG;IACH,qBAJW,MAAM,SACN,MAAM,GACJ,IAAI,CAOhB;IAwBD;;;;;OAKG;IACH,sBAHW,UAAU,GACR,IAAI,CAwBhB;IAED;;;;;OAKG;IACH,yBAHW,UAAU,GACR,IAAI,CAmBhB;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;;;;;;;;cApTY,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,6DAUb;IAED;;;OAGG;IACH,qBAHW,UAAU,YACV,GAAG,qFAQb;CACF"}
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,6DAcb;IAED;;;OAGG;IACH,qBAHW,UAAU,YACV,GAAG,qFAQb;CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"dial-request.d.ts","sourceRoot":"","sources":["../../../src/dialer/dial-request.js"],"names":[],"mappings":";AAUA;;;;GAIG;AAEH;;;;;;;;GAQG;AAEH;IACE;;;;;;;;;OASG;IACH,2CAFW,kBAAkB,EAU5B;IAHC,uCAAkB;IAClB,qBAAoB;IACpB,gBAtBc,SAAS,WAAW,WAAW,KAAK,QAAQ,UAAU,CAAC,CAsBzC;IAG9B;;;;;OAKG;IACH;;oBAFa,QAAQ,UAAU,CAAC,CA4C/B;CACF;;;;;;WA3Ea,SAAS,EAAE;oBACP,SAAS,WAAW,WAAW,KAAK,QAAQ,UAAU,CAAC;YAC3D,MAAM;;cAXP,OAAO,IAAI,CAAC;iBACZ,OAAO,WAAW,EAAE,SAAS;;YAK5B,WAAW"}
1
+ {"version":3,"file":"dial-request.d.ts","sourceRoot":"","sources":["../../../src/dialer/dial-request.js"],"names":[],"mappings":";AAWA;;;;GAIG;AAEH;;;;;;;;GAQG;AAEH;IACE;;;;;;;;;OASG;IACH,2CAFW,kBAAkB,EAU5B;IAHC,uCAAkB;IAClB,qBAAoB;IACpB,gBAtBc,SAAS,WAAW,WAAW,KAAK,QAAQ,UAAU,CAAC,CAsBzC;IAG9B;;;;;OAKG;IACH;;oBAFa,QAAQ,UAAU,CAAC,CA4C/B;CACF;;;;;;WA3Ea,SAAS,EAAE;oBACP,SAAS,WAAW,WAAW,KAAK,QAAQ,UAAU,CAAC;YAC3D,MAAM;;cAXP,OAAO,IAAI,CAAC;iBACZ,OAAO,WAAW,EAAE,SAAS;;YAK5B,WAAW"}
@@ -20,6 +20,7 @@ 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
@@ -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[];
@@ -47,6 +48,7 @@ declare class Dialer {
47
48
  tokens: number[];
48
49
  _pendingDials: Map<any, any>;
49
50
  _pendingDialTargets: Map<any, any>;
51
+ _metrics: import("../metrics") | undefined;
50
52
  /**
51
53
  * Clears any pending dials
52
54
  */
@@ -156,6 +158,7 @@ type DialerOptions = {
156
158
  * - multiaddr resolvers to use when dialing
157
159
  */
158
160
  resolvers?: Record<string, Resolver> | undefined;
161
+ metrics?: import("../metrics") | undefined;
159
162
  };
160
163
  type PeerStore = import('../peer-store');
161
164
  type Address = import('../peer-store/address-book').Address;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/dialer/index.js"],"names":[],"mappings":";AAwBA;;;;;;GAMG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH;IACE;;;OAGG;IACH,uIAFW,gBAAgB,GAAG,aAAa,EA0B1C;IAdC,iDAAwC;IACxC,mCAA0B;IAC1B,2BAnCsB,OAAO,EAAE,KAAK,OAAO,EAAE,CAmCX;IAClC,yBAAwC;IACxC,uBAAoC;IACpC,gBAA0B;IAC1B,wBAAsC;IACtC,iBAAuE;IACvE,6BAA8B;IAC9B,mCAAoC;IAOtC;;OAEG;IACH,gBAcC;IAED;;;;;;;;;OASG;IACH,oBALW,MAAM,GAAC,SAAS,GAAC,MAAM;;oB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,GAAC,SAAS,GAAC,MAAM;;oBAGrB,QAAQ,UAAU,CAAC,CAwB/B;IAED;;;;;;;OAOG;IACH,mCAHW,MAAM,GAAC,SAAS,GAAC,MAAM,GACrB,QAAQ,UAAU,CAAC,CAqB/B;IAED;;;;;;;;;OASG;IACH,0BAmCC;IAED;;;;;;;;OAQG;IACH,2BAyCC;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;;;;cA5TY,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;;iBAgBpC,WAAW;gBACX,iBAAiB;aACjB,QAAQ,UAAU,CAAC;mBACR,IAAI"}
@@ -36,5 +36,29 @@ export namespace codes {
36
36
  export const ERR_UNSUPPORTED_PROTOCOL: string;
37
37
  export const ERR_INVALID_MULTIADDR: string;
38
38
  export const ERR_SIGNATURE_NOT_VALID: string;
39
+ export const ERR_FIND_SELF: string;
40
+ export const ERR_NO_ROUTERS_AVAILABLE: string;
41
+ export const ERR_CONNECTION_NOT_MULTIPLEXED: string;
42
+ export const ERR_NO_DIAL_TOKENS: string;
43
+ export const ERR_KEYCHAIN_REQUIRED: string;
44
+ export const ERR_INVALID_CMS: string;
45
+ export const ERR_MISSING_KEYS: string;
46
+ export const ERR_NO_KEY: string;
47
+ export const ERR_INVALID_KEY_NAME: string;
48
+ export const ERR_INVALID_KEY_TYPE: string;
49
+ export const ERR_KEY_ALREADY_EXISTS: string;
50
+ export const ERR_INVALID_KEY_SIZE: string;
51
+ export const ERR_KEY_NOT_FOUND: string;
52
+ export const ERR_OLD_KEY_NAME_INVALID: string;
53
+ export const ERR_NEW_KEY_NAME_INVALID: string;
54
+ export const ERR_PASSWORD_REQUIRED: string;
55
+ export const ERR_PEM_REQUIRED: string;
56
+ export const ERR_CANNOT_READ_KEY: string;
57
+ export const ERR_MISSING_PRIVATE_KEY: string;
58
+ export const ERR_INVALID_OLD_PASS_TYPE: string;
59
+ export const ERR_INVALID_NEW_PASS_TYPE: string;
60
+ export const ERR_INVALID_PASS_LENGTH: string;
61
+ export const ERR_NOT_IMPLEMENTED: string;
62
+ export const ERR_WRONG_PING_ACK: string;
39
63
  }
40
64
  //# sourceMappingURL=errors.d.ts.map
@@ -19,16 +19,9 @@ export = Libp2p;
19
19
  * @property {MuxedStream} stream
20
20
  * @property {string} protocol
21
21
  *
22
- * @typedef {Object} RandomWalkOptions
23
- * @property {boolean} [enabled = false]
24
- * @property {number} [queriesPerPeriod = 1]
25
- * @property {number} [interval = 300e3]
26
- * @property {number} [timeout = 10e3]
27
- *
28
22
  * @typedef {Object} DhtOptions
29
23
  * @property {boolean} [enabled = false]
30
24
  * @property {number} [kBucketSize = 20]
31
- * @property {RandomWalkOptions} [randomWalk]
32
25
  * @property {boolean} [clientMode]
33
26
  * @property {import('libp2p-interfaces/src/types').DhtSelectors} [selectors]
34
27
  * @property {import('libp2p-interfaces/src/types').DhtValidators} [validators]
@@ -154,12 +147,6 @@ declare class Libp2p extends EventEmitter {
154
147
  dht: {
155
148
  enabled: boolean;
156
149
  kBucketSize: number;
157
- randomWalk: {
158
- enabled: boolean;
159
- queriesPerPeriod: number;
160
- interval: number;
161
- timeout: number;
162
- };
163
150
  };
164
151
  nat: {
165
152
  enabled: boolean;
@@ -213,12 +200,6 @@ declare class Libp2p extends EventEmitter {
213
200
  dht: {
214
201
  enabled: boolean;
215
202
  kBucketSize: number;
216
- randomWalk: {
217
- enabled: boolean;
218
- queriesPerPeriod: number;
219
- interval: number;
220
- timeout: number;
221
- };
222
203
  };
223
204
  nat: {
224
205
  enabled: boolean;
@@ -410,7 +391,7 @@ declare class Libp2p extends EventEmitter {
410
391
  private _setupPeerDiscovery;
411
392
  }
412
393
  declare namespace Libp2p {
413
- export { Connection, MuxedStream, TransportFactory, MuxerFactory, ContentRoutingModule, PeerDiscoveryFactory, PeerRoutingModule, Crypto, Pubsub, PubsubOptions, Datastore, Protector, HandlerProps, RandomWalkOptions, DhtOptions, KeychainOptions, PeerStoreOptions, PubsubLocalOptions, MetricsOptions, RelayOptions, Libp2pConfig, Libp2pModules, Libp2pOptions, constructorOptions, CreateOptions };
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 };
414
395
  }
415
396
  import { EventEmitter } from "events";
416
397
  type Libp2pOptions = {
@@ -501,16 +482,9 @@ type Pubsub = import('libp2p-interfaces/src/pubsub');
501
482
  type PubsubOptions = import('libp2p-interfaces/src/pubsub').PubsubOptions;
502
483
  type Datastore = import('interface-datastore').Datastore;
503
484
  type Protector = import('./pnet');
504
- type RandomWalkOptions = {
505
- enabled?: boolean | undefined;
506
- queriesPerPeriod?: number | undefined;
507
- interval?: number | undefined;
508
- timeout?: number | undefined;
509
- };
510
485
  type DhtOptions = {
511
486
  enabled?: boolean | undefined;
512
487
  kBucketSize?: number | undefined;
513
- randomWalk?: RandomWalkOptions | undefined;
514
488
  clientMode?: boolean | undefined;
515
489
  selectors?: import("libp2p-interfaces/src/types").DhtSelectors | undefined;
516
490
  validators?: import("libp2p-interfaces/src/types").DhtValidators | undefined;
@@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,oBAAoB;yBACzE,OAAO,0CAA0C,EAAE,WAAW;cAC9D,OAAO,oCAAoC,EAAE,MAAM;cACnD,OAAO,8BAA8B,CAAC;qBACtC,OAAO,8BAA8B,EAAE,aAAa;iBACpD,OAAO,qBAAqB,EAAE,SAAS;iBACvC,OAAO,QAAQ,CAAC;;;;;;;;;;;;iBAoBf,OAAO;;;aAGP,OAAO;;;aAGP,OAAO"}
@@ -1 +1 @@
1
- {"version":3,"file":"cms.d.ts","sourceRoot":"","sources":["../../../src/keychain/cms.js"],"names":[],"mappings":";AAeA;;;;;;;;GAQG;AACH;IACE;;;;;OAKG;IACH,sBAHW,OAAO,SAAS,CAAC,OACjB,MAAM,EAShB;IAFC,4BAAwB;IAI1B;;;;;;;;OAQG;IACH,cAJW,MAAM,SACN,UAAU,GACR,QAAQ,UAAU,CAAC,CAuB/B;IAED;;;;;;;;OAQG;IACH,iBAHW,UAAU,GACR,QAAQ,UAAU,CAAC,CA8D/B;CACF"}
1
+ {"version":3,"file":"cms.d.ts","sourceRoot":"","sources":["../../../src/keychain/cms.js"],"names":[],"mappings":";AAgBA;;;;;;;;GAQG;AACH;IACE;;;;;OAKG;IACH,sBAHW,OAAO,SAAS,CAAC,OACjB,MAAM,EAShB;IAFC,4BAAwB;IAI1B;;;;;;;;OAQG;IACH,cAJW,MAAM,SACN,UAAU,GACR,QAAQ,UAAU,CAAC,CAuB/B;IAED;;;;;;;;OAQG;IACH,iBAHW,UAAU,GACR,QAAQ,UAAU,CAAC,CA8D/B;CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/keychain/index.js"],"names":[],"mappings":";AAkHA;;;;;;;GAOG;AACH;IAwDE;;;;OAIG;IACH,0BAFa,MAAM,CAOlB;IAED;;;;;OAKG;IACH,6BAEC;IA3ED;;;;;;OAMG;IACH,mBAJW,SAAS,WACT,eAAe,EAmCzB;IA5BC,+CAAkB;IAElB,UAAiD;IA4BnD;;;;;;;;;OASG;IAC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;;;;;;OASG;IACH,eAEC;IAwBD;;;;;;;OAOG;IACH,gBALW,MAAM,QACN,MAAM,8BAEJ,QAAQ,OAAO,CAAC,CAiD5B;IAED;;;;OAIG;IACH,YAFa,QAAQ,OAAO,EAAE,CAAC,CAc9B;IAED;;;;;OAKG;IACH,gBAHW,MAAM,GACJ,QAAQ,OAAO,GAAC,SAAS,CAAC,CAStC;IAED;;;;;OAKG;IACH,oBAHW,MAAM,GACJ,QAAQ,OAAO,CAAC,CAc5B;IAED;;;;;OAKG;IACH,gBAHW,MAAM,GACJ,QAAQ,OAAO,CAAC,CAc5B;IAED;;;;;;OAMG;IACH,mBAJW,MAAM,WACN,MAAM,GACJ,QAAQ,OAAO,CAAC,CAkC5B;IAED;;;;;;OAMG;IACH,gBAJW,MAAM,YACN,MAAM,GACJ,QAAQ,MAAM,CAAC,CAqB3B;IAED;;;;;;;OAOG;IACH,gBALW,MAAM,OACN,MAAM,YACN,MAAM,GACJ,QAAQ,OAAO,CAAC,CAyC5B;IAED;;;;;;OAMG;IACH,iBAJW,MAAM,QACN,MAAM,GACJ,QAAQ,OAAO,CAAC,CAiC5B;IAED;;;;;OAKG;IACH,qBAHW,MAAM,GACJ,QAAQ,MAAM,CAAC,CAc3B;IAED;;;;;OAKG;IACH,4BAHW,MAAM,WACN,MAAM,sBA2ChB;CACF;;;;;;;;;;;;QAtgBa,MAAM;;;;UACN,MAAM;;cArBP,OAAO,SAAS,CAAC;iBACjB,OAAO,qBAAqB,EAAE,SAAS;;;;;;UAKtC,MAAM;UACN,MAAM;oBACN,MAAM;eACN,MAAM"}
@@ -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 {MetricsProperties & MetricsOptions} options
25
+ * @param {MetricsOptions} options
29
26
  */
30
- constructor(options: MetricsProperties & MetricsOptions);
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
- _connectionManager: import("../connection-manager");
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, MetricsProperties, MetricsOptions };
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;;;;;;;;;GASG;AAEH;IAwNE;;;;;;;OAOG;IACH,0BAJW,KAAK,SACL,KAAK,GACH,KAAK,CAWjB;IAxOD;;;OAGG;IACH,qBAFW,iBAAiB,GAAG,cAAc,EAc5C;IAXC,cAAqD;IACrD,oBAA6D;IAC7D,0BAA2B;IAC3B,8BAA+B;IAC/B,eAA+D;IAC/D,kBAAqB;IAiGvB;;;;;;;;;;;;OAYG;IACH,mBAwBC;IApIC,oDAAmD;IAMrD;;;OAGG;IACH,cAEC;IAED;;;OAGG;IACH,aASC;IAED;;;;OAIG;IACH,oBAEC;IAED;;;;OAIG;IACH,sBAEC;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;;;;;cAzPY,OAAO,SAAS,CAAC;2BACjB,OAAO,uCAAuC,EAAE,mBAAmB;;uBAKlE,OAAO,uBAAuB,CAAC"}
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 +1 @@
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"}
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"}
@@ -1 +1 @@
1
- {"version":3,"file":"book.d.ts","sourceRoot":"","sources":["../../../src/peer-store/book.js"],"names":[],"mappings":";AAcA;;GAEG;AAEH;IACE;;;;;;;;;OASG;IACH;QALiC,SAAS,EAA/B,SAAS;QACU,SAAS,EAA5B,MAAM;QACa,aAAa,EAAhC,MAAM;QAC4B,gBAAgB,WAA3C,GAAG,KAAK,GAAG,EAAE;OAc9B;IAXC,kBAAoB;IACpB,kBAA0B;IAC1B,sBAAkC;IAClC,yBANgB,GAAG,KAAK,GAAG,EAAE,CAMW;IAExC;;;;OAIG;IACH,MAFU,IAAI,MAAM,EAAE,GAAG,EAAE,GAAC,GAAG,CAAC,CAEX;IAGvB;;;;;OAKG;IACH,YAHW,MAAM,QACN,GAAG,EAAE,GAAC,GAAG,QAInB;IAED;;;;;;;;;OASG;IACH,2BANW,MAAM,QACN,GAAG;;oBAGD,IAAI,CAUhB;IAED;;;;;;OAMG;IACH,wBAHW,MAAM,SACN,GAAG,QAOb;IAED;;;;;;OAMG;IACH,YAHW,MAAM,GACJ,GAAG,EAAE,GAAC,GAAG,GAAC,SAAS,CAW/B;IAED;;;;;OAKG;IACH,eAHW,MAAM,GACJ,OAAO,CAcnB;CACF;;;;;iBA7GY,OAAO,IAAI,CAAC"}
1
+ {"version":3,"file":"book.d.ts","sourceRoot":"","sources":["../../../src/peer-store/book.js"],"names":[],"mappings":";AAWA;;GAEG;AAEH;IACE;;;;;;;;;OASG;IACH;QALiC,SAAS,EAA/B,SAAS;QACU,SAAS,EAA5B,MAAM;QACa,aAAa,EAAhC,MAAM;QAC4B,gBAAgB,WAA3C,GAAG,KAAK,GAAG,EAAE;OAc9B;IAXC,kBAAoB;IACpB,kBAA0B;IAC1B,sBAAkC;IAClC,yBANgB,GAAG,KAAK,GAAG,EAAE,CAMW;IAExC;;;;OAIG;IACH,MAFU,IAAI,MAAM,EAAE,GAAG,EAAE,GAAC,GAAG,CAAC,CAEX;IAGvB;;;;;OAKG;IACH,YAHW,MAAM,QACN,GAAG,EAAE,GAAC,GAAG,QAInB;IAED;;;;;;;;;OASG;IACH,2BANW,MAAM,QACN,GAAG;;oBAGD,IAAI,CAUhB;IAED;;;;;;OAMG;IACH,wBAHW,MAAM,SACN,GAAG,QAOb;IAED;;;;;;OAMG;IACH,YAHW,MAAM,GACJ,GAAG,EAAE,GAAC,GAAG,GAAC,SAAS,CAW/B;IAED;;;;;OAKG;IACH,eAHW,MAAM,GACJ,OAAO,CAcnB;CACF;;;;;iBA7GY,OAAO,IAAI,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libp2p",
3
- "version": "0.35.2",
3
+ "version": "0.35.6",
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",
@@ -69,7 +69,7 @@
69
69
  "node": ">=15.0.0"
70
70
  },
71
71
  "browser": {
72
- "@motrix/nat-api": false
72
+ "nat-api": false
73
73
  },
74
74
  "eslintConfig": {
75
75
  "extends": "ipfs",
@@ -80,7 +80,6 @@
80
80
  ]
81
81
  },
82
82
  "dependencies": {
83
- "@motrix/nat-api": "^0.3.1",
84
83
  "@vascosantos/moving-average": "^1.1.0",
85
84
  "abort-controller": "^3.0.0",
86
85
  "abortable-iterator": "^3.0.0",
@@ -114,6 +113,7 @@
114
113
  "multiformats": "^9.0.0",
115
114
  "multistream-select": "^2.0.0",
116
115
  "mutable-proxy": "^1.0.0",
116
+ "nat-api": "^0.3.1",
117
117
  "node-forge": "^0.10.0",
118
118
  "p-any": "^3.0.0",
119
119
  "p-fifo": "^1.0.0",
@@ -133,7 +133,7 @@
133
133
  "xsalsa20": "^1.1.0"
134
134
  },
135
135
  "devDependencies": {
136
- "@chainsafe/libp2p-noise": "^4.0.0",
136
+ "@chainsafe/libp2p-noise": "^5.0.0",
137
137
  "@nodeutils/defaults-deep": "^1.1.0",
138
138
  "@types/es6-promisify": "^6.0.0",
139
139
  "@types/node": "^16.0.1",
@@ -151,9 +151,9 @@
151
151
  "libp2p": ".",
152
152
  "libp2p-bootstrap": "^0.14.0",
153
153
  "libp2p-delegated-content-routing": "^0.11.0",
154
- "libp2p-delegated-peer-routing": "^0.11.0",
155
- "libp2p-floodsub": "^0.27.0",
156
- "libp2p-gossipsub": "^0.11.0",
154
+ "libp2p-delegated-peer-routing": "^0.11.1",
155
+ "libp2p-floodsub": "^0.28.0",
156
+ "libp2p-gossipsub": "^0.12.1",
157
157
  "libp2p-interfaces-compliance-tests": "^2.0.1",
158
158
  "libp2p-interop": "^0.5.0",
159
159
  "libp2p-kad-dht": "^0.27.1",
@@ -184,21 +184,21 @@
184
184
  "dirkmc <dirkmdev@gmail.com>",
185
185
  "Chris Dostert <chrisdostert@users.noreply.github.com>",
186
186
  "Volker Mische <volker.mische@gmail.com>",
187
- "zeim839 <50573884+zeim839@users.noreply.github.com>",
187
+ "Robert Kiel <robert.kiel@hoprnet.org>",
188
188
  "Richard Littauer <richard.littauer@gmail.com>",
189
+ "zeim839 <50573884+zeim839@users.noreply.github.com>",
189
190
  "a1300 <matthias-knopp@gmx.net>",
190
191
  "Ryan Bell <ryan@piing.net>",
191
192
  "ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ <victorbjelkholm@gmail.com>",
193
+ "Andrew Nesbitt <andrewnez@gmail.com>",
194
+ "Franck Royer <franck@royer.one>",
195
+ "Thomas Eizinger <thomas@eizinger.io>",
192
196
  "Giovanni T. Parra <fiatjaf@gmail.com>",
193
197
  "acolytec3 <17355484+acolytec3@users.noreply.github.com>",
194
- "Franck Royer <franck@royer.one>",
198
+ "Alan Smithee <ggnore.alan.smithee@gmail.com>",
195
199
  "Elven <mon.samuel@qq.com>",
196
- "Robert Kiel <robert.kiel@hoprnet.org>",
197
- "Andrew Nesbitt <andrewnez@gmail.com>",
198
200
  "Samlior <samlior@foxmail.com>",
199
- "Thomas Eizinger <thomas@eizinger.io>",
200
201
  "Didrik Nordström <didrik.nordstrom@gmail.com>",
201
- "Smite Chow <xiaopengyou@live.com>",
202
202
  "Soeren <nikorpoulsen@gmail.com>",
203
203
  "Sönke Hahn <soenkehahn@gmail.com>",
204
204
  "TJKoury <TJKoury@gmail.com>",
@@ -218,7 +218,6 @@
218
218
  "shresthagrawal <34920931+shresthagrawal@users.noreply.github.com>",
219
219
  "swedneck <40505480+swedneck@users.noreply.github.com>",
220
220
  "greenSnot <greenSnot@users.noreply.github.com>",
221
- "Alan Smithee <ggnore.alan.smithee@gmail.com>",
222
221
  "Aleksei <vozhdb@gmail.com>",
223
222
  "Bernd Strehl <bernd.strehl@gmail.com>",
224
223
  "Chris Bratlien <chrisbratlien@gmail.com>",
@@ -243,10 +242,12 @@
243
242
  "Lars Gierth <lgierth@users.noreply.github.com>",
244
243
  "Leask Wong <i@leaskh.com>",
245
244
  "Marcin Tojek <mtojek@users.noreply.github.com>",
245
+ "Marston Connell <34043723+TheMarstonConnell@users.noreply.github.com>",
246
246
  "Michael Burns <5170+mburns@users.noreply.github.com>",
247
247
  "Miguel Mota <miguelmota2@gmail.com>",
248
248
  "Nuno Nogueira <nunofmn@gmail.com>",
249
249
  "Philipp Muens <raute1337@gmx.de>",
250
- "RasmusErik Voel Jensen <github@solsort.com>"
250
+ "RasmusErik Voel Jensen <github@solsort.com>",
251
+ "Smite Chow <xiaopengyou@live.com>"
251
252
  ]
252
253
  }
@@ -4,7 +4,7 @@ const debug = require('debug')
4
4
  const log = Object.assign(debug('libp2p:relay'), {
5
5
  error: debug('libp2p:relay:err')
6
6
  })
7
-
7
+ const { codes } = require('./../errors')
8
8
  const {
9
9
  setDelayedInterval,
10
10
  clearDelayedInterval
@@ -88,7 +88,7 @@ class Relay {
88
88
  const cid = await namespaceToCid(RELAY_RENDEZVOUS_NS)
89
89
  await this._libp2p.contentRouting.provide(cid)
90
90
  } catch (/** @type {any} */ err) {
91
- if (err.code === 'NO_ROUTERS_AVAILABLE') {
91
+ if (err.code === codes.ERR_NO_ROUTERS_AVAILABLE) {
92
92
  log.error('a content router, such as a DHT, must be provided in order to advertise the relay service', err)
93
93
  // Stop the advertise
94
94
  this.stop()
package/src/config.js CHANGED
@@ -60,13 +60,7 @@ const DefaultConfig = {
60
60
  protocolPrefix: 'ipfs',
61
61
  dht: {
62
62
  enabled: false,
63
- kBucketSize: 20,
64
- randomWalk: {
65
- enabled: false, // disabled waiting for https://github.com/libp2p/js-libp2p-kad-dht/issues/86
66
- queriesPerPeriod: 1,
67
- interval: 300e3,
68
- timeout: 10e3
69
- }
63
+ kBucketSize: 20
70
64
  },
71
65
  nat: {
72
66
  enabled: true,
@@ -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_ALL_CONNECTIONS = 'all-connections'
38
+
35
39
  /**
36
40
  * @typedef {import('../')} Libp2p
37
41
  * @typedef {import('libp2p-interfaces/src/connection').Connection} Connection
@@ -160,6 +164,8 @@ class ConnectionManager extends EventEmitter {
160
164
 
161
165
  await Promise.all(tasks)
162
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)
163
169
  }
164
170
 
165
171
  /**
@@ -211,10 +217,13 @@ class ConnectionManager extends EventEmitter {
211
217
  const storedConn = this.connections.get(peerIdStr)
212
218
 
213
219
  this.emit('peer:connect', connection)
220
+
214
221
  if (storedConn) {
215
222
  storedConn.push(connection)
216
223
  } else {
217
224
  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)
218
227
  }
219
228
 
220
229
  this._libp2p.peerStore.keyBook.set(peerId, peerId.pubKey)
@@ -243,7 +252,12 @@ class ConnectionManager extends EventEmitter {
243
252
  this.connections.delete(peerId)
244
253
  this._peerValues.delete(connection.remotePeer.toB58String())
245
254
  this.emit('peer:disconnect', connection)
255
+
256
+ this._libp2p.metrics && this._libp2p.metrics.onPeerDisconnected(connection.remotePeer)
246
257
  }
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)
247
261
  }
248
262
 
249
263
  /**
@@ -54,7 +54,7 @@ class ContentRouting {
54
54
  */
55
55
  async * findProviders (key, options = {}) {
56
56
  if (!this.routers.length) {
57
- throw errCode(new Error('No content this.routers available'), 'NO_ROUTERS_AVAILABLE')
57
+ throw errCode(new Error('No content this.routers available'), codes.ERR_NO_ROUTERS_AVAILABLE)
58
58
  }
59
59
 
60
60
  yield * pipe(
@@ -77,7 +77,7 @@ class ContentRouting {
77
77
  */
78
78
  async provide (key) {
79
79
  if (!this.routers.length) {
80
- throw errCode(new Error('No content routers available'), 'NO_ROUTERS_AVAILABLE')
80
+ throw errCode(new Error('No content routers available'), codes.ERR_NO_ROUTERS_AVAILABLE)
81
81
  }
82
82
 
83
83
  await Promise.all(this.routers.map((router) => router.provide(key)))
@@ -27,8 +27,12 @@ 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 === 'FINAL_PEER') {
31
- return event.peer
30
+ if (event.name === 'PEER_RESPONSE') {
31
+ const peer = event.closer.find(peerData => peerData.id.equals(peerId))
32
+
33
+ if (peer) {
34
+ return peer
35
+ }
32
36
  }
33
37
  }
34
38
 
@@ -7,6 +7,7 @@ const FIFO = require('p-fifo')
7
7
  const pAny = require('p-any')
8
8
  // @ts-expect-error setMaxListeners is missing from the types
9
9
  const { setMaxListeners } = require('events')
10
+ const { codes } = require('../errors')
10
11
 
11
12
  /**
12
13
  * @typedef {import('libp2p-interfaces/src/connection').Connection} Connection
@@ -55,7 +56,7 @@ class DialRequest {
55
56
  const tokens = this.dialer.getTokens(this.addrs.length)
56
57
  // If no tokens are available, throw
57
58
  if (tokens.length < 1) {
58
- throw errCode(new Error('No dial tokens available'), 'ERR_NO_DIAL_TOKENS')
59
+ throw errCode(new Error('No dial tokens available'), codes.ERR_NO_DIAL_TOKENS)
59
60
  }
60
61
 
61
62
  const tokenHolder = new FIFO()
@@ -9,7 +9,8 @@ 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')
@@ -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,6 +49,7 @@ 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
@@ -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
@@ -81,6 +88,7 @@ class Dialer {
81
88
  this.tokens = [...new Array(maxParallelDials)].map((_, index) => index)
82
89
  this._pendingDials = new Map()
83
90
  this._pendingDialTargets = new Map()
91
+ this._metrics = metrics
84
92
 
85
93
  for (const [key, value] of Object.entries(resolvers)) {
86
94
  Multiaddr.resolvers.set(key, value)
@@ -104,6 +112,9 @@ class Dialer {
104
112
  pendingTarget.reject(new AbortError('Dialer was destroyed'))
105
113
  }
106
114
  this._pendingDialTargets.clear()
115
+
116
+ this._metrics && this._metrics.updateComponentMetric(METRICS_COMPONENT, METRICS_PENDING_DIALS, 0)
117
+ this._metrics && this._metrics.updateComponentMetric(METRICS_COMPONENT, METRICS_PENDING_DIAL_TARGETS, 0)
107
118
  }
108
119
 
109
120
  /**
@@ -153,16 +164,20 @@ class Dialer {
153
164
  const id = `${(parseInt(String(Math.random() * 1e9), 10)).toString() + Date.now()}`
154
165
  const cancellablePromise = new Promise((resolve, reject) => {
155
166
  this._pendingDialTargets.set(id, { resolve, reject })
167
+ this._metrics && this._metrics.updateComponentMetric(METRICS_COMPONENT, METRICS_PENDING_DIAL_TARGETS, this._pendingDialTargets.size)
156
168
  })
157
169
 
158
- const dialTarget = await Promise.race([
159
- this._createDialTarget(peer),
160
- cancellablePromise
161
- ])
162
-
163
- this._pendingDialTargets.delete(id)
170
+ try {
171
+ const dialTarget = await Promise.race([
172
+ this._createDialTarget(peer),
173
+ cancellablePromise
174
+ ])
164
175
 
165
- return dialTarget
176
+ return dialTarget
177
+ } finally {
178
+ this._pendingDialTargets.delete(id)
179
+ this._metrics && this._metrics.updateComponentMetric(METRICS_COMPONENT, METRICS_PENDING_DIAL_TARGETS, this._pendingDialTargets.size)
180
+ }
166
181
  }
167
182
 
168
183
  /**
@@ -239,6 +254,10 @@ class Dialer {
239
254
 
240
255
  // Combine the timeout signal and options.signal, if provided
241
256
  const timeoutController = new TimeoutController(this.timeout)
257
+ // this controller will potentially be used while dialing lots of
258
+ // peers so prevent MaxListenersExceededWarning appearing in the console
259
+ setMaxListeners && setMaxListeners(Infinity, timeoutController.signal)
260
+
242
261
  const signals = [timeoutController.signal]
243
262
  options.signal && signals.push(options.signal)
244
263
  const signal = anySignal(signals)
@@ -250,9 +269,13 @@ class Dialer {
250
269
  destroy: () => {
251
270
  timeoutController.clear()
252
271
  this._pendingDials.delete(dialTarget.id)
272
+ this._metrics && this._metrics.updateComponentMetric(METRICS_COMPONENT, METRICS_PENDING_DIALS, this._pendingDials.size)
253
273
  }
254
274
  }
255
275
  this._pendingDials.set(dialTarget.id, pendingDial)
276
+
277
+ this._metrics && this._metrics.updateComponentMetric(METRICS_COMPONENT, METRICS_PENDING_DIALS, this._pendingDials.size)
278
+
256
279
  return pendingDial
257
280
  }
258
281
 
package/src/errors.js CHANGED
@@ -36,5 +36,29 @@ exports.codes = {
36
36
  ERR_TRANSPORT_DIAL_FAILED: 'ERR_TRANSPORT_DIAL_FAILED',
37
37
  ERR_UNSUPPORTED_PROTOCOL: 'ERR_UNSUPPORTED_PROTOCOL',
38
38
  ERR_INVALID_MULTIADDR: 'ERR_INVALID_MULTIADDR',
39
- ERR_SIGNATURE_NOT_VALID: 'ERR_SIGNATURE_NOT_VALID'
39
+ ERR_SIGNATURE_NOT_VALID: 'ERR_SIGNATURE_NOT_VALID',
40
+ ERR_FIND_SELF: 'ERR_FIND_SELF',
41
+ ERR_NO_ROUTERS_AVAILABLE: 'ERR_NO_ROUTERS_AVAILABLE',
42
+ ERR_CONNECTION_NOT_MULTIPLEXED: 'ERR_CONNECTION_NOT_MULTIPLEXED',
43
+ ERR_NO_DIAL_TOKENS: 'ERR_NO_DIAL_TOKENS',
44
+ ERR_KEYCHAIN_REQUIRED: 'ERR_KEYCHAIN_REQUIRED',
45
+ ERR_INVALID_CMS: 'ERR_INVALID_CMS',
46
+ ERR_MISSING_KEYS: 'ERR_MISSING_KEYS',
47
+ ERR_NO_KEY: 'ERR_NO_KEY',
48
+ ERR_INVALID_KEY_NAME: 'ERR_INVALID_KEY_NAME',
49
+ ERR_INVALID_KEY_TYPE: 'ERR_INVALID_KEY_TYPE',
50
+ ERR_KEY_ALREADY_EXISTS: 'ERR_KEY_ALREADY_EXISTS',
51
+ ERR_INVALID_KEY_SIZE: 'ERR_INVALID_KEY_SIZE',
52
+ ERR_KEY_NOT_FOUND: 'ERR_KEY_NOT_FOUND',
53
+ ERR_OLD_KEY_NAME_INVALID: 'ERR_OLD_KEY_NAME_INVALID',
54
+ ERR_NEW_KEY_NAME_INVALID: 'ERR_NEW_KEY_NAME_INVALID',
55
+ ERR_PASSWORD_REQUIRED: 'ERR_PASSWORD_REQUIRED',
56
+ ERR_PEM_REQUIRED: 'ERR_PEM_REQUIRED',
57
+ ERR_CANNOT_READ_KEY: 'ERR_CANNOT_READ_KEY',
58
+ ERR_MISSING_PRIVATE_KEY: 'ERR_MISSING_PRIVATE_KEY',
59
+ ERR_INVALID_OLD_PASS_TYPE: 'ERR_INVALID_OLD_PASS_TYPE',
60
+ ERR_INVALID_NEW_PASS_TYPE: 'ERR_INVALID_NEW_PASS_TYPE',
61
+ ERR_INVALID_PASS_LENGTH: 'ERR_INVALID_PASS_LENGTH',
62
+ ERR_NOT_IMPLEMENTED: 'ERR_NOT_IMPLEMENTED',
63
+ ERR_WRONG_PING_ACK: 'ERR_WRONG_PING_ACK'
40
64
  }
package/src/index.js CHANGED
@@ -56,16 +56,9 @@ const { updateSelfPeerRecord } = require('./record/utils')
56
56
  * @property {MuxedStream} stream
57
57
  * @property {string} protocol
58
58
  *
59
- * @typedef {Object} RandomWalkOptions
60
- * @property {boolean} [enabled = false]
61
- * @property {number} [queriesPerPeriod = 1]
62
- * @property {number} [interval = 300e3]
63
- * @property {number} [timeout = 10e3]
64
- *
65
59
  * @typedef {Object} DhtOptions
66
60
  * @property {boolean} [enabled = false]
67
61
  * @property {number} [kBucketSize = 20]
68
- * @property {RandomWalkOptions} [randomWalk]
69
62
  * @property {boolean} [clientMode]
70
63
  * @property {import('libp2p-interfaces/src/types').DhtSelectors} [selectors]
71
64
  * @property {import('libp2p-interfaces/src/types').DhtValidators} [validators]
@@ -204,10 +197,11 @@ class Libp2p extends EventEmitter {
204
197
 
205
198
  // Create Metrics
206
199
  if (this._options.metrics.enabled) {
207
- this.metrics = new Metrics({
208
- ...this._options.metrics,
209
- connectionManager: this.connectionManager
200
+ const metrics = new Metrics({
201
+ ...this._options.metrics
210
202
  })
203
+
204
+ this.metrics = metrics
211
205
  }
212
206
 
213
207
  // Create keychain
@@ -269,6 +263,7 @@ class Libp2p extends EventEmitter {
269
263
  this.dialer = new Dialer({
270
264
  transportManager: this.transportManager,
271
265
  peerStore: this.peerStore,
266
+ metrics: this.metrics,
272
267
  ...this._options.dialer
273
268
  })
274
269
 
@@ -10,6 +10,7 @@ const { certificateForKey, findAsync } = require('./util')
10
10
  const errcode = require('err-code')
11
11
  const { fromString: uint8ArrayFromString } = require('uint8arrays/from-string')
12
12
  const { toString: uint8ArrayToString } = require('uint8arrays/to-string')
13
+ const { codes } = require('../errors')
13
14
 
14
15
  const privates = new WeakMap()
15
16
 
@@ -31,7 +32,7 @@ class CMS {
31
32
  */
32
33
  constructor (keychain, dek) {
33
34
  if (!keychain) {
34
- throw errcode(new Error('keychain is required'), 'ERR_KEYCHAIN_REQUIRED')
35
+ throw errcode(new Error('keychain is required'), codes.ERR_KEYCHAIN_REQUIRED)
35
36
  }
36
37
 
37
38
  this.keychain = keychain
@@ -49,7 +50,7 @@ class CMS {
49
50
  */
50
51
  async encrypt (name, plain) {
51
52
  if (!(plain instanceof Uint8Array)) {
52
- throw errcode(new Error('Plain data must be a Uint8Array'), 'ERR_INVALID_PARAMS')
53
+ throw errcode(new Error('Plain data must be a Uint8Array'), codes.ERR_INVALID_PARAMETERS)
53
54
  }
54
55
 
55
56
  const key = await this.keychain.findKeyByName(name)
@@ -81,7 +82,7 @@ class CMS {
81
82
  */
82
83
  async decrypt (cmsData) {
83
84
  if (!(cmsData instanceof Uint8Array)) {
84
- throw errcode(new Error('CMS data is required'), 'ERR_INVALID_PARAMS')
85
+ throw errcode(new Error('CMS data is required'), codes.ERR_INVALID_PARAMETERS)
85
86
  }
86
87
 
87
88
  let cms
@@ -91,7 +92,7 @@ class CMS {
91
92
  // @ts-ignore not defined
92
93
  cms = forge.pkcs7.messageFromAsn1(obj)
93
94
  } catch (/** @type {any} */ err) {
94
- throw errcode(new Error('Invalid CMS: ' + err.message), 'ERR_INVALID_CMS')
95
+ throw errcode(new Error('Invalid CMS: ' + err.message), codes.ERR_INVALID_CMS)
95
96
  }
96
97
 
97
98
  // Find a recipient whose key we hold. We only deal with recipient certs
@@ -123,7 +124,7 @@ class CMS {
123
124
  if (!r) {
124
125
  // @ts-ignore cms types not defined
125
126
  const missingKeys = recipients.map(r => r.keyId)
126
- throw errcode(new Error('Decryption needs one of the key(s): ' + missingKeys.join(', ')), 'ERR_MISSING_KEYS', {
127
+ throw errcode(new Error('Decryption needs one of the key(s): ' + missingKeys.join(', ')), codes.ERR_MISSING_KEYS, {
127
128
  missingKeys
128
129
  })
129
130
  }
@@ -131,7 +132,7 @@ class CMS {
131
132
  const key = await this.keychain.findKeyById(r.keyId)
132
133
 
133
134
  if (!key) {
134
- throw errcode(new Error('No key available to decrypto'), 'ERR_NO_KEY')
135
+ throw errcode(new Error('No key available to decrypto'), codes.ERR_NO_KEY)
135
136
  }
136
137
 
137
138
  const pem = await this.keychain._getPrivateKey(key.name)
@@ -10,6 +10,7 @@ const crypto = require('libp2p-crypto')
10
10
  const { Key } = require('interface-datastore/key')
11
11
  const CMS = require('./cms')
12
12
  const errcode = require('err-code')
13
+ const { codes } = require('../errors')
13
14
  const { toString: uint8ArrayToString } = require('uint8arrays/to-string')
14
15
  const { fromString: uint8ArrayFromString } = require('uint8arrays/from-string')
15
16
 
@@ -210,21 +211,21 @@ class Keychain {
210
211
  const self = this
211
212
 
212
213
  if (!validateKeyName(name) || name === 'self') {
213
- return throwDelayed(errcode(new Error(`Invalid key name '${name}'`), 'ERR_INVALID_KEY_NAME'))
214
+ return throwDelayed(errcode(new Error(`Invalid key name '${name}'`), codes.ERR_INVALID_KEY_NAME))
214
215
  }
215
216
 
216
217
  if (typeof type !== 'string') {
217
- return throwDelayed(errcode(new Error(`Invalid key type '${type}'`), 'ERR_INVALID_KEY_TYPE'))
218
+ return throwDelayed(errcode(new Error(`Invalid key type '${type}'`), codes.ERR_INVALID_KEY_TYPE))
218
219
  }
219
220
 
220
221
  const dsname = DsName(name)
221
222
  const exists = await self.store.has(dsname)
222
- if (exists) return throwDelayed(errcode(new Error(`Key '${name}' already exists`), 'ERR_KEY_ALREADY_EXISTS'))
223
+ if (exists) return throwDelayed(errcode(new Error(`Key '${name}' already exists`), codes.ERR_KEY_ALREADY_EXISTS))
223
224
 
224
225
  switch (type.toLowerCase()) {
225
226
  case 'rsa':
226
227
  if (!Number.isSafeInteger(size) || size < 2048) {
227
- return throwDelayed(errcode(new Error(`Invalid RSA key size ${size}`), 'ERR_INVALID_KEY_SIZE'))
228
+ return throwDelayed(errcode(new Error(`Invalid RSA key size ${size}`), codes.ERR_INVALID_KEY_SIZE))
228
229
  }
229
230
  break
230
231
  default:
@@ -297,7 +298,7 @@ class Keychain {
297
298
  */
298
299
  async findKeyByName (name) {
299
300
  if (!validateKeyName(name)) {
300
- return throwDelayed(errcode(new Error(`Invalid key name '${name}'`), 'ERR_INVALID_KEY_NAME'))
301
+ return throwDelayed(errcode(new Error(`Invalid key name '${name}'`), codes.ERR_INVALID_KEY_NAME))
301
302
  }
302
303
 
303
304
  const dsname = DsInfoName(name)
@@ -305,7 +306,7 @@ class Keychain {
305
306
  const res = await this.store.get(dsname)
306
307
  return JSON.parse(uint8ArrayToString(res))
307
308
  } catch (/** @type {any} */ err) {
308
- return throwDelayed(errcode(new Error(`Key '${name}' does not exist. ${err.message}`), 'ERR_KEY_NOT_FOUND'))
309
+ return throwDelayed(errcode(new Error(`Key '${name}' does not exist. ${err.message}`), codes.ERR_KEY_NOT_FOUND))
309
310
  }
310
311
  }
311
312
 
@@ -318,7 +319,7 @@ class Keychain {
318
319
  async removeKey (name) {
319
320
  const self = this
320
321
  if (!validateKeyName(name) || name === 'self') {
321
- return throwDelayed(errcode(new Error(`Invalid key name '${name}'`), 'ERR_INVALID_KEY_NAME'))
322
+ return throwDelayed(errcode(new Error(`Invalid key name '${name}'`), codes.ERR_INVALID_KEY_NAME))
322
323
  }
323
324
  const dsname = DsName(name)
324
325
  const keyInfo = await self.findKeyByName(name)
@@ -339,10 +340,10 @@ class Keychain {
339
340
  async renameKey (oldName, newName) {
340
341
  const self = this
341
342
  if (!validateKeyName(oldName) || oldName === 'self') {
342
- return throwDelayed(errcode(new Error(`Invalid old key name '${oldName}'`), 'ERR_OLD_KEY_NAME_INVALID'))
343
+ return throwDelayed(errcode(new Error(`Invalid old key name '${oldName}'`), codes.ERR_OLD_KEY_NAME_INVALID))
343
344
  }
344
345
  if (!validateKeyName(newName) || newName === 'self') {
345
- return throwDelayed(errcode(new Error(`Invalid new key name '${newName}'`), 'ERR_NEW_KEY_NAME_INVALID'))
346
+ return throwDelayed(errcode(new Error(`Invalid new key name '${newName}'`), codes.ERR_NEW_KEY_NAME_INVALID))
346
347
  }
347
348
  const oldDsname = DsName(oldName)
348
349
  const newDsname = DsName(newName)
@@ -350,7 +351,7 @@ class Keychain {
350
351
  const newInfoName = DsInfoName(newName)
351
352
 
352
353
  const exists = await self.store.has(newDsname)
353
- if (exists) return throwDelayed(errcode(new Error(`Key '${newName}' already exists`), 'ERR_KEY_ALREADY_EXISTS'))
354
+ if (exists) return throwDelayed(errcode(new Error(`Key '${newName}' already exists`), codes.ERR_KEY_ALREADY_EXISTS))
354
355
 
355
356
  try {
356
357
  const pem = await self.store.get(oldDsname)
@@ -379,10 +380,10 @@ class Keychain {
379
380
  */
380
381
  async exportKey (name, password) {
381
382
  if (!validateKeyName(name)) {
382
- return throwDelayed(errcode(new Error(`Invalid key name '${name}'`), 'ERR_INVALID_KEY_NAME'))
383
+ return throwDelayed(errcode(new Error(`Invalid key name '${name}'`), codes.ERR_INVALID_KEY_NAME))
383
384
  }
384
385
  if (!password) {
385
- return throwDelayed(errcode(new Error('Password is required'), 'ERR_PASSWORD_REQUIRED'))
386
+ return throwDelayed(errcode(new Error('Password is required'), codes.ERR_PASSWORD_REQUIRED))
386
387
  }
387
388
 
388
389
  const dsname = DsName(name)
@@ -409,20 +410,20 @@ class Keychain {
409
410
  async importKey (name, pem, password) {
410
411
  const self = this
411
412
  if (!validateKeyName(name) || name === 'self') {
412
- return throwDelayed(errcode(new Error(`Invalid key name '${name}'`), 'ERR_INVALID_KEY_NAME'))
413
+ return throwDelayed(errcode(new Error(`Invalid key name '${name}'`), codes.ERR_INVALID_KEY_NAME))
413
414
  }
414
415
  if (!pem) {
415
- return throwDelayed(errcode(new Error('PEM encoded key is required'), 'ERR_PEM_REQUIRED'))
416
+ return throwDelayed(errcode(new Error('PEM encoded key is required'), codes.ERR_PEM_REQUIRED))
416
417
  }
417
418
  const dsname = DsName(name)
418
419
  const exists = await self.store.has(dsname)
419
- if (exists) return throwDelayed(errcode(new Error(`Key '${name}' already exists`), 'ERR_KEY_ALREADY_EXISTS'))
420
+ if (exists) return throwDelayed(errcode(new Error(`Key '${name}' already exists`), codes.ERR_KEY_ALREADY_EXISTS))
420
421
 
421
422
  let privateKey
422
423
  try {
423
424
  privateKey = await crypto.keys.import(pem, password)
424
425
  } catch (/** @type {any} */ err) {
425
- return throwDelayed(errcode(new Error('Cannot read the key, most likely the password is wrong'), 'ERR_CANNOT_READ_KEY'))
426
+ return throwDelayed(errcode(new Error('Cannot read the key, most likely the password is wrong'), codes.ERR_CANNOT_READ_KEY))
426
427
  }
427
428
 
428
429
  let kid
@@ -457,16 +458,16 @@ class Keychain {
457
458
  async importPeer (name, peer) {
458
459
  const self = this
459
460
  if (!validateKeyName(name)) {
460
- return throwDelayed(errcode(new Error(`Invalid key name '${name}'`), 'ERR_INVALID_KEY_NAME'))
461
+ return throwDelayed(errcode(new Error(`Invalid key name '${name}'`), codes.ERR_INVALID_KEY_NAME))
461
462
  }
462
463
  if (!peer || !peer.privKey) {
463
- return throwDelayed(errcode(new Error('Peer.privKey is required'), 'ERR_MISSING_PRIVATE_KEY'))
464
+ return throwDelayed(errcode(new Error('Peer.privKey is required'), codes.ERR_MISSING_PRIVATE_KEY))
464
465
  }
465
466
 
466
467
  const privateKey = peer.privKey
467
468
  const dsname = DsName(name)
468
469
  const exists = await self.store.has(dsname)
469
- if (exists) return throwDelayed(errcode(new Error(`Key '${name}' already exists`), 'ERR_KEY_ALREADY_EXISTS'))
470
+ if (exists) return throwDelayed(errcode(new Error(`Key '${name}' already exists`), codes.ERR_KEY_ALREADY_EXISTS))
470
471
 
471
472
  try {
472
473
  const kid = await privateKey.id()
@@ -495,7 +496,7 @@ class Keychain {
495
496
  */
496
497
  async _getPrivateKey (name) {
497
498
  if (!validateKeyName(name)) {
498
- return throwDelayed(errcode(new Error(`Invalid key name '${name}'`), 'ERR_INVALID_KEY_NAME'))
499
+ return throwDelayed(errcode(new Error(`Invalid key name '${name}'`), codes.ERR_INVALID_KEY_NAME))
499
500
  }
500
501
 
501
502
  try {
@@ -503,7 +504,7 @@ class Keychain {
503
504
  const res = await this.store.get(dsname)
504
505
  return uint8ArrayToString(res)
505
506
  } catch (/** @type {any} */ err) {
506
- return throwDelayed(errcode(new Error(`Key '${name}' does not exist. ${err.message}`), 'ERR_KEY_NOT_FOUND'))
507
+ return throwDelayed(errcode(new Error(`Key '${name}' does not exist. ${err.message}`), codes.ERR_KEY_NOT_FOUND))
507
508
  }
508
509
  }
509
510
 
@@ -515,13 +516,13 @@ class Keychain {
515
516
  */
516
517
  async rotateKeychainPass (oldPass, newPass) {
517
518
  if (typeof oldPass !== 'string') {
518
- return throwDelayed(errcode(new Error(`Invalid old pass type '${typeof oldPass}'`), 'ERR_INVALID_OLD_PASS_TYPE'))
519
+ return throwDelayed(errcode(new Error(`Invalid old pass type '${typeof oldPass}'`), codes.ERR_INVALID_OLD_PASS_TYPE))
519
520
  }
520
521
  if (typeof newPass !== 'string') {
521
- return throwDelayed(errcode(new Error(`Invalid new pass type '${typeof newPass}'`), 'ERR_INVALID_NEW_PASS_TYPE'))
522
+ return throwDelayed(errcode(new Error(`Invalid new pass type '${typeof newPass}'`), codes.ERR_INVALID_NEW_PASS_TYPE))
522
523
  }
523
524
  if (newPass.length < 20) {
524
- return throwDelayed(errcode(new Error(`Invalid pass length ${newPass.length}`), 'ERR_INVALID_PASS_LENGTH'))
525
+ return throwDelayed(errcode(new Error(`Invalid pass length ${newPass.length}`), codes.ERR_INVALID_PASS_LENGTH))
525
526
  }
526
527
  log('recreating keychain')
527
528
  const oldDek = privates.get(this).dek
@@ -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 {MetricsProperties & MetricsOptions} options
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._connectionManager = options.connectionManager
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.
@@ -1,7 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  // @ts-ignore nat-api does not export types
4
- const NatAPI = require('@motrix/nat-api')
4
+ const NatAPI = require('nat-api')
5
5
  const debug = require('debug')
6
6
  const { promisify } = require('es6-promisify')
7
7
  const { Multiaddr } = require('multiaddr')
@@ -5,6 +5,7 @@ const log = Object.assign(debug('libp2p:peer-routing'), {
5
5
  error: debug('libp2p:peer-routing:err')
6
6
  })
7
7
  const errCode = require('err-code')
8
+ const errors = require('./errors')
8
9
  const {
9
10
  storeAddresses,
10
11
  uniquePeers,
@@ -23,6 +24,8 @@ const {
23
24
  // @ts-ignore module with no types
24
25
  } = require('set-delayed-interval')
25
26
  const { DHTPeerRouting } = require('./dht/dht-peer-routing')
27
+ // @ts-expect-error setMaxListeners is missing from the types
28
+ const { setMaxListeners } = require('events')
26
29
 
27
30
  /**
28
31
  * @typedef {import('peer-id')} PeerId
@@ -104,19 +107,24 @@ class PeerRouting {
104
107
  */
105
108
  async findPeer (id, options) { // eslint-disable-line require-await
106
109
  if (!this._routers.length) {
107
- throw errCode(new Error('No peer routers available'), 'NO_ROUTERS_AVAILABLE')
110
+ throw errCode(new Error('No peer routers available'), errors.codes.ERR_NO_ROUTERS_AVAILABLE)
108
111
  }
109
112
 
110
113
  if (id.toB58String() === this._peerId.toB58String()) {
111
- throw errCode(new Error('Should not try to find self'), 'ERR_FIND_SELF')
114
+ throw errCode(new Error('Should not try to find self'), errors.codes.ERR_FIND_SELF)
112
115
  }
113
116
 
114
117
  const output = await pipe(
115
118
  merge(
116
- ...this._routers.map(router => [router.findPeer(id, options)])
119
+ ...this._routers.map(router => (async function * () {
120
+ try {
121
+ yield await router.findPeer(id, options)
122
+ } catch (err) {
123
+ log.error(err)
124
+ }
125
+ })())
117
126
  ),
118
127
  (source) => filter(source, Boolean),
119
- // @ts-ignore findPeer resolves a Promise
120
128
  (source) => storeAddresses(source, this._peerStore),
121
129
  (source) => first(source)
122
130
  )
@@ -125,7 +133,7 @@ class PeerRouting {
125
133
  return output
126
134
  }
127
135
 
128
- throw errCode(new Error('not found'), 'NOT_FOUND')
136
+ throw errCode(new Error(errors.messages.NOT_FOUND), errors.codes.ERR_NOT_FOUND)
129
137
  }
130
138
 
131
139
  /**
@@ -139,11 +147,16 @@ class PeerRouting {
139
147
  */
140
148
  async * getClosestPeers (key, options = { timeout: 30e3 }) {
141
149
  if (!this._routers.length) {
142
- throw errCode(new Error('No peer routers available'), 'NO_ROUTERS_AVAILABLE')
150
+ throw errCode(new Error('No peer routers available'), errors.codes.ERR_NO_ROUTERS_AVAILABLE)
143
151
  }
144
152
 
145
153
  if (options.timeout) {
146
- options.signal = new TimeoutController(options.timeout).signal
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
147
160
  }
148
161
 
149
162
  yield * pipe(
@@ -2,10 +2,7 @@
2
2
 
3
3
  const errcode = require('err-code')
4
4
  const PeerId = require('peer-id')
5
-
6
- const {
7
- codes: { ERR_INVALID_PARAMETERS }
8
- } = require('../errors')
5
+ const { codes } = require('../errors')
9
6
 
10
7
  /**
11
8
  * @param {any} data
@@ -48,7 +45,7 @@ class Book {
48
45
  * @param {any[]|any} data
49
46
  */
50
47
  set (peerId, data) {
51
- throw errcode(new Error('set must be implemented by the subclass'), 'ERR_NOT_IMPLEMENTED')
48
+ throw errcode(new Error('set must be implemented by the subclass'), codes.ERR_NOT_IMPLEMENTED)
52
49
  }
53
50
 
54
51
  /**
@@ -94,7 +91,7 @@ class Book {
94
91
  */
95
92
  get (peerId) {
96
93
  if (!PeerId.isPeerId(peerId)) {
97
- throw errcode(new Error('peerId must be an instance of peer-id'), ERR_INVALID_PARAMETERS)
94
+ throw errcode(new Error('peerId must be an instance of peer-id'), codes.ERR_INVALID_PARAMETERS)
98
95
  }
99
96
 
100
97
  const rec = this.data.get(peerId.toB58String())
@@ -111,7 +108,7 @@ class Book {
111
108
  */
112
109
  delete (peerId) {
113
110
  if (!PeerId.isPeerId(peerId)) {
114
- throw errcode(new Error('peerId must be an instance of peer-id'), ERR_INVALID_PARAMETERS)
111
+ throw errcode(new Error('peerId must be an instance of peer-id'), codes.ERR_INVALID_PARAMETERS)
115
112
  }
116
113
 
117
114
  if (!this.data.delete(peerId.toB58String())) {
package/src/ping/index.js CHANGED
@@ -5,7 +5,7 @@ const log = Object.assign(debug('libp2p:ping'), {
5
5
  error: debug('libp2p:ping:err')
6
6
  })
7
7
  const errCode = require('err-code')
8
-
8
+ const { codes } = require('../errors')
9
9
  const crypto = require('libp2p-crypto')
10
10
  const { pipe } = require('it-pipe')
11
11
  // @ts-ignore it-buffer has no types exported
@@ -50,7 +50,7 @@ async function ping (node, peer) {
50
50
  const end = Date.now()
51
51
 
52
52
  if (!equals(data, result)) {
53
- throw errCode(new Error('Received wrong ping ack'), 'ERR_WRONG_PING_ACK')
53
+ throw errCode(new Error('Received wrong ping ack'), codes.ERR_WRONG_PING_ACK)
54
54
  }
55
55
 
56
56
  return end - start
package/src/upgrader.js CHANGED
@@ -297,7 +297,7 @@ class Upgrader {
297
297
  maConn.timeline.upgraded = Date.now()
298
298
 
299
299
  const errConnectionNotMultiplexed = () => {
300
- throw errCode(new Error('connection is not multiplexed'), 'ERR_CONNECTION_NOT_MULTIPLEXED')
300
+ throw errCode(new Error('connection is not multiplexed'), codes.ERR_CONNECTION_NOT_MULTIPLEXED)
301
301
  }
302
302
 
303
303
  // Create the connection