libp2p 0.46.19 → 0.46.20
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 +22 -22
- package/dist/src/components.d.ts +3 -1
- package/dist/src/components.d.ts.map +1 -1
- package/dist/src/components.js +4 -0
- package/dist/src/components.js.map +1 -1
- package/dist/src/connection/index.d.ts +3 -1
- package/dist/src/connection/index.d.ts.map +1 -1
- package/dist/src/connection/index.js +17 -11
- package/dist/src/connection/index.js.map +1 -1
- package/dist/src/connection-manager/auto-dial.d.ts +3 -1
- package/dist/src/connection-manager/auto-dial.d.ts.map +1 -1
- package/dist/src/connection-manager/auto-dial.js +20 -20
- package/dist/src/connection-manager/auto-dial.js.map +1 -1
- package/dist/src/connection-manager/connection-pruner.d.ts +3 -1
- package/dist/src/connection-manager/connection-pruner.d.ts.map +1 -1
- package/dist/src/connection-manager/connection-pruner.js +8 -8
- package/dist/src/connection-manager/connection-pruner.js.map +1 -1
- package/dist/src/connection-manager/dial-queue.d.ts +3 -1
- package/dist/src/connection-manager/dial-queue.d.ts.map +1 -1
- package/dist/src/connection-manager/dial-queue.js +26 -23
- package/dist/src/connection-manager/dial-queue.js.map +1 -1
- package/dist/src/connection-manager/index.d.ts +3 -1
- package/dist/src/connection-manager/index.d.ts.map +1 -1
- package/dist/src/connection-manager/index.js +21 -18
- package/dist/src/connection-manager/index.js.map +1 -1
- package/dist/src/connection-manager/utils.d.ts +2 -1
- package/dist/src/connection-manager/utils.d.ts.map +1 -1
- package/dist/src/connection-manager/utils.js +2 -4
- package/dist/src/connection-manager/utils.js.map +1 -1
- package/dist/src/identify/consts.d.ts +1 -1
- package/dist/src/identify/identify.d.ts.map +1 -1
- package/dist/src/identify/identify.js +28 -21
- package/dist/src/identify/identify.js.map +1 -1
- package/dist/src/identify/index.d.ts +2 -1
- package/dist/src/identify/index.d.ts.map +1 -1
- package/dist/src/identify/index.js.map +1 -1
- package/dist/src/index.d.ts +21 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/libp2p.d.ts +2 -1
- package/dist/src/libp2p.d.ts.map +1 -1
- package/dist/src/libp2p.js +20 -16
- package/dist/src/libp2p.js.map +1 -1
- package/dist/src/ping/index.d.ts.map +1 -1
- package/dist/src/ping/index.js +9 -3
- package/dist/src/ping/index.js.map +1 -1
- package/dist/src/upgrader.d.ts +3 -1
- package/dist/src/upgrader.d.ts.map +1 -1
- package/dist/src/upgrader.js +37 -31
- package/dist/src/upgrader.js.map +1 -1
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/package.json +21 -21
- package/src/components.ts +8 -1
- package/src/connection/index.ts +20 -13
- package/src/connection-manager/auto-dial.ts +22 -22
- package/src/connection-manager/connection-pruner.ts +10 -10
- package/src/connection-manager/dial-queue.ts +28 -25
- package/src/connection-manager/index.ts +23 -20
- package/src/connection-manager/utils.ts +5 -7
- package/src/identify/identify.ts +30 -23
- package/src/identify/index.ts +2 -1
- package/src/index.ts +22 -1
- package/src/libp2p.ts +21 -18
- package/src/ping/index.ts +10 -3
- package/src/upgrader.ts +39 -32
- package/src/version.ts +1 -1
package/dist/src/components.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Startable } from '@libp2p/interface/startable';
|
|
2
|
-
import type { Libp2pEvents } from '@libp2p/interface';
|
|
2
|
+
import type { Libp2pEvents, ComponentLogger } from '@libp2p/interface';
|
|
3
3
|
import type { ConnectionProtector } from '@libp2p/interface/connection';
|
|
4
4
|
import type { ConnectionGater } from '@libp2p/interface/connection-gater';
|
|
5
5
|
import type { ContentRouting } from '@libp2p/interface/content-routing';
|
|
@@ -16,6 +16,7 @@ import type { TransportManager } from '@libp2p/interface-internal/transport-mana
|
|
|
16
16
|
import type { Datastore } from 'interface-datastore';
|
|
17
17
|
export interface Components extends Record<string, any>, Startable {
|
|
18
18
|
peerId: PeerId;
|
|
19
|
+
logger: ComponentLogger;
|
|
19
20
|
events: TypedEventTarget<Libp2pEvents>;
|
|
20
21
|
addressManager: AddressManager;
|
|
21
22
|
peerStore: PeerStore;
|
|
@@ -32,6 +33,7 @@ export interface Components extends Record<string, any>, Startable {
|
|
|
32
33
|
}
|
|
33
34
|
export interface ComponentsInit {
|
|
34
35
|
peerId?: PeerId;
|
|
36
|
+
logger?: ComponentLogger;
|
|
35
37
|
events?: TypedEventTarget<Libp2pEvents>;
|
|
36
38
|
addressManager?: AddressManager;
|
|
37
39
|
peerStore?: PeerStore;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"components.d.ts","sourceRoot":"","sources":["../../src/components.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,KAAK,SAAS,EAAE,MAAM,6BAA6B,CAAA;
|
|
1
|
+
{"version":3,"file":"components.d.ts","sourceRoot":"","sources":["../../src/components.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,KAAK,SAAS,EAAE,MAAM,6BAA6B,CAAA;AAEzE,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACtE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAA;AACvE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAA;AACzE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAA;AACvE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AAChE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAA;AACxD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAA;AACjE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;AAC7D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAA;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,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AAC,EAAE,gBAAgB,CAAA;IACnC,eAAe,CAAC,EAAE,eAAe,CAAA;IACjC,cAAc,CAAC,EAAE,cAAc,CAAA;IAC/B,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB,mBAAmB,CAAC,EAAE,mBAAmB,CAAA;CAC1C;AA6ED,wBAAgB,iBAAiB,CAAE,IAAI,GAAE,cAAmB,GAAG,UAAU,CA+BxE"}
|
package/dist/src/components.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CodeError } from '@libp2p/interface/errors';
|
|
2
2
|
import { isStartable } from '@libp2p/interface/startable';
|
|
3
|
+
import { defaultLogger } from '@libp2p/logger';
|
|
3
4
|
class DefaultComponents {
|
|
4
5
|
components = {};
|
|
5
6
|
_started = false;
|
|
@@ -8,6 +9,9 @@ class DefaultComponents {
|
|
|
8
9
|
for (const [key, value] of Object.entries(init)) {
|
|
9
10
|
this.components[key] = value;
|
|
10
11
|
}
|
|
12
|
+
if (this.components.logger == null) {
|
|
13
|
+
this.components.logger = defaultLogger();
|
|
14
|
+
}
|
|
11
15
|
}
|
|
12
16
|
isStarted() {
|
|
13
17
|
return this._started;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"components.js","sourceRoot":"","sources":["../../src/components.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,EAAE,WAAW,EAAkB,MAAM,6BAA6B,CAAA;
|
|
1
|
+
{"version":3,"file":"components.js","sourceRoot":"","sources":["../../src/components.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,EAAE,WAAW,EAAkB,MAAM,6BAA6B,CAAA;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAqD9C,MAAM,iBAAiB;IACd,UAAU,GAAwB,EAAE,CAAA;IACnC,QA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A;aACpC;iBAAM;gBACL,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,CAAA;aACjC;YAED,OAAO,IAAI,CAAA;QACb,CAAC;KACF,CAAC,CAAA;IAEF,8CAA8C;IAC9C,OAAO,KAAK,CAAA;AACd,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { symbol } from '@libp2p/interface/connection';
|
|
2
|
-
import type { AbortOptions } from '@libp2p/interface';
|
|
2
|
+
import type { AbortOptions, ComponentLogger } from '@libp2p/interface';
|
|
3
3
|
import type { Direction, Connection, Stream, ConnectionTimeline, ConnectionStatus, NewStreamOptions } from '@libp2p/interface/connection';
|
|
4
4
|
import type { PeerId } from '@libp2p/interface/peer-id';
|
|
5
5
|
import type { Multiaddr } from '@multiformats/multiaddr';
|
|
@@ -16,12 +16,14 @@ interface ConnectionInit {
|
|
|
16
16
|
multiplexer?: string;
|
|
17
17
|
encryption?: string;
|
|
18
18
|
transient?: boolean;
|
|
19
|
+
logger: ComponentLogger;
|
|
19
20
|
}
|
|
20
21
|
/**
|
|
21
22
|
* An implementation of the js-libp2p connection.
|
|
22
23
|
* Any libp2p transport should use an upgrader to return this connection.
|
|
23
24
|
*/
|
|
24
25
|
export declare class ConnectionImpl implements Connection {
|
|
26
|
+
#private;
|
|
25
27
|
/**
|
|
26
28
|
* Connection identifier.
|
|
27
29
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/connection/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/connection/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAA;AAGrD,OAAO,KAAK,EAAE,YAAY,EAAU,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAC9E,OA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;OAGG;IACI,IAAI,EAAE,MAAM,EAAE,CAAA;IAErB;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAsE;IAEjG;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA2C;IAElE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAsB;IAE7C;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAgB;IAI5C;;;OAGG;gBACU,IAAI,EAAE,cAAc;IAyBjC,QAAQ,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,gBAAe;IAE5C,QAAQ,CAAC,CAAC,MAAM,CAAC,QAAO;IAExB;;OAEG;IACH,IAAI,OAAO,IAAK,MAAM,EAAE,CAEvB;IAED;;OAEG;IACG,SAAS,CAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC;IAwB3F;;OAEG;IACG,KAAK,CAAE,OAAO,GAAE,YAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IA0CvD,KAAK,CAAE,GAAG,EAAE,KAAK,GAAG,IAAI;CAczB;AAED,wBAAgB,gBAAgB,CAAE,IAAI,EAAE,cAAc,GAAG,UAAU,CAElE"}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { symbol } from '@libp2p/interface/connection';
|
|
2
2
|
import { CodeError } from '@libp2p/interface/errors';
|
|
3
3
|
import { setMaxListeners } from '@libp2p/interface/events';
|
|
4
|
-
import { logger } from '@libp2p/logger';
|
|
5
|
-
const log = logger('libp2p:connection');
|
|
6
4
|
const CLOSE_TIMEOUT = 500;
|
|
7
5
|
/**
|
|
8
6
|
* An implementation of the js-libp2p connection.
|
|
@@ -45,6 +43,7 @@ export class ConnectionImpl {
|
|
|
45
43
|
* Reference to the getStreams function of the muxer
|
|
46
44
|
*/
|
|
47
45
|
_getStreams;
|
|
46
|
+
#log;
|
|
48
47
|
/**
|
|
49
48
|
* An implementation of the js-libp2p connection.
|
|
50
49
|
* Any libp2p transport should use an upgrader to return this connection.
|
|
@@ -60,6 +59,7 @@ export class ConnectionImpl {
|
|
|
60
59
|
this.multiplexer = init.multiplexer;
|
|
61
60
|
this.encryption = init.encryption;
|
|
62
61
|
this.transient = init.transient ?? false;
|
|
62
|
+
this.#log = init.logger.forComponent('libp2p:connection');
|
|
63
63
|
if (this.remoteAddr.getPeerId() == null) {
|
|
64
64
|
this.remoteAddr = this.remoteAddr.encapsulate(`/p2p/${this.remotePeer}`);
|
|
65
65
|
}
|
|
@@ -104,31 +104,37 @@ export class ConnectionImpl {
|
|
|
104
104
|
if (this.status === 'closed' || this.status === 'closing') {
|
|
105
105
|
return;
|
|
106
106
|
}
|
|
107
|
-
log('closing connection to %a', this.remoteAddr);
|
|
107
|
+
this.#log('closing connection to %a', this.remoteAddr);
|
|
108
108
|
this.status = 'closing';
|
|
109
|
-
options.signal
|
|
110
|
-
|
|
109
|
+
if (options.signal == null) {
|
|
110
|
+
const signal = AbortSignal.timeout(CLOSE_TIMEOUT);
|
|
111
|
+
setMaxListeners(Infinity, signal);
|
|
112
|
+
options = {
|
|
113
|
+
...options,
|
|
114
|
+
signal
|
|
115
|
+
};
|
|
116
|
+
}
|
|
111
117
|
try {
|
|
112
|
-
log.trace('closing all streams');
|
|
118
|
+
this.#log.trace('closing all streams');
|
|
113
119
|
// close all streams gracefully - this can throw if we're not multiplexed
|
|
114
120
|
await Promise.all(this.streams.map(async (s) => s.close(options)));
|
|
115
|
-
log.trace('closing underlying transport');
|
|
121
|
+
this.#log.trace('closing underlying transport');
|
|
116
122
|
// close raw connection
|
|
117
123
|
await this._close(options);
|
|
118
|
-
log.trace('updating timeline with close time');
|
|
124
|
+
this.#log.trace('updating timeline with close time');
|
|
119
125
|
this.status = 'closed';
|
|
120
126
|
this.timeline.close = Date.now();
|
|
121
127
|
}
|
|
122
128
|
catch (err) {
|
|
123
|
-
log.error('error encountered during graceful close of connection to %a', this.remoteAddr, err);
|
|
129
|
+
this.#log.error('error encountered during graceful close of connection to %a', this.remoteAddr, err);
|
|
124
130
|
this.abort(err);
|
|
125
131
|
}
|
|
126
132
|
}
|
|
127
133
|
abort(err) {
|
|
128
|
-
log.error('aborting connection to %a due to error', this.remoteAddr, err);
|
|
134
|
+
this.#log.error('aborting connection to %a due to error', this.remoteAddr, err);
|
|
129
135
|
this.status = 'closing';
|
|
130
136
|
this.streams.forEach(s => { s.abort(err); });
|
|
131
|
-
log.error('all streams aborted', this.streams.length);
|
|
137
|
+
this.#log.error('all streams aborted', this.streams.length);
|
|
132
138
|
// Abort raw connection
|
|
133
139
|
this._abort(err);
|
|
134
140
|
this.timeline.close = Date.now();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/connection/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAA;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/connection/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAA;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAM1D,MAAM,aAAa,GAAG,GAAG,CAAA;AAkBzB;;;GAGG;AACH,MAAM,OAAO,cAAc;IACzB;;OAEG;IACa,EAAE,CAAQ;IAE1B;;OAEG;IACa,UAAU,CAAW;IAErC;;OAEG;IACa,UAAU,CAAQ;IAE3B,SAAS,CAAW;IACpB,QAAQ,CAAoB;IAC5B,WAAW,CAAS;IACpB,UAAU,CAAS;IACnB,MAAM,CAAkB;IACxB,SAAS,CAAS;IAEzB;;;OAGG;IACI,IAAI,CAAU;IAErB;;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CAAA;QACvB,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA,CAAC,CAAC,CAAC,CAAA;QAE3C,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,qBAAqB,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QAE3D,uBAAuB;QACvB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QAEhB,IAAI,CAAC,QAAQ,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QAChC,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAA;IACxB,CAAC;CACF;AAED,MAAM,UAAU,gBAAgB,CAAE,IAAoB;IACpD,OAAO,IAAI,cAAc,CAAC,IAAI,CAAC,CAAA;AACjC,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Libp2pEvents } from '@libp2p/interface';
|
|
1
|
+
import type { Libp2pEvents, ComponentLogger } from '@libp2p/interface';
|
|
2
2
|
import type { TypedEventTarget } from '@libp2p/interface/events';
|
|
3
3
|
import type { PeerStore } from '@libp2p/interface/peer-store';
|
|
4
4
|
import type { Startable } from '@libp2p/interface/startable';
|
|
@@ -16,8 +16,10 @@ interface AutoDialComponents {
|
|
|
16
16
|
connectionManager: ConnectionManager;
|
|
17
17
|
peerStore: PeerStore;
|
|
18
18
|
events: TypedEventTarget<Libp2pEvents>;
|
|
19
|
+
logger: ComponentLogger;
|
|
19
20
|
}
|
|
20
21
|
export declare class AutoDial implements Startable {
|
|
22
|
+
#private;
|
|
21
23
|
private readonly connectionManager;
|
|
22
24
|
private readonly peerStore;
|
|
23
25
|
private readonly queue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auto-dial.d.ts","sourceRoot":"","sources":["../../../src/connection-manager/auto-dial.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"auto-dial.d.ts","source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AC,QAAQ,CAAC,+BAA+B,CAAQ;IACxD,OAAO,CAAC,gBAAgB,CAAC,CAAgC;IACzD,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,OAAO,CAAS;IAGxB;;;;OAIG;gBACU,UAAU,EAAE,kBAAkB,EAAE,IAAI,EAAE,YAAY;IA4C/D,SAAS,IAAK,OAAO;IAIrB,KAAK,IAAK,IAAI;IAUd,UAAU,IAAK,IAAI;IAOnB,IAAI,IAAK,IAAI;IAQP,QAAQ,IAAK,OAAO,CAAC,IAAI,CAAC;CA4JjC"}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { logger } from '@libp2p/logger';
|
|
2
1
|
import { PeerMap, PeerSet } from '@libp2p/peer-collections';
|
|
3
2
|
import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
|
|
4
3
|
import { PeerJobQueue } from '../utils/peer-job-queue.js';
|
|
5
4
|
import { AUTO_DIAL_CONCURRENCY, AUTO_DIAL_DISCOVERED_PEERS_DEBOUNCE, AUTO_DIAL_INTERVAL, AUTO_DIAL_MAX_QUEUE_LENGTH, AUTO_DIAL_PEER_RETRY_THRESHOLD, AUTO_DIAL_PRIORITY, LAST_DIAL_FAILURE_KEY, MIN_CONNECTIONS } from './constants.js';
|
|
6
|
-
const log = logger('libp2p:connection-manager:auto-dial');
|
|
7
5
|
const defaultOptions = {
|
|
8
6
|
minConnections: MIN_CONNECTIONS,
|
|
9
7
|
maxQueueLength: AUTO_DIAL_MAX_QUEUE_LENGTH,
|
|
@@ -26,6 +24,7 @@ export class AutoDial {
|
|
|
26
24
|
autoDialInterval;
|
|
27
25
|
started;
|
|
28
26
|
running;
|
|
27
|
+
#log;
|
|
29
28
|
/**
|
|
30
29
|
* Proactively tries to connect to known peers stored in the PeerStore.
|
|
31
30
|
* It will keep the number of connections below the upper limit and sort
|
|
@@ -40,19 +39,20 @@ export class AutoDial {
|
|
|
40
39
|
this.autoDialMaxQueueLength = init.maxQueueLength ?? defaultOptions.maxQueueLength;
|
|
41
40
|
this.autoDialPeerRetryThresholdMs = init.autoDialPeerRetryThreshold ?? defaultOptions.autoDialPeerRetryThreshold;
|
|
42
41
|
this.autoDialDiscoveredPeersDebounce = init.autoDialDiscoveredPeersDebounce ?? defaultOptions.autoDialDiscoveredPeersDebounce;
|
|
42
|
+
this.#log = components.logger.forComponent('libp2p:connection-manager:auto-dial');
|
|
43
43
|
this.started = false;
|
|
44
44
|
this.running = false;
|
|
45
45
|
this.queue = new PeerJobQueue({
|
|
46
46
|
concurrency: init.autoDialConcurrency ?? defaultOptions.autoDialConcurrency
|
|
47
47
|
});
|
|
48
48
|
this.queue.addListener('error', (err) => {
|
|
49
|
-
log.error('error during auto-dial', err);
|
|
49
|
+
this.#log.error('error during auto-dial', err);
|
|
50
50
|
});
|
|
51
51
|
// check the min connection limit whenever a peer disconnects
|
|
52
52
|
components.events.addEventListener('connection:close', () => {
|
|
53
53
|
this.autoDial()
|
|
54
54
|
.catch(err => {
|
|
55
|
-
log.error(err);
|
|
55
|
+
this.#log.error(err);
|
|
56
56
|
});
|
|
57
57
|
});
|
|
58
58
|
// sometimes peers are discovered in quick succession so add a small
|
|
@@ -65,7 +65,7 @@ export class AutoDial {
|
|
|
65
65
|
debounce = setTimeout(() => {
|
|
66
66
|
this.autoDial()
|
|
67
67
|
.catch(err => {
|
|
68
|
-
log.error(err);
|
|
68
|
+
this.#log.error(err);
|
|
69
69
|
});
|
|
70
70
|
}, this.autoDialDiscoveredPeersDebounce);
|
|
71
71
|
});
|
|
@@ -77,7 +77,7 @@ export class AutoDial {
|
|
|
77
77
|
this.autoDialInterval = setTimeout(() => {
|
|
78
78
|
this.autoDial()
|
|
79
79
|
.catch(err => {
|
|
80
|
-
log.error('error while autodialing', err);
|
|
80
|
+
this.#log.error('error while autodialing', err);
|
|
81
81
|
});
|
|
82
82
|
}, this.autoDialIntervalMs);
|
|
83
83
|
this.started = true;
|
|
@@ -85,7 +85,7 @@ export class AutoDial {
|
|
|
85
85
|
afterStart() {
|
|
86
86
|
this.autoDial()
|
|
87
87
|
.catch(err => {
|
|
88
|
-
log.error('error while autodialing', err);
|
|
88
|
+
this.#log.error('error while autodialing', err);
|
|
89
89
|
});
|
|
90
90
|
}
|
|
91
91
|
stop() {
|
|
@@ -104,20 +104,20 @@ export class AutoDial {
|
|
|
104
104
|
// Already has enough connections
|
|
105
105
|
if (numConnections >= this.minConnections) {
|
|
106
106
|
if (this.minConnections > 0) {
|
|
107
|
-
log.trace('have enough connections %d/%d', numConnections, this.minConnections);
|
|
107
|
+
this.#log.trace('have enough connections %d/%d', numConnections, this.minConnections);
|
|
108
108
|
}
|
|
109
109
|
return;
|
|
110
110
|
}
|
|
111
111
|
if (this.queue.size > this.autoDialMaxQueueLength) {
|
|
112
|
-
log('not enough connections %d/%d but auto dial queue is full', numConnections, this.minConnections);
|
|
112
|
+
this.#log('not enough connections %d/%d but auto dial queue is full', numConnections, this.minConnections);
|
|
113
113
|
return;
|
|
114
114
|
}
|
|
115
115
|
if (this.running) {
|
|
116
|
-
log('not enough connections %d/%d - but skipping autodial as it is already running', numConnections, this.minConnections);
|
|
116
|
+
this.#log('not enough connections %d/%d - but skipping autodial as it is already running', numConnections, this.minConnections);
|
|
117
117
|
return;
|
|
118
118
|
}
|
|
119
119
|
this.running = true;
|
|
120
|
-
log('not enough connections %d/%d - will dial peers to increase the number of connections', numConnections, this.minConnections);
|
|
120
|
+
this.#log('not enough connections %d/%d - will dial peers to increase the number of connections', numConnections, this.minConnections);
|
|
121
121
|
const dialQueue = new PeerSet(
|
|
122
122
|
// @ts-expect-error boolean filter removes falsy peer IDs
|
|
123
123
|
this.connectionManager.getDialQueue()
|
|
@@ -130,22 +130,22 @@ export class AutoDial {
|
|
|
130
130
|
(peer) => {
|
|
131
131
|
// Remove peers without addresses
|
|
132
132
|
if (peer.addresses.length === 0) {
|
|
133
|
-
log.trace('not autodialing %p because they have no addresses', peer.id);
|
|
133
|
+
this.#log.trace('not autodialing %p because they have no addresses', peer.id);
|
|
134
134
|
return false;
|
|
135
135
|
}
|
|
136
136
|
// remove peers we are already connected to
|
|
137
137
|
if (connections.has(peer.id)) {
|
|
138
|
-
log.trace('not autodialing %p because they are already connected', peer.id);
|
|
138
|
+
this.#log.trace('not autodialing %p because they are already connected', peer.id);
|
|
139
139
|
return false;
|
|
140
140
|
}
|
|
141
141
|
// remove peers we are already dialling
|
|
142
142
|
if (dialQueue.has(peer.id)) {
|
|
143
|
-
log.trace('not autodialing %p because they are already being dialed', peer.id);
|
|
143
|
+
this.#log.trace('not autodialing %p because they are already being dialed', peer.id);
|
|
144
144
|
return false;
|
|
145
145
|
}
|
|
146
146
|
// remove peers already in the autodial queue
|
|
147
147
|
if (this.queue.hasJob(peer.id)) {
|
|
148
|
-
log.trace('not autodialing %p because they are already being autodialed', peer.id);
|
|
148
|
+
this.#log.trace('not autodialing %p because they are already being autodialed', peer.id);
|
|
149
149
|
return false;
|
|
150
150
|
}
|
|
151
151
|
return true;
|
|
@@ -190,24 +190,24 @@ export class AutoDial {
|
|
|
190
190
|
// only dial if the time since the last failure is above the retry threshold
|
|
191
191
|
return Date.now() - lastDialFailureTimestamp > this.autoDialPeerRetryThresholdMs;
|
|
192
192
|
});
|
|
193
|
-
log('selected %d/%d peers to dial', peersThatHaveNotFailed.length, peers.length);
|
|
193
|
+
this.#log('selected %d/%d peers to dial', peersThatHaveNotFailed.length, peers.length);
|
|
194
194
|
for (const peer of peersThatHaveNotFailed) {
|
|
195
195
|
this.queue.add(async () => {
|
|
196
196
|
const numConnections = this.connectionManager.getConnectionsMap().size;
|
|
197
197
|
// Check to see if we still need to auto dial
|
|
198
198
|
if (numConnections >= this.minConnections) {
|
|
199
|
-
log('got enough connections now %d/%d', numConnections, this.minConnections);
|
|
199
|
+
this.#log('got enough connections now %d/%d', numConnections, this.minConnections);
|
|
200
200
|
this.queue.clear();
|
|
201
201
|
return;
|
|
202
202
|
}
|
|
203
|
-
log('connecting to a peerStore stored peer %p', peer.id);
|
|
203
|
+
this.#log('connecting to a peerStore stored peer %p', peer.id);
|
|
204
204
|
await this.connectionManager.openConnection(peer.id, {
|
|
205
205
|
priority: this.autoDialPriority
|
|
206
206
|
});
|
|
207
207
|
}, {
|
|
208
208
|
peerId: peer.id
|
|
209
209
|
}).catch(err => {
|
|
210
|
-
log.error('could not connect to peerStore stored peer', err);
|
|
210
|
+
this.#log.error('could not connect to peerStore stored peer', err);
|
|
211
211
|
});
|
|
212
212
|
}
|
|
213
213
|
this.running = false;
|
|
@@ -215,7 +215,7 @@ export class AutoDial {
|
|
|
215
215
|
this.autoDialInterval = setTimeout(() => {
|
|
216
216
|
this.autoDial()
|
|
217
217
|
.catch(err => {
|
|
218
|
-
log.error('error while autodialing', err);
|
|
218
|
+
this.#log.error('error while autodialing', err);
|
|
219
219
|
});
|
|
220
220
|
}, this.autoDialIntervalMs);
|
|
221
221
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auto-dial.js","sourceRoot":"","sources":["../../../src/connection-manager/auto-dial.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"auto-dial.js","sourceRoot":"","sources":["../../../src/connection-manager/auto-dial.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAA;AAC3D,OAAO,EAAE,QAAQ,IAAI,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AACzD,OAAO,EAAE,qBAAqB,EAAE,mCAAmC,EAAE,kBAAkB,EAAE,0BAA0B,EAAE,8BAA8B,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAwBvO,MAAM,cAAc,GAAG;IACrB,cAAc,EAAE,eAAe;IAC/B,cAAc,EAAE,0BAA0B;IAC1C,mBAAmB,EAAE,qBAAqB;IAC1C,gBAAgB,EAAE,kBAAkB;IACp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gBAC9D,MAAM,IAAI,CAAC,iBAAiB,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,EAAE;oBACnD,QAAQ,EAAE,IAAI,CAAC,gBAAgB;iBAChC,CAAC,CAAA;YACJ,CAAC,EAAE;gBACD,MAAM,EAAE,IAAI,CAAC,EAAE;aAChB,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;gBACb,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,4CAA4C,EAAE,GAAG,CAAC,CAAA;YACpE,CAAC,CAAC,CAAA;SACH;QAED,IAAI,CAAC,OAAO,GAAG,KAAK,CAAA;QAEpB,IAAI,IAAI,CAAC,OAAO,EAAE;YAChB,IAAI,CAAC,gBAAgB,GAAG,UAAU,CAAC,GAAG,EAAE;gBACtC,IAAI,CAAC,QAAQ,EAAE;qBACZ,KAAK,CAAC,GAAG,CAAC,EAAE;oBACX,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,yBAAyB,EAAE,GAAG,CAAC,CAAA;gBACjD,CAAC,CAAC,CAAA;YACN,CAAC,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAA;SAC5B;IACH,CAAC;CACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Libp2pEvents } from '@libp2p/interface';
|
|
1
|
+
import type { Libp2pEvents, ComponentLogger } from '@libp2p/interface';
|
|
2
2
|
import type { TypedEventTarget } from '@libp2p/interface/events';
|
|
3
3
|
import type { PeerStore } from '@libp2p/interface/peer-store';
|
|
4
4
|
import type { ConnectionManager } from '@libp2p/interface-internal/connection-manager';
|
|
@@ -11,11 +11,13 @@ interface ConnectionPrunerComponents {
|
|
|
11
11
|
connectionManager: ConnectionManager;
|
|
12
12
|
peerStore: PeerStore;
|
|
13
13
|
events: TypedEventTarget<Libp2pEvents>;
|
|
14
|
+
logger: ComponentLogger;
|
|
14
15
|
}
|
|
15
16
|
/**
|
|
16
17
|
* If we go over the max connections limit, choose some connections to close
|
|
17
18
|
*/
|
|
18
19
|
export declare class ConnectionPruner {
|
|
20
|
+
#private;
|
|
19
21
|
private readonly maxConnections;
|
|
20
22
|
private readonly connectionManager;
|
|
21
23
|
private readonly peerStore;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection-pruner.d.ts","sourceRoot":"","sources":["../../../src/connection-manager/connection-pruner.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"connection-pruner.d.ts","sourceRoot":"","sources":["../../../src/connection-manager/connection-pruner.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAU,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAC9E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AAChE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;AAC7D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+CAA+C,CAAA;AACtF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAExD,UAAU,oBAAoB;IAC5B,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,KAAK,CAAC,EAAE,SAAS,EAAE,CAAA;CACpB;AAED,UAAU,0BAA0B;IAClC,iBAAiB,EAAE,iBAAiB,CAAA;IACpC,SAAS,EAAE,SAAS,CAAA;IACpB,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAA;IACtC,MAAM,EAAE,eAAe,CAAA;CACxB;AAOD;;GAEG;AACH,qBAAa,gBAAgB;;IAC3B,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAQ;IACvC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAmB;IACrD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAW;IACrC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAa;IACnC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgC;gBAG1C,UAAU,EAAE,0BAA0B,EAAE,IAAI,GAAE,oBAAyB;IAiBpF;;;OAGG;IACG,qBAAqB,IAAK,OAAO,CAAC,IAAI,CAAC;CAmG9C"}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { logger } from '@libp2p/logger';
|
|
2
1
|
import { PeerMap } from '@libp2p/peer-collections';
|
|
3
2
|
import { MAX_CONNECTIONS } from './constants.js';
|
|
4
|
-
const log = logger('libp2p:connection-manager:connection-pruner');
|
|
5
3
|
const defaultOptions = {
|
|
6
4
|
maxConnections: MAX_CONNECTIONS,
|
|
7
5
|
allow: []
|
|
@@ -15,17 +13,19 @@ export class ConnectionPruner {
|
|
|
15
13
|
peerStore;
|
|
16
14
|
allow;
|
|
17
15
|
events;
|
|
16
|
+
#log;
|
|
18
17
|
constructor(components, init = {}) {
|
|
19
18
|
this.maxConnections = init.maxConnections ?? defaultOptions.maxConnections;
|
|
20
19
|
this.allow = init.allow ?? defaultOptions.allow;
|
|
21
20
|
this.connectionManager = components.connectionManager;
|
|
22
21
|
this.peerStore = components.peerStore;
|
|
23
22
|
this.events = components.events;
|
|
23
|
+
this.#log = components.logger.forComponent('libp2p:connection-manager:connection-pruner');
|
|
24
24
|
// check the max connection limit whenever a peer connects
|
|
25
25
|
components.events.addEventListener('connection:open', () => {
|
|
26
26
|
this.maybePruneConnections()
|
|
27
27
|
.catch(err => {
|
|
28
|
-
log.error(err);
|
|
28
|
+
this.#log.error(err);
|
|
29
29
|
});
|
|
30
30
|
});
|
|
31
31
|
}
|
|
@@ -37,11 +37,11 @@ export class ConnectionPruner {
|
|
|
37
37
|
const connections = this.connectionManager.getConnections();
|
|
38
38
|
const numConnections = connections.length;
|
|
39
39
|
const toPrune = Math.max(numConnections - this.maxConnections, 0);
|
|
40
|
-
log('checking max connections limit %d/%d', numConnections, this.maxConnections);
|
|
40
|
+
this.#log('checking max connections limit %d/%d', numConnections, this.maxConnections);
|
|
41
41
|
if (numConnections <= this.maxConnections) {
|
|
42
42
|
return;
|
|
43
43
|
}
|
|
44
|
-
log('max connections limit exceeded %d/%d, pruning %d connection(s)', numConnections, this.maxConnections, toPrune);
|
|
44
|
+
this.#log('max connections limit exceeded %d/%d, pruning %d connection(s)', numConnections, this.maxConnections, toPrune);
|
|
45
45
|
const peerValues = new PeerMap();
|
|
46
46
|
// work out peer values
|
|
47
47
|
for (const connection of connections) {
|
|
@@ -59,7 +59,7 @@ export class ConnectionPruner {
|
|
|
59
59
|
}
|
|
60
60
|
catch (err) {
|
|
61
61
|
if (err.code !== 'ERR_NOT_FOUND') {
|
|
62
|
-
log.error('error loading peer tags', err);
|
|
62
|
+
this.#log.error('error loading peer tags', err);
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
}
|
|
@@ -87,7 +87,7 @@ export class ConnectionPruner {
|
|
|
87
87
|
// close some connections
|
|
88
88
|
const toClose = [];
|
|
89
89
|
for (const connection of sortedConnections) {
|
|
90
|
-
log('too many connections open - closing a connection to %p', connection.remotePeer);
|
|
90
|
+
this.#log('too many connections open - closing a connection to %p', connection.remotePeer);
|
|
91
91
|
// check allow list
|
|
92
92
|
const connectionInAllowList = this.allow.some((ma) => {
|
|
93
93
|
return connection.remoteAddr.toString().startsWith(ma.toString());
|
|
@@ -106,7 +106,7 @@ export class ConnectionPruner {
|
|
|
106
106
|
await connection.close();
|
|
107
107
|
}
|
|
108
108
|
catch (err) {
|
|
109
|
-
log.error(err);
|
|
109
|
+
this.#log.error(err);
|
|
110
110
|
}
|
|
111
111
|
}));
|
|
112
112
|
// despatch prune event
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection-pruner.js","sourceRoot":"","sources":["../../../src/connection-manager/connection-pruner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"connection-pruner.js","sourceRoot":"","sources":["../../../src/connection-manager/connection-pruner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAA;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAmBhD,MA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AK,EAAC,UAAU,EAAC,EAAE;YAC7B,IAAI;gBACF,MAAM,UAAU,CAAC,KAAK,EAAE,CAAA;aACzB;YAAC,OAAO,GAAG,EAAE;gBACZ,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;aACrB;QACH,CAAC,CAAC,CACH,CAAA;QAED,uBAAuB;QACvB,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,kBAAkB,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAA;IACxE,CAAC;CACF"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PeerMap } from '@libp2p/peer-collections';
|
|
2
2
|
import { type Multiaddr, type Resolver } from '@multiformats/multiaddr';
|
|
3
3
|
import PQueue from 'p-queue';
|
|
4
|
-
import type { AddressSorter, AbortOptions, PendingDial } from '@libp2p/interface';
|
|
4
|
+
import type { AddressSorter, AbortOptions, PendingDial, ComponentLogger } from '@libp2p/interface';
|
|
5
5
|
import type { Connection } from '@libp2p/interface/connection';
|
|
6
6
|
import type { ConnectionGater } from '@libp2p/interface/connection-gater';
|
|
7
7
|
import type { Metrics } from '@libp2p/interface/metrics';
|
|
@@ -34,8 +34,10 @@ interface DialQueueComponents {
|
|
|
34
34
|
peerStore: PeerStore;
|
|
35
35
|
transportManager: TransportManager;
|
|
36
36
|
connectionGater: ConnectionGater;
|
|
37
|
+
logger: ComponentLogger;
|
|
37
38
|
}
|
|
38
39
|
export declare class DialQueue {
|
|
40
|
+
#private;
|
|
39
41
|
pendingDials: PendingDialInternal[];
|
|
40
42
|
queue: PQueue;
|
|
41
43
|
private readonly peerId;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dial-queue.d.ts","sourceRoot":"","sources":["../../../src/connection-manager/dial-queue.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dial-queue.d.ts","sourceRoot":"","sources":["../../../src/connection-manager/dial-queue.ts"],"names":[],"mappings":"AAEA,OAAO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