@amritk/nish-aarch64-linux 0.36.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 +67 -58
- package/bin/nish +0 -0
- package/docs/AI.md +43 -4
- package/package.json +1 -1
- package/runtime/async.d.mts +2 -0
- package/runtime/async.mjs +7 -0
- package/runtime/nish.d.ts +736 -499
- 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/scripts/build.sh +147 -5
- package/std/README.md +107 -82
- package/std/bytes.ts +23 -19
- package/std/compress/checksum.ts +1 -1
- package/std/crypto/aes.ts +48 -43
- package/std/crypto/base64url.ts +7 -5
- package/std/crypto/bcrypt-batch.ts +13 -13
- package/std/crypto/bcrypt.ts +33 -27
- package/std/crypto/chacha20poly1305.ts +16 -14
- package/std/crypto/ed25519.ts +19 -16
- package/std/crypto/hmac.ts +7 -6
- package/std/crypto/jwt.ts +23 -20
- package/std/crypto/p256.ts +63 -56
- package/std/crypto/p384.ts +23 -20
- package/std/crypto/pki.ts +18 -15
- package/std/crypto/rsa.ts +23 -19
- package/std/crypto/x25519.ts +11 -10
- package/std/crypto/x509.ts +69 -62
- package/std/host/ring.ts +124 -0
- package/std/json-equal.ts +12 -11
- package/std/json-number.ts +12 -12
- package/std/json-tokenizer.ts +26 -22
- package/std/json-typed.ts +92 -78
- package/std/json-value.ts +38 -33
- package/std/json.ts +32 -28
- package/std/net/fetch.ts +1117 -230
- package/std/net/handler.ts +18 -0
- package/std/net/hpack.ts +29 -26
- package/std/net/http-compress.ts +27 -21
- package/std/net/http1-client-codec.ts +29 -25
- package/std/net/http1-codec.ts +44 -87
- package/std/net/http1-server.ts +66 -54
- package/std/net/http2-frame.ts +17 -16
- package/std/net/http2-tls.ts +17 -15
- package/std/net/http2.ts +67 -54
- package/std/net/http3-frame.ts +11 -10
- package/std/net/http3-server.ts +36 -35
- package/std/net/http3.ts +70 -58
- package/std/net/postgres.ts +178 -160
- package/std/net/prefork.ts +38 -34
- package/std/net/qpack.ts +15 -14
- package/std/net/quic-conn-ack.ts +1 -0
- package/std/net/quic-conn-cid.ts +11 -0
- package/std/net/quic-conn-params.ts +41 -14
- package/std/net/quic-datagram.ts +7 -0
- package/std/net/quic-frame.ts +48 -12
- package/std/net/quic-listener.ts +61 -44
- package/std/net/quic-packet.ts +71 -52
- package/std/net/quic-recovery.ts +59 -21
- package/std/net/quic-stream.ts +83 -55
- package/std/net/quic.ts +204 -152
- package/std/net/tls/client.ts +1 -0
- package/std/net/tls/codec.ts +81 -12
- package/std/net/tls/record-client.ts +30 -18
- package/std/net/tls/record-server.ts +74 -46
- package/std/net/tls/record.ts +33 -24
- package/std/net/tls/ticket.ts +2 -0
- package/std/net/tls/verify.ts +8 -7
- package/std/net/tls-tcp.ts +58 -50
- package/std/net/tls.ts +55 -43
- package/std/net/url.ts +12 -9
- package/std/net/websocket.ts +23 -19
- package/std/net/webtransport.ts +24 -18
- package/std/random.ts +8 -6
- package/std/regex.ts +70 -59
- package/std/sync/ring.ts +24 -21
- package/std/sync/shm.ts +9 -7
- package/std/term-io.ts +17 -14
- package/std/term-probe.ts +11 -10
- package/std/term-rate.ts +71 -61
- package/std/term.ts +73 -59
- package/std/text.ts +11 -10
- package/std/threads.ts +19 -15
- package/std/yaml-json.ts +17 -15
- package/std/yaml-write.ts +21 -14
package/std/net/http1-server.ts
CHANGED
|
@@ -45,15 +45,16 @@
|
|
|
45
45
|
*
|
|
46
46
|
* **Streaming both ways.** A request body arrives a chunk at a time, at most
|
|
47
47
|
* `chunkSize` bytes in each `H1_BODY`, whether it was sent with
|
|
48
|
-
* `Content-Length` or chunked. A response is written with a length or
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* a
|
|
56
|
-
*
|
|
48
|
+
* `Content-Length` or chunked. A response is written with a length or chunked,
|
|
49
|
+
* a `write` at a time into the output buffer; a `write` takes what fits and
|
|
50
|
+
* answers how much, and when it could not take everything the connection
|
|
51
|
+
* answers `H1_NEED_MORE` until the socket has drained half the output, then
|
|
52
|
+
* `H1_WRITE`. Until then it reads nothing, so the window the program is writing
|
|
53
|
+
* from stays valid: back-pressure on the way out.
|
|
54
|
+
*
|
|
55
|
+
* Nothing buffers a whole body. On an `Http1Server` slot `sendBody` sends a
|
|
56
|
+
* body with a length from the program's own array, the queued output with it,
|
|
57
|
+
* and copies only what the socket did not take, under the same rules.
|
|
57
58
|
*
|
|
58
59
|
* **What the server decides.** The framing field (`Content-Length` or
|
|
59
60
|
* `Transfer-Encoding: chunked`) and the `Connection` field are the server's;
|
|
@@ -92,18 +93,20 @@
|
|
|
92
93
|
* instead of requests, the bytes that followed the request included. A ping
|
|
93
94
|
* is answered with a pong and a close with a close, by the connection.
|
|
94
95
|
*
|
|
95
|
-
* **Caps are start-up numbers**, all in `Http1Config`: the request target,
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
96
|
+
* **Caps are start-up numbers**, all in `Http1Config`: the request target, the
|
|
97
|
+
* header section and its field count, a request body, the chunk handed over,
|
|
98
|
+
* the output buffer, a WebSocket message, the idle timeout and the deadline for
|
|
99
|
+
* a whole request head (`headTimeout`, against slowloris); the slots are the
|
|
100
|
+
* pool's size.
|
|
101
|
+
*
|
|
102
|
+
* `Http1Server` builds a slot's connection on the first accept into it and
|
|
103
|
+
* keeps it, so a pool sized for its peak costs at start-up only what does not
|
|
104
|
+
* depend on the size, and holds at most `size` connections once the peak has
|
|
105
|
+
* come; `Http1TlsServer` does the same for a slot's connection and, through
|
|
106
|
+
* `TlsTcpServer`, its TLS state. Every buffer is allocated with its slot or
|
|
107
|
+
* grown to its cap on first use and kept, so a warmed slot serves request after
|
|
108
|
+
* request with `Arena.used()` flat. Accepting a WebSocket allocates (the accept
|
|
109
|
+
* key), once a connection.
|
|
107
110
|
*
|
|
108
111
|
* **Output is borrowed.** The pools' slots share an `Http1OutputPool`: a
|
|
109
112
|
* connection takes an `outputSize` buffer when it first needs room to write
|
|
@@ -508,6 +511,7 @@ const http1ServerReserved = (name: u8[]): boolean =>
|
|
|
508
511
|
*/
|
|
509
512
|
export class Http1OutputPool {
|
|
510
513
|
// Widest first, so the layout packs without padding.
|
|
514
|
+
/** The buffers given back and not yet taken again; `made - free.length` is how many are out. */
|
|
511
515
|
free: u8[][]
|
|
512
516
|
private size: i32 = 0
|
|
513
517
|
/** How many buffers the pool has made. */
|
|
@@ -579,6 +583,7 @@ export class Http1Connection {
|
|
|
579
583
|
pool: Http1OutputPool | null
|
|
580
584
|
/** Where the parser's input and head buffers go while the slot rests, with `Http1Config.idleInput`; null otherwise. */
|
|
581
585
|
inputs: Http1OutputPool | null
|
|
586
|
+
/** Where the parser's head buffer goes while the slot rests, beside `inputs`; null otherwise. */
|
|
582
587
|
heads: Http1OutputPool | null
|
|
583
588
|
/**
|
|
584
589
|
* The `Date` every final response carries. The connection makes its own;
|
|
@@ -606,7 +611,9 @@ export class Http1Connection {
|
|
|
606
611
|
* @internal Read by `std/net/handler.ts` to know how much of a sized body is still to write.
|
|
607
612
|
*/
|
|
608
613
|
responseLeft: i32 = 0
|
|
614
|
+
/** Where the unsent bytes start in `output`; a carrier sends from here and calls `consume` with what it sent. */
|
|
609
615
|
outputStart: i32 = 0
|
|
616
|
+
/** Where the unsent bytes end in `output`, one past the last; equal to `outputStart` when nothing waits. */
|
|
610
617
|
outputEnd: i32 = 0
|
|
611
618
|
/**
|
|
612
619
|
* `output.length`, kept beside the offsets so that `acquire` and `release`
|
|
@@ -634,7 +641,9 @@ export class Http1Connection {
|
|
|
634
641
|
private inputEnded: boolean = false
|
|
635
642
|
/** A head has begun to arrive and is not read whole yet: `headSince` is its deadline's start. */
|
|
636
643
|
headTimed: boolean = false
|
|
644
|
+
/** Where the bytes `H1_BODY` or `H1_WS_MESSAGE` handed over start in `data`. */
|
|
637
645
|
dataStart: i32 = 0
|
|
646
|
+
/** How many bytes `H1_BODY` or `H1_WS_MESSAGE` handed over, from `data[dataStart]`. */
|
|
638
647
|
dataLength: i32 = 0
|
|
639
648
|
/** `H1_WS_MESSAGE`'s opcode: text or binary. */
|
|
640
649
|
opcode: i32 = 0
|
|
@@ -1355,21 +1364,22 @@ export class Http1Connection {
|
|
|
1355
1364
|
}
|
|
1356
1365
|
|
|
1357
1366
|
/**
|
|
1358
|
-
* `write` of `buf[off .. off + len)`, sent from `buf` itself where it can
|
|
1359
|
-
*
|
|
1360
|
-
*
|
|
1361
|
-
*
|
|
1362
|
-
*
|
|
1363
|
-
*
|
|
1364
|
-
*
|
|
1365
|
-
*
|
|
1366
|
-
*
|
|
1367
|
-
*
|
|
1368
|
-
*
|
|
1369
|
-
* `
|
|
1370
|
-
*
|
|
1371
|
-
*
|
|
1372
|
-
*
|
|
1367
|
+
* `write` of `buf[off .. off + len)`, sent from `buf` itself where it can be:
|
|
1368
|
+
* under a `Content-Length` response on a connection whose carrier named its
|
|
1369
|
+
* socket (`fd`, set by `Http1Server.accept`) and with no write held back, the
|
|
1370
|
+
* queued output and the body leave in one `netWrite2`, and only what the
|
|
1371
|
+
* socket did not take is copied into the output, the way `write` copies it
|
|
1372
|
+
* (what does not fit is answered short, and `H1_WRITE` says when to send the
|
|
1373
|
+
* rest).
|
|
1374
|
+
*
|
|
1375
|
+
* Once it returns the connection holds no reference to `buf`, so the caller
|
|
1376
|
+
* may reuse or give back its bytes at once. A chunked or empty response, a
|
|
1377
|
+
* write held back (`H1_AGAIN` or a short answer not yet followed by
|
|
1378
|
+
* `H1_WRITE`), and a connection with no socket (`Http1TlsServer`, a sans-IO
|
|
1379
|
+
* carrier) copy all of it: it is `write`, with the same bytes on the wire.
|
|
1380
|
+
* Answers what `write` answers, `H1_INVALID` for more than the response still
|
|
1381
|
+
* owes; `H1_CLOSED` also when the socket failed during the send, which aborts
|
|
1382
|
+
* the connection. A window outside `buf` panics.
|
|
1373
1383
|
*
|
|
1374
1384
|
* @param buf the body bytes to send, free for the caller to reuse once this returns
|
|
1375
1385
|
* @param off where in `buf` the window starts
|
|
@@ -1515,24 +1525,24 @@ export class Http1Connection {
|
|
|
1515
1525
|
/**
|
|
1516
1526
|
* Answers the current request with all of `body[off .. off + len)` in one
|
|
1517
1527
|
* call: `respond`, `write` and `end`, the body compressed by `enc` when
|
|
1518
|
-
* `coding` (from `acceptEncoding`) is gzip and `enc.compress` takes it,
|
|
1519
|
-
*
|
|
1520
|
-
*
|
|
1521
|
-
*
|
|
1522
|
-
*
|
|
1523
|
-
*
|
|
1524
|
-
*
|
|
1525
|
-
*
|
|
1526
|
-
* says what was chosen. A
|
|
1527
|
-
*
|
|
1528
|
-
* (`enc.compressAnyway`).
|
|
1529
|
-
*
|
|
1530
|
-
*
|
|
1531
|
-
* it: `H1_AGAIN` when the output has
|
|
1532
|
-
* when to try again, compressing again),
|
|
1533
|
-
* larger than the output could ever hold or one
|
|
1534
|
-
* `H1_CLOSED` with no request to answer; 0 once it is
|
|
1535
|
-
* outside `body` panics.
|
|
1528
|
+
* `coding` (from `acceptEncoding`) is gzip and `enc.compress` takes it, with
|
|
1529
|
+
* `Content-Encoding: gzip` and the compressed `Content-Length`, and otherwise
|
|
1530
|
+
* sent as it is; `Vary: Accept-Encoding` while `enc.vary` is set and the
|
|
1531
|
+
* choice turned on the request (`HttpCompressor.varies`).
|
|
1532
|
+
*
|
|
1533
|
+
* Under `enc.segmentMode` the compressed response goes out only when, head
|
|
1534
|
+
* included, it takes fewer segments of `segmentMss(enc)` bytes than the body
|
|
1535
|
+
* as it is, and a response that fits one segment as it is goes so without
|
|
1536
|
+
* compressing (`enc.oneSegment`); `enc.decision` says what was chosen. A
|
|
1537
|
+
* request that refuses identity (`identityRefused`) is sent gzip whatever the
|
|
1538
|
+
* length, the saving or the segments (`enc.compressAnyway`). The program's
|
|
1539
|
+
* fields may not name `Content-Encoding` or, with `enc.vary`, `Vary`.
|
|
1540
|
+
*
|
|
1541
|
+
* The whole response is written or none of it: `H1_AGAIN` when the output has
|
|
1542
|
+
* no room for it yet (`H1_WRITE` says when to try again, compressing again),
|
|
1543
|
+
* `H1_INVALID` for a response larger than the output could ever hold or one
|
|
1544
|
+
* `respond` refuses, `H1_CLOSED` with no request to answer; 0 once it is
|
|
1545
|
+
* queued. A window outside `body` panics.
|
|
1536
1546
|
*
|
|
1537
1547
|
* @param status the HTTP status code to send, as `respond` takes it
|
|
1538
1548
|
* @param names the program's field names, without `Content-Encoding` (or `Vary` under `enc.vary`)
|
|
@@ -1859,6 +1869,7 @@ export class Http1Server {
|
|
|
1859
1869
|
outputs: Http1OutputPool
|
|
1860
1870
|
/** The input and head buffers resting slots lend, with `Http1Config.idleInput`. */
|
|
1861
1871
|
inputs: Http1OutputPool
|
|
1872
|
+
/** The head buffers resting slots lend, beside `inputs`; `made` counts how many the slots ever needed. */
|
|
1862
1873
|
heads: Http1OutputPool
|
|
1863
1874
|
/**
|
|
1864
1875
|
* The slots closed since they were used, a stack whose top `accept` takes
|
|
@@ -2248,6 +2259,7 @@ export class Http1Server {
|
|
|
2248
2259
|
*/
|
|
2249
2260
|
export class Http1TlsServer {
|
|
2250
2261
|
private config: Http1Config
|
|
2262
|
+
/** The TLS 1.3 pool underneath, one slot beside each connection; read it for a slot's TLS connection. */
|
|
2251
2263
|
tls: TlsTcpServer
|
|
2252
2264
|
/**
|
|
2253
2265
|
* The connections built so far, slot `k`'s at `k`: one per slot ever
|
package/std/net/http2-frame.ts
CHANGED
|
@@ -27,22 +27,23 @@
|
|
|
27
27
|
* const end: i32 = http2WriteData(out, at, streamId, body, 0, n, H2_FLAG_END_STREAM, -1);
|
|
28
28
|
* };
|
|
29
29
|
*
|
|
30
|
-
* **What a parse refuses**, as the error code RFC 9113 names, which closes
|
|
31
|
-
*
|
|
32
|
-
* (FRAME_SIZE_ERROR, §4.2); DATA, HEADERS, PRIORITY, RST_STREAM,
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
30
|
+
* **What a parse refuses**, as the error code RFC 9113 names, which closes the
|
|
31
|
+
* connection: a frame longer than the receiver's SETTINGS_MAX_FRAME_SIZE
|
|
32
|
+
* (FRAME_SIZE_ERROR, §4.2); DATA, HEADERS, PRIORITY, RST_STREAM, PUSH_PROMISE
|
|
33
|
+
* or CONTINUATION on stream 0, and SETTINGS, PING or GOAWAY on any other
|
|
34
|
+
* (PROTOCOL_ERROR); a frame too short for its fixed fields, a RST_STREAM or
|
|
35
|
+
* WINDOW_UPDATE that is not four bytes, a PING that is not eight, a SETTINGS
|
|
36
|
+
* whose length is not a multiple of six or an ACK with a payload, and a GOAWAY
|
|
37
|
+
* under eight (FRAME_SIZE_ERROR); padding as long as what it pads or longer
|
|
38
|
+
* (PROTOCOL_ERROR, §6.1); and a WINDOW_UPDATE of zero on the connection
|
|
39
|
+
* (PROTOCOL_ERROR, §6.9).
|
|
40
|
+
*
|
|
41
|
+
* Two refusals only reset the stream, and come back in `streamError` with a
|
|
42
|
+
* parse that answers 0: a PRIORITY of the wrong length (FRAME_SIZE_ERROR,
|
|
43
|
+
* §6.3), and a WINDOW_UPDATE of zero on a stream (PROTOCOL_ERROR). A HEADERS or
|
|
44
|
+
* PRIORITY that makes a stream depend on itself is the same (PROTOCOL_ERROR,
|
|
45
|
+
* §5.3.1). A frame of a type this module does not know is read and answers 0:
|
|
46
|
+
* §4.1 says it is ignored, and that is the connection's to do.
|
|
46
47
|
*
|
|
47
48
|
* SETTINGS values are checked one at a time by `http2SettingError`, because
|
|
48
49
|
* which value a refusal names is the reader's business (§6.5.2): an
|
package/std/net/http2-tls.ts
CHANGED
|
@@ -56,23 +56,25 @@
|
|
|
56
56
|
* configuration offers `h2` (and may offer `http/1.1` beside it, for a
|
|
57
57
|
* program that serves both and calls `alpn(slot)` itself).
|
|
58
58
|
*
|
|
59
|
-
* **Slots, a cap; buffers, borrowed.** The constructor makes the TLS pool
|
|
60
|
-
*
|
|
59
|
+
* **Slots, a cap; buffers, borrowed.** The constructor makes the TLS pool and
|
|
60
|
+
* slot 0's connection, but no other slot's and no frame buffer: a slot's
|
|
61
61
|
* connection is made by the first `accept` into it and kept, so a pool sized
|
|
62
62
|
* for its peak costs at start-up only what does not depend on the size, and
|
|
63
|
-
* holds at most `size` connections once the peak has come.
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
* slot
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
* slot count, so a
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
63
|
+
* holds at most `size` connections once the peak has come.
|
|
64
|
+
*
|
|
65
|
+
* A connection borrows its input, output and header-block buffers from the
|
|
66
|
+
* server's `Http2Pools` when it first needs each, and gives each back once it
|
|
67
|
+
* is empty and when the slot closes, so a free or idle slot holds none. A slot
|
|
68
|
+
* whose handshake is not done holds one output buffer, its SETTINGS written and
|
|
69
|
+
* waiting on TLS, until the handshake ends or the slot closes: one client that
|
|
70
|
+
* stalls its handshake keeps one buffer, as it kept a whole slot before
|
|
71
|
+
* (`docs/security/tls.md`, TLS-4). Each pool's ceiling is the slot count, so a
|
|
72
|
+
* borrow never fails.
|
|
73
|
+
*
|
|
74
|
+
* `accept` resets the slot's connection, and once the pools are warm nothing a
|
|
75
|
+
* connection does allocates but a header block's HPACK decoding
|
|
76
|
+
* (`docs/security/http2.md`, H2-1). The caps are the `Http2Config`'s, one for
|
|
77
|
+
* every slot, so a program sets them once.
|
|
76
78
|
*
|
|
77
79
|
* **The Date.** Every final response carries one `date` field (RFC 9110
|
|
78
80
|
* §6.6.1) from the pool's `HttpDate`, which formats the IMF-fixdate at most
|
package/std/net/http2.ts
CHANGED
|
@@ -34,64 +34,77 @@
|
|
|
34
34
|
* // then conn.consume(sent)
|
|
35
35
|
* };
|
|
36
36
|
*
|
|
37
|
-
* **Events.**
|
|
38
|
-
* first that means something to the program: `H2_REQUEST` (a stream opened
|
|
39
|
-
* with a request's header section; `fields` holds it until the next header
|
|
40
|
-
* block on the connection is read, for any stream, and a program copies what
|
|
41
|
-
* it keeps past that: the next block empties `fields` and reuses the arrays
|
|
42
|
-
* it pointed into), `H2_DATA` (some of a request body, a window onto the input
|
|
43
|
-
* buffer that stays valid until the next `feed`), `H2_TRAILERS`, `H2_RESET`
|
|
44
|
-
* (the stream is gone: the peer reset it, or broke a rule that resets it —
|
|
45
|
-
* `errorCode` says which), `H2_WINDOW` (a send window that held `writeData`
|
|
46
|
-
* back has opened: `stream`, or 0 for the connection's), `H2_GOAWAY` (the
|
|
47
|
-
* peer is going away; `lastStreamId`), and
|
|
48
|
-
* `H2_ERROR`, final: the connection broke a rule, a GOAWAY with `errorCode`
|
|
49
|
-
* is queued, and every later call answers it again. `H2_NEED_MORE` asks for
|
|
50
|
-
* more input, or for the output to drain: a frame is read only while the
|
|
51
|
-
* output has room for whatever it makes the connection answer, so a peer
|
|
52
|
-
* that sends PINGs or SETTINGS and never reads the acknowledgements stops
|
|
53
|
-
* being read rather than growing a queue. Bodies move a frame at a time and
|
|
54
|
-
* nothing buffers a whole one.
|
|
37
|
+
* **Events.**
|
|
55
38
|
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
* `
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
39
|
+
* `next()` reads the frames `feed` handed it and answers the first that means
|
|
40
|
+
* something to the program:
|
|
41
|
+
* - `H2_REQUEST` (a stream opened with a request's header section; `fields`
|
|
42
|
+
* holds it until the next header block on the connection is read, for any
|
|
43
|
+
* stream, and a program copies what it keeps past that: the next block
|
|
44
|
+
* empties `fields` and reuses the arrays it pointed into),
|
|
45
|
+
* - `H2_DATA` (some of a request body, a window onto the input buffer that
|
|
46
|
+
* stays valid until the next `feed`),
|
|
47
|
+
* - `H2_TRAILERS`,
|
|
48
|
+
* - `H2_RESET` (the stream is gone: the peer reset it, or broke a rule that
|
|
49
|
+
* resets it — `errorCode` says which),
|
|
50
|
+
* - `H2_WINDOW` (a send window that held `writeData` back has opened: `stream`,
|
|
51
|
+
* or 0 for the connection's),
|
|
52
|
+
* - `H2_GOAWAY` (the peer is going away; `lastStreamId`),
|
|
53
|
+
* - and `H2_ERROR`, final: the connection broke a rule, a GOAWAY with
|
|
54
|
+
* `errorCode` is queued, and every later call answers it again.
|
|
55
|
+
*
|
|
56
|
+
* `H2_NEED_MORE` asks for more input, or for the output to drain: a frame is
|
|
57
|
+
* read only while the output has room for whatever it makes the connection
|
|
58
|
+
* answer, so a peer that sends PINGs or SETTINGS and never reads the
|
|
59
|
+
* acknowledgements stops being read rather than growing a queue. Bodies move a
|
|
60
|
+
* frame at a time and nothing buffers a whole one.
|
|
61
|
+
*
|
|
62
|
+
* **What the connection refuses**, as RFC 9113 classes it.
|
|
63
|
+
*
|
|
64
|
+
* A connection error sends GOAWAY and ends the connection:
|
|
65
|
+
* - a bad preface or a first frame that is not SETTINGS (PROTOCOL_ERROR, §3.4);
|
|
66
|
+
* - every refusal of `nish/net/http2-frame`;
|
|
67
|
+
* - a frame other than CONTINUATION inside a header block, or a CONTINUATION
|
|
68
|
+
* outside one (§6.10);
|
|
69
|
+
* - a stream identifier that is even or does not increase (§5.1.1);
|
|
70
|
+
* - DATA, WINDOW_UPDATE or RST_STREAM on an idle stream, and a PUSH_PROMISE
|
|
71
|
+
* from a client (PROTOCOL_ERROR);
|
|
72
|
+
* - HEADERS on a closed stream (STREAM_CLOSED);
|
|
73
|
+
* - a header block HPACK cannot decode (COMPRESSION_ERROR, RFC 7541 §2.3.2);
|
|
74
|
+
* - DATA past the connection window, or a window pushed past 2^31 − 1
|
|
75
|
+
* (FLOW_CONTROL_ERROR, §6.9);
|
|
76
|
+
* - a setting `http2SettingError` refuses;
|
|
77
|
+
* - a header block longer than `maxHeaderBlock` or cut into more than
|
|
78
|
+
* `H2_MAX_FRAGMENTS` frames, a header block that would make the HPACK table
|
|
79
|
+
* copy past its budget (`HPACK_ERR_COPY_BUDGET`), and more streams reset than
|
|
80
|
+
* `resetBudget` allows — by the peer, or by the server for a stream error the
|
|
81
|
+
* peer caused (ENHANCE_YOUR_CALM, §10.5).
|
|
82
|
+
*
|
|
83
|
+
* A stream error resets one stream and the connection lives: a malformed
|
|
84
|
+
* request — any refusal of `nish/net/http-fields`, trailers without END_STREAM,
|
|
85
|
+
* a body that disagrees with `content-length` (PROTOCOL_ERROR, §8.1.1); DATA or
|
|
86
|
+
* HEADERS after the peer ended the stream (STREAM_CLOSED, §5.1); DATA past the
|
|
87
|
+
* stream's window, or its window pushed past 2^31 − 1 (FLOW_CONTROL_ERROR); a
|
|
88
|
+
* stream past `maxStreams` (REFUSED_STREAM, §5.1.2); a stream that depends on
|
|
89
|
+
* itself and a PRIORITY of the wrong length. A request whose header list is
|
|
90
|
+
* longer than `maxHeaderListSize` is answered with a 431 and never reaches the
|
|
91
|
+
* program (§10.5.1).
|
|
80
92
|
*
|
|
81
93
|
* **Caps are start-up numbers**, all in `Http2Config`: the streams open at
|
|
82
94
|
* once, the windows, the largest frame and header block accepted, the header
|
|
83
|
-
* list, the output buffer and the reset budget. Every stream slot is
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
+
* list, the output buffer and the reset budget. Every stream slot is allocated
|
|
96
|
+
* by the constructor; the input, output and header-block buffers are borrowed
|
|
97
|
+
* from an `Http2Pools` when first needed and given back, zeroed as far as they
|
|
98
|
+
* were written, once each is empty or the connection ends, so an idle
|
|
99
|
+
* connection holds none.
|
|
100
|
+
*
|
|
101
|
+
* A server shares one `Http2Pools` among its slots; a connection on its own
|
|
102
|
+
* makes a private one that holds one buffer of each. Once the pools are warm,
|
|
103
|
+
* reading DATA, writing DATA and every control frame allocate nothing, and
|
|
104
|
+
* neither does a header block once the decoder's arrays have grown to the
|
|
105
|
+
* largest block and header list seen: it decodes into storage the connection
|
|
106
|
+
* owns, bounded by `maxHeaderBlock` and `maxHeaderListSize` whether the stream
|
|
107
|
+
* is opened, refused or reset (`docs/security/http2.md`, H2-1).
|
|
95
108
|
*
|
|
96
109
|
* The server sends no PUSH_PROMISE and no PRIORITY, and reads PRIORITY only to
|
|
97
110
|
* check it: RFC 9113 §5.3.2 deprecates the scheme. Every field it sends is a
|
package/std/net/http3-frame.ts
CHANGED
|
@@ -38,16 +38,17 @@
|
|
|
38
38
|
* **SETTINGS** (§7.2.4). `h3ReadSettings` reads a whole payload into an
|
|
39
39
|
* `Http3Settings`: the three identifiers this endpoint understands, and the
|
|
40
40
|
* first `H3_SETTINGS_KEEP` it does not, kept rather than dropped so that an
|
|
41
|
-
* extension can read them. The four that extended CONNECT and WebTransport
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
41
|
+
* extension can read them. The four that extended CONNECT and WebTransport read
|
|
42
|
+
* (RFC 9220's, RFC 9297's and the two of the WebTransport drafts) are also
|
|
43
|
+
* recorded in fields of their own, refused when repeated, so a peer cannot push
|
|
44
|
+
* them out of reach behind eight others.
|
|
45
|
+
*
|
|
46
|
+
* A payload that ends inside a pair is H3_FRAME_ERROR (§7.1); an identifier
|
|
47
|
+
* HTTP/2 defined with no HTTP/3 counterpart (0x00, 0x02 to 0x05), or one that
|
|
48
|
+
* appears twice, is H3_SETTINGS_ERROR (§7.2.4, §7.2.4.1). A repeat among the
|
|
49
|
+
* unknown ones is caught while they are kept, and past `H3_SETTINGS_KEEP` they
|
|
50
|
+
* are counted, not compared, so a peer cannot make the read cost more than a
|
|
51
|
+
* fixed number of compares per setting.
|
|
51
52
|
*
|
|
52
53
|
* **Stream types** (§6.2): control 0x00, push 0x01, RFC 9204's QPACK
|
|
53
54
|
* encoder 0x02 and decoder 0x03, and WebTransport's 0x54, whose bidirectional
|
package/std/net/http3-server.ts
CHANGED
|
@@ -65,19 +65,19 @@
|
|
|
65
65
|
* GSO where the platform has it and one datagram at a time where it does not.
|
|
66
66
|
* Each flight goes with the ECN codepoint its connection marked it with
|
|
67
67
|
* (`QuicFlight.ecn`, RFC 9000 §13.4), so the peer's ACK_ECN counts are
|
|
68
|
-
* validated and a CE mark shrinks the window. Where the platform sends no
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
* one
|
|
74
|
-
*
|
|
75
|
-
* round trip is under a millisecond it
|
|
76
|
-
* millisecond to earn credit nor holds a slot back
|
|
77
|
-
* `clock` it counts whole milliseconds.
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
68
|
+
* validated and a CE mark shrinks the window. Where the platform sends no ECN
|
|
69
|
+
* (Darwin, whose `udpSendTo` answers -95 to a marked send), the first marked
|
|
70
|
+
* send goes again unmarked and no slot marks after it.
|
|
71
|
+
*
|
|
72
|
+
* A -95 is also what a platform without segmentation offload answers, so a
|
|
73
|
+
* refused GSO send goes again one datagram at a time, still marked, and only a
|
|
74
|
+
* -95 to one of those turns marking off. The pacer counts the microseconds
|
|
75
|
+
* `clock` gives it, so on a path whose round trip is under a millisecond it
|
|
76
|
+
* neither waits for the next millisecond to earn credit nor holds a slot back
|
|
77
|
+
* for a whole one; without `clock` it counts whole milliseconds. A slot whose
|
|
78
|
+
* HTTP/3 side sent GOAWAY and whose requests have all finished, every byte
|
|
79
|
+
* acknowledged, is closed with H3_NO_ERROR; a closed slot is freed once its
|
|
80
|
+
* CONNECTION_CLOSE is out.
|
|
81
81
|
*
|
|
82
82
|
* **Timers** are a wheel of `H3_SERVER_WHEEL` one-millisecond buckets, a
|
|
83
83
|
* slot in at most one: after every datagram and every flush the slot is filed
|
|
@@ -88,15 +88,16 @@
|
|
|
88
88
|
*
|
|
89
89
|
* **Caps, fixed at start-up**: the slots, and inside each the QUIC
|
|
90
90
|
* configuration's streams and buffers and the `Http3Config`'s field section,
|
|
91
|
-
* body chunk and DATA frame.
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
91
|
+
* body chunk and DATA frame.
|
|
92
|
+
*
|
|
93
|
+
* A slot's connections and address are built on the first Initial accepted into
|
|
94
|
+
* it and kept, so a pool sized for its peak costs at start-up only its per-slot
|
|
95
|
+
* tables (the index, the wheel, the queues), and holds at most `size`
|
|
96
|
+
* connections once the peak has come; a datagram an established connection
|
|
97
|
+
* reads, and every datagram it sends, allocates nothing; nor does a datagram no
|
|
98
|
+
* slot owns, which the listener reads where it lies and answers into scratch
|
|
99
|
+
* made once, nor a handshake into a slot built before, whose state is the
|
|
100
|
+
* slot's — `docs/security/http3.md` (H3-1, H3-3).
|
|
100
101
|
*
|
|
101
102
|
* **The Date.** Every response carries one `date` field (RFC 9110 §6.6.1)
|
|
102
103
|
* from the pool's `HttpDate`, which formats the IMF-fixdate at most once a
|
|
@@ -1223,19 +1224,19 @@ export class Http3Server {
|
|
|
1223
1224
|
|
|
1224
1225
|
/**
|
|
1225
1226
|
* Stops the server for good and wipes the keys it holds: every built slot's
|
|
1226
|
-
* connection is released (`QuicConnection.release`, which sends nothing),
|
|
1227
|
-
*
|
|
1228
|
-
*
|
|
1229
|
-
*
|
|
1230
|
-
*
|
|
1231
|
-
*
|
|
1232
|
-
*
|
|
1233
|
-
*
|
|
1234
|
-
*
|
|
1235
|
-
*
|
|
1236
|
-
*
|
|
1237
|
-
*
|
|
1238
|
-
* anyone can forge.
|
|
1227
|
+
* connection is released (`QuicConnection.release`, which sends nothing), as
|
|
1228
|
+
* is one built after, by `connection` or `quic`; the listener is released;
|
|
1229
|
+
* and the configuration's `statelessResetKey` and `retryTokenKey`, the
|
|
1230
|
+
* index's salt, the connections' entropy scratch and the listener's last
|
|
1231
|
+
* answer (a Retry's or a reset's token) are zeroed. From then on every
|
|
1232
|
+
* datagram is dropped and no connection is accepted.
|
|
1233
|
+
*
|
|
1234
|
+
* The configuration's two keys are the server's once it is made with them: a
|
|
1235
|
+
* program that keeps a copy of either, to start the next server with, wipes
|
|
1236
|
+
* its own copy. The keys are zeroed in place, so give each server a
|
|
1237
|
+
* `QuicServerConfig` of its own: any other listener, connection or server
|
|
1238
|
+
* made with the same one would go on MACing Retry tokens and deriving
|
|
1239
|
+
* stateless reset tokens under an all-zero key, which anyone can forge.
|
|
1239
1240
|
*/
|
|
1240
1241
|
stop(): void {
|
|
1241
1242
|
this.stopped = true
|