[relay] Calls: a long-poll on the fetch route, TURN credentials for coturn, wakes every 10 s; the module passes the TURN secret by systemd credential

This commit is contained in:
2026-12-03 00:29:07 +01:00
parent 1e2eed8e5b
commit 776e4ce39b
15 changed files with 654 additions and 22 deletions
+11 -5
View File
@@ -98,7 +98,8 @@ Nothing else. *(2026-11-22:)* a file has no mailbox, no sender and no recipient,
keeps **no count of fetches**: it sees each one as it serves it. A file is deleted when its
uploader deletes it, after **30 days**, or after **24 hours** if not all its chunks have arrived. No IP, no user agent, no request log beyond counts. *(2026-11-20:)* the relay also
remembers **in memory only**, never on disk, when it last woke each mailbox (§6), to wake it at most
once a minute. A blob is deleted on acknowledged
once every 10 seconds. *(2026-12-03, calls:)* also in memory only, never on disk: which mailboxes have a long-poll
waiting right now, and how many TURN credentials each mailbox got this hour (§8). A blob is deleted on acknowledged
delivery and after **30 days** at the latest *(decided 2026-11-08)*. The reverse proxy in front must also not
log; the NixOS module ships configured that way.
@@ -110,7 +111,8 @@ A notification for a closed app needs a push service. The wake-up carries **no c
**push endpoint per mailbox** (§8, `PUT …/push`), so the relay cannot link a person's mailboxes by
endpoint — it does see the endpoint's **host**, which on a person's own push server links them.
When a blob is stored under a valid post token, the relay POSTs the constant body `wake` to the
endpoint, at most once a minute per mailbox, with nothing of the mailbox, the blob or its sender.
endpoint, at most once every 10 seconds per mailbox *(60 until 2026-12-03; lowered so a call right after a
message still wakes a closed app)*, with nothing of the mailbox, the blob or its sender.
It connects only to **global** addresses (it resolves the host itself and drops loopback,
private, link-local, CGNAT, multicast and reserved addresses, IPv4-mapped forms included), follows
no redirect, gives up after 10 s, and has at most 16 wakes on their way. A push server's 404 or
@@ -132,11 +134,14 @@ The platform facts above are Claude's understanding, to be verified in `.agents/
- A post without a valid token is refused; after rotation the old token is refused.
- A delivered blob is gone; an undelivered blob is gone after the TTL (clock injected).
- A wake carries the constant body and nothing of the mailbox, its tokens or the blob; a mailbox is
woken at most once a minute; a non-global address is never connected to (`relay/tests/wake.rs`).
woken at most once every 10 seconds; a non-global address is never connected to (`relay/tests/wake.rs`).
- *(2026-12-03)* A long-poll is answered as soon as a blob arrives for its mailbox, and only then or after its
wait; a wrong token is never held; TURN credentials are coturn's REST pair, name no mailbox, are limited per
hour, and neither they nor the TURN secret reach the database (`relay/tests/calls.rs`).
- Parsers are fuzzed (`cargo fuzz`) for every message type.
- Every check in `VERIFY.md` §1 has a CI job or a documented manual procedure.
## 8. The wire (v0) — approved 2026-11-08, routes added 2026-11-14, quotas 2026-11-16, join page 2026-11-18, push 2026-11-20, files 2026-11-22
## 8. The wire (v0) — approved 2026-11-08, routes added 2026-11-14, quotas 2026-11-16, join page 2026-11-18, push 2026-11-20, files 2026-11-22, calls 2026-12-03
HTTP/1.1 behind TLS (the reverse proxy, F23). Ids and tokens are unpadded base64url of a fixed length
with one canonical spelling: ids are 16 bytes, and tokens and hashes are 32. JSON bodies refuse
unknown fields. A blob is at most 256 KiB, and a KeyPackage at most 16 KiB.
@@ -145,7 +150,8 @@ unknown fields. A blob is at most 256 KiB, and a KeyPackage at most 16 KiB.
|:--|:--|:--|
| `POST /v0/mailboxes` `{id, postTokenHash, fetchTokenHash}` | none | creates a mailbox. The owner sends **hashes**, so the relay never holds a token |
| `POST /v0/mailboxes/{id}/blobs` (bytes) | post token | stores the blob with its size and the hour it arrived |
| `GET /v0/mailboxes/{id}/blobs` | fetch token | the waiting blobs, oldest first, at most 100. Fetching deletes nothing |
| `GET /v0/mailboxes/{id}/blobs[?wait=N]` | fetch token | the waiting blobs, oldest first, at most 100. Fetching deletes nothing. *(2026-12-03)* With `wait` (seconds, at most 25) and nothing waiting, the request is held until a blob arrives for this mailbox or `wait` passes. At most 1 024 held relay-wide; over that, answered at once. A held request tells the relay the client is online, as each fetch already does |
| `POST /v0/mailboxes/{id}/turn` *(2026-12-03)* | fetch token | `{username, password, ttl, urls}`: a TURN REST API pair (coturn `use-auth-secret`) for a call, valid 600 s; `username` is `<expiry>:<random>`, `password` base64(HMAC-SHA1(secret, username)). 30 per mailbox per hour, then 429. 404 on a relay without a TURN server. Stores nothing |
| `DELETE /v0/mailboxes/{id}/blobs/{sha256}` | fetch token | acknowledges: deletes that mailbox's blob with this SHA-256. §5 has no blob id, and a sequential id would leak how busy the relay is |
| `PUT /v0/mailboxes/{id}/post-token` `{postTokenHash}` | fetch token | blocks: the old post token is refused from now on |
| `PUT /v0/mailboxes/{id}/push` `{endpoint}` *(2026-11-20)* | fetch token | where to wake the owner (§6): `https://`, a host, no user info or fragment, at most 1 000 bytes. 204 |