@libp2p/tcp 10.1.18 → 10.1.19
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"socket-to-conn.d.ts","sourceRoot":"","sources":["../../src/socket-to-conn.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,eAAe,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAC3F,OAAO,KAAK,EAAgB,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACtE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,KAAK,CAAA;AAGjC,UAAU,mBAAmB;IAC3B,aAAa,CAAC,EAAE,SAAS,CAAA;IACzB,UAAU,CAAC,EAAE,SAAS,CAAA;IACtB,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB,uBAAuB,CAAC,EAAE,MAAM,CAAA;IAChC,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,OAAO,CAAC,EAAE,YAAY,CAAA;IACtB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,MAAM,EAAE,eAAe,CAAA;IACvB,SAAS,EAAE,SAAS,GAAG,UAAU,CAAA;CAClC;AAED;;;GAGG;AACH,eAAO,MAAM,qBAAqB,GAAI,QAAQ,MAAM,EAAE,SAAS,mBAAmB,KAAG,
|
|
1
|
+
{"version":3,"file":"socket-to-conn.d.ts","sourceRoot":"","sources":["../../src/socket-to-conn.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,eAAe,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAC3F,OAAO,KAAK,EAAgB,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACtE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,KAAK,CAAA;AAGjC,UAAU,mBAAmB;IAC3B,aAAa,CAAC,EAAE,SAAS,CAAA;IACzB,UAAU,CAAC,EAAE,SAAS,CAAA;IACtB,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB,uBAAuB,CAAC,EAAE,MAAM,CAAA;IAChC,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,OAAO,CAAC,EAAE,YAAY,CAAA;IACtB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,MAAM,EAAE,eAAe,CAAA;IACvB,SAAS,EAAE,SAAS,GAAG,UAAU,CAAA;CAClC;AAED;;;GAGG;AACH,eAAO,MAAM,qBAAqB,GAAI,QAAQ,MAAM,EAAE,SAAS,mBAAmB,KAAG,mBA2LpF,CAAA"}
|
|
@@ -11,7 +11,6 @@ import { multiaddrToNetConfig } from './utils.js';
|
|
|
11
11
|
*/
|
|
12
12
|
export const toMultiaddrConnection = (socket, options) => {
|
|
13
13
|
let closePromise;
|
|
14
|
-
const log = options.logger.forComponent('libp2p:tcp:socket');
|
|
15
14
|
const direction = options.direction;
|
|
16
15
|
const metrics = options.metrics;
|
|
17
16
|
const metricPrefix = options.metricPrefix ?? '';
|
|
@@ -30,7 +29,7 @@ export const toMultiaddrConnection = (socket, options) => {
|
|
|
30
29
|
socket.on('error', err => {
|
|
31
30
|
errored = true;
|
|
32
31
|
if (!timedOut) {
|
|
33
|
-
log.error('%s socket error - %e', direction, err);
|
|
32
|
+
maConn.log.error('%s socket error - %e', direction, err);
|
|
34
33
|
metrics?.increment({ [`${metricPrefix}error`]: true });
|
|
35
34
|
}
|
|
36
35
|
socket.destroy();
|
|
@@ -56,7 +55,7 @@ export const toMultiaddrConnection = (socket, options) => {
|
|
|
56
55
|
socket.setTimeout(inactivityTimeout);
|
|
57
56
|
socket.once('timeout', () => {
|
|
58
57
|
timedOut = true;
|
|
59
|
-
log('%s %s socket read timeout', direction, lOptsStr);
|
|
58
|
+
maConn.log('%s %s socket read timeout', direction, lOptsStr);
|
|
60
59
|
metrics?.increment({ [`${metricPrefix}timeout`]: true });
|
|
61
60
|
// if the socket times out due to inactivity we must manually close the connection
|
|
62
61
|
// https://nodejs.org/dist/latest-v16.x/docs/api/net.html#event-timeout
|
|
@@ -66,7 +65,7 @@ export const toMultiaddrConnection = (socket, options) => {
|
|
|
66
65
|
socket.once('close', () => {
|
|
67
66
|
// record metric for clean exit
|
|
68
67
|
if (!timedOut && !errored) {
|
|
69
|
-
log('%s %s socket close', direction, lOptsStr);
|
|
68
|
+
maConn.log('%s %s socket close', direction, lOptsStr);
|
|
70
69
|
metrics?.increment({ [`${metricPrefix}close`]: true });
|
|
71
70
|
}
|
|
72
71
|
// In instances where `close` was not explicitly called,
|
|
@@ -78,7 +77,7 @@ export const toMultiaddrConnection = (socket, options) => {
|
|
|
78
77
|
socket.once('end', () => {
|
|
79
78
|
// the remote sent a FIN packet which means no more data will be sent
|
|
80
79
|
// https://nodejs.org/dist/latest-v16.x/docs/api/net.html#event-end
|
|
81
|
-
log('%s %s socket end', direction, lOptsStr);
|
|
80
|
+
maConn.log('%s %s socket end', direction, lOptsStr);
|
|
82
81
|
metrics?.increment({ [`${metricPrefix}end`]: true });
|
|
83
82
|
});
|
|
84
83
|
const maConn = {
|
|
@@ -101,7 +100,7 @@ export const toMultiaddrConnection = (socket, options) => {
|
|
|
101
100
|
// If the source errored the socket will already have been destroyed by
|
|
102
101
|
// duplex(). If the socket errored it will already be
|
|
103
102
|
// destroyed. There's nothing to do here except log the error & return.
|
|
104
|
-
log.error('%s %s error in sink - %e', direction, lOptsStr, err);
|
|
103
|
+
maConn.log.error('%s %s error in sink - %e', direction, lOptsStr, err);
|
|
105
104
|
}
|
|
106
105
|
}
|
|
107
106
|
// we have finished writing, send the FIN message
|
|
@@ -113,11 +112,11 @@ export const toMultiaddrConnection = (socket, options) => {
|
|
|
113
112
|
timeline: { open: Date.now() },
|
|
114
113
|
async close(options = {}) {
|
|
115
114
|
if (socket.closed) {
|
|
116
|
-
log('the %s %s socket is already closed', direction, lOptsStr);
|
|
115
|
+
maConn.log('the %s %s socket is already closed', direction, lOptsStr);
|
|
117
116
|
return;
|
|
118
117
|
}
|
|
119
118
|
if (socket.destroyed) {
|
|
120
|
-
log('the %s %s socket is already destroyed', direction, lOptsStr);
|
|
119
|
+
maConn.log('the %s %s socket is already destroyed', direction, lOptsStr);
|
|
121
120
|
return;
|
|
122
121
|
}
|
|
123
122
|
if (closePromise != null) {
|
|
@@ -133,11 +132,11 @@ export const toMultiaddrConnection = (socket, options) => {
|
|
|
133
132
|
const signal = options.signal ?? AbortSignal.timeout(closeTimeout);
|
|
134
133
|
// wait for any unsent data to be sent
|
|
135
134
|
if (socket.writableLength > 0) {
|
|
136
|
-
log('%s %s draining socket', direction, lOptsStr);
|
|
135
|
+
maConn.log('%s %s draining socket', direction, lOptsStr);
|
|
137
136
|
await raceEvent(eventTarget, 'drain', signal, {
|
|
138
137
|
errorEvent: 'error'
|
|
139
138
|
});
|
|
140
|
-
log('%s %s socket drained', direction, lOptsStr);
|
|
139
|
+
maConn.log('%s %s socket drained', direction, lOptsStr);
|
|
141
140
|
}
|
|
142
141
|
await Promise.all([
|
|
143
142
|
raceEvent(eventTarget, 'close', signal, {
|
|
@@ -155,7 +154,7 @@ export const toMultiaddrConnection = (socket, options) => {
|
|
|
155
154
|
}
|
|
156
155
|
},
|
|
157
156
|
abort: (err) => {
|
|
158
|
-
log('%s %s socket abort due to error - %e', direction, lOptsStr, err);
|
|
157
|
+
maConn.log('%s %s socket abort due to error - %e', direction, lOptsStr, err);
|
|
159
158
|
// the abortSignalListener may already destroyed the socket with an error
|
|
160
159
|
socket.destroy();
|
|
161
160
|
// closing a socket is always asynchronous (must wait for "close" event)
|
|
@@ -164,7 +163,7 @@ export const toMultiaddrConnection = (socket, options) => {
|
|
|
164
163
|
// reality.
|
|
165
164
|
maConn.timeline.close = Date.now();
|
|
166
165
|
},
|
|
167
|
-
log
|
|
166
|
+
log: options.logger.forComponent('libp2p:tcp:connection')
|
|
168
167
|
};
|
|
169
168
|
return maConn;
|
|
170
169
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"socket-to-conn.js","sourceRoot":"","sources":["../../src/socket-to-conn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACxE,OAAO,EAAE,iBAAiB,IAAI,WAAW,EAAE,MAAM,oCAAoC,CAAA;AACrF,OAAO,MAAM,MAAM,SAAS,CAAA;AAC5B,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAC9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAkBjD;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,MAAc,EAAE,OAA4B,EAAuB,EAAE;IACzG,IAAI,YAAmC,CAAA;IACvC,MAAM,
|
|
1
|
+
{"version":3,"file":"socket-to-conn.js","sourceRoot":"","sources":["../../src/socket-to-conn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACxE,OAAO,EAAE,iBAAiB,IAAI,WAAW,EAAE,MAAM,oCAAoC,CAAA;AACrF,OAAO,MAAM,MAAM,SAAS,CAAA;AAC5B,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAC9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAkBjD;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,MAAc,EAAE,OAA4B,EAAuB,EAAE;IACzG,IAAI,YAAmC,CAAA;IACvC,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,CAAA;IACnC,MAAM,OAAO,GAAG,OAAO,CAAC,OA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|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/tcp",
|
|
3
|
-
"version": "10.1.
|
|
3
|
+
"version": "10.1.19",
|
|
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": "^2.
|
|
57
|
-
"@libp2p/utils": "^6.7.
|
|
56
|
+
"@libp2p/interface": "^2.11.0",
|
|
57
|
+
"@libp2p/utils": "^6.7.2",
|
|
58
58
|
"@multiformats/multiaddr": "^12.4.4",
|
|
59
59
|
"@multiformats/multiaddr-matcher": "^2.0.0",
|
|
60
60
|
"@types/sinon": "^17.0.4",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"stream-to-it": "^1.0.1"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
|
-
"@libp2p/logger": "^5.
|
|
69
|
+
"@libp2p/logger": "^5.2.0",
|
|
70
70
|
"aegir": "^47.0.14",
|
|
71
71
|
"p-wait-for": "^5.0.2",
|
|
72
72
|
"sinon": "^20.0.0",
|
package/src/socket-to-conn.ts
CHANGED
|
@@ -28,7 +28,6 @@ interface ToConnectionOptions {
|
|
|
28
28
|
*/
|
|
29
29
|
export const toMultiaddrConnection = (socket: Socket, options: ToConnectionOptions): MultiaddrConnection => {
|
|
30
30
|
let closePromise: DeferredPromise<void>
|
|
31
|
-
const log = options.logger.forComponent('libp2p:tcp:socket')
|
|
32
31
|
const direction = options.direction
|
|
33
32
|
const metrics = options.metrics
|
|
34
33
|
const metricPrefix = options.metricPrefix ?? ''
|
|
@@ -51,7 +50,7 @@ export const toMultiaddrConnection = (socket: Socket, options: ToConnectionOptio
|
|
|
51
50
|
errored = true
|
|
52
51
|
|
|
53
52
|
if (!timedOut) {
|
|
54
|
-
log.error('%s socket error - %e', direction, err)
|
|
53
|
+
maConn.log.error('%s socket error - %e', direction, err)
|
|
55
54
|
metrics?.increment({ [`${metricPrefix}error`]: true })
|
|
56
55
|
}
|
|
57
56
|
|
|
@@ -83,7 +82,7 @@ export const toMultiaddrConnection = (socket: Socket, options: ToConnectionOptio
|
|
|
83
82
|
|
|
84
83
|
socket.once('timeout', () => {
|
|
85
84
|
timedOut = true
|
|
86
|
-
log('%s %s socket read timeout', direction, lOptsStr)
|
|
85
|
+
maConn.log('%s %s socket read timeout', direction, lOptsStr)
|
|
87
86
|
metrics?.increment({ [`${metricPrefix}timeout`]: true })
|
|
88
87
|
|
|
89
88
|
// if the socket times out due to inactivity we must manually close the connection
|
|
@@ -95,7 +94,7 @@ export const toMultiaddrConnection = (socket: Socket, options: ToConnectionOptio
|
|
|
95
94
|
socket.once('close', () => {
|
|
96
95
|
// record metric for clean exit
|
|
97
96
|
if (!timedOut && !errored) {
|
|
98
|
-
log('%s %s socket close', direction, lOptsStr)
|
|
97
|
+
maConn.log('%s %s socket close', direction, lOptsStr)
|
|
99
98
|
metrics?.increment({ [`${metricPrefix}close`]: true })
|
|
100
99
|
}
|
|
101
100
|
|
|
@@ -109,7 +108,7 @@ export const toMultiaddrConnection = (socket: Socket, options: ToConnectionOptio
|
|
|
109
108
|
socket.once('end', () => {
|
|
110
109
|
// the remote sent a FIN packet which means no more data will be sent
|
|
111
110
|
// https://nodejs.org/dist/latest-v16.x/docs/api/net.html#event-end
|
|
112
|
-
log('%s %s socket end', direction, lOptsStr)
|
|
111
|
+
maConn.log('%s %s socket end', direction, lOptsStr)
|
|
113
112
|
metrics?.increment({ [`${metricPrefix}end`]: true })
|
|
114
113
|
})
|
|
115
114
|
|
|
@@ -131,7 +130,7 @@ export const toMultiaddrConnection = (socket: Socket, options: ToConnectionOptio
|
|
|
131
130
|
// If the source errored the socket will already have been destroyed by
|
|
132
131
|
// duplex(). If the socket errored it will already be
|
|
133
132
|
// destroyed. There's nothing to do here except log the error & return.
|
|
134
|
-
log.error('%s %s error in sink - %e', direction, lOptsStr, err)
|
|
133
|
+
maConn.log.error('%s %s error in sink - %e', direction, lOptsStr, err)
|
|
135
134
|
}
|
|
136
135
|
}
|
|
137
136
|
|
|
@@ -148,12 +147,12 @@ export const toMultiaddrConnection = (socket: Socket, options: ToConnectionOptio
|
|
|
148
147
|
|
|
149
148
|
async close (options: AbortOptions = {}) {
|
|
150
149
|
if (socket.closed) {
|
|
151
|
-
log('the %s %s socket is already closed', direction, lOptsStr)
|
|
150
|
+
maConn.log('the %s %s socket is already closed', direction, lOptsStr)
|
|
152
151
|
return
|
|
153
152
|
}
|
|
154
153
|
|
|
155
154
|
if (socket.destroyed) {
|
|
156
|
-
log('the %s %s socket is already destroyed', direction, lOptsStr)
|
|
155
|
+
maConn.log('the %s %s socket is already destroyed', direction, lOptsStr)
|
|
157
156
|
return
|
|
158
157
|
}
|
|
159
158
|
|
|
@@ -175,11 +174,11 @@ export const toMultiaddrConnection = (socket: Socket, options: ToConnectionOptio
|
|
|
175
174
|
|
|
176
175
|
// wait for any unsent data to be sent
|
|
177
176
|
if (socket.writableLength > 0) {
|
|
178
|
-
log('%s %s draining socket', direction, lOptsStr)
|
|
177
|
+
maConn.log('%s %s draining socket', direction, lOptsStr)
|
|
179
178
|
await raceEvent(eventTarget, 'drain', signal, {
|
|
180
179
|
errorEvent: 'error'
|
|
181
180
|
})
|
|
182
|
-
log('%s %s socket drained', direction, lOptsStr)
|
|
181
|
+
maConn.log('%s %s socket drained', direction, lOptsStr)
|
|
183
182
|
}
|
|
184
183
|
|
|
185
184
|
await Promise.all([
|
|
@@ -198,7 +197,7 @@ export const toMultiaddrConnection = (socket: Socket, options: ToConnectionOptio
|
|
|
198
197
|
},
|
|
199
198
|
|
|
200
199
|
abort: (err: Error) => {
|
|
201
|
-
log('%s %s socket abort due to error - %e', direction, lOptsStr, err)
|
|
200
|
+
maConn.log('%s %s socket abort due to error - %e', direction, lOptsStr, err)
|
|
202
201
|
|
|
203
202
|
// the abortSignalListener may already destroyed the socket with an error
|
|
204
203
|
socket.destroy()
|
|
@@ -210,7 +209,7 @@ export const toMultiaddrConnection = (socket: Socket, options: ToConnectionOptio
|
|
|
210
209
|
maConn.timeline.close = Date.now()
|
|
211
210
|
},
|
|
212
211
|
|
|
213
|
-
log
|
|
212
|
+
log: options.logger.forComponent('libp2p:tcp:connection')
|
|
214
213
|
}
|
|
215
214
|
|
|
216
215
|
return maConn
|