@amritk/nish-aarch64-linux 0.35.0 → 0.36.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.
Files changed (119) hide show
  1. package/INSTALL.md +6 -1
  2. package/bin/nish +0 -0
  3. package/docs/AI.md +9 -2
  4. package/package.json +1 -1
  5. package/runtime/nish.d.ts +4612 -430
  6. package/runtime/vite.d.ts +30 -0
  7. package/runtime/vite.mjs +150 -0
  8. package/scripts/build.sh +108 -13
  9. package/std/base64.ts +34 -5
  10. package/std/bytes.ts +256 -40
  11. package/std/cli-args.ts +296 -70
  12. package/std/cli-flags.ts +184 -19
  13. package/std/cli.ts +475 -54
  14. package/std/collections.ts +121 -23
  15. package/std/compress/checksum.ts +44 -14
  16. package/std/compress/deflate.ts +224 -111
  17. package/std/compress/gzip.ts +217 -53
  18. package/std/compress/zlib.ts +63 -7
  19. package/std/crypto/aes.ts +80 -9
  20. package/std/crypto/base64url.ts +22 -0
  21. package/std/crypto/bcrypt-batch.ts +88 -21
  22. package/std/crypto/bcrypt.ts +60 -0
  23. package/std/crypto/chacha20poly1305.ts +53 -0
  24. package/std/crypto/ct.ts +32 -13
  25. package/std/crypto/ed25519.ts +47 -0
  26. package/std/crypto/hkdf.ts +198 -13
  27. package/std/crypto/hmac.ts +235 -31
  28. package/std/crypto/jwt.ts +192 -63
  29. package/std/crypto/p256.ts +159 -16
  30. package/std/crypto/p384.ts +28 -3
  31. package/std/crypto/pki-roots.ts +32 -2
  32. package/std/crypto/pki.ts +81 -15
  33. package/std/crypto/rsa.ts +33 -3
  34. package/std/crypto/sha1.ts +3 -0
  35. package/std/crypto/sha256.ts +24 -1
  36. package/std/crypto/sha512.ts +99 -14
  37. package/std/crypto/x25519.ts +152 -14
  38. package/std/crypto/x509-random.ts +10 -0
  39. package/std/crypto/x509.ts +67 -7
  40. package/std/json-equal.ts +19 -0
  41. package/std/json-format.ts +112 -13
  42. package/std/json-number.ts +64 -14
  43. package/std/json-pointer.ts +23 -1
  44. package/std/json-tokenizer.ts +100 -29
  45. package/std/json-typed.ts +713 -66
  46. package/std/json-value.ts +400 -124
  47. package/std/json.ts +138 -10
  48. package/std/map.ts +25 -7
  49. package/std/math.ts +36 -4
  50. package/std/net/buffer-pool.ts +42 -11
  51. package/std/net/dns-config.ts +109 -23
  52. package/std/net/dns-message.ts +62 -7
  53. package/std/net/dns-resolver.ts +247 -53
  54. package/std/net/dns.ts +203 -35
  55. package/std/net/fetch.ts +151 -61
  56. package/std/net/handler.ts +278 -80
  57. package/std/net/hpack.ts +262 -52
  58. package/std/net/http-compress.ts +125 -15
  59. package/std/net/http-fields.ts +85 -9
  60. package/std/net/http1-client-codec.ts +100 -19
  61. package/std/net/http1-codec.ts +235 -27
  62. package/std/net/http1-server.ts +343 -85
  63. package/std/net/http2-frame.ts +272 -35
  64. package/std/net/http2-tls.ts +135 -34
  65. package/std/net/http2.ts +247 -106
  66. package/std/net/http3-frame.ts +154 -17
  67. package/std/net/http3-server.ts +246 -96
  68. package/std/net/http3.ts +307 -115
  69. package/std/net/outbound.ts +37 -3
  70. package/std/net/postgres-carrier.ts +144 -8
  71. package/std/net/postgres.ts +723 -103
  72. package/std/net/prefork.ts +164 -31
  73. package/std/net/qpack.ts +105 -18
  74. package/std/net/quic-conn-ack.ts +59 -12
  75. package/std/net/quic-conn-cid.ts +124 -27
  76. package/std/net/quic-conn-params.ts +70 -10
  77. package/std/net/quic-datagram.ts +43 -3
  78. package/std/net/quic-frame.ts +286 -12
  79. package/std/net/quic-listener.ts +101 -32
  80. package/std/net/quic-packet.ts +302 -21
  81. package/std/net/quic-recovery.ts +228 -44
  82. package/std/net/quic-stream.ts +353 -91
  83. package/std/net/quic.ts +489 -171
  84. package/std/net/router.ts +87 -40
  85. package/std/net/tls/client.ts +166 -51
  86. package/std/net/tls/codec.ts +413 -56
  87. package/std/net/tls/record-client.ts +110 -55
  88. package/std/net/tls/record-server.ts +159 -59
  89. package/std/net/tls/record.ts +109 -12
  90. package/std/net/tls/schedule.ts +235 -26
  91. package/std/net/tls/ticket.ts +159 -40
  92. package/std/net/tls/verify.ts +49 -3
  93. package/std/net/tls-tcp.ts +250 -45
  94. package/std/net/tls.ts +221 -59
  95. package/std/net/upstream.ts +81 -45
  96. package/std/net/url.ts +97 -13
  97. package/std/net/websocket.ts +122 -12
  98. package/std/net/webtransport.ts +220 -89
  99. package/std/pair.ts +10 -2
  100. package/std/random.ts +34 -9
  101. package/std/regex.ts +352 -198
  102. package/std/region.ts +70 -15
  103. package/std/secret.ts +52 -11
  104. package/std/sort.ts +17 -2
  105. package/std/sqlite.ts +256 -35
  106. package/std/sync/ring.ts +205 -35
  107. package/std/sync/shm.ts +194 -16
  108. package/std/term-io.ts +137 -64
  109. package/std/term-pixels.ts +144 -19
  110. package/std/term-probe.ts +66 -25
  111. package/std/term-rate.ts +128 -57
  112. package/std/term.ts +332 -121
  113. package/std/testing.ts +130 -32
  114. package/std/text.ts +73 -7
  115. package/std/threads.ts +229 -41
  116. package/std/yaml-json.ts +94 -82
  117. package/std/yaml-lines.ts +47 -15
  118. package/std/yaml-write.ts +24 -16
  119. package/std/yaml.ts +764 -384
