Build, test and run it
Running the app and the relay from source, the tests, the scripts, and how the code is commented.
Everything is in one repository, github.com/InfamousVague/ghost-messaging, under the AGPL-3.0. A build from source isn't signed as the releases are, so it installs as a separate app beside the real one.
What you need
- Flutter (stable), which brings Dart. The relay uses the same Dart and nothing else.
- For Android: the Android SDK and a phone or emulator. For a Mac or iPhone build: Xcode.
- Node for the scripts in
tool/, the Discord bot and the browser extension; Go only to build the helper programs insidecar/. - Rust only for the direct route's core and the link helper.
native/p2p/rust-toolchain.tomlpins the version (1.94.1), andtool/build-p2p.shstops with any other. - For the browser build's end-to-end test: Playwright's Chromium and WebKit (
npx playwright install chromium webkit).
Run it
flutter pub get
flutter run # on the connected phone, or -d macos / windows / linux
flutter build apk --release --target-platform android-arm64
flutter build macos
A computer's build starts in lib/desktop/main.dart; with no phone paired it runs on its own, with an account and no texts. The app talks to the relay at gogho.st unless Settings › Routes is given another.
The helper programs for other networks are not built by flutter run. Build the one you want first (tool/build-signalsidecar.sh, tool/build-accountsidecar.sh messenger mac…): on a computer the app looks for it beside itself and then under build/<name>-sidecar/, where those scripts put it.
Build it for a browser
node tool/build-web.mjs # into build/web, to be served under /app/ by a relay
dart run relay/bin/relay.dart --web build/web # then open http://127.0.0.1:8787/app/
node tool/web/e2e.mjs # two people using it, in Chromium and then WebKit
tool/build-web.mjs is flutter build web -t lib/web/main.dart with what the page needs said for it: the engine served from the build's own folder, no code made from text at run time, no service worker, and main.dart.js named by its hash. Before it builds it runs test/web_build_test.dart (the page's policy, its files and its headers) and tool/web/check-argon2.mjs (the Argon2id worker against test/vectors/argon2id.json). Its options:
| Option | What it does |
|---|---|
--base /app/ | Where the page will be served from. |
--hub wss://…/hub | The hub it speaks to. With none it speaks to the hub beside the page: /hub where the page is /app/. |
--out <folder> | Somewhere other than build/web. |
--profile | Names kept in the JavaScript, for reading what went wrong. |
Letters the app's own fonts have no shape for (Chinese, Arabic, mathematics…) are drawn from Noto fonts served beside the page, never fetched from Google by a visitor's browser. node tool/web/fallback-fonts.mjs --fetch brings them to build/fallback-fonts once; without them such letters are boxes. web/argon2id.js is committed, and tool/web/build-argon2.mjs builds it again from the extension's pinned packages.
Run the relay
cd relay
dart pub get # the test package only
dart run bin/relay.dart --port 8787 --verbose # ws://127.0.0.1:8787/hub and /relay/<channel>
dart compile exe bin/relay.dart -o ghost-relay # one file to run on a server
It listens on this machine alone unless given --host, keeps everything under --data (relay-data), and serves the browser build under /app/ with --web <folder>. Every other choice is a variable in its environment, and none is required: relay/deploy/relay.env.example lists them all, grouped by what each switches on.
Put it behind a web server that holds the certificate and passes everything to it, WebSockets included: /hub, /relay/*, /files*, /market*, /link/*, /word/*, /feedback, and /app/* where it serves the app. relay/deploy has samples for Caddy and nginx, a systemd service, and a compose file that runs relay/Dockerfile with Caddy in front. Then point an app at it: Settings › Routes takes the hub's address.
| To switch on | Set |
|---|---|
| Passing packets to other relays | GHOST_FED=open or list, with GHOST_PUBLIC_HUB, the address other relays dial to check yours. Off by default. |
| Sign-ins bound to your relay's host | GHOST_HUB_NAMES |
| Calls through a TURN server | GHOST_TURN_SECRET and GHOST_TURN_URLS, for a coturn you run with the same secret (relay/deploy/turnserver.conf.example). |
| Link helpers for direct links | GHOST_LINK_HELPERS, for an iroh-relay you run (below). |
| The app in a browser | --web or GHOST_WEB_DIR |
docs/SELF_HOSTING.md in the repository is the full guide, and says what a relay of your own does and doesn't reach. Running your own has the short version.
The direct route's core and a link helper
sh tool/build-p2p.sh mac # build/p2p/mac/libghost_p2p.dylib; also: android, ios
(cd native/p2p && cargo test --release --locked)
sh tool/build-link.sh host # build/link/host/iroh-relay, for this machine
(cd native/link-check && cargo run) # starts that helper and links two nodes through it
native/p2p builds to one library with a small C interface (include/ghost_p2p.h), which lib/net/p2p/node_ffi.dart loads. Windows and Linux build theirs with a plain cargo build --release --locked on their release runners. Nothing is fetched but what Cargo.lock names.
A link helper is iroh's own relay server, built from source by tool/build-link.sh (server for Linux, host for this machine) at a pinned version and checksum. cargo run -- https://your.helper:port in native/link-check checks one that is running somewhere. relay/deploy/link-helper.toml.example and ghost-link.service are what a server needs.
Tests
| Run | What it covers |
|---|---|
flutter test | The app: about 270 files in test/, by feature. Screen tests draw each screen and compare it with the picture in test/shots; --update-goldens writes them again. Several start the real relay in the test's own process and send through it. The direct route runs against a stand-in mesh (test/support/fake_p2p.dart). |
flutter test test/platform_info_test.dart test/aside_test.dart test/source_guards_test.dart | The guard tests (tool/lib/guards.mjs): they read the source for what would break the browser build without a compile error, and the Android and Mac releases run them before they build anything. |
cd relay && dart test | The relay, part by part: the hub, relays that talk and their limits, the doors, the app's files and headers, and self_host_test.dart, which starts the program with an empty environment and checks the sample env file lists every variable it reads. |
cd android && ./gradlew :app:testDebugUnitTest | The Kotlin that needs no phone: the MMS format, the encryption, the link's sealing and session, bubbles, notifications held back, formatting taken out of a preview. |
cd native/p2p && cargo test --release --locked | The direct route's core: nodes in one process, linked over loopback and through a link helper inside the test. A workflow runs the same on Linux and Windows (messaging-p2p-core.yml). |
native/voicefx/test/run.sh | The microphone engine on this computer: noise down, gain, the limiter, odd block sizes. |
cd extension && npm test | The browser extension's sealing and its talk with the relay. |
cd discord && npm test | The Discord bot and its bridge. |
go test ./... in a sidecar/ folder | That helper program. |
node tool/web/e2e.mjs | The browser build end to end: a relay on this machine serving it, and Chromium and WebKit driving the page as two people. |
flutter test tool/net/live_hub_test.dart --dart-define=HUB=wss://…/hub | Two made-up installs through a running relay. tool/net has one of these for each of the relay's parts. |
flutter test integration_test/… -d macos | On a real device: the desktop link against a phone, the native recorder and transcripts, a recording played back, a call's video, and the direct route's real core (p2p_core_test.dart). |
Where two languages must agree to the byte (Kotlin and Dart on a seal, the app and the relay on a home record or a plugin's checks, Dart and JavaScript on Argon2id), both are tested against the same fixed values, kept in test/*_vectors.json and test/vectors.
Scripts
| Script | What it does |
|---|---|
tool/build-docs.mjs | Builds these docs from docs-src into site/docs, with the API reference and the Postman collection. --check fails where site/docs isn't what docs-src makes. |
tool/ghost-api.mjs | A command-line client for the app's API. |
tool/build-web.mjs, tool/web/*.mjs | The browser build, its end-to-end test, its fallback fonts and its Argon2id worker (above). |
tool/build-p2p.sh, build-link.sh | The direct route's core for a Mac, Android or an iPhone, and the link helper (above). |
tool/build-*sidecar.sh, build-tdlib.sh | Build the helper programs and Telegram's library for each platform. build-accountsidecar.sh <name> [mac|linux|windows|android] builds any of the account helpers. |
tool/release*.mjs | Build, check and publish a release for Android, Mac, Windows and Linux. The Android and Mac ones run the guard tests first (tool/lib/guards.mjs), and each ends by publishing the source (tool/publish-source.mjs). |
tool/deploy-relay.mjs, deploy-site.mjs, deploy-discord.mjs, deploy-turn.mjs, deploy-link.mjs | Put the relay, the site (and with --app the browser build), the Discord bot, a TURN server and a link helper on Uplink's own server. They are written for that server; for your own, follow docs/SELF_HOSTING.md. |
tool/phosphor.mjs, cosmetic_art.sh and the .py files | Make the icons, stickers, effects, sounds (the soundboard's among them) and profile decorations the app ships with. |
Keeping the API docs true
The API pages and the Postman collection are made, not written:
- The app's API comes from the app's own registry. After changing
lib/api/methods.dart, runUPDATE_API_DOCS=1 flutter test test/api_reference_test.dart, which writesdocs-src/api/app-methods.json. Without the variable the same test fails where the file is behind the code. - The relay's routes are listed in
docs-src/api/relay-routes.mjs. A route added torelay/libis added there. node tool/build-docs.mjsthen draws both references and writes the collection.
How the code is commented
The source is written to be read. The conventions, so a change fits in:
- A file opens by saying what it is for and where it sits: a doc comment on its main class, or on
library;. - Classes, and any method whose name and signature don't say enough, have a line or two on what they are for and what they promise. Comments say why, and what a caller can rely on; they don't repeat the code.
- Inside a function, a comment sits above a step whose reason isn't plain: a workaround, an order that matters, a detail of a protocol.
- Plain words. "Chooses a route for each thing sent" rather than "route selection manager".
- Where a file has a twin in another language (
DeskCrypto.ktandlib/desktop/link/crypto.dart), each names the other.
Developer docs