libp2p 0.40.0 → 0.41.0
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 +21 -2
- package/dist/src/address-manager/index.d.ts.map +1 -1
- package/dist/src/address-manager/index.js +1 -1
- package/dist/src/address-manager/index.js.map +1 -1
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +0 -11
- package/dist/src/config.js.map +1 -1
- package/dist/src/connection/index.d.ts +83 -0
- package/dist/src/connection/index.d.ts.map +1 -0
- package/dist/src/connection/index.js +96 -0
- package/dist/src/connection/index.js.map +1 -0
- package/dist/src/connection-manager/dialer/index.d.ts +13 -14
- package/dist/src/connection-manager/dialer/index.d.ts.map +1 -1
- package/dist/src/connection-manager/dialer/index.js +82 -62
- package/dist/src/connection-manager/dialer/index.js.map +1 -1
- package/dist/src/connection-manager/index.d.ts +2 -10
- package/dist/src/connection-manager/index.d.ts.map +1 -1
- package/dist/src/connection-manager/index.js +21 -53
- package/dist/src/connection-manager/index.js.map +1 -1
- package/dist/src/fetch/index.d.ts.map +1 -1
- package/dist/src/fetch/index.js +15 -3
- package/dist/src/fetch/index.js.map +1 -1
- package/dist/src/get-peer.d.ts +2 -2
- package/dist/src/get-peer.d.ts.map +1 -1
- package/dist/src/get-peer.js +2 -5
- package/dist/src/get-peer.js.map +1 -1
- package/dist/src/index.d.ts +10 -6
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +7 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/keychain/index.d.ts +1 -1
- package/dist/src/keychain/index.d.ts.map +1 -1
- package/dist/src/libp2p.d.ts +3 -3
- package/dist/src/libp2p.d.ts.map +1 -1
- package/dist/src/libp2p.js +2 -3
- package/dist/src/libp2p.js.map +1 -1
- package/dist/src/registrar.d.ts +5 -0
- package/dist/src/registrar.d.ts.map +1 -1
- package/dist/src/registrar.js +25 -0
- package/dist/src/registrar.js.map +1 -1
- package/dist/src/transport-manager.d.ts.map +1 -1
- package/dist/src/transport-manager.js +1 -2
- package/dist/src/transport-manager.js.map +1 -1
- package/dist/src/upgrader.d.ts +1 -1
- package/dist/src/upgrader.d.ts.map +1 -1
- package/dist/src/upgrader.js +46 -59
- package/dist/src/upgrader.js.map +1 -1
- package/package.json +9 -10
- package/src/address-manager/index.ts +3 -2
- package/src/circuit/README.md +6 -6
- package/src/config.ts +0 -11
- package/src/connection/index.ts +171 -0
- package/src/connection-manager/dialer/index.ts +100 -75
- package/src/connection-manager/index.ts +21 -58
- package/src/fetch/index.ts +16 -3
- package/src/get-peer.ts +3 -7
- package/src/index.ts +15 -7
- package/src/keychain/index.ts +1 -1
- package/src/libp2p.ts +5 -6
- package/src/registrar.ts +29 -2
- package/src/transport-manager.ts +1 -2
- package/src/upgrader.ts +51 -64
- package/src/version.ts +1 -1
- package/dist/src/metrics/index.d.ts +0 -93
- package/dist/src/metrics/index.d.ts.map +0 -1
- package/dist/src/metrics/index.js +0 -234
- package/dist/src/metrics/index.js.map +0 -1
- package/dist/src/metrics/moving-average.d.ts +0 -14
- package/dist/src/metrics/moving-average.d.ts.map +0 -1
- package/dist/src/metrics/moving-average.js +0 -40
- package/dist/src/metrics/moving-average.js.map +0 -1
- package/dist/src/metrics/stats.d.ts +0 -87
- package/dist/src/metrics/stats.d.ts.map +0 -1
- package/dist/src/metrics/stats.js +0 -183
- package/dist/src/metrics/stats.js.map +0 -1
- package/src/metrics/index.ts +0 -311
- package/src/metrics/moving-average.ts +0 -53
- package/src/metrics/stats.ts +0 -238
package/README.md
CHANGED
|
@@ -18,9 +18,7 @@
|
|
|
18
18
|
<p align="center">
|
|
19
19
|
<a href="https://github.com/libp2p/js-libp2p/actions?query=branch%3Amaster+workflow%3Aci+"><img src="https://img.shields.io/github/workflow/status/libp2p/js-libp2p/ci?label=ci&style=flat-square" /></a>
|
|
20
20
|
<a href="https://codecov.io/gh/libp2p/js-libp2p"><img src="https://img.shields.io/codecov/c/github/libp2p/js-libp2p/master.svg?style=flat-square"></a>
|
|
21
|
-
<a href="https://bundlephobia.com/result?p=ipfsd-ctl"><img src="https://flat.badgen.net/bundlephobia/minzip/ipfsd-ctl"></a>
|
|
22
21
|
<br>
|
|
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
22
|
<a href="https://github.com/feross/standard"><img src="https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square"></a>
|
|
25
23
|
<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
24
|
<a href=""><img src="https://img.shields.io/badge/npm-%3E%3D7.0.0-orange.svg?style=flat-square" /></a>
|
|
@@ -42,6 +40,7 @@ If you are looking for the documentation of the latest release, you can view the
|
|
|
42
40
|
## Table of Contents <!-- omit in toc -->
|
|
43
41
|
|
|
44
42
|
- [Background](#background)
|
|
43
|
+
- [Roadmap](#roadmap)
|
|
45
44
|
- [Install](#install)
|
|
46
45
|
- [Usage](#usage)
|
|
47
46
|
- [Configuration](#configuration)
|
|
@@ -74,6 +73,14 @@ We are in the process of writing better documentation, blog posts, tutorials and
|
|
|
74
73
|
|
|
75
74
|
To sum up, libp2p is a "network stack" -- a protocol suite -- that cleanly separates concerns, and enables sophisticated applications to only use the protocols they absolutely need, without giving up interoperability and upgradeability. libp2p grew out of IPFS, but it is built so that lots of people can use it, for lots of different projects.
|
|
76
75
|
|
|
76
|
+
## Roadmap
|
|
77
|
+
|
|
78
|
+
The js-libp2p roadmap can be found here: https://github.com/libp2p/js-libp2p/blob/master/ROADMAP.md
|
|
79
|
+
|
|
80
|
+
It represents current projects the js-libp2p maintainers are focused on and provides an estimation of completion targets.
|
|
81
|
+
|
|
82
|
+
It is complementary to the overarching libp2p project roadmap: https://github.com/libp2p/specs/blob/master/ROADMAP.md
|
|
83
|
+
|
|
77
84
|
## Install
|
|
78
85
|
|
|
79
86
|
```sh
|
|
@@ -175,6 +182,18 @@ List of packages currently in existence for libp2p
|
|
|
175
182
|
| [`libp2p-nat-mgnr`](//github.com/libp2p/js-libp2p-nat-mgnr) | [](//github.com/libp2p/js-libp2p-nat-mgnr/releases) | [](https://david-dm.org/libp2p/js-libp2p-nat-mgnr) | [](https://travis-ci.com/libp2p/js-libp2p-nat-mgnr) | [](https://codecov.io/gh/libp2p/js-libp2p-nat-mgnr) | N/A |
|
|
176
183
|
| [`libp2p-utils`](//github.com/libp2p/js-libp2p-utils) | [](//github.com/libp2p/js-libp2p-utils/releases) | [](https://david-dm.org/libp2p/js-libp2p-utils) | [](https://travis-ci.com/libp2p/js-libp2p-utils) | [](https://codecov.io/gh/libp2p/js-libp2p-utils) | [Vasco Santos](mailto:santos.vasco10@gmail.com) |
|
|
177
184
|
|
|
185
|
+
## Used by
|
|
186
|
+
|
|
187
|
+
<div style="padding: 20px">
|
|
188
|
+
<p align="middle">
|
|
189
|
+
<a href="https://lodestar.chainsafe.io/"><img width="300" src="https://github.com/ChainSafe/lodestar/blob/unstable/assets/lodestar_icon_text_black_stroke.png?raw=true"></a>
|
|
190
|
+
<a href="https://hoprnet.org/"><img width="150" src="https://github.com/hoprnet/hopr-assets/blob/master/v1/logo/hopr_logo_padded.png?raw=true" alt="HOPR Logo">
|
|
191
|
+
<a href="https:/https://js.ipfs.io/"><img src="https://ipfs.io/ipfs/Qme6KJdKcp85TYbLxuLV7oQzMiLremD7HMoXLZEmgo6Rnh/js-ipfs-sticker.png" alt="IPFS in JavaScript logo" width="150" /></a>
|
|
192
|
+
</p>
|
|
193
|
+
</div>
|
|
194
|
+
|
|
195
|
+
And [many others...](https://github.com/libp2p/js-libp2p/network/dependents)
|
|
196
|
+
|
|
178
197
|
## Contribute
|
|
179
198
|
|
|
180
199
|
The libp2p implementation in JavaScript is a work in progress. As such, there are a few things you can do right now to help out:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/address-manager/index.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AAC,EAAE,aAAa,CAAA;IAE9B;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;IAEjB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;IAEnB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;CACtB;AAED,MAAM,WAAW,+BAA+B;IAC9C,MAAM,EAAE,MAAM,CAAA;IACd,gBAAgB,EAAE,gBAAgB,CAAA;CACnC;AAED,MAAM,WAAW,aAAa;IAC5B,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,SAAS,EAAE,CAAA;CAClC;AAID,qBAAa,qBAAsB,SAAQ,YAAY,CAAC,oBAAoB,CAAC;IAC3E,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAiC;IAE5D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAU;IACjC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAa;IACtC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAa;IACtC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAe;IAE9C;;;;;OAKG;gBACU,UAAU,EAAE,+BAA+B,EAAE,IAAI,EAAE,kBAAkB;IAYlF;;OAEG;IACH,cAAc,IAAK,SAAS,EAAE;IAI9B;;OAEG;IACH,gBAAgB,IAAK,SAAS,EAAE;IAIhC;;OAEG;IACH,gBAAgB,IAAK,SAAS,EAAE;IAIhC;;;;OAIG;IACH,mBAAmB,CAAE,IAAI,EAAE,SAAS,GAAG,IAAI;IAI3C;;;OAGG;IACH,kBAAkB,CAAE,IAAI,EAAE,SAAS,GAAG,IAAI;IAI1C;;OAEG;IACH,eAAe,CAAE,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI;IAyBhD,YAAY,IAAK,SAAS,EAAE;CAwB7B"}
|
|
@@ -13,7 +13,7 @@ export class DefaultAddressManager extends EventEmitter {
|
|
|
13
13
|
super();
|
|
14
14
|
const { listen = [], announce = [] } = init;
|
|
15
15
|
this.components = components;
|
|
16
|
-
this.listen =
|
|
16
|
+
this.listen = listen.map(ma => ma.toString());
|
|
17
17
|
this.announce = new Set(announce.map(ma => ma.toString()));
|
|
18
18
|
this.observed = new Set();
|
|
19
19
|
this.announceFilter = init.announceFilter ?? defaultAddressFilter;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/address-manager/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAErE,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAgClD,MAAM,oBAAoB,GAAG,CAAC,KAAkB,EAAe,EAAE,CAAC,KAAK,CAAA;AAEvE,MAAM,OAAO,qBAAsB,SAAQ,YAAkC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/address-manager/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAErE,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAgClD,MAAM,oBAAoB,GAAG,CAAC,KAAkB,EAAe,EAAE,CAAC,KAAK,CAAA;AAEvE,MAAM,OAAO,qBAAsB,SAAQ,YAAkC;IAQ3E;;;;;OAKG;IACH,YAAa,UAA2C,EAAE,IAAwB;QAChF,KAAK,EAAE,CAAA;QAEP,MAAM,EAAE,MAAM,GAAG,EAAE,EAAE,QAAQ,GAAG,EAAE,EAAE,GAAG,IAAI,CAAA;QAE3C,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAA;QAC7C,IA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CAAC,CAAC;aAC3B,GAAG,CAAC,EAAE,CAAC,EAAE;YACR,IAAI,EAAE,CAAC,SAAS,EAAE,KAAK,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE;gBACxD,OAAO,EAAE,CAAA;aACV;YAED,OAAO,EAAE,CAAC,WAAW,CAAC,QAAQ,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA;QACpE,CAAC,CAAC,CAAA;IACN,CAAC;CACF"}
|
package/dist/src/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAG5C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAG5C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAmF1D,wBAAgB,cAAc,CAAE,IAAI,EAAE,gBAAgB,CAAC,UAAU,CAAC,GAAG,UAAU,CAyB9E"}
|
package/dist/src/config.js
CHANGED
|
@@ -33,17 +33,6 @@ const DefaultConfig = {
|
|
|
33
33
|
transportManager: {
|
|
34
34
|
faultTolerance: FaultTolerance.FATAL_ALL
|
|
35
35
|
},
|
|
36
|
-
metrics: {
|
|
37
|
-
enabled: false,
|
|
38
|
-
computeThrottleMaxQueueSize: 1000,
|
|
39
|
-
computeThrottleTimeout: 2000,
|
|
40
|
-
movingAverageIntervals: [
|
|
41
|
-
60 * 1000,
|
|
42
|
-
5 * 60 * 1000,
|
|
43
|
-
15 * 60 * 1000 // 15 minutes
|
|
44
|
-
],
|
|
45
|
-
maxOldPeersRetention: 50
|
|
46
|
-
},
|
|
47
36
|
peerRouting: {
|
|
48
37
|
refreshManager: {
|
|
49
38
|
enabled: true,
|
package/dist/src/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAA;AACnE,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACpD,OAAO,KAAK,cAAc,MAAM,wBAAwB,CAAA;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAA;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAGvD,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,OAAO,MAAM,UAAU,CAAA;AAE9B,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,cAAc,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAE9G,MAAM,aAAa,GAAwB;IACzC,SAAS,EAAE;QACT,MAAM,EAAE,EAAE;QACV,QAAQ,EAAE,EAAE;QACZ,UAAU,EAAE,EAAE;QACd,cAAc,EAAE,CAAC,UAAuB,EAAE,EAAE,CAAC,UAAU;KACxD;IACD,iBAAiB,EAAE;QACjB,cAAc,EAAE,GAAG;QACnB,cAAc,EAAE,EAAE;QAClB,QAAQ,EAAE,IAAI;QACd,gBAAgB,EAAE,KAAK;QACvB,gBAAgB,EAAE,SAAS,CAAC,kBAAkB;QAC9C,eAAe,EAAE,SAAS,CAAC,kBAAkB;QAC7C,WAAW,EAAE,SAAS,CAAC,YAAY;QACnC,qBAAqB,EAAE,SAAS,CAAC,uBAAuB;QACxD,SAAS,EAAE;YACT,OAAO,EAAE,eAA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r';
|
|
2
|
+
import { symbol } from '@libp2p/interface-connection';
|
|
3
|
+
import type { Connection, ConnectionStat, Stream } from '@libp2p/interface-connection';
|
|
4
|
+
import type { PeerId } from '@libp2p/interface-peer-id';
|
|
5
|
+
import type { AbortOptions } from '@libp2p/interfaces';
|
|
6
|
+
interface ConnectionInit {
|
|
7
|
+
remoteAddr: Multiaddr;
|
|
8
|
+
remotePeer: PeerId;
|
|
9
|
+
newStream: (protocols: string[], options?: AbortOptions) => Promise<Stream>;
|
|
10
|
+
close: () => Promise<void>;
|
|
11
|
+
getStreams: () => Stream[];
|
|
12
|
+
stat: ConnectionStat;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* An implementation of the js-libp2p connection.
|
|
16
|
+
* Any libp2p transport should use an upgrader to return this connection.
|
|
17
|
+
*/
|
|
18
|
+
export declare class ConnectionImpl implements Connection {
|
|
19
|
+
/**
|
|
20
|
+
* Connection identifier.
|
|
21
|
+
*/
|
|
22
|
+
readonly id: string;
|
|
23
|
+
/**
|
|
24
|
+
* Observed multiaddr of the remote peer
|
|
25
|
+
*/
|
|
26
|
+
readonly remoteAddr: Multiaddr;
|
|
27
|
+
/**
|
|
28
|
+
* Remote peer id
|
|
29
|
+
*/
|
|
30
|
+
readonly remotePeer: PeerId;
|
|
31
|
+
/**
|
|
32
|
+
* Connection metadata
|
|
33
|
+
*/
|
|
34
|
+
readonly stat: ConnectionStat;
|
|
35
|
+
/**
|
|
36
|
+
* User provided tags
|
|
37
|
+
*
|
|
38
|
+
*/
|
|
39
|
+
tags: string[];
|
|
40
|
+
/**
|
|
41
|
+
* Reference to the new stream function of the multiplexer
|
|
42
|
+
*/
|
|
43
|
+
private readonly _newStream;
|
|
44
|
+
/**
|
|
45
|
+
* Reference to the close function of the raw connection
|
|
46
|
+
*/
|
|
47
|
+
private readonly _close;
|
|
48
|
+
/**
|
|
49
|
+
* Reference to the getStreams function of the muxer
|
|
50
|
+
*/
|
|
51
|
+
private readonly _getStreams;
|
|
52
|
+
private _closing;
|
|
53
|
+
/**
|
|
54
|
+
* An implementation of the js-libp2p connection.
|
|
55
|
+
* Any libp2p transport should use an upgrader to return this connection.
|
|
56
|
+
*/
|
|
57
|
+
constructor(init: ConnectionInit);
|
|
58
|
+
get [Symbol.toStringTag](): string;
|
|
59
|
+
get [symbol](): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Get all the streams of the muxer
|
|
62
|
+
*/
|
|
63
|
+
get streams(): Stream[];
|
|
64
|
+
/**
|
|
65
|
+
* Create a new stream from this connection
|
|
66
|
+
*/
|
|
67
|
+
newStream(protocols: string | string[], options?: AbortOptions): Promise<Stream>;
|
|
68
|
+
/**
|
|
69
|
+
* Add a stream when it is opened to the registry
|
|
70
|
+
*/
|
|
71
|
+
addStream(stream: Stream): void;
|
|
72
|
+
/**
|
|
73
|
+
* Remove stream registry after it is closed
|
|
74
|
+
*/
|
|
75
|
+
removeStream(id: string): void;
|
|
76
|
+
/**
|
|
77
|
+
* Close the connection
|
|
78
|
+
*/
|
|
79
|
+
close(): Promise<void>;
|
|
80
|
+
}
|
|
81
|
+
export declare function createConnection(init: ConnectionInit): Connection;
|
|
82
|
+
export {};
|
|
83
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/connection/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAGxD,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAA;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAA;AACtF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AAEvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAItD,UAAU,cAAc;IACtB,UAAU,EAAE,SAAS,CAAA;IACrB,UAAU,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GAAG,UAAU,CAElE"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import errCode from 'err-code';
|
|
2
|
+
import { OPEN, CLOSING, CLOSED } from '@libp2p/interface-connection/status';
|
|
3
|
+
import { symbol } from '@libp2p/interface-connection';
|
|
4
|
+
import { logger } from '@libp2p/logger';
|
|
5
|
+
const log = logger('libp2p:connection');
|
|
6
|
+
/**
|
|
7
|
+
* An implementation of the js-libp2p connection.
|
|
8
|
+
* Any libp2p transport should use an upgrader to return this connection.
|
|
9
|
+
*/
|
|
10
|
+
export class ConnectionImpl {
|
|
11
|
+
/**
|
|
12
|
+
* An implementation of the js-libp2p connection.
|
|
13
|
+
* Any libp2p transport should use an upgrader to return this connection.
|
|
14
|
+
*/
|
|
15
|
+
constructor(init) {
|
|
16
|
+
const { remoteAddr, remotePeer, newStream, close, getStreams, stat } = init;
|
|
17
|
+
this.id = `${(parseInt(String(Math.random() * 1e9))).toString(36)}${Date.now()}`;
|
|
18
|
+
this.remoteAddr = remoteAddr;
|
|
19
|
+
this.remotePeer = remotePeer;
|
|
20
|
+
this.stat = {
|
|
21
|
+
...stat,
|
|
22
|
+
status: OPEN
|
|
23
|
+
};
|
|
24
|
+
this._newStream = newStream;
|
|
25
|
+
this._close = close;
|
|
26
|
+
this._getStreams = getStreams;
|
|
27
|
+
this.tags = [];
|
|
28
|
+
this._closing = false;
|
|
29
|
+
}
|
|
30
|
+
get [Symbol.toStringTag]() {
|
|
31
|
+
return 'Connection';
|
|
32
|
+
}
|
|
33
|
+
get [symbol]() {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Get all the streams of the muxer
|
|
38
|
+
*/
|
|
39
|
+
get streams() {
|
|
40
|
+
return this._getStreams();
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Create a new stream from this connection
|
|
44
|
+
*/
|
|
45
|
+
async newStream(protocols, options) {
|
|
46
|
+
if (this.stat.status === CLOSING) {
|
|
47
|
+
throw errCode(new Error('the connection is being closed'), 'ERR_CONNECTION_BEING_CLOSED');
|
|
48
|
+
}
|
|
49
|
+
if (this.stat.status === CLOSED) {
|
|
50
|
+
throw errCode(new Error('the connection is closed'), 'ERR_CONNECTION_CLOSED');
|
|
51
|
+
}
|
|
52
|
+
if (!Array.isArray(protocols)) {
|
|
53
|
+
protocols = [protocols];
|
|
54
|
+
}
|
|
55
|
+
const stream = await this._newStream(protocols, options);
|
|
56
|
+
stream.stat.direction = 'outbound';
|
|
57
|
+
return stream;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Add a stream when it is opened to the registry
|
|
61
|
+
*/
|
|
62
|
+
addStream(stream) {
|
|
63
|
+
stream.stat.direction = 'inbound';
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Remove stream registry after it is closed
|
|
67
|
+
*/
|
|
68
|
+
removeStream(id) {
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Close the connection
|
|
72
|
+
*/
|
|
73
|
+
async close() {
|
|
74
|
+
if (this.stat.status === CLOSED || this._closing) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
this.stat.status = CLOSING;
|
|
78
|
+
// close all streams - this can throw if we're not multiplexed
|
|
79
|
+
try {
|
|
80
|
+
this.streams.forEach(s => s.close());
|
|
81
|
+
}
|
|
82
|
+
catch (err) {
|
|
83
|
+
log.error(err);
|
|
84
|
+
}
|
|
85
|
+
// Close raw connection
|
|
86
|
+
this._closing = true;
|
|
87
|
+
await this._close();
|
|
88
|
+
this._closing = false;
|
|
89
|
+
this.stat.timeline.close = Date.now();
|
|
90
|
+
this.stat.status = CLOSED;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
export function createConnection(init) {
|
|
94
|
+
return new ConnectionImpl(init);
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["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GAAG,CAAC,CAAA;SACf;QAED,uBAAuB;QACvB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAA;QACpB,MAAM,IAAI,CAAC,MAAM,EAAE,CAAA;QACnB,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAA;QAErB,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QACrC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IAC3B,CAAC;CACF;AAED,MAAM,UAAU,gBAAgB,CAAE,IAAoB;IACpD,OAAO,IAAI,cAAc,CAAC,IAAI,CAAC,CAAA;AACjC,CAAC"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Multiaddr, Resolver } from '@multiformats/multiaddr';
|
|
2
2
|
import { TimeoutController } from 'timeout-abort-controller';
|
|
3
3
|
import { DialRequest } from './dial-request.js';
|
|
4
4
|
import type { Connection, ConnectionGater } from '@libp2p/interface-connection';
|
|
5
5
|
import type { AbortOptions } from '@libp2p/interfaces';
|
|
6
6
|
import type { Startable } from '@libp2p/interfaces/startable';
|
|
7
|
-
import
|
|
7
|
+
import { PeerId } from '@libp2p/interface-peer-id';
|
|
8
8
|
import type { AddressSorter, PeerStore } from '@libp2p/interface-peer-store';
|
|
9
|
-
import type {
|
|
9
|
+
import type { Metrics } from '@libp2p/interface-metrics';
|
|
10
10
|
import type { Dialer } from '@libp2p/interface-connection-manager';
|
|
11
11
|
import type { TransportManager } from '@libp2p/interface-transport';
|
|
12
12
|
export interface DialTarget {
|
|
@@ -48,7 +48,6 @@ export interface DialerInit {
|
|
|
48
48
|
* Multiaddr resolvers to use when dialing
|
|
49
49
|
*/
|
|
50
50
|
resolvers?: Record<string, Resolver>;
|
|
51
|
-
metrics?: ComponentMetricsTracker;
|
|
52
51
|
}
|
|
53
52
|
export interface DefaultDialerComponents {
|
|
54
53
|
peerId: PeerId;
|
|
@@ -65,7 +64,7 @@ export declare class DefaultDialer implements Startable, Dialer {
|
|
|
65
64
|
private readonly maxDialsPerPeer;
|
|
66
65
|
tokens: number[];
|
|
67
66
|
pendingDials: Map<string, PendingDial>;
|
|
68
|
-
pendingDialTargets: Map<string,
|
|
67
|
+
pendingDialTargets: Map<string, AbortController>;
|
|
69
68
|
private started;
|
|
70
69
|
constructor(components: DefaultDialerComponents, init?: DialerInit);
|
|
71
70
|
isStarted(): boolean;
|
|
@@ -79,20 +78,20 @@ export declare class DefaultDialer implements Startable, Dialer {
|
|
|
79
78
|
* The dial to the first address that is successfully able to upgrade a connection
|
|
80
79
|
* will be used.
|
|
81
80
|
*/
|
|
82
|
-
dial(
|
|
83
|
-
/**
|
|
84
|
-
* Connects to a given `peer` by dialing all of its known addresses.
|
|
85
|
-
* The dial to the first address that is successfully able to upgrade a connection
|
|
86
|
-
* will be used.
|
|
87
|
-
*/
|
|
88
|
-
_createCancellableDialTarget(peer: PeerId, options: AbortOptions): Promise<DialTarget>;
|
|
81
|
+
dial(peerIdOrMultiaddr: PeerId | Multiaddr, options?: AbortOptions): Promise<Connection>;
|
|
89
82
|
/**
|
|
90
83
|
* Creates a DialTarget. The DialTarget is used to create and track
|
|
91
84
|
* the DialRequest to a given peer.
|
|
92
|
-
*
|
|
85
|
+
*
|
|
86
|
+
* If a multiaddr is received it should be the only address attempted.
|
|
87
|
+
*
|
|
93
88
|
* Multiaddrs not supported by the available transports will be filtered out.
|
|
94
89
|
*/
|
|
95
|
-
_createDialTarget(
|
|
90
|
+
_createDialTarget(peerIdOrMultiaddr: PeerId | Multiaddr, options: AbortOptions): Promise<DialTarget>;
|
|
91
|
+
/**
|
|
92
|
+
* Loads a list of addresses from the peer store for the passed peer id
|
|
93
|
+
*/
|
|
94
|
+
_loadAddresses(peer: PeerId): Promise<Multiaddr[]>;
|
|
96
95
|
/**
|
|
97
96
|
* Creates a PendingDial that wraps the underlying DialRequest
|
|
98
97
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/connection-manager/dialer/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/connection-manager/dialer/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAe,SAAS,EAAE,QAAQ,EAAwB,MAAM,yBAAyB,CAAA;AAChG,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAG5D,OAAO,EAAc,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAU3D,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAA;AAC/E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;AAC7D,OAAO,EAAY,MAAM,EAAE,MAAM,2BAA2B,CAAA;AAE5D,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;AAC5E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAA;AACxD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sCAAsC,CAAA;AAClE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAA;AAInE,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,SAAS,EAAE,CAAA;CACnB;AAED,MAAM,WAAW,WAAW;IAC1B,WAAW,EAAE,WAAW,CAAA;IACxB,UAAU,EAAE,iBAAiB,CAAA;IAC7B,OAAO,EAAE,OAAO,CAAC,UAAU,CAAC,CAAA;IAC5B,OAAO,EAAE,MAAM,IAAI,CAAA;CACpB;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAA;IAC7B,MAAM,EAAE,CAAC,GAAG,EAAE,KAAK,KAAK,IAAI,CAA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C;IAmEnG;;;;;;;OAOG;IACG,iBAAiB,CAAE,iBAAiB,EAAE,MAAM,GAAG,SAAS,EAAE,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC;IAwC3G;;OAEG;IACG,cAAc,CAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;IAoBzD;;OAEG;IACH,kBAAkB,CAAE,UAAU,EAAE,UAAU,EAAE,OAAO,GAAE,YAAiB,GAAG,WAAW;IAkDpF,SAAS,CAAE,GAAG,EAAE,MAAM;IAOtB,YAAY,CAAE,KAAK,EAAE,MAAM;IAU3B;;OAEG;IACG,QAAQ,CAAE,EAAE,EAAE,SAAS,EAAE,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;IAwB3E;;OAEG;IACG,cAAc,CAAE,EAAE,EAAE,SAAS,EAAE,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;CAUlF"}
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import { logger } from '@libp2p/logger';
|
|
2
|
-
import all from 'it-all';
|
|
3
|
-
import filter from 'it-filter';
|
|
4
|
-
import { pipe } from 'it-pipe';
|
|
5
2
|
import errCode from 'err-code';
|
|
6
|
-
import { multiaddr, resolvers } from '@multiformats/multiaddr';
|
|
3
|
+
import { isMultiaddr, multiaddr, resolvers } from '@multiformats/multiaddr';
|
|
7
4
|
import { TimeoutController } from 'timeout-abort-controller';
|
|
8
|
-
import { AbortError } from '@libp2p/interfaces/errors';
|
|
9
5
|
import { anySignal } from 'any-signal';
|
|
10
6
|
import { setMaxListeners } from 'events';
|
|
11
7
|
import { DialRequest } from './dial-request.js';
|
|
@@ -13,13 +9,9 @@ import { publicAddressesFirst } from '@libp2p/utils/address-sort';
|
|
|
13
9
|
import { trackedMap } from '@libp2p/tracked-map';
|
|
14
10
|
import { codes } from '../../errors.js';
|
|
15
11
|
import { DIAL_TIMEOUT, MAX_PARALLEL_DIALS, MAX_PER_PEER_DIALS, MAX_ADDRS_TO_DIAL } from '../../constants.js';
|
|
12
|
+
import { isPeerId } from '@libp2p/interface-peer-id';
|
|
16
13
|
import { getPeer } from '../../get-peer.js';
|
|
17
|
-
import sort from 'it-sort';
|
|
18
|
-
import map from 'it-map';
|
|
19
14
|
const log = logger('libp2p:dialer');
|
|
20
|
-
const METRICS_COMPONENT = 'dialler';
|
|
21
|
-
const METRICS_PENDING_DIALS = 'pending-dials';
|
|
22
|
-
const METRICS_PENDING_DIAL_TARGETS = 'pending-dial-targets';
|
|
23
15
|
export class DefaultDialer {
|
|
24
16
|
constructor(components, init = {}) {
|
|
25
17
|
this.started = false;
|
|
@@ -30,13 +22,11 @@ export class DefaultDialer {
|
|
|
30
22
|
this.tokens = [...new Array(init.maxParallelDials ?? MAX_PARALLEL_DIALS)].map((_, index) => index);
|
|
31
23
|
this.components = components;
|
|
32
24
|
this.pendingDials = trackedMap({
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
metrics: init.metrics
|
|
25
|
+
name: 'libp2p_dialler_pending_dials',
|
|
26
|
+
metrics: components.metrics
|
|
36
27
|
});
|
|
37
28
|
this.pendingDialTargets = trackedMap({
|
|
38
|
-
|
|
39
|
-
metric: METRICS_PENDING_DIAL_TARGETS,
|
|
29
|
+
name: 'libp2p_dialler_pending_dial_targets',
|
|
40
30
|
metrics: components.metrics
|
|
41
31
|
});
|
|
42
32
|
for (const [key, value] of Object.entries(init.resolvers ?? {})) {
|
|
@@ -64,7 +54,7 @@ export class DefaultDialer {
|
|
|
64
54
|
}
|
|
65
55
|
this.pendingDials.clear();
|
|
66
56
|
for (const pendingTarget of this.pendingDialTargets.values()) {
|
|
67
|
-
pendingTarget.
|
|
57
|
+
pendingTarget.abort();
|
|
68
58
|
}
|
|
69
59
|
this.pendingDialTargets.clear();
|
|
70
60
|
}
|
|
@@ -73,8 +63,8 @@ export class DefaultDialer {
|
|
|
73
63
|
* The dial to the first address that is successfully able to upgrade a connection
|
|
74
64
|
* will be used.
|
|
75
65
|
*/
|
|
76
|
-
async dial(
|
|
77
|
-
const { id, multiaddrs } = getPeer(
|
|
66
|
+
async dial(peerIdOrMultiaddr, options = {}) {
|
|
67
|
+
const { id, multiaddrs } = getPeer(peerIdOrMultiaddr);
|
|
78
68
|
if (this.components.peerId.equals(id)) {
|
|
79
69
|
throw errCode(new Error('Tried to dial self'), codes.ERR_DIALED_SELF);
|
|
80
70
|
}
|
|
@@ -87,11 +77,31 @@ export class DefaultDialer {
|
|
|
87
77
|
throw errCode(new Error('The dial request is blocked by gater.allowDialPeer'), codes.ERR_PEER_DIAL_INTERCEPTED);
|
|
88
78
|
}
|
|
89
79
|
log('creating dial target for %p', id);
|
|
90
|
-
|
|
80
|
+
// resolving multiaddrs can involve dns lookups so allow them to be aborted
|
|
81
|
+
const controller = new AbortController();
|
|
82
|
+
const controllerId = randomId();
|
|
83
|
+
this.pendingDialTargets.set(controllerId, controller);
|
|
84
|
+
let signal = controller.signal;
|
|
85
|
+
// merge with the passed signal, if any
|
|
86
|
+
if (options.signal != null) {
|
|
87
|
+
signal = anySignal([signal, options.signal]);
|
|
88
|
+
}
|
|
89
|
+
let dialTarget;
|
|
90
|
+
try {
|
|
91
|
+
dialTarget = await this._createDialTarget(peerIdOrMultiaddr, {
|
|
92
|
+
...options,
|
|
93
|
+
signal
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
finally {
|
|
97
|
+
// done resolving the multiaddrs so remove the abort controller
|
|
98
|
+
this.pendingDialTargets.delete(controllerId);
|
|
99
|
+
}
|
|
91
100
|
if (dialTarget.addrs.length === 0) {
|
|
92
101
|
throw errCode(new Error('The dial request has no valid addresses'), codes.ERR_NO_VALID_ADDRESSES);
|
|
93
102
|
}
|
|
94
|
-
|
|
103
|
+
// try to join an in-flight dial for this peer if one is available
|
|
104
|
+
const pendingDial = this.pendingDials.get(dialTarget.id.toString()) ?? this._createPendingDial(dialTarget, options);
|
|
95
105
|
try {
|
|
96
106
|
const connection = await pendingDial.promise;
|
|
97
107
|
log('dial succeeded to %s', dialTarget.id);
|
|
@@ -110,61 +120,59 @@ export class DefaultDialer {
|
|
|
110
120
|
pendingDial.destroy();
|
|
111
121
|
}
|
|
112
122
|
}
|
|
113
|
-
/**
|
|
114
|
-
* Connects to a given `peer` by dialing all of its known addresses.
|
|
115
|
-
* The dial to the first address that is successfully able to upgrade a connection
|
|
116
|
-
* will be used.
|
|
117
|
-
*/
|
|
118
|
-
async _createCancellableDialTarget(peer, options) {
|
|
119
|
-
// Make dial target promise cancellable
|
|
120
|
-
const id = `${(parseInt(String(Math.random() * 1e9), 10)).toString()}${Date.now()}`;
|
|
121
|
-
const cancellablePromise = new Promise((resolve, reject) => {
|
|
122
|
-
this.pendingDialTargets.set(id, { resolve, reject });
|
|
123
|
-
});
|
|
124
|
-
try {
|
|
125
|
-
const dialTarget = await Promise.race([
|
|
126
|
-
this._createDialTarget(peer, options),
|
|
127
|
-
cancellablePromise
|
|
128
|
-
]);
|
|
129
|
-
return dialTarget;
|
|
130
|
-
}
|
|
131
|
-
finally {
|
|
132
|
-
this.pendingDialTargets.delete(id);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
123
|
/**
|
|
136
124
|
* Creates a DialTarget. The DialTarget is used to create and track
|
|
137
125
|
* the DialRequest to a given peer.
|
|
138
|
-
*
|
|
126
|
+
*
|
|
127
|
+
* If a multiaddr is received it should be the only address attempted.
|
|
128
|
+
*
|
|
139
129
|
* Multiaddrs not supported by the available transports will be filtered out.
|
|
140
130
|
*/
|
|
141
|
-
async _createDialTarget(
|
|
131
|
+
async _createDialTarget(peerIdOrMultiaddr, options) {
|
|
142
132
|
const _resolve = this._resolve.bind(this);
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
},
|
|
152
|
-
// Multiaddrs not supported by the available transports will be filtered out.
|
|
153
|
-
(source) => filter(source, (ma) => Boolean(this.components.transportManager.transportForMultiaddr(ma))), (source) => map(source, (ma) => {
|
|
154
|
-
if (peer.toString() === ma.getPeerId()) {
|
|
155
|
-
return ma;
|
|
156
|
-
}
|
|
157
|
-
return ma.encapsulate(`/p2p/${peer.toString()}`);
|
|
158
|
-
}), async (source) => await all(source));
|
|
133
|
+
let addrs = isMultiaddr(peerIdOrMultiaddr) ? [peerIdOrMultiaddr] : await this._loadAddresses(peerIdOrMultiaddr);
|
|
134
|
+
addrs = (await Promise.all(addrs.map(async (ma) => await _resolve(ma, options))))
|
|
135
|
+
.flat()
|
|
136
|
+
// Multiaddrs not supported by the available transports will be filtered out.
|
|
137
|
+
.filter(ma => Boolean(this.components.transportManager.transportForMultiaddr(ma)));
|
|
138
|
+
// deduplicate addresses
|
|
139
|
+
addrs = [...new Set(addrs)];
|
|
159
140
|
if (addrs.length > this.maxAddrsToDial) {
|
|
160
|
-
await this.components.peerStore.delete(peer);
|
|
161
141
|
throw errCode(new Error('dial with more addresses than allowed'), codes.ERR_TOO_MANY_ADDRESSES);
|
|
162
142
|
}
|
|
143
|
+
const peerId = isPeerId(peerIdOrMultiaddr) ? peerIdOrMultiaddr : undefined;
|
|
144
|
+
if (peerId != null) {
|
|
145
|
+
const peerIdMultiaddr = `/p2p/${peerId.toString()}`;
|
|
146
|
+
addrs = addrs.map(addr => {
|
|
147
|
+
const addressPeerId = addr.getPeerId();
|
|
148
|
+
if (addressPeerId == null || !peerId.equals(addressPeerId)) {
|
|
149
|
+
return addr.encapsulate(peerIdMultiaddr);
|
|
150
|
+
}
|
|
151
|
+
return addr;
|
|
152
|
+
});
|
|
153
|
+
}
|
|
163
154
|
return {
|
|
164
|
-
id:
|
|
155
|
+
id: peerId == null ? randomId() : peerId.toString(),
|
|
165
156
|
addrs
|
|
166
157
|
};
|
|
167
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* Loads a list of addresses from the peer store for the passed peer id
|
|
161
|
+
*/
|
|
162
|
+
async _loadAddresses(peer) {
|
|
163
|
+
const addresses = await this.components.peerStore.addressBook.get(peer);
|
|
164
|
+
return (await Promise.all(addresses.map(async (address) => {
|
|
165
|
+
const deny = await this.components.connectionGater.denyDialMultiaddr(peer, address.multiaddr);
|
|
166
|
+
if (deny) {
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
return address;
|
|
170
|
+
})))
|
|
171
|
+
.filter(isTruthy)
|
|
172
|
+
// Sort addresses so, for example, we try certified public address first
|
|
173
|
+
.sort(this.addressSorter)
|
|
174
|
+
.map(address => address.multiaddr);
|
|
175
|
+
}
|
|
168
176
|
/**
|
|
169
177
|
* Creates a PendingDial that wraps the underlying DialRequest
|
|
170
178
|
*/
|
|
@@ -263,4 +271,16 @@ export class DefaultDialer {
|
|
|
263
271
|
}
|
|
264
272
|
}
|
|
265
273
|
}
|
|
274
|
+
/**
|
|
275
|
+
* Type safe version of `list.filter(Boolean)`
|
|
276
|
+
*/
|
|
277
|
+
function isTruthy(e) {
|
|
278
|
+
return Boolean(e);
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Returns a random string
|
|
282
|
+
*/
|
|
283
|
+
function randomId() {
|
|
284
|
+
return `${(parseInt(String(Math.random() * 1e9), 10)).toString()}${Date.now()}`;
|
|
285
|
+
}
|
|
266
286
|
//# sourceMappingURL=index.js.map
|