[client] Calls: four MLS kinds (call, callAnswer, callIce, callEnd) with the frame key in the offer; coturn in the NixOS module; Caddy's global logger mkDefault; v0.3.0
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
# Calls, the client's part: four MLS kinds and the call's frame key
|
||||
|
||||
Designed 2026-12-03 for Amicitia F36 (`amicitia/.agents/features/calls.md`), after the relay's part
|
||||
(`calls-relay.md`, v0.2.0). This change adds the call's own messages to the client, plus the coturn server
|
||||
that `calls-relay.md` §2 designed for the NixOS module.
|
||||
|
||||
## 1. Why and what
|
||||
A call is set up by two apps exchanging an offer, an answer and network candidates (WebRTC's SDP and ICE), and it
|
||||
ends with one line in the chat (*Call, 23 min* or *Missed call*). These go **inside MLS**, like texts, so the relay
|
||||
sees only sealed blobs of the usual sizes. The SDP carries each side's DTLS fingerprint, so no TURN server or relay
|
||||
can sit in the middle of the media's DTLS handshake.
|
||||
|
||||
Four kinds (`docs/PROTOCOL.md` §4):
|
||||
|
||||
| `kind` | Fields | Meaning |
|
||||
| :-- | :-- | :-- |
|
||||
| `call` | `id`, `video`, `sdp`, `key`, `at` | an offer: `id` 16 random bytes made by the caller; `sdp` 1 byte to 16 KiB; `key` the call's 32-byte frame key; `at` the caller's clock in Unix seconds. No `seq` |
|
||||
| `callAnswer` | `id`, `sdp` | the answer to the receiver's own offer `id`. No `seq` |
|
||||
| `callIce` | `id`, `candidates` | 0–32 ICE candidates for `id`, each 1–512 bytes without control characters; an empty list says *no more*. No `seq` |
|
||||
| `callEnd` | `id`, `seq`, `reason`, `seconds` | the call is over: `reason` is `hangUp`, `declined`, `busy`, `missed` or `failed`; `seconds` 0–86 400 it lasted. **A message** (it shares `seq` with `text`): the one line a call leaves |
|
||||
|
||||
Only `callEnd` has a `seq`, so an older client shows *update the app* for it and drops the other three without a
|
||||
trace. Such a client cannot answer, so the caller sees no answer and ends the call as *missed*.
|
||||
|
||||
## 2. Design
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
participant A as caller's client
|
||||
participant R as relay
|
||||
participant B as callee's client
|
||||
A->>A: offer_call(contact, video, sdp, now) → id, key
|
||||
A->>R: call {id, video, sdp, key, at}
|
||||
R->>B: (fetched, long-poll)
|
||||
B->>B: Event::CallOffered: the app rings, if `at` is recent
|
||||
B->>R: callAnswer {id, sdp} · callIce {id, candidates} (both ways)
|
||||
R->>A: Event::CallAnswered, Event::CallCandidates
|
||||
Note over A,B: media over TURN: DTLS-SRTP, each frame sealed under `key` by the app
|
||||
A->>R: callEnd {id, seq, reason, seconds}
|
||||
R->>B: Event::CallEnded (the chat's line)
|
||||
```
|
||||
- **The frame key travels in the offer.** The F36 design derived it from the MLS exporter. Instead the caller's
|
||||
client makes 32 random bytes and sends them inside the MLS-sealed `call`. It is equally secret (only the two
|
||||
members can open the message), it is post-quantum exactly when MLS is, and it does not depend on both sides being
|
||||
in the same MLS epoch: an exporter key would silently differ if one side had processed a commit the other had not
|
||||
(a key update, a later move to a post-quantum suite, a second device). `CallKey`'s `Debug` prints nothing.
|
||||
- **Live calls, in memory only.** The client remembers the calls in progress: their id, contact, whether they are
|
||||
ours, and whether they have been answered. At most 8, the oldest forgotten first. A restart forgets them, so an
|
||||
answer or candidates for a call the app no longer knows are dropped; that call has failed anyway.
|
||||
- `call`: dropped if its id is already live (on either side), if the contact is blocked, or if it is malformed.
|
||||
- `callAnswer`: accepted only for **our** live offer to **this** contact that has not been answered yet. A second
|
||||
answer, an answer to their own offer, or an answer from another contact is dropped.
|
||||
- `callIce`: accepted only for a live call with this contact.
|
||||
- `callEnd`: always shown if well formed and the contact is not blocked (a missed call must leave its line even
|
||||
when the offer was never seen); it ends the live call if there is one. Its `seq` counts for receipts.
|
||||
- **Sending:** `offer_call`, `answer_call` (only for their live, unanswered offer), `call_candidates` (a live call),
|
||||
`end_call` (any id: an app that restarted mid-call can still say it ended; a live one is forgotten). All return an
|
||||
`Outgoing`; nothing reaches the network until the app delivers it, as for texts.
|
||||
- **Clock.** `at` lets the callee's app show an offer fetched hours later as missed instead of ringing. Clocks
|
||||
differ; the app should ring only when `at` is within a minute or two of its own clock, and otherwise say *missed*.
|
||||
The client does not judge it.
|
||||
- **Two calls crossing** (each calls the other at once): both offers are live, with different ids. The client
|
||||
reports both; the app keeps one (the lower id) and ends the other as `busy`.
|
||||
- **New error:** `ClientError::BadCall` (an id that is not live where one must be, an SDP or a candidate outside its
|
||||
limits, too many candidates).
|
||||
|
||||
### coturn in the NixOS module (`calls-relay.md` §2, §4.4)
|
||||
`services.tabellarius.turn` already has `secretFile` and `urls` (v0.2.0). New: `turn.coturn.enable` runs coturn on
|
||||
the same host with `use-auth-secret` and the same secret file (read by systemd's `LoadCredential`, never in the Nix
|
||||
store), `realm` = the relay's domain, listening on 3478 UDP and TCP, relay ports 49152–49999, and **no logs**
|
||||
(`no-stdout-log`, `log-file=/dev/null`, `simple-log`, `no-cli`), `no-multicast-peers`, `denied-peer-ip` for private,
|
||||
loopback and link-local ranges (so TURN cannot reach the server's own network), and `no-tls`/`no-dtls` (the media
|
||||
inside is DTLS-SRTP and frame-sealed; the credentials are HMAC-based). It opens those ports in the firewall.
|
||||
Caddy's global `logFormat` becomes `lib.mkDefault`, so a host that keeps a global error log (as .217 does) sets it
|
||||
without `mkForce`.
|
||||
|
||||
## 3. Risks
|
||||
- **Privacy surface:** nothing new reaches the relay: four more kinds of sealed blob. The SDP holds the device's
|
||||
candidate addresses; it travels only inside MLS, and the app asks ICE for relay candidates only (TURN), so it holds
|
||||
no local or public address of the device. coturn sees both devices' addresses while a call runs (`calls-relay.md`
|
||||
§3); it writes none to disk (VM test).
|
||||
- **Events (Amicitia):** none here; *Log this call* is the app's.
|
||||
- **Offline:** a call to an unreachable relay fails at delivery, like a text.
|
||||
- **Abuse:** a contact can only ring you if you accepted their invite; a blocked contact's calls are dropped.
|
||||
|
||||
## 4. Verification (tests first)
|
||||
| Case | Kind | Where |
|
||||
| :-- | :-- | :-- |
|
||||
| an offer, its answer, candidates both ways and the end go from one client to the other through a relay; both hold the same key | integration | `client/tests/calls.rs` |
|
||||
| a second `call` for a live id, an answer to their own offer, a second answer, an answer from another contact, candidates for an unknown id are dropped | integration | `client/tests/calls.rs` |
|
||||
| `callEnd` for a call never seen still arrives, with its `seq`, and counts for receipts | integration | `client/tests/calls.rs` |
|
||||
| a blocked contact's offer is dropped | integration | `client/tests/calls.rs` |
|
||||
| sending: an answer, candidates or an SDP outside the rules give `BadCall`; nothing is sealed | integration | `client/tests/calls.rs` |
|
||||
| an older client (without the kinds) shows `callEnd` as unsupported and drops the rest | unit | `client/src/lib.rs` |
|
||||
| every new kind is in `KNOWN_KINDS`; a known call kind with an unknown field is dropped | unit | `client/src/lib.rs` |
|
||||
| `CallKey`'s `Debug` shows no byte | unit | `protocol/src/lib.rs` |
|
||||
| the call kinds' SDP, candidates and key never reach the relay's database | integration | `client/tests/real_relay.rs` |
|
||||
| coturn allocates with the relay's credentials and refuses a wrong password; no client address on the server's disk or journal | NixOS VM | `deploy/nixos/test.nix` |
|
||||
@@ -52,7 +52,9 @@ flowchart LR
|
||||
module writes an access log per host by default; the host's `logFormat` is set to
|
||||
`output discard`, and Caddy's default logger too. Caddy's own TLS-handshake and proxy errors can
|
||||
name a client address, so no log is the rule; an operator who needs one turns it on and knows
|
||||
why. Headers: none added.
|
||||
why. Headers: none added. *(2026-12-03)* The default logger is every site's on the machine, so the module sets
|
||||
it with `lib.mkDefault`: a host that serves other sites may keep a global error log (.217 sets
|
||||
`"level ERROR"`). Such a log can then hold a client's address in a rare TLS-handshake error for the relay's name.
|
||||
- **journald:** the relay prints one line at start. Nothing per request.
|
||||
|
||||
### The VM test (`deploy/nixos/test.nix`, `nix flake check`)
|
||||
@@ -78,6 +80,13 @@ input pins the tag, so the code that runs is the code tagged and published (`doc
|
||||
- **DNS and TLS:** one A/AAAA name for the relay. Caddy gets its certificate by HTTP-01, so port 80 must reach it.
|
||||
- **After deploying:** `curl -s https://<name>/version` answers the relay's version, and `https://<name>/join` serves the join page; `journalctl -u
|
||||
tabellarius` shows the one start line and nothing per request; no file under `/var/log` names a client.
|
||||
- **Calls (v0.3.0, `call-kinds.md`):** a secret file outside the store, written by Custos (32 random bytes, base64,
|
||||
one line), then `turn.secretFile = "<path>"`, `turn.urls = [ "turn:<name>:3478?transport=udp"
|
||||
"turn:<name>:3478?transport=tcp" ]` and `turn.coturn.enable = true`. coturn runs on the same machine with the
|
||||
same secret and no log. Behind NAT: `turn.coturn.externalIp = "<public>/<this machine's LAN address>"`, and the
|
||||
router forwards 3478 (UDP and TCP) and 49152–49999 (UDP) to it. The relay answers `POST /v0/mailboxes/{id}/turn`
|
||||
only once `secretFile` is set. Check: `systemctl status coturn`, `ss -lun 'sport = :3478'`, and from outside
|
||||
`turnutils_uclient` with a pair from the relay.
|
||||
- **Rollback:** point the input at the previous tag and switch. The database (`/var/lib/tabellarius/relay.db`)
|
||||
keeps only waiting ciphertext; it stays across versions unless `docs/PROTOCOL.md` says otherwise.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user