@amritk/nish-x86_64-linux 0.38.0 → 0.40.1

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.
Files changed (86) hide show
  1. package/INSTALL.md +74 -129
  2. package/bin/nish +0 -0
  3. package/docs/AI.md +455 -65
  4. package/package.json +1 -1
  5. package/runtime/core/host.d.ts +11 -0
  6. package/runtime/core/host.mjs +35 -0
  7. package/runtime/nish.d.ts +320 -33
  8. package/runtime/nish.h +84 -10
  9. package/runtime/nish.mjs +69 -6
  10. package/runtime/node.mjs +117 -0
  11. package/runtime/page-frame.d.ts +123 -0
  12. package/runtime/page-frame.mjs +736 -0
  13. package/runtime/page-game.d.ts +132 -0
  14. package/runtime/page-game.mjs +738 -0
  15. package/runtime/runtime-aes.c +97 -12
  16. package/runtime/runtime-async.c +43 -10
  17. package/runtime/runtime-bytes.c +88 -4
  18. package/runtime/runtime-checksum.c +207 -15
  19. package/runtime/runtime-net.c +64 -3
  20. package/runtime/runtime-os.c +174 -27
  21. package/runtime/runtime-region.c +94 -10
  22. package/runtime/runtime-sandbox.c +404 -17
  23. package/runtime/runtime-sha256.c +11 -4
  24. package/runtime/runtime-wasm.c +437 -0
  25. package/runtime/runtime.c +5 -0
  26. package/runtime/vite.mjs +1 -1
  27. package/scripts/build.sh +42 -8
  28. package/std/README.md +78 -91
  29. package/std/array.ts +36 -3
  30. package/std/collections.ts +51 -0
  31. package/std/compress/checksum.ts +13 -0
  32. package/std/compress/deflate.ts +0 -2
  33. package/std/crypto/hmac.ts +37 -10
  34. package/std/crypto/p256.ts +1629 -2732
  35. package/std/crypto/p384.ts +3 -1
  36. package/std/crypto/pki.ts +151 -13
  37. package/std/crypto/sha256.ts +34 -6
  38. package/std/crypto/x25519.ts +153 -64
  39. package/std/crypto/x509.ts +120 -10
  40. package/std/host/game.ts +273 -0
  41. package/std/input.ts +56 -0
  42. package/std/json-tokenizer.ts +344 -111
  43. package/std/json-typed.ts +256 -12
  44. package/std/json-value.ts +144 -3
  45. package/std/json.ts +63 -8
  46. package/std/net/fetch.ts +22 -4
  47. package/std/net/handler.ts +130 -16
  48. package/std/net/http-server.ts +3382 -0
  49. package/std/net/http1-client-codec.ts +6 -2
  50. package/std/net/http1-codec.ts +636 -162
  51. package/std/net/http1-server.ts +569 -42
  52. package/std/net/http2-cleartext.ts +526 -0
  53. package/std/net/http2-tls.ts +48 -0
  54. package/std/net/http2.ts +131 -14
  55. package/std/net/http3-server.ts +29 -3
  56. package/std/net/http3.ts +180 -7
  57. package/std/net/postgres-async.ts +1304 -86
  58. package/std/net/postgres-carrier.ts +343 -10
  59. package/std/net/postgres.ts +122 -7
  60. package/std/net/prefork.ts +195 -11
  61. package/std/net/quic-datagram.ts +30 -0
  62. package/std/net/quic-listener.ts +38 -12
  63. package/std/net/quic-packet.ts +19 -6
  64. package/std/net/quic-recovery.ts +373 -27
  65. package/std/net/quic-stream.ts +195 -37
  66. package/std/net/quic.ts +516 -22
  67. package/std/net/router.ts +407 -38
  68. package/std/net/serve.ts +1022 -110
  69. package/std/net/tls/codec.ts +110 -32
  70. package/std/net/tls/record-server.ts +37 -7
  71. package/std/net/tls/verify.ts +19 -1
  72. package/std/net/tls-tcp.ts +56 -1
  73. package/std/net/tls.ts +196 -50
  74. package/std/net/url.ts +83 -35
  75. package/std/net/websocket.ts +129 -19
  76. package/std/net/webtransport.ts +185 -1
  77. package/std/raster.ts +837 -0
  78. package/std/regex.ts +69 -47
  79. package/std/region.ts +62 -11
  80. package/std/release.ts +593 -0
  81. package/std/secret.ts +26 -59
  82. package/std/synth.ts +143 -0
  83. package/std/text.ts +233 -0
  84. package/std/threads.ts +298 -0
  85. package/std/yaml-json.ts +368 -28
  86. package/std/yaml.ts +122 -27
package/std/net/quic.ts CHANGED
@@ -107,12 +107,16 @@
107
107
  *
108
108
  * **Time.** The connection has no clock: `receive`, `takeDatagram` and
109
109
  * `handleTimer` take the caller's monotonic time in milliseconds, and
110
- * `deadline()` says when `handleTimer` is next due. Five things run on it. The
110
+ * `deadline()` says when `handleTimer` is next due. Six things run on it. The
111
111
  * idle timeout (RFC 9000 §10.1) is the smaller of the two sides'
112
112
  * `max_idle_timeout`, never under `QUIC_CONN_IDLE_FLOOR` or three probe
113
113
  * timeouts; once it passes with nothing received, the connection closes
114
114
  * silently (`QUIC_STATE_TIMED_OUT`) and wipes its keys. Loss recovery's timer
115
115
  * declares packets lost by the time threshold or fires the probe timeout.
116
+ * While a stream's send buffer is full behind bytes in flight, an early
117
+ * ACK-eliciting probe goes half a round trip after the last ACK-eliciting
118
+ * packet, so a client whose NAT rebinds while nothing else is sent still
119
+ * answers from its new port (QUIC-12).
116
120
  *
117
121
  * After a key update the previous read keys are kept for a probe timeout
118
122
  * (`recovery.probeTimeout()`), for packets the network reordered, before the
