@amritk/nish-aarch64-linux 0.37.0 → 0.39.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 +28 -16
- package/bin/nish +0 -0
- package/docs/AI.md +380 -47
- package/package.json +1 -1
- package/runtime/core/arrays.d.ts +4 -0
- package/runtime/core/arrays.mjs +33 -0
- package/runtime/core/host.d.ts +11 -0
- package/runtime/core/host.mjs +35 -0
- package/runtime/nish.d.ts +645 -66
- package/runtime/nish.h +101 -15
- package/runtime/nish.mjs +69 -6
- package/runtime/node.mjs +117 -0
- package/runtime/runtime-aes.c +12 -4
- package/runtime/runtime-async.c +267 -51
- package/runtime/runtime-checksum.c +207 -15
- package/runtime/runtime-cross.c +2 -1
- package/runtime/runtime-net.c +32 -3
- package/runtime/runtime-os.c +174 -27
- package/runtime/runtime-region.c +170 -8
- package/runtime/runtime-sandbox.c +377 -17
- package/runtime/runtime-sha256.c +11 -4
- package/runtime/runtime-text.c +1068 -0
- package/runtime/runtime-wasm.c +18 -3
- package/runtime/runtime.c +55 -961
- package/runtime/vite.mjs +48 -11
- package/scripts/build.sh +113 -36
- package/std/LICENSE-fdlibm +8 -0
- package/std/README.md +7 -4
- package/std/array.ts +266 -0
- package/std/compress/checksum.ts +13 -0
- package/std/compress/deflate.ts +0 -2
- package/std/crypto/p256.ts +247 -74
- package/std/crypto/p384.ts +3 -1
- package/std/crypto/pki.ts +35 -9
- package/std/crypto/x25519.ts +153 -64
- package/std/crypto/x509.ts +113 -10
- package/std/host/text.ts +86 -0
- package/std/json-tokenizer.ts +20 -0
- package/std/json-typed.ts +217 -8
- package/std/math.ts +743 -41
- package/std/net/dns-resolver.ts +46 -6
- package/std/net/dns.ts +50 -13
- package/std/net/fetch.ts +691 -129
- package/std/net/handler.ts +142 -16
- package/std/net/http-compress.ts +17 -9
- package/std/net/http-fields.ts +19 -4
- package/std/net/http1-codec.ts +517 -154
- package/std/net/http1-server.ts +508 -25
- package/std/net/http2-cleartext.ts +526 -0
- package/std/net/http2-tls.ts +48 -0
- package/std/net/http2.ts +84 -0
- package/std/net/postgres-async.ts +2223 -0
- package/std/net/postgres-carrier.ts +343 -10
- package/std/net/postgres.ts +129 -11
- package/std/net/prefork.ts +195 -11
- package/std/net/quic-datagram.ts +30 -0
- package/std/net/quic-listener.ts +38 -12
- package/std/net/quic-packet.ts +19 -6
- package/std/net/quic-recovery.ts +134 -19
- package/std/net/quic-stream.ts +174 -36
- package/std/net/quic.ts +418 -18
- package/std/net/router.ts +39 -17
- package/std/net/serve.ts +867 -0
- package/std/net/tls/codec.ts +110 -32
- package/std/net/tls/record-server.ts +37 -7
- package/std/net/tls-tcp.ts +56 -1
- package/std/net/tls.ts +196 -50
- package/std/net/websocket.ts +55 -18
- package/std/net/webtransport.ts +179 -1
- package/std/regex.ts +69 -47
- package/std/region.ts +62 -11
- package/std/secret.ts +26 -59
- package/std/text.ts +464 -5
package/std/net/quic-listener.ts
CHANGED
|
@@ -83,8 +83,8 @@
|
|
|
83
83
|
* **GSO and GRO** (`nish:net`'s `UDP_SEGMENT` and `UDP_GRO`). A carrier that
|
|
84
84
|
* sends with segmentation offload takes a whole flight at once:
|
|
85
85
|
* `quicListenerTakeFlight` writes as many datagrams as the pacer has credit for
|
|
86
|
-
* back to back into one buffer, every one `
|
|
87
|
-
* the last, which is what one `udpSendTo` with that segment size cuts back into
|
|
86
|
+
* back to back into one buffer, every one the connection's `datagramSize()`
|
|
87
|
+
* but the last, which is what one `udpSendTo` with that segment size cuts back into
|
|
88
88
|
* datagrams; each is written in place, so a flight allocates nothing.
|
|
89
89
|
*
|
|
90
90
|
* The flight is paced as a whole: it is as long as the pacer's credit, and
|
|
@@ -158,6 +158,8 @@ import {
|
|
|
158
158
|
QuicConnection,
|
|
159
159
|
QuicServerConfig,
|
|
160
160
|
quicConnResetTokenInto,
|
|
161
|
+
quicWorkerByte,
|
|
162
|
+
quicWorkerCheck,
|
|
161
163
|
} from "nish/net/quic"
|
|
162
164
|
|
|
163
165
|
// ---- What `handle` answers ----------------------------------------------------
|
|
@@ -405,11 +407,14 @@ export class QuicListener {
|
|
|
405
407
|
*
|
|
406
408
|
* @param config The server's configuration, kept by reference: its static keys and Retry token lifetime.
|
|
407
409
|
* Keys of the wrong size, or a lifetime outside 1 to `QUIC_LISTENER_MAX_TOKEN_LIFETIME` ms, make a
|
|
408
|
-
* listener that drops every datagram.
|
|
410
|
+
* listener that drops every datagram. Its `workerIndex` and `workerCount` are checked here
|
|
411
|
+
* (`quicWorkerCheck`, which panics on a bad pair); a valid pair puts the worker in byte 0 of each
|
|
412
|
+
* Retry's connection ID and holds back the reset for an ID a sibling worker issued.
|
|
409
413
|
* @param entropy `QUIC_LISTENER_ENTROPY_SIZE` (32) random bytes, the seed of every unpredictable byte
|
|
410
414
|
* the listener sends. Zeroed on return; any other length makes a listener that drops every datagram.
|
|
411
415
|
*/
|
|
412
416
|
constructor(config: QuicServerConfig, entropy: u8[]) {
|
|
417
|
+
quicWorkerCheck(config)
|
|
413
418
|
this.config = config
|
|
414
419
|
this.seed = new Array<u8>(QUIC_LISTENER_ENTROPY_SIZE)
|
|
415
420
|
quicPacketCopy(this.seed, 0, entropy, 0, QUIC_LISTENER_ENTROPY_SIZE)
|
|
@@ -557,6 +562,17 @@ export class QuicListener {
|
|
|
557
562
|
return answer.kind
|
|
558
563
|
}
|
|
559
564
|
if (header.type === QUIC_PACKET_SHORT) {
|
|
565
|
+
// RFC 9000 §21.11: an ID whose worker byte names a sibling in the
|
|
566
|
+
// steered group is that sibling's, and a reset under the shared key
|
|
567
|
+
// would end its live connection. Byte 0 at or above N is no worker's.
|
|
568
|
+
const owner: i32 = toI32(datagram[header.dcidStart])
|
|
569
|
+
if (
|
|
570
|
+
quicWorkerByte(this.config) >= 0 &&
|
|
571
|
+
owner < this.config.workerCount &&
|
|
572
|
+
owner !== this.config.workerIndex
|
|
573
|
+
) {
|
|
574
|
+
return answer.kind
|
|
575
|
+
}
|
|
560
576
|
this.statelessReset(answer, len, datagram, header.dcidStart, header.dcidLength)
|
|
561
577
|
return answer.kind
|
|
562
578
|
}
|
|
@@ -736,6 +752,11 @@ export class QuicListener {
|
|
|
736
752
|
const reply: u8[] = answer.reply
|
|
737
753
|
quicListenerResize(reply, tagAt + QUIC_RETRY_TAG_SIZE)
|
|
738
754
|
this.randomInto(reply, retryScidAt, QUIC_CONN_CID_LENGTH)
|
|
755
|
+
const worker: i32 = quicWorkerByte(this.config)
|
|
756
|
+
if (worker >= 0) {
|
|
757
|
+
// The retried Initial is sent to this ID, so it steers back here.
|
|
758
|
+
reply[retryScidAt] = toU8(worker)
|
|
759
|
+
}
|
|
739
760
|
reply[tokenAt] = toU8(QUIC_LISTENER_TOKEN_MARKER)
|
|
740
761
|
quicListenerPutNumber(reply, tokenAt + 1, this.now, 8)
|
|
741
762
|
reply[tokenAt + QUIC_LISTENER_TOKEN_HEAD - 1] = toU8(odcidLength)
|
|
@@ -980,7 +1001,7 @@ export const QUIC_LISTENER_FLIGHT_QUANTUM: i32 = 4800
|
|
|
980
1001
|
* `QUIC_LISTENER_FLIGHT_QUANTUM`.
|
|
981
1002
|
*/
|
|
982
1003
|
const quicListenerQuantum = (conn: QuicConnection): i32 =>
|
|
983
|
-
conn.recovery.pacerQuantum(
|
|
1004
|
+
conn.recovery.pacerQuantum(conn.datagramSize(), QUIC_LISTENER_FLIGHT_QUANTUM)
|
|
984
1005
|
|
|
985
1006
|
/**
|
|
986
1007
|
* When `quicListenerTakeFlight` next lets `conn` start a flight, in the
|
|
@@ -1015,11 +1036,15 @@ export class QuicFlight {
|
|
|
1015
1036
|
* waits for, a millisecond's earning of one to four datagrams; then each
|
|
1016
1037
|
* datagram goes only when the pacer has credit for a full one (RFC 9002 §7.7)
|
|
1017
1038
|
* and is charged at its real size, as `quicListenerTakePaced` does, so the
|
|
1018
|
-
* flight is the pacer's whole credit and no more.
|
|
1019
|
-
*
|
|
1020
|
-
*
|
|
1021
|
-
*
|
|
1022
|
-
*
|
|
1039
|
+
* flight is the pacer's whole credit and no more. Every datagram after the
|
|
1040
|
+
* first is held to the first's size, the segment, and the flight stops at the
|
|
1041
|
+
* first datagram shorter than the segment or than the connection's
|
|
1042
|
+
* `datagramSize()`, which can only be the last of a segmented send, at
|
|
1043
|
+
* `QUIC_LISTENER_FLIGHT_MAX` datagrams, when `cap` has no room for another,
|
|
1044
|
+
* and before a datagram whose ECN codepoint would not be the first's. A path
|
|
1045
|
+
* MTU probe (see `QuicConnection.pathMtu`) goes only when `cap` has room for
|
|
1046
|
+
* it, so a carrier gives `QUIC_CONN_DATAGRAM_MAX` bytes or more to let the
|
|
1047
|
+
* connection discover a larger path.
|
|
1023
1048
|
*
|
|
1024
1049
|
* @param conn The connection to send for.
|
|
1025
1050
|
* @param now The caller's time in milliseconds.
|
|
@@ -1048,14 +1073,15 @@ export const quicListenerTakeFlight = (
|
|
|
1048
1073
|
while (
|
|
1049
1074
|
flight.count < QUIC_LISTENER_FLIGHT_MAX &&
|
|
1050
1075
|
length + QUIC_CONN_DATAGRAM_SIZE <= cap &&
|
|
1051
|
-
conn.recovery.pacerDelay(now,
|
|
1076
|
+
conn.recovery.pacerDelay(now, conn.datagramSize()) <= 0
|
|
1052
1077
|
) {
|
|
1053
1078
|
// The codepoint `takeDatagramInto` would mark the next datagram with: one send carries one.
|
|
1054
1079
|
const next: i32 = conn.ecnMarking ? conn.recovery.ecnCodepoint() : 0
|
|
1055
1080
|
if (flight.count > 0 && next !== flight.ecn) {
|
|
1056
1081
|
return length
|
|
1057
1082
|
}
|
|
1058
|
-
const
|
|
1083
|
+
const room: i32 = flight.count > 0 && flight.segment < cap - length ? flight.segment : cap - length
|
|
1084
|
+
const n: i32 = conn.takeDatagramWithin(buf, at + length, room, now)
|
|
1059
1085
|
if (n <= 0) {
|
|
1060
1086
|
return length
|
|
1061
1087
|
}
|
|
@@ -1066,7 +1092,7 @@ export const quicListenerTakeFlight = (
|
|
|
1066
1092
|
}
|
|
1067
1093
|
flight.count = flight.count + 1
|
|
1068
1094
|
length = length + n
|
|
1069
|
-
if (n <
|
|
1095
|
+
if (n < flight.segment || n < conn.datagramSize()) {
|
|
1070
1096
|
return length
|
|
1071
1097
|
}
|
|
1072
1098
|
}
|
package/std/net/quic-packet.ts
CHANGED
|
@@ -116,6 +116,7 @@ import {
|
|
|
116
116
|
} from "nish/crypto/aes"
|
|
117
117
|
import { chacha20HeaderMask, chacha20Poly1305Open, chacha20Poly1305Seal } from "nish/crypto/chacha20poly1305"
|
|
118
118
|
import { timingSafeEqual } from "nish/crypto/ct"
|
|
119
|
+
import { copyBytes } from "nish/bytes"
|
|
119
120
|
import {
|
|
120
121
|
HkdfScratch,
|
|
121
122
|
hkdfExpandLabelHeldInto,
|
|
@@ -627,8 +628,8 @@ const quicPacketCidWindowFits = (cid: u8[], length: i32): boolean =>
|
|
|
627
628
|
length >= 0 && length <= QUIC_MAX_CID_LENGTH && length <= toI32(cid.length)
|
|
628
629
|
|
|
629
630
|
/**
|
|
630
|
-
* Writes `bytes[from .. from + length)` into `buf` at `at
|
|
631
|
-
*
|
|
631
|
+
* Writes `bytes[from .. from + length)` into `buf` at `at`, as one slice copy; the caller has checked both windows.
|
|
632
|
+
* The part of the run outside either window is skipped rather than written, so a wrong window cannot panic.
|
|
632
633
|
*
|
|
633
634
|
* @param buf The buffer to write into; it is not grown.
|
|
634
635
|
* @param at The byte offset in `buf` of the first byte written.
|
|
@@ -637,10 +638,22 @@ const quicPacketCidWindowFits = (cid: u8[], length: i32): boolean =>
|
|
|
637
638
|
* @param length How many bytes to copy.
|
|
638
639
|
*/
|
|
639
640
|
export const quicPacketCopy = (buf: u8[], at: i32, bytes: u8[], from: i32, length: i32): void => {
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
641
|
+
let low: i32 = 0
|
|
642
|
+
if (low < -at) {
|
|
643
|
+
low = -at
|
|
644
|
+
}
|
|
645
|
+
if (low < -from) {
|
|
646
|
+
low = -from
|
|
647
|
+
}
|
|
648
|
+
let high: i32 = length
|
|
649
|
+
if (high > toI32(buf.length) - at) {
|
|
650
|
+
high = toI32(buf.length) - at
|
|
651
|
+
}
|
|
652
|
+
if (high > toI32(bytes.length) - from) {
|
|
653
|
+
high = toI32(bytes.length) - from
|
|
654
|
+
}
|
|
655
|
+
if (low < high) {
|
|
656
|
+
copyBytes(buf, at + low, bytes, from + low, high - low)
|
|
644
657
|
}
|
|
645
658
|
}
|
|
646
659
|
|
package/std/net/quic-recovery.ts
CHANGED
|
@@ -111,11 +111,15 @@ export const QUIC_RECOVERY_PACKET_THRESHOLD: i64 = 3
|
|
|
111
111
|
export const QUIC_RECOVERY_GRANULARITY: i64 = 1
|
|
112
112
|
/** kInitialRtt (§6.2.2), in milliseconds: the round trip assumed before the first sample. */
|
|
113
113
|
export const QUIC_RECOVERY_INITIAL_RTT: i64 = 333
|
|
114
|
-
/**
|
|
114
|
+
/**
|
|
115
|
+
* max_datagram_size (B.1) on a path nothing has been learnt of: the 1200
|
|
116
|
+
* bytes every datagram is at most until path MTU discovery validates more
|
|
117
|
+
* (`QuicRecovery.datagramSize`).
|
|
118
|
+
*/
|
|
115
119
|
export const QUIC_RECOVERY_DATAGRAM_SIZE: i64 = 1200
|
|
116
|
-
/** kInitialWindow (§7.2): min(10 × 1200, max(14720, 2 × 1200)), so 12000 bytes. */
|
|
120
|
+
/** kInitialWindow (§7.2) at 1200 bytes: min(10 × 1200, max(14720, 2 × 1200)), so 12000 bytes. */
|
|
117
121
|
export const QUIC_RECOVERY_INITIAL_WINDOW: i64 = 12000
|
|
118
|
-
/** kMinimumWindow (§7.2): two datagrams, 2400 bytes. */
|
|
122
|
+
/** kMinimumWindow (§7.2) at 1200 bytes: two datagrams, 2400 bytes. */
|
|
119
123
|
export const QUIC_RECOVERY_MINIMUM_WINDOW: i64 = 2400
|
|
120
124
|
/** kPersistentCongestionThreshold (§7.6.1): lost packets spanning three probe timeouts collapse the window. */
|
|
121
125
|
export const QUIC_RECOVERY_PERSISTENT_THRESHOLD: i64 = 3
|
|
@@ -143,6 +147,10 @@ const QUIC_RECOVERY_LOST: i32 = 3
|
|
|
143
147
|
const QUIC_RECOVERY_LOST_NOW: i32 = 4
|
|
144
148
|
/** The bit of a slot's state byte that says its packet was sent marked ECT(0), kept beside the state so a slot costs no second byte. */
|
|
145
149
|
const QUIC_RECOVERY_MARKED: i32 = 128
|
|
150
|
+
/** The bit of a slot's state byte that says its packet was a path MTU probe, whose loss is not congestion (RFC 9000 §14.4). */
|
|
151
|
+
const QUIC_RECOVERY_PROBE: i32 = 64
|
|
152
|
+
/** The state bits of a slot's state byte, below the two flags. */
|
|
153
|
+
const QUIC_RECOVERY_STATE_BITS: i32 = 63
|
|
146
154
|
|
|
147
155
|
/** The ECT(0) codepoint (RFC 3168), the only one this module asks a caller to mark with. */
|
|
148
156
|
export const QUIC_RECOVERY_ECT0: i32 = 2
|
|
@@ -270,7 +278,7 @@ export class QuicSentPackets {
|
|
|
270
278
|
if (s < 0 || s >= toI32(this.state.length)) {
|
|
271
279
|
return QUIC_RECOVERY_FREE
|
|
272
280
|
}
|
|
273
|
-
return toI32(this.state[s]) &
|
|
281
|
+
return toI32(this.state[s]) & QUIC_RECOVERY_STATE_BITS
|
|
274
282
|
}
|
|
275
283
|
|
|
276
284
|
/**
|
|
@@ -279,7 +287,7 @@ export class QuicSentPackets {
|
|
|
279
287
|
*/
|
|
280
288
|
setState(s: i32, value: i32): void {
|
|
281
289
|
if (s >= 0 && s < toI32(this.state.length)) {
|
|
282
|
-
this.state[s] = toU8((toI32(this.state[s]) & QUIC_RECOVERY_MARKED) | value)
|
|
290
|
+
this.state[s] = toU8((toI32(this.state[s]) & (QUIC_RECOVERY_MARKED | QUIC_RECOVERY_PROBE)) | value)
|
|
283
291
|
}
|
|
284
292
|
}
|
|
285
293
|
|
|
@@ -340,7 +348,30 @@ export class QuicSentPackets {
|
|
|
340
348
|
*/
|
|
341
349
|
setMarked(s: i32, value: boolean): void {
|
|
342
350
|
if (s >= 0 && s < toI32(this.state.length)) {
|
|
343
|
-
|
|
351
|
+
const kept: i32 = toI32(this.state[s]) & (QUIC_RECOVERY_STATE_BITS | QUIC_RECOVERY_PROBE)
|
|
352
|
+
this.state[s] = toU8(kept | (value ? QUIC_RECOVERY_MARKED : 0))
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Whether the packet in slot `s` was a path MTU probe (RFC 8899), whose
|
|
358
|
+
* loss says nothing of congestion.
|
|
359
|
+
*
|
|
360
|
+
* @param s A ring slot, as `onPacketSent`, `ackedSlot` or `lostSlot` answers it; any other index is safe.
|
|
361
|
+
* @returns True when `onProbeSent` marked it; false for an index outside the ring.
|
|
362
|
+
*/
|
|
363
|
+
probeAt(s: i32): boolean {
|
|
364
|
+
return s >= 0 && s < toI32(this.state.length) && (toI32(this.state[s]) & QUIC_RECOVERY_PROBE) !== 0
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Sets whether the packet in slot `s` was a path MTU probe.
|
|
369
|
+
* @internal Read in quic-recovery.ts outside the class.
|
|
370
|
+
*/
|
|
371
|
+
setProbe(s: i32, value: boolean): void {
|
|
372
|
+
if (s >= 0 && s < toI32(this.state.length)) {
|
|
373
|
+
const kept: i32 = toI32(this.state[s]) & (QUIC_RECOVERY_STATE_BITS | QUIC_RECOVERY_MARKED)
|
|
374
|
+
this.state[s] = toU8(kept | (value ? QUIC_RECOVERY_PROBE : 0))
|
|
344
375
|
}
|
|
345
376
|
}
|
|
346
377
|
|
|
@@ -530,6 +561,15 @@ export class QuicRecovery {
|
|
|
530
561
|
ptoCount: i32 = 0
|
|
531
562
|
/** The space the last `onTimeout` acted on, or -1. */
|
|
532
563
|
timeoutSpace: i32 = -1
|
|
564
|
+
/**
|
|
565
|
+
* max_datagram_size (B.1): the largest datagram the connection sends on
|
|
566
|
+
* this path, 1200 until path MTU discovery validates more. The initial and
|
|
567
|
+
* minimum windows and congestion avoidance's step are counted in it.
|
|
568
|
+
* `resetPath`, which the constructor runs, sets it to
|
|
569
|
+
* `QUIC_RECOVERY_DATAGRAM_SIZE`; a field's initializer
|
|
570
|
+
* must be a literal.
|
|
571
|
+
*/
|
|
572
|
+
datagramSize: i64 = 1200
|
|
533
573
|
/** How many congestion events reduced the window, and how many of them were persistent congestion. */
|
|
534
574
|
congestionEvents: i32 = 0
|
|
535
575
|
/**
|
|
@@ -599,6 +639,7 @@ export class QuicRecovery {
|
|
|
599
639
|
* @internal Read by quic.ts.
|
|
600
640
|
*/
|
|
601
641
|
resetPath(): void {
|
|
642
|
+
this.datagramSize = QUIC_RECOVERY_DATAGRAM_SIZE
|
|
602
643
|
this.latestRtt = 0
|
|
603
644
|
this.smoothedRtt = QUIC_RECOVERY_INITIAL_RTT
|
|
604
645
|
this.rttVar = QUIC_RECOVERY_INITIAL_RTT / 2
|
|
@@ -612,6 +653,50 @@ export class QuicRecovery {
|
|
|
612
653
|
this.pacerRtt = QUIC_RECOVERY_INITIAL_RTT * QUIC_RECOVERY_MICROS
|
|
613
654
|
}
|
|
614
655
|
|
|
656
|
+
/**
|
|
657
|
+
* kInitialWindow (§7.2) for the current datagram size: min(10 × size,
|
|
658
|
+
* max(14720, 2 × size)).
|
|
659
|
+
*
|
|
660
|
+
* @returns The initial window in bytes: 12000 at 1200 bytes.
|
|
661
|
+
*/
|
|
662
|
+
initialWindow(): i64 {
|
|
663
|
+
const ten: i64 = 10 * this.datagramSize
|
|
664
|
+
const floor: i64 = quicRecoveryMax(14720, 2 * this.datagramSize)
|
|
665
|
+
return ten < floor ? ten : floor
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
/**
|
|
669
|
+
* kMinimumWindow (§7.2) for the current datagram size: two datagrams.
|
|
670
|
+
*
|
|
671
|
+
* @returns The minimum window in bytes: 2400 at 1200 bytes.
|
|
672
|
+
*/
|
|
673
|
+
minimumWindow(): i64 {
|
|
674
|
+
return 2 * this.datagramSize
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
/**
|
|
678
|
+
* Sets max_datagram_size to `size` bytes, as path MTU discovery validates
|
|
679
|
+
* a larger path or falls back from one (RFC 9002 §7.2). A window still at
|
|
680
|
+
* the old initial window becomes the new one, so a connection that has
|
|
681
|
+
* learnt nothing of the path yet starts from what the new size allows; a
|
|
682
|
+
* window below the new minimum is raised to it. A smaller size keeps the
|
|
683
|
+
* window as it is, and the pacer's held credit is cut to the new burst.
|
|
684
|
+
*
|
|
685
|
+
* @param size The new datagram size in bytes; anything under 1200 is taken as 1200.
|
|
686
|
+
*/
|
|
687
|
+
setDatagramSize(size: i64): void {
|
|
688
|
+
const next: i64 = quicRecoveryMax(size, QUIC_RECOVERY_DATAGRAM_SIZE)
|
|
689
|
+
const atInitial: boolean = this.congestionWindow === this.initialWindow()
|
|
690
|
+
this.datagramSize = next
|
|
691
|
+
if (atInitial) {
|
|
692
|
+
this.congestionWindow = this.initialWindow()
|
|
693
|
+
}
|
|
694
|
+
this.congestionWindow = quicRecoveryMax(this.congestionWindow, this.minimumWindow())
|
|
695
|
+
if (this.pacerBudget > this.initialWindow()) {
|
|
696
|
+
this.pacerBudget = this.initialWindow()
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
|
|
615
700
|
/**
|
|
616
701
|
* Tests ECN again from the start, as on a new path (RFC 9000 §13.4.2).
|
|
617
702
|
* Every packet still in flight loses its mark: those sent on the old
|
|
@@ -664,10 +749,10 @@ export class QuicRecovery {
|
|
|
664
749
|
* Whether the window has room for another full-sized datagram (B.4). The
|
|
665
750
|
* caller sends nothing ack-eliciting while it has not, except a probe.
|
|
666
751
|
*
|
|
667
|
-
* @returns True when the bytes in flight plus
|
|
752
|
+
* @returns True when the bytes in flight plus `datagramSize` bytes fit the congestion window.
|
|
668
753
|
*/
|
|
669
754
|
canSend(): boolean {
|
|
670
|
-
return this.bytesInFlight() +
|
|
755
|
+
return this.bytesInFlight() + this.datagramSize <= this.congestionWindow
|
|
671
756
|
}
|
|
672
757
|
|
|
673
758
|
/**
|
|
@@ -703,6 +788,7 @@ export class QuicRecovery {
|
|
|
703
788
|
sp.fineSent[s] = this.fineNow(now)
|
|
704
789
|
sp.size[s] = size
|
|
705
790
|
sp.setMarked(s, false)
|
|
791
|
+
sp.setProbe(s, false)
|
|
706
792
|
sp.setState(s, QUIC_RECOVERY_SENT)
|
|
707
793
|
sp.count = sp.count + 1
|
|
708
794
|
sp.inFlight = sp.inFlight + 1
|
|
@@ -712,6 +798,22 @@ export class QuicRecovery {
|
|
|
712
798
|
return s
|
|
713
799
|
}
|
|
714
800
|
|
|
801
|
+
/**
|
|
802
|
+
* Marks the packet in `space`'s slot `slot`, just recorded by
|
|
803
|
+
* `onPacketSent`, as a path MTU probe (RFC 8899): it counts in flight and
|
|
804
|
+
* its acknowledgement grows the window, but its loss is no congestion
|
|
805
|
+
* event and no part of persistent congestion (RFC 9000 §14.4).
|
|
806
|
+
*
|
|
807
|
+
* @param space The space's index, as given to `onPacketSent`.
|
|
808
|
+
* @param slot The slot `onPacketSent` answered; -1 or any other index outside the ring does nothing.
|
|
809
|
+
*/
|
|
810
|
+
onProbeSent(space: i32, slot: i32): void {
|
|
811
|
+
const sp: QuicSentPackets | null = this.space(space)
|
|
812
|
+
if (sp !== null) {
|
|
813
|
+
sp.setProbe(slot, true)
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
|
|
715
817
|
/**
|
|
716
818
|
* The ECN codepoint to mark the next packet with (RFC 9000 A.4): ECT(0)
|
|
717
819
|
* for the first `QUIC_RECOVERY_ECN_TESTING_PACKETS` and, once the path is
|
|
@@ -1068,7 +1170,9 @@ export class QuicRecovery {
|
|
|
1068
1170
|
}
|
|
1069
1171
|
let newest: i64 = -1
|
|
1070
1172
|
for (let k: i32 = 0; k < sp.lostCount; k += 1) {
|
|
1071
|
-
|
|
1173
|
+
if (!sp.probeAt(sp.lostSlot(k))) {
|
|
1174
|
+
newest = quicRecoveryMax(newest, sp.timeAt(sp.lostSlot(k)))
|
|
1175
|
+
}
|
|
1072
1176
|
if (sp.markedAt(sp.lostSlot(k)) && this.ecnState !== QUIC_RECOVERY_ECN_CAPABLE) {
|
|
1073
1177
|
this.ecnTestLost = this.ecnTestLost + 1
|
|
1074
1178
|
}
|
|
@@ -1081,9 +1185,12 @@ export class QuicRecovery {
|
|
|
1081
1185
|
) {
|
|
1082
1186
|
this.ecnState = QUIC_RECOVERY_ECN_FAILED
|
|
1083
1187
|
}
|
|
1084
|
-
|
|
1085
|
-
if (
|
|
1086
|
-
this.
|
|
1188
|
+
// A lost path MTU probe is no sign of congestion (RFC 9000 §14.4): only the others count.
|
|
1189
|
+
if (newest >= 0) {
|
|
1190
|
+
this.congestionEvent(newest, now)
|
|
1191
|
+
}
|
|
1192
|
+
if (newest >= 0 && this.persistentCongestion(sp)) {
|
|
1193
|
+
this.congestionWindow = this.minimumWindow()
|
|
1087
1194
|
this.recoveryStart = -1
|
|
1088
1195
|
this.persistentCongestions = this.persistentCongestions + 1
|
|
1089
1196
|
}
|
|
@@ -1109,8 +1216,17 @@ export class QuicRecovery {
|
|
|
1109
1216
|
for (let k: i32 = 0; k < sp.count; k += 1) {
|
|
1110
1217
|
const s: i32 = sp.slot(k)
|
|
1111
1218
|
const state: i32 = sp.stateAt(s)
|
|
1219
|
+
// An acknowledged probe still breaks the run; only a lost one says nothing (RFC 9000 §14.4).
|
|
1220
|
+
if (state === QUIC_RECOVERY_ACKED) {
|
|
1221
|
+
first = -1
|
|
1222
|
+
fresh = false
|
|
1223
|
+
continue
|
|
1224
|
+
}
|
|
1225
|
+
if (sp.probeAt(s)) {
|
|
1226
|
+
continue
|
|
1227
|
+
}
|
|
1112
1228
|
const lost: boolean = state === QUIC_RECOVERY_LOST || state === QUIC_RECOVERY_LOST_NOW
|
|
1113
|
-
if (
|
|
1229
|
+
if (lost && sp.timeAt(s) < this.firstSampleTime) {
|
|
1114
1230
|
first = -1
|
|
1115
1231
|
fresh = false
|
|
1116
1232
|
continue
|
|
@@ -1141,13 +1257,13 @@ export class QuicRecovery {
|
|
|
1141
1257
|
}
|
|
1142
1258
|
this.recoveryStart = now
|
|
1143
1259
|
this.ssthresh = this.congestionWindow / 2
|
|
1144
|
-
this.congestionWindow = quicRecoveryMax(this.ssthresh,
|
|
1260
|
+
this.congestionWindow = quicRecoveryMax(this.ssthresh, this.minimumWindow())
|
|
1145
1261
|
this.congestionEvents = this.congestionEvents + 1
|
|
1146
1262
|
}
|
|
1147
1263
|
|
|
1148
1264
|
/**
|
|
1149
1265
|
* OnPacketAcked (B.5) for slot `s`: in slow start the window grows by the
|
|
1150
|
-
* packet's size, in congestion avoidance by
|
|
1266
|
+
* packet's size, in congestion avoidance by datagramSize × size / window; not at
|
|
1151
1267
|
* all for a packet sent during recovery, or when `inUse` says the window
|
|
1152
1268
|
* was not being used (§7.8).
|
|
1153
1269
|
*/
|
|
@@ -1159,8 +1275,7 @@ export class QuicRecovery {
|
|
|
1159
1275
|
if (this.congestionWindow < this.ssthresh) {
|
|
1160
1276
|
this.congestionWindow = this.congestionWindow + size
|
|
1161
1277
|
} else {
|
|
1162
|
-
this.congestionWindow =
|
|
1163
|
-
this.congestionWindow + (QUIC_RECOVERY_DATAGRAM_SIZE * size) / this.congestionWindow
|
|
1278
|
+
this.congestionWindow = this.congestionWindow + (this.datagramSize * size) / this.congestionWindow
|
|
1164
1279
|
}
|
|
1165
1280
|
}
|
|
1166
1281
|
|
|
@@ -1369,8 +1484,8 @@ export class QuicRecovery {
|
|
|
1369
1484
|
const rtt: i64 = quicRecoveryMax(this.pacerRtt, 1)
|
|
1370
1485
|
const earned: i64 = (elapsed * this.pacerWindow() * 5) / (rtt * 4)
|
|
1371
1486
|
this.pacerBudget = this.pacerBudget + earned
|
|
1372
|
-
if (this.pacerBudget >
|
|
1373
|
-
this.pacerBudget =
|
|
1487
|
+
if (this.pacerBudget > this.initialWindow()) {
|
|
1488
|
+
this.pacerBudget = this.initialWindow()
|
|
1374
1489
|
}
|
|
1375
1490
|
this.pacerTime = at
|
|
1376
1491
|
}
|