Calls: long-poll, TURN credentials, wakes every 10 s (v0.2.0) #27
Reference in New Issue
Block a user
Delete Branch "feature/calls-relay"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The relay's part of calls (
.agents/features/calls-relay.md; for Amicitia F36). This is a protocol change, anddocs/PROTOCOL.md§5, §6, §7 and §8 say what changed, when and why.GET /v0/mailboxes/{id}/blobs?wait=N(at most 25 s): a long-poll, so a call rings within about a second. In memory only; at most 1 024 held.POST /v0/mailboxes/{id}/turn(fetch token): coturn REST API credentials, valid 600 s, 30 per mailbox per hour. Nothing is stored.--turn-secret-fileand--turn-url, which come together or not at all. Module:services.tabellarius.turn.{secretFile, urls}; the secret reaches the relay through systemd'sLoadCredentialand never enters the Nix store.The self-review is posted below.
Self-review (CLAUDE.md §3, adversarial).
Evidence
cargo test --workspace: client 76 (unit 24, block 7, files 8, pairing 8, polls 4, push 3, reactions 5, real_relay 3, state 14), protocol 20 (wire), relay 57 (unit 2, calls 11 new, files 8, quotas 8, relay 19, wake 9).cargo clippy --workspace --all-targets -D warnings: clean.turnenabled: TURN 200 for the fetch token, 404 for the post token,?wait=1200, the client's IP nowhere, the TURN secret not in the relay's data or /var/log). Then rarh8t363kzbx at the 0.2.0 commit.arrivals.arrived(&id)inpost_blob,a_long_poll_answers_as_soon_as_a_blob_arrivesfails (held the full 25 s); (2) TURN authorised by the post token instead of the fetch token: three TURN tests fail.Findings
turn.secretFilewas typedpath. A local path would be copied into the world-readable Nix store, secret included. It is a string now, and the secret travels byLoadCredential.Arrivals::entersums every entry, which is O(n) with n ≤ 1 024 under a mutex. Cheap at this size; a counter would do if the cap grows.use-auth-secretdocuments it, but coturn itself is in the next PR (its NixOS service and a VM test withturnutils_uclient). Until then no URL points at a TURN server, and the route stays off.@@ -0,0 +29,4 @@/// A place to wait for `id`, or `None` when the relay already holds `max` waiters.pub fn enter(&self, id: MailboxId) -> Option<Place<'_>> {let mut w = self.waiting.lock().unwrap_or_else(|e| e.into_inner());let total: usize = w.values().map(|(_, n)| n).sum();Finding 4: O(n) under the lock, n ≤ 1 024; fine now, a counter if the cap grows.
@@ -158,0 +200,4 @@};let notified = place.notify.notified();tokio::pin!(notified);notified.as_mut().enable();The waiter is enabled before the store is read, so a blob posted between the read and the wait still wakes it. Planted bug 1 removes the notify in post_blob and the test catches it.
@@ -67,0 +67,4 @@turn = {secretFile = lib.mkOption {# A string, not a path: a path would copy the secret into the world-readable Nix store.type = lib.types.nullOr lib.types.str;Finding 1: a
pathoption would copy the secret into /nix/store (world-readable). Kept a string; LoadCredential below hands it to the DynamicUser.Merged into main as
7a2b825(--no-ff; the remote hash was checked). Tagged v0.2.0 on the merge, the tag the home server deploys from.Pull request closed