@ai-ecoverse/slicc-kernel 1.30.0 → 1.31.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.
@@ -29,6 +29,45 @@ var init_protocol = __esm({
29
29
  }
30
30
  });
31
31
 
32
+ // src/kernel/net/loopback-names.ts
33
+ function reserved(name) {
34
+ const lower = name.toLowerCase();
35
+ return lower === "localhost" || lower.endsWith(".localhost") || lower === HOST_LOOPBACK || lower === "wasmer.sh" || /^\d+(\.\d+){3}$/.test(lower);
36
+ }
37
+ function isHostname(name) {
38
+ if (typeof name !== "string" || name.length > 253 || reserved(name)) return false;
39
+ return name.split(".").every((l) => LABEL.test(l));
40
+ }
41
+ function hostnameOf(env) {
42
+ return isHostname(env.HOSTNAME) ? env.HOSTNAME : DEFAULT_HOSTNAME;
43
+ }
44
+ function ownNames(hostname) {
45
+ return [.../* @__PURE__ */ new Set([hostname.toLowerCase(), ...LIBC_HOSTNAMES])];
46
+ }
47
+ function hostsFile(hostname = DEFAULT_HOSTNAME) {
48
+ return [
49
+ "127.0.0.1 localhost localhost.localdomain",
50
+ "::1 localhost ip6-localhost",
51
+ `${HOSTNAME_ADDRESS} ${ownNames(hostname).join(" ")}`,
52
+ `${HOST_LOOPBACK_ADDRESS.join(".")} ${HOST_LOOPBACK}`,
53
+ ""
54
+ ].join("\n");
55
+ }
56
+ var HOST_LOOPBACK, HOST_LOOPBACK_ADDRESS, PAGE_LOOPBACK, PAGE_LOOPBACK_URL, DEFAULT_HOSTNAME, HOSTNAME_ADDRESS, LIBC_HOSTNAMES, LABEL;
57
+ var init_loopback_names = __esm({
58
+ "src/kernel/net/loopback-names.ts"() {
59
+ "use strict";
60
+ HOST_LOOPBACK = "host.slicc.internal";
61
+ HOST_LOOPBACK_ADDRESS = [10, 0, 2, 2];
62
+ PAGE_LOOPBACK = "kernel.localhost";
63
+ PAGE_LOOPBACK_URL = `http://{port}.${PAGE_LOOPBACK}`;
64
+ DEFAULT_HOSTNAME = "slicc";
65
+ HOSTNAME_ADDRESS = "127.0.1.1";
66
+ LIBC_HOSTNAMES = ["emscripten", "wasmer.sh"];
67
+ LABEL = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/i;
68
+ }
69
+ });
70
+
32
71
  // src/kernel/signals.ts
33
72
  function sigbit(sig) {
34
73
  return 1 << sig;
@@ -2074,24 +2113,6 @@ var init_process_children = __esm({
2074
2113
  }
2075
2114
  });
2076
2115
 
2077
- // src/kernel/net/loopback-names.ts
2078
- function hostsFile() {
2079
- return `127.0.0.1 localhost
2080
- ::1 localhost ip6-localhost
2081
- ${HOST_LOOPBACK_ADDRESS.join(".")} ${HOST_LOOPBACK}
2082
- `;
2083
- }
2084
- var HOST_LOOPBACK, HOST_LOOPBACK_ADDRESS, PAGE_LOOPBACK, PAGE_LOOPBACK_URL;
2085
- var init_loopback_names = __esm({
2086
- "src/kernel/net/loopback-names.ts"() {
2087
- "use strict";
2088
- HOST_LOOPBACK = "host.slicc.internal";
2089
- HOST_LOOPBACK_ADDRESS = [10, 0, 2, 2];
2090
- PAGE_LOOPBACK = "kernel.localhost";
2091
- PAGE_LOOPBACK_URL = `http://{port}.${PAGE_LOOPBACK}`;
2092
- }
2093
- });
2094
-
2095
2116
  // src/process/process-pty.ts
2096
2117
  function failed(e) {
2097
2118
  const code2 = e?.code;
@@ -2538,10 +2559,13 @@ function useMounts(Fs, env = {}, live = false) {
2538
2559
  mkdirTree.call(Fs, "/dev/.etc");
2539
2560
  writeFile.call(Fs, "/dev/.etc/passwd", passwd);
2540
2561
  writeFile.call(Fs, "/dev/.etc/group", group);
2541
- writeFile.call(Fs, "/dev/.etc/hosts", hostsFile());
2562
+ writeFile.call(Fs, "/dev/.etc/hosts", hostsFile(hostnameOf(env)));
2563
+ writeFile.call(Fs, "/dev/.etc/hostname", `${hostnameOf(env)}
2564
+ `);
2542
2565
  backing["/etc/passwd"] = "/dev/.etc/passwd";
2543
2566
  backing["/etc/group"] = "/dev/.etc/group";
2544
2567
  backing["/etc/hosts"] = "/dev/.etc/hosts";
2568
+ backing["/etc/hostname"] = "/dev/.etc/hostname";
2545
2569
  } catch {
2546
2570
  }
2547
2571
  const open = Fs.open.bind(Fs);
@@ -3674,6 +3698,7 @@ async function runWasmProcess(init, port, deps = {}) {
3674
3698
  stdioPromoter: () => vfsPromoter(running.FS, sys, streams, livePath)
3675
3699
  });
3676
3700
  running.sliccKernel.http = createHttpKernel(transport);
3701
+ running.sliccKernel.hostname = hostnameOf(init.env);
3677
3702
  running.sliccKernel.net = createSocketKernel({
3678
3703
  transport,
3679
3704
  Fs: running.FS,
@@ -3732,6 +3757,7 @@ var O_RDONLY, O_WRONLY2, O_RDWR3, GLUE_TRAILER, evaluateGlue, EVAL_BLOCKED;
3732
3757
  var init_process_runtime = __esm({
3733
3758
  "src/process/process-runtime.ts"() {
3734
3759
  "use strict";
3760
+ init_loopback_names();
3735
3761
  init_signals();
3736
3762
  init_emscripten_vfs_hook();
3737
3763
  init_live_vfs_fs();