Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion dart/moq/lib/socket.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ library;

import 'package:moq_ffi/moq_ffi.dart';

/// Announces one hidden endpoint and dials or accepts sessions.
/// A server, a client, or both: its first dial announces it as a client, and its
/// first accept as a server.
typedef Endpoint = MoqSocketEndpoint;

/// An incoming TCP dial, consumed by accepting or rejecting it.
Expand Down
8 changes: 4 additions & 4 deletions dart/moq_ffi/lib/src/moq.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24754,13 +24754,13 @@ void _checkApiChecksums() {
if (uniffi_moq_ffi_checksum_method_moqsocketendpoint_accept_track() != 3641) {
throw UniffiInternalError.panicked("UniFFI API checksum mismatch");
}
if (uniffi_moq_ffi_checksum_method_moqsocketendpoint_close() != 33296) {
if (uniffi_moq_ffi_checksum_method_moqsocketendpoint_close() != 18581) {
throw UniffiInternalError.panicked("UniFFI API checksum mismatch");
}
if (uniffi_moq_ffi_checksum_method_moqsocketendpoint_dial_tcp() != 61959) {
if (uniffi_moq_ffi_checksum_method_moqsocketendpoint_dial_tcp() != 44736) {
throw UniffiInternalError.panicked("UniFFI API checksum mismatch");
}
if (uniffi_moq_ffi_checksum_method_moqsocketendpoint_dial_track() != 5972) {
if (uniffi_moq_ffi_checksum_method_moqsocketendpoint_dial_track() != 54786) {
throw UniffiInternalError.panicked("UniFFI API checksum mismatch");
}
if (uniffi_moq_ffi_checksum_method_moqsocketendpoint_id() != 2699) {
Expand Down Expand Up @@ -24965,7 +24965,7 @@ void _checkApiChecksums() {
if (uniffi_moq_ffi_checksum_constructor_moqclient_new() != 48355) {
throw UniffiInternalError.panicked("UniFFI API checksum mismatch");
}
if (uniffi_moq_ffi_checksum_constructor_moqsocketendpoint_new() != 7442) {
if (uniffi_moq_ffi_checksum_constructor_moqsocketendpoint_new() != 25288) {
throw UniffiInternalError.panicked("UniFFI API checksum mismatch");
}
if (uniffi_moq_ffi_checksum_constructor_moqvideoconsumer_subscribe() !=
Expand Down
24 changes: 12 additions & 12 deletions demo/carla/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ carla/{truck}/{camera}.hang <- one media broadcast per camera (hang catalo
hd 720p H.264, for the focused view
status JSON Snapshot telemetry

carla/.socket/{truck} <- the truck's socket endpoint, which drivers dial
carla/.socket/driver-{id} <- one endpoint per driver lease
carla/.server/{truck} <- the truck's server socket endpoint, which drivers dial
carla/.client/{id} <- one client endpoint per driver lease
```

Each truck accepts `track` sessions on its endpoint. A driver dials from an
endpoint of its own, one session per lease, and sends one control per message;
Each truck accepts `track` sessions on its server endpoint. A driver dials from
a client endpoint of its own, one session per lease, and sends one control per message;
the truck answers each control it accepted from the lease holder on the same
session. Cameras are sibling broadcasts, so switching views never creates a
second claim on the same wheel.
Expand Down Expand Up @@ -150,16 +150,16 @@ The worker's gate (`sim/moq_carla_sim/drive.py`) owns every truck's controls:
returns to a free spawn point under autonomy, its e-stop cleared.

The lease is cooperative. Anonymous drivers share one grant to publish
`carla/.socket/driver-*`, so an endpoint id is all it takes to announce in a
driver's place and win the relay's route to its next dial. Each driver's id is
`carla/.client/*`, so an endpoint id is all it takes to announce in a driver's
place and win the relay's route to its next session. Each driver's id is
therefore 128 random bits, and `status` names the holder and the e-stop's
sender by a handle instead: `driver-` and 8 hex digits of the SHA-256 of the
session's secret id, which the driver derives the same way to recognize its
own lease. Truck names must not look like driver ids, or the same grant would
let anyone impersonate a truck; the worker refuses one. Anyone may still claim
a free truck or press its e-stop, so the lease stops two honest drivers
fighting over a truck, not a deliberate disruption. Anything beyond a simulator
needs per-driver tokens scoped to the driver's own endpoint.
own lease. The grant covers only client endpoints, so no driver can announce a
truck's server endpoint, whatever its name. Anyone may still claim a free truck
or press its e-stop, so the lease stops two honest drivers fighting over a
truck, not a deliberate disruption. Anything beyond a simulator needs
per-driver tokens scoped to the driver's own endpoint.

## The simulator

Expand Down Expand Up @@ -222,7 +222,7 @@ just carla venv
just carla service-install

# The units read this. MOQ_URL carries a token allowed to publish `carla/**`,
# which covers the trucks' endpoints, and subscribe `carla/.socket/driver-*`,
# which covers the trucks' server endpoints, and subscribe `carla/.client/**`,
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
# the endpoints drivers dial from; keeping it here keeps it off the command
# line. CARLA_IMAGE is the tag the moq-dev/carla build printed, since the worker
# refuses a stock simulator.
Expand Down
7 changes: 0 additions & 7 deletions demo/carla/sim/moq_carla_sim/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@
# peer. The web player offers the same list.
VERSIONS = ("moq-lite-07-wip", "moq-transport-22")

# The id form anonymous drivers may publish endpoints under. A truck named like
# one could be impersonated by any of them.
DRIVER_ID_PREFIX = "driver-"


def default_trucks() -> list[str]:
trucks = json.loads(TRUCKS_FILE.read_text())
Expand Down Expand Up @@ -89,9 +85,6 @@ def parse_args(argv: list[str] | None = None) -> argparse.Namespace:
args = parser.parse_args(argv)
if not args.trucks:
args.trucks = default_trucks()
for truck in args.trucks:
if truck.startswith(DRIVER_ID_PREFIX):
parser.error(f"truck {truck!r} is named like a driver, whose endpoints anyone may publish")
return args


Expand Down
16 changes: 8 additions & 8 deletions demo/carla/sim/moq_carla_sim/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
speaks:

carla/{truck}/{camera}.hang video (sd, hd) + status
carla/.socket/{truck} the truck's socket endpoint
carla/.socket/driver-{id} each driver's socket endpoint
carla/.server/{truck} the truck's server socket endpoint
carla/.client/{id} each driver's client socket endpoint
"""

from __future__ import annotations
Expand Down Expand Up @@ -294,7 +294,7 @@ def _number_or_none(value: Any) -> float | None:


# Every endpoint the trucks and their drivers talk through sits under this
# prefix, as `{prefix}/.socket/{id}`.
# prefix: a truck's as `{prefix}/.server/{truck}`, a driver's as `{prefix}/.client/{id}`.
SOCKET_PREFIX = "carla"

# How far a control may fall behind the newest before it is skipped: one player
Expand All @@ -304,10 +304,10 @@ def _number_or_none(value: Any) -> float | None:


class Drivers:
"""A truck's socket endpoint: accepts each driver's session, fans its controls
into the command queue, and answers the driver on the same session.
"""A truck's server socket endpoint: accepts each driver's session, fans its
controls into the command queue, and answers the driver on the same session.

Each driver dials from an endpoint of its own, one `track` session per lease,
Each driver dials from a client endpoint of its own, one `track` session per lease,
whose messages are one control per group. Replies go back the same way, so a
driver's acknowledgements never reach anyone else.
"""
Expand All @@ -320,8 +320,8 @@ def __init__(self, truck: str, commands: asyncio.Queue[Command]) -> None:

@property
def path(self) -> str:
"""Where the truck's endpoint is announced."""
return f"{SOCKET_PREFIX}/.socket/{self._truck}"
"""Where the truck's server endpoint is announced."""
return f"{SOCKET_PREFIX}/.server/{self._truck}"

def reply(self, command: Command, message: dict[str, Any]) -> None:
"""Send `message` on the session that carried `command`, if it is still open.
Expand Down
2 changes: 1 addition & 1 deletion demo/carla/sim/systemd/install-user-service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Before starting, write the relay settings to:
CARLA_IMAGE=localhost/moq-carla:<tag printed by the moq-dev/carla build>

The token is a demo-project JWT scoped to publish carla/** and subscribe
carla/.socket/driver-*, the endpoints drivers dial from. For local
carla/.client/**, the endpoints drivers dial from. For local
development, MOQ_URL=http://localhost:4443 needs no token.

Then run:
Expand Down
2 changes: 1 addition & 1 deletion demo/carla/sim/systemd/install-user-service.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ CARLA_SYSTEMD_USER_DIR="$tmp/units" \
grep -Fxq ' MOQ_URL=https://cdn.moq.dev/demo?jwt=<token>' "$tmp/install.out"
grep -Fxq ' CARLA_IMAGE=localhost/moq-carla:<tag printed by the moq-dev/carla build>' "$tmp/install.out"
grep -Fq 'scoped to publish carla/** and subscribe' "$tmp/install.out"
grep -Fq 'carla/.socket/driver-*, the endpoints drivers dial from. For local' "$tmp/install.out"
grep -Fq 'carla/.client/**, the endpoints drivers dial from. For local' "$tmp/install.out"
test "$(stat -c %a "$tmp/units")" = 700
test "$(stat -c %a "$tmp/config")" = 700
test "$(stat -c %a "$tmp/units/carla-sim.service")" = 600
Expand Down
8 changes: 1 addition & 7 deletions demo/carla/sim/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,7 @@ def test_relay_url_defaults_to_the_local_relay(monkeypatch: pytest.MonkeyPatch)

def test_paths_match_the_player() -> None:
assert broadcast_path("truck1", "front") == "carla/truck1/front.hang"
assert Drivers("truck1", asyncio.Queue()).path == "carla/.socket/truck1"


def test_a_truck_named_like_a_driver_is_refused() -> None:
"""Anonymous drivers may publish `driver-*` endpoints, so such a truck could be impersonated."""
with pytest.raises(SystemExit):
parse_args(["--url", "http://localhost:4443", "--truck", "driver-1"])
assert Drivers("truck1", asyncio.Queue()).path == "carla/.server/truck1"


def test_log_level_configures_python_and_rust(monkeypatch: pytest.MonkeyPatch) -> None:
Expand Down
3 changes: 2 additions & 1 deletion demo/carla/web/src/paths.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ describe("parseCamera", () => {
"carla/truck1/front",
"carla/truck1/rear/extra.hang",
"other/truck1/front.hang",
"carla/.socket/truck1",
"carla/.server/truck1",
"carla/.client/driver",
]) {
expect(parseCamera(path)).toBeUndefined();
}
Expand Down
8 changes: 4 additions & 4 deletions demo/carla/web/src/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
* The paths and connection settings shared with the simulator.
*
* Trucks publish one media broadcast per camera at `carla/{truck}/{camera}.hang`,
* and accept drivers on a socket endpoint named for the truck. A driver dials it
* from an endpoint of its own, `driver-{id}`, a form the demo relay lets
* and accept drivers on a server socket endpoint named for the truck. A driver
* dials it from a client endpoint of its own, the only role the demo relay lets
* anonymous viewers publish. The truck's public `status` names a driver by its
* session's {@link handle} instead, so no viewer learns an id it could announce.
* session's {@link handle} instead of its id.
*
* @module
*/
Expand All @@ -29,7 +29,7 @@ export function parseCamera(path: string): Camera | undefined {
return { truck, id: `${truck}/${file.slice(0, -".hang".length)}` };
}

/** The prefix every truck and driver socket endpoint sits under, as `carla/.socket/{id}`. */
/** The prefix every truck and driver socket endpoint sits under: `carla/.server/{truck}` and `carla/.client/{driver}`. */
export const SOCKET = Moq.Path.from("carla");

/**
Expand Down
12 changes: 7 additions & 5 deletions demo/relay/prod.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,16 @@ key = "key.pem"
# moq auth serve --listen 127.0.0.1:4440 --key root.jwk \
# --public-subscribe 'anon/**' --public-subscribe 'demo/**' \
# --public-publish 'anon/**' \
# --public-publish 'demo/boy/.socket/viewer-*' \
# --public-publish 'demo/carla/.socket/driver-*' \
# --public-publish 'demo/boy/.client/*' \
# --public-publish 'demo/carla/.client/*' \
# --mtls-publish '**' --mtls-subscribe '**' --mtls-link peer
#
# Anonymous MoQ Boy viewers and CARLA drivers get one shared grant each, covering only
# `viewer-*` and `driver-*` endpoint ids: a game's or truck's endpoint stays its
# publisher's, which signs in with a token. Each viewer's id is 128 random bits, so no
# viewer can guess another's.
# client socket endpoints: a game's or truck's server endpoint, `.server/<name>`, stays
# its publisher's, which signs in with a token. `demo/**` lets viewers dial those
# servers, and also read another viewer's client endpoint, which yields nothing without
# a session's secret id. Each viewer's id is 128 random bits, so no viewer can guess
# another's.
#
# For multiple keys with rotation, give it `--key-dir /path/to/keys/` instead:
# keys are named {kid}.jwk and resolved by the kid in the JWT header.
Expand Down
4 changes: 2 additions & 2 deletions doc/bin/demo.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ What it demonstrates:

- **On-demand encoding.** Emulation and encoding pause when the last viewer leaves and resume with a keyframe when one arrives. No timers, just subscription state.
- **Discovery by prefix.** Game sessions appear under `boy/game/`. No control plane.
- **Sockets.** Each emulator runs a [socket](/concept/socket) endpoint named for its game, and each viewer dials it from an endpoint with a random id. Button presses go up as messages on the viewer's own session, and the emulator answers each with that viewer's latency. A `status` track comes down to everyone with the held buttons and player count. Same relay, same protocol as the media. Sockets need `moq-lite-07-wip`, which is opt-in, on every hop, so the local relay enables it.
- **Split trust.** In production only the server publishes games and their endpoints, while anonymous viewers may publish only `viewer-*` endpoints.
- **Sockets.** Each emulator runs a [socket](/concept/socket) server endpoint named for its game, and each viewer dials it from a client endpoint with a random id. Button presses go up as messages on the viewer's own session, and the emulator answers each with that viewer's latency. A `status` track comes down to everyone with the held buttons and player count. Same relay, same protocol as the media. Sockets need `moq-lite-07-wip` or moq-transport on every hop. The emulator and viewer offer `moq-lite-07-wip`, which is opt-in, so the local relay enables it.
- **Split trust.** In production only the server publishes games and their server endpoints, while anonymous viewers may publish only client endpoints.

Code: [`rs/moq-boy`](https://github.com/moq-dev/moq/tree/main/rs/moq-boy) (emulator
and publisher), [`js/moq-boy`](https://github.com/moq-dev/moq/tree/main/js/moq-boy)
Expand Down
Loading
Loading