nish 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/docs/AI.md +50 -4
- package/docs/INSTALL.md +73 -59
- package/package.json +19 -5
- 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/scripts/fuzz.sh +1 -0
- package/scripts/undocumented.txt +14 -0
- 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/quic-recovery.ts
CHANGED
|
@@ -14,15 +14,16 @@
|
|
|
14
14
|
* if (now >= recovery.deadline(blocked)) { recovery.onTimeout(now, blocked); }
|
|
15
15
|
*
|
|
16
16
|
* **What it tracks.** Each space keeps its ack-eliciting packets in a fixed
|
|
17
|
-
* ring (`QuicSentPackets`), in the order they were sent, so the memory is
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* `
|
|
25
|
-
*
|
|
17
|
+
* ring (`QuicSentPackets`), in the order they were sent, so the memory is fixed
|
|
18
|
+
* when the connection is made and nothing is allocated per packet. A packet
|
|
19
|
+
* that elicits no acknowledgement (one that carries only ACK, PADDING or
|
|
20
|
+
* CONNECTION_CLOSE) is not recorded: it is never in flight, and neither an RTT
|
|
21
|
+
* sample nor a loss is ever taken from it (RFC 9002 §2, §5.1).
|
|
22
|
+
*
|
|
23
|
+
* The caller keeps what each packet carried in its own arrays, indexed by the
|
|
24
|
+
* slot `onPacketSent` answers, and reads `acked` and `lost` after each `onAck`
|
|
25
|
+
* and `onTimeout` to learn which slots were settled. A slot named there keeps
|
|
26
|
+
* its packet number, time and size until the next call.
|
|
26
27
|
*
|
|
27
28
|
* **Time and units.** Every time and every duration is the caller's
|
|
28
29
|
* monotonic clock in milliseconds, which is also the timer granularity
|
|
@@ -52,18 +53,21 @@
|
|
|
52
53
|
* **ECN** (§7.1, B.7; RFC 9000 §13.4.2 and its Appendix A.4). A caller that
|
|
53
54
|
* marks its packets ECT(0) asks `ecnCodepoint()` what to mark with, says so
|
|
54
55
|
* with `onEctSent` for every packet it marked, and hands an ACK_ECN frame's
|
|
55
|
-
* counts to `onAckEcn`.
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
56
|
+
* counts to `onAckEcn`.
|
|
57
|
+
*
|
|
58
|
+
* The counts are validated against the packets marked before they are used: an
|
|
59
|
+
* ACK that newly acknowledges a marked packet without counts, a count that
|
|
60
|
+
* falls, counts past the packets marked, or an increase in ECT(0) and ECN-CE
|
|
61
|
+
* short of the marked packets newly acknowledged fails validation, as does
|
|
62
|
+
* every packet of the testing period being lost, and a failed path is marked no
|
|
63
|
+
* more (`QUIC_RECOVERY_ECN_FAILED`). Only the first
|
|
64
|
+
* `QUIC_RECOVERY_ECN_TESTING_PACKETS` are marked until one validates.
|
|
65
|
+
*
|
|
66
|
+
* A rise in the ECN-CE count is a congestion event, from the largest packet
|
|
67
|
+
* newly acknowledged, so it halves the window once per recovery period as a
|
|
68
|
+
* loss does. Counts that arrive with an ACK that does not raise the largest
|
|
69
|
+
* acknowledged are neither validated nor used: they may be older than those
|
|
70
|
+
* already read.
|
|
67
71
|
*
|
|
68
72
|
* **What a peer cannot do.** Every input is checked: the ranges of an
|
|
69
73
|
* acknowledgement are read only up to the count given and the array's
|
|
@@ -146,8 +150,16 @@ export const QUIC_RECOVERY_ECT0: i32 = 2
|
|
|
146
150
|
export const QUIC_RECOVERY_ECN_TESTING_PACKETS: i32 = 10
|
|
147
151
|
/** ECN's states (RFC 9000 A.4): testing, marking the first packets; unknown, those sent and none validated yet; capable; and failed, for the connection's life. */
|
|
148
152
|
export const QUIC_RECOVERY_ECN_TESTING: i32 = 0
|
|
153
|
+
/**
|
|
154
|
+
* ECN is unknown: the testing packets are sent, none is validated yet, and nothing more is marked
|
|
155
|
+
* until one is.
|
|
156
|
+
*/
|
|
149
157
|
export const QUIC_RECOVERY_ECN_UNKNOWN: i32 = 1
|
|
158
|
+
/** The path is ECN-capable: a marked packet's counts validated, and every packet is marked from here on. */
|
|
150
159
|
export const QUIC_RECOVERY_ECN_CAPABLE: i32 = 2
|
|
160
|
+
/**
|
|
161
|
+
* Validation failed: nothing is marked again for the connection's life, unless `restartEcn` tests a new path.
|
|
162
|
+
*/
|
|
151
163
|
export const QUIC_RECOVERY_ECN_FAILED: i32 = 3
|
|
152
164
|
|
|
153
165
|
/** Microseconds in a millisecond: the pacer's clock against the caller's `now`. */
|
|
@@ -172,10 +184,16 @@ const quicRecoveryMax = (a: i64, b: i64): i64 => (a > b ? a : b)
|
|
|
172
184
|
* acknowledged (§7.6.2).
|
|
173
185
|
*/
|
|
174
186
|
export class QuicSentPackets {
|
|
187
|
+
/** @internal Read only by this module; `pnAt` answers for a slot. */
|
|
175
188
|
pn: i64[]
|
|
189
|
+
/**
|
|
190
|
+
* When each slot's packet was sent, the `now` `onPacketSent` was given, in milliseconds;
|
|
191
|
+
* loss detection and RTT samples read it.
|
|
192
|
+
*/
|
|
176
193
|
timeSent: i64[]
|
|
177
194
|
/** When each packet was sent on the pacer's clock, in microseconds. */
|
|
178
195
|
fineSent: i64[]
|
|
196
|
+
/** @internal Read only by this module: each slot's packet size in bytes, for the congestion window. */
|
|
179
197
|
size: i32[]
|
|
180
198
|
/** Each slot's state, with `QUIC_RECOVERY_MARKED` set if its packet was sent marked ECT(0). */
|
|
181
199
|
state: u8[]
|
|
@@ -193,20 +211,35 @@ export class QuicSentPackets {
|
|
|
193
211
|
lastAckEliciting: i64 = -1
|
|
194
212
|
/** The bytes of this space's packets in flight. */
|
|
195
213
|
bytesInFlight: i64 = 0
|
|
196
|
-
capacity: i32 = 0
|
|
197
|
-
head: i32 = 0
|
|
214
|
+
private capacity: i32 = 0
|
|
215
|
+
private head: i32 = 0
|
|
216
|
+
/**
|
|
217
|
+
* How many packets the ring keeps, in flight and settled; a test reads it to see what a flight
|
|
218
|
+
* recorded.
|
|
219
|
+
*/
|
|
198
220
|
count: i32 = 0
|
|
199
221
|
/** How many recorded packets are still in flight: neither acknowledged nor lost. */
|
|
200
222
|
inFlight: i32 = 0
|
|
223
|
+
/** @internal Read by `net/quic.ts`: how many slots of `acked` the last `onAck` filled. */
|
|
201
224
|
ackedCount: i32 = 0
|
|
225
|
+
/** How many slots of `lost` the last `onAck` or `onTimeout` filled. */
|
|
202
226
|
lostCount: i32 = 0
|
|
203
227
|
/** How many of this space's packets, recorded or not, were sent marked ECT(0). */
|
|
204
228
|
ectSent: i64 = 0
|
|
205
229
|
/** The ECN counts of the last ACK_ECN frame validated in this space (RFC 9000 §19.3.2). */
|
|
206
230
|
ect0: i64 = 0
|
|
231
|
+
/** The ECT(1) count of the last ACK_ECN frame validated in this space. */
|
|
207
232
|
ect1: i64 = 0
|
|
233
|
+
/** The ECN-CE count of the last ACK_ECN frame validated in this space; a rise is a congestion event. */
|
|
208
234
|
ce: i64 = 0
|
|
209
235
|
|
|
236
|
+
/**
|
|
237
|
+
* An empty ring; `QuicRecovery` makes one for each space.
|
|
238
|
+
*
|
|
239
|
+
* @param capacity How many sent packets the ring records at once, fixed for its life: in flight and
|
|
240
|
+
* settled alike, until `compact` drops the settled ones. `QUIC_RECOVERY_HANDSHAKE_CAPACITY` or
|
|
241
|
+
* `QUIC_RECOVERY_APPLICATION_CAPACITY`.
|
|
242
|
+
*/
|
|
210
243
|
constructor(capacity: i32) {
|
|
211
244
|
this.capacity = capacity
|
|
212
245
|
this.pn = new Array<i64>(capacity)
|
|
@@ -218,12 +251,21 @@ export class QuicSentPackets {
|
|
|
218
251
|
this.lost = new Array<i32>(capacity)
|
|
219
252
|
}
|
|
220
253
|
|
|
221
|
-
/**
|
|
254
|
+
/**
|
|
255
|
+
* The ring slot of the `k`-th packet kept, counting from the oldest.
|
|
256
|
+
* @internal Read by quic.ts, and in quic-recovery.ts outside the class.
|
|
257
|
+
*/
|
|
222
258
|
slot(k: i32): i32 {
|
|
223
259
|
return (this.head + k) % this.capacity
|
|
224
260
|
}
|
|
225
261
|
|
|
226
|
-
/**
|
|
262
|
+
/**
|
|
263
|
+
* The state of slot `s`, or free for a slot outside the ring.
|
|
264
|
+
*
|
|
265
|
+
* @param s A ring slot, as `onPacketSent`, `ackedSlot` or `lostSlot` answers it; any other index is safe.
|
|
266
|
+
* @returns The slot's state without its ECT(0) mark: free, in flight, acknowledged, lost, or lost now
|
|
267
|
+
* (`markLost`'s mark for a packet the current call declared lost).
|
|
268
|
+
*/
|
|
227
269
|
stateAt(s: i32): i32 {
|
|
228
270
|
if (s < 0 || s >= toI32(this.state.length)) {
|
|
229
271
|
return QUIC_RECOVERY_FREE
|
|
@@ -231,67 +273,128 @@ export class QuicSentPackets {
|
|
|
231
273
|
return toI32(this.state[s]) & (QUIC_RECOVERY_MARKED - 1)
|
|
232
274
|
}
|
|
233
275
|
|
|
234
|
-
/**
|
|
276
|
+
/**
|
|
277
|
+
* Sets slot `s`'s state.
|
|
278
|
+
* @internal Read in quic-recovery.ts outside the class.
|
|
279
|
+
*/
|
|
235
280
|
setState(s: i32, value: i32): void {
|
|
236
281
|
if (s >= 0 && s < toI32(this.state.length)) {
|
|
237
282
|
this.state[s] = toU8((toI32(this.state[s]) & QUIC_RECOVERY_MARKED) | value)
|
|
238
283
|
}
|
|
239
284
|
}
|
|
240
285
|
|
|
241
|
-
/**
|
|
286
|
+
/**
|
|
287
|
+
* The packet number in slot `s`, or -1.
|
|
288
|
+
*
|
|
289
|
+
* @param s A ring slot, as `onPacketSent`, `ackedSlot` or `lostSlot` answers it; any other index is safe.
|
|
290
|
+
* @returns The packet number recorded there, or -1 for an index outside the ring.
|
|
291
|
+
*/
|
|
242
292
|
pnAt(s: i32): i64 {
|
|
243
293
|
return s >= 0 && s < toI32(this.pn.length) ? this.pn[s] : -1
|
|
244
294
|
}
|
|
245
295
|
|
|
246
|
-
/**
|
|
296
|
+
/**
|
|
297
|
+
* When the packet in slot `s` was sent, or -1.
|
|
298
|
+
*
|
|
299
|
+
* @param s A ring slot, as `onPacketSent`, `ackedSlot` or `lostSlot` answers it; any other index is safe.
|
|
300
|
+
* @returns The `now` it was recorded at, in the caller's milliseconds, or -1 for an index outside the ring.
|
|
301
|
+
*/
|
|
247
302
|
timeAt(s: i32): i64 {
|
|
248
303
|
return s >= 0 && s < toI32(this.timeSent.length) ? this.timeSent[s] : -1
|
|
249
304
|
}
|
|
250
305
|
|
|
251
|
-
/**
|
|
306
|
+
/**
|
|
307
|
+
* When the packet in slot `s` was sent on the pacer's clock, in microseconds, or -1.
|
|
308
|
+
*
|
|
309
|
+
* @param s A ring slot, as `onPacketSent`, `ackedSlot` or `lostSlot` answers it; any other index is safe.
|
|
310
|
+
* @returns The send time in microseconds (`now × 1000` when `micros` was not current), or -1 for an
|
|
311
|
+
* index outside the ring.
|
|
312
|
+
*/
|
|
252
313
|
fineAt(s: i32): i64 {
|
|
253
314
|
return s >= 0 && s < toI32(this.fineSent.length) ? this.fineSent[s] : -1
|
|
254
315
|
}
|
|
255
316
|
|
|
256
|
-
/**
|
|
317
|
+
/**
|
|
318
|
+
* The size of the packet in slot `s`, or 0.
|
|
319
|
+
*
|
|
320
|
+
* @param s A ring slot, as `onPacketSent`, `ackedSlot` or `lostSlot` answers it; any other index is safe.
|
|
321
|
+
* @returns Its size on the wire in bytes, or 0 for an index outside the ring.
|
|
322
|
+
*/
|
|
257
323
|
sizeAt(s: i32): i32 {
|
|
258
324
|
return s >= 0 && s < toI32(this.size.length) ? this.size[s] : 0
|
|
259
325
|
}
|
|
260
326
|
|
|
261
|
-
/**
|
|
327
|
+
/**
|
|
328
|
+
* Whether the packet in slot `s` was sent marked ECT(0).
|
|
329
|
+
*
|
|
330
|
+
* @param s A ring slot, as `onPacketSent`, `ackedSlot` or `lostSlot` answers it; any other index is safe.
|
|
331
|
+
* @returns True when `onEctSent` marked it; false for an index outside the ring.
|
|
332
|
+
*/
|
|
262
333
|
markedAt(s: i32): boolean {
|
|
263
334
|
return s >= 0 && s < toI32(this.state.length) && (toI32(this.state[s]) & QUIC_RECOVERY_MARKED) !== 0
|
|
264
335
|
}
|
|
265
336
|
|
|
266
|
-
/**
|
|
337
|
+
/**
|
|
338
|
+
* Sets whether the packet in slot `s` was sent marked ECT(0).
|
|
339
|
+
* @internal Read in quic-recovery.ts outside the class.
|
|
340
|
+
*/
|
|
267
341
|
setMarked(s: i32, value: boolean): void {
|
|
268
342
|
if (s >= 0 && s < toI32(this.state.length)) {
|
|
269
343
|
this.state[s] = toU8(this.stateAt(s) | (value ? QUIC_RECOVERY_MARKED : 0))
|
|
270
344
|
}
|
|
271
345
|
}
|
|
272
346
|
|
|
273
|
-
/**
|
|
347
|
+
/**
|
|
348
|
+
* The `k`-th slot the last call acknowledged, or -1.
|
|
349
|
+
*
|
|
350
|
+
* @param k The position in `acked`, from 0 to `ackedCount - 1`, oldest first.
|
|
351
|
+
* @returns The slot, or -1 for `k` out of range. It names that packet only until the next call that
|
|
352
|
+
* records, settles or frees a packet in this space, any of which can free or reuse the slot:
|
|
353
|
+
* `onPacketSent`, `onAck`, `onAckEcn`, `onTimeout`, `evictOldest`, `discardSpace` and `reset` on the
|
|
354
|
+
* recovery, and this ring's own `full` and `compact`.
|
|
355
|
+
*/
|
|
274
356
|
ackedSlot(k: i32): i32 {
|
|
275
357
|
return k >= 0 && k < this.ackedCount && k < toI32(this.acked.length) ? this.acked[k] : -1
|
|
276
358
|
}
|
|
277
359
|
|
|
278
|
-
/**
|
|
360
|
+
/**
|
|
361
|
+
* The `k`-th slot the last call declared lost, or -1.
|
|
362
|
+
*
|
|
363
|
+
* @param k The position in `lost`, from 0 to `lostCount - 1`, oldest first.
|
|
364
|
+
* @returns The slot, or -1 for `k` out of range. It names that packet only until the next call that
|
|
365
|
+
* records, settles or frees a packet in this space, any of which can free or reuse the slot:
|
|
366
|
+
* `onPacketSent`, `onAck`, `onAckEcn`, `onTimeout`, `evictOldest`, `discardSpace` and `reset` on the
|
|
367
|
+
* recovery, and this ring's own `full` and `compact`.
|
|
368
|
+
*/
|
|
279
369
|
lostSlot(k: i32): i32 {
|
|
280
370
|
return k >= 0 && k < this.lostCount && k < toI32(this.lost.length) ? this.lost[k] : -1
|
|
281
371
|
}
|
|
282
372
|
|
|
283
|
-
/**
|
|
373
|
+
/**
|
|
374
|
+
* Whether slot `s` holds a packet still in flight.
|
|
375
|
+
*
|
|
376
|
+
* @param s A ring slot, as `onPacketSent`, `ackedSlot` or `lostSlot` answers it; any other index is safe.
|
|
377
|
+
* @returns True for a packet neither acknowledged nor lost; false for an index outside the ring.
|
|
378
|
+
*/
|
|
284
379
|
inFlightAt(s: i32): boolean {
|
|
285
380
|
return this.stateAt(s) === QUIC_RECOVERY_SENT
|
|
286
381
|
}
|
|
287
382
|
|
|
288
|
-
/**
|
|
383
|
+
/**
|
|
384
|
+
* Whether every slot is taken, so nothing more can be recorded until a packet is settled.
|
|
385
|
+
*
|
|
386
|
+
* @returns True when `onPacketSent` would refuse a packet for want of room. Settled slots at the oldest
|
|
387
|
+
* end are freed first, so asking can change `count`.
|
|
388
|
+
*/
|
|
289
389
|
full(): boolean {
|
|
290
390
|
this.compact()
|
|
291
391
|
return this.count >= this.capacity
|
|
292
392
|
}
|
|
293
393
|
|
|
294
|
-
/**
|
|
394
|
+
/**
|
|
395
|
+
* Frees the oldest slots that are settled, acknowledged or lost.
|
|
396
|
+
* @internal Read by quic.ts, and in quic-recovery.ts outside the class.
|
|
397
|
+
*/
|
|
295
398
|
compact(): void {
|
|
296
399
|
while (this.count > 0 && this.stateAt(this.head) !== QUIC_RECOVERY_SENT) {
|
|
297
400
|
this.setState(this.head, QUIC_RECOVERY_FREE)
|
|
@@ -303,20 +406,29 @@ export class QuicSentPackets {
|
|
|
303
406
|
}
|
|
304
407
|
}
|
|
305
408
|
|
|
306
|
-
/**
|
|
409
|
+
/**
|
|
410
|
+
* Forgets the results of the last call.
|
|
411
|
+
* @internal Read in quic-recovery.ts outside the class.
|
|
412
|
+
*/
|
|
307
413
|
clearResults(): void {
|
|
308
414
|
this.ackedCount = 0
|
|
309
415
|
this.lostCount = 0
|
|
310
416
|
}
|
|
311
417
|
|
|
312
|
-
/**
|
|
418
|
+
/**
|
|
419
|
+
* Takes packet `s` out of flight.
|
|
420
|
+
* @internal Read in quic-recovery.ts outside the class.
|
|
421
|
+
*/
|
|
313
422
|
settle(s: i32, state: i32): void {
|
|
314
423
|
this.setState(s, state)
|
|
315
424
|
this.inFlight = this.inFlight - 1
|
|
316
425
|
this.bytesInFlight = this.bytesInFlight - toI64(this.sizeAt(s))
|
|
317
426
|
}
|
|
318
427
|
|
|
319
|
-
/**
|
|
428
|
+
/**
|
|
429
|
+
* Settles packet `s` as lost and lists it in `lost`.
|
|
430
|
+
* @internal Read in quic-recovery.ts outside the class.
|
|
431
|
+
*/
|
|
320
432
|
markLost(s: i32): void {
|
|
321
433
|
this.settle(s, QUIC_RECOVERY_LOST_NOW)
|
|
322
434
|
if (this.lostCount < toI32(this.lost.length)) {
|
|
@@ -325,7 +437,10 @@ export class QuicSentPackets {
|
|
|
325
437
|
}
|
|
326
438
|
}
|
|
327
439
|
|
|
328
|
-
/**
|
|
440
|
+
/**
|
|
441
|
+
* Drops every packet, as when the space's keys are discarded (A.11).
|
|
442
|
+
* @internal Read in quic-recovery.ts outside the class.
|
|
443
|
+
*/
|
|
329
444
|
clear(): void {
|
|
330
445
|
for (let s: i32 = 0; s < toI32(this.state.length); s += 1) {
|
|
331
446
|
this.state[s] = toU8(QUIC_RECOVERY_FREE)
|
|
@@ -339,7 +454,10 @@ export class QuicSentPackets {
|
|
|
339
454
|
this.clearResults()
|
|
340
455
|
}
|
|
341
456
|
|
|
342
|
-
/**
|
|
457
|
+
/**
|
|
458
|
+
* Empties the ring and forgets every number, for a connection slot reused for another peer.
|
|
459
|
+
* @internal Read in quic-recovery.ts outside the class.
|
|
460
|
+
*/
|
|
343
461
|
reset(): void {
|
|
344
462
|
this.clear()
|
|
345
463
|
this.largestAcked = -1
|
|
@@ -374,6 +492,10 @@ const quicRecoveryInRanges = (ranges: i64[], count: i32, pn: i64): boolean => {
|
|
|
374
492
|
* counts a test or a log reads (`congestionEvents`, `persistentCongestions`).
|
|
375
493
|
*/
|
|
376
494
|
export class QuicRecovery {
|
|
495
|
+
/**
|
|
496
|
+
* The sent-packet ring of each packet number space, indexed by `QUIC_RECOVERY_INITIAL` and its
|
|
497
|
+
* siblings.
|
|
498
|
+
*/
|
|
377
499
|
spaces: QuicSentPackets[]
|
|
378
500
|
/** latest_rtt (§5.1): the last sample, in milliseconds. */
|
|
379
501
|
latestRtt: i64 = 0
|
|
@@ -395,6 +517,10 @@ export class QuicRecovery {
|
|
|
395
517
|
recoveryStart: i64 = -1
|
|
396
518
|
/** The pacer's credit in bytes (§7.7), and the time it was last topped up in microseconds, or -1. */
|
|
397
519
|
pacerBudget: i64 = 0
|
|
520
|
+
/**
|
|
521
|
+
* When the pacer's credit was last topped up, in microseconds on the pacer's clock, or -1 before the
|
|
522
|
+
* first time.
|
|
523
|
+
*/
|
|
398
524
|
pacerTime: i64 = -1
|
|
399
525
|
/** The smoothed RTT the pacer's rate is taken from, in microseconds: `smoothedRtt` on the pacer's clock. */
|
|
400
526
|
pacerRtt: i64 = 0
|
|
@@ -406,6 +532,10 @@ export class QuicRecovery {
|
|
|
406
532
|
timeoutSpace: i32 = -1
|
|
407
533
|
/** How many congestion events reduced the window, and how many of them were persistent congestion. */
|
|
408
534
|
congestionEvents: i32 = 0
|
|
535
|
+
/**
|
|
536
|
+
* How many of `congestionEvents` were persistent congestion (§7.6), which collapses the window to
|
|
537
|
+
* its minimum.
|
|
538
|
+
*/
|
|
409
539
|
persistentCongestions: i32 = 0
|
|
410
540
|
/** How many congestion events a rise in the ECN-CE count caused (§7.1). */
|
|
411
541
|
ecnCongestionEvents: i32 = 0
|
|
@@ -413,11 +543,23 @@ export class QuicRecovery {
|
|
|
413
543
|
ecnState: i32 = 0
|
|
414
544
|
/** The packets marked while testing, and of those recorded, how many and how many of them were lost. */
|
|
415
545
|
ecnTestSent: i32 = 0
|
|
546
|
+
/**
|
|
547
|
+
* How many of the packets marked while testing ECN are recorded in a space's ring, so their loss can
|
|
548
|
+
* be seen.
|
|
549
|
+
*/
|
|
416
550
|
ecnTestRecorded: i32 = 0
|
|
551
|
+
/**
|
|
552
|
+
* How many marked packets were lost before ECN validated: once it reaches `ecnTestRecorded`, ECN
|
|
553
|
+
* fails (RFC 9000 A.4).
|
|
554
|
+
*/
|
|
417
555
|
ecnTestLost: i32 = 0
|
|
418
556
|
/** Whether the handshake is confirmed (RFC 9001 §4.1.2), which the caller sets: the peer's max_ack_delay then bounds its ACK delays, and the Application Data space has a probe timeout. */
|
|
419
557
|
handshakeConfirmed: boolean = false
|
|
420
558
|
|
|
559
|
+
/**
|
|
560
|
+
* Makes the state a new connection has, as `reset` leaves it: every space
|
|
561
|
+
* empty, the RTT estimate and the window at their initial values.
|
|
562
|
+
*/
|
|
421
563
|
constructor() {
|
|
422
564
|
this.spaces = [
|
|
423
565
|
new QuicSentPackets(QUIC_RECOVERY_HANDSHAKE_CAPACITY),
|
|
@@ -454,6 +596,7 @@ export class QuicRecovery {
|
|
|
454
596
|
* address it has proved it holds (RFC 9000 §9.4): what was learnt of the
|
|
455
597
|
* old path says nothing about the new one. The packets in flight, the
|
|
456
598
|
* peer's `max_ack_delay` and the counters are kept.
|
|
599
|
+
* @internal Read by quic.ts.
|
|
457
600
|
*/
|
|
458
601
|
resetPath(): void {
|
|
459
602
|
this.latestRtt = 0
|
|
@@ -476,6 +619,7 @@ export class QuicRecovery {
|
|
|
476
619
|
* went out under the old test. Their loss, or an ACK of them, says
|
|
477
620
|
* nothing of the new test, and only packets marked from here on count
|
|
478
621
|
* toward it.
|
|
622
|
+
* @internal Read by quic.ts.
|
|
479
623
|
*/
|
|
480
624
|
restartEcn(): void {
|
|
481
625
|
for (const sp of this.spaces) {
|
|
@@ -489,7 +633,13 @@ export class QuicRecovery {
|
|
|
489
633
|
this.ecnTestLost = 0
|
|
490
634
|
}
|
|
491
635
|
|
|
492
|
-
/**
|
|
636
|
+
/**
|
|
637
|
+
* Space `space`'s packets, or `null` for an index that names no space.
|
|
638
|
+
*
|
|
639
|
+
* @param space A space's index: `QUIC_RECOVERY_INITIAL`, `QUIC_RECOVERY_HANDSHAKE` or
|
|
640
|
+
* `QUIC_RECOVERY_APPLICATION`.
|
|
641
|
+
* @returns The space's own ring, not a copy, or `null` for any other index.
|
|
642
|
+
*/
|
|
493
643
|
space(space: i32): QuicSentPackets | null {
|
|
494
644
|
if (space < 0 || space >= toI32(this.spaces.length)) {
|
|
495
645
|
return null
|
|
@@ -497,7 +647,11 @@ export class QuicRecovery {
|
|
|
497
647
|
return this.spaces[space]
|
|
498
648
|
}
|
|
499
649
|
|
|
500
|
-
/**
|
|
650
|
+
/**
|
|
651
|
+
* bytes_in_flight (B.2): every space's packets in flight.
|
|
652
|
+
*
|
|
653
|
+
* @returns The bytes of every packet in flight, summed over the three spaces.
|
|
654
|
+
*/
|
|
501
655
|
bytesInFlight(): i64 {
|
|
502
656
|
let total: i64 = 0
|
|
503
657
|
for (const sp of this.spaces) {
|
|
@@ -509,6 +663,8 @@ export class QuicRecovery {
|
|
|
509
663
|
/**
|
|
510
664
|
* Whether the window has room for another full-sized datagram (B.4). The
|
|
511
665
|
* caller sends nothing ack-eliciting while it has not, except a probe.
|
|
666
|
+
*
|
|
667
|
+
* @returns True when the bytes in flight plus 1200 bytes fit the congestion window.
|
|
512
668
|
*/
|
|
513
669
|
canSend(): boolean {
|
|
514
670
|
return this.bytesInFlight() + QUIC_RECOVERY_DATAGRAM_SIZE <= this.congestionWindow
|
|
@@ -520,6 +676,12 @@ export class QuicRecovery {
|
|
|
520
676
|
* the caller keeps what it carried, or -1, recording nothing, for a space
|
|
521
677
|
* that does not exist, a size that is not positive, a packet number that is
|
|
522
678
|
* not above the last one recorded, or a ring that is full.
|
|
679
|
+
*
|
|
680
|
+
* @param space The space's index, `QUIC_RECOVERY_INITIAL` to `QUIC_RECOVERY_APPLICATION`.
|
|
681
|
+
* @param pn The packet's number: above the last one recorded and at most 2^62 − 1.
|
|
682
|
+
* @param size The packet's size on the wire in bytes; must be positive.
|
|
683
|
+
* @param now The send time, in the caller's milliseconds.
|
|
684
|
+
* @returns The ring slot the packet is recorded in, or -1 when nothing was recorded.
|
|
523
685
|
*/
|
|
524
686
|
onPacketSent(space: i32, pn: i64, size: i32, now: i64): i32 {
|
|
525
687
|
const sp: QuicSentPackets | null = this.space(space)
|
|
@@ -555,6 +717,8 @@ export class QuicRecovery {
|
|
|
555
717
|
* for the first `QUIC_RECOVERY_ECN_TESTING_PACKETS` and, once the path is
|
|
556
718
|
* capable, for every one; 0, Not-ECT, while the testing packets wait to be
|
|
557
719
|
* validated and once validation failed.
|
|
720
|
+
*
|
|
721
|
+
* @returns `QUIC_RECOVERY_ECT0` (2) to mark with, or 0 for Not-ECT.
|
|
558
722
|
*/
|
|
559
723
|
ecnCodepoint(): i32 {
|
|
560
724
|
const testing: boolean =
|
|
@@ -567,6 +731,9 @@ export class QuicRecovery {
|
|
|
567
731
|
* `onPacketSent` answered for it, or -1 for a packet that elicits no
|
|
568
732
|
* acknowledgement and so was not recorded. Every packet of a datagram
|
|
569
733
|
* marked counts, whatever `ecnCodepoint()` answers by the last of them.
|
|
734
|
+
*
|
|
735
|
+
* @param space The space's index, `QUIC_RECOVERY_INITIAL` to `QUIC_RECOVERY_APPLICATION`.
|
|
736
|
+
* @param slot The slot `onPacketSent` answered for the packet, or -1 when it was not recorded.
|
|
570
737
|
*/
|
|
571
738
|
onEctSent(space: i32, slot: i32): void {
|
|
572
739
|
const sp: QuicSentPackets | null = this.space(space)
|
|
@@ -601,6 +768,14 @@ export class QuicRecovery {
|
|
|
601
768
|
* exist or there is no range. A packet number the space never sent is the
|
|
602
769
|
* caller's to refuse (RFC 9000 §13.1): only it knows the packets that
|
|
603
770
|
* elicit no acknowledgement, which are not recorded here.
|
|
771
|
+
*
|
|
772
|
+
* @param space The space's index, `QUIC_RECOVERY_INITIAL` to `QUIC_RECOVERY_APPLICATION`.
|
|
773
|
+
* @param ranges The acknowledged packet numbers, as `[smallest, largest]` pairs, highest first; only read.
|
|
774
|
+
* @param count How many pairs of `ranges` to read; past the array's length the rest are ignored.
|
|
775
|
+
* @param ackDelay The peer's ACK Delay, already scaled, in milliseconds.
|
|
776
|
+
* @param now The time the ACK arrived, in the caller's milliseconds.
|
|
777
|
+
* @returns How many recorded packets were newly acknowledged, or -1 when the space or the ranges are
|
|
778
|
+
* missing.
|
|
604
779
|
*/
|
|
605
780
|
onAck(space: i32, ranges: i64[], count: i32, ackDelay: i64, now: i64): i32 {
|
|
606
781
|
const none: i64 = -1
|
|
@@ -613,6 +788,17 @@ export class QuicRecovery {
|
|
|
613
788
|
* carries none. The counts are validated (RFC 9000 §13.4.2.1) and a rise
|
|
614
789
|
* in ECN-CE is a congestion event (§7.1, B.7) before loss is detected, as
|
|
615
790
|
* A.7 orders it.
|
|
791
|
+
*
|
|
792
|
+
* @param space The space's index, `QUIC_RECOVERY_INITIAL` to `QUIC_RECOVERY_APPLICATION`.
|
|
793
|
+
* @param ranges The acknowledged packet numbers, as `[smallest, largest]` pairs, highest first; only read.
|
|
794
|
+
* @param count How many pairs of `ranges` to read; past the array's length the rest are ignored.
|
|
795
|
+
* @param ackDelay The peer's ACK Delay, already scaled, in milliseconds.
|
|
796
|
+
* @param now The time the ACK arrived, in the caller's milliseconds.
|
|
797
|
+
* @param ect0 The frame's ECT(0) count, or -1 for an ACK without counts.
|
|
798
|
+
* @param ect1 The frame's ECT(1) count, or -1 for an ACK without counts.
|
|
799
|
+
* @param ce The frame's ECN-CE count, or -1 for an ACK without counts.
|
|
800
|
+
* @returns How many recorded packets were newly acknowledged, or -1 when the space or the ranges are
|
|
801
|
+
* missing.
|
|
616
802
|
*/
|
|
617
803
|
onAckEcn(
|
|
618
804
|
space: i32,
|
|
@@ -699,7 +885,7 @@ export class QuicRecovery {
|
|
|
699
885
|
* acknowledged it is timed from `later`, a send time no earlier than the
|
|
700
886
|
* largest acknowledged packet's, which recovery did not record.
|
|
701
887
|
*/
|
|
702
|
-
processEcn(
|
|
888
|
+
private processEcn(
|
|
703
889
|
sp: QuicSentPackets,
|
|
704
890
|
raised: boolean,
|
|
705
891
|
ect0: i64,
|
|
@@ -756,7 +942,7 @@ export class QuicRecovery {
|
|
|
756
942
|
}
|
|
757
943
|
|
|
758
944
|
/** UpdateRtt (§5.3, A.7) with a sample in `latestRtt`, `ackDelay` the peer's delay in milliseconds. */
|
|
759
|
-
updateRtt(ackDelay: i64, now: i64): void {
|
|
945
|
+
private updateRtt(ackDelay: i64, now: i64): void {
|
|
760
946
|
const latest: i64 = this.latestRtt
|
|
761
947
|
if (this.firstSampleTime < 0) {
|
|
762
948
|
this.minRtt = latest
|
|
@@ -780,13 +966,16 @@ export class QuicRecovery {
|
|
|
780
966
|
}
|
|
781
967
|
|
|
782
968
|
/** The peer's ACK delay in milliseconds as §5.3 counts it: at most max_ack_delay once the handshake is confirmed. */
|
|
783
|
-
boundAckDelay(ackDelay: i64): i64 {
|
|
969
|
+
private boundAckDelay(ackDelay: i64): i64 {
|
|
784
970
|
return this.handshakeConfirmed && ackDelay > this.maxAckDelay ? this.maxAckDelay : ackDelay
|
|
785
971
|
}
|
|
786
972
|
|
|
787
973
|
/**
|
|
788
974
|
* `now` on the pacer's clock: `micros` when it falls inside the
|
|
789
975
|
* millisecond `now` names, and `now × 1000` otherwise.
|
|
976
|
+
*
|
|
977
|
+
* @param now The caller's time in milliseconds.
|
|
978
|
+
* @returns The same instant in microseconds.
|
|
790
979
|
*/
|
|
791
980
|
fineNow(now: i64): i64 {
|
|
792
981
|
const coarse: i64 = now * QUIC_RECOVERY_MICROS
|
|
@@ -802,7 +991,7 @@ export class QuicRecovery {
|
|
|
802
991
|
* runs long by up to a millisecond: only a carrier that calls `clock` on
|
|
803
992
|
* some sends and not others sees that.
|
|
804
993
|
*/
|
|
805
|
-
fineSample(now: i64, sent: i64): i64 {
|
|
994
|
+
private fineSample(now: i64, sent: i64): i64 {
|
|
806
995
|
const at: i64 = this.fineNow(now)
|
|
807
996
|
const floor: i64 = at === this.micros ? 1 : QUIC_RECOVERY_GRANULARITY * QUIC_RECOVERY_MICROS
|
|
808
997
|
return quicRecoveryMax(at - sent, floor)
|
|
@@ -815,7 +1004,7 @@ export class QuicRecovery {
|
|
|
815
1004
|
* true minimum, so a delay is taken off a little more readily than
|
|
816
1005
|
* `updateRtt` takes it.
|
|
817
1006
|
*/
|
|
818
|
-
updatePacerRtt(sample: i64, ackDelay: i64, first: boolean): void {
|
|
1007
|
+
private updatePacerRtt(sample: i64, ackDelay: i64, first: boolean): void {
|
|
819
1008
|
if (first) {
|
|
820
1009
|
this.pacerRtt = sample
|
|
821
1010
|
return
|
|
@@ -828,7 +1017,11 @@ export class QuicRecovery {
|
|
|
828
1017
|
this.pacerRtt = (7 * this.pacerRtt + adjusted) / 8
|
|
829
1018
|
}
|
|
830
1019
|
|
|
831
|
-
/**
|
|
1020
|
+
/**
|
|
1021
|
+
* The loss delay (§6.1.2): 9/8 of the larger of the latest and the smoothed RTT, at least the granularity.
|
|
1022
|
+
*
|
|
1023
|
+
* @returns How long after a packet was sent it is lost by the time threshold, in milliseconds, at least 1.
|
|
1024
|
+
*/
|
|
832
1025
|
lossDelay(): i64 {
|
|
833
1026
|
const delay: i64 = (9 * quicRecoveryMax(this.latestRtt, this.smoothedRtt)) / 8
|
|
834
1027
|
return quicRecoveryMax(delay, QUIC_RECOVERY_GRANULARITY)
|
|
@@ -840,7 +1033,7 @@ export class QuicRecovery {
|
|
|
840
1033
|
* three numbers below the largest acknowledged; the first that is neither
|
|
841
1034
|
* sets `lossTime`.
|
|
842
1035
|
*/
|
|
843
|
-
detectLoss(sp: QuicSentPackets, now: i64): void {
|
|
1036
|
+
private detectLoss(sp: QuicSentPackets, now: i64): void {
|
|
844
1037
|
sp.lossTime = -1
|
|
845
1038
|
const delay: i64 = this.lossDelay()
|
|
846
1039
|
const lostSendTime: i64 = now - delay
|
|
@@ -869,7 +1062,7 @@ export class QuicRecovery {
|
|
|
869
1062
|
* congestion event for the newest of them, and persistent congestion
|
|
870
1063
|
* when they span long enough.
|
|
871
1064
|
*/
|
|
872
|
-
packetsLost(sp: QuicSentPackets, now: i64): void {
|
|
1065
|
+
private packetsLost(sp: QuicSentPackets, now: i64): void {
|
|
873
1066
|
if (sp.lostCount === 0) {
|
|
874
1067
|
return
|
|
875
1068
|
}
|
|
@@ -906,7 +1099,7 @@ export class QuicRecovery {
|
|
|
906
1099
|
* spanning more than three probe timeouts with max_ack_delay, and holding
|
|
907
1100
|
* at least one packet this call declared lost.
|
|
908
1101
|
*/
|
|
909
|
-
persistentCongestion(sp: QuicSentPackets): boolean {
|
|
1102
|
+
private persistentCongestion(sp: QuicSentPackets): boolean {
|
|
910
1103
|
if (this.firstSampleTime < 0) {
|
|
911
1104
|
return false
|
|
912
1105
|
}
|
|
@@ -937,12 +1130,12 @@ export class QuicRecovery {
|
|
|
937
1130
|
}
|
|
938
1131
|
|
|
939
1132
|
/** Whether a packet sent at `sentTime` was sent during the current recovery period (B.4). */
|
|
940
|
-
inRecovery(sentTime: i64): boolean {
|
|
1133
|
+
private inRecovery(sentTime: i64): boolean {
|
|
941
1134
|
return this.recoveryStart >= 0 && sentTime <= this.recoveryStart
|
|
942
1135
|
}
|
|
943
1136
|
|
|
944
1137
|
/** OnCongestionEvent (B.6): halve the window, once per recovery period. */
|
|
945
|
-
congestionEvent(sentTime: i64, now: i64): void {
|
|
1138
|
+
private congestionEvent(sentTime: i64, now: i64): void {
|
|
946
1139
|
if (this.inRecovery(sentTime)) {
|
|
947
1140
|
return
|
|
948
1141
|
}
|
|
@@ -958,7 +1151,7 @@ export class QuicRecovery {
|
|
|
958
1151
|
* all for a packet sent during recovery, or when `inUse` says the window
|
|
959
1152
|
* was not being used (§7.8).
|
|
960
1153
|
*/
|
|
961
|
-
packetAcked(sp: QuicSentPackets, s: i32, inUse: boolean): void {
|
|
1154
|
+
private packetAcked(sp: QuicSentPackets, s: i32, inUse: boolean): void {
|
|
962
1155
|
if (!inUse || this.inRecovery(sp.timeAt(s))) {
|
|
963
1156
|
return
|
|
964
1157
|
}
|
|
@@ -976,6 +1169,8 @@ export class QuicRecovery {
|
|
|
976
1169
|
* max(4 × rttvar, kGranularity), plus the peer's max_ack_delay once the
|
|
977
1170
|
* handshake is confirmed. It is also what a key update's old keys are kept
|
|
978
1171
|
* for and what the idle timeout is at least three of.
|
|
1172
|
+
*
|
|
1173
|
+
* @returns The period in milliseconds, at least 1.
|
|
979
1174
|
*/
|
|
980
1175
|
probeTimeout(): i64 {
|
|
981
1176
|
const base: i64 = this.ptoBase()
|
|
@@ -983,7 +1178,7 @@ export class QuicRecovery {
|
|
|
983
1178
|
}
|
|
984
1179
|
|
|
985
1180
|
/** smoothed_rtt + max(4 × rttvar, kGranularity): every probe timeout's period before max_ack_delay and the backoff. */
|
|
986
|
-
ptoBase(): i64 {
|
|
1181
|
+
private ptoBase(): i64 {
|
|
987
1182
|
return this.smoothedRtt + quicRecoveryMax(4 * this.rttVar, QUIC_RECOVERY_GRANULARITY)
|
|
988
1183
|
}
|
|
989
1184
|
|
|
@@ -991,8 +1186,9 @@ export class QuicRecovery {
|
|
|
991
1186
|
* GetPtoTimeAndSpace (A.8): when the probe timeout fires, the earliest
|
|
992
1187
|
* over the spaces with an ack-eliciting packet in flight, with the backoff
|
|
993
1188
|
* applied; the Application Data space counts only once the handshake is
|
|
994
|
-
* confirmed. Answers -1 with nothing in flight.
|
|
995
|
-
*
|
|
1189
|
+
* confirmed. Answers -1 with nothing in flight.
|
|
1190
|
+
*
|
|
1191
|
+
* @returns The time the probe timeout fires, in the caller's milliseconds, or -1 when no space has one.
|
|
996
1192
|
*/
|
|
997
1193
|
ptoTime(): i64 {
|
|
998
1194
|
const space: i32 = this.ptoSpace()
|
|
@@ -1003,7 +1199,7 @@ export class QuicRecovery {
|
|
|
1003
1199
|
}
|
|
1004
1200
|
|
|
1005
1201
|
/** The probe timeout of space `space`, from its last ack-eliciting packet, with the backoff. */
|
|
1006
|
-
ptoTimeOf(space: i32): i64 {
|
|
1202
|
+
private ptoTimeOf(space: i32): i64 {
|
|
1007
1203
|
const sp: QuicSentPackets | null = this.space(space)
|
|
1008
1204
|
if (sp === null || sp.lastAckEliciting < 0) {
|
|
1009
1205
|
return -1
|
|
@@ -1017,7 +1213,7 @@ export class QuicRecovery {
|
|
|
1017
1213
|
}
|
|
1018
1214
|
|
|
1019
1215
|
/** The space whose probe timeout fires first, or -1 when no space may have one. */
|
|
1020
|
-
ptoSpace(): i32 {
|
|
1216
|
+
private ptoSpace(): i32 {
|
|
1021
1217
|
let best: i32 = -1
|
|
1022
1218
|
let bestTime: i64 = -1
|
|
1023
1219
|
for (let space: i32 = 0; space < toI32(this.spaces.length); space += 1) {
|
|
@@ -1035,7 +1231,7 @@ export class QuicRecovery {
|
|
|
1035
1231
|
}
|
|
1036
1232
|
|
|
1037
1233
|
/** The space with the earliest `lossTime`, or -1 when none is set. */
|
|
1038
|
-
lossSpace(): i32 {
|
|
1234
|
+
private lossSpace(): i32 {
|
|
1039
1235
|
let best: i32 = -1
|
|
1040
1236
|
let bestTime: i64 = -1
|
|
1041
1237
|
for (let space: i32 = 0; space < toI32(this.spaces.length); space += 1) {
|
|
@@ -1053,6 +1249,9 @@ export class QuicRecovery {
|
|
|
1053
1249
|
* time-threshold loss, else the probe timeout — or -1 for none. With
|
|
1054
1250
|
* `amplificationBlocked`, when the server may send nothing until the client
|
|
1055
1251
|
* does (RFC 9000 §8.1), there is no probe timeout (§6.2.2.1).
|
|
1252
|
+
*
|
|
1253
|
+
* @param amplificationBlocked Whether the anti-amplification limit stops the server sending anything now.
|
|
1254
|
+
* @returns The time `onTimeout` is next due, in the caller's milliseconds, or -1 when no timer is set.
|
|
1056
1255
|
*/
|
|
1057
1256
|
deadline(amplificationBlocked: boolean): i64 {
|
|
1058
1257
|
const loss: i32 = this.lossSpace()
|
|
@@ -1072,6 +1271,11 @@ export class QuicRecovery {
|
|
|
1072
1271
|
* timeout is due, the backoff doubles and the caller is to send a probe in
|
|
1073
1272
|
* `timeoutSpace`: `QUIC_RECOVERY_TIMEOUT_PTO`. Before either is due, or
|
|
1074
1273
|
* when nothing is timed, `QUIC_RECOVERY_TIMEOUT_NONE`.
|
|
1274
|
+
*
|
|
1275
|
+
* @param now The caller's time in milliseconds.
|
|
1276
|
+
* @param amplificationBlocked Whether the anti-amplification limit stops the server sending anything now.
|
|
1277
|
+
* @returns One of `QUIC_RECOVERY_TIMEOUT_NONE`, `QUIC_RECOVERY_TIMEOUT_LOSS` or
|
|
1278
|
+
* `QUIC_RECOVERY_TIMEOUT_PTO`.
|
|
1075
1279
|
*/
|
|
1076
1280
|
onTimeout(now: i64, amplificationBlocked: boolean): i32 {
|
|
1077
1281
|
for (const sp of this.spaces) {
|
|
@@ -1104,6 +1308,9 @@ export class QuicRecovery {
|
|
|
1104
1308
|
* when the ring is full. The caller has already queued what the space had
|
|
1105
1309
|
* in flight again, which is what a probe sends. Answers the slot, or -1
|
|
1106
1310
|
* when nothing is in flight there.
|
|
1311
|
+
*
|
|
1312
|
+
* @param space The space's index, `QUIC_RECOVERY_INITIAL` to `QUIC_RECOVERY_APPLICATION`.
|
|
1313
|
+
* @returns The slot of the packet given up, now settled as lost, or -1 when nothing is in flight there.
|
|
1107
1314
|
*/
|
|
1108
1315
|
evictOldest(space: i32): i32 {
|
|
1109
1316
|
const sp: QuicSentPackets | null = this.space(space)
|
|
@@ -1124,6 +1331,8 @@ export class QuicRecovery {
|
|
|
1124
1331
|
/**
|
|
1125
1332
|
* OnPacketNumberSpaceDiscarded (A.11): the space's keys are gone, so its
|
|
1126
1333
|
* packets leave flight uncounted, its timers stop, and the backoff resets.
|
|
1334
|
+
*
|
|
1335
|
+
* @param space The space's index, `QUIC_RECOVERY_INITIAL` to `QUIC_RECOVERY_APPLICATION`.
|
|
1127
1336
|
*/
|
|
1128
1337
|
discardSpace(space: i32): void {
|
|
1129
1338
|
const sp: QuicSentPackets | null = this.space(space)
|
|
@@ -1135,7 +1344,7 @@ export class QuicRecovery {
|
|
|
1135
1344
|
}
|
|
1136
1345
|
|
|
1137
1346
|
/** The congestion window the pacer earns by: at most `QUIC_RECOVERY_PACER_WINDOW`. */
|
|
1138
|
-
pacerWindow(): i64 {
|
|
1347
|
+
private pacerWindow(): i64 {
|
|
1139
1348
|
return this.congestionWindow < QUIC_RECOVERY_PACER_WINDOW
|
|
1140
1349
|
? this.congestionWindow
|
|
1141
1350
|
: QUIC_RECOVERY_PACER_WINDOW
|
|
@@ -1146,7 +1355,7 @@ export class QuicRecovery {
|
|
|
1146
1355
|
* window per `pacerRtt`, and holds at most the initial window, which is the
|
|
1147
1356
|
* largest burst it allows.
|
|
1148
1357
|
*/
|
|
1149
|
-
pacerRefill(now: i64): void {
|
|
1358
|
+
private pacerRefill(now: i64): void {
|
|
1150
1359
|
const at: i64 = this.fineNow(now)
|
|
1151
1360
|
if (this.pacerTime < 0 || at < this.pacerTime) {
|
|
1152
1361
|
this.pacerTime = at
|
|
@@ -1171,6 +1380,10 @@ export class QuicRecovery {
|
|
|
1171
1380
|
* bytes go: 0 when it may go now, else its wait in microseconds rounded
|
|
1172
1381
|
* up to whole milliseconds, so at least 1. The rate is 5/4 of the window per `pacerRtt`
|
|
1173
1382
|
* (§7.7's N of 1.25).
|
|
1383
|
+
*
|
|
1384
|
+
* @param now The caller's time in milliseconds; the pacer reads `micros` too when it is current.
|
|
1385
|
+
* @param size The datagram's size in bytes.
|
|
1386
|
+
* @returns The wait in whole milliseconds: 0 to send now, else at least 1.
|
|
1174
1387
|
*/
|
|
1175
1388
|
pacerDelay(now: i64, size: i32): i64 {
|
|
1176
1389
|
this.pacerRefill(now)
|
|
@@ -1190,6 +1403,10 @@ export class QuicRecovery {
|
|
|
1190
1403
|
* pacer that earns by the microsecond would otherwise let a fast
|
|
1191
1404
|
* connection out a datagram at a time, one send each; one that earns
|
|
1192
1405
|
* slowly still lets a datagram go as soon as it has the credit for it.
|
|
1406
|
+
*
|
|
1407
|
+
* @param least The smallest quantum, in bytes, such as one full datagram.
|
|
1408
|
+
* @param most The largest quantum, in bytes, such as `QUIC_LISTENER_FLIGHT_QUANTUM`.
|
|
1409
|
+
* @returns The bytes the pacer earns in a millisecond, held to `least` and `most`.
|
|
1193
1410
|
*/
|
|
1194
1411
|
pacerQuantum(least: i32, most: i32): i32 {
|
|
1195
1412
|
const rtt: i64 = quicRecoveryMax(this.pacerRtt, 1)
|
|
@@ -1200,7 +1417,12 @@ export class QuicRecovery {
|
|
|
1200
1417
|
return milli > toI64(most) ? most : toI32(milli)
|
|
1201
1418
|
}
|
|
1202
1419
|
|
|
1203
|
-
/**
|
|
1420
|
+
/**
|
|
1421
|
+
* Charges the pacer for a datagram of `size` bytes sent at `now`.
|
|
1422
|
+
*
|
|
1423
|
+
* @param now The send time in the caller's milliseconds; the pacer is topped up to it first.
|
|
1424
|
+
* @param size The datagram's size in bytes, which may take the credit below 0.
|
|
1425
|
+
*/
|
|
1204
1426
|
onPaced(now: i64, size: i32): void {
|
|
1205
1427
|
this.pacerRefill(now)
|
|
1206
1428
|
this.pacerBudget = this.pacerBudget - toI64(size)
|