Skip to content
ciao22kingPublic

Repository files navigation

Android Windows 11/10 Linux

Apache License 2.0

Kotlin Rust

ShutChat!

A peer-to-peer messenger for Android and Linux. Messages and calls travel directly between devices: there is no server, no account, and nothing to sign up for.

Conversations are opened with a short invite code that the other person pastes or scans. The code carries its own expiry day, or can be set to never expire.

How it works

The whole access model is the invite code. It is 15 bytes rendered as 24 characters of Base32 (Crockford alphabet, so 1/l/I and 0/O cannot be confused when read off a screen):

Bytes Contents
0 version and chat kind
1..2 expiry day, big endian, 0xFFFF = never
3..4 CRC-16, so a mistyped character is caught
5..14 80-bit rendezvous secret

The expiry is stored as a day, not a timestamp, so every device in a room enforces the same UTC deadline no matter its timezone.

The room id is derived from the secret with HKDF and travels in the clear in every frame header. That is deliberate: it lets a device forward a frame it cannot decrypt, which is what makes relaying possible. The message key and the file-transfer key are separate derivations of the same secret, so a file chunk cannot be replayed as a message.

Transport is chosen at runtime:

  • LAN — UDP multicast to find peers on the same network, TCP for the data.
  • mDNS — a second discovery channel on the same Wi-Fi, through the system resolver. It keeps working on access points that filter multicast, and it is the replacement for Nearby Connections: no Play Services, so it also runs on a phone with no Google account.
  • Public relay — MQTT over TLS, for devices on different networks. On by default, because a messenger that only works on one network is not one; it can be switched off from settings. The broker relays sealed frames on a topic derived from the invite secret, so it sees neither the message nor who is talking; it cannot read a frame any more than a LAN peer could.

The relay uses QoS 1 with a persistent session keyed on the node id, so a frame published while the other phone is asleep is queued by the broker and delivered when it reconnects. It fails over between broker.hivemq.com, broker.emqx.io and test.mosquitto.org, and reconnects with a backoff that resets on success.

Calls ride the same mesh: the offer, the answer and the ICE candidates are ordinary envelopes, so they take whichever transport is available and never need a second rendezvous mechanism. Media itself is WebRTC peer to peer (opus audio, VP8 video); the signalling is the only part that ever touches a broker, and it is sealed like everything else.

Two devices behind mobile carriers have no reachable address, so something has to be reachable for long-distance chat to work at all. The relay is that something, and it is deliberately the only third party involved.

A foreground service keeps the mesh listening when the app is closed, because with no push server a message can only arrive if something is awake to receive it.

Modules

Module Contents
shared Protocol, crypto, invite codec, mesh engine, transports, call state machine. Plain Kotlin/JVM, no Android types.
app Android client: Compose UI, foreground service, mDNS proximity transport, WebRTC media.
desktop Linux client, Compose for Desktop: chats, group details, settings, calls, attachments, notifications, WebRTC media via webrtc-java. Retired once rust reaches parity.
rust Linux client, native: protocol crate core, Slint UI and SQLite store. LAN text messaging today, the rest of the port is tracked in docs/desktop-rust.md.

Android-specific pieces (multicast lock, NsdManager) sit behind small interfaces in shared, so the same mesh runs on a JVM without an emulator.

No Google

The Android build has no Play Services, no Firebase and no ML Kit, and does not need the Play Store: it installs and runs on an AOSP device, LineageOS or GrapheneOS. That is a property of the dependency graph rather than a promise, so it is checked in the build:

./gradlew :app:verifyNoPlayServices

Two things were given up to get there. QR scanning is zxing, a pure Java decoder that ships inside the APK instead of a model downloaded from Google. Proximity discovery is mDNS through the system resolver instead of Nearby Connections, so two devices find each other on the same Wi-Fi but not with Wi-Fi Direct and no network at all. Over Bluetooth the phone build is therefore no longer able to talk to a peer with no shared network; the relay covers that case, and LAN does too whenever both devices see the same access point.

