garage44.eu/jeroen/cartopolis

logclone: git clone https://garage44.eu/jeroen/cartopolis.git

.. /docs/notes/chat-across-servers.md

raw


topic: chat-across-servers triggers: [crates/simulator/src/remote, remote/calls.rs, "call/join", "call/signal", "accounts.home", V45__people_elsewhere.sql, "/ap/chat", peer_test_bases, chat_elsewhere.rs, "other servers", "full address", local_name, ADDRESS_MARK] updated: 2026-11-28

Contacts and private chats between servers

Built 2026-11-16: the first part of stage 5 of docs/mockups/federation/README.md. Somebody on one server can look somebody up on another by full address (bob@rug.example), send a contact request, have it accepted, and talk in a direct private chat, each connected only to their own server. The apps and the wire did not change (no protocol revision): every identity was already a full address (protocol 37, web-chat.md), so what changed is that the simulator forwards instead of answering 501.

Somebody elsewhere is an account here

The rules (contacts, requests, blocks, chat membership, devices) are all keyed by account, so a person elsewhere is given one, the first time they are named (remote::account, accounts.home, V45): username their full address, pw_hash no PHC string, request policy anyone. Nothing else needed changing to hold them. Each server applies a request or an answer to its own copy, so each enforces its own person's setting and limits: the sender's home its daily limit, the receiver's home their policy and blocks.

Two consequences to keep:

Rejected: separate tables for remote members and contacts. Every rule would have needed a second path, and a second path is where a block stops holding.

A chat lives on its hub

A conversation's id names its hub (address::group_home), which orders its log as before. A member elsewhere's home follows:

Call (POST /ap/chat/…)From → toWhat
personasker's home → their homethe person card, answered by their home
contact-request, contact-answerhome → homeapplied on both sides; a decline stays silent
keysasker's home → their homekey packages, only with a contact or request between them
submitmember's home → huban E2eeSend from a device elsewhere; the hub's answer is passed back
deliver, invitehub → member's homewhat the hub appended, for that home's people
syncmember's home → huba device catching up; blocks are filtered at home

Calls go under /ap/, which Caddy already sends to the simulator for the fediverse, so a deployment needed no proxy change. They are JSON, signed with the instance actor's key the fediverse already has, and a server is believed only with its own (key_id_of: the key id must be https://<server>/ap/actor#main-key, and the people a call names must end in @<server>). Blocked servers and the fediverse's per-server throttle apply. The whole thing is off where the fediverse is off (a localhost development sim): Link::enabled.

Delivery from the hub runs in the background and is not retried: a missed deliver is a gap the device fills by sync, as it does for any gap. A missed invite is not recovered yet; the inviter's device has to add them again.

Calls (2026-11-19)

A call in a chat runs on the forwarder of the chat's hub, for every member wherever they live (remote::calls): one call, one forwarder, nobody's media relayed twice, and the keys are the chat's as on one server. A device still talks only to its home; its home forwards what it says about the call:

Call (POST /ap/chat/call/…)From → toWhat
joinmember's home → huba CallJoin, with the full addresses the person blocks; answered with the forwarder's SDP, "waiting", or the refusal
answer, leavemember's home → hubanswers to the forwarder's offers, in order; leaving, joining another call or the connection ending
signalhub → member's homea call message for one device in the call (offers, CallJoined on admission, CallEnded, reactions), or a roster for the people named — which is what rings them

The media goes from the device straight to the hub's forwarder: its address is the one candidate in the forwarder's SDP, so the hub needs calls_listen and a reachable calls_public_addr; the member's home needs neither.

A closed app of a member elsewhere is woken by its home (2026-11-28): the hub's first roster of a call — one member, sent for their joining (calls::starts_a_call) — makes the home push to the people it names, as the hub does for its own (ChatHub::wake_for_call, message-wake-ups.md). The hub knows no member's push address and needs none; a hub older than this rings the same way, since the roster is what it always sent. The caller's own account at the home and whoever blocked them are not woken.

Not across servers yet: declining (the caller elsewhere rings until the minute is up), a device that comes online mid-call at a home is not told of the running call (Catchup knows only devices here), and hands, host actions, reactions sent, cameras watched, guests from a device elsewhere (CallControl, CallReact, CallWatch, CallInvite, CallKeyDrop are not forwarded; the defaults — everybody's cameras — hold). None of it has run between two real servers on the internet: the test runs two on one machine (people_on_two_servers_call_each_other_on_the_chats_hub).

Not done yet

Testing it

tests/integration/chat_elsewhere.rs runs two simulators on one machine, named localhost and 127.0.0.1, with real MLS devices: a refused request, a card, a request, an acceptance, a direct chat both ways, and a catch-up after being away. peer_test_bases (tests only, read only with fediverse_allow_private) says where each finds the other, since a server's name drops its port.