libp2p 1.9.4-81ebe4e47 → 1.9.4-a142bb642
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 +6 -6
- package/dist/src/connection-monitor.d.ts +1 -0
- package/dist/src/connection-monitor.d.ts.map +1 -1
- package/dist/src/connection-monitor.js +13 -3
- package/dist/src/connection-monitor.js.map +1 -1
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/package.json +17 -17
- package/src/connection-monitor.ts +13 -4
- package/src/version.ts +1 -1
|
@@ -49,6 +49,7 @@ export declare class ConnectionMonitor implements Startable {
|
|
|
49
49
|
private readonly pingIntervalMs;
|
|
50
50
|
private abortController?;
|
|
51
51
|
private readonly timeout;
|
|
52
|
+
private readonly abortConnectionOnPingFailure;
|
|
52
53
|
constructor(components: ConnectionMonitorComponents, init?: ConnectionMonitorInit);
|
|
53
54
|
readonly [Symbol.toStringTag] = "@libp2p/connection-monitor";
|
|
54
55
|
readonly [serviceCapabilities]: string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection-monitor.d.ts","sourceRoot":"","sources":["../../src/connection-monitor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,
|
|
1
|
+
{"version":3,"file":"connection-monitor.d.ts","sourceRoot":"","sources":["../../src/connection-monitor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAmB,MAAM,mBAAmB,CAAA;AAGxE,OAAO,KAAK,EAAE,eAAe,EAAU,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AACpF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAA;AACnE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAA;AASzE,MAAM,WAAW,qBAAqB;IACpC;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IAEjB;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IAErB;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,IAAI,CAAC,mBAAmB,EAAE,aAAa,GAAG,SAAS,CAAC,CAAA;IAElE;;;;OAIG;IACH,4BAA4B,CAAC,EAAE,OAAO,CAAA;IAEtC;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB;AAED,MAAM,WAAW,2BAA2B;IAC1C,MAAM,EAAE,eAAe,CAAA;IACvB,iBAAiB,EAAE,iBAAiB,CAAA;IACpC,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,qBAAa,iBAAkB,YAAW,SAAS;IACjD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAQ;IACjC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA6B;IACxD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAQ;IAC5B,OAAO,CAAC,iBAAiB,CAAC,CAAgC;IAC1D,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAQ;IACvC,OAAO,CAAC,eAAe,CAAC,CAAiB;IACzC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiB;IACzC,OAAO,CAAC,QAAQ,CAAC,4BAA4B,CAAS;gBAEzC,UAAU,EAAE,2BAA2B,EAAE,IAAI,GAAE,qBAA0B;IActF,QAAQ,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,gCAA+B;IAE5D,QAAQ,CAAC,CAAC,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAEvC;IAED,KAAK,IAAK,IAAI;IA2Dd,IAAI,IAAK,IAAI;CAOd"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { randomBytes } from '@libp2p/crypto';
|
|
2
|
-
import { serviceCapabilities } from '@libp2p/interface';
|
|
2
|
+
import { serviceCapabilities, setMaxListeners } from '@libp2p/interface';
|
|
3
3
|
import { AdaptiveTimeout } from '@libp2p/utils/adaptive-timeout';
|
|
4
4
|
import { byteStream } from 'it-byte-stream';
|
|
5
5
|
const DEFAULT_PING_INTERVAL_MS = 10000;
|
|
@@ -7,6 +7,7 @@ const PROTOCOL_VERSION = '1.0.0';
|
|
|
7
7
|
const PROTOCOL_NAME = 'ping';
|
|
8
8
|
const PROTOCOL_PREFIX = 'ipfs';
|
|
9
9
|
const PING_LENGTH = 32;
|
|
10
|
+
const DEFAULT_ABORT_CONNECTION_ON_PING_FAILURE = true;
|
|
10
11
|
export class ConnectionMonitor {
|
|
11
12
|
protocol;
|
|
12
13
|
components;
|
|
@@ -15,11 +16,13 @@ export class ConnectionMonitor {
|
|
|
15
16
|
pingIntervalMs;
|
|
16
17
|
abortController;
|
|
17
18
|
timeout;
|
|
19
|
+
abortConnectionOnPingFailure;
|
|
18
20
|
constructor(components, init = {}) {
|
|
19
21
|
this.components = components;
|
|
20
22
|
this.protocol = `/${init.protocolPrefix ?? PROTOCOL_PREFIX}/${PROTOCOL_NAME}/${PROTOCOL_VERSION}`;
|
|
21
23
|
this.log = components.logger.forComponent('libp2p:connection-monitor');
|
|
22
24
|
this.pingIntervalMs = init.pingInterval ?? DEFAULT_PING_INTERVAL_MS;
|
|
25
|
+
this.abortConnectionOnPingFailure = init.abortConnectionOnPingFailure ?? DEFAULT_ABORT_CONNECTION_ON_PING_FAILURE;
|
|
23
26
|
this.timeout = new AdaptiveTimeout({
|
|
24
27
|
...(init.pingTimeout ?? {}),
|
|
25
28
|
metrics: components.metrics,
|
|
@@ -32,6 +35,7 @@ export class ConnectionMonitor {
|
|
|
32
35
|
];
|
|
33
36
|
start() {
|
|
34
37
|
this.abortController = new AbortController();
|
|
38
|
+
setMaxListeners(Infinity, this.abortController.signal);
|
|
35
39
|
this.heartbeatInterval = setInterval(() => {
|
|
36
40
|
this.components.connectionManager.getConnections().forEach(conn => {
|
|
37
41
|
Promise.resolve().then(async () => {
|
|
@@ -71,8 +75,14 @@ export class ConnectionMonitor {
|
|
|
71
75
|
}
|
|
72
76
|
})
|
|
73
77
|
.catch(err => {
|
|
74
|
-
this.log.error('error during heartbeat
|
|
75
|
-
|
|
78
|
+
this.log.error('error during heartbeat', err);
|
|
79
|
+
if (this.abortConnectionOnPingFailure) {
|
|
80
|
+
this.log.error('aborting connection due to ping failure');
|
|
81
|
+
conn.abort(err);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
this.log('connection ping failed, but not aborting due to abortConnectionOnPingFailure flag');
|
|
85
|
+
}
|
|
76
86
|
});
|
|
77
87
|
});
|
|
78
88
|
}, this.pingIntervalMs);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection-monitor.js","sourceRoot":"","sources":["../../src/connection-monitor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"connection-monitor.js","sourceRoot":"","sources":["../../src/connection-monitor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACxE,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAK3C,MAAM,wBAAwB,GAAG,KAAK,CAAA;AACtC,MAAM,gBAAgB,GAAG,OAAO,CAAA;AAChC,MAAM,aAAa,GAAG,MAAM,CAAA;AAC5B,MAAM,eAAe,GAAG,MAAM,CAAA;AAC9B,MAAM,WAAW,GAAG,EAAE,CAAA;AACtB,MAAM,wCAAwC,GAAG,IAAI,CAAA;AA+CrD,MAAM,OAAO,iBAAiB;IACX,QAAQ,CAAQ;IAChB,UAAU,CAA6B;IACvC,GAAG,CAAQ;IACpB,iBAAiB,CAAiC;IACzC,cAAc,CAAQ;IAC/B,eAAe,CAAkB;IACxB,OAAO,CAAiB;IACxB,4BAA4B,CAAS;IAEtD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BACzD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;oBACjB,CAAC;yBAAM,CAAC;wBACN,IAAI,CAAC,GAAG,CAAC,mFAAmF,CAAC,CAAA;oBAC/F,CAAC;gBACH,CAAC,CAAC,CAAA;YACN,CAAC,CAAC,CAAA;QACJ,CAAC,EAAE,IAAI,CAAC,cAAc,CAAC,CAAA;IACzB,CAAC;IAED,IAAI;QACF,IAAI,CAAC,eAAe,EAAE,KAAK,EAAE,CAAA;QAE7B,IAAI,IAAI,CAAC,iBAAiB,IAAI,IAAI,EAAE,CAAC;YACnC,aAAa,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAA;QACvC,CAAC;IACH,CAAC;CACF"}
|
package/dist/src/version.d.ts
CHANGED
package/dist/src/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "libp2p",
|
|
3
|
-
"version": "1.9.4-
|
|
3
|
+
"version": "1.9.4-a142bb642",
|
|
4
4
|
"description": "JavaScript implementation of libp2p, a modular peer to peer network stack",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/libp2p#readme",
|
|
@@ -85,15 +85,15 @@
|
|
|
85
85
|
"test:webkit": "aegir test -t browser -f \"./dist/test/**/*.spec.js\" -- --browser webkit"
|
|
86
86
|
},
|
|
87
87
|
"dependencies": {
|
|
88
|
-
"@libp2p/crypto": "4.1.9-
|
|
89
|
-
"@libp2p/interface": "1.7.0-
|
|
90
|
-
"@libp2p/interface-internal": "1.3.4-
|
|
91
|
-
"@libp2p/logger": "4.0.20-
|
|
92
|
-
"@libp2p/multistream-select": "5.1.17-
|
|
93
|
-
"@libp2p/peer-collections": "5.2.9-
|
|
94
|
-
"@libp2p/peer-id": "4.2.4-
|
|
95
|
-
"@libp2p/peer-store": "10.1.5-
|
|
96
|
-
"@libp2p/utils": "5.4.9-
|
|
88
|
+
"@libp2p/crypto": "4.1.9-a142bb642",
|
|
89
|
+
"@libp2p/interface": "1.7.0-a142bb642",
|
|
90
|
+
"@libp2p/interface-internal": "1.3.4-a142bb642",
|
|
91
|
+
"@libp2p/logger": "4.0.20-a142bb642",
|
|
92
|
+
"@libp2p/multistream-select": "5.1.17-a142bb642",
|
|
93
|
+
"@libp2p/peer-collections": "5.2.9-a142bb642",
|
|
94
|
+
"@libp2p/peer-id": "4.2.4-a142bb642",
|
|
95
|
+
"@libp2p/peer-store": "10.1.5-a142bb642",
|
|
96
|
+
"@libp2p/utils": "5.4.9-a142bb642",
|
|
97
97
|
"@multiformats/dns": "^1.0.6",
|
|
98
98
|
"@multiformats/multiaddr": "^12.2.3",
|
|
99
99
|
"@multiformats/multiaddr-matcher": "^1.2.1",
|
|
@@ -114,13 +114,13 @@
|
|
|
114
114
|
},
|
|
115
115
|
"devDependencies": {
|
|
116
116
|
"@chainsafe/libp2p-yamux": "^6.0.2",
|
|
117
|
-
"@libp2p/circuit-relay-v2": "1.1.5-
|
|
118
|
-
"@libp2p/identify": "2.1.5-
|
|
119
|
-
"@libp2p/interface-compliance-tests": "5.4.12-
|
|
120
|
-
"@libp2p/mplex": "10.1.5-
|
|
121
|
-
"@libp2p/plaintext": "1.1.6-
|
|
122
|
-
"@libp2p/tcp": "9.1.6-
|
|
123
|
-
"@libp2p/websockets": "8.2.0-
|
|
117
|
+
"@libp2p/circuit-relay-v2": "1.1.5-a142bb642",
|
|
118
|
+
"@libp2p/identify": "2.1.5-a142bb642",
|
|
119
|
+
"@libp2p/interface-compliance-tests": "5.4.12-a142bb642",
|
|
120
|
+
"@libp2p/mplex": "10.1.5-a142bb642",
|
|
121
|
+
"@libp2p/plaintext": "1.1.6-a142bb642",
|
|
122
|
+
"@libp2p/tcp": "9.1.6-a142bb642",
|
|
123
|
+
"@libp2p/websockets": "8.2.0-a142bb642",
|
|
124
124
|
"@multiformats/mafmt": "^12.1.6",
|
|
125
125
|
"aegir": "^44.0.1",
|
|
126
126
|
"delay": "^6.0.0",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { randomBytes } from '@libp2p/crypto'
|
|
2
|
-
import { serviceCapabilities } from '@libp2p/interface'
|
|
2
|
+
import { serviceCapabilities, setMaxListeners } from '@libp2p/interface'
|
|
3
3
|
import { AdaptiveTimeout } from '@libp2p/utils/adaptive-timeout'
|
|
4
4
|
import { byteStream } from 'it-byte-stream'
|
|
5
5
|
import type { ComponentLogger, Logger, Metrics, Startable } from '@libp2p/interface'
|
|
@@ -11,6 +11,7 @@ const PROTOCOL_VERSION = '1.0.0'
|
|
|
11
11
|
const PROTOCOL_NAME = 'ping'
|
|
12
12
|
const PROTOCOL_PREFIX = 'ipfs'
|
|
13
13
|
const PING_LENGTH = 32
|
|
14
|
+
const DEFAULT_ABORT_CONNECTION_ON_PING_FAILURE = true
|
|
14
15
|
|
|
15
16
|
export interface ConnectionMonitorInit {
|
|
16
17
|
/**
|
|
@@ -65,6 +66,7 @@ export class ConnectionMonitor implements Startable {
|
|
|
65
66
|
private readonly pingIntervalMs: number
|
|
66
67
|
private abortController?: AbortController
|
|
67
68
|
private readonly timeout: AdaptiveTimeout
|
|
69
|
+
private readonly abortConnectionOnPingFailure: boolean
|
|
68
70
|
|
|
69
71
|
constructor (components: ConnectionMonitorComponents, init: ConnectionMonitorInit = {}) {
|
|
70
72
|
this.components = components
|
|
@@ -72,7 +74,7 @@ export class ConnectionMonitor implements Startable {
|
|
|
72
74
|
|
|
73
75
|
this.log = components.logger.forComponent('libp2p:connection-monitor')
|
|
74
76
|
this.pingIntervalMs = init.pingInterval ?? DEFAULT_PING_INTERVAL_MS
|
|
75
|
-
|
|
77
|
+
this.abortConnectionOnPingFailure = init.abortConnectionOnPingFailure ?? DEFAULT_ABORT_CONNECTION_ON_PING_FAILURE
|
|
76
78
|
this.timeout = new AdaptiveTimeout({
|
|
77
79
|
...(init.pingTimeout ?? {}),
|
|
78
80
|
metrics: components.metrics,
|
|
@@ -88,6 +90,7 @@ export class ConnectionMonitor implements Startable {
|
|
|
88
90
|
|
|
89
91
|
start (): void {
|
|
90
92
|
this.abortController = new AbortController()
|
|
93
|
+
setMaxListeners(Infinity, this.abortController.signal)
|
|
91
94
|
|
|
92
95
|
this.heartbeatInterval = setInterval(() => {
|
|
93
96
|
this.components.connectionManager.getConnections().forEach(conn => {
|
|
@@ -131,8 +134,14 @@ export class ConnectionMonitor implements Startable {
|
|
|
131
134
|
}
|
|
132
135
|
})
|
|
133
136
|
.catch(err => {
|
|
134
|
-
this.log.error('error during heartbeat
|
|
135
|
-
|
|
137
|
+
this.log.error('error during heartbeat', err)
|
|
138
|
+
|
|
139
|
+
if (this.abortConnectionOnPingFailure) {
|
|
140
|
+
this.log.error('aborting connection due to ping failure')
|
|
141
|
+
conn.abort(err)
|
|
142
|
+
} else {
|
|
143
|
+
this.log('connection ping failed, but not aborting due to abortConnectionOnPingFailure flag')
|
|
144
|
+
}
|
|
136
145
|
})
|
|
137
146
|
})
|
|
138
147
|
}, this.pingIntervalMs)
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const version = '1.9.4-
|
|
1
|
+
export const version = '1.9.4-a142bb642'
|
|
2
2
|
export const name = 'libp2p'
|