package/std/net/dns.ts CHANGED
@@ -3,18 +3,68 @@
3
3
  * `nish:net` sockets on the caller's own readiness loop, and `resolveHost`,
4
4
  * which runs a loop of its own for a program that has none.
5
5
  *
6
- * const client = new DnsClient(new DnsResolver(config, hosts, 4), loop, 1000);
7
- * const lookup = client.start("example.com", 443, monotonicNanos());
8
- * // in the loop: pollWait(loop, ready, client.timeoutMs(now, own)); hand
9
- * // each token client.owns to client.ready, call client.tick(now), and
10
- * // read client.result(lookup, out, ttls) until it is not PENDING.
6
+ * import { DnsClient, resolveHost } from "nish/net/dns"
7
+ * import { DNS_RESOLVE_MAX_ADDRESSES, DNS_RESOLVE_PENDING, DnsResolver } from "nish/net/dns-resolver"
8
+ * import { DnsConfig, dnsParseResolvConf } from "nish/net/dns-config"
9
+ * import { DNS_ADDRESS_BYTES } from "nish/net/dns-message"
10
+ * import { readFileBytesSync } from "nish:fs"
11
+ * import { pollCreate, pollWait } from "nish:net"
12
+ * import { monotonicNanos } from "nish:process"
11
13
  *
