nish 0.34.1 → 0.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -6
- package/docs/AI.md +86 -16
- package/docs/INSTALL.md +22 -13
- package/llms.txt +5 -2
- package/package.json +15 -5
- package/runtime/async.d.mts +49 -0
- package/runtime/async.mjs +27 -0
- package/runtime/nish.d.ts +4681 -427
- package/runtime/nish.h +6 -2
- package/runtime/nish.mjs +4 -0
- package/runtime/runtime-net.c +22 -0
- package/runtime/runtime-shm.c +93 -2
- package/runtime/vite.d.ts +30 -0
- package/runtime/vite.mjs +150 -0
- package/scripts/build.sh +108 -13
- package/std/README.md +131 -131
- package/std/base64.ts +34 -5
- package/std/bytes.ts +258 -42
- package/std/cli-args.ts +296 -70
- package/std/cli-flags.ts +184 -19
- package/std/cli.ts +475 -54
- package/std/collections.ts +121 -23
- package/std/compress/checksum.ts +44 -14
- package/std/compress/deflate.ts +224 -111
- package/std/compress/gzip.ts +217 -53
- package/std/compress/zlib.ts +63 -7
- package/std/crypto/aes.ts +80 -9
- package/std/crypto/base64url.ts +22 -0
- package/std/crypto/bcrypt-batch.ts +88 -21
- package/std/crypto/bcrypt.ts +60 -0
- package/std/crypto/chacha20poly1305.ts +53 -0
- package/std/crypto/ct.ts +32 -13
- package/std/crypto/ed25519.ts +47 -0
- package/std/crypto/hkdf.ts +198 -13
- package/std/crypto/hmac.ts +235 -31
- package/std/crypto/jwt.ts +192 -63
- package/std/crypto/p256.ts +159 -16
- package/std/crypto/p384.ts +28 -3
- package/std/crypto/pki-roots.ts +32 -2
- package/std/crypto/pki.ts +81 -15
- package/std/crypto/rsa.ts +33 -3
- package/std/crypto/sha1.ts +3 -0
- package/std/crypto/sha256.ts +24 -1
- package/std/crypto/sha512.ts +99 -14
- package/std/crypto/x25519.ts +152 -14
- package/std/crypto/x509-random.ts +10 -0
- package/std/crypto/x509.ts +67 -7
- package/std/json-equal.ts +19 -0
- package/std/json-format.ts +112 -13
- package/std/json-number.ts +64 -14
- package/std/json-pointer.ts +23 -1
- package/std/json-tokenizer.ts +100 -29
- package/std/json-typed.ts +713 -66
- package/std/json-value.ts +400 -124
- package/std/json.ts +138 -10
- package/std/map.ts +25 -7
- package/std/math.ts +36 -4
- package/std/net/buffer-pool.ts +42 -11
- package/std/net/dns-config.ts +109 -23
- package/std/net/dns-message.ts +62 -7
- package/std/net/dns-resolver.ts +247 -53
- package/std/net/dns.ts +203 -35
- package/std/net/fetch.ts +151 -61
- package/std/net/handler.ts +278 -80
- package/std/net/hpack.ts +262 -52
- package/std/net/http-compress.ts +125 -15
- package/std/net/http-fields.ts +85 -9
- package/std/net/http1-client-codec.ts +100 -19
- package/std/net/http1-codec.ts +297 -77
- package/std/net/http1-server.ts +430 -94
- package/std/net/http2-frame.ts +272 -35
- package/std/net/http2-tls.ts +135 -34
- package/std/net/http2.ts +247 -106
- package/std/net/http3-frame.ts +154 -17
- package/std/net/http3-server.ts +275 -101
- package/std/net/http3.ts +307 -115
- package/std/net/outbound.ts +37 -3
- package/std/net/postgres-carrier.ts +144 -8
- package/std/net/postgres.ts +801 -112
- package/std/net/prefork.ts +164 -31
- package/std/net/qpack.ts +105 -18
- package/std/net/quic-conn-ack.ts +59 -12
- package/std/net/quic-conn-cid.ts +124 -27
- package/std/net/quic-conn-params.ts +70 -10
- package/std/net/quic-datagram.ts +43 -3
- package/std/net/quic-frame.ts +286 -12
- package/std/net/quic-listener.ts +101 -32
- package/std/net/quic-packet.ts +302 -21
- package/std/net/quic-recovery.ts +264 -52
- package/std/net/quic-stream.ts +353 -91
- package/std/net/quic.ts +1124 -201
- package/std/net/router.ts +87 -40
- package/std/net/tls/client.ts +166 -51
- package/std/net/tls/codec.ts +413 -56
- package/std/net/tls/record-client.ts +110 -55
- package/std/net/tls/record-server.ts +159 -59
- package/std/net/tls/record.ts +109 -12
- package/std/net/tls/schedule.ts +235 -26
- package/std/net/tls/ticket.ts +159 -40
- package/std/net/tls/verify.ts +49 -3
- package/std/net/tls-tcp.ts +250 -45
- package/std/net/tls.ts +221 -59
- package/std/net/upstream.ts +81 -45
- package/std/net/url.ts +97 -13
- package/std/net/websocket.ts +122 -12
- package/std/net/webtransport.ts +220 -89
- package/std/pair.ts +10 -2
- package/std/random.ts +34 -9
- package/std/regex.ts +352 -198
- package/std/region.ts +70 -15
- package/std/secret.ts +52 -11
- package/std/sort.ts +17 -2
- package/std/sqlite.ts +256 -35
- package/std/sync/ring.ts +430 -40
- package/std/sync/shm.ts +222 -15
- package/std/term-io.ts +137 -64
- package/std/term-pixels.ts +144 -19
- package/std/term-probe.ts +66 -25
- package/std/term-rate.ts +128 -57
- package/std/term.ts +332 -121
- package/std/testing.ts +130 -32
- package/std/text.ts +73 -7
- package/std/threads.ts +229 -41
- package/std/yaml-json.ts +94 -82
- package/std/yaml-lines.ts +47 -15
- package/std/yaml-write.ts +24 -16
- package/std/yaml.ts +764 -384
package/std/net/quic-recovery.ts
CHANGED
|
@@ -146,8 +146,16 @@ export const QUIC_RECOVERY_ECT0: i32 = 2
|
|
|
146
146
|
export const QUIC_RECOVERY_ECN_TESTING_PACKETS: i32 = 10
|
|
147
147
|
/** 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
148
|
export const QUIC_RECOVERY_ECN_TESTING: i32 = 0
|
|
149
|
+
/**
|
|
150
|
+
* ECN is unknown: the testing packets are sent, none is validated yet, and nothing more is marked
|
|
151
|
+
* until one is.
|
|
152
|
+
*/
|
|
149
153
|
export const QUIC_RECOVERY_ECN_UNKNOWN: i32 = 1
|
|
154
|
+
/** The path is ECN-capable: a marked packet's counts validated, and every packet is marked from here on. */
|
|
150
155
|
export const QUIC_RECOVERY_ECN_CAPABLE: i32 = 2
|
|
156
|
+
/**
|
|
157
|
+
* Validation failed: nothing is marked again for the connection's life, unless `restartEcn` tests a new path.
|
|
158
|
+
*/
|
|
151
159
|
export const QUIC_RECOVERY_ECN_FAILED: i32 = 3
|
|
152
160
|
|
|
153
161
|
/** Microseconds in a millisecond: the pacer's clock against the caller's `now`. */
|
|
@@ -193,8 +201,8 @@ export class QuicSentPackets {
|
|
|
193
201
|
lastAckEliciting: i64 = -1
|
|
194
202
|
/** The bytes of this space's packets in flight. */
|
|
195
203
|
bytesInFlight: i64 = 0
|
|
196
|
-
capacity: i32 = 0
|
|
197
|
-
head: i32 = 0
|
|
204
|
+
private capacity: i32 = 0
|
|
205
|
+
private head: i32 = 0
|
|
198
206
|
count: i32 = 0
|
|
199
207
|
/** How many recorded packets are still in flight: neither acknowledged nor lost. */
|
|
200
208
|
inFlight: i32 = 0
|
|
@@ -207,6 +215,13 @@ export class QuicSentPackets {
|
|
|
207
215
|
ect1: i64 = 0
|
|
208
216
|
ce: i64 = 0
|
|
209
217
|
|
|
218
|
+
/**
|
|
219
|
+
* An empty ring; `QuicRecovery` makes one for each space.
|
|
220
|
+
*
|
|
221
|
+
* @param capacity How many sent packets the ring records at once, fixed for its life: in flight and
|
|
222
|
+
* settled alike, until `compact` drops the settled ones. `QUIC_RECOVERY_HANDSHAKE_CAPACITY` or
|
|
223
|
+
* `QUIC_RECOVERY_APPLICATION_CAPACITY`.
|
|
224
|
+
*/
|
|
210
225
|
constructor(capacity: i32) {
|
|
211
226
|
this.capacity = capacity
|
|
212
227
|
this.pn = new Array<i64>(capacity)
|
|
@@ -218,12 +233,21 @@ export class QuicSentPackets {
|
|
|
218
233
|
this.lost = new Array<i32>(capacity)
|
|
219
234
|
}
|
|
220
235
|
|
|
221
|
-
/**
|
|
236
|
+
/**
|
|
237
|
+
* The ring slot of the `k`-th packet kept, counting from the oldest.
|
|
238
|
+
* @internal Read by quic.ts, and in quic-recovery.ts outside the class.
|
|
239
|
+
*/
|
|
222
240
|
slot(k: i32): i32 {
|
|
223
241
|
return (this.head + k) % this.capacity
|
|
224
242
|
}
|
|
225
243
|
|
|
226
|
-
/**
|
|
244
|
+
/**
|
|
245
|
+
* The state of slot `s`, or free for a slot outside the ring.
|
|
246
|
+
*
|
|
247
|
+
* @param s A ring slot, as `onPacketSent`, `ackedSlot` or `lostSlot` answers it; any other index is safe.
|
|
248
|
+
* @returns The slot's state without its ECT(0) mark: free, in flight, acknowledged, lost, or lost now
|
|
249
|
+
* (`markLost`'s mark for a packet the current call declared lost).
|
|
250
|
+
*/
|
|
227
251
|
stateAt(s: i32): i32 {
|
|
228
252
|
if (s < 0 || s >= toI32(this.state.length)) {
|
|
229
253
|
return QUIC_RECOVERY_FREE
|
|
@@ -231,67 +255,128 @@ export class QuicSentPackets {
|
|
|
231
255
|
return toI32(this.state[s]) & (QUIC_RECOVERY_MARKED - 1)
|
|
232
256
|
}
|
|
233
257
|
|
|
234
|
-
/**
|
|
258
|
+
/**
|
|
259
|
+
* Sets slot `s`'s state.
|
|
260
|
+
* @internal Read in quic-recovery.ts outside the class.
|
|
261
|
+
*/
|
|
235
262
|
setState(s: i32, value: i32): void {
|
|
236
263
|
if (s >= 0 && s < toI32(this.state.length)) {
|
|
237
264
|
this.state[s] = toU8((toI32(this.state[s]) & QUIC_RECOVERY_MARKED) | value)
|
|
238
265
|
}
|
|
239
266
|
}
|
|
240
267
|
|
|
241
|
-
/**
|
|
268
|
+
/**
|
|
269
|
+
* The packet number in slot `s`, or -1.
|
|
270
|
+
*
|
|
271
|
+
* @param s A ring slot, as `onPacketSent`, `ackedSlot` or `lostSlot` answers it; any other index is safe.
|
|
272
|
+
* @returns The packet number recorded there, or -1 for an index outside the ring.
|
|
273
|
+
*/
|
|
242
274
|
pnAt(s: i32): i64 {
|
|
243
275
|
return s >= 0 && s < toI32(this.pn.length) ? this.pn[s] : -1
|
|
244
276
|
}
|
|
245
277
|
|
|
246
|
-
/**
|
|
278
|
+
/**
|
|
279
|
+
* When the packet in slot `s` was sent, or -1.
|
|
280
|
+
*
|
|
281
|
+
* @param s A ring slot, as `onPacketSent`, `ackedSlot` or `lostSlot` answers it; any other index is safe.
|
|
282
|
+
* @returns The `now` it was recorded at, in the caller's milliseconds, or -1 for an index outside the ring.
|
|
283
|
+
*/
|
|
247
284
|
timeAt(s: i32): i64 {
|
|
248
285
|
return s >= 0 && s < toI32(this.timeSent.length) ? this.timeSent[s] : -1
|
|
249
286
|
}
|
|
250
287
|
|
|
251
|
-
/**
|
|
288
|
+
/**
|
|
289
|
+
* When the packet in slot `s` was sent on the pacer's clock, in microseconds, or -1.
|
|
290
|
+
*
|
|
291
|
+
* @param s A ring slot, as `onPacketSent`, `ackedSlot` or `lostSlot` answers it; any other index is safe.
|
|
292
|
+
* @returns The send time in microseconds (`now × 1000` when `micros` was not current), or -1 for an
|
|
293
|
+
* index outside the ring.
|
|
294
|
+
*/
|
|
252
295
|
fineAt(s: i32): i64 {
|
|
253
296
|
return s >= 0 && s < toI32(this.fineSent.length) ? this.fineSent[s] : -1
|
|
254
297
|
}
|
|
255
298
|
|
|
256
|
-
/**
|
|
299
|
+
/**
|
|
300
|
+
* The size of the packet in slot `s`, or 0.
|
|
301
|
+
*
|
|
302
|
+
* @param s A ring slot, as `onPacketSent`, `ackedSlot` or `lostSlot` answers it; any other index is safe.
|
|
303
|
+
* @returns Its size on the wire in bytes, or 0 for an index outside the ring.
|
|
304
|
+
*/
|
|
257
305
|
sizeAt(s: i32): i32 {
|
|
258
306
|
return s >= 0 && s < toI32(this.size.length) ? this.size[s] : 0
|
|
259
307
|
}
|
|
260
308
|
|
|
261
|
-
/**
|
|
309
|
+
/**
|
|
310
|
+
* Whether the packet in slot `s` was sent marked ECT(0).
|
|
311
|
+
*
|
|
312
|
+
* @param s A ring slot, as `onPacketSent`, `ackedSlot` or `lostSlot` answers it; any other index is safe.
|
|
313
|
+
* @returns True when `onEctSent` marked it; false for an index outside the ring.
|
|
314
|
+
*/
|
|
262
315
|
markedAt(s: i32): boolean {
|
|
263
316
|
return s >= 0 && s < toI32(this.state.length) && (toI32(this.state[s]) & QUIC_RECOVERY_MARKED) !== 0
|
|
264
317
|
}
|
|
265
318
|
|
|
266
|
-
/**
|
|
319
|
+
/**
|
|
320
|
+
* Sets whether the packet in slot `s` was sent marked ECT(0).
|
|
321
|
+
* @internal Read in quic-recovery.ts outside the class.
|
|
322
|
+
*/
|
|
267
323
|
setMarked(s: i32, value: boolean): void {
|
|
268
324
|
if (s >= 0 && s < toI32(this.state.length)) {
|
|
269
325
|
this.state[s] = toU8(this.stateAt(s) | (value ? QUIC_RECOVERY_MARKED : 0))
|
|
270
326
|
}
|
|
271
327
|
}
|
|
272
328
|
|
|
273
|
-
/**
|
|
329
|
+
/**
|
|
330
|
+
* The `k`-th slot the last call acknowledged, or -1.
|
|
331
|
+
*
|
|
332
|
+
* @param k The position in `acked`, from 0 to `ackedCount - 1`, oldest first.
|
|
333
|
+
* @returns The slot, or -1 for `k` out of range. It names that packet only until the next call that
|
|
334
|
+
* records, settles or frees a packet in this space, any of which can free or reuse the slot:
|
|
335
|
+
* `onPacketSent`, `onAck`, `onAckEcn`, `onTimeout`, `evictOldest`, `discardSpace` and `reset` on the
|
|
336
|
+
* recovery, and this ring's own `full` and `compact`.
|
|
337
|
+
*/
|
|
274
338
|
ackedSlot(k: i32): i32 {
|
|
275
339
|
return k >= 0 && k < this.ackedCount && k < toI32(this.acked.length) ? this.acked[k] : -1
|
|
276
340
|
}
|
|
277
341
|
|
|
278
|
-
/**
|
|
342
|
+
/**
|
|
343
|
+
* The `k`-th slot the last call declared lost, or -1.
|
|
344
|
+
*
|
|
345
|
+
* @param k The position in `lost`, from 0 to `lostCount - 1`, oldest first.
|
|
346
|
+
* @returns The slot, or -1 for `k` out of range. It names that packet only until the next call that
|
|
347
|
+
* records, settles or frees a packet in this space, any of which can free or reuse the slot:
|
|
348
|
+
* `onPacketSent`, `onAck`, `onAckEcn`, `onTimeout`, `evictOldest`, `discardSpace` and `reset` on the
|
|
349
|
+
* recovery, and this ring's own `full` and `compact`.
|
|
350
|
+
*/
|
|
279
351
|
lostSlot(k: i32): i32 {
|
|
280
352
|
return k >= 0 && k < this.lostCount && k < toI32(this.lost.length) ? this.lost[k] : -1
|
|
281
353
|
}
|
|
282
354
|
|
|
283
|
-
/**
|
|
355
|
+
/**
|
|
356
|
+
* Whether slot `s` holds a packet still in flight.
|
|
357
|
+
*
|
|
358
|
+
* @param s A ring slot, as `onPacketSent`, `ackedSlot` or `lostSlot` answers it; any other index is safe.
|
|
359
|
+
* @returns True for a packet neither acknowledged nor lost; false for an index outside the ring.
|
|
360
|
+
*/
|
|
284
361
|
inFlightAt(s: i32): boolean {
|
|
285
362
|
return this.stateAt(s) === QUIC_RECOVERY_SENT
|
|
286
363
|
}
|
|
287
364
|
|
|
288
|
-
/**
|
|
365
|
+
/**
|
|
366
|
+
* Whether every slot is taken, so nothing more can be recorded until a packet is settled.
|
|
367
|
+
*
|
|
368
|
+
* @returns True when `onPacketSent` would refuse a packet for want of room. Settled slots at the oldest
|
|
369
|
+
* end are freed first, so asking can change `count`.
|
|
370
|
+
*/
|
|
289
371
|
full(): boolean {
|
|
290
372
|
this.compact()
|
|
291
373
|
return this.count >= this.capacity
|
|
292
374
|
}
|
|
293
375
|
|
|
294
|
-
/**
|
|
376
|
+
/**
|
|
377
|
+
* Frees the oldest slots that are settled, acknowledged or lost.
|
|
378
|
+
* @internal Read by quic.ts, and in quic-recovery.ts outside the class.
|
|
379
|
+
*/
|
|
295
380
|
compact(): void {
|
|
296
381
|
while (this.count > 0 && this.stateAt(this.head) !== QUIC_RECOVERY_SENT) {
|
|
297
382
|
this.setState(this.head, QUIC_RECOVERY_FREE)
|
|
@@ -303,20 +388,29 @@ export class QuicSentPackets {
|
|
|
303
388
|
}
|
|
304
389
|
}
|
|
305
390
|
|
|
306
|
-
/**
|
|
391
|
+
/**
|
|
392
|
+
* Forgets the results of the last call.
|
|
393
|
+
* @internal Read in quic-recovery.ts outside the class.
|
|
394
|
+
*/
|
|
307
395
|
clearResults(): void {
|
|
308
396
|
this.ackedCount = 0
|
|
309
397
|
this.lostCount = 0
|
|
310
398
|
}
|
|
311
399
|
|
|
312
|
-
/**
|
|
400
|
+
/**
|
|
401
|
+
* Takes packet `s` out of flight.
|
|
402
|
+
* @internal Read in quic-recovery.ts outside the class.
|
|
403
|
+
*/
|
|
313
404
|
settle(s: i32, state: i32): void {
|
|
314
405
|
this.setState(s, state)
|
|
315
406
|
this.inFlight = this.inFlight - 1
|
|
316
407
|
this.bytesInFlight = this.bytesInFlight - toI64(this.sizeAt(s))
|
|
317
408
|
}
|
|
318
409
|
|
|
319
|
-
/**
|
|
410
|
+
/**
|
|
411
|
+
* Settles packet `s` as lost and lists it in `lost`.
|
|
412
|
+
* @internal Read in quic-recovery.ts outside the class.
|
|
413
|
+
*/
|
|
320
414
|
markLost(s: i32): void {
|
|
321
415
|
this.settle(s, QUIC_RECOVERY_LOST_NOW)
|
|
322
416
|
if (this.lostCount < toI32(this.lost.length)) {
|
|
@@ -325,7 +419,10 @@ export class QuicSentPackets {
|
|
|
325
419
|
}
|
|
326
420
|
}
|
|
327
421
|
|
|
328
|
-
/**
|
|
422
|
+
/**
|
|
423
|
+
* Drops every packet, as when the space's keys are discarded (A.11).
|
|
424
|
+
* @internal Read in quic-recovery.ts outside the class.
|
|
425
|
+
*/
|
|
329
426
|
clear(): void {
|
|
330
427
|
for (let s: i32 = 0; s < toI32(this.state.length); s += 1) {
|
|
331
428
|
this.state[s] = toU8(QUIC_RECOVERY_FREE)
|
|
@@ -339,7 +436,10 @@ export class QuicSentPackets {
|
|
|
339
436
|
this.clearResults()
|
|
340
437
|
}
|
|
341
438
|
|
|
342
|
-
/**
|
|
439
|
+
/**
|
|
440
|
+
* Empties the ring and forgets every number, for a connection slot reused for another peer.
|
|
441
|
+
* @internal Read in quic-recovery.ts outside the class.
|
|
442
|
+
*/
|
|
343
443
|
reset(): void {
|
|
344
444
|
this.clear()
|
|
345
445
|
this.largestAcked = -1
|
|
@@ -418,6 +518,10 @@ export class QuicRecovery {
|
|
|
418
518
|
/** 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
519
|
handshakeConfirmed: boolean = false
|
|
420
520
|
|
|
521
|
+
/**
|
|
522
|
+
* Makes the state a new connection has, as `reset` leaves it: every space
|
|
523
|
+
* empty, the RTT estimate and the window at their initial values.
|
|
524
|
+
*/
|
|
421
525
|
constructor() {
|
|
422
526
|
this.spaces = [
|
|
423
527
|
new QuicSentPackets(QUIC_RECOVERY_HANDSHAKE_CAPACITY),
|
|
@@ -436,32 +540,68 @@ export class QuicRecovery {
|
|
|
436
540
|
for (const sp of this.spaces) {
|
|
437
541
|
sp.reset()
|
|
438
542
|
}
|
|
543
|
+
this.resetPath()
|
|
544
|
+
this.maxAckDelay = QUIC_RECOVERY_DEFAULT_MAX_ACK_DELAY
|
|
545
|
+
this.micros = -1
|
|
546
|
+
this.ptoCount = 0
|
|
547
|
+
this.timeoutSpace = -1
|
|
548
|
+
this.congestionEvents = 0
|
|
549
|
+
this.persistentCongestions = 0
|
|
550
|
+
this.ecnCongestionEvents = 0
|
|
551
|
+
this.restartEcn()
|
|
552
|
+
this.handshakeConfirmed = false
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
/**
|
|
556
|
+
* Starts the RTT estimate, the congestion window and the pacer again from
|
|
557
|
+
* their initial values, for a connection whose peer moved to a new
|
|
558
|
+
* address it has proved it holds (RFC 9000 §9.4): what was learnt of the
|
|
559
|
+
* old path says nothing about the new one. The packets in flight, the
|
|
560
|
+
* peer's `max_ack_delay` and the counters are kept.
|
|
561
|
+
* @internal Read by quic.ts.
|
|
562
|
+
*/
|
|
563
|
+
resetPath(): void {
|
|
439
564
|
this.latestRtt = 0
|
|
440
565
|
this.smoothedRtt = QUIC_RECOVERY_INITIAL_RTT
|
|
441
566
|
this.rttVar = QUIC_RECOVERY_INITIAL_RTT / 2
|
|
442
567
|
this.minRtt = 0
|
|
443
568
|
this.firstSampleTime = -1
|
|
444
|
-
this.maxAckDelay = QUIC_RECOVERY_DEFAULT_MAX_ACK_DELAY
|
|
445
569
|
this.congestionWindow = QUIC_RECOVERY_INITIAL_WINDOW
|
|
446
570
|
this.ssthresh = QUIC_MAX_VARINT
|
|
447
571
|
this.recoveryStart = -1
|
|
448
572
|
this.pacerBudget = QUIC_RECOVERY_INITIAL_WINDOW
|
|
449
573
|
this.pacerTime = -1
|
|
450
574
|
this.pacerRtt = QUIC_RECOVERY_INITIAL_RTT * QUIC_RECOVERY_MICROS
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* Tests ECN again from the start, as on a new path (RFC 9000 §13.4.2).
|
|
579
|
+
* Every packet still in flight loses its mark: those sent on the old
|
|
580
|
+
* path, and those sent to the new one before it was validated, which
|
|
581
|
+
* went out under the old test. Their loss, or an ACK of them, says
|
|
582
|
+
* nothing of the new test, and only packets marked from here on count
|
|
583
|
+
* toward it.
|
|
584
|
+
* @internal Read by quic.ts.
|
|
585
|
+
*/
|
|
586
|
+
restartEcn(): void {
|
|
587
|
+
for (const sp of this.spaces) {
|
|
588
|
+
for (let s: i32 = 0; s < toI32(sp.state.length); s += 1) {
|
|
589
|
+
sp.setMarked(s, false)
|
|
590
|
+
}
|
|
591
|
+
}
|
|
457
592
|
this.ecnState = QUIC_RECOVERY_ECN_TESTING
|
|
458
593
|
this.ecnTestSent = 0
|
|
459
594
|
this.ecnTestRecorded = 0
|
|
460
595
|
this.ecnTestLost = 0
|
|
461
|
-
this.handshakeConfirmed = false
|
|
462
596
|
}
|
|
463
597
|
|
|
464
|
-
/**
|
|
598
|
+
/**
|
|
599
|
+
* Space `space`'s packets, or `null` for an index that names no space.
|
|
600
|
+
*
|
|
601
|
+
* @param space A space's index: `QUIC_RECOVERY_INITIAL`, `QUIC_RECOVERY_HANDSHAKE` or
|
|
602
|
+
* `QUIC_RECOVERY_APPLICATION`.
|
|
603
|
+
* @returns The space's own ring, not a copy, or `null` for any other index.
|
|
604
|
+
*/
|
|
465
605
|
space(space: i32): QuicSentPackets | null {
|
|
466
606
|
if (space < 0 || space >= toI32(this.spaces.length)) {
|
|
467
607
|
return null
|
|
@@ -469,7 +609,11 @@ export class QuicRecovery {
|
|
|
469
609
|
return this.spaces[space]
|
|
470
610
|
}
|
|
471
611
|
|
|
472
|
-
/**
|
|
612
|
+
/**
|
|
613
|
+
* bytes_in_flight (B.2): every space's packets in flight.
|
|
614
|
+
*
|
|
615
|
+
* @returns The bytes of every packet in flight, summed over the three spaces.
|
|
616
|
+
*/
|
|
473
617
|
bytesInFlight(): i64 {
|
|
474
618
|
let total: i64 = 0
|
|
475
619
|
for (const sp of this.spaces) {
|
|
@@ -481,6 +625,8 @@ export class QuicRecovery {
|
|
|
481
625
|
/**
|
|
482
626
|
* Whether the window has room for another full-sized datagram (B.4). The
|
|
483
627
|
* caller sends nothing ack-eliciting while it has not, except a probe.
|
|
628
|
+
*
|
|
629
|
+
* @returns True when the bytes in flight plus 1200 bytes fit the congestion window.
|
|
484
630
|
*/
|
|
485
631
|
canSend(): boolean {
|
|
486
632
|
return this.bytesInFlight() + QUIC_RECOVERY_DATAGRAM_SIZE <= this.congestionWindow
|
|
@@ -492,6 +638,12 @@ export class QuicRecovery {
|
|
|
492
638
|
* the caller keeps what it carried, or -1, recording nothing, for a space
|
|
493
639
|
* that does not exist, a size that is not positive, a packet number that is
|
|
494
640
|
* not above the last one recorded, or a ring that is full.
|
|
641
|
+
*
|
|
642
|
+
* @param space The space's index, `QUIC_RECOVERY_INITIAL` to `QUIC_RECOVERY_APPLICATION`.
|
|
643
|
+
* @param pn The packet's number: above the last one recorded and at most 2^62 − 1.
|
|
644
|
+
* @param size The packet's size on the wire in bytes; must be positive.
|
|
645
|
+
* @param now The send time, in the caller's milliseconds.
|
|
646
|
+
* @returns The ring slot the packet is recorded in, or -1 when nothing was recorded.
|
|
495
647
|
*/
|
|
496
648
|
onPacketSent(space: i32, pn: i64, size: i32, now: i64): i32 {
|
|
497
649
|
const sp: QuicSentPackets | null = this.space(space)
|
|
@@ -527,6 +679,8 @@ export class QuicRecovery {
|
|
|
527
679
|
* for the first `QUIC_RECOVERY_ECN_TESTING_PACKETS` and, once the path is
|
|
528
680
|
* capable, for every one; 0, Not-ECT, while the testing packets wait to be
|
|
529
681
|
* validated and once validation failed.
|
|
682
|
+
*
|
|
683
|
+
* @returns `QUIC_RECOVERY_ECT0` (2) to mark with, or 0 for Not-ECT.
|
|
530
684
|
*/
|
|
531
685
|
ecnCodepoint(): i32 {
|
|
532
686
|
const testing: boolean =
|
|
@@ -539,6 +693,9 @@ export class QuicRecovery {
|
|
|
539
693
|
* `onPacketSent` answered for it, or -1 for a packet that elicits no
|
|
540
694
|
* acknowledgement and so was not recorded. Every packet of a datagram
|
|
541
695
|
* marked counts, whatever `ecnCodepoint()` answers by the last of them.
|
|
696
|
+
*
|
|
697
|
+
* @param space The space's index, `QUIC_RECOVERY_INITIAL` to `QUIC_RECOVERY_APPLICATION`.
|
|
698
|
+
* @param slot The slot `onPacketSent` answered for the packet, or -1 when it was not recorded.
|
|
542
699
|
*/
|
|
543
700
|
onEctSent(space: i32, slot: i32): void {
|
|
544
701
|
const sp: QuicSentPackets | null = this.space(space)
|
|
@@ -573,6 +730,14 @@ export class QuicRecovery {
|
|
|
573
730
|
* exist or there is no range. A packet number the space never sent is the
|
|
574
731
|
* caller's to refuse (RFC 9000 §13.1): only it knows the packets that
|
|
575
732
|
* elicit no acknowledgement, which are not recorded here.
|
|
733
|
+
*
|
|
734
|
+
* @param space The space's index, `QUIC_RECOVERY_INITIAL` to `QUIC_RECOVERY_APPLICATION`.
|
|
735
|
+
* @param ranges The acknowledged packet numbers, as `[smallest, largest]` pairs, highest first; only read.
|
|
736
|
+
* @param count How many pairs of `ranges` to read; past the array's length the rest are ignored.
|
|
737
|
+
* @param ackDelay The peer's ACK Delay, already scaled, in milliseconds.
|
|
738
|
+
* @param now The time the ACK arrived, in the caller's milliseconds.
|
|
739
|
+
* @returns How many recorded packets were newly acknowledged, or -1 when the space or the ranges are
|
|
740
|
+
* missing.
|
|
576
741
|
*/
|
|
577
742
|
onAck(space: i32, ranges: i64[], count: i32, ackDelay: i64, now: i64): i32 {
|
|
578
743
|
const none: i64 = -1
|
|
@@ -585,6 +750,17 @@ export class QuicRecovery {
|
|
|
585
750
|
* carries none. The counts are validated (RFC 9000 §13.4.2.1) and a rise
|
|
586
751
|
* in ECN-CE is a congestion event (§7.1, B.7) before loss is detected, as
|
|
587
752
|
* A.7 orders it.
|
|
753
|
+
*
|
|
754
|
+
* @param space The space's index, `QUIC_RECOVERY_INITIAL` to `QUIC_RECOVERY_APPLICATION`.
|
|
755
|
+
* @param ranges The acknowledged packet numbers, as `[smallest, largest]` pairs, highest first; only read.
|
|
756
|
+
* @param count How many pairs of `ranges` to read; past the array's length the rest are ignored.
|
|
757
|
+
* @param ackDelay The peer's ACK Delay, already scaled, in milliseconds.
|
|
758
|
+
* @param now The time the ACK arrived, in the caller's milliseconds.
|
|
759
|
+
* @param ect0 The frame's ECT(0) count, or -1 for an ACK without counts.
|
|
760
|
+
* @param ect1 The frame's ECT(1) count, or -1 for an ACK without counts.
|
|
761
|
+
* @param ce The frame's ECN-CE count, or -1 for an ACK without counts.
|
|
762
|
+
* @returns How many recorded packets were newly acknowledged, or -1 when the space or the ranges are
|
|
763
|
+
* missing.
|
|
588
764
|
*/
|
|
589
765
|
onAckEcn(
|
|
590
766
|
space: i32,
|
|
@@ -671,7 +847,7 @@ export class QuicRecovery {
|
|
|
671
847
|
* acknowledged it is timed from `later`, a send time no earlier than the
|
|
672
848
|
* largest acknowledged packet's, which recovery did not record.
|
|
673
849
|
*/
|
|
674
|
-
processEcn(
|
|
850
|
+
private processEcn(
|
|
675
851
|
sp: QuicSentPackets,
|
|
676
852
|
raised: boolean,
|
|
677
853
|
ect0: i64,
|
|
@@ -728,7 +904,7 @@ export class QuicRecovery {
|
|
|
728
904
|
}
|
|
729
905
|
|
|
730
906
|
/** UpdateRtt (§5.3, A.7) with a sample in `latestRtt`, `ackDelay` the peer's delay in milliseconds. */
|
|
731
|
-
updateRtt(ackDelay: i64, now: i64): void {
|
|
907
|
+
private updateRtt(ackDelay: i64, now: i64): void {
|
|
732
908
|
const latest: i64 = this.latestRtt
|
|
733
909
|
if (this.firstSampleTime < 0) {
|
|
734
910
|
this.minRtt = latest
|
|
@@ -752,13 +928,16 @@ export class QuicRecovery {
|
|
|
752
928
|
}
|
|
753
929
|
|
|
754
930
|
/** The peer's ACK delay in milliseconds as §5.3 counts it: at most max_ack_delay once the handshake is confirmed. */
|
|
755
|
-
boundAckDelay(ackDelay: i64): i64 {
|
|
931
|
+
private boundAckDelay(ackDelay: i64): i64 {
|
|
756
932
|
return this.handshakeConfirmed && ackDelay > this.maxAckDelay ? this.maxAckDelay : ackDelay
|
|
757
933
|
}
|
|
758
934
|
|
|
759
935
|
/**
|
|
760
936
|
* `now` on the pacer's clock: `micros` when it falls inside the
|
|
761
937
|
* millisecond `now` names, and `now × 1000` otherwise.
|
|
938
|
+
*
|
|
939
|
+
* @param now The caller's time in milliseconds.
|
|
940
|
+
* @returns The same instant in microseconds.
|
|
762
941
|
*/
|
|
763
942
|
fineNow(now: i64): i64 {
|
|
764
943
|
const coarse: i64 = now * QUIC_RECOVERY_MICROS
|
|
@@ -774,7 +953,7 @@ export class QuicRecovery {
|
|
|
774
953
|
* runs long by up to a millisecond: only a carrier that calls `clock` on
|
|
775
954
|
* some sends and not others sees that.
|
|
776
955
|
*/
|
|
777
|
-
fineSample(now: i64, sent: i64): i64 {
|
|
956
|
+
private fineSample(now: i64, sent: i64): i64 {
|
|
778
957
|
const at: i64 = this.fineNow(now)
|
|
779
958
|
const floor: i64 = at === this.micros ? 1 : QUIC_RECOVERY_GRANULARITY * QUIC_RECOVERY_MICROS
|
|
780
959
|
return quicRecoveryMax(at - sent, floor)
|
|
@@ -787,7 +966,7 @@ export class QuicRecovery {
|
|
|
787
966
|
* true minimum, so a delay is taken off a little more readily than
|
|
788
967
|
* `updateRtt` takes it.
|
|
789
968
|
*/
|
|
790
|
-
updatePacerRtt(sample: i64, ackDelay: i64, first: boolean): void {
|
|
969
|
+
private updatePacerRtt(sample: i64, ackDelay: i64, first: boolean): void {
|
|
791
970
|
if (first) {
|
|
792
971
|
this.pacerRtt = sample
|
|
793
972
|
return
|
|
@@ -800,7 +979,11 @@ export class QuicRecovery {
|
|
|
800
979
|
this.pacerRtt = (7 * this.pacerRtt + adjusted) / 8
|
|
801
980
|
}
|
|
802
981
|
|
|
803
|
-
/**
|
|
982
|
+
/**
|
|
983
|
+
* The loss delay (§6.1.2): 9/8 of the larger of the latest and the smoothed RTT, at least the granularity.
|
|
984
|
+
*
|
|
985
|
+
* @returns How long after a packet was sent it is lost by the time threshold, in milliseconds, at least 1.
|
|
986
|
+
*/
|
|
804
987
|
lossDelay(): i64 {
|
|
805
988
|
const delay: i64 = (9 * quicRecoveryMax(this.latestRtt, this.smoothedRtt)) / 8
|
|
806
989
|
return quicRecoveryMax(delay, QUIC_RECOVERY_GRANULARITY)
|
|
@@ -812,7 +995,7 @@ export class QuicRecovery {
|
|
|
812
995
|
* three numbers below the largest acknowledged; the first that is neither
|
|
813
996
|
* sets `lossTime`.
|
|
814
997
|
*/
|
|
815
|
-
detectLoss(sp: QuicSentPackets, now: i64): void {
|
|
998
|
+
private detectLoss(sp: QuicSentPackets, now: i64): void {
|
|
816
999
|
sp.lossTime = -1
|
|
817
1000
|
const delay: i64 = this.lossDelay()
|
|
818
1001
|
const lostSendTime: i64 = now - delay
|
|
@@ -841,7 +1024,7 @@ export class QuicRecovery {
|
|
|
841
1024
|
* congestion event for the newest of them, and persistent congestion
|
|
842
1025
|
* when they span long enough.
|
|
843
1026
|
*/
|
|
844
|
-
packetsLost(sp: QuicSentPackets, now: i64): void {
|
|
1027
|
+
private packetsLost(sp: QuicSentPackets, now: i64): void {
|
|
845
1028
|
if (sp.lostCount === 0) {
|
|
846
1029
|
return
|
|
847
1030
|
}
|
|
@@ -878,7 +1061,7 @@ export class QuicRecovery {
|
|
|
878
1061
|
* spanning more than three probe timeouts with max_ack_delay, and holding
|
|
879
1062
|
* at least one packet this call declared lost.
|
|
880
1063
|
*/
|
|
881
|
-
persistentCongestion(sp: QuicSentPackets): boolean {
|
|
1064
|
+
private persistentCongestion(sp: QuicSentPackets): boolean {
|
|
882
1065
|
if (this.firstSampleTime < 0) {
|
|
883
1066
|
return false
|
|
884
1067
|
}
|
|
@@ -909,12 +1092,12 @@ export class QuicRecovery {
|
|
|
909
1092
|
}
|
|
910
1093
|
|
|
911
1094
|
/** Whether a packet sent at `sentTime` was sent during the current recovery period (B.4). */
|
|
912
|
-
inRecovery(sentTime: i64): boolean {
|
|
1095
|
+
private inRecovery(sentTime: i64): boolean {
|
|
913
1096
|
return this.recoveryStart >= 0 && sentTime <= this.recoveryStart
|
|
914
1097
|
}
|
|
915
1098
|
|
|
916
1099
|
/** OnCongestionEvent (B.6): halve the window, once per recovery period. */
|
|
917
|
-
congestionEvent(sentTime: i64, now: i64): void {
|
|
1100
|
+
private congestionEvent(sentTime: i64, now: i64): void {
|
|
918
1101
|
if (this.inRecovery(sentTime)) {
|
|
919
1102
|
return
|
|
920
1103
|
}
|
|
@@ -930,7 +1113,7 @@ export class QuicRecovery {
|
|
|
930
1113
|
* all for a packet sent during recovery, or when `inUse` says the window
|
|
931
1114
|
* was not being used (§7.8).
|
|
932
1115
|
*/
|
|
933
|
-
packetAcked(sp: QuicSentPackets, s: i32, inUse: boolean): void {
|
|
1116
|
+
private packetAcked(sp: QuicSentPackets, s: i32, inUse: boolean): void {
|
|
934
1117
|
if (!inUse || this.inRecovery(sp.timeAt(s))) {
|
|
935
1118
|
return
|
|
936
1119
|
}
|
|
@@ -948,6 +1131,8 @@ export class QuicRecovery {
|
|
|
948
1131
|
* max(4 × rttvar, kGranularity), plus the peer's max_ack_delay once the
|
|
949
1132
|
* handshake is confirmed. It is also what a key update's old keys are kept
|
|
950
1133
|
* for and what the idle timeout is at least three of.
|
|
1134
|
+
*
|
|
1135
|
+
* @returns The period in milliseconds, at least 1.
|
|
951
1136
|
*/
|
|
952
1137
|
probeTimeout(): i64 {
|
|
953
1138
|
const base: i64 = this.ptoBase()
|
|
@@ -955,7 +1140,7 @@ export class QuicRecovery {
|
|
|
955
1140
|
}
|
|
956
1141
|
|
|
957
1142
|
/** smoothed_rtt + max(4 × rttvar, kGranularity): every probe timeout's period before max_ack_delay and the backoff. */
|
|
958
|
-
ptoBase(): i64 {
|
|
1143
|
+
private ptoBase(): i64 {
|
|
959
1144
|
return this.smoothedRtt + quicRecoveryMax(4 * this.rttVar, QUIC_RECOVERY_GRANULARITY)
|
|
960
1145
|
}
|
|
961
1146
|
|
|
@@ -963,8 +1148,9 @@ export class QuicRecovery {
|
|
|
963
1148
|
* GetPtoTimeAndSpace (A.8): when the probe timeout fires, the earliest
|
|
964
1149
|
* over the spaces with an ack-eliciting packet in flight, with the backoff
|
|
965
1150
|
* applied; the Application Data space counts only once the handshake is
|
|
966
|
-
* confirmed. Answers -1 with nothing in flight.
|
|
967
|
-
*
|
|
1151
|
+
* confirmed. Answers -1 with nothing in flight.
|
|
1152
|
+
*
|
|
1153
|
+
* @returns The time the probe timeout fires, in the caller's milliseconds, or -1 when no space has one.
|
|
968
1154
|
*/
|
|
969
1155
|
ptoTime(): i64 {
|
|
970
1156
|
const space: i32 = this.ptoSpace()
|
|
@@ -975,7 +1161,7 @@ export class QuicRecovery {
|
|
|
975
1161
|
}
|
|
976
1162
|
|
|
977
1163
|
/** The probe timeout of space `space`, from its last ack-eliciting packet, with the backoff. */
|
|
978
|
-
ptoTimeOf(space: i32): i64 {
|
|
1164
|
+
private ptoTimeOf(space: i32): i64 {
|
|
979
1165
|
const sp: QuicSentPackets | null = this.space(space)
|
|
980
1166
|
if (sp === null || sp.lastAckEliciting < 0) {
|
|
981
1167
|
return -1
|
|
@@ -989,7 +1175,7 @@ export class QuicRecovery {
|
|
|
989
1175
|
}
|
|
990
1176
|
|
|
991
1177
|
/** The space whose probe timeout fires first, or -1 when no space may have one. */
|
|
992
|
-
ptoSpace(): i32 {
|
|
1178
|
+
private ptoSpace(): i32 {
|
|
993
1179
|
let best: i32 = -1
|
|
994
1180
|
let bestTime: i64 = -1
|
|
995
1181
|
for (let space: i32 = 0; space < toI32(this.spaces.length); space += 1) {
|
|
@@ -1007,7 +1193,7 @@ export class QuicRecovery {
|
|
|
1007
1193
|
}
|
|
1008
1194
|
|
|
1009
1195
|
/** The space with the earliest `lossTime`, or -1 when none is set. */
|
|
1010
|
-
lossSpace(): i32 {
|
|
1196
|
+
private lossSpace(): i32 {
|
|
1011
1197
|
let best: i32 = -1
|
|
1012
1198
|
let bestTime: i64 = -1
|
|
1013
1199
|
for (let space: i32 = 0; space < toI32(this.spaces.length); space += 1) {
|
|
@@ -1025,6 +1211,9 @@ export class QuicRecovery {
|
|
|
1025
1211
|
* time-threshold loss, else the probe timeout — or -1 for none. With
|
|
1026
1212
|
* `amplificationBlocked`, when the server may send nothing until the client
|
|
1027
1213
|
* does (RFC 9000 §8.1), there is no probe timeout (§6.2.2.1).
|
|
1214
|
+
*
|
|
1215
|
+
* @param amplificationBlocked Whether the anti-amplification limit stops the server sending anything now.
|
|
1216
|
+
* @returns The time `onTimeout` is next due, in the caller's milliseconds, or -1 when no timer is set.
|
|
1028
1217
|
*/
|
|
1029
1218
|
deadline(amplificationBlocked: boolean): i64 {
|
|
1030
1219
|
const loss: i32 = this.lossSpace()
|
|
@@ -1044,6 +1233,11 @@ export class QuicRecovery {
|
|
|
1044
1233
|
* timeout is due, the backoff doubles and the caller is to send a probe in
|
|
1045
1234
|
* `timeoutSpace`: `QUIC_RECOVERY_TIMEOUT_PTO`. Before either is due, or
|
|
1046
1235
|
* when nothing is timed, `QUIC_RECOVERY_TIMEOUT_NONE`.
|
|
1236
|
+
*
|
|
1237
|
+
* @param now The caller's time in milliseconds.
|
|
1238
|
+
* @param amplificationBlocked Whether the anti-amplification limit stops the server sending anything now.
|
|
1239
|
+
* @returns One of `QUIC_RECOVERY_TIMEOUT_NONE`, `QUIC_RECOVERY_TIMEOUT_LOSS` or
|
|
1240
|
+
* `QUIC_RECOVERY_TIMEOUT_PTO`.
|
|
1047
1241
|
*/
|
|
1048
1242
|
onTimeout(now: i64, amplificationBlocked: boolean): i32 {
|
|
1049
1243
|
for (const sp of this.spaces) {
|
|
@@ -1076,6 +1270,9 @@ export class QuicRecovery {
|
|
|
1076
1270
|
* when the ring is full. The caller has already queued what the space had
|
|
1077
1271
|
* in flight again, which is what a probe sends. Answers the slot, or -1
|
|
1078
1272
|
* when nothing is in flight there.
|
|
1273
|
+
*
|
|
1274
|
+
* @param space The space's index, `QUIC_RECOVERY_INITIAL` to `QUIC_RECOVERY_APPLICATION`.
|
|
1275
|
+
* @returns The slot of the packet given up, now settled as lost, or -1 when nothing is in flight there.
|
|
1079
1276
|
*/
|
|
1080
1277
|
evictOldest(space: i32): i32 {
|
|
1081
1278
|
const sp: QuicSentPackets | null = this.space(space)
|
|
@@ -1096,6 +1293,8 @@ export class QuicRecovery {
|
|
|
1096
1293
|
/**
|
|
1097
1294
|
* OnPacketNumberSpaceDiscarded (A.11): the space's keys are gone, so its
|
|
1098
1295
|
* packets leave flight uncounted, its timers stop, and the backoff resets.
|
|
1296
|
+
*
|
|
1297
|
+
* @param space The space's index, `QUIC_RECOVERY_INITIAL` to `QUIC_RECOVERY_APPLICATION`.
|
|
1099
1298
|
*/
|
|
1100
1299
|
discardSpace(space: i32): void {
|
|
1101
1300
|
const sp: QuicSentPackets | null = this.space(space)
|
|
@@ -1107,7 +1306,7 @@ export class QuicRecovery {
|
|
|
1107
1306
|
}
|
|
1108
1307
|
|
|
1109
1308
|
/** The congestion window the pacer earns by: at most `QUIC_RECOVERY_PACER_WINDOW`. */
|
|
1110
|
-
pacerWindow(): i64 {
|
|
1309
|
+
private pacerWindow(): i64 {
|
|
1111
1310
|
return this.congestionWindow < QUIC_RECOVERY_PACER_WINDOW
|
|
1112
1311
|
? this.congestionWindow
|
|
1113
1312
|
: QUIC_RECOVERY_PACER_WINDOW
|
|
@@ -1118,7 +1317,7 @@ export class QuicRecovery {
|
|
|
1118
1317
|
* window per `pacerRtt`, and holds at most the initial window, which is the
|
|
1119
1318
|
* largest burst it allows.
|
|
1120
1319
|
*/
|
|
1121
|
-
pacerRefill(now: i64): void {
|
|
1320
|
+
private pacerRefill(now: i64): void {
|
|
1122
1321
|
const at: i64 = this.fineNow(now)
|
|
1123
1322
|
if (this.pacerTime < 0 || at < this.pacerTime) {
|
|
1124
1323
|
this.pacerTime = at
|
|
@@ -1143,6 +1342,10 @@ export class QuicRecovery {
|
|
|
1143
1342
|
* bytes go: 0 when it may go now, else its wait in microseconds rounded
|
|
1144
1343
|
* up to whole milliseconds, so at least 1. The rate is 5/4 of the window per `pacerRtt`
|
|
1145
1344
|
* (§7.7's N of 1.25).
|
|
1345
|
+
*
|
|
1346
|
+
* @param now The caller's time in milliseconds; the pacer reads `micros` too when it is current.
|
|
1347
|
+
* @param size The datagram's size in bytes.
|
|
1348
|
+
* @returns The wait in whole milliseconds: 0 to send now, else at least 1.
|
|
1146
1349
|
*/
|
|
1147
1350
|
pacerDelay(now: i64, size: i32): i64 {
|
|
1148
1351
|
this.pacerRefill(now)
|
|
@@ -1162,6 +1365,10 @@ export class QuicRecovery {
|
|
|
1162
1365
|
* pacer that earns by the microsecond would otherwise let a fast
|
|
1163
1366
|
* connection out a datagram at a time, one send each; one that earns
|
|
1164
1367
|
* slowly still lets a datagram go as soon as it has the credit for it.
|
|
1368
|
+
*
|
|
1369
|
+
* @param least The smallest quantum, in bytes, such as one full datagram.
|
|
1370
|
+
* @param most The largest quantum, in bytes, such as `QUIC_LISTENER_FLIGHT_QUANTUM`.
|
|
1371
|
+
* @returns The bytes the pacer earns in a millisecond, held to `least` and `most`.
|
|
1165
1372
|
*/
|
|
1166
1373
|
pacerQuantum(least: i32, most: i32): i32 {
|
|
1167
1374
|
const rtt: i64 = quicRecoveryMax(this.pacerRtt, 1)
|
|
@@ -1172,7 +1379,12 @@ export class QuicRecovery {
|
|
|
1172
1379
|
return milli > toI64(most) ? most : toI32(milli)
|
|
1173
1380
|
}
|
|
1174
1381
|
|
|
1175
|
-
/**
|
|
1382
|
+
/**
|
|
1383
|
+
* Charges the pacer for a datagram of `size` bytes sent at `now`.
|
|
1384
|
+
*
|
|
1385
|
+
* @param now The send time in the caller's milliseconds; the pacer is topped up to it first.
|
|
1386
|
+
* @param size The datagram's size in bytes, which may take the credit below 0.
|
|
1387
|
+
*/
|
|
1176
1388
|
onPaced(now: i64, size: i32): void {
|
|
1177
1389
|
this.pacerRefill(now)
|
|
1178
1390
|
this.pacerBudget = this.pacerBudget - toI64(size)
|