@amritk/nish-aarch64-linux 0.34.1 → 0.36.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 +22 -13
- package/bin/nish +0 -0
- package/docs/AI.md +86 -16
- package/package.json +1 -1
- package/runtime/async.d.mts +49 -0
- package/runtime/async.mjs +27 -0
- package/runtime/nish.d.ts +4681 -427
- package/runtime/nish.h +6 -2
- package/runtime/nish.mjs +4 -0
- package/runtime/runtime-net.c +22 -0
- package/runtime/runtime-shm.c +93 -2
- package/runtime/vite.d.ts +30 -0
- package/runtime/vite.mjs +150 -0
- package/scripts/build.sh +108 -13
- package/std/README.md +131 -131
- package/std/base64.ts +34 -5
- package/std/bytes.ts +258 -42
- 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 +80 -9
- package/std/crypto/base64url.ts +22 -0
- package/std/crypto/bcrypt-batch.ts +88 -21
- package/std/crypto/bcrypt.ts +60 -0
- package/std/crypto/chacha20poly1305.ts +53 -0
- package/std/crypto/ct.ts +32 -13
- package/std/crypto/ed25519.ts +47 -0
- package/std/crypto/hkdf.ts +198 -13
- package/std/crypto/hmac.ts +235 -31
- package/std/crypto/jwt.ts +192 -63
- package/std/crypto/p256.ts +159 -16
- package/std/crypto/p384.ts +28 -3
- package/std/crypto/pki-roots.ts +32 -2
- package/std/crypto/pki.ts +81 -15
- package/std/crypto/rsa.ts +33 -3
- 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 +152 -14
- package/std/crypto/x509-random.ts +10 -0
- package/std/crypto/x509.ts +67 -7
- package/std/json-equal.ts +19 -0
- package/std/json-format.ts +112 -13
- package/std/json-number.ts +64 -14
- package/std/json-pointer.ts +23 -1
- package/std/json-tokenizer.ts +100 -29
- package/std/json-typed.ts +713 -66
- package/std/json-value.ts +400 -124
- package/std/json.ts +138 -10
- 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 +151 -61
- package/std/net/handler.ts +278 -80
- package/std/net/hpack.ts +262 -52
- package/std/net/http-compress.ts +125 -15
- package/std/net/http-fields.ts +85 -9
- package/std/net/http1-client-codec.ts +100 -19
- package/std/net/http1-codec.ts +297 -77
- package/std/net/http1-server.ts +430 -94
- package/std/net/http2-frame.ts +272 -35
- package/std/net/http2-tls.ts +135 -34
- package/std/net/http2.ts +247 -106
- package/std/net/http3-frame.ts +154 -17
- package/std/net/http3-server.ts +275 -101
- package/std/net/http3.ts +307 -115
- package/std/net/outbound.ts +37 -3
- package/std/net/postgres-carrier.ts +144 -8
- package/std/net/postgres.ts +801 -112
- package/std/net/prefork.ts +164 -31
- package/std/net/qpack.ts +105 -18
- package/std/net/quic-conn-ack.ts +59 -12
- package/std/net/quic-conn-cid.ts +124 -27
- package/std/net/quic-conn-params.ts +70 -10
- package/std/net/quic-datagram.ts +43 -3
- package/std/net/quic-frame.ts +286 -12
- package/std/net/quic-listener.ts +101 -32
- package/std/net/quic-packet.ts +302 -21
- package/std/net/quic-recovery.ts +264 -52
- package/std/net/quic-stream.ts +353 -91
- package/std/net/quic.ts +1124 -201
- package/std/net/router.ts +87 -40
- package/std/net/tls/client.ts +166 -51
- package/std/net/tls/codec.ts +413 -56
- package/std/net/tls/record-client.ts +110 -55
- package/std/net/tls/record-server.ts +159 -59
- package/std/net/tls/record.ts +109 -12
- package/std/net/tls/schedule.ts +235 -26
- package/std/net/tls/ticket.ts +159 -40
- package/std/net/tls/verify.ts +49 -3
- package/std/net/tls-tcp.ts +250 -45
- package/std/net/tls.ts +221 -59
- package/std/net/upstream.ts +81 -45
- package/std/net/url.ts +97 -13
- package/std/net/websocket.ts +122 -12
- package/std/net/webtransport.ts +220 -89
- package/std/pair.ts +10 -2
- package/std/random.ts +34 -9
- package/std/regex.ts +352 -198
- 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 +430 -40
- package/std/sync/shm.ts +222 -15
- package/std/term-io.ts +137 -64
- package/std/term-pixels.ts +144 -19
- package/std/term-probe.ts +66 -25
- package/std/term-rate.ts +128 -57
- package/std/term.ts +332 -121
- package/std/testing.ts +130 -32
- package/std/text.ts +73 -7
- package/std/threads.ts +229 -41
- package/std/yaml-json.ts +94 -82
- package/std/yaml-lines.ts +47 -15
- package/std/yaml-write.ts +24 -16
- package/std/yaml.ts +764 -384
package/std/net/http3-frame.ts
CHANGED
|
@@ -5,14 +5,20 @@
|
|
|
5
5
|
* unknown. Sans-IO: every reader takes a byte window `(buf, off, len)` and
|
|
6
6
|
* reads it in place, and every writer writes into the caller's buffer at an
|
|
7
7
|
* offset, before an end, and answers the offset past what it wrote, or -1
|
|
8
|
-
*
|
|
8
|
+
* when it does not fit (the frame writers may have written their header by
|
|
9
|
+
* then). Nothing here allocates.
|
|
9
10
|
*
|
|
10
|
-
* import {
|
|
11
|
+
* import {
|
|
12
|
+
* Http3FrameHeader, h3ReadFrameHeader, h3PutFrameHeader, H3_FRAME_DATA, H3_FRAME_HEADER_MAX,
|
|
13
|
+
* } from "nish/net/http3-frame";
|
|
11
14
|
*
|
|
15
|
+
* const buf: u8[] = [0x00, 0x03, 0x61, 0x62, 0x63]; // bytes a stream delivered: DATA, 3 bytes
|
|
12
16
|
* const h = new Http3FrameHeader();
|
|
13
|
-
* const size: i32 = h3ReadFrameHeader(h, buf,
|
|
17
|
+
* const size: i32 = h3ReadFrameHeader(h, buf, 0, toI32(buf.length)); // 2; 0 if the header is cut off
|
|
14
18
|
* // h.type, h.length; the payload is the next h.length bytes of the stream
|
|
15
|
-
* const
|
|
19
|
+
* const out: u8[] = new Array<u8>(H3_FRAME_HEADER_MAX);
|
|
20
|
+
* const n: i32 = 3;
|
|
21
|
+
* const at: i32 = h3PutFrameHeader(out, 0, toI32(out.length), H3_FRAME_DATA, toI64(n)); // 2
|
|
16
22
|
*
|
|
17
23
|
* **Frames** (§7.1) are a type and a length, each a QUIC variable-length
|
|
18
24
|
* integer, and then that many bytes of payload. On a QUIC stream a frame may
|
|
@@ -128,22 +134,39 @@ export const H3_SETTINGS_KEEP: i32 = 8
|
|
|
128
134
|
|
|
129
135
|
/** What `h3ReadSettings` answers for a payload it read whole. */
|
|
130
136
|
export const H3_SETTINGS_OK: i64 = 0
|
|
137
|
+
/** H3_NO_ERROR (0x0100): no error, for closing a connection or stream with nothing to signal (§8.1). */
|
|
131
138
|
export const H3_NO_ERROR: i64 = 0x0100
|
|
139
|
+
/** H3_GENERAL_PROTOCOL_ERROR (0x0101): a protocol violation no more specific code names (§8.1). */
|
|
132
140
|
export const H3_GENERAL_PROTOCOL_ERROR: i64 = 0x0101
|
|
141
|
+
/** H3_INTERNAL_ERROR (0x0102): an internal error in the HTTP stack (§8.1). */
|
|
133
142
|
export const H3_INTERNAL_ERROR: i64 = 0x0102
|
|
143
|
+
/** H3_STREAM_CREATION_ERROR (0x0103): the peer created a stream this endpoint will not accept (§8.1). */
|
|
134
144
|
export const H3_STREAM_CREATION_ERROR: i64 = 0x0103
|
|
145
|
+
/** H3_CLOSED_CRITICAL_STREAM (0x0104): a stream the connection needs was closed or reset (§8.1). */
|
|
135
146
|
export const H3_CLOSED_CRITICAL_STREAM: i64 = 0x0104
|
|
147
|
+
/** H3_FRAME_UNEXPECTED (0x0105): a frame not allowed in the current state or on its stream (§8.1). */
|
|
136
148
|
export const H3_FRAME_UNEXPECTED: i64 = 0x0105
|
|
149
|
+
/** H3_FRAME_ERROR (0x0106): a frame whose layout or size is wrong (§8.1). */
|
|
137
150
|
export const H3_FRAME_ERROR: i64 = 0x0106
|
|
151
|
+
/** H3_EXCESSIVE_LOAD (0x0107): the peer behaves in a way that may cause excessive load (§8.1). */
|
|
138
152
|
export const H3_EXCESSIVE_LOAD: i64 = 0x0107
|
|
153
|
+
/** H3_ID_ERROR (0x0108): a stream ID or push ID used wrongly, such as past a limit or reused (§8.1). */
|
|
139
154
|
export const H3_ID_ERROR: i64 = 0x0108
|
|
155
|
+
/** H3_SETTINGS_ERROR (0x0109): an error in a SETTINGS payload (§8.1, §7.2.4). */
|
|
140
156
|
export const H3_SETTINGS_ERROR: i64 = 0x0109
|
|
157
|
+
/** H3_MISSING_SETTINGS (0x010a): the control stream did not start with SETTINGS (§8.1, §6.2.1). */
|
|
141
158
|
export const H3_MISSING_SETTINGS: i64 = 0x010a
|
|
159
|
+
/** H3_REQUEST_REJECTED (0x010b): the server refused a request before any processing of it (§8.1). */
|
|
142
160
|
export const H3_REQUEST_REJECTED: i64 = 0x010b
|
|
161
|
+
/** H3_REQUEST_CANCELLED (0x010c): a request or its response is cancelled (§8.1). */
|
|
143
162
|
export const H3_REQUEST_CANCELLED: i64 = 0x010c
|
|
163
|
+
/** H3_REQUEST_INCOMPLETE (0x010d): the client's stream ended without a whole request (§8.1). */
|
|
144
164
|
export const H3_REQUEST_INCOMPLETE: i64 = 0x010d
|
|
165
|
+
/** H3_MESSAGE_ERROR (0x010e): a malformed HTTP message (§8.1, §4.1.2). */
|
|
145
166
|
export const H3_MESSAGE_ERROR: i64 = 0x010e
|
|
167
|
+
/** H3_CONNECT_ERROR (0x010f): a CONNECT request's TCP connection was reset or closed abnormally (§8.1). */
|
|
146
168
|
export const H3_CONNECT_ERROR: i64 = 0x010f
|
|
169
|
+
/** H3_VERSION_FALLBACK (0x0110): the request cannot be served over HTTP/3; retry it over HTTP/1.1 (§8.1). */
|
|
147
170
|
export const H3_VERSION_FALLBACK: i64 = 0x0110
|
|
148
171
|
/** WT_SESSION_GONE (draft-ietf-webtrans-http3-02 §4.5): a WebTransport stream of a session that is gone, or can never come. */
|
|
149
172
|
export const H3_WT_SESSION_GONE: i64 = 0x170d7b68
|
|
@@ -164,7 +187,9 @@ const H3_FRAME_ZERO: i32 = 0
|
|
|
164
187
|
|
|
165
188
|
/** One frame header as `h3ReadFrameHeader` read it: the type and the payload's length. */
|
|
166
189
|
export class Http3FrameHeader {
|
|
190
|
+
/** The frame type, 0 to 2^62 - 1, any value: set by each `h3ReadFrameHeader` that answers above 0. */
|
|
167
191
|
type: i64 = 0
|
|
192
|
+
/** The payload's length in bytes, 0 to 2^62 - 1, set with `type`; the payload itself is not read here. */
|
|
168
193
|
length: i64 = 0
|
|
169
194
|
}
|
|
170
195
|
|
|
@@ -176,10 +201,16 @@ export class Http3FrameHeader {
|
|
|
176
201
|
* values, in order, and the rest counted in `dropped`.
|
|
177
202
|
*/
|
|
178
203
|
export class Http3Settings {
|
|
179
|
-
unknownIds: i64[]
|
|
180
|
-
unknownValues: i64[]
|
|
204
|
+
private unknownIds: i64[]
|
|
205
|
+
private unknownValues: i64[]
|
|
206
|
+
/** SETTINGS_QPACK_MAX_TABLE_CAPACITY in bytes as the peer sent it, unchecked; 0 by default. */
|
|
181
207
|
maxTableCapacity: i64 = 0
|
|
208
|
+
/**
|
|
209
|
+
* SETTINGS_MAX_FIELD_SECTION_SIZE as the peer sent it: the largest field section it takes, as §4.2.2
|
|
210
|
+
* counts it; -1, unlimited, by default.
|
|
211
|
+
*/
|
|
182
212
|
maxFieldSectionSize: i64 = -1
|
|
213
|
+
/** SETTINGS_QPACK_BLOCKED_STREAMS, a count of streams, as the peer sent it, unchecked; 0 by default. */
|
|
183
214
|
blockedStreams: i64 = 0
|
|
184
215
|
/**
|
|
185
216
|
* The extension settings WebTransport reads, -1 when the frame did not
|
|
@@ -189,8 +220,11 @@ export class Http3Settings {
|
|
|
189
220
|
* as an unknown identifier while there is room, so `unknown` still finds it.
|
|
190
221
|
*/
|
|
191
222
|
enableConnectProtocol: i64 = -1
|
|
223
|
+
/** SETTINGS_H3_DATAGRAM's value as the peer sent it, or -1 when the frame did not carry it. */
|
|
192
224
|
h3Datagram: i64 = -1
|
|
225
|
+
/** SETTINGS_ENABLE_WEBTRANSPORT's value as the peer sent it, or -1 when the frame did not carry it. */
|
|
193
226
|
enableWebtransport: i64 = -1
|
|
227
|
+
/** SETTINGS_WEBTRANSPORT_MAX_SESSIONS's value as the peer sent it, or -1 when the frame lacked it. */
|
|
194
228
|
webtransportMaxSessions: i64 = -1
|
|
195
229
|
/** The bits of the identifiers understood that the frame set. */
|
|
196
230
|
seen: i32 = 0
|
|
@@ -199,12 +233,17 @@ export class Http3Settings {
|
|
|
199
233
|
/** How many more there were, saturating at 2^31 - 1. */
|
|
200
234
|
dropped: i32 = 0
|
|
201
235
|
|
|
236
|
+
/** Settings at their defaults, with room for `H3_SETTINGS_KEEP` unknown identifiers made once. */
|
|
202
237
|
constructor() {
|
|
203
238
|
this.unknownIds = new Array<i64>(H3_SETTINGS_KEEP)
|
|
204
239
|
this.unknownValues = new Array<i64>(H3_SETTINGS_KEEP)
|
|
205
240
|
}
|
|
206
241
|
|
|
207
|
-
/**
|
|
242
|
+
/**
|
|
243
|
+
* Back to the defaults, for the next connection.
|
|
244
|
+
* @internal Called by `h3ReadSettings` before it reads and by `http3.ts`'s connection restart; not for
|
|
245
|
+
* callers.
|
|
246
|
+
*/
|
|
208
247
|
reset(): void {
|
|
209
248
|
this.maxTableCapacity = 0
|
|
210
249
|
this.maxFieldSectionSize = -1
|
|
@@ -218,7 +257,12 @@ export class Http3Settings {
|
|
|
218
257
|
this.dropped = 0
|
|
219
258
|
}
|
|
220
259
|
|
|
221
|
-
/**
|
|
260
|
+
/**
|
|
261
|
+
* The value of an identifier this module does not understand.
|
|
262
|
+
* @param id The setting identifier to look up among the kept ones.
|
|
263
|
+
* @returns Its value as the peer sent it, 0 to 2^62 - 1, or -1 when it is not kept; -1 also for the three
|
|
264
|
+
* identifiers this module understands, which are never kept.
|
|
265
|
+
*/
|
|
222
266
|
unknown(id: i64): i64 {
|
|
223
267
|
for (let k: i32 = 0; k < this.unknownCount && k < H3_SETTINGS_KEEP; k++) {
|
|
224
268
|
if (this.unknownIds[k] === id) {
|
|
@@ -228,7 +272,10 @@ export class Http3Settings {
|
|
|
228
272
|
return H3_FRAME_NONE
|
|
229
273
|
}
|
|
230
274
|
|
|
231
|
-
/**
|
|
275
|
+
/**
|
|
276
|
+
* Records one pair; answers `H3_SETTINGS_OK` or H3_SETTINGS_ERROR for a reserved or repeated identifier.
|
|
277
|
+
* @internal Called once per pair by `h3ReadSettings`, which resets first; not for callers.
|
|
278
|
+
*/
|
|
232
279
|
take(id: i64, value: i64): i64 {
|
|
233
280
|
if (id === 0x00 || (id >= 0x02 && id <= 0x05)) {
|
|
234
281
|
return H3_SETTINGS_ERROR
|
|
@@ -288,14 +335,24 @@ export class Http3Settings {
|
|
|
288
335
|
}
|
|
289
336
|
}
|
|
290
337
|
|
|
291
|
-
/**
|
|
338
|
+
/**
|
|
339
|
+
* Panics unless `[off, off + len)` lies inside `buf`: a window outside its buffer is the program's mistake.
|
|
340
|
+
* @param what The caller's name, which starts the panic message.
|
|
341
|
+
* @param buf The buffer the window is meant to lie in.
|
|
342
|
+
* @param off The window's first byte offset; negative panics.
|
|
343
|
+
* @param len The window's length in bytes; negative panics, and so does an end past `buf.length`.
|
|
344
|
+
*/
|
|
292
345
|
export const h3CheckWindow = (what: string, buf: u8[], off: i32, len: i32): void => {
|
|
293
346
|
if (off < 0 || len < 0 || toI64(off) + toI64(len) > toI64(buf.length)) {
|
|
294
347
|
panic(`${what}: the window [${off}, ${off} + ${len}) is outside a buffer of ${buf.length} bytes`)
|
|
295
348
|
}
|
|
296
349
|
}
|
|
297
350
|
|
|
298
|
-
/**
|
|
351
|
+
/**
|
|
352
|
+
* `count` plus one, saturating at 2^31 - 1: every counter a peer drives.
|
|
353
|
+
* @param count The counter's current value.
|
|
354
|
+
* @returns `count + 1`, or `count` unchanged once it is 2^31 - 1.
|
|
355
|
+
*/
|
|
299
356
|
export const h3Count = (count: i32): i32 => (count < 2147483647 ? count + 1 : count)
|
|
300
357
|
|
|
301
358
|
/** Whether `[at, end)` is a usable place to write in `buf`. */
|
|
@@ -305,16 +362,34 @@ const h3FrameRoom = (buf: u8[], at: i32, end: i32): boolean =>
|
|
|
305
362
|
/**
|
|
306
363
|
* The varint at `buf[at]`, read only from `buf[at .. end)`, or -1 when it
|
|
307
364
|
* does not fit there. Advance past it by `h3VarintLength(buf, at)`.
|
|
365
|
+
* @param buf The bytes holding the integer.
|
|
366
|
+
* @param at The byte offset of the integer's first byte.
|
|
367
|
+
* @param end The offset the integer must end at or before; past `buf.length` reads nothing.
|
|
368
|
+
* @returns The value, 0 to 2^62 - 1, or -1 when `at` is outside `buf`, `end` is past `buf.length`, or the
|
|
369
|
+
* integer's bytes run past `end`.
|
|
308
370
|
*/
|
|
309
371
|
export const h3ReadVarint = (buf: u8[], at: i32, end: i32): i64 => quicVarintRead(buf, at, end)
|
|
310
372
|
|
|
311
|
-
/**
|
|
373
|
+
/**
|
|
374
|
+
* The length of the varint whose first byte is `buf[at]`.
|
|
375
|
+
* @param buf The bytes holding the integer.
|
|
376
|
+
* @param at The byte offset of the integer's first byte.
|
|
377
|
+
* @returns 1, 2, 4 or 8 bytes, read from the first byte's two-bit prefix alone (the rest need not be in
|
|
378
|
+
* `buf`), or 0 when `at` is outside `buf`.
|
|
379
|
+
*/
|
|
312
380
|
export const h3VarintLength = (buf: u8[], at: i32): i32 => quicVarintLength(buf, at)
|
|
313
381
|
|
|
314
382
|
/**
|
|
315
383
|
* Writes `value` as a varint in the fewest bytes at `buf[at]`, before `end`,
|
|
316
384
|
* and answers the offset past it, or -1 when it does not fit or no varint
|
|
317
385
|
* holds the value.
|
|
386
|
+
* @param buf The buffer to write into.
|
|
387
|
+
* @param at The byte offset to write the first byte at.
|
|
388
|
+
* @param end The offset the integer must end at or before; at most `buf.length`.
|
|
389
|
+
* @param value The value to encode, 0 to 2^62 - 1.
|
|
390
|
+
* @returns The offset past the 1, 2, 4 or 8 bytes written, or -1 with nothing written when `value` is
|
|
391
|
+
* negative or above 2^62 - 1, `[at, end)` is not a window inside `buf`, or the integer does not fit before
|
|
392
|
+
* `end`.
|
|
318
393
|
*/
|
|
319
394
|
export const h3PutVarint = (buf: u8[], at: i32, end: i32, value: i64): i32 => {
|
|
320
395
|
const size: i32 = quicVarintSize(value)
|
|
@@ -324,7 +399,12 @@ export const h3PutVarint = (buf: u8[], at: i32, end: i32, value: i64): i32 => {
|
|
|
324
399
|
return quicVarintPut(buf, at, value, size)
|
|
325
400
|
}
|
|
326
401
|
|
|
327
|
-
/**
|
|
402
|
+
/**
|
|
403
|
+
* How many bytes a frame header of `type` and `length` takes.
|
|
404
|
+
* @param type The frame type.
|
|
405
|
+
* @param length The payload's length in bytes.
|
|
406
|
+
* @returns 2 to 16 bytes, or 0 when `type` or `length` is negative or above 2^62 - 1.
|
|
407
|
+
*/
|
|
328
408
|
export const h3FrameHeaderSize = (type: i64, length: i64): i32 => {
|
|
329
409
|
const a: i32 = quicVarintSize(type)
|
|
330
410
|
const b: i32 = quicVarintSize(length)
|
|
@@ -336,6 +416,11 @@ export const h3FrameHeaderSize = (type: i64, length: i64): i32 => {
|
|
|
336
416
|
* many bytes it took, or 0 when the window ends inside it (and `h` is not
|
|
337
417
|
* touched). Any type and any length up to 2^62 - 1 is a header; whether the
|
|
338
418
|
* type is allowed where it arrived is the stream's question.
|
|
419
|
+
* @param h The header to fill; set only when the answer is above 0.
|
|
420
|
+
* @param buf The bytes the stream delivered.
|
|
421
|
+
* @param off The window's first byte offset, where the header starts.
|
|
422
|
+
* @param len The window's length in bytes; the window must lie inside `buf`, or this panics.
|
|
423
|
+
* @returns The header's size, 2 to 16 bytes, or 0 when the window ends before both varints are whole.
|
|
339
424
|
*/
|
|
340
425
|
export const h3ReadFrameHeader = (h: Http3FrameHeader, buf: u8[], off: i32, len: i32): i32 => {
|
|
341
426
|
h3CheckWindow("h3ReadFrameHeader", buf, off, len)
|
|
@@ -354,7 +439,16 @@ export const h3ReadFrameHeader = (h: Http3FrameHeader, buf: u8[], off: i32, len:
|
|
|
354
439
|
return at + quicVarintLength(buf, at) - off
|
|
355
440
|
}
|
|
356
441
|
|
|
357
|
-
/**
|
|
442
|
+
/**
|
|
443
|
+
* Writes a frame header of `type` and `length` at `buf[at]`, before `end`.
|
|
444
|
+
* @param buf The buffer to write into.
|
|
445
|
+
* @param at The byte offset to write the header at.
|
|
446
|
+
* @param end The offset the header must end at or before; at most `buf.length`.
|
|
447
|
+
* @param type The frame type, 0 to 2^62 - 1, written as given.
|
|
448
|
+
* @param length The payload's length in bytes, 0 to 2^62 - 1; the payload is the caller's to write.
|
|
449
|
+
* @returns The offset past the 2 to 16 bytes written, or -1 with nothing written when `type` or `length` is
|
|
450
|
+
* no varint, `[at, end)` is not a window inside `buf`, or the header does not fit before `end`.
|
|
451
|
+
*/
|
|
358
452
|
export const h3PutFrameHeader = (buf: u8[], at: i32, end: i32, type: i64, length: i64): i32 => {
|
|
359
453
|
const size: i32 = h3FrameHeaderSize(type, length)
|
|
360
454
|
if (size === 0 || !h3FrameRoom(buf, at, end) || at > end - size) {
|
|
@@ -363,11 +457,21 @@ export const h3PutFrameHeader = (buf: u8[], at: i32, end: i32, type: i64, length
|
|
|
363
457
|
return h3PutVarint(buf, h3PutVarint(buf, at, end, type), end, length)
|
|
364
458
|
}
|
|
365
459
|
|
|
366
|
-
/**
|
|
460
|
+
/**
|
|
461
|
+
* Whether `type` is one HTTP/2 used that HTTP/3 reserves, whose receipt is H3_FRAME_UNEXPECTED (§7.2.8).
|
|
462
|
+
* @param type A frame type as read.
|
|
463
|
+
* @returns True for 0x02, 0x06, 0x08 and 0x09; false for every other type.
|
|
464
|
+
*/
|
|
367
465
|
export const h3ReservedHttp2Frame = (type: i64): boolean =>
|
|
368
466
|
type === 0x02 || type === 0x06 || type === 0x08 || type === 0x09
|
|
369
467
|
|
|
370
|
-
/**
|
|
468
|
+
/**
|
|
469
|
+
* Whether `value` is one of the `0x1f * N + 0x21` values reserved to exercise the rule that unknowns are
|
|
470
|
+
* ignored (§7.2.8, §7.2.4.1, §6.2.3).
|
|
471
|
+
* @param value A frame type, setting identifier or stream type.
|
|
472
|
+
* @returns True when `value` is 0x21 or above and 0x21 more than a multiple of 0x1f; false otherwise,
|
|
473
|
+
* negatives included.
|
|
474
|
+
*/
|
|
371
475
|
export const h3Greased = (value: i64): boolean => value >= 0x21 && (value - 0x21) % 0x1f === 0
|
|
372
476
|
|
|
373
477
|
/**
|
|
@@ -375,6 +479,15 @@ export const h3Greased = (value: i64): boolean => value >= 0x21 && (value - 0x21
|
|
|
375
479
|
* resets first). Answers `H3_SETTINGS_OK`, H3_FRAME_ERROR for a payload that
|
|
376
480
|
* ends inside a pair (§7.1), or H3_SETTINGS_ERROR for a reserved or repeated
|
|
377
481
|
* identifier (§7.2.4).
|
|
482
|
+
* @param s The settings to fill; reset first, and after an error answer its contents are not meaningful.
|
|
483
|
+
* @param buf The bytes holding the payload.
|
|
484
|
+
* @param off The payload's first byte offset.
|
|
485
|
+
* @param len The payload's length in bytes, the frame header's `length`; the window must lie inside `buf`,
|
|
486
|
+
* or this panics. An empty payload is read as the defaults.
|
|
487
|
+
* @returns `H3_SETTINGS_OK` when every pair was read; H3_FRAME_ERROR when the payload ends inside an
|
|
488
|
+
* identifier or a value; H3_SETTINGS_ERROR for an identifier HTTP/2 defined (0x00, 0x02 to 0x05) or a
|
|
489
|
+
* repeat of an identifier understood, of an extension one, or of a kept unknown one. It stops at the first
|
|
490
|
+
* error.
|
|
378
491
|
*/
|
|
379
492
|
export const h3ReadSettings = (s: Http3Settings, buf: u8[], off: i32, len: i32): i64 => {
|
|
380
493
|
h3CheckWindow("h3ReadSettings", buf, off, len)
|
|
@@ -403,8 +516,17 @@ export const h3ReadSettings = (s: Http3Settings, buf: u8[], off: i32, len: i32):
|
|
|
403
516
|
/**
|
|
404
517
|
* Writes a whole SETTINGS frame of the pairs `ids[k]`, `values[k]` at
|
|
405
518
|
* `buf[at]`, before `end`, and answers the offset past it, or -1 when it does
|
|
406
|
-
* not fit, the lists differ in length, or a value is no varint. It writes
|
|
519
|
+
* not fit, the lists differ in length, or an identifier or a value is no varint. It writes
|
|
407
520
|
* what it is given: refusing a reserved identifier is the reader's job.
|
|
521
|
+
* @param buf The buffer to write into.
|
|
522
|
+
* @param at The byte offset to write the frame at.
|
|
523
|
+
* @param end The offset the frame must end at or before; at most `buf.length`.
|
|
524
|
+
* @param ids The setting identifiers, in the order they are written; read, not kept.
|
|
525
|
+
* @param values The values, one per identifier at the same index; read, not kept.
|
|
526
|
+
* @returns The offset past the frame written, header and payload, or -1 when the lists differ in length,
|
|
527
|
+
* an identifier or a value is negative or above 2^62 - 1, `[at, end)` is not a window inside `buf`, or
|
|
528
|
+
* the frame does not fit before `end`. Nothing is written for the first three; when only the payload
|
|
529
|
+
* does not fit, the header may already be in `buf[at ..]`.
|
|
408
530
|
*/
|
|
409
531
|
export const h3PutSettings = (buf: u8[], at: i32, end: i32, ids: i64[], values: i64[]): i32 => {
|
|
410
532
|
const n: i32 = toI32(ids.length)
|
|
@@ -435,6 +557,15 @@ export const h3PutSettings = (buf: u8[], at: i32, end: i32, ids: i64[], values:
|
|
|
435
557
|
* Writes a frame whose payload is one identifier — GOAWAY, MAX_PUSH_ID or
|
|
436
558
|
* CANCEL_PUSH (§7.2.6, §7.2.7, §7.2.3) — at `buf[at]`, before `end`; answers
|
|
437
559
|
* the offset past it, or -1.
|
|
560
|
+
* @param buf The buffer to write into.
|
|
561
|
+
* @param at The byte offset to write the frame at.
|
|
562
|
+
* @param end The offset the frame must end at or before; at most `buf.length`.
|
|
563
|
+
* @param type The frame type, written as given: `H3_FRAME_GOAWAY`, `H3_FRAME_MAX_PUSH_ID` or
|
|
564
|
+
* `H3_FRAME_CANCEL_PUSH`, which this does not check.
|
|
565
|
+
* @param id The stream ID or push ID the payload carries, 0 to 2^62 - 1.
|
|
566
|
+
* @returns The offset past the frame written, or -1 when `type` or `id` is no varint, `[at, end)` is not a
|
|
567
|
+
* window inside `buf`, or the frame does not fit before `end`; when only the identifier does not fit, the
|
|
568
|
+
* header may already be in `buf[at ..]`.
|
|
438
569
|
*/
|
|
439
570
|
export const h3PutIdFrame = (buf: u8[], at: i32, end: i32, type: i64, id: i64): i32 => {
|
|
440
571
|
const size: i32 = quicVarintSize(id)
|
|
@@ -449,6 +580,12 @@ export const h3PutIdFrame = (buf: u8[], at: i32, end: i32, type: i64, id: i64):
|
|
|
449
580
|
* The identifier a GOAWAY, MAX_PUSH_ID or CANCEL_PUSH payload
|
|
450
581
|
* `buf[off, off + len)` carries, or -1 when the payload is not exactly one
|
|
451
582
|
* varint, which is H3_FRAME_ERROR (§7.1).
|
|
583
|
+
* @param buf The bytes holding the payload.
|
|
584
|
+
* @param off The payload's first byte offset.
|
|
585
|
+
* @param len The payload's length in bytes, the frame header's `length`; the window must lie inside `buf`,
|
|
586
|
+
* or this panics.
|
|
587
|
+
* @returns The identifier, 0 to 2^62 - 1, or -1 when the payload is empty, ends inside the varint, or has
|
|
588
|
+
* bytes after it.
|
|
452
589
|
*/
|
|
453
590
|
export const h3ReadIdPayload = (buf: u8[], off: i32, len: i32): i64 => {
|
|
454
591
|
h3CheckWindow("h3ReadIdPayload", buf, off, len)
|