@amritk/nish-aarch64-linux 0.37.0 → 0.38.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 +32 -10
- package/package.json +1 -1
- package/runtime/core/arrays.d.ts +4 -0
- package/runtime/core/arrays.mjs +33 -0
- package/runtime/nish.d.ts +344 -48
- package/runtime/nish.h +29 -7
- package/runtime/runtime-async.c +228 -45
- package/runtime/runtime-cross.c +2 -1
- package/runtime/runtime-region.c +85 -7
- package/runtime/runtime-text.c +1068 -0
- package/runtime/runtime-wasm.c +3 -3
- package/runtime/runtime.c +50 -961
- package/runtime/vite.mjs +48 -11
- package/scripts/build.sh +86 -28
- package/std/LICENSE-fdlibm +8 -0
- package/std/README.md +2 -0
- package/std/array.ts +266 -0
- package/std/host/text.ts +86 -0
- 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 +12 -0
- package/std/net/http-compress.ts +17 -9
- package/std/net/http-fields.ts +19 -4
- package/std/net/http1-codec.ts +18 -4
- package/std/net/http1-server.ts +13 -3
- package/std/net/postgres-async.ts +1005 -0
- package/std/net/postgres.ts +7 -4
- package/std/net/serve.ts +763 -0
- package/std/text.ts +231 -5
package/std/net/dns-resolver.ts
CHANGED
|
@@ -765,6 +765,41 @@ export class DnsResolver {
|
|
|
765
765
|
this.lookupState[lookup] = DNS_L_FREE
|
|
766
766
|
}
|
|
767
767
|
|
|
768
|
+
/**
|
|
769
|
+
* Ends `lookup` now with the addresses it already has, when one of its
|
|
770
|
+
* current name's two queries has answered with addresses and the other is
|
|
771
|
+
* still asking; the one still asking is owed a `DNS_CLOSE`, as `cancel`
|
|
772
|
+
* owes one. Otherwise the lookup is left as it was. A driver whose own time
|
|
773
|
+
* is up calls this before `cancel`, so a network that never answers AAAA
|
|
774
|
+
* still gives the A addresses it found. Panics when `lookup` is not a
|
|
775
|
+
* lookup in progress, as `result` does.
|
|
776
|
+
*
|
|
777
|
+
* @param lookup The slot `start` answered.
|
|
778
|
+
* @returns Whether the lookup has now finished, its answer for `result`
|
|
779
|
+
* to read; true for one that had finished already.
|
|
780
|
+
*/
|
|
781
|
+
settle(lookup: i32): boolean {
|
|
782
|
+
if (lookup < 0 || lookup >= this.maxLookups || this.lookupState[lookup] === DNS_L_FREE) {
|
|
783
|
+
panic(`DnsResolver.settle: ${lookup} is not a lookup in progress`)
|
|
784
|
+
}
|
|
785
|
+
if (this.lookupState[lookup] === DNS_L_DONE) {
|
|
786
|
+
return true
|
|
787
|
+
}
|
|
788
|
+
const a: i32 = lookup * 2
|
|
789
|
+
let open: i32 = -1
|
|
790
|
+
if (this.state[a] === DNS_Q_DONE && this.outcome[a] > 0) {
|
|
791
|
+
open = a + 1
|
|
792
|
+
} else if (this.state[a + 1] === DNS_Q_DONE && this.outcome[a + 1] > 0) {
|
|
793
|
+
open = a
|
|
794
|
+
}
|
|
795
|
+
if (open < 0 || this.state[open] === DNS_Q_DONE) {
|
|
796
|
+
return false
|
|
797
|
+
}
|
|
798
|
+
// The other has addresses, so this finishes the lookup and never reaches a next name, which alone reads the clock.
|
|
799
|
+
dnsResolverDone(this, open, DNS_RESOLVE_NO_ANSWER, 0)
|
|
800
|
+
return true
|
|
801
|
+
}
|
|
802
|
+
|
|
768
803
|
/**
|
|
769
804
|
* How many slots are taken.
|
|
770
805
|
*
|
|
@@ -1163,7 +1198,9 @@ const dnsResolverSameName = (a: u8[], b: u8[]): boolean => {
|
|
|
1163
1198
|
* an NXDOMAIN, such an error is the lookup's, since the name may well exist.
|
|
1164
1199
|
* Otherwise the name has no address: NXDOMAIN from both moves the search on,
|
|
1165
1200
|
* and NODATA ends it, as musl's resolver does, since the name exists and only
|
|
1166
|
-
* lacks the type asked.
|
|
1201
|
+
* lacks the type asked. NODATA is `DNS_RESOLVE_NOT_FOUND` even after an
|
|
1202
|
+
* earlier candidate left an error to fall back on: that error stands only
|
|
1203
|
+
* when no later candidate answers.
|
|
1167
1204
|
*/
|
|
1168
1205
|
const dnsResolverDone = (r: DnsResolver, q: i32, outcome: i32, nowNanos: i64): void => {
|
|
1169
1206
|
if (r.state[q] === DNS_Q_UDP || r.state[q] === DNS_Q_TCP) {
|
|
@@ -1196,14 +1233,17 @@ const dnsResolverDone = (r: DnsResolver, q: i32, outcome: i32, nowNanos: i64): v
|
|
|
1196
1233
|
dnsResolverFinish(r, l, error)
|
|
1197
1234
|
return
|
|
1198
1235
|
}
|
|
1236
|
+
if (error === 0 && !(r.nxdomain[a] && r.nxdomain[a + 1])) {
|
|
1237
|
+
// NODATA answers for the name, so an earlier candidate's fallback does not stand.
|
|
1238
|
+
dnsResolverFinish(r, l, DNS_RESOLVE_NOT_FOUND)
|
|
1239
|
+
return
|
|
1240
|
+
}
|
|
1199
1241
|
if (error !== 0 && r.fallback[l] === 0) {
|
|
1200
1242
|
r.fallback[l] = error
|
|
1201
1243
|
}
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
return
|
|
1206
|
-
}
|
|
1244
|
+
r.candidate[l] = r.candidate[l] + 1
|
|
1245
|
+
if (dnsResolverNextCandidate(r, l, nowNanos)) {
|
|
1246
|
+
return
|
|
1207
1247
|
}
|
|
1208
1248
|
dnsResolverFinish(r, l, r.fallback[l] !== 0 ? r.fallback[l] : DNS_RESOLVE_NOT_FOUND)
|
|
1209
1249
|
}
|
package/std/net/dns.ts
CHANGED
|
@@ -279,6 +279,22 @@ export class DnsClient {
|
|
|
279
279
|
this.pump(nowNanos)
|
|
280
280
|
}
|
|
281
281
|
|
|
282
|
+
/**
|
|
283
|
+
* `DnsResolver.settle`, closing the socket of the query it stops: ends the
|
|
284
|
+
* lookup with the addresses one family has found when the other is still
|
|
285
|
+
* asking, so a caller whose time is up keeps them.
|
|
286
|
+
*
|
|
287
|
+
* @param lookup An id `start` answered whose answer has not been read.
|
|
288
|
+
* @param nowNanos The caller's monotonic clock now, in nanoseconds.
|
|
289
|
+
* @returns Whether the lookup has finished, so `result` answers it rather than
|
|
290
|
+
* `DNS_RESOLVE_PENDING`.
|
|
291
|
+
*/
|
|
292
|
+
settle(lookup: i32, nowNanos: i64): boolean {
|
|
293
|
+
const done: boolean = this.resolver.settle(lookup)
|
|
294
|
+
this.pump(nowNanos)
|
|
295
|
+
return done
|
|
296
|
+
}
|
|
297
|
+
|
|
282
298
|
/**
|
|
283
299
|
* The pair `token`, `events` that `pollWait` reported at `nowNanos`, for a
|
|
284
300
|
* token `owns` answers true for: reads the datagrams (at most
|
|
@@ -529,9 +545,9 @@ const dnsClientReadStream = (c: DnsClient, q: i32, fd: i32, hungUp: boolean, now
|
|
|
529
545
|
* The addresses of `name`, looked up as `/etc/resolv.conf` and `/etc/hosts`
|
|
530
546
|
* say (a missing resolv.conf means the defaults, a missing hosts file no
|
|
531
547
|
* entries), each 18 bytes with `port` into `out` and its TTL in seconds into
|
|
532
|
-
* `ttls`. It waits for both the A and the AAAA answer
|
|
533
|
-
* answered is
|
|
534
|
-
* `DNS_RESOLVE_TIMEOUT`.
|
|
548
|
+
* `ttls`. It waits for both the A and the AAAA answer until `timeoutMs`
|
|
549
|
+
* passes; then a family that answered with addresses is returned on its own,
|
|
550
|
+
* and only a lookup with none yet is `DNS_RESOLVE_TIMEOUT`.
|
|
535
551
|
*
|
|
536
552
|
* **It blocks the thread** until the lookup ends, on a loop of its own, so
|
|
537
553
|
* it is for a CLI or a program's start-up; a server resolves with a
|
|
@@ -548,24 +564,41 @@ const dnsClientReadStream = (c: DnsClient, q: i32, fd: i32, hungUp: boolean, now
|
|
|
548
564
|
* `DNS_RESOLVE_MAX_ADDRESSES * 18` bytes.
|
|
549
565
|
* @param ttls Where each address's TTL goes, in seconds; at least `DNS_RESOLVE_MAX_ADDRESSES`.
|
|
550
566
|
* @returns The count of addresses written; or a negative code: `DNS_RESOLVE_TIMEOUT` once
|
|
551
|
-
* `timeoutMs` has passed, `DNS_RESOLVE_NOT_FOUND`, `DNS_RESOLVE_NO_ANSWER` or
|
|
567
|
+
* `timeoutMs` has passed with no address found, `DNS_RESOLVE_NOT_FOUND`, `DNS_RESOLVE_NO_ANSWER` or
|
|
552
568
|
* `DNS_RESOLVE_CNAME` from the lookup, the `DNS_ERR_*` code of a name that is not one, or
|
|
553
569
|
* the negative errno of a poll loop that cannot be made or waited on.
|
|
554
570
|
*/
|
|
555
571
|
export const resolveHost = (name: string, timeoutMs: i32, port: i32, out: u8[], ttls: i32[]): i32 => {
|
|
556
572
|
const config: DnsConfig = new DnsConfig()
|
|
557
|
-
const conf: u8[] | null = readFileBytesSync("/etc/resolv.conf")
|
|
558
|
-
if (conf !== null) {
|
|
559
|
-
dnsParseResolvConf(conf, 0, toI32(conf.length), config)
|
|
560
|
-
} else {
|
|
561
|
-
dnsParseResolvConf(new Array<u8>(0), 0, 0, config)
|
|
562
|
-
}
|
|
563
573
|
const hosts: DnsHosts = new DnsHosts()
|
|
574
|
+
dnsLoadSystem(config, hosts)
|
|
575
|
+
return dnsLookupWith(config, hosts, name, timeoutMs, port, out, ttls)
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* Reads the system's resolver settings the way `resolveHost` does:
|
|
580
|
+
* `/etc/resolv.conf` into `config` (a missing file means the defaults) and
|
|
581
|
+
* `/etc/hosts` into `hosts` (a missing file adds no entry). A driver of its
|
|
582
|
+
* own, such as the async `fetch`'s, starts from this so every lookup in a
|
|
583
|
+
* program honours the same files. Both reads are synchronous file reads.
|
|
584
|
+
*
|
|
585
|
+
* @param config A fresh `DnsConfig` to fill, or null to leave
|
|
586
|
+
* `/etc/resolv.conf` unread (a caller with a configuration of its own).
|
|
587
|
+
* @param hosts A fresh `DnsHosts` to fill.
|
|
588
|
+
*/
|
|
589
|
+
export const dnsLoadSystem = (config: DnsConfig | null, hosts: DnsHosts): void => {
|
|
590
|
+
if (config !== null) {
|
|
591
|
+
const conf: u8[] | null = readFileBytesSync("/etc/resolv.conf")
|
|
592
|
+
if (conf !== null) {
|
|
593
|
+
dnsParseResolvConf(conf, 0, toI32(conf.length), config)
|
|
594
|
+
} else {
|
|
595
|
+
dnsParseResolvConf(new Array<u8>(0), 0, 0, config)
|
|
596
|
+
}
|
|
597
|
+
}
|
|
564
598
|
const hostsFile: u8[] | null = readFileBytesSync("/etc/hosts")
|
|
565
599
|
if (hostsFile !== null) {
|
|
566
600
|
dnsParseHosts(hostsFile, 0, toI32(hostsFile.length), hosts)
|
|
567
601
|
}
|
|
568
|
-
return dnsLookupWith(config, hosts, name, timeoutMs, port, out, ttls)
|
|
569
602
|
}
|
|
570
603
|
|
|
571
604
|
/**
|
|
@@ -618,8 +651,12 @@ export const dnsLookupWith = (
|
|
|
618
651
|
while (status === DNS_RESOLVE_PENDING) {
|
|
619
652
|
const now: i64 = monotonicNanos()
|
|
620
653
|
if (now >= end) {
|
|
621
|
-
client.
|
|
622
|
-
|
|
654
|
+
if (client.settle(lookup, now)) {
|
|
655
|
+
status = client.result(lookup, out, ttls)
|
|
656
|
+
} else {
|
|
657
|
+
client.cancel(lookup, now)
|
|
658
|
+
status = DNS_RESOLVE_TIMEOUT
|
|
659
|
+
}
|
|
623
660
|
break
|
|
624
661
|
}
|
|
625
662
|
const own: i32 = toI32((end - now + 999999) / 1000000)
|