Uplink Developer docs Get Uplink
APIs

The hub and pairing protocols

What an app says to the relay server over a WebSocket: signing in, packets, presence, rooms and the directory.

The relay server speaks two WebSocket protocols. The hub is where installs find each other: any address ending in /hub, so wss://gogho.st/hub. A pairing channel joins one phone to one of its computers: an address ending in 32 hex digits, wss://gogho.st/relay/<channel>. Both pass sealed bytes the server can't read. A third is spoken between relay servers: one relay dials another's hub and, in place of an app's sign-in, says it is a relay (Relays that talk to each other). Its plain HTTP routes are in the relay's HTTP routes, and how the app uses all of this is in Routes.

On all of them, a text frame is one JSON object and a binary frame is a sealed packet. The server pings each socket every 30 seconds, never compresses a message, and holds every message to a length before it reads it (Message sizes and the memory budget). The code is relay/lib/hub.dart, relay/lib/relay.dart, relay/lib/federation.dart and relay/lib/ws_door.dart; the app's side of the hub is lib/net/hub_carrier.dart.

Who an install is

An install is a P-256 (secp256r1) key pair made on the device. The hub knows it by a name made from the public key. There is no account to make first: anyone with a key can sign in.

ThingWhat it is
Public key33 bytes, compressed: 02 or 03, then x. Sent as base64 in the sign-in, whois and acct-put; as 66 lowercase hex digits for a read-only room's owner.
Name (id)The first 16 bytes of SHA-256 of those 33 bytes, as 32 lowercase hex digits. In binary frames it is the 16 raw bytes.
SignatureECDSA over SHA-256 of the message, as 64 raw bytes: r, then s, big-endian. Not DER. Sent as base64 in the sign-in and in bind; as 128 lowercase hex digits in a read-only room's grants.
Account addressAn Uplink account is a second key, secp256k1, known by an Ethereum-style address: 0x and 40 hex digits. Only the account messages use it.

All hex the server reads is lowercase.

Signing in to the hub

  1. Open a WebSocket to wss://gogho.st/hub. With 20,000 sockets open already, the upgrade is refused with HTTP 503.
  2. The hub speaks first, with a number made for this connection (32 random bytes, as 64 hex digits):
    {"hello": "<64 hex>", "peek": true, "react": true, "v2": true,
     "relay": {"id": "<32 hex>", "key": "<base64>", "url": "wss://relay.example.com/hub", "fed": true}}
    peek says this hub knows the look-only sign-in below. react says it takes reaction packets. v2 is there only on a hub that knows the hosts it is reached at, and says it takes the sign-in bound to a host, below. relay is there only on a relay that talks to other relays: its own name and key, its hub's address where it claims one (url), and the relay it stays linked to where it has one (via).
  3. Within 10 seconds, answer with one text frame of 16,384 bytes at most:
    {"id": "<32 hex>", "key": "<base64, 33 bytes>", "sig": "<base64, 64 bytes>", "device": "desk-1",
     "v": 2, "host": "gogho.st"}
  4. The hub answers, then hands over what it held for you as binary frames:
    {"ok": true, "held": 3, "now": 1763900000000, "since": 1763800000000, "helpers": ["https://…"]}
    now is the hub's clock and since is when it started, both in milliseconds. What a hub holds is in memory, so a packet it said it held before since is gone. helpers is there only where the relay names link helpers: up to 4 https:// addresses of servers that help two devices link directly.
FieldWhat it holds
idYour name. It must be the one made from key.
keyYour public key, base64.
sigYour signature, base64. Without v: over the 13 bytes of ghost-hub v1 (with its space) followed by the 32 raw bytes of the hub's number: the hex decoded, not the hex text. With "v": 2: over the 13 bytes of ghost-hub v2 , one byte holding the length of host, the bytes of host in lower case, then the 32 bytes of the hub's number.
vOptional. 2 for the sign-in bound to a host. Use it when the hello said "v2": true.
hostWith "v": 2: the host you dialled, with its port only where that is not 443 or 80. It must be one the hub is reached at, compared in lower case.
deviceOptional. Which of your devices this is, 64 characters at most. Left out, too long or not a string, it counts as the empty string.
peekOptional. true makes this a look only.
modeOptional. busy or invisible: how you are shown from the first moment, where this is your name's first device here. See Presence.
fed1 from another relay, never from an app: the frame is then a relay's hello, with other fields.

Bound to a host

A v1 signature says nothing of where it was made, so a server an app was pointed at could pass the app's own relay's number to it and sign in there with the answer. A v2 signature is good only at a hub reached by the host it names. Once the hub has seen a key sign in with v2, it takes no v1 from that key while it knows its own hosts, and answers {"ok": false, "err": "This account signs in a newer way now: update Uplink on this device."}. Refused again within the hour, the answer comes 2 minutes late, with the connection open meanwhile. The hub remembers 200,000 such keys across restarts, letting go first of those that hold no username. A hub that knows no hosts takes v1 from anyone and never says v2.

One name can be signed in from 8 devices at once. A new connection with the same device takes the older one's place, and a ninth device takes the place of the one connected longest. The connection that lost its place is closed with 4409.

Where the hub counts what one place does, a place is the connection's address: an IPv4 address, or the first 48 bits of an IPv6 one. Behind a proxy on the same machine or a private network, it is the last address in X-Forwarded-For, the one the proxy saw.

A look

With "peek": true the hub says how much is waiting and closes the socket with 1000 (looked). Nothing is handed over or removed, and no other connection of yours is replaced. A closed app uses it to see whether it should wake.

{"ok": true, "held": 3, "peek": true, "here": false}

here says whether any device of this name is connected now.

Refusals and close codes