@@ -313,7 +317,10 @@ import {
313
317
  import { QuicAckRanges } from "nish/net/quic-conn-ack"
314
318
  import {
315
319
  QUIC_RECOVERY_APPLICATION_CAPACITY,
320
+ QUIC_RECOVERY_CUBIC,
321
+ QUIC_RECOVERY_GRANULARITY,
316
322
  QUIC_RECOVERY_HANDSHAKE_CAPACITY,
323
+ QUIC_RECOVERY_NEWRENO,
317
324
  QUIC_RECOVERY_TIMEOUT_LOSS,
318
325
  QUIC_RECOVERY_TIMEOUT_PTO,
319
326
  QuicRecovery,
@@ -360,12 +367,24 @@ import { Secret, expose, exposeWith, secret, wipe } from "nish:secret"
360
367
  /** The length of every connection ID this server issues; a short header's DCID is read at this length. */
361
368
  export const QUIC_CONN_CID_LENGTH: i32 = 8
362
369
  /**
363
- * The largest datagram the server sends, and the smallest a client's first
364
- * Initial may arrive in (RFC 9000 §14.1): 1200 bytes, which every QUIC path
365
- * carries, so no path MTU discovery is needed. `takeDatagramInto` needs this
366
- * much room.
370
+ * The most processes a steered UDP group may have (`QuicServerConfig.workerCount`):
371
+ * the worker index is one byte of the connection ID, read modulo the count.
372
+ */
373
+ export const QUIC_WORKER_MAX: i32 = 255
374
+ /**
375
+ * The datagram size every QUIC path carries, and the smallest a client's
376
+ * first Initial may arrive in (RFC 9000 §14.1): 1200 bytes. The server sends
377
+ * no larger datagram until path MTU discovery has validated one (`pathMtu`),
378
+ * and falls back to it when a validated path stops carrying larger ones.
379
+ * `takeDatagramInto` needs this much room.
367
380
  */
368
381
  export const QUIC_CONN_DATAGRAM_SIZE: i32 = 1200
382
+ /**
383
+ * The largest datagram path MTU discovery searches for: 1452 bytes, what a
384
+ * 1500-byte Ethernet MTU carries under an IPv6 and a UDP header. The search
385
+ * also stops at `pathMtuLimit` and at the client's `max_udp_payload_size`.
386
+ */
387
+ export const QUIC_CONN_DATAGRAM_MAX: i32 = 1452
369
388
  /**
370
389
  * How many random bytes the constructor and `reset` take: 32 for the TLS
371
390
  * server random, 32 for the x25519 key, 8 for the first connection ID and
@@ -597,7 +616,11 @@ export interface QuicServerConfig {
597
616
  /**
598
617
  * `initial_max_stream_data_bidi_remote` (and `_uni`, and `_bidi_local`
599
618
  * when the server opens streams): each stream's receive window and the
600
- * size of its buffer each way, 1 to 1 MiB.
619
+ * size of its buffer each way, 1 to 1 MiB. The send buffer holds what the
620
+ * client has not acknowledged, so it bounds a stream's send-side memory
621
+ * and its bytes in flight: behind one lost packet a stream sends nothing
622
+ * new until the resend is acknowledged, and the connection sends an early
623
+ * ACK-eliciting probe meanwhile so a client's NAT rebinding is still seen.
601
624
  */
602
625
  maxStreamData: i64
603
626
  /** `initial_max_streams_bidi`: how many bidirectional streams the client may have open at once, 0 to 1024. */
@@ -631,8 +654,61 @@ export interface QuicServerConfig {
631
654
  statelessResetKey: u8[]
632
655
  /** The key `nish/net/quic-listener` authenticates its Retry tokens with (§8.1.4), `QUIC_CONN_STATIC_KEY_SIZE` bytes. */
633
656
  retryTokenKey: u8[]
657
+ /**
658
+ * This process's index k in a prefork group whose UDP sockets are steered
659
+ * by connection ID (`preforkIndex`), or -1 outside one. With a valid pair,
660
+ * every connection ID the server issues carries k in byte 0, so the
661
+ * kernel hands the connection's packets to this process whatever address
662
+ * they come from. Copy it from the supervisor's flags, never compute it.
663
+ */
664
+ workerIndex: i32
665
+ /**
666
+ * How many processes N share the steered UDP port (`preforkUdpCount`), or 0
667
+ * outside a prefork group. Valid with `workerIndex` when 0 <= k < N <= 255,
668
+ * or both unset (-1 and 0); `QuicListener` and `Http3Server` panic on any
669
+ * other pair.
670
+ */
671
+ workerCount: i32
672
+ /**
673
+ * The congestion controller every connection runs: `QUIC_RECOVERY_NEWRENO`
674
+ * (RFC 9002) or `QUIC_RECOVERY_CUBIC` (RFC 9438), from
675
+ * `nish/net/quic-recovery`; `QUIC_RECOVERY_DEFAULT` names the one to pass
676
+ * without a reason to pick. Any other value does not fit, and a connection
677
+ * made with it closes at once.
678
+ */
679
+ congestion: i32
680
+ }
681
+
682
+ /**
683
+ * Panics, with the pair in the message, unless `config`'s worker fields are
684
+ * both unset (`workerIndex` -1 and `workerCount` 0) or name a worker of a
685
+ * steered group (0 <= k < N <= 255). `QuicListener` calls it when it is built,
686
+ * before it reads a datagram, so an `Http3Server` panics through its listener.
687
+ *
688
+ * @param config The configuration whose `workerIndex` and `workerCount` are checked.
689
+ */
690
+ export const quicWorkerCheck = (config: QuicServerConfig): void => {
691
+ const k: i32 = config.workerIndex
692
+ const n: i32 = config.workerCount
693
+ if ((k === -1 && n === 0) || (k >= 0 && k < n && n <= QUIC_WORKER_MAX)) {
694
+ return
695
+ }
696
+ panic(`nish/net/quic: workerIndex ${k} and workerCount ${n}, not 0 <= k < n <= ${QUIC_WORKER_MAX}`)
634
697
  }
635
698
 
699
+ /**
700
+ * The byte a server writes at the start of every connection ID it issues:
701
+ * `config.workerIndex` when the pair names a worker of a steered group, -1
702
+ * (write nothing) otherwise.
703
+ *
704
+ * @param config The server's configuration.
705
+ * @returns The worker index k, from 0 to 254, or -1 when the IDs carry no worker.
706
+ */
707
+ export const quicWorkerByte = (config: QuicServerConfig): i32 =>
708
+ config.workerIndex >= 0 && config.workerIndex < config.workerCount && config.workerCount <= QUIC_WORKER_MAX
709
+ ? config.workerIndex
710
+ : -1
711
+
636
712
  /** One run of stream data the client sent, in order, as `readStream` answers it: `fin` when it ends the stream. */
637
713
  export class QuicStreamData {
638
714
  /** The RFC 9000 stream ID the bytes arrived on. */
@@ -1349,6 +1425,14 @@ const quicConnEphemeralIn = (held: u8[], entropy: u8[]): i32 => {
1349
1425
  return 0
1350
1426
  }
1351
1427
 
1428
+ /** Writes the worker byte (`quicWorkerByte`) into `cid[0]`, when the configuration names a worker. */
1429
+ const quicWorkerMark = (config: QuicServerConfig, cid: u8[]): void => {
1430
+ const k: i32 = quicWorkerByte(config)
1431
+ if (k >= 0 && toI32(cid.length) > 0) {
1432
+ cid[0] = toU8(k)
1433
+ }
1434
+ }
1435
+
1352
1436
  /** Whether the configuration's limits are ones this module can honour. */
1353
1437
  const quicConnConfigFits = (config: QuicServerConfig): boolean =>
1354
1438
  config.maxStreamData >= 1 &&
@@ -1369,6 +1453,7 @@ const quicConnConfigFits = (config: QuicServerConfig): boolean =>
1369
1453
  config.maxIdleTimeout <= QUIC_MAX_VARINT &&
1370
1454
  config.activeConnectionIdLimit >= 2 &&
1371
1455
  config.activeConnectionIdLimit <= 8 &&
1456
+ (config.congestion === QUIC_RECOVERY_NEWRENO || config.congestion === QUIC_RECOVERY_CUBIC) &&
1372
1457
  toI32(config.statelessResetKey.length) === QUIC_CONN_STATIC_KEY_SIZE
1373
1458
 
1374
1459
  /**
@@ -1520,6 +1605,12 @@ export class QuicConnection {
1520
1605
  challengeUntil: i64 = -1
1521
1606
  /** How many PATH_CHALLENGE data have been drawn over the connection; see `challengeData`. */
1522
1607
  challengesDrawn: i64 = 0
1608
+ /**
1609
+ * The Application Data space's largest acknowledged packet number when
1610
+ * the last early probe was asked for (`earlyProbeAt`), so one goes per
1611
+ * acknowledgment that moves it; -2 before any.
1612
+ */
1613
+ earlyProbeAcked: i64 = -2
1523
1614
  private frame: QuicFrame
1524
1615
  /** The header and the packet numbers of the packet being read, reused for every one. */
1525
1616
  private header: QuicHeader
@@ -1664,6 +1755,49 @@ export class QuicConnection {
1664
1755
  /** Whether the packet being read carries a non-probing frame (§9.1), and whether a packet of the datagram moves the connection (§9.3). */
1665
1756
  private nonProbing: boolean = false
1666
1757
  private migrateOwed: boolean = false
1758
+ /** The packet number of the probe in flight. */
1759
+ private pmtuProbePn: i64 = -1
1760
+ /**
1761
+ * Path MTU discovery (RFC 9000 §14.3, RFC 8899): once the handshake is
1762
+ * confirmed and the path validated, the server probes for a datagram
1763
+ * larger than 1200 bytes with a PING padded to the size being tried, sent
1764
+ * only when nothing else is due, so a probe never holds data back. An
1765
+ * acknowledged probe validates its size as `pathMtu`, which every later
1766
+ * datagram may then fill; three lost probes of a size end the search below
1767
+ * it. A lost probe is no congestion signal (§14.4). Three loss events that
1768
+ * each lose a packet larger than 1200 bytes, with none of that size
1769
+ * acknowledged between, are taken for a black hole: `pathMtu` falls back
1770
+ * to 1200 and the search resumes below the size that stopped getting
1771
+ * through. A new address starts again from 1200.
1772
+ *
1773
+ * `pathMtuLimit` is the carrier's to lower, for an interface whose MTU
1774
+ * carries less than `QUIC_CONN_DATAGRAM_MAX`: before the first datagram
1775
+ * by setting it, and at any time through `setPathMtuLimit`, which also
1776
+ * takes a `pathMtu` above it down to it. The next probe keeps under it,
1777
+ * and an acknowledged probe raises `pathMtu` no higher than it. 1200 or
1778
+ * less turns discovery off. `reset` keeps it.
1779
+ */
1780
+ pathMtuLimit: i32 = 1452
1781
+ /** The largest datagram validated on the current path: 1200 until a probe is acknowledged. */
1782
+ pathMtu: i32 = 1200
1783
+ /** Path MTU probes sent. */
1784
+ pmtuProbes: i32 = 0
1785
+ /** Path MTU probes declared lost. */
1786
+ pmtuProbesLost: i32 = 0
1787
+ /** Times a black hole sent `pathMtu` back to 1200. */
1788
+ pmtuBlackHoles: i32 = 0
1789
+ /** The search's validated floor and the largest size not yet ruled out. */
1790
+ private pmtuLow: i32 = 0
1791
+ private pmtuHigh: i32 = 0
1792
+ /** The size the next probe tries, 0 when the search is over, and the size of the probe in flight, 0 for none. */
1793
+ private pmtuNext: i32 = 0
1794
+ private pmtuProbeSize: i32 = 0
1795
+ /** Probes of `pmtuNext` lost so far, and loss events in a row that lost a packet larger than 1200 bytes. */
1796
+ private pmtuTries: i32 = 0
1797
+ private pmtuSuspect: i32 = 0
1798
+ /** Whether the search has its bounds for this path, and whether the packet being sealed is a probe. */
1799
+ private pmtuStarted: boolean = false
1800
+ private pmtuSealing: boolean = false
1667
1801
 
1668
1802
  /**
1669
1803
  * A connection under `config`, with `entropy` its `QUIC_CONN_ENTROPY_SIZE`
@@ -1696,6 +1830,8 @@ export class QuicConnection {
1696
1830
  QUIC_CONN_LOCAL_CIDS
1697
1831
  )
1698
1832
  this.recovery = new QuicRecovery()
1833
+ this.recovery.controller =
1834
+ config.congestion === QUIC_RECOVERY_CUBIC ? QUIC_RECOVERY_CUBIC : QUIC_RECOVERY_NEWRENO
1699
1835
  this.defaultParameters = new QuicTransportParameters()
1700
1836
  this.peerParameters = this.defaultParameters
1701
1837
  // A configuration that does not fit closes the connection at once (see
@@ -1708,7 +1844,7 @@ export class QuicConnection {
1708
1844
  this.streams = new QuicStreams(streams, uni, local, buffer, fits ? config.maxData : QUIC_CONN_NONE)
1709
1845
  // The rings are made only when DATAGRAM frames are offered at all.
1710
1846
  const datagrams: i32 = fits && config.maxDatagramFrameSize > 0 ? QUIC_CONN_DATAGRAM_QUEUE : 0
1711
- this.datagramsOut = new QuicDatagramQueue(datagrams, QUIC_CONN_DATAGRAM_SIZE)
1847
+ this.datagramsOut = new QuicDatagramQueue(datagrams, QUIC_CONN_DATAGRAM_MAX)
1712
1848
  this.datagramsIn = new QuicDatagramQueue(
1713
1849
  datagrams,
1714
1850
  fits ? toI32(config.maxDatagramFrameSize) : QUIC_CONN_FROM
@@ -1793,6 +1929,7 @@ export class QuicConnection {
1793
1929
  this.appReadSlot = 0
1794
1930
  this.appWriteSlot = 0
1795
1931
  this.earlyResends = 0
1932
+ this.earlyProbeAcked = -2
1796
1933
  this.resendLevel = -1
1797
1934
  this.now = 0
1798
1935
  this.idleSince = -1
@@ -1833,6 +1970,10 @@ export class QuicConnection {
1833
1970
  this.writePhase = false
1834
1971
  this.cryptoArrived = false
1835
1972
  this.topUpOwed = false
1973
+ this.pmtuProbes = 0
1974
+ this.pmtuProbesLost = 0
1975
+ this.pmtuBlackHoles = 0
1976
+ this.pmtuReset()
1836
1977
  this.begin(entropy)
1837
1978
  }
1838
1979
 
@@ -1841,6 +1982,7 @@ export class QuicConnection {
1841
1982
  quicCidCopy(this.serverRandom, entropy, 0, 32)
1842
1983
  exposeWith(this.ephemeral, entropy, quicConnEphemeralIn)
1843
1984
  quicCidCopy(this.localScid, entropy, 64, QUIC_CONN_CID_LENGTH)
1985
+ quicWorkerMark(this.config, this.localScid)
1844
1986
  quicCidCopy(this.cidSeed, entropy, 72, 32)
1845
1987
  const fits: boolean = toI32(entropy.length) === QUIC_CONN_ENTROPY_SIZE && quicConnConfigFits(this.config)
1846
1988
  secureZero(entropy)
@@ -2093,6 +2235,7 @@ export class QuicConnection {
2093
2235
  // Loss recovery's timer runs after the datagram, so an acknowledgement
2094
2236
  // it carries settles what it acknowledges before a probe is owed.
2095
2237
  this.runRecoveryTimer()
2238
+ this.runEarlyProbe()
2096
2239
  return this.closed() ? this.error : QUIC_ERROR_NO_ERROR
2097
2240
  }
2098
2241
 
@@ -2824,7 +2967,11 @@ export class QuicConnection {
2824
2967
  return
2825
2968
  }
2826
2969
  for (let k: i32 = 0; k < sent.ackedCount; k += 1) {
2827
- this.untrack(space, sent.ackedSlot(k))
2970
+ const slot: i32 = sent.ackedSlot(k)
2971
+ this.untrack(space, slot)
2972
+ if (space.level === TLS_LEVEL_APPLICATION) {
2973
+ this.pmtuAcked(sent, slot)
2974
+ }
2828
2975
  }
2829
2976
  this.packetsLost(space, sent)
2830
2977
  }
@@ -2867,9 +3014,222 @@ export class QuicConnection {
2867
3014
 
2868
3015
  /** Every packet of `space` that loss recovery's last call declared lost: what each carried is queued again. */
2869
3016
  private packetsLost(space: QuicConnSpace, sent: QuicSentPackets): void {
3017
+ let large: boolean = false
2870
3018
  for (let k: i32 = 0; k < sent.lostCount; k += 1) {
2871
- this.requeue(space, sent.lostSlot(k))
3019
+ const slot: i32 = sent.lostSlot(k)
3020
+ this.requeue(space, slot)
3021
+ if (space.level !== TLS_LEVEL_APPLICATION) {
3022
+ continue
3023
+ }
3024
+ if (sent.probeAt(slot)) {
3025
+ this.pmtuProbeLost(sent.pnAt(slot))
3026
+ } else if (sent.sizeAt(slot) > QUIC_CONN_DATAGRAM_SIZE) {
3027
+ large = true
3028
+ }
3029
+ }
3030
+ if (large) {
3031
+ this.pmtuLargeLost()
3032
+ }
3033
+ }
3034
+
3035
+ // ---- Path MTU discovery -------------------------------------------------------
3036
+
3037
+ /**
3038
+ * The largest datagram the server sends now: `pathMtu`, or 1200 while a
3039
+ * new path is being validated.
3040
+ *
3041
+ * @returns The size in bytes, from 1200 to `QUIC_CONN_DATAGRAM_MAX`.
3042
+ */
3043
+ datagramSize(): i32 {
3044
+ return this.pathValidating ? QUIC_CONN_DATAGRAM_SIZE : this.pathMtu
3045
+ }
3046
+
3047
+ /**
3048
+ * Sets `pathMtuLimit`, for a carrier whose interface MTU changed. A
3049
+ * `pathMtu` above the new limit falls to it, no lower than 1200, and
3050
+ * recovery's datagram size with it; the search goes on below it.
3051
+ *
3052
+ * @param limit The largest datagram the interface carries, in bytes; 1200 or less turns discovery off.
3053
+ */
3054
+ setPathMtuLimit(limit: i32): void {
3055
+ this.pathMtuLimit = limit
3056
+ if (this.pathMtu > limit) {
3057
+ this.pathMtu = limit > QUIC_CONN_DATAGRAM_SIZE ? limit : QUIC_CONN_DATAGRAM_SIZE
3058
+ this.pmtuLow = this.pathMtu
3059
+ this.recovery.setDatagramSize(toI64(this.pathMtu))
3060
+ }
3061
+ }
3062
+
3063
+ /**
3064
+ * Forgets what discovery learnt of the path: `pathMtu` is 1200 again, and
3065
+ * the search starts afresh. Each caller has just reset loss recovery's
3066
+ * path, whose datagram size that puts back to 1200 too.
3067
+ */
3068
+ private pmtuReset(): void {
3069
+ this.pathMtu = QUIC_CONN_DATAGRAM_SIZE
3070
+ this.pmtuStarted = false
3071
+ this.pmtuLow = QUIC_CONN_DATAGRAM_SIZE
3072
+ this.pmtuHigh = QUIC_CONN_DATAGRAM_SIZE
3073
+ this.pmtuNext = 0
3074
+ this.pmtuProbeSize = 0
3075
+ this.pmtuProbePn = -1
3076
+ this.pmtuTries = 0
3077
+ this.pmtuSuspect = 0
3078
+ }
3079
+
3080
+ /**
3081
+ * Whether a probe of `pmtuNext` bytes is due in `room` bytes: the
3082
+ * handshake confirmed, the path validated, the search not over, no probe
3083
+ * in flight, no loss-recovery probe owed, and room in the record and the
3084
+ * congestion window. The search's bounds are taken the first time:
3085
+ * `pathMtuLimit`, `QUIC_CONN_DATAGRAM_MAX` and the client's
3086
+ * `max_udp_payload_size`, whichever is least.
3087
+ */
3088
+ private pmtuDue(room: i32): boolean {
3089
+ if (!this.handshakeComplete || this.state !== QUIC_STATE_CONNECTED || this.pathValidating) {
3090
+ return false
2872
3091
  }
3092
+ if (!this.pmtuStarted) {
3093
+ this.pmtuStarted = true
3094
+ let high: i64 = toI64(this.pathMtuLimit)
3095
+ if (high > toI64(QUIC_CONN_DATAGRAM_MAX)) {
3096
+ high = toI64(QUIC_CONN_DATAGRAM_MAX)
3097
+ }
3098
+ if (high > this.peerParameters.maxUdpPayloadSize) {
3099
+ high = this.peerParameters.maxUdpPayloadSize
3100
+ }
3101
+ this.pmtuLow = this.pathMtu
3102
+ this.pmtuHigh = high > toI64(this.pathMtu) ? toI32(high) : this.pathMtu
3103
+ this.pmtuNext = this.pmtuHigh > this.pmtuLow ? this.pmtuHigh : 0
3104
+ }
3105
+ // A limit the carrier lowered after the search began holds from the next probe.
3106
+ if (this.pmtuHigh > this.pathMtuLimit && this.pmtuHigh > this.pmtuLow) {
3107
+ this.pmtuHigh = this.pathMtuLimit > this.pmtuLow ? this.pathMtuLimit : this.pmtuLow
3108
+ this.pmtuNext = this.pmtuHigh > this.pmtuLow ? this.pmtuHigh : 0
3109
+ this.pmtuTries = 0
3110
+ }
3111
+ const size: i32 = this.pmtuNext
3112
+ const sent: QuicSentPackets | null = this.recovery.space(TLS_LEVEL_APPLICATION)
3113
+ return (
3114
+ size > 0 &&
3115
+ size <= room &&
3116
+ this.pmtuProbeSize === 0 &&
3117
+ this.application.probes === 0 &&
3118
+ sent !== null &&
3119
+ !sent.full() &&
3120
+ this.recovery.bytesInFlight() + toI64(size) <= this.recovery.congestionWindow
3121
+ )
3122
+ }
3123
+
3124
+ /**
3125
+ * A path MTU probe of `size` bytes into `out` at `at`: a 1-RTT packet of
3126
+ * a PING and PADDING to `size`, sealed and recorded as a probe. Answers
3127
+ * its length, or 0 when it could not be sealed.
3128
+ */
3129
+ private buildPmtuProbe(out: u8[], at: i32, size: i32): i32 {
3130
+ const space: QuicConnSpace = this.application
3131
+ const overhead: i32 = this.overhead(space)
3132
+ if (overhead === 0 || overhead + 1 > size) {
3133
+ return 0
3134
+ }
3135
+ space.clearStaged()
3136
+ const payloadStart: i32 = at + overhead - QUIC_AEAD_TAG_SIZE
3137
+ const payloadEnd: i32 = at + size - QUIC_AEAD_TAG_SIZE
3138
+ const ping: i32 = quicPutTypeOnly(out, payloadStart, payloadEnd, QUIC_FRAME_PING)
3139
+ if (ping < 0) {
3140
+ return 0
3141
+ }
3142
+ space.stagedEliciting = true
3143
+ const pn: i64 = space.nextPn
3144
+ this.pmtuSealing = true
3145
+ const n: i32 = this.sealAt(space, out, at, quicPutPadding(out, ping, payloadEnd - ping))
3146
+ this.pmtuSealing = false
3147
+ if (n <= 0) {
3148
+ return 0
3149
+ }
3150
+ this.pmtuProbeSize = n
3151
+ this.pmtuProbePn = pn
3152
+ if (this.pmtuProbes < 2147483647) {
3153
+ this.pmtuProbes = this.pmtuProbes + 1
3154
+ }
3155
+ if (!this.elicitingSent) {
3156
+ this.idleSince = this.now
3157
+ this.elicitingSent = true
3158
+ }
3159
+ this.bytesSent = this.bytesSent + toI64(n)
3160
+ this.notePathSent(n)
3161
+ return n
3162
+ }
3163
+
3164
+ /**
3165
+ * An acknowledged 1-RTT packet in `sent`'s slot `slot`: the probe in
3166
+ * flight validates its size, no more than `pathMtuLimit` (which may have
3167
+ * fallen while it flew), and a packet larger than 1200 bytes shows the
3168
+ * path still carries one, which clears the black-hole count.
3169
+ */
3170
+ private pmtuAcked(sent: QuicSentPackets, slot: i32): void {
3171
+ if (sent.probeAt(slot)) {
3172
+ if (this.pmtuProbeSize > 0 && sent.pnAt(slot) === this.pmtuProbePn) {
3173
+ const probed: i32 = this.pmtuProbeSize
3174
+ const size: i32 = probed < this.pathMtuLimit ? probed : this.pathMtuLimit
3175
+ this.pmtuProbeSize = 0
3176
+ this.pmtuSuspect = 0
3177
+ if (size > this.pathMtu) {
3178
+ this.pathMtu = size
3179
+ this.recovery.setDatagramSize(toI64(size))
3180
+ }
3181
+ this.pmtuLow = size > this.pmtuLow ? size : this.pmtuLow
3182
+ this.pmtuStep()
3183
+ }
3184
+ } else if (sent.sizeAt(slot) > QUIC_CONN_DATAGRAM_SIZE) {
3185
+ this.pmtuSuspect = 0
3186
+ }
3187
+ }
3188
+
3189
+ /** The probe numbered `pn` was lost: after three of one size, the search goes on below it. */
3190
+ private pmtuProbeLost(pn: i64): void {
3191
+ if (this.pmtuProbesLost < 2147483647) {
3192
+ this.pmtuProbesLost = this.pmtuProbesLost + 1
3193
+ }
3194
+ if (this.pmtuProbeSize === 0 || pn !== this.pmtuProbePn) {
3195
+ return
3196
+ }
3197
+ const size: i32 = this.pmtuProbeSize
3198
+ this.pmtuProbeSize = 0
3199
+ this.pmtuTries = this.pmtuTries + 1
3200
+ if (this.pmtuTries >= 3) {
3201
+ this.pmtuHigh = size - 1
3202
+ this.pmtuStep()
3203
+ }
3204
+ }
3205
+
3206
+ /**
3207
+ * A loss event lost a packet larger than 1200 bytes: the third in a row
3208
+ * with none of that size acknowledged takes the path for a black hole
3209
+ * (RFC 8899 §4.3), and `pathMtu` falls back to 1200.
3210
+ */
3211
+ private pmtuLargeLost(): void {
3212
+ this.pmtuSuspect = this.pmtuSuspect + 1
3213
+ if (this.pmtuSuspect < 3 || this.pathMtu <= QUIC_CONN_DATAGRAM_SIZE) {
3214
+ return
3215
+ }
3216
+ const failed: i32 = this.pathMtu
3217
+ this.pathMtu = QUIC_CONN_DATAGRAM_SIZE
3218
+ this.recovery.setDatagramSize(toI64(QUIC_CONN_DATAGRAM_SIZE))
3219
+ this.pmtuSuspect = 0
3220
+ this.pmtuProbeSize = 0
3221
+ this.pmtuLow = QUIC_CONN_DATAGRAM_SIZE
3222
+ this.pmtuHigh = failed - 1
3223
+ if (this.pmtuBlackHoles < 2147483647) {
3224
+ this.pmtuBlackHoles = this.pmtuBlackHoles + 1
3225
+ }
3226
+ this.pmtuStep()
3227
+ }
3228
+
3229
+ /** The next size to try, halfway between the bounds, or 0 when they are within 16 bytes. */
3230
+ private pmtuStep(): void {
3231
+ this.pmtuTries = 0
3232
+ this.pmtuNext = this.pmtuHigh - this.pmtuLow < 16 ? 0 : (this.pmtuLow + this.pmtuHigh + 1) / 2
2873
3233
  }
2874
3234
 
2875
3235
  /**
@@ -3361,6 +3721,7 @@ export class QuicConnection {
3361
3721
  }
3362
3722
  while (this.cids.nextLocal < QUIC_CONN_MAX_ISSUED_CIDS && toI64(this.cids.activeLocal()) < want) {
3363
3723
  this.deriveConnectionId(this.cids.nextLocal)
3724
+ quicWorkerMark(this.config, this.cidScratch)
3364
3725
  quicConnResetTokenInto(
3365
3726
  this.kdf.sha256,
3366
3727
  this.config.statelessResetKey,
@@ -3456,7 +3817,8 @@ export class QuicConnection {
3456
3817
  /**
3457
3818
  * When `handleTimer` is next due, in the caller's milliseconds: the idle
3458
3819
  * timeout, loss recovery's timer (a time-threshold loss or the probe
3459
- * timeout), the end of a key update's probe timeout, or, while a path is
3820
+ * timeout), an early probe while a stream's send buffer is full behind
3821
+ * bytes in flight, the end of a key update's probe timeout, or, while a path is
3460
3822
  * validated, its PATH_CHALLENGE's resend or the end of its validation,
3461
3823
  * whichever comes first; once the connection has closed, the end of its closing or
3462
3824
  * draining period, when its keys are wiped. -1 when nothing is timed:
@@ -3482,6 +3844,10 @@ export class QuicConnection {
3482
3844
  if (recovery >= 0 && (due < 0 || recovery < due)) {
3483
3845
  due = recovery
3484
3846
  }
3847
+ const early: i64 = this.earlyProbeAt()
3848
+ if (early >= 0 && (due < 0 || early < due)) {
3849
+ due = early
3850
+ }
3485
3851
  if (this.pathValidating) {
3486
3852
  const path: i64 =
3487
3853
  this.challengeResendAt < this.challengeUntil ? this.challengeResendAt : this.challengeUntil
@@ -3527,7 +3893,10 @@ export class QuicConnection {
3527
3893
  * Past loss recovery's timer, packets lost by the time threshold have their
3528
3894
  * frames queued again, or a probe timeout queues every space's packets in
3529
3895
  * flight and asks for a probe (RFC 9002 §6.1.2, §6.2.4): `takeDatagram` then
3530
- * sends it. `receive` and `takeDatagram` run it themselves. Time never runs
3896
+ * sends it. Past the early probe's time, while a stream's send buffer is
3897
+ * full behind bytes in flight, a probe is asked for the same way, so the
3898
+ * client answers from wherever its NAT now sends it.
3899
+ * `receive` and `takeDatagram` run it themselves. Time never runs
3531
3900
  * backwards here: an earlier `now` than one already given counts as that one.
3532
3901
  *
3533
3902
  * @param now The caller's monotonic time in milliseconds.
@@ -3535,6 +3904,7 @@ export class QuicConnection {
3535
3904
  handleTimer(now: i64): void {
3536
3905
  this.runClocks(now)
3537
3906
  this.runRecoveryTimer()
3907
+ this.runEarlyProbe()
3538
3908
  }
3539
3909
 
3540
3910
  /**
@@ -3758,6 +4128,7 @@ export class QuicConnection {
3758
4128
  this.endValidation()
3759
4129
  if (!portOnly) {
3760
4130
  this.recovery.resetPath()
4131
+ this.pmtuReset()
3761
4132
  }
3762
4133
  this.recovery.restartEcn()
3763
4134
  }
@@ -3878,6 +4249,61 @@ export class QuicConnection {
3878
4249
  return this.sealAt(space, out, at, quicPutPadding(out, next, payloadEnd - next))
3879
4250
  }
3880
4251
 
4252
+ /**
4253
+ * When a sender blocked by its own stream buffer sends an ack-eliciting
4254
+ * probe, or -1 when it need not. A stream whose send buffer is full
4255
+ * behind a hole (`QuicStreams.bufferBlocked`) sends nothing new until
4256
+ * the hole is acknowledged; once the client has acknowledged everything
4257
+ * in flight it has nothing to acknowledge and sends nothing either, so a
4258
+ * NAT rebind in that gap is never seen and every later packet, burst and
4259
+ * probe timeout alike, goes to the old binding. Half a smoothed RTT after
4260
+ * the last ack-eliciting packet, with the Application Data space's
4261
+ * largest acknowledged packet moved since the last such probe, one
4262
+ * datagram goes regardless of the window (a PING when nothing else is
4263
+ * queued), so the client always has one to answer, from wherever it now
4264
+ * is (RFC 9000 §9.3). One per acknowledgment that advances the space, so
4265
+ * up to two full datagrams a round trip, a buffer-limited transfer that
4266
+ * lost nothing included, since the probe carries any other stream's queued
4267
+ * data; none while the sent ring is full, where a probe would resend the
4268
+ * oldest packet in flight instead. After a validated migration
4269
+ * `resetPath` puts the smoothed RTT back to the 333 ms initial RTT, so the
4270
+ * probe waits about 166 ms until the new path's first sample. The probe
4271
+ * timeout still runs as before. With the NAT beside the client, a rebind after the probe
4272
+ * arrives and before the next burst does is still missed: only the client
4273
+ * sending can close that half round trip.
4274
+ */
4275
+ private earlyProbeAt(): i64 {
4276
+ if (this.state !== QUIC_STATE_CONNECTED || this.application.probes > 0) {
4277
+ return -1
4278
+ }
4279
+ const sent: QuicSentPackets | null = this.recovery.space(TLS_LEVEL_APPLICATION)
4280
+ if (
4281
+ sent === null ||
4282
+ sent.inFlight === 0 ||
4283
+ sent.lastAckEliciting < 0 ||
4284
+ sent.largestAcked <= this.earlyProbeAcked ||
4285
+ sent.full() ||
4286
+ !this.streams.bufferBlocked()
4287
+ ) {
4288
+ return -1
4289
+ }
4290
+ const half: i64 = this.recovery.smoothedRtt / 2
4291
+ return sent.lastAckEliciting + (half > QUIC_RECOVERY_GRANULARITY ? half : QUIC_RECOVERY_GRANULARITY)
4292
+ }
4293
+
4294
+ /** The early probe of `earlyProbeAt`, if it is due. */
4295
+ private runEarlyProbe(): void {
4296
+ const at: i64 = this.earlyProbeAt()
4297
+ if (at < 0 || this.now < at) {
4298
+ return
4299
+ }
4300
+ const sent: QuicSentPackets | null = this.recovery.space(TLS_LEVEL_APPLICATION)
4301
+ if (sent !== null) {
4302
+ this.earlyProbeAcked = sent.largestAcked
4303
+ this.application.probes = 1
4304
+ }
4305
+ }
4306
+
3881
4307
  /** Loss recovery's timer, if it is due (RFC 9002 §6.2, A.9). */
3882
4308
  private runRecoveryTimer(): void {
3883
4309
  if (this.closed() || this.state === QUIC_STATE_WAIT_INITIAL) {
@@ -4113,15 +4539,17 @@ export class QuicConnection {
4113
4539
  /**
4114
4540
  * The largest DATAGRAM payload `sendDatagram` takes now: what fits the
4115
4541
  * client's `max_datagram_frame_size` with the frame's type and Length, and
4116
- * a 1-RTT packet of `QUIC_CONN_DATAGRAM_SIZE` with the longest packet
4117
- * number; 0 when the client takes none, or the server sends none.
4542
+ * a 1-RTT packet of `datagramSize()` with the longest packet number; 0
4543
+ * when the client takes none, or the server sends none. It grows when
4544
+ * path MTU discovery validates a larger datagram, and shrinks again on a
4545
+ * fall back to 1200, which drops a queued payload that no longer fits.
4118
4546
  *
4119
- * @returns The payload size in bytes, 0 up to a little under `QUIC_CONN_DATAGRAM_SIZE`.
4547
+ * @returns The payload size in bytes, 0 up to a little under `datagramSize()`.
4120
4548
  */
4121
4549
  maxDatagramPayload(): i32 {
4122
4550
  const entry: QuicCidEntry | null = this.cids.currentPeerEntry()
4123
4551
  const cid: i32 = entry !== null ? entry.length : QUIC_CONN_FROM
4124
- let limit: i64 = toI64(QUIC_CONN_DATAGRAM_SIZE - 1 - cid - 4 - QUIC_AEAD_TAG_SIZE)
4552
+ let limit: i64 = toI64(this.datagramSize() - 1 - cid - 4 - QUIC_AEAD_TAG_SIZE)
4125
4553
  if (this.peerMaxDatagramFrame < limit) {
4126
4554
  limit = this.peerMaxDatagramFrame
4127
4555
  }
@@ -4195,6 +4623,8 @@ export class QuicConnection {
4195
4623
  /**
4196
4624
  * The next datagram to send, or `null` when nothing is due: the
4197
4625
  * allocating form of `takeDatagramInto`, which a test or a recording uses.
4626
+ * It is held to `QUIC_CONN_DATAGRAM_SIZE` bytes, so it never sends a path
4627
+ * MTU probe nor fills a larger validated path.
4198
4628
  *
4199
4629
  * @param now The caller's monotonic time in milliseconds.
4200
4630
  * @returns A new array the caller owns, at most `QUIC_CONN_DATAGRAM_SIZE` bytes, or `null`.
@@ -4207,7 +4637,8 @@ export class QuicConnection {
4207
4637
 
4208
4638
  /**
4209
4639
  * Writes the next datagram to send into `out` at `at`, which needs
4210
- * `QUIC_CONN_DATAGRAM_SIZE` bytes of room, and answers its length, or 0 when
4640
+ * `QUIC_CONN_DATAGRAM_SIZE` bytes of room and may take up to `datagramSize()`,
4641
+ * or a path MTU probe's size (see `takeDatagramWithin`), and answers its length, or 0 when
4211
4642
  * nothing is due (or the room is not there). Call it until it answers 0 after
4212
4643
  * every `receive`, `sign`, write and `close`. It coalesces an Initial, a
4213
4644
  * Handshake and a 1-RTT packet as each has something to carry, pads a
@@ -4229,19 +4660,49 @@ export class QuicConnection {
4229
4660
  * carrier that paces calls `nish/net/quic-listener`'s
4230
4661
  * `quicListenerTakeFlight` instead.
4231
4662
  *
4663
+ * Its contract changed with path MTU discovery: it writes up to the
4664
+ * room in `out` from `at`, capped at `datagramSize()` (never past
4665
+ * `pathMtuLimit` or `QUIC_CONN_DATAGRAM_MAX`), where it once wrote at
4666
+ * most 1200 bytes. A carrier that sizes its buffer from
4667
+ * `QUIC_CONN_DATAGRAM_SIZE` keeps getting datagrams of at most that size
4668
+ * and is never probed past it; one that hands over a larger buffer must
4669
+ * send all of what comes back.
4670
+ *
4232
4671
  * @param out Where the datagram is written.
4233
4672
  * @param at Where in `out` it starts; `out` needs `QUIC_CONN_DATAGRAM_SIZE` bytes from here.
4234
4673
  * @param now The caller's monotonic time in milliseconds; timers due by then run first.
4235
- * @returns The datagram's length in bytes, at most `QUIC_CONN_DATAGRAM_SIZE`, or 0.
4674
+ * @returns The datagram's length in bytes, at most what `out` holds from `at` and `datagramSize()`, or 0.
4236
4675
  */
4237
4676
  takeDatagramInto(out: u8[], at: i32, now: i64): i32 {
4677
+ return this.takeDatagramWithin(out, at, toI32(out.length) - at, now)
4678
+ }
4679
+
4680
+ /**
4681
+ * `takeDatagramInto` with the datagram held to `room` bytes: it is at
4682
+ * most `room` and `datagramSize()`, whichever is less. When nothing else
4683
+ * is due and `room` has space for it, the datagram is a path MTU probe
4684
+ * (see `pathMtu`), so a carrier that wants probing gives at least
4685
+ * `QUIC_CONN_DATAGRAM_MAX` bytes of room, and one that gives 1200 never
4686
+ * probes. A probe never displaces data: a sender that always has
4687
+ * something due does not probe until it runs out, and stays at 1200
4688
+ * bytes until then.
4689
+ *
4690
+ * @param out Where the datagram is written.
4691
+ * @param at Where in `out` it starts.
4692
+ * @param room The most bytes the datagram may take from `at`; under `QUIC_CONN_DATAGRAM_SIZE`, or past the
4693
+ * end of `out`, nothing is written.
4694
+ * @param now The caller's monotonic time in milliseconds; timers due by then run first.
4695
+ * @returns The datagram's length in bytes, at most `room` and `QUIC_CONN_DATAGRAM_MAX`, or 0.
4696
+ */
4697
+ takeDatagramWithin(out: u8[], at: i32, room: i32, now: i64): i32 {
4238
4698
  this.handleTimer(now)
4239
4699
  if (
4240
4700
  this.state === QUIC_STATE_WAIT_INITIAL ||
4241
4701
  this.state === QUIC_STATE_DRAINING ||
4242
4702
  this.state === QUIC_STATE_TIMED_OUT ||
4243
4703
  at < 0 ||
4244
- at > toI32(out.length) - QUIC_CONN_DATAGRAM_SIZE
4704
+ room < QUIC_CONN_DATAGRAM_SIZE ||
4705
+ at > toI32(out.length) - room
4245
4706
  ) {
4246
4707
  return 0
4247
4708
  }
@@ -4262,9 +4723,13 @@ export class QuicConnection {
4262
4723
  }
4263
4724
  this.beforeDatagram()
4264
4725
  this.datagramEcn = this.ecnMarking ? this.recovery.ecnCodepoint() : 0
4726
+ const size: i32 = this.datagramSize()
4265
4727
  {
4266
4728
  using _scope = arena()
4267
- n = this.buildDatagram(out, at)
4729
+ n = this.buildDatagram(out, at, room < size ? room : size)
4730
+ if (n === 0 && this.pmtuDue(room)) {
4731
+ n = this.buildPmtuProbe(out, at, this.pmtuNext)
4732
+ }
4268
4733
  }
4269
4734
  return n
4270
4735
  }
@@ -4301,8 +4766,8 @@ export class QuicConnection {
4301
4766
  * last padded when an Initial elicits, then each sealed where it lies.
4302
4767
  * Answers the datagram's length, or 0 when no space had anything.
4303
4768
  */
4304
- private buildDatagram(out: u8[], at: i32): i32 {
4305
- let remaining: i32 = QUIC_CONN_DATAGRAM_SIZE
4769
+ private buildDatagram(out: u8[], at: i32, size: i32): i32 {
4770
+ let remaining: i32 = size
4306
4771
  // A path being validated has its own 3x limit (§9.3.1), which the
4307
4772
  // datagram may not pass; `amplificationBlocked` kept it above the floor.
4308
4773
  const budget: i64 = this.pathBudget()
@@ -4625,11 +5090,19 @@ export class QuicConnection {
4625
5090
  space.stageControl(streams.lastKind, streams.lastValue)
4626
5091
  }
4627
5092
  // DATAGRAMs ride in any packet the window lets elicit, and are recorded
4628
- // only by size: a lost one is not sent again (RFC 9221 §5.2).
5093
+ // only by size: a lost one is not sent again (RFC 9221 §5.2). One queued
5094
+ // for a larger path than the datagram size allows now never fits: it is
5095
+ // dropped rather than left to hold the rest back. While a new path is
5096
+ // validated it is not dropped but moved behind the others, which go out
5097
+ // ahead of it, since a path that keeps `pathMtu` carries it once
5098
+ // validated (RFC 9221 §5 promises no order).
5099
+ const most: i32 = this.maxDatagramPayload()
5100
+ this.datagramsPassOversized(most)
4629
5101
  let datagram: i32 = this.datagramsOut.putFrame(out, at, end)
4630
5102
  while (datagram > at) {
4631
5103
  at = datagram
4632
5104
  space.stagedEliciting = true
5105
+ this.datagramsPassOversized(most)
4633
5106
  datagram = this.datagramsOut.putFrame(out, at, end)
4634
5107
  }
4635
5108
  streams.beginPacket()
@@ -4644,6 +5117,24 @@ export class QuicConnection {
4644
5117
  return at
4645
5118
  }
4646
5119
 
5120
+ /**
5121
+ * Clears the head of the DATAGRAM queue of every payload over `most`
5122
+ * bytes: dropped, or while a new path is validated, moved to the back, at
5123
+ * most once each so a queue of nothing but large ones ends the pass.
5124
+ */
5125
+ private datagramsPassOversized(most: i32): void {
5126
+ const queue: QuicDatagramQueue = this.datagramsOut
5127
+ let passes: i32 = queue.count
5128
+ while (passes > 0 && queue.peekLength() > most) {
5129
+ if (this.pathValidating) {
5130
+ queue.deferOldest()
5131
+ } else {
5132
+ queue.dropOldest()
5133
+ }
5134
+ passes = passes - 1
5135
+ }
5136
+ }
5137
+
4647
5138
  /**
4648
5139
  * Seals the packet of `space` whose payload `buildDatagram` wrote from
4649
5140
  * `start` plus its header to `payloadEnd`: the header written in front of
@@ -4702,6 +5193,9 @@ export class QuicConnection {
4702
5193
  this.sealedUnderKey = this.sealedUnderKey + 1
4703
5194
  }
4704
5195
  const slot: i32 = this.recordSent(space, pn, end - start)
5196
+ if (this.pmtuSealing) {
5197
+ this.recovery.onProbeSent(space.level, slot)
5198
+ }
4705
5199
  if (this.datagramEcn !== 0) {
4706
5200
  this.recovery.onEctSent(space.level, slot)
4707
5201
  }