libp2p 0.34.0 → 0.35.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.
@@ -0,0 +1,56 @@
1
+ export = AutoDialler;
2
+ /**
3
+ * @typedef {import('../index')} Libp2p
4
+ * @typedef {import('libp2p-interfaces/src/connection').Connection} Connection
5
+ */
6
+ /**
7
+ * @typedef {Object} AutoDiallerOptions
8
+ * @property {boolean} [enabled = true] - Should preemptively guarantee connections are above the low watermark
9
+ * @property {number} [minConnections = 0] - The minimum number of connections to avoid pruning
10
+ * @property {number} [autoDialInterval = 10000] - How often, in milliseconds, it should preemptively guarantee connections are above the low watermark
11
+ */
12
+ declare class AutoDialler {
13
+ /**
14
+ * Proactively tries to connect to known peers stored in the PeerStore.
15
+ * It will keep the number of connections below the upper limit and sort
16
+ * the peers to connect based on wether we know their keys and protocols.
17
+ *
18
+ * @class
19
+ * @param {Libp2p} libp2p
20
+ * @param {AutoDiallerOptions} options
21
+ */
22
+ constructor(libp2p: Libp2p, options?: AutoDiallerOptions);
23
+ _options: any;
24
+ _libp2p: import("../index");
25
+ _running: boolean;
26
+ _autoDialTimeout: any;
27
+ _autoDial(): Promise<void>;
28
+ /**
29
+ * Starts the auto dialer
30
+ */
31
+ start(): void;
32
+ /**
33
+ * Stops the auto dialler
34
+ */
35
+ stop(): Promise<void>;
36
+ }
37
+ declare namespace AutoDialler {
38
+ export { Libp2p, Connection, AutoDiallerOptions };
39
+ }
40
+ type Libp2p = import('../index');
41
+ type AutoDiallerOptions = {
42
+ /**
43
+ * - Should preemptively guarantee connections are above the low watermark
44
+ */
45
+ enabled?: boolean | undefined;
46
+ /**
47
+ * - The minimum number of connections to avoid pruning
48
+ */
49
+ minConnections?: number | undefined;
50
+ /**
51
+ * - How often, in milliseconds, it should preemptively guarantee connections are above the low watermark
52
+ */
53
+ autoDialInterval?: number | undefined;
54
+ };
55
+ type Connection = import("libp2p-interfaces/src/connection/connection");
56
+ //# sourceMappingURL=auto-dialler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auto-dialler.d.ts","sourceRoot":"","sources":["../../../src/connection-manager/auto-dialler.js"],"names":[],"mappings":";AAiBA;;;GAGG;AAEH;;;;;GAKG;AAEH;IACE;;;;;;;;OAQG;IACH,oBAHW,MAAM,YACN,kBAAkB,EAU5B;IAPC,cAAqF;IACrF,4BAAqB;IACrB,kBAAqB;IACrB,sBAA4B;IAkC9B,2BAqCC;IAjED;;OAEG;IACH,cASC;IAED;;OAEG;IACH,sBASC;CAwCF;;;;cAjGY,OAAO,UAAU,CAAC"}
@@ -48,7 +48,6 @@ declare class ConnectionManager extends EventEmitter {
48
48
  connections: Map<string, Connection[]>;
49
49
  _started: boolean;
50
50
  _timer: any;
51
- _autoDialTimeout: any;
52
51
  /**
53
52
  * Checks the libp2p metrics to determine if any values have exceeded
54
53
  * the configured maximums.
@@ -56,15 +55,6 @@ declare class ConnectionManager extends EventEmitter {
56
55
  * @private
57
56
  */
58
57
  private _checkMetrics;
59
- /**
60
- * Proactively tries to connect to known peers stored in the PeerStore.
61
- * It will keep the number of connections below the upper limit and sort
62
- * the peers to connect based on wether we know their keys and protocols.
63
- *
64
- * @async
65
- * @private
66
- */
67
- private _autoDial;
68
58
  _latencyMonitor: LatencyMonitor;
69
59
  /**
70
60
  * Get current number of open connections.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/connection-manager/index.js"],"names":[],"mappings":";AAkCA;;;GAGG;AAEH;;;;;;;;;;;;;GAaG;AAEH;;;;GAIG;AACH;IACE;;;;;;OAMG;IACH,oBAHW,MAAM,YACN,wBAAwB,EAuClC;IAlCC,uBAAqB;IACrB,gBAA0C;IAE1C,cAAqF;IAOrF;;;;OAIG;IACH,aAFU,IAAI,MAAM,EAAE,MAAM,CAAC,CAED;IAE5B;;;;OAIG;IACH,aAFU,IAAI,MAAM,EAAE,UAAU,EAAE,CAAC,CAEP;IAE5B,kBAAqB;IACrB,YAAkB;IAClB,sBAA4B;IAwF9B;;;;;OAKG;IACH,sBAcC;IA8GD;;;;;;;OAOG;IACH,kBAqCC;IAnQC,gCAGE;IAGJ;;OAEG;IACH,mBAGC;IAED;;;OAGG;IACH,cAcC;IA4JD;;;;;OAKG;IACH,0BAEC;IAlKD;;;;OAIG;IACH,sBAUC;IAED;;;;OAIG;IACH,wBAWC;IAED;;;;;;;OAOG;IACH,qBAJW,MAAM,SACN,MAAM,GACJ,IAAI,CAOhB;IAwBD;;;;;OAKG;IACH,sBAHW,UAAU,GACR,IAAI,CAqBhB;IAED;;;;;OAKG;IACH,yBAHW,UAAU,GACR,IAAI,CAchB;IAED;;;;;OAKG;IACH,YAHW,MAAM,GACJ,UAAU,GAAC,IAAI,CAQ3B;IAED;;;;;OAKG;IACH,eAHW,MAAM,GACJ,UAAU,EAAE,CAexB;IAYD;;;;;;OAMG;IACH,uBAOC;IAiDD;;;;;OAKG;IACH,4BAiBC;CACF;;;;;;;;cA9VY,OAAO,KAAK,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/connection-manager/index.js"],"names":[],"mappings":";AAkCA;;;GAGG;AAEH;;;;;;;;;;;;;GAaG;AAEH;;;;GAIG;AACH;IACE;;;;;;OAMG;IACH,oBAHW,MAAM,YACN,wBAAwB,EAqClC;IAhCC,uBAAqB;IACrB,gBAA0C;IAE1C,cAAqF;IAOrF;;;;OAIG;IACH,aAFU,IAAI,MAAM,EAAE,MAAM,CAAC,CAED;IAE5B;;;;OAIG;IACH,aAFU,IAAI,MAAM,EAAE,UAAU,EAAE,CAAC,CAEP;IAE5B,kBAAqB;IACrB,YAAkB;IAoFpB;;;;;OAKG;IACH,sBAcC;IArGC,gCAGE;IAGJ;;OAEG;IACH,mBAGC;IAED;;;OAGG;IACH,cAYC;IA2JD;;;;;OAKG;IACH,0BAEC;IAjKD;;;;OAIG;IACH,sBASC;IAED;;;;OAIG;IACH,wBAWC;IAED;;;;;;;OAOG;IACH,qBAJW,MAAM,SACN,MAAM,GACJ,IAAI,CAOhB;IAwBD;;;;;OAKG;IACH,sBAHW,UAAU,GACR,IAAI,CAqBhB;IAED;;;;;OAKG;IACH,yBAHW,UAAU,GACR,IAAI,CAchB;IAED;;;;;OAKG;IACH,YAHW,MAAM,GACJ,UAAU,GAAC,IAAI,CAQ3B;IAED;;;;;OAKG;IACH,eAHW,MAAM,GACJ,UAAU,EAAE,CAexB;IAYD;;;;;;OAMG;IACH,uBAOC;IAED;;;;;OAKG;IACH,4BAiBC;CACF;;;;;;;;cA1SY,OAAO,KAAK,CAAC"}
@@ -163,7 +163,7 @@ type TransportManager = import('../transport-manager');
163
163
  type Resolver = (addr: Multiaddr) => Promise<string[]>;
164
164
  type PendingDial = {
165
165
  dialRequest: DialRequest;
166
- controller: any;
166
+ controller: TimeoutController;
167
167
  promise: Promise<Connection>;
168
168
  destroy: () => void;
169
169
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/dialer/index.js"],"names":[],"mappings":";AAyBA;;;;;;GAMG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH;IACE;;;OAGG;IACH,uIAFW,gBAAgB,GAAG,aAAa,EA0B1C;IAdC,iDAAwC;IACxC,mCAA0B;IAC1B,2BAnCsB,OAAO,EAAE,KAAK,OAAO,EAAE,CAmCX;IAClC,yBAAwC;IACxC,uBAAoC;IACpC,gBAA0B;IAC1B,wBAAsC;IACtC,iBAAuE;IACvE,6BAA8B;IAC9B,mCAAoC;IAOtC;;OAEG;IACH,gBAcC;IAED;;;;;;;;;OASG;IACH,oBALW,MAAM,GAAC,SAAS,GAAC,MAAM;;oBAGrB,QAAQ,UAAU,CAAC,CAwB/B;IAED;;;;;;;OAOG;IACH,mCAHW,MAAM,GAAC,SAAS,GAAC,MAAM,GACrB,QAAQ,UAAU,CAAC,CAiB/B;IAED;;;;;;;;;OASG;IACH,0BAmCC;IAED;;;;;;;;OAQG;I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ACH,2BAiCC;IAED;;OAEG;IACH,eAFW,MAAM,YAOhB;IAED;;OAEG;IACH,oBAFW,MAAM,QAOhB;IAED;;;;;OAKG;IACH,aAHW,SAAS,GACP,QAAQ,SAAS,EAAE,CAAC,CAwBhC;IAED;;;;;OAKG;IACH,mBAHW,SAAS,GACP,QAAQ,SAAS,EAAE,CAAC,CAWhC;CACF;;;;cA1SY,OAAO,SAAS,CAAC;;;;QAsBhB,MAAM;WACN,SAAS,EAAE;;;eAfX,SAAS;sBACT,gBAAgB;;;;;;iCAKJ,OAAO,EAAE,KAAK,OAAO,EAAE;;;;;;;;;;;;;;;;;;;;;;iBAbpC,OAAO,eAAe,CAAC;eACvB,OAAO,4BAA4B,EAAE,OAAO;wBAC5C,OAAO,sBAAsB,CAAC;uBAQxB,SAAS,KAAK,QAAQ,MAAM,EAAE,CAAC;;iBAepC,WAAW;gBACX,iBAAiB;aACjB,QAAQ,UAAU,CAAC;mBACR,IAAI"}
@@ -257,6 +257,7 @@ declare class Libp2p extends EventEmitter {
257
257
  _transport: any[];
258
258
  _discovery: Map<any, any>;
259
259
  connectionManager: ConnectionManager;
260
+ _autodialler: AutoDialler;
260
261
  metrics: Metrics | undefined;
261
262
  keychain: Keychain | undefined;
262
263
  upgrader: Upgrader;
@@ -467,6 +468,7 @@ type Libp2pConfig = {
467
468
  transport?: Record<string, Object> | undefined;
468
469
  };
469
470
  import ConnectionManager = require("./connection-manager");
471
+ import AutoDialler = require("./connection-manager/auto-dialler");
470
472
  import Metrics = require("./metrics");
471
473
  import Keychain = require("./keychain");
472
474
  import Upgrader = require("./upgrader");
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.js"],"names":[],"mappings":";AAoCA;;;;;;;;;;;;;GAaG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgFG;AACH;IACE;;;;;;OAMG;IACH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AO;;;aAGP,OAAO;;;aAGP,OAAO"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libp2p",
3
- "version": "0.34.0",
3
+ "version": "0.35.0",
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",
@@ -66,7 +66,7 @@
66
66
  "homepage": "https://libp2p.io",
67
67
  "license": "MIT",
68
68
  "engines": {
69
- "node": ">=14.0.0"
69
+ "node": ">=15.0.0"
70
70
  },
71
71
  "browser": {
72
72
  "@motrix/nat-api": false
@@ -80,10 +80,10 @@
80
80
  ]
81
81
  },
82
82
  "dependencies": {
83
- "abortable-iterator": "^3.0.0",
84
83
  "@motrix/nat-api": "^0.3.1",
85
84
  "@vascosantos/moving-average": "^1.1.0",
86
85
  "abort-controller": "^3.0.0",
86
+ "abortable-iterator": "^3.0.0",
87
87
  "aggregate-error": "^3.1.0",
88
88
  "any-signal": "^2.1.1",
89
89
  "bignumber.js": "^9.0.1",
@@ -105,8 +105,8 @@
105
105
  "it-merge": "^1.0.0",
106
106
  "it-pipe": "^1.1.0",
107
107
  "it-take": "^1.0.0",
108
- "libp2p-crypto": "^0.19.4",
109
- "libp2p-interfaces": "^1.0.0",
108
+ "libp2p-crypto": "^0.21.0",
109
+ "libp2p-interfaces": "^2.0.1",
110
110
  "libp2p-utils": "^0.4.0",
111
111
  "mafmt": "^10.0.0",
112
112
  "merge-options": "^3.0.4",
@@ -119,14 +119,14 @@
119
119
  "p-fifo": "^1.0.0",
120
120
  "p-retry": "^4.4.0",
121
121
  "p-settle": "^4.1.1",
122
- "peer-id": "^0.15.0",
122
+ "peer-id": "^0.16.0",
123
123
  "private-ip": "^2.1.0",
124
124
  "protobufjs": "^6.10.2",
125
125
  "retimer": "^3.0.0",
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": "^1.1.1",
129
+ "timeout-abort-controller": "^2.0.0",
130
130
  "uint8arrays": "^3.0.0",
131
131
  "varint": "^6.0.0",
132
132
  "wherearewe": "^1.0.0",
@@ -143,31 +143,31 @@
143
143
  "buffer": "^6.0.3",
144
144
  "datastore-core": "^6.0.7",
145
145
  "delay": "^5.0.0",
146
- "into-stream": "^7.0.0",
147
- "ipfs-http-client": "^52.0.2",
146
+ "into-stream": "^6.0.0",
147
+ "ipfs-http-client": "^54.0.2",
148
148
  "it-concat": "^2.0.0",
149
149
  "it-pair": "^1.0.0",
150
150
  "it-pushable": "^1.4.0",
151
151
  "libp2p": ".",
152
- "libp2p-bootstrap": "^0.13.0",
152
+ "libp2p-bootstrap": "^0.14.0",
153
153
  "libp2p-delegated-content-routing": "^0.11.0",
154
- "libp2p-delegated-peer-routing": "^0.10.0",
154
+ "libp2p-delegated-peer-routing": "^0.11.0",
155
155
  "libp2p-floodsub": "^0.27.0",
156
156
  "libp2p-gossipsub": "^0.11.0",
157
- "libp2p-interfaces-compliance-tests": "^1.0.0",
157
+ "libp2p-interfaces-compliance-tests": "^2.0.1",
158
158
  "libp2p-interop": "^0.5.0",
159
- "libp2p-kad-dht": "^0.26.5",
160
- "libp2p-mdns": "^0.17.0",
159
+ "libp2p-kad-dht": "^0.27.1",
160
+ "libp2p-mdns": "^0.18.0",
161
161
  "libp2p-mplex": "^0.10.1",
162
162
  "libp2p-tcp": "^0.17.0",
163
- "libp2p-webrtc-star": "^0.23.0",
163
+ "libp2p-webrtc-star": "^0.25.0",
164
164
  "libp2p-websockets": "^0.16.0",
165
165
  "nock": "^13.0.3",
166
166
  "p-defer": "^3.0.0",
167
167
  "p-times": "^3.0.0",
168
168
  "p-wait-for": "^3.2.0",
169
169
  "rimraf": "^3.0.2",
170
- "sinon": "^11.1.1",
170
+ "sinon": "^12.0.1",
171
171
  "util": "^0.12.3"
172
172
  },
173
173
  "contributors": [
@@ -181,24 +181,23 @@
181
181
  "Friedel Ziegelmayer <dignifiedquire@gmail.com>",
182
182
  "Maciej Krüger <mkg20001@gmail.com>",
183
183
  "Hugo Dias <mail@hugodias.me>",
184
- "Chris Dostert <chrisdostert@users.noreply.github.com>",
185
184
  "dirkmc <dirkmdev@gmail.com>",
185
+ "Chris Dostert <chrisdostert@users.noreply.github.com>",
186
186
  "Volker Mische <volker.mische@gmail.com>",
187
187
  "zeim839 <50573884+zeim839@users.noreply.github.com>",
188
188
  "Richard Littauer <richard.littauer@gmail.com>",
189
189
  "a1300 <matthias-knopp@gmx.net>",
190
190
  "Ryan Bell <ryan@piing.net>",
191
- "Elven <mon.samuel@qq.com>",
192
191
  "ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ <victorbjelkholm@gmail.com>",
193
- "Thomas Eizinger <thomas@eizinger.io>",
192
+ "Giovanni T. Parra <fiatjaf@gmail.com>",
193
+ "acolytec3 <17355484+acolytec3@users.noreply.github.com>",
194
+ "Franck Royer <franck@royer.one>",
195
+ "Elven <mon.samuel@qq.com>",
194
196
  "Robert Kiel <robert.kiel@hoprnet.org>",
195
197
  "Andrew Nesbitt <andrewnez@gmail.com>",
196
198
  "Samlior <samlior@foxmail.com>",
197
- "acolytec3 <17355484+acolytec3@users.noreply.github.com>",
198
- "Franck Royer <franck@royer.one>",
199
- "Giovanni T. Parra <fiatjaf@gmail.com>",
199
+ "Thomas Eizinger <thomas@eizinger.io>",
200
200
  "Didrik Nordström <didrik.nordstrom@gmail.com>",
201
- "RasmusErik Voel Jensen <github@solsort.com>",
202
201
  "Smite Chow <xiaopengyou@live.com>",
203
202
  "Soeren <nikorpoulsen@gmail.com>",
204
203
  "Sönke Hahn <soenkehahn@gmail.com>",
@@ -247,6 +246,7 @@
247
246
  "Michael Burns <5170+mburns@users.noreply.github.com>",
248
247
  "Miguel Mota <miguelmota2@gmail.com>",
249
248
  "Nuno Nogueira <nunofmn@gmail.com>",
250
- "Philipp Muens <raute1337@gmx.de>"
249
+ "Philipp Muens <raute1337@gmx.de>",
250
+ "RasmusErik Voel Jensen <github@solsort.com>"
251
251
  ]
252
252
  }
@@ -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 (/** @type {any} */ 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.
@@ -6,8 +6,7 @@ const log = Object.assign(debug('libp2p:dialer'), {
6
6
  })
7
7
  const errCode = require('err-code')
8
8
  const { Multiaddr } = require('multiaddr')
9
- // @ts-ignore timeout-abourt-controles does not export types
10
- const TimeoutController = require('timeout-abort-controller')
9
+ const { TimeoutController } = require('timeout-abort-controller')
11
10
  const { AbortError } = require('abortable-iterator')
12
11
  const { anySignal } = require('any-signal')
13
12
 
package/src/index.js CHANGED
@@ -18,6 +18,7 @@ const { codes, messages } = require('./errors')
18
18
 
19
19
  const AddressManager = require('./address-manager')
20
20
  const ConnectionManager = require('./connection-manager')
21
+ const AutoDialler = require('./connection-manager/auto-dialler')
21
22
  const Circuit = require('./circuit/transport')
22
23
  const Relay = require('./circuit')
23
24
  const Dialer = require('./dialer')
@@ -193,9 +194,13 @@ class Libp2p extends EventEmitter {
193
194
 
194
195
  // Create the Connection Manager
195
196
  this.connectionManager = new ConnectionManager(this, {
196
- autoDial: this._config.peerDiscovery.autoDial,
197
197
  ...this._options.connectionManager
198
198
  })
199
+ this._autodialler = new AutoDialler(this, {
200
+ enabled: this._config.peerDiscovery.autoDial,
201
+ minConnections: this._options.connectionManager.minConnections,
202
+ autoDialInterval: this._options.connectionManager.autoDialInterval
203
+ })
199
204
 
200
205
  // Create Metrics
201
206
  if (this._options.metrics.enabled) {
@@ -380,6 +385,8 @@ class Libp2p extends EventEmitter {
380
385
 
381
386
  this.relay && this.relay.stop()
382
387
  this.peerRouting.stop()
388
+ this._autodialler.stop()
389
+ await (this._dht && this._dht.stop())
383
390
 
384
391
  for (const service of this._discovery.values()) {
385
392
  service.removeListener('peer', this._onDiscoveryPeer)
@@ -394,7 +401,6 @@ class Libp2p extends EventEmitter {
394
401
 
395
402
  await Promise.all([
396
403
  this.pubsub && this.pubsub.stop(),
397
- this._dht && this._dht.stop(),
398
404
  this.metrics && this.metrics.stop()
399
405
  ])
400
406
 
@@ -650,6 +656,7 @@ class Libp2p extends EventEmitter {
650
656
  }
651
657
 
652
658
  this.connectionManager.start()
659
+ this._autodialler.start()
653
660
 
654
661
  // Peer discovery
655
662
  await this._setupPeerDiscovery()