12
- * `DnsClient` opens a fresh UDP socket on a kernel-chosen port for every UDP
13
- * try and a TCP connection for every TCP one, watches each under a token of
14
- * the range it was given, and closes it when the try ends. It never waits,
15
- * never reads the clock and never reads a file: the caller's loop owns all
16
- * three, so a lookup costs a server nothing while it waits. Each send's
17
- * query ID is drawn from `crypto.getRandomValues`.
14
+ * const out: u8[] = new Array<u8>(DNS_RESOLVE_MAX_ADDRESSES * DNS_ADDRESS_BYTES)
15
+ * const ttls: i32[] = new Array<i32>(DNS_RESOLVE_MAX_ADDRESSES)
16
+ *
17
+ * // A command-line tool: block for at most two seconds.
18
+ * const count: i32 = resolveHost("example.com", 2000, 443, out, ttls)
19
+ *
20
+ * // A server: the lookup rides the loop it already runs.
21
+ * const config: DnsConfig = new DnsConfig()
22
+ * const resolv: u8[] = readFileBytesSync("/etc/resolv.conf") ?? new Array<u8>(0)
23
+ * dnsParseResolvConf(resolv, 0, toI32(resolv.length), config)
24
+ * const loop: i32 = pollCreate()
25
+ * const client: DnsClient = new DnsClient(new DnsResolver(config, null, 4), loop, 1000)
26
+ * const lookup: i32 = client.start("example.com", 443, monotonicNanos())
27
+ * if (lookup >= 0) {
28
+ * const ready: i32[] = new Array<i32>(16)
29
+ * let status: i32 = client.result(lookup, out, ttls)
30
+ * while (status === DNS_RESOLVE_PENDING) {
31
+ * const n: i32 = pollWait(loop, ready, client.timeoutMs(monotonicNanos(), -1))
32
+ * const now: i64 = monotonicNanos()
33
+ * for (let k: i32 = 0; k < n; k++) {
34
+ * if (client.owns(ready[2 * k])) {
35
+ * client.ready(ready[2 * k], ready[2 * k + 1], now)
36
+ * }
37
+ * }
38
+ * client.tick(now)
39
+ * status = client.result(lookup, out, ttls)
40
+ * }
41
+ * // status: the address count, 18 bytes each in out, or a DNS_RESOLVE_* code
42
+ * }
43
+ *
44
+ * **`DnsClient` is for a program with a loop.** It opens a fresh UDP socket
45
+ * on a kernel-chosen port for every UDP try and a TCP connection for every
46
+ * TCP one, watches each under a token of the range it was given, and closes
47
+ * it when the try ends. It never waits, never reads the clock and never
48
+ * reads a file: the caller's loop owns all three, so a lookup costs a server
49
+ * nothing while it waits. Each send's query ID is drawn from
50
+ * `crypto.getRandomValues`, and every buffer it uses is made in its
51
+ * constructor.
52
+ *
53
+ * **`resolveHost` and `dnsLookupWith` block the thread**, on a poll loop of
54
+ * their own, so they are for a command-line tool or a program's start-up.
55
+ *
56
+ * **The caller owns `out` and `ttls`.** Both need room for
57
+ * `DNS_RESOLVE_MAX_ADDRESSES` entries (18 bytes each in `out`), or the call
58
+ * that reads the answer panics; they are written only when it answers a
59
+ * count. Reading a finished lookup's answer frees its slot, so read it once.
60
+ *
61
+ * **Errors are negative numbers.** `start` answers `DNS_RESOLVE_BUSY` when
62
+ * every slot is in use or the `DNS_ERR_*` code of a name that is not one; a
63
+ * finished lookup answers `DNS_RESOLVE_NOT_FOUND`, `DNS_RESOLVE_NO_ANSWER` or
64
+ * `DNS_RESOLVE_CNAME`. A socket that cannot be opened, written or connected
65
+ * fails that one try, counted in `socketFailures`, and the query moves to
66
+ * the next server. A token outside the client's range, a negative token base
67
+ * and an `out` or `ttls` that is too short are bugs in the caller and panic.
18
68
  *
19
69
  * Private helpers share the importing program's flat symbol namespace
20
70
  * (`docs/wp26-stdlib.md` §3e), which is why each one carries the module's name.
