This page documents TransportConfig, a centralized configuration enum that serves as the single source of truth for all transport, protocol, UI, and service tuning parameters in BitChat. By consolidating over 150 constants into a single namespace, the codebase eliminates "magic numbers" and provides a unified interface for system-wide performance tuning. bitchat/Services/TransportConfig.swift3-5
TransportConfig is implemented as an enum with no cases, making it a pure namespace of static constants that cannot be instantiated. These values are resolved at compile time, ensuring zero runtime overhead for configuration access. bitchat/Services/TransportConfig.swift5
The following diagram illustrates how TransportConfig serves as the configuration backbone for all major BitChat subsystems.
Sources: bitchat/Services/TransportConfig.swift1-135 bitchat/Services/BLE/BLEService.swift27-35 bitchat/Services/NetworkActivationService.swift53-73
The Bluetooth Low Energy (BLE) stack is the most sensitive to timing and buffer constraints. TransportConfig defines the parameters that balance mesh flooding reliability against battery and bandwidth.
bleDefaultFragmentSize (469 bytes): Optimized for a ~512 MTU after accounting for protocol headers. bitchat/Services/TransportConfig.swift7 This value is used by BLEService as the default per-fragment chunk size when link limits are unknown. bitchat/Services/BLE/BLEService.swift27messageTTLDefault (7): The default "Time-To-Live" for mesh packets. bitchat/Services/TransportConfig.swift8 BLEService uses this for its messageTTL. bitchat/Services/BLE/BLEService.swift30bleFragmentRelayTtlCap (7): Fragment relay TTL in sparse graphs; matches messageTTLDefault so media reaches as far as text. bitchat/Services/TransportConfig.swift14-16bleFragmentRelayTtlCapDense (5): Contain fragment floods in dense graphs. bitchat/Services/TransportConfig.swift17bleMaxInFlightAssemblies (128): Caps concurrent fragment reassembly tasks to manage memory. bitchat/Services/TransportConfig.swift9 BLEService uses this to cap concurrent fragment assemblies. bitchat/Services/BLE/BLEService.swift32bleHighDegreeThreshold (6): Used for adaptive TTL/probabilistic relays. bitchat/Services/TransportConfig.swift10 BLEService uses this for its highDegreeThreshold. bitchat/Services/BLE/BLEService.swift33To prevent BLE buffer overflows which lead to packet loss, BitChat implements strict limits and jitter bounds:
bleMaxConcurrentTransfers (2): Limits simultaneous large media sends to prevent link saturation. bitchat/Services/TransportConfig.swift11bleFragmentRelayMinDelayMs (8ms): Faster forwarding for media fragments. bitchat/Services/TransportConfig.swift12bleFragmentRelayMaxDelayMs (25ms): Upper jitter bound for fragment relays. bitchat/Services/TransportConfig.swift13blePendingWriteBufferCapBytes (1,000,000): Maximum size of the outbound write buffer before applying backpressure. bitchat/Services/TransportConfig.swift67bleNotificationAssemblerHardCapBytes (8MB): Absolute limit on memory for notification assembly. bitchat/Services/TransportConfig.swift68BitChat conserves battery by cycling the BLE radio and performing periodic maintenance:
bleDutyOnDuration (5.0s): Duration BLE scanning/advertising is active. bitchat/Services/TransportConfig.swift60bleDutyOffDuration (10.0s): Duration BLE scanning/advertising is inactive. bitchat/Services/TransportConfig.swift61bleMaintenanceInterval (5.0s): Frequency of the background maintenance task for link cleanup. bitchat/Services/TransportConfig.swift115blePeerInactivityTimeoutSeconds (8.0s): How long without seeing traffic before the system sanity-checks the direct link. bitchat/Services/TransportConfig.swift126bleMaxCentralLinks (6): Maximum number of concurrent central role connections. bitchat/Services/TransportConfig.swift59Specific constraints for the PTT system to ensure low-latency delivery without fragmenting:
pttMaxBurstContentBytes (210): Sized so the Noise ciphertext fits in one BLE frame. bitchat/Services/TransportConfig.swift26pttJitterBufferSeconds (0.35s): Buffered audio before live playback starts. bitchat/Services/TransportConfig.swift27pttInboundMaxBytesPerSecond (6,000): Inbound flood guard for voice frames. bitchat/Services/TransportConfig.swift35Sources: bitchat/Services/TransportConfig.swift6-130 bitchat/Services/BLE/BLEService.swift27-34
The protocol includes a robust synchronization mechanism and diagnostic tools. Configuration here ensures that requests do not become an attack vector.
meshPingTimeoutSeconds (10s): Window to wait for a probe response. bitchat/Services/TransportConfig.swift41meshPingInboundMaxPerLink (5): Inbound ping budget per ingress link to prevent amplification. bitchat/Services/TransportConfig.swift42meshPingInboundWindowSeconds (10s): Sliding window for the inbound ping budget. bitchat/Services/TransportConfig.swift43bleRecentPeripheralCacheCap (16): Max number of peripherals remembered for background wake-on-proximity. bitchat/Services/TransportConfig.swift131bleRecentPeripheralMaxAgeSeconds (900s): 15-minute expiry for background reconnection targets. bitchat/Services/TransportConfig.swift132BLERecentPeripheralCache: A generic cache implementation that uses these constants to prune expired entries and enforce capacity limits. bitchat/Services/BLE/BLERecentPeripheralCache.swift7-23Sources: bitchat/Services/TransportConfig.swift41-43 bitchat/Services/TransportConfig.swift131-132 bitchat/Services/BLE/BLERecentPeripheralCache.swift7-23
To ensure the app remains responsive and memory-efficient, BitChat enforces strict limits on message history and UI updates.
privateChatCap (1337): Max messages retained per DM session. bitchat/Services/TransportConfig.swift46meshTimelineCap (1337): Max messages in the local mesh public feed. bitchat/Services/TransportConfig.swift47geoTimelineCap (1337): Max messages per geohash channel. bitchat/Services/TransportConfig.swift48contentLRUCap (2000): Limit for the Least Recently Used cache for media content. bitchat/Services/TransportConfig.swift49basePublicFlushInterval (0.08s): Batches incoming messages for UI rendering at ~12.5 FPS. bitchat/Services/TransportConfig.swift55uiSenderRateBucketCapacity (5.0): Token bucket capacity for UI sender rate limiting. bitchat/Services/TransportConfig.swift97uiContentRateBucketCapacity (3.0): Token bucket capacity for UI content rate limiting. bitchat/Services/TransportConfig.swift99uiBatchDispatchStaggerSeconds (0.15s): Staggering delay for UI batch updates. bitchat/Services/TransportConfig.swift108Sources: bitchat/Services/TransportConfig.swift46-55 bitchat/Services/TransportConfig.swift97-109
Nostr transport parameters manage global connectivity via relays and the Tor network.
| Parameter | Value | Purpose |
|---|---|---|
nostrReadAckInterval | 0.35s | Throttles read-receipt broadcasts to ~3 per second. bitchat/Services/TransportConfig.swift78 |
nostrInboundEventDedupCap | 4096 | Maximum capacity for inbound event deduplication. bitchat/Services/TransportConfig.swift79 |
nostrInboundEventDedupTrimTarget | 3072 | Target size for trimming the dedup cache. bitchat/Services/TransportConfig.swift80 |
nostrDuplicateEventLogInterval | 50 | Sample interval for logging duplicate inbound events. bitchat/Services/TransportConfig.swift81 |
nostrInboundEventLogInterval | 100 | Sample interval for debug logs on the inbound path. bitchat/Services/TransportConfig.swift83 |
The TorManager (backed by the Arti Rust implementation) manages the lifecycle of the SOCKS5 proxy used for Nostr communication. localPackages/Arti/Sources/TorManager.swift33-43 It enforces a "fail-closed" behavior where networking is only permitted when Tor is ready, unless a developer bypass is active. localPackages/Arti/Sources/TorManager.swift57-69
Sources: bitchat/Services/TransportConfig.swift78-83 localPackages/Arti/Sources/TorManager.swift33-69
The system uses specific grace periods and debouncing for network state changes to prevent thrashing.
NetworkActivationService coordinates when the app is allowed to start Tor and connect to Nostr relays based on location permissions, mutual favorites, and network reachability. bitchat/Services/NetworkActivationService.swift27-32
NWPathReachabilityMonitor: Implements a 2.5s debounce to filter out path flapping. bitchat/Services/NetworkReachabilityMonitor.swift106-122networkResetGraceSeconds (600s): 10-minute window before triggering a network reset after loss. bitchat/Services/TransportConfig.swift53networkNotificationCooldownSeconds (300s): 5-minute cooldown for network-related alerts. bitchat/Services/TransportConfig.swift54Sources: bitchat/Services/TransportConfig.swift53-54 bitchat/Services/NetworkReachabilityMonitor.swift106-122 bitchat/Services/NetworkActivationService.swift27-32
Refresh this wiki
This wiki was recently refreshed. Please wait 6 days to refresh again.