@libp2p/tcp 10.1.12 → 10.1.13-2a7425cdb
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 +1 -1
- package/dist/index.min.js.map +2 -2
- package/dist/src/index.d.ts +14 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/listener.d.ts +3 -22
- package/dist/src/listener.d.ts.map +1 -1
- package/dist/src/listener.js +43 -45
- package/dist/src/listener.js.map +1 -1
- package/package.json +5 -5
- package/src/index.ts +16 -2
- package/src/listener.ts +52 -71
- package/dist/typedoc-urls.json +0 -19
package/dist/src/index.d.ts
CHANGED
|
@@ -26,10 +26,22 @@
|
|
|
26
26
|
* // use connection...
|
|
27
27
|
* ```
|
|
28
28
|
*/
|
|
29
|
-
import type { CloseServerOnMaxConnectionsOpts } from './listener.js';
|
|
30
29
|
import type { ComponentLogger, CounterGroup, Metrics, CreateListenerOptions, DialTransportOptions, Transport, OutboundConnectionUpgradeEvents } from '@libp2p/interface';
|
|
31
30
|
import type { ProgressEvent } from 'progress-events';
|
|
32
|
-
export
|
|
31
|
+
export interface CloseServerOnMaxConnectionsOpts {
|
|
32
|
+
/**
|
|
33
|
+
* Server listens once connection count is less than `listenBelow`
|
|
34
|
+
*/
|
|
35
|
+
listenBelow: number;
|
|
36
|
+
/**
|
|
37
|
+
* Close server once connection count is greater than or equal to `closeAbove`
|
|
38
|
+
*/
|
|
39
|
+
closeAbove: number;
|
|
40
|
+
/**
|
|
41
|
+
* Invoked when there was an error listening on a socket
|
|
42
|
+
*/
|
|
43
|
+
onListenError?(err: Error): void;
|
|
44
|
+
}
|
|
33
45
|
export interface TCPOptions {
|
|
34
46
|
/**
|
|
35
47
|
* An optional number in ms that is used as an inactivity timeout after which the socket will be closed
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":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E9B;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AAED,MAAM,MAAM,aAAa,GACvB,+BAA+B,GAC/B,aAAa,CAAC,qBAAqB,CAAC,CAAA;AAEtC,MAAM,WAAW,cAAe,SAAQ,oBAAoB,CAAC,aAAa,CAAC,EAAE,gBAAgB;CAE5F;AAED,MAAM,WAAW,wBAAyB,SAAQ,qBAAqB,EAAE,gBAAgB;CAExF;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,MAAM,EAAE,eAAe,CAAA;CACxB;AAED,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,YAAY,CAAC,OAAO,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,CAAC,CAAA;IAC/D,MAAM,EAAE,YAAY,CAAC,wBAAwB,GAAG,kBAAkB,CAAC,CAAA;CACpE;AAED,wBAAgB,GAAG,CAAE,IAAI,GAAE,UAAe,GAAG,CAAC,UAAU,EAAE,aAAa,KAAK,SAAS,CAIpF"}
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAiH9B,MAAM,UAAU,GAAG,CAAE,OAAmB,EAAE;IACxC,OAAO,CAAC,UAAyB,EAAE,EAAE;QACnC,OAAO,IAAI,GAAG,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;IAClC,CAAC,CAAA;AACH,CAAC"}
|
package/dist/src/listener.d.ts
CHANGED
|
@@ -1,21 +1,7 @@
|
|
|
1
1
|
import { TypedEventEmitter } from '@libp2p/interface';
|
|
2
|
-
import type { TCPCreateListenerOptions } from './index.js';
|
|
3
|
-
import type { ComponentLogger,
|
|
2
|
+
import type { CloseServerOnMaxConnectionsOpts, TCPCreateListenerOptions } from './index.js';
|
|
3
|
+
import type { ComponentLogger, Metrics, Listener, ListenerEvents, Upgrader } from '@libp2p/interface';
|
|
4
4
|
import type { Multiaddr } from '@multiformats/multiaddr';
|
|
5
|
-
export interface CloseServerOnMaxConnectionsOpts {
|
|
6
|
-
/**
|
|
7
|
-
* Server listens once connection count is less than `listenBelow`
|
|
8
|
-
*/
|
|
9
|
-
listenBelow: number;
|
|
10
|
-
/**
|
|
11
|
-
* Close server once connection count is greater than or equal to `closeAbove`
|
|
12
|
-
*/
|
|
13
|
-
closeAbove: number;
|
|
14
|
-
/**
|
|
15
|
-
* Invoked when there was an error listening on a socket
|
|
16
|
-
*/
|
|
17
|
-
onListenError?(err: Error): void;
|
|
18
|
-
}
|
|
19
5
|
interface Context extends TCPCreateListenerOptions {
|
|
20
6
|
upgrader: Upgrader;
|
|
21
7
|
socketInactivityTimeout?: number;
|
|
@@ -26,18 +12,13 @@ interface Context extends TCPCreateListenerOptions {
|
|
|
26
12
|
closeServerOnMaxConnections?: CloseServerOnMaxConnectionsOpts;
|
|
27
13
|
logger: ComponentLogger;
|
|
28
14
|
}
|
|
29
|
-
export interface TCPListenerMetrics {
|
|
30
|
-
status: MetricGroup;
|
|
31
|
-
errors: CounterGroup;
|
|
32
|
-
events: CounterGroup;
|
|
33
|
-
}
|
|
34
15
|
export declare class TCPListener extends TypedEventEmitter<ListenerEvents> implements Listener {
|
|
35
16
|
private readonly context;
|
|
36
17
|
private readonly server;
|
|
37
18
|
/** Keep track of open sockets to destroy in case of timeout */
|
|
38
19
|
private readonly sockets;
|
|
39
20
|
private status;
|
|
40
|
-
private metrics
|
|
21
|
+
private metrics;
|
|
41
22
|
private addr;
|
|
42
23
|
private readonly log;
|
|
43
24
|
private readonly shutdownController;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listener.d.ts","sourceRoot":"","sources":["../../src/listener.ts"],"names":[],"mappings":"AACA,OAAO,EAAgE,iBAAiB,EAAmB,MAAM,mBAAmB,CAAA;AAMpI,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"listener.d.ts","sourceRoot":"","sources":["../../src/listener.ts"],"names":[],"mappings":"AACA,OAAO,EAAgE,iBAAiB,EAAmB,MAAM,mBAAmB,CAAA;AAMpI,OAAO,KAAK,EAAE,+BAA+B,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAA;AAE3F,OAAO,KAAK,EAAE,eAAe,EAA0D,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC7J,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAExD,UAAU,OAAQ,SAAQ,wBAAwB;IAChD,QAAQ,EAAE,QAAQ,CAAA;IAClB,uBAAuB,CAAC,EAAE,MAAM,CAAA;IAChC,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,2BAA2B,CAAC,EAAE,+BAA+B,CAAA;IAC7D,MAAM,EAAE,eAAe,CAAA;CACxB;AA0BD,qBAAa,WAAY,SAAQ,iBAAiB,CAAC,cAAc,CAAE,YAAW,QAAQ;IAUvE,OAAO,CAAC,QAAQ,CAAC,OAAO;IATrC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAY;IACnC,+DAA+D;IAC/D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAwB;IAChD,OAAO,CAAC,MAAM,CAAmD;IACjE,OAAO,CAAC,OAAO,CAAoB;IACnC,OAAO,CAAC,IAAI,CAAQ;IACpB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAQ;IAC5B,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAiB;gBAEtB,OAAO,EAAE,OAAO;IA+F9C,OAAO,CAAC,QAAQ;IAsEhB,QAAQ,IAAK,SAAS,EAAE;IAqBxB,mBAAmB,IAAK,IAAI;IAItB,MAAM,CAAE,EAAE,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAmBrC,KAAK,IAAK,OAAO,CAAC,IAAI,CAAC;IAyB7B;;OAEG;YACW,MAAM;IAkBpB,OAAO,CAAC,KAAK;CAmCd"}
|
package/dist/src/listener.js
CHANGED
|
@@ -50,56 +50,54 @@ export class TCPListener extends TypedEventEmitter {
|
|
|
50
50
|
throw new InvalidParametersError('closeAbove must be >= listenBelow');
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
+
context.metrics?.registerMetricGroup('libp2p_tcp_inbound_connections_total', {
|
|
54
|
+
label: 'address',
|
|
55
|
+
help: 'Current active connections in TCP listener',
|
|
56
|
+
calculate: () => {
|
|
57
|
+
return {
|
|
58
|
+
[this.addr]: this.sockets.size
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
this.metrics = {
|
|
63
|
+
status: context.metrics?.registerMetricGroup('libp2p_tcp_listener_status_info', {
|
|
64
|
+
label: 'address',
|
|
65
|
+
help: 'Current status of the TCP listener socket'
|
|
66
|
+
}),
|
|
67
|
+
errors: context.metrics?.registerMetricGroup('libp2p_tcp_listener_errors_total', {
|
|
68
|
+
label: 'address',
|
|
69
|
+
help: 'Total count of TCP listener errors by type'
|
|
70
|
+
}),
|
|
71
|
+
events: context.metrics?.registerMetricGroup('libp2p_tcp_listener_events_total', {
|
|
72
|
+
label: 'address',
|
|
73
|
+
help: 'Total count of TCP listener events by type'
|
|
74
|
+
})
|
|
75
|
+
};
|
|
53
76
|
this.server
|
|
54
77
|
.on('listening', () => {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
this.addr = address;
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
this.addr = `${address.address}:${address.port}`;
|
|
67
|
-
}
|
|
68
|
-
context.metrics?.registerMetricGroup('libp2p_tcp_inbound_connections_total', {
|
|
69
|
-
label: 'address',
|
|
70
|
-
help: 'Current active connections in TCP listener',
|
|
71
|
-
calculate: () => {
|
|
72
|
-
return {
|
|
73
|
-
[this.addr]: this.sockets.size
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
this.metrics = {
|
|
78
|
-
status: context.metrics.registerMetricGroup('libp2p_tcp_listener_status_info', {
|
|
79
|
-
label: 'address',
|
|
80
|
-
help: 'Current status of the TCP listener socket'
|
|
81
|
-
}),
|
|
82
|
-
errors: context.metrics.registerMetricGroup('libp2p_tcp_listener_errors_total', {
|
|
83
|
-
label: 'address',
|
|
84
|
-
help: 'Total count of TCP listener errors by type'
|
|
85
|
-
}),
|
|
86
|
-
events: context.metrics.registerMetricGroup('libp2p_tcp_listener_events_total', {
|
|
87
|
-
label: 'address',
|
|
88
|
-
help: 'Total count of TCP listener events by type'
|
|
89
|
-
})
|
|
90
|
-
};
|
|
91
|
-
this.metrics?.status.update({
|
|
92
|
-
[this.addr]: TCPListenerStatusCode.ACTIVE
|
|
93
|
-
});
|
|
78
|
+
// we are listening, register metrics for our port
|
|
79
|
+
const address = this.server.address();
|
|
80
|
+
if (address == null) {
|
|
81
|
+
this.addr = 'unknown';
|
|
82
|
+
}
|
|
83
|
+
else if (typeof address === 'string') {
|
|
84
|
+
// unix socket
|
|
85
|
+
this.addr = address;
|
|
94
86
|
}
|
|
87
|
+
else {
|
|
88
|
+
this.addr = `${address.address}:${address.port}`;
|
|
89
|
+
}
|
|
90
|
+
this.metrics.status?.update({
|
|
91
|
+
[this.addr]: TCPListenerStatusCode.ACTIVE
|
|
92
|
+
});
|
|
95
93
|
this.safeDispatchEvent('listening');
|
|
96
94
|
})
|
|
97
95
|
.on('error', err => {
|
|
98
|
-
this.metrics?.
|
|
96
|
+
this.metrics.errors?.increment({ [`${this.addr} listen_error`]: true });
|
|
99
97
|
this.safeDispatchEvent('error', { detail: err });
|
|
100
98
|
})
|
|
101
99
|
.on('close', () => {
|
|
102
|
-
this.metrics?.
|
|
100
|
+
this.metrics.status?.update({
|
|
103
101
|
[this.addr]: this.status.code
|
|
104
102
|
});
|
|
105
103
|
// If this event is emitted, the transport manager will remove the
|
|
@@ -111,11 +109,11 @@ export class TCPListener extends TypedEventEmitter {
|
|
|
111
109
|
}
|
|
112
110
|
})
|
|
113
111
|
.on('drop', () => {
|
|
114
|
-
this.metrics?.
|
|
112
|
+
this.metrics.events?.increment({ [`${this.addr} drop`]: true });
|
|
115
113
|
});
|
|
116
114
|
}
|
|
117
115
|
onSocket(socket) {
|
|
118
|
-
this.metrics?.
|
|
116
|
+
this.metrics.events?.increment({ [`${this.addr} connection`]: true });
|
|
119
117
|
if (this.status.code !== TCPListenerStatusCode.ACTIVE) {
|
|
120
118
|
socket.destroy();
|
|
121
119
|
throw new NotStartedError('Server is not listening yet');
|
|
@@ -134,7 +132,7 @@ export class TCPListener extends TypedEventEmitter {
|
|
|
134
132
|
}
|
|
135
133
|
catch (err) {
|
|
136
134
|
this.log.error('inbound connection failed', err);
|
|
137
|
-
this.metrics?.
|
|
135
|
+
this.metrics.errors?.increment({ [`${this.addr} inbound_to_connection`]: true });
|
|
138
136
|
socket.destroy();
|
|
139
137
|
return;
|
|
140
138
|
}
|
|
@@ -168,7 +166,7 @@ export class TCPListener extends TypedEventEmitter {
|
|
|
168
166
|
})
|
|
169
167
|
.catch(async (err) => {
|
|
170
168
|
this.log.error('inbound connection upgrade failed', err);
|
|
171
|
-
this.metrics?.
|
|
169
|
+
this.metrics.errors?.increment({ [`${this.addr} inbound_upgrade`]: true });
|
|
172
170
|
this.sockets.delete(socket);
|
|
173
171
|
maConn.abort(err);
|
|
174
172
|
});
|
package/dist/src/listener.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listener.js","sourceRoot":"","sources":["../../src/listener.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAA;AACrB,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,eAAe,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACpI,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAA;AAC9E,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAChC,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAA;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"listener.js","sourceRoot":"","sources":["../../src/listener.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAA;AACrB,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,eAAe,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACpI,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAA;AAC9E,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAChC,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAA;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAuBjD,IAAK,qBAUJ;AAVD,WAAK,qBAAqB;IACxB;;;;OAIG;IACH,yEAAY,CAAA;IACZ,qEAAU,CAAA;IACV,kCAAkC;IAClC,qEAAU,CAAA;AACZ,CAAC,EAVI,qBAAqB,KAArB,qBAAqB,QAUzB;AAQD,MAAM,OAAO,WAAY,SAAQ,iBAAi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yE;QACzE,2BAA2B;QAC3B,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAA;IACrB,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/tcp",
|
|
3
|
-
"version": "10.1.
|
|
3
|
+
"version": "10.1.13-2a7425cdb",
|
|
4
4
|
"description": "A TCP transport for libp2p",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/transport-tcp#readme",
|
|
@@ -53,8 +53,8 @@
|
|
|
53
53
|
"test:electron-main": "aegir test -t electron-main"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@libp2p/interface": "
|
|
57
|
-
"@libp2p/utils": "
|
|
56
|
+
"@libp2p/interface": "2.10.2-2a7425cdb",
|
|
57
|
+
"@libp2p/utils": "6.6.5-2a7425cdb",
|
|
58
58
|
"@multiformats/multiaddr": "^12.4.0",
|
|
59
59
|
"@multiformats/multiaddr-matcher": "^1.7.2",
|
|
60
60
|
"@types/sinon": "^17.0.4",
|
|
@@ -65,8 +65,8 @@
|
|
|
65
65
|
"stream-to-it": "^1.0.1"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"@libp2p/logger": "
|
|
69
|
-
"aegir": "^47.0.
|
|
68
|
+
"@libp2p/logger": "5.1.18-2a7425cdb",
|
|
69
|
+
"aegir": "^47.0.14",
|
|
70
70
|
"p-wait-for": "^5.0.2",
|
|
71
71
|
"sinon": "^20.0.0",
|
|
72
72
|
"sinon-ts": "^2.0.0",
|
package/src/index.ts
CHANGED
|
@@ -28,11 +28,25 @@
|
|
|
28
28
|
*/
|
|
29
29
|
|
|
30
30
|
import { TCP } from './tcp.js'
|
|
31
|
-
import type { CloseServerOnMaxConnectionsOpts } from './listener.js'
|
|
32
31
|
import type { ComponentLogger, CounterGroup, Metrics, CreateListenerOptions, DialTransportOptions, Transport, OutboundConnectionUpgradeEvents } from '@libp2p/interface'
|
|
33
32
|
import type { ProgressEvent } from 'progress-events'
|
|
34
33
|
|
|
35
|
-
export
|
|
34
|
+
export interface CloseServerOnMaxConnectionsOpts {
|
|
35
|
+
/**
|
|
36
|
+
* Server listens once connection count is less than `listenBelow`
|
|
37
|
+
*/
|
|
38
|
+
listenBelow: number
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Close server once connection count is greater than or equal to `closeAbove`
|
|
42
|
+
*/
|
|
43
|
+
closeAbove: number
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Invoked when there was an error listening on a socket
|
|
47
|
+
*/
|
|
48
|
+
onListenError?(err: Error): void
|
|
49
|
+
}
|
|
36
50
|
|
|
37
51
|
export interface TCPOptions {
|
|
38
52
|
/**
|
package/src/listener.ts
CHANGED
|
@@ -5,28 +5,11 @@ import { multiaddr } from '@multiformats/multiaddr'
|
|
|
5
5
|
import { pEvent } from 'p-event'
|
|
6
6
|
import { toMultiaddrConnection } from './socket-to-conn.js'
|
|
7
7
|
import { multiaddrToNetConfig } from './utils.js'
|
|
8
|
-
import type { TCPCreateListenerOptions } from './index.js'
|
|
8
|
+
import type { CloseServerOnMaxConnectionsOpts, TCPCreateListenerOptions } from './index.js'
|
|
9
9
|
import type { NetConfig } from './utils.js'
|
|
10
10
|
import type { ComponentLogger, Logger, MultiaddrConnection, CounterGroup, MetricGroup, Metrics, Listener, ListenerEvents, Upgrader } from '@libp2p/interface'
|
|
11
11
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
12
12
|
|
|
13
|
-
export interface CloseServerOnMaxConnectionsOpts {
|
|
14
|
-
/**
|
|
15
|
-
* Server listens once connection count is less than `listenBelow`
|
|
16
|
-
*/
|
|
17
|
-
listenBelow: number
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Close server once connection count is greater than or equal to `closeAbove`
|
|
21
|
-
*/
|
|
22
|
-
closeAbove: number
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Invoked when there was an error listening on a socket
|
|
26
|
-
*/
|
|
27
|
-
onListenError?(err: Error): void
|
|
28
|
-
}
|
|
29
|
-
|
|
30
13
|
interface Context extends TCPCreateListenerOptions {
|
|
31
14
|
upgrader: Upgrader
|
|
32
15
|
socketInactivityTimeout?: number
|
|
@@ -38,10 +21,10 @@ interface Context extends TCPCreateListenerOptions {
|
|
|
38
21
|
logger: ComponentLogger
|
|
39
22
|
}
|
|
40
23
|
|
|
41
|
-
|
|
42
|
-
status
|
|
43
|
-
errors
|
|
44
|
-
events
|
|
24
|
+
interface TCPListenerMetrics {
|
|
25
|
+
status?: MetricGroup
|
|
26
|
+
errors?: CounterGroup
|
|
27
|
+
events?: CounterGroup
|
|
45
28
|
}
|
|
46
29
|
|
|
47
30
|
enum TCPListenerStatusCode {
|
|
@@ -53,7 +36,7 @@ enum TCPListenerStatusCode {
|
|
|
53
36
|
INACTIVE = 0,
|
|
54
37
|
ACTIVE = 1,
|
|
55
38
|
/* During the connection limits */
|
|
56
|
-
PAUSED = 2
|
|
39
|
+
PAUSED = 2
|
|
57
40
|
}
|
|
58
41
|
|
|
59
42
|
type Status = { code: TCPListenerStatusCode.INACTIVE } | {
|
|
@@ -67,7 +50,7 @@ export class TCPListener extends TypedEventEmitter<ListenerEvents> implements Li
|
|
|
67
50
|
/** Keep track of open sockets to destroy in case of timeout */
|
|
68
51
|
private readonly sockets = new Set<net.Socket>()
|
|
69
52
|
private status: Status = { code: TCPListenerStatusCode.INACTIVE }
|
|
70
|
-
private metrics
|
|
53
|
+
private metrics: TCPListenerMetrics
|
|
71
54
|
private addr: string
|
|
72
55
|
private readonly log: Logger
|
|
73
56
|
private readonly shutdownController: AbortController
|
|
@@ -100,59 +83,57 @@ export class TCPListener extends TypedEventEmitter<ListenerEvents> implements Li
|
|
|
100
83
|
}
|
|
101
84
|
}
|
|
102
85
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
// unix socket
|
|
113
|
-
this.addr = address
|
|
114
|
-
} else {
|
|
115
|
-
this.addr = `${address.address}:${address.port}`
|
|
116
|
-
}
|
|
86
|
+
context.metrics?.registerMetricGroup('libp2p_tcp_inbound_connections_total', {
|
|
87
|
+
label: 'address',
|
|
88
|
+
help: 'Current active connections in TCP listener',
|
|
89
|
+
calculate: () => {
|
|
90
|
+
return {
|
|
91
|
+
[this.addr]: this.sockets.size
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
})
|
|
117
95
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}),
|
|
133
|
-
errors: context.metrics.registerMetricGroup('libp2p_tcp_listener_errors_total', {
|
|
134
|
-
label: 'address',
|
|
135
|
-
help: 'Total count of TCP listener errors by type'
|
|
136
|
-
}),
|
|
137
|
-
events: context.metrics.registerMetricGroup('libp2p_tcp_listener_events_total', {
|
|
138
|
-
label: 'address',
|
|
139
|
-
help: 'Total count of TCP listener events by type'
|
|
140
|
-
})
|
|
141
|
-
}
|
|
96
|
+
this.metrics = {
|
|
97
|
+
status: context.metrics?.registerMetricGroup('libp2p_tcp_listener_status_info', {
|
|
98
|
+
label: 'address',
|
|
99
|
+
help: 'Current status of the TCP listener socket'
|
|
100
|
+
}),
|
|
101
|
+
errors: context.metrics?.registerMetricGroup('libp2p_tcp_listener_errors_total', {
|
|
102
|
+
label: 'address',
|
|
103
|
+
help: 'Total count of TCP listener errors by type'
|
|
104
|
+
}),
|
|
105
|
+
events: context.metrics?.registerMetricGroup('libp2p_tcp_listener_events_total', {
|
|
106
|
+
label: 'address',
|
|
107
|
+
help: 'Total count of TCP listener events by type'
|
|
108
|
+
})
|
|
109
|
+
}
|
|
142
110
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
111
|
+
this.server
|
|
112
|
+
.on('listening', () => {
|
|
113
|
+
// we are listening, register metrics for our port
|
|
114
|
+
const address = this.server.address()
|
|
115
|
+
|
|
116
|
+
if (address == null) {
|
|
117
|
+
this.addr = 'unknown'
|
|
118
|
+
} else if (typeof address === 'string') {
|
|
119
|
+
// unix socket
|
|
120
|
+
this.addr = address
|
|
121
|
+
} else {
|
|
122
|
+
this.addr = `${address.address}:${address.port}`
|
|
146
123
|
}
|
|
147
124
|
|
|
125
|
+
this.metrics.status?.update({
|
|
126
|
+
[this.addr]: TCPListenerStatusCode.ACTIVE
|
|
127
|
+
})
|
|
128
|
+
|
|
148
129
|
this.safeDispatchEvent('listening')
|
|
149
130
|
})
|
|
150
131
|
.on('error', err => {
|
|
151
|
-
this.metrics?.
|
|
132
|
+
this.metrics.errors?.increment({ [`${this.addr} listen_error`]: true })
|
|
152
133
|
this.safeDispatchEvent('error', { detail: err })
|
|
153
134
|
})
|
|
154
135
|
.on('close', () => {
|
|
155
|
-
this.metrics?.
|
|
136
|
+
this.metrics.status?.update({
|
|
156
137
|
[this.addr]: this.status.code
|
|
157
138
|
})
|
|
158
139
|
|
|
@@ -165,12 +146,12 @@ export class TCPListener extends TypedEventEmitter<ListenerEvents> implements Li
|
|
|
165
146
|
}
|
|
166
147
|
})
|
|
167
148
|
.on('drop', () => {
|
|
168
|
-
this.metrics?.
|
|
149
|
+
this.metrics.events?.increment({ [`${this.addr} drop`]: true })
|
|
169
150
|
})
|
|
170
151
|
}
|
|
171
152
|
|
|
172
153
|
private onSocket (socket: net.Socket): void {
|
|
173
|
-
this.metrics?.
|
|
154
|
+
this.metrics.events?.increment({ [`${this.addr} connection`]: true })
|
|
174
155
|
|
|
175
156
|
if (this.status.code !== TCPListenerStatusCode.ACTIVE) {
|
|
176
157
|
socket.destroy()
|
|
@@ -190,7 +171,7 @@ export class TCPListener extends TypedEventEmitter<ListenerEvents> implements Li
|
|
|
190
171
|
})
|
|
191
172
|
} catch (err: any) {
|
|
192
173
|
this.log.error('inbound connection failed', err)
|
|
193
|
-
this.metrics?.
|
|
174
|
+
this.metrics.errors?.increment({ [`${this.addr} inbound_to_connection`]: true })
|
|
194
175
|
socket.destroy()
|
|
195
176
|
return
|
|
196
177
|
}
|
|
@@ -233,7 +214,7 @@ export class TCPListener extends TypedEventEmitter<ListenerEvents> implements Li
|
|
|
233
214
|
})
|
|
234
215
|
.catch(async err => {
|
|
235
216
|
this.log.error('inbound connection upgrade failed', err)
|
|
236
|
-
this.metrics?.
|
|
217
|
+
this.metrics.errors?.increment({ [`${this.addr} inbound_upgrade`]: true })
|
|
237
218
|
this.sockets.delete(socket)
|
|
238
219
|
maConn.abort(err)
|
|
239
220
|
})
|
package/dist/typedoc-urls.json
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"CloseServerOnMaxConnectionsOpts": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_tcp.CloseServerOnMaxConnectionsOpts.html",
|
|
3
|
-
"TCPComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_tcp.TCPComponents.html",
|
|
4
|
-
".:TCPComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_tcp.TCPComponents.html",
|
|
5
|
-
"TCPCreateListenerOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_tcp.TCPCreateListenerOptions.html",
|
|
6
|
-
".:TCPCreateListenerOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_tcp.TCPCreateListenerOptions.html",
|
|
7
|
-
"TCPDialOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_tcp.TCPDialOptions.html",
|
|
8
|
-
".:TCPDialOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_tcp.TCPDialOptions.html",
|
|
9
|
-
"TCPMetrics": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_tcp.TCPMetrics.html",
|
|
10
|
-
".:TCPMetrics": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_tcp.TCPMetrics.html",
|
|
11
|
-
"TCPOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_tcp.TCPOptions.html",
|
|
12
|
-
".:TCPOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_tcp.TCPOptions.html",
|
|
13
|
-
"TCPSocketOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_tcp.TCPSocketOptions.html",
|
|
14
|
-
".:TCPSocketOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_tcp.TCPSocketOptions.html",
|
|
15
|
-
"TCPDialEvents": "https://libp2p.github.io/js-libp2p/types/_libp2p_tcp.TCPDialEvents.html",
|
|
16
|
-
".:TCPDialEvents": "https://libp2p.github.io/js-libp2p/types/_libp2p_tcp.TCPDialEvents.html",
|
|
17
|
-
"tcp": "https://libp2p.github.io/js-libp2p/functions/_libp2p_tcp.tcp.html",
|
|
18
|
-
".:tcp": "https://libp2p.github.io/js-libp2p/functions/_libp2p_tcp.tcp.html"
|
|
19
|
-
}
|