Files
bitchat/docs/TOR-INTEGRATION.md
T
jackandjack 6f1deedb79 bitchat 2.0.0: Everyday Utility, Unified Liquid Glass Navigation & Polish (#1925)
* Add Phase 1 everyday utility: inbox tabs, encrypted history, friend invites, hybrid groups, and Privacy Mode

* Unify app chrome, sheets, DM navigation, and theme tokens across tabs

* Use slim 4-tab bottom bar with Settings tab and fix remote place titles

* Simplify all bars, sheets, and composers into one edge-to-edge chrome language

* Remove tap-to-info action from Nearby header title

* Keep floating glass bottom nav visible while typing and dismiss keyboard interactively

* Split Mesh Notices (Nearby) and Place Notes (Places) and fix first-mount top inset

* Use clean neutral Liquid Glass canvas and remove duplicate DM sheet backdrops

* Replace bottom nav with top-left dropdown, restore borderless floating glass, and move Location Notes to top of Places

* Bump version to 2.0.0, persist last tab, unify icons, and redesign notices sheets

* Unify 3D globe picker HUD onto floating Liquid Glass top bar and bottom dock

* Add swipe-right to pin and swipe-left to delete chats in inbox

* Place geo channel people count pill to the right of pin icon

* Clean up Nearby timeline: remove geo notes hint, gray echo band, and tighten top spacing

* Use normal title and sentence case across Settings and Info copy

* Move AppSupportFileStore disk writes and removals off the main thread

* Polish 2.0.0: async launch reads, onboarding, inbox search, delivery clarity, media/notifications, and copy casing

* Fix Release crash on launch: keep SwiftUI field metadata (without-names)

* Add in-chat search & jump, quoted replies, emoji reactions, and unified Contact Detail sheet (2.0.0 build 2)

* Add walkie-talkie deck and push-to-talk ergonomics

* Add Phase 3 walkie-talkie: mesh groups, auto-listen rules, and PushToTalk bridge

* Preserve 1.x Tor and RAM-only posture on upgrade, restore triple-tap wipe, and align privacy docs

* Fix compiler warnings in SystemPTTChannelManager and AppSupportFileStore

* Align peer colors across GeoDM avatars, quoted replies, and Light Mode self orange

* Indicate unread Nearby mesh messages in section switcher and Chats banner

* Remove pulsing MeshRadarView from empty Nearby chat

* Clip opaque photo blur inside card and refine dark mode reveal scrim

* Address PR #1925 review findings across invites, groups, history, and privacy mode

* Remove daily device sightings line from empty Nearby chat

* Fix SwiftLint unused_setter_value and Periphery dead-code warnings

* Remove remaining unused import and environment object for Periphery

* Replace stale mesh empty-state text with status-aware 1-liner

---------

Co-authored-by: jack <jackjackbits@users.noreply.github.com>
2026-11-27 21:39:16 -10:00

5.8 KiB

Tor integration

Overview

When Tor routing is enabled — in Stealth Mode, via the Settings toggle, or preserved automatically on upgrades from 1.x — all internet traffic (Nostr relay sockets and the geo-relay directory fetch) is routed through Tor, fail-closed: when Tor is wanted but not ready, requests queue rather than falling back to clearnet.

On fresh 2.0 installs, Everyday Mode starts with Tor off so Nostr relays connect directly without Tor bootstrap latency (users can pick Stealth Mode during first-run onboarding before any relay connection opens, or switch anytime in Settings). Existing 1.x installs migrating to 2.0 preserve their prior Tor behavior — keeping Tor explicitly on for users who relied on 1.x's Tor-on default — until the user chooses a mode.

Tor is provided by Arti, in-process, vendored as a Swift package under localPackages/Arti wrapping a Rust static-library xcframework. There is no tor binary, no torrc, and no control port. A SOCKS5 listener on 127.0.0.1:39050 is the only interface.

Key pieces

  • TorManager — owns the Arti client and its data directory under Application Support, exposes the SOCKS port, and provides awaitReady().
    • torEnforced is compile-time: true unless BITCHAT_DEV_ALLOW_CLEARNET is defined. It is not set anywhere in Configs/ or the project file, so release builds enforce.
    • isStarting, bootstrapProgress, and bootstrapSummary describe an attempt in flight.
    • bootstrapDidStall becomes true when an attempt spends its whole 75-second deadline without completing, and posts .TorBootstrapDidStall. This is the state a network that blocks Tor produces, and it is deliberately distinct from isStarting: without it the UI says "starting tor…" indefinitely. It is cleared on each new start or restart.
  • TorURLSession — a shared URLSession with the SOCKS proxy configured when proxying is on, and an unproxied session when it is off. setProxyMode(useTor:) is the switch, driven by NetworkActivationService.
  • NetworkActivationService — decides whether Tor may run at all. Tor starts when the activation policy permits it and the Tor preference is on. persistedTorPreference(in:) is a nonisolated read of that preference for callers off the main actor.

Both network call sites go through TorURLSession: NostrRelayManager (relay websockets) and GeoRelayDirectory (directory CSV refresh). There is no other outbound network in the app or the share extension.

The Tor preference is user-visible

There is a Tor Routing toggle in Settings, persisted under networkActivationService.userTorEnabled, coordinated with Privacy Mode (Everyday vs Stealth):

  • Fresh 2.0 installs default to Everyday Mode (userTorEnabled unset → direct relays, with no outbound network calls before the user grants location permission, adds a mutual friend, or opens a location channel).
  • Stealth Mode enables Tor (userTorEnabled = true, fail-closed).
  • Upgrades from 1.x run PrivacyModeSettings.migrateLegacyInstallIfNeeded() before startup networking, pinning userTorEnabled = true and .stealth mode for installs that relied on 1.x's Tor-on default (or preserving false if the user had explicitly turned Tor off).

Turning it off is a real change in exposure, not a performance tweak. Every fail-closed guard is conditioned on the preference, so with it off:

  • relay websockets connect directly, and every relay operator sees the device IP — including relays carrying private messages;
  • the geo-relay directory fetch also goes direct.

The settings UI states this while the toggle is off.

GeoRelayDirectory keys its Tor wait on the preference, not on live readiness, and this distinction is load-bearing. With Tor off, waiting for a client that has been shut down would spend the full bootstrap timeout on every refresh and freeze the directory on its cached copy. With Tor on but not ready, the wait must still fail so the fetch is skipped rather than silently leaking the IP.

Relays

Private messages target the built-in relay set plus any relays added by hand (NostrRelaySettings, capped at 8). The built-in set is four well-known clearnet hostnames, so adding custom wss:// relays lets users work around filters blocking those hosts. .onion onion-service relays are not yet supported because arti-client is built without the onion-service-client feature.

Artifact maintenance

  • Binary provenance, rebuild steps, and current hashes: docs/ARTI-BINARY-PROVENANCE.md, enforced by .github/workflows/arti-provenance.yml.
  • The xcframework must include iOS device, iOS simulator, and macOS arm64 slices.
  • Any refresh reviews the Rust source, Cargo.lock, generated header, build script, and new hashes together. A binary-only update is not acceptable.

Known gap: no bridges or pluggable transports

arti-client is built with default-features = false and features ["tokio", "rustls"] only — no pt-client, no bridge-client — and arti-bitchat/src/lib.rs bootstraps from stock configuration with no bridge lines and no configurable directory authorities.

So in a country that blocks Tor by blocking the public relays and directory authorities, bootstrap never completes. The app reports that clearly now instead of appearing to start forever, and the BLE mesh is unaffected, but there is no circumvention path: obfs4, snowflake, and meek are all unavailable.

Closing this means enabling the pluggable-transport features, plumbing bridge configuration through the FFI and a settings surface, and rebuilding the xcframework under the pinned toolchain with a provenance-manifest update. That is the single largest remaining gap in censorship resilience for the internet transport.

Dev bypass (local only)

Define the Swift compiler flag BITCHAT_DEV_ALLOW_CLEARNET to allow direct network access without Tor while developing. Never enable it in release builds.