@libp2p/webtransport 4.1.0 → 4.1.1
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 +3 -3
- package/dist/src/index.d.ts +3 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +14 -6
- package/dist/src/index.js.map +1 -1
- package/dist/src/webtransport.browser.d.ts +5 -1
- package/dist/src/webtransport.browser.d.ts.map +1 -1
- package/dist/src/webtransport.browser.js +3 -1
- package/dist/src/webtransport.browser.js.map +1 -1
- package/dist/typedoc-urls.json +2 -0
- package/package.json +9 -8
- package/src/index.ts +33 -9
- package/src/webtransport.browser.ts +3 -1
package/dist/src/index.d.ts
CHANGED
|
@@ -28,8 +28,9 @@
|
|
|
28
28
|
* })
|
|
29
29
|
* ```
|
|
30
30
|
*/
|
|
31
|
-
import type { Transport, ComponentLogger, CounterGroup, Metrics, PeerId } from '@libp2p/interface';
|
|
31
|
+
import type { Transport, ComponentLogger, CounterGroup, Metrics, PeerId, OutboundConnectionUpgradeEvents } from '@libp2p/interface';
|
|
32
32
|
import type { MultihashDigest } from 'multiformats/hashes/interface';
|
|
33
|
+
import type { ProgressEvent } from 'progress-events';
|
|
33
34
|
/**
|
|
34
35
|
* PEM format server certificate and private key
|
|
35
36
|
*/
|
|
@@ -51,5 +52,6 @@ export interface WebTransportComponents {
|
|
|
51
52
|
export interface WebTransportMetrics {
|
|
52
53
|
dialerEvents: CounterGroup;
|
|
53
54
|
}
|
|
55
|
+
export type WebTransportDialEvents = OutboundConnectionUpgradeEvents | ProgressEvent<'webtransport:wait-for-session'> | ProgressEvent<'webtransport:open-authentication-stream'> | ProgressEvent<'webtransport:secure-outbound-connection'> | ProgressEvent<'webtransport:close-authentication-stream'>;
|
|
54
56
|
export declare function webTransport(init?: WebTransportInit): (components: WebTransportComponents) => Transport;
|
|
55
57
|
//# sourceMappingURL=index.d.ts.map
|
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAaH,OAAO,KAAK,EAAE,SAAS,EAAgD,eAAe,EAA2C,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,+BAA+B,EAAE,MAAM,mBAAmB,CAAA;AAG1N,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AACpE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAGpD;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,UAAU,EAAE,MAAM,CAAA;IAClB,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,eAAe,CAAC,MAAM,CAAC,CAAA;IAC7B,MAAM,EAAE,MAAM,CAAA;CACf;AAMD,MAAM,WAAW,gBAAgB;IAC/B,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,YAAY,CAAC,EAAE,uBAAuB,EAAE,CAAA;CACzC;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;AAED,MAAM,MAAM,sBAAsB,GAChC,+BAA+B,GAC/B,aAAa,CAAC,+BAA+B,CAAC,GAC9C,aAAa,CAAC,yCAAyC,CAAC,GACxD,aAAa,CAAC,yCAAyC,CAAC,GACxD,aAAa,CAAC,0CAA0C,CAAC,CAAA;AA8Q3D,wBAAgB,YAAY,CAAE,IAAI,GAAE,gBAAqB,GAAG,CAAC,UAAU,EAAE,sBAAsB,KAAK,SAAS,CAE5G"}
|
package/dist/src/index.js
CHANGED
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
import { noise } from '@chainsafe/libp2p-noise';
|
|
32
32
|
import { AbortError, CodeError, serviceCapabilities, transportSymbol } from '@libp2p/interface';
|
|
33
33
|
import { WebTransport as WebTransportMatcher } from '@multiformats/multiaddr-matcher';
|
|
34
|
+
import { CustomProgressEvent } from 'progress-events';
|
|
34
35
|
import { raceSignal } from 'race-signal';
|
|
35
36
|
import createListener from './listener.js';
|
|
36
37
|
import { webtransportMuxer } from './muxer.js';
|
|
@@ -123,6 +124,7 @@ class WebTransportTransport {
|
|
|
123
124
|
once: true
|
|
124
125
|
});
|
|
125
126
|
this.log('wait for session to be ready');
|
|
127
|
+
options.onProgress?.(new CustomProgressEvent('webtransport:wait-for-session'));
|
|
126
128
|
await Promise.race([
|
|
127
129
|
wt.closed,
|
|
128
130
|
wt.ready
|
|
@@ -137,7 +139,7 @@ class WebTransportTransport {
|
|
|
137
139
|
.finally(() => {
|
|
138
140
|
cleanUpWTSession('remote_close');
|
|
139
141
|
});
|
|
140
|
-
authenticated = await raceSignal(this.authenticateWebTransport(wt, localPeer, remotePeer, certhashes), options.signal);
|
|
142
|
+
authenticated = await raceSignal(this.authenticateWebTransport({ wt, localPeer, remotePeer, certhashes, ...options }), options.signal);
|
|
141
143
|
if (!authenticated) {
|
|
142
144
|
throw new CodeError('Failed to authenticate webtransport', 'ERR_AUTHENTICATION_FAILED');
|
|
143
145
|
}
|
|
@@ -162,7 +164,8 @@ class WebTransportTransport {
|
|
|
162
164
|
return await options.upgrader.upgradeOutbound(maConn, {
|
|
163
165
|
skipEncryption: true,
|
|
164
166
|
muxerFactory: webtransportMuxer(wt, wt.incomingBidirectionalStreams.getReader(), this.components.logger, this.config),
|
|
165
|
-
skipProtection: true
|
|
167
|
+
skipProtection: true,
|
|
168
|
+
onProgress: options.onProgress
|
|
166
169
|
});
|
|
167
170
|
}
|
|
168
171
|
catch (err) {
|
|
@@ -184,10 +187,9 @@ class WebTransportTransport {
|
|
|
184
187
|
}
|
|
185
188
|
}
|
|
186
189
|
}
|
|
187
|
-
async authenticateWebTransport(wt, localPeer, remotePeer, certhashes
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
}
|
|
190
|
+
async authenticateWebTransport({ wt, localPeer, remotePeer, certhashes, onProgress, signal }) {
|
|
191
|
+
signal?.throwIfAborted();
|
|
192
|
+
onProgress?.(new CustomProgressEvent('webtransport:open-authentication-stream'));
|
|
191
193
|
const stream = await wt.createBidirectionalStream();
|
|
192
194
|
const writer = stream.writable.getWriter();
|
|
193
195
|
const reader = stream.readable.getReader();
|
|
@@ -214,7 +216,9 @@ class WebTransportTransport {
|
|
|
214
216
|
}
|
|
215
217
|
};
|
|
216
218
|
const n = noise()(this.components);
|
|
219
|
+
onProgress?.(new CustomProgressEvent('webtransport:secure-outbound-connection'));
|
|
217
220
|
const { remoteExtensions } = await n.secureOutbound(localPeer, duplex, remotePeer);
|
|
221
|
+
onProgress?.(new CustomProgressEvent('webtransport:close-authentication-stream'));
|
|
218
222
|
// We're done with this authentication stream
|
|
219
223
|
writer.close().catch((err) => {
|
|
220
224
|
this.log.error(`Failed to close authentication stream writer: ${err.message}`);
|
|
@@ -245,6 +249,10 @@ class WebTransportTransport {
|
|
|
245
249
|
* Filter check for all Multiaddrs that this transport can dial
|
|
246
250
|
*/
|
|
247
251
|
dialFilter(multiaddrs) {
|
|
252
|
+
// test for WebTransport support
|
|
253
|
+
if (globalThis.WebTransport == null) {
|
|
254
|
+
return [];
|
|
255
|
+
}
|
|
248
256
|
return multiaddrs.filter(ma => {
|
|
249
257
|
if (!WebTransportMatcher.exactMatch(ma)) {
|
|
250
258
|
return false;
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webtransport.browser.d.ts","sourceRoot":"","sources":["../../src/webtransport.browser.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"webtransport.browser.d.ts","sourceRoot":"","sources":["../../src/webtransport.browser.ts"],"names":[],"mappings":";;;;AAEA,wBAAsC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webtransport.browser.js","sourceRoot":"","sources":["../../src/webtransport.browser.ts"],"names":[],"mappings":"AAAA,eAAe,YAAY,CAAA"}
|
|
1
|
+
{"version":3,"file":"webtransport.browser.js","sourceRoot":"","sources":["../../src/webtransport.browser.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,+BAA+B;AAC/B,eAAe,UAAU,CAAC,YAAY,CAAA"}
|
package/dist/typedoc-urls.json
CHANGED
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
".:WebTransportInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_webtransport.WebTransportInit.html",
|
|
8
8
|
"WebTransportMetrics": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_webtransport.WebTransportMetrics.html",
|
|
9
9
|
".:WebTransportMetrics": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_webtransport.WebTransportMetrics.html",
|
|
10
|
+
"WebTransportDialEvents": "https://libp2p.github.io/js-libp2p/types/_libp2p_webtransport.WebTransportDialEvents.html",
|
|
11
|
+
".:WebTransportDialEvents": "https://libp2p.github.io/js-libp2p/types/_libp2p_webtransport.WebTransportDialEvents.html",
|
|
10
12
|
"webTransport": "https://libp2p.github.io/js-libp2p/functions/_libp2p_webtransport.webTransport.html",
|
|
11
13
|
".:webTransport": "https://libp2p.github.io/js-libp2p/functions/_libp2p_webtransport.webTransport.html"
|
|
12
14
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/webtransport",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.1",
|
|
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/main/packages/transport-webtransport#readme",
|
|
@@ -51,29 +51,30 @@
|
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"@chainsafe/libp2p-noise": "^15.0.0",
|
|
54
|
-
"@libp2p/interface": "^1.
|
|
55
|
-
"@libp2p/peer-id": "^4.
|
|
56
|
-
"@libp2p/utils": "^5.4.
|
|
54
|
+
"@libp2p/interface": "^1.6.0",
|
|
55
|
+
"@libp2p/peer-id": "^4.2.0",
|
|
56
|
+
"@libp2p/utils": "^5.4.5",
|
|
57
57
|
"@multiformats/multiaddr": "^12.2.3",
|
|
58
58
|
"@multiformats/multiaddr-matcher": "^1.2.1",
|
|
59
59
|
"it-stream-types": "^2.0.1",
|
|
60
60
|
"multiformats": "^13.1.0",
|
|
61
|
+
"progress-events": "^1.0.0",
|
|
61
62
|
"race-signal": "^1.0.2",
|
|
62
63
|
"uint8arraylist": "^2.4.8",
|
|
63
64
|
"uint8arrays": "^5.1.0"
|
|
64
65
|
},
|
|
65
66
|
"devDependencies": {
|
|
66
67
|
"@libp2p/daemon-client": "^8.0.5",
|
|
67
|
-
"@libp2p/logger": "^4.0.
|
|
68
|
-
"@libp2p/peer-id-factory": "^4.
|
|
69
|
-
"@libp2p/ping": "^1.1.
|
|
68
|
+
"@libp2p/logger": "^4.0.16",
|
|
69
|
+
"@libp2p/peer-id-factory": "^4.2.0",
|
|
70
|
+
"@libp2p/ping": "^1.1.1",
|
|
70
71
|
"@noble/hashes": "^1.4.0",
|
|
71
72
|
"aegir": "^43.0.1",
|
|
72
73
|
"execa": "^9.1.0",
|
|
73
74
|
"go-libp2p": "^1.2.0",
|
|
74
75
|
"it-map": "^3.1.0",
|
|
75
76
|
"it-to-buffer": "^4.0.7",
|
|
76
|
-
"libp2p": "^1.
|
|
77
|
+
"libp2p": "^1.8.0",
|
|
77
78
|
"p-defer": "^4.0.1",
|
|
78
79
|
"p-wait-for": "^5.0.2"
|
|
79
80
|
},
|
package/src/index.ts
CHANGED
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
import { noise } from '@chainsafe/libp2p-noise'
|
|
33
33
|
import { AbortError, CodeError, serviceCapabilities, transportSymbol } from '@libp2p/interface'
|
|
34
34
|
import { WebTransport as WebTransportMatcher } from '@multiformats/multiaddr-matcher'
|
|
35
|
+
import { CustomProgressEvent } from 'progress-events'
|
|
35
36
|
import { raceSignal } from 'race-signal'
|
|
36
37
|
import createListener from './listener.js'
|
|
37
38
|
import { webtransportMuxer } from './muxer.js'
|
|
@@ -39,10 +40,11 @@ import { inertDuplex } from './utils/inert-duplex.js'
|
|
|
39
40
|
import { isSubset } from './utils/is-subset.js'
|
|
40
41
|
import { parseMultiaddr } from './utils/parse-multiaddr.js'
|
|
41
42
|
import WebTransport from './webtransport.js'
|
|
42
|
-
import type { Transport, CreateListenerOptions, DialOptions, Listener, ComponentLogger, Logger, Connection, MultiaddrConnection, CounterGroup, Metrics, PeerId } from '@libp2p/interface'
|
|
43
|
+
import type { Transport, CreateListenerOptions, DialOptions, Listener, ComponentLogger, Logger, Connection, MultiaddrConnection, CounterGroup, Metrics, PeerId, OutboundConnectionUpgradeEvents } from '@libp2p/interface'
|
|
43
44
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
44
45
|
import type { Source } from 'it-stream-types'
|
|
45
46
|
import type { MultihashDigest } from 'multiformats/hashes/interface'
|
|
47
|
+
import type { ProgressEvent } from 'progress-events'
|
|
46
48
|
import type { Uint8ArrayList } from 'uint8arraylist'
|
|
47
49
|
|
|
48
50
|
/**
|
|
@@ -74,7 +76,21 @@ export interface WebTransportMetrics {
|
|
|
74
76
|
dialerEvents: CounterGroup
|
|
75
77
|
}
|
|
76
78
|
|
|
77
|
-
|
|
79
|
+
export type WebTransportDialEvents =
|
|
80
|
+
OutboundConnectionUpgradeEvents |
|
|
81
|
+
ProgressEvent<'webtransport:wait-for-session'> |
|
|
82
|
+
ProgressEvent<'webtransport:open-authentication-stream'> |
|
|
83
|
+
ProgressEvent<'webtransport:secure-outbound-connection'> |
|
|
84
|
+
ProgressEvent<'webtransport:close-authentication-stream'>
|
|
85
|
+
|
|
86
|
+
interface AuthenticateWebTransportOptions extends DialOptions<WebTransportDialEvents> {
|
|
87
|
+
wt: WebTransport
|
|
88
|
+
localPeer: PeerId
|
|
89
|
+
remotePeer?: PeerId
|
|
90
|
+
certhashes: Array<MultihashDigest<number>>
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
class WebTransportTransport implements Transport<WebTransportDialEvents> {
|
|
78
94
|
private readonly log: Logger
|
|
79
95
|
private readonly components: WebTransportComponents
|
|
80
96
|
private readonly config: Required<WebTransportInit>
|
|
@@ -107,7 +123,7 @@ class WebTransportTransport implements Transport {
|
|
|
107
123
|
'@libp2p/transport'
|
|
108
124
|
]
|
|
109
125
|
|
|
110
|
-
async dial (ma: Multiaddr, options: DialOptions): Promise<Connection> {
|
|
126
|
+
async dial (ma: Multiaddr, options: DialOptions<WebTransportDialEvents>): Promise<Connection> {
|
|
111
127
|
if (options?.signal?.aborted === true) {
|
|
112
128
|
throw new AbortError()
|
|
113
129
|
}
|
|
@@ -172,6 +188,7 @@ class WebTransportTransport implements Transport {
|
|
|
172
188
|
})
|
|
173
189
|
|
|
174
190
|
this.log('wait for session to be ready')
|
|
191
|
+
options.onProgress?.(new CustomProgressEvent('webtransport:wait-for-session'))
|
|
175
192
|
await Promise.race([
|
|
176
193
|
wt.closed,
|
|
177
194
|
wt.ready
|
|
@@ -189,7 +206,7 @@ class WebTransportTransport implements Transport {
|
|
|
189
206
|
cleanUpWTSession('remote_close')
|
|
190
207
|
})
|
|
191
208
|
|
|
192
|
-
authenticated = await raceSignal(this.authenticateWebTransport(wt, localPeer, remotePeer, certhashes), options.signal)
|
|
209
|
+
authenticated = await raceSignal(this.authenticateWebTransport({ wt, localPeer, remotePeer, certhashes, ...options }), options.signal)
|
|
193
210
|
|
|
194
211
|
if (!authenticated) {
|
|
195
212
|
throw new CodeError('Failed to authenticate webtransport', 'ERR_AUTHENTICATION_FAILED')
|
|
@@ -218,7 +235,8 @@ class WebTransportTransport implements Transport {
|
|
|
218
235
|
return await options.upgrader.upgradeOutbound(maConn, {
|
|
219
236
|
skipEncryption: true,
|
|
220
237
|
muxerFactory: webtransportMuxer(wt, wt.incomingBidirectionalStreams.getReader(), this.components.logger, this.config),
|
|
221
|
-
skipProtection: true
|
|
238
|
+
skipProtection: true,
|
|
239
|
+
onProgress: options.onProgress
|
|
222
240
|
})
|
|
223
241
|
} catch (err: any) {
|
|
224
242
|
this.log.error('caught wt session err', err)
|
|
@@ -239,11 +257,10 @@ class WebTransportTransport implements Transport {
|
|
|
239
257
|
}
|
|
240
258
|
}
|
|
241
259
|
|
|
242
|
-
async authenticateWebTransport (wt
|
|
243
|
-
|
|
244
|
-
throw new AbortError()
|
|
245
|
-
}
|
|
260
|
+
async authenticateWebTransport ({ wt, localPeer, remotePeer, certhashes, onProgress, signal }: AuthenticateWebTransportOptions): Promise<boolean> {
|
|
261
|
+
signal?.throwIfAborted()
|
|
246
262
|
|
|
263
|
+
onProgress?.(new CustomProgressEvent('webtransport:open-authentication-stream'))
|
|
247
264
|
const stream = await wt.createBidirectionalStream()
|
|
248
265
|
const writer = stream.writable.getWriter()
|
|
249
266
|
const reader = stream.readable.getReader()
|
|
@@ -277,8 +294,10 @@ class WebTransportTransport implements Transport {
|
|
|
277
294
|
|
|
278
295
|
const n = noise()(this.components)
|
|
279
296
|
|
|
297
|
+
onProgress?.(new CustomProgressEvent('webtransport:secure-outbound-connection'))
|
|
280
298
|
const { remoteExtensions } = await n.secureOutbound(localPeer, duplex, remotePeer)
|
|
281
299
|
|
|
300
|
+
onProgress?.(new CustomProgressEvent('webtransport:close-authentication-stream'))
|
|
282
301
|
// We're done with this authentication stream
|
|
283
302
|
writer.close().catch((err: Error) => {
|
|
284
303
|
this.log.error(`Failed to close authentication stream writer: ${err.message}`)
|
|
@@ -315,6 +334,11 @@ class WebTransportTransport implements Transport {
|
|
|
315
334
|
* Filter check for all Multiaddrs that this transport can dial
|
|
316
335
|
*/
|
|
317
336
|
dialFilter (multiaddrs: Multiaddr[]): Multiaddr[] {
|
|
337
|
+
// test for WebTransport support
|
|
338
|
+
if (globalThis.WebTransport == null) {
|
|
339
|
+
return []
|
|
340
|
+
}
|
|
341
|
+
|
|
318
342
|
return multiaddrs.filter(ma => {
|
|
319
343
|
if (!WebTransportMatcher.exactMatch(ma)) {
|
|
320
344
|
return false
|