Uplink Developer docs Get Uplink
The source

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.

  1. 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.

  2. Dart to Kotlin

    lib/sms.dart passes send to Sms.calls. On Android that is the overlay (lib/standalone/overlay.dart), which passes a phone number on to the channel ghost_messaging/sms, answered in MainActivity.kt.

  3. Sender chooses SMS or MMS

    Sender.send in Messaging.kt. One person and no attachment is an SMS, sealed first by E2e.kt where encryption is on with them. Several people, or a picture, is an MMS, which Pdu.kt encodes.

  4. Android's database, then the radio

    Store.kt writes the message to Android's own database, and Android's SmsManager sends it. Reports of sent and delivered come back to SmsStatusReceiver.

  5. The screen hears

    Bus.changed sends an event up ghost_messaging/events; Sms.instance.changes fires 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

  1. 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.

  2. Into an envelope

    An Envelope of kind text goes to Net.send (lib/net/net.dart), and on to Switchboard.send.

  3. 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).

  4. 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.

  5. 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 to Federation.pass (relay/lib/federation.dart), and that relay hands it on or keeps it as its own.

  6. 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. Friends sends again what stays unanswered.

  7. 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. Friends stores 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.

  1. The candidates

    Switchboard.routes takes 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.reaches is true only where Direct is on and an unexpired device card is held for one of their devices.

  2. 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.

  3. 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.

  4. 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.meet also 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.

  5. 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.

  6. 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

  1. The name is split

    Buddies.add (lib/friends/buddies.dart) takes maya@relay.example apart. A name with no relay, or with this app's own, is asked of its own relay's directory as ever.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. Records kept in step

    The two friends send each other their own home records in sealed home envelopes, and again whenever one moves. A friend's app follows the record with the highest count.

Joining a call in a space

  1. 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.

  2. The microphone

    RtcMedia (lib/voice/rtc.dart) opens it, with noise removal from native/voicefx in the capture path. On Android a foreground service (CallService.kt) keeps the call alive with the screen off.

  3. 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 as HubCarrier.callRelay).

  4. 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.

  5. 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.

  6. 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.

  7. Kept connected

    VoiceSession looks 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.

  1. The kind

    A space's kind travels as k wherever the space goes (its JSON, its link, the circle's manifest); an open space's is open (SpaceKind.open, lib/voice/voice.dart). SpaceKind.of reads a kind it doesn't know as voice, 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.

  2. The floor appears

    Voice.join (lib/voice/channels.dart) calls OpenSpaces.follow before the relay has answered, so the floor (an OpenSpace over the session) is there from the first frame. Every surface that draws a call asks OpenSpaces.isCall(session), which looks only at the space's kind, and draws OpenSpaceFloor in place of the call's people: the phone's page and the computer's pane in lib/ui/hangout_screen.dart, the stage beside the list, and inlineSpaceCall in lib/ui/space_designs, which draws no call page for it. Should a frame come before the floor is made, OpenSpaceFloor says the call is coming in rather than draw anything like another kind of call.

  3. Where each person stands

    A place is an os message, {t: 'os', x, y, d, w}: where on the 2400 by 1600 floor, which way they face in degrees, and w: 1 while walking. VoiceSession.sayPlace seals 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. VoiceSession hands os and osg to onPlace; 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 at OpenWorld.middle. Each device draws the others eased towards where they last said.

  4. Distance into loudness

    Whenever anyone moves, OpenSpace._settle works out who stands in which group and how loud everyone is played, and hands each member's gain to PlacedMedia.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 is OpenWorld.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.

  5. 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 an osg message 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).

  6. The chat's bubbles

    FloorBubbles follows 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 with HangoutRoom.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

  1. The page starts

    lib/web/main.dart hands over to lib/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).

  2. The same calls as a computer of its own

    StandaloneCalls.on(WebStandaloneStore(…)) becomes Sms.calls. The hub's address is the one the build names, or /hub beside the page (hubFor).

  3. 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, through lib/account/argon2_browser.dart), and fetches the sealed backup with the proof, as any new device does.

  4. 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.

  5. 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.

  6. 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.dart answers 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.

  1. The new device shows a code

    HandoverNewDevice.start makes 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).

  2. The phone scans it

    HandoverPhone.start makes 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.

  3. 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.

  4. 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.

  5. The words go once

    HandoverPhone.approve seals the words with a key made from the shared one. The new device takes one answer, leaves the room, and signs in with Account.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.

  1. The helper starts

    AccountHelper (lib/inbox/account_helper.dart) starts that network's helper program with a folder of its own and reads its ready event from its output.

  2. 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; tokenIn reads Discord's or Slack's token. Or synced: the extension sealed them and kept them on the relay, and CurlSync (lib/inbox/curl_sync.dart) opens them on this device.

  3. 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.

  4. Chats and messages

    The helper sends chat and message events as lines; AccountHelper turns them into InboxChat and InboxMessage, and they join the list. sidecar/ACCOUNT_HELPERS.md lists every request and event.

Pairing a computer

  1. 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.

  2. 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 in lib/desktop/link/crypto.dart).

  3. 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).

  4. 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.

  5. After that

    The computer's screens call Sms.instance as a phone's do. LinkCalls (lib/desktop/remote.dart) turns each call into a sealed request, DeskCalls in DeskSession.kt runs it on the phone, and the answer is kept sealed on the computer for next time.

Adding a Marketplace plugin

  1. The catalog

    MarketState (lib/market/market_state.dart) reads the relay's catalog and its list of withdrawals.

  2. 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.

  3. What it may do, then Add

    addListing (lib/ui/market/market_flows.dart) shows what the plugin reads and adds, from the same file.

  4. Installed

    InstalledPlugins.installReviewed (lib/plugins/pack/installed.dart) checks it once more, keeps the file, and adds it to the registry as a PackPlugin. The list sorts itself again with the plugin's tags and tabs.

  5. At every start

    The approval is checked again and withdrawals applied, so a plugin withdrawn after it was added stops.

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