The relay
A relay is the server a person's app talks to. It keeps their account, devices and profile card,
queues what other servers send them, files the conversations their DM settings take as requests
in a request inbox, and
forwards their requests to the servers that host the spaces they use. Every server is the relay of
its local users unless it runs with RIM_ROLE=host. This page explains what a relay and a host
do, for operators and for client authors. The contract is docs/specs/server-to-server-v1.md;
the server's key, id and transport settings are in docs/server-identity.md; deploying a public
relay is deploy/README.md and running one is docs/operations/relay-public.md.
Nothing here runs until server-to-server traffic is on (RIM_PUBLIC_BASE_URL is an https URL).
Before that, a server is the relay and host of its own users only, as it always was.
For operators #
Configuration #
| Variable | Default | Meaning |
|---|---|---|
RIM_ROLE |
both |
relay creates no new workspaces; host refuses /api/remote/…, contacts, DM requests and deliveries |
RIM_RELAY_QUEUE_BYTES_PER_USER |
268435456 | Bytes queued per local user; over it the oldest items are dropped |
RIM_RELAY_RETENTION_DAYS |
30 | How long queued items and DM requests are kept |
RIM_S2S_DEVICE_RATE_PER_MIN |
120 | Forwarded requests per device per minute: those a local user's device sends through /api/remote/…, and those a host accepts |
RIM_S2S_SUBSCRIPTIONS_PER_PEER |
10000 | Active delegations one relay may hold on this host; past it new delegations are refused as limited, while renewals of active ones still go through |
RIM_S2S_PEER_DEAD_AFTER_HOURS |
24 | Hours every delivery to a relay may fail before it is dead: no new outbox rows are written for it until a delivery succeeds again (1 to 168) |
RIM_HOST_ALLOWED_RELAYS |
empty = any | Server ids of the relays allowed to push identities, join, subscribe, forward, report presence and bring revocations here |
RIM_RELAY_FORWARDS_PER_USER_PER_DAY |
50000 | Requests a local user sends through /api/remote/… per day |
RIM_RELAY_DM_REQUESTS_PER_DAY |
20 | DM requests one sender principal files here per day, and invites a local user sends per day to people on other servers they do not know (a contact who lists them too, or someone either accepted a DM request from here) |
RIM_RELAY_CARD_MAX_BYTES |
131072 | Largest profile card a local user publishes |
RIM_RELAY_KEY_PACKAGES_PER_DEVICE |
100 | Unclaimed one-time key packages per device and cipher suite |
RIM_RELAY_DEVICES_PER_USER |
32 | Devices a local user keeps, revoked ones not counted |
RIM_REGISTRATION_POW_BITS |
unset | Turns on proof-of-work signups, "The public relay" |
The direct space #
Each server has one server row of kind direct, named "Direct messages", created at start. It
holds the DMs and groups its users start with people on other servers, and is never listed by
servers nor found by name. Everyone in it is a guest: nobody sees its member list, and nobody
creates channels, invites or plugins there. Local users join it on first use: a signed-in
relayInfo, or any read or write of the direct space that needs membership; people from
other servers join when a local user adds them. Custom emojis, plugins, workspace keybinds,
pipelines, workspace state and channels answer VALIDATION ("not available in the direct
space") there, reads and writes alike, and the refused call joins nobody.
With no Owner or Moderator there, a report of a message in the direct space (reportMessage,
reportEncryptedMessage) goes to the instance operators. They list, open and resolve these
reports in the app with the workspace moderation roots and the direct space's id, read the one
reported message when it is not encrypted, see its author's principal id to block it, and may
delete a reported unencrypted message or a message with a verified report; nobody else can
(docs/api.md, "Instance moderation").
A conversation's home is the relay whose direct space holds it. The home sequences it: it stores the messages, Commits and Welcomes, and every member's app reads and writes there, through their own relay when it is elsewhere.
People from other servers #
When a local user adds someone from another server, this server fetches their identity (key log,
devices with certificates and revocations, profile card) from their relay, checks every signature,
and stores them as a user row of kind remote named r_ and the first 30 characters of their
principal id. Their relay pushes identity changes (POST /s2s/v1/identity) to the servers that
queued items or filed requests for them; this server applies a push only from a relay their
profile card lists, their home relay while they have no card, or a relay holding a delegation of
one of their devices, and refuses any other server with 403 not_delegated. principalDevices
also refetches a remote person's identity when the stored copy is over an hour old, from the
relays their card lists and then their home relay. If such a person later signs up here with
their key, the remote row becomes their local account and keeps its memberships.
The r_ username is internal and never shown as a name. What people see for someone from
another server is their handle, @<username>:<domain> (User.handle): the username their
home relay gives them and that relay's handle domain (docs/server-identity.md, "Handles and
delegation"). A relay sends its user's username with their identity and with a workspace join;
this server records it only from the relay that is their home relay, and only with a handle
domain it checked to point back at that relay. Until both are known (the relay is older and does
not send the username, or its domain does not delegate to it) the person has no handle here,
User.handle is null, and clients show their card's display name. Local people's handles use
this server's own handle domain, so in a shared workspace two people called kuba on two servers
read @kuba:rim-platform.org and @kuba:example.org. A search can name either form:
from:@kuba (a local account) or from:@kuba:example.org.
Remote users never sign in here and never run account mutations here: sign-in, sign-up, device
and key changes, card publishing, profile, workspace creation, device links, instance invites
and the relay's own mutations are refused with FORBIDDEN ("not available to remote
members").
Queues and the outbox #
Every event of a space with remote members becomes a signed host event (host-event) on a stream:
c:<conversationId> for a conversation's events, u:<principalId> for one person's (their
notifications, mentions, read states, Welcomes, DM invites, and for a guest the directory events
about them), w for other space-wide events, e for typing and presence. Each stream's seq
counts from 1 without gaps; e has none. The host appends one outbox row per relay that should
get the event (for a workspace, the relays holding an active delegation of the person; for the
direct space, the relays the person's newest card lists, else the relay that served their
identity) and a sender delivers each relay's rows in order (POST /s2s/v1/deliver), backing off
from 1 second to 5 minutes. Outbox rows are kept 7 days, delivered or not. A relay that refuses a
person as unknown is not sent their events for 24 hours. Each server process keeps that refusal in
memory: a restart forgets it, and with several nodes each node learns it from the relay on its own.
The rows a relay has not acknowledged are capped at 100,000 rows and 2 GiB per relay; delivered
rows do not count. Past either cap, and while the relay is dead (every delivery to it has failed
for RIM_S2S_PEER_DEAD_AFTER_HOURS), new events get no row for that relay: they are counted in
rim_outbox_not_queued_rows_total and logged at warn ("host events for a relay are not queued")
at most once a minute per relay. The message or change itself is saved here, and other relays
and local members get it as usual. A dead relay is tried once every 5 minutes, with an empty
delivery when nothing is left for it; the first success ends its failures and queueing resumes
within 10 seconds. The events it did not get still took their streams' seq, so its people's
apps see the gap and reconcile from this host, as for any gap.
A relay queues an item that names no conversation (a w event, presence on e, a person's
directory events on their u: stream) for a recipient who holds an active subscription to its
workspace. A host's direct space sends such items too, presence and the recipient's own directory
events: those are queued for a recipient who accepted a conversation that host homes. Anything
else naming no conversation is refused (not_subscribed). Items queued from
one host take at most 2 GiB a day across all recipients, those of workspaces the recipient
subscribed to not counted; past it the host's items are refused (limited) until its day ends.
The count is in memory, per node.
A relay stores each envelope once and one item per recipient. Each device reads its user's items
above its cursor; a device added later starts at the newest item queued before it. An item is
deleted once every non-revoked device of its user has acknowledged it, and after the retention
period regardless; an item a DM request holds is kept as long as the request, and one released by
accepting it for at least the retention period from then. Over the per-user byte cap the oldest items go first and the devices online get
a QueueOverflow notice; a device offline at the time sees the gap in the stream's seq. Items a
DM request holds are not counted toward that cap and are never dropped for it; the request
inbox's own limits bound them. A relay pulls what a host still holds for it
(GET /s2s/v1/outbox) every minute, so a delivery missed while the relay was down arrives on the
next pull.
The request inbox #
A relay files a conversation's invite (DmInvite) by the recipient's effective DM setting, the
three layers of docs/messaging.md ("Who May Start A DM"): the operator's RIM_DM_INBOUND, then
the floors of the recipient's workspaces, then the recipient's choice, with fellow members of a
workspace hosted here judged by the recipient's choice for that workspace (or its default) and
delivered when they are its Owner or a Moderator. What the setting delivers is recorded as
accepted at once; what it takes as a request is filed as a DM request; what it refuses is
answered blocked. Before any of that, an invite another host delivers must come from someone
that host speaks for: its card verifies against the sender's key log (the copy held here, an
identity cached in the last day, or the one the host serves), and the newest card known for
the sender lists the host's origin, or the sender is a local user subscribed to a workspace
there. Otherwise it is refused (invalid_invite) and nothing is filed, so a host cannot pass
off a stranger's DM as one from a contact or a fellow workspace member. When neither this
server nor the host has an identity for the sender (the host may serve identities to its
partners only), the invite is judged as a stranger's, whoever it names: a pending request at
most, which the app verifies before it shows the sender's name. A request keeps the sender's
card and holds up to three items of the conversation in at most 1 MiB; later ones are dropped
until it is accepted. Items of a conversation the relay has no invite for are refused
(not_subscribed), so a host cannot skip the inbox. A decided conversation keeps its decision
when the settings change later.
A conversation accepted as it arrives keeps no card. A recipient holds at most 5,000 accepted
conversations per other host; past them an invite their settings deliver is refused as limited,
while accepting a request is never refused. This server's own conversations are not counted, so
nobody here can fill the cap to silence a user; they are bounded where they are started (a user
starts at most 50 conversations a day in the direct space, docs/messaging.md). An accepted conversation's row expires 400 days after the
last item delivered for it. The next item of such a conversation is refused not_subscribed;
its host, when it is a RIM server still holding the person as a member, sends the conversation's
invite again (at most once a day per conversation and person, as this server does for its own
direct space), and the invite is filed like any other: at once for a contact or someone accepted
before, as a request otherwise. The same repairs a conversation whose invite this relay never
got, written while its host held no deliveries for it after a day of failures. A conversation
whose host is gone simply stops reaching the queue. The row goes at once when its user leaves the conversation or is removed
from it: here when this server hosts it, and for a conversation hosted elsewhere when the host's
MemberRemovedFromConversation names the user, which the relay recognizes once an event of that
host on the user's own stream (a Welcome, a read state, a notification) told it the host's id
for them.
The same rule covers conversations of this server's own direct space whose creator is someone else
(a person from another relay creating a DM with a local user through the forward path, or a local
user), and DMs between members of a workspace this server hosts. The server files its own invite for
the local member; until they accept, the conversation is left out of their inboxConversations, its
events out of their workspaceEvents, and its notifications, mentions and unread counts out of the
notification list, the bell, unreadCounts and the email digest; its first events are held with the
request. Everything appears once they accept. They may read the conversation before they decide, but
post nothing into it: while their request for it is pending or ignored, or they blocked whoever
started it (in any space here, for DMs and groups: "What a blocked person started"), sendMessage, replyToMessage, forwardMessage into it, sendEncryptedMessage and
toggleReaction answer FORBIDDEN ("accept the message request before posting here"), and
startTyping answers false without telling anyone. Someone the other member of a DM blocked posts
nothing into it either: the same mutations answer FORBIDDEN ("they do not take direct messages
from you"), so nothing they write while blocked is stored here. This server enforces it for the
conversations it hosts; a reply to a request for a conversation hosted elsewhere goes to that host
through the forward path, which leaves it to the client. This needs server-to-server traffic to be
on; with it off, conversations in the direct space are live at once.
| Action | Effect |
|---|---|
acceptDmRequest |
Held items released; later items flow; the sender becomes a contact |
ignoreDmRequest |
Held items deleted but the invite, which stays with the request; later items dropped; the request expires after 30 days (for a conversation this server hosts, the request is cleared instead, below) |
blockPrincipal |
Pending requests from the principal ignored as above; its invites (blocked) and key package claims refused; what they started is hidden and silenced (below) |
unblockPrincipal |
The block lifted; every ignored request from the principal that still keeps its invite, ignored by hand or by the block, is cleared: listed and counted nowhere, until the next item of its conversation files it again as a new pending request holding that item. Nothing dropped while it was ignored comes back. A conversation hosted elsewhere keeps at its host what they wrote meanwhile, which reading it there shows. Unblocking someone not blocked changes nothing. Nothing is cleared while the operator blocks the principal. A DM or group of this server the person started that the user had accepted is cleared too: it stays out of their view until its next event sends its invite again and files a request holding it, the sender's card taken from that invite. So nothing they wrote while blocked shows before the user decides. A DM the user started, and a conversation hosted on another server, come back as they were. |
reportDmRequest |
Filed in relay_abuse_report for the operator and audited as relay.dm_request_reported; a pending request is ignored. Once per user and request: a second report is CONFLICT |
| Nothing | Expires after the retention period; from then on accepting, ignoring or reporting it is NOT_FOUND, as for an unknown request; for a conversation this server hosts, see below |
Blocking someone also removes them from your contacts; unblocking does not add them back, so their new conversations arrive as requests.
What a blocked person started. DMs and groups someone the user blocked started are hidden and silenced until the unblock, wherever they are hosted. Channels are not.
Here, in any space this server hosts (the direct space, a workspace or the default
workspace), the conversation's creator decides. It is left out of the user's inboxConversations
and workspaceEvents, and out of their notifications, bell, digest and unread counts. The user
posts nothing into it: the posting mutations answer FORBIDDEN as for an undecided request, and
startTyping answers false. The person they blocked still sees the conversation. In a group
they still post, for its other members. In a DM their posts are refused ("they do not take
direct messages from you").
A DM with the person is hidden here the same way whoever started it, a DM the user started included.
On another server, the relay does not know who created a conversation, only who sent the user's invite. That is its creator, or for a group the member who added the user later. It drops every item of an accepted conversation whose invite came from someone the user blocked, and acknowledges it, so the host does not send it again. So a group someone else started is silenced if the blocked person added the user to it, and one the blocked person started is not silenced if someone else added the user. The conversation's history stays at its host, which keeps listing it for the user; the app leaves it out of Direct messages while the person is blocked.
A group someone else started is not affected, wherever it is hosted.
A request of a conversation this server hosts never lapses into a conversation. Its recipient is
a member from the start, and only the request keeps the conversation out of their view. When such
a request expires, unanswered or 30 days after an Ignore, while its recipient is still a member,
the relay clears it instead of deleting it. A cleared request is listed and counted nowhere and
holds nothing. It still keeps the conversation out of their view, and their posts out of it. The
conversation's next event first sends its DmInvite again, from whoever sent the first, and the
request is filed anew holding that invite and the event, with a DmRequestReceived notice. A
request from someone the user or the operator blocked is not cleared: it stays ignored for another
retention period. The recipient takes a cleared conversation back by posting into it (the
mutations above), which accepts it. A request of a conversation hosted elsewhere is deleted when
it expires; its host sends the invite again with the next item.
Limits: 100 pending requests per recipient, RIM_RELAY_DM_REQUESTS_PER_DAY (20) per sender
principal per day on this relay, 1,000 per delivering host per day whichever principals it names,
and 16 MiB of held items per recipient, the invites ignored requests keep included; past them
invites are refused as limited, and an item past the held bytes is dropped. A conversation
started on this server (by a local user, or through the forward path) that would file a request
past the pending or daily limit is refused when it is started: FORBIDDEN for a full inbox,
RATE_LIMITED with retryAfterSeconds for the sender's daily limit (docs/messaging.md, "Who
May Start A DM"). So is one by a creator with a principal id but no profile card with a local
user who has one (VALIDATION): no invite could be filed for it. An own invite still refused for a local member (limited or blocked) is kept
as an ignored request that is never listed or counted and expires after 30 days, so its
conversation stays out of their view and raises no notification. Another server's claim of a
local user's key packages names its claimer, a name the relay cannot check, so whom the claimer
knows does not count: the claim is a stranger's unless the user accepted a conversation that
server homes or holds an active subscription to a workspace it hosts. A stranger's claim gets
last-resort packages only, at most 20 claims per claimer per day; a claimer the user blocked is
refused.
With RIM_DM_INBOUND=partners the identity endpoint (GET /s2s/v1/principals/<id>) answers
only the servers RIM_DM_PARTNERS lists, and with none no server; everyone else gets 404 as
for an unknown principal, so a leaked directory reaches nobody. Key package claims from those
servers are refused (403). A server where the person holds an active subscription to a
workspace is answered either way: they joined it. Outbound, RIM_DM_OUTBOUND decides which
servers a local user may start a DM with, claim key packages from, and have direct-space events
sent to (docs/messaging.md).
Forwarded requests #
A local user's app reaches a space hosted elsewhere at /api/remote/<hostServerId>/<path> with
its session cookie (and X-CSRF-Token for POST), a device-signed request statement in
Rim-Device-Request (unpadded base64url of the payload) and its signature in
Rim-Device-Signature. The relay checks that the statement names the session's principal and
device, that the device is not revoked and that the signature verifies, then forwards the body
unchanged to <host>/s2s/v1/forward/<path> and returns the host's answer unchanged. A host it
cannot reach is 502 {"error":"upstream_unavailable","hostServerId":…}.
The host checks the S2S signature, the device request (a device of a user it holds, its own id,
the method, path and body hash, the seq window), and that the relay may carry the user's
traffic: the relay holds an active delegation of that device for a workspace the user is still a
member of, or the user is a member of its direct space and their newest card lists the relay's
origin (403 not_delegated otherwise). It then runs GraphQL (POST /api), attachment downloads and
uploads, avatar uploads (POST /api/files/avatar), stored-file downloads (GET /api/files/<path>),
plugin bundle downloads or custom emoji images (GET /api/emoji/<id>) as that user and device,
with no session, and signs every
answer, refusals included, with Rim-Host-Response and Rim-Host-Signature. Per-IP limits key
on relay:<serverId>:<principalId>.
A device request's seq is accepted once: the host remembers accepted values for at least 10
minutes and until they fall below its window (5 minutes in microseconds under the device's
highest), and refuses a repeat or a lower value with 409 {"error":"replay","highestSeq":…}.
Workspaces with members from other servers #
A person whose relay is another server joins a workspace here through that relay. Their app gets
a login challenge from this server (POST /s2s/v1/join/challenge, 120 seconds, single use),
with the workspace its invite names, and
signs it with this server's id as the audience, so the proof is good here only. It also signs a
delegation: its relay may receive this workspace's events for the person and forward that
device's signed requests here, for at most 24 hours. The relay presents both with the person's key
log, devices and card (POST /s2s/v1/join). This server checks everything, joins the person by
the invite exactly as joinServerByInvite does (bans included; a current member sends no invite),
stores them as a remote user and keeps the delegation.
A delegation is accepted when its device is a live device of the person, it names this server
and the presenting relay, its relay key hash names a key of the relay's log that no recovery
rotation replaced, the person is a current, unbanned member, and it runs at most 24 hours. It is
kept until its expiry or a day after acceptance, whichever is first, one per workspace, device and
relay. Relays renew them (POST /s2s/v1/subscriptions, at most 64 at a time, each accepted or
refused with a reason) and cancel them (POST /s2s/v1/subscriptions/cancel). A workspace's events
go to the relays holding an active delegation of a recipient; those relays may forward the
device's requests. A kick or a ban ends the person's delegations once their MemberLeft is queued;
a revoked device's delegations end with it.
Relays report whether their users are online (POST /s2s/v1/presence); this server shows a remote
member online in every workspace their relay holds a delegation for, until the relay reports them
offline.
A revocation of a remote member's device arrives from their relay (POST /s2s/v1/revocations) or
straight from their app (applyRemoteRevocation). This server checks it against its copy of the
person's key log, marks the device revoked, ends its delegations and sessions, removes it from
encrypted groups, and answers a signed acknowledgement; a repeat gets the same one.
When their relay is down, a remote member's desktop app may sign in here directly with its device
key (loginWithKey, audience this server's id). This server first tries to refresh the person's
identity from their relays, waiting up to 10 seconds, and issues a session of 24 hours. Account
mutations stay refused on it.
Cleanup and audit #
Every minute the server deletes acknowledged and expired items, envelopes no item uses, expired
requests, outbox rows over 7 days (delivered or not) and accepted seq values out of the window,
ends expired delegations and those of revoked devices or departed members, and marks this relay's
expired subscriptions lapsed. Every 5 seconds it sends revocations due for another attempt. Audit
events (target audit, ids only): relay.principal_blocked (scope user with
ignored_requests and removed_contact for a user's block, server for an operator's),
relay.principal_unblocked (scope user with cleared_requests and cleared_conversations
for a user's unblock, server for an operator's, with cleared_requests too),
relay.blocked_principal_refused,
relay.dm_request_reported, relay.abuse_report_filed, relay.abuse_report_resolved,
blocked_email_refused (action signup), relay.registration_pow, relay.left,
key_identity_adopted, host.revocation_applied, host.recovery_applied and
host.identity_revocations_applied (a recovery or revocations applied from a person's identity,
with the sessions and delegations they ended); host.remote_join and host.delegation_accepted are
also written to command_audit_log (initiator s2s).
The public relay #
A relay anyone may sign up on runs with the settings of deploy/compose.relay.yml on top of
deploy/compose.yml, as RIM_ROLE=relay, or both to host workspaces as well, as the
project's relay does. This section says how its registration and blocks behave;
docs/operations/relay-public.md has its quotas, the operator's commands and the abuse policy.
Registration. RIM_REGISTRATION_POW_BITS (1 to 40; 24 on the public relay) turns on pow
registration, whatever RIM_OPEN_REGISTRATION says. signupWithKey then takes a registration
token (instance invite or workspace invite) or proofOfWork: an 8-byte nonce,
unpadded base64url, such that
SHA-256("rim.pow.v1\0" || this server's id || "\0" || inception payload || nonce)
starts with that many zero bits. The work is bound to this server and one principal, and
checking it is one hash. Proof-of-work signups also count against the open-signup limit per IP,
checked after the proof, so a proof that fails uses up none of the address's signups, and are
audited as relay.registration_pow. The descriptor says "registration":{"mode":"pow","powBits":24} and registrationMode
answers POW. A signup link from rim_server invite create lets a person in without the work;
it needs no account or workspace, so it works with RIM_ROLE=relay.
Account cap. RIM_LIMIT_ACCOUNTS caps the local accounts the relay holds, those waiting out
their deletion grace period included; the r_ rows of people from other servers and purged
accounts do not count. At the cap every signup is refused with REGISTRATION_FULL, a signup link
and a proof-of-work too, a person from another server signing up here with their key included,
and the discovery document says "registration":{"full":true} beside the descriptor.
Quotas per local user are the RIM_RELAY_* settings above. The per-minute and per-day
counters are in memory, per node.
Blocking a principal. rim_server principal block <principalId> --reason <text> stores the
block in relay_principal_block, ends the sessions of the account holding the principal here
and ignores its pending DM requests for every recipient. From then on, until principal unblock: its logins and signups are refused (FORBIDDEN); deliveries to it are
refused as unknown_principal and its invites as blocked; its key packages are not handed
out, and it claims none; GET /s2s/v1/principals/<id> answers 404; forwarded requests it
signs are refused with 403. principal list shows the blocks.
In the same transaction the command revokes the account's instance and workspace invites that
still have uses left, adds its email (if it has one) to blocked_email, which refuses that
address at signup (VALIDATION, "this email cannot sign up here"), and records the reason as an abuse report, resolved by the block. Every account
records the invite it signed up with and that invite's creator, so the command then lists the
accounts the blocked one's invites created; --cascade blocks them too, recursively, each with
the reason followed by "(invited by <username>)". An account without a key identity is blocked
by its email alone. principal show <principalId> prints the account, its inviter, the tree of
accounts its invites created, its invites, its open reports and its block. principal unblock
lifts the principal's block and its email's, not the sessions or invites that ended. It clears the
DM requests the block ignored, for every recipient who has not blocked the principal themselves,
so the next item of such a conversation files it again as a request ("The request inbox"); it
prints how many and audits them as cleared_requests.
Blocking a peer. rim_server peer block <serverId> sets the pinned peer's status to
blocked, which the request check reads on every request: its requests get
403 peer_not_allowed and nothing is sent to it. peer unblock makes it active again. A
forked peer stays forked; a peer never pinned is refused with RIM_S2S_DENIED_PEERS instead.
Audited as s2s.peer_blocked and s2s.peer_unblocked.
Idle pins and cached identities. An hourly job forgets the pin of a server that was neither
fetched nor sent a request for 90 days when nothing here refers to it and the configuration does
not name it, keeping its key-log head: its next contact pins it again only with a log that
extends that head (docs/specs/server-to-server-v1.md, "Pinning a peer"). Forked and blocked
pins stay. The same job deletes cached identities of people on other servers 30 days after they
were fetched, except those of remote users held here. One origin holds at most 4 pins.
Abuse reports. reportDmRequest in the app and reports that come by mail (rim_server abuse-reports add) both end in relay_abuse_report, which abuse-reports list (oldest first,
100 a page or up to 500 with --limit, --after <report id> for the next page) and
abuse-reports resolve work through. Reports of messages in DMs and groups stay in
message_report under the direct space, which the operators read in the app ("The direct
space").
For clients #
relayInfo { serverId roles directSpaceId }(no session needed) names the direct space.remoteServer(origin)pins another server through the relay and returns its discovery document to verify and pin in the app. It failsCONFLICTwhen 4 other servers are pinned at that origin.remoteIdentity(principalId, relayUrl)returns a principal's key log, devices and card, from this server or fetched fromrelayUrland cached for 24 hours. WithoutrelayUrlit refetches from the relay that served the cached copy, which is deleted 30 days after the fetch (kept for remote users held here); after thatrelayUrlis needed again. Verify the log against the principal id, each certificate against the log and the card against the head.contacts,addContact(principalId, relayUrls),removeContact(principalId): the contact list the request inbox filters by. Relay URLs are 1 to 8 of 1 to 256 bytes of printable ASCII without?,#or@. The caller's own principal is refused (VALIDATION, "cannot add yourself as a contact"), and so is someone new once the caller holds 1,000 contacts (VALIDATION, "a user holds at most 1000 contacts; remove one first"). A contact added on one side only does not exempt its holder from the daily invites to other servers or from probation; one who lists the holder too does.createConversation(input: { serverId: <directSpaceId>, remoteMembers: [{ principalId, relayUrls }], encrypted })starts a DM (one remote member, nootherUserIdormemberIds) or a group with people on other servers; people on this relay may be named the same way. A conversation with someone on another relay must beencrypted(otherwiseVALIDATION, "conversations with people on other servers are encrypted"), and every member needs an MLS-active device. AnymemberIds, or more than one remote member, makes a group. The caller needs a published profile card: their relays show it in the request inbox. Remote members that name nobody but the caller are refused (VALIDATION, "cannot create DM with yourself").predecessor: { hostServerId, conversationId }records the conversation a successor replaces, andConversation.predecessorreturns it.addConversationMembers(serverId: <directSpaceId>, conversationId, remoteMembers: [{ principalId, relayUrls }])adds people to a group of the direct space the same way, with the same rules: an encrypted group, an MLS-active device for everyone added, a published card.- On a relay in
powregistration mode (registrationModeisPOW; the difficulty is the discovery document'sregistration.powBits),signupWithKeytakesproofOfWork: count from 0, hash as in "The public relay" with the counter as the 8-byte big-endian nonce, and send the first nonce that meets the difficulty, unpadded base64url. A registration token instead skips the work. dmRequests(status),acceptDmRequest,ignoreDmRequest,blockPrincipal,unblockPrincipal,reportDmRequestwork the request inbox. A request'sheldItemsare host-signed envelopes to read before deciding, theDmInvitefirst; verify it to bind the conversation's space to its home before reading or leaving it.myBlockedPrincipalslists the caller's blocks newest first:principalId,blockedAt, anduserId,usernameanddisplayNameof the account on this server holding the principal (null when none does).unblockPrincipaltakes one off and clears the requests ignored from that person and the conversations here accepted from them ("The request inbox").relayStream(after)on the existing WebSocket yields the session device's items aboveafter(its cursor when omitted), then live ones, as JSON strings:{"type":"RelayItem","id","hostServerId","workspaceId","envelope":{"payload","signature"}}, plus{"type":"DmRequestReceived","requestId"}and{"type":"QueueOverflow","spaces":[{"hostServerId","workspaceId"}]}.relayItems(after, limit)pulls the same items;ackRelayItems(upTo)moves the device's cursor. The session must be bound to a device.- For every item, check the envelope's signature under the host key pinned for
hostServerIdat itskeySeq, thathostis that server, and that the stream matches the event (c:its conversation,u:your principal). Apply a stream's events inseqorder; on a gap, reconcile through the host (its change feed andstreamHeads(serverId, streams)through the forward path). leaveRelaycancels the caller's subscriptions at every host, then deletes their queue, DM requests, the join requests they filed at other hosts, contacts and blocks on this relay.
Joining a workspace on another host #
Read the invite link
rim-invite:1:<hostServerId>:<hostKeyHash>:<inviteToken>:<hostOrigin>and pin the host withremoteServer(origin). A workspace's public link,https://<host>/join/rim_pjl_…, names the host by its origin only:remoteServer(origin)answers its server id, which the app pins.remoteJoinChallenge(hostServerId, hostOrigin, inviteToken, publicLinkToken), with at most one of the two tokens, returns{ challengeId nonce expiresAt workspaceId workspaceName publicLinkMode }:workspaceIdis the workspace the invite or link names (looked up, not used), null without either;workspaceNameandpublicLinkMode(DIRECTorREQUESTS) are set for a link, so the app can show "Join" or "Ask to join". Every invalid link answersNOT_FOUND; a link that does not admit accounts of other servers, and a host that blocked this relay, answerFORBIDDEN. Sign aloginstatement over the challenge withaudience= the host's server id.Sign a delegation with the device key over
rim.delegation.v1\0 || payload:{"v":2,"type":"delegation","principalId":"rimp1_…","deviceId":"<uuid>","relay":"<relay server id>", "relayKeyHash":"<hash of the relay's current key>","host":"<host server id>","workspaceId":"<uuid>", "scope":"workspace","nonce":"<16 random bytes, base64url>","issuedAt":"…","expiresAt":"…"}expiresAtis at most 24 hours afterissuedAt.relayInfonames the relay; its key hash is in the relay's discovery document.joinRemoteWorkspace(input: { hostServerId, hostOrigin, inviteToken, publicLinkToken, message, proof, delegation })returns{ hostServerId workspaceId userId role outcome joinRequestId joinRequestExpiresAt }; both tokens are null for a current member, andmessageis the note to the moderators of a link that takes join requests. Withoutcome: JOINEDthe workspace is then used through/api/remote/<hostServerId>/api, and its events arrive onrelayStream.With
outcome: REQUESTEDthe host filed a join request and the person is not a member yet: no subscription exists, androleis the role the link gives. The relay records the request until it expires and queues the decision, aJoinRequestDecideditem on the person'su:stream withoutcomeaccepted,declinedorcancelled, then forgets the request. Onaccepted, sign a fresh challenge and delegation and sendjoinRemoteWorkspacewith no token, as a current member.myJoinRequestson the relay does not list requests filed at other hosts.
Keeping delegations fresh #
remoteSubscriptionslists{ hostServerId workspaceId status expiresAt }withstatusactive,lapsed(every delegation expired) orended(cancelled).- When the current delegations have less than 6 hours left, an online device signs fresh ones and
sends them with
renewDelegations(delegations). Each entry of the answer isactivewith itsexpiresAt, orrefusedwith areason: one of the host's (not_member,expired, …), orhost_unreachable(try again later; the subscription is unchanged) orhost_refused(the host turned the presentation down). The relay logs what lies behind the last two. - While a device has
relayStreamopen, the hosts see the person online; 30 seconds after the last stream closes they see them offline.
Revoking a device #
revokeDeviceKey on the relay also sends the revocation to every host and DM home holding the
person, retrying at 10 s, 30 s, 1 min, 2 min, 5 min and then every 15 minutes for a day.
deviceRevocationStatus(deviceId) lists { hostServerId status attempts ack } per host, status
PENDING, ACKED or GAVE_UP; relayStream pushes
{"type":"RevocationAcked","deviceId","hostServerId","ack":{"payload","signature"}} as each host
acknowledges. Check each ack (a revocation-ack statement) under the host's pinned key and its
revocationSha256 against the revocation. A host that has not acknowledged within 2 minutes gets
the revocation from the app directly: applyRemoteRevocation(revocation) on the host's own /api
needs no session and no CSRF header and returns the acknowledgement; an address may try it 20
times in 15 minutes.
Signing in to a host directly #
When the relay is unreachable, the desktop app calls keyLoginChallenge and loginWithKey on the
host's own /api with audience = the host's server id. The session lasts 24 hours; account
mutations are refused on it (FORBIDDEN), as through the relay.