@fails-components/webtransport 0.2.2 → 0.3.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/CMakeLists.txt +3 -0
- package/dist/lib/client.d.ts +7 -3
- package/dist/lib/client.d.ts.map +1 -1
- package/dist/lib/dom.d.ts +15 -4
- package/dist/lib/dom.d.ts.map +1 -1
- package/dist/lib/error.d.ts +8 -0
- package/dist/lib/error.d.ts.map +1 -0
- package/dist/lib/event-loop.d.ts +4 -2
- package/dist/lib/event-loop.d.ts.map +1 -1
- package/dist/lib/native.d.ts.map +1 -1
- package/dist/lib/server.d.ts +5 -2
- package/dist/lib/server.d.ts.map +1 -1
- package/dist/lib/session.d.ts +36 -23
- package/dist/lib/session.d.ts.map +1 -1
- package/dist/lib/stream.d.ts +15 -4
- package/dist/lib/stream.d.ts.map +1 -1
- package/dist/lib/transport.d.ts +12 -3
- package/dist/lib/transport.d.ts.map +1 -1
- package/dist/lib/types.d.ts +43 -4
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib/utils.d.ts +5 -0
- package/dist/lib/utils.d.ts.map +1 -1
- package/dist/lib/webtransport.d.ts +11 -21
- package/dist/lib/webtransport.d.ts.map +1 -1
- package/dist/test/datagrams.spec.d.ts.map +1 -1
- package/dist/test/event-loop.node.d.ts +2 -0
- package/dist/test/event-loop.node.d.ts.map +1 -0
- package/dist/test/fixtures/chai.d.ts.map +1 -1
- package/dist/test/fixtures/known-bytes.d.ts +6 -0
- package/dist/test/fixtures/known-bytes.d.ts.map +1 -0
- package/dist/test/fixtures/read-cert-hash.d.ts +6 -0
- package/dist/test/fixtures/read-cert-hash.d.ts.map +1 -0
- package/dist/test/fixtures/read-stream.d.ts +10 -1
- package/dist/test/fixtures/read-stream.d.ts.map +1 -1
- package/dist/test/fixtures/reader-value.d.ts +16 -1
- package/dist/test/fixtures/reader-value.d.ts.map +1 -1
- package/dist/test/fixtures/server.d.ts +0 -5
- package/dist/test/fixtures/server.d.ts.map +1 -1
- package/dist/test/fixtures/webtransport.browser.d.ts +3 -0
- package/dist/test/fixtures/webtransport.browser.d.ts.map +1 -0
- package/dist/test/fixtures/webtransport.d.ts +3 -0
- package/dist/test/fixtures/webtransport.d.ts.map +1 -0
- package/dist/test/fixtures/write-stream.d.ts.map +1 -1
- package/dist/test/index.d.ts +2 -0
- package/dist/test/index.d.ts.map +1 -0
- package/dist/test/session.spec.d.ts +5 -0
- package/dist/test/session.spec.d.ts.map +1 -0
- package/dist/test/unidirectional-streams.spec.d.ts +1 -4
- package/dist/test/unidirectional-streams.spec.d.ts.map +1 -1
- package/lib/client.js +57 -43
- package/lib/dom.ts +18 -4
- package/lib/error.js +10 -0
- package/lib/event-loop.js +8 -5
- package/lib/native.js +4 -1
- package/lib/server.js +18 -10
- package/lib/session.js +145 -32
- package/lib/stream.js +51 -22
- package/lib/transport.js +48 -10
- package/lib/types.ts +53 -5
- package/lib/utils.js +13 -0
- package/lib/webtransport.js +10 -18
- package/{test → old_test}/echoserver.js +1 -2
- package/{test → old_test}/test.js +5 -3
- package/package.json +16 -5
- package/readme.md +64 -0
- package/src/http3client.cc +2 -2
- package/src/http3dispatcher.cc +3 -2
- package/src/http3dispatcher.h +2 -1
- package/src/http3eventloop.cc +106 -2
- package/src/http3eventloop.h +13 -0
- package/src/http3wtsessionvisitor.cc +2 -0
- package/src/http3wtsessionvisitor.h +41 -1
- package/test/bidirectional-streams.spec.js +41 -97
- package/test/datagrams.spec.js +46 -99
- package/test/fixtures/chai.js +2 -0
- package/test/fixtures/known-bytes.js +15 -0
- package/test/fixtures/read-cert-hash.js +7 -0
- package/test/fixtures/read-stream.js +5 -0
- package/test/fixtures/reader-value.js +32 -0
- package/test/fixtures/server.js +237 -21
- package/test/fixtures/webtransport.browser.js +2 -0
- package/test/fixtures/webtransport.js +3 -0
- package/test/fixtures/write-stream.js +8 -1
- package/test/index.js +87 -0
- package/test/session.spec.js +159 -0
- package/test/unidirectional-streams.spec.js +67 -138
- package/tsconfig.json +0 -1
- package/dist/test/echoclient.d.ts +0 -2
- package/dist/test/echoclient.d.ts.map +0 -1
- package/dist/test/echoserver.d.ts +0 -2
- package/dist/test/echoserver.d.ts.map +0 -1
- package/dist/test/event-loop.spec.d.ts +0 -2
- package/dist/test/event-loop.spec.d.ts.map +0 -1
- package/dist/test/test.d.ts +0 -2
- package/dist/test/test.d.ts.map +0 -1
- package/dist/test/testsuite.d.ts +0 -25
- package/dist/test/testsuite.d.ts.map +0 -1
- package/platform/base/strings/utf_ostream_operators.h +0 -5
- /package/{test → old_test}/echoclient.js +0 -0
- /package/{test → old_test}/testsuite.js +0 -0
- /package/test/{event-loop.spec.js → event-loop.node.js} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"known-bytes.d.ts","sourceRoot":"","sources":["../../../test/fixtures/known-bytes.js"],"names":[],"mappings":"AAAA;;GAEG;AACH,uCAMC;AAED,wCAGC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-cert-hash.d.ts","sourceRoot":"","sources":["../../../test/fixtures/read-cert-hash.js"],"names":[],"mappings":"AAAA;;;GAGG;AACH,6DAFa,UAAU,CAItB"}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/**
|
|
3
|
+
* @template T
|
|
4
|
+
* @typedef {import('node:stream/web').ReadableStream<T>} ReadableStream<T>
|
|
5
|
+
*/
|
|
1
6
|
/**
|
|
2
7
|
* Read a stream contents to the end and return it
|
|
3
8
|
*
|
|
@@ -6,5 +11,9 @@
|
|
|
6
11
|
* @param {number} [expected]
|
|
7
12
|
* @returns
|
|
8
13
|
*/
|
|
9
|
-
export function readStream<T>(readable: ReadableStream<T>, expected?: number | undefined): Promise<T[]>;
|
|
14
|
+
export function readStream<T>(readable: import("stream/web").ReadableStream<T>, expected?: number | undefined): Promise<T[]>;
|
|
15
|
+
/**
|
|
16
|
+
* <T>
|
|
17
|
+
*/
|
|
18
|
+
export type ReadableStream<T> = import('node:stream/web').ReadableStream<T>;
|
|
10
19
|
//# sourceMappingURL=read-stream.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read-stream.d.ts","sourceRoot":"","sources":["../../../test/fixtures/read-stream.js"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,
|
|
1
|
+
{"version":3,"file":"read-stream.d.ts","sourceRoot":"","sources":["../../../test/fixtures/read-stream.js"],"names":[],"mappings":";AAAA;;;GAGG;AAEH;;;;;;;GAOG;AACH,6HA8BC;;;;gCAzCY,OAAO,iBAAiB,EAAE,cAAc,CAAC,CAAC,CAAC"}
|
|
@@ -1,7 +1,22 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/**
|
|
3
|
+
* @template T
|
|
4
|
+
* @typedef {import('node:stream/web').ReadableStream<T>} ReadableStream<T>
|
|
5
|
+
*/
|
|
1
6
|
/**
|
|
2
7
|
* @template T
|
|
3
8
|
* @param {ReadableStream<T>} readableStream
|
|
4
9
|
* @returns {Promise<T>}
|
|
5
10
|
*/
|
|
6
|
-
export function getReaderValue<T>(readableStream: ReadableStream<T>): Promise<T>;
|
|
11
|
+
export function getReaderValue<T>(readableStream: import("stream/web").ReadableStream<T>): Promise<T>;
|
|
12
|
+
/**
|
|
13
|
+
* @template T
|
|
14
|
+
* @param {ReadableStream<T>} readableStream
|
|
15
|
+
* @returns {AsyncGenerator<T>}
|
|
16
|
+
*/
|
|
17
|
+
export function getReaderStream<T>(readableStream: import("stream/web").ReadableStream<T>): AsyncGenerator<T, any, any>;
|
|
18
|
+
/**
|
|
19
|
+
* <T>
|
|
20
|
+
*/
|
|
21
|
+
export type ReadableStream<T> = import('node:stream/web').ReadableStream<T>;
|
|
7
22
|
//# sourceMappingURL=reader-value.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reader-value.d.ts","sourceRoot":"","sources":["../../../test/fixtures/reader-value.js"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,
|
|
1
|
+
{"version":3,"file":"reader-value.d.ts","sourceRoot":"","sources":["../../../test/fixtures/reader-value.js"],"names":[],"mappings":";AAAA;;;GAGG;AAEH;;;;GAIG;AACH,sGAkBC;AAED;;;;GAIG;AACH,wHAoBC;;;;gCArDY,OAAO,iBAAiB,EAAE,cAAc,CAAC,CAAC,CAAC"}
|
|
@@ -2,9 +2,4 @@ export function createServer(): Promise<{
|
|
|
2
2
|
server: Http3Server;
|
|
3
3
|
certificate: import("./certificate.js").Certificate;
|
|
4
4
|
}>;
|
|
5
|
-
/**
|
|
6
|
-
* @param {import('../../lib/server.js').Http3Server} server
|
|
7
|
-
* @param {string} path
|
|
8
|
-
*/
|
|
9
|
-
export function getServerSession(server: import('../../lib/server.js').Http3Server, path: string): Promise<import("../../lib/types.js").WebTransportSession>;
|
|
10
5
|
//# sourceMappingURL=server.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../test/fixtures/server.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../test/fixtures/server.js"],"names":[],"mappings":"AASA;;;GAkPC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webtransport.browser.d.ts","sourceRoot":"","sources":["../../../test/fixtures/webtransport.browser.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webtransport.d.ts","sourceRoot":"","sources":["../../../test/fixtures/webtransport.js"],"names":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write-stream.d.ts","sourceRoot":"","sources":["../../../test/fixtures/write-stream.js"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,
|
|
1
|
+
{"version":3,"file":"write-stream.d.ts","sourceRoot":"","sources":["../../../test/fixtures/write-stream.js"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,uFAeC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../test/index.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.spec.d.ts","sourceRoot":"","sources":["../../test/session.spec.js"],"names":[],"mappings":";;;0BAQa,OAAO,cAAc,EAAE,QAAQ,CAAC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unidirectional-streams.spec.d.ts","sourceRoot":"","sources":["../../test/unidirectional-streams.spec.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"unidirectional-streams.spec.d.ts","sourceRoot":"","sources":["../../test/unidirectional-streams.spec.js"],"names":[],"mappings":""}
|
package/lib/client.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { Http3WebTransport } from './transport.js'
|
|
2
|
+
import { WebTransportError } from './error.js'
|
|
3
|
+
import { logger } from './utils.js'
|
|
4
|
+
|
|
5
|
+
const log = logger(`webtransport:http3client(${process.pid})`)
|
|
2
6
|
|
|
3
7
|
/**
|
|
4
8
|
* @typedef {import('./session').Http3WTSession} Http3WTSession
|
|
9
|
+
* @typedef {import('./types').Http3ClientInit} Http3ClientInit
|
|
5
10
|
*
|
|
6
11
|
* Http3Client events
|
|
7
12
|
* @typedef {import('./types').Http3ClientEventHandler} Http3ClientEventHandler
|
|
@@ -15,7 +20,7 @@ import { Http3WebTransport } from './transport.js'
|
|
|
15
20
|
*/
|
|
16
21
|
export class Http3Client extends Http3WebTransport {
|
|
17
22
|
/**
|
|
18
|
-
* @param {
|
|
23
|
+
* @param {Http3ClientInit} args
|
|
19
24
|
*/
|
|
20
25
|
constructor(args) {
|
|
21
26
|
super(args, 'client')
|
|
@@ -35,9 +40,14 @@ export class Http3Client extends Http3WebTransport {
|
|
|
35
40
|
this.webtransportProm = null
|
|
36
41
|
/** @type {{ resolve: (value?: any) => void, reject: (err?: Error) => void} | null | undefined} */
|
|
37
42
|
this.quicconnectedProm = null
|
|
43
|
+
|
|
44
|
+
this._quicConnectTimeout = args.quicConnectTimeout ?? 8000
|
|
45
|
+
this._webTransportConnectTimeout = args.webTransportConnectTimeout ?? 2000
|
|
38
46
|
}
|
|
39
47
|
|
|
40
48
|
async handleConnection() {
|
|
49
|
+
this.createTransportInt()
|
|
50
|
+
|
|
41
51
|
this.quicconnected = new Promise((resolve, reject) => {
|
|
42
52
|
this.quicconnectedProm = { resolve, reject }
|
|
43
53
|
})
|
|
@@ -45,26 +55,18 @@ export class Http3Client extends Http3WebTransport {
|
|
|
45
55
|
this.webtransportProm = { resolve, reject }
|
|
46
56
|
})
|
|
47
57
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
new Error('Timeout webtransport support')
|
|
61
|
-
)
|
|
62
|
-
delete this.webtransportProm
|
|
63
|
-
}
|
|
64
|
-
}, 2000)
|
|
65
|
-
} catch (error) {
|
|
66
|
-
throw new Error('Cl:' + error)
|
|
67
|
-
}
|
|
58
|
+
const timeout = setTimeout(() => {
|
|
59
|
+
if (this.quicconnectedProm) {
|
|
60
|
+
log.error('quic connection timeout')
|
|
61
|
+
this.quicconnectedProm.reject(
|
|
62
|
+
new WebTransportError('Opening handshake failed.')
|
|
63
|
+
)
|
|
64
|
+
delete this.quicconnectedProm
|
|
65
|
+
}
|
|
66
|
+
}, this._quicConnectTimeout)
|
|
67
|
+
|
|
68
|
+
await this.quicconnected
|
|
69
|
+
clearTimeout(timeout)
|
|
68
70
|
}
|
|
69
71
|
|
|
70
72
|
/**
|
|
@@ -73,26 +75,36 @@ export class Http3Client extends Http3WebTransport {
|
|
|
73
75
|
* @returns
|
|
74
76
|
*/
|
|
75
77
|
async createWTSession(sessionobj, path) {
|
|
76
|
-
//
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
78
|
+
// now create Webtransport session
|
|
79
|
+
const timeout = setTimeout(() => {
|
|
80
|
+
if (this.webtransportProm) {
|
|
81
|
+
log.error('webtransport connection timeout')
|
|
82
|
+
this.webtransportProm.reject(
|
|
83
|
+
new WebTransportError('Opening handshake failed.')
|
|
84
|
+
)
|
|
85
|
+
delete this.webtransportProm
|
|
86
|
+
}
|
|
87
|
+
}, this._webTransportConnectTimeout)
|
|
88
|
+
await this.webtransport // wait for webtransport support
|
|
89
|
+
clearTimeout(timeout)
|
|
90
|
+
|
|
91
|
+
// ok now we open the session
|
|
92
|
+
this.sessionobjint = sessionobj
|
|
93
|
+
this.transportInt.openWTSession(path)
|
|
94
|
+
|
|
95
|
+
// we wait for a new session
|
|
96
|
+
const sessobj = await this.sessionobj
|
|
97
|
+
|
|
98
|
+
delete this.sessionobj
|
|
99
|
+
|
|
100
|
+
return sessobj
|
|
92
101
|
}
|
|
93
102
|
|
|
94
103
|
closeHookSession() {
|
|
95
|
-
this.transportInt
|
|
104
|
+
if (this.transportInt != null) {
|
|
105
|
+
this.transportInt.closeClient()
|
|
106
|
+
}
|
|
107
|
+
|
|
96
108
|
this.stopped = true
|
|
97
109
|
}
|
|
98
110
|
|
|
@@ -104,10 +116,11 @@ export class Http3Client extends Http3WebTransport {
|
|
|
104
116
|
if (args.success) this.quicconnectedProm.resolve()
|
|
105
117
|
else
|
|
106
118
|
this.quicconnectedProm.reject(
|
|
107
|
-
new
|
|
119
|
+
new WebTransportError('Opening handshake failed.')
|
|
108
120
|
)
|
|
109
121
|
delete this.quicconnectedProm
|
|
110
|
-
} else
|
|
122
|
+
} else
|
|
123
|
+
throw new WebTransportError('Client connected with no pending promise')
|
|
111
124
|
}
|
|
112
125
|
|
|
113
126
|
/**
|
|
@@ -132,7 +145,7 @@ export class Http3Client extends Http3WebTransport {
|
|
|
132
145
|
this.sessionProm.resolve(args.session)
|
|
133
146
|
delete this.sessionProm
|
|
134
147
|
} else {
|
|
135
|
-
throw new
|
|
148
|
+
throw new WebTransportError(
|
|
136
149
|
'Http3WTSessionVisitor no object session or nor sessionprom'
|
|
137
150
|
)
|
|
138
151
|
}
|
|
@@ -142,7 +155,8 @@ export class Http3Client extends Http3WebTransport {
|
|
|
142
155
|
* @param {ClientConnectedEvent | ClientWebtransportSupportEvent | Http3WTSessionVisitorEvent} args
|
|
143
156
|
*/
|
|
144
157
|
customCallback(args) {
|
|
145
|
-
|
|
158
|
+
log('callback', args?.purpose)
|
|
159
|
+
log.trace(args)
|
|
146
160
|
if (args.purpose) {
|
|
147
161
|
switch (args.purpose) {
|
|
148
162
|
case 'ClientConnected':
|
|
@@ -155,7 +169,7 @@ export class Http3Client extends Http3WebTransport {
|
|
|
155
169
|
this.onHttp3WTSessionVisitor(args)
|
|
156
170
|
break
|
|
157
171
|
default: {
|
|
158
|
-
throw new
|
|
172
|
+
throw new WebTransportError('unknown purpose')
|
|
159
173
|
}
|
|
160
174
|
}
|
|
161
175
|
}
|
package/lib/dom.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { ReadableStream } from 'node:stream/web'
|
|
2
|
+
|
|
1
3
|
// Types taken from https://www.w3.org/TR/webtransport
|
|
2
4
|
// These can be removed when they are added to the default typescript types
|
|
3
5
|
|
|
@@ -20,6 +22,7 @@ export interface WebTransportStats {
|
|
|
20
22
|
smoothedRtt: number
|
|
21
23
|
rttVariation: number
|
|
22
24
|
minRtt: number
|
|
25
|
+
estimatedSendRate: bigint
|
|
23
26
|
datagrams: WebTransportDatagramStats
|
|
24
27
|
}
|
|
25
28
|
|
|
@@ -38,10 +41,6 @@ export interface WebTransportDatagramDuplexStream {
|
|
|
38
41
|
// outgoingHighWaterMark: number
|
|
39
42
|
}
|
|
40
43
|
|
|
41
|
-
export interface WebTransportBidirectionalStream {
|
|
42
|
-
readonly readable: WebTransportReceiveStream
|
|
43
|
-
readonly writable: WebTransportSendStream
|
|
44
|
-
}
|
|
45
44
|
|
|
46
45
|
export interface WebTransportSendStreamStats {
|
|
47
46
|
timestamp: number
|
|
@@ -64,6 +63,11 @@ export interface WebTransportReceiveStream extends ReadableStream<Uint8Array> {
|
|
|
64
63
|
getStats: () => Promise<WebTransportReceiveStreamStats>
|
|
65
64
|
}
|
|
66
65
|
|
|
66
|
+
export interface WebTransportBidirectionalStream {
|
|
67
|
+
readonly readable: WebTransportReceiveStream
|
|
68
|
+
readonly writable: WebTransportSendStream
|
|
69
|
+
}
|
|
70
|
+
|
|
67
71
|
export interface WebTransportHash {
|
|
68
72
|
algorithm: string
|
|
69
73
|
value: BufferSource
|
|
@@ -73,6 +77,16 @@ export interface WebTransportOptions {
|
|
|
73
77
|
allowPooling?: boolean
|
|
74
78
|
requireUnreliable?: boolean
|
|
75
79
|
serverCertificateHashes?: WebTransportHash[]
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Nonstandard option - when a new connection is opened, how long to wait for the quic handshake to complete in ms before rejecting
|
|
83
|
+
*/
|
|
84
|
+
quicConnectTimeout?: number
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Nonstandard option - when a new connection is opened, how long to wait for the webtransport handshake to complete in ms before rejecting
|
|
88
|
+
*/
|
|
89
|
+
webTransportConnectTimeout?: number
|
|
76
90
|
congestionControl?: WebTransportCongestionControl
|
|
77
91
|
}
|
|
78
92
|
|
package/lib/error.js
ADDED
package/lib/event-loop.js
CHANGED
|
@@ -2,13 +2,16 @@ import { Http3WebTransport } from './transport.js'
|
|
|
2
2
|
import { Http3WTStream } from './stream.js'
|
|
3
3
|
import { Http3WTSession } from './session.js'
|
|
4
4
|
import { wtrouter } from './native.js'
|
|
5
|
+
import { logger } from './utils.js'
|
|
6
|
+
|
|
7
|
+
const log = logger(`webtransport:event-loop(${process.pid})`)
|
|
5
8
|
|
|
6
9
|
export class Http3EventLoop {
|
|
7
10
|
/** @type {Http3EventLoop | null} */
|
|
8
11
|
static globalLoop = null
|
|
9
12
|
|
|
10
13
|
/**
|
|
11
|
-
* @param {
|
|
14
|
+
* @param {{ quicheLogVerbose: any; } | undefined} [args]
|
|
12
15
|
*/
|
|
13
16
|
constructor(args) {
|
|
14
17
|
this.eventloopInt = new wtrouter.Http3EventLoop({
|
|
@@ -28,13 +31,13 @@ export class Http3EventLoop {
|
|
|
28
31
|
* @param {*} [args]
|
|
29
32
|
*/
|
|
30
33
|
startEventLoop(args) {
|
|
31
|
-
|
|
34
|
+
log('start GlobalEventLoop')
|
|
32
35
|
this.eventloopInt.startEventLoop(args)
|
|
33
36
|
this.loopGuardianTimer = setInterval(this.loopGuardian, 5000)
|
|
34
37
|
}
|
|
35
38
|
|
|
36
39
|
shutdownEventLoop() {
|
|
37
|
-
|
|
40
|
+
log('shutdown GlobalEventLoop')
|
|
38
41
|
Http3EventLoop.globalLoop = null
|
|
39
42
|
clearInterval(this.loopGuardianTimer)
|
|
40
43
|
this.eventloopInt.shutDownEventLoop()
|
|
@@ -54,7 +57,7 @@ export class Http3EventLoop {
|
|
|
54
57
|
}
|
|
55
58
|
|
|
56
59
|
static callback() {
|
|
57
|
-
|
|
60
|
+
log('final eventloop callback called')
|
|
58
61
|
}
|
|
59
62
|
|
|
60
63
|
/**
|
|
@@ -65,7 +68,7 @@ export class Http3EventLoop {
|
|
|
65
68
|
if (!Http3EventLoop.globalLoop) {
|
|
66
69
|
Http3EventLoop.globalLoop = new Http3EventLoop()
|
|
67
70
|
Http3EventLoop.globalLoop.startEventLoop(args)
|
|
68
|
-
|
|
71
|
+
log('createGlobalEventLoop')
|
|
69
72
|
}
|
|
70
73
|
return Http3EventLoop.globalLoop
|
|
71
74
|
}
|
package/lib/native.js
CHANGED
|
@@ -3,6 +3,9 @@ import { createRequire } from 'module'
|
|
|
3
3
|
import * as path from 'path'
|
|
4
4
|
import * as url from 'url'
|
|
5
5
|
import { arch, platform } from 'node:process'
|
|
6
|
+
import { logger } from './utils.js'
|
|
7
|
+
|
|
8
|
+
const log = logger(`webtransport:native(${process.pid})`)
|
|
6
9
|
|
|
7
10
|
const binplatform = platform + '_' + arch
|
|
8
11
|
const require = createRequire(import.meta.url)
|
|
@@ -20,6 +23,6 @@ if (
|
|
|
20
23
|
wtpath = buildpath + '/Debug/webtransport.node'
|
|
21
24
|
}
|
|
22
25
|
|
|
23
|
-
|
|
26
|
+
log('load webtransport binary:', wtpath)
|
|
24
27
|
|
|
25
28
|
export const wtrouter = require(wtpath)
|
package/lib/server.js
CHANGED
|
@@ -2,8 +2,9 @@ import { Http3WebTransport } from './transport.js'
|
|
|
2
2
|
import { ReadableStream } from 'node:stream/web'
|
|
3
3
|
import { Http3WTSession } from './session.js'
|
|
4
4
|
import { isIPv4 } from 'net'
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
import { defer, logger } from './utils.js'
|
|
6
|
+
|
|
7
|
+
const log = logger(`webtransport:http3server(${process.pid})`)
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* @typedef {import('./types').WebTransportSession} WebTransportSession
|
|
@@ -47,6 +48,7 @@ export class Http3Server extends Http3WebTransport {
|
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
startServer() {
|
|
51
|
+
this.createTransportInt()
|
|
50
52
|
this.transportInt.startServer()
|
|
51
53
|
}
|
|
52
54
|
|
|
@@ -86,7 +88,8 @@ export class Http3Server extends Http3WebTransport {
|
|
|
86
88
|
|
|
87
89
|
/**
|
|
88
90
|
* @param {string} path
|
|
89
|
-
* @param {
|
|
91
|
+
* @param {object} [args]
|
|
92
|
+
* @param {boolean} [args.noAutoPaths]
|
|
90
93
|
* @returns {ReadableStream<WebTransportSession>}
|
|
91
94
|
*/
|
|
92
95
|
sessionStream(path, args) {
|
|
@@ -98,7 +101,9 @@ export class Http3Server extends Http3WebTransport {
|
|
|
98
101
|
this.sessionController[path] = controller
|
|
99
102
|
}
|
|
100
103
|
})
|
|
101
|
-
if (!args || !args.noAutoPaths)
|
|
104
|
+
if (!args || !args.noAutoPaths) {
|
|
105
|
+
this.transportInt.addPath(path)
|
|
106
|
+
}
|
|
102
107
|
return this.sessionStreams[path]
|
|
103
108
|
}
|
|
104
109
|
|
|
@@ -108,17 +113,19 @@ export class Http3Server extends Http3WebTransport {
|
|
|
108
113
|
onSessionRequest(args) {
|
|
109
114
|
if (args.promise && args.header) {
|
|
110
115
|
if (!this.requestHandler) throw new Error('Request handler not set')
|
|
111
|
-
this.requestHandler({ header: args.header })
|
|
112
|
-
(/** @type {any} */ result) => {
|
|
113
|
-
|
|
116
|
+
this.requestHandler({ header: args.header })
|
|
117
|
+
.then((/** @type {any} */ result) => {
|
|
118
|
+
log('oSR', result)
|
|
114
119
|
this.transportInt.finishSessionRequest({
|
|
115
120
|
promise: args.promise,
|
|
116
121
|
header: args.header,
|
|
117
122
|
session: args.session,
|
|
118
123
|
...result
|
|
119
124
|
})
|
|
120
|
-
}
|
|
121
|
-
|
|
125
|
+
})
|
|
126
|
+
.catch((/** @type {any} */ err) => {
|
|
127
|
+
log.error(err)
|
|
128
|
+
})
|
|
122
129
|
} else throw new Error('onSessionRequest')
|
|
123
130
|
}
|
|
124
131
|
|
|
@@ -183,7 +190,8 @@ export class Http3Server extends Http3WebTransport {
|
|
|
183
190
|
* @param {Http3WTServerSessionVisitorEvent | ServerStatusEvent | ServerSessionRequestEvent} args
|
|
184
191
|
*/
|
|
185
192
|
customCallback(args) {
|
|
186
|
-
|
|
193
|
+
log('callback', args?.purpose)
|
|
194
|
+
log.trace(args)
|
|
187
195
|
if (args.purpose) {
|
|
188
196
|
switch (args.purpose) {
|
|
189
197
|
case 'SessionRequest':
|