Features

  • Direct and group chats, both created from a single code
  • Photos, audio and files, transferred in chunks with progress
  • Replies, edits, deletes, emoji reactions
  • Read receipts and typing indicators, sent as explicit envelopes
  • A retry queue: a message for an offline peer is re-sent until it is acknowledged
  • Online/offline presence per member
  • Message search, pin, mute, archive, drafts
  • QR code sharing for an invite
  • Automatic expiry and rotation of invite codes
  • Notifications with inline reply
  • Audio and video calls, with mute, speaker and a ring timeout
  • Light and dark theme with Material You dynamic colour
  • Settings with a check for updates against the release feed

The Android app and the Linux client speak the same protocol, so a code created on one opens the same room on the other.

Desktop client

The Linux client is a first-class member of the mesh, not a companion: it creates and joins rooms, relays for others, sends photos, files and voice notes, and takes calls.

Screen What it does
Home chat list with search, archive, presence and the relay/local-network status line
New / Join create a direct chat or a group with an expiry, or paste a code
Conversation text, attachments with progress, replies, reactions, edits, deletes, voice notes, typing, receipts
Group details QR code, the code as text, expiry, member list, rename, leave
Settings name, status, theme, receipts, retention, notifications, transports, forwarding, diagnostics, update check

State lives in plain JSON under ~/.config/shutchat and ~/.local/share/shutchat; attachments and voice notes go to the same place, so a backup is a copy of two directories.

Calls need a working sound device. On a machine without PulseAudio or ALSA the client falls back to a silent audio device, connects the call anyway and says so on screen, which keeps the app usable on headless boxes and in CI.

Native Linux client

rust/ is the client that will replace the Compose one: one binary, no JVM, no bundled runtime, Slint for the UI. It shares the wire protocol with Android, so a code created on the phone opens the same room here.

What it does today: creates and joins rooms with a 15-byte code, pairs two peers over the local network (UDP multicast for discovery, TCP for the links), stores chats in SQLite, sends and receives text with delivery receipts, and raises a desktop notification for messages that arrive while the window is elsewhere. Relay, attachments and calls are the next steps, in that order.

cd rust
cargo build -p shutchat          # debug binary in target/debug
cargo run -p shutchat            # launch it
cargo test                       # core and store tests

State lives in $XDG_DATA_HOME/shutchat (default ~/.local/share/shutchat) and $XDG_CONFIG_HOME/shutchat. Two instances on one machine are two directories:

XDG_DATA_HOME=/tmp/demo-a cargo run -p shutchat

Build

You need JDK 17 or newer and the Android SDK with platform 35 and build-tools 35.0.0. Point local.properties at your SDK:

sdk.dir=/path/to/android-sdk

Then:

./gradlew :app:assembleDebug     # debug APK
./gradlew :app:assembleRelease   # minified release APK
./gradlew :app:testDebugUnitTest :app:verifyNoPlayServices # tests and the no-Google guard
./gradlew :shared:test :desktop:test   # shared and desktop unit tests

Linux packages

./gradlew :desktop:packageDeb && desktop/package-deb.sh
desktop/package-appimage.sh
  • .deb → desktop/build/compose/binaries/main/deb/shutchat_<version>_amd64.deb. Installs to /opt/shutchat, with a menu entry and an icon. package-deb.sh adds the .desktop file and the icon, which jpackage does not emit here.
  • AppImage → desktop/build/compose/binaries/main/appimage/ShutChat-<version>-x86_64.AppImage. One file, no install, no root. package-appimage.sh downloads appimagetool on first use and runs it with --appimage-extract-and-run, so FUSE is not needed to build it.

Both wrap a jlink runtime, so the target machine does not need Java.

Linux packages, native client