CodeReasonWhen
4400bad helloThe first frame wasn't JSON text, the base64 didn't decode, id isn't made from key, or the signature is wrong. Sent first: {"ok": false, "err": "bad hello"}. Also a v2 sign-in whose host is not one of the hub's (err is then This relay isn't reached as <host>.), and a v1 sign-in from a key that signs in with v2.
4401no helloNo sign-in was accepted within 10 seconds.
4409replacedA newer connection took this device's place.
1000lookedA look was answered.
1009too bigA binary frame was empty or longer than 65,568 bytes.
4403The reasonAnother relay's hello was refused. See Linking.
4503fullThe hub filled while this connection was being made.
1001The server is stopping.
NoneThe socket is dropped with no close frame for a message past what the door takes, or a connection that holds too much.

After signing in

A text frame is known by its keys, tried in this order: ping, push, dir, watch, mode, away, join, anchor, leave, look, unlook. The first that matches decides. {"ping": 1} is answered {"pong": 1}, with whatever value was sent.

Packets to a person

A binary frame's first byte is its kind. Kind 0x01 is a packet to one name. The payload is sealed by the apps; the hub doesn't read it. The hub puts the sender's name in itself, so nobody can send under another's.

DirectionBytesHolds
To the hub00x01
1 to 4seq: a number you choose, uint32, big-endian. It comes back in the answer.
5 to 20The recipient's name, 16 bytes.
21 onThe payload, one byte at least.
From the hub00x01
1 to 16The sender's name, 16 bytes.
17 onThe payload.

A whole frame is 65,568 bytes at most (64 KiB and 32 bytes for headers). A longer one, or an empty one, closes the connection with 1009.

The packet goes to every connected device of the recipient except the connection that sent it. Each one is answered with a text frame:

AnswerMeaning
{"ack": <seq>, "here": true}Passed to at least one connected device.
{"ack": <seq>, "here": false}Nobody was there. It is held, and a push is asked for where the recipient registered one.
{"nak": <seq>, "err": "full"}Nobody was there and it could not be held.
{"ack": <seq>, "here": false, "fed": true}The recipient lives on another relay, and that relay took it. Whether they are connected there is never said across relays.
{"ack": <seq>, "here": false, "fed": true, "waiting": true}The recipient lives on another relay that can't be reached just now. The packet waits on this relay until it can.
{"nak": <seq>, "err": "home"}For another relay, but this relay holds no home record of yours that names it. Give your record and send again.
{"nak": <seq>, "err": "busy"}For another relay, and you are past what one install may send across relays, or may make this relay dial.
{"nak": <seq>, "err": "far"}Their relay is one this relay doesn't link with, or can't reach.
{"nak": <seq>, "err": "refused"}Their relay would not take it.

The answers with fed, and the last four refusals, come only from a relay that talks to other relays, and only for a recipient who is not connected here and whose home record names another relay. A packet you send to your own name is never passed on.

Held for someone away

The hub holds up to 200 frames and 1 MiB for one name, 96 MiB for everyone together, for 7 days. Against the 96 MiB each held frame counts as its bytes and 256 more. When the name next signs in, its mailbox is emptied and everything not too old is handed over, right after {"ok": true, "held": n}. An ack means the hub took the packet, not that the other app opened it.

The frames are handed over in order, only as fast as the connection takes them. Any not written by the time the connection closes go back to the mailbox. A packet a device sent to its own name is not handed back to that device: it stays held for the name's other devices.

Presence

A connection asks about names with watch, and from then on is told when they come and go. Watches add up for the life of the connection, to 500 names. There is no message to stop watching.

{"watch": ["<id>", "<id>"]}

Answered at once, about the names in that message:

{"here": ["<id>"], "away": ["<id>"], "busy": ["<id>"], "seen": {"<id>": 1763900000000}}
FieldMeaning
hereNames connected now.
awayNames connected with every device put away.
busyNames connected that chose to be shown as busy.
seenFor names not connected, when each was last here, in milliseconds since 1970. The hub remembers this for 200,000 names.
MessageFromMeaning
{"away": true} or falseYouThis device was put away, or is back in use. Not answered.
{"came": "<id>"}HubThe name's first device connected.
{"went": "<id>", "at": <ms>}HubIts last device disconnected. at is when it was put away, if it had been, else now.
{"away": "<id>", "is": <bool>, "at": <ms>}HubWhether all of its devices are away has changed.
{"mode": "online"}, "busy" or "invisible"YouHow your name is shown, said by any of its devices and held while one is connected. Any other word counts as online. Not answered.
{"busy": "<id>", "is": <bool>}HubThe name became busy, or stopped being.

An invisible name is shown to its watchers as gone. They are sent went when it hides. While it hides it is in none of here, away and busy, no came or away is sent for it, and its last-seen time stays where it was. When it stops hiding, watchers are sent came, then away if its devices are put away. A mode said in the sign-in holds from the first moment, so a name that signs in invisible never shows as come.

Rooms

A room is how more than two installs talk, such as a space or a circle's channel. Its name is 32 hex digits and its token 64 hex digits, both made by the apps. The first to join sets the token; the hub keeps only its SHA-256. A room with nobody in it is forgotten, though the packets it kept are not.

{"join": "<32 hex>", "token": "<64 hex>"}
AnswerWhen
{"room": "<room>", "ok": true, "members": ["<id>"]}Joined. members is the other names in it, not yours. In a read-only room there is also "ro": "writer" or "ro": "reader". On a relay with a media relay for calls there is also ice, below. The room's kept packets follow as binary frames.
{"room": …, "ok": false, "err": "bad room"}The name isn't 32 hex digits or the token isn't 64.
{"room": …, "ok": false, "err": "bad anchor"}A read-only join whose name isn't made from its base and owner.
{"room": …, "ok": false, "err": "refused"}The wrong token, or this connection is in the other room of that name (ordinary or read-only).
{"room": …, "ok": false, "err": "full"}The room has 64 names and yours isn't one, or the hub has 50,000 rooms and this would be a new one.

Every device of a name can be in a room. The room counts names, not devices.

A media relay for calls

A call's sound and picture go between the devices, not through the hub. Where two devices can't reach each other, they need a TURN server to pass the packets. A relay set up with one hands whoever joins a room a username and password for it, in the answer to join:

"ice": {"urls": ["turn:relay.example.com:3478?transport=udp"], "username": "1763986400:0f1e2d3c4b5a6978", "credential": "<base64>"}

It is an RTCIceServer entry as WebRTC takes it. username is the time it stops working, in seconds since 1970, a colon, and the first 16 characters of your name. credential is the base64 HMAC-SHA1 of the username under a secret the relay shares with the TURN server. It works for 24 hours unless the relay is set otherwise. Nothing about the room goes into it, and only a device that joined a room is given one. Without a TURN server there is no ice, and calls are direct only.

MessageFromMeaning
{"room": "<room>", "came": "<id>"}HubA name's first device joined. Sent to everyone else in the room.
{"room": "<room>", "went": "<id>"}HubA name's last device left or disconnected.
{"leave": "<room>"}YouLeaves the room. Not answered.
{"look": "<room>", "token": "<64 hex>"}YouAsks who is in an ordinary room without joining it. 200 looks a connection at most.
{"room": "<room>", "look": ["<id>"]}HubWho is in the room now, sent at once and again whenever that changes. An empty list for a room that doesn't exist. With the wrong token, nothing is said, now or later.
{"unlook": "<room>"}YouStops the looking. Not answered.
{"anchor": "<room>", "gv": …, "g": {…}, "gs": "…"}YouHands a read-only room you are in a newer list of admins. Not answered.
{"room": "<room>", "ro": "refused"}HubA reader in a read-only room sent a kept packet. It was neither kept nor passed on.

Room frames

DirectionBytesHolds
To the hub00x02 a packet, 0x03 a packet to keep, 0x04 a reaction.
1 to 16The room's name, 16 bytes.
17 onThe payload, one byte at least. A reaction's is 512 bytes at most.
From the hub00x02 for a packet, kept or not; 0x04 for a reaction.
1 to 16The room's name.
17 to 32The sender's name, 16 bytes.
33 onThe payload.
KindWhat the hub does
0x02Passes it to every other connection in the room, the sender's other devices too. Not answered. Ignored from someone not in the room.
0x03As 0x02, and keeps it for whoever joins later. It arrives as 0x02.
0x04Keeps it and passes it to everyone else in the room, readers too. One over 512 bytes is dropped without a word.

A room keeps its newest 300 frames for 7 days, within 256 MiB over all rooms. A device that joins with the token they were kept under is handed them, in order, after the answer to its join, only as fast as its connection takes them. A packet sent to the room meanwhile arrives after them, never among them.

Read-only rooms

In a read-only room only the owner and the admins the owner named may post. Its name is tied to the owner's key, so nobody else can open it first. Join with an ro object:

{"join": "<room>", "token": "<token>",
 "ro": {"base": "<32 hex>", "owner": "<66 hex>", "gv": 2,
        "g": {"<admin id>": "<128 hex>"}, "gs": "<128 hex>"}}
FieldWhat it holds
base16 bytes the app chose, as hex.
ownerThe owner's public key, 33 bytes as hex. The room's name must be the first 16 bytes of SHA-256 of ghost-ro|, then the 16 bytes of base, then the 33 bytes of owner.
gThe admins: each name with the owner's signature over ghost-circle admin|<owner hex>|<id>. 200 entries at most. An entry whose signature is wrong doesn't count.
gvOptional. The list's generation, a whole number. A list with a higher one replaces the one the room has.
gsNeeded when gv is above 0: the owner's signature over ghost-circle grants|<owner hex>|<gv>|<g as JSON>, with g's keys sorted and no spaces.

The owner's own name always may post. A reader's 0x03 is refused, a reader's 0x02 reaches the writers only, and a reader's 0x04 reaches everyone. A read-only room is kept apart from an ordinary room of the same name, and a connection can be in one of the two at a time. anchor takes the same gv, g and gs later on.

Pushes

An iPhone's app tells the hub its Apple push token, so that it can be woken when a packet is held for it. Android phones look for themselves, with a look.

MessageEffectAnswer
{"push": {"apns": "<hex>", "sandbox": false}}Keeps the token for this device of this name, by the device it signed in with. apns is 32 to 200 hex digits. sandbox counts only as true. The same token under another device of the name is forgotten there.{"push": true}, or false from a server that sends no pushes.
{"push": null}Forgets this device's token. So does any value that isn't such an object.The same.

When a packet is held for a name, every device of it that registered a token is sent one notification. It says only Uplink and New message, once a minute for one name at most. The server never has the words of a message to put in it.

The directory

Messages with a dir key ask the server's directory: usernames, linked handles, badges, accounts and invitations. Each is {"dir": "<name>", …} and its answer comes back on the same connection as another dir message. They aren't numbered: match an answer by its dir and the fields it repeats.

A refusal looks the same for all of them. err is a sentence to show the person:

{"dir": "err", "about": "claim", "err": "A username is 3 to 20 letters, numbers, dots or underscores."}

The messages under Usernames, Linked handles, Number verification and Badges also repeat the p that was sent. Something unexpected is answered That did not work. Try again in a while. A server run without one of these parts answers This server keeps no accounts. (or no invite words, no invites, no handles).

Two hashes appear throughout, both SHA-256 as 64 hex digits. A username's key is the hash of ghost-name v1|<username>. A handle's key k is the hash of ghost-handle v1|<network>|<handle>. Both are tidied first: trimmed, lower case, no leading @, and a phone number in E.164 form.

Usernames and profile

A username is 3 to 20 characters from a-z, 0-9, . and _, starting with a letter or digit, with no two dots together. Some words are reserved (admin, support, uplink and the like). An install holds one at a time.

MessageTakesAnswer
helloname: your own username, optional.{"dir": "hello", "ways", "listed", "links", "watching", "souls", "special"}. ways says how each network is linked here: signin, proof, text or off. links is a list of {"p", "k", "at"}. Then souls-gifts where something was given that the app has not said it showed, and any linked and joined that happened while you were away.
nameNothing.{"dir": "name", "k": …}: your username's key, or null.
claimname{"dir": "claim", "name", "ok": true, "k"}. Held by someone else: {"dir": "claim", "name", "ok": false, "err": "taken"}. Claiming another gives up the one you had.
releaseNothing.{"dir": "released"}. Anyone may claim it from then.
whoisname{"dir": "whois", "name", "id", "key"}: the holder's name and public key (base64), which is all it takes to write to them. Nobody: {"dir": "whois", "name", "none": true}. 120 an hour for one name, all its devices together. On a relay that talks to other relays the answer also carries home, the holder's home record, where one is held; and with at the name is asked of another relay.
keepblob: a string, 262,144 characters at most. Empty forgets it.{"dir": "keep", "ok": true}. One sealed blob for each install, replaced whole.
keptNothing.{"dir": "kept", "blob": …}: the blob, or null.
curl-keepblob: a string, 131,072 characters at most. Empty forgets it.{"dir": "curl-keep", "ok": true}. A second sealed blob for each name, kept apart from the first and replaced whole. The app keeps there the sign-ins to other networks that an account's devices share, sealed with a key only those devices have.
curl-keptNothing.{"dir": "curl-kept", "blob": …}: that blob, or null.

Linked handles

p names a network. discord, telegram and x are linked by signing in through a browser. bluesky, mastodon and github are linked by putting a code in the public profile. phone is linked by a texted code, below.

MessageTakesAnswer
linkp: a sign-in network.{"dir": "link", "p", "url"}: a page to open in a browser, good for 10 minutes. linked follows when the sign-in is done.
proofp: a profile network; handle{"dir": "proof", "p", "handle", "code"}: the code to put in the profile, ghost- and 10 hex digits.
checkp, handleReads the profile. linked where the code is in it, else a refusal. 40 reads an hour, shared with follows.
unlinkp{"dir": "unlinked", "p"}. No answer for a network the server doesn't know.
listedon: true or false.{"dir": "listed", "on"}. Turned on, those watching for one of your handles are told you joined. A phone number is never announced.
watchadd, remove: lists of handle keys.{"dir": "watching", "n"}: how many you now watch, 5,000 at most. Then {"dir": "joined", "list", "already": true} for those added that a listed install holds already.
followsp: a profile network; handle: your own linked handle.{"dir": "follows", "p", "handles"}: who that account follows, 5,000 at most.
forgetNothing.{"dir": "forgotten"}. Your links, listing and watch list are gone. Your username, souls, badges and kept blob are not touched.

Two messages come unasked:

MessageWhen
{"dir": "linked", "p", "handle", "k", "about"}A link was proved. about, with name and picture, comes only after a browser sign-in and only when there is something in it.
{"dir": "joined", "list": ["<k>"]}A listed install linked a handle you watch. Up to 300 wait for you while you are away.

Number verification

MessageTakesAnswer
textp: phone; handle: the number, with its country code.{"dir": "text", "p": "phone", "handle"}, the number in E.164 form. A code was texted to it. Nothing is linked yet.
codep: phone; handle; code: the digits.{"dir": "linked", "p": "phone", "handle", "k"}

An install may ask for 3 codes an hour and 6 a day, and so may a number. A code lasts 10 minutes and takes 10 tries an hour. Which countries can be texted, and how many texts go out in a day, are the server's settings. A refusal's err says which limit was met.

Badges, souls and admin

The special badges are bughunter, alpha, founder, team, supporter and helper. Souls are a count that belongs to each install and is told to nobody else.

MessageTakesAnswer
badgesids, names: lists of names and usernames, the first 64 of each.{"dir": "badges", "ids", "names"}: those of them that verified a phone number. Never the number. Where there is something to say, also show and showNames (the badge each shows) and special and specialNames (all of each one's badges). 240 an hour.
souls?Nothing.{"dir": "souls", "n", "special", "show"}: your souls, your badges and the one you show. show is left out when there is none.
showcasebadge: one of yours, or an empty string for the default.The souls message.

The souls message also comes unasked when something is given: with got and why for souls, or with badge for a badge. What the admin gives also carries gift, an id of 16 hex digits, and is kept until the app says it showed it, the newest 50 for one install:

MessageFromMeaning
{"dir": "souls-gifts", "list": [{"g", "at", "souls", "why"}, {"g", "at", "badge"}], "n", "special"}HubSent after the answer to hello: everything given and not yet shown, oldest first, with your souls and badges now. at is an ISO 8601 time.
{"dir": "souls-seen", "ids": ["<g>"]}YouThose were shown. They are not sent again. Not answered.

Souls given through POST /bounty come as a souls message with got and why, to an install that is connected.

Souls a person sends another through POST /souls/send come the same way: the receiver hears a souls message with got and a why of From <username>, the sender one with their new count.

The admin messages are for whoever runs the server. They work only on a connection that signed in with admin-login, from an install the server is set to allow; the sign-in lasts 8 hours and ends with the connection. Anyone else is answered {"dir": "<the dir>", "ok": false, "err": "Sign in to the admin page first."}.

MessageTakesAnswer
admin-loginuser, pass{"dir": "admin", "ok": true}, or "ok": false with err. 5 tries an hour.
admin-usersNothing.{"dir": "admin-users", "ok": true, "users": […]}: everyone known to the server.
admin-logNothing.{"dir": "admin-log", "ok": true, "grants": […]}: the newest 200 things given.
admin-giveto: a name; souls: a whole number, not 0, 100,000 either way at most; why{"dir": "admin-give", "ok": true, "to", "n"}: the new total.
admin-badgeto; badge; on: true or false.{"dir": "admin-badge", "ok": true, "to", "special"}

Accounts

An Uplink account is an address holding two sealed backups of one identity: one sealed by the password, one by the recovery words. The server can open neither. Four of these messages must be signed by the account's key, and come in an envelope:

{"dir": "acct-put", "body": "{\"op\":\"put\",\"a\":\"0x…\",\"by\":\"<your id>\",\"at\":1763900000000,…}", "sig": "<130 hex>"}
MessageTakesAnswer
acct-put (signed)In body: id and key (the identity's name and public key, base64); bind (that key's signature, base64, over ghost-account bind v1|<address, lower case>); pw and seed (the two sealed backups, 65,536 characters each at most); pwv (SHA-256 of the password proof, hex).{"dir": "acct-put", "ok": true, "a"}. One account for an identity, and one identity for an account.
acct-findname: a username.{"dir": "acct-find", "name", "phone", "kdf"}: whether a texted code is needed, and the settings to stretch the password with (v, k, m, t, p, s). No account: {"dir": "acct-find", "name", "none": true}. 30 an hour.
acct-textname; number: the account's verified number.{"dir": "acct-text", "name", "sent": true}. Only the right number is texted. 5 wrong numbers an hour.
acct-getname; auth: the password proof, 32 bytes as hex; number and code where the account has a verified number.{"dir": "acct-get", "name", "a", "blob"}: the address and the password-sealed backup. Where a code is needed and none came: {"dir": "acct-get", "name", "phone": true}. 6 tries an hour for a connection, 10 for an account.
acct-seed (signed)Nothing more.{"dir": "acct-seed", "a", "blob", "pw"}: both backups, for someone who signed in with the recovery words. No account: {"dir": "acct-seed", "a", "none": true}.
acct-devices (signed)In body, optional: add as {"d", "n", "p"} (a device's id of 32 hex digits, its name and its platform); remove (a device id). Neither just lists.{"dir": "acct-devices", "a", "list"}: each device as {"d", "n", "p", "at", "seen"}. 20 devices at most. The signed body and sig of a removal are kept for the removed device, for the 20 removed most lately.
acct-helloa: the address; d: this device's id.{"dir": "acct-hello", "a", "known", "account"}: whether this device is on the account, and whether the account exists. For a device the account removed there is also "removed": {"body", "sig"}: the account's own signed removal, which the device can check for itself.
acct-leavea: the address; d: this device's id.{"dir": "acct-leave", "a", "gone"}: whether a device was taken off the list. Not signed: it is for a device that holds no account key, such as a page in a browser signing out, and it removes that one device and nothing else.
acct-delete (signed)Nothing more.{"dir": "acct-delete", "a", "ok": true}, also when there was none.

The password itself never reaches the server. The app stretches it with Argon2id, sends a proof made from the result as auth, and the server checks only that the proof's SHA-256 is the pwv it was given. Signed changes, and acct-leave, are held to 60 an hour for a connection's name. A server that can't read the accounts it keeps answers every account message This server can't read the accounts it keeps just now. Nothing has been changed: try again later.

Invitations

An invitation waits for someone who isn't on the app yet, under a hash of their number: h is the handle key of that number on the network phone. b is the invitation, sealed by the app, as base64 of 2,048 characters at most.

MessageTakesAnswer
invitelist: 1 to 25 of {"h", "b", "t"}. t is an optional tag of 64 hex digits; a newer invitation with the same tag for the same number replaces the older.{"dir": "invite", "left"}: how many were kept. The sender needs a verified number or a linked account. 40 an hour and 120 a day.
invitesh{"dir": "invites", "h", "list"}: each as {"i", "b", "at"}. Only for the install that verified that number by text.
invites-droph; ids: a list of i.{"dir": "invites-drop", "left"}: how many still wait.

A number has 20 waiting at most, 3 of them from one sender, and each waits 30 days.

Invite words

A circle's invite word stands for its invite link. The word is never sent: h is its SHA-256 as 64 hex digits, and b is the link sealed by the app, 1,024 characters at most.

MessageTakesAnswer
word-seth, b{"dir": "word-set", "h", "ok": true}. Refused where another install holds the word. 10 words an install, 20 set an hour.
word-droph{"dir": "word-drop", "h", "ok": true}, also when there was no such word. Refused for someone else's.
wordh{"dir": "word", "h", "b": …}: the sealed link, or null.

A word not set again within 365 days is let go. The same lookup is there over HTTP, as GET /word/<h>.

Home records and names on other relays

These three are answered only by a relay that talks to other relays. On any other, home and home? get no answer, as any dir the server doesn't know, and at is not looked at.

A home record says where an account lives, signed by the account. It is the one thing a relay believes about where someone is.

{"v": 1, "a": "<32 hex>", "k": "<base64, 33 bytes>", "h": ["wss://relay.example.com/hub"],
 "n": 4, "t": 1763900000000, "s": "<base64, 64 bytes>"}
FieldWhat it holds
a, kThe account's name and public key. The name must be the one made from the key.
h1 to 3 addresses, each up to 200 characters of printable ASCII. A hub's address (wss://host/hub), or, for a relay with no address of its own, ghost-relay://<relay name>?n=<node id>&via=<the public relay it stays linked to>.
nA count from 1 to 4,294,967,295 that only goes up.
tWhen it was made, in milliseconds. At most 5 minutes ahead of the relay's clock. The record is good for 30 days from then.
sThe account's signature over: the 14 bytes of ghost-home v1 and a line feed; the name (16 bytes); n (4 bytes, big-endian); t (8 bytes, big-endian); the number of addresses (1 byte); then each address as its length (1 byte) and its bytes.

Of two records for one account the one believed has the higher n, then the later t, then the greater signature byte by byte. Two hub addresses are compared as written by one rule: wss or ws, the host in lower case, the port only where it is not the scheme's own, no slash at the end of the path, and no user, query or fragment.

MessageTakesAnswer
homerec: a home record. Your own, or a friend's so that this relay can route to them.{"dir": "home", "a", "ok": true, "n"}: the count of the record now held for that account. Or {"dir": "home", "a", "ok": false, "err"}, where err is busy (too many checks just now: give it again later), old (past its 30 days) or bad. 600 records checked an hour for one install; the record already held is not checked again.
home?a: your own name.{"dir": "home?", "a", "rec"}: your record as held here. {"dir": "home?", "a", "none": true} where there is none, or a is anyone else's.
whois with atname; at: the other relay's host, with a port where it has one. Its hub is taken to be wss://<at>/hub.{"dir": "whois", "name", "at", "id", "key", "home"}: asked of that relay over a link. home is there where that relay gave the holder's record. Nobody, or no answer: {"dir": "whois", "name", "at", "none": true, "why"}. An answer about this relay itself also carries "here": true.

why is left out when it is only that nobody holds the name. Otherwise it is off (this relay doesn't link with that one), refused (that one won't link with this), down (it couldn't be reached, or didn't answer in 8 seconds) or busy. A lookup at another relay counts against the same 120 an hour as any whois, and one install may make its relay dial 8 relays an hour for the first time.

A relay keeps the records its own people gave it across restarts, 20,000 at most, and the 10,000 others it used most lately in memory. Nobody is told another account's record but with the username its holder chose to be found by, or over a link between relays.

Relays that talk to each other

Two people whose apps use different relays can write to each other. Each app stays on its own relay, and the relays pass the sealed packets between them. It is off unless the relay's keeper turns it on, either with any relay that proves its key or only with those listed. A relay with it off makes no key, keeps no record, and its hub is as the rest of this page describes without it.

A relay is a key pair like an install's. Its name is made from its public key the same way, and its hub's hello carries both in relay. What it adds to what a relay can see is which of its people write to people on which other relay. Still never what.

RuleWhat it means
A relay speaks only for its own peopleA packet passed on as from someone is taken only where that someone's home record names the relay that passed it.
One hopA packet from another relay is handed to someone here or held for them, never passed to a third relay. The one exception is a relay with no address of its own, below.
Only for people known hereA packet from another relay is held only for a name that is connected, was seen since the hub started, holds a username here, or gave its own home record here.
No presence across relaysThe other relay is told that a packet was taken, never whether its recipient is connected.
Addresses are checked before they are dialledwss:// only, port 443, a path ending /hub, 200 characters. Every address the name resolves to must be public, and the connection is made to the address that was checked. 10 seconds to connect. A redirect is a refusal. A keeper can allow other ports and ws://.

A link is one WebSocket, opened by the relay that needs it, to the other relay's hub address.

  1. The dialled hub says its hello, as to any app. It must carry relay with an id made from its key.
  2. The dialler answers, in place of an app's sign-in:
    {"fed": 1, "id": "<32 hex>", "key": "<base64, 33 bytes>", "sig": "<base64, 64 bytes>",
     "url": "wss://dialler.example.com/hub", "c": "<64 hex>", "stay": true}
  3. The dialled relay answers yes, or no:
    {"ok": true, "fed": 1, "id": "<32 hex>", "key": "<base64>", "sig": "<base64>"}
    {"ok": false, "err": "not listed"}
FieldWhat it holds
id, keyThe relay's name and public key.
c32 random bytes the dialler made up for this link, as hex.
urlOptional. The dialler's own hub address, written by the rule above. Left out by a relay that has none.
stayOptional, true or false. true from a relay with no address that means to stay linked.
The dialler's sigOver the 18 bytes of ghost-fed-dial v2 (with its space); the hub's number (32 bytes); the dialler's name and the dialled relay's name (16 bytes each); c (32 bytes); one byte, 1 for stay and 0 otherwise; the address that was dialled; and the dialler's url, empty where it has none. Each address is one byte of length, then its bytes.
The answer's sigOver the 13 bytes of ghost-fed v2 ; c; the dialler's name; its own name; and the address it was dialled at, as one byte of length and its bytes.

Both sign both names and the address dialled, so what one signs for this link is of no use on another. The dialled relay takes the hello only where the address dialled is its own. It believes the dialler's url only after it has dialled that address itself and seen the same key in the hello there, which it remembers for an hour. What is for an address goes only over a link this relay dialled to that address, never over one that came in claiming it.

A refusal is sent as {"ok": false, "err": …} and the socket closed with 4403 and the same word:

errWhen
fed offThis relay links with none, or is stopping. A relay with federation off does not get this far: it answers bad hello and closes with 4400, as to any hello it can't read.
no addressThis relay claims no address of its own, so it takes no hello.
bad helloA field of the wrong shape, an id not made from key, or a wrong signature.
selfThe hello carries this relay's own name.
bad addressurl is not a hub's address written by the rule, or not one that may be dialled.
blocked, not listedIts keeper's lists say no.
busyToo many hellos this minute (30 from relays not yet seen at their address, together; 30 from each one that has been), no dial left to look at the address, or no room for another link.
addressThe key seen at url is not the one in the hello.

A link is opened when first needed and closed after 10 minutes with nothing crossing it. A relay that could not be reached is tried again after 5 seconds, then twice as long each time, up to 10 minutes. The dialler closes with 1000 and a word: idle, stuck (a packet unanswered for 30 seconds), room, slow (a hello not finished in 10 seconds), no or self.

On a link

FrameBytesHolds
A packet for someone on the other relay00x05
1 to 4A number the sender chooses, uint32, big-endian. It comes back in the answer.
5 to 20The recipient's name, 16 bytes.
21 to 36The sender's name, 16 bytes.
37 onThe payload, as the sender's app gave it to its hub: 65,568 bytes at most.
A packet for someone on a relay that stays linked to the other00x06
1 to 36As 0x05.
37 to 52, then 53 onThat relay's name, 16 bytes, then the payload.

Each is answered {"ack": <number>} or {"nak": <number>, "err": …}. At most 64 wait for an answer on one link at once.

errMeaningWhat the sending relay does
homeNo record of the sender's that names the sending relay is held.Says the record and sends once more.
toNobody of that name has signed in here; or, for 0x06, the recipient's record doesn't name that relay through this one.Says the recipient's record and sends once more, then gives up.
movedThe record held here says they live elsewhere. It has just been said on the link.Routes the packet again by that record, once.
limitThe sending relay is past its packets a minute or bytes a day.Keeps the packet, leaves this relay alone for 15 seconds, then twice as long each time up to an hour, then sends one packet alone to see.
busyToo busy to check the sender's record a moment ago.
fullNo room to hold it for the recipient.Tells the sender full.
big, farThe payload is over 65,568 bytes; or, for 0x06, that relay may not stay linked here.Tells the sender refused.

Text frames on a link:

MessageMeaning
{"fed": "home", "rec": {…}}A home record: to show whom the relay speaks for, or where someone lives. Checked like one an app gives. Not answered. 240 a minute from one relay.
{"fed": "whois", "q": <number>, "name": "maya"}Who holds this username on your relay?
{"fed": "whois", "q": <number>, "id", "key", "home"}The holder's name and key, and their record where one is held. Nobody: {"fed": "whois", "q", "none": true}, with "why": "busy" where the asking relay is past its lookups an hour.
{"ping": <value>}Answered {"pong": <value>} where the value is a whole number or a string of 32 characters at most, 60 a minute.

A text frame over 8,192 characters is ignored. A binary frame over 65,792 bytes, or a text frame over 65,536 characters, closes the link with 1009. The relay that dialled reads no message over 131,072 bytes from the hub it dialled.

What waits

A packet for a relay that can't be reached waits on the sender's relay. The sender's app is told "waiting": true at once, or after 4 seconds without an answer. For a relay linked with before, it waits up to 7 days. An address never once linked with is tried four times or for 2 minutes, then what waits for it is refused with far and the address is left alone for 10 minutes. What waits is in memory, and a restart loses it.

A relay with no address

A relay that can't be dialled, such as one hosted from an app, names a public relay to stay linked to. It dials that relay with "stay": true and no url, and keeps the link up. Its people's home records give the address ghost-relay://<its name>?…&via=<that relay's hub>. Another relay reaches them by sending the public relay a 0x06 frame naming the hosted one, and the public relay passes it down the standing link as 0x05. The hosted relay sends everything not for its own people up the same link, and the public relay passes it on to the relay the recipient lives on. That is two links at most. A public relay does this only where its keeper lets relays stay, for any or for those named. It is off by default.

Message sizes and the memory budget

Every WebSocket the relay takes or dials passes a guard that reads the frames' headers before anything else reads the message. A message past the limit ends the connection before a byte of it is held. The socket is dropped: there is no close frame and no code.

WhereFirst messageAny later message
The hub16,384 bytes1,048,576 bytes
A pairing channel16,384 bytes1,114,176 bytes. A binary frame over 1,048,640 that fits is closed with 1009.
A link, read by the relay that dialled it16,384 bytes131,072 bytes

All connections together may hold 64 MB in memory: the parts of messages still coming in, and what waits to go out. A connection is ended for what it holds only in these cases:

CaseWhen
Past its shareMore than 8 MB has waited to go out to it for 10 seconds on end.
A message coming in stalledIt has neither finished nor grown by 16 KiB in 20 seconds.
Everyone together past the budgetThose stalled longest go first, then those that hold the most, until the rest fit.

A connection whose own answers wait past 1 MiB is not read from until they fall below 256 KiB, so one that floods pings, or anything else that is answered, slows only itself. What the hub hands over of what it keeps waits while more than 256 KiB is on its way to that connection. The four numbers a keeper can change are in Running your own.

Pairing channels

A channel passes frames between a phone and one paired computer. Its name is the last part of the address: 32 lowercase hex digits. No headers or query are read. A WebSocket to any other address that doesn't end in hub is answered 404.

The first frame, within 10 seconds, says the channel's token and which end this is:

{"auth": "<64 hex>", "role": "phone"}
FieldWhat it holds
authThe channel's token. The first connection to a channel sets it, and the relay keeps only its SHA-256. Later ones must say the same.
rolephone or desk. One socket for each; a newer one in the same role replaces the older.
tempOptional. true, on the hello that makes the channel, makes it a temporary one, made for pairing.

After that:

MessageFromMeaning
{"ok": true, "peer": <bool>}RelayYou are in. peer says whether the other end is connected now.
{"ok": false, "err": "bad hello"}RelayThe hello wasn't JSON text, or its auth or role was wrong. Closed with 4400.
{"ok": false, "err": "refused"}RelayNot this channel's token, or the relay has all the channels it keeps. Closed with 4403.
{"peer": true}RelayThe other end joined.
{"peer": false}RelayThe other end's socket closed.
A binary frameEither endPassed to the other end as it came, 1,048,640 bytes at most (1 MiB and 64 bytes). The hello is 16,384 bytes at most.
{"dropped": true}RelayYour binary frame went nowhere: the other end isn't connected.
{"delete": true}YouUnpairs. The channel is removed and both ends closed with 4410.
{"ping": <value>}YouAnswered {"pong": <value>}.

Any other text frame is ignored.

Close codes

CodeReasonWhen
4400bad helloA malformed hello.
4401no tokenNo hello was accepted within 10 seconds.
4403refusedThe wrong token, or no room for a new channel.
4409replacedA newer connection took this role.
4410deleted, expired or unusedThe channel is gone: unpaired, a temporary one past its 10 minutes, or one nobody joined for 90 days.
1009too bigA binary frame over 1,048,640 bytes.
1001The server is stopping.
NoneThe socket is dropped with no close frame for a message over 1,114,176 bytes, a hello over 16,384, or a connection that holds too much (Message sizes and the memory budget).

What is kept

No frame is kept or queued. With the other end away a frame is dropped and its sender told. Of a channel the relay keeps its name, the hash of its token and the day it was last joined, and forgets it 90 days after that day when nobody is connected. A temporary channel is never written down. It lasts 10 minutes, or until both ends have left if that is sooner.

Limits

These are the values in the code. A server someone else runs may have changed the ones marked as settings.

LimitValue
Hub: sockets open at once20,000 (a setting)
Hub: time to sign in10 seconds
Hub: devices connected for one name8
Hub: one binary frame65,568 bytes
Hub: the sign-in frame16,384 bytes
Hub: any later message1,048,576 bytes, in 1,024 frames at most
Hub: keys remembered as signing in with v2200,000 (a setting); 30 new ones an hour from one place, 5,000 from everywhere
Hub: a late answer to an old sign-in2 minutes, 1,000 waiting at once
Hub: link helpers named4, of 200 characters each
Hub: held for one name200 frames, 1 MiB
Hub: held for everyone96 MiB (a setting), each frame counted with 256 bytes more
Hub: how long a packet is held7 days
Hub: names one connection watches500
Hub: last-seen times remembered200,000 names
Room: names in one64
Room: rooms at once50,000
Room: kept framesThe newest 300, for 7 days
Room: kept over all rooms256 MiB
Room: one reaction512 bytes
Room: looks for one connection200
Room: admins of a read-only room200
Room: a media relay's username and password24 hours (a setting)
Pushes: for one name1 a minute
Directory: whois120 an hour for one name, here or at another relay
Directory: badges240 an hour, 64 names and 64 usernames each
Directory: kept blob262,144 characters
Directory: the second kept blob (curl-keep)131,072 characters
Directory: gifts kept until shown50 for one install
Directory: handles watched5,000
Directory: profile reads (check, follows)40 an hour
Directory: a sign-in link10 minutes
Number: codes asked for3 an hour, 6 a day, for an install and for a number
Number: tries at a code10 an hour; a code lasts 10 minutes
Accounts: one sealed backup65,536 characters
Accounts: signed body196,608 characters (2,048 for acct-devices), its time within 10 minutes
Accounts: signed changes and acct-leave60 an hour
Accounts: acct-find30 an hour
Accounts: password tries6 an hour for a connection, 10 for an account
Accounts: wrong numbers5 an hour
Accounts: devices on one20
Accounts: on one server200,000, 256 MiB of backups
Invitations: in one message25
Invitations: sent40 an hour, 120 a day
Invitations: waiting for one number20, 3 from one sender, 30 days each
Invitations: one sealed invitation2,048 characters
Invitations: on one server20,000, 24 MiB
Invite words: held by one install10
Invite words: set20 an hour
Invite words: one sealed link1,024 characters
Invite words: on one server200,000; each let go after 365 days unset
Home records: one record1 to 3 addresses of 200 characters; good for 30 days
Home records: checked for one install600 an hour; 20 a second for everyone
Home records: kept20,000 of the relay's own people; 10,000 others in memory
Relays: links open at once64
Relays: other relays waited on at once256
Relays: taken from one linked relay1,200 packets a minute, 512 MiB a day, 600 names asked an hour (settings); 240 records a minute
Relays: sent across by one installA quarter of the packets a minute and an eighth of the bytes a day; 8 relays dialled for the first time an hour
Relays: waiting for one relay2,000 packets, 16 MiB, 7 days
Relays: waiting for all relays32 MiB, each packet counted with 384 bytes more
Relays: waiting from one sender, or for one recipient200 packets, 1 MiB
Relays: unanswered on one link64 packets, 64 names asked
Relays: hellos from relays not yet seen at their address30 a minute
Relays: dials30 first dials, 30 tries again and 10 looks at a claimed address a minute; 10 seconds each
Relays: a link with nothing crossing itClosed after 10 minutes
Relays: the key seen at an addressBelieved for an hour
Pairing: time to say the token10 seconds
Pairing: one binary frame1,048,640 bytes
Pairing: the hello16,384 bytes
Pairing: a temporary channel10 minutes
Pairing: an unused channel90 days
Pairing: channels at once200,000
All: server pingsEvery 30 seconds
All: held in memory by every connection together64 MB (a setting)
All: waiting to go out to one connection8 MB for 10 seconds (settings)
All: a message coming in that stalls20 seconds (a setting)

A text frame and a binary frame are held to the same length: the guard in front of each socket counts a message's bytes, whatever its kind.

Something wrong or missing here? Tell us in the Alpha testers circle, or at the app's GitHub.