siltrun 0.1.0 → 0.2.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/LICENSE +21 -0
- package/README.md +62 -75
- package/package.json +32 -8
- package/src/args.test.ts +18 -0
- package/src/args.ts +5 -1
- package/src/cli.ts +3 -1
- package/src/deploy.ts +7 -3
- package/src/dev.ts +15 -4
- package/src/room-info.test.ts +21 -0
- package/src/room-info.ts +7 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Joel Brubaker
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# `siltrun` — the Silt CLI
|
|
2
2
|
|
|
3
3
|
Run an authoritative multiplayer room on your machine with one command. A room is a
|
|
4
|
-
reducer (`tick(state, inputs)`); the server owns the truth.
|
|
5
|
-
|
|
4
|
+
reducer (`tick(state, inputs)`); the server owns the truth. The full quickstart is at
|
|
5
|
+
<https://silt.run/docs/quickstart/>.
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
npx siltrun dev room.ts
|
|
@@ -21,13 +21,13 @@ const { state, send } = useRoom("http://localhost:4000", { id: crypto.randomUUID
|
|
|
21
21
|
|
|
22
22
|
1. **Builds** the Go room-server binary if it is missing or stale (`go build`).
|
|
23
23
|
2. **Bundles** your contract and its imports into a single module (Bun's bundler).
|
|
24
|
-
3. **Runs the determinism doctor**
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
3. **Runs the determinism doctor** if `@siltrun/room-host` is resolvable — it replays the
|
|
25
|
+
tick sequence and reports drift at the exact tick/field. If the doctor is not present,
|
|
26
|
+
dev prints a notice and keeps running.
|
|
27
27
|
4. **Boots the room-server in compute mode** (`--contract <bundle> --host <host.ts>`) and
|
|
28
28
|
scrapes the per-boot dev certificate hash it prints.
|
|
29
29
|
5. **Serves room-info** on `:4000` — `GET /.well-known/silt` returns
|
|
30
|
-
`{ wtEndpoint, certHash, mode }`
|
|
30
|
+
`{ wtEndpoint, certHash, mode }` with permissive CORS, so a Vite app on
|
|
31
31
|
another port can discover the room and dial WebTransport with the cert pinned. **You
|
|
32
32
|
never touch `serverCertificateHashes`.**
|
|
33
33
|
6. **Watches** the contract. On save it rebundles, re-runs the doctor, and restarts the
|
|
@@ -42,14 +42,27 @@ restart (250ms → 5s cap), clearly logged, so a transient failure never ends yo
|
|
|
42
42
|
|
|
43
43
|
```
|
|
44
44
|
siltrun dev <contract.ts> [options]
|
|
45
|
-
--wt-port <n> WebTransport port
|
|
46
|
-
--info-port <n> room-info port
|
|
47
|
-
--wt-host <host> WebTransport
|
|
45
|
+
--wt-port <n> WebTransport port (default 4433, env SILT_WT_PORT)
|
|
46
|
+
--info-port <n> room-info port (default 4000, env SILT_INFO_PORT)
|
|
47
|
+
--wt-host <host> advertised WebTransport host (default 127.0.0.1, env SILT_WT_HOST)
|
|
48
|
+
--wt-bind <addr> WebTransport bind address (default: --wt-host, env SILT_WT_BIND)
|
|
48
49
|
--no-doctor skip the determinism check on (re)load
|
|
49
50
|
```
|
|
50
51
|
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
`--wt-host` is what the room *advertises*; `--wt-bind` is the address it *listens* on.
|
|
53
|
+
They are the same by default. To reach the room from a second device, bind wide and let
|
|
54
|
+
discovery answer for itself:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
npx siltrun dev room.ts --wt-bind 0.0.0.0
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
room-info binds wherever WebTransport binds — a device that can reach the room can also
|
|
61
|
+
discover it — and the advertised `wtEndpoint` follows the host each request arrived on, so
|
|
62
|
+
a loopback fetch learns a loopback endpoint and a LAN or tailnet fetch learns that one.
|
|
63
|
+
|
|
64
|
+
Path overrides (mainly for tests and for running against a local checkout):
|
|
65
|
+
`SILT_ROOM_SERVER_DIR`, `SILT_ROOM_HOST_ENTRY`, `SILT_DOCTOR_ENTRY`.
|
|
53
66
|
|
|
54
67
|
## `siltrun deploy`
|
|
55
68
|
|
|
@@ -58,76 +71,50 @@ npx siltrun deploy room.ts
|
|
|
58
71
|
```
|
|
59
72
|
|
|
60
73
|
Ships a contract to the hosted beta: bundle → local determinism doctor → upload
|
|
61
|
-
(`SILT_DEPLOY_TOKEN` required
|
|
62
|
-
check page on success.
|
|
63
|
-
|
|
64
|
-
Deployed room names are capped at **12 chars** (charset `[A-Za-z0-9._-]`): the box
|
|
65
|
-
maps each room to a Linux tap device `tap<room>`, and IFNAMSIZ caps interface names
|
|
66
|
-
at 15. The CLI enforces this client-side, before upload, with the same reason the
|
|
67
|
-
intake worker gives (DIG-676). Local `siltrun dev` has no length cap — no tap device.
|
|
68
|
-
|
|
69
|
-
## Distribution — how the npm package is shaped
|
|
70
|
-
|
|
71
|
-
`npm install siltrun` must work from an empty directory with **Node as the only
|
|
72
|
-
prerequisite** (the wrangler/workerd bar). Three runtimes ship as packages:
|
|
73
|
-
|
|
74
|
-
- **The CLI itself** runs on Bun, but its `bin` is a plain-Node shim
|
|
75
|
-
(`bin/silt.mjs`) that locates Bun and re-execs `src/cli.ts` under it. Bun arrives
|
|
76
|
-
through the official `bun` npm package (a dependency); the shim resolves it in
|
|
77
|
-
order: `SILT_BUN` env → the `bun` package's populated `bin/bun.exe` → the
|
|
78
|
-
`@oven/bun-<platform>` package directly (covers `--ignore-scripts` installs) →
|
|
79
|
-
`bun` on PATH. The resolved path is exported as `SILT_BUN` so every downstream
|
|
80
|
-
spawn (doctor, and the Go server spawning the room-host) uses the same runtime.
|
|
81
|
-
- **The Go room-server** ships prebuilt in per-platform packages
|
|
82
|
-
(`@siltrun/room-server-<os>-<arch>`, `optionalDependencies` with `os`/`cpu` fields —
|
|
83
|
-
npm installs exactly the matching one). `paths.ts` resolves the installed binary;
|
|
84
|
-
in the monorepo the sibling Go source wins and is built/rebuilt from source.
|
|
85
|
-
- **The Bun room-host** (host.ts, doctor, deterministic realm) ships as
|
|
86
|
-
`@siltrun/room-host` — plain TS source, zero runtime deps; the CLI resolves it from
|
|
87
|
-
node_modules, or from the sibling package in-repo.
|
|
88
|
-
|
|
89
|
-
`create-siltrun` (`npm create siltrun my-game`) scaffolds the consumer project: `room.ts`
|
|
90
|
-
at the root, a `src/Game.tsx` React client, and a `dev` script that runs
|
|
91
|
-
`siltrun dev room.ts` + vite together.
|
|
92
|
-
|
|
93
|
-
### Releasing
|
|
74
|
+
(`SILT_DEPLOY_TOKEN` required). Prints the room endpoint and the check page on success.
|
|
94
75
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
```
|
|
76
|
+
Deployed room names are capped at **12 chars**, charset `[A-Za-z0-9._-]`. The CLI
|
|
77
|
+
enforces this before upload, so an over-long name fails on your machine in a second
|
|
78
|
+
instead of after a round trip. Local `siltrun dev` has no length cap.
|
|
99
79
|
|
|
100
|
-
|
|
101
|
-
real versions by `bun pm pack` and verified by the script (it fails on any leaked
|
|
102
|
-
`workspace:` and on a platform tarball missing its binary). Publishing is
|
|
103
|
-
`npm publish <tarball>` per file. QA without touching the npm registry: publish the
|
|
104
|
-
tarballs to a local registry (verdaccio) and walk `npm create siltrun` against it.
|
|
80
|
+
## What gets installed
|
|
105
81
|
|
|
106
|
-
|
|
82
|
+
`npm install siltrun` works from an empty directory with **Node as the only
|
|
83
|
+
prerequisite**. Three runtimes arrive as packages, and you do not install any of them
|
|
84
|
+
yourself:
|
|
107
85
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
86
|
+
- **The CLI** runs on Bun, but its `bin` is a plain-Node shim that locates Bun and
|
|
87
|
+
re-execs under it. Bun arrives through the official `bun` npm package, a dependency.
|
|
88
|
+
Set `SILT_BUN` to point at a specific Bun binary if you need to; otherwise the shim
|
|
89
|
+
finds one, and every downstream spawn reuses the same runtime.
|
|
90
|
+
- **The room-server** ships prebuilt in per-platform packages
|
|
91
|
+
(`@siltrun/room-server-<os>-<arch>`), declared as `optionalDependencies` with `os`
|
|
92
|
+
and `cpu` fields, so npm installs exactly the one matching your machine.
|
|
93
|
+
- **The room-host** (the contract runtime, the doctor, and the deterministic realm)
|
|
94
|
+
ships as `@siltrun/room-host`, plain TypeScript source with zero runtime deps.
|
|
114
95
|
|
|
115
|
-
|
|
96
|
+
To start a project rather than add the CLI to one, `npm create siltrun@latest my-game`
|
|
97
|
+
scaffolds `room.ts`, a React client, and a `dev` script that runs the room and Vite
|
|
98
|
+
together.
|
|
116
99
|
|
|
117
|
-
|
|
118
|
-
Bun is the toolchain regardless; the CLI's own code runs under it (via the Node
|
|
119
|
-
shim above — never assume `bun` is on the user's PATH).
|
|
120
|
-
- **Room route:** `/room/<name>` — named by `--room`, `SILT_ROOM`, or derived from the
|
|
121
|
-
contract path (generic basenames like `room.ts` defer to the parent directory). The
|
|
122
|
-
dev never types this path — only the room-info URL.
|
|
100
|
+
## Where this is heading
|
|
123
101
|
|
|
124
|
-
|
|
102
|
+
`npx siltrun dev` is the standalone path. The intended future is a **Vite plugin**, so
|
|
103
|
+
the room runs inside your existing `npm run dev`: one project, one terminal, one reload
|
|
104
|
+
story, the way API routes feel in a web framework. `room.ts` should feel like adding a
|
|
105
|
+
route rather than running a game server. The plugin would host the room-info endpoint on
|
|
106
|
+
the Vite dev server itself and own the same supervise, bundle, and doctor pipeline this
|
|
107
|
+
CLI implements today, so the standalone path stays the reference implementation.
|
|
125
108
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
109
|
+
## Notes
|
|
110
|
+
|
|
111
|
+
- **Runtime:** Bun. The room-host runs on Bun and the contract is bundled with Bun, so
|
|
112
|
+
Bun is the toolchain either way. The CLI's own code runs under it through the Node
|
|
113
|
+
shim above, and never assumes `bun` is on your PATH.
|
|
114
|
+
- **Room route:** `/room/<name>`, named by `--room`, `SILT_ROOM`, or derived from the
|
|
115
|
+
contract path (generic basenames like `room.ts` defer to the parent directory). You
|
|
116
|
+
never type this path yourself, only the room-info URL.
|
|
117
|
+
|
|
118
|
+
## Docs
|
|
131
119
|
|
|
132
|
-
|
|
133
|
-
phase. These tests cover the pieces the CLI owns standalone.
|
|
120
|
+
Full guides and API reference: <https://silt.run/docs/>
|
package/package.json
CHANGED
|
@@ -1,26 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "siltrun",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"license": "MIT",
|
|
4
5
|
"description": "The Silt CLI — run an authoritative multiplayer room locally with `siltrun dev`.",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"multiplayer",
|
|
8
|
+
"webtransport",
|
|
9
|
+
"realtime",
|
|
10
|
+
"game-server",
|
|
11
|
+
"silt",
|
|
12
|
+
"cli",
|
|
13
|
+
"dev-server",
|
|
14
|
+
"netcode",
|
|
15
|
+
"gamedev",
|
|
16
|
+
"authoritative-server"
|
|
17
|
+
],
|
|
18
|
+
"homepage": "https://silt.run",
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/siltrun/silt/issues"
|
|
21
|
+
},
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/siltrun/silt.git",
|
|
25
|
+
"directory": "packages/cli"
|
|
26
|
+
},
|
|
5
27
|
"type": "module",
|
|
6
28
|
"bin": {
|
|
7
29
|
"siltrun": "bin/silt.mjs"
|
|
8
30
|
},
|
|
9
|
-
"files": [
|
|
31
|
+
"files": [
|
|
32
|
+
"bin",
|
|
33
|
+
"src"
|
|
34
|
+
],
|
|
10
35
|
"scripts": {
|
|
11
36
|
"test": "bun test",
|
|
12
37
|
"typecheck": "tsc --noEmit"
|
|
13
38
|
},
|
|
14
|
-
"repository": "https://github.com/digitalpine/silt",
|
|
15
39
|
"dependencies": {
|
|
16
|
-
"@siltrun/room-host": "0.
|
|
40
|
+
"@siltrun/room-host": "0.2.0",
|
|
17
41
|
"bun": "^1.3.0"
|
|
18
42
|
},
|
|
19
43
|
"optionalDependencies": {
|
|
20
|
-
"@siltrun/room-server-darwin-arm64": "0.
|
|
21
|
-
"@siltrun/room-server-darwin-x64": "0.
|
|
22
|
-
"@siltrun/room-server-linux-arm64": "0.
|
|
23
|
-
"@siltrun/room-server-linux-x64": "0.
|
|
44
|
+
"@siltrun/room-server-darwin-arm64": "0.2.0",
|
|
45
|
+
"@siltrun/room-server-darwin-x64": "0.2.0",
|
|
46
|
+
"@siltrun/room-server-linux-arm64": "0.2.0",
|
|
47
|
+
"@siltrun/room-server-linux-x64": "0.2.0"
|
|
24
48
|
},
|
|
25
49
|
"engines": {
|
|
26
50
|
"node": ">=18"
|
package/src/args.test.ts
CHANGED
|
@@ -91,3 +91,21 @@ describe("deriveRoomName", () => {
|
|
|
91
91
|
expect(deriveRoomName("examples/„…“/⚡.ts")).toBe("room");
|
|
92
92
|
});
|
|
93
93
|
});
|
|
94
|
+
|
|
95
|
+
describe("wt-bind", () => {
|
|
96
|
+
const noEnv = {};
|
|
97
|
+
test("defaults to wtHost", () => {
|
|
98
|
+
const o = parseDevArgs(["room.ts", "--wt-host", "100.64.0.5"], noEnv);
|
|
99
|
+
expect(o.wtBind).toBe("100.64.0.5");
|
|
100
|
+
});
|
|
101
|
+
test("splits bind from advertised host", () => {
|
|
102
|
+
const o = parseDevArgs(["room.ts", "--wt-host", "100.64.0.5", "--wt-bind", "0.0.0.0"], noEnv);
|
|
103
|
+
expect(o.wtBind).toBe("0.0.0.0");
|
|
104
|
+
expect(o.wtHost).toBe("100.64.0.5");
|
|
105
|
+
});
|
|
106
|
+
test("reads SILT_WT_BIND from env", () => {
|
|
107
|
+
const o = parseDevArgs(["room.ts"], { SILT_WT_BIND: "0.0.0.0" });
|
|
108
|
+
expect(o.wtBind).toBe("0.0.0.0");
|
|
109
|
+
expect(o.wtHost).toBe("127.0.0.1");
|
|
110
|
+
});
|
|
111
|
+
});
|
package/src/args.ts
CHANGED
|
@@ -9,6 +9,9 @@ export interface DevOptions {
|
|
|
9
9
|
wtPort: number;
|
|
10
10
|
infoPort: number;
|
|
11
11
|
wtHost: string;
|
|
12
|
+
/** WT bind address; defaults to wtHost. Split so a host can bind 0.0.0.0 (serve
|
|
13
|
+
* loopback AND a LAN/tailnet interface) while advertising one reachable host. */
|
|
14
|
+
wtBind: string;
|
|
12
15
|
doctor: boolean;
|
|
13
16
|
}
|
|
14
17
|
|
|
@@ -105,6 +108,7 @@ export function parseDevArgs(argv: string[], env: Record<string, string | undefi
|
|
|
105
108
|
}
|
|
106
109
|
|
|
107
110
|
const wtHost = (flags.get("wt-host") as string) || env.SILT_WT_HOST || "127.0.0.1";
|
|
111
|
+
const wtBind = (flags.get("wt-bind") as string) || env.SILT_WT_BIND || wtHost;
|
|
108
112
|
const wtPort = intOpt((flags.get("wt-port") as string) ?? env.SILT_WT_PORT, "--wt-port", 4433);
|
|
109
113
|
const infoPort = intOpt(
|
|
110
114
|
(flags.get("info-port") as string) ?? env.SILT_INFO_PORT,
|
|
@@ -113,5 +117,5 @@ export function parseDevArgs(argv: string[], env: Record<string, string | undefi
|
|
|
113
117
|
);
|
|
114
118
|
const doctor = flags.get("no-doctor") !== true;
|
|
115
119
|
|
|
116
|
-
return { contract, room, wtPort, infoPort, wtHost, doctor };
|
|
120
|
+
return { contract, room, wtPort, infoPort, wtHost, wtBind, doctor };
|
|
117
121
|
}
|
package/src/cli.ts
CHANGED
|
@@ -26,7 +26,9 @@ ${paint.bold("dev options")}
|
|
|
26
26
|
generic like room.ts/index.ts; env SILT_ROOM)
|
|
27
27
|
--wt-port <n> WebTransport port (default: 4433, env SILT_WT_PORT)
|
|
28
28
|
--info-port <n> room-info port (default: 4000, env SILT_INFO_PORT)
|
|
29
|
-
--wt-host <host> WebTransport
|
|
29
|
+
--wt-host <host> advertised WebTransport + room-info host (default: 127.0.0.1)
|
|
30
|
+
--wt-bind <addr> WT bind address (default: --wt-host; use 0.0.0.0 to serve
|
|
31
|
+
loopback and a LAN/tailnet interface at once)
|
|
30
32
|
--no-doctor skip the determinism check on (re)load
|
|
31
33
|
|
|
32
34
|
${paint.bold("deploy options")}
|
package/src/deploy.ts
CHANGED
|
@@ -36,8 +36,12 @@ import { log, paint } from "./log.ts";
|
|
|
36
36
|
// any time via SILT_DEPLOY_URL for local mocks / miniflare.
|
|
37
37
|
export const DEFAULT_INTAKE_URL = "https://silt-deploy-intake.ai-chat-game.workers.dev";
|
|
38
38
|
|
|
39
|
-
// Where a
|
|
40
|
-
|
|
39
|
+
// Where a logged-out user goes next. Kept as a pointer so the "no credential" error is
|
|
40
|
+
// actionable. This is the FIRST thing a stranger sees when they run `deploy` before
|
|
41
|
+
// `login`, so it must resolve: the old https://silt.digitalpine.io/beta 404s (verified
|
|
42
|
+
// 2026-08-02), and so does /beta on the current host. The docs quickstart is the live,
|
|
43
|
+
// honest target and documents the login step this error is telling them to run.
|
|
44
|
+
const ONBOARDING_DOC = "https://silt.run/docs/quickstart/";
|
|
41
45
|
|
|
42
46
|
// Where a tester reports a failure that isn't theirs to fix (docs/SUPPORT.md — Discord
|
|
43
47
|
// #support is THE channel; there is no support email).
|
|
@@ -221,7 +225,7 @@ export async function runDeploy(
|
|
|
221
225
|
const token = envToken || (sessionUsable ? creds!.token : undefined);
|
|
222
226
|
if (!token) {
|
|
223
227
|
logger.error("no deploy credential — run `siltrun login` (or set SILT_DEPLOY_TOKEN to a beta token)");
|
|
224
|
-
logger.plain(paint.dim(`
|
|
228
|
+
logger.plain(paint.dim(` Getting started: ${ONBOARDING_DOC}`));
|
|
225
229
|
return { ok: false, status: "aborted", error: "no token" };
|
|
226
230
|
}
|
|
227
231
|
if (usingSession) {
|
package/src/dev.ts
CHANGED
|
@@ -93,9 +93,16 @@ export async function dev(opts: DevOptions): Promise<void> {
|
|
|
93
93
|
// room-info state — cert refreshes on each (re)boot. The room name (SEAM §4:
|
|
94
94
|
// /room/<name>) comes from --room, or is derived from the contract path (args.ts);
|
|
95
95
|
// the server serves exactly this path and loudly rejects anything else.
|
|
96
|
-
|
|
96
|
+
// The advertised WT host follows the host the info request arrived on (a loopback
|
|
97
|
+
// fetch gets a loopback endpoint, a tailnet fetch the tailnet one — cert pinning
|
|
98
|
+
// makes the hostname interchangeable); --wt-host is the fallback for callers with
|
|
99
|
+
// no request in hand (boot banner).
|
|
97
100
|
let certHash: string | null = null;
|
|
98
|
-
const getInfo = (): RoomInfo => ({
|
|
101
|
+
const getInfo = (requestHost?: string): RoomInfo => ({
|
|
102
|
+
wtEndpoint: `https://${requestHost ?? opts.wtHost}:${opts.wtPort}/room/${opts.room}`,
|
|
103
|
+
certHash,
|
|
104
|
+
mode,
|
|
105
|
+
});
|
|
99
106
|
|
|
100
107
|
// 4. supervise the room-server.
|
|
101
108
|
// The server treats a non-empty --contract as "enable compute mode"; empty = relay.
|
|
@@ -107,7 +114,7 @@ export async function dev(opts: DevOptions): Promise<void> {
|
|
|
107
114
|
cwd: existsSync(paths.roomServerDir) ? paths.roomServerDir : undefined,
|
|
108
115
|
// SILT_BUN: the server spawns the Bun room-host itself (compute.go) — hand it the
|
|
109
116
|
// exact runtime running this CLI so it never depends on `bun` being on PATH.
|
|
110
|
-
env: { WT_BIND: `${opts.
|
|
117
|
+
env: { WT_BIND: `${opts.wtBind}:${opts.wtPort}`, SILT_BUN: bunBin() },
|
|
111
118
|
onCert: (h) => {
|
|
112
119
|
certHash = h;
|
|
113
120
|
},
|
|
@@ -134,7 +141,11 @@ export async function dev(opts: DevOptions): Promise<void> {
|
|
|
134
141
|
// 5. room-info endpoint
|
|
135
142
|
let roomInfo: RoomInfoServer;
|
|
136
143
|
try {
|
|
137
|
-
|
|
144
|
+
// Bind room-info wherever WebTransport binds: a device that can reach the room
|
|
145
|
+
// must also be able to discover it (the /.well-known/silt fetch carries the cert
|
|
146
|
+
// hash), and with --wt-bind 0.0.0.0 that includes loopback AND the external
|
|
147
|
+
// interface. Default flags keep this loopback-only, exactly as before.
|
|
148
|
+
roomInfo = startRoomInfoServer({ port: opts.infoPort, hostname: opts.wtBind, getInfo });
|
|
138
149
|
} catch (e) {
|
|
139
150
|
log.error(`could not bind room-info on :${opts.infoPort}: ${String(e)}`);
|
|
140
151
|
log.plain(
|
package/src/room-info.test.ts
CHANGED
|
@@ -78,3 +78,24 @@ describe("room-info endpoint (SEAM §4)", () => {
|
|
|
78
78
|
expect(res.status).toBe(404);
|
|
79
79
|
});
|
|
80
80
|
});
|
|
81
|
+
|
|
82
|
+
describe("request-host advertisement", () => {
|
|
83
|
+
test("getInfo receives the hostname the request arrived on", async () => {
|
|
84
|
+
let seen: string | undefined = "unset" as string | undefined;
|
|
85
|
+
const s = startRoomInfoServer({
|
|
86
|
+
port: 0,
|
|
87
|
+
getInfo: (requestHost) => {
|
|
88
|
+
seen = requestHost;
|
|
89
|
+
return { wtEndpoint: `https://${requestHost}:4433/room/x`, certHash: null, mode: "compute" };
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
try {
|
|
93
|
+
const res = await fetch(`http://127.0.0.1:${s.port}${WELL_KNOWN_PATH}`);
|
|
94
|
+
const body = (await res.json()) as { wtEndpoint: string };
|
|
95
|
+
expect(seen).toBe("127.0.0.1");
|
|
96
|
+
expect(body.wtEndpoint).toBe("https://127.0.0.1:4433/room/x");
|
|
97
|
+
} finally {
|
|
98
|
+
s.stop();
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
});
|
package/src/room-info.ts
CHANGED
|
@@ -31,12 +31,15 @@ export interface RoomInfoServer {
|
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* Serve room-info on `port`. `getInfo` is called per request so the served cert hash
|
|
34
|
-
* tracks the live room-server across restarts (the cert changes each boot).
|
|
34
|
+
* tracks the live room-server across restarts (the cert changes each boot). It receives
|
|
35
|
+
* the hostname the request arrived on, so a multi-homed dev server (--wt-bind 0.0.0.0)
|
|
36
|
+
* can advertise a WT endpoint the asking client can actually reach — a loopback fetch
|
|
37
|
+
* learns a loopback endpoint, a tailnet fetch learns the tailnet one.
|
|
35
38
|
*/
|
|
36
39
|
export function startRoomInfoServer(opts: {
|
|
37
40
|
port: number;
|
|
38
41
|
hostname?: string;
|
|
39
|
-
getInfo: () => RoomInfo;
|
|
42
|
+
getInfo: (requestHost?: string) => RoomInfo;
|
|
40
43
|
}): RoomInfoServer {
|
|
41
44
|
const hostname = opts.hostname ?? "127.0.0.1";
|
|
42
45
|
const server = Bun.serve({
|
|
@@ -53,7 +56,8 @@ export function startRoomInfoServer(opts: {
|
|
|
53
56
|
if (req.method !== "GET") {
|
|
54
57
|
return new Response("method not allowed", { status: 405, headers: CORS });
|
|
55
58
|
}
|
|
56
|
-
|
|
59
|
+
const requestHost = new URL(req.url).hostname || undefined;
|
|
60
|
+
return Response.json(opts.getInfo(requestHost), { headers: CORS });
|
|
57
61
|
}
|
|
58
62
|
|
|
59
63
|
return new Response("not found", { status: 404, headers: CORS });
|