@amritk/nish-x86_64-linux 0.50.0 → 0.51.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/bin/nish +0 -0
- package/docs/AI.md +4 -1
- package/package.json +1 -1
- package/runtime/nish.d.ts +82 -2
- package/runtime/nish.h +5 -0
- package/runtime/runtime-host.c +21 -5
- package/std/README.md +7 -7
- package/std/base64.ts +61 -95
- package/std/bytes.ts +6 -4
- package/std/cli-args.ts +150 -107
- package/std/compress/checksum.ts +68 -10
- package/std/compress/deflate.ts +193 -100
- package/std/compress/gzip.ts +124 -49
- package/std/compress/zlib.ts +57 -15
- package/std/crypto/aes.ts +51 -9
- package/std/crypto/ed25519.ts +12 -10
- package/std/crypto/hkdf.ts +405 -283
- package/std/crypto/hmac.ts +483 -148
- package/std/crypto/jwt.ts +19 -21
- package/std/crypto/p256.ts +5 -7
- package/std/crypto/pki-roots.ts +28 -8
- package/std/crypto/rsa-sign.ts +5 -2
- package/std/crypto/sha256.ts +81 -26
- package/std/crypto/sha512.ts +135 -49
- package/std/json-value.ts +14 -15
- package/std/net/buffer-pool.ts +25 -14
- package/std/net/fetch.ts +108 -27
- package/std/net/handler.ts +11 -22
- package/std/net/hpack.ts +38 -19
- package/std/net/http-compress.ts +21 -12
- package/std/net/http-server.ts +9 -4
- package/std/net/http1-client-codec.ts +22 -15
- package/std/net/http1-codec.ts +37 -36
- package/std/net/http3-server.ts +127 -45
- package/std/net/http3.ts +99 -50
- package/std/net/postgres-async.ts +5 -10
- package/std/net/qpack.ts +83 -17
- package/std/net/quic-listener.ts +42 -27
- package/std/net/quic-packet.ts +91 -50
- package/std/net/quic-stream.ts +29 -22
- package/std/net/quic.ts +48 -23
- package/std/net/static.ts +5 -3
- package/std/net/tls/client.ts +81 -34
- package/std/net/tls/codec.ts +3 -4
- package/std/net/tls/record.ts +54 -22
- package/std/net/tls/schedule.ts +339 -149
- package/std/net/tls.ts +42 -12
- package/std/net/upstream.ts +18 -19
- package/std/net/url.ts +78 -21
- package/std/net/websocket.ts +3 -11
- package/std/net/webtransport.ts +95 -21
- package/std/raster.ts +12 -2
- package/std/term-pixels.ts +18 -2
- package/std/text.ts +5 -5
|
@@ -151,6 +151,11 @@ export const HTTP1_E_INFORMATIONAL_LIMIT: i32 = 17
|
|
|
151
151
|
* phrase and fields.
|
|
152
152
|
*/
|
|
153
153
|
export const HTTP1_E_MEMORY_LIMIT: i32 = 18
|
|
154
|
+
/**
|
|
155
|
+
* `error`: a `feed` whose window `data[off .. off + len)` is not inside
|
|
156
|
+
* `data`, a mistake of the program rather than of the server.
|
|
157
|
+
*/
|
|
158
|
+
export const HTTP1_E_WINDOW: i32 = 19
|
|
154
159
|
|
|
155
160
|
// --- The writer -------------------------------------------------------------
|
|
156
161
|
|
|
@@ -578,16 +583,12 @@ const http1ClientHeadArray = (
|
|
|
578
583
|
return out
|
|
579
584
|
}
|
|
580
585
|
|
|
581
|
-
/**
|
|
582
|
-
* `n` zero bytes, appended one at a time: the prover reads only a constant
|
|
583
|
-
* length of `new Array` as in range, and these lengths are computed.
|
|
584
|
-
*/
|
|
586
|
+
/** `n` zero bytes, none when `n` is below 1: one zeroed allocation, not a `push` per byte. */
|
|
585
587
|
const http1ClientZeros = (n: i32): u8[] => {
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
out.push(toU8(0))
|
|
588
|
+
if (n <= 0) {
|
|
589
|
+
return []
|
|
589
590
|
}
|
|
590
|
-
return
|
|
591
|
+
return new Array<u8>(n)
|
|
591
592
|
}
|
|
592
593
|
|
|
593
594
|
// --- The parser -------------------------------------------------------------
|
|
@@ -829,8 +830,10 @@ export class Http1ResponseParser {
|
|
|
829
830
|
|
|
830
831
|
/**
|
|
831
832
|
* Appends `data[off .. off + len)` to the input. A window outside `data`
|
|
832
|
-
*
|
|
833
|
-
*
|
|
833
|
+
* is refused with `HTTP1_E_WINDOW`, as final as any refusal, whatever the
|
|
834
|
+
* parser's state, except that a parser that has already refused keeps its
|
|
835
|
+
* first error. After `finish()`, or once the parser has closed or refused,
|
|
836
|
+
* the input is dropped; in a tunnel it is kept for `tunnelBytes()`. Input that
|
|
834
837
|
* would leave more than 2^30 bytes fed and not read is refused with
|
|
835
838
|
* `HTTP1_E_MEMORY_LIMIT`.
|
|
836
839
|
* @param data The bytes read from the connection.
|
|
@@ -840,7 +843,10 @@ export class Http1ResponseParser {
|
|
|
840
843
|
feed(data: u8[], off: i32, len: i32): void {
|
|
841
844
|
const size: i32 = toI32(data.length)
|
|
842
845
|
if (off < 0 || len < 0 || off > size || len > size - off) {
|
|
843
|
-
|
|
846
|
+
if (this.state !== HTTP1_CLIENT_S_ERROR) {
|
|
847
|
+
http1ClientFail(this, HTTP1_E_WINDOW, "a feed window outside its buffer")
|
|
848
|
+
}
|
|
849
|
+
return
|
|
844
850
|
}
|
|
845
851
|
if (this.closed || this.state === HTTP1_CLIENT_S_CLOSED || this.state === HTTP1_CLIENT_S_ERROR) {
|
|
846
852
|
return
|
|
@@ -990,11 +996,12 @@ export class Http1ResponseParser {
|
|
|
990
996
|
if (this.state !== HTTP1_CLIENT_S_TUNNEL || from < 0 || to <= from || to > toI32(this.buf.length)) {
|
|
991
997
|
return []
|
|
992
998
|
}
|
|
993
|
-
const
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
out.push(buf[k])
|
|
999
|
+
const count: i32 = to - from
|
|
1000
|
+
if (count <= 0) {
|
|
1001
|
+
return []
|
|
997
1002
|
}
|
|
1003
|
+
const out: u8[] = new Array<u8>(count)
|
|
1004
|
+
tryCopyBytes(out, 0, this.buf, from, count)
|
|
998
1005
|
return out
|
|
999
1006
|
}
|
|
1000
1007
|
}
|
package/std/net/http1-codec.ts
CHANGED
|
@@ -619,13 +619,17 @@ export class Http1Parser {
|
|
|
619
619
|
* @returns a copy the caller owns of the bytes that belong to the next protocol, empty when none arrived yet
|
|
620
620
|
*/
|
|
621
621
|
upgradeBytes(): u8[] {
|
|
622
|
-
const
|
|
623
|
-
const to: i32 = this.end
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
622
|
+
const from: i32 = this.start
|
|
623
|
+
const to: i32 = this.end < toI32(this.buf.length) ? this.end : toI32(this.buf.length)
|
|
624
|
+
if (from < 0 || to <= from) {
|
|
625
|
+
return []
|
|
626
|
+
}
|
|
627
|
+
const count: i32 = to - from
|
|
628
|
+
if (count <= 0) {
|
|
629
|
+
return []
|
|
628
630
|
}
|
|
631
|
+
const out: u8[] = new Array<u8>(count)
|
|
632
|
+
tryCopyBytes(out, 0, this.buf, from, count)
|
|
629
633
|
return out
|
|
630
634
|
}
|
|
631
635
|
|
|
@@ -774,10 +778,11 @@ const http1Reserve = (p: Http1Parser, len: i32): boolean => {
|
|
|
774
778
|
}
|
|
775
779
|
|
|
776
780
|
/**
|
|
777
|
-
* A buffer of `size` bytes whose first `live` are `old[from ..]
|
|
778
|
-
*
|
|
779
|
-
*
|
|
780
|
-
*
|
|
781
|
+
* A buffer of `size` bytes whose first `live` are `old[from ..]`: one zeroed
|
|
782
|
+
* allocation and one bulk copy. The first input buffer, `HTTP1_FIRST_INPUT`
|
|
783
|
+
* bytes, is the common one and copies nothing. Its callers cap `size` below
|
|
784
|
+
* 2^31 (twice `HTTP1_MOST_INPUT`), so clearing its top bit (`<< 1 >>> 1`),
|
|
785
|
+
* which is what proves the allocation's length non-negative, changes nothing.
|
|
781
786
|
*/
|
|
782
787
|
const http1Grown = (old: u8[], from: i32, live: u32, size: u32): u8[] => {
|
|
783
788
|
if (old.length === 0 && size === toU32(HTTP1_FIRST_INPUT)) {
|
|
@@ -786,25 +791,14 @@ const http1Grown = (old: u8[], from: i32, live: u32, size: u32): u8[] => {
|
|
|
786
791
|
if (old.length === 0 && size === toU32(HTTP1_FIRST_HEAD)) {
|
|
787
792
|
return new Array<u8>(HTTP1_FIRST_HEAD)
|
|
788
793
|
}
|
|
794
|
+
const n: i32 = toI32((size << toU32(1)) >>> toU32(1))
|
|
795
|
+
const buf: u8[] = new Array<u8>(n)
|
|
789
796
|
// `live` is the count from `from` to the end of the bytes in `old`, so the
|
|
790
|
-
// window always fits and `to` is its end; -1
|
|
797
|
+
// window always fits and `to` is its end; -1 copies nothing.
|
|
791
798
|
const to: i32 = http1WindowEnd(old, from, toI32(live))
|
|
792
|
-
if (
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
let at: i32 = 0
|
|
796
|
-
for (let k: i32 = from; k >= 0 && k < toI32(old.length) && k < to && at < toI32(sized.length); k += 1) {
|
|
797
|
-
sized[at] = old[k]
|
|
798
|
-
at += 1
|
|
799
|
-
}
|
|
800
|
-
return sized
|
|
801
|
-
}
|
|
802
|
-
const buf: u8[] = []
|
|
803
|
-
for (let k: i32 = from; k >= 0 && k < toI32(old.length) && k < to; k += 1) {
|
|
804
|
-
buf.push(old[k])
|
|
805
|
-
}
|
|
806
|
-
while (toU32(buf.length) < size) {
|
|
807
|
-
buf.push(0)
|
|
799
|
+
if (from >= 0 && to > from) {
|
|
800
|
+
const count: i32 = to - from
|
|
801
|
+
tryCopyBytes(buf, 0, old, from, count < n ? count : n)
|
|
808
802
|
}
|
|
809
803
|
return buf
|
|
810
804
|
}
|
|
@@ -1246,15 +1240,22 @@ const http1HeadAppend = (p: Http1Parser, from: i32, to: i32): i32 => {
|
|
|
1246
1240
|
const http1SpanSet = (p: Http1Parser, at: i32, value: i32): void => {
|
|
1247
1241
|
if (at >= toI32(p.spans.length)) {
|
|
1248
1242
|
const old: i32[] = p.spans
|
|
1249
|
-
//
|
|
1250
|
-
//
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1243
|
+
// `at` counts four spans a field. The head is under `HTTP1_MOST_INPUT`
|
|
1244
|
+
// (2^30) bytes and each field line takes at least four of them, so there
|
|
1245
|
+
// are under 2^28 fields, `at` is under 2^30 and the size under 2^31:
|
|
1246
|
+
// clearing its top bit (`<< 1 >>> 1`), which is what proves the
|
|
1247
|
+
// allocation's length non-negative, changes nothing.
|
|
1248
|
+
// (The caller's own guard is looser: it lets the count reach 2^29 - 1.)
|
|
1249
|
+
const wide: u32 = at < HTTP1_FIRST_SPANS ? toU32(HTTP1_FIRST_SPANS) : toU32(at) * toU32(2) + toU32(4)
|
|
1250
|
+
const size: i32 = toI32((wide << toU32(1)) >>> toU32(1))
|
|
1251
|
+
const grown: i32[] = new Array<i32>(size)
|
|
1252
|
+
// `new Array` is zero-filled already. The fill stays because
|
|
1253
|
+
// `Http1Parser.next` inlines this function, and without the fill it
|
|
1254
|
+
// compiles to 2.2M more instructions on the std-http1 bench row.
|
|
1255
|
+
grown.fill(0)
|
|
1256
|
+
const keep: i32 = toI32(old.length)
|
|
1257
|
+
for (let k: i32 = 0; k < keep && k < toI32(grown.length); k += 1) {
|
|
1258
|
+
grown[k] = old[k]
|
|
1258
1259
|
}
|
|
1259
1260
|
p.spans = grown
|
|
1260
1261
|
}
|
package/std/net/http3-server.ts
CHANGED
|
@@ -743,8 +743,9 @@ export class Http3Server {
|
|
|
743
743
|
private from: u8[]
|
|
744
744
|
private meta: i32[]
|
|
745
745
|
/**
|
|
746
|
-
* `QUIC_CONN_ENTROPY_SIZE` bytes of scratch,
|
|
747
|
-
*
|
|
746
|
+
* `QUIC_CONN_ENTROPY_SIZE` bytes of scratch, filled from `crypto.tryGetRandomValues` for each
|
|
747
|
+
* connection accepted and zeroed by the connection that copies it, so it holds zeros between
|
|
748
|
+
* accepts; `stop` zeroes it too.
|
|
748
749
|
*/
|
|
749
750
|
entropy: u8[]
|
|
750
751
|
private flight: QuicFlight
|
|
@@ -793,6 +794,11 @@ export class Http3Server {
|
|
|
793
794
|
accepted: i32 = 0
|
|
794
795
|
/** Initials dropped because no slot was free, saturating at 2^31 - 1. */
|
|
795
796
|
refused: i32 = 0
|
|
797
|
+
/**
|
|
798
|
+
* Initials dropped because the entropy source failed (`crypto.tryGetRandomValues`
|
|
799
|
+
* answered false) before a slot was taken, saturating at 2^31 - 1; the slot stays free.
|
|
800
|
+
*/
|
|
801
|
+
starved: i32 = 0
|
|
796
802
|
/** Datagrams no slot owns dropped past the answer budget before the listener read them, saturating. */
|
|
797
803
|
limited: i32 = 0
|
|
798
804
|
private sendErrors: i32 = 0
|
|
@@ -821,22 +827,15 @@ export class Http3Server {
|
|
|
821
827
|
* @param quicConfig The QUIC configuration, kept by reference and shared by the listener and every slot.
|
|
822
828
|
* @param config The HTTP/3 configuration, kept by reference; its `bodyChunk` and `maxFieldSectionSize`
|
|
823
829
|
* size the shared buffer pools.
|
|
830
|
+
* An `idleTimeout` or `headTimeout` under 1 panics here, before a peer's first Initial reaches a slot;
|
|
831
|
+
* `openHttp3Server` answers it and a `size` out of range as an `Err` instead.
|
|
824
832
|
* @param fd The bound UDP socket, kept; the server does not close it.
|
|
825
|
-
* @param size How many slots, 1 to 65536; any other panics,
|
|
826
|
-
* under 1.
|
|
833
|
+
* @param size How many slots, 1 to 65536; any other panics, a contract of this constructor.
|
|
827
834
|
* @param listenerEntropy `QUIC_LISTENER_ENTROPY_SIZE` random bytes, copied and then zeroed in this array.
|
|
828
835
|
*/
|
|
829
836
|
constructor(quicConfig: QuicServerConfig, config: Http3Config, fd: i32, size: i32, listenerEntropy: u8[]) {
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
}
|
|
833
|
-
// Checked here as well as by each slot's connection, which is built only on its first Initial.
|
|
834
|
-
if (config.idleTimeout < 1) {
|
|
835
|
-
panic(`Http3Server: idleTimeout of ${config.idleTimeout}, outside 1 to 2147483647`)
|
|
836
|
-
}
|
|
837
|
-
if (config.headTimeout < 1) {
|
|
838
|
-
panic(`Http3Server: headTimeout of ${config.headTimeout}, outside 1 to 2147483647`)
|
|
839
|
-
}
|
|
837
|
+
http3ServerCheckSize(size)
|
|
838
|
+
http3ServerCheckTimeouts(config)
|
|
840
839
|
this.quicConfig = quicConfig
|
|
841
840
|
this.config = config
|
|
842
841
|
this.fd = fd
|
|
@@ -897,13 +896,16 @@ export class Http3Server {
|
|
|
897
896
|
}
|
|
898
897
|
|
|
899
898
|
/**
|
|
900
|
-
* Builds the next slot, `quics.length`: its QUIC connection
|
|
901
|
-
*
|
|
902
|
-
*
|
|
903
|
-
*
|
|
899
|
+
* Builds the next slot, `quics.length`: its QUIC connection, sharing
|
|
900
|
+
* `streamPools` when its stream table is the one they were made for, its
|
|
901
|
+
* HTTP/3 connection on the pool's buffers and `date`, and its address.
|
|
902
|
+
* The QUIC connection is made from `entropy` as it stands, zeros (each
|
|
903
|
+
* connection zeroes it once copied): a built slot meets no peer and its
|
|
904
|
+
* connection IDs are not indexed until an accept takes it, and the accept
|
|
905
|
+
* seeds it again with `reset` from bytes the source gave, so no
|
|
906
|
+
* connection a peer reaches runs on these.
|
|
904
907
|
*/
|
|
905
908
|
private build(): void {
|
|
906
|
-
crypto.getRandomValues(this.entropy)
|
|
907
909
|
const quic = new QuicConnection(this.quicConfig, this.entropy)
|
|
908
910
|
quic.ecnMarking = this.ecn
|
|
909
911
|
this.quics.push(quic)
|
|
@@ -1190,7 +1192,7 @@ export class Http3Server {
|
|
|
1190
1192
|
if (this.listener.handleWindow(buf, at, len, address, now, answer) !== QUIC_LISTEN_ACCEPT) {
|
|
1191
1193
|
const reply: i32 = toI32(answer.reply.length)
|
|
1192
1194
|
if (reply > 0) {
|
|
1193
|
-
this.send(answer.reply,
|
|
1195
|
+
this.send(answer.reply, reply, address, H3_SERVER_ZERO, H3_SERVER_ZERO)
|
|
1194
1196
|
}
|
|
1195
1197
|
return
|
|
1196
1198
|
}
|
|
@@ -1224,7 +1226,13 @@ export class Http3Server {
|
|
|
1224
1226
|
const addresses: u8[][] = this.addresses
|
|
1225
1227
|
const state: i32[] = this.state
|
|
1226
1228
|
const signatures: i64[] = this.signatures
|
|
1227
|
-
|
|
1229
|
+
// A source that fails drops the Initial before the slot is taken; the peer may send it again.
|
|
1230
|
+
// The fill may have written a prefix, which is zeroed with the rest.
|
|
1231
|
+
if (!crypto.tryGetRandomValues(this.entropy)) {
|
|
1232
|
+
secureZero(this.entropy)
|
|
1233
|
+
this.starved = h3Count(this.starved)
|
|
1234
|
+
return
|
|
1235
|
+
}
|
|
1228
1236
|
// Never taken: a released slot was built, `slotAt` builds the one it answers, and
|
|
1229
1237
|
// `state` and `signatures` are `size` long.
|
|
1230
1238
|
if (
|
|
@@ -1443,11 +1451,16 @@ export class Http3Server {
|
|
|
1443
1451
|
}
|
|
1444
1452
|
|
|
1445
1453
|
/**
|
|
1446
|
-
* Sends `buf[
|
|
1447
|
-
*
|
|
1454
|
+
* Sends `buf[0 .. len)` to `to` with the ECN codepoint `ecn`, cut into
|
|
1455
|
+
* `segment`-byte datagrams when it is above 0; answers whether it went.
|
|
1448
1456
|
*/
|
|
1449
|
-
private send(buf: u8[],
|
|
1450
|
-
|
|
1457
|
+
private send(buf: u8[], len: i32, to: u8[], segment: i32, ecn: i32): boolean {
|
|
1458
|
+
if (len < 0 || len > toI32(buf.length)) {
|
|
1459
|
+
// Never taken: every caller sends the first `len` bytes of `buf`, a
|
|
1460
|
+
// count its writer answered for the buffer it wrote into.
|
|
1461
|
+
return false
|
|
1462
|
+
}
|
|
1463
|
+
const sent: i32 = udpSendTo(this.fd, buf, 0, len, to, segment, ecn)
|
|
1451
1464
|
if (sent >= 0) {
|
|
1452
1465
|
return true
|
|
1453
1466
|
}
|
|
@@ -1463,34 +1476,37 @@ export class Http3Server {
|
|
|
1463
1476
|
mark = H3_SERVER_ZERO
|
|
1464
1477
|
}
|
|
1465
1478
|
const step: i32 = segment > 0 ? segment : len
|
|
1466
|
-
if (
|
|
1467
|
-
// Never taken
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
let
|
|
1472
|
-
while (
|
|
1473
|
-
|
|
1474
|
-
|
|
1479
|
+
if (step <= 0 || len > toI32(buf.length)) {
|
|
1480
|
+
// Never taken past an empty send: `len` was checked above and
|
|
1481
|
+
// `udpSendTo` does not resize `buf`.
|
|
1482
|
+
return len === 0
|
|
1483
|
+
}
|
|
1484
|
+
let p: i32 = 0
|
|
1485
|
+
while (p >= 0 && p < len) {
|
|
1486
|
+
// The datagram's end: `p + step` when that is short of `len`, so it fits an i32.
|
|
1487
|
+
const q: i32 = p < len - step ? toI32(toI64(p) + toI64(step)) : len
|
|
1488
|
+
if (q < p || q > toI32(buf.length)) {
|
|
1489
|
+
// Never taken: `p <= q <= len`, and `len` fits `buf`.
|
|
1490
|
+
return false
|
|
1491
|
+
}
|
|
1492
|
+
let one: i32 = udpSendTo(this.fd, buf, p, q - p, to, H3_SERVER_ZERO, mark)
|
|
1475
1493
|
if (one === H3_SERVER_UNSUPPORTED && mark !== 0) {
|
|
1476
1494
|
// No ECN here: this datagram and the rest go unmarked and no slot
|
|
1477
1495
|
// marks again. The packets just counted as marked fail their
|
|
1478
1496
|
// connection's validation.
|
|
1479
1497
|
this.unmark()
|
|
1480
1498
|
mark = H3_SERVER_ZERO
|
|
1481
|
-
|
|
1499
|
+
if (q > toI32(buf.length)) {
|
|
1500
|
+
// Never taken: `unmark` does not resize `buf`.
|
|
1501
|
+
return false
|
|
1502
|
+
}
|
|
1503
|
+
one = udpSendTo(this.fd, buf, p, q - p, to, H3_SERVER_ZERO, mark)
|
|
1482
1504
|
}
|
|
1483
1505
|
if (one < 0) {
|
|
1484
1506
|
this.sendErrors = h3Count(this.sendErrors)
|
|
1485
1507
|
return false
|
|
1486
1508
|
}
|
|
1487
|
-
|
|
1488
|
-
// Never taken: `n` is the smaller of `left` and a positive `step`.
|
|
1489
|
-
return false
|
|
1490
|
-
}
|
|
1491
|
-
left = left - n
|
|
1492
|
-
// `p + n`, at most `at + len`, which `udpSendTo` took, so it fits an i32.
|
|
1493
|
-
p = toI32(toI64(p) + toI64(n))
|
|
1509
|
+
p = q
|
|
1494
1510
|
}
|
|
1495
1511
|
return true
|
|
1496
1512
|
}
|
|
@@ -1561,7 +1577,7 @@ export class Http3Server {
|
|
|
1561
1577
|
// the flight below picks where it goes.
|
|
1562
1578
|
const probe: i32 = quic.takeProbeInto(this.tx, H3_SERVER_ZERO, now)
|
|
1563
1579
|
if (probe > 0) {
|
|
1564
|
-
this.send(this.tx,
|
|
1580
|
+
this.send(this.tx, probe, quic.probeAddress, H3_SERVER_ZERO, H3_SERVER_ZERO)
|
|
1565
1581
|
}
|
|
1566
1582
|
if (quic.pathKnown) {
|
|
1567
1583
|
const current: u8[] = quic.sendAddress()
|
|
@@ -1589,7 +1605,7 @@ export class Http3Server {
|
|
|
1589
1605
|
break
|
|
1590
1606
|
}
|
|
1591
1607
|
const segment: i32 = this.flight.count > 1 ? this.flight.segment : H3_SERVER_ZERO
|
|
1592
|
-
if (!this.send(this.tx,
|
|
1608
|
+
if (!this.send(this.tx, n, to, segment, this.flight.ecn)) {
|
|
1593
1609
|
break
|
|
1594
1610
|
}
|
|
1595
1611
|
retried = false
|
|
@@ -1598,7 +1614,7 @@ export class Http3Server {
|
|
|
1598
1614
|
// The CONNECTION_CLOSE goes whatever the pacer says: nothing follows it.
|
|
1599
1615
|
const n: i32 = quic.takeDatagramInto(this.tx, H3_SERVER_ZERO, now)
|
|
1600
1616
|
if (n > 0) {
|
|
1601
|
-
this.send(this.tx,
|
|
1617
|
+
this.send(this.tx, n, to, H3_SERVER_ZERO, quic.datagramEcn)
|
|
1602
1618
|
}
|
|
1603
1619
|
this.release(slot)
|
|
1604
1620
|
return
|
|
@@ -1791,3 +1807,69 @@ export class Http3Server {
|
|
|
1791
1807
|
return this.wheel.next(now)
|
|
1792
1808
|
}
|
|
1793
1809
|
}
|
|
1810
|
+
|
|
1811
|
+
/** Why `config`'s timeouts cannot make a server, or `""` when they can: an `idleTimeout` or `headTimeout` under 1. */
|
|
1812
|
+
const http3ServerTimeoutFault = (config: Http3Config): string => {
|
|
1813
|
+
if (config.idleTimeout < 1) {
|
|
1814
|
+
return `Http3Server: idleTimeout of ${config.idleTimeout}, outside 1 to 2147483647`
|
|
1815
|
+
}
|
|
1816
|
+
if (config.headTimeout < 1) {
|
|
1817
|
+
return `Http3Server: headTimeout of ${config.headTimeout}, outside 1 to 2147483647`
|
|
1818
|
+
}
|
|
1819
|
+
return ""
|
|
1820
|
+
}
|
|
1821
|
+
|
|
1822
|
+
/** Why `size` cannot be a server's slot count, or `""` when it can. */
|
|
1823
|
+
const http3ServerSizeFault = (size: i32): string => {
|
|
1824
|
+
if (size < 1 || size > 65536) {
|
|
1825
|
+
return `Http3Server: ${size} slots, outside 1 to 65536`
|
|
1826
|
+
}
|
|
1827
|
+
return ""
|
|
1828
|
+
}
|
|
1829
|
+
|
|
1830
|
+
/** Panics unless `config`'s timeouts can make a server, at its construction: a timeout under 1 is the program's mistake. */
|
|
1831
|
+
const http3ServerCheckTimeouts = (config: Http3Config): void => {
|
|
1832
|
+
const fault: string = http3ServerTimeoutFault(config)
|
|
1833
|
+
if (fault.length > 0) {
|
|
1834
|
+
panic(fault)
|
|
1835
|
+
}
|
|
1836
|
+
}
|
|
1837
|
+
|
|
1838
|
+
/** Panics unless `size` can be a server's slot count: a count out of range is the program's mistake. */
|
|
1839
|
+
const http3ServerCheckSize = (size: i32): void => {
|
|
1840
|
+
const fault: string = http3ServerSizeFault(size)
|
|
1841
|
+
if (fault.length > 0) {
|
|
1842
|
+
panic(fault)
|
|
1843
|
+
}
|
|
1844
|
+
}
|
|
1845
|
+
|
|
1846
|
+
/**
|
|
1847
|
+
* A server as `new Http3Server(quicConfig, config, fd, size, listenerEntropy)`
|
|
1848
|
+
* makes one, with a slot count out of range and an `idleTimeout` or
|
|
1849
|
+
* `headTimeout` under 1, which that constructor panics on, answered as an
|
|
1850
|
+
* `Err` before anything is built or `listenerEntropy` is touched.
|
|
1851
|
+
* @param quicConfig The QUIC configuration, as the constructor keeps it.
|
|
1852
|
+
* @param config The HTTP/3 configuration, as the constructor keeps it.
|
|
1853
|
+
* @param fd The bound UDP socket, kept; the server does not close it.
|
|
1854
|
+
* @param size How many slots, 1 to 65536.
|
|
1855
|
+
* @param listenerEntropy `QUIC_LISTENER_ENTROPY_SIZE` random bytes, copied and then zeroed in this array
|
|
1856
|
+
* when the server is built.
|
|
1857
|
+
* @returns `Ok` with the server, or `Err` saying which of `size`, `idleTimeout` and `headTimeout` is out of range.
|
|
1858
|
+
*/
|
|
1859
|
+
export const openHttp3Server = (
|
|
1860
|
+
quicConfig: QuicServerConfig,
|
|
1861
|
+
config: Http3Config,
|
|
1862
|
+
fd: i32,
|
|
1863
|
+
size: i32,
|
|
1864
|
+
listenerEntropy: u8[]
|
|
1865
|
+
): Result<Http3Server, string> => {
|
|
1866
|
+
const timeouts: string = http3ServerTimeoutFault(config)
|
|
1867
|
+
if (timeouts.length > 0) {
|
|
1868
|
+
return Err(timeouts)
|
|
1869
|
+
}
|
|
1870
|
+
const fault: string = http3ServerSizeFault(size)
|
|
1871
|
+
if (fault.length > 0) {
|
|
1872
|
+
return Err(fault)
|
|
1873
|
+
}
|
|
1874
|
+
return Ok(new Http3Server(quicConfig, config, fd, size, listenerEntropy))
|
|
1875
|
+
}
|