@amritk/nish-aarch64-darwin 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.
- package/INSTALL.md +6 -1
- package/bin/nish +0 -0
- package/docs/AI.md +9 -2
- package/package.json +1 -1
- package/runtime/nish.d.ts +4612 -430
- package/runtime/vite.d.ts +30 -0
- package/runtime/vite.mjs +150 -0
- package/scripts/build.sh +108 -13
- package/std/base64.ts +34 -5
- package/std/bytes.ts +256 -40
- package/std/cli-args.ts +296 -70
- package/std/cli-flags.ts +184 -19
- package/std/cli.ts +475 -54
- package/std/collections.ts +121 -23
- package/std/compress/checksum.ts +44 -14
- package/std/compress/deflate.ts +224 -111
- package/std/compress/gzip.ts +217 -53
- package/std/compress/zlib.ts +63 -7
- package/std/crypto/aes.ts +80 -9
- package/std/crypto/base64url.ts +22 -0
- package/std/crypto/bcrypt-batch.ts +88 -21
- package/std/crypto/bcrypt.ts +60 -0
- package/std/crypto/chacha20poly1305.ts +53 -0
- package/std/crypto/ct.ts +32 -13
- package/std/crypto/ed25519.ts +47 -0
- package/std/crypto/hkdf.ts +198 -13
- package/std/crypto/hmac.ts +235 -31
- package/std/crypto/jwt.ts +192 -63
- package/std/crypto/p256.ts +159 -16
- package/std/crypto/p384.ts +28 -3
- package/std/crypto/pki-roots.ts +32 -2
- package/std/crypto/pki.ts +81 -15
- package/std/crypto/rsa.ts +33 -3
- package/std/crypto/sha1.ts +3 -0
- package/std/crypto/sha256.ts +24 -1
- package/std/crypto/sha512.ts +99 -14
- package/std/crypto/x25519.ts +152 -14
- package/std/crypto/x509-random.ts +10 -0
- package/std/crypto/x509.ts +67 -7
- package/std/json-equal.ts +19 -0
- package/std/json-format.ts +112 -13
- package/std/json-number.ts +64 -14
- package/std/json-pointer.ts +23 -1
- package/std/json-tokenizer.ts +100 -29
- package/std/json-typed.ts +713 -66
- package/std/json-value.ts +400 -124
- package/std/json.ts +138 -10
- package/std/map.ts +25 -7
- package/std/math.ts +36 -4
- package/std/net/buffer-pool.ts +42 -11
- package/std/net/dns-config.ts +109 -23
- package/std/net/dns-message.ts +62 -7
- package/std/net/dns-resolver.ts +247 -53
- package/std/net/dns.ts +203 -35
- package/std/net/fetch.ts +151 -61
- package/std/net/handler.ts +278 -80
- package/std/net/hpack.ts +262 -52
- package/std/net/http-compress.ts +125 -15
- package/std/net/http-fields.ts +85 -9
- package/std/net/http1-client-codec.ts +100 -19
- package/std/net/http1-codec.ts +235 -27
- package/std/net/http1-server.ts +343 -85
- package/std/net/http2-frame.ts +272 -35
- package/std/net/http2-tls.ts +135 -34
- package/std/net/http2.ts +247 -106
- package/std/net/http3-frame.ts +154 -17
- package/std/net/http3-server.ts +246 -96
- package/std/net/http3.ts +307 -115
- package/std/net/outbound.ts +37 -3
- package/std/net/postgres-carrier.ts +144 -8
- package/std/net/postgres.ts +723 -103
- package/std/net/prefork.ts +164 -31
- package/std/net/qpack.ts +105 -18
- package/std/net/quic-conn-ack.ts +59 -12
- package/std/net/quic-conn-cid.ts +124 -27
- package/std/net/quic-conn-params.ts +70 -10
- package/std/net/quic-datagram.ts +43 -3
- package/std/net/quic-frame.ts +286 -12
- package/std/net/quic-listener.ts +101 -32
- package/std/net/quic-packet.ts +302 -21
- package/std/net/quic-recovery.ts +228 -44
- package/std/net/quic-stream.ts +353 -91
- package/std/net/quic.ts +489 -171
- package/std/net/router.ts +87 -40
- package/std/net/tls/client.ts +166 -51
- package/std/net/tls/codec.ts +413 -56
- package/std/net/tls/record-client.ts +110 -55
- package/std/net/tls/record-server.ts +159 -59
- package/std/net/tls/record.ts +109 -12
- package/std/net/tls/schedule.ts +235 -26
- package/std/net/tls/ticket.ts +159 -40
- package/std/net/tls/verify.ts +49 -3
- package/std/net/tls-tcp.ts +250 -45
- package/std/net/tls.ts +221 -59
- package/std/net/upstream.ts +81 -45
- package/std/net/url.ts +97 -13
- package/std/net/websocket.ts +122 -12
- package/std/net/webtransport.ts +220 -89
- package/std/pair.ts +10 -2
- package/std/random.ts +34 -9
- package/std/regex.ts +352 -198
- package/std/region.ts +70 -15
- package/std/secret.ts +52 -11
- package/std/sort.ts +17 -2
- package/std/sqlite.ts +256 -35
- package/std/sync/ring.ts +205 -35
- package/std/sync/shm.ts +194 -16
- package/std/term-io.ts +137 -64
- package/std/term-pixels.ts +144 -19
- package/std/term-probe.ts +66 -25
- package/std/term-rate.ts +128 -57
- package/std/term.ts +332 -121
- package/std/testing.ts +130 -32
- package/std/text.ts +73 -7
- package/std/threads.ts +229 -41
- package/std/yaml-json.ts +94 -82
- package/std/yaml-lines.ts +47 -15
- package/std/yaml-write.ts +24 -16
- package/std/yaml.ts +764 -384
package/std/net/http2-tls.ts
CHANGED
|
@@ -5,24 +5,42 @@
|
|
|
5
5
|
* server, so a bad `Http2Config` is refused there; every other slot's is built
|
|
6
6
|
* on the first accept into it.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
8
|
+
* import { Secret } from "nish:secret";
|
|
9
|
+
* import { pollAdd, pollModify, tcpListen } from "nish:net";
|
|
10
|
+
* import { H2_ERROR, H2_NEED_MORE, H2_REQUEST, Http2Config, Http2Connection } from "nish/net/http2";
|
|
11
|
+
* import { Http2TlsServer } from "nish/net/http2-tls";
|
|
12
|
+
* import { TlsServerConfig } from "nish/net/tls";
|
|
13
|
+
* import { TLS_RECORD_DONE, TLS_RECORD_SIGN } from "nish/net/tls/record-server";
|
|
14
|
+
*
|
|
15
|
+
* // `tlsConfig.alpn` holds `H2_ALPN`; `loop` is the program's, from `pollCreate`.
|
|
16
|
+
* const LISTENER: i32 = 64; // past every slot's token
|
|
17
|
+
* const start = (loop: i32, tlsConfig: TlsServerConfig): Http2TlsServer => {
|
|
18
|
+
* const listener: i32 = tcpListen("0.0.0.0", 8443, 128);
|
|
19
|
+
* pollAdd(loop, listener, 1, LISTENER);
|
|
20
|
+
* return new Http2TlsServer(tlsConfig, new Http2Config(), listener, 64);
|
|
21
|
+
* };
|
|
22
|
+
* // When the listener's token comes back:
|
|
23
|
+
* const admit = (loop: i32, server: Http2TlsServer, random: u8[], key: u8[]): void => {
|
|
24
|
+
* crypto.getRandomValues(random);
|
|
25
|
+
* crypto.getRandomValues(key);
|
|
26
|
+
* const slot: i32 = server.accept(random, key);
|
|
27
|
+
* if (slot >= 0) { pollAdd(loop, server.fd(slot), 1, slot); }
|
|
28
|
+
* };
|
|
29
|
+
* // When a slot's token comes back with `events`:
|
|
30
|
+
* const serve = (loop: i32, server: Http2TlsServer, slot: i32, events: i32, key: Secret<u8[]>): void => {
|
|
31
|
+
* let wants: i32 = (events & 5) !== 0 ? server.readable(slot) : server.writable(slot);
|
|
32
|
+
* if ((wants & TLS_RECORD_SIGN) !== 0) { wants = server.signP256(slot, key); }
|
|
33
|
+
* const none: u8[][] = [];
|
|
34
|
+
* let event: i32 = server.next(slot);
|
|
35
|
+
* while (event !== H2_NEED_MORE && event !== H2_ERROR) {
|
|
36
|
+
* const conn: Http2Connection = server.connection(slot);
|
|
37
|
+
* if (event === H2_REQUEST) { conn.respond(conn.stream, 200, none, none, true); }
|
|
38
|
+
* event = server.next(slot);
|
|
39
|
+
* }
|
|
40
|
+
* wants = server.flush(slot);
|
|
41
|
+
* if ((wants & TLS_RECORD_DONE) !== 0) { server.close(slot); }
|
|
42
|
+
* else { pollModify(loop, server.fd(slot), wants & 3, slot); }
|
|
43
|
+
* };
|
|
26
44
|
*
|
|
27
45
|
* It is `nish/net/tls-tcp`'s loop with one step added: `next` moves what TLS
|
|
28
46
|
* has decrypted into the slot's connection and answers the connection's next
|
|
@@ -82,9 +100,15 @@ export const H2_ALPN: string = "h2"
|
|
|
82
100
|
* `TlsTcpServer`'s, and `connection(slot)` is the HTTP/2 side of each.
|
|
83
101
|
*/
|
|
84
102
|
export class Http2TlsServer {
|
|
103
|
+
/**
|
|
104
|
+
* The TLS pool under this server, slot for slot, for what this class does not wrap, such as session
|
|
105
|
+
* tickets (`enableTickets`, `issue`, `resume`). Accept through this class's `accept`: a slot accepted on
|
|
106
|
+
* `tls` itself gets no fresh HTTP/2 connection, so `next` and `flush` may treat it as free or run it on
|
|
107
|
+
* the state of the slot's last peer.
|
|
108
|
+
*/
|
|
85
109
|
tls: TlsTcpServer
|
|
86
110
|
/** The caps every slot's connection is made under. */
|
|
87
|
-
config: Http2Config
|
|
111
|
+
private config: Http2Config
|
|
88
112
|
/**
|
|
89
113
|
* The connections made so far, slot `k`'s at `k`: slot 0's, made by the
|
|
90
114
|
* constructor, and one for each slot accepted into since.
|
|
@@ -105,6 +129,12 @@ export class Http2TlsServer {
|
|
|
105
129
|
* here, so a config it refuses panics now, with its words; every other
|
|
106
130
|
* slot's is made by the first `accept` into it and kept. Frame buffers are
|
|
107
131
|
* borrowed from `pools` as a connection needs them.
|
|
132
|
+
*
|
|
133
|
+
* @param tlsConfig What TLS serves on every slot: the certificate chain, the ALPN list (which must offer
|
|
134
|
+
* `h2`) and the rest; every slot shares it.
|
|
135
|
+
* @param config The caps every slot's connection is made under; kept, and shared by every slot.
|
|
136
|
+
* @param listener The listening socket from `tcpListen`; the program still owns it and closes it.
|
|
137
|
+
* @param size How many connections may be open at once; anything below 1 is taken as 1.
|
|
108
138
|
*/
|
|
109
139
|
constructor(tlsConfig: TlsServerConfig, config: Http2Config, listener: i32, size: i32) {
|
|
110
140
|
this.tls = new TlsTcpServer(tlsConfig, listener, size)
|
|
@@ -121,7 +151,7 @@ export class Http2TlsServer {
|
|
|
121
151
|
}
|
|
122
152
|
|
|
123
153
|
/** Makes the next slot's connection, on this pool's buffers and `date`. */
|
|
124
|
-
build(): void {
|
|
154
|
+
private build(): void {
|
|
125
155
|
const conn: Http2Connection = new Http2Connection(this.config)
|
|
126
156
|
conn.date = this.date.current()
|
|
127
157
|
conn.pools = this.pools
|
|
@@ -129,26 +159,45 @@ export class Http2TlsServer {
|
|
|
129
159
|
}
|
|
130
160
|
|
|
131
161
|
/** Whether `slot` holds a connection and its HTTP/2 side has been made. */
|
|
132
|
-
live(slot: i32): boolean {
|
|
162
|
+
private live(slot: i32): boolean {
|
|
133
163
|
return this.tls.holds(slot) && slot < toI32(this.connections.length)
|
|
134
164
|
}
|
|
135
165
|
|
|
136
|
-
/**
|
|
166
|
+
/**
|
|
167
|
+
* How many slots the pool has, made or not.
|
|
168
|
+
*
|
|
169
|
+
* @returns The slot count the TLS pool settled on, at least 1.
|
|
170
|
+
*/
|
|
137
171
|
size(): i32 {
|
|
138
172
|
return this.tls.size()
|
|
139
173
|
}
|
|
140
174
|
|
|
141
|
-
/**
|
|
175
|
+
/**
|
|
176
|
+
* How many slots hold a connection.
|
|
177
|
+
*
|
|
178
|
+
* @returns Slots with an open descriptor, lingering ones included; 0 to `size()`.
|
|
179
|
+
*/
|
|
142
180
|
busy(): i32 {
|
|
143
181
|
return this.tls.busy()
|
|
144
182
|
}
|
|
145
183
|
|
|
146
|
-
/**
|
|
184
|
+
/**
|
|
185
|
+
* Whether `slot` holds a connection.
|
|
186
|
+
*
|
|
187
|
+
* @param slot A slot number, as `accept` answered it; any value is safe to ask about.
|
|
188
|
+
* @returns True when `slot` is in range and holds a descriptor, lingering or live.
|
|
189
|
+
*/
|
|
147
190
|
holds(slot: i32): boolean {
|
|
148
191
|
return this.tls.holds(slot)
|
|
149
192
|
}
|
|
150
193
|
|
|
151
|
-
/**
|
|
194
|
+
/**
|
|
195
|
+
* The descriptor of `slot`, for `pollAdd`.
|
|
196
|
+
*
|
|
197
|
+
* @param slot A slot number, as `accept` answered it.
|
|
198
|
+
* @returns The socket descriptor, which the pool still owns and closes in `close`; -1 when `slot` holds
|
|
199
|
+
* none.
|
|
200
|
+
*/
|
|
152
201
|
fd(slot: i32): i32 {
|
|
153
202
|
return this.tls.fd(slot)
|
|
154
203
|
}
|
|
@@ -156,6 +205,10 @@ export class Http2TlsServer {
|
|
|
156
205
|
/**
|
|
157
206
|
* The HTTP/2 connection of `slot`, its `date` brought up to now. A slot
|
|
158
207
|
* never accepted into, or out of range, names slot 0's, which may be live.
|
|
208
|
+
*
|
|
209
|
+
* @param slot A slot number, as `accept` answered it.
|
|
210
|
+
* @returns The slot's connection, to read events from and answer on; the server keeps it and restarts
|
|
211
|
+
* it for the slot's next peer.
|
|
159
212
|
*/
|
|
160
213
|
connection(slot: i32): Http2Connection {
|
|
161
214
|
this.date.current()
|
|
@@ -163,7 +216,13 @@ export class Http2TlsServer {
|
|
|
163
216
|
return this.connections[at]
|
|
164
217
|
}
|
|
165
218
|
|
|
166
|
-
/**
|
|
219
|
+
/**
|
|
220
|
+
* The ALPN protocol `slot`'s handshake chose.
|
|
221
|
+
*
|
|
222
|
+
* @param slot A slot number, as `accept` answered it.
|
|
223
|
+
* @returns The protocol chosen, empty when none was or the handshake is not that far; a free slot
|
|
224
|
+
* answers its last connection's, and a slot out of range slot 0's.
|
|
225
|
+
*/
|
|
167
226
|
alpn(slot: i32): string {
|
|
168
227
|
return this.tls.connection(slot).tls.alpn
|
|
169
228
|
}
|
|
@@ -174,6 +233,13 @@ export class Http2TlsServer {
|
|
|
174
233
|
* SETTINGS go out once the handshake is done: the slot's own, restarted,
|
|
175
234
|
* or one made now if this is the first accept into it. Answers the slot,
|
|
176
235
|
* or what `TlsTcpServer.accept` answers.
|
|
236
|
+
*
|
|
237
|
+
* @param serverRandom 32 fresh random bytes for the ServerHello's random; copied, not kept.
|
|
238
|
+
* @param ephemeralPrivate 32 fresh random bytes for this handshake's key share; when a slot is answered it
|
|
239
|
+
* has been copied into the slot and this array wiped.
|
|
240
|
+
* @returns The slot, 0 or more, that now holds the connection; or, taking none, -11 when no connection is
|
|
241
|
+
* waiting, `TLS_TCP_POOL_FULL` when every slot is busy (the connection is closed), `tcpAccept`'s own
|
|
242
|
+
* failure, or `TLS_RECORD_INVALID` (-22) for a random or key that is not 32 bytes.
|
|
177
243
|
*/
|
|
178
244
|
accept(serverRandom: u8[], ephemeralPrivate: u8[]): i32 {
|
|
179
245
|
const slot: i32 = this.tls.accept(serverRandom, ephemeralPrivate)
|
|
@@ -189,7 +255,12 @@ export class Http2TlsServer {
|
|
|
189
255
|
return slot
|
|
190
256
|
}
|
|
191
257
|
|
|
192
|
-
/**
|
|
258
|
+
/**
|
|
259
|
+
* The socket of `slot` is readable: TLS reads it, and what HTTP/2 has to send goes after.
|
|
260
|
+
*
|
|
261
|
+
* @param slot The slot whose socket `pollWait` reported readable, or hung up.
|
|
262
|
+
* @returns The slot's interest, as `flush` answers it; `TLS_RECORD_DONE` for a free slot.
|
|
263
|
+
*/
|
|
193
264
|
readable(slot: i32): i32 {
|
|
194
265
|
this.tls.readable(slot)
|
|
195
266
|
const wants: i32 = this.flush(slot)
|
|
@@ -197,7 +268,12 @@ export class Http2TlsServer {
|
|
|
197
268
|
return wants
|
|
198
269
|
}
|
|
199
270
|
|
|
200
|
-
/**
|
|
271
|
+
/**
|
|
272
|
+
* The socket of `slot` is writable: what TLS and HTTP/2 hold goes out.
|
|
273
|
+
*
|
|
274
|
+
* @param slot The slot whose socket `pollWait` reported writable.
|
|
275
|
+
* @returns The slot's interest, as `flush` answers it; `TLS_RECORD_DONE` for a free slot.
|
|
276
|
+
*/
|
|
201
277
|
writable(slot: i32): i32 {
|
|
202
278
|
this.tls.writable(slot)
|
|
203
279
|
const wants: i32 = this.flush(slot)
|
|
@@ -205,7 +281,13 @@ export class Http2TlsServer {
|
|
|
205
281
|
return wants
|
|
206
282
|
}
|
|
207
283
|
|
|
208
|
-
/**
|
|
284
|
+
/**
|
|
285
|
+
* Signs `slot`'s CertificateVerify with `key`, as `TlsTcpServer.signP256` does.
|
|
286
|
+
*
|
|
287
|
+
* @param slot The slot whose interest says `TLS_RECORD_SIGN`.
|
|
288
|
+
* @param key The certificate's P-256 private key; borrowed for the call, still the caller's to wipe.
|
|
289
|
+
* @returns The slot's interest, as `flush` answers it; `TLS_RECORD_DONE` for a free slot.
|
|
290
|
+
*/
|
|
209
291
|
signP256(slot: i32, key: Secret<u8[]>): i32 {
|
|
210
292
|
this.tls.signP256(slot, key)
|
|
211
293
|
const wants: i32 = this.flush(slot)
|
|
@@ -214,7 +296,7 @@ export class Http2TlsServer {
|
|
|
214
296
|
}
|
|
215
297
|
|
|
216
298
|
/** Whether `slot`'s handshake is done and chose anything but `h2`. */
|
|
217
|
-
refused(slot: i32): boolean {
|
|
299
|
+
private refused(slot: i32): boolean {
|
|
218
300
|
return this.tls.connection(slot).state === TLS_RECORD_STATE_OPEN && this.alpn(slot) !== H2_ALPN
|
|
219
301
|
}
|
|
220
302
|
|
|
@@ -222,6 +304,12 @@ export class Http2TlsServer {
|
|
|
222
304
|
* Moves what TLS has decrypted for `slot` into its connection, as far as
|
|
223
305
|
* the connection has room, and answers the connection's next event. A free
|
|
224
306
|
* slot, or one whose ALPN was not `h2`, answers `H2_ERROR`.
|
|
307
|
+
*
|
|
308
|
+
* @param slot The slot to read, as `accept` answered it.
|
|
309
|
+
* @returns The connection's next event, `H2_REQUEST` to `H2_GOAWAY` of `nish/net/http2`, read from
|
|
310
|
+
* `connection(slot)`; `H2_NEED_MORE` once it needs more input or its output to drain, after the
|
|
311
|
+
* output has gone to TLS; or `H2_ERROR` for a connection that failed, a free slot, a slot
|
|
312
|
+
* whose HTTP/2 connection was never made, or one whose ALPN was not `h2`.
|
|
225
313
|
*/
|
|
226
314
|
next(slot: i32): i32 {
|
|
227
315
|
if (!this.live(slot) || this.refused(slot)) {
|
|
@@ -258,9 +346,16 @@ export class Http2TlsServer {
|
|
|
258
346
|
|
|
259
347
|
/**
|
|
260
348
|
* Writes what `slot`'s connection holds into TLS, as far as TLS takes it,
|
|
261
|
-
* and sends it; shuts TLS down once the connection is over
|
|
262
|
-
*
|
|
263
|
-
*
|
|
349
|
+
* and sends it; shuts TLS down once the connection is over (everything is
|
|
350
|
+
* sent, and it failed, or no stream is left after a GOAWAY or after the
|
|
351
|
+
* peer's byte stream ended), or ALPN chose another protocol. Answers the
|
|
352
|
+
* interest, with the write bit while the connection still holds bytes.
|
|
353
|
+
*
|
|
354
|
+
* @param slot The slot whose output to send, as `accept` answered it.
|
|
355
|
+
* @returns The slot's `TLS_RECORD_*` interest, whose low two bits are the events for `pollModify`;
|
|
356
|
+
* once TLS is shut down, its interest until the `close_notify` is sent and the client has hung up,
|
|
357
|
+
* then `TLS_RECORD_DONE`; `TLS_RECORD_DONE` for a free slot or one whose HTTP/2 connection was never
|
|
358
|
+
* made.
|
|
264
359
|
*/
|
|
265
360
|
flush(slot: i32): i32 {
|
|
266
361
|
if (!this.live(slot)) {
|
|
@@ -287,6 +382,8 @@ export class Http2TlsServer {
|
|
|
287
382
|
/**
|
|
288
383
|
* Ends `slot`'s connection and frees the slot at once, as
|
|
289
384
|
* `TlsTcpServer.close` does; the connection gives back every buffer it holds.
|
|
385
|
+
*
|
|
386
|
+
* @param slot The slot to free; for a free or unknown slot nothing is sent or closed.
|
|
290
387
|
*/
|
|
291
388
|
close(slot: i32): void {
|
|
292
389
|
if (slot >= 0 && slot < toI32(this.connections.length)) {
|
|
@@ -295,7 +392,11 @@ export class Http2TlsServer {
|
|
|
295
392
|
this.tls.close(slot)
|
|
296
393
|
}
|
|
297
394
|
|
|
298
|
-
/**
|
|
395
|
+
/**
|
|
396
|
+
* Gives back the buffers `slot`'s connection holds and has emptied, so an idle slot holds none.
|
|
397
|
+
*
|
|
398
|
+
* @param slot A slot number; a slot never accepted into, or out of range, is left alone.
|
|
399
|
+
*/
|
|
299
400
|
rest(slot: i32): void {
|
|
300
401
|
if (slot >= 0 && slot < toI32(this.connections.length)) {
|
|
301
402
|
this.connections[slot].rest()
|