@fails-components/webtransport 0.1.0-macarmbuild.5 → 0.1.0
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 +1 -0
- package/dist/lib/client.d.ts +74 -0
- package/dist/lib/client.d.ts.map +1 -0
- package/dist/lib/dom.d.ts +70 -0
- package/dist/lib/dom.d.ts.map +1 -0
- package/dist/lib/event-loop.d.ts +26 -0
- package/dist/lib/event-loop.d.ts.map +1 -0
- package/dist/lib/index.d.ts +79 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/native.d.ts +2 -0
- package/dist/lib/native.d.ts.map +1 -0
- package/dist/lib/server.d.ts +88 -0
- package/dist/lib/server.d.ts.map +1 -0
- package/dist/lib/session.d.ts +225 -0
- package/dist/lib/session.d.ts.map +1 -0
- package/dist/lib/stream.d.ts +116 -0
- package/dist/lib/stream.d.ts.map +1 -0
- package/dist/lib/transport.d.ts +25 -0
- package/dist/lib/transport.d.ts.map +1 -0
- package/dist/lib/types.d.ts +164 -0
- package/dist/lib/types.d.ts.map +1 -0
- package/dist/lib/utils.d.ts +6 -0
- package/dist/lib/utils.d.ts.map +1 -0
- package/dist/lib/webtransport.d.ts +35 -0
- package/dist/lib/webtransport.d.ts.map +1 -0
- package/dist/test/bidirectional-streams.spec.d.ts +5 -0
- package/dist/test/bidirectional-streams.spec.d.ts.map +1 -0
- package/dist/test/datagrams.spec.d.ts +5 -0
- package/dist/test/datagrams.spec.d.ts.map +1 -0
- package/dist/test/echoclient.d.ts +2 -0
- package/dist/test/echoclient.d.ts.map +1 -0
- package/dist/test/echoserver.d.ts +2 -0
- package/dist/test/echoserver.d.ts.map +1 -0
- package/dist/test/event-loop.spec.d.ts +2 -0
- package/dist/test/event-loop.spec.d.ts.map +1 -0
- package/dist/test/fixtures/certificate.d.ts +21 -0
- package/dist/test/fixtures/certificate.d.ts.map +1 -0
- package/dist/test/fixtures/chai.d.ts +2 -0
- package/dist/test/fixtures/chai.d.ts.map +1 -0
- package/dist/test/fixtures/read-stream.d.ts +10 -0
- package/dist/test/fixtures/read-stream.d.ts.map +1 -0
- package/dist/test/fixtures/reader-value.d.ts +7 -0
- package/dist/test/fixtures/reader-value.d.ts.map +1 -0
- package/dist/test/fixtures/server.d.ts +10 -0
- package/dist/test/fixtures/server.d.ts.map +1 -0
- package/dist/test/fixtures/write-stream.d.ts +10 -0
- package/dist/test/fixtures/write-stream.d.ts.map +1 -0
- package/dist/test/test.d.ts +2 -0
- package/dist/test/test.d.ts.map +1 -0
- package/dist/test/testsuite.d.ts +25 -0
- package/dist/test/testsuite.d.ts.map +1 -0
- package/dist/test/unidirectional-streams.spec.d.ts +5 -0
- package/dist/test/unidirectional-streams.spec.d.ts.map +1 -0
- package/lib/index.js +1 -0
- package/lib/server.js +44 -4
- package/lib/session.js +3 -0
- package/lib/types.ts +16 -0
- package/lib/utils.js +1 -2
- package/package.json +5 -2
- package/src/http3eventloop.cc +124 -32
- package/src/http3eventloop.h +30 -17
- package/src/http3server.cc +111 -0
- package/src/http3server.h +14 -6
- package/src/http3serverbackend.cc +31 -18
- package/src/http3serverbackend.h +38 -3
- package/src/http3serverstream.cc +19 -6
- package/src/http3serverstream.h +2 -0
- package/src/http3wtstreamvisitor.cc +3 -0
- package/src/http3wtstreamvisitor.h +3 -1
- package/test/bidirectional-streams.spec.js +3 -2
- package/test/datagrams.spec.js +3 -2
- package/test/{event-loop.specoff.js → event-loop.spec.js} +7 -6
- package/test/fixtures/certificate.js +9 -9
- package/test/fixtures/chai.js +6 -0
- package/test/fixtures/reader-value.js +1 -2
- package/test/fixtures/write-stream.js +1 -2
- package/test/unidirectional-streams.spec.js +54 -1
- package/test/suite.specoff.js +0 -9
package/lib/server.js
CHANGED
|
@@ -11,6 +11,8 @@ import { defer } from './utils.js'
|
|
|
11
11
|
* @typedef {import('./types').Http3ServerEventHandler} Http3ServerEventHandler
|
|
12
12
|
* @typedef {import('./types').Http3WTServerSessionVisitorEvent} Http3WTServerSessionVisitorEvent
|
|
13
13
|
* @typedef {import('./types').ServerStatusEvent} ServerStatusEvent
|
|
14
|
+
* @typedef {import('./types').ServerSessionRequestEvent} ServerSessionRequestEvent
|
|
15
|
+
* @typedef {import('./types').Http3ServerInit} Http3ServerInit
|
|
14
16
|
*/
|
|
15
17
|
|
|
16
18
|
/**
|
|
@@ -19,7 +21,7 @@ import { defer } from './utils.js'
|
|
|
19
21
|
export class Http3Server extends Http3WebTransport {
|
|
20
22
|
/**
|
|
21
23
|
*
|
|
22
|
-
* @param {
|
|
24
|
+
* @param {Http3ServerInit} args
|
|
23
25
|
*/
|
|
24
26
|
constructor(args) {
|
|
25
27
|
super(args, 'server')
|
|
@@ -33,6 +35,10 @@ export class Http3Server extends Http3WebTransport {
|
|
|
33
35
|
this.port = null
|
|
34
36
|
this.host = null
|
|
35
37
|
|
|
38
|
+
// FIX ME TYPE
|
|
39
|
+
/** @type {any} */
|
|
40
|
+
this.requestHandler = null
|
|
41
|
+
|
|
36
42
|
this._ready = defer()
|
|
37
43
|
this.ready = this._ready.promise
|
|
38
44
|
|
|
@@ -69,11 +75,21 @@ export class Http3Server extends Http3WebTransport {
|
|
|
69
75
|
}
|
|
70
76
|
}
|
|
71
77
|
|
|
78
|
+
/**
|
|
79
|
+
* @param {any} callback
|
|
80
|
+
*/
|
|
81
|
+
setRequestCallback(callback) {
|
|
82
|
+
this.requestHandler = callback
|
|
83
|
+
|
|
84
|
+
this.transportInt.setJSRequestHandler(!!callback)
|
|
85
|
+
}
|
|
86
|
+
|
|
72
87
|
/**
|
|
73
88
|
* @param {string} path
|
|
89
|
+
* @param {any | undefined} [args=undefined]
|
|
74
90
|
* @returns {ReadableStream<WebTransportSession>}
|
|
75
91
|
*/
|
|
76
|
-
sessionStream(path) {
|
|
92
|
+
sessionStream(path, args) {
|
|
77
93
|
if (path in this.sessionStreams) {
|
|
78
94
|
return this.sessionStreams[path]
|
|
79
95
|
}
|
|
@@ -82,10 +98,30 @@ export class Http3Server extends Http3WebTransport {
|
|
|
82
98
|
this.sessionController[path] = controller
|
|
83
99
|
}
|
|
84
100
|
})
|
|
85
|
-
this.transportInt.addPath(path)
|
|
101
|
+
if (!args || !args.noAutoPaths) this.transportInt.addPath(path)
|
|
86
102
|
return this.sessionStreams[path]
|
|
87
103
|
}
|
|
88
104
|
|
|
105
|
+
/**
|
|
106
|
+
* @param {ServerSessionRequestEvent} args
|
|
107
|
+
*/
|
|
108
|
+
onSessionRequest(args) {
|
|
109
|
+
if (args.promise && args.header) {
|
|
110
|
+
if (!this.requestHandler) throw new Error('Request handler not set')
|
|
111
|
+
this.requestHandler({ header: args.header }).then(
|
|
112
|
+
(/** @type {any} */ result) => {
|
|
113
|
+
console.log('oSR', result)
|
|
114
|
+
this.transportInt.finishSessionRequest({
|
|
115
|
+
promise: args.promise,
|
|
116
|
+
header: args.header,
|
|
117
|
+
session: args.session,
|
|
118
|
+
...result
|
|
119
|
+
})
|
|
120
|
+
}
|
|
121
|
+
)
|
|
122
|
+
} else throw new Error('onSessionRequest')
|
|
123
|
+
}
|
|
124
|
+
|
|
89
125
|
/**
|
|
90
126
|
* @param {Http3WTServerSessionVisitorEvent} args
|
|
91
127
|
*/
|
|
@@ -94,6 +130,7 @@ export class Http3Server extends Http3WebTransport {
|
|
|
94
130
|
if (args.object) {
|
|
95
131
|
const sesobj = new Http3WTSession({
|
|
96
132
|
object: args.session,
|
|
133
|
+
header: args.header,
|
|
97
134
|
parentobj: this
|
|
98
135
|
})
|
|
99
136
|
if (this.sessionController[args.path])
|
|
@@ -143,12 +180,15 @@ export class Http3Server extends Http3WebTransport {
|
|
|
143
180
|
}
|
|
144
181
|
|
|
145
182
|
/**
|
|
146
|
-
* @param {Http3WTServerSessionVisitorEvent | ServerStatusEvent} args
|
|
183
|
+
* @param {Http3WTServerSessionVisitorEvent | ServerStatusEvent | ServerSessionRequestEvent} args
|
|
147
184
|
*/
|
|
148
185
|
customCallback(args) {
|
|
149
186
|
// console.log('incoming callback server', args)
|
|
150
187
|
if (args.purpose) {
|
|
151
188
|
switch (args.purpose) {
|
|
189
|
+
case 'SessionRequest':
|
|
190
|
+
this.onSessionRequest(args)
|
|
191
|
+
break
|
|
152
192
|
case 'Http3WTSessionVisitor':
|
|
153
193
|
this.onHttp3WTSessionVisitor(args)
|
|
154
194
|
break
|
package/lib/session.js
CHANGED
|
@@ -35,6 +35,7 @@ export class Http3WTSession {
|
|
|
35
35
|
* @param {object} args
|
|
36
36
|
* @param {import('./types').NativeHttp3WTSession} [args.object]
|
|
37
37
|
* @param {Http3Server | Http3Client} args.parentobj
|
|
38
|
+
* @param {any | undefined} [args.header= undefined]
|
|
38
39
|
*/
|
|
39
40
|
constructor(args) {
|
|
40
41
|
if (args.object) {
|
|
@@ -49,6 +50,8 @@ export class Http3WTSession {
|
|
|
49
50
|
this.readyResolve = null
|
|
50
51
|
/** @type {(() => void) | null | undefined} */
|
|
51
52
|
this.closeHook = null
|
|
53
|
+
/** @type {(any | null | undefined)} */
|
|
54
|
+
this.header = args.header
|
|
52
55
|
|
|
53
56
|
/** @type {Promise<void>} */
|
|
54
57
|
this.ready = new Promise((resolve, reject) => {
|
package/lib/types.ts
CHANGED
|
@@ -129,6 +129,14 @@ export interface Http3ClientEventHandler {
|
|
|
129
129
|
export interface Http3WTServerSessionVisitorEvent extends Http3WTSessionVisitorEvent {
|
|
130
130
|
path: string
|
|
131
131
|
object: any
|
|
132
|
+
header?: any
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export interface ServerSessionRequestEvent {
|
|
136
|
+
purpose: 'SessionRequest'
|
|
137
|
+
header: Object
|
|
138
|
+
promise: any
|
|
139
|
+
session: any
|
|
132
140
|
}
|
|
133
141
|
|
|
134
142
|
/**
|
|
@@ -171,3 +179,11 @@ export type WebTransportSessionState = 'connected' | 'closed' | 'failed'
|
|
|
171
179
|
export interface WebTransportSession extends WebTransport {
|
|
172
180
|
state: WebTransportSessionState
|
|
173
181
|
}
|
|
182
|
+
|
|
183
|
+
export interface Http3ServerInit {
|
|
184
|
+
port: number
|
|
185
|
+
host: string
|
|
186
|
+
secret: string
|
|
187
|
+
cert: string
|
|
188
|
+
privKey: string
|
|
189
|
+
}
|
package/lib/utils.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fails-components/webtransport",
|
|
3
|
-
"version": "0.1.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "A component to add webtransport support (server and client) to node.js using libquiche",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "lib/index.js",
|
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
"rebuild": "node build.js rebuild",
|
|
19
19
|
"rebuild-debug": "node build.js rebuild-debug -D",
|
|
20
20
|
"build-debug": "node build.js build-debug",
|
|
21
|
-
"types": "tsc"
|
|
21
|
+
"types": "tsc",
|
|
22
|
+
"lint": "eslint lib test"
|
|
22
23
|
},
|
|
23
24
|
"repository": {
|
|
24
25
|
"type": "git",
|
|
@@ -42,10 +43,12 @@
|
|
|
42
43
|
"@babel/core": "^7.17.10",
|
|
43
44
|
"@babel/eslint-parser": "^7.17.0",
|
|
44
45
|
"@types/chai": "^4.3.3",
|
|
46
|
+
"@types/dirty-chai": "^2.0.2",
|
|
45
47
|
"@types/mocha": "^10.0.0",
|
|
46
48
|
"@types/node": "^18.11.5",
|
|
47
49
|
"chai": "^4.3.6",
|
|
48
50
|
"cmake-js": "^6.3.2",
|
|
51
|
+
"dirty-chai": "^2.0.1",
|
|
49
52
|
"eslint": "^7.32.0",
|
|
50
53
|
"eslint-config-prettier": "^7.2.0",
|
|
51
54
|
"eslint-config-standard": "^16.0.2",
|
package/src/http3eventloop.cc
CHANGED
|
@@ -253,12 +253,25 @@ namespace quic
|
|
|
253
253
|
progress_->Send(&report, 1);
|
|
254
254
|
}
|
|
255
255
|
|
|
256
|
-
void Http3EventLoop::
|
|
256
|
+
void Http3EventLoop::informAboutNewSessionRequest(Http3Server *server, WebTransportSession *session, spdy::Http2HeaderBlock *reqheadcopy, WebTransportRespPromisePtr promise)
|
|
257
|
+
{
|
|
258
|
+
struct Http3ProgressReport report;
|
|
259
|
+
report.type = Http3ProgressReport::NewSessionRequest;
|
|
260
|
+
report.webtsession = session;
|
|
261
|
+
report.serverobj = server;
|
|
262
|
+
report.headerblock = reqheadcopy;
|
|
263
|
+
report.promise = new WebTransportRespPromisePtr(promise);
|
|
264
|
+
if (progress_)
|
|
265
|
+
progress_->Send(&report, 1);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
void Http3EventLoop::informAboutNewSession(Http3Server *server, Http3WTSession *session, absl::string_view path, Napi::Reference<Napi::Value> *header)
|
|
257
269
|
{
|
|
258
270
|
struct Http3ProgressReport report;
|
|
259
271
|
report.type = Http3ProgressReport::NewSession;
|
|
260
272
|
report.serverobj = server;
|
|
261
273
|
report.session = session;
|
|
274
|
+
report.header = header;
|
|
262
275
|
report.para = new std::string(path);
|
|
263
276
|
if (progress_)
|
|
264
277
|
progress_->Send(&report, 1);
|
|
@@ -295,7 +308,7 @@ namespace quic
|
|
|
295
308
|
progress_->Send(&report, 1);
|
|
296
309
|
}
|
|
297
310
|
|
|
298
|
-
void Http3EventLoop::informServerStatus(Http3Server *serverobj, NetworkStatus status, ServerStatusDetails*
|
|
311
|
+
void Http3EventLoop::informServerStatus(Http3Server *serverobj, NetworkStatus status, ServerStatusDetails *details)
|
|
299
312
|
{
|
|
300
313
|
struct Http3ProgressReport report;
|
|
301
314
|
report.type = Http3ProgressReport::ServerStatus;
|
|
@@ -314,7 +327,8 @@ namespace quic
|
|
|
314
327
|
|
|
315
328
|
void Http3EventLoop::processClientConnected(Http3Client *clientobj, bool success)
|
|
316
329
|
{
|
|
317
|
-
if (!checkQw())
|
|
330
|
+
if (!checkQw())
|
|
331
|
+
return;
|
|
318
332
|
HandleScope scope(qw_->Env());
|
|
319
333
|
auto client = clientobj->getJS();
|
|
320
334
|
|
|
@@ -330,7 +344,8 @@ namespace quic
|
|
|
330
344
|
|
|
331
345
|
void Http3EventLoop::processClientWebtransportSupport(Http3Client *clientobj)
|
|
332
346
|
{
|
|
333
|
-
if (!checkQw())
|
|
347
|
+
if (!checkQw())
|
|
348
|
+
return;
|
|
334
349
|
HandleScope scope(qw_->Env());
|
|
335
350
|
|
|
336
351
|
auto client = clientobj->getJS();
|
|
@@ -345,7 +360,8 @@ namespace quic
|
|
|
345
360
|
|
|
346
361
|
void Http3EventLoop::processStream(bool incom, bool bidi, Http3WTSession *sessionobj, Http3WTStream *stream)
|
|
347
362
|
{
|
|
348
|
-
if (!checkQw())
|
|
363
|
+
if (!checkQw())
|
|
364
|
+
return;
|
|
349
365
|
HandleScope scope(qw_->Env());
|
|
350
366
|
|
|
351
367
|
Http3Constructors *constr = qw_->Env().GetInstanceData<Http3Constructors>();
|
|
@@ -369,7 +385,8 @@ namespace quic
|
|
|
369
385
|
|
|
370
386
|
void Http3EventLoop::processStreamRecvSignal(Http3WTStream *streamobj, WebTransportStreamError error_code, NetworkTask task)
|
|
371
387
|
{
|
|
372
|
-
if (!checkQw())
|
|
388
|
+
if (!checkQw())
|
|
389
|
+
return;
|
|
373
390
|
HandleScope scope(qw_->Env());
|
|
374
391
|
auto stream = streamobj->getJS();
|
|
375
392
|
if (!stream)
|
|
@@ -409,7 +426,8 @@ namespace quic
|
|
|
409
426
|
|
|
410
427
|
void Http3EventLoop::processStreamRead(Http3WTStream *streamobj, std::string *data, bool fin)
|
|
411
428
|
{
|
|
412
|
-
if (!checkQw())
|
|
429
|
+
if (!checkQw())
|
|
430
|
+
return;
|
|
413
431
|
HandleScope scope(qw_->Env());
|
|
414
432
|
|
|
415
433
|
Napi::Object dataVal =
|
|
@@ -435,7 +453,8 @@ namespace quic
|
|
|
435
453
|
|
|
436
454
|
void Http3EventLoop::processStreamWrite(Http3WTStream *streamobj, Napi::ObjectReference *bufferhandle, bool success)
|
|
437
455
|
{
|
|
438
|
-
if (!checkQw())
|
|
456
|
+
if (!checkQw())
|
|
457
|
+
return;
|
|
439
458
|
HandleScope scope(qw_->Env());
|
|
440
459
|
|
|
441
460
|
auto stream = streamobj->getJS();
|
|
@@ -456,7 +475,8 @@ namespace quic
|
|
|
456
475
|
|
|
457
476
|
void Http3EventLoop::processStreamReset(Http3WTStream *streamobj)
|
|
458
477
|
{
|
|
459
|
-
if (!checkQw())
|
|
478
|
+
if (!checkQw())
|
|
479
|
+
return;
|
|
460
480
|
HandleScope scope(qw_->Env());
|
|
461
481
|
|
|
462
482
|
auto stream = streamobj->getJS();
|
|
@@ -474,7 +494,8 @@ namespace quic
|
|
|
474
494
|
|
|
475
495
|
void Http3EventLoop::processStreamNetworkFinish(Http3WTStream *streamobj, NetworkTask task)
|
|
476
496
|
{
|
|
477
|
-
if (!checkQw())
|
|
497
|
+
if (!checkQw())
|
|
498
|
+
return;
|
|
478
499
|
HandleScope scope(qw_->Env());
|
|
479
500
|
|
|
480
501
|
auto stream = streamobj->getJS();
|
|
@@ -520,7 +541,8 @@ namespace quic
|
|
|
520
541
|
|
|
521
542
|
void Http3EventLoop::processDatagramReceived(Http3WTSession *sessionobj, std::string *datagram)
|
|
522
543
|
{
|
|
523
|
-
if (!checkQw())
|
|
544
|
+
if (!checkQw())
|
|
545
|
+
return;
|
|
524
546
|
HandleScope scope(qw_->Env());
|
|
525
547
|
Napi::Object datagramVal =
|
|
526
548
|
Napi::Uint8Array::New(qw_->Env(),
|
|
@@ -544,7 +566,8 @@ namespace quic
|
|
|
544
566
|
|
|
545
567
|
void Http3EventLoop::processDatagramSend(Http3WTSession *sessionobj)
|
|
546
568
|
{
|
|
547
|
-
if (!checkQw())
|
|
569
|
+
if (!checkQw())
|
|
570
|
+
return;
|
|
548
571
|
HandleScope scope(qw_->Env());
|
|
549
572
|
auto session = sessionobj->getJS();
|
|
550
573
|
if (!session)
|
|
@@ -558,9 +581,55 @@ namespace quic
|
|
|
558
581
|
cbsession_.Call({retObj});
|
|
559
582
|
}
|
|
560
583
|
|
|
561
|
-
void Http3EventLoop::
|
|
584
|
+
void Http3EventLoop::processNewSessionRequest(Http3Server *serverobj, WebTransportSession *session, spdy::Http2HeaderBlock *reqheadcopy, WebTransportRespPromisePtr *promise)
|
|
562
585
|
{
|
|
563
|
-
if (!checkQw())
|
|
586
|
+
if (!checkQw())
|
|
587
|
+
return;
|
|
588
|
+
HandleScope scope(qw_->Env());
|
|
589
|
+
|
|
590
|
+
Napi::Object objVal = serverobj->getJS()->Value();
|
|
591
|
+
|
|
592
|
+
Napi::Object retObj = Napi::Object::New(qw_->Env());
|
|
593
|
+
|
|
594
|
+
retObj.Set("purpose", "SessionRequest");
|
|
595
|
+
// header
|
|
596
|
+
|
|
597
|
+
Napi::Object headObj = Napi::Object::New(qw_->Env());
|
|
598
|
+
for (auto pair : *reqheadcopy)
|
|
599
|
+
{
|
|
600
|
+
// we iterate over all header fields
|
|
601
|
+
headObj.Set(std::string(pair.first), std::string(pair.second));
|
|
602
|
+
}
|
|
603
|
+
retObj.Set("header", headObj);
|
|
604
|
+
delete reqheadcopy; // we own it and must free it!
|
|
605
|
+
|
|
606
|
+
// promise
|
|
607
|
+
Napi::External<WebTransportRespPromisePtr> promObj =
|
|
608
|
+
Napi::External<WebTransportRespPromisePtr>::New(qw_->Env(), promise,
|
|
609
|
+
[](Napi::Env /*env*/, WebTransportRespPromisePtr *ref)
|
|
610
|
+
{
|
|
611
|
+
delete ref; // we own it and must delete it
|
|
612
|
+
});
|
|
613
|
+
retObj.Set("promise", promObj);
|
|
614
|
+
|
|
615
|
+
Napi::External<WebTransportSession> wtsObj =
|
|
616
|
+
Napi::External<WebTransportSession>::New(qw_->Env(), session,
|
|
617
|
+
[](Napi::Env /*env*/, WebTransportSession *ref)
|
|
618
|
+
{
|
|
619
|
+
// we do not own it! And do not delete it.
|
|
620
|
+
// does it outlife everything?
|
|
621
|
+
});
|
|
622
|
+
retObj.Set("session", wtsObj);
|
|
623
|
+
|
|
624
|
+
retObj.Set("object", objVal);
|
|
625
|
+
|
|
626
|
+
cbtransport_.Call({retObj});
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
void Http3EventLoop::processNewSession(Http3Server *serverobj, Http3WTSession *session, const std::string &path, Napi::Reference<Napi::Value> *header)
|
|
630
|
+
{
|
|
631
|
+
if (!checkQw())
|
|
632
|
+
return;
|
|
564
633
|
HandleScope scope(qw_->Env());
|
|
565
634
|
|
|
566
635
|
Http3Constructors *constr = qw_->Env().GetInstanceData<Http3Constructors>();
|
|
@@ -577,13 +646,20 @@ namespace quic
|
|
|
577
646
|
retObj.Set("session", sessionobj);
|
|
578
647
|
retObj.Set("path", path);
|
|
579
648
|
retObj.Set("object", objVal);
|
|
649
|
+
if (header)
|
|
650
|
+
{
|
|
651
|
+
retObj.Set("header", header->Value());
|
|
652
|
+
header->Unref();
|
|
653
|
+
delete header;
|
|
654
|
+
}
|
|
580
655
|
|
|
581
656
|
cbtransport_.Call({retObj});
|
|
582
657
|
}
|
|
583
658
|
|
|
584
659
|
void Http3EventLoop::processNewClientSession(Http3Client *clientobj, Http3WTSession *session)
|
|
585
660
|
{
|
|
586
|
-
if (!checkQw())
|
|
661
|
+
if (!checkQw())
|
|
662
|
+
return;
|
|
587
663
|
HandleScope scope(qw_->Env());
|
|
588
664
|
|
|
589
665
|
Napi::Object retObj = Napi::Object::New(qw_->Env());
|
|
@@ -607,7 +683,8 @@ namespace quic
|
|
|
607
683
|
|
|
608
684
|
void Http3EventLoop::processSessionReady(Http3WTSession *sessionobj)
|
|
609
685
|
{
|
|
610
|
-
if (!checkQw())
|
|
686
|
+
if (!checkQw())
|
|
687
|
+
return;
|
|
611
688
|
HandleScope scope(qw_->Env());
|
|
612
689
|
auto session = sessionobj->getJS();
|
|
613
690
|
if (!session)
|
|
@@ -623,7 +700,8 @@ namespace quic
|
|
|
623
700
|
|
|
624
701
|
void Http3EventLoop::processSessionClose(Http3WTSession *sessionobj, uint32_t errorcode, const std::string &error)
|
|
625
702
|
{
|
|
626
|
-
if (!checkQw())
|
|
703
|
+
if (!checkQw())
|
|
704
|
+
return;
|
|
627
705
|
HandleScope scope(qw_->Env());
|
|
628
706
|
|
|
629
707
|
auto session = sessionobj->getJS();
|
|
@@ -642,9 +720,10 @@ namespace quic
|
|
|
642
720
|
cbsession_.Call({retObj});
|
|
643
721
|
}
|
|
644
722
|
|
|
645
|
-
void Http3EventLoop::processServerStatus(Http3Server *serverobj, NetworkStatus status, ServerStatusDetails *
|
|
723
|
+
void Http3EventLoop::processServerStatus(Http3Server *serverobj, NetworkStatus status, ServerStatusDetails *details)
|
|
646
724
|
{
|
|
647
|
-
if (!checkQw())
|
|
725
|
+
if (!checkQw())
|
|
726
|
+
return;
|
|
648
727
|
HandleScope scope(qw_->Env());
|
|
649
728
|
|
|
650
729
|
Napi::Object objVal = serverobj->getJS()->Value();
|
|
@@ -660,19 +739,27 @@ namespace quic
|
|
|
660
739
|
delete details; // we own it and must throw it away
|
|
661
740
|
switch (status)
|
|
662
741
|
{
|
|
663
|
-
|
|
742
|
+
case NetError:
|
|
743
|
+
{
|
|
664
744
|
retObj.Set("status", "error");
|
|
665
|
-
|
|
666
|
-
|
|
745
|
+
}
|
|
746
|
+
break;
|
|
747
|
+
case NetListening:
|
|
748
|
+
{
|
|
667
749
|
retObj.Set("status", "listening");
|
|
668
|
-
|
|
669
|
-
|
|
750
|
+
}
|
|
751
|
+
break;
|
|
752
|
+
case NetClose:
|
|
753
|
+
{
|
|
670
754
|
retObj.Set("status", "close");
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
755
|
+
}
|
|
756
|
+
break;
|
|
757
|
+
default:
|
|
758
|
+
{
|
|
759
|
+
Napi::Error::New(Env(), "Unknown status from server").ThrowAsJavaScriptException();
|
|
760
|
+
return;
|
|
761
|
+
}
|
|
762
|
+
break;
|
|
676
763
|
};
|
|
677
764
|
cbtransport_.Call({retObj});
|
|
678
765
|
}
|
|
@@ -699,9 +786,14 @@ namespace quic
|
|
|
699
786
|
processNewClientSession(cur.clientobj, cur.session);
|
|
700
787
|
}
|
|
701
788
|
break;
|
|
789
|
+
case Http3ProgressReport::NewSessionRequest:
|
|
790
|
+
{
|
|
791
|
+
processNewSessionRequest(cur.serverobj, cur.webtsession, cur.headerblock, cur.promise);
|
|
792
|
+
}
|
|
793
|
+
break;
|
|
702
794
|
case Http3ProgressReport::NewSession:
|
|
703
795
|
{
|
|
704
|
-
processNewSession(cur.serverobj, cur.session, *cur.para);
|
|
796
|
+
processNewSession(cur.serverobj, cur.session, *cur.para, cur.header);
|
|
705
797
|
}
|
|
706
798
|
break;
|
|
707
799
|
case Http3ProgressReport::SessionReady:
|
|
@@ -791,7 +883,6 @@ namespace quic
|
|
|
791
883
|
if (cur.para)
|
|
792
884
|
delete cur.para;
|
|
793
885
|
}
|
|
794
|
-
|
|
795
886
|
}
|
|
796
887
|
|
|
797
888
|
Http3EventLoop::Http3EventLoop(const Napi::CallbackInfo &info)
|
|
@@ -866,7 +957,8 @@ namespace quic
|
|
|
866
957
|
// got the object we can now start the server
|
|
867
958
|
Ref(); // do not garbage collect
|
|
868
959
|
// epoll_server_.set_timeout_in_us(-1); // negative values would mean wait forever
|
|
869
|
-
if (!checkQw())
|
|
960
|
+
if (!checkQw())
|
|
961
|
+
return;
|
|
870
962
|
qw_->Queue(); // from asyncprogressqueue worker
|
|
871
963
|
}
|
|
872
964
|
|
package/src/http3eventloop.h
CHANGED
|
@@ -33,6 +33,7 @@ namespace quic
|
|
|
33
33
|
class Http3WTSession;
|
|
34
34
|
class Http3WTStream;
|
|
35
35
|
class Http3EventLoop;
|
|
36
|
+
class WebTransportRespPromise;
|
|
36
37
|
|
|
37
38
|
class LifetimeHelper
|
|
38
39
|
{
|
|
@@ -58,10 +59,10 @@ namespace quic
|
|
|
58
59
|
{
|
|
59
60
|
Napi::FunctionReference stream;
|
|
60
61
|
Napi::FunctionReference session;
|
|
61
|
-
|
|
62
62
|
};
|
|
63
63
|
|
|
64
|
-
struct ServerStatusDetails
|
|
64
|
+
struct ServerStatusDetails
|
|
65
|
+
{
|
|
65
66
|
std::string host;
|
|
66
67
|
int port;
|
|
67
68
|
};
|
|
@@ -69,12 +70,15 @@ namespace quic
|
|
|
69
70
|
class Http3ProgressReport // actually struct would be a better fit but make napi happy
|
|
70
71
|
{
|
|
71
72
|
public:
|
|
73
|
+
using WebTransportRespPromise = JSlikePromise<Http3ServerBackend::WebTransportResponse>;
|
|
74
|
+
using WebTransportRespPromisePtr = std::shared_ptr<Http3ServerBackend::WebTransportRespPromise>;
|
|
72
75
|
enum
|
|
73
76
|
{
|
|
74
77
|
ClientConnected,
|
|
75
78
|
ClientWebTransportSupport,
|
|
76
79
|
NewClientSession,
|
|
77
80
|
NewSession,
|
|
81
|
+
NewSessionRequest,
|
|
78
82
|
SessionReady,
|
|
79
83
|
SessionClosed,
|
|
80
84
|
IncomBiDiStream,
|
|
@@ -105,23 +109,27 @@ namespace quic
|
|
|
105
109
|
WebTransportSessionError wtecode;
|
|
106
110
|
NetworkTask nettask;
|
|
107
111
|
NetworkStatus status;
|
|
112
|
+
WebTransportSession *webtsession;
|
|
108
113
|
};
|
|
109
114
|
union
|
|
110
115
|
{
|
|
111
116
|
Http3WTStream *stream; // unowned
|
|
112
117
|
Http3WTSession *session; // unowned
|
|
118
|
+
spdy::Http2HeaderBlock *headerblock; // we own it and must delete it after return from js
|
|
113
119
|
Napi::ObjectReference *bufferhandle; // we own it and must delete it if present
|
|
114
120
|
bool fin;
|
|
115
121
|
WebTransportStreamError wtscode;
|
|
116
122
|
};
|
|
117
123
|
union
|
|
118
124
|
{
|
|
119
|
-
bool success;
|
|
120
|
-
};
|
|
121
|
-
union {
|
|
122
|
-
|
|
123
125
|
std::string *para = nullptr; // for session and others, we own it, and must delete it
|
|
124
|
-
ServerStatusDetails *
|
|
126
|
+
ServerStatusDetails *details;
|
|
127
|
+
};
|
|
128
|
+
union
|
|
129
|
+
{
|
|
130
|
+
bool success;
|
|
131
|
+
WebTransportRespPromisePtr *promise;
|
|
132
|
+
Napi::Reference<Napi::Value> *header;
|
|
125
133
|
};
|
|
126
134
|
};
|
|
127
135
|
|
|
@@ -162,8 +170,6 @@ namespace quic
|
|
|
162
170
|
eventloop_->Destroy();
|
|
163
171
|
}
|
|
164
172
|
|
|
165
|
-
|
|
166
|
-
|
|
167
173
|
protected:
|
|
168
174
|
Http3EventLoop *eventloop_;
|
|
169
175
|
};
|
|
@@ -192,11 +198,15 @@ namespace quic
|
|
|
192
198
|
void informClientWebtransportSupport(Http3Client *client);
|
|
193
199
|
void informNewClientSession(Http3Client *client, Http3WTSession *session);
|
|
194
200
|
|
|
195
|
-
|
|
201
|
+
using WebTransportRespPromise = JSlikePromise<Http3ServerBackend::WebTransportResponse>;
|
|
202
|
+
using WebTransportRespPromisePtr = std::shared_ptr<Http3ServerBackend::WebTransportRespPromise>;
|
|
203
|
+
|
|
204
|
+
void informAboutNewSessionRequest(Http3Server *server, WebTransportSession *session, spdy::Http2HeaderBlock *reqheadcopy, WebTransportRespPromisePtr promise);
|
|
205
|
+
void informAboutNewSession(Http3Server *server, Http3WTSession *session, absl::string_view path, Napi::Reference<Napi::Value> *header);
|
|
196
206
|
void informSessionClosed(Http3WTSession *sessionobj, WebTransportSessionError error_code, absl::string_view error_message);
|
|
197
207
|
void informSessionReady(Http3WTSession *sessionobj);
|
|
198
208
|
|
|
199
|
-
void informServerStatus(Http3Server *serverobj, NetworkStatus status, ServerStatusDetails*
|
|
209
|
+
void informServerStatus(Http3Server *serverobj, NetworkStatus status, ServerStatusDetails *details);
|
|
200
210
|
|
|
201
211
|
void informAboutStream(bool incom, bool bidir, Http3WTSession *sessionobj, Http3WTStream *stream);
|
|
202
212
|
void informStreamRecvSignal(Http3WTStream *streamobj, WebTransportStreamError error_code, NetworkTask task);
|
|
@@ -219,15 +229,18 @@ namespace quic
|
|
|
219
229
|
private:
|
|
220
230
|
QueueWorker *qw_;
|
|
221
231
|
|
|
222
|
-
bool checkQw()
|
|
223
|
-
|
|
232
|
+
bool checkQw()
|
|
233
|
+
{
|
|
234
|
+
if (!qw_)
|
|
235
|
+
{
|
|
224
236
|
Napi::Error::New(Env(), "Queueworker gone").ThrowAsJavaScriptException();
|
|
225
237
|
return false;
|
|
226
238
|
}
|
|
227
239
|
return true;
|
|
228
240
|
}
|
|
229
241
|
|
|
230
|
-
void removeQw()
|
|
242
|
+
void removeQw()
|
|
243
|
+
{
|
|
231
244
|
qw_ = nullptr;
|
|
232
245
|
}
|
|
233
246
|
|
|
@@ -254,11 +267,12 @@ namespace quic
|
|
|
254
267
|
void processClientWebtransportSupport(Http3Client *client);
|
|
255
268
|
void processNewClientSession(Http3Client *client, Http3WTSession *session);
|
|
256
269
|
|
|
257
|
-
void
|
|
270
|
+
void processNewSessionRequest(Http3Server *server, WebTransportSession *session, spdy::Http2HeaderBlock *reqheadcopy, WebTransportRespPromisePtr *promise);
|
|
271
|
+
void processNewSession(Http3Server *serverobj, Http3WTSession *session, const std::string &path, Napi::Reference<Napi::Value> *header);
|
|
258
272
|
void processSessionClose(Http3WTSession *sessionobj, uint32_t errorcode, const std::string &path);
|
|
259
273
|
void processSessionReady(Http3WTSession *sessionobj);
|
|
260
274
|
|
|
261
|
-
void processServerStatus(Http3Server *serverobj, NetworkStatus status, ServerStatusDetails *
|
|
275
|
+
void processServerStatus(Http3Server *serverobj, NetworkStatus status, ServerStatusDetails *details);
|
|
262
276
|
|
|
263
277
|
void processStream(bool incom, bool bidi, Http3WTSession *sessionobj, Http3WTStream *stream);
|
|
264
278
|
void processStreamRecvSignal(Http3WTStream *streamobj, WebTransportStreamError error_code, NetworkTask task);
|
|
@@ -279,7 +293,6 @@ namespace quic
|
|
|
279
293
|
Napi::FunctionReference cbsession_;
|
|
280
294
|
Napi::FunctionReference cbtransport_;
|
|
281
295
|
|
|
282
|
-
|
|
283
296
|
bool loop_running_;
|
|
284
297
|
};
|
|
285
298
|
}
|