libp2p 0.32.5 → 0.35.1
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/src/circuit/index.d.ts +2 -2
- package/dist/src/circuit/index.d.ts.map +1 -1
- package/dist/src/circuit/transport.d.ts +1 -1
- package/dist/src/circuit/transport.d.ts.map +1 -1
- package/dist/src/config.d.ts +0 -1
- package/dist/src/connection-manager/auto-dialler.d.ts +56 -0
- package/dist/src/connection-manager/auto-dialler.d.ts.map +1 -0
- package/dist/src/connection-manager/index.d.ts +0 -10
- package/dist/src/connection-manager/index.d.ts.map +1 -1
- package/dist/src/content-routing/index.d.ts +4 -2
- package/dist/src/content-routing/index.d.ts.map +1 -1
- package/dist/src/dht/dht-content-routing.d.ts +30 -0
- package/dist/src/dht/dht-content-routing.d.ts.map +1 -0
- package/dist/src/dht/dht-peer-routing.d.ts +29 -0
- package/dist/src/dht/dht-peer-routing.d.ts.map +1 -0
- package/dist/src/dialer/dial-request.d.ts +4 -4
- package/dist/src/dialer/dial-request.d.ts.map +1 -1
- package/dist/src/dialer/index.d.ts +2 -3
- package/dist/src/dialer/index.d.ts.map +1 -1
- package/dist/src/errors.d.ts +2 -0
- package/dist/src/identify/index.d.ts +1 -1
- package/dist/src/identify/index.d.ts.map +1 -1
- package/dist/src/index.d.ts +6 -5
- package/dist/src/index.d.ts.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/metrics/stats.d.ts +0 -1
- package/dist/src/metrics/stats.d.ts.map +1 -1
- package/dist/src/nat-manager.d.ts.map +1 -1
- package/dist/src/peer-routing.d.ts +8 -1
- package/dist/src/peer-routing.d.ts.map +1 -1
- package/dist/src/peer-store/address-book.d.ts +1 -1
- package/dist/src/peer-store/address-book.d.ts.map +1 -1
- package/dist/src/peer-store/index.d.ts +37 -24
- package/dist/src/peer-store/index.d.ts.map +1 -1
- package/dist/src/peer-store/metadata-book.d.ts +3 -2
- package/dist/src/peer-store/metadata-book.d.ts.map +1 -1
- package/dist/src/peer-store/persistent/index.d.ts +1 -2
- package/dist/src/peer-store/persistent/index.d.ts.map +1 -1
- package/dist/src/record/envelope/index.d.ts +23 -0
- package/dist/src/record/envelope/index.d.ts.map +1 -1
- package/dist/src/record/peer-record/index.d.ts +6 -0
- package/dist/src/record/peer-record/index.d.ts.map +1 -1
- package/dist/src/registrar.d.ts +1 -1
- package/dist/src/registrar.d.ts.map +1 -1
- package/dist/src/upgrader.d.ts +1 -1
- package/dist/src/upgrader.d.ts.map +1 -1
- package/package.json +32 -26
- package/src/circuit/auto-relay.js +4 -4
- package/src/circuit/circuit/hop.js +2 -2
- package/src/circuit/circuit/stop.js +1 -1
- package/src/circuit/circuit/utils.js +2 -2
- package/src/circuit/index.js +1 -1
- package/src/circuit/transport.js +1 -1
- package/src/connection-manager/auto-dialler.js +118 -0
- package/src/connection-manager/index.js +0 -52
- package/src/content-routing/index.js +35 -9
- package/src/dht/dht-content-routing.js +44 -0
- package/src/dht/dht-peer-routing.js +51 -0
- package/src/dialer/index.js +3 -4
- package/src/errors.js +3 -1
- package/src/get-peer.js +1 -1
- package/src/identify/index.js +8 -8
- package/src/index.js +16 -14
- package/src/insecure/plaintext.js +1 -1
- package/src/keychain/cms.js +2 -2
- package/src/keychain/index.js +10 -10
- package/src/nat-manager.js +2 -2
- package/src/peer-routing.js +12 -4
- package/src/peer-store/address-book.js +1 -1
- package/src/peer-store/metadata-book.js +2 -1
- package/src/peer-store/persistent/index.js +6 -6
- package/src/pnet/crypto.js +1 -1
- package/src/pnet/key-generator.js +1 -1
- package/src/transport-manager.js +1 -1
- package/src/upgrader.js +9 -9
|
@@ -23,7 +23,7 @@ declare class PersistentPeerStore extends PeerStore {
|
|
|
23
23
|
/**
|
|
24
24
|
* Backend datastore used to persist data.
|
|
25
25
|
*/
|
|
26
|
-
_datastore: import("interface-datastore
|
|
26
|
+
_datastore: import("interface-datastore").Datastore;
|
|
27
27
|
/**
|
|
28
28
|
* Peers modified after the latest data persisted.
|
|
29
29
|
*/
|
|
@@ -126,5 +126,4 @@ type PersistentPeerStoreOptions = {
|
|
|
126
126
|
};
|
|
127
127
|
type Batch = import('interface-datastore').Batch;
|
|
128
128
|
type Address = import('../address-book.js').Address;
|
|
129
|
-
import PeerId = require("peer-id");
|
|
130
129
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/peer-store/persistent/index.js"],"names":[],"mappings":";AAwBA;;;GAGG;AAEH;;;;;;;GAOG;AAEH;;GAEG;AACH;IACE;;;OAGG;IACH,8CAFW,6BAA6B,GAAG,0BAA0B,EAwBpE;IAnBC;;OAEG;IACH,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/peer-store/persistent/index.js"],"names":[],"mappings":";AAwBA;;;GAGG;AAEH;;;;;;;GAOG;AAEH;;GAEG;AACH;IACE;;;OAGG;IACH,8CAFW,6BAA6B,GAAG,0BAA0B,EAwBpE;IAnBC;;OAEG;IACH,oDAA2B;IAE3B;;OAEG;IACH,sBAA4B;IAE5B;;;;OAIG;IACH,gBAFU,IAAI,MAAM,EAAE,IAAI,MAAM,CAAC,CAAC,CAEH;IAE/B,kBAA0B;IAsC5B;;;;;;OAMG;IACH,sBAYC;IAED;;;;;;OAMG;IACH,yBAiBC;IAED;;;;;;;OAOG;IACH,8BAiBC;IAED;;;;;OAKG;IACH,oBA+BC;IAED;;;;;;OAMG;IACH,0BA8BC;IAED;;;;;;OAMG;IACH,sBAiBC;IAED;;;;;;OAMG;IACH,2BAkBC;IAED;;;;;;OAMG;IACH,wBAmBC;IAED;;;;;;;;OAQG;IACH,+BA0DC;CACF;;;;;;YAtXa,MAAM;eACN,OAAO,qBAAqB,EAAE,SAAS;;;;;;;;aAPxC,OAAO,qBAAqB,EAAE,KAAK;eACnC,OAAO,oBAAoB,EAAE,OAAO"}
|
|
@@ -50,8 +50,31 @@ declare namespace Envelope {
|
|
|
50
50
|
export { createFromProtobuf, seal, openAndCertify, Record };
|
|
51
51
|
}
|
|
52
52
|
import PeerId = require("peer-id");
|
|
53
|
+
/**
|
|
54
|
+
* Unmarshal a serialized Envelope protobuf message.
|
|
55
|
+
*
|
|
56
|
+
* @param {Uint8Array} data
|
|
57
|
+
* @returns {Promise<Envelope>}
|
|
58
|
+
*/
|
|
53
59
|
declare function createFromProtobuf(data: Uint8Array): Promise<Envelope>;
|
|
60
|
+
/**
|
|
61
|
+
* Seal marshals the given Record, places the marshaled bytes inside an Envelope
|
|
62
|
+
* and signs it with the given peerId's private key.
|
|
63
|
+
*
|
|
64
|
+
* @async
|
|
65
|
+
* @param {Record} record
|
|
66
|
+
* @param {PeerId} peerId
|
|
67
|
+
* @returns {Promise<Envelope>}
|
|
68
|
+
*/
|
|
54
69
|
declare function seal(record: Record, peerId: PeerId): Promise<Envelope>;
|
|
70
|
+
/**
|
|
71
|
+
* Open and certify a given marshalled envelope.
|
|
72
|
+
* Data is unmarshalled and the signature validated for the given domain.
|
|
73
|
+
*
|
|
74
|
+
* @param {Uint8Array} data
|
|
75
|
+
* @param {string} domain
|
|
76
|
+
* @returns {Promise<Envelope>}
|
|
77
|
+
*/
|
|
55
78
|
declare function openAndCertify(data: Uint8Array, domain: string): Promise<Envelope>;
|
|
56
79
|
type Record = import('libp2p-interfaces/src/record/types').Record;
|
|
57
80
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/record/envelope/index.js"],"names":[],"mappings":";AAcA;;GAEG;AAEH;IACE;;;;;;;;;;OAUG;IACH;QAL0B,MAAM,EAArB,MAAM;QACa,WAAW,EAA9B,UAAU;QACS,OAAO,EAA1B,UAAU;QACS,SAAS,EAA5B,UAAU;OAUpB;IAPC,eAAoB;IACpB,wBAA8B;IAC9B,oBAAsB;IACtB,sBAA0B;IAG1B,iCAAyB;IAG3B;;;;OAIG;IACH,WAFa,UAAU,CAiBtB;IAED;;;;;OAKG;IACH,cAHW,QAAQ,GACN,OAAO,CAOnB;IAED;;;;;OAKG;IACH,iBAHW,MAAM,GACJ,QAAQ,OAAO,CAAC,CAM5B;CACF;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/record/envelope/index.js"],"names":[],"mappings":";AAcA;;GAEG;AAEH;IACE;;;;;;;;;;OAUG;IACH;QAL0B,MAAM,EAArB,MAAM;QACa,WAAW,EAA9B,UAAU;QACS,OAAO,EAA1B,UAAU;QACS,SAAS,EAA5B,UAAU;OAUpB;IAPC,eAAoB;IACpB,wBAA8B;IAC9B,oBAAsB;IACtB,sBAA0B;IAG1B,iCAAyB;IAG3B;;;;OAIG;IACH,WAFa,UAAU,CAiBtB;IAED;;;;;OAKG;IACH,cAHW,QAAQ,GACN,OAAO,CAOnB;IAED;;;;;OAKG;IACH,iBAHW,MAAM,GACJ,QAAQ,OAAO,CAAC,CAM5B;CACF;;;;;AAkCD;;;;;GAKG;AACH,0CAHW,UAAU,GACR,QAAQ,QAAQ,CAAC,CAY7B;AAED;;;;;;;;GAQG;AACH,8BAJW,MAAM,UACN,MAAM,GACJ,QAAQ,QAAQ,CAAC,CAgB7B;AAED;;;;;;;GAOG;AACH,sCAJW,UAAU,UACV,MAAM,GACJ,QAAQ,QAAQ,CAAC,CAW7B;cArKY,OAAO,oCAAoC,EAAE,MAAM"}
|
|
@@ -48,6 +48,12 @@ declare namespace PeerRecord {
|
|
|
48
48
|
type Record = import('libp2p-interfaces/src/record/types').Record;
|
|
49
49
|
import PeerId = require("peer-id");
|
|
50
50
|
import { Multiaddr } from "multiaddr";
|
|
51
|
+
/**
|
|
52
|
+
* Unmarshal Peer Record Protobuf.
|
|
53
|
+
*
|
|
54
|
+
* @param {Uint8Array} buf - marshaled peer record.
|
|
55
|
+
* @returns {PeerRecord}
|
|
56
|
+
*/
|
|
51
57
|
declare function createFromProtobuf(buf: Uint8Array): PeerRecord;
|
|
52
58
|
import { ENVELOPE_DOMAIN_PEER_RECORD } from "./consts";
|
|
53
59
|
type Address = import('../../peer-store/address-book.js').Address;
|
|
@@ -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;;;
|
|
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,kCAAkC,EAAE,OAAO"}
|
package/dist/src/registrar.d.ts
CHANGED
|
@@ -74,9 +74,9 @@ declare namespace Registrar {
|
|
|
74
74
|
export { PeerId, PeerStore, ConnectionManager, Connection, HandlerProps };
|
|
75
75
|
}
|
|
76
76
|
import Topology = require("libp2p-interfaces/src/topology");
|
|
77
|
-
type HandlerProps = import('./').HandlerProps;
|
|
78
77
|
type Connection = import("libp2p-interfaces/src/connection/connection");
|
|
79
78
|
type PeerId = import('peer-id');
|
|
80
79
|
type PeerStore = import('./peer-store');
|
|
81
80
|
type ConnectionManager = import('./connection-manager');
|
|
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,kCAA0B;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,MAAM,CAiBlB;IAED;;;;;OAKG;IACH,eAHW,MAAM,GACJ,OAAO,CAInB;CAaF
|
|
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,kCAA0B;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,MAAM,CAiBlB;IAED;;;;;OAKG;IACH,eAHW,MAAM,GACJ,OAAO,CAInB;CAaF;;;;;;cA9GY,OAAO,SAAS,CAAC;iBACjB,OAAO,cAAc,CAAC;yBACtB,OAAO,sBAAsB,CAAC;oBAE9B,OAAO,IAAI,EAAE,YAAY"}
|
package/dist/src/upgrader.d.ts
CHANGED
|
@@ -132,8 +132,8 @@ declare namespace Upgrader {
|
|
|
132
132
|
export { MultiaddrConnection, MuxerFactory, Muxer, MuxedStream, Crypto, Connection, Multiaddr, CryptoResult };
|
|
133
133
|
}
|
|
134
134
|
import PeerId = require("peer-id");
|
|
135
|
-
import { Connection } from "libp2p-interfaces/src/connection";
|
|
136
135
|
type MultiaddrConnection = import('libp2p-interfaces/src/transport/types').MultiaddrConnection;
|
|
136
|
+
import { Connection } from "libp2p-interfaces/src/connection";
|
|
137
137
|
type MuxerFactory = import('libp2p-interfaces/src/stream-muxer/types').MuxerFactory;
|
|
138
138
|
type Muxer = import('libp2p-interfaces/src/stream-muxer/types').Muxer;
|
|
139
139
|
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":";AAiBA;;;;;;;;GAQG;AAEH;;;;;GAKG;AAEH;IACE;;;;;;;;OAQG;IACH;mBAPW,MAAM;;;;mCAIO,UAAU,KAAK,IAAI;sCACnB,UAAU,KAAK,IAAI;OAmB1C;IATC,kBAA0B;IAC1B,yCAAsB;IACtB,0EAAsB;IACtB,qFAAoB;IACpB,sCAAsC;IACtC,WADW,OAAO,QAAQ,CAAC,GAAG,IAAI,CACb;IACrB,yBAA0B;IAC1B,2BAlBsB,UAAU,KAAK,IAAI,CAkBT;IAChC,8BAlBsB,UAAU,KAAK,IAAI,CAkBH;IAGxC;;;;;;OAMG;IACH,uBAHW,mBAAmB,GACjB,QAAQ,UAAU,CAAC,CA6D/B;IAED;;;;;;OAMG;IACH,wBAHW,mBAAmB,GACjB,QAAQ,UAAU,CAAC,CAoE/B;IAED;;;;;;;;;;;;OAYG;IACH,0BA8GC;IAED;;;;;;;;OAQG;IACH,kBAGC;IAED;;;;;;;;;OASG;IACH,wBAqBC;IAED;;;;;;;;;;;OAWG;IACH,yBAqBC;IAED;;;;;;;;;OASG;IACH,2BAYC;IAED;;;;;;;;;OASG;IACH,0BAWC;CACF
|
|
1
|
+
{"version":3,"file":"upgrader.d.ts","sourceRoot":"","sources":["../../src/upgrader.js"],"names":[],"mappings":";AAiBA;;;;;;;;GAQG;AAEH;;;;;GAKG;AAEH;IACE;;;;;;;;OAQG;IACH;mBAPW,MAAM;;;;mCAIO,UAAU,KAAK,IAAI;sCACnB,UAAU,KAAK,IAAI;OAmB1C;IATC,kBAA0B;IAC1B,yCAAsB;IACtB,0EAAsB;IACtB,qFAAoB;IACpB,sCAAsC;IACtC,WADW,OAAO,QAAQ,CAAC,GAAG,IAAI,CACb;IACrB,yBAA0B;IAC1B,2BAlBsB,UAAU,KAAK,IAAI,CAkBT;IAChC,8BAlBsB,UAAU,KAAK,IAAI,CAkBH;IAGxC;;;;;;OAMG;IACH,uBAHW,mBAAmB,GACjB,QAAQ,UAAU,CAAC,CA6D/B;IAED;;;;;;OAMG;IACH,wBAHW,mBAAmB,GACjB,QAAQ,UAAU,CAAC,CAoE/B;IAED;;;;;;;;;;;;OAYG;IACH,0BA8GC;IAED;;;;;;;;OAQG;IACH,kBAGC;IAED;;;;;;;;;OASG;IACH,wBAqBC;IAED;;;;;;;;;;;OAWG;IACH,yBAqBC;IAED;;;;;;;;;OASG;IACH,2BAYC;IAED;;;;;;;;;OASG;IACH,0BAWC;CACF;;;;;2BAzbY,OAAO,uCAAuC,EAAE,mBAAmB;;oBACnE,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;;;;;UAK5B,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.35.1",
|
|
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",
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"test:node": "aegir test -t node -f \"./test/**/*.{node,spec}.js\"",
|
|
42
42
|
"test:browser": "aegir test -t browser",
|
|
43
43
|
"test:examples": "cd examples && npm run test:all",
|
|
44
|
+
"test:interop": "LIBP2P_JS=$PWD npx aegir test -t node -f ./node_modules/libp2p-interop/test/*",
|
|
44
45
|
"prepare": "aegir build --no-bundle",
|
|
45
46
|
"release": "aegir release -t node -t browser",
|
|
46
47
|
"release-minor": "aegir release --type minor -t node -t browser",
|
|
@@ -65,7 +66,7 @@
|
|
|
65
66
|
"homepage": "https://libp2p.io",
|
|
66
67
|
"license": "MIT",
|
|
67
68
|
"engines": {
|
|
68
|
-
"node": ">=
|
|
69
|
+
"node": ">=15.0.0"
|
|
69
70
|
},
|
|
70
71
|
"browser": {
|
|
71
72
|
"@motrix/nat-api": false
|
|
@@ -74,14 +75,15 @@
|
|
|
74
75
|
"extends": "ipfs",
|
|
75
76
|
"ignorePatterns": [
|
|
76
77
|
"!.aegir.js",
|
|
77
|
-
"test/ts-use"
|
|
78
|
+
"test/ts-use",
|
|
79
|
+
"*.d.ts"
|
|
78
80
|
]
|
|
79
81
|
},
|
|
80
82
|
"dependencies": {
|
|
81
|
-
"abortable-iterator": "^3.0.0",
|
|
82
83
|
"@motrix/nat-api": "^0.3.1",
|
|
83
84
|
"@vascosantos/moving-average": "^1.1.0",
|
|
84
85
|
"abort-controller": "^3.0.0",
|
|
86
|
+
"abortable-iterator": "^3.0.0",
|
|
85
87
|
"aggregate-error": "^3.1.0",
|
|
86
88
|
"any-signal": "^2.1.1",
|
|
87
89
|
"bignumber.js": "^9.0.1",
|
|
@@ -91,7 +93,7 @@
|
|
|
91
93
|
"es6-promisify": "^7.0.0",
|
|
92
94
|
"events": "^3.3.0",
|
|
93
95
|
"hashlru": "^2.3.0",
|
|
94
|
-
"interface-datastore": "^
|
|
96
|
+
"interface-datastore": "^6.0.2",
|
|
95
97
|
"it-all": "^1.0.4",
|
|
96
98
|
"it-buffer": "^0.1.2",
|
|
97
99
|
"it-drain": "^1.0.3",
|
|
@@ -103,8 +105,8 @@
|
|
|
103
105
|
"it-merge": "^1.0.0",
|
|
104
106
|
"it-pipe": "^1.1.0",
|
|
105
107
|
"it-take": "^1.0.0",
|
|
106
|
-
"libp2p-crypto": "^0.
|
|
107
|
-
"libp2p-interfaces": "^
|
|
108
|
+
"libp2p-crypto": "^0.21.0",
|
|
109
|
+
"libp2p-interfaces": "^2.0.1",
|
|
108
110
|
"libp2p-utils": "^0.4.0",
|
|
109
111
|
"mafmt": "^10.0.0",
|
|
110
112
|
"merge-options": "^3.0.4",
|
|
@@ -117,14 +119,14 @@
|
|
|
117
119
|
"p-fifo": "^1.0.0",
|
|
118
120
|
"p-retry": "^4.4.0",
|
|
119
121
|
"p-settle": "^4.1.1",
|
|
120
|
-
"peer-id": "^0.
|
|
122
|
+
"peer-id": "^0.16.0",
|
|
121
123
|
"private-ip": "^2.1.0",
|
|
122
124
|
"protobufjs": "^6.10.2",
|
|
123
125
|
"retimer": "^3.0.0",
|
|
124
126
|
"sanitize-filename": "^1.6.3",
|
|
125
127
|
"set-delayed-interval": "^1.0.0",
|
|
126
128
|
"streaming-iterables": "^6.0.0",
|
|
127
|
-
"timeout-abort-controller": "^
|
|
129
|
+
"timeout-abort-controller": "^2.0.0",
|
|
128
130
|
"uint8arrays": "^3.0.0",
|
|
129
131
|
"varint": "^6.0.0",
|
|
130
132
|
"wherearewe": "^1.0.0",
|
|
@@ -137,34 +139,35 @@
|
|
|
137
139
|
"@types/node": "^16.0.1",
|
|
138
140
|
"@types/node-forge": "^0.10.1",
|
|
139
141
|
"@types/varint": "^6.0.0",
|
|
140
|
-
"aegir": "^
|
|
142
|
+
"aegir": "^36.0.0",
|
|
141
143
|
"buffer": "^6.0.3",
|
|
144
|
+
"datastore-core": "^6.0.7",
|
|
142
145
|
"delay": "^5.0.0",
|
|
143
|
-
"
|
|
144
|
-
"
|
|
145
|
-
"ipfs-http-client": "^52.0.2",
|
|
146
|
+
"into-stream": "^6.0.0",
|
|
147
|
+
"ipfs-http-client": "^54.0.2",
|
|
146
148
|
"it-concat": "^2.0.0",
|
|
147
149
|
"it-pair": "^1.0.0",
|
|
148
150
|
"it-pushable": "^1.4.0",
|
|
149
151
|
"libp2p": ".",
|
|
150
|
-
"libp2p-bootstrap": "^0.
|
|
152
|
+
"libp2p-bootstrap": "^0.14.0",
|
|
151
153
|
"libp2p-delegated-content-routing": "^0.11.0",
|
|
152
|
-
"libp2p-delegated-peer-routing": "^0.
|
|
154
|
+
"libp2p-delegated-peer-routing": "^0.11.0",
|
|
153
155
|
"libp2p-floodsub": "^0.27.0",
|
|
154
156
|
"libp2p-gossipsub": "^0.11.0",
|
|
155
|
-
"libp2p-interfaces-compliance-tests": "^
|
|
156
|
-
"libp2p-
|
|
157
|
-
"libp2p-
|
|
157
|
+
"libp2p-interfaces-compliance-tests": "^2.0.1",
|
|
158
|
+
"libp2p-interop": "^0.5.0",
|
|
159
|
+
"libp2p-kad-dht": "^0.27.1",
|
|
160
|
+
"libp2p-mdns": "^0.18.0",
|
|
158
161
|
"libp2p-mplex": "^0.10.1",
|
|
159
162
|
"libp2p-tcp": "^0.17.0",
|
|
160
|
-
"libp2p-webrtc-star": "^0.
|
|
163
|
+
"libp2p-webrtc-star": "^0.25.0",
|
|
161
164
|
"libp2p-websockets": "^0.16.0",
|
|
162
165
|
"nock": "^13.0.3",
|
|
163
166
|
"p-defer": "^3.0.0",
|
|
164
167
|
"p-times": "^3.0.0",
|
|
165
168
|
"p-wait-for": "^3.2.0",
|
|
166
169
|
"rimraf": "^3.0.2",
|
|
167
|
-
"sinon": "^
|
|
170
|
+
"sinon": "^12.0.1",
|
|
168
171
|
"util": "^0.12.3"
|
|
169
172
|
},
|
|
170
173
|
"contributors": [
|
|
@@ -178,28 +181,28 @@
|
|
|
178
181
|
"Friedel Ziegelmayer <dignifiedquire@gmail.com>",
|
|
179
182
|
"Maciej Krüger <mkg20001@gmail.com>",
|
|
180
183
|
"Hugo Dias <mail@hugodias.me>",
|
|
181
|
-
"Chris Dostert <chrisdostert@users.noreply.github.com>",
|
|
182
184
|
"dirkmc <dirkmdev@gmail.com>",
|
|
185
|
+
"Chris Dostert <chrisdostert@users.noreply.github.com>",
|
|
183
186
|
"Volker Mische <volker.mische@gmail.com>",
|
|
184
187
|
"zeim839 <50573884+zeim839@users.noreply.github.com>",
|
|
185
188
|
"Richard Littauer <richard.littauer@gmail.com>",
|
|
186
189
|
"a1300 <matthias-knopp@gmx.net>",
|
|
187
190
|
"Ryan Bell <ryan@piing.net>",
|
|
188
191
|
"ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ <victorbjelkholm@gmail.com>",
|
|
189
|
-
"Franck Royer <franck@royer.one>",
|
|
190
|
-
"Thomas Eizinger <thomas@eizinger.io>",
|
|
191
192
|
"Giovanni T. Parra <fiatjaf@gmail.com>",
|
|
192
193
|
"acolytec3 <17355484+acolytec3@users.noreply.github.com>",
|
|
194
|
+
"Franck Royer <franck@royer.one>",
|
|
193
195
|
"Elven <mon.samuel@qq.com>",
|
|
196
|
+
"Robert Kiel <robert.kiel@hoprnet.org>",
|
|
194
197
|
"Andrew Nesbitt <andrewnez@gmail.com>",
|
|
195
198
|
"Samlior <samlior@foxmail.com>",
|
|
199
|
+
"Thomas Eizinger <thomas@eizinger.io>",
|
|
196
200
|
"Didrik Nordström <didrik.nordstrom@gmail.com>",
|
|
197
|
-
"RasmusErik Voel Jensen <github@solsort.com>",
|
|
198
|
-
"Robert Kiel <robert.kiel@hoprnet.org>",
|
|
199
201
|
"Smite Chow <xiaopengyou@live.com>",
|
|
200
202
|
"Soeren <nikorpoulsen@gmail.com>",
|
|
201
203
|
"Sönke Hahn <soenkehahn@gmail.com>",
|
|
202
204
|
"TJKoury <TJKoury@gmail.com>",
|
|
205
|
+
"TheStarBoys <41286328+TheStarBoys@users.noreply.github.com>",
|
|
203
206
|
"Tiago Alves <alvesjtiago@gmail.com>",
|
|
204
207
|
"XiaoZhang <zxinmyth@gmail.com>",
|
|
205
208
|
"Yusef Napora <yusef@napora.org>",
|
|
@@ -209,11 +212,13 @@
|
|
|
209
212
|
"isan_rivkin <isanrivkin@gmail.com>",
|
|
210
213
|
"mayerwin <mayerwin@users.noreply.github.com>",
|
|
211
214
|
"mcclure <andi.m.mcclure@gmail.com>",
|
|
215
|
+
"patrickwoodhead <91056047+patrickwoodhead@users.noreply.github.com>",
|
|
212
216
|
"phillmac <phillmac@users.noreply.github.com>",
|
|
213
217
|
"robertkiel <robert.kiel@validitylabs.org>",
|
|
214
218
|
"shresthagrawal <34920931+shresthagrawal@users.noreply.github.com>",
|
|
215
219
|
"swedneck <40505480+swedneck@users.noreply.github.com>",
|
|
216
220
|
"greenSnot <greenSnot@users.noreply.github.com>",
|
|
221
|
+
"Alan Smithee <ggnore.alan.smithee@gmail.com>",
|
|
217
222
|
"Aleksei <vozhdb@gmail.com>",
|
|
218
223
|
"Bernd Strehl <bernd.strehl@gmail.com>",
|
|
219
224
|
"Chris Bratlien <chrisbratlien@gmail.com>",
|
|
@@ -241,6 +246,7 @@
|
|
|
241
246
|
"Michael Burns <5170+mburns@users.noreply.github.com>",
|
|
242
247
|
"Miguel Mota <miguelmota2@gmail.com>",
|
|
243
248
|
"Nuno Nogueira <nunofmn@gmail.com>",
|
|
244
|
-
"Philipp Muens <raute1337@gmx.de>"
|
|
249
|
+
"Philipp Muens <raute1337@gmx.de>",
|
|
250
|
+
"RasmusErik Voel Jensen <github@solsort.com>"
|
|
245
251
|
]
|
|
246
252
|
}
|
|
@@ -116,7 +116,7 @@ class AutoRelay {
|
|
|
116
116
|
this._peerStore.metadataBook.set(peerId, HOP_METADATA_KEY, uint8ArrayFromString(HOP_METADATA_VALUE))
|
|
117
117
|
await this._addListenRelay(connection, id)
|
|
118
118
|
}
|
|
119
|
-
} catch (err) {
|
|
119
|
+
} catch (/** @type {any} */ err) {
|
|
120
120
|
this._onError(err)
|
|
121
121
|
}
|
|
122
122
|
}
|
|
@@ -169,7 +169,7 @@ class AutoRelay {
|
|
|
169
169
|
try {
|
|
170
170
|
await this._transportManager.listen([new Multiaddr(listenAddr)])
|
|
171
171
|
// Announce multiaddrs will update on listen success by TransportManager event being triggered
|
|
172
|
-
} catch (err) {
|
|
172
|
+
} catch (/** @type {any} */ err) {
|
|
173
173
|
this._onError(err)
|
|
174
174
|
this._listenRelays.delete(id)
|
|
175
175
|
}
|
|
@@ -267,7 +267,7 @@ class AutoRelay {
|
|
|
267
267
|
return
|
|
268
268
|
}
|
|
269
269
|
}
|
|
270
|
-
} catch (err) {
|
|
270
|
+
} catch (/** @type {any} */ err) {
|
|
271
271
|
this._onError(err)
|
|
272
272
|
}
|
|
273
273
|
}
|
|
@@ -279,7 +279,7 @@ class AutoRelay {
|
|
|
279
279
|
try {
|
|
280
280
|
const connection = await this._libp2p.dial(peerId)
|
|
281
281
|
await this._addListenRelay(connection, peerId.toB58String())
|
|
282
|
-
} catch (err) {
|
|
282
|
+
} catch (/** @type {any} */ err) {
|
|
283
283
|
this._onError(err, `could not connect and listen on known hop relay ${peerId.toB58String()}`)
|
|
284
284
|
}
|
|
285
285
|
}
|
|
@@ -54,7 +54,7 @@ async function handleHop ({
|
|
|
54
54
|
// Validate the HOP request has the required input
|
|
55
55
|
try {
|
|
56
56
|
validateAddrs(request, streamHandler)
|
|
57
|
-
} catch (err) {
|
|
57
|
+
} catch (/** @type {any} */ err) {
|
|
58
58
|
return log.error('invalid hop request via peer %s', connection.remotePeer.toB58String(), err)
|
|
59
59
|
}
|
|
60
60
|
|
|
@@ -93,7 +93,7 @@ async function handleHop ({
|
|
|
93
93
|
connection: destinationConnection,
|
|
94
94
|
request: stopRequest
|
|
95
95
|
})
|
|
96
|
-
} catch (err) {
|
|
96
|
+
} catch (/** @type {any} */ err) {
|
|
97
97
|
return log.error(err)
|
|
98
98
|
}
|
|
99
99
|
|
|
@@ -34,7 +34,7 @@ module.exports.handleStop = function handleStop ({
|
|
|
34
34
|
// Validate the STOP request has the required input
|
|
35
35
|
try {
|
|
36
36
|
validateAddrs(request, streamHandler)
|
|
37
|
-
} catch (err) {
|
|
37
|
+
} catch (/** @type {any} */ err) {
|
|
38
38
|
return log.error('invalid stop request via peer %s', connection.remotePeer.toB58String(), err)
|
|
39
39
|
}
|
|
40
40
|
|
|
@@ -34,7 +34,7 @@ function validateAddrs (msg, streamHandler) {
|
|
|
34
34
|
return new Multiaddr(addr)
|
|
35
35
|
})
|
|
36
36
|
}
|
|
37
|
-
} catch (err) {
|
|
37
|
+
} catch (/** @type {any} */ err) {
|
|
38
38
|
writeResponse(streamHandler, msg.type === CircuitRelay.Type.HOP
|
|
39
39
|
? CircuitRelay.Status.HOP_DST_MULTIADDR_INVALID
|
|
40
40
|
: CircuitRelay.Status.STOP_DST_MULTIADDR_INVALID)
|
|
@@ -47,7 +47,7 @@ function validateAddrs (msg, streamHandler) {
|
|
|
47
47
|
return new Multiaddr(addr)
|
|
48
48
|
})
|
|
49
49
|
}
|
|
50
|
-
} catch (err) {
|
|
50
|
+
} catch (/** @type {any} */ err) {
|
|
51
51
|
writeResponse(streamHandler, msg.type === CircuitRelay.Type.HOP
|
|
52
52
|
? CircuitRelay.Status.HOP_SRC_MULTIADDR_INVALID
|
|
53
53
|
: CircuitRelay.Status.STOP_SRC_MULTIADDR_INVALID)
|
package/src/circuit/index.js
CHANGED
|
@@ -87,7 +87,7 @@ class Relay {
|
|
|
87
87
|
try {
|
|
88
88
|
const cid = await namespaceToCid(RELAY_RENDEZVOUS_NS)
|
|
89
89
|
await this._libp2p.contentRouting.provide(cid)
|
|
90
|
-
} catch (err) {
|
|
90
|
+
} catch (/** @type {any} */ err) {
|
|
91
91
|
if (err.code === '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
|
package/src/circuit/transport.js
CHANGED
|
@@ -171,7 +171,7 @@ class Circuit {
|
|
|
171
171
|
log('new outbound connection %s', maConn.remoteAddr)
|
|
172
172
|
|
|
173
173
|
return this._upgrader.upgradeOutbound(maConn)
|
|
174
|
-
} catch (err) {
|
|
174
|
+
} catch (/** @type {any} */ err) {
|
|
175
175
|
log.error('Circuit relay dial failed', err)
|
|
176
176
|
disconnectOnFailure && await relayConnection.close()
|
|
177
177
|
throw err
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const debug = require('debug')
|
|
4
|
+
const mergeOptions = require('merge-options')
|
|
5
|
+
// @ts-ignore retimer does not have types
|
|
6
|
+
const retimer = require('retimer')
|
|
7
|
+
|
|
8
|
+
const log = Object.assign(debug('libp2p:connection-manager:auto-dialler'), {
|
|
9
|
+
error: debug('libp2p:connection-manager:auto-dialler:err')
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
const defaultOptions = {
|
|
13
|
+
enabled: true,
|
|
14
|
+
minConnections: 0,
|
|
15
|
+
autoDialInterval: 10000
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @typedef {import('../index')} Libp2p
|
|
20
|
+
* @typedef {import('libp2p-interfaces/src/connection').Connection} Connection
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @typedef {Object} AutoDiallerOptions
|
|
25
|
+
* @property {boolean} [enabled = true] - Should preemptively guarantee connections are above the low watermark
|
|
26
|
+
* @property {number} [minConnections = 0] - The minimum number of connections to avoid pruning
|
|
27
|
+
* @property {number} [autoDialInterval = 10000] - How often, in milliseconds, it should preemptively guarantee connections are above the low watermark
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
class AutoDialler {
|
|
31
|
+
/**
|
|
32
|
+
* Proactively tries to connect to known peers stored in the PeerStore.
|
|
33
|
+
* It will keep the number of connections below the upper limit and sort
|
|
34
|
+
* the peers to connect based on wether we know their keys and protocols.
|
|
35
|
+
*
|
|
36
|
+
* @class
|
|
37
|
+
* @param {Libp2p} libp2p
|
|
38
|
+
* @param {AutoDiallerOptions} options
|
|
39
|
+
*/
|
|
40
|
+
constructor (libp2p, options = {}) {
|
|
41
|
+
this._options = mergeOptions.call({ ignoreUndefined: true }, defaultOptions, options)
|
|
42
|
+
this._libp2p = libp2p
|
|
43
|
+
this._running = false
|
|
44
|
+
this._autoDialTimeout = null
|
|
45
|
+
this._autoDial = this._autoDial.bind(this)
|
|
46
|
+
|
|
47
|
+
log('options: %j', this._options)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Starts the auto dialer
|
|
52
|
+
*/
|
|
53
|
+
start () {
|
|
54
|
+
if (!this._options.enabled) {
|
|
55
|
+
log('not enabled')
|
|
56
|
+
return
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
this._running = true
|
|
60
|
+
this._autoDial()
|
|
61
|
+
log('started')
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Stops the auto dialler
|
|
66
|
+
*/
|
|
67
|
+
async stop () {
|
|
68
|
+
if (!this._options.enabled) {
|
|
69
|
+
log('not enabled')
|
|
70
|
+
return
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
this._running = false
|
|
74
|
+
this._autoDialTimeout && this._autoDialTimeout.clear()
|
|
75
|
+
log('stopped')
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async _autoDial () {
|
|
79
|
+
const minConnections = this._options.minConnections
|
|
80
|
+
|
|
81
|
+
// Already has enough connections
|
|
82
|
+
if (this._libp2p.connections.size >= minConnections) {
|
|
83
|
+
this._autoDialTimeout = retimer(this._autoDial, this._options.autoDialInterval)
|
|
84
|
+
return
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Sort peers on wether we know protocols of public keys for them
|
|
88
|
+
const peers = Array.from(this._libp2p.peerStore.peers.values())
|
|
89
|
+
.sort((a, b) => {
|
|
90
|
+
if (b.protocols && b.protocols.length && (!a.protocols || !a.protocols.length)) {
|
|
91
|
+
return 1
|
|
92
|
+
} else if (b.id.pubKey && !a.id.pubKey) {
|
|
93
|
+
return 1
|
|
94
|
+
}
|
|
95
|
+
return -1
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
for (let i = 0; this._running && i < peers.length && this._libp2p.connections.size < minConnections; i++) {
|
|
99
|
+
if (!this._libp2p.connectionManager.get(peers[i].id)) {
|
|
100
|
+
log('connecting to a peerStore stored peer %s', peers[i].id.toB58String())
|
|
101
|
+
try {
|
|
102
|
+
await this._libp2p.dialer.connectToPeer(peers[i].id)
|
|
103
|
+
} catch (/** @type {any} */ err) {
|
|
104
|
+
log.error('could not connect to peerStore stored peer', err)
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Connection Manager was stopped
|
|
110
|
+
if (!this._running) {
|
|
111
|
+
return
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
this._autoDialTimeout = retimer(this._autoDial, this._options.autoDialInterval)
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
module.exports = AutoDialler
|
|
@@ -94,9 +94,7 @@ class ConnectionManager extends EventEmitter {
|
|
|
94
94
|
|
|
95
95
|
this._started = false
|
|
96
96
|
this._timer = null
|
|
97
|
-
this._autoDialTimeout = null
|
|
98
97
|
this._checkMetrics = this._checkMetrics.bind(this)
|
|
99
|
-
this._autoDial = this._autoDial.bind(this)
|
|
100
98
|
|
|
101
99
|
this._latencyMonitor = new LatencyMonitor({
|
|
102
100
|
latencyCheckIntervalMs: this._options.pollInterval,
|
|
@@ -128,8 +126,6 @@ class ConnectionManager extends EventEmitter {
|
|
|
128
126
|
|
|
129
127
|
this._started = true
|
|
130
128
|
log('started')
|
|
131
|
-
|
|
132
|
-
this._options.autoDial && this._autoDial()
|
|
133
129
|
}
|
|
134
130
|
|
|
135
131
|
/**
|
|
@@ -138,7 +134,6 @@ class ConnectionManager extends EventEmitter {
|
|
|
138
134
|
* @async
|
|
139
135
|
*/
|
|
140
136
|
async stop () {
|
|
141
|
-
this._autoDialTimeout && this._autoDialTimeout.clear()
|
|
142
137
|
this._timer && this._timer.clear()
|
|
143
138
|
|
|
144
139
|
this._latencyMonitor.removeListener('data', this._onLatencyMeasure)
|
|
@@ -312,53 +307,6 @@ class ConnectionManager extends EventEmitter {
|
|
|
312
307
|
}
|
|
313
308
|
}
|
|
314
309
|
|
|
315
|
-
/**
|
|
316
|
-
* Proactively tries to connect to known peers stored in the PeerStore.
|
|
317
|
-
* It will keep the number of connections below the upper limit and sort
|
|
318
|
-
* the peers to connect based on wether we know their keys and protocols.
|
|
319
|
-
*
|
|
320
|
-
* @async
|
|
321
|
-
* @private
|
|
322
|
-
*/
|
|
323
|
-
async _autoDial () {
|
|
324
|
-
const minConnections = this._options.minConnections
|
|
325
|
-
|
|
326
|
-
// Already has enough connections
|
|
327
|
-
if (this.size >= minConnections) {
|
|
328
|
-
this._autoDialTimeout = retimer(this._autoDial, this._options.autoDialInterval)
|
|
329
|
-
return
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
// Sort peers on wether we know protocols of public keys for them
|
|
333
|
-
const peers = Array.from(this._libp2p.peerStore.peers.values())
|
|
334
|
-
.sort((a, b) => {
|
|
335
|
-
if (b.protocols && b.protocols.length && (!a.protocols || !a.protocols.length)) {
|
|
336
|
-
return 1
|
|
337
|
-
} else if (b.id.pubKey && !a.id.pubKey) {
|
|
338
|
-
return 1
|
|
339
|
-
}
|
|
340
|
-
return -1
|
|
341
|
-
})
|
|
342
|
-
|
|
343
|
-
for (let i = 0; i < peers.length && this.size < minConnections; i++) {
|
|
344
|
-
if (!this.get(peers[i].id)) {
|
|
345
|
-
log('connecting to a peerStore stored peer %s', peers[i].id.toB58String())
|
|
346
|
-
try {
|
|
347
|
-
await this._libp2p.dialer.connectToPeer(peers[i].id)
|
|
348
|
-
|
|
349
|
-
// Connection Manager was stopped
|
|
350
|
-
if (!this._started) {
|
|
351
|
-
return
|
|
352
|
-
}
|
|
353
|
-
} catch (err) {
|
|
354
|
-
log.error('could not connect to peerStore stored peer', err)
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
this._autoDialTimeout = retimer(this._autoDial, this._options.autoDialInterval)
|
|
360
|
-
}
|
|
361
|
-
|
|
362
310
|
/**
|
|
363
311
|
* If we have more connections than our maximum, close a connection
|
|
364
312
|
* to the lowest valued peer.
|