@libp2p/websockets 9.0.13-6ddc1b80e → 9.0.13-8a9258a24
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/README.md +1 -35
- package/dist/index.min.js +1 -1
- package/dist/src/index.d.ts +27 -38
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +5 -43
- package/dist/src/index.js.map +1 -1
- package/dist/src/listener.d.ts +50 -5
- package/dist/src/listener.d.ts.map +1 -1
- package/dist/src/listener.js +289 -97
- package/dist/src/listener.js.map +1 -1
- package/package.json +6 -6
- package/src/index.ts +35 -48
- package/src/listener.ts +341 -110
package/dist/src/listener.js
CHANGED
|
@@ -1,105 +1,269 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import http from 'node:http';
|
|
2
|
+
import https from 'node:https';
|
|
3
|
+
import net from 'node:net';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import { TypedEventEmitter, setMaxListeners } from '@libp2p/interface';
|
|
3
6
|
import { ipPortToMultiaddr as toMultiaddr } from '@libp2p/utils/ip-port-to-multiaddr';
|
|
4
|
-
import { multiaddr
|
|
5
|
-
import {
|
|
7
|
+
import { multiaddr } from '@multiformats/multiaddr';
|
|
8
|
+
import { WebSockets, WebSocketsSecure } from '@multiformats/multiaddr-matcher';
|
|
9
|
+
import duplex from 'it-ws/duplex';
|
|
10
|
+
import { pEvent } from 'p-event';
|
|
11
|
+
import * as ws from 'ws';
|
|
6
12
|
import { socketToMaConn } from './socket-to-conn.js';
|
|
7
|
-
class WebSocketListener extends TypedEventEmitter {
|
|
8
|
-
connections;
|
|
9
|
-
listeningMultiaddr;
|
|
10
|
-
server;
|
|
13
|
+
export class WebSocketListener extends TypedEventEmitter {
|
|
11
14
|
log;
|
|
15
|
+
logger;
|
|
16
|
+
server;
|
|
17
|
+
wsServer;
|
|
12
18
|
metrics;
|
|
19
|
+
sockets;
|
|
20
|
+
upgrader;
|
|
21
|
+
inboundConnectionUpgradeTimeout;
|
|
22
|
+
httpOptions;
|
|
23
|
+
httpsOptions;
|
|
24
|
+
http;
|
|
25
|
+
https;
|
|
13
26
|
addr;
|
|
27
|
+
listeningMultiaddr;
|
|
14
28
|
constructor(components, init) {
|
|
15
29
|
super();
|
|
16
30
|
this.log = components.logger.forComponent('libp2p:websockets:listener');
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
this.
|
|
20
|
-
|
|
21
|
-
this.
|
|
22
|
-
this.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const maConn = socketToMaConn(stream, toMultiaddr(stream.remoteAddress ?? '', stream.remotePort ?? 0), {
|
|
26
|
-
logger: components.logger,
|
|
27
|
-
metrics: this.metrics?.events,
|
|
28
|
-
metricPrefix: `${this.addr} `
|
|
29
|
-
});
|
|
30
|
-
this.log('new inbound connection %s', maConn.remoteAddr);
|
|
31
|
-
this.connections.add(stream);
|
|
32
|
-
stream.socket.on('close', function () {
|
|
33
|
-
self.connections.delete(stream);
|
|
34
|
-
});
|
|
35
|
-
init.upgrader.upgradeInbound(maConn)
|
|
36
|
-
.catch(async (err) => {
|
|
37
|
-
this.log.error('inbound connection failed to upgrade', err);
|
|
38
|
-
this.metrics?.errors.increment({ [`${this.addr} inbound_upgrade`]: true });
|
|
39
|
-
try {
|
|
40
|
-
maConn.abort(err);
|
|
41
|
-
}
|
|
42
|
-
catch (err) {
|
|
43
|
-
this.log.error('inbound connection failed to close after upgrade failed - %e', err);
|
|
44
|
-
this.metrics?.errors.increment({ [`${this.addr} inbound_closing_failed`]: true });
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
}
|
|
31
|
+
this.logger = components.logger;
|
|
32
|
+
this.upgrader = init.upgrader;
|
|
33
|
+
this.httpOptions = init.http;
|
|
34
|
+
this.httpsOptions = init.https ?? init.http;
|
|
35
|
+
this.inboundConnectionUpgradeTimeout = init.inboundConnectionUpgradeTimeout ?? 5000;
|
|
36
|
+
this.sockets = new Set();
|
|
37
|
+
this.wsServer = new ws.WebSocketServer({
|
|
38
|
+
noServer: true
|
|
48
39
|
});
|
|
49
|
-
this.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
this.metrics = {
|
|
63
|
-
status: metrics?.registerMetricGroup('libp2p_websockets_listener_status_info', {
|
|
64
|
-
label: 'address',
|
|
65
|
-
help: 'Current status of the WebSocket listener socket'
|
|
66
|
-
}),
|
|
67
|
-
errors: metrics?.registerMetricGroup('libp2p_websockets_listener_errors_total', {
|
|
68
|
-
label: 'address',
|
|
69
|
-
help: 'Total count of WebSocket listener errors by type'
|
|
70
|
-
}),
|
|
71
|
-
events: metrics?.registerMetricGroup('libp2p_websockets_listener_events_total', {
|
|
72
|
-
label: 'address',
|
|
73
|
-
help: 'Total count of WebSocket listener events by type'
|
|
74
|
-
})
|
|
40
|
+
this.wsServer.addListener('connection', this.onWsServerConnection.bind(this));
|
|
41
|
+
components.metrics?.registerMetricGroup('libp2p_websockets_inbound_connections_total', {
|
|
42
|
+
label: 'address',
|
|
43
|
+
help: 'Current active connections in WebSocket listener',
|
|
44
|
+
calculate: () => {
|
|
45
|
+
if (this.addr == null) {
|
|
46
|
+
return {};
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
[this.addr]: this.sockets.size
|
|
75
50
|
};
|
|
76
51
|
}
|
|
77
|
-
this.dispatchEvent(new CustomEvent('listening'));
|
|
78
52
|
});
|
|
79
|
-
this.
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
})
|
|
53
|
+
this.metrics = {
|
|
54
|
+
status: components.metrics?.registerMetricGroup('libp2p_websockets_listener_status_info', {
|
|
55
|
+
label: 'address',
|
|
56
|
+
help: 'Current status of the WebSocket listener socket'
|
|
57
|
+
}),
|
|
58
|
+
errors: components.metrics?.registerMetricGroup('libp2p_websockets_listener_errors_total', {
|
|
59
|
+
label: 'address',
|
|
60
|
+
help: 'Total count of WebSocket listener errors by type'
|
|
61
|
+
}),
|
|
62
|
+
events: components.metrics?.registerMetricGroup('libp2p_websockets_listener_events_total', {
|
|
63
|
+
label: 'address',
|
|
64
|
+
help: 'Total count of WebSocket listener events by type'
|
|
65
|
+
})
|
|
66
|
+
};
|
|
67
|
+
this.server = net.createServer({
|
|
68
|
+
pauseOnConnect: true
|
|
69
|
+
}, (socket) => {
|
|
70
|
+
this.onSocketConnection(socket)
|
|
71
|
+
.catch(err => {
|
|
72
|
+
this.log.error('error handling socket - %e', err);
|
|
73
|
+
socket.destroy();
|
|
74
|
+
});
|
|
84
75
|
});
|
|
85
|
-
|
|
86
|
-
|
|
76
|
+
components.events.addEventListener('certificate:provision', this.onCertificateProvision.bind(this));
|
|
77
|
+
components.events.addEventListener('certificate:renew', this.onCertificateRenew.bind(this));
|
|
78
|
+
}
|
|
79
|
+
async onSocketConnection(socket) {
|
|
80
|
+
this.metrics.events?.increment({ [`${this.addr} connection`]: true });
|
|
81
|
+
let buffer = socket.read(1);
|
|
82
|
+
if (buffer == null) {
|
|
83
|
+
await pEvent(socket, 'readable');
|
|
84
|
+
buffer = socket.read(1);
|
|
85
|
+
}
|
|
86
|
+
// determine if this is an HTTP(s) request
|
|
87
|
+
const byte = buffer[0];
|
|
88
|
+
let server = this.http;
|
|
89
|
+
// https://github.com/mscdex/httpolyglot/blob/1c6c4af65f4cf95a32c918d0fdcc532e0c095740/lib/index.js#L92
|
|
90
|
+
if (byte < 32 || byte >= 127) {
|
|
91
|
+
server = this.https;
|
|
92
|
+
}
|
|
93
|
+
if (server == null) {
|
|
94
|
+
this.log.error('no appropriate listener configured for byte %d', byte);
|
|
95
|
+
socket.destroy();
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
// store the socket so we can close it when the listener closes
|
|
99
|
+
this.sockets.add(socket);
|
|
100
|
+
socket.on('close', () => {
|
|
101
|
+
this.metrics.events?.increment({ [`${this.addr} close`]: true });
|
|
102
|
+
this.sockets.delete(socket);
|
|
103
|
+
});
|
|
104
|
+
socket.on('error', (err) => {
|
|
105
|
+
this.log.error('socket error - %e', err);
|
|
106
|
+
this.metrics.events?.increment({ [`${this.addr} error`]: true });
|
|
107
|
+
socket.destroy();
|
|
108
|
+
});
|
|
109
|
+
socket.once('timeout', () => {
|
|
110
|
+
this.metrics.events?.increment({ [`${this.addr} timeout`]: true });
|
|
87
111
|
});
|
|
112
|
+
socket.once('end', () => {
|
|
113
|
+
this.metrics.events?.increment({ [`${this.addr} end`]: true });
|
|
114
|
+
});
|
|
115
|
+
// re-queue first data chunk
|
|
116
|
+
socket.unshift(buffer);
|
|
117
|
+
// hand the socket off to the appropriate server
|
|
118
|
+
server.emit('connection', socket);
|
|
88
119
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
120
|
+
onWsServerConnection(socket, req) {
|
|
121
|
+
let addr;
|
|
122
|
+
try {
|
|
123
|
+
addr = this.server.address();
|
|
124
|
+
if (typeof addr === 'string') {
|
|
125
|
+
throw new Error('Cannot listen on unix sockets');
|
|
126
|
+
}
|
|
127
|
+
if (addr == null) {
|
|
128
|
+
throw new Error('Server was closing or not running');
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
catch (err) {
|
|
132
|
+
this.log.error('error obtaining remote socket address - %e', err);
|
|
133
|
+
req.destroy(err);
|
|
134
|
+
socket.close();
|
|
93
135
|
return;
|
|
94
136
|
}
|
|
95
|
-
|
|
137
|
+
const stream = {
|
|
138
|
+
...duplex(socket, {
|
|
139
|
+
remoteAddress: req.socket.remoteAddress ?? '0.0.0.0',
|
|
140
|
+
remotePort: req.socket.remotePort ?? 0
|
|
141
|
+
}),
|
|
142
|
+
localAddress: addr.address,
|
|
143
|
+
localPort: addr.port
|
|
144
|
+
};
|
|
145
|
+
let maConn;
|
|
146
|
+
try {
|
|
147
|
+
maConn = socketToMaConn(stream, toMultiaddr(stream.remoteAddress ?? '', stream.remotePort ?? 0), {
|
|
148
|
+
logger: this.logger,
|
|
149
|
+
metrics: this.metrics?.events,
|
|
150
|
+
metricPrefix: `${this.addr} `
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
catch (err) {
|
|
154
|
+
this.log.error('inbound connection failed', err);
|
|
155
|
+
this.metrics.errors?.increment({ [`${this.addr} inbound_to_connection`]: true });
|
|
156
|
+
socket.close();
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
this.log('new inbound connection %s', maConn.remoteAddr);
|
|
160
|
+
const signal = AbortSignal.timeout(this.inboundConnectionUpgradeTimeout);
|
|
161
|
+
setMaxListeners(Infinity, signal);
|
|
162
|
+
this.upgrader.upgradeInbound(maConn, {
|
|
163
|
+
signal
|
|
164
|
+
})
|
|
165
|
+
.catch(async (err) => {
|
|
166
|
+
this.log.error('inbound connection failed to upgrade - %e', err);
|
|
167
|
+
this.metrics.errors?.increment({ [`${this.addr} inbound_upgrade`]: true });
|
|
168
|
+
await maConn.close()
|
|
169
|
+
.catch(err => {
|
|
170
|
+
this.log.error('inbound connection failed to close after upgrade failed', err);
|
|
171
|
+
this.metrics.errors?.increment({ [`${this.addr} inbound_closing_failed`]: true });
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
onUpgrade(req, socket, head) {
|
|
176
|
+
this.wsServer.handleUpgrade(req, socket, head, this.onWsServerConnection.bind(this));
|
|
177
|
+
}
|
|
178
|
+
onTLSClientError(err, socket) {
|
|
179
|
+
this.log.error('TLS client error - %e', err);
|
|
180
|
+
socket.destroy();
|
|
96
181
|
}
|
|
97
182
|
async listen(ma) {
|
|
183
|
+
if (WebSockets.exactMatch(ma)) {
|
|
184
|
+
this.http = http.createServer(this.httpOptions ?? {}, this.httpRequestHandler.bind(this));
|
|
185
|
+
this.http.addListener('upgrade', this.onUpgrade.bind(this));
|
|
186
|
+
}
|
|
187
|
+
else if (WebSocketsSecure.exactMatch(ma)) {
|
|
188
|
+
this.https = https.createServer(this.httpsOptions ?? {}, this.httpRequestHandler.bind(this));
|
|
189
|
+
this.https.addListener('upgrade', this.onUpgrade.bind(this));
|
|
190
|
+
this.https.addListener('tlsClientError', this.onTLSClientError.bind(this));
|
|
191
|
+
}
|
|
98
192
|
this.listeningMultiaddr = ma;
|
|
99
|
-
|
|
193
|
+
const { host, port } = ma.toOptions();
|
|
194
|
+
this.addr = `${host}:${port}`;
|
|
195
|
+
this.server.listen(port, host);
|
|
196
|
+
await new Promise((resolve, reject) => {
|
|
197
|
+
const onListening = () => {
|
|
198
|
+
removeListeners();
|
|
199
|
+
resolve();
|
|
200
|
+
};
|
|
201
|
+
const onError = (err) => {
|
|
202
|
+
this.metrics.errors?.increment({ [`${this.addr} listen_error`]: true });
|
|
203
|
+
removeListeners();
|
|
204
|
+
reject(err);
|
|
205
|
+
};
|
|
206
|
+
const onDrop = () => {
|
|
207
|
+
this.metrics.events?.increment({ [`${this.addr} drop`]: true });
|
|
208
|
+
};
|
|
209
|
+
const removeListeners = () => {
|
|
210
|
+
this.server.removeListener('listening', onListening);
|
|
211
|
+
this.server.removeListener('error', onError);
|
|
212
|
+
this.server.removeListener('drop', onDrop);
|
|
213
|
+
};
|
|
214
|
+
this.server.addListener('listening', onListening);
|
|
215
|
+
this.server.addListener('error', onError);
|
|
216
|
+
this.server.addListener('drop', onDrop);
|
|
217
|
+
});
|
|
218
|
+
this.safeDispatchEvent('listening');
|
|
219
|
+
}
|
|
220
|
+
onCertificateProvision(event) {
|
|
221
|
+
if (this.https != null) {
|
|
222
|
+
this.log('auto-tls certificate found but already listening on https');
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
this.log('auto-tls certificate found, starting https server');
|
|
226
|
+
this.https = https.createServer({
|
|
227
|
+
...this.httpsOptions,
|
|
228
|
+
...event.detail
|
|
229
|
+
}, this.httpRequestHandler.bind(this));
|
|
230
|
+
this.https.addListener('upgrade', this.onUpgrade.bind(this));
|
|
231
|
+
this.https.addListener('tlsClientError', this.onTLSClientError.bind(this));
|
|
232
|
+
this.safeDispatchEvent('listening');
|
|
233
|
+
}
|
|
234
|
+
onCertificateRenew(event) {
|
|
235
|
+
// stop accepting new connections
|
|
236
|
+
this.https?.close();
|
|
237
|
+
this.log('auto-tls certificate renewed, restarting https server');
|
|
238
|
+
this.https = https.createServer({
|
|
239
|
+
...this.httpsOptions,
|
|
240
|
+
...event.detail
|
|
241
|
+
}, this.httpRequestHandler.bind(this));
|
|
242
|
+
this.https.addListener('upgrade', this.onUpgrade.bind(this));
|
|
243
|
+
this.https.addListener('tlsClientError', this.onTLSClientError.bind(this));
|
|
244
|
+
}
|
|
245
|
+
async close() {
|
|
246
|
+
this.server.close();
|
|
247
|
+
this.http?.close();
|
|
248
|
+
this.https?.close();
|
|
249
|
+
this.wsServer.close();
|
|
250
|
+
// close all connections, must be done after closing the server to prevent
|
|
251
|
+
// race conditions where a new connection is accepted while we are closing
|
|
252
|
+
// the existing ones
|
|
253
|
+
this.http?.closeAllConnections();
|
|
254
|
+
this.https?.closeAllConnections();
|
|
255
|
+
[...this.sockets].forEach(socket => {
|
|
256
|
+
socket.destroy();
|
|
257
|
+
});
|
|
258
|
+
await Promise.all([
|
|
259
|
+
pEvent(this.server, 'close'),
|
|
260
|
+
this.http == null ? null : pEvent(this.http, 'close'),
|
|
261
|
+
this.https == null ? null : pEvent(this.https, 'close'),
|
|
262
|
+
pEvent(this.wsServer, 'close')
|
|
263
|
+
]);
|
|
264
|
+
this.safeDispatchEvent('close');
|
|
100
265
|
}
|
|
101
266
|
getAddrs() {
|
|
102
|
-
const multiaddrs = [];
|
|
103
267
|
const address = this.server.address();
|
|
104
268
|
if (address == null) {
|
|
105
269
|
throw new Error('Listener is not ready yet');
|
|
@@ -110,35 +274,63 @@ class WebSocketListener extends TypedEventEmitter {
|
|
|
110
274
|
if (this.listeningMultiaddr == null) {
|
|
111
275
|
throw new Error('Listener is not ready yet');
|
|
112
276
|
}
|
|
113
|
-
const
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
const wsProto = protos.some(proto => proto.code === protocols('ws').code) ? '/ws' : '/wss';
|
|
119
|
-
let m = this.listeningMultiaddr.decapsulate('tcp');
|
|
120
|
-
m = m.encapsulate(`/tcp/${address.port}${wsProto}`);
|
|
121
|
-
if (ipfsId != null) {
|
|
122
|
-
m = m.encapsulate(`/p2p/${ipfsId}`);
|
|
123
|
-
}
|
|
124
|
-
if (m.toString().includes('0.0.0.0')) {
|
|
125
|
-
const netInterfaces = os.networkInterfaces();
|
|
126
|
-
Object.values(netInterfaces).forEach(niInfos => {
|
|
277
|
+
const options = this.listeningMultiaddr.toOptions();
|
|
278
|
+
const multiaddrs = [];
|
|
279
|
+
if (options.family === 4) {
|
|
280
|
+
if (options.host === '0.0.0.0') {
|
|
281
|
+
Object.values(os.networkInterfaces()).forEach(niInfos => {
|
|
127
282
|
if (niInfos == null) {
|
|
128
283
|
return;
|
|
129
284
|
}
|
|
130
285
|
niInfos.forEach(ni => {
|
|
131
286
|
if (ni.family === 'IPv4') {
|
|
132
|
-
multiaddrs.push(multiaddr(
|
|
287
|
+
multiaddrs.push(multiaddr(`/ip${options.family}/${ni.address}/${options.transport}/${address.port}`));
|
|
133
288
|
}
|
|
134
289
|
});
|
|
135
290
|
});
|
|
136
291
|
}
|
|
137
292
|
else {
|
|
138
|
-
multiaddrs.push(
|
|
293
|
+
multiaddrs.push(multiaddr(`/ip${options.family}/${options.host}/${options.transport}/${address.port}`));
|
|
139
294
|
}
|
|
140
295
|
}
|
|
141
|
-
|
|
296
|
+
else if (options.family === 6) {
|
|
297
|
+
if (options.host === '::') {
|
|
298
|
+
Object.values(os.networkInterfaces()).forEach(niInfos => {
|
|
299
|
+
if (niInfos == null) {
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
niInfos.forEach(ni => {
|
|
303
|
+
if (ni.family === 'IPv6') {
|
|
304
|
+
multiaddrs.push(multiaddr(`/ip${options.family}/${ni.address}/${options.transport}/${address.port}`));
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
multiaddrs.push(multiaddr(`/ip${options.family}/${options.host}/${options.transport}/${address.port}`));
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
const insecureMultiaddrs = [];
|
|
314
|
+
if (this.http != null) {
|
|
315
|
+
multiaddrs.forEach(ma => {
|
|
316
|
+
insecureMultiaddrs.push(ma.encapsulate('/ws'));
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
const secureMultiaddrs = [];
|
|
320
|
+
if (this.https != null) {
|
|
321
|
+
multiaddrs.forEach(ma => {
|
|
322
|
+
secureMultiaddrs.push(ma.encapsulate('/tls/ws'));
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
return [
|
|
326
|
+
...insecureMultiaddrs,
|
|
327
|
+
...secureMultiaddrs
|
|
328
|
+
];
|
|
329
|
+
}
|
|
330
|
+
httpRequestHandler(req, res) {
|
|
331
|
+
res.writeHead(400);
|
|
332
|
+
res.write('Only WebSocket connections are supported');
|
|
333
|
+
res.end();
|
|
142
334
|
}
|
|
143
335
|
}
|
|
144
336
|
export function createListener(components, init) {
|
package/dist/src/listener.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listener.js","sourceRoot":"","sources":["../../src/listener.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAA;AACnB,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,EAAE,iBAAiB,IAAI,WAAW,EAAE,MAAM,oCAAoC,CAAA;AACrF,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,qB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,IAAI,EAAE,CAAC;YACtB,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE;gBACtB,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAA;YAChD,CAAC,CAAC,CAAA;QACJ,CAAC;QAED,MAAM,gBAAgB,GAAgB,EAAE,CAAA;QAExC,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,EAAE,CAAC;YACvB,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE;gBACtB,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,CAAA;YAClD,CAAC,CAAC,CAAA;QACJ,CAAC;QAED,OAAO;YACL,GAAG,kBAAkB;YACrB,GAAG,gBAAgB;SACpB,CAAA;IACH,CAAC;IAEO,kBAAkB,CAAE,GAAyB,EAAE,GAAwB;QAC7E,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA;QAClB,GAAG,CAAC,KAAK,CAAC,0CAA0C,CAAC,CAAA;QACrD,GAAG,CAAC,GAAG,EAAE,CAAA;IACX,CAAC;CACF;AAED,MAAM,UAAU,cAAc,CAAE,UAAuC,EAAE,IAA2B;IAClG,OAAO,IAAI,iBAAiB,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;AAChD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/websockets",
|
|
3
|
-
"version": "9.0.13-
|
|
3
|
+
"version": "9.0.13-8a9258a24",
|
|
4
4
|
"description": "JavaScript implementation of the WebSockets module that libp2p uses and that implements the interface-transport spec",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/transport-websockets#readme",
|
|
@@ -74,21 +74,21 @@
|
|
|
74
74
|
"test:electron-main": "aegir test -t electron-main -f ./dist/test/node.js --cov"
|
|
75
75
|
},
|
|
76
76
|
"dependencies": {
|
|
77
|
-
"@libp2p/interface": "2.2.1-
|
|
78
|
-
"@libp2p/utils": "6.2.1-
|
|
77
|
+
"@libp2p/interface": "2.2.1-8a9258a24",
|
|
78
|
+
"@libp2p/utils": "6.2.1-8a9258a24",
|
|
79
79
|
"@multiformats/multiaddr": "^12.2.3",
|
|
80
80
|
"@multiformats/multiaddr-matcher": "^1.4.0",
|
|
81
|
-
"@multiformats/multiaddr-to-uri": "^
|
|
81
|
+
"@multiformats/multiaddr-to-uri": "^11.0.0",
|
|
82
82
|
"@types/ws": "^8.5.10",
|
|
83
83
|
"it-ws": "^6.1.1",
|
|
84
84
|
"p-defer": "^4.0.1",
|
|
85
|
+
"p-event": "^6.0.1",
|
|
85
86
|
"progress-events": "^1.0.0",
|
|
86
87
|
"race-signal": "^1.0.2",
|
|
87
|
-
"wherearewe": "^2.0.1",
|
|
88
88
|
"ws": "^8.17.0"
|
|
89
89
|
},
|
|
90
90
|
"devDependencies": {
|
|
91
|
-
"@libp2p/logger": "5.1.4-
|
|
91
|
+
"@libp2p/logger": "5.1.4-8a9258a24",
|
|
92
92
|
"aegir": "^44.0.1",
|
|
93
93
|
"is-loopback-addr": "^2.0.2",
|
|
94
94
|
"p-wait-for": "^5.0.2",
|
package/src/index.ts
CHANGED
|
@@ -18,43 +18,9 @@
|
|
|
18
18
|
* })
|
|
19
19
|
* await node.start()
|
|
20
20
|
*
|
|
21
|
-
* const ma = multiaddr('/
|
|
21
|
+
* const ma = multiaddr('/dns4/example.com/tcp/9090/tls/ws')
|
|
22
22
|
* await node.dial(ma)
|
|
23
23
|
* ```
|
|
24
|
-
*
|
|
25
|
-
* ## Filters
|
|
26
|
-
*
|
|
27
|
-
* When run in a browser by default this module will only connect to secure web socket addresses.
|
|
28
|
-
*
|
|
29
|
-
* To change this you should pass a filter to the factory function.
|
|
30
|
-
*
|
|
31
|
-
* You can create your own address filters for this transports, or rely in the filters [provided](./src/filters.js).
|
|
32
|
-
*
|
|
33
|
-
* The available filters are:
|
|
34
|
-
*
|
|
35
|
-
* - `filters.all`
|
|
36
|
-
* - Returns all TCP and DNS based addresses, both with `ws` or `wss`.
|
|
37
|
-
* - `filters.dnsWss`
|
|
38
|
-
* - Returns all DNS based addresses with `wss`.
|
|
39
|
-
* - `filters.dnsWsOrWss`
|
|
40
|
-
* - Returns all DNS based addresses, both with `ws` or `wss`.
|
|
41
|
-
*
|
|
42
|
-
* @example Allow dialing insecure WebSockets
|
|
43
|
-
*
|
|
44
|
-
* ```TypeScript
|
|
45
|
-
* import { createLibp2p } from 'libp2p'
|
|
46
|
-
* import { webSockets } from '@libp2p/websockets'
|
|
47
|
-
* import * as filters from '@libp2p/websockets/filters'
|
|
48
|
-
*
|
|
49
|
-
* const node = await createLibp2p({
|
|
50
|
-
* transports: [
|
|
51
|
-
* webSockets({
|
|
52
|
-
* // connect to all sockets, even insecure ones
|
|
53
|
-
* filter: filters.all
|
|
54
|
-
* })
|
|
55
|
-
* ]
|
|
56
|
-
* })
|
|
57
|
-
* ```
|
|
58
24
|
*/
|
|
59
25
|
|
|
60
26
|
import { transportSymbol, serviceCapabilities, ConnectionFailedError } from '@libp2p/interface'
|
|
@@ -63,25 +29,50 @@ import { connect, type WebSocketOptions } from 'it-ws/client'
|
|
|
63
29
|
import pDefer from 'p-defer'
|
|
64
30
|
import { CustomProgressEvent } from 'progress-events'
|
|
65
31
|
import { raceSignal } from 'race-signal'
|
|
66
|
-
import { isBrowser, isWebWorker } from 'wherearewe'
|
|
67
32
|
import * as filters from './filters.js'
|
|
68
33
|
import { createListener } from './listener.js'
|
|
69
34
|
import { socketToMaConn } from './socket-to-conn.js'
|
|
70
|
-
import type { Transport, MultiaddrFilter, CreateListenerOptions, DialTransportOptions, Listener, AbortOptions, ComponentLogger, Logger, Connection, OutboundConnectionUpgradeEvents, Metrics, CounterGroup } from '@libp2p/interface'
|
|
35
|
+
import type { Transport, MultiaddrFilter, CreateListenerOptions, DialTransportOptions, Listener, AbortOptions, ComponentLogger, Logger, Connection, OutboundConnectionUpgradeEvents, Metrics, CounterGroup, TypedEventTarget, Libp2pEvents } from '@libp2p/interface'
|
|
71
36
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
72
|
-
import type { Server } from 'http'
|
|
73
37
|
import type { DuplexWebSocket } from 'it-ws/duplex'
|
|
38
|
+
import type http from 'node:http'
|
|
39
|
+
import type https from 'node:https'
|
|
74
40
|
import type { ProgressEvent } from 'progress-events'
|
|
75
41
|
import type { ClientOptions } from 'ws'
|
|
76
42
|
|
|
77
43
|
export interface WebSocketsInit extends AbortOptions, WebSocketOptions {
|
|
44
|
+
/**
|
|
45
|
+
* @deprecated Use a ConnectionGater instead
|
|
46
|
+
*/
|
|
78
47
|
filter?: MultiaddrFilter
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Options used to create WebSockets
|
|
51
|
+
*/
|
|
79
52
|
websocket?: ClientOptions
|
|
80
|
-
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Options used to create the HTTP server
|
|
56
|
+
*/
|
|
57
|
+
http?: http.ServerOptions
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Options used to create the HTTPs server. `options.http` will be used if
|
|
61
|
+
* unspecified.
|
|
62
|
+
*/
|
|
63
|
+
https?: https.ServerOptions
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Inbound connections must complete their upgrade within this many ms
|
|
67
|
+
*
|
|
68
|
+
* @default 5000
|
|
69
|
+
*/
|
|
70
|
+
inboundConnectionUpgradeTimeout?: number
|
|
81
71
|
}
|
|
82
72
|
|
|
83
73
|
export interface WebSocketsComponents {
|
|
84
74
|
logger: ComponentLogger
|
|
75
|
+
events: TypedEventTarget<Libp2pEvents>
|
|
85
76
|
metrics?: Metrics
|
|
86
77
|
}
|
|
87
78
|
|
|
@@ -95,12 +86,12 @@ export type WebSocketsDialEvents =
|
|
|
95
86
|
|
|
96
87
|
class WebSockets implements Transport<WebSocketsDialEvents> {
|
|
97
88
|
private readonly log: Logger
|
|
98
|
-
private readonly init
|
|
89
|
+
private readonly init: WebSocketsInit
|
|
99
90
|
private readonly logger: ComponentLogger
|
|
100
91
|
private readonly metrics?: WebSocketsMetrics
|
|
101
92
|
private readonly components: WebSocketsComponents
|
|
102
93
|
|
|
103
|
-
constructor (components: WebSocketsComponents, init
|
|
94
|
+
constructor (components: WebSocketsComponents, init: WebSocketsInit = {}) {
|
|
104
95
|
this.log = components.logger.forComponent('libp2p:websockets')
|
|
105
96
|
this.logger = components.logger
|
|
106
97
|
this.components = components
|
|
@@ -180,13 +171,14 @@ class WebSockets implements Transport<WebSocketsDialEvents> {
|
|
|
180
171
|
}
|
|
181
172
|
|
|
182
173
|
/**
|
|
183
|
-
* Creates a
|
|
174
|
+
* Creates a WebSockets listener. The provided `handler` function will be called
|
|
184
175
|
* anytime a new incoming Connection has been successfully upgraded via
|
|
185
176
|
* `upgrader.upgradeInbound`
|
|
186
177
|
*/
|
|
187
178
|
createListener (options: CreateListenerOptions): Listener {
|
|
188
179
|
return createListener({
|
|
189
180
|
logger: this.logger,
|
|
181
|
+
events: this.components.events,
|
|
190
182
|
metrics: this.components.metrics
|
|
191
183
|
}, {
|
|
192
184
|
...this.init,
|
|
@@ -195,7 +187,7 @@ class WebSockets implements Transport<WebSocketsDialEvents> {
|
|
|
195
187
|
}
|
|
196
188
|
|
|
197
189
|
/**
|
|
198
|
-
* Takes a list of `Multiaddr`s and returns only valid
|
|
190
|
+
* Takes a list of `Multiaddr`s and returns only valid WebSockets addresses.
|
|
199
191
|
* By default, in a browser environment only DNS+WSS multiaddr is accepted,
|
|
200
192
|
* while in a Node.js environment DNS+{WS, WSS} multiaddrs are accepted.
|
|
201
193
|
*/
|
|
@@ -206,11 +198,6 @@ class WebSockets implements Transport<WebSocketsDialEvents> {
|
|
|
206
198
|
return this.init?.filter(multiaddrs)
|
|
207
199
|
}
|
|
208
200
|
|
|
209
|
-
// Browser
|
|
210
|
-
if (isBrowser || isWebWorker) {
|
|
211
|
-
return filters.wss(multiaddrs)
|
|
212
|
-
}
|
|
213
|
-
|
|
214
201
|
return filters.all(multiaddrs)
|
|
215
202
|
}
|
|
216
203
|
|