@amritk/nish-aarch64-linux 0.39.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.
- package/INSTALL.md +74 -129
- package/bin/nish +0 -0
- package/docs/AI.md +112 -33
- package/package.json +1 -1
- package/runtime/nish.d.ts +21 -17
- package/runtime/nish.h +10 -0
- package/runtime/page-frame.d.ts +123 -0
- package/runtime/page-frame.mjs +736 -0
- package/runtime/page-game.d.ts +132 -0
- package/runtime/page-game.mjs +738 -0
- package/runtime/runtime-aes.c +85 -8
- package/runtime/runtime-bytes.c +88 -4
- package/runtime/runtime-net.c +32 -0
- package/runtime/runtime-sandbox.c +55 -28
- package/runtime/runtime-wasm.c +422 -0
- package/runtime/vite.mjs +1 -1
- package/scripts/build.sh +15 -0
- package/std/README.md +73 -87
- package/std/array.ts +36 -3
- package/std/collections.ts +51 -0
- package/std/crypto/hmac.ts +37 -10
- package/std/crypto/p256.ts +1388 -2664
- package/std/crypto/pki.ts +116 -4
- package/std/crypto/sha256.ts +34 -6
- package/std/crypto/x509.ts +7 -0
- package/std/host/game.ts +273 -0
- package/std/input.ts +56 -0
- package/std/json-tokenizer.ts +325 -112
- package/std/json-typed.ts +43 -8
- package/std/json-value.ts +144 -3
- package/std/json.ts +63 -8
- package/std/net/fetch.ts +22 -4
- package/std/net/http-server.ts +3382 -0
- package/std/net/http1-client-codec.ts +6 -2
- package/std/net/http1-codec.ts +137 -12
- package/std/net/http1-server.ts +83 -29
- package/std/net/http2.ts +47 -14
- package/std/net/http3-server.ts +29 -3
- package/std/net/http3.ts +180 -7
- package/std/net/quic-recovery.ts +240 -9
- package/std/net/quic-stream.ts +21 -1
- package/std/net/quic.ts +98 -4
- package/std/net/router.ts +378 -31
- package/std/net/serve.ts +873 -65
- package/std/net/tls/verify.ts +19 -1
- package/std/net/url.ts +83 -35
- package/std/net/websocket.ts +74 -1
- package/std/net/webtransport.ts +7 -1
- package/std/raster.ts +837 -0
- package/std/release.ts +593 -0
- package/std/synth.ts +143 -0
- package/std/threads.ts +298 -0
- package/std/yaml-json.ts +368 -28
- package/std/yaml.ts +122 -27
package/std/net/quic-stream.ts
CHANGED
|
@@ -726,7 +726,11 @@ export class QuicStream {
|
|
|
726
726
|
}
|
|
727
727
|
|
|
728
728
|
/**
|
|
729
|
-
* How many more bytes the send buffer takes.
|
|
729
|
+
* How many more bytes the send buffer takes. The buffer is the stream's
|
|
730
|
+
* `maxStreamData` and is the memory bound of its send side: bytes stay in
|
|
731
|
+
* it until the peer acknowledges them, so one lost packet holds back
|
|
732
|
+
* everything written after it until its resend is acknowledged (quic.ts
|
|
733
|
+
* probes early meanwhile, so a peer whose address changes is still seen).
|
|
730
734
|
*
|
|
731
735
|
* @returns The buffer size less the bytes written and not yet acknowledged.
|
|
732
736
|
*/
|
|
@@ -1181,6 +1185,22 @@ export class QuicStreams {
|
|
|
1181
1185
|
this.streamsBlockedUniOwed = false
|
|
1182
1186
|
}
|
|
1183
1187
|
|
|
1188
|
+
/**
|
|
1189
|
+
* Whether a stream's send buffer is full behind bytes the peer has not
|
|
1190
|
+
* acknowledged, with nothing of it left to send: the application offered
|
|
1191
|
+
* more than `room` took, and every byte the buffer holds is in flight. The
|
|
1192
|
+
* stream then sends nothing new until an ACK frees room.
|
|
1193
|
+
* @internal Read by quic.ts, for its early probe.
|
|
1194
|
+
*/
|
|
1195
|
+
bufferBlocked(): boolean {
|
|
1196
|
+
for (const stream of this.slots) {
|
|
1197
|
+
if (stream.id >= 0 && stream.wantsWrite && stream.room() <= 0 && !stream.wantsToSend()) {
|
|
1198
|
+
return true
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1201
|
+
return false
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1184
1204
|
/**
|
|
1185
1205
|
* Takes the peer's transport parameters (RFC 9000 §18.2): its limits on
|
|
1186
1206
|
* the streams this side opens, the credit each kind of stream starts with,
|
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.
|
|
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,
|
|
@@ -609,7 +616,11 @@ export interface QuicServerConfig {
|
|
|
609
616
|
/**
|
|
610
617
|
* `initial_max_stream_data_bidi_remote` (and `_uni`, and `_bidi_local`
|
|
611
618
|
* when the server opens streams): each stream's receive window and the
|
|
612
|
-
* 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.
|
|
613
624
|
*/
|
|
614
625
|
maxStreamData: i64
|
|
615
626
|
/** `initial_max_streams_bidi`: how many bidirectional streams the client may have open at once, 0 to 1024. */
|
|
@@ -658,6 +669,14 @@ export interface QuicServerConfig {
|
|
|
658
669
|
* other pair.
|
|
659
670
|
*/
|
|
660
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
|
|
661
680
|
}
|
|
662
681
|
|
|
663
682
|
/**
|
|
@@ -1434,6 +1453,7 @@ const quicConnConfigFits = (config: QuicServerConfig): boolean =>
|
|
|
1434
1453
|
config.maxIdleTimeout <= QUIC_MAX_VARINT &&
|
|
1435
1454
|
config.activeConnectionIdLimit >= 2 &&
|
|
1436
1455
|
config.activeConnectionIdLimit <= 8 &&
|
|
1456
|
+
(config.congestion === QUIC_RECOVERY_NEWRENO || config.congestion === QUIC_RECOVERY_CUBIC) &&
|
|
1437
1457
|
toI32(config.statelessResetKey.length) === QUIC_CONN_STATIC_KEY_SIZE
|
|
1438
1458
|
|
|
1439
1459
|
/**
|
|
@@ -1585,6 +1605,12 @@ export class QuicConnection {
|
|
|
1585
1605
|
challengeUntil: i64 = -1
|
|
1586
1606
|
/** How many PATH_CHALLENGE data have been drawn over the connection; see `challengeData`. */
|
|
1587
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
|
|
1588
1614
|
private frame: QuicFrame
|
|
1589
1615
|
/** The header and the packet numbers of the packet being read, reused for every one. */
|
|
1590
1616
|
private header: QuicHeader
|
|
@@ -1804,6 +1830,8 @@ export class QuicConnection {
|
|
|
1804
1830
|
QUIC_CONN_LOCAL_CIDS
|
|
1805
1831
|
)
|
|
1806
1832
|
this.recovery = new QuicRecovery()
|
|
1833
|
+
this.recovery.controller =
|
|
1834
|
+
config.congestion === QUIC_RECOVERY_CUBIC ? QUIC_RECOVERY_CUBIC : QUIC_RECOVERY_NEWRENO
|
|
1807
1835
|
this.defaultParameters = new QuicTransportParameters()
|
|
1808
1836
|
this.peerParameters = this.defaultParameters
|
|
1809
1837
|
// A configuration that does not fit closes the connection at once (see
|
|
@@ -1901,6 +1929,7 @@ export class QuicConnection {
|
|
|
1901
1929
|
this.appReadSlot = 0
|
|
1902
1930
|
this.appWriteSlot = 0
|
|
1903
1931
|
this.earlyResends = 0
|
|
1932
|
+
this.earlyProbeAcked = -2
|
|
1904
1933
|
this.resendLevel = -1
|
|
1905
1934
|
this.now = 0
|
|
1906
1935
|
this.idleSince = -1
|
|
@@ -2206,6 +2235,7 @@ export class QuicConnection {
|
|
|
2206
2235
|
// Loss recovery's timer runs after the datagram, so an acknowledgement
|
|
2207
2236
|
// it carries settles what it acknowledges before a probe is owed.
|
|
2208
2237
|
this.runRecoveryTimer()
|
|
2238
|
+
this.runEarlyProbe()
|
|
2209
2239
|
return this.closed() ? this.error : QUIC_ERROR_NO_ERROR
|
|
2210
2240
|
}
|
|
2211
2241
|
|
|
@@ -3787,7 +3817,8 @@ export class QuicConnection {
|
|
|
3787
3817
|
/**
|
|
3788
3818
|
* When `handleTimer` is next due, in the caller's milliseconds: the idle
|
|
3789
3819
|
* timeout, loss recovery's timer (a time-threshold loss or the probe
|
|
3790
|
-
* timeout),
|
|
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
|
|
3791
3822
|
* validated, its PATH_CHALLENGE's resend or the end of its validation,
|
|
3792
3823
|
* whichever comes first; once the connection has closed, the end of its closing or
|
|
3793
3824
|
* draining period, when its keys are wiped. -1 when nothing is timed:
|
|
@@ -3813,6 +3844,10 @@ export class QuicConnection {
|
|
|
3813
3844
|
if (recovery >= 0 && (due < 0 || recovery < due)) {
|
|
3814
3845
|
due = recovery
|
|
3815
3846
|
}
|
|
3847
|
+
const early: i64 = this.earlyProbeAt()
|
|
3848
|
+
if (early >= 0 && (due < 0 || early < due)) {
|
|
3849
|
+
due = early
|
|
3850
|
+
}
|
|
3816
3851
|
if (this.pathValidating) {
|
|
3817
3852
|
const path: i64 =
|
|
3818
3853
|
this.challengeResendAt < this.challengeUntil ? this.challengeResendAt : this.challengeUntil
|
|
@@ -3858,7 +3893,10 @@ export class QuicConnection {
|
|
|
3858
3893
|
* Past loss recovery's timer, packets lost by the time threshold have their
|
|
3859
3894
|
* frames queued again, or a probe timeout queues every space's packets in
|
|
3860
3895
|
* flight and asks for a probe (RFC 9002 §6.1.2, §6.2.4): `takeDatagram` then
|
|
3861
|
-
* sends it.
|
|
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
|
|
3862
3900
|
* backwards here: an earlier `now` than one already given counts as that one.
|
|
3863
3901
|
*
|
|
3864
3902
|
* @param now The caller's monotonic time in milliseconds.
|
|
@@ -3866,6 +3904,7 @@ export class QuicConnection {
|
|
|
3866
3904
|
handleTimer(now: i64): void {
|
|
3867
3905
|
this.runClocks(now)
|
|
3868
3906
|
this.runRecoveryTimer()
|
|
3907
|
+
this.runEarlyProbe()
|
|
3869
3908
|
}
|
|
3870
3909
|
|
|
3871
3910
|
/**
|
|
@@ -4210,6 +4249,61 @@ export class QuicConnection {
|
|
|
4210
4249
|
return this.sealAt(space, out, at, quicPutPadding(out, next, payloadEnd - next))
|
|
4211
4250
|
}
|
|
4212
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
|
+
|
|
4213
4307
|
/** Loss recovery's timer, if it is due (RFC 9002 §6.2, A.9). */
|
|
4214
4308
|
private runRecoveryTimer(): void {
|
|
4215
4309
|
if (this.closed() || this.state === QUIC_STATE_WAIT_INITIAL) {
|