@ai-ecoverse/slicc-kernel 1.115.0 → 1.116.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/dist/node.js CHANGED
@@ -1865,6 +1865,14 @@ var LoopbackNet = class {
1865
1865
  facades = /* @__PURE__ */ new Map();
1866
1866
  nextEphemeral = EPHEMERAL_FIRST;
1867
1867
  route;
1868
+ origins;
1869
+ useOrigins(serve) {
1870
+ this.origins = serve;
1871
+ }
1872
+ serveOrigin(conn, origin) {
1873
+ if (!this.origins) throw new KernelError("ENETUNREACH");
1874
+ void this.origins(conn, origin).catch(() => conn.close());
1875
+ }
1868
1876
  useUplink(route) {
1869
1877
  this.route = route;
1870
1878
  }
@@ -5650,6 +5658,12 @@ var Incoming = class {
5650
5658
  this.buf = this.buf.subarray(n);
5651
5659
  return out;
5652
5660
  }
5661
+ async firstLine(max, signal) {
5662
+ while (this.buf.length < max && !this.buf.includes(10) && await this.fill(signal)) ;
5663
+ const end = this.buf.indexOf(10);
5664
+ const bytes = this.buf.subarray(0, end >= 0 ? end + 1 : Math.min(max, this.buf.length));
5665
+ return String.fromCharCode(...bytes);
5666
+ }
5653
5667
  async peek(signal) {
5654
5668
  if (this.buf.length === 0) await this.fill(signal);
5655
5669
  return this.buf[0];
@@ -6545,7 +6559,7 @@ function satisfies(version, range2) {
6545
6559
  }
6546
6560
 
6547
6561
  // src/version.ts
6548
- var KERNEL_VERSION = true ? "1.115.0" : "0.0.0-dev";
6562
+ var KERNEL_VERSION = true ? "1.116.1" : "0.0.0-dev";
6549
6563
  var OS_RELEASE = "6.0.0-slicc";
6550
6564
  function procVersion() {
6551
6565
  return `Linux version ${OS_RELEASE} (slicc-kernel ${KERNEL_VERSION}) #1 SMP PREEMPT_DYNAMIC
@@ -7193,7 +7207,25 @@ function missedFires(schedule, from, until, utc = false, cap = MISSED_CAP) {
7193
7207
  count2++;
7194
7208
  }
7195
7209
  const next3 = nextFire(schedule, last, utc);
7196
- return { count: count2, last, more: next3 !== null && next3 <= until };
7210
+ if (next3 === null || next3 > until) return { count: count2, last, more: false };
7211
+ return { count: count2, last: latestFire(schedule, last, until, utc), more: true };
7212
+ }
7213
+ function latestFire(schedule, from, until, utc = false) {
7214
+ let found = from;
7215
+ for (let span = 6e4; ; span *= 2) {
7216
+ const start2 = Math.max(from, until - span);
7217
+ const first = nextFire(schedule, start2, utc);
7218
+ if (first !== null && first <= until) {
7219
+ found = first;
7220
+ break;
7221
+ }
7222
+ if (start2 === from) return from;
7223
+ }
7224
+ for (let at = nextFire(schedule, found, utc); at !== null && at <= until; ) {
7225
+ found = at;
7226
+ at = nextFire(schedule, at, utc);
7227
+ }
7228
+ return found;
7197
7229
  }
7198
7230
 
7199
7231
  // src/cron/table.ts
@@ -7683,6 +7715,9 @@ var TLS_HANDSHAKE = 22;
7683
7715
  var TOKEN2 = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
7684
7716
  var NO_WEBSOCKET2 = "WebSocket not supported by this transport (fetchTransport needs { webSocket: true })";
7685
7717
  var REALM_PROXY_PORT = 3128;
7718
+ var REQUEST_LINE_MAX = 8192;
7719
+ var REQUEST_LINE = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+ \S+ HTTP\/1\.[01]\r?\n$/;
7720
+ var NOT_HTTP = "not HTTP/1.1: TLS through the transport carries only HTTP/1.1 and WebSocket";
7686
7721
  var DEFAULT_LIMITS = {
7687
7722
  maxConnections: 64,
7688
7723
  maxHead: 64 * 1024,
@@ -7971,6 +8006,26 @@ var RealmProxy = class {
7971
8006
  conn.close();
7972
8007
  }
7973
8008
  }
8009
+ async serveOrigin(conn, origin) {
8010
+ if (this.stop.signal.aborted) {
8011
+ conn.close();
8012
+ return;
8013
+ }
8014
+ this.connections.add(conn);
8015
+ const idle = { ms: this.limits.idleMs };
8016
+ const incoming = new Incoming(timedSource(conn, idle, this.stop.signal));
8017
+ try {
8018
+ const line = await incoming.firstLine(REQUEST_LINE_MAX).catch(() => "");
8019
+ if (line !== "" && !REQUEST_LINE.test(line)) {
8020
+ await this.refuse(conn, new HttpError(400, NOT_HTTP));
8021
+ return;
8022
+ }
8023
+ await this.requests({ sink: conn, incoming, origin, socket: conn, idle });
8024
+ } finally {
8025
+ this.connections.delete(conn);
8026
+ conn.close();
8027
+ }
8028
+ }
7974
8029
  async requests(ctx) {
7975
8030
  try {
7976
8031
  for (; ; ) {
@@ -14421,7 +14476,7 @@ async function writeCaFile(fs, ca, locks = globalThis.navigator?.locks) {
14421
14476
  function enableNetwork(net, options) {
14422
14477
  let proxy;
14423
14478
  const transport = options.transport ?? missingTransport();
14424
- net.activate({ family: "inet", host: "127.0.0.1", port: REALM_PROXY_PORT }, () => {
14479
+ const start2 = () => {
14425
14480
  const tls2 = new TlsTerminator({
14426
14481
  ca: options.ca,
14427
14482
  engine: options.engine,
@@ -14440,6 +14495,11 @@ function enableNetwork(net, options) {
14440
14495
  if (proxy === started) proxy = void 0;
14441
14496
  await tls2.close();
14442
14497
  });
14498
+ };
14499
+ net.activate({ family: "inet", host: "127.0.0.1", port: REALM_PROXY_PORT }, start2);
14500
+ net.useOrigins((conn, origin) => {
14501
+ if (!proxy) start2();
14502
+ return proxy.serveOrigin(conn, origin);
14443
14503
  });
14444
14504
  return () => proxy;
14445
14505
  }
@@ -16245,7 +16305,8 @@ var SOCKET_OPS = [
16245
16305
  "sock-setopt",
16246
16306
  "sock-resolve",
16247
16307
  "sock-sendto",
16248
- "sock-recvfrom"
16308
+ "sock-recvfrom",
16309
+ "sock-tls"
16249
16310
  ];
16250
16311
  function socketAt(fds, fd) {
16251
16312
  const file = anySocketAt(fds, fd);
@@ -16317,6 +16378,8 @@ async function socketSyscall(req, proc) {
16317
16378
  if (addresses.length === 0) throw new KernelError("ENOENT");
16318
16379
  return ok3(addresses);
16319
16380
  }
16381
+ case "sock-tls":
16382
+ return ok3(tlsOverTransport(req, proc));
16320
16383
  default:
16321
16384
  return datagram(req, proc);
16322
16385
  }
@@ -16420,6 +16483,48 @@ async function accept(proc, fd, nonblock) {
16420
16483
  const socket = await listener.accept(waits ? proc.blocking() : void 0, nonblock);
16421
16484
  return { fd: proc.fds.install(new OpenFile(socket), 3), peer: socket.peer };
16422
16485
  }
16486
+ var NOT_HTTP_PORTS = /* @__PURE__ */ new Set([
16487
+ 465,
16488
+ 563,
16489
+ 585,
16490
+ 636,
16491
+ 853,
16492
+ 989,
16493
+ 990,
16494
+ 992,
16495
+ 993,
16496
+ 994,
16497
+ 995,
16498
+ 5061,
16499
+ 5671,
16500
+ 6697,
16501
+ 8883
16502
+ ]);
16503
+ var HOST_NAME = /^[A-Za-z0-9.-]+$|^\[?[0-9A-Fa-f:.]+\]?$/;
16504
+ function tlsOverTransport(req, proc) {
16505
+ if (req.ca) throw new KernelError("ENOTSUP");
16506
+ if (req.alpn && req.alpn.length > 0 && !req.alpn.includes("http/1.1")) {
16507
+ throw new KernelError("EPROTONOSUPPORT");
16508
+ }
16509
+ if (!Number.isInteger(req.port) || req.port < 1 || req.port > 65535)
16510
+ throw new KernelError("EINVAL");
16511
+ if (NOT_HTTP_PORTS.has(req.port)) throw new KernelError("EPROTONOSUPPORT");
16512
+ const servername = req.servername || req.host;
16513
+ if (!HOST_NAME.test(servername)) throw new KernelError("EINVAL");
16514
+ if (isLoopbackHost(servername) || isLoopbackHost(req.host)) throw new KernelError("ENOTSUP");
16515
+ const host = servername.includes(":") && !servername.startsWith("[") ? `[${servername}]` : servername;
16516
+ const origin = req.port === 443 ? `https://${host}` : `https://${host}:${req.port}`;
16517
+ const [mine, theirs] = KernelSocket.pair(proc.net, "inet", proc.cred?.());
16518
+ mine.peer = { family: "inet", host: req.host, port: req.port };
16519
+ try {
16520
+ proc.net.serveOrigin(theirs, origin);
16521
+ } catch (err) {
16522
+ mine.close();
16523
+ theirs.close();
16524
+ throw err;
16525
+ }
16526
+ return { fd: proc.fds.install(new OpenFile(mine), 3), alpnProtocol: "http/1.1", servername };
16527
+ }
16423
16528
 
16424
16529
  // src/kernel/vfs-file.ts
16425
16530
  var O_ACCMODE = 3;