How the parts work together
Things followed from the tap to the wire: a text, a message to a friend, a call, an open space's floor, pairing a computer, adding a plugin, and more.
The quickest way into the source is to follow one thing through it. Here are several, each from the tap to the wire, naming the file at every step. How the app is built says what each part is.
Sending a text
On an Android phone where Uplink is the texting app.
The box decides
lib/ui/thread.dart: words alone to one friend go by the routes (the next section). Anything else is a text:Sms.instance.send.Dart to Kotlin
lib/sms.dartpassessendtoSms.calls. On Android that is the overlay (lib/standalone/overlay.dart), which passes a phone number on to the channelghost_messaging/sms, answered inMainActivity.kt.Sender chooses SMS or MMS
Sender.sendinMessaging.kt. One person and no attachment is an SMS, sealed first byE2e.ktwhere encryption is on with them. Several people, or a picture, is an MMS, whichPdu.ktencodes.Android's database, then the radio
Store.ktwrites the message to Android's own database, and Android'sSmsManagersends it. Reports of sent and delivered come back toSmsStatusReceiver.The screen hears
Bus.changedsends an event upghost_messaging/events;Sms.instance.changesfires and the thread and list read again.
A text arriving runs the other way: SmsDeliverReceiver in Messaging.kt writes it, Notifier.kt shows it (unless the list hides that kind of text: NotifyHush.kt), paired computers are told, and the screen hears the same event.
A message to a friend
Kept first
Friends.sendText(lib/friends/friends.dart) stores the message where the person's texts are, so it is in the conversation whether or not it has gone.Into an envelope
An
Envelopeof kindtextgoes toNet.send(lib/net/net.dart), and on toSwitchboard.send.Sealed
The switchboard (
lib/net/switchboard.dart) adds this device's prekey to the envelope. Where the friend's devices have offered prekeys of their own it seals the envelope for forward secrecy:ForwardSecrecy.sealAway(lib/net/forward_secrecy.dart) makes a key pair for this packet alone and wraps the envelope's key for each of their devices. Otherwise it seals with the key the two installs share. Either way the result is wrapped as a packet (lib/net/packet.dart).Routed
The routes are tried in order. A message isn't allowed to cost money, so the SMS route is passed over and the hub comes first. The next section says how the choice is made.
Through the hub
HubCarrier.send(lib/net/hub_carrier.dart) hands it to the relay's hub (relay/lib/hub.dart), which passes it to the friend's connected devices, or keeps it and says so. Where nobody of that name is on this relay and the friend's home record names another, the hub gives it toFederation.pass(relay/lib/federation.dart), and that relay hands it on or keeps it as its own.Answered, or waited for
Passed on, the sender waits a few seconds for the other app's answer and marks the message delivered. Kept, it is marked sent, and the friend's closed app is woken: an Android phone by an empty data text (at most one every ten minutes), an iPhone by a push from
relay/lib/pushes.dart.Friendssends again what stays unanswered.On the other side
The packet arrives at
Switchboard, which joins its parts, opens it (a forward-secret one with the prekey it names), drops it if it has been seen before, and answers. A device that can't open it, because it was sealed for another device of the account, passes it on unopened to the account's own name.Friendsstores it, and the conversation changes.
The hub or a direct link
How Switchboard.send chooses between the relay and the direct route, where a build has the direct route's core.
The candidates
Switchboard.routestakes the routes in the person's order (the hub, then Direct, then SMS, where they chose none) and leaves out any that is switched off, not up, doesn't reach this person, can't hold the packet, or costs money for something not worth it.P2pCarrier.reachesis true only where Direct is on and an unexpired device card is held for one of their devices.The hub first
The hub takes the packet and says one of two things: passed on, or kept. Passed on, the answer from the other app is waited for, and that is the end of it.
Kept: only by a link already open
Kept means they are away from the relay. The direct route is then given the packet only where a stream to one of their devices is open right now (
LiveLinks.linked), by that stream and without waiting. Nothing is dialled and no node is started for someone who is away. The same holds where the hub passed the packet on and no answer came in time.The hub can't take it: dial
Where the hub is down or refuses the packet, the switchboard goes on to Direct.
P2pCarrier.send(lib/net/p2p/p2p_carrier.dart) starts the node if it is a phone's, and sends to every device a card is held for: on an open stream, else dialled by where that device last said it was, five seconds for all of it. Where another route can still carry an envelope,P2p.meetalso asks the device to bring its node up and say where it is now. Passed if one device took it; otherwise it throws and the switchboard tries the next route.Whose stream it is
A stream opens with each end's nonce, then each end's proof: an HMAC under a key only the two accounts' devices hold, over both accounts, both node ids and both nonces. Until the proof has come nothing is sent or taken. What arrives after is taken as from the account whose card names that node, as the hub's stamp is.
Written down
The switchboard tells the ledger (
lib/net/ledger.dart) which route took the packet and what the route said. The next time a direct stream to that friend opens, the two ledgers compare, and anything the relay said it passed that never came is sent again straight.
Adding a friend on another relay
The name is split
Buddies.add(lib/friends/buddies.dart) takesmaya@relay.exampleapart. A name with no relay, or with this app's own, is asked of its own relay's directory as ever.Asked through its own relay
Homes.whois(lib/net/homes.dart) asks the app's relay, which asks the other over a link between the two (relay/lib/federation.dart). The answer is their name, key and home record.Or asked directly
Where the app's relay links with nobody, or couldn't reach that one,
whoisAt(lib/net/relay_ask.dart) dials the other relay's hub itself, signed in under a key made for this one question and thrown away. Nothing of the account goes there.The record is checked
HomeRecord.check(lib/net/home_record.dart) holds the record to the key it came with: the name is the key's, the signature is the key's. With no record, or a relay that passes nothing on, the app says they can't be reached and sends nothing.The request goes
The friend request is an ordinary sealed envelope to their name. The app's hub finds nobody of that name connected, sees their record names another relay, and passes the packet there. The other relay takes it because the sender's own record names the relay it came from.
Records kept in step
The two friends send each other their own home records in sealed
homeenvelopes, and again whenever one moves. A friend's app follows the record with the highest count.
Joining a call in a space
Allowed?
Voice.join(lib/voice/channels.dart) checks the hub is reachable and the circle's roles allow voice, and leaves any call already on.The microphone
RtcMedia(lib/voice/rtc.dart) opens it, with noise removal fromnative/voicefxin the capture path. On Android a foreground service (CallService.kt) keeps the call alive with the screen off.Into the room
VoiceSession.join(lib/voice/voice.dart) joins the space's room on the hub with the name and token made from the space's seed. The hub answers with who is there, and, where the relay has a TURN server, a username and password for it that stop working after a while (relay/lib/turn.dart; kept asHubCarrier.callRelay).An offer to each
The newcomer makes a WebRTC connection to each member and says an offer in the room, sealed with the space's key. Each answers, and both sides exchange candidates the same way.
A path is found
Each connection is given the public STUN servers and the TURN server (
RtcMedia.iceServers). Where a TURN server was handed out the connection starts through it alone, which connects whatever routers are between the two; if that fails, the side that offered starts over trying every path at once (FallbackMedia,VoiceSession._failed). With none handed out, it is direct paths only.Sound, between the members
From there the call's sound and picture go between the members' devices, or through the TURN server, which passes packets it can't open. The hub carried the setup and carries none of the call.
Kept connected
VoiceSessionlooks at every member every two seconds. Where a connection is missing, failed, or has been finding its way too long, one of the two offers a new one: the lower id first, the other if it never does, further apart each time. Two offers that cross are settled by id. When a device's own connection to the hub drops and comes back, the carrier joins the room again and the session offers to everyone anew, since they were told it went. Nobody has to leave and come back.
Ringing one friend is the same call with no space made: FriendCalls.call (lib/voice/friend_calls.dart) makes the call's seed from the two friends' names, joins it, and sends a sealed voice envelope by the routes. Every device of the friend's rings (on Android through IncomingCall.kt); the one that answers tells the account's other devices to stop.
An open space's floor
An open space is an ordinary call (VoiceSession, joined as above) with a floor on top. The floor is the app's alone: the relay passes its messages as it passes the call's offers, sealed, and knows nothing of places or groups. The model is lib/voice/open_space.dart (OpenWorld, OpenSpace, OpenSpaces), the drawing lib/ui/open_space_view.dart, the chat's bubbles lib/ui/open_space_chat.dart.
The kind
A space's kind travels as
kwherever the space goes (its JSON, its link, the circle's manifest); an open space's isopen(SpaceKind.open,lib/voice/voice.dart).SpaceKind.ofreads a kind it doesn't know asvoice, so a build from before open spaces sees one on its own as a plain call where everyone is heard whole, and in a circle as a chat.The floor appears
Voice.join(lib/voice/channels.dart) callsOpenSpaces.followbefore the relay has answered, so the floor (anOpenSpaceover the session) is there from the first frame. Every surface that draws a call asksOpenSpaces.isCall(session), which looks only at the space's kind, and drawsOpenSpaceFloorin place of the call's people: the phone's page and the computer's pane inlib/ui/hangout_screen.dart, the stage beside the list, andinlineSpaceCallinlib/ui/space_designs, which draws no call page for it. Should a frame come before the floor is made,OpenSpaceFloorsays the call is coming in rather than draw anything like another kind of call.Where each person stands
A place is an
osmessage,{t: 'os', x, y, d, w}: where on the 2400 by 1600 floor, which way they face in degrees, andw: 1while walking.VoiceSession.sayPlaceseals it with the space's key and says it in the call's room on the hub, as the call's offers go. It is said on coming in, whenever someone new joins the call, at most every 100 ms while walking, once on stopping, and every 3 seconds while standing still (OpenSpace.beatEvery), for whoever missed it.VoiceSessionhandsosandosgtoonPlace; an older build's switch has no case for them and drops them. Someone who never says a place (an older build, a browser guest, the Discord bridge) stands atOpenWorld.middle. Each device draws the others eased towards where they last said.Distance into loudness
Whenever anyone moves,
OpenSpace._settleworks out who stands in which group and how loud everyone is played, and hands each member's gain toPlacedMedia.setPlaceGain.RtcMedia(lib/voice/rtc.dart) multiplies it into that person's playback with their own volume, the output volume and the auto leveler, so nothing about the call's connections changes and walking back brings them back. The curve isOpenWorld.gain: whole within 170 units (near; a face is about 56), nothing past 760 (far, the ring the view draws round this device), and between them the square of how far through the gap they are, so it falls quickly at first. Two people in the same group are whole to each other wherever they stand in it; where only one of them is in a group, or they are in two, it is times 0.3 (throughEdge). Changes under a hundredth aren't set, except to silence or to whole, and on leaving the call every gain goes back to 1.Groups, shared by everyone
A group (
SpaceGroup) is an id, a name of up to 32 letters, a middle, one of eight hues and the moment it was last changed. Anyone in the call may make, rename, move or remove one: the change is said as anosgmessage carrying the group, and every device takes the newest word about each id. A device stamps its own change no earlier than one after what it changes, whatever its clock says; at the same moment a removal wins, then the greater name, so every device ends the same. A space holds 24. A removed group is kept as removed for 14 days, so a device that was away doesn't bring it back. Each device keeps what it knows in its own settings (open_<room>_groups) and says all of it on coming in and to every newcomer, so the groups are there for whoever comes back to an empty room. Who is in a group is never said: each device works it out from the places (OpenWorld.radiusFor: 130 units, plus 38 times the square root of how many are in it, up to 420; in two circles at once, the nearer middle).The chat's bubbles
FloorBubblesfollows the space's own chat (HangoutRoom) and sends and keeps nothing. Each message written after the floor opened comes up over the group its writer stands in, as this device sees it, or at the side. A stack keeps the newest four (most); a bubble stays 10 seconds (life), fading over the last 1.8, and is drawn as strongly as its writer is heard (for a group's, as its edge is), never below 0.08. The box at the floor's foot writes to the same chat withHangoutRoom.sendWith.
The figure is built for what comes next: the view draws each person through one builder handed an OpenFigure (their size, how loud they are, which way they face, whether they walk, how much of them is heard), so a character in place of the picture is a new builder, and its cosmetics one more field beside those of os.
Signing in from a browser
The page starts
lib/web/main.darthands over tolib/web/app.dart, which makes sure it is the only tab of itself, by the browser's own lock, and opens the page's store (lib/web/browser.dart,browser_web.dart).The same calls as a computer of its own
StandaloneCalls.on(WebStandaloneStore(…))becomesSms.calls. The hub's address is the one the build names, or/hubbeside the page (hubFor).Username and password
Account.signInWithPassword(lib/account/account.dart) asks the relay for the account's salt and settings, stretches the password with Argon2id on a worker (web/argon2id.js, throughlib/account/argon2_browser.dart), and fetches the sealed backup with the proof, as any new device does.Kept, sealed
WebStandaloneStore(lib/web/store.dart) writes the identity, the conversations and every secret to IndexedDB, each record sealed under a key the browser made as not extractable. The recovery words and the password's key are not kept.The network starts
startPeople(lib/people.dart) starts the routes, friends, groups, spaces and circles. The hub's connection is the browser's own WebSocket (lib/net/hub_link_web.dart); there is no direct route and no SMS route.Signing out
The whole database is deleted, its key with it, and the page asks its server for
Clear-Site-Data(relay/lib/web_app.dartanswers it at/app/clear-site-data). A browser removed from the account on another device does the same when it next hears of it.
Signing in a new device by a scanned code
A phone already signed in hands the account's recovery words to a new device (lib/account/handover.dart; the screens are lib/ui/handover_screens.dart). The relay needs nothing new: the two meet in an ordinary room.
The new device shows a code
HandoverNewDevice.startmakes a P-256 key pair and a 32-byte secret for this one sign-in. The QR holds the public key, the secret and the hub's address (HandoverCode), nothing of any account. It joins a room whose name and token are made from the secret (HubHandoverRoom,lib/account/handover_hub.dart).The phone scans it
HandoverPhone.startmakes a key pair of its own, joins the same room and says its public key, sealed with a key made from the secret. A new device on another relay is refused here: the account would not be found there.Both hold one key
ECDH of the two keys through HKDF, salted with the secret and bound to both public keys (
HandoverKeys.make). The six digits are made from it. The new device answers with proof of the key, and only then can the phone approve.The phone's lock
On yes, the screen asks the app's lock (
lib/app_lock/app_lock.dart) or the phone's fingerprint or face, and where there is neither, the account's password.The words go once
HandoverPhone.approveseals the words with a key made from the shared one. The new device takes one answer, leaves the room, and signs in withAccount.signInWithWords. Each side gives up two minutes after it began. Room packets are passed on and never kept by the relay.
Signing in to a network with browser cookies
Messenger, Instagram, Discord, X and Slack.
The helper starts
AccountHelper(lib/inbox/account_helper.dart) starts that network's helper program with a folder of its own and reads itsreadyevent from its output.The cookies arrive
Pasted: the person copies a request from the browser's developer tools, and
cookiesIn(lib/inbox/cookie_paste.dart) keeps only the cookies that service needs;tokenInreads Discord's or Slack's token. Or synced: the extension sealed them and kept them on the relay, andCurlSync(lib/inbox/curl_sync.dart) opens them on this device.sign_in
The app writes one line of JSON,
{"id": …, "op": "sign_in", "cookies": {…}}, to the helper's input. The helper connects to the service as the website would and answers with who it is signed in as.Chats and messages
The helper sends
chatandmessageevents as lines;AccountHelperturns them intoInboxChatandInboxMessage, and they join the list.sidecar/ACCOUNT_HELPERS.mdlists every request and event.
Pairing a computer
The computer makes an offer
PhoneLink.beginPairing(lib/desktop/link/link.dart) makes a key pair and 16 random bytes and draws them as a QR code.The phone scans it
Desk.begin(Desk.kt) makes its own key pair. Both ends now work out the same pairing key from the two key pairs and the code's random bytes (DeskCrypto, in Kotlin and inlib/desktop/link/crypto.dart).They connect
Over the local network where the phone can be found there, otherwise through a ten-minute channel on the relay. Each connection starts with hellos in the clear, then keys of its own, then everything sealed (
LinkSession,DeskSession.kt).Six digits
Both show six digits made from the pairing key. They match only if nobody is in the middle; the person confirms on both.
After that
The computer's screens call
Sms.instanceas a phone's do.LinkCalls(lib/desktop/remote.dart) turns each call into a sealed request,DeskCallsinDeskSession.ktruns it on the phone, and the answer is kept sealed on the computer for next time.
Adding a Marketplace plugin
The catalog
MarketState(lib/market/market_state.dart) reads the relay's catalog and its list of withdrawals.Checked before it is shown
For each entry the app checks the reviewer's signature against the keys it ships with (
lib/plugins/pack/review_keys.dart), fetches the plugin's file, checks its SHA-256, and reads it (lib/plugins/pack/manifest.dart). The card is drawn from the checked file, never from what the catalog says of it.What it may do, then Add
addListing(lib/ui/market/market_flows.dart) shows what the plugin reads and adds, from the same file.Installed
InstalledPlugins.installReviewed(lib/plugins/pack/installed.dart) checks it once more, keeps the file, and adds it to the registry as aPackPlugin. The list sorts itself again with the plugin's tags and tabs.At every start
The approval is checked again and withdrawals applied, so a plugin withdrawn after it was added stops.
Developer docs