@amritk/nish-aarch64-linux 0.44.0 → 0.46.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 +3 -1
- package/bin/nish +0 -0
- package/docs/AI.md +18 -16
- package/package.json +1 -1
- package/runtime/core/numbers.mjs +3 -1
- package/runtime/core/strings.mjs +90 -38
- package/runtime/core.d.ts +8 -0
- package/runtime/core.mjs +16 -0
- package/runtime/nish.d.ts +88 -5
- package/runtime/nish.h +10 -0
- package/runtime/nish.mjs +5 -0
- package/runtime/runtime-host.c +15 -0
- package/runtime/runtime-net.c +223 -4
- package/runtime/runtime-os.c +15 -1
- package/runtime/runtime-uring.c +291 -31
- package/runtime/sqlite/nish-sqlite.c +301 -128
- package/std/README.md +15 -15
- package/std/array.ts +10 -2
- package/std/bytes.ts +239 -26
- package/std/cli-args.ts +1072 -606
- package/std/cli-flags.ts +180 -98
- package/std/cli.ts +21 -13
- package/std/collections.ts +245 -127
- package/std/compress/checksum.ts +32 -37
- package/std/compress/deflate.ts +1102 -542
- package/std/compress/gzip.ts +290 -145
- package/std/compress/zlib.ts +57 -21
- package/std/crypto/aes.ts +153 -75
- package/std/crypto/base64url.ts +84 -61
- package/std/crypto/bcrypt-batch.ts +164 -90
- package/std/crypto/bcrypt.ts +185 -107
- package/std/crypto/chacha20poly1305.ts +84 -68
- package/std/crypto/ct.ts +9 -7
- package/std/crypto/ed25519.ts +64 -27
- package/std/crypto/hkdf.ts +105 -63
- package/std/crypto/hmac.ts +95 -89
- package/std/crypto/jwt.ts +248 -126
- package/std/crypto/p256.ts +758 -444
- package/std/crypto/p384.ts +20 -13
- package/std/crypto/pki-roots.ts +95 -38
- package/std/crypto/pki.ts +164 -60
- package/std/crypto/rsa.ts +266 -223
- package/std/crypto/scram.ts +3 -4
- package/std/crypto/sha1.ts +107 -65
- package/std/crypto/sha256.ts +502 -422
- package/std/crypto/sha512.ts +204 -135
- package/std/crypto/x509-random.ts +9 -3
- package/std/crypto/x509.ts +331 -171
- package/std/json-equal.ts +35 -19
- package/std/json-format.ts +215 -108
- package/std/json-number.ts +126 -72
- package/std/json-pointer.ts +42 -13
- package/std/json-tokenizer.ts +498 -307
- package/std/json-typed.ts +115 -36
- package/std/json-value.ts +341 -152
- package/std/json.ts +300 -158
- package/std/net/buffer-pool.ts +17 -7
- package/std/net/dns-config.ts +427 -236
- package/std/net/dns-message.ts +114 -47
- package/std/net/dns-resolver.ts +736 -237
- package/std/net/dns.ts +205 -52
- package/std/net/fetch.ts +320 -184
- package/std/net/grpc.ts +948 -0
- package/std/net/handler.ts +1315 -222
- package/std/net/hpack.ts +395 -180
- package/std/net/http-compress.ts +502 -65
- package/std/net/http-fields.ts +85 -49
- package/std/net/http-server.ts +1764 -602
- package/std/net/http1-client-codec.ts +372 -161
- package/std/net/http1-codec.ts +665 -331
- package/std/net/http1-server.ts +660 -278
- package/std/net/http2-cleartext.ts +165 -95
- package/std/net/http2-frame.ts +232 -89
- package/std/net/http2-tls.ts +42 -12
- package/std/net/http2.ts +327 -101
- package/std/net/http3-frame.ts +68 -33
- package/std/net/http3-server.ts +647 -192
- package/std/net/http3.ts +667 -189
- package/std/net/oidc.ts +63 -24
- package/std/net/outbound.ts +207 -142
- package/std/net/postgres-async.ts +1165 -443
- package/std/net/postgres-carrier.ts +575 -372
- package/std/net/postgres.ts +1459 -559
- package/std/net/prefork.ts +254 -98
- package/std/net/protobuf.ts +1017 -0
- package/std/net/qpack.ts +143 -92
- package/std/net/quic-conn-ack.ts +50 -18
- package/std/net/quic-conn-cid.ts +66 -26
- package/std/net/quic-conn-params.ts +13 -7
- package/std/net/quic-datagram.ts +90 -27
- package/std/net/quic-frame.ts +225 -124
- package/std/net/quic-listener.ts +197 -89
- package/std/net/quic-packet.ts +289 -163
- package/std/net/quic-recovery.ts +279 -128
- package/std/net/quic-stream.ts +466 -167
- package/std/net/quic.ts +568 -257
- package/std/net/router.ts +450 -99
- package/std/net/serve.ts +651 -232
- package/std/net/static.ts +1458 -0
- package/std/net/tls/client.ts +140 -45
- package/std/net/tls/codec.ts +510 -260
- package/std/net/tls/record-client.ts +268 -76
- package/std/net/tls/record-server.ts +236 -79
- package/std/net/tls/record.ts +173 -47
- package/std/net/tls/schedule.ts +58 -39
- package/std/net/tls/ticket.ts +295 -103
- package/std/net/tls/verify.ts +1 -1
- package/std/net/tls-tcp.ts +218 -75
- package/std/net/tls.ts +260 -152
- package/std/net/upstream.ts +283 -86
- package/std/net/url.ts +277 -102
- package/std/net/websocket.ts +370 -186
- package/std/net/webtransport.ts +755 -436
- package/std/regex.ts +1659 -829
- package/std/sqlite.ts +171 -0
- package/std/sync/ring.ts +320 -156
- package/std/sync/shm.ts +53 -6
- package/std/text.ts +205 -124
- package/std/threads.ts +22 -2
package/std/net/quic-recovery.ts
CHANGED
|
@@ -224,6 +224,59 @@ const QUIC_RECOVERY_CUBIC_SCALE: i64 = 5000000000
|
|
|
224
224
|
/** The larger of two times or durations. */
|
|
225
225
|
const quicRecoveryMax = (a: i64, b: i64): i64 => (a > b ? a : b)
|
|
226
226
|
|
|
227
|
+
/** 2^63 − 1, the largest `i64`, which a sum or product past it is held at. */
|
|
228
|
+
const quicRecoveryTop = (): i64 => toI64((toU64(1) << toU64(63)) - toU64(1))
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* `a + b`, held at 2^63 − 1 when the true sum is past it and at −2^63 when
|
|
232
|
+
* it is below. Recovery's times, durations and byte counts are far inside
|
|
233
|
+
* an `i64`, so a held sum is one no clock or window reaches: a deadline that
|
|
234
|
+
* never comes, a window nothing fills. Taken in `u64`, whose `+` wraps, and
|
|
235
|
+
* read back as the `i64` with the same bits, which is the true sum whenever
|
|
236
|
+
* that fits.
|
|
237
|
+
*/
|
|
238
|
+
const quicRecoverySum = (a: i64, b: i64): i64 => {
|
|
239
|
+
const sum: i64 = toI64(toU64(a) + toU64(b))
|
|
240
|
+
if (a >= 0 && b >= 0 && sum < 0) {
|
|
241
|
+
return quicRecoveryTop()
|
|
242
|
+
}
|
|
243
|
+
if (a < 0 && b < 0 && sum >= 0) {
|
|
244
|
+
return toI64(toU64(1) << toU64(63))
|
|
245
|
+
}
|
|
246
|
+
return sum
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/** `a − b`, held at 2^63 − 1 / −2^63 where the true difference passes either. */
|
|
250
|
+
const quicRecoveryLess = (a: i64, b: i64): i64 => {
|
|
251
|
+
const diff: i64 = toI64(toU64(a) - toU64(b))
|
|
252
|
+
if (a >= 0 && b < 0 && diff < 0) {
|
|
253
|
+
return quicRecoveryTop()
|
|
254
|
+
}
|
|
255
|
+
if (a < 0 && b >= 0 && diff >= 0) {
|
|
256
|
+
return toI64(toU64(1) << toU64(63))
|
|
257
|
+
}
|
|
258
|
+
return diff
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/** `n + 1` for a counter, held at 2^31 − 1, which no connection's events reach. */
|
|
262
|
+
const quicRecoveryStep = (n: i32): i32 => (n >= 2147483647 ? n : n + 1)
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* `a × b` for two non-negative times, durations or byte counts, held at
|
|
266
|
+
* 2^63 − 1 when the true product is past it, as `quicRecoverySum` holds a
|
|
267
|
+
* sum. Below that it is taken in `u64` and is exact. A negative operand
|
|
268
|
+
* counts as 0: every caller passes values it has kept at 0 or above.
|
|
269
|
+
*/
|
|
270
|
+
const quicRecoveryProduct = (a: i64, b: i64): i64 => {
|
|
271
|
+
if (a <= 0 || b <= 0) {
|
|
272
|
+
return 0
|
|
273
|
+
}
|
|
274
|
+
if (b > quicRecoveryTop() / a) {
|
|
275
|
+
return quicRecoveryTop()
|
|
276
|
+
}
|
|
277
|
+
return toI64(toU64(a) * toU64(b))
|
|
278
|
+
}
|
|
279
|
+
|
|
227
280
|
/** `x` clamped to −`QUIC_RECOVERY_CUBIC_SPAN` .. `QUIC_RECOVERY_CUBIC_SPAN`. */
|
|
228
281
|
const quicRecoveryCubicClamp = (x: i64): i64 => {
|
|
229
282
|
if (x > QUIC_RECOVERY_CUBIC_SPAN) {
|
|
@@ -241,24 +294,27 @@ const quicRecoveryCubicClamp = (x: i64): i64 => {
|
|
|
241
294
|
* @returns Its root, 0 to 40000.
|
|
242
295
|
*/
|
|
243
296
|
export const quicRecoveryCbrt = (x: i64): i64 => {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
297
|
+
if (x <= 0) {
|
|
298
|
+
return 0
|
|
299
|
+
}
|
|
300
|
+
// Unsigned, and exact: every value below is at most the span, 40000, and every cube at most
|
|
301
|
+
// 40000³ = 6.4 × 10¹³, far inside 64 bits.
|
|
302
|
+
const cube: u64 = toU64(x)
|
|
303
|
+
let lo: u64 = 0
|
|
304
|
+
let hi: u64 = toU64(QUIC_RECOVERY_CUBIC_SPAN)
|
|
305
|
+
if (cube >= hi * hi * hi) {
|
|
306
|
+
return QUIC_RECOVERY_CUBIC_SPAN
|
|
251
307
|
}
|
|
252
308
|
// lo³ <= x < hi³ holds at every step.
|
|
253
309
|
while (hi - lo > 1) {
|
|
254
|
-
const mid:
|
|
255
|
-
if (mid * mid * mid <=
|
|
310
|
+
const mid: u64 = (lo + hi) / 2
|
|
311
|
+
if (mid * mid * mid <= cube) {
|
|
256
312
|
lo = mid
|
|
257
313
|
} else {
|
|
258
314
|
hi = mid
|
|
259
315
|
}
|
|
260
316
|
}
|
|
261
|
-
return lo
|
|
317
|
+
return toI64(lo)
|
|
262
318
|
}
|
|
263
319
|
|
|
264
320
|
/**
|
|
@@ -297,7 +353,7 @@ export class QuicSentPackets {
|
|
|
297
353
|
lastAckEliciting: i64 = -1
|
|
298
354
|
/** The bytes of this space's packets in flight. */
|
|
299
355
|
bytesInFlight: i64 = 0
|
|
300
|
-
private capacity:
|
|
356
|
+
private capacity: u8 = 0
|
|
301
357
|
private head: i32 = 0
|
|
302
358
|
/**
|
|
303
359
|
* How many packets the ring keeps, in flight and settled; a test reads it to see what a flight
|
|
@@ -324,9 +380,10 @@ export class QuicSentPackets {
|
|
|
324
380
|
*
|
|
325
381
|
* @param capacity How many sent packets the ring records at once, fixed for its life: in flight and
|
|
326
382
|
* settled alike, until `compact` drops the settled ones. `QUIC_RECOVERY_HANDSHAKE_CAPACITY` or
|
|
327
|
-
* `QUIC_RECOVERY_APPLICATION_CAPACITY`.
|
|
383
|
+
* `QUIC_RECOVERY_APPLICATION_CAPACITY`. A `u8`, so no ring is larger than 255 slots and an
|
|
384
|
+
* index sum of two slots stays far inside `i32`.
|
|
328
385
|
*/
|
|
329
|
-
constructor(capacity:
|
|
386
|
+
constructor(capacity: u8) {
|
|
330
387
|
this.capacity = capacity
|
|
331
388
|
this.pn = new Array<i64>(capacity)
|
|
332
389
|
this.timeSent = new Array<i64>(capacity)
|
|
@@ -342,7 +399,14 @@ export class QuicSentPackets {
|
|
|
342
399
|
* @internal Read by quic.ts, and in quic-recovery.ts outside the class.
|
|
343
400
|
*/
|
|
344
401
|
slot(k: i32): i32 {
|
|
345
|
-
|
|
402
|
+
const capacity: i32 = toI32(this.capacity)
|
|
403
|
+
const head: i32 = this.head
|
|
404
|
+
// Never taken for a `k` below `count`: `head` stays below the capacity, and `count` never passes it.
|
|
405
|
+
if (k < 0 || k >= capacity || head < 0 || head >= capacity) {
|
|
406
|
+
return -1
|
|
407
|
+
}
|
|
408
|
+
const s: i32 = head + k
|
|
409
|
+
return s >= capacity ? s - capacity : s
|
|
346
410
|
}
|
|
347
411
|
|
|
348
412
|
/**
|
|
@@ -497,7 +561,7 @@ export class QuicSentPackets {
|
|
|
497
561
|
*/
|
|
498
562
|
full(): boolean {
|
|
499
563
|
this.compact()
|
|
500
|
-
return this.count >= this.capacity
|
|
564
|
+
return this.count >= toI32(this.capacity)
|
|
501
565
|
}
|
|
502
566
|
|
|
503
567
|
/**
|
|
@@ -505,11 +569,17 @@ export class QuicSentPackets {
|
|
|
505
569
|
* @internal Read by quic.ts, and in quic-recovery.ts outside the class.
|
|
506
570
|
*/
|
|
507
571
|
compact(): void {
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
572
|
+
const capacity: i32 = toI32(this.capacity)
|
|
573
|
+
let count: i32 = this.count
|
|
574
|
+
let head: i32 = this.head
|
|
575
|
+
while (count > 0 && head >= 0 && head < capacity && this.stateAt(head) !== QUIC_RECOVERY_SENT) {
|
|
576
|
+
this.setState(head, QUIC_RECOVERY_FREE)
|
|
577
|
+
const next: i32 = head + 1
|
|
578
|
+
head = next >= capacity ? 0 : next
|
|
579
|
+
count = count - 1
|
|
580
|
+
}
|
|
581
|
+
this.head = head
|
|
582
|
+
this.count = count
|
|
513
583
|
if (this.count === 0) {
|
|
514
584
|
this.head = 0
|
|
515
585
|
}
|
|
@@ -529,9 +599,18 @@ export class QuicSentPackets {
|
|
|
529
599
|
* @internal Read in quic-recovery.ts outside the class.
|
|
530
600
|
*/
|
|
531
601
|
settle(s: i32, state: i32): void {
|
|
602
|
+
const size: i64 = toI64(this.sizeAt(s))
|
|
532
603
|
this.setState(s, state)
|
|
533
|
-
|
|
534
|
-
|
|
604
|
+
// Both guards hold for a packet in flight, the only kind a caller settles: it is counted in
|
|
605
|
+
// `inFlight` and its size in `bytesInFlight`.
|
|
606
|
+
const inFlight: i32 = this.inFlight
|
|
607
|
+
if (inFlight > 0) {
|
|
608
|
+
this.inFlight = inFlight - 1
|
|
609
|
+
}
|
|
610
|
+
const bytes: i64 = this.bytesInFlight
|
|
611
|
+
if (bytes >= 0 && size >= 0) {
|
|
612
|
+
this.bytesInFlight = bytes - size
|
|
613
|
+
}
|
|
535
614
|
}
|
|
536
615
|
|
|
537
616
|
/**
|
|
@@ -540,9 +619,11 @@ export class QuicSentPackets {
|
|
|
540
619
|
*/
|
|
541
620
|
markLost(s: i32): void {
|
|
542
621
|
this.settle(s, QUIC_RECOVERY_LOST_NOW)
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
622
|
+
const lost: i32[] = this.lost
|
|
623
|
+
const n: i32 = this.lostCount
|
|
624
|
+
if (n >= 0 && n < toI32(lost.length)) {
|
|
625
|
+
lost[n] = s
|
|
626
|
+
this.lostCount = n + 1
|
|
546
627
|
}
|
|
547
628
|
}
|
|
548
629
|
|
|
@@ -580,15 +661,19 @@ export class QuicSentPackets {
|
|
|
580
661
|
|
|
581
662
|
/** Whether `pn` falls in one of the first `count` `[smallest, largest]` pairs of `ranges`. */
|
|
582
663
|
const quicRecoveryInRanges = (ranges: i64[], count: i32, pn: i64): boolean => {
|
|
583
|
-
|
|
584
|
-
|
|
664
|
+
const n: i32 = toI32(ranges.length)
|
|
665
|
+
let left: i32 = count
|
|
666
|
+
let low: i32 = 0
|
|
667
|
+
while (left > 0 && low >= 0 && low < n) {
|
|
585
668
|
const high: i32 = low + 1
|
|
586
|
-
if (
|
|
669
|
+
if (high >= n) {
|
|
587
670
|
return false
|
|
588
671
|
}
|
|
589
672
|
if (pn >= ranges[low] && pn <= ranges[high]) {
|
|
590
673
|
return true
|
|
591
674
|
}
|
|
675
|
+
low = high + 1
|
|
676
|
+
left = left - 1
|
|
592
677
|
}
|
|
593
678
|
return false
|
|
594
679
|
}
|
|
@@ -707,9 +792,9 @@ export class QuicRecovery {
|
|
|
707
792
|
*/
|
|
708
793
|
constructor() {
|
|
709
794
|
this.spaces = [
|
|
710
|
-
new QuicSentPackets(QUIC_RECOVERY_HANDSHAKE_CAPACITY),
|
|
711
|
-
new QuicSentPackets(QUIC_RECOVERY_HANDSHAKE_CAPACITY),
|
|
712
|
-
new QuicSentPackets(QUIC_RECOVERY_APPLICATION_CAPACITY),
|
|
795
|
+
new QuicSentPackets(toU8(QUIC_RECOVERY_HANDSHAKE_CAPACITY)),
|
|
796
|
+
new QuicSentPackets(toU8(QUIC_RECOVERY_HANDSHAKE_CAPACITY)),
|
|
797
|
+
new QuicSentPackets(toU8(QUIC_RECOVERY_APPLICATION_CAPACITY)),
|
|
713
798
|
]
|
|
714
799
|
this.reset()
|
|
715
800
|
}
|
|
@@ -773,8 +858,8 @@ export class QuicRecovery {
|
|
|
773
858
|
* @returns The initial window in bytes: 12000 at 1200 bytes.
|
|
774
859
|
*/
|
|
775
860
|
initialWindow(): i64 {
|
|
776
|
-
const ten: i64 = 10
|
|
777
|
-
const floor: i64 = quicRecoveryMax(14720, 2
|
|
861
|
+
const ten: i64 = quicRecoveryProduct(10, this.datagramSize)
|
|
862
|
+
const floor: i64 = quicRecoveryMax(14720, quicRecoveryProduct(2, this.datagramSize))
|
|
778
863
|
return ten < floor ? ten : floor
|
|
779
864
|
}
|
|
780
865
|
|
|
@@ -784,7 +869,7 @@ export class QuicRecovery {
|
|
|
784
869
|
* @returns The minimum window in bytes: 2400 at 1200 bytes.
|
|
785
870
|
*/
|
|
786
871
|
minimumWindow(): i64 {
|
|
787
|
-
return 2
|
|
872
|
+
return quicRecoveryProduct(2, this.datagramSize)
|
|
788
873
|
}
|
|
789
874
|
|
|
790
875
|
/**
|
|
@@ -853,7 +938,7 @@ export class QuicRecovery {
|
|
|
853
938
|
bytesInFlight(): i64 {
|
|
854
939
|
let total: i64 = 0
|
|
855
940
|
for (const sp of this.spaces) {
|
|
856
|
-
total = total
|
|
941
|
+
total = quicRecoverySum(total, sp.bytesInFlight)
|
|
857
942
|
}
|
|
858
943
|
return total
|
|
859
944
|
}
|
|
@@ -865,7 +950,7 @@ export class QuicRecovery {
|
|
|
865
950
|
* @returns True when the bytes in flight plus `datagramSize` bytes fit the congestion window.
|
|
866
951
|
*/
|
|
867
952
|
canSend(): boolean {
|
|
868
|
-
return this.bytesInFlight()
|
|
953
|
+
return quicRecoverySum(this.bytesInFlight(), this.datagramSize) <= this.congestionWindow
|
|
869
954
|
}
|
|
870
955
|
|
|
871
956
|
/**
|
|
@@ -886,26 +971,38 @@ export class QuicRecovery {
|
|
|
886
971
|
if (sp === null || size <= 0 || pn <= sp.lastPn || pn > QUIC_MAX_VARINT || sp.full()) {
|
|
887
972
|
return -1
|
|
888
973
|
}
|
|
889
|
-
const
|
|
974
|
+
const count: i32 = sp.count
|
|
975
|
+
const inFlight: i32 = sp.inFlight
|
|
976
|
+
const s: i32 = sp.slot(count)
|
|
977
|
+
const pns: i64[] = sp.pn
|
|
978
|
+
const times: i64[] = sp.timeSent
|
|
979
|
+
const fines: i64[] = sp.fineSent
|
|
980
|
+
const sizes: i32[] = sp.size
|
|
981
|
+
// Never taken: `full()` answered false, so the ring has a free slot, and
|
|
982
|
+
// every array is the ring's capacity long, which neither count reaches.
|
|
890
983
|
if (
|
|
891
984
|
s < 0 ||
|
|
892
|
-
s >= toI32(
|
|
893
|
-
s >= toI32(
|
|
894
|
-
s >= toI32(
|
|
895
|
-
s >= toI32(
|
|
985
|
+
s >= toI32(pns.length) ||
|
|
986
|
+
s >= toI32(times.length) ||
|
|
987
|
+
s >= toI32(fines.length) ||
|
|
988
|
+
s >= toI32(sizes.length) ||
|
|
989
|
+
count < 0 ||
|
|
990
|
+
count >= toI32(pns.length) ||
|
|
991
|
+
inFlight < 0 ||
|
|
992
|
+
inFlight >= toI32(pns.length)
|
|
896
993
|
) {
|
|
897
994
|
return -1
|
|
898
995
|
}
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
996
|
+
pns[s] = pn
|
|
997
|
+
times[s] = now
|
|
998
|
+
fines[s] = this.fineNow(now)
|
|
999
|
+
sizes[s] = size
|
|
903
1000
|
sp.setMarked(s, false)
|
|
904
1001
|
sp.setProbe(s, false)
|
|
905
1002
|
sp.setState(s, QUIC_RECOVERY_SENT)
|
|
906
|
-
sp.count =
|
|
907
|
-
sp.inFlight =
|
|
908
|
-
sp.bytesInFlight = sp.bytesInFlight
|
|
1003
|
+
sp.count = count + 1
|
|
1004
|
+
sp.inFlight = inFlight + 1
|
|
1005
|
+
sp.bytesInFlight = quicRecoverySum(sp.bytesInFlight, toI64(size))
|
|
909
1006
|
sp.lastPn = pn
|
|
910
1007
|
sp.lastAckEliciting = now
|
|
911
1008
|
return s
|
|
@@ -955,15 +1052,15 @@ export class QuicRecovery {
|
|
|
955
1052
|
if (sp === null) {
|
|
956
1053
|
return
|
|
957
1054
|
}
|
|
958
|
-
sp.ectSent = sp.ectSent
|
|
1055
|
+
sp.ectSent = quicRecoverySum(sp.ectSent, 1)
|
|
959
1056
|
const recorded: boolean = sp.inFlightAt(slot) && !sp.markedAt(slot)
|
|
960
1057
|
if (recorded) {
|
|
961
1058
|
sp.setMarked(slot, true)
|
|
962
1059
|
}
|
|
963
1060
|
if (this.ecnState === QUIC_RECOVERY_ECN_TESTING || this.ecnState === QUIC_RECOVERY_ECN_UNKNOWN) {
|
|
964
|
-
this.ecnTestSent = this.ecnTestSent
|
|
1061
|
+
this.ecnTestSent = quicRecoveryStep(this.ecnTestSent)
|
|
965
1062
|
if (recorded) {
|
|
966
|
-
this.ecnTestRecorded = this.ecnTestRecorded
|
|
1063
|
+
this.ecnTestRecorded = quicRecoveryStep(this.ecnTestRecorded)
|
|
967
1064
|
}
|
|
968
1065
|
if (this.ecnTestSent >= QUIC_RECOVERY_ECN_TESTING_PACKETS) {
|
|
969
1066
|
this.ecnState = QUIC_RECOVERY_ECN_UNKNOWN
|
|
@@ -1038,7 +1135,7 @@ export class QuicRecovery {
|
|
|
1038
1135
|
}
|
|
1039
1136
|
// The bytes in flight before this ACK decide whether the window was in
|
|
1040
1137
|
// use, and so whether it may grow (§7.8).
|
|
1041
|
-
const inUse: boolean = this.bytesInFlight()
|
|
1138
|
+
const inUse: boolean = quicRecoveryProduct(this.bytesInFlight(), 2) >= this.congestionWindow
|
|
1042
1139
|
let sampleAt: i32 = -1
|
|
1043
1140
|
// The send time of the first recorded packet past the largest acknowledged, or `now`: no earlier than the largest's own.
|
|
1044
1141
|
let later: i64 = now
|
|
@@ -1051,9 +1148,11 @@ export class QuicRecovery {
|
|
|
1051
1148
|
}
|
|
1052
1149
|
if (sp.stateAt(s) === QUIC_RECOVERY_SENT && quicRecoveryInRanges(ranges, count, sp.pnAt(s))) {
|
|
1053
1150
|
sp.settle(s, QUIC_RECOVERY_ACKED)
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1151
|
+
const acked: i32[] = sp.acked
|
|
1152
|
+
const n: i32 = sp.ackedCount
|
|
1153
|
+
if (n >= 0 && n < toI32(acked.length)) {
|
|
1154
|
+
acked[n] = s
|
|
1155
|
+
sp.ackedCount = n + 1
|
|
1057
1156
|
}
|
|
1058
1157
|
if (sp.pnAt(s) === largest) {
|
|
1059
1158
|
sampleAt = s
|
|
@@ -1070,7 +1169,7 @@ export class QuicRecovery {
|
|
|
1070
1169
|
return 0
|
|
1071
1170
|
}
|
|
1072
1171
|
if (sampleAt >= 0) {
|
|
1073
|
-
this.latestRtt = quicRecoveryMax(now
|
|
1172
|
+
this.latestRtt = quicRecoveryMax(quicRecoveryLess(now, sp.timeAt(sampleAt)), 0)
|
|
1074
1173
|
// §5.3: the Initial space's ACKs are not delayed by the peer, so their delay is ignored.
|
|
1075
1174
|
const none: i64 = 0
|
|
1076
1175
|
const delay: i64 = space === QUIC_RECOVERY_INITIAL ? none : quicRecoveryMax(ackDelay, none)
|
|
@@ -1115,7 +1214,7 @@ export class QuicRecovery {
|
|
|
1115
1214
|
let marked: i64 = 0
|
|
1116
1215
|
for (let k: i32 = 0; k < sp.ackedCount; k += 1) {
|
|
1117
1216
|
if (sp.markedAt(sp.ackedSlot(k))) {
|
|
1118
|
-
marked = marked
|
|
1217
|
+
marked = quicRecoverySum(marked, 1)
|
|
1119
1218
|
}
|
|
1120
1219
|
}
|
|
1121
1220
|
if (ect0 < 0 || ect1 < 0 || ce < 0) {
|
|
@@ -1136,9 +1235,9 @@ export class QuicRecovery {
|
|
|
1136
1235
|
ect1 < sp.ect1 ||
|
|
1137
1236
|
ce < sp.ce ||
|
|
1138
1237
|
ect0 > sent ||
|
|
1139
|
-
ect1 > sent
|
|
1140
|
-
ce > sent
|
|
1141
|
-
ect0
|
|
1238
|
+
ect1 > quicRecoveryLess(sent, ect0) ||
|
|
1239
|
+
ce > quicRecoveryLess(quicRecoveryLess(sent, ect0), ect1) ||
|
|
1240
|
+
quicRecoverySum(quicRecoveryLess(ect0, sp.ect0), quicRecoveryLess(ce, sp.ce)) < marked
|
|
1142
1241
|
) {
|
|
1143
1242
|
this.ecnState = QUIC_RECOVERY_ECN_FAILED
|
|
1144
1243
|
return
|
|
@@ -1152,9 +1251,10 @@ export class QuicRecovery {
|
|
|
1152
1251
|
sp.ce = ce
|
|
1153
1252
|
if (rose) {
|
|
1154
1253
|
const events: i32 = this.congestionEvents
|
|
1155
|
-
|
|
1254
|
+
const n: i32 = sp.ackedCount
|
|
1255
|
+
this.congestionEvent(n > 0 ? sp.timeAt(sp.ackedSlot(n - 1)) : later, now)
|
|
1156
1256
|
if (this.congestionEvents > events) {
|
|
1157
|
-
this.ecnCongestionEvents = this.ecnCongestionEvents
|
|
1257
|
+
this.ecnCongestionEvents = quicRecoveryStep(this.ecnCongestionEvents)
|
|
1158
1258
|
}
|
|
1159
1259
|
}
|
|
1160
1260
|
}
|
|
@@ -1175,12 +1275,14 @@ export class QuicRecovery {
|
|
|
1175
1275
|
const delay: i64 = this.boundAckDelay(ackDelay)
|
|
1176
1276
|
// The delay is taken off only where that leaves the sample at or above min_rtt.
|
|
1177
1277
|
let adjusted: i64 = latest
|
|
1178
|
-
if (latest
|
|
1179
|
-
adjusted = latest
|
|
1278
|
+
if (quicRecoveryLess(latest, this.minRtt) >= delay) {
|
|
1279
|
+
adjusted = quicRecoveryLess(latest, delay)
|
|
1180
1280
|
}
|
|
1181
|
-
const
|
|
1182
|
-
|
|
1183
|
-
|
|
1281
|
+
const smoothed: i64 = this.smoothedRtt
|
|
1282
|
+
const gap: i64 =
|
|
1283
|
+
smoothed > adjusted ? quicRecoveryLess(smoothed, adjusted) : quicRecoveryLess(adjusted, smoothed)
|
|
1284
|
+
this.rttVar = quicRecoverySum(quicRecoveryProduct(3, this.rttVar), gap) / 4
|
|
1285
|
+
this.smoothedRtt = quicRecoverySum(quicRecoveryProduct(7, smoothed), adjusted) / 8
|
|
1184
1286
|
}
|
|
1185
1287
|
|
|
1186
1288
|
/** The peer's ACK delay in milliseconds as §5.3 counts it: at most max_ack_delay once the handshake is confirmed. */
|
|
@@ -1196,8 +1298,10 @@ export class QuicRecovery {
|
|
|
1196
1298
|
* @returns The same instant in microseconds.
|
|
1197
1299
|
*/
|
|
1198
1300
|
fineNow(now: i64): i64 {
|
|
1199
|
-
const coarse: i64 = now
|
|
1200
|
-
return this.micros >= coarse && this.micros < coarse
|
|
1301
|
+
const coarse: i64 = quicRecoveryProduct(now, QUIC_RECOVERY_MICROS)
|
|
1302
|
+
return this.micros >= coarse && this.micros < quicRecoverySum(coarse, QUIC_RECOVERY_MICROS)
|
|
1303
|
+
? this.micros
|
|
1304
|
+
: coarse
|
|
1201
1305
|
}
|
|
1202
1306
|
|
|
1203
1307
|
/**
|
|
@@ -1211,8 +1315,9 @@ export class QuicRecovery {
|
|
|
1211
1315
|
*/
|
|
1212
1316
|
private fineSample(now: i64, sent: i64): i64 {
|
|
1213
1317
|
const at: i64 = this.fineNow(now)
|
|
1214
|
-
const floor: i64 =
|
|
1215
|
-
|
|
1318
|
+
const floor: i64 =
|
|
1319
|
+
at === this.micros ? 1 : quicRecoveryProduct(QUIC_RECOVERY_GRANULARITY, QUIC_RECOVERY_MICROS)
|
|
1320
|
+
return quicRecoveryMax(quicRecoveryLess(at, sent), floor)
|
|
1216
1321
|
}
|
|
1217
1322
|
|
|
1218
1323
|
/**
|
|
@@ -1227,12 +1332,12 @@ export class QuicRecovery {
|
|
|
1227
1332
|
this.pacerRtt = sample
|
|
1228
1333
|
return
|
|
1229
1334
|
}
|
|
1230
|
-
const delay: i64 = this.boundAckDelay(ackDelay)
|
|
1335
|
+
const delay: i64 = quicRecoveryProduct(this.boundAckDelay(ackDelay), QUIC_RECOVERY_MICROS)
|
|
1231
1336
|
let adjusted: i64 = sample
|
|
1232
|
-
if (sample
|
|
1233
|
-
adjusted = sample
|
|
1337
|
+
if (quicRecoveryLess(sample, quicRecoveryProduct(this.minRtt, QUIC_RECOVERY_MICROS)) >= delay) {
|
|
1338
|
+
adjusted = quicRecoveryLess(sample, delay)
|
|
1234
1339
|
}
|
|
1235
|
-
this.pacerRtt = (7
|
|
1340
|
+
this.pacerRtt = quicRecoverySum(quicRecoveryProduct(7, this.pacerRtt), adjusted) / 8
|
|
1236
1341
|
}
|
|
1237
1342
|
|
|
1238
1343
|
/**
|
|
@@ -1241,7 +1346,7 @@ export class QuicRecovery {
|
|
|
1241
1346
|
* @returns How long after a packet was sent it is lost by the time threshold, in milliseconds, at least 1.
|
|
1242
1347
|
*/
|
|
1243
1348
|
lossDelay(): i64 {
|
|
1244
|
-
const delay: i64 = (9
|
|
1349
|
+
const delay: i64 = quicRecoveryProduct(9, quicRecoveryMax(this.latestRtt, this.smoothedRtt)) / 8
|
|
1245
1350
|
return quicRecoveryMax(delay, QUIC_RECOVERY_GRANULARITY)
|
|
1246
1351
|
}
|
|
1247
1352
|
|
|
@@ -1254,7 +1359,7 @@ export class QuicRecovery {
|
|
|
1254
1359
|
private detectLoss(sp: QuicSentPackets, now: i64): void {
|
|
1255
1360
|
sp.lossTime = -1
|
|
1256
1361
|
const delay: i64 = this.lossDelay()
|
|
1257
|
-
const lostSendTime: i64 = now
|
|
1362
|
+
const lostSendTime: i64 = quicRecoveryLess(now, delay)
|
|
1258
1363
|
for (let k: i32 = 0; k < sp.count; k += 1) {
|
|
1259
1364
|
const s: i32 = sp.slot(k)
|
|
1260
1365
|
const pn: i64 = sp.pnAt(s)
|
|
@@ -1264,10 +1369,13 @@ export class QuicRecovery {
|
|
|
1264
1369
|
if (sp.stateAt(s) !== QUIC_RECOVERY_SENT) {
|
|
1265
1370
|
continue
|
|
1266
1371
|
}
|
|
1267
|
-
if (
|
|
1372
|
+
if (
|
|
1373
|
+
sp.timeAt(s) <= lostSendTime ||
|
|
1374
|
+
quicRecoveryLess(sp.largestAcked, pn) >= QUIC_RECOVERY_PACKET_THRESHOLD
|
|
1375
|
+
) {
|
|
1268
1376
|
sp.markLost(s)
|
|
1269
1377
|
} else {
|
|
1270
|
-
const at: i64 = sp.timeAt(s)
|
|
1378
|
+
const at: i64 = quicRecoverySum(sp.timeAt(s), delay)
|
|
1271
1379
|
if (sp.lossTime < 0 || at < sp.lossTime) {
|
|
1272
1380
|
sp.lossTime = at
|
|
1273
1381
|
}
|
|
@@ -1290,7 +1398,7 @@ export class QuicRecovery {
|
|
|
1290
1398
|
newest = quicRecoveryMax(newest, sp.timeAt(sp.lostSlot(k)))
|
|
1291
1399
|
}
|
|
1292
1400
|
if (sp.markedAt(sp.lostSlot(k)) && this.ecnState !== QUIC_RECOVERY_ECN_CAPABLE) {
|
|
1293
|
-
this.ecnTestLost = this.ecnTestLost
|
|
1401
|
+
this.ecnTestLost = quicRecoveryStep(this.ecnTestLost)
|
|
1294
1402
|
}
|
|
1295
1403
|
}
|
|
1296
1404
|
// RFC 9000 A.4: every packet marked while testing that could be lost was.
|
|
@@ -1311,7 +1419,7 @@ export class QuicRecovery {
|
|
|
1311
1419
|
// CUBIC starts over from slow start (RFC 9438 §4.8): its next stage is a new epoch.
|
|
1312
1420
|
this.cubicEpoch = -1
|
|
1313
1421
|
this.cubicIdle = -1
|
|
1314
|
-
this.persistentCongestions = this.persistentCongestions
|
|
1422
|
+
this.persistentCongestions = quicRecoveryStep(this.persistentCongestions)
|
|
1315
1423
|
}
|
|
1316
1424
|
for (let k: i32 = 0; k < sp.lostCount; k += 1) {
|
|
1317
1425
|
sp.setState(sp.lostSlot(k), QUIC_RECOVERY_LOST)
|
|
@@ -1329,7 +1437,10 @@ export class QuicRecovery {
|
|
|
1329
1437
|
if (this.firstSampleTime < 0) {
|
|
1330
1438
|
return false
|
|
1331
1439
|
}
|
|
1332
|
-
const span: i64 = (
|
|
1440
|
+
const span: i64 = quicRecoveryProduct(
|
|
1441
|
+
quicRecoverySum(this.ptoBase(), this.maxAckDelay),
|
|
1442
|
+
QUIC_RECOVERY_PERSISTENT_THRESHOLD
|
|
1443
|
+
)
|
|
1333
1444
|
let first: i64 = -1
|
|
1334
1445
|
let fresh: boolean = false
|
|
1335
1446
|
for (let k: i32 = 0; k < sp.count; k += 1) {
|
|
@@ -1357,7 +1468,7 @@ export class QuicRecovery {
|
|
|
1357
1468
|
first = sp.timeAt(s)
|
|
1358
1469
|
}
|
|
1359
1470
|
fresh = fresh || state === QUIC_RECOVERY_LOST_NOW
|
|
1360
|
-
if (fresh && sp.timeAt(s)
|
|
1471
|
+
if (fresh && quicRecoveryLess(sp.timeAt(s), first) > span) {
|
|
1361
1472
|
return true
|
|
1362
1473
|
}
|
|
1363
1474
|
}
|
|
@@ -1382,16 +1493,16 @@ export class QuicRecovery {
|
|
|
1382
1493
|
this.recoveryStart = now
|
|
1383
1494
|
const cwnd: i64 = this.congestionWindow
|
|
1384
1495
|
if (this.controller === QUIC_RECOVERY_CUBIC) {
|
|
1385
|
-
this.cubicMax = cwnd < this.cubicMax ? (cwnd
|
|
1496
|
+
this.cubicMax = cwnd < this.cubicMax ? quicRecoveryProduct(cwnd, 17) / 20 : cwnd
|
|
1386
1497
|
this.cubicPrior = cwnd
|
|
1387
1498
|
this.cubicEpoch = -1
|
|
1388
1499
|
this.cubicIdle = -1
|
|
1389
|
-
this.ssthresh = (cwnd
|
|
1500
|
+
this.ssthresh = quicRecoveryProduct(cwnd, 7) / 10
|
|
1390
1501
|
} else {
|
|
1391
1502
|
this.ssthresh = cwnd / 2
|
|
1392
1503
|
}
|
|
1393
1504
|
this.congestionWindow = quicRecoveryMax(this.ssthresh, this.minimumWindow())
|
|
1394
|
-
this.congestionEvents = this.congestionEvents
|
|
1505
|
+
this.congestionEvents = quicRecoveryStep(this.congestionEvents)
|
|
1395
1506
|
}
|
|
1396
1507
|
|
|
1397
1508
|
/**
|
|
@@ -1405,12 +1516,14 @@ export class QuicRecovery {
|
|
|
1405
1516
|
return
|
|
1406
1517
|
}
|
|
1407
1518
|
const size: i64 = toI64(sp.sizeAt(s))
|
|
1408
|
-
|
|
1409
|
-
|
|
1519
|
+
const cwnd: i64 = this.congestionWindow
|
|
1520
|
+
// A window of nothing has no fraction to grow by, so it grows as in slow start.
|
|
1521
|
+
if (cwnd < this.ssthresh || cwnd <= 0) {
|
|
1522
|
+
this.congestionWindow = quicRecoverySum(cwnd, size)
|
|
1410
1523
|
} else if (this.controller === QUIC_RECOVERY_CUBIC) {
|
|
1411
1524
|
this.cubicAcked(size, now)
|
|
1412
1525
|
} else {
|
|
1413
|
-
this.congestionWindow =
|
|
1526
|
+
this.congestionWindow = quicRecoverySum(cwnd, quicRecoveryProduct(this.datagramSize, size) / cwnd)
|
|
1414
1527
|
}
|
|
1415
1528
|
}
|
|
1416
1529
|
|
|
@@ -1429,6 +1542,10 @@ export class QuicRecovery {
|
|
|
1429
1542
|
*/
|
|
1430
1543
|
private cubicAcked(size: i64, now: i64): void {
|
|
1431
1544
|
const cwnd: i64 = this.congestionWindow
|
|
1545
|
+
// Never taken: `packetAcked` grows a window of nothing as slow start does.
|
|
1546
|
+
if (cwnd <= 0) {
|
|
1547
|
+
return
|
|
1548
|
+
}
|
|
1432
1549
|
if (this.cubicEpoch < 0) {
|
|
1433
1550
|
this.cubicEpoch = now
|
|
1434
1551
|
this.cubicIdle = -1
|
|
@@ -1436,29 +1553,39 @@ export class QuicRecovery {
|
|
|
1436
1553
|
this.cubicEstCarry = 0
|
|
1437
1554
|
this.cubicCarry = 0
|
|
1438
1555
|
if (this.cubicMax > cwnd) {
|
|
1439
|
-
this.cubicK = this.cubicSpan(this.cubicMax
|
|
1556
|
+
this.cubicK = this.cubicSpan(quicRecoveryLess(this.cubicMax, cwnd))
|
|
1440
1557
|
} else {
|
|
1441
1558
|
this.cubicK = 0
|
|
1442
1559
|
this.cubicMax = cwnd
|
|
1443
1560
|
}
|
|
1444
1561
|
}
|
|
1445
1562
|
const alpha: i64 = this.cubicEst >= this.cubicPrior ? 17 : 9
|
|
1446
|
-
const num: i64 =
|
|
1447
|
-
|
|
1448
|
-
|
|
1563
|
+
const num: i64 = quicRecoverySum(
|
|
1564
|
+
quicRecoveryProduct(quicRecoveryProduct(alpha, size), this.datagramSize),
|
|
1565
|
+
this.cubicEstCarry
|
|
1566
|
+
)
|
|
1567
|
+
const den: i64 = quicRecoveryProduct(17, cwnd)
|
|
1568
|
+
// Never taken: 17 × a window past 0 is past 0, or held at 2^63 − 1.
|
|
1569
|
+
if (den <= 0) {
|
|
1570
|
+
return
|
|
1571
|
+
}
|
|
1572
|
+
this.cubicEst = quicRecoverySum(this.cubicEst, num / den)
|
|
1449
1573
|
this.cubicEstCarry = num % den
|
|
1450
|
-
const t: i64 = now
|
|
1574
|
+
const t: i64 = quicRecoveryLess(now, this.cubicEpoch)
|
|
1451
1575
|
if (this.cubicWindow(t) < this.cubicEst) {
|
|
1452
1576
|
this.congestionWindow = quicRecoveryMax(cwnd, this.cubicEst)
|
|
1453
1577
|
return
|
|
1454
1578
|
}
|
|
1455
|
-
const ceiling: i64 = cwnd
|
|
1456
|
-
const curve: i64 = this.cubicWindow(t
|
|
1579
|
+
const ceiling: i64 = quicRecoverySum(cwnd, cwnd / 2)
|
|
1580
|
+
const curve: i64 = this.cubicWindow(quicRecoverySum(t, this.smoothedRtt))
|
|
1457
1581
|
const target: i64 = quicRecoveryMax(cwnd, curve > ceiling ? ceiling : curve)
|
|
1458
1582
|
// The window only grows within a stage, so the carry, below the window
|
|
1459
1583
|
// it was a fraction of, stays below the one it is added against.
|
|
1460
|
-
const step: i64 = (
|
|
1461
|
-
|
|
1584
|
+
const step: i64 = quicRecoverySum(
|
|
1585
|
+
quicRecoveryProduct(quicRecoveryLess(target, cwnd), size),
|
|
1586
|
+
this.cubicCarry
|
|
1587
|
+
)
|
|
1588
|
+
this.congestionWindow = quicRecoverySum(cwnd, step / cwnd)
|
|
1462
1589
|
this.cubicCarry = step % cwnd
|
|
1463
1590
|
}
|
|
1464
1591
|
|
|
@@ -1469,8 +1596,13 @@ export class QuicRecovery {
|
|
|
1469
1596
|
* division truncates toward zero.
|
|
1470
1597
|
*/
|
|
1471
1598
|
private cubicWindow(t: i64): i64 {
|
|
1472
|
-
const d: i64 = quicRecoveryCubicClamp(t
|
|
1473
|
-
|
|
1599
|
+
const d: i64 = quicRecoveryCubicClamp(quicRecoveryLess(t, this.cubicK))
|
|
1600
|
+
// |t − K| is at most 40000, so its cube, 6.4 × 10¹³ at most, fits; the sign goes back on after the division.
|
|
1601
|
+
const size: u64 = d < 0 ? toU64(0) - toU64(d) : toU64(d)
|
|
1602
|
+
const cube: i64 = toI64(size * size * size)
|
|
1603
|
+
const move: i64 =
|
|
1604
|
+
quicRecoveryProduct(cube, quicRecoveryProduct(2, this.datagramSize)) / QUIC_RECOVERY_CUBIC_SCALE
|
|
1605
|
+
return d < 0 ? quicRecoveryLess(this.cubicMax, move) : quicRecoverySum(this.cubicMax, move)
|
|
1474
1606
|
}
|
|
1475
1607
|
|
|
1476
1608
|
/**
|
|
@@ -1479,13 +1611,15 @@ export class QuicRecovery {
|
|
|
1479
1611
|
* milliseconds, rounded down; a fall too deep for the cube to fit is 40 s.
|
|
1480
1612
|
*/
|
|
1481
1613
|
private cubicSpan(drop: i64): i64 {
|
|
1482
|
-
const two: i64 = 2
|
|
1614
|
+
const two: i64 = quicRecoveryProduct(2, this.datagramSize)
|
|
1483
1615
|
const span: i64 = QUIC_RECOVERY_CUBIC_SPAN
|
|
1484
|
-
// drop >= span³ × 2 × size / (5 × 10⁹), which is 25600 × size, has K at the span or past it
|
|
1485
|
-
|
|
1616
|
+
// drop >= span³ × 2 × size / (5 × 10⁹), which is 25600 × size, has K at the span or past it, as has a
|
|
1617
|
+
// datagram size of nothing. The product below is held at 2^63 − 1 only for a size past 72000, where
|
|
1618
|
+
// what it is divided to is past span³ too.
|
|
1619
|
+
if (drop >= quicRecoveryProduct(25600, this.datagramSize) || two <= 0) {
|
|
1486
1620
|
return span
|
|
1487
1621
|
}
|
|
1488
|
-
return quicRecoveryCbrt((drop
|
|
1622
|
+
return quicRecoveryCbrt(quicRecoveryProduct(drop, QUIC_RECOVERY_CUBIC_SCALE) / two)
|
|
1489
1623
|
}
|
|
1490
1624
|
|
|
1491
1625
|
/**
|
|
@@ -1505,7 +1639,7 @@ export class QuicRecovery {
|
|
|
1505
1639
|
return
|
|
1506
1640
|
}
|
|
1507
1641
|
if (this.cubicIdle >= 0) {
|
|
1508
|
-
this.cubicEpoch = this.cubicEpoch
|
|
1642
|
+
this.cubicEpoch = quicRecoverySum(this.cubicEpoch, quicRecoveryLess(now, this.cubicIdle))
|
|
1509
1643
|
this.cubicIdle = -1
|
|
1510
1644
|
}
|
|
1511
1645
|
}
|
|
@@ -1520,12 +1654,15 @@ export class QuicRecovery {
|
|
|
1520
1654
|
*/
|
|
1521
1655
|
probeTimeout(): i64 {
|
|
1522
1656
|
const base: i64 = this.ptoBase()
|
|
1523
|
-
return this.handshakeConfirmed ? base
|
|
1657
|
+
return this.handshakeConfirmed ? quicRecoverySum(base, this.maxAckDelay) : base
|
|
1524
1658
|
}
|
|
1525
1659
|
|
|
1526
1660
|
/** smoothed_rtt + max(4 × rttvar, kGranularity): every probe timeout's period before max_ack_delay and the backoff. */
|
|
1527
1661
|
private ptoBase(): i64 {
|
|
1528
|
-
return
|
|
1662
|
+
return quicRecoverySum(
|
|
1663
|
+
this.smoothedRtt,
|
|
1664
|
+
quicRecoveryMax(quicRecoveryProduct(4, this.rttVar), QUIC_RECOVERY_GRANULARITY)
|
|
1665
|
+
)
|
|
1529
1666
|
}
|
|
1530
1667
|
|
|
1531
1668
|
/**
|
|
@@ -1553,9 +1690,9 @@ export class QuicRecovery {
|
|
|
1553
1690
|
const backoff: i64 = toI64(1) << toI64(this.ptoCount)
|
|
1554
1691
|
let duration: i64 = this.ptoBase()
|
|
1555
1692
|
if (space === QUIC_RECOVERY_APPLICATION) {
|
|
1556
|
-
duration = duration
|
|
1693
|
+
duration = quicRecoverySum(duration, this.maxAckDelay)
|
|
1557
1694
|
}
|
|
1558
|
-
return sp.lastAckEliciting
|
|
1695
|
+
return quicRecoverySum(sp.lastAckEliciting, quicRecoveryProduct(duration, backoff))
|
|
1559
1696
|
}
|
|
1560
1697
|
|
|
1561
1698
|
/** The space whose probe timeout fires first, or -1 when no space may have one. */
|
|
@@ -1600,9 +1737,9 @@ export class QuicRecovery {
|
|
|
1600
1737
|
* @returns The time `onTimeout` is next due, in the caller's milliseconds, or -1 when no timer is set.
|
|
1601
1738
|
*/
|
|
1602
1739
|
deadline(amplificationBlocked: boolean): i64 {
|
|
1603
|
-
const loss:
|
|
1604
|
-
if (loss
|
|
1605
|
-
return
|
|
1740
|
+
const loss: QuicSentPackets | null = this.space(this.lossSpace())
|
|
1741
|
+
if (loss !== null) {
|
|
1742
|
+
return loss.lossTime
|
|
1606
1743
|
}
|
|
1607
1744
|
if (amplificationBlocked) {
|
|
1608
1745
|
return -1
|
|
@@ -1634,16 +1771,17 @@ export class QuicRecovery {
|
|
|
1634
1771
|
return QUIC_RECOVERY_TIMEOUT_NONE
|
|
1635
1772
|
}
|
|
1636
1773
|
const loss: i32 = this.lossSpace()
|
|
1637
|
-
|
|
1638
|
-
|
|
1774
|
+
const sp: QuicSentPackets | null = this.space(loss)
|
|
1775
|
+
if (sp !== null) {
|
|
1639
1776
|
this.detectLoss(sp, now)
|
|
1640
1777
|
this.packetsLost(sp, now)
|
|
1641
1778
|
this.timeoutSpace = loss
|
|
1642
1779
|
return QUIC_RECOVERY_TIMEOUT_LOSS
|
|
1643
1780
|
}
|
|
1644
1781
|
this.timeoutSpace = this.ptoSpace()
|
|
1645
|
-
|
|
1646
|
-
|
|
1782
|
+
const count: i32 = this.ptoCount
|
|
1783
|
+
if (count < QUIC_RECOVERY_MAX_BACKOFF) {
|
|
1784
|
+
this.ptoCount = count + 1
|
|
1647
1785
|
}
|
|
1648
1786
|
return QUIC_RECOVERY_TIMEOUT_PTO
|
|
1649
1787
|
}
|
|
@@ -1708,13 +1846,17 @@ export class QuicRecovery {
|
|
|
1708
1846
|
return
|
|
1709
1847
|
}
|
|
1710
1848
|
// A minute is far past what fills the budget, and keeps the product in range.
|
|
1711
|
-
let elapsed: i64 = at
|
|
1849
|
+
let elapsed: i64 = quicRecoveryLess(at, this.pacerTime)
|
|
1712
1850
|
if (elapsed > 60000000) {
|
|
1713
1851
|
elapsed = 60000000
|
|
1714
1852
|
}
|
|
1715
|
-
const
|
|
1716
|
-
|
|
1717
|
-
|
|
1853
|
+
const per: i64 = quicRecoveryProduct(quicRecoveryMax(this.pacerRtt, 1), 4)
|
|
1854
|
+
// Never taken: 4 × an RTT of at least 1 is past 0, or held at 2^63 − 1.
|
|
1855
|
+
if (per <= 0) {
|
|
1856
|
+
return
|
|
1857
|
+
}
|
|
1858
|
+
const earned: i64 = quicRecoveryProduct(quicRecoveryProduct(elapsed, this.pacerWindow()), 5) / per
|
|
1859
|
+
this.pacerBudget = quicRecoverySum(this.pacerBudget, earned)
|
|
1718
1860
|
if (this.pacerBudget > this.initialWindow()) {
|
|
1719
1861
|
this.pacerBudget = this.initialWindow()
|
|
1720
1862
|
}
|
|
@@ -1733,14 +1875,18 @@ export class QuicRecovery {
|
|
|
1733
1875
|
*/
|
|
1734
1876
|
pacerDelay(now: i64, size: i32): i64 {
|
|
1735
1877
|
this.pacerRefill(now)
|
|
1736
|
-
const need: i64 = toI64(size)
|
|
1878
|
+
const need: i64 = quicRecoveryLess(toI64(size), this.pacerBudget)
|
|
1737
1879
|
if (need <= 0) {
|
|
1738
1880
|
return 0
|
|
1739
1881
|
}
|
|
1740
|
-
const
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1882
|
+
const rate: i64 = quicRecoveryMax(quicRecoveryProduct(this.pacerWindow(), 5), 1)
|
|
1883
|
+
// Never taken: the rate is at least 1.
|
|
1884
|
+
if (rate <= 0) {
|
|
1885
|
+
return 1
|
|
1886
|
+
}
|
|
1887
|
+
const time: i64 = quicRecoveryProduct(quicRecoveryProduct(need, quicRecoveryMax(this.pacerRtt, 1)), 4)
|
|
1888
|
+
const wait: i64 = quicRecoverySum(time, rate - 1) / rate
|
|
1889
|
+
return quicRecoveryMax(quicRecoverySum(wait, QUIC_RECOVERY_MICROS - 1) / QUIC_RECOVERY_MICROS, 1)
|
|
1744
1890
|
}
|
|
1745
1891
|
|
|
1746
1892
|
/**
|
|
@@ -1755,8 +1901,13 @@ export class QuicRecovery {
|
|
|
1755
1901
|
* @returns The bytes the pacer earns in a millisecond, held to `least` and `most`.
|
|
1756
1902
|
*/
|
|
1757
1903
|
pacerQuantum(least: i32, most: i32): i32 {
|
|
1758
|
-
const
|
|
1759
|
-
|
|
1904
|
+
const per: i64 = quicRecoveryProduct(quicRecoveryMax(this.pacerRtt, 1), 4)
|
|
1905
|
+
// Never taken: 4 × an RTT of at least 1 is past 0, or held at 2^63 − 1.
|
|
1906
|
+
if (per <= 0) {
|
|
1907
|
+
return least
|
|
1908
|
+
}
|
|
1909
|
+
const milli: i64 =
|
|
1910
|
+
quicRecoveryProduct(quicRecoveryProduct(this.pacerWindow(), 5), QUIC_RECOVERY_MICROS) / per
|
|
1760
1911
|
if (milli < toI64(least)) {
|
|
1761
1912
|
return least
|
|
1762
1913
|
}
|
|
@@ -1771,6 +1922,6 @@ export class QuicRecovery {
|
|
|
1771
1922
|
*/
|
|
1772
1923
|
onPaced(now: i64, size: i32): void {
|
|
1773
1924
|
this.pacerRefill(now)
|
|
1774
|
-
this.pacerBudget = this.pacerBudget
|
|
1925
|
+
this.pacerBudget = quicRecoveryLess(this.pacerBudget, toI64(size))
|
|
1775
1926
|
}
|
|
1776
1927
|
}
|