@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.
@@ -2305,6 +2305,12 @@ var Incoming = class {
2305
2305
  this.buf = this.buf.subarray(n);
2306
2306
  return out;
2307
2307
  }
2308
+ async firstLine(max, signal) {
2309
+ while (this.buf.length < max && !this.buf.includes(10) && await this.fill(signal)) ;
2310
+ const end = this.buf.indexOf(10);
2311
+ const bytes = this.buf.subarray(0, end >= 0 ? end + 1 : Math.min(max, this.buf.length));
2312
+ return String.fromCharCode(...bytes);
2313
+ }
2308
2314
  async peek(signal) {
2309
2315
  if (this.buf.length === 0) await this.fill(signal);
2310
2316
  return this.buf[0];
@@ -4708,6 +4714,14 @@ var LoopbackNet = class {
4708
4714
  facades = /* @__PURE__ */ new Map();
4709
4715
  nextEphemeral = EPHEMERAL_FIRST;
4710
4716
  route;
4717
+ origins;
4718
+ useOrigins(serve) {
4719
+ this.origins = serve;
4720
+ }
4721
+ serveOrigin(conn, origin) {
4722
+ if (!this.origins) throw new KernelError("ENETUNREACH");
4723
+ void this.origins(conn, origin).catch(() => conn.close());
4724
+ }
4711
4725
  useUplink(route) {
4712
4726
  this.route = route;
4713
4727
  }
@@ -6227,7 +6241,7 @@ function satisfies(version, range2) {
6227
6241
  }
6228
6242
 
6229
6243
  // src/version.ts
6230
- var KERNEL_VERSION = true ? "1.115.0" : "0.0.0-dev";
6244
+ var KERNEL_VERSION = true ? "1.116.1" : "0.0.0-dev";
6231
6245
  var OS_RELEASE = "6.0.0-slicc";
6232
6246
  function procVersion() {
6233
6247
  return `Linux version ${OS_RELEASE} (slicc-kernel ${KERNEL_VERSION}) #1 SMP PREEMPT_DYNAMIC
@@ -6875,7 +6889,25 @@ function missedFires(schedule, from, until, utc = false, cap = MISSED_CAP) {
6875
6889
  count2++;
6876
6890
  }
6877
6891
  const next3 = nextFire(schedule, last, utc);
6878
- return { count: count2, last, more: next3 !== null && next3 <= until };
6892
+ if (next3 === null || next3 > until) return { count: count2, last, more: false };
6893
+ return { count: count2, last: latestFire(schedule, last, until, utc), more: true };
6894
+ }
6895
+ function latestFire(schedule, from, until, utc = false) {
6896
+ let found = from;
6897
+ for (let span = 6e4; ; span *= 2) {
6898
+ const start2 = Math.max(from, until - span);
6899
+ const first = nextFire(schedule, start2, utc);
6900
+ if (first !== null && first <= until) {
6901
+ found = first;
6902
+ break;
6903
+ }
6904
+ if (start2 === from) return from;
6905
+ }
6906
+ for (let at = nextFire(schedule, found, utc); at !== null && at <= until; ) {
6907
+ found = at;
6908
+ at = nextFire(schedule, at, utc);
6909
+ }
6910
+ return found;
6879
6911
  }
6880
6912
 
6881
6913
  // src/cron/table.ts
@@ -7587,6 +7619,9 @@ var TLS_HANDSHAKE = 22;
7587
7619
  var TOKEN2 = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
7588
7620
  var NO_WEBSOCKET2 = "WebSocket not supported by this transport (fetchTransport needs { webSocket: true })";
7589
7621
  var REALM_PROXY_PORT = 3128;
7622
+ var REQUEST_LINE_MAX = 8192;
7623
+ var REQUEST_LINE = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+ \S+ HTTP\/1\.[01]\r?\n$/;
7624
+ var NOT_HTTP = "not HTTP/1.1: TLS through the transport carries only HTTP/1.1 and WebSocket";
7590
7625
  var DEFAULT_LIMITS = {
7591
7626
  maxConnections: 64,
7592
7627
  maxHead: 64 * 1024,
@@ -7875,6 +7910,26 @@ var RealmProxy = class {
7875
7910
  conn.close();
7876
7911
  }
7877
7912
  }
7913
+ async serveOrigin(conn, origin) {
7914
+ if (this.stop.signal.aborted) {
7915
+ conn.close();
7916
+ return;
7917
+ }
7918
+ this.connections.add(conn);
7919
+ const idle = { ms: this.limits.idleMs };
7920
+ const incoming = new Incoming(timedSource(conn, idle, this.stop.signal));
7921
+ try {
7922
+ const line = await incoming.firstLine(REQUEST_LINE_MAX).catch(() => "");
7923
+ if (line !== "" && !REQUEST_LINE.test(line)) {
7924
+ await this.refuse(conn, new HttpError(400, NOT_HTTP));
7925
+ return;
7926
+ }
7927
+ await this.requests({ sink: conn, incoming, origin, socket: conn, idle });
7928
+ } finally {
7929
+ this.connections.delete(conn);
7930
+ conn.close();
7931
+ }
7932
+ }
7878
7933
  async requests(ctx) {
7879
7934
  try {
7880
7935
  for (; ; ) {
@@ -14373,7 +14428,7 @@ async function writeCaFile(fs, ca, locks = globalThis.navigator?.locks) {
14373
14428
  function enableNetwork(net, options) {
14374
14429
  let proxy;
14375
14430
  const transport = options.transport ?? missingTransport();
14376
- net.activate({ family: "inet", host: "127.0.0.1", port: REALM_PROXY_PORT }, () => {
14431
+ const start2 = () => {
14377
14432
  const tls = new TlsTerminator({
14378
14433
  ca: options.ca,
14379
14434
  engine: options.engine,
@@ -14392,6 +14447,11 @@ function enableNetwork(net, options) {
14392
14447
  if (proxy === started) proxy = void 0;
14393
14448
  await tls.close();
14394
14449
  });
14450
+ };
14451
+ net.activate({ family: "inet", host: "127.0.0.1", port: REALM_PROXY_PORT }, start2);
14452
+ net.useOrigins((conn, origin) => {
14453
+ if (!proxy) start2();
14454
+ return proxy.serveOrigin(conn, origin);
14395
14455
  });
14396
14456
  return () => proxy;
14397
14457
  }
@@ -16307,7 +16367,8 @@ var SOCKET_OPS = [
16307
16367
  "sock-setopt",
16308
16368
  "sock-resolve",
16309
16369
  "sock-sendto",
16310
- "sock-recvfrom"
16370
+ "sock-recvfrom",
16371
+ "sock-tls"
16311
16372
  ];
16312
16373
  function socketAt(fds, fd) {
16313
16374
  const file = anySocketAt(fds, fd);
@@ -16379,6 +16440,8 @@ async function socketSyscall(req, proc) {
16379
16440
  if (addresses.length === 0) throw new KernelError("ENOENT");
16380
16441
  return ok3(addresses);
16381
16442
  }
16443
+ case "sock-tls":
16444
+ return ok3(tlsOverTransport(req, proc));
16382
16445
  default:
16383
16446
  return datagram(req, proc);
16384
16447
  }
@@ -16482,6 +16545,48 @@ async function accept(proc, fd, nonblock) {
16482
16545
  const socket = await listener.accept(waits ? proc.blocking() : void 0, nonblock);
16483
16546
  return { fd: proc.fds.install(new OpenFile(socket), 3), peer: socket.peer };
16484
16547
  }
16548
+ var NOT_HTTP_PORTS = /* @__PURE__ */ new Set([
16549
+ 465,
16550
+ 563,
16551
+ 585,
16552
+ 636,
16553
+ 853,
16554
+ 989,
16555
+ 990,
16556
+ 992,
16557
+ 993,
16558
+ 994,
16559
+ 995,
16560
+ 5061,
16561
+ 5671,
16562
+ 6697,
16563
+ 8883
16564
+ ]);
16565
+ var HOST_NAME = /^[A-Za-z0-9.-]+$|^\[?[0-9A-Fa-f:.]+\]?$/;
16566
+ function tlsOverTransport(req, proc) {
16567
+ if (req.ca) throw new KernelError("ENOTSUP");
16568
+ if (req.alpn && req.alpn.length > 0 && !req.alpn.includes("http/1.1")) {
16569
+ throw new KernelError("EPROTONOSUPPORT");
16570
+ }
16571
+ if (!Number.isInteger(req.port) || req.port < 1 || req.port > 65535)
16572
+ throw new KernelError("EINVAL");
16573
+ if (NOT_HTTP_PORTS.has(req.port)) throw new KernelError("EPROTONOSUPPORT");
16574
+ const servername = req.servername || req.host;
16575
+ if (!HOST_NAME.test(servername)) throw new KernelError("EINVAL");
16576
+ if (isLoopbackHost(servername) || isLoopbackHost(req.host)) throw new KernelError("ENOTSUP");
16577
+ const host = servername.includes(":") && !servername.startsWith("[") ? `[${servername}]` : servername;
16578
+ const origin = req.port === 443 ? `https://${host}` : `https://${host}:${req.port}`;
16579
+ const [mine, theirs] = KernelSocket.pair(proc.net, "inet", proc.cred?.());
16580
+ mine.peer = { family: "inet", host: req.host, port: req.port };
16581
+ try {
16582
+ proc.net.serveOrigin(theirs, origin);
16583
+ } catch (err) {
16584
+ mine.close();
16585
+ theirs.close();
16586
+ throw err;
16587
+ }
16588
+ return { fd: proc.fds.install(new OpenFile(mine), 3), alpnProtocol: "http/1.1", servername };
16589
+ }
16485
16590
 
16486
16591
  // src/kernel/vfs-file.ts
16487
16592
  var O_ACCMODE = 3;