@libp2p/webtransport 5.0.51 → 6.0.0-55b7e5fea
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 +11 -12
- package/dist/index.min.js.map +4 -4
- package/dist/src/index.d.ts +1 -4
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +32 -63
- package/dist/src/index.js.map +1 -1
- package/dist/src/listener.d.ts +0 -1
- package/dist/src/listener.d.ts.map +1 -1
- package/dist/src/listener.js.map +1 -1
- package/dist/src/muxer.d.ts +2 -5
- package/dist/src/muxer.d.ts.map +1 -1
- package/dist/src/muxer.js +44 -74
- package/dist/src/muxer.js.map +1 -1
- package/dist/src/session-to-conn.d.ts +11 -0
- package/dist/src/session-to-conn.d.ts.map +1 -0
- package/dist/src/session-to-conn.js +35 -0
- package/dist/src/session-to-conn.js.map +1 -0
- package/dist/src/stream.d.ts +21 -2
- package/dist/src/stream.d.ts.map +1 -1
- package/dist/src/stream.js +75 -47
- package/dist/src/stream.js.map +1 -1
- package/dist/src/utils/parse-multiaddr.d.ts +1 -1
- package/dist/src/utils/parse-multiaddr.d.ts.map +1 -1
- package/dist/src/utils/parse-multiaddr.js +17 -11
- package/dist/src/utils/parse-multiaddr.js.map +1 -1
- package/dist/src/utils/webtransport-message-stream.d.ts +18 -0
- package/dist/src/utils/webtransport-message-stream.d.ts.map +1 -0
- package/dist/src/utils/webtransport-message-stream.js +49 -0
- package/dist/src/utils/webtransport-message-stream.js.map +1 -0
- package/package.json +20 -21
- package/src/index.ts +36 -74
- package/src/listener.ts +0 -1
- package/src/muxer.ts +60 -84
- package/src/session-to-conn.ts +50 -0
- package/src/stream.ts +88 -55
- package/src/utils/parse-multiaddr.ts +20 -12
- package/src/utils/webtransport-message-stream.ts +69 -0
- package/dist/src/constants.d.ts +0 -2
- package/dist/src/constants.d.ts.map +0 -1
- package/dist/src/constants.js +0 -2
- package/dist/src/constants.js.map +0 -1
- package/dist/src/utils/inert-duplex.d.ts +0 -3
- package/dist/src/utils/inert-duplex.d.ts.map +0 -1
- package/dist/src/utils/inert-duplex.js +0 -20
- package/dist/src/utils/inert-duplex.js.map +0 -1
- package/dist/typedoc-urls.json +0 -14
- package/src/constants.ts +0 -1
- package/src/utils/inert-duplex.ts +0 -21
package/dist/src/stream.js
CHANGED
|
@@ -1,67 +1,96 @@
|
|
|
1
|
-
import { AbstractStream } from '@libp2p/utils
|
|
1
|
+
import { AbstractStream } from '@libp2p/utils';
|
|
2
2
|
import { raceSignal } from 'race-signal';
|
|
3
|
-
|
|
4
|
-
class WebTransportStream extends AbstractStream {
|
|
3
|
+
export class WebTransportStream extends AbstractStream {
|
|
5
4
|
writer;
|
|
6
5
|
reader;
|
|
7
6
|
constructor(init) {
|
|
8
7
|
super(init);
|
|
9
|
-
this.writer = init.
|
|
10
|
-
this.reader = init.
|
|
8
|
+
this.writer = init.stream.writable.getWriter();
|
|
9
|
+
this.reader = init.stream.readable.getReader();
|
|
10
|
+
void this.writer.closed
|
|
11
|
+
.then(() => {
|
|
12
|
+
this.log('writer closed gracefully');
|
|
13
|
+
})
|
|
14
|
+
.catch((err) => {
|
|
15
|
+
// chrome/ff send different messages
|
|
16
|
+
if (err.message.includes('STOP_SENDING') || err.message.includes('StopSending')) {
|
|
17
|
+
// err.code === 0 so we may be able to use this to detect remote close
|
|
18
|
+
// read instead?
|
|
19
|
+
this.onRemoteCloseRead();
|
|
20
|
+
}
|
|
21
|
+
else if (err.message.includes('RESET_STREAM') || err.message.includes('Reset')) {
|
|
22
|
+
this.onRemoteReset();
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
this.log('writer close promise rejected - %e', err);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
this.readData();
|
|
29
|
+
}
|
|
30
|
+
readData() {
|
|
11
31
|
Promise.resolve()
|
|
12
32
|
.then(async () => {
|
|
13
33
|
while (true) {
|
|
14
34
|
const result = await this.reader.read();
|
|
35
|
+
if (result.value != null) {
|
|
36
|
+
this.onData(result.value);
|
|
37
|
+
}
|
|
15
38
|
if (result.done) {
|
|
16
|
-
|
|
39
|
+
this.log('remote closed write');
|
|
40
|
+
this.onRemoteCloseWrite();
|
|
17
41
|
return;
|
|
18
42
|
}
|
|
19
|
-
if (
|
|
20
|
-
|
|
43
|
+
if (this.readStatus === 'paused') {
|
|
44
|
+
break;
|
|
21
45
|
}
|
|
22
46
|
}
|
|
23
47
|
})
|
|
24
48
|
.catch(err => {
|
|
25
|
-
init.log.error('error reading from stream', err);
|
|
26
49
|
this.abort(err);
|
|
27
50
|
})
|
|
28
51
|
.finally(() => {
|
|
29
|
-
this.
|
|
30
|
-
});
|
|
31
|
-
void this.writer.closed
|
|
32
|
-
.then(() => {
|
|
33
|
-
init.log('writer closed');
|
|
34
|
-
})
|
|
35
|
-
.catch((err) => {
|
|
36
|
-
init.log('writer close promise rejected', err);
|
|
37
|
-
})
|
|
38
|
-
.finally(() => {
|
|
39
|
-
this.remoteCloseRead();
|
|
52
|
+
this.reader.releaseLock();
|
|
40
53
|
});
|
|
41
54
|
}
|
|
42
|
-
|
|
43
|
-
//
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
this.log('sendData waiting for writer to be ready');
|
|
48
|
-
await raceSignal(this.writer.ready, options?.signal);
|
|
49
|
-
// the streams spec recommends not waiting for data to be sent
|
|
50
|
-
// https://streams.spec.whatwg.org/#example-manual-write-dont-await
|
|
51
|
-
this.writer.write(chunk)
|
|
55
|
+
sendData(data) {
|
|
56
|
+
// the streams spec recommends not waiting for data to be sent
|
|
57
|
+
// https://streams.spec.whatwg.org/#example-manual-write-dont-await
|
|
58
|
+
for (const buf of data) {
|
|
59
|
+
this.writer.write(buf)
|
|
52
60
|
.catch(err => {
|
|
53
|
-
this.
|
|
61
|
+
this.abort(err);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
this.log.trace('desired size after sending %d bytes is %d bytes', data.byteLength, this.writer.desiredSize);
|
|
65
|
+
// null means the stream has errored - https://streams.spec.whatwg.org/#writable-stream-default-writer-get-desired-size
|
|
66
|
+
if (this.writer.desiredSize == null) {
|
|
67
|
+
return {
|
|
68
|
+
sentBytes: data.byteLength,
|
|
69
|
+
canSendMore: false
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
const canSendMore = this.writer.desiredSize > 0;
|
|
73
|
+
if (!canSendMore) {
|
|
74
|
+
this.writer.ready.then(() => {
|
|
75
|
+
this.safeDispatchEvent('drain');
|
|
76
|
+
}, (err) => {
|
|
77
|
+
this.abort(err);
|
|
54
78
|
});
|
|
55
79
|
}
|
|
80
|
+
return {
|
|
81
|
+
sentBytes: data.byteLength,
|
|
82
|
+
canSendMore
|
|
83
|
+
};
|
|
56
84
|
}
|
|
57
|
-
|
|
58
|
-
this.
|
|
59
|
-
|
|
60
|
-
|
|
85
|
+
sendReset(err) {
|
|
86
|
+
this.writer.abort(err)
|
|
87
|
+
.catch(err => {
|
|
88
|
+
this.log.error('error aborting writer - %e', err);
|
|
89
|
+
});
|
|
61
90
|
}
|
|
62
91
|
async sendCloseWrite(options) {
|
|
63
92
|
this.log('sendCloseWrite closing writer');
|
|
64
|
-
await raceSignal(this.writer.close(), options?.signal);
|
|
93
|
+
await raceSignal(this.writer.close().catch(() => { }), options?.signal);
|
|
65
94
|
this.log('sendCloseWrite closed writer');
|
|
66
95
|
}
|
|
67
96
|
async sendCloseRead(options) {
|
|
@@ -69,21 +98,20 @@ class WebTransportStream extends AbstractStream {
|
|
|
69
98
|
await raceSignal(this.reader.cancel(), options?.signal);
|
|
70
99
|
this.log('sendCloseRead cancelled reader');
|
|
71
100
|
}
|
|
101
|
+
sendPause() {
|
|
102
|
+
}
|
|
103
|
+
sendResume() {
|
|
104
|
+
this.readData();
|
|
105
|
+
}
|
|
72
106
|
}
|
|
73
|
-
export
|
|
74
|
-
|
|
75
|
-
|
|
107
|
+
export function webtransportBiDiStreamToStream(stream, streamId, direction, log, options) {
|
|
108
|
+
return new WebTransportStream({
|
|
109
|
+
...options,
|
|
110
|
+
stream,
|
|
76
111
|
id: streamId,
|
|
77
112
|
direction,
|
|
78
113
|
log: log.newScope(`${direction}:${streamId}`),
|
|
79
|
-
|
|
80
|
-
const index = activeStreams.findIndex(s => s === stream);
|
|
81
|
-
if (index !== -1) {
|
|
82
|
-
activeStreams.splice(index, 1);
|
|
83
|
-
}
|
|
84
|
-
onStreamEnd?.(stream);
|
|
85
|
-
}
|
|
114
|
+
protocol: ''
|
|
86
115
|
});
|
|
87
|
-
return stream;
|
|
88
116
|
}
|
|
89
117
|
//# sourceMappingURL=stream.js.map
|
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,cAAc,EAAE,MAAM
|
|
1
|
+
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AASxC,MAAM,OAAO,kBAAmB,SAAQ,cAAc;IACnC,MAAM,CAAyC;IAC/C,MAAM,CAAyC;IAEhE,YAAa,IAA4B;QACvC,KAAK,CAAC,IAAI,CAAC,CAAA;QAEX,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAA;QAC9C,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAA;QAE9C,KAAK,IAAI,CAAC,MAAM,CAAC,MAAM;aACpB,IAAI,CAAC,GAAG,EAAE;YACT,IAAI,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAA;QACtC,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;YACb,oCAAoC;YACpC,IAAI,GAAG,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AI,CAAC,GAAG,CAAC,KAAK,CAAC,4BAA4B,EAAE,GAAG,CAAC,CAAA;QACnD,CAAC,CAAC,CAAA;IACN,CAAC;IAED,KAAK,CAAC,cAAc,CAAE,OAAsB;QAC1C,IAAI,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAA;QACzC,MAAM,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,CAAA;QACtE,IAAI,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAA;IAC1C,CAAC;IAED,KAAK,CAAC,aAAa,CAAE,OAAsB;QACzC,IAAI,CAAC,GAAG,CAAC,iCAAiC,CAAC,CAAA;QAC3C,MAAM,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,CAAC,CAAA;QACvD,IAAI,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAA;IAC5C,CAAC;IAED,SAAS;IAET,CAAC;IAED,UAAU;QACR,IAAI,CAAC,QAAQ,EAAE,CAAA;IACjB,CAAC;CACF;AAED,MAAM,UAAU,8BAA8B,CAAE,MAAuC,EAAE,QAAgB,EAAE,SAAiC,EAAE,GAAW,EAAE,OAAuB;IAChL,OAAO,IAAI,kBAAkB,CAAC;QAC5B,GAAG,OAAO;QACV,MAAM;QACN,EAAE,EAAE,QAAQ;QACZ,SAAS;QACT,GAAG,EAAE,GAAG,CAAC,QAAQ,CAAC,GAAG,SAAS,IAAI,QAAQ,EAAE,CAAC;QAC7C,QAAQ,EAAE,EAAE;KACb,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -4,7 +4,7 @@ import type { MultihashDigest } from 'multiformats/hashes/interface';
|
|
|
4
4
|
export interface ParsedMultiaddr {
|
|
5
5
|
url: string;
|
|
6
6
|
certhashes: MultihashDigest[];
|
|
7
|
-
remotePeer
|
|
7
|
+
remotePeer: PeerId;
|
|
8
8
|
}
|
|
9
9
|
export declare function parseMultiaddr(ma: Multiaddr): ParsedMultiaddr;
|
|
10
10
|
//# sourceMappingURL=parse-multiaddr.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-multiaddr.d.ts","sourceRoot":"","sources":["../../../src/utils/parse-multiaddr.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AASpE,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,MAAM,CAAA;IACX,UAAU,EAAE,eAAe,EAAE,CAAA;IAC7B,UAAU,
|
|
1
|
+
{"version":3,"file":"parse-multiaddr.d.ts","sourceRoot":"","sources":["../../../src/utils/parse-multiaddr.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AASpE,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,MAAM,CAAA;IACX,UAAU,EAAE,eAAe,EAAE,CAAA;IAC7B,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,wBAAgB,cAAc,CAAE,EAAE,EAAE,SAAS,GAAG,eAAe,CA4C9D"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { InvalidMultiaddrError } from '@libp2p/interface';
|
|
2
2
|
import { peerIdFromString } from '@libp2p/peer-id';
|
|
3
|
-
import {
|
|
3
|
+
import { getNetConfig } from '@libp2p/utils';
|
|
4
4
|
import { WebTransport } from '@multiformats/multiaddr-matcher';
|
|
5
5
|
import { bases, digest } from 'multiformats/basics';
|
|
6
6
|
// @ts-expect-error - Not easy to combine these types.
|
|
@@ -12,17 +12,23 @@ export function parseMultiaddr(ma) {
|
|
|
12
12
|
if (!WebTransport.matches(ma)) {
|
|
13
13
|
throw new InvalidMultiaddrError('Invalid multiaddr, was not a WebTransport address');
|
|
14
14
|
}
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
.
|
|
23
|
-
|
|
15
|
+
const certhashes = [];
|
|
16
|
+
let remotePeer;
|
|
17
|
+
for (const components of ma.getComponents()) {
|
|
18
|
+
if (components.name === 'certhash') {
|
|
19
|
+
certhashes.push(decodeCerthashStr(components.value ?? ''));
|
|
20
|
+
}
|
|
21
|
+
// only take the first peer id in the multiaddr as it may be a relay
|
|
22
|
+
if (components.name === 'p2p' && remotePeer == null) {
|
|
23
|
+
remotePeer = peerIdFromString(components.value ?? '');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (remotePeer == null) {
|
|
27
|
+
throw new InvalidMultiaddrError('Remote peer must be present in multiaddr');
|
|
28
|
+
}
|
|
29
|
+
const opts = getNetConfig(ma);
|
|
24
30
|
let host = opts.host;
|
|
25
|
-
if (opts.
|
|
31
|
+
if (opts.type === 'ip6' && host.includes(':')) {
|
|
26
32
|
/**
|
|
27
33
|
* This resolves cases where `new WebTransport()` fails to construct because of an invalid URL being passed.
|
|
28
34
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-multiaddr.js","sourceRoot":"","sources":["../../../src/utils/parse-multiaddr.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"parse-multiaddr.js","sourceRoot":"","sources":["../../../src/utils/parse-multiaddr.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,q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AK,IAAI,EAAE,CAAC,CAAA;QACvD,CAAC;IACH,CAAC;IAED,IAAI,UAAU,IAAI,IAAI,EAAE,CAAC;QACvB,MAAM,IAAI,qBAAqB,CAAC,0CAA0C,CAAC,CAAA;IAC7E,CAAC;IAED,MAAM,IAAI,GAAG,YAAY,CAAC,EAAE,CAAC,CAAA;IAC7B,IAAI,IAAI,GAAG,IAAI,CAAC,IAAI,CAAA;IAEpB,IAAI,IAAI,CAAC,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAC9C;;;;;;;WAOG;QACH,IAAI,GAAG,IAAI,IAAI,GAAG,CAAA;IACpB,CAAC;IAED,OAAO;QACL,kCAAkC;QAClC,GAAG,EAAE,WAAW,IAAI,IAAI,IAAI,CAAC,IAAI,EAAE;QACnC,UAAU;QACV,UAAU;KACX,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { AbstractMessageStream } from '@libp2p/utils';
|
|
2
|
+
import type { AbortOptions } from '@libp2p/interface';
|
|
3
|
+
import type { MessageStreamInit, SendResult } from '@libp2p/utils';
|
|
4
|
+
import type { Uint8ArrayList } from 'uint8arraylist';
|
|
5
|
+
export interface WebTransportMessageStreamInit extends MessageStreamInit {
|
|
6
|
+
stream: WebTransportBidirectionalStream;
|
|
7
|
+
}
|
|
8
|
+
export declare class WebTransportMessageStream extends AbstractMessageStream {
|
|
9
|
+
private writer;
|
|
10
|
+
private reader;
|
|
11
|
+
constructor(init: WebTransportMessageStreamInit);
|
|
12
|
+
close(options?: AbortOptions): Promise<void>;
|
|
13
|
+
sendData(data: Uint8ArrayList): SendResult;
|
|
14
|
+
sendReset(err: Error): void;
|
|
15
|
+
sendPause(): void;
|
|
16
|
+
sendResume(): void;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=webtransport-message-stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webtransport-message-stream.d.ts","sourceRoot":"","sources":["../../../src/utils/webtransport-message-stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AAErD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAClE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD,MAAM,WAAW,6BAA8B,SAAQ,iBAAiB;IACtE,MAAM,EAAE,+BAA+B,CAAA;CACxC;AAED,qBAAa,yBAA0B,SAAQ,qBAAqB;IAClE,OAAO,CAAC,MAAM,CAAkC;IAChD,OAAO,CAAC,MAAM,CAAkC;gBAEnC,IAAI,EAAE,6BAA6B;IAwB1C,KAAK,CAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAInD,QAAQ,CAAE,IAAI,EAAE,cAAc,GAAG,UAAU;IAY3C,SAAS,CAAE,GAAG,EAAE,KAAK,GAAG,IAAI;IAO5B,SAAS,IAAK,IAAI;IAIlB,UAAU,IAAK,IAAI;CAGpB"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { AbstractMessageStream } from '@libp2p/utils';
|
|
2
|
+
import { raceSignal } from 'race-signal';
|
|
3
|
+
export class WebTransportMessageStream extends AbstractMessageStream {
|
|
4
|
+
writer;
|
|
5
|
+
reader;
|
|
6
|
+
constructor(init) {
|
|
7
|
+
super(init);
|
|
8
|
+
this.writer = init.stream.writable.getWriter();
|
|
9
|
+
this.reader = init.stream.readable.getReader();
|
|
10
|
+
Promise.resolve().then(async () => {
|
|
11
|
+
while (true) {
|
|
12
|
+
const { done, value } = await this.reader.read();
|
|
13
|
+
if (value != null) {
|
|
14
|
+
this.onData(value);
|
|
15
|
+
}
|
|
16
|
+
if (done) {
|
|
17
|
+
break;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
})
|
|
21
|
+
.catch(err => {
|
|
22
|
+
this.abort(err);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
async close(options) {
|
|
26
|
+
await raceSignal(this.writer.close(), options?.signal);
|
|
27
|
+
}
|
|
28
|
+
sendData(data) {
|
|
29
|
+
this.writer.write(data.subarray())
|
|
30
|
+
.catch(err => {
|
|
31
|
+
this.abort(err);
|
|
32
|
+
});
|
|
33
|
+
return {
|
|
34
|
+
sentBytes: data.byteLength,
|
|
35
|
+
canSendMore: true
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
sendReset(err) {
|
|
39
|
+
this.writer.abort(err)
|
|
40
|
+
.catch(err => {
|
|
41
|
+
this.log.error('could not send reset - %e', err);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
sendPause() {
|
|
45
|
+
}
|
|
46
|
+
sendResume() {
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=webtransport-message-stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webtransport-message-stream.js","sourceRoot":"","sources":["../../../src/utils/webtransport-message-stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AASxC,MAAM,OAAO,yBAA0B,SAAQ,qBAAqB;IAC1D,MAAM,CAAkC;IACxC,MAAM,CAAkC;IAEhD,YAAa,IAAmC;QAC9C,KAAK,CAAC,IAAI,CAAC,CAAA;QAEX,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAA;QAC9C,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAA;QAE9C,OAAO,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE;YAChC,OAAO,IAAI,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
-
"version": "
|
|
3
|
+
"version": "6.0.0-55b7e5fea",
|
|
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",
|
|
@@ -40,36 +40,35 @@
|
|
|
40
40
|
"build": "aegir build",
|
|
41
41
|
"test": "aegir test -t browser -t webworker",
|
|
42
42
|
"test:chrome": "aegir test -t browser --cov",
|
|
43
|
-
"test:chrome-webworker": "aegir test -t webworker"
|
|
43
|
+
"test:chrome-webworker": "aegir test -t webworker",
|
|
44
|
+
"test:firefox": "aegir test -t browser -- --browser firefox"
|
|
44
45
|
},
|
|
45
46
|
"dependencies": {
|
|
46
|
-
"@
|
|
47
|
-
"@libp2p/
|
|
48
|
-
"@libp2p/peer-id": "
|
|
49
|
-
"@libp2p/utils": "
|
|
50
|
-
"@multiformats/multiaddr": "^
|
|
51
|
-
"@multiformats/multiaddr-matcher": "^
|
|
52
|
-
"it-stream-types": "^2.0.2",
|
|
47
|
+
"@libp2p/interface": "3.0.0-55b7e5fea",
|
|
48
|
+
"@libp2p/noise": "1.0.0-55b7e5fea",
|
|
49
|
+
"@libp2p/peer-id": "6.0.0-55b7e5fea",
|
|
50
|
+
"@libp2p/utils": "7.0.0-55b7e5fea",
|
|
51
|
+
"@multiformats/multiaddr": "^13.0.1",
|
|
52
|
+
"@multiformats/multiaddr-matcher": "^3.0.1",
|
|
53
53
|
"multiformats": "^13.3.6",
|
|
54
54
|
"progress-events": "^1.0.1",
|
|
55
|
-
"race-signal": "^
|
|
55
|
+
"race-signal": "^2.0.0",
|
|
56
56
|
"uint8arraylist": "^2.4.8",
|
|
57
57
|
"uint8arrays": "^5.1.0"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
|
-
"@libp2p/crypto": "
|
|
61
|
-
"@libp2p/daemon-client": "
|
|
62
|
-
"@libp2p/logger": "
|
|
63
|
-
"@libp2p/ping": "
|
|
64
|
-
"@noble/hashes": "^
|
|
65
|
-
"aegir": "^47.0.
|
|
66
|
-
"execa": "^9.
|
|
60
|
+
"@libp2p/crypto": "5.1.9-55b7e5fea",
|
|
61
|
+
"@libp2p/daemon-client": "10.0.0-55b7e5fea",
|
|
62
|
+
"@libp2p/logger": "6.0.0-55b7e5fea",
|
|
63
|
+
"@libp2p/ping": "3.0.0-55b7e5fea",
|
|
64
|
+
"@noble/hashes": "^2.0.1",
|
|
65
|
+
"aegir": "^47.0.22",
|
|
66
|
+
"execa": "^9.6.0",
|
|
67
67
|
"go-libp2p": "^1.6.0",
|
|
68
|
-
"it-
|
|
69
|
-
"
|
|
70
|
-
"libp2p": "^2.10.0",
|
|
68
|
+
"it-all": "^3.0.9",
|
|
69
|
+
"libp2p": "3.0.0-55b7e5fea",
|
|
71
70
|
"p-defer": "^4.0.1",
|
|
72
|
-
"p-
|
|
71
|
+
"p-event": "^7.0.0",
|
|
73
72
|
"sinon-ts": "^2.0.0"
|
|
74
73
|
},
|
|
75
74
|
"browser": {
|
package/src/index.ts
CHANGED
|
@@ -3,20 +3,18 @@
|
|
|
3
3
|
*
|
|
4
4
|
* A [libp2p transport](https://docs.libp2p.io/concepts/transports/overview/) based on [WebTransport](https://www.w3.org/TR/webtransport/).
|
|
5
5
|
*
|
|
6
|
-
* >
|
|
7
6
|
* > ⚠️ **Note**
|
|
8
7
|
* >
|
|
9
8
|
* > This WebTransport implementation currently only allows dialing to other nodes. It does not yet allow listening for incoming dials. This feature requires QUIC support to land in Node JS first.
|
|
10
9
|
* >
|
|
11
10
|
* > QUIC support in Node JS is actively being worked on. You can keep an eye on the progress by watching the [related issues on the Node JS issue tracker](https://github.com/nodejs/node/labels/quic)
|
|
12
|
-
* >
|
|
13
11
|
*
|
|
14
12
|
* @example
|
|
15
13
|
*
|
|
16
14
|
* ```TypeScript
|
|
17
15
|
* import { createLibp2p } from 'libp2p'
|
|
18
16
|
* import { webTransport } from '@libp2p/webtransport'
|
|
19
|
-
* import { noise } from '@
|
|
17
|
+
* import { noise } from '@libp2p/noise'
|
|
20
18
|
*
|
|
21
19
|
* const node = await createLibp2p({
|
|
22
20
|
* transports: [
|
|
@@ -29,24 +27,21 @@
|
|
|
29
27
|
* ```
|
|
30
28
|
*/
|
|
31
29
|
|
|
32
|
-
import { noise } from '@chainsafe/libp2p-noise'
|
|
33
30
|
import { InvalidCryptoExchangeError, InvalidParametersError, serviceCapabilities, transportSymbol } from '@libp2p/interface'
|
|
31
|
+
import { noise } from '@libp2p/noise'
|
|
34
32
|
import { WebTransport as WebTransportMatcher } from '@multiformats/multiaddr-matcher'
|
|
35
33
|
import { CustomProgressEvent } from 'progress-events'
|
|
36
|
-
import { raceSignal } from 'race-signal'
|
|
37
|
-
import { MAX_INBOUND_STREAMS } from './constants.js'
|
|
38
34
|
import createListener from './listener.js'
|
|
39
35
|
import { webtransportMuxer } from './muxer.js'
|
|
40
|
-
import {
|
|
36
|
+
import { toMultiaddrConnection } from './session-to-conn.ts'
|
|
41
37
|
import { isSubset } from './utils/is-subset.js'
|
|
42
38
|
import { parseMultiaddr } from './utils/parse-multiaddr.js'
|
|
39
|
+
import { WebTransportMessageStream } from './utils/webtransport-message-stream.ts'
|
|
43
40
|
import WebTransport from './webtransport.js'
|
|
44
41
|
import type { Upgrader, Transport, CreateListenerOptions, DialTransportOptions, Listener, ComponentLogger, Logger, Connection, MultiaddrConnection, CounterGroup, Metrics, PeerId, OutboundConnectionUpgradeEvents, PrivateKey } from '@libp2p/interface'
|
|
45
42
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
46
|
-
import type { Source } from 'it-stream-types'
|
|
47
43
|
import type { MultihashDigest } from 'multiformats/hashes/interface'
|
|
48
44
|
import type { ProgressEvent } from 'progress-events'
|
|
49
|
-
import type { Uint8ArrayList } from 'uint8arraylist'
|
|
50
45
|
|
|
51
46
|
/**
|
|
52
47
|
* PEM format server certificate and private key
|
|
@@ -63,7 +58,6 @@ interface WebTransportSessionCleanup {
|
|
|
63
58
|
}
|
|
64
59
|
|
|
65
60
|
export interface WebTransportInit {
|
|
66
|
-
maxInboundStreams?: number
|
|
67
61
|
certificates?: WebTransportCertificate[]
|
|
68
62
|
}
|
|
69
63
|
|
|
@@ -88,6 +82,7 @@ export type WebTransportDialEvents =
|
|
|
88
82
|
|
|
89
83
|
interface AuthenticateWebTransportOptions extends DialTransportOptions<WebTransportDialEvents> {
|
|
90
84
|
wt: WebTransport
|
|
85
|
+
maConn: MultiaddrConnection
|
|
91
86
|
remotePeer?: PeerId
|
|
92
87
|
certhashes: Array<MultihashDigest<number>>
|
|
93
88
|
}
|
|
@@ -103,7 +98,6 @@ class WebTransportTransport implements Transport<WebTransportDialEvents> {
|
|
|
103
98
|
this.components = components
|
|
104
99
|
this.config = {
|
|
105
100
|
...init,
|
|
106
|
-
maxInboundStreams: init.maxInboundStreams ?? MAX_INBOUND_STREAMS,
|
|
107
101
|
certificates: init.certificates ?? []
|
|
108
102
|
}
|
|
109
103
|
|
|
@@ -202,36 +196,32 @@ class WebTransportTransport implements Transport<WebTransportDialEvents> {
|
|
|
202
196
|
cleanUpWTSession('remote_close')
|
|
203
197
|
})
|
|
204
198
|
|
|
205
|
-
authenticated = await raceSignal(this.authenticateWebTransport({ wt, remotePeer, certhashes, ...options }), options.signal)
|
|
206
|
-
|
|
207
|
-
if (!authenticated) {
|
|
208
|
-
throw new InvalidCryptoExchangeError('Failed to authenticate webtransport')
|
|
209
|
-
}
|
|
210
|
-
|
|
211
199
|
this.metrics?.dialerEvents.increment({ open: true })
|
|
212
200
|
|
|
213
|
-
maConn = {
|
|
214
|
-
close: async () => {
|
|
215
|
-
this.log('closing webtransport')
|
|
216
|
-
cleanUpWTSession('close')
|
|
217
|
-
},
|
|
218
|
-
abort: (err: Error) => {
|
|
219
|
-
this.log('aborting webtransport due to passed err', err)
|
|
220
|
-
cleanUpWTSession('abort')
|
|
221
|
-
},
|
|
201
|
+
maConn = toMultiaddrConnection({
|
|
222
202
|
remoteAddr: ma,
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
203
|
+
cleanUpWTSession,
|
|
204
|
+
direction: 'outbound',
|
|
205
|
+
log: this.components.logger.forComponent('libp2p:webtransport:connection')
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
authenticated = await this.authenticateWebTransport({
|
|
209
|
+
wt,
|
|
210
|
+
maConn,
|
|
211
|
+
remotePeer,
|
|
212
|
+
certhashes,
|
|
213
|
+
...options
|
|
214
|
+
})
|
|
215
|
+
|
|
216
|
+
if (!authenticated) {
|
|
217
|
+
throw new InvalidCryptoExchangeError('Failed to authenticate webtransport')
|
|
229
218
|
}
|
|
230
219
|
|
|
231
220
|
return await options.upgrader.upgradeOutbound(maConn, {
|
|
232
221
|
...options,
|
|
233
222
|
skipEncryption: true,
|
|
234
|
-
|
|
223
|
+
remotePeer,
|
|
224
|
+
muxerFactory: webtransportMuxer(wt),
|
|
235
225
|
skipProtection: true
|
|
236
226
|
})
|
|
237
227
|
} catch (err: any) {
|
|
@@ -253,61 +243,34 @@ class WebTransportTransport implements Transport<WebTransportDialEvents> {
|
|
|
253
243
|
}
|
|
254
244
|
}
|
|
255
245
|
|
|
256
|
-
async authenticateWebTransport ({ wt, remotePeer, certhashes, onProgress, signal }: AuthenticateWebTransportOptions): Promise<boolean> {
|
|
257
|
-
signal?.throwIfAborted()
|
|
258
|
-
|
|
246
|
+
async authenticateWebTransport ({ wt, maConn, remotePeer, certhashes, onProgress, signal }: AuthenticateWebTransportOptions): Promise<boolean> {
|
|
259
247
|
onProgress?.(new CustomProgressEvent('webtransport:open-authentication-stream'))
|
|
260
248
|
const stream = await wt.createBidirectionalStream()
|
|
261
|
-
|
|
262
|
-
const reader = stream.readable.getReader()
|
|
263
|
-
|
|
264
|
-
const duplex = {
|
|
265
|
-
source: (async function * () {
|
|
266
|
-
while (true) {
|
|
267
|
-
const val = await reader.read()
|
|
268
|
-
|
|
269
|
-
if (val.value != null) {
|
|
270
|
-
yield val.value
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
if (val.done) {
|
|
274
|
-
break
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
})(),
|
|
278
|
-
sink: async (source: Source<Uint8Array | Uint8ArrayList>) => {
|
|
279
|
-
for await (const chunk of source) {
|
|
280
|
-
await raceSignal(writer.ready, signal)
|
|
281
|
-
|
|
282
|
-
const buf = chunk instanceof Uint8Array ? chunk : chunk.subarray()
|
|
249
|
+
signal?.throwIfAborted()
|
|
283
250
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
}
|
|
289
|
-
}
|
|
251
|
+
const messages = new WebTransportMessageStream({
|
|
252
|
+
stream,
|
|
253
|
+
log: maConn.log.newScope('muxer')
|
|
254
|
+
})
|
|
290
255
|
|
|
291
256
|
const n = noise()(this.components)
|
|
292
257
|
|
|
293
258
|
onProgress?.(new CustomProgressEvent('webtransport:secure-outbound-connection'))
|
|
294
|
-
const { remoteExtensions } = await n.secureOutbound(
|
|
259
|
+
const { remoteExtensions } = await n.secureOutbound(messages, {
|
|
295
260
|
signal,
|
|
296
261
|
remotePeer,
|
|
297
262
|
skipStreamMuxerNegotiation: true
|
|
298
263
|
})
|
|
299
264
|
|
|
300
265
|
onProgress?.(new CustomProgressEvent('webtransport:close-authentication-stream'))
|
|
301
|
-
// We're done with this authentication stream
|
|
302
|
-
writer.close().catch((err: Error) => {
|
|
303
|
-
this.log.error(`Failed to close authentication stream writer: ${err.message}`)
|
|
304
|
-
})
|
|
305
266
|
|
|
306
|
-
|
|
307
|
-
|
|
267
|
+
// We're done with this authentication stream
|
|
268
|
+
await messages.close({
|
|
269
|
+
signal
|
|
308
270
|
})
|
|
309
271
|
|
|
310
|
-
// Verify the certhashes we used when dialing are a subset of the certhashes
|
|
272
|
+
// Verify the certhashes we used when dialing are a subset of the certhashes
|
|
273
|
+
// relayed by the remote peer
|
|
311
274
|
if (!isSubset(remoteExtensions?.webtransportCerthashes ?? [], certhashes.map(ch => ch.bytes))) {
|
|
312
275
|
throw new InvalidParametersError("Our certhashes are not a subset of the remote's reported certhashes")
|
|
313
276
|
}
|
|
@@ -318,8 +281,7 @@ class WebTransportTransport implements Transport<WebTransportDialEvents> {
|
|
|
318
281
|
createListener (options: CreateListenerOptions): Listener {
|
|
319
282
|
return createListener(this.components, {
|
|
320
283
|
...options,
|
|
321
|
-
certificates: this.config.certificates
|
|
322
|
-
maxInboundStreams: this.config.maxInboundStreams
|
|
284
|
+
certificates: this.config.certificates
|
|
323
285
|
})
|
|
324
286
|
}
|
|
325
287
|
|
package/src/listener.ts
CHANGED
|
@@ -11,7 +11,6 @@ export interface WebTransportListenerInit extends CreateListenerOptions {
|
|
|
11
11
|
handler?(conn: Connection): void
|
|
12
12
|
upgrader: Upgrader
|
|
13
13
|
certificates?: WebTransportCertificate[]
|
|
14
|
-
maxInboundStreams?: number
|
|
15
14
|
}
|
|
16
15
|
|
|
17
16
|
export default function createListener (components: WebTransportListenerComponents, options: WebTransportListenerInit): Listener {
|