libp2p 0.35.8 → 0.36.0-d44bd90
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/dist/index.min.js +55 -0
- package/dist/src/circuit/auto-relay.d.ts +8 -10
- package/dist/src/circuit/auto-relay.d.ts.map +1 -1
- package/dist/src/config.d.ts +2 -0
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/connection-manager/auto-dialler.d.ts +1 -1
- package/dist/src/connection-manager/auto-dialler.d.ts.map +1 -1
- package/dist/src/connection-manager/index.d.ts +1 -2
- package/dist/src/connection-manager/index.d.ts.map +1 -1
- package/dist/src/content-routing/utils.d.ts +3 -3
- package/dist/src/content-routing/utils.d.ts.map +1 -1
- package/dist/src/dialer/dial-request.d.ts.map +1 -1
- package/dist/src/dialer/index.d.ts +12 -7
- package/dist/src/dialer/index.d.ts.map +1 -1
- package/dist/src/errors.d.ts +2 -0
- package/dist/src/fetch/constants.d.ts +2 -0
- package/dist/src/fetch/constants.d.ts.map +1 -0
- package/dist/src/fetch/index.d.ts +76 -0
- package/dist/src/fetch/index.d.ts.map +1 -0
- package/dist/src/fetch/proto.d.ts +134 -0
- package/dist/src/identify/index.d.ts +4 -4
- package/dist/src/identify/index.d.ts.map +1 -1
- package/dist/src/index.d.ts +26 -7
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/metrics/index.d.ts +9 -4
- package/dist/src/metrics/index.d.ts.map +1 -1
- package/dist/src/metrics/tracked-map.d.ts +6 -1
- package/dist/src/metrics/tracked-map.d.ts.map +1 -1
- package/dist/src/peer-routing.d.ts +1 -1
- package/dist/src/peer-routing.d.ts.map +1 -1
- package/dist/src/peer-store/address-book.d.ts +30 -84
- package/dist/src/peer-store/address-book.d.ts.map +1 -1
- package/dist/src/peer-store/index.d.ts +28 -94
- package/dist/src/peer-store/index.d.ts.map +1 -1
- package/dist/src/peer-store/key-book.d.ts +31 -15
- package/dist/src/peer-store/key-book.d.ts.map +1 -1
- package/dist/src/peer-store/metadata-book.d.ts +33 -29
- package/dist/src/peer-store/metadata-book.d.ts.map +1 -1
- package/dist/src/peer-store/pb/peer.d.ts +222 -0
- package/dist/src/peer-store/proto-book.d.ts +27 -28
- package/dist/src/peer-store/proto-book.d.ts.map +1 -1
- package/dist/src/peer-store/store.d.ts +73 -0
- package/dist/src/peer-store/store.d.ts.map +1 -0
- package/dist/src/peer-store/types.d.ts +202 -0
- package/dist/src/peer-store/types.d.ts.map +1 -0
- package/dist/src/ping/index.d.ts +32 -25
- package/dist/src/ping/index.d.ts.map +1 -1
- package/dist/src/record/peer-record/index.d.ts +2 -2
- package/dist/src/record/peer-record/index.d.ts.map +1 -1
- package/dist/src/registrar.d.ts +5 -5
- package/dist/src/registrar.d.ts.map +1 -1
- package/dist/src/types.d.ts +90 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/upgrader.d.ts +8 -2
- package/dist/src/upgrader.d.ts.map +1 -1
- package/package.json +23 -26
- package/src/circuit/auto-relay.js +52 -38
- package/src/config.js +2 -0
- package/src/connection-manager/auto-dialler.js +20 -8
- package/src/connection-manager/index.js +42 -22
- package/src/content-routing/utils.js +4 -4
- package/src/dialer/dial-request.js +4 -1
- package/src/dialer/index.js +38 -8
- package/src/errors.js +2 -0
- package/src/fetch/README.md +36 -0
- package/src/fetch/constants.js +6 -0
- package/src/fetch/index.js +159 -0
- package/src/fetch/proto.d.ts +134 -0
- package/src/fetch/proto.js +333 -0
- package/src/fetch/proto.proto +15 -0
- package/src/identify/index.js +47 -38
- package/src/index.js +81 -34
- package/src/metrics/index.js +15 -8
- package/src/metrics/tracked-map.js +40 -14
- package/src/peer-routing.js +4 -1
- package/src/peer-store/address-book.js +254 -226
- package/src/peer-store/index.js +79 -110
- package/src/peer-store/key-book.js +99 -54
- package/src/peer-store/metadata-book.js +171 -101
- package/src/peer-store/pb/peer.d.ts +222 -0
- package/src/peer-store/pb/peer.js +643 -0
- package/src/peer-store/pb/peer.proto +31 -0
- package/src/peer-store/proto-book.js +171 -105
- package/src/peer-store/store.js +263 -0
- package/src/peer-store/types.ts +245 -0
- package/src/ping/index.js +51 -46
- package/src/record/peer-record/index.js +1 -1
- package/src/record/utils.js +1 -1
- package/src/registrar.js +4 -4
- package/src/types.ts +98 -0
- package/src/upgrader.js +32 -2
- package/dist/src/peer-store/book.d.ts +0 -81
- package/dist/src/peer-store/book.d.ts.map +0 -1
- package/dist/src/peer-store/persistent/consts.d.ts +0 -6
- package/dist/src/peer-store/persistent/consts.d.ts.map +0 -1
- package/dist/src/peer-store/persistent/index.d.ts +0 -129
- package/dist/src/peer-store/persistent/index.d.ts.map +0 -1
- package/dist/src/peer-store/persistent/pb/address-book.d.ts +0 -198
- package/dist/src/peer-store/persistent/pb/proto-book.d.ts +0 -59
- package/src/peer-store/book.js +0 -124
- package/src/peer-store/persistent/consts.js +0 -15
- package/src/peer-store/persistent/index.js +0 -408
- package/src/peer-store/persistent/pb/address-book.d.ts +0 -198
- package/src/peer-store/persistent/pb/address-book.js +0 -522
- package/src/peer-store/persistent/pb/address-book.proto +0 -27
- package/src/peer-store/persistent/pb/proto-book.d.ts +0 -59
- package/src/peer-store/persistent/pb/proto-book.js +0 -157
- package/src/peer-store/persistent/pb/proto-book.proto +0 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/record/peer-record/index.js"],"names":[],"mappings":";AAYA;;;GAGG;AAEH;;GAEG;AACH;IACE;;;;;;;;;OASG;IACH;QAJ0B,MAAM,EAArB,MAAM;QACc,UAAU,EAA9B,SAAS,EAAE;QACK,SAAS;OAYnC;IATC,eAAyC;IACzC,kBAA8C;IAE9C,eAAoB;IACpB,wBAA4B;IAC5B,kBAA0B;IAG1B,iCAAyB;IAG3B;;;;OAIG;IACH,WAFa,UAAU,CAgBtB;IAED;;;;;OAKG;IACH,cAHW,OAAO,GACL,OAAO,CAuBnB;CACF;;;;cA9EY,OAAO,oCAAoC,EAAE,MAAM;;;AAgFhE;;;;;GAKG;AACH,yCAHW,UAAU,GACR,UAAU,CAUtB;;eA/FY,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/record/peer-record/index.js"],"names":[],"mappings":";AAYA;;;GAGG;AAEH;;GAEG;AACH;IACE;;;;;;;;;OASG;IACH;QAJ0B,MAAM,EAArB,MAAM;QACc,UAAU,EAA9B,SAAS,EAAE;QACK,SAAS;OAYnC;IATC,eAAyC;IACzC,kBAA8C;IAE9C,eAAoB;IACpB,wBAA4B;IAC5B,kBAA0B;IAG1B,iCAAyB;IAG3B;;;;OAIG;IACH,WAFa,UAAU,CAgBtB;IAED;;;;;OAKG;IACH,cAHW,OAAO,GACL,OAAO,CAuBnB;CACF;;;;cA9EY,OAAO,oCAAoC,EAAE,MAAM;;;AAgFhE;;;;;GAKG;AACH,yCAHW,UAAU,GACR,UAAU,CAUtB;;eA/FY,OAAO,wBAAwB,EAAE,OAAO"}
|
package/dist/src/registrar.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export = Registrar;
|
|
2
2
|
/**
|
|
3
3
|
* @typedef {import('peer-id')} PeerId
|
|
4
|
-
* @typedef {import('./peer-store')} PeerStore
|
|
4
|
+
* @typedef {import('./peer-store/types').PeerStore} PeerStore
|
|
5
5
|
* @typedef {import('./connection-manager')} ConnectionManager
|
|
6
6
|
* @typedef {import('libp2p-interfaces/src/connection').Connection} Connection
|
|
7
7
|
* @typedef {import('./').HandlerProps} HandlerProps
|
|
@@ -23,7 +23,7 @@ declare class Registrar {
|
|
|
23
23
|
peerStore: PeerStore;
|
|
24
24
|
connectionManager: ConnectionManager;
|
|
25
25
|
});
|
|
26
|
-
peerStore: import("./peer-store");
|
|
26
|
+
peerStore: import("./peer-store/types").PeerStore;
|
|
27
27
|
connectionManager: import("./connection-manager");
|
|
28
28
|
/**
|
|
29
29
|
* Map of topologies
|
|
@@ -59,9 +59,9 @@ declare class Registrar {
|
|
|
59
59
|
* Register handlers for a set of multicodecs given
|
|
60
60
|
*
|
|
61
61
|
* @param {Topology} topology - protocol topology
|
|
62
|
-
* @returns {string} registrar identifier
|
|
62
|
+
* @returns {Promise<string>} registrar identifier
|
|
63
63
|
*/
|
|
64
|
-
register(topology: Topology): string
|
|
64
|
+
register(topology: Topology): Promise<string>;
|
|
65
65
|
/**
|
|
66
66
|
* Unregister topology.
|
|
67
67
|
*
|
|
@@ -76,7 +76,7 @@ declare namespace Registrar {
|
|
|
76
76
|
import Topology = require("libp2p-interfaces/src/topology");
|
|
77
77
|
type Connection = import("libp2p-interfaces/src/connection/connection");
|
|
78
78
|
type PeerId = import('peer-id');
|
|
79
|
-
type PeerStore = import('./peer-store');
|
|
79
|
+
type PeerStore = import('./peer-store/types').PeerStore;
|
|
80
80
|
type ConnectionManager = import('./connection-manager');
|
|
81
81
|
type HandlerProps = import('./').HandlerProps;
|
|
82
82
|
//# sourceMappingURL=registrar.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registrar.d.ts","sourceRoot":"","sources":["../../src/registrar.js"],"names":[],"mappings":";AAaA;;;;;;GAMG;AAEH;;GAEG;AAEH;;GAEG;AACH;IACE;;;;;OAKG;IACH;QAJ4B,SAAS,EAA1B,SAAS;QACgB,iBAAiB,EAA1C,iBAAiB;OAsB3B;IAjBC,
|
|
1
|
+
{"version":3,"file":"registrar.d.ts","sourceRoot":"","sources":["../../src/registrar.js"],"names":[],"mappings":";AAaA;;;;;;GAMG;AAEH;;GAEG;AAEH;;GAEG;AACH;IACE;;;;;OAKG;IACH;QAJ4B,SAAS,EAA1B,SAAS;QACgB,iBAAiB,EAA1C,iBAAiB;OAsB3B;IAjBC,kDAA0B;IAE1B,kDAA0C;IAE1C;;;;OAIG;IACH,YAFU,IAAI,MAAM,EAAE,QAAQ,CAAC,CAEJ;IAE3B,2FAA2F;IAE3F,qBAFuB,MAAM,EAAE,GAAC,MAAM,mBAAmB,YAAY,KAAK,IAAI,KAAK,IAAI,CAE/D;IA+D1B;;;;;OAKG;IACH,0BAHW,UAAU,GACR,IAAI,CAMhB;IA5DD;;OAEG;IACH,4BATyB,MAAM,EAAE,GAAC,MAAM,mBAAmB,YAAY,KAAK,IAAI,KAAK,IAAI,EAWxF;IAZD;;OAEG;IACH,0BAFyB,MAAM,EAAE,GAAC,MAAM,mBAAmB,YAAY,KAAK,IAAI,KAAK,IAAI,CAIxF;IASD;;;;;OAKG;IACH,sBAHW,MAAM,GACJ,UAAU,GAAG,IAAI,CAI7B;IAED;;;;;OAKG;IACH,mBAHW,QAAQ,GACN,QAAQ,MAAM,CAAC,CAiB3B;IAED;;;;;OAKG;IACH,eAHW,MAAM,GACJ,OAAO,CAInB;CAaF;;;;;;cA9GY,OAAO,SAAS,CAAC;iBACjB,OAAO,oBAAoB,EAAE,SAAS;yBACtC,OAAO,sBAAsB,CAAC;oBAE9B,OAAO,IAAI,EAAE,YAAY"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type PeerId from 'peer-id';
|
|
2
|
+
import type { Multiaddr } from 'multiaddr';
|
|
3
|
+
import type { MultiaddrConnection } from 'libp2p-interfaces/src/transport/types';
|
|
4
|
+
export interface ConnectionGater {
|
|
5
|
+
/**
|
|
6
|
+
* denyDialMultiaddr tests whether we're permitted to Dial the
|
|
7
|
+
* specified peer.
|
|
8
|
+
*
|
|
9
|
+
* This is called by the dialer.connectToPeer implementation before
|
|
10
|
+
* dialling a peer.
|
|
11
|
+
*
|
|
12
|
+
* Return true to prevent dialing the passed peer.
|
|
13
|
+
*/
|
|
14
|
+
denyDialPeer: (peerId: PeerId) => Promise<boolean>;
|
|
15
|
+
/**
|
|
16
|
+
* denyDialMultiaddr tests whether we're permitted to dial the specified
|
|
17
|
+
* multiaddr for the given peer.
|
|
18
|
+
*
|
|
19
|
+
* This is called by the dialer.connectToPeer implementation after it has
|
|
20
|
+
* resolved the peer's addrs, and prior to dialling each.
|
|
21
|
+
*
|
|
22
|
+
* Return true to prevent dialing the passed peer on the passed multiaddr.
|
|
23
|
+
*/
|
|
24
|
+
denyDialMultiaddr: (peerId: PeerId, multiaddr: Multiaddr) => Promise<boolean>;
|
|
25
|
+
/**
|
|
26
|
+
* denyInboundConnection tests whether an incipient inbound connection is allowed.
|
|
27
|
+
*
|
|
28
|
+
* This is called by the upgrader, or by the transport directly (e.g. QUIC,
|
|
29
|
+
* Bluetooth), straight after it has accepted a connection from its socket.
|
|
30
|
+
*
|
|
31
|
+
* Return true to deny the incoming passed connection.
|
|
32
|
+
*/
|
|
33
|
+
denyInboundConnection: (maConn: MultiaddrConnection) => Promise<boolean>;
|
|
34
|
+
/**
|
|
35
|
+
* denyOutboundConnection tests whether an incipient outbound connection is allowed.
|
|
36
|
+
*
|
|
37
|
+
* This is called by the upgrader, or by the transport directly (e.g. QUIC,
|
|
38
|
+
* Bluetooth), straight after it has created a connection with its socket.
|
|
39
|
+
*
|
|
40
|
+
* Return true to deny the incoming passed connection.
|
|
41
|
+
*/
|
|
42
|
+
denyOutboundConnection: (peerId: PeerId, maConn: MultiaddrConnection) => Promise<boolean>;
|
|
43
|
+
/**
|
|
44
|
+
* denyInboundEncryptedConnection tests whether a given connection, now encrypted,
|
|
45
|
+
* is allowed.
|
|
46
|
+
*
|
|
47
|
+
* This is called by the upgrader, after it has performed the security
|
|
48
|
+
* handshake, and before it negotiates the muxer, or by the directly by the
|
|
49
|
+
* transport, at the exact same checkpoint.
|
|
50
|
+
*
|
|
51
|
+
* Return true to deny the passed secured connection.
|
|
52
|
+
*/
|
|
53
|
+
denyInboundEncryptedConnection: (peerId: PeerId, maConn: MultiaddrConnection) => Promise<boolean>;
|
|
54
|
+
/**
|
|
55
|
+
* denyOutboundEncryptedConnection tests whether a given connection, now encrypted,
|
|
56
|
+
* is allowed.
|
|
57
|
+
*
|
|
58
|
+
* This is called by the upgrader, after it has performed the security
|
|
59
|
+
* handshake, and before it negotiates the muxer, or by the directly by the
|
|
60
|
+
* transport, at the exact same checkpoint.
|
|
61
|
+
*
|
|
62
|
+
* Return true to deny the passed secured connection.
|
|
63
|
+
*/
|
|
64
|
+
denyOutboundEncryptedConnection: (peerId: PeerId, maConn: MultiaddrConnection) => Promise<boolean>;
|
|
65
|
+
/**
|
|
66
|
+
* denyInboundUpgradedConnection tests whether a fully capable connection is allowed.
|
|
67
|
+
*
|
|
68
|
+
* This is called after encryption has been negotiated and the connection has been
|
|
69
|
+
* multiplexed, if a multiplexer is configured.
|
|
70
|
+
*
|
|
71
|
+
* Return true to deny the passed upgraded connection.
|
|
72
|
+
*/
|
|
73
|
+
denyInboundUpgradedConnection: (peerId: PeerId, maConn: MultiaddrConnection) => Promise<boolean>;
|
|
74
|
+
/**
|
|
75
|
+
* denyOutboundUpgradedConnection tests whether a fully capable connection is allowed.
|
|
76
|
+
*
|
|
77
|
+
* This is called after encryption has been negotiated and the connection has been
|
|
78
|
+
* multiplexed, if a multiplexer is configured.
|
|
79
|
+
*
|
|
80
|
+
* Return true to deny the passed upgraded connection.
|
|
81
|
+
*/
|
|
82
|
+
denyOutboundUpgradedConnection: (peerId: PeerId, maConn: MultiaddrConnection) => Promise<boolean>;
|
|
83
|
+
/**
|
|
84
|
+
* Used by the address book to filter passed addresses.
|
|
85
|
+
*
|
|
86
|
+
* Return true to allow storing the passed multiaddr for the passed peer.
|
|
87
|
+
*/
|
|
88
|
+
filterMultiaddrForPeer: (peer: PeerId, multiaddr: Multiaddr) => Promise<boolean>;
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,SAAS,CAAA;AACjC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAC1C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAA;AAEhF,MAAM,WAAW,eAAe;IAC9B;;;;;;;;OAQG;IACH,YAAY,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;IAElD;;;;;;;;OAQG;IACH,iBAAiB,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;IAE7E;;;;;;;OAOG;IACH,qBAAqB,EAAE,CAAC,MAAM,EAAE,mBAAmB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;IAExE;;;;;;;OAOG;IACH,sBAAsB,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,mBAAmB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;IAEzF;;;;;;;;;OASG;IACH,8BAA8B,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,mBAAmB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;IAEjG;;;;;;;;;OASG;IACH,+BAA+B,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,mBAAmB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;IAElG;;;;;;;OAOG;IACH,6BAA6B,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,mBAAmB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;IAEhG;;;;;;;OAOG;IACH,8BAA8B,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,mBAAmB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;IAEjG;;;;OAIG;IACH,sBAAsB,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;CACjF"}
|
package/dist/src/upgrader.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export = Upgrader;
|
|
|
7
7
|
* @typedef {import('libp2p-interfaces/src/crypto/types').Crypto} Crypto
|
|
8
8
|
* @typedef {import('libp2p-interfaces/src/connection').Connection} Connection
|
|
9
9
|
* @typedef {import('multiaddr').Multiaddr} Multiaddr
|
|
10
|
+
* @typedef {import('./types').ConnectionGater} ConnectionGater
|
|
10
11
|
*/
|
|
11
12
|
/**
|
|
12
13
|
* @typedef CryptoResult
|
|
@@ -18,20 +19,24 @@ declare class Upgrader {
|
|
|
18
19
|
/**
|
|
19
20
|
* @param {object} options
|
|
20
21
|
* @param {PeerId} options.localPeer
|
|
22
|
+
* @param {ConnectionGater} options.connectionGater
|
|
23
|
+
*
|
|
21
24
|
* @param {import('./metrics')} [options.metrics]
|
|
22
25
|
* @param {Map<string, Crypto>} [options.cryptos]
|
|
23
26
|
* @param {Map<string, MuxerFactory>} [options.muxers]
|
|
24
27
|
* @param {(connection: Connection) => void} options.onConnection - Called when a connection is upgraded
|
|
25
28
|
* @param {(connection: Connection) => void} options.onConnectionEnd
|
|
26
29
|
*/
|
|
27
|
-
constructor({ localPeer, metrics, cryptos, muxers, onConnectionEnd, onConnection }: {
|
|
30
|
+
constructor({ localPeer, metrics, connectionGater, cryptos, muxers, onConnectionEnd, onConnection }: {
|
|
28
31
|
localPeer: PeerId;
|
|
32
|
+
connectionGater: ConnectionGater;
|
|
29
33
|
metrics?: import("./metrics") | undefined;
|
|
30
34
|
cryptos?: Map<string, import("libp2p-interfaces/src/crypto/types").Crypto> | undefined;
|
|
31
35
|
muxers?: Map<string, import("libp2p-interfaces/src/stream-muxer/types").MuxerFactory> | undefined;
|
|
32
36
|
onConnection: (connection: Connection) => void;
|
|
33
37
|
onConnectionEnd: (connection: Connection) => void;
|
|
34
38
|
});
|
|
39
|
+
connectionGater: import("./types").ConnectionGater;
|
|
35
40
|
localPeer: PeerId;
|
|
36
41
|
metrics: import("./metrics") | undefined;
|
|
37
42
|
cryptos: Map<string, import("libp2p-interfaces/src/crypto/types").Crypto>;
|
|
@@ -129,11 +134,12 @@ declare class Upgrader {
|
|
|
129
134
|
private _multiplexInbound;
|
|
130
135
|
}
|
|
131
136
|
declare namespace Upgrader {
|
|
132
|
-
export { MultiaddrConnection, MuxerFactory, Muxer, MuxedStream, Crypto, Connection, Multiaddr, CryptoResult };
|
|
137
|
+
export { MultiaddrConnection, MuxerFactory, Muxer, MuxedStream, Crypto, Connection, Multiaddr, ConnectionGater, CryptoResult };
|
|
133
138
|
}
|
|
134
139
|
import PeerId = require("peer-id");
|
|
135
140
|
type MultiaddrConnection = import('libp2p-interfaces/src/transport/types').MultiaddrConnection;
|
|
136
141
|
import { Connection } from "libp2p-interfaces/src/connection";
|
|
142
|
+
type ConnectionGater = import('./types').ConnectionGater;
|
|
137
143
|
type MuxerFactory = import('libp2p-interfaces/src/stream-muxer/types').MuxerFactory;
|
|
138
144
|
type Muxer = import('libp2p-interfaces/src/stream-muxer/types').Muxer;
|
|
139
145
|
type MuxedStream = import('libp2p-interfaces/src/stream-muxer/types').MuxedStream;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upgrader.d.ts","sourceRoot":"","sources":["../../src/upgrader.js"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"upgrader.d.ts","sourceRoot":"","sources":["../../src/upgrader.js"],"names":[],"mappings":";AAgBA;;;;;;;;;GASG;AAEH;;;;;GAKG;AAEH;IACE;;;;;;;;;;OAUG;IACH;mBATW,MAAM;yBACN,eAAe;;;;mCAKF,UAAU,KAAK,IAAI;sCACnB,UAAU,KAAK,IAAI;OAqB1C;IAVC,mDAAsC;IACtC,kBAA0B;IAC1B,yCAAsB;IACtB,0EAAsB;IACtB,qFAAoB;IACpB,sCAAsC;IACtC,WADW,OAAO,QAAQ,CAAC,GAAG,IAAI,CACb;IACrB,yBAA0B;IAC1B,2BApBsB,UAAU,KAAK,IAAI,CAoBT;IAChC,8BApBsB,UAAU,KAAK,IAAI,CAoBH;IAGxC;;;;;;OAMG;IACH,uBAHW,mBAAmB,GACjB,QAAQ,UAAU,CAAC,CAyE/B;IAED;;;;;;OAMG;IACH,wBAHW,mBAAmB,GACjB,QAAQ,UAAU,CAAC,CAgF/B;IAED;;;;;;;;;;;;OAYG;IACH,0BAgHC;IAED;;;;;;;;OAQG;IACH,kBAGC;IAED;;;;;;;;;OASG;IACH,wBAqBC;IAED;;;;;;;;;;;OAWG;IACH,yBAqBC;IAED;;;;;;;;;OASG;IACH,2BAYC;IAED;;;;;;;;;OASG;IACH,0BAWC;CACF;;;;;2BAxdY,OAAO,uCAAuC,EAAE,mBAAmB;;uBAOnE,OAAO,SAAS,EAAE,eAAe;oBANjC,OAAO,0CAA0C,EAAE,YAAY;aAC/D,OAAO,0CAA0C,EAAE,KAAK;mBACxD,OAAO,0CAA0C,EAAE,WAAW;cAC9D,OAAO,oCAAoC,EAAE,MAAM;;iBAEnD,OAAO,WAAW,EAAE,SAAS;;;;;UAM5B,mBAAmB;gBACnB,MAAM;cACN,MAAM"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "libp2p",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.36.0-d44bd90",
|
|
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",
|
|
@@ -20,20 +20,20 @@
|
|
|
20
20
|
"scripts": {
|
|
21
21
|
"lint": "aegir lint",
|
|
22
22
|
"build": "aegir build",
|
|
23
|
-
"build:proto": "npm run build:proto:circuit && npm run build:proto:identify && npm run build:proto:plaintext && npm run build:proto:address-book && npm run build:proto:proto-book && npm run build:proto:peer-record && npm run build:proto:envelope",
|
|
23
|
+
"build:proto": "npm run build:proto:circuit && npm run build:proto:fetch && npm run build:proto:identify && npm run build:proto:plaintext && npm run build:proto:address-book && npm run build:proto:proto-book && npm run build:proto:peer && npm run build:proto:peer-record && npm run build:proto:envelope",
|
|
24
24
|
"build:proto:circuit": "pbjs -t static-module -w commonjs -r libp2p-circuit --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/circuit/protocol/index.js ./src/circuit/protocol/index.proto",
|
|
25
|
+
"build:proto:fetch": "pbjs -t static-module -w commonjs -r libp2p-fetch --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/fetch/proto.js ./src/fetch/proto.proto",
|
|
25
26
|
"build:proto:identify": "pbjs -t static-module -w commonjs -r libp2p-identify --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/identify/message.js ./src/identify/message.proto",
|
|
26
27
|
"build:proto:plaintext": "pbjs -t static-module -w commonjs -r libp2p-plaintext --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/insecure/proto.js ./src/insecure/proto.proto",
|
|
27
|
-
"build:proto:
|
|
28
|
-
"build:proto:proto-book": "pbjs -t static-module -w commonjs -r libp2p-proto-book --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/peer-store/persistent/pb/proto-book.js ./src/peer-store/persistent/pb/proto-book.proto",
|
|
28
|
+
"build:proto:peer": "pbjs -t static-module -w commonjs -r libp2p-peer --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/peer-store/pb/peer.js ./src/peer-store/pb/peer.proto",
|
|
29
29
|
"build:proto:peer-record": "pbjs -t static-module -w commonjs -r libp2p-peer-record --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/record/peer-record/peer-record.js ./src/record/peer-record/peer-record.proto",
|
|
30
30
|
"build:proto:envelope": "pbjs -t static-module -w commonjs -r libp2p-envelope --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/record/envelope/envelope.js ./src/record/envelope/envelope.proto",
|
|
31
|
-
"build:proto-types": "npm run build:proto-types:circuit && npm run build:proto-types:identify && npm run build:proto-types:plaintext && npm run build:proto-types:address-book && npm run build:proto-types:proto-book && npm run build:proto-types:peer-record && npm run build:proto-types:envelope",
|
|
31
|
+
"build:proto-types": "npm run build:proto-types:circuit && npm run build:proto-types:fetch && npm run build:proto-types:identify && npm run build:proto-types:plaintext && npm run build:proto-types:address-book && npm run build:proto-types:proto-book && npm run build:proto-types:peer && npm run build:proto-types:peer-record && npm run build:proto-types:envelope",
|
|
32
32
|
"build:proto-types:circuit": "pbts -o src/circuit/protocol/index.d.ts src/circuit/protocol/index.js",
|
|
33
|
+
"build:proto-types:fetch": "pbts -o src/fetch/proto.d.ts src/fetch/proto.js",
|
|
33
34
|
"build:proto-types:identify": "pbts -o src/identify/message.d.ts src/identify/message.js",
|
|
34
35
|
"build:proto-types:plaintext": "pbts -o src/insecure/proto.d.ts src/insecure/proto.js",
|
|
35
|
-
"build:proto-types:
|
|
36
|
-
"build:proto-types:proto-book": "pbts -o src/peer-store/persistent/pb/proto-book.d.ts src/peer-store/persistent/pb/proto-book.js",
|
|
36
|
+
"build:proto-types:peer": "pbts -o src/peer-store/pb/peer.d.ts src/peer-store/pb/peer.js",
|
|
37
37
|
"build:proto-types:peer-record": "pbts -o src/record/peer-record/peer-record.d.ts src/record/peer-record/peer-record.js",
|
|
38
38
|
"build:proto-types:envelope": "pbts -o src/record/envelope/envelope.d.ts src/record/envelope/envelope.js",
|
|
39
39
|
"test": "aegir test",
|
|
@@ -42,10 +42,7 @@
|
|
|
42
42
|
"test:browser": "aegir test -t browser",
|
|
43
43
|
"test:examples": "cd examples && npm run test:all",
|
|
44
44
|
"test:interop": "LIBP2P_JS=$PWD npx aegir test -t node -f ./node_modules/libp2p-interop/test/*",
|
|
45
|
-
"prepare": "
|
|
46
|
-
"release": "aegir release -t node -t browser",
|
|
47
|
-
"release-minor": "aegir release --type minor -t node -t browser",
|
|
48
|
-
"release-major": "aegir release --type major -t node -t browser",
|
|
45
|
+
"prepare": "npm run build",
|
|
49
46
|
"coverage": "nyc --reporter=text --reporter=lcov npm run test:node"
|
|
50
47
|
},
|
|
51
48
|
"repository": {
|
|
@@ -81,12 +78,12 @@
|
|
|
81
78
|
},
|
|
82
79
|
"dependencies": {
|
|
83
80
|
"@vascosantos/moving-average": "^1.1.0",
|
|
84
|
-
"abort-controller": "^3.0.0",
|
|
85
81
|
"abortable-iterator": "^3.0.0",
|
|
86
82
|
"aggregate-error": "^3.1.0",
|
|
87
|
-
"any-signal": "^
|
|
83
|
+
"any-signal": "^3.0.0",
|
|
88
84
|
"bignumber.js": "^9.0.1",
|
|
89
85
|
"class-is": "^1.1.0",
|
|
86
|
+
"datastore-core": "^7.0.0",
|
|
90
87
|
"debug": "^4.3.1",
|
|
91
88
|
"err-code": "^3.0.0",
|
|
92
89
|
"es6-promisify": "^7.0.0",
|
|
@@ -98,23 +95,26 @@
|
|
|
98
95
|
"it-drain": "^1.0.3",
|
|
99
96
|
"it-filter": "^1.0.1",
|
|
100
97
|
"it-first": "^1.0.4",
|
|
98
|
+
"it-foreach": "^0.1.1",
|
|
101
99
|
"it-handshake": "^2.0.0",
|
|
102
100
|
"it-length-prefixed": "^5.0.2",
|
|
103
101
|
"it-map": "^1.0.4",
|
|
104
102
|
"it-merge": "^1.0.0",
|
|
105
103
|
"it-pipe": "^1.1.0",
|
|
104
|
+
"it-sort": "^1.0.1",
|
|
106
105
|
"it-take": "^1.0.0",
|
|
107
|
-
"libp2p-crypto": "^0.21.
|
|
108
|
-
"libp2p-interfaces": "^
|
|
106
|
+
"libp2p-crypto": "^0.21.2",
|
|
107
|
+
"libp2p-interfaces": "^4.0.0",
|
|
109
108
|
"libp2p-utils": "^0.4.0",
|
|
110
109
|
"mafmt": "^10.0.0",
|
|
111
110
|
"merge-options": "^3.0.4",
|
|
111
|
+
"mortice": "^2.0.1",
|
|
112
112
|
"multiaddr": "^10.0.0",
|
|
113
113
|
"multiformats": "^9.0.0",
|
|
114
|
-
"multistream-select": "^
|
|
114
|
+
"multistream-select": "^3.0.0",
|
|
115
115
|
"mutable-proxy": "^1.0.0",
|
|
116
116
|
"nat-api": "^0.3.1",
|
|
117
|
-
"node-forge": "^
|
|
117
|
+
"node-forge": "^1.2.1",
|
|
118
118
|
"p-any": "^3.0.0",
|
|
119
119
|
"p-fifo": "^1.0.0",
|
|
120
120
|
"p-retry": "^4.4.0",
|
|
@@ -126,7 +126,7 @@
|
|
|
126
126
|
"sanitize-filename": "^1.6.3",
|
|
127
127
|
"set-delayed-interval": "^1.0.0",
|
|
128
128
|
"streaming-iterables": "^6.0.0",
|
|
129
|
-
"timeout-abort-controller": "^
|
|
129
|
+
"timeout-abort-controller": "^3.0.0",
|
|
130
130
|
"uint8arrays": "^3.0.0",
|
|
131
131
|
"varint": "^6.0.0",
|
|
132
132
|
"wherearewe": "^1.0.0",
|
|
@@ -137,11 +137,10 @@
|
|
|
137
137
|
"@nodeutils/defaults-deep": "^1.1.0",
|
|
138
138
|
"@types/es6-promisify": "^6.0.0",
|
|
139
139
|
"@types/node": "^16.0.1",
|
|
140
|
-
"@types/node-forge": "^0.
|
|
140
|
+
"@types/node-forge": "^1.0.0",
|
|
141
141
|
"@types/varint": "^6.0.0",
|
|
142
142
|
"aegir": "^36.0.0",
|
|
143
143
|
"buffer": "^6.0.3",
|
|
144
|
-
"datastore-core": "^6.0.7",
|
|
145
144
|
"delay": "^5.0.0",
|
|
146
145
|
"into-stream": "^6.0.0",
|
|
147
146
|
"ipfs-http-client": "^54.0.2",
|
|
@@ -152,13 +151,11 @@
|
|
|
152
151
|
"libp2p-bootstrap": "^0.14.0",
|
|
153
152
|
"libp2p-delegated-content-routing": "^0.11.0",
|
|
154
153
|
"libp2p-delegated-peer-routing": "^0.11.1",
|
|
155
|
-
"libp2p-
|
|
156
|
-
"libp2p-
|
|
157
|
-
"libp2p-
|
|
158
|
-
"libp2p-interop": "^0.5.0",
|
|
159
|
-
"libp2p-kad-dht": "^0.27.1",
|
|
154
|
+
"libp2p-interfaces-compliance-tests": "^4.0.8",
|
|
155
|
+
"libp2p-interop": "^0.7.1",
|
|
156
|
+
"libp2p-kad-dht": "^0.28.6",
|
|
160
157
|
"libp2p-mdns": "^0.18.0",
|
|
161
|
-
"libp2p-mplex": "^0.10.
|
|
158
|
+
"libp2p-mplex": "^0.10.4",
|
|
162
159
|
"libp2p-tcp": "^0.17.0",
|
|
163
160
|
"libp2p-webrtc-star": "^0.25.0",
|
|
164
161
|
"libp2p-websockets": "^0.16.0",
|
|
@@ -8,7 +8,7 @@ const log = Object.assign(debug('libp2p:auto-relay'), {
|
|
|
8
8
|
const { fromString: uint8ArrayFromString } = require('uint8arrays/from-string')
|
|
9
9
|
const { toString: uint8ArrayToString } = require('uint8arrays/to-string')
|
|
10
10
|
const { Multiaddr } = require('multiaddr')
|
|
11
|
-
const
|
|
11
|
+
const all = require('it-all')
|
|
12
12
|
|
|
13
13
|
const { relay: multicodec } = require('./multicodec')
|
|
14
14
|
const { canHop } = require('./circuit/hop')
|
|
@@ -22,7 +22,8 @@ const {
|
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* @typedef {import('libp2p-interfaces/src/connection').Connection} Connection
|
|
25
|
-
* @typedef {import('../peer-store/
|
|
25
|
+
* @typedef {import('../peer-store/types').Address} Address
|
|
26
|
+
* @typedef {import('peer-id')} PeerId
|
|
26
27
|
*/
|
|
27
28
|
|
|
28
29
|
/**
|
|
@@ -91,7 +92,7 @@ class AutoRelay {
|
|
|
91
92
|
|
|
92
93
|
// If no protocol, check if we were keeping the peer before as a listenRelay
|
|
93
94
|
if (!hasProtocol && this._listenRelays.has(id)) {
|
|
94
|
-
this._removeListenRelay(id)
|
|
95
|
+
await this._removeListenRelay(id)
|
|
95
96
|
return
|
|
96
97
|
} else if (!hasProtocol || this._listenRelays.has(id)) {
|
|
97
98
|
return
|
|
@@ -113,7 +114,7 @@ class AutoRelay {
|
|
|
113
114
|
const supportsHop = await canHop({ connection })
|
|
114
115
|
|
|
115
116
|
if (supportsHop) {
|
|
116
|
-
this._peerStore.metadataBook.
|
|
117
|
+
await this._peerStore.metadataBook.setValue(peerId, HOP_METADATA_KEY, uint8ArrayFromString(HOP_METADATA_VALUE))
|
|
117
118
|
await this._addListenRelay(connection, id)
|
|
118
119
|
}
|
|
119
120
|
} catch (/** @type {any} */ err) {
|
|
@@ -125,7 +126,6 @@ class AutoRelay {
|
|
|
125
126
|
* Peer disconnects.
|
|
126
127
|
*
|
|
127
128
|
* @param {Connection} connection - connection to the peer
|
|
128
|
-
* @returns {void}
|
|
129
129
|
*/
|
|
130
130
|
_onPeerDisconnected (connection) {
|
|
131
131
|
const peerId = connection.remotePeer
|
|
@@ -136,7 +136,9 @@ class AutoRelay {
|
|
|
136
136
|
return
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
-
this._removeListenRelay(id)
|
|
139
|
+
this._removeListenRelay(id).catch(err => {
|
|
140
|
+
log.error(err)
|
|
141
|
+
})
|
|
140
142
|
}
|
|
141
143
|
|
|
142
144
|
/**
|
|
@@ -148,27 +150,35 @@ class AutoRelay {
|
|
|
148
150
|
* @returns {Promise<void>}
|
|
149
151
|
*/
|
|
150
152
|
async _addListenRelay (connection, id) {
|
|
151
|
-
// Check if already listening on enough relays
|
|
152
|
-
if (this._listenRelays.size >= this.maxListeners) {
|
|
153
|
-
return
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// Get peer known addresses and sort them per public addresses first
|
|
157
|
-
const remoteAddrs = this._peerStore.addressBook.getMultiaddrsForPeer(
|
|
158
|
-
connection.remotePeer, this._addressSorter
|
|
159
|
-
)
|
|
160
|
-
|
|
161
|
-
if (!remoteAddrs || !remoteAddrs.length) {
|
|
162
|
-
return
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
const listenAddr = `${remoteAddrs[0].toString()}/p2p-circuit`
|
|
166
|
-
this._listenRelays.add(id)
|
|
167
|
-
|
|
168
|
-
// Attempt to listen on relay
|
|
169
153
|
try {
|
|
170
|
-
|
|
171
|
-
|
|
154
|
+
// Check if already listening on enough relays
|
|
155
|
+
if (this._listenRelays.size >= this.maxListeners) {
|
|
156
|
+
return
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Get peer known addresses and sort them per public addresses first
|
|
160
|
+
const remoteAddrs = await this._peerStore.addressBook.getMultiaddrsForPeer(
|
|
161
|
+
connection.remotePeer, this._addressSorter
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
// Attempt to listen on relay
|
|
165
|
+
const result = await Promise.all(
|
|
166
|
+
remoteAddrs.map(async addr => {
|
|
167
|
+
try {
|
|
168
|
+
// Announce multiaddrs will update on listen success by TransportManager event being triggered
|
|
169
|
+
await this._transportManager.listen([new Multiaddr(`${addr.toString()}/p2p-circuit`)])
|
|
170
|
+
return true
|
|
171
|
+
} catch (/** @type {any} */ err) {
|
|
172
|
+
this._onError(err)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return false
|
|
176
|
+
})
|
|
177
|
+
)
|
|
178
|
+
|
|
179
|
+
if (result.includes(true)) {
|
|
180
|
+
this._listenRelays.add(id)
|
|
181
|
+
}
|
|
172
182
|
} catch (/** @type {any} */ err) {
|
|
173
183
|
this._onError(err)
|
|
174
184
|
this._listenRelays.delete(id)
|
|
@@ -180,12 +190,11 @@ class AutoRelay {
|
|
|
180
190
|
*
|
|
181
191
|
* @private
|
|
182
192
|
* @param {string} id - peer identifier string.
|
|
183
|
-
* @returns {void}
|
|
184
193
|
*/
|
|
185
|
-
_removeListenRelay (id) {
|
|
194
|
+
async _removeListenRelay (id) {
|
|
186
195
|
if (this._listenRelays.delete(id)) {
|
|
187
196
|
// TODO: this should be responsibility of the connMgr
|
|
188
|
-
this._listenOnAvailableHopRelays([id])
|
|
197
|
+
await this._listenOnAvailableHopRelays([id])
|
|
189
198
|
}
|
|
190
199
|
}
|
|
191
200
|
|
|
@@ -197,7 +206,6 @@ class AutoRelay {
|
|
|
197
206
|
* 3. Search the network.
|
|
198
207
|
*
|
|
199
208
|
* @param {string[]} [peersToIgnore]
|
|
200
|
-
* @returns {Promise<void>}
|
|
201
209
|
*/
|
|
202
210
|
async _listenOnAvailableHopRelays (peersToIgnore = []) {
|
|
203
211
|
// TODO: The peer redial issue on disconnect should be handled by connection gating
|
|
@@ -207,31 +215,37 @@ class AutoRelay {
|
|
|
207
215
|
}
|
|
208
216
|
|
|
209
217
|
const knownHopsToDial = []
|
|
218
|
+
const peers = await all(this._peerStore.getPeers())
|
|
210
219
|
|
|
211
220
|
// Check if we have known hop peers to use and attempt to listen on the already connected
|
|
212
|
-
for (const
|
|
221
|
+
for await (const { id, metadata } of peers) {
|
|
222
|
+
const idStr = id.toB58String()
|
|
223
|
+
|
|
213
224
|
// Continue to next if listening on this or peer to ignore
|
|
214
|
-
if (this._listenRelays.has(
|
|
225
|
+
if (this._listenRelays.has(idStr)) {
|
|
215
226
|
continue
|
|
216
227
|
}
|
|
217
228
|
|
|
218
|
-
|
|
229
|
+
if (peersToIgnore.includes(idStr)) {
|
|
230
|
+
continue
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const supportsHop = metadata.get(HOP_METADATA_KEY)
|
|
219
234
|
|
|
220
235
|
// Continue to next if it does not support Hop
|
|
221
236
|
if (!supportsHop || uint8ArrayToString(supportsHop) !== HOP_METADATA_VALUE) {
|
|
222
237
|
continue
|
|
223
238
|
}
|
|
224
239
|
|
|
225
|
-
const
|
|
226
|
-
const connection = this._connectionManager.get(peerId)
|
|
240
|
+
const connection = this._connectionManager.get(id)
|
|
227
241
|
|
|
228
242
|
// If not connected, store for possible later use.
|
|
229
243
|
if (!connection) {
|
|
230
|
-
knownHopsToDial.push(
|
|
244
|
+
knownHopsToDial.push(id)
|
|
231
245
|
continue
|
|
232
246
|
}
|
|
233
247
|
|
|
234
|
-
await this._addListenRelay(connection,
|
|
248
|
+
await this._addListenRelay(connection, idStr)
|
|
235
249
|
|
|
236
250
|
// Check if already listening on enough relays
|
|
237
251
|
if (this._listenRelays.size >= this.maxListeners) {
|
|
@@ -258,7 +272,7 @@ class AutoRelay {
|
|
|
258
272
|
}
|
|
259
273
|
|
|
260
274
|
const peerId = provider.id
|
|
261
|
-
this._peerStore.addressBook.add(peerId, provider.multiaddrs)
|
|
275
|
+
await this._peerStore.addressBook.add(peerId, provider.multiaddrs)
|
|
262
276
|
|
|
263
277
|
await this._tryToListenOnRelay(peerId)
|
|
264
278
|
|
package/src/config.js
CHANGED
|
@@ -13,6 +13,7 @@ const { FaultTolerance } = require('./transport-manager')
|
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* @typedef {import('multiaddr').Multiaddr} Multiaddr
|
|
16
|
+
* @typedef {import('./types').ConnectionGater} ConnectionGater
|
|
16
17
|
* @typedef {import('.').Libp2pOptions} Libp2pOptions
|
|
17
18
|
* @typedef {import('.').constructorOptions} constructorOptions
|
|
18
19
|
*/
|
|
@@ -27,6 +28,7 @@ const DefaultConfig = {
|
|
|
27
28
|
connectionManager: {
|
|
28
29
|
minConnections: 25
|
|
29
30
|
},
|
|
31
|
+
connectionGater: /** @type {ConnectionGater} */ {},
|
|
30
32
|
transportManager: {
|
|
31
33
|
faultTolerance: FaultTolerance.FATAL_ALL
|
|
32
34
|
},
|
|
@@ -4,6 +4,10 @@ const debug = require('debug')
|
|
|
4
4
|
const mergeOptions = require('merge-options')
|
|
5
5
|
// @ts-ignore retimer does not have types
|
|
6
6
|
const retimer = require('retimer')
|
|
7
|
+
const all = require('it-all')
|
|
8
|
+
const { pipe } = require('it-pipe')
|
|
9
|
+
const filter = require('it-filter')
|
|
10
|
+
const sort = require('it-sort')
|
|
7
11
|
|
|
8
12
|
const log = Object.assign(debug('libp2p:connection-manager:auto-dialler'), {
|
|
9
13
|
error: debug('libp2p:connection-manager:auto-dialler:err')
|
|
@@ -50,7 +54,7 @@ class AutoDialler {
|
|
|
50
54
|
/**
|
|
51
55
|
* Starts the auto dialer
|
|
52
56
|
*/
|
|
53
|
-
start () {
|
|
57
|
+
async start () {
|
|
54
58
|
if (!this._options.enabled) {
|
|
55
59
|
log('not enabled')
|
|
56
60
|
return
|
|
@@ -86,22 +90,30 @@ class AutoDialler {
|
|
|
86
90
|
return
|
|
87
91
|
}
|
|
88
92
|
|
|
89
|
-
// Sort peers on
|
|
90
|
-
|
|
91
|
-
|
|
93
|
+
// Sort peers on whether we know protocols of public keys for them
|
|
94
|
+
// TODO: assuming the `peerStore.getPeers()` order is stable this will mean
|
|
95
|
+
// we keep trying to connect to the same peers?
|
|
96
|
+
const peers = await pipe(
|
|
97
|
+
this._libp2p.peerStore.getPeers(),
|
|
98
|
+
(source) => filter(source, (peer) => !peer.id.equals(this._libp2p.peerId)),
|
|
99
|
+
(source) => sort(source, (a, b) => {
|
|
92
100
|
if (b.protocols && b.protocols.length && (!a.protocols || !a.protocols.length)) {
|
|
93
101
|
return 1
|
|
94
102
|
} else if (b.id.pubKey && !a.id.pubKey) {
|
|
95
103
|
return 1
|
|
96
104
|
}
|
|
97
105
|
return -1
|
|
98
|
-
})
|
|
106
|
+
}),
|
|
107
|
+
(source) => all(source)
|
|
108
|
+
)
|
|
99
109
|
|
|
100
110
|
for (let i = 0; this._running && i < peers.length && this._libp2p.connections.size < minConnections; i++) {
|
|
101
|
-
|
|
102
|
-
|
|
111
|
+
const peer = peers[i]
|
|
112
|
+
|
|
113
|
+
if (!this._libp2p.connectionManager.get(peer.id)) {
|
|
114
|
+
log('connecting to a peerStore stored peer %s', peer.id.toB58String())
|
|
103
115
|
try {
|
|
104
|
-
await this._libp2p.dialer.connectToPeer(
|
|
116
|
+
await this._libp2p.dialer.connectToPeer(peer.id)
|
|
105
117
|
} catch (/** @type {any} */ err) {
|
|
106
118
|
log.error('could not connect to peerStore stored peer', err)
|
|
107
119
|
}
|