@amritk/nish-x86_64-linux 0.36.0 → 0.38.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 +92 -71
- package/bin/nish +0 -0
- package/docs/AI.md +75 -14
- package/package.json +1 -1
- package/runtime/async.d.mts +2 -0
- package/runtime/async.mjs +7 -0
- package/runtime/core/arrays.d.ts +4 -0
- package/runtime/core/arrays.mjs +33 -0
- package/runtime/nish.d.ts +1045 -512
- package/runtime/nish.h +53 -6
- package/runtime/page.d.ts +53 -0
- package/runtime/page.mjs +146 -0
- package/runtime/runtime-async.c +740 -0
- package/runtime/runtime-cross.c +2 -1
- package/runtime/runtime-region.c +85 -7
- package/runtime/runtime-text.c +1068 -0
- package/runtime/runtime-wasm.c +65 -9
- package/runtime/runtime.c +50 -961
- package/runtime/vite.mjs +48 -11
- package/scripts/build.sh +231 -31
- package/std/LICENSE-fdlibm +8 -0
- package/std/README.md +109 -82
- package/std/array.ts +266 -0
- 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/host/text.ts +86 -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/math.ts +743 -41
- package/std/net/dns-resolver.ts +46 -6
- package/std/net/dns.ts +50 -13
- package/std/net/fetch.ts +1744 -295
- package/std/net/handler.ts +30 -0
- package/std/net/hpack.ts +29 -26
- package/std/net/http-compress.ts +42 -28
- package/std/net/http-fields.ts +19 -4
- package/std/net/http1-client-codec.ts +29 -25
- package/std/net/http1-codec.ts +62 -91
- package/std/net/http1-server.ts +79 -57
- 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-async.ts +1005 -0
- package/std/net/postgres.ts +185 -164
- 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/serve.ts +763 -0
- 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 +242 -15
- package/std/threads.ts +19 -15
- package/std/yaml-json.ts +17 -15
- package/std/yaml-write.ts +21 -14
package/std/net/quic.ts
CHANGED
|
@@ -54,89 +54,98 @@
|
|
|
54
54
|
*
|
|
55
55
|
* **Loss recovery** (RFC 9002). It is `nish/net/quic-recovery`'s: every
|
|
56
56
|
* ack-eliciting packet is recorded in its space's ring with what it carried
|
|
57
|
-
* (its CRYPTO range, its STREAM chunks, HANDSHAKE_DONE and the control
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* resend (§6.2.4) — two
|
|
66
|
-
*
|
|
67
|
-
* server's handshake data (an
|
|
68
|
-
* ack-eliciting Handshake packet) gets it
|
|
69
|
-
* time, up to `QUIC_CONN_EARLY_RESENDS` times
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
57
|
+
* (its CRYPTO range, its STREAM chunks, HANDSHAKE_DONE and the control frames),
|
|
58
|
+
* the client's ACKs give the RTT estimate and show what was lost by packet or
|
|
59
|
+
* time threshold, and what a lost packet carried is sent again, from the CRYPTO
|
|
60
|
+
* bytes a level keeps until it is discarded and the bytes a stream keeps until
|
|
61
|
+
* they are acknowledged; a control frame goes again with its current value.
|
|
62
|
+
*
|
|
63
|
+
* When nothing is acknowledged for a probe timeout, with its backoff,
|
|
64
|
+
* everything in flight is queued again and a probe goes out in each space that
|
|
65
|
+
* has packets in flight, a PING if there is nothing to resend (§6.2.4) — two
|
|
66
|
+
* datagrams of them during the handshake, each with the oldest CRYPTO data not
|
|
67
|
+
* acknowledged. A client that shows it lacks the server's handshake data (an
|
|
68
|
+
* Initial repeating CRYPTO data, an ack-eliciting Handshake packet) gets it
|
|
69
|
+
* again at once, a datagram each time, up to `QUIC_CONN_EARLY_RESENDS` times
|
|
70
|
+
* (§6.2.3).
|
|
71
|
+
*
|
|
72
|
+
* NewReno's window holds back everything ack-eliciting but a probe; an ACK
|
|
73
|
+
* always goes. PATH_RESPONSE and DATAGRAM are never sent again (RFC 9000 §13.3,
|
|
74
|
+
* RFC 9221 §5.2). Pacing, and GSO batching, are the carrier's:
|
|
75
|
+
* `nish/net/quic-listener`. Once the 1-RTT keys are in, one Application Data
|
|
76
|
+
* packet number in every 128 to 1024 is skipped, at a distance drawn from the
|
|
77
|
+
* ID seed, and the last `QUIC_CONN_SKIP_RING` are remembered: an ACK of one
|
|
78
|
+
* acknowledges a packet never sent, an optimistic ACK meant to widen the
|
|
79
|
+
* congestion window, and is PROTOCOL_VIOLATION (RFC 9000 §21.4).
|
|
78
80
|
*
|
|
79
81
|
* **Nothing allocated per packet** (QUIC-3). A connection is a slot: every
|
|
80
|
-
* buffer it uses — the packet record, the CRYPTO reassembly, the
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
82
|
+
* buffer it uses — the packet record, the CRYPTO reassembly, the connection-ID
|
|
83
|
+
* table, the datagram rings — is made by the constructor and reused, and
|
|
84
|
+
* `reset` makes the slot a new connection for the next peer.
|
|
85
|
+
*
|
|
86
|
+
* The stream buffers are borrowed instead (`QuicStreamPools` in
|
|
87
|
+
* `nish/net/quic-stream`): a receive side takes one on its first byte and a
|
|
88
|
+
* send side on its first write, each goes back zeroed once the stream is done
|
|
89
|
+
* with it, and a server's connections share one set of pools, so idle slots
|
|
90
|
+
* hold none. A standalone connection makes private pools as large as all its
|
|
91
|
+
* slots at its first packet. The pools are primed before a packet's arena block
|
|
92
|
+
* and never touched inside it.
|
|
93
|
+
*
|
|
94
|
+
* A packet is opened (`receiveWindow`) and a datagram built and sealed
|
|
95
|
+
* (`takeDatagramInto`) inside a `using a = arena()` block, so the AEAD's and
|
|
96
|
+
* the header protection's temporaries go when the block ends, and the compiler
|
|
97
|
+
* refuses the block if anything in it could store one.
|
|
98
|
+
*
|
|
99
|
+
* The handshake keeps its state in the slot too: one `TlsServer`, made by the
|
|
100
|
+
* slot's first handshake and `restart`ed by each after it; every level's packet
|
|
101
|
+
* keys, and a key update's, derived in place into `QuicKeysSlot`s
|
|
102
|
+
* (`nish/net/quic-packet`) over the slot's HKDF scratch; the Initial secrets,
|
|
103
|
+
* the stateless reset tokens and the connection IDs computed in arena blocks;
|
|
104
|
+
* the transport parameters encoded and parsed into the slot's own objects.
|
|
105
|
+
* After the first connection in a slot, a connection keeps nothing at all
|
|
106
|
+
* (QUIC-3 in `docs/security/quic.md`).
|
|
101
107
|
*
|
|
102
108
|
* **Time.** The connection has no clock: `receive`, `takeDatagram` and
|
|
103
109
|
* `handleTimer` take the caller's monotonic time in milliseconds, and
|
|
104
|
-
* `deadline()` says when `handleTimer` is next due. Five things run on it.
|
|
105
|
-
*
|
|
110
|
+
* `deadline()` says when `handleTimer` is next due. Five things run on it. The
|
|
111
|
+
* idle timeout (RFC 9000 §10.1) is the smaller of the two sides'
|
|
106
112
|
* `max_idle_timeout`, never under `QUIC_CONN_IDLE_FLOOR` or three probe
|
|
107
113
|
* timeouts; once it passes with nothing received, the connection closes
|
|
108
|
-
* silently (`QUIC_STATE_TIMED_OUT`) and wipes its keys. Loss recovery's
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
* after the move (RFC 9000
|
|
116
|
-
*
|
|
117
|
-
* closing or draining period, three probe timeouts (RFC 9000 §10.2), and
|
|
118
|
-
* wiped at its end; `deadline()` is that end, then -1. A close this side
|
|
119
|
-
* owes starts the period when `takeDatagram` sends it, not when `close` or
|
|
120
|
-
* `fail` is called, so that however long the caller waits, the close still
|
|
121
|
-
* goes out.
|
|
114
|
+
* silently (`QUIC_STATE_TIMED_OUT`) and wipes its keys. Loss recovery's timer
|
|
115
|
+
* declares packets lost by the time threshold or fires the probe timeout.
|
|
116
|
+
*
|
|
117
|
+
* After a key update the previous read keys are kept for a probe timeout
|
|
118
|
+
* (`recovery.probeTimeout()`), for packets the network reordered, before the
|
|
119
|
+
* next generation's are derived (RFC 9001 §6.5). And while a new path is
|
|
120
|
+
* validated, its PATH_CHALLENGE goes again a probe timeout after the last, and
|
|
121
|
+
* validation gives up max(3 PTO, 6 kInitialRtt) after the move (RFC 9000
|
|
122
|
+
* §8.2.4, §9.3.2).
|
|
122
123
|
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
124
|
+
* Once the connection has closed, by either side, its keys are kept through the
|
|
125
|
+
* closing or draining period, three probe timeouts (RFC 9000 §10.2), and wiped
|
|
126
|
+
* at its end; `deadline()` is that end, then -1. A close this side owes starts
|
|
127
|
+
* the period when `takeDatagram` sends it, not when `close` or `fail` is
|
|
128
|
+
* called, so that however long the caller waits, the close still goes out.
|
|
129
|
+
*
|
|
130
|
+
* **Key update** (RFC 9001 §6), both ways. A 1-RTT packet whose Key Phase bit
|
|
131
|
+
* differs from the current one is opened with the next generation's read keys,
|
|
132
|
+
* which are derived ahead of time so that a forged bit costs no derivation and
|
|
133
|
+
* shows no timing difference (§6.3); if it opens, the client has updated, and
|
|
134
|
+
* the server's write keys follow before anything is acknowledged (§6.2).
|
|
135
|
+
* `updateKeys()` starts an update from the server once the client has
|
|
136
|
+
* acknowledged a packet of the current phase (§6.1).
|
|
137
|
+
*
|
|
138
|
+
* The generations take turns in two key slots and two secrets a direction, so
|
|
139
|
+
* an update keeps nothing in the arena; each still costs two key derivations of
|
|
140
|
+
* work, so a connection takes at most `QUIC_CONN_MAX_KEY_UPDATES` updates the
|
|
141
|
+
* client starts and closes on the next with KEY_UPDATE_ERROR (QUIC-4).
|
|
142
|
+
*
|
|
143
|
+
* The AEAD limits are kept (RFC 9001 §6.6): from three quarters of AES-GCM's
|
|
144
|
+
* confidentiality limit, 2^23 packets under one write key, the server starts an
|
|
145
|
+
* update itself, and closes with AEAD_LIMIT_REACHED, sealing nothing more, if
|
|
146
|
+
* it reaches the limit with none possible; past the integrity limit of packets
|
|
147
|
+
* that fail to authenticate over the connection, 2^52 for AES-GCM and 2^36 for
|
|
148
|
+
* ChaCha20-Poly1305, it closes with AEAD_LIMIT_REACHED too.
|
|
140
149
|
*
|
|
141
150
|
* **Sans-IO and deterministic.** No socket, no clock and no random device:
|
|
142
151
|
* every random choice (the TLS server random and ephemeral key, the server's
|
|
@@ -147,61 +156,68 @@
|
|
|
147
156
|
*
|
|
148
157
|
* **Paths** (RFC 9000 §8.2, §9). `receiveWindowFrom` takes the 18-byte
|
|
149
158
|
* `nish:net` address each datagram came from, and `sendAddress()` says where
|
|
150
|
-
* the connection's datagrams go: the first Initial's address, validated by
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
159
|
+
* the connection's datagrams go: the first Initial's address, validated by the
|
|
160
|
+
* handshake, until the client's address changes. Before the handshake is
|
|
161
|
+
* confirmed a datagram from any other address is dropped unread, so no forged
|
|
162
|
+
* source moves a handshake or takes its flight.
|
|
163
|
+
*
|
|
164
|
+
* After it, a datagram from a new address whose newest non-probing packet
|
|
165
|
+
* authenticates moves the connection there (§9.3) — a later one from the old
|
|
166
|
+
* address, with a lower packet number, does not move it back — and a
|
|
167
|
+
* PATH_CHALLENGE, eight bytes from the ID seed's HMAC, padded to 1,200 bytes,
|
|
168
|
+
* validates the new path.
|
|
169
|
+
*
|
|
170
|
+
* Until a PATH_RESPONSE with any of the last three challenges' data arrives, on
|
|
171
|
+
* any path, the server sends there at most three times what came from it
|
|
172
|
+
* (§9.3.1); a lost challenge is drawn again, fresh, a probe timeout later; past
|
|
173
|
+
* max(3 PTO, 6 kInitialRtt) validation has failed and the connection goes back
|
|
174
|
+
* to the last validated address, where the client — or, for a forged source,
|
|
175
|
+
* the real client's next packet — finds it.
|
|
176
|
+
*
|
|
177
|
+
* Validated, a new address starts congestion control and the RTT estimate
|
|
178
|
+
* again, a port-only change keeps them (§9.4), and ECN is tested again
|
|
179
|
+
* (§13.4.2). A packet that carries only probing frames moves nothing: its
|
|
180
|
+
* PATH_CHALLENGE is answered on its own path, alone in a datagram
|
|
181
|
+
* `takeProbeInto` writes for `probeAddress`, under that path's own 3x limit.
|
|
182
|
+
* The client's connection ID is kept across a move (§9.5): a NAT rebinding
|
|
183
|
+
* gives the client no reason to change it, and this server never migrates
|
|
184
|
+
* itself. Every address, challenge and counter is a field made by the
|
|
185
|
+
* constructor and cleared by `reset`.
|
|
173
186
|
*
|
|
174
187
|
* **What a peer cannot do.** Nothing it sends makes this module panic. A
|
|
175
188
|
* datagram that does not parse, a packet that does not authenticate, a
|
|
176
189
|
* duplicate packet number, a packet for keys already discarded and a 1-RTT
|
|
177
|
-
* packet before the handshake is done are dropped and counted in `dropped`.
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
* the
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
* `
|
|
187
|
-
*
|
|
190
|
+
* packet before the handshake is done are dropped and counted in `dropped`. A
|
|
191
|
+
* frame that breaks the protocol closes the connection with the transport error
|
|
192
|
+
* RFC 9000 names (`QUIC_ERROR_*` in `nish/net/quic-frame`), a TLS alert closes
|
|
193
|
+
* it with CRYPTO_ERROR (0x100 + the alert), and the CONNECTION_CLOSE is the
|
|
194
|
+
* next datagram out.
|
|
195
|
+
*
|
|
196
|
+
* Before the client's address is validated — by a Handshake packet, or by a
|
|
197
|
+
* Retry token `nish/net/quic-listener` checked — the server sends at most three
|
|
198
|
+
* times what it received (§8.1). Every buffer a peer can fill is fixed: CRYPTO
|
|
199
|
+
* reassembly by `QUIC_CONN_CRYPTO_WINDOW`, each stream by the credit advertised
|
|
200
|
+
* (its buffer), the connection by `maxData`, the connection-ID table by the
|
|
201
|
+
* limit advertised, the received packet numbers by `QUIC_ACK_MAX_RANGES`, and
|
|
202
|
+
* datagrams by their ring.
|
|
188
203
|
*
|
|
189
204
|
* **Secrets.** The packet keys of each level live in this connection's key
|
|
190
205
|
* slots as long as the level does; so do the 1-RTT secrets the next key
|
|
191
|
-
* generation is derived from, and the next generation's read keys. The
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
206
|
+
* generation is derived from, and the next generation's read keys. The traffic
|
|
207
|
+
* secrets and the ephemeral key `TlsServer` holds are `Secret` fields its
|
|
208
|
+
* `wipe()` reaches (TLS-1): `afterTls` takes each level's secrets out of them
|
|
209
|
+
* once, into this connection's plain slots, and zeroes them through
|
|
210
|
+
* `wipeSecret`.
|
|
211
|
+
*
|
|
212
|
+
* The slots are plain bytes, wiped with stores no optimiser removes
|
|
213
|
+
* (`secureZero`, and `aesKeyWipe` for an AES schedule): each level's key, IV,
|
|
214
|
+
* header-protection key and schedules when the level is discarded; each
|
|
215
|
+
* generation's key, IV, schedule and secret when a key update replaces it; and
|
|
216
|
+
* the rest — the 1-RTT keys, the key-update secrets, whatever `TlsServer` still
|
|
217
|
+
* holds and the connection-ID seed — by `release()`, `reset`, the idle timeout,
|
|
218
|
+
* and the end of the closing or draining period (RFC 9000 §10.2), three probe
|
|
219
|
+
* timeouts after this side's CONNECTION_CLOSE went out or the client's arrived.
|
|
220
|
+
* `docs/security/quic.md` records what is wiped where as QUIC-2.
|
|
205
221
|
*
|
|
206
222
|
* Written from RFC 9000, RFC 9001 and RFC 9221, in this module's own
|
|
207
223
|
* structure; nothing here is ported from another implementation. Private
|
|
@@ -619,8 +635,11 @@ export interface QuicServerConfig {
|
|
|
619
635
|
|
|
620
636
|
/** One run of stream data the client sent, in order, as `readStream` answers it: `fin` when it ends the stream. */
|
|
621
637
|
export class QuicStreamData {
|
|
638
|
+
/** The RFC 9000 stream ID the bytes arrived on. */
|
|
622
639
|
streamId: i64 = 0
|
|
640
|
+
/** The bytes of the run, in stream order. */
|
|
623
641
|
data: u8[]
|
|
642
|
+
/** Whether the run ends the stream: the client sends no bytes after it. */
|
|
624
643
|
fin: boolean = false
|
|
625
644
|
|
|
626
645
|
/**
|
|
@@ -1394,6 +1413,7 @@ export class QuicConnection {
|
|
|
1394
1413
|
private tlsConfig: TlsServerConfig
|
|
1395
1414
|
/** The server's transport parameters, set for each connection, and their encoding. */
|
|
1396
1415
|
localParameters: QuicTransportParameters
|
|
1416
|
+
/** `localParameters` encoded for the TLS extension the server sends. */
|
|
1397
1417
|
localEncoded: u8[]
|
|
1398
1418
|
/** The client's transport parameters, parsed into the slot's own object. */
|
|
1399
1419
|
private parsedParameters: QuicTransportParameters
|
|
@@ -1401,6 +1421,7 @@ export class QuicConnection {
|
|
|
1401
1421
|
private kdf: HkdfScratch
|
|
1402
1422
|
/** The Initial secrets of RFC 9001 §5.2, the client's and the server's. */
|
|
1403
1423
|
initialClient: u8[]
|
|
1424
|
+
/** The server's Initial secret (RFC 9001 §5.2); see `initialClient`. */
|
|
1404
1425
|
initialServer: u8[]
|
|
1405
1426
|
/**
|
|
1406
1427
|
* The 1-RTT traffic secrets (RFC 9001 §6.1), one set of SHA-256's length
|
|
@@ -1411,17 +1432,26 @@ export class QuicConnection {
|
|
|
1411
1432
|
* it moves to them.
|
|
1412
1433
|
*/
|
|
1413
1434
|
readonly readSecret256: Secret<u8[]>
|
|
1435
|
+
/** The next generation's 1-RTT read secret under SHA-256, 32 bytes; see `readSecret256`. */
|
|
1414
1436
|
readonly nextReadSecret256: Secret<u8[]>
|
|
1437
|
+
/** The current 1-RTT write secret under SHA-256, 32 bytes; see `readSecret256`. */
|
|
1415
1438
|
readonly writeSecret256: Secret<u8[]>
|
|
1439
|
+
/** The current 1-RTT read secret under SHA-384, 48 bytes; see `readSecret256`. */
|
|
1416
1440
|
readonly readSecret384: Secret<u8[]>
|
|
1441
|
+
/** The next generation's 1-RTT read secret under SHA-384, 48 bytes; see `readSecret256`. */
|
|
1417
1442
|
readonly nextReadSecret384: Secret<u8[]>
|
|
1443
|
+
/** The current 1-RTT write secret under SHA-384, 48 bytes; see `readSecret256`. */
|
|
1418
1444
|
readonly writeSecret384: Secret<u8[]>
|
|
1419
1445
|
/** A connection ID being issued and its stateless reset token, before the table copies them. */
|
|
1420
1446
|
private cidScratch: u8[]
|
|
1421
1447
|
private tokenScratch: u8[]
|
|
1448
|
+
/** The Initial packet number space: its keys, packet numbers and acknowledgements (RFC 9000 §12.3). */
|
|
1422
1449
|
initial: QuicConnSpace
|
|
1450
|
+
/** The Handshake packet number space. */
|
|
1423
1451
|
handshake: QuicConnSpace
|
|
1452
|
+
/** The Application Data packet number space, which holds the 1-RTT keys. */
|
|
1424
1453
|
application: QuicConnSpace
|
|
1454
|
+
/** The connection IDs of both sides and their stateless reset tokens (`nish/net/quic-conn-cid`). */
|
|
1425
1455
|
cids: QuicCidTable
|
|
1426
1456
|
/** Loss detection, the RTT estimate, the congestion window and the pacer (RFC 9002). */
|
|
1427
1457
|
recovery: QuicRecovery
|
|
@@ -1431,6 +1461,7 @@ export class QuicConnection {
|
|
|
1431
1461
|
private defaultParameters: QuicTransportParameters
|
|
1432
1462
|
/** Bytes received and sent, for the anti-amplification limit (RFC 9000 §8.1). */
|
|
1433
1463
|
bytesReceived: i64 = 0
|
|
1464
|
+
/** Bytes sent, which may not pass three times `bytesReceived` before the address is validated. */
|
|
1434
1465
|
bytesSent: i64 = 0
|
|
1435
1466
|
/** The ALPN protocol the handshake chose. */
|
|
1436
1467
|
alpn: string = ""
|
|
@@ -1440,6 +1471,7 @@ export class QuicConnection {
|
|
|
1440
1471
|
streams: QuicStreams
|
|
1441
1472
|
/** DATAGRAM payloads waiting to be sent, and those the client sent waiting to be read. */
|
|
1442
1473
|
datagramsOut: QuicDatagramQueue
|
|
1474
|
+
/** DATAGRAM payloads the client sent, waiting to be read; its `dropped` counts those that found it full. */
|
|
1443
1475
|
datagramsIn: QuicDatagramQueue
|
|
1444
1476
|
/** The CRYPTO bytes the client sent, put back in order. */
|
|
1445
1477
|
private cryptoIn: QuicConnReassembly
|
|
@@ -1454,6 +1486,10 @@ export class QuicConnection {
|
|
|
1454
1486
|
* datagram being read's. Made once and overwritten in place.
|
|
1455
1487
|
*/
|
|
1456
1488
|
private pathCurrent: u8[]
|
|
1489
|
+
/**
|
|
1490
|
+
* The last address the client proved it receives at, in `nish:net`'s
|
|
1491
|
+
* 18-byte form (RFC 9000 §9): the handshake's, or one a PATH_RESPONSE answered.
|
|
1492
|
+
*/
|
|
1457
1493
|
pathValidated: u8[]
|
|
1458
1494
|
private pathArrival: u8[]
|
|
1459
1495
|
/**
|
|
@@ -1475,11 +1511,14 @@ export class QuicConnection {
|
|
|
1475
1511
|
private challengeData: u8[]
|
|
1476
1512
|
/** Bytes received from and sent to the path being validated, for its own 3x limit (§9.3, §8.1). */
|
|
1477
1513
|
pathReceived: i64 = 0
|
|
1514
|
+
/** Bytes sent to the path being validated, at most three times `pathReceived`. */
|
|
1478
1515
|
pathSent: i64 = 0
|
|
1479
1516
|
private probeBudget: i64 = 0
|
|
1480
1517
|
/** When the PATH_CHALLENGE goes again with fresh data, and when validation gives up (§8.2.4); -1 when not validating. */
|
|
1481
1518
|
challengeResendAt: i64 = -1
|
|
1519
|
+
/** When path validation gives up, in milliseconds, or -1 when not validating. */
|
|
1482
1520
|
challengeUntil: i64 = -1
|
|
1521
|
+
/** How many PATH_CHALLENGE data have been drawn over the connection; see `challengeData`. */
|
|
1483
1522
|
challengesDrawn: i64 = 0
|
|
1484
1523
|
private frame: QuicFrame
|
|
1485
1524
|
/** The header and the packet numbers of the packet being read, reused for every one. */
|
|
@@ -1526,9 +1565,15 @@ export class QuicConnection {
|
|
|
1526
1565
|
* lower them after the handshake; nothing else should set them.
|
|
1527
1566
|
*/
|
|
1528
1567
|
confidentialityLimit: i64 = 8388608
|
|
1568
|
+
/**
|
|
1569
|
+
* Packets that may fail to authenticate before the connection closes (RFC
|
|
1570
|
+
* 9001 §6.6). `afterTls` sets it from the suite; a test may lower it after
|
|
1571
|
+
* the handshake.
|
|
1572
|
+
*/
|
|
1529
1573
|
integrityLimit: i64 = 4503599627370496
|
|
1530
1574
|
/** Packets sealed under the current 1-RTT write key, and packets that failed to authenticate, against those limits. */
|
|
1531
1575
|
sealedUnderKey: i64 = 0
|
|
1576
|
+
/** Packets that failed to authenticate over the connection, against `integrityLimit`. */
|
|
1532
1577
|
authFailures: i64 = 0
|
|
1533
1578
|
/**
|
|
1534
1579
|
* The next Application Data packet number skipped (RFC 9000 §21.4), or -1
|
|
@@ -1538,6 +1583,7 @@ export class QuicConnection {
|
|
|
1538
1583
|
*/
|
|
1539
1584
|
nextSkip: i64 = -1
|
|
1540
1585
|
private skipped: i64[]
|
|
1586
|
+
/** How many skip distances have been drawn; see `nextSkip`. */
|
|
1541
1587
|
skipsDrawn: i64 = 0
|
|
1542
1588
|
/** How many of `challengeData`'s slots hold a challenge sent on the path being validated. */
|
|
1543
1589
|
private challengeCount: i32 = 0
|
|
@@ -1557,6 +1603,7 @@ export class QuicConnection {
|
|
|
1557
1603
|
skipHead: i32 = 0
|
|
1558
1604
|
/** Which of the Application Data space's two read slots, and two write slots, hold the current keys. */
|
|
1559
1605
|
appReadSlot: i32 = 0
|
|
1606
|
+
/** Which of the Application Data space's two write slots holds the current keys, 0 or 1. */
|
|
1560
1607
|
appWriteSlot: i32 = 0
|
|
1561
1608
|
/** Handshake data sent again early, against `QUIC_CONN_EARLY_RESENDS` (RFC 9002 §6.2.3). */
|
|
1562
1609
|
earlyResends: i32 = 0
|
|
@@ -1572,6 +1619,7 @@ export class QuicConnection {
|
|
|
1572
1619
|
* keeps `ecnMarking`, which is the carrier's, and clears the rest.
|
|
1573
1620
|
*/
|
|
1574
1621
|
datagramEcn: i32 = 0
|
|
1622
|
+
/** Whether the carrier sends with the ECN bits of `datagramEcn`; the carrier sets it, and `reset` keeps it. */
|
|
1575
1623
|
ecnMarking: boolean = false
|
|
1576
1624
|
/** Whether `error` is an application code (CONNECTION_CLOSE 0x1d) rather than a transport error. */
|
|
1577
1625
|
errorIsApplication: boolean = false
|
|
@@ -1596,6 +1644,7 @@ export class QuicConnection {
|
|
|
1596
1644
|
otherIsNext: boolean = false
|
|
1597
1645
|
/** The Key Phase bit of the current read keys, and of the current write keys. */
|
|
1598
1646
|
readPhase: boolean = false
|
|
1647
|
+
/** The Key Phase bit of the current write keys. */
|
|
1599
1648
|
writePhase: boolean = false
|
|
1600
1649
|
/** Whether the packet just read brought CRYPTO bytes for TLS, or retired an ID that wants replacing. */
|
|
1601
1650
|
private cryptoArrived: boolean = false
|
|
@@ -3467,18 +3516,19 @@ export class QuicConnection {
|
|
|
3467
3516
|
}
|
|
3468
3517
|
|
|
3469
3518
|
/**
|
|
3470
|
-
* Runs whatever is due by `now`, the caller's monotonic time in
|
|
3471
|
-
*
|
|
3472
|
-
*
|
|
3473
|
-
*
|
|
3474
|
-
*
|
|
3475
|
-
*
|
|
3476
|
-
*
|
|
3477
|
-
*
|
|
3478
|
-
*
|
|
3479
|
-
*
|
|
3480
|
-
*
|
|
3481
|
-
*
|
|
3519
|
+
* Runs whatever is due by `now`, the caller's monotonic time in milliseconds;
|
|
3520
|
+
* call it at `deadline()`, or any time. Past the idle timeout the connection
|
|
3521
|
+
* closes silently (`QUIC_STATE_TIMED_OUT`, RFC 9000 §10.1): no
|
|
3522
|
+
* CONNECTION_CLOSE, every key wiped. Past the closing or draining period of a
|
|
3523
|
+
* connection that closed, every key is wiped (§10.2). Past a key update's
|
|
3524
|
+
* probe timeout the previous read keys are wiped and the next generation's
|
|
3525
|
+
* derived (RFC 9001 §6.5).
|
|
3526
|
+
*
|
|
3527
|
+
* Past loss recovery's timer, packets lost by the time threshold have their
|
|
3528
|
+
* frames queued again, or a probe timeout queues every space's packets in
|
|
3529
|
+
* flight and asks for a probe (RFC 9002 §6.1.2, §6.2.4): `takeDatagram` then
|
|
3530
|
+
* sends it. `receive` and `takeDatagram` run it themselves. Time never runs
|
|
3531
|
+
* backwards here: an earlier `now` than one already given counts as that one.
|
|
3482
3532
|
*
|
|
3483
3533
|
* @param now The caller's monotonic time in milliseconds.
|
|
3484
3534
|
*/
|
|
@@ -4157,24 +4207,26 @@ export class QuicConnection {
|
|
|
4157
4207
|
|
|
4158
4208
|
/**
|
|
4159
4209
|
* Writes the next datagram to send into `out` at `at`, which needs
|
|
4160
|
-
* `QUIC_CONN_DATAGRAM_SIZE` bytes of room, and answers its length, or 0
|
|
4161
|
-
*
|
|
4162
|
-
*
|
|
4163
|
-
*
|
|
4164
|
-
*
|
|
4165
|
-
*
|
|
4166
|
-
*
|
|
4167
|
-
*
|
|
4168
|
-
*
|
|
4169
|
-
*
|
|
4170
|
-
*
|
|
4171
|
-
*
|
|
4172
|
-
*
|
|
4210
|
+
* `QUIC_CONN_DATAGRAM_SIZE` bytes of room, and answers its length, or 0 when
|
|
4211
|
+
* nothing is due (or the room is not there). Call it until it answers 0 after
|
|
4212
|
+
* every `receive`, `sign`, write and `close`. It coalesces an Initial, a
|
|
4213
|
+
* Handshake and a 1-RTT packet as each has something to carry, pads a
|
|
4214
|
+
* datagram with an ack-eliciting Initial to 1200 bytes (RFC 9000 §14.1), and
|
|
4215
|
+
* before the client's address is validated sends only while three times what
|
|
4216
|
+
* was received allows (§8.1).
|
|
4217
|
+
*
|
|
4218
|
+
* After a close it writes the CONNECTION_CLOSE once, then nothing. While the
|
|
4219
|
+
* handshake waits for a signature it writes nothing, so the server's flight
|
|
4220
|
+
* leaves whole. Lost data goes before new data. While the congestion window
|
|
4221
|
+
* is full (RFC 9002 §7), or a space's record of packets in flight is, a space
|
|
4222
|
+
* sends only an ACK, unless a probe timeout asked it for a probe.
|
|
4223
|
+
*
|
|
4224
|
+
* `now` is the caller's time in milliseconds: a datagram that elicits an
|
|
4173
4225
|
* acknowledgement restarts the idle timer when it is the first since the
|
|
4174
|
-
* client's last packet (RFC 9000 §10.1), and once the idle timeout has
|
|
4175
|
-
*
|
|
4176
|
-
*
|
|
4177
|
-
*
|
|
4226
|
+
* client's last packet (RFC 9000 §10.1), and once the idle timeout has passed
|
|
4227
|
+
* nothing goes out. The datagram is built and sealed in place, inside an
|
|
4228
|
+
* arena block: nothing it does allocates past the call. This is not paced: a
|
|
4229
|
+
* carrier that paces calls `nish/net/quic-listener`'s
|
|
4178
4230
|
* `quicListenerTakeFlight` instead.
|
|
4179
4231
|
*
|
|
4180
4232
|
* @param out Where the datagram is written.
|