@@ -48,7 +98,10 @@ import {
48
98
  import { readFileBytesSync } from "nish:fs"
49
99
  import { monotonicNanos } from "nish:process"
50
100
 
51
- /** The longest datagram a UDP try reads; a longer one is cut, fails to parse and is dropped. */
101
+ /**
102
+ * The longest datagram a UDP try reads, in bytes; a longer one is cut, fails
103
+ * to parse and is dropped. A TCP try reads its stream in chunks of this size.
104
+ */
52
105
  export const DNS_UDP_MAX_REPLY: i32 = 4096
53
106
 
54
107
  /**
@@ -72,25 +125,46 @@ const DNS_FD_TCP_READ: i32 = 3
72
125
  export class DnsClient {
73
126
  /** The core; `start`, `result` and `cancel` go through the client so its sockets follow. */
74
127
  resolver: DnsResolver
75
- /** Each query's socket, or -1. */
128
+ /**
129
+ * Each query's socket, or -1.
130
+ * @internal Used by `dnsClientClose`, `dnsClientSendUdp`, `dnsClientOpenTcp`, `dnsClientReadDatagrams` and `dnsClientReadStream` in this module.
131
+ */
76
132
  fds: i32[]
77
- /** What each query's socket is doing, a `DNS_FD_*`. */
133
+ /**
134
+ * What each query's socket is doing, a `DNS_FD_*`.
135
+ * @internal Used by `dnsClientClose`, `dnsClientSendUdp`, `dnsClientOpenTcp`, `dnsClientWrite` and `dnsClientReadStream` in this module.
136
+ */
78
137
  fdState: i32[]
79
- /** Each query's TCP bytes, length prefix first, kept until they are all written. */
138
+ /**
139
+ * Each query's TCP bytes, length prefix first, kept until they are all written.
140
+ * @internal Used by `dnsClientOpenTcp` and `dnsClientWrite` in this module.
141
+ */
80
142
  outputs: u8[][]
143
+ /** @internal Used by `dnsClientOpenTcp` and `dnsClientWrite` in this module. */
81
144
  outputLength: i32[]
145
+ /** @internal Used by `dnsClientOpenTcp` and `dnsClientWrite` in this module. */
82
146
  outputSent: i32[]
83
- /** Scratch for `nextOutgoing`, a read, a sender's address and the ID. */
147
+ /**
148
+ * Scratch for `nextOutgoing`, a read, a sender's address and the ID.
149
+ * @internal Used by `dnsClientSendUdp` and `dnsClientOpenTcp` in this module.
150
+ */
84
151
  out: u8[]
152
+ /** @internal Used by `dnsClientSendUdp` and `dnsClientOpenTcp` in this module. */
85
153
  to: u8[]
154
+ /** @internal Used by `dnsClientSendUdp` and `dnsClientOpenTcp` in this module. */
86
155
  meta: i32[]
156
+ /** @internal Used by `dnsClientReadDatagrams` and `dnsClientReadStream` in this module. */
87
157
  buf: u8[]
158
+ /** @internal Used by `dnsClientReadDatagrams` in this module. */
88
159
  from: u8[]
160
+ /** @internal Used by `dnsClientReadDatagrams` in this module. */
89
161
  recvMeta: i32[]
90
- idBytes: u8[]
162
+ private idBytes: u8[]
91
163
  /** Whether `idBytes` holds an ID no send has used yet. */
92
- idFresh: boolean = false
164
+ private idFresh: boolean = false
165
+ /** @internal Used by `dnsClientSendUdp`, `dnsClientOpenTcp` and `dnsClientWrite` in this module. */
93
166
  loop: i32 = 0
167
+ /** The first of the client's tokens; its sockets use `tokenBase` to `tokenBase + tokens() - 1`. */
94
168
  tokenBase: i32 = 0
95
169
  /** Sockets that could not be opened, written or connected, each a failed try. */
96
170
  socketFailures: i32 = 0
@@ -99,7 +173,14 @@ export class DnsClient {
99
173
 
100
174
  /**
101
175
  * A client for `resolver` whose sockets join the loop `loop` under tokens
102
- * from `tokenBase`. Panics when `tokenBase` is negative.
176
+ * from `tokenBase`. Every buffer the client uses is made here, one TCP
177
+ * output buffer per query among them. Panics when `tokenBase` is negative.
178
+ *
179
+ * @param resolver The core the client drives; the client owns it from now on, so go through
180
+ * the client's `start`, `result` and `cancel` rather than the resolver's.
181
+ * @param loop The `pollCreate` loop the client's sockets join; the caller keeps it and closes it.
182
+ * @param tokenBase The first of `tokens()` consecutive tokens the client watches its sockets
183
+ * under; pick a range none of the caller's own sockets use.
103
184
  */
104
185
  constructor(resolver: DnsResolver, loop: i32, tokenBase: i32) {
105
186
  if (tokenBase < 0) {
@@ -129,29 +210,70 @@ export class DnsClient {
129
210
  this.idBytes = new Array<u8>(2)
130
211
  }
131
212
 
132
- /** How many tokens, from `tokenBase`, the client's sockets use. */
213
+ /**
214
+ * How many tokens, from `tokenBase`, the client's sockets use: two per
215
+ * lookup slot, one for the A query and one for the AAAA query.
216
+ *
217
+ * @returns The width of the client's token range.
218
+ */
133
219
  tokens(): i32 {
134
220
  return this.resolver.maxLookups * 2
135
221
  }
136
222
 
137
- /** Whether `token` is one of the client's. */
223
+ /**
224
+ * Whether `token` is one of the client's, so the caller knows which ready
225
+ * pairs from `pollWait` to hand to `ready`.
226
+ *
227
+ * @param token A token `pollWait` reported.
228
+ * @returns True when `token` lies in `tokenBase` to `tokenBase + tokens() - 1`.
229
+ */
138
230
  owns(token: i32): boolean {
139
231
  return token >= this.tokenBase && token - this.tokenBase < this.tokens()
140
232
  }
141
233
 
142
- /** `DnsResolver.start`, with its first packets sent: the lookup, or a negative error. */
234
+ /**
235
+ * `DnsResolver.start`, with its first packets sent. `localhost`, an address
236
+ * literal and a hosts entry finish at once, so `result` has their answer
237
+ * straight away.
238
+ *
239
+ * @param name The name to look up, as the search list and `ndots` will read it.
240
+ * @param port The port, 0 to 65535, written into every address the lookup answers; any other
241
+ * value panics.
242
+ * @param nowNanos The caller's monotonic clock now, in nanoseconds.
243
+ * @returns The lookup's id, 0 or more, to pass to `result` and `cancel`; or `DNS_RESOLVE_BUSY`
244
+ * when every slot is in use, or the negative `DNS_ERR_*` code of a name that is not one.
245
+ */
143
246
  start(name: string, port: i32, nowNanos: i64): i32 {
144
247
  const lookup: i32 = this.resolver.start(name, port, nowNanos)
145
248
  this.pump(nowNanos)
146
249
  return lookup
147
250
  }
148
251
 
149
- /** `DnsResolver.result`; a finished lookup's sockets are already closed. */
252
+ /**
253
+ * `DnsResolver.result`; a finished lookup's sockets are already closed.
254
+ * Answering a finished lookup frees its slot, so a second call for it, or
255
+ * one for an id `start` did not give out, panics.
256
+ *
257
+ * @param lookup An id `start` answered.
258
+ * @param out Where the addresses go, 18 bytes each from offset 0, A first, with the lookup's
259
+ * port; it needs room for `DNS_RESOLVE_MAX_ADDRESSES`, or this panics.
260
+ * @param ttls Where each address's TTL goes, in seconds; room for
261
+ * `DNS_RESOLVE_MAX_ADDRESSES`, or this panics.
262
+ * @returns `DNS_RESOLVE_PENDING` while the lookup runs; once it has finished, the count of
263
+ * addresses written, or a negative `DNS_RESOLVE_*` code.
264
+ */
150
265
  result(lookup: i32, out: u8[], ttls: i32[]): i32 {
151
266
  return this.resolver.result(lookup, out, ttls)
152
267
  }
153
268
 
154
- /** `DnsResolver.cancel`, closing the lookup's sockets. */
269
+ /**
270
+ * `DnsResolver.cancel`, closing the lookup's sockets now and freeing its
271
+ * slot, whether or not it had finished. Panics for an id that is not a
272
+ * lookup in progress, as `result` does.
273
+ *
274
+ * @param lookup An id `start` answered whose answer has not been read.
275
+ * @param nowNanos The caller's monotonic clock now, in nanoseconds.
276
+ */
155
277
  cancel(lookup: i32, nowNanos: i64): void {
156
278
  this.resolver.cancel(lookup)
157
279
  this.pump(nowNanos)
@@ -162,6 +284,12 @@ export class DnsClient {
162
284
  * token `owns` answers true for: reads the datagrams (at most
163
285
  * `DNS_CLIENT_MAX_DATAGRAMS`) or stream bytes that are waiting, finishes a
164
286
  * connection or a write, and sends whatever the core asks next. Panics for a token that is not the client's.
287
+ * A token whose try has already ended is ignored.
288
+ *
289
+ * @param token The ready token, one `owns` answers true for.
290
+ * @param events The events `pollWait` reported with it: 1 readable, 2 writable, with 4 added
291
+ * for a hang-up or an error.
292
+ * @param nowNanos The caller's monotonic clock now, in nanoseconds.
165
293
  */
166
294
  ready(token: i32, events: i32, nowNanos: i64): void {
167
295
  if (!this.owns(token)) {
@@ -183,7 +311,12 @@ export class DnsClient {
183
311
  this.pump(nowNanos)
184
312
  }
185
313
 
186
- /** `DnsResolver.tick`, then whatever it asks to send. */
314
+ /**
315
+ * `DnsResolver.tick`, then whatever it asks to send: every try past its
316
+ * deadline moves to the next server. Call it after each wake of the loop.
317
+ *
318
+ * @param nowNanos The caller's monotonic clock now, in nanoseconds.
319
+ */
187
320
  tick(nowNanos: i64): void {
188
321
  this.resolver.tick(nowNanos)
189
322
  this.pump(nowNanos)
@@ -193,6 +326,12 @@ export class DnsClient {
193
326
  * The `pollWait` timeout for a caller who would otherwise wait `ownMs`
194
327
  * (negative for ever): the smaller of it and the milliseconds, rounded up,
195
328
  * to the core's next deadline after `nowNanos`.
329
+ *
330
+ * @param nowNanos The caller's monotonic clock now, in nanoseconds.
331
+ * @param ownMs How long the caller would wait for its own sake, in milliseconds, or negative
332
+ * to wait for ever.
333
+ * @returns The milliseconds to pass to `pollWait`: 0 when a deadline has already passed,
334
+ * `ownMs` itself when the client has no try in flight.
196
335
  */
197
336
  timeoutMs(nowNanos: i64, ownMs: i32): i32 {
198
337
  const deadline: i64 = this.resolver.nextDeadlineNanos()
@@ -209,7 +348,10 @@ export class DnsClient {
209
348
  return toI32(wait)
210
349
  }
211
350
 
212
- /** Carries out everything the core has queued: opens, sends and closes sockets. */
351
+ /**
352
+ * Carries out everything the core has queued: opens, sends and closes sockets.
353
+ * @internal Used by `dnsClientReadDatagrams` and `dnsClientReadStream` in this module.
354
+ */
213
355
  pump(nowNanos: i64): void {
214
356
  let q: i32 = this.nextOutgoing()
215
357
  while (q >= 0 && q < toI32(this.fds.length)) {
@@ -229,7 +371,7 @@ export class DnsClient {
229
371
  * drawn only after the last went out, so an empty call or a close costs no
230
372
  * `getRandomValues`.
231
373
  */
232
- nextOutgoing(): i32 {
374
+ private nextOutgoing(): i32 {
233
375
  if (!this.idFresh) {
234
376
  crypto.getRandomValues(this.idBytes)
235
377
  this.idFresh = true
@@ -385,17 +527,30 @@ const dnsClientReadStream = (c: DnsClient, q: i32, fd: i32, hungUp: boolean, now
385
527
 
386
528
  /**
387
529
  * The addresses of `name`, looked up as `/etc/resolv.conf` and `/etc/hosts`
388
- * say (either missing means the defaults), each 18 bytes with `port` into
389
- * `out` and its TTL in seconds into `ttls`: the count, or a negative
390
- * `DNS_RESOLVE_*` code, `DNS_RESOLVE_TIMEOUT` once `timeoutMs` has passed,
391
- * or the negative errno of a poll loop that cannot be made or waited on.
392
- * It waits for both the A and the AAAA answer, so a family that answered is
393
- * not returned on its own once `timeoutMs` passes: it is `DNS_RESOLVE_TIMEOUT`.
530
+ * say (a missing resolv.conf means the defaults, a missing hosts file no
531
+ * 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, so a family that
533
+ * answered is not returned on its own once `timeoutMs` passes: it is
534
+ * `DNS_RESOLVE_TIMEOUT`.
394
535
  *
395
536
  * **It blocks the thread** until the lookup ends, on a loop of its own, so
396
537
  * it is for a CLI or a program's start-up; a server resolves with a
397
538
  * `DnsClient` on its own loop. `out` and `ttls` need room for
398
- * `DNS_RESOLVE_MAX_ADDRESSES`, or it panics.
539
+ * `DNS_RESOLVE_MAX_ADDRESSES`, or it panics. Each call reads both files and
540
+ * makes its own configuration, resolver and loop, closing the loop before
541
+ * it returns.
542
+ *
543
+ * @param name The name to look up; `localhost`, an address literal and a hosts entry answer
544
+ * without a packet, even with a `timeoutMs` of 0.
545
+ * @param timeoutMs The most the whole lookup may take, in milliseconds, on the monotonic clock.
546
+ * @param port The port, 0 to 65535, written into every address; any other value panics.
547
+ * @param out Where the addresses go, from offset 0, A first; at least
548
+ * `DNS_RESOLVE_MAX_ADDRESSES * 18` bytes.
549
+ * @param ttls Where each address's TTL goes, in seconds; at least `DNS_RESOLVE_MAX_ADDRESSES`.
550
+ * @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
552
+ * `DNS_RESOLVE_CNAME` from the lookup, the `DNS_ERR_*` code of a name that is not one, or
553
+ * the negative errno of a poll loop that cannot be made or waited on.
399
554
  */
400
555
  export const resolveHost = (name: string, timeoutMs: i32, port: i32, out: u8[], ttls: i32[]): i32 => {
401
556
  const config: DnsConfig = new DnsConfig()
@@ -416,7 +571,20 @@ export const resolveHost = (name: string, timeoutMs: i32, port: i32, out: u8[],
416
571
  /**
417
572
  * `resolveHost` with the configuration given rather than read: one lookup
418
573
  * of `name` on a loop of its own, for at most `timeoutMs`. Blocks as
419
- * `resolveHost` does.
574
+ * `resolveHost` does, and reads no file. `config` and `hosts` are only read,
575
+ * so one pair can serve many calls.
576
+ *
577
+ * @param config The resolv.conf to use, as `dnsParseResolvConf` filled it.
578
+ * @param hosts The hosts file to consult first, as `dnsParseHosts` filled it, or null for none.
579
+ * @param name The name to look up.
580
+ * @param timeoutMs The most the whole lookup may take, in milliseconds, on the monotonic clock.
581
+ * @param port The port, 0 to 65535, written into every address; any other value panics.
582
+ * @param out Where the addresses go, from offset 0, A first; at least
583
+ * `DNS_RESOLVE_MAX_ADDRESSES * 18` bytes, or this panics.
584
+ * @param ttls Where each address's TTL goes, in seconds; at least `DNS_RESOLVE_MAX_ADDRESSES`,
585
+ * or this panics.
586
+ * @returns What `resolveHost` answers: the address count, or a negative `DNS_RESOLVE_*`,
587
+ * `DNS_ERR_*` or errno code.
420
588
  */
421
589
  export const dnsLookupWith = (
422
590
  config: DnsConfig,