@libp2p/webtransport 3.1.9 → 3.1.10-97ab31c0c
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 +0 -4
- package/dist/index.min.js +9 -9
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +18 -17
- package/dist/src/index.js.map +1 -1
- package/dist/src/stream.d.ts +2 -1
- package/dist/src/stream.d.ts.map +1 -1
- package/dist/src/stream.js +2 -3
- package/dist/src/stream.js.map +1 -1
- package/package.json +9 -25
- package/src/index.ts +34 -18
- package/src/stream.ts +3 -5
- package/dist/typedoc-urls.json +0 -10
package/dist/src/index.d.ts
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
* ```
|
|
22
22
|
*/
|
|
23
23
|
import { type Transport } from '@libp2p/interface/transport';
|
|
24
|
+
import type { ComponentLogger } from '@libp2p/interface';
|
|
24
25
|
import type { CounterGroup, Metrics } from '@libp2p/interface/metrics';
|
|
25
26
|
import type { PeerId } from '@libp2p/interface/peer-id';
|
|
26
27
|
export interface WebTransportInit {
|
|
@@ -29,6 +30,7 @@ export interface WebTransportInit {
|
|
|
29
30
|
export interface WebTransportComponents {
|
|
30
31
|
peerId: PeerId;
|
|
31
32
|
metrics?: Metrics;
|
|
33
|
+
logger: ComponentLogger;
|
|
32
34
|
}
|
|
33
35
|
export interface WebTransportMetrics {
|
|
34
36
|
dialerEvents: CounterGroup;
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAGH,OAAO,EAAE,KAAK,SAAS,EAAuE,MAAM,6BAA6B,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAGH,OAAO,EAAE,KAAK,SAAS,EAAuE,MAAM,6BAA6B,CAAA;AAOjI,OAAO,KAAK,EAAE,eAAe,EAAU,MAAM,mBAAmB,CAAA;AAEhE,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAA;AACtE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AASvD,MAAM,WAAW,gBAAgB;IAC/B,iBAAiB,CAAC,EAAE,MAAM,CAAA;CAC3B;AAED,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,MAAM,EAAE,eAAe,CAAA;CACxB;AAED,MAAM,WAAW,mBAAmB;IAClC,YAAY,EAAE,YAAY,CAAA;CAC3B;AAgUD,wBAAgB,YAAY,CAAE,IAAI,GAAE,gBAAqB,GAAG,CAAC,UAAU,EAAE,sBAAsB,KAAK,SAAS,CAE5G"}
|
package/dist/src/index.js
CHANGED
|
@@ -22,19 +22,19 @@
|
|
|
22
22
|
*/
|
|
23
23
|
import { noise } from '@chainsafe/libp2p-noise';
|
|
24
24
|
import { symbol } from '@libp2p/interface/transport';
|
|
25
|
-
import { logger } from '@libp2p/logger';
|
|
26
25
|
import {} from '@multiformats/multiaddr';
|
|
27
26
|
import { WebTransport as WebTransportMatcher } from '@multiformats/multiaddr-matcher';
|
|
28
27
|
import { webtransportBiDiStreamToStream } from './stream.js';
|
|
29
28
|
import { inertDuplex } from './utils/inert-duplex.js';
|
|
30
29
|
import { isSubset } from './utils/is-subset.js';
|
|
31
30
|
import { parseMultiaddr } from './utils/parse-multiaddr.js';
|
|
32
|
-
const log = logger('libp2p:webtransport');
|
|
33
31
|
class WebTransportTransport {
|
|
32
|
+
log;
|
|
34
33
|
components;
|
|
35
34
|
config;
|
|
36
35
|
metrics;
|
|
37
36
|
constructor(components, init = {}) {
|
|
37
|
+
this.log = components.logger.forComponent('libp2p:webtransport');
|
|
38
38
|
this.components = components;
|
|
39
39
|
this.config = {
|
|
40
40
|
maxInboundStreams: init.maxInboundStreams ?? 1000
|
|
@@ -52,7 +52,7 @@ class WebTransportTransport {
|
|
|
52
52
|
[symbol] = true;
|
|
53
53
|
async dial(ma, options) {
|
|
54
54
|
options?.signal?.throwIfAborted();
|
|
55
|
-
log('dialing %s', ma);
|
|
55
|
+
this.log('dialing %s', ma);
|
|
56
56
|
const localPeer = this.components.peerId;
|
|
57
57
|
if (localPeer === undefined) {
|
|
58
58
|
throw new Error('Need a local peerid');
|
|
@@ -89,7 +89,7 @@ class WebTransportTransport {
|
|
|
89
89
|
wt.close();
|
|
90
90
|
}
|
|
91
91
|
catch (err) {
|
|
92
|
-
log.error('error closing wt session', err);
|
|
92
|
+
this.log.error('error closing wt session', err);
|
|
93
93
|
}
|
|
94
94
|
finally {
|
|
95
95
|
// This is how we specify the connection is closed and shouldn't be used.
|
|
@@ -119,7 +119,7 @@ class WebTransportTransport {
|
|
|
119
119
|
this.metrics?.dialerEvents.increment({ ready: true });
|
|
120
120
|
// this promise resolves/throws when the session is closed
|
|
121
121
|
wt.closed.catch((err) => {
|
|
122
|
-
log.error('error on remote wt session close', err);
|
|
122
|
+
this.log.error('error on remote wt session close', err);
|
|
123
123
|
})
|
|
124
124
|
.finally(() => {
|
|
125
125
|
cleanUpWTSession('remote_close');
|
|
@@ -130,11 +130,11 @@ class WebTransportTransport {
|
|
|
130
130
|
this.metrics?.dialerEvents.increment({ open: true });
|
|
131
131
|
maConn = {
|
|
132
132
|
close: async () => {
|
|
133
|
-
log('Closing webtransport');
|
|
133
|
+
this.log('Closing webtransport');
|
|
134
134
|
cleanUpWTSession('close');
|
|
135
135
|
},
|
|
136
136
|
abort: (err) => {
|
|
137
|
-
log('aborting webtransport due to passed err', err);
|
|
137
|
+
this.log('aborting webtransport due to passed err', err);
|
|
138
138
|
cleanUpWTSession('abort');
|
|
139
139
|
},
|
|
140
140
|
remoteAddr: ma,
|
|
@@ -148,7 +148,7 @@ class WebTransportTransport {
|
|
|
148
148
|
return await options.upgrader.upgradeOutbound(maConn, { skipEncryption: true, muxerFactory: this.webtransportMuxer(wt), skipProtection: true });
|
|
149
149
|
}
|
|
150
150
|
catch (err) {
|
|
151
|
-
log.error('caught wt session err', err);
|
|
151
|
+
this.log.error('caught wt session err', err);
|
|
152
152
|
if (authenticated) {
|
|
153
153
|
cleanUpWTSession('upgrade_error');
|
|
154
154
|
}
|
|
@@ -193,10 +193,10 @@ class WebTransportTransport {
|
|
|
193
193
|
const { remoteExtensions } = await n.secureOutbound(localPeer, duplex, remotePeer);
|
|
194
194
|
// We're done with this authentication stream
|
|
195
195
|
writer.close().catch((err) => {
|
|
196
|
-
log.error(`Failed to close authentication stream writer: ${err.message}`);
|
|
196
|
+
this.log.error(`Failed to close authentication stream writer: ${err.message}`);
|
|
197
197
|
});
|
|
198
198
|
reader.cancel().catch((err) => {
|
|
199
|
-
log.error(`Failed to close authentication stream reader: ${err.message}`);
|
|
199
|
+
this.log.error(`Failed to close authentication stream reader: ${err.message}`);
|
|
200
200
|
});
|
|
201
201
|
// Verify the certhashes we used when dialing are a subset of the certhashes relayed by the remote peer
|
|
202
202
|
if (!isSubset(remoteExtensions?.webtransportCerthashes ?? [], certhashes.map(ch => ch.bytes))) {
|
|
@@ -207,6 +207,7 @@ class WebTransportTransport {
|
|
|
207
207
|
webtransportMuxer(wt) {
|
|
208
208
|
let streamIDCounter = 0;
|
|
209
209
|
const config = this.config;
|
|
210
|
+
const self = this;
|
|
210
211
|
return {
|
|
211
212
|
protocol: 'webtransport',
|
|
212
213
|
createStreamMuxer: (init) => {
|
|
@@ -227,27 +228,27 @@ class WebTransportTransport {
|
|
|
227
228
|
if (activeStreams.length >= config.maxInboundStreams) {
|
|
228
229
|
// We've reached our limit, close this stream.
|
|
229
230
|
wtStream.writable.close().catch((err) => {
|
|
230
|
-
log.error(`Failed to close inbound stream that crossed our maxInboundStream limit: ${err.message}`);
|
|
231
|
+
self.log.error(`Failed to close inbound stream that crossed our maxInboundStream limit: ${err.message}`);
|
|
231
232
|
});
|
|
232
233
|
wtStream.readable.cancel().catch((err) => {
|
|
233
|
-
log.error(`Failed to close inbound stream that crossed our maxInboundStream limit: ${err.message}`);
|
|
234
|
+
self.log.error(`Failed to close inbound stream that crossed our maxInboundStream limit: ${err.message}`);
|
|
234
235
|
});
|
|
235
236
|
}
|
|
236
237
|
else {
|
|
237
|
-
const stream = await webtransportBiDiStreamToStream(wtStream, String(streamIDCounter++), 'inbound', activeStreams, init?.onStreamEnd);
|
|
238
|
+
const stream = await webtransportBiDiStreamToStream(wtStream, String(streamIDCounter++), 'inbound', activeStreams, init?.onStreamEnd, self.components.logger);
|
|
238
239
|
activeStreams.push(stream);
|
|
239
240
|
init?.onIncomingStream?.(stream);
|
|
240
241
|
}
|
|
241
242
|
}
|
|
242
243
|
})().catch(() => {
|
|
243
|
-
log.error('WebTransport failed to receive incoming stream');
|
|
244
|
+
this.log.error('WebTransport failed to receive incoming stream');
|
|
244
245
|
});
|
|
245
246
|
const muxer = {
|
|
246
247
|
protocol: 'webtransport',
|
|
247
248
|
streams: activeStreams,
|
|
248
249
|
newStream: async (name) => {
|
|
249
250
|
const wtStream = await wt.createBidirectionalStream();
|
|
250
|
-
const stream = await webtransportBiDiStreamToStream(wtStream, String(streamIDCounter++), init?.direction ?? 'outbound', activeStreams, init?.onStreamEnd);
|
|
251
|
+
const stream = await webtransportBiDiStreamToStream(wtStream, String(streamIDCounter++), init?.direction ?? 'outbound', activeStreams, init?.onStreamEnd, self.components.logger);
|
|
251
252
|
activeStreams.push(stream);
|
|
252
253
|
return stream;
|
|
253
254
|
},
|
|
@@ -255,11 +256,11 @@ class WebTransportTransport {
|
|
|
255
256
|
* Close or abort all tracked streams and stop the muxer
|
|
256
257
|
*/
|
|
257
258
|
close: async (options) => {
|
|
258
|
-
log('Closing webtransport muxer');
|
|
259
|
+
this.log('Closing webtransport muxer');
|
|
259
260
|
await Promise.all(activeStreams.map(async (s) => s.close(options)));
|
|
260
261
|
},
|
|
261
262
|
abort: (err) => {
|
|
262
|
-
log('Aborting webtransport muxer with err:', err);
|
|
263
|
+
this.log('Aborting webtransport muxer with err:', err);
|
|
263
264
|
for (const stream of activeStreams) {
|
|
264
265
|
stream.abort(err);
|
|
265
266
|
}
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAC/C,OAAO,EAAkB,MAAM,EAA+D,MAAM,6BAA6B,CAAA;AACjI,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAC/C,OAAO,EAAkB,MAAM,EAA+D,MAAM,6BAA6B,CAAA;AACjI,OAAO,EAAqC,MAAM,yBAAyB,CAAA;AAC3E,OAAO,EAAE,YAAY,IAAI,mBAAmB,EAAE,MAAM,iCAAiC,CAAA;AACrF,OAAO,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAA;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AA2B3D,MAAM,qBAAqB;IACR,GAAG,CAAQ;IACX,UAAU,CAAwB;IAClC,MAAM,CAA4B;IAClC,OAAO,CAAsB;IAE9C,YAAa,UAAkC,EAAE,OAAyB,EAAE;QAC1E,IAAI,CAAC,GAAG,GAAG,UAAU,CAAC,MAAM,CAAC,YAAY,CAAC,qBAAqB,CAAC,CAAA;QAChE,IAAI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,IAAI,aAAa,EAAE;4BAClC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;yBAClB;oBACH,CAAC;oBACD,gGAAgG;oBAChG,GAAG,WAAW,EAAE;iBACjB,CAAA;gBAED,OAAO,KAAK,CAAA;YACd,CAAC;SACF,CAAA;IACH,CAAC;IAED,cAAc,CAAE,OAA8B;QAC5C,MAAM,IAAI,KAAK,CAAC,+DAA+D,CAAC,CAAA;IAClF,CAAC;IAED;;OAEG;IACH,MAAM,CAAE,UAAuB;QAC7B,OAAO,UAAU,CAAC,MAAM,CAAC,mBAAmB,CAAC,UAAU,CAAC,CAAA;IAC1D,CAAC;CACF;AAED,MAAM,UAAU,YAAY,CAAE,OAAyB,EAAE;IACvD,OAAO,CAAC,UAAkC,EAAE,EAAE,CAAC,IAAI,qBAAqB,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;AAC5F,CAAC"}
|
package/dist/src/stream.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ComponentLogger } from '@libp2p/interface';
|
|
1
2
|
import type { Direction, Stream } from '@libp2p/interface/connection';
|
|
2
|
-
export declare function webtransportBiDiStreamToStream(bidiStream: WebTransportBidirectionalStream, streamId: string, direction: Direction, activeStreams: Stream[], onStreamEnd: undefined | ((s: Stream) => void)): Promise<Stream>;
|
|
3
|
+
export declare function webtransportBiDiStreamToStream(bidiStream: WebTransportBidirectionalStream, streamId: string, direction: Direction, activeStreams: Stream[], onStreamEnd: undefined | ((s: Stream) => void), logger: ComponentLogger): Promise<Stream>;
|
|
3
4
|
//# sourceMappingURL=stream.d.ts.map
|
package/dist/src/stream.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../src/stream.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../src/stream.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAgB,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACtE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAA;AAGrE,wBAAsB,8BAA8B,CAAE,UAAU,EAAE,+BAA+B,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,EAAE,EAAE,WAAW,EAAE,SAAS,GAAG,CAAC,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC,EAAE,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,CAkL5P"}
|
package/dist/src/stream.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { logger } from '@libp2p/logger';
|
|
2
1
|
import { Uint8ArrayList } from 'uint8arraylist';
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
export async function webtransportBiDiStreamToStream(bidiStream, streamId, direction, activeStreams, onStreamEnd, logger) {
|
|
3
|
+
const log = logger.forComponent('libp2p:webtransport:stream');
|
|
5
4
|
const writer = bidiStream.writable.getWriter();
|
|
6
5
|
const reader = bidiStream.readable.getReader();
|
|
7
6
|
await writer.ready;
|
package/dist/src/stream.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAK/C,MAAM,CAAC,KAAK,UAAU,8BAA8B,CAAE,UAA2C,EAAE,QAAgB,EAAE,SAAoB,EAAE,aAAuB,EAAE,WAA8C,EAAE,MAAuB;IACzO,MAAM,GAAG,GAAG,MAAM,CAAC,YAAY,CAAC,4BAA4B,CAAC,CAAA;IAC7D,MAAM,MAAM,GAAG,UAAU,CAAC,QAAQ,CAAC,SAAS,EAAE,C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ACxB;qBACF;iBACF;gBAED,IAAI,CAAC,WAAW,GAAG,MAAM,CAAA;aAC1B;oBAAS;gBACR,IAAI,CAAC,QAAQ,CAAC,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;gBACrC,IAAI,CAAC,WAAW,GAAG,QAAQ,CAAA;gBAE3B,MAAM,MAAM,CAAC,UAAU,EAAE,CAAA;aAC1B;QACH,CAAC;KACF,CAAA;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/webtransport",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.10-97ab31c0c",
|
|
4
4
|
"description": "JavaScript implementation of the WebTransport 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/master/packages/transport-webtransport#readme",
|
|
@@ -16,22 +16,6 @@
|
|
|
16
16
|
],
|
|
17
17
|
"type": "module",
|
|
18
18
|
"types": "./dist/src/index.d.ts",
|
|
19
|
-
"typesVersions": {
|
|
20
|
-
"*": {
|
|
21
|
-
"*": [
|
|
22
|
-
"*",
|
|
23
|
-
"dist/*",
|
|
24
|
-
"dist/src/*",
|
|
25
|
-
"dist/src/*/index"
|
|
26
|
-
],
|
|
27
|
-
"src/*": [
|
|
28
|
-
"*",
|
|
29
|
-
"dist/*",
|
|
30
|
-
"dist/src/*",
|
|
31
|
-
"dist/src/*/index"
|
|
32
|
-
]
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
19
|
"files": [
|
|
36
20
|
"src",
|
|
37
21
|
"dist",
|
|
@@ -62,20 +46,20 @@
|
|
|
62
46
|
},
|
|
63
47
|
"dependencies": {
|
|
64
48
|
"@chainsafe/libp2p-noise": "^13.0.0",
|
|
65
|
-
"@libp2p/interface": "
|
|
66
|
-
"@libp2p/
|
|
67
|
-
"@
|
|
68
|
-
"@multiformats/multiaddr": "^
|
|
69
|
-
"@multiformats/multiaddr-matcher": "^1.0.1",
|
|
49
|
+
"@libp2p/interface": "0.1.6-97ab31c0c",
|
|
50
|
+
"@libp2p/peer-id": "3.0.6-97ab31c0c",
|
|
51
|
+
"@multiformats/multiaddr": "^12.1.10",
|
|
52
|
+
"@multiformats/multiaddr-matcher": "^1.1.0",
|
|
70
53
|
"it-stream-types": "^2.0.1",
|
|
71
|
-
"multiformats": "^12.
|
|
54
|
+
"multiformats": "^12.1.3",
|
|
72
55
|
"uint8arraylist": "^2.4.3",
|
|
73
56
|
"uint8arrays": "^4.0.6"
|
|
74
57
|
},
|
|
75
58
|
"devDependencies": {
|
|
76
|
-
"@libp2p/
|
|
59
|
+
"@libp2p/logger": "3.1.0-97ab31c0c",
|
|
60
|
+
"@libp2p/peer-id-factory": "3.0.8-97ab31c0c",
|
|
77
61
|
"aegir": "^41.0.2",
|
|
78
|
-
"libp2p": "
|
|
62
|
+
"libp2p": "0.46.21-97ab31c0c",
|
|
79
63
|
"p-defer": "^4.0.0"
|
|
80
64
|
},
|
|
81
65
|
"browser": {
|
package/src/index.ts
CHANGED
|
@@ -23,13 +23,13 @@
|
|
|
23
23
|
|
|
24
24
|
import { noise } from '@chainsafe/libp2p-noise'
|
|
25
25
|
import { type Transport, symbol, type CreateListenerOptions, type DialOptions, type Listener } from '@libp2p/interface/transport'
|
|
26
|
-
import { logger } from '@libp2p/logger'
|
|
27
26
|
import { type Multiaddr, type AbortOptions } from '@multiformats/multiaddr'
|
|
28
27
|
import { WebTransport as WebTransportMatcher } from '@multiformats/multiaddr-matcher'
|
|
29
28
|
import { webtransportBiDiStreamToStream } from './stream.js'
|
|
30
29
|
import { inertDuplex } from './utils/inert-duplex.js'
|
|
31
30
|
import { isSubset } from './utils/is-subset.js'
|
|
32
31
|
import { parseMultiaddr } from './utils/parse-multiaddr.js'
|
|
32
|
+
import type { ComponentLogger, Logger } from '@libp2p/interface'
|
|
33
33
|
import type { Connection, MultiaddrConnection, Stream } from '@libp2p/interface/connection'
|
|
34
34
|
import type { CounterGroup, Metrics } from '@libp2p/interface/metrics'
|
|
35
35
|
import type { PeerId } from '@libp2p/interface/peer-id'
|
|
@@ -41,8 +41,6 @@ interface WebTransportSessionCleanup {
|
|
|
41
41
|
(metric: string): void
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
const log = logger('libp2p:webtransport')
|
|
45
|
-
|
|
46
44
|
export interface WebTransportInit {
|
|
47
45
|
maxInboundStreams?: number
|
|
48
46
|
}
|
|
@@ -50,6 +48,7 @@ export interface WebTransportInit {
|
|
|
50
48
|
export interface WebTransportComponents {
|
|
51
49
|
peerId: PeerId
|
|
52
50
|
metrics?: Metrics
|
|
51
|
+
logger: ComponentLogger
|
|
53
52
|
}
|
|
54
53
|
|
|
55
54
|
export interface WebTransportMetrics {
|
|
@@ -57,11 +56,13 @@ export interface WebTransportMetrics {
|
|
|
57
56
|
}
|
|
58
57
|
|
|
59
58
|
class WebTransportTransport implements Transport {
|
|
59
|
+
private readonly log: Logger
|
|
60
60
|
private readonly components: WebTransportComponents
|
|
61
61
|
private readonly config: Required<WebTransportInit>
|
|
62
62
|
private readonly metrics?: WebTransportMetrics
|
|
63
63
|
|
|
64
64
|
constructor (components: WebTransportComponents, init: WebTransportInit = {}) {
|
|
65
|
+
this.log = components.logger.forComponent('libp2p:webtransport')
|
|
65
66
|
this.components = components
|
|
66
67
|
this.config = {
|
|
67
68
|
maxInboundStreams: init.maxInboundStreams ?? 1000
|
|
@@ -84,7 +85,7 @@ class WebTransportTransport implements Transport {
|
|
|
84
85
|
async dial (ma: Multiaddr, options: DialOptions): Promise<Connection> {
|
|
85
86
|
options?.signal?.throwIfAborted()
|
|
86
87
|
|
|
87
|
-
log('dialing %s', ma)
|
|
88
|
+
this.log('dialing %s', ma)
|
|
88
89
|
const localPeer = this.components.peerId
|
|
89
90
|
if (localPeer === undefined) {
|
|
90
91
|
throw new Error('Need a local peerid')
|
|
@@ -131,7 +132,7 @@ class WebTransportTransport implements Transport {
|
|
|
131
132
|
this.metrics?.dialerEvents.increment({ [metric]: true })
|
|
132
133
|
wt.close()
|
|
133
134
|
} catch (err) {
|
|
134
|
-
log.error('error closing wt session', err)
|
|
135
|
+
this.log.error('error closing wt session', err)
|
|
135
136
|
} finally {
|
|
136
137
|
// This is how we specify the connection is closed and shouldn't be used.
|
|
137
138
|
if (maConn != null) {
|
|
@@ -164,7 +165,7 @@ class WebTransportTransport implements Transport {
|
|
|
164
165
|
|
|
165
166
|
// this promise resolves/throws when the session is closed
|
|
166
167
|
wt.closed.catch((err: Error) => {
|
|
167
|
-
log.error('error on remote wt session close', err)
|
|
168
|
+
this.log.error('error on remote wt session close', err)
|
|
168
169
|
})
|
|
169
170
|
.finally(() => {
|
|
170
171
|
cleanUpWTSession('remote_close')
|
|
@@ -178,11 +179,11 @@ class WebTransportTransport implements Transport {
|
|
|
178
179
|
|
|
179
180
|
maConn = {
|
|
180
181
|
close: async () => {
|
|
181
|
-
log('Closing webtransport')
|
|
182
|
+
this.log('Closing webtransport')
|
|
182
183
|
cleanUpWTSession('close')
|
|
183
184
|
},
|
|
184
185
|
abort: (err: Error) => {
|
|
185
|
-
log('aborting webtransport due to passed err', err)
|
|
186
|
+
this.log('aborting webtransport due to passed err', err)
|
|
186
187
|
cleanUpWTSession('abort')
|
|
187
188
|
},
|
|
188
189
|
remoteAddr: ma,
|
|
@@ -197,7 +198,7 @@ class WebTransportTransport implements Transport {
|
|
|
197
198
|
|
|
198
199
|
return await options.upgrader.upgradeOutbound(maConn, { skipEncryption: true, muxerFactory: this.webtransportMuxer(wt), skipProtection: true })
|
|
199
200
|
} catch (err: any) {
|
|
200
|
-
log.error('caught wt session err', err)
|
|
201
|
+
this.log.error('caught wt session err', err)
|
|
201
202
|
|
|
202
203
|
if (authenticated) {
|
|
203
204
|
cleanUpWTSession('upgrade_error')
|
|
@@ -248,11 +249,11 @@ class WebTransportTransport implements Transport {
|
|
|
248
249
|
|
|
249
250
|
// We're done with this authentication stream
|
|
250
251
|
writer.close().catch((err: Error) => {
|
|
251
|
-
log.error(`Failed to close authentication stream writer: ${err.message}`)
|
|
252
|
+
this.log.error(`Failed to close authentication stream writer: ${err.message}`)
|
|
252
253
|
})
|
|
253
254
|
|
|
254
255
|
reader.cancel().catch((err: Error) => {
|
|
255
|
-
log.error(`Failed to close authentication stream reader: ${err.message}`)
|
|
256
|
+
this.log.error(`Failed to close authentication stream reader: ${err.message}`)
|
|
256
257
|
})
|
|
257
258
|
|
|
258
259
|
// Verify the certhashes we used when dialing are a subset of the certhashes relayed by the remote peer
|
|
@@ -266,6 +267,7 @@ class WebTransportTransport implements Transport {
|
|
|
266
267
|
webtransportMuxer (wt: WebTransport): StreamMuxerFactory {
|
|
267
268
|
let streamIDCounter = 0
|
|
268
269
|
const config = this.config
|
|
270
|
+
const self = this
|
|
269
271
|
return {
|
|
270
272
|
protocol: 'webtransport',
|
|
271
273
|
createStreamMuxer: (init?: StreamMuxerInit): StreamMuxer => {
|
|
@@ -292,19 +294,26 @@ class WebTransportTransport implements Transport {
|
|
|
292
294
|
if (activeStreams.length >= config.maxInboundStreams) {
|
|
293
295
|
// We've reached our limit, close this stream.
|
|
294
296
|
wtStream.writable.close().catch((err: Error) => {
|
|
295
|
-
log.error(`Failed to close inbound stream that crossed our maxInboundStream limit: ${err.message}`)
|
|
297
|
+
self.log.error(`Failed to close inbound stream that crossed our maxInboundStream limit: ${err.message}`)
|
|
296
298
|
})
|
|
297
299
|
wtStream.readable.cancel().catch((err: Error) => {
|
|
298
|
-
log.error(`Failed to close inbound stream that crossed our maxInboundStream limit: ${err.message}`)
|
|
300
|
+
self.log.error(`Failed to close inbound stream that crossed our maxInboundStream limit: ${err.message}`)
|
|
299
301
|
})
|
|
300
302
|
} else {
|
|
301
|
-
const stream = await webtransportBiDiStreamToStream(
|
|
303
|
+
const stream = await webtransportBiDiStreamToStream(
|
|
304
|
+
wtStream,
|
|
305
|
+
String(streamIDCounter++),
|
|
306
|
+
'inbound',
|
|
307
|
+
activeStreams,
|
|
308
|
+
init?.onStreamEnd,
|
|
309
|
+
self.components.logger
|
|
310
|
+
)
|
|
302
311
|
activeStreams.push(stream)
|
|
303
312
|
init?.onIncomingStream?.(stream)
|
|
304
313
|
}
|
|
305
314
|
}
|
|
306
315
|
})().catch(() => {
|
|
307
|
-
log.error('WebTransport failed to receive incoming stream')
|
|
316
|
+
this.log.error('WebTransport failed to receive incoming stream')
|
|
308
317
|
})
|
|
309
318
|
|
|
310
319
|
const muxer: StreamMuxer = {
|
|
@@ -313,7 +322,14 @@ class WebTransportTransport implements Transport {
|
|
|
313
322
|
newStream: async (name?: string): Promise<Stream> => {
|
|
314
323
|
const wtStream = await wt.createBidirectionalStream()
|
|
315
324
|
|
|
316
|
-
const stream = await webtransportBiDiStreamToStream(
|
|
325
|
+
const stream = await webtransportBiDiStreamToStream(
|
|
326
|
+
wtStream,
|
|
327
|
+
String(streamIDCounter++),
|
|
328
|
+
init?.direction ?? 'outbound',
|
|
329
|
+
activeStreams,
|
|
330
|
+
init?.onStreamEnd,
|
|
331
|
+
self.components.logger
|
|
332
|
+
)
|
|
317
333
|
activeStreams.push(stream)
|
|
318
334
|
|
|
319
335
|
return stream
|
|
@@ -323,14 +339,14 @@ class WebTransportTransport implements Transport {
|
|
|
323
339
|
* Close or abort all tracked streams and stop the muxer
|
|
324
340
|
*/
|
|
325
341
|
close: async (options?: AbortOptions) => {
|
|
326
|
-
log('Closing webtransport muxer')
|
|
342
|
+
this.log('Closing webtransport muxer')
|
|
327
343
|
|
|
328
344
|
await Promise.all(
|
|
329
345
|
activeStreams.map(async s => s.close(options))
|
|
330
346
|
)
|
|
331
347
|
},
|
|
332
348
|
abort: (err: Error) => {
|
|
333
|
-
log('Aborting webtransport muxer with err:', err)
|
|
349
|
+
this.log('Aborting webtransport muxer with err:', err)
|
|
334
350
|
|
|
335
351
|
for (const stream of activeStreams) {
|
|
336
352
|
stream.abort(err)
|
package/src/stream.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import { logger } from '@libp2p/logger'
|
|
2
1
|
import { Uint8ArrayList } from 'uint8arraylist'
|
|
3
|
-
import type { AbortOptions } from '@libp2p/interface'
|
|
2
|
+
import type { AbortOptions, ComponentLogger } from '@libp2p/interface'
|
|
4
3
|
import type { Direction, Stream } from '@libp2p/interface/connection'
|
|
5
4
|
import type { Source } from 'it-stream-types'
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export async function webtransportBiDiStreamToStream (bidiStream: WebTransportBidirectionalStream, streamId: string, direction: Direction, activeStreams: Stream[], onStreamEnd: undefined | ((s: Stream) => void)): Promise<Stream> {
|
|
6
|
+
export async function webtransportBiDiStreamToStream (bidiStream: WebTransportBidirectionalStream, streamId: string, direction: Direction, activeStreams: Stream[], onStreamEnd: undefined | ((s: Stream) => void), logger: ComponentLogger): Promise<Stream> {
|
|
7
|
+
const log = logger.forComponent('libp2p:webtransport:stream')
|
|
10
8
|
const writer = bidiStream.writable.getWriter()
|
|
11
9
|
const reader = bidiStream.readable.getReader()
|
|
12
10
|
await writer.ready
|
package/dist/typedoc-urls.json
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"WebTransportComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_webtransport.WebTransportComponents.html",
|
|
3
|
-
".:WebTransportComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_webtransport.WebTransportComponents.html",
|
|
4
|
-
"WebTransportInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_webtransport.WebTransportInit.html",
|
|
5
|
-
".:WebTransportInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_webtransport.WebTransportInit.html",
|
|
6
|
-
"WebTransportMetrics": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_webtransport.WebTransportMetrics.html",
|
|
7
|
-
".:WebTransportMetrics": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_webtransport.WebTransportMetrics.html",
|
|
8
|
-
"webTransport": "https://libp2p.github.io/js-libp2p/functions/_libp2p_webtransport.webTransport.html",
|
|
9
|
-
".:webTransport": "https://libp2p.github.io/js-libp2p/functions/_libp2p_webtransport.webTransport.html"
|
|
10
|
-
}
|