cd rust && cargo build --release -p shutchat && cd ..
rust/packaging/package-deb.sh 0.1.0
rust/packaging/package-appimage.sh 0.1.0
  • .deb → rust/target/debian/shutchat_<version>_amd64.deb. Installs /usr/bin/shutchat plus the menu entry and the icon, with the dependencies taken from dpkg-shlibdeps.
  • AppImage → rust/target/appimage/ShutChat-<version>-x86_64.AppImage. One file, no install, no root. Graphics and display libraries stay on the host; the rest of the binary's libraries are bundled.

Windows package

rustup target add x86_64-pc-windows-gnu   # once
sudo apt install mingw-w64                # once, on Debian/Ubuntu
cd rust && cargo build --release -p shutchat --target x86_64-pc-windows-gnu && cd ..
rust/packaging/package-windows.sh 0.1.0
  • .zip → rust/target/windows/ShutChat-<version>-windows-x64.zip. Contains ShutChat.exe, the licence and a short readme. The executable links only against DLLs that ship with Windows, so there is nothing to install: unzip and double-click. Windows SmartScreen will warn that the publisher is unknown, because the binary is not code-signed.

Packages, all three platforms

Platform Artifact Where
Android app-release.apk, signed with the release key app/build/outputs/apk/release/
Linux shutchat_<version>_amd64.deb rust/target/debian/
Linux ShutChat-<version>-x86_64.AppImage rust/target/appimage/
Windows ShutChat-<version>-windows-x64.zip rust/target/windows/

Android and the desktop client speak the same protocol and share the same invite codes, so a code created on the phone opens the same room in the Windows or Linux client, and a message typed on the laptop arrives on the phone over the LAN or through the relay.

What the native client does today

The Windows and Linux binaries carry the same two long-distance paths as the phone: the LAN mesh for peers on the same network, and the public relay for a peer anywhere else. The relay is on by default and can be switched off in settings; the settings screen says which state it is in rather than guessing. Calls, attachments and voice notes are still Android and Compose-desktop only — docs/desktop-rust.md tracks what is left.

Two broker tests are kept out of the default run because they need the internet. They are the release check, since they are the only proof that a message crosses the relay:

cd rust
cargo test -p shutchat -- --ignored

If a network blocks multicast, SHUTCHAT_NO_LAN=1 shutchat puts the client on the relay alone.

Integration tests against a real broker

The relay is the one part that cannot be proven offline. Two opt-in suites start two real clients against the public broker:

./gradlew :desktop:test --tests '*RelayRoundTripIT*' -Dshutchat.it=1
./gradlew :desktop:test --tests '*DesktopRelayParityTest*' -Dshutchat.it=1

DesktopRelayParityTest covers the paths the two clients must agree on: a text message, a file of several chunks, a call that reaches the media path on both sides, and a chat that survives a restart.

The release build is signed with the project's release key, read from keys/keystore.properties (see keys/README-SIGNING.txt). Keep that keystore: Android only installs an update over an existing app when the signing certificate is the same one, so losing it means every installed copy must be uninstalled first.

SHA-256  9B:68:8B:FB:5E:86:88:E2:D8:C8:33:EC:CA:9D:FD:58:EE:6B:B9:7A:E0:59:54:84:1D:5A:5F:A3:30:E2:4D:21

Check a built APK with:

apksigner verify --print-certs app/build/outputs/apk/release/app-release.apk

Requirements

Android 8.0 (API 26) or newer. The app asks for camera, microphone and notification permissions. It does not ask for Bluetooth or location: discovery goes through mDNS and the multicast socket, neither of which needs them.

The desktop client needs a Linux x86-64 machine with glibc and an X11 or Wayland session. It ships its own Java runtime, so no JDK is needed. Calls use the default sound device and are audio only; a video call started from Android still connects and simply carries audio.

Licence

Apache 2.0. See LICENSE.

Releases

Packages

Contributors

Languages