@amritk/nish-aarch64-linux 0.35.0 → 0.37.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/INSTALL.md +73 -59
- package/bin/nish +0 -0
- package/docs/AI.md +50 -4
- package/package.json +1 -1
- package/runtime/async.d.mts +2 -0
- package/runtime/async.mjs +7 -0
- package/runtime/nish.d.ts +4849 -430
- package/runtime/nish.h +25 -0
- package/runtime/page.d.ts +53 -0
- package/runtime/page.mjs +146 -0
- package/runtime/runtime-async.c +557 -0
- package/runtime/runtime-wasm.c +63 -7
- package/runtime/vite.d.ts +30 -0
- package/runtime/vite.mjs +150 -0
- package/scripts/build.sh +252 -15
- package/std/README.md +107 -82
- package/std/base64.ts +34 -5
- package/std/bytes.ts +279 -59
- package/std/cli-args.ts +296 -70
- package/std/cli-flags.ts +184 -19
- package/std/cli.ts +475 -54
- package/std/collections.ts +121 -23
- package/std/compress/checksum.ts +44 -14
- package/std/compress/deflate.ts +224 -111
- package/std/compress/gzip.ts +217 -53
- package/std/compress/zlib.ts +63 -7
- package/std/crypto/aes.ts +128 -52
- package/std/crypto/base64url.ts +29 -5
- package/std/crypto/bcrypt-batch.ts +101 -34
- package/std/crypto/bcrypt.ts +93 -27
- package/std/crypto/chacha20poly1305.ts +69 -14
- package/std/crypto/ct.ts +32 -13
- package/std/crypto/ed25519.ts +66 -16
- package/std/crypto/hkdf.ts +198 -13
- package/std/crypto/hmac.ts +242 -37
- package/std/crypto/jwt.ts +204 -72
- package/std/crypto/p256.ts +222 -72
- package/std/crypto/p384.ts +51 -23
- package/std/crypto/pki-roots.ts +32 -2
- package/std/crypto/pki.ts +99 -30
- package/std/crypto/rsa.ts +56 -22
- package/std/crypto/sha1.ts +3 -0
- package/std/crypto/sha256.ts +24 -1
- package/std/crypto/sha512.ts +99 -14
- package/std/crypto/x25519.ts +163 -24
- package/std/crypto/x509-random.ts +10 -0
- package/std/crypto/x509.ts +133 -66
- package/std/host/ring.ts +124 -0
- package/std/json-equal.ts +31 -11
- package/std/json-format.ts +112 -13
- package/std/json-number.ts +76 -26
- package/std/json-pointer.ts +23 -1
- package/std/json-tokenizer.ts +126 -51
- package/std/json-typed.ts +757 -96
- package/std/json-value.ts +438 -157
- package/std/json.ts +170 -38
- package/std/map.ts +25 -7
- package/std/math.ts +36 -4
- package/std/net/buffer-pool.ts +42 -11
- package/std/net/dns-config.ts +109 -23
- package/std/net/dns-message.ts +62 -7
- package/std/net/dns-resolver.ts +247 -53
- package/std/net/dns.ts +203 -35
- package/std/net/fetch.ts +1267 -290
- package/std/net/handler.ts +296 -80
- package/std/net/hpack.ts +290 -77
- package/std/net/http-compress.ts +152 -36
- package/std/net/http-fields.ts +85 -9
- package/std/net/http1-client-codec.ts +129 -44
- package/std/net/http1-codec.ts +279 -114
- package/std/net/http1-server.ts +409 -139
- package/std/net/http2-frame.ts +289 -51
- package/std/net/http2-tls.ts +152 -49
- package/std/net/http2.ts +314 -160
- package/std/net/http3-frame.ts +165 -27
- package/std/net/http3-server.ts +282 -131
- package/std/net/http3.ts +377 -173
- package/std/net/outbound.ts +37 -3
- package/std/net/postgres-carrier.ts +144 -8
- package/std/net/postgres.ts +898 -260
- package/std/net/prefork.ts +202 -65
- package/std/net/qpack.ts +120 -32
- package/std/net/quic-conn-ack.ts +60 -12
- package/std/net/quic-conn-cid.ts +135 -27
- package/std/net/quic-conn-params.ts +109 -22
- package/std/net/quic-datagram.ts +50 -3
- package/std/net/quic-frame.ts +333 -23
- package/std/net/quic-listener.ts +161 -75
- package/std/net/quic-packet.ts +373 -73
- package/std/net/quic-recovery.ts +287 -65
- package/std/net/quic-stream.ts +436 -146
- package/std/net/quic.ts +693 -323
- package/std/net/router.ts +87 -40
- package/std/net/tls/client.ts +167 -51
- package/std/net/tls/codec.ts +494 -68
- package/std/net/tls/record-client.ts +140 -73
- package/std/net/tls/record-server.ts +233 -105
- package/std/net/tls/record.ts +142 -36
- package/std/net/tls/schedule.ts +235 -26
- package/std/net/tls/ticket.ts +161 -40
- package/std/net/tls/verify.ts +57 -10
- package/std/net/tls-tcp.ts +308 -95
- package/std/net/tls.ts +276 -102
- package/std/net/upstream.ts +81 -45
- package/std/net/url.ts +109 -22
- package/std/net/websocket.ts +140 -26
- package/std/net/webtransport.ts +243 -106
- package/std/pair.ts +10 -2
- package/std/random.ts +42 -15
- package/std/regex.ts +422 -257
- package/std/region.ts +70 -15
- package/std/secret.ts +52 -11
- package/std/sort.ts +17 -2
- package/std/sqlite.ts +256 -35
- package/std/sync/ring.ts +229 -56
- package/std/sync/shm.ts +203 -23
- package/std/term-io.ts +154 -78
- package/std/term-pixels.ts +144 -19
- package/std/term-probe.ts +77 -35
- package/std/term-rate.ts +199 -118
- package/std/term.ts +400 -175
- package/std/testing.ts +130 -32
- package/std/text.ts +84 -17
- package/std/threads.ts +248 -56
- package/std/yaml-json.ts +111 -97
- package/std/yaml-lines.ts +47 -15
- package/std/yaml-write.ts +45 -30
- package/std/yaml.ts +764 -384
package/std/net/http3.ts
CHANGED
|
@@ -12,33 +12,50 @@
|
|
|
12
12
|
* this module reads and writes that connection's streams. `nish/net/http3-server`
|
|
13
13
|
* runs it over a UDP socket with ALPN `h3`.
|
|
14
14
|
*
|
|
15
|
-
* import { Http3Config, Http3Connection, H3_NEED_MORE, H3_ERROR,
|
|
15
|
+
* import { Http3Config, Http3Connection, H3_NEED_MORE, H3_ERROR, H3_END } from "nish/net/http3";
|
|
16
|
+
* import { httpFieldBytes } from "nish/net/http-fields";
|
|
17
|
+
* import { QuicConnection } from "nish/net/quic";
|
|
16
18
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* while (event !== H3_NEED_MORE && event !== H3_ERROR) {
|
|
21
|
-
* // H3_REQUEST: h3.stream, h3.fields (method, path, get("accept"))
|
|
22
|
-
* // H3_DATA: h3.data[h3.dataStart .. h3.dataStart + h3.dataLength)
|
|
23
|
-
* // H3_END: the request is whole; respond
|
|
24
|
-
* event = h3.next();
|
|
19
|
+
* // Once per slot, beside a server QuicConnection; restart() per connection.
|
|
20
|
+
* function open(quic: QuicConnection): Http3Connection {
|
|
21
|
+
* return new Http3Connection(new Http3Config(), quic);
|
|
25
22
|
* }
|
|
26
|
-
* h3.respond(stream, 200, names, values, false);
|
|
27
|
-
* h3.writeData(stream, body, 0, n, true); // answers how much it took
|
|
28
23
|
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* stream
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
24
|
+
* // After each quic.receive(...):
|
|
25
|
+
* function serve(h3: Http3Connection): void {
|
|
26
|
+
* const names: u8[][] = [httpFieldBytes("content-type")];
|
|
27
|
+
* const values: u8[][] = [httpFieldBytes("text/plain")];
|
|
28
|
+
* const body: u8[] = httpFieldBytes("hello\n");
|
|
29
|
+
* let event: i32 = h3.next();
|
|
30
|
+
* while (event !== H3_NEED_MORE && event !== H3_ERROR) {
|
|
31
|
+
* // H3_REQUEST: h3.stream, h3.fields (method, path, get("accept"))
|
|
32
|
+
* // H3_DATA: h3.data[h3.dataStart .. h3.dataStart + h3.dataLength)
|
|
33
|
+
* if (event === H3_END) { // the request is whole: respond
|
|
34
|
+
* h3.respond(h3.stream, 200, names, values, false);
|
|
35
|
+
* h3.writeData(h3.stream, body, 0, toI32(body.length), true); // answers how much it took
|
|
36
|
+
* }
|
|
37
|
+
* event = h3.next();
|
|
38
|
+
* }
|
|
39
|
+
* }
|
|
40
|
+
*
|
|
41
|
+
* **Events.**
|
|
42
|
+
*
|
|
43
|
+
* `next()` reads the streams the QUIC connection has news for and answers the
|
|
44
|
+
* first thing that means something to the program:
|
|
45
|
+
* - `H3_REQUEST` (a request's field section, in `fields`),
|
|
46
|
+
* - `H3_DATA` (a piece of its body, a window onto `data` valid until the next
|
|
47
|
+
* call),
|
|
48
|
+
* - `H3_TRAILERS`,
|
|
49
|
+
* - `H3_END` (the request ended, and its `content-length`, if any, matched),
|
|
50
|
+
* - `H3_RESET` (the stream is gone: the client reset it or stopped it, or it
|
|
51
|
+
* broke a rule that resets it — `errorCode` says which, `resetByPeer` who),
|
|
52
|
+
* - `H3_WRITABLE` (a stream whose write was held back can take more),
|
|
53
|
+
* - `H3_GOAWAY` (the client is going away; `lastStreamId` is its push ID),
|
|
54
|
+
* - and `H3_ERROR`, final: the connection broke a rule, it is closed with
|
|
55
|
+
* `errorCode`, and every later call answers it again.
|
|
56
|
+
*
|
|
57
|
+
* `H3_NEED_MORE` asks for more datagrams. A request's events come in order —
|
|
58
|
+
* REQUEST, DATA…, TRAILERS, END — and after `H3_RESET` its stream has no more.
|
|
42
59
|
*
|
|
43
60
|
* **Back-pressure** is QUIC's flow control. A body is read only as the
|
|
44
61
|
* program calls `next()`, `bodyChunk` bytes at most at a time, and QUIC gives
|
|
@@ -59,29 +76,34 @@
|
|
|
59
76
|
* A unidirectional stream of a type it does not know is asked to stop
|
|
60
77
|
* (H3_STREAM_CREATION_ERROR) and read to its end (§6.2).
|
|
61
78
|
*
|
|
62
|
-
* **What it refuses.**
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
* a
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
* §4.1.2)
|
|
79
|
+
* **What it refuses.**
|
|
80
|
+
*
|
|
81
|
+
* A connection error closes the QUIC connection with the code:
|
|
82
|
+
* - a second control, encoder or decoder stream, or a push stream from a client
|
|
83
|
+
* (H3_STREAM_CREATION_ERROR, §6.2.1, §6.2.2);
|
|
84
|
+
* - a control stream whose first frame is not SETTINGS (H3_MISSING_SETTINGS);
|
|
85
|
+
* - the end, reset or STOP_SENDING of any critical stream, either side's
|
|
86
|
+
* (H3_CLOSED_CRITICAL_STREAM);
|
|
87
|
+
* - a frame where it may not be — DATA or HEADERS on the control stream, a
|
|
88
|
+
* control frame on a request stream, a second SETTINGS, DATA before HEADERS,
|
|
89
|
+
* anything but the end after trailers, any PUSH_PROMISE from a client, and an
|
|
90
|
+
* HTTP/2 type HTTP/3 reserves (H3_FRAME_UNEXPECTED, §7.2.8);
|
|
91
|
+
* - a frame cut off by its stream's end or a payload of the wrong length
|
|
92
|
+
* (H3_FRAME_ERROR, §7.1);
|
|
93
|
+
* - a SETTINGS frame `nish/net/http3-frame` refuses (H3_SETTINGS_ERROR);
|
|
94
|
+
* - a GOAWAY whose push ID rose, a MAX_PUSH_ID that fell, a CANCEL_PUSH past
|
|
95
|
+
* the push IDs allowed (H3_ID_ERROR, §5.2, §7.2.7, §7.2.3);
|
|
96
|
+
* - a control frame past `H3_CONTROL_FRAME_MAX` (H3_EXCESSIVE_LOAD);
|
|
97
|
+
* - and QPACK's three.
|
|
98
|
+
*
|
|
99
|
+
* A stream error resets one request, both ways, and the connection lives: a
|
|
100
|
+
* field section `nish/net/http-fields` refuses, and a body that disagrees with
|
|
101
|
+
* `content-length` (H3_MESSAGE_ERROR, §4.1.2); a request stream that ends
|
|
102
|
+
* before its HEADERS (H3_REQUEST_INCOMPLETE, §4.1.1); a request on a stream at
|
|
103
|
+
* or past the ID of the GOAWAY this side sent (H3_REQUEST_REJECTED, §5.2). A
|
|
104
|
+
* request whose field section is longer than `maxFieldSectionSize` — the frame,
|
|
105
|
+
* or the section once decoded — is answered with a 431, never reaches the
|
|
106
|
+
* program, and its stream is asked to stop with H3_NO_ERROR (§4.2.2, §4.1.2).
|
|
85
107
|
*
|
|
86
108
|
* **No server push.** It never sends PUSH_PROMISE; a client's MAX_PUSH_ID is
|
|
87
109
|
* allowed, checked and ignored.
|
|
@@ -89,7 +111,7 @@
|
|
|
89
111
|
* **Caps are start-up numbers**, all in `Http3Config`. The stream state for
|
|
90
112
|
* every QUIC stream slot and the control frame are made by the constructor;
|
|
91
113
|
* the body chunk and the field section are borrowed, around one read, from
|
|
92
|
-
* pools that a server's connections share
|
|
114
|
+
* pools that a server's connections share and that a standalone
|
|
93
115
|
* connection keeps one buffer each of. A field section's
|
|
94
116
|
* names and values are copied into arrays the connection keeps, which grow to
|
|
95
117
|
* the largest section seen and are then reused, so a warm connection
|
|
@@ -97,28 +119,30 @@
|
|
|
97
119
|
* counters saturate, and the lookup of a stream's state is the QUIC
|
|
98
120
|
* connection's own hash index (`QuicStreams.slotOf`), never a scan.
|
|
99
121
|
*
|
|
100
|
-
* **Extended CONNECT and WebTransport.** With `extendedConnect` the
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
* draft-
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
+
* **Extended CONNECT and WebTransport.** With `extendedConnect` the connection
|
|
123
|
+
* sends SETTINGS_ENABLE_CONNECT_PROTOCOL 1 and a request may carry `:protocol`
|
|
124
|
+
* (RFC 9220); without it `:protocol` is malformed, H3_MESSAGE_ERROR.
|
|
125
|
+
*
|
|
126
|
+
* `webtransportSessions` above 0 turns that on and also sends
|
|
127
|
+
* SETTINGS_H3_DATAGRAM 1, draft-02's SETTINGS_ENABLE_WEBTRANSPORT 1 and
|
|
128
|
+
* draft-07's SETTINGS_WEBTRANSPORT_MAX_SESSIONS, and `nish/net/webtransport`
|
|
129
|
+
* runs its sessions on top: a request then waits for the client's SETTINGS
|
|
130
|
+
* (draft-02 §3.1), and a stream that opens with WebTransport's unidirectional
|
|
131
|
+
* type (0x54) or bidirectional signal (0x41) is read as far as its session ID,
|
|
132
|
+
* held unread and named in `H3_STREAM` until the program calls `acceptStream`
|
|
133
|
+
* (its bytes then come as H3_DATA, H3_END, H3_RESET and H3_STOPPED, and
|
|
134
|
+
* `writeStream` writes them as they are) or `refuseStream`.
|
|
135
|
+
*
|
|
136
|
+
* `openStream` opens one of this side's; `writeDataWhole` writes a capsule; a
|
|
137
|
+
* GOAWAY still lets a session's new stream in, and `H3_DROPPED` names a request
|
|
138
|
+
* stream that ended before its request reached the program. The client's
|
|
139
|
+
* SETTINGS_ENABLE_CONNECT_PROTOCOL and SETTINGS_H3_DATAGRAM must be 0 or 1
|
|
140
|
+
* (H3_SETTINGS_ERROR), a session ID that is no client-initiated bidirectional
|
|
141
|
+
* stream is H3_ID_ERROR, and the signal anywhere but a stream's start is
|
|
142
|
+
* H3_FRAME_ERROR. Holding every request, not only an extended CONNECT, until
|
|
143
|
+
* the client's SETTINGS keeps a decoded field section from having to be held
|
|
144
|
+
* per stream; it costs a request only when the client's control stream is lost
|
|
145
|
+
* or reordered.
|
|
122
146
|
*
|
|
123
147
|
* Private helpers share the importing program's flat symbol namespace
|
|
124
148
|
* (`docs/wp26-stdlib.md` §3e), which is why each one carries the module's name.
|
|
@@ -397,44 +421,55 @@ const http3Min = (a: i64, b: i64): i64 => (a < b ? a : b)
|
|
|
397
421
|
export class Http3Connection {
|
|
398
422
|
// Pointers and 64-bit fields first, then 32-bit ones, then flags: the
|
|
399
423
|
// order the layout packs without padding.
|
|
424
|
+
/** @internal Read by `webtransport.ts` for `webtransportSessions`; callers keep their own `Http3Config`. */
|
|
400
425
|
config: Http3Config
|
|
426
|
+
/** The QUIC connection this one runs on, given to the constructor and kept for its life. */
|
|
401
427
|
quic: QuicConnection
|
|
428
|
+
/**
|
|
429
|
+
* The QPACK decoder of the client's field sections, at dynamic table capacity 0; it also reads the
|
|
430
|
+
* client's encoder stream.
|
|
431
|
+
*/
|
|
402
432
|
decoder: QpackDecoder
|
|
433
|
+
/** The QPACK encoder of this side's field sections; it also reads the client's decoder stream. */
|
|
403
434
|
encoder: QpackEncoder
|
|
404
435
|
/** The last request's or trailers' fields, valid until the next of either. */
|
|
405
436
|
fields: HttpFields
|
|
406
437
|
/** The client's SETTINGS. */
|
|
407
438
|
peer: Http3Settings
|
|
408
|
-
header: Http3FrameHeader
|
|
439
|
+
private header: Http3FrameHeader
|
|
409
440
|
/**
|
|
410
441
|
* H3_DATA's bytes, and where a payload being skipped is read to: a
|
|
411
442
|
* `bodyChunk`-byte buffer borrowed from `dataPool` for the read that needs
|
|
412
|
-
* it and held while an H3_DATA window is live, else
|
|
443
|
+
* it and held while an H3_DATA window is live, else an empty array. Any
|
|
444
|
+
* event but H3_DATA gives the buffer back, zeroed as far as reads wrote.
|
|
413
445
|
*/
|
|
414
446
|
data: u8[]
|
|
415
447
|
/** A HEADERS payload read whole, for the decoder: a buffer borrowed from `sectionPool` around one read and decode, else `none`. */
|
|
416
|
-
section: u8[]
|
|
448
|
+
private section: u8[]
|
|
417
449
|
/** The empty array `data` and `section` are while they hold nothing borrowed. */
|
|
418
|
-
none: u8[]
|
|
419
|
-
/** Where `data` is borrowed from: the connection's own pool until
|
|
450
|
+
private none: u8[]
|
|
451
|
+
/** Where `data` is borrowed from: the connection's own pool until its server lends it the server's. */
|
|
420
452
|
dataPool: BufferPool
|
|
421
|
-
/**
|
|
453
|
+
/**
|
|
454
|
+
* Where the buffer a HEADERS payload is read into whole, for the decoder, is borrowed from around one
|
|
455
|
+
* read and decode: the connection's own pool until its server lends it the server's.
|
|
456
|
+
*/
|
|
422
457
|
sectionPool: BufferPool
|
|
423
458
|
/** A control frame's payload, read whole. */
|
|
424
|
-
control: u8[]
|
|
459
|
+
private control: u8[]
|
|
425
460
|
/** Frame headers, SETTINGS and GOAWAY on their way out. */
|
|
426
|
-
scratch: u8[]
|
|
461
|
+
private scratch: u8[]
|
|
427
462
|
/** Zeros, the payload of a filler frame. */
|
|
428
|
-
zeros: u8[]
|
|
463
|
+
private zeros: u8[]
|
|
429
464
|
/** A response's field section, encoded, emptied and reused. */
|
|
430
|
-
encoded: u8[]
|
|
465
|
+
private encoded: u8[]
|
|
431
466
|
/** Copies of the decoded names and values, in arrays by size class (`copyOf`), and the lists handed to `fields`. */
|
|
432
|
-
pools: u8[][][]
|
|
433
|
-
poolUsed: i32[]
|
|
434
|
-
nameList: u8[][]
|
|
435
|
-
valueList: u8[][]
|
|
436
|
-
statusName: u8[]
|
|
437
|
-
statusValue: u8[]
|
|
467
|
+
private pools: u8[][][]
|
|
468
|
+
private poolUsed: i32[]
|
|
469
|
+
private nameList: u8[][]
|
|
470
|
+
private valueList: u8[][]
|
|
471
|
+
private statusName: u8[]
|
|
472
|
+
private statusValue: u8[]
|
|
438
473
|
/**
|
|
439
474
|
* The `date` every response carries (RFC 9110 §6.6.1), as the 29 bytes of
|
|
440
475
|
* an IMF-fixdate, or empty for none. A bare connection has no clock, so it
|
|
@@ -443,30 +478,30 @@ export class Http3Connection {
|
|
|
443
478
|
*/
|
|
444
479
|
date: u8[]
|
|
445
480
|
/** The bytes of `date`, the field's name, made once. */
|
|
446
|
-
dateName: u8[]
|
|
447
|
-
/** The SETTINGS this side sends. */
|
|
481
|
+
private dateName: u8[]
|
|
482
|
+
/** The identifiers of the SETTINGS this side sends, in the order sent; fixed by the constructor. */
|
|
448
483
|
settingIds: i64[]
|
|
449
|
-
settingValues: i64[]
|
|
484
|
+
private settingValues: i64[]
|
|
450
485
|
/** Per QUIC stream slot: the stream the state is for, or -1. */
|
|
451
|
-
slotId: i64[]
|
|
486
|
+
private slotId: i64[]
|
|
452
487
|
/** The frame being read: its type, and what is left of its payload (-1 between frames). */
|
|
453
|
-
frameType: i64[]
|
|
454
|
-
frameLeft: i64[]
|
|
488
|
+
private frameType: i64[]
|
|
489
|
+
private frameLeft: i64[]
|
|
455
490
|
/** DATA bytes received on the request, and its `content-length` or -1. */
|
|
456
|
-
dataTotal: i64[]
|
|
457
|
-
contentLength: i64[]
|
|
491
|
+
private dataTotal: i64[]
|
|
492
|
+
private contentLength: i64[]
|
|
458
493
|
/** Bytes still owed on the stream: a filler's payload, and the DATA frame's payload the program is writing. */
|
|
459
|
-
fillLeft: i64[]
|
|
460
|
-
dataLeft: i64[]
|
|
461
|
-
phase: i32[]
|
|
462
|
-
flags: i32[]
|
|
494
|
+
private fillLeft: i64[]
|
|
495
|
+
private dataLeft: i64[]
|
|
496
|
+
private phase: i32[]
|
|
497
|
+
private flags: i32[]
|
|
463
498
|
/** A frame header (or a stream type) being read, `headLen[k]` bytes of `head[k * 16 ..]`. */
|
|
464
|
-
headLen: i32[]
|
|
465
|
-
head: u8[]
|
|
499
|
+
private headLen: i32[]
|
|
500
|
+
private head: u8[]
|
|
466
501
|
/** Frame-header bytes owed before anything else, `pendLen[k]` of `pend[k * 16 + pendAt[k] ..]`. */
|
|
467
|
-
pendAt: i32[]
|
|
468
|
-
pendLen: i32[]
|
|
469
|
-
pend: u8[]
|
|
502
|
+
private pendAt: i32[]
|
|
503
|
+
private pendLen: i32[]
|
|
504
|
+
private pend: u8[]
|
|
470
505
|
/**
|
|
471
506
|
* Streams `next` steps again before asking QUIC for news, a ring of
|
|
472
507
|
* `againCount` from `againHead`: WebTransport streams the program let go,
|
|
@@ -474,56 +509,84 @@ export class Http3Connection {
|
|
|
474
509
|
* `waitCount` of them. A stream is on each at most once (its flags say),
|
|
475
510
|
* so neither needs more room than there are stream slots.
|
|
476
511
|
*/
|
|
477
|
-
again: i64[]
|
|
478
|
-
waiting: i64[]
|
|
479
|
-
/** This side's
|
|
480
|
-
ownControl: i64 = -1
|
|
481
|
-
ownEncoder: i64 = -1
|
|
482
|
-
ownDecoder: i64 = -1
|
|
512
|
+
private again: i64[]
|
|
513
|
+
private waiting: i64[]
|
|
514
|
+
/** This side's control, encoder and decoder streams; -1 until opened. */
|
|
515
|
+
private ownControl: i64 = -1
|
|
516
|
+
private ownEncoder: i64 = -1
|
|
517
|
+
private ownDecoder: i64 = -1
|
|
518
|
+
/** The ID of the client's control stream, or -1 until its stream type has been read. */
|
|
483
519
|
peerControl: i64 = -1
|
|
520
|
+
/** The ID of the client's QPACK encoder stream, or -1 until its stream type has been read. */
|
|
484
521
|
peerEncoder: i64 = -1
|
|
522
|
+
/** The ID of the client's QPACK decoder stream, or -1 until its stream type has been read. */
|
|
485
523
|
peerDecoder: i64 = -1
|
|
486
524
|
/** The stream `next` is reading, or -1. */
|
|
487
|
-
active: i64 = -1
|
|
488
|
-
/** The ID this side's GOAWAY named, or -1; the client's last GOAWAY push ID
|
|
489
|
-
goawayId: i64 = -1
|
|
490
|
-
peerGoaway: i64 = -1
|
|
525
|
+
private active: i64 = -1
|
|
526
|
+
/** The ID this side's GOAWAY named, or -1; the client's last GOAWAY push ID. */
|
|
527
|
+
private goawayId: i64 = -1
|
|
528
|
+
private peerGoaway: i64 = -1
|
|
529
|
+
/**
|
|
530
|
+
* The client's MAX_PUSH_ID, or -1 until it sends one. It is checked (it may not fall, and bounds
|
|
531
|
+
* CANCEL_PUSH) and otherwise unused, since this side never pushes.
|
|
532
|
+
*/
|
|
491
533
|
maxPushId: i64 = -1
|
|
492
534
|
/** The last event's stream. */
|
|
493
535
|
stream: i64 = -1
|
|
494
|
-
/** H3_RESET's and H3_ERROR's code. */
|
|
536
|
+
/** H3_RESET's, H3_STOPPED's and H3_ERROR's code. */
|
|
495
537
|
errorCode: i64 = 0
|
|
496
538
|
/** H3_GOAWAY's push ID. */
|
|
497
539
|
lastStreamId: i64 = 0
|
|
498
540
|
/** H3_STREAM's session ID. */
|
|
499
541
|
session: i64 = -1
|
|
500
|
-
/**
|
|
542
|
+
/**
|
|
543
|
+
* The QUIC stream slot of the last event's stream: still right when the read that made the event freed it.
|
|
544
|
+
* @internal Read by `webtransport.ts` to find its own per-slot state; not for callers.
|
|
545
|
+
*/
|
|
501
546
|
slot: i32 = -1
|
|
502
|
-
/** H3_DATA's window onto `data
|
|
547
|
+
/** Where H3_DATA's window onto `data` starts. */
|
|
503
548
|
dataStart: i32 = 0
|
|
549
|
+
/** H3_DATA's window length in bytes, 1 to `bodyChunk`; valid until the next `next()`. */
|
|
504
550
|
dataLength: i32 = 0
|
|
505
551
|
/** How much of `control` is filled. */
|
|
506
|
-
controlFill: i32 = 0
|
|
552
|
+
private controlFill: i32 = 0
|
|
507
553
|
/** How far into the borrowed `data` reads have written: what its give-back zeroes. */
|
|
508
|
-
dataUsed: i32 = 0
|
|
554
|
+
private dataUsed: i32 = 0
|
|
555
|
+
/** 0 while the connection is open; 1 once it failed (H3_ERROR), which only `restart` undoes. */
|
|
509
556
|
state: i32 = 0
|
|
510
|
-
/**
|
|
557
|
+
/**
|
|
558
|
+
* Requests open, taken and not yet finished both ways, plus the bidirectional WebTransport streams held
|
|
559
|
+
* after this side's GOAWAY for a session below it.
|
|
560
|
+
*/
|
|
511
561
|
live: i32 = 0
|
|
512
|
-
/**
|
|
562
|
+
/**
|
|
563
|
+
* Counters for a log or a test, each saturating and zeroed by `restart`. This one: request streams refused
|
|
564
|
+
* because their ID is at or past the one this side's GOAWAY named, and WebTransport streams dropped
|
|
565
|
+
* because their session's is.
|
|
566
|
+
*/
|
|
513
567
|
rejected: i32 = 0
|
|
568
|
+
/**
|
|
569
|
+
* Requests whose field section was past `maxFieldSectionSize`: answered with a 431, or reset when the 431
|
|
570
|
+
* did not fit.
|
|
571
|
+
*/
|
|
514
572
|
tooLarge: i32 = 0
|
|
573
|
+
/**
|
|
574
|
+
* Requests reset for breaking a rule (a stream error, §8): a malformed message, a body that disagrees
|
|
575
|
+
* with `content-length`, a stream that ends before its HEADERS, a trailer section too large.
|
|
576
|
+
*/
|
|
515
577
|
streamErrors: i32 = 0
|
|
516
|
-
againHead: i32 = 0
|
|
517
|
-
againCount: i32 = 0
|
|
518
|
-
waitCount: i32 = 0
|
|
578
|
+
private againHead: i32 = 0
|
|
579
|
+
private againCount: i32 = 0
|
|
580
|
+
private waitCount: i32 = 0
|
|
519
581
|
/** How many times `restart` ran: a layer above that keeps state per connection compares it to know when to forget its own. */
|
|
520
582
|
generation: i32 = 0
|
|
521
583
|
/** Whether the client's SETTINGS have arrived. */
|
|
522
584
|
settingsSeen: boolean = false
|
|
523
585
|
/** Whether H3_RESET came from the client. */
|
|
524
586
|
resetByPeer: boolean = false
|
|
525
|
-
/** Whether extended CONNECT is on
|
|
526
|
-
connect: boolean = false
|
|
587
|
+
/** Whether extended CONNECT is on. */
|
|
588
|
+
private connect: boolean = false
|
|
589
|
+
/** Whether WebTransport is on: `webtransportSessions` above 0. Fixed by the constructor. */
|
|
527
590
|
webtransport: boolean = false
|
|
528
591
|
|
|
529
592
|
/**
|
|
@@ -532,6 +595,11 @@ export class Http3Connection {
|
|
|
532
595
|
* one on every request stream fit half the connection's window, and let
|
|
533
596
|
* the client open the three unidirectional streams it needs and this side
|
|
534
597
|
* open its own three (§6.2). A cap out of range panics.
|
|
598
|
+
*
|
|
599
|
+
* @param config The caps; kept, not copied, so it must not change after this call.
|
|
600
|
+
* @param quic The server QUIC connection to run on, kept for this connection's life. Its stream caps
|
|
601
|
+
* are checked as above, and it must take DATAGRAM frames exactly when `webtransportSessions` is above
|
|
602
|
+
* 0, or this panics.
|
|
535
603
|
*/
|
|
536
604
|
constructor(config: Http3Config, quic: QuicConnection) {
|
|
537
605
|
const buffer: i32 = quic.streams.bufferSize
|
|
@@ -688,7 +756,10 @@ export class Http3Connection {
|
|
|
688
756
|
|
|
689
757
|
// ---- The connection -----------------------------------------------------------
|
|
690
758
|
|
|
691
|
-
/**
|
|
759
|
+
/**
|
|
760
|
+
* Closes the connection with `code` (a connection error) and answers H3_ERROR.
|
|
761
|
+
* @internal Called by `webtransport.ts` to fail the connection on a malformed datagram; not for callers.
|
|
762
|
+
*/
|
|
692
763
|
fail(code: i64): i32 {
|
|
693
764
|
if (this.state !== H3_STATE_FAILED) {
|
|
694
765
|
this.state = H3_STATE_FAILED
|
|
@@ -702,6 +773,9 @@ export class Http3Connection {
|
|
|
702
773
|
* Whether this side sent GOAWAY and every request it took has finished
|
|
703
774
|
* both ways, every byte of each response acknowledged: the carrier may
|
|
704
775
|
* close the connection.
|
|
776
|
+
*
|
|
777
|
+
* @returns True when this side's GOAWAY has gone out, `live` is 0 and QUIC has closed every request
|
|
778
|
+
* stream the client opened; false otherwise, and always before `goaway()` has sent one.
|
|
705
779
|
*/
|
|
706
780
|
isDone(): boolean {
|
|
707
781
|
const streams = this.quic.streams
|
|
@@ -709,7 +783,7 @@ export class Http3Connection {
|
|
|
709
783
|
}
|
|
710
784
|
|
|
711
785
|
/** Writes `buf[0 .. n)` to this side's new stream `id` whole, as its first bytes; answers whether it took them. */
|
|
712
|
-
writeNew(id: i64, buf: u8[], n: i32): boolean {
|
|
786
|
+
private writeNew(id: i64, buf: u8[], n: i32): boolean {
|
|
713
787
|
return n > 0 && this.quic.streamWrite(id, buf, H3_ZERO, n, false) === n
|
|
714
788
|
}
|
|
715
789
|
|
|
@@ -719,7 +793,7 @@ export class Http3Connection {
|
|
|
719
793
|
* §4.2). A stream the client's MAX_STREAMS does not allow yet is opened on
|
|
720
794
|
* a later call.
|
|
721
795
|
*/
|
|
722
|
-
start(): void {
|
|
796
|
+
private start(): void {
|
|
723
797
|
const end: i32 = toI32(this.scratch.length)
|
|
724
798
|
if (this.ownControl < 0) {
|
|
725
799
|
const id: i64 = this.quic.openStream(false)
|
|
@@ -766,6 +840,11 @@ export class Http3Connection {
|
|
|
766
840
|
* Reads what the QUIC connection has for the program and answers the next
|
|
767
841
|
* event (see the module comment). Call it after every datagram the QUIC
|
|
768
842
|
* connection takes, until it answers H3_NEED_MORE or H3_ERROR.
|
|
843
|
+
*
|
|
844
|
+
* @returns One of the `H3_*` events: H3_REQUEST, H3_DATA, H3_TRAILERS, H3_END, H3_RESET, H3_WRITABLE,
|
|
845
|
+
* H3_GOAWAY, and with WebTransport on H3_STREAM, H3_STOPPED and H3_DROPPED; H3_NEED_MORE when
|
|
846
|
+
* nothing more is there, or while the QUIC handshake is not done; H3_ERROR once the connection has
|
|
847
|
+
* failed, or the QUIC connection has closed, and on every call after.
|
|
769
848
|
*/
|
|
770
849
|
next(): i32 {
|
|
771
850
|
// The last H3_DATA window ends here. A body read chunk by chunk keeps the
|
|
@@ -782,6 +861,10 @@ export class Http3Connection {
|
|
|
782
861
|
* back to the old pools whatever it holds. Panics unless their buffers are
|
|
783
862
|
* `bodyChunk` and `maxFieldSectionSize` bytes long, as this connection's
|
|
784
863
|
* reads need.
|
|
864
|
+
*
|
|
865
|
+
* @param data The pool H3_DATA's buffer is borrowed from from now on; kept, not copied.
|
|
866
|
+
* @param section The pool a HEADERS payload's buffer is borrowed from from now on; kept, not copied.
|
|
867
|
+
* @internal Called by `http3-server.ts` when it builds a slot; not for callers.
|
|
785
868
|
*/
|
|
786
869
|
share(data: BufferPool, section: BufferPool): void {
|
|
787
870
|
if (data.size !== this.config.bodyChunk || section.size !== this.config.maxFieldSectionSize) {
|
|
@@ -794,20 +877,24 @@ export class Http3Connection {
|
|
|
794
877
|
this.sectionPool = section
|
|
795
878
|
}
|
|
796
879
|
|
|
797
|
-
/**
|
|
880
|
+
/**
|
|
881
|
+
* Releases the QUIC connection (`QuicConnection.release`) and gives back every pooled buffer this
|
|
882
|
+
* connection holds.
|
|
883
|
+
* @internal Called by `http3-server.ts` when it frees a slot or has stopped; not for callers.
|
|
884
|
+
*/
|
|
798
885
|
release(): void {
|
|
799
886
|
this.quic.release()
|
|
800
887
|
this.giveBack()
|
|
801
888
|
}
|
|
802
889
|
|
|
803
890
|
/** Gives back `data` and `section` if either is borrowed: the connection holds no pooled buffer after it. */
|
|
804
|
-
giveBack(): void {
|
|
891
|
+
private giveBack(): void {
|
|
805
892
|
this.giveData()
|
|
806
893
|
this.giveSection(H3_ZERO)
|
|
807
894
|
}
|
|
808
895
|
|
|
809
896
|
/** `data`, borrowed from `dataPool` first if it is not already. */
|
|
810
|
-
borrowData(): u8[] {
|
|
897
|
+
private borrowData(): u8[] {
|
|
811
898
|
if (this.data.length === 0) {
|
|
812
899
|
this.data = this.dataPool.take()
|
|
813
900
|
this.dataUsed = 0
|
|
@@ -816,7 +903,7 @@ export class Http3Connection {
|
|
|
816
903
|
}
|
|
817
904
|
|
|
818
905
|
/** Gives `data` back to `dataPool`, zeroed as far as reads wrote, if it is borrowed. */
|
|
819
|
-
giveData(): void {
|
|
906
|
+
private giveData(): void {
|
|
820
907
|
if (this.data.length > 0) {
|
|
821
908
|
this.dataPool.give(this.data, this.dataUsed)
|
|
822
909
|
this.data = this.none
|
|
@@ -825,7 +912,7 @@ export class Http3Connection {
|
|
|
825
912
|
}
|
|
826
913
|
|
|
827
914
|
/** Reads up to `want` bytes of stream `id` into the start of `data`, borrowed for it: `streamRead`'s answer. */
|
|
828
|
-
readData(id: i64, want: i32): i32 {
|
|
915
|
+
private readData(id: i64, want: i32): i32 {
|
|
829
916
|
const n: i32 = this.quic.streamRead(id, this.borrowData(), H3_ZERO, want)
|
|
830
917
|
if (n > this.dataUsed) {
|
|
831
918
|
this.dataUsed = n
|
|
@@ -834,7 +921,7 @@ export class Http3Connection {
|
|
|
834
921
|
}
|
|
835
922
|
|
|
836
923
|
/** `section`, borrowed from `sectionPool`. */
|
|
837
|
-
borrowSection(): u8[] {
|
|
924
|
+
private borrowSection(): u8[] {
|
|
838
925
|
if (this.section.length === 0) {
|
|
839
926
|
this.section = this.sectionPool.take()
|
|
840
927
|
}
|
|
@@ -842,7 +929,7 @@ export class Http3Connection {
|
|
|
842
929
|
}
|
|
843
930
|
|
|
844
931
|
/** Gives `section` back to `sectionPool`, zeroed over `[0, used)`, if it is borrowed. */
|
|
845
|
-
giveSection(used: i32): void {
|
|
932
|
+
private giveSection(used: i32): void {
|
|
846
933
|
if (this.section.length > 0) {
|
|
847
934
|
this.sectionPool.give(this.section, used)
|
|
848
935
|
this.section = this.none
|
|
@@ -850,7 +937,7 @@ export class Http3Connection {
|
|
|
850
937
|
}
|
|
851
938
|
|
|
852
939
|
/** `next`'s work: everything but the lending of `data` around it. */
|
|
853
|
-
nextEvent(): i32 {
|
|
940
|
+
private nextEvent(): i32 {
|
|
854
941
|
if (this.state === H3_STATE_FAILED) {
|
|
855
942
|
return H3_ERROR
|
|
856
943
|
}
|
|
@@ -887,7 +974,7 @@ export class Http3Connection {
|
|
|
887
974
|
}
|
|
888
975
|
|
|
889
976
|
/** The oldest stream on the `again` ring, taken off it. */
|
|
890
|
-
takeAgain(): i64 {
|
|
977
|
+
private takeAgain(): i64 {
|
|
891
978
|
const size: i32 = toI32(this.again.length)
|
|
892
979
|
const id: i64 = this.again[this.againHead]
|
|
893
980
|
this.againHead = (this.againHead + 1) % size
|
|
@@ -900,7 +987,7 @@ export class Http3Connection {
|
|
|
900
987
|
}
|
|
901
988
|
|
|
902
989
|
/** Puts stream `id`, slot `k`, on the `again` ring, unless it is there. */
|
|
903
|
-
stepAgain(k: i32, id: i64): void {
|
|
990
|
+
private stepAgain(k: i32, id: i64): void {
|
|
904
991
|
const size: i32 = toI32(this.again.length)
|
|
905
992
|
if ((this.flags[k] & H3_FLAG_AGAIN) !== 0 || this.againCount >= size) {
|
|
906
993
|
return
|
|
@@ -911,7 +998,7 @@ export class Http3Connection {
|
|
|
911
998
|
}
|
|
912
999
|
|
|
913
1000
|
/** The next event stream `id` has, or H3_NEED_MORE when it has nothing more to say now. */
|
|
914
|
-
step(id: i64): i32 {
|
|
1001
|
+
private step(id: i64): i32 {
|
|
915
1002
|
const k: i32 = this.quic.streams.slotOf(id)
|
|
916
1003
|
if (k < 0 || k >= toI32(this.slotId.length)) {
|
|
917
1004
|
return H3_NEED_MORE
|
|
@@ -938,7 +1025,7 @@ export class Http3Connection {
|
|
|
938
1025
|
}
|
|
939
1026
|
|
|
940
1027
|
/** The state of a stream the client just opened in slot `k`. */
|
|
941
|
-
open(k: i32, id: i64): void {
|
|
1028
|
+
private open(k: i32, id: i64): void {
|
|
942
1029
|
this.slotId[k] = id
|
|
943
1030
|
this.frameType[k] = H3_SKIP_TYPE
|
|
944
1031
|
this.frameLeft[k] = -1
|
|
@@ -969,7 +1056,7 @@ export class Http3Connection {
|
|
|
969
1056
|
}
|
|
970
1057
|
|
|
971
1058
|
/** §5.2: a request past the GOAWAY this side sent is refused, both ways, unprocessed. */
|
|
972
|
-
reject(k: i32, id: i64): void {
|
|
1059
|
+
private reject(k: i32, id: i64): void {
|
|
973
1060
|
this.quic.streamReset(id, H3_REQUEST_REJECTED)
|
|
974
1061
|
this.quic.streamStopSending(id, H3_REQUEST_REJECTED)
|
|
975
1062
|
this.flags[k] = H3_FLAG_SEND_DONE
|
|
@@ -978,7 +1065,7 @@ export class Http3Connection {
|
|
|
978
1065
|
}
|
|
979
1066
|
|
|
980
1067
|
/** One of this side's own streams has news: the client may not stop it (§6.2.1, RFC 9204 §4.2). */
|
|
981
|
-
ownStream(k: i32): i32 {
|
|
1068
|
+
private ownStream(k: i32): i32 {
|
|
982
1069
|
const stream: QuicStream = this.quic.streams.slots[k]
|
|
983
1070
|
if (stream.stopCode >= 0) {
|
|
984
1071
|
return this.fail(H3_CLOSED_CRITICAL_STREAM)
|
|
@@ -987,7 +1074,7 @@ export class Http3Connection {
|
|
|
987
1074
|
}
|
|
988
1075
|
|
|
989
1076
|
/** Lets a slot's request count as finished once both of its sides are done. */
|
|
990
|
-
settle(k: i32): void {
|
|
1077
|
+
private settle(k: i32): void {
|
|
991
1078
|
const done: i32 = H3_FLAG_SEND_DONE | H3_FLAG_RECV_DONE | H3_FLAG_COUNTED
|
|
992
1079
|
if ((this.flags[k] & done) === done) {
|
|
993
1080
|
this.flags[k] = this.flags[k] & ~H3_FLAG_COUNTED
|
|
@@ -996,7 +1083,7 @@ export class Http3Connection {
|
|
|
996
1083
|
}
|
|
997
1084
|
|
|
998
1085
|
/** Marks flags on slot `k` and settles it. */
|
|
999
|
-
mark(k: i32, bits: i32): void {
|
|
1086
|
+
private mark(k: i32, bits: i32): void {
|
|
1000
1087
|
this.flags[k] = this.flags[k] | bits
|
|
1001
1088
|
this.settle(k)
|
|
1002
1089
|
}
|
|
@@ -1008,7 +1095,7 @@ export class Http3Connection {
|
|
|
1008
1095
|
* `header` filled, 0 when more is needed, or the `QUIC_STREAM_*` answer
|
|
1009
1096
|
* that ended the read.
|
|
1010
1097
|
*/
|
|
1011
|
-
readHeader(k: i32, id: i64): i32 {
|
|
1098
|
+
private readHeader(k: i32, id: i64): i32 {
|
|
1012
1099
|
const base: i32 = k * H3_HEAD
|
|
1013
1100
|
while (this.headLen[k] < H3_HEAD) {
|
|
1014
1101
|
const have: i32 = this.headLen[k]
|
|
@@ -1037,7 +1124,7 @@ export class Http3Connection {
|
|
|
1037
1124
|
// ---- Unidirectional streams ------------------------------------------------------
|
|
1038
1125
|
|
|
1039
1126
|
/** The next event of the client's unidirectional stream `id` in slot `k`. */
|
|
1040
|
-
uniStep(k: i32, id: i64): i32 {
|
|
1127
|
+
private uniStep(k: i32, id: i64): i32 {
|
|
1041
1128
|
while (this.state !== H3_STATE_FAILED) {
|
|
1042
1129
|
const phase: i32 = this.phase[k]
|
|
1043
1130
|
if (phase === H3_PHASE_UNI_TYPE) {
|
|
@@ -1086,7 +1173,7 @@ export class Http3Connection {
|
|
|
1086
1173
|
}
|
|
1087
1174
|
|
|
1088
1175
|
/** The client's unidirectional stream `id` turned out to be of `type` (§6.2). */
|
|
1089
|
-
typed(k: i32, id: i64, type: i64): i32 {
|
|
1176
|
+
private typed(k: i32, id: i64, type: i64): i32 {
|
|
1090
1177
|
if (type === H3_STREAM_CONTROL) {
|
|
1091
1178
|
if (this.peerControl >= 0) {
|
|
1092
1179
|
return this.fail(H3_STREAM_CREATION_ERROR)
|
|
@@ -1128,7 +1215,7 @@ export class Http3Connection {
|
|
|
1128
1215
|
}
|
|
1129
1216
|
|
|
1130
1217
|
/** Frames on the client's control stream (§6.2.1, §7.2). */
|
|
1131
|
-
controlStep(k: i32, id: i64): i32 {
|
|
1218
|
+
private controlStep(k: i32, id: i64): i32 {
|
|
1132
1219
|
while (this.state !== H3_STATE_FAILED) {
|
|
1133
1220
|
if (this.frameLeft[k] < 0) {
|
|
1134
1221
|
const got: i32 = this.readHeader(k, id)
|
|
@@ -1194,7 +1281,7 @@ export class Http3Connection {
|
|
|
1194
1281
|
}
|
|
1195
1282
|
|
|
1196
1283
|
/** Acts on a whole control frame of `type` in `control[0 .. controlFill)`. */
|
|
1197
|
-
controlFrame(type: i64): i32 {
|
|
1284
|
+
private controlFrame(type: i64): i32 {
|
|
1198
1285
|
if (type === H3_FRAME_SETTINGS) {
|
|
1199
1286
|
const result: i64 = h3ReadSettings(this.peer, this.control, H3_ZERO, this.controlFill)
|
|
1200
1287
|
if (result !== H3_SETTINGS_OK) {
|
|
@@ -1247,7 +1334,7 @@ export class Http3Connection {
|
|
|
1247
1334
|
}
|
|
1248
1335
|
|
|
1249
1336
|
/** Reads and drops what is left of stream `id`, slot `k`, to its end or reset. */
|
|
1250
|
-
discard(k: i32, id: i64): i32 {
|
|
1337
|
+
private discard(k: i32, id: i64): i32 {
|
|
1251
1338
|
const n: i32 = this.drop(id)
|
|
1252
1339
|
if (n < 0) {
|
|
1253
1340
|
this.phase[k] = H3_PHASE_DONE
|
|
@@ -1257,7 +1344,7 @@ export class Http3Connection {
|
|
|
1257
1344
|
}
|
|
1258
1345
|
|
|
1259
1346
|
/** Reads stream `id` into `data` until nothing more is there; answers 0, or the `QUIC_STREAM_*` that ended it. */
|
|
1260
|
-
drop(id: i64): i32 {
|
|
1347
|
+
private drop(id: i64): i32 {
|
|
1261
1348
|
let n: i32 = this.readData(id, this.config.bodyChunk)
|
|
1262
1349
|
while (n > 0) {
|
|
1263
1350
|
n = this.readData(id, this.config.bodyChunk)
|
|
@@ -1272,7 +1359,7 @@ export class Http3Connection {
|
|
|
1272
1359
|
* held, unread, and the program told with H3_STREAM. A session ID that is
|
|
1273
1360
|
* not a client-initiated bidirectional stream is H3_ID_ERROR (draft-02 §4).
|
|
1274
1361
|
*/
|
|
1275
|
-
held(k: i32, id: i64, session: i64): i32 {
|
|
1362
|
+
private held(k: i32, id: i64, session: i64): i32 {
|
|
1276
1363
|
if (!http3IsRequest(session)) {
|
|
1277
1364
|
return this.fail(H3_ID_ERROR)
|
|
1278
1365
|
}
|
|
@@ -1296,7 +1383,7 @@ export class Http3Connection {
|
|
|
1296
1383
|
* FIN and H3_RESET at the client's RESET_STREAM; H3_STOPPED once for the
|
|
1297
1384
|
* client's STOP_SENDING; and H3_WRITABLE.
|
|
1298
1385
|
*/
|
|
1299
|
-
wtStep(k: i32, id: i64): i32 {
|
|
1386
|
+
private wtStep(k: i32, id: i64): i32 {
|
|
1300
1387
|
const stream: QuicStream = this.quic.streams.slots[k]
|
|
1301
1388
|
if (stream.stopCode >= 0 && (this.flags[k] & H3_FLAG_SEND_DONE) === 0) {
|
|
1302
1389
|
this.mark(k, H3_FLAG_SEND_DONE)
|
|
@@ -1357,7 +1444,7 @@ export class Http3Connection {
|
|
|
1357
1444
|
}
|
|
1358
1445
|
|
|
1359
1446
|
/** The slot of WebTransport stream `id` when it is known here, else -1. */
|
|
1360
|
-
wtSlot(id: i64): i32 {
|
|
1447
|
+
private wtSlot(id: i64): i32 {
|
|
1361
1448
|
if (this.state === H3_STATE_FAILED) {
|
|
1362
1449
|
return -1
|
|
1363
1450
|
}
|
|
@@ -1377,6 +1464,10 @@ export class Http3Connection {
|
|
|
1377
1464
|
* Lets a stream H3_STREAM held go: its bytes come as H3_DATA from the next
|
|
1378
1465
|
* `next()`, and the program may write it. Answers 0, or H3_CLOSED for a
|
|
1379
1466
|
* stream that is not one held.
|
|
1467
|
+
*
|
|
1468
|
+
* @param id The stream H3_STREAM named in `stream`.
|
|
1469
|
+
* @returns 0 once the stream is let go; H3_CLOSED for a stream not held, one already accepted, or
|
|
1470
|
+
* any stream once the connection has failed.
|
|
1380
1471
|
*/
|
|
1381
1472
|
acceptStream(id: i64): i32 {
|
|
1382
1473
|
const k: i32 = this.wtSlot(id)
|
|
@@ -1392,6 +1483,12 @@ export class Http3Connection {
|
|
|
1392
1483
|
* Refuses WebTransport stream `id` with `code`: its side here is reset,
|
|
1393
1484
|
* the client's asked to stop, and what it sent read and dropped. Answers 0,
|
|
1394
1485
|
* or H3_CLOSED for a stream that is not a WebTransport one.
|
|
1486
|
+
*
|
|
1487
|
+
* @param id A WebTransport stream known here, held or accepted, the client's or this side's.
|
|
1488
|
+
* @param code The application error code its RESET_STREAM and STOP_SENDING carry. A side already
|
|
1489
|
+
* finished, reset or being dropped is left as it is.
|
|
1490
|
+
* @returns 0; H3_CLOSED for a stream that is not a WebTransport one known here, or any stream once
|
|
1491
|
+
* the connection has failed.
|
|
1395
1492
|
*/
|
|
1396
1493
|
refuseStream(id: i64, code: i64): i32 {
|
|
1397
1494
|
const k: i32 = this.wtSlot(id)
|
|
@@ -1404,7 +1501,7 @@ export class Http3Connection {
|
|
|
1404
1501
|
}
|
|
1405
1502
|
|
|
1406
1503
|
/** Asks the client to stop stream `id`, slot `k`, with `code`, and drops what it still sends, unless its side is over or being dropped. */
|
|
1407
|
-
stopReading(k: i32, id: i64, code: i64): void {
|
|
1504
|
+
private stopReading(k: i32, id: i64, code: i64): void {
|
|
1408
1505
|
if (this.phase[k] !== H3_PHASE_DONE && this.phase[k] !== H3_PHASE_DISCARD) {
|
|
1409
1506
|
this.quic.streamStopSending(id, code)
|
|
1410
1507
|
this.phase[k] = H3_PHASE_DISCARD
|
|
@@ -1418,6 +1515,14 @@ export class Http3Connection {
|
|
|
1418
1515
|
* the signal 0x41, and the session ID, which go before anything written.
|
|
1419
1516
|
* Answers its ID, H3_AGAIN while the client's MAX_STREAMS allows no more,
|
|
1420
1517
|
* or H3_CLOSED with WebTransport off or the connection failed.
|
|
1518
|
+
*
|
|
1519
|
+
* @param session The session's ID: the ID of the client-initiated bidirectional stream that carried
|
|
1520
|
+
* its CONNECT. It is written as given; whether such a session is open here is not checked.
|
|
1521
|
+
* @param bidirectional True for a bidirectional stream (signal 0x41), false for a unidirectional one
|
|
1522
|
+
* (type 0x54) this side only writes.
|
|
1523
|
+
* @returns The new stream's ID; H3_AGAIN when QUIC can open no stream of that kind now; H3_CLOSED
|
|
1524
|
+
* with WebTransport off, the connection failed, or a `session` that is not a client-initiated
|
|
1525
|
+
* bidirectional stream ID.
|
|
1421
1526
|
*/
|
|
1422
1527
|
openStream(session: i64, bidirectional: boolean): i64 {
|
|
1423
1528
|
if (!this.webtransport || this.state === H3_STATE_FAILED || !http3IsRequest(session) || session < 0) {
|
|
@@ -1452,6 +1557,15 @@ export class Http3Connection {
|
|
|
1452
1557
|
* many it took — fewer only when the send buffer filled, and H3_WRITABLE
|
|
1453
1558
|
* then names the stream — or H3_AGAIN when it took none, or H3_CLOSED for
|
|
1454
1559
|
* a stream with no side here to write, finished, reset, held or stopped.
|
|
1560
|
+
* A window outside `buf` panics.
|
|
1561
|
+
*
|
|
1562
|
+
* @param id A WebTransport stream this side writes, accepted or opened by `openStream`.
|
|
1563
|
+
* @param buf The bytes; copied into the stream's send buffer, so the caller may reuse it.
|
|
1564
|
+
* @param off Where the bytes start in `buf`.
|
|
1565
|
+
* @param len How many bytes to offer; 0 with `fin` sends only the FIN.
|
|
1566
|
+
* @param fin True to finish this side of the stream once all `len` bytes are taken.
|
|
1567
|
+
* @returns The bytes taken, 1 to `len`, or 0 for a FIN alone; H3_AGAIN when it took none, a `len` of
|
|
1568
|
+
* 0 without `fin` among them; H3_CLOSED as above, or any stream once the connection has failed.
|
|
1455
1569
|
*/
|
|
1456
1570
|
writeStream(id: i64, buf: u8[], off: i32, len: i32, fin: boolean): i32 {
|
|
1457
1571
|
h3CheckWindow("Http3Connection.writeStream", buf, off, len)
|
|
@@ -1480,7 +1594,15 @@ export class Http3Connection {
|
|
|
1480
1594
|
return n > 0 || (fin && len === 0) ? n : H3_AGAIN
|
|
1481
1595
|
}
|
|
1482
1596
|
|
|
1483
|
-
/**
|
|
1597
|
+
/**
|
|
1598
|
+
* Resets this side of WebTransport stream `id` with `code`; the client's side goes on.
|
|
1599
|
+
*
|
|
1600
|
+
* @param id A WebTransport stream known here.
|
|
1601
|
+
* @param code The application error code RESET_STREAM carries; nothing is sent when this side is
|
|
1602
|
+
* already finished or reset.
|
|
1603
|
+
* @returns 0; H3_CLOSED for a stream that is not a WebTransport one known here, or any stream once
|
|
1604
|
+
* the connection has failed.
|
|
1605
|
+
*/
|
|
1484
1606
|
resetStream(id: i64, code: i64): i32 {
|
|
1485
1607
|
const k: i32 = this.wtSlot(id)
|
|
1486
1608
|
if (k < 0) {
|
|
@@ -1494,6 +1616,12 @@ export class Http3Connection {
|
|
|
1494
1616
|
* Asks the client to stop its side of WebTransport stream `id` with
|
|
1495
1617
|
* `code`, and drops what it still sends; this side's goes on. Answers 0 or
|
|
1496
1618
|
* H3_CLOSED.
|
|
1619
|
+
*
|
|
1620
|
+
* @param id A WebTransport stream known here.
|
|
1621
|
+
* @param code The application error code STOP_SENDING carries; nothing is sent when the client's
|
|
1622
|
+
* side has already ended or is being dropped.
|
|
1623
|
+
* @returns 0; H3_CLOSED for a stream that is not a WebTransport one known here, or any stream once
|
|
1624
|
+
* the connection has failed.
|
|
1497
1625
|
*/
|
|
1498
1626
|
stopStream(id: i64, code: i64): i32 {
|
|
1499
1627
|
const k: i32 = this.wtSlot(id)
|
|
@@ -1507,7 +1635,7 @@ export class Http3Connection {
|
|
|
1507
1635
|
// ---- Request streams ------------------------------------------------------------
|
|
1508
1636
|
|
|
1509
1637
|
/** The next event of request stream `id` in slot `k`. */
|
|
1510
|
-
requestStep(k: i32, id: i64): i32 {
|
|
1638
|
+
private requestStep(k: i32, id: i64): i32 {
|
|
1511
1639
|
const stream: QuicStream = this.quic.streams.slots[k]
|
|
1512
1640
|
while (this.state !== H3_STATE_FAILED) {
|
|
1513
1641
|
const phase: i32 = this.phase[k]
|
|
@@ -1619,7 +1747,7 @@ export class Http3Connection {
|
|
|
1619
1747
|
* trailers, and anything else unknown and skipped, or refused where
|
|
1620
1748
|
* RFC 9114 says so. A stream that ends here ends the request.
|
|
1621
1749
|
*/
|
|
1622
|
-
requestFrame(k: i32, id: i64): i32 {
|
|
1750
|
+
private requestFrame(k: i32, id: i64): i32 {
|
|
1623
1751
|
const stream: QuicStream = this.quic.streams.slots[k]
|
|
1624
1752
|
const resetCode: i64 = stream.resetCode
|
|
1625
1753
|
const got: i32 = this.readHeader(k, id)
|
|
@@ -1709,7 +1837,7 @@ export class Http3Connection {
|
|
|
1709
1837
|
* field section, or its trailers. Decodes it, copies it into `fields` and
|
|
1710
1838
|
* checks it there.
|
|
1711
1839
|
*/
|
|
1712
|
-
fieldSection(k: i32, id: i64, length: i32): i32 {
|
|
1840
|
+
private fieldSection(k: i32, id: i64, length: i32): i32 {
|
|
1713
1841
|
const result: i64 = this.decoder.decode(this.section, H3_ZERO, length)
|
|
1714
1842
|
const first: boolean = this.phase[k] === H3_PHASE_HEADERS
|
|
1715
1843
|
if (result === QPACK_SECTION_TOO_LARGE) {
|
|
@@ -1740,7 +1868,7 @@ export class Http3Connection {
|
|
|
1740
1868
|
}
|
|
1741
1869
|
|
|
1742
1870
|
/** Copies the decoder's fields into the connection's own arrays and the lists `fields` reads. */
|
|
1743
|
-
copyFields(): void {
|
|
1871
|
+
private copyFields(): void {
|
|
1744
1872
|
const d: QpackDecoder = this.decoder
|
|
1745
1873
|
http3EmptyList(this.nameList)
|
|
1746
1874
|
http3EmptyList(this.valueList)
|
|
@@ -1760,7 +1888,7 @@ export class Http3Connection {
|
|
|
1760
1888
|
* size than any before it, and the total stays bounded by the field-section
|
|
1761
1889
|
* cap (`docs/security/http3.md`, H3-2).
|
|
1762
1890
|
*/
|
|
1763
|
-
copyOf(d: QpackDecoder, start: i32, length: i32): u8[] {
|
|
1891
|
+
private copyOf(d: QpackDecoder, start: i32, length: i32): u8[] {
|
|
1764
1892
|
let j: i32 = 0
|
|
1765
1893
|
while (j < H3_FIELD_CLASSES - 1 && 1 << j <= length) {
|
|
1766
1894
|
j++
|
|
@@ -1786,7 +1914,7 @@ export class Http3Connection {
|
|
|
1786
1914
|
* The request stream ended, cleanly (`n` is `QUIC_STREAM_END`) or by the
|
|
1787
1915
|
* client's RESET_STREAM with `resetCode`, at a frame boundary.
|
|
1788
1916
|
*/
|
|
1789
|
-
ended(k: i32, id: i64, n: i32, resetCode: i64): i32 {
|
|
1917
|
+
private ended(k: i32, id: i64, n: i32, resetCode: i64): i32 {
|
|
1790
1918
|
const phase: i32 = this.phase[k]
|
|
1791
1919
|
this.phase[k] = H3_PHASE_DONE
|
|
1792
1920
|
this.mark(k, H3_FLAG_RECV_DONE)
|
|
@@ -1816,7 +1944,7 @@ export class Http3Connection {
|
|
|
1816
1944
|
}
|
|
1817
1945
|
|
|
1818
1946
|
/** Resets this side's half of request stream `id` with `code`, unless it is done already. */
|
|
1819
|
-
abandon(k: i32, id: i64, code: i64): void {
|
|
1947
|
+
private abandon(k: i32, id: i64, code: i64): void {
|
|
1820
1948
|
if ((this.flags[k] & H3_FLAG_SEND_DONE) === 0) {
|
|
1821
1949
|
this.quic.streamReset(id, code)
|
|
1822
1950
|
}
|
|
@@ -1824,7 +1952,7 @@ export class Http3Connection {
|
|
|
1824
1952
|
}
|
|
1825
1953
|
|
|
1826
1954
|
/** A stream error (§8): the request is reset both ways with `code`, and the program told when it knew the request. */
|
|
1827
|
-
streamError(k: i32, id: i64, code: i64): i32 {
|
|
1955
|
+
private streamError(k: i32, id: i64, code: i64): i32 {
|
|
1828
1956
|
this.streamErrors = h3Count(this.streamErrors)
|
|
1829
1957
|
this.abandon(k, id, code)
|
|
1830
1958
|
this.quic.streamStopSending(id, code)
|
|
@@ -1836,7 +1964,7 @@ export class Http3Connection {
|
|
|
1836
1964
|
}
|
|
1837
1965
|
|
|
1838
1966
|
/** H3_DROPPED for request stream `id` with WebTransport on, which waits on such a stream; H3_NEED_MORE without. */
|
|
1839
|
-
dropped(id: i64): i32 {
|
|
1967
|
+
private dropped(id: i64): i32 {
|
|
1840
1968
|
if (!this.webtransport) {
|
|
1841
1969
|
return H3_NEED_MORE
|
|
1842
1970
|
}
|
|
@@ -1845,7 +1973,7 @@ export class Http3Connection {
|
|
|
1845
1973
|
}
|
|
1846
1974
|
|
|
1847
1975
|
/** H3_RESET for `id` with `code`. */
|
|
1848
|
-
resetEvent(id: i64, code: i64, byPeer: boolean): i32 {
|
|
1976
|
+
private resetEvent(id: i64, code: i64, byPeer: boolean): i32 {
|
|
1849
1977
|
this.stream = id
|
|
1850
1978
|
this.errorCode = code
|
|
1851
1979
|
this.resetByPeer = byPeer
|
|
@@ -1859,7 +1987,7 @@ export class Http3Connection {
|
|
|
1859
1987
|
* SETTINGS_MAX_FIELD_SECTION_SIZE has room for a bare 431 but not for one
|
|
1860
1988
|
* with the date gets it without the date rather than a reset.
|
|
1861
1989
|
*/
|
|
1862
|
-
answerTooLarge(k: i32, id: i64): i32 {
|
|
1990
|
+
private answerTooLarge(k: i32, id: i64): i32 {
|
|
1863
1991
|
this.tooLarge = h3Count(this.tooLarge)
|
|
1864
1992
|
const empty: u8[][] = this.nameList
|
|
1865
1993
|
http3EmptyList(empty)
|
|
@@ -1880,7 +2008,7 @@ export class Http3Connection {
|
|
|
1880
2008
|
* written, and once the buffer has room again the program is told with
|
|
1881
2009
|
* H3_WRITABLE. Answers that, or H3_NEED_MORE.
|
|
1882
2010
|
*/
|
|
1883
|
-
writable(k: i32, id: i64): i32 {
|
|
2011
|
+
private writable(k: i32, id: i64): i32 {
|
|
1884
2012
|
if ((this.flags[k] & H3_FLAG_BLOCKED) === 0 || (this.flags[k] & H3_FLAG_SEND_DONE) !== 0) {
|
|
1885
2013
|
return H3_NEED_MORE
|
|
1886
2014
|
}
|
|
@@ -1895,7 +2023,7 @@ export class Http3Connection {
|
|
|
1895
2023
|
// ---- Writing ----------------------------------------------------------------------
|
|
1896
2024
|
|
|
1897
2025
|
/** The slot of request stream `id` when the program may write to it, else -1. */
|
|
1898
|
-
writeSlot(id: i64): i32 {
|
|
2026
|
+
private writeSlot(id: i64): i32 {
|
|
1899
2027
|
if (this.state === H3_STATE_FAILED || !http3IsRequest(id)) {
|
|
1900
2028
|
return -1
|
|
1901
2029
|
}
|
|
@@ -1915,7 +2043,7 @@ export class Http3Connection {
|
|
|
1915
2043
|
* a frame header, a filler's payload — as far as the send buffer takes
|
|
1916
2044
|
* them. Answers whether none are owed now.
|
|
1917
2045
|
*/
|
|
1918
|
-
drain(k: i32, id: i64): boolean {
|
|
2046
|
+
private drain(k: i32, id: i64): boolean {
|
|
1919
2047
|
const base: i32 = k * H3_HEAD
|
|
1920
2048
|
while (this.pendLen[k] > 0) {
|
|
1921
2049
|
const n: i32 = this.quic.streamWrite(id, this.pend, base + this.pendAt[k], this.pendLen[k], false)
|
|
@@ -1937,7 +2065,7 @@ export class Http3Connection {
|
|
|
1937
2065
|
}
|
|
1938
2066
|
|
|
1939
2067
|
/** Queues `buf[0 .. n)`, a frame header, as the bytes owed first on slot `k`. */
|
|
1940
|
-
owe(k: i32, buf: u8[], n: i32): void {
|
|
2068
|
+
private owe(k: i32, buf: u8[], n: i32): void {
|
|
1941
2069
|
const base: i32 = k * H3_HEAD
|
|
1942
2070
|
for (let j: i32 = 0; j < n && j < H3_HEAD && j < toI32(buf.length); j++) {
|
|
1943
2071
|
this.pend[base + j] = buf[j]
|
|
@@ -1951,7 +2079,7 @@ export class Http3Connection {
|
|
|
1951
2079
|
* the room left is filled with a reserved frame the client skips (§7.2.8),
|
|
1952
2080
|
* so that QUIC names the stream again once acknowledgements free room.
|
|
1953
2081
|
*/
|
|
1954
|
-
arm(k: i32, id: i64): void {
|
|
2082
|
+
private arm(k: i32, id: i64): void {
|
|
1955
2083
|
const stream: QuicStream = this.quic.streams.slots[k]
|
|
1956
2084
|
const room: i64 = stream.room()
|
|
1957
2085
|
this.mark(k, H3_FLAG_BLOCKED)
|
|
@@ -1990,7 +2118,15 @@ export class Http3Connection {
|
|
|
1990
2118
|
* SETTINGS_MAX_FIELD_SECTION_SIZE as any field does. Answers 0, H3_AGAIN,
|
|
1991
2119
|
* or H3_TOO_LARGE.
|
|
1992
2120
|
*/
|
|
1993
|
-
writeHead(
|
|
2121
|
+
private writeHead(
|
|
2122
|
+
k: i32,
|
|
2123
|
+
id: i64,
|
|
2124
|
+
status: i32,
|
|
2125
|
+
names: u8[][],
|
|
2126
|
+
values: u8[][],
|
|
2127
|
+
fin: boolean,
|
|
2128
|
+
dated: boolean
|
|
2129
|
+
): i32 {
|
|
1994
2130
|
const out: u8[] = this.encoded
|
|
1995
2131
|
http3Empty(out)
|
|
1996
2132
|
this.encoder.beginSection(out)
|
|
@@ -2067,6 +2203,18 @@ export class Http3Connection {
|
|
|
2067
2203
|
* that is not an open request; H3_INVALID for a second head, a status out
|
|
2068
2204
|
* of range or a field `httpFieldsCheckOutgoing` refuses; H3_TOO_LARGE for a
|
|
2069
2205
|
* section past the client's SETTINGS_MAX_FIELD_SECTION_SIZE; or H3_AGAIN.
|
|
2206
|
+
*
|
|
2207
|
+
* @param id The request stream, as H3_REQUEST named it in `stream`.
|
|
2208
|
+
* @param status The final status, 200 to 599.
|
|
2209
|
+
* @param names The field names, lowercase and valid, as many as `values`; encoded, not kept.
|
|
2210
|
+
* @param values The field values, one per name; encoded, not kept.
|
|
2211
|
+
* @param endStream True to end the stream with the head, for a response with no body.
|
|
2212
|
+
* @returns 0 once the whole HEADERS frame is in the send buffer; H3_CLOSED for a stream that is not
|
|
2213
|
+
* an open request: unknown, not yet handed to the program, its response finished or reset, stopped
|
|
2214
|
+
* by the client, or any stream once the connection has failed;
|
|
2215
|
+
* H3_INVALID as above; H3_TOO_LARGE for a section past the client's limit or a frame past the
|
|
2216
|
+
* stream's buffer; H3_AGAIN while the send buffer lacks room for the frame, and H3_WRITABLE then
|
|
2217
|
+
* names the stream.
|
|
2070
2218
|
*/
|
|
2071
2219
|
respond(id: i64, status: i32, names: u8[][], values: u8[][], endStream: boolean): i32 {
|
|
2072
2220
|
const k: i32 = this.writeSlot(id)
|
|
@@ -2088,6 +2236,14 @@ export class Http3Connection {
|
|
|
2088
2236
|
* Writes a trailer section on request stream `id` after its body, which
|
|
2089
2237
|
* ends the stream. Answers as `respond` does; H3_INVALID before the head
|
|
2090
2238
|
* or inside a DATA frame `writeData` has not finished.
|
|
2239
|
+
*
|
|
2240
|
+
* @param id The request stream, after `respond`.
|
|
2241
|
+
* @param names The trailer field names, lowercase and valid, as many as `values`; encoded, not kept.
|
|
2242
|
+
* @param values The trailer field values, one per name; encoded, not kept.
|
|
2243
|
+
* @returns 0 once the whole frame is in the send buffer and the stream ended; H3_CLOSED for a stream
|
|
2244
|
+
* that is not an open request: unknown, not yet handed to the program, its response finished or
|
|
2245
|
+
* reset, stopped by the client, or any stream once the connection has failed;
|
|
2246
|
+
* H3_INVALID as above; H3_TOO_LARGE or H3_AGAIN as `respond` answers them.
|
|
2091
2247
|
*/
|
|
2092
2248
|
writeTrailers(id: i64, names: u8[][], values: u8[][]): i32 {
|
|
2093
2249
|
const k: i32 = this.writeSlot(id)
|
|
@@ -2113,6 +2269,19 @@ export class Http3Connection {
|
|
|
2113
2269
|
* took none;
|
|
2114
2270
|
* H3_CLOSED, or H3_INVALID before the head or when `endStream` would cut
|
|
2115
2271
|
* short the DATA frame the last call started.
|
|
2272
|
+
* A window outside `buf` panics.
|
|
2273
|
+
*
|
|
2274
|
+
* @param id The request stream, after `respond`.
|
|
2275
|
+
* @param buf The body bytes; copied into the stream's send buffer, so the caller may reuse it.
|
|
2276
|
+
* @param off Where the bytes start in `buf`.
|
|
2277
|
+
* @param len How many bytes to offer; 0 with `endStream` sends only the end.
|
|
2278
|
+
* @param endStream True to end the stream once all `len` bytes are taken.
|
|
2279
|
+
* @returns The bytes taken, 1 to `len` — fewer when the send buffer filled, or when the stream closed
|
|
2280
|
+
* partway — or 0 for a `len` of 0; H3_AGAIN when it took none, or while bytes an earlier call
|
|
2281
|
+
* left owed cannot go; H3_CLOSED for a stream that is not an open request: unknown, not yet handed
|
|
2282
|
+
* to the program, its response finished or reset, stopped by the client, or any stream once the
|
|
2283
|
+
* connection has failed;
|
|
2284
|
+
* H3_INVALID as above.
|
|
2116
2285
|
*/
|
|
2117
2286
|
writeData(id: i64, buf: u8[], off: i32, len: i32, endStream: boolean): i32 {
|
|
2118
2287
|
h3CheckWindow("Http3Connection.writeData", buf, off, len)
|
|
@@ -2180,6 +2349,18 @@ export class Http3Connection {
|
|
|
2180
2349
|
* H3_AGAIN while the send buffer lacks room, and H3_WRITABLE then names the
|
|
2181
2350
|
* stream; or as `writeData` refuses, and H3_TOO_LARGE for a frame past the
|
|
2182
2351
|
* stream's buffer.
|
|
2352
|
+
* A window outside `buf` panics.
|
|
2353
|
+
*
|
|
2354
|
+
* @param id The request stream, after `respond`.
|
|
2355
|
+
* @param buf The frame's payload; copied into the stream's send buffer, so the caller may reuse it.
|
|
2356
|
+
* @param off Where the payload starts in `buf`.
|
|
2357
|
+
* @param len The payload's length in bytes; the frame with its header must fit the stream's buffer.
|
|
2358
|
+
* @param fin True to end the stream after the frame.
|
|
2359
|
+
* @returns 0 once the whole frame is in the send buffer; H3_AGAIN while the send buffer lacks room for
|
|
2360
|
+
* it, and H3_WRITABLE then names the stream; H3_CLOSED for a stream that is not an open request:
|
|
2361
|
+
* unknown, not yet handed to the program, its response finished or reset, stopped by the client, or
|
|
2362
|
+
* any stream once the connection has failed;
|
|
2363
|
+
* H3_INVALID before the head or inside a DATA frame `writeData` has not finished; H3_TOO_LARGE.
|
|
2183
2364
|
*/
|
|
2184
2365
|
writeDataWhole(id: i64, buf: u8[], off: i32, len: i32, fin: boolean): i32 {
|
|
2185
2366
|
h3CheckWindow("Http3Connection.writeDataWhole", buf, off, len)
|
|
@@ -2216,6 +2397,13 @@ export class Http3Connection {
|
|
|
2216
2397
|
* Resets request stream `id` both ways with `code` — H3_REQUEST_CANCELLED,
|
|
2217
2398
|
* or H3_REQUEST_REJECTED for one the program did not process (§4.1.1).
|
|
2218
2399
|
* Answers 0 or H3_CLOSED.
|
|
2400
|
+
*
|
|
2401
|
+
* @param id The request stream, as H3_REQUEST named it.
|
|
2402
|
+
* @param code The error code RESET_STREAM and STOP_SENDING carry; STOP_SENDING is not sent once the
|
|
2403
|
+
* request has been read to its end.
|
|
2404
|
+
* @returns 0; H3_CLOSED for a stream that is not an open request: unknown, not yet handed to the
|
|
2405
|
+
* program, its response finished or reset, stopped by the client, or any stream once the connection
|
|
2406
|
+
* has failed.
|
|
2219
2407
|
*/
|
|
2220
2408
|
reset(id: i64, code: i64): i32 {
|
|
2221
2409
|
const k: i32 = this.writeSlot(id)
|
|
@@ -2235,6 +2423,12 @@ export class Http3Connection {
|
|
|
2235
2423
|
* not opened, opened by a later stream's frame (RFC 9000 §3.2), or still
|
|
2236
2424
|
* waiting for its HEADERS. A WebTransport stream that names it as its
|
|
2237
2425
|
* session may wait for it.
|
|
2426
|
+
*
|
|
2427
|
+
* @param id A stream ID, as a WebTransport stream named its session.
|
|
2428
|
+
* @returns True while the request may still come: not opened and within what the client may open now,
|
|
2429
|
+
* opened but not yet read here, or waiting for its HEADERS; false for an ID that is no
|
|
2430
|
+
* client-initiated bidirectional stream, one at or past this side's GOAWAY, a WebTransport stream,
|
|
2431
|
+
* or one whose field section has been read or refused.
|
|
2238
2432
|
*/
|
|
2239
2433
|
awaitsRequest(id: i64): boolean {
|
|
2240
2434
|
if (!http3IsRequest(id) || id < 0 || (this.goawayId >= 0 && id >= this.goawayId)) {
|
|
@@ -2258,6 +2452,12 @@ export class Http3Connection {
|
|
|
2258
2452
|
* side has finished its response — a refused WebTransport session's
|
|
2259
2453
|
* stream, after its status. Answers 0, or H3_CLOSED for a stream that is
|
|
2260
2454
|
* not a request here.
|
|
2455
|
+
*
|
|
2456
|
+
* @param id The request stream.
|
|
2457
|
+
* @param code The error code STOP_SENDING carries; nothing is sent when the client's side has already
|
|
2458
|
+
* ended or is being dropped.
|
|
2459
|
+
* @returns 0, also when there was nothing left to stop; H3_CLOSED for an ID that is no request stream
|
|
2460
|
+
* known here, or any stream once the connection has failed.
|
|
2261
2461
|
*/
|
|
2262
2462
|
discardRequest(id: i64, code: i64): i32 {
|
|
2263
2463
|
if (this.state === H3_STATE_FAILED || !http3IsRequest(id)) {
|
|
@@ -2278,6 +2478,10 @@ export class Http3Connection {
|
|
|
2278
2478
|
* call never raises the ID, and sends nothing when the ID has not fallen.
|
|
2279
2479
|
* Answers 0, or H3_AGAIN before this side's control stream is open or while
|
|
2280
2480
|
* it has no room for the frame.
|
|
2481
|
+
*
|
|
2482
|
+
* @returns 0 once the frame is in the control stream's send buffer, or when there was nothing new to
|
|
2483
|
+
* send; H3_AGAIN before this side's control stream is open, while it has no room for the whole
|
|
2484
|
+
* frame, and on a connection that has failed.
|
|
2281
2485
|
*/
|
|
2282
2486
|
goaway(): i32 {
|
|
2283
2487
|
if (this.ownControl < 0 || this.state === H3_STATE_FAILED) {
|