mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 19:45:22 +00:00
* Sign public broadcasts; verify relayed messages via persisted signing keys; keep scheduled relays in sparse graphs and speed their jitter; persist announce signing key for offline auth; add short backoff after disconnect errors to reduce reconnect thrash * Add connected vs reachable model: retain peers after link drop, expire after reachability window; expose all peers in snapshots; compute isReachable in UI; add meshReachable state and sorting; avoid removing peers on link events; notify UI on stale removals * ContentView: handle new .meshReachable connection state in header icon switch (exhaustive switch fix) * Logs: tag relayed announces as 'Reachable via mesh' and annotate public message logs with (direct|mesh) path for easier field analysis * Fix syntax error: remove stray else/log inserted into writeOrEnqueue; keep logs clean * UI: use 'point.3.connected.trianglepath.dotted' for mesh-reachable; change people count to include connected+reachable (exclude Nostr-only) * UI: switch to 'point.3.filled.connected.trianglepath.dotted' for mesh-reachable icons in list and header * Reachability: reduce retention to 21s for all peers (verified and unverified) to minimize stale presence * mesh DMs/acks: route to reachable peers; queue READ/DELIVERED until handshake; add Transport.isPeerReachable; UI: hide offline non-mutuals; DM header: better name fallback + show transport + encryption icons; fix NostrTransport conformance * Verification sheet: compute encryption status and fingerprint using short mesh ID mapping (fix 'not encrypted/handshake' for DMs with stable key) * Announce cadence: faster discovery (4s), sparse 15±4s, dense 30±8s; initial 0.6s; post-subscribe 50ms; min-force 150ms; maintenance 5s; proactive announces on handshake + recent-traffic nudge * Relay: increase broadcast TTL cap in sparse graphs to 6; tighten jitter for handshake (10–35ms) and directed (20–60ms) relays * Range/robustness: store-and-forward for directed packets (15s) with flush on new links + periodic; announces: no subset + afterglow re-announce on first-seen; adaptive scanning: force ON when <=2 neighbors or recent traffic * Fix warnings: remove unused msgID and unused mutable var in directed spool flush * Announces: TTL 7 (sparse only) via RelayController; no fanout subset for announces; neighbor-change rebroadcast of last 2–3 announces. Fragments: faster pacing (5ms global, 4ms directed). * Peer list: real-time icon updates by publishing snapshots on connectivity checks; add unread message indicator (envelope) next to peers with unread DMs * UI: unread envelope uses orange; hasUnreadMessages checks Nostr conv key for peers with known Nostr pubkeys (geohash DM consistency) * Logs/robustness: debounce disconnect notifications (1.5s), debounce 'reconnected' logs (2s), add weak-link cooldown after timeouts on very weak RSSI (<= -90) * Peer icons: faster, accurate reachability\n\n- Run connectivity checks every maintenance tick (5s)\n- Publish peer snapshots on central unsubscribe for instant UI refresh\n- Lower inactivity timeout to 8s and disconnect debounce to 0.9s\n- Gate reachability on mesh-attached (>=1 direct link); no links => no reachable peers\n- Keep 21s retention for verified/unverified, but only when attached to mesh\n\nImproves list responsiveness when walking out of range and prevents stale 'reachable' states when isolated. --------- Co-authored-by: jack <jackjackbits@users.noreply.github.com>
101 lines
2.8 KiB
Swift
101 lines
2.8 KiB
Swift
import Foundation
|
|
import CoreBluetooth
|
|
|
|
/// Represents a peer in the BitChat network with all associated metadata
|
|
struct BitchatPeer: Identifiable, Equatable {
|
|
let id: String // Hex-encoded peer ID
|
|
let noisePublicKey: Data
|
|
let nickname: String
|
|
let lastSeen: Date
|
|
let isConnected: Bool
|
|
let isReachable: Bool
|
|
|
|
// Favorite-related properties
|
|
var favoriteStatus: FavoritesPersistenceService.FavoriteRelationship?
|
|
|
|
// Nostr identity (if known)
|
|
var nostrPublicKey: String?
|
|
|
|
// Connection state
|
|
enum ConnectionState {
|
|
case bluetoothConnected
|
|
case meshReachable // Seen via mesh recently, not directly connected
|
|
case nostrAvailable // Mutual favorite, reachable via Nostr
|
|
case offline // Not connected via any transport
|
|
}
|
|
|
|
var connectionState: ConnectionState {
|
|
if isConnected {
|
|
return .bluetoothConnected
|
|
} else if isReachable {
|
|
return .meshReachable
|
|
} else if favoriteStatus?.isMutual == true {
|
|
// Mutual favorites can communicate via Nostr when offline
|
|
return .nostrAvailable
|
|
} else {
|
|
return .offline
|
|
}
|
|
}
|
|
|
|
var isFavorite: Bool {
|
|
favoriteStatus?.isFavorite ?? false
|
|
}
|
|
|
|
var isMutualFavorite: Bool {
|
|
favoriteStatus?.isMutual ?? false
|
|
}
|
|
|
|
var theyFavoritedUs: Bool {
|
|
favoriteStatus?.theyFavoritedUs ?? false
|
|
}
|
|
|
|
// Display helpers
|
|
var displayName: String {
|
|
nickname.isEmpty ? String(id.prefix(8)) : nickname
|
|
}
|
|
|
|
var statusIcon: String {
|
|
switch connectionState {
|
|
case .bluetoothConnected:
|
|
return "📻" // Radio icon for mesh connection
|
|
case .meshReachable:
|
|
return "📡" // Antenna for mesh reachable
|
|
case .nostrAvailable:
|
|
return "🌐" // Purple globe for Nostr
|
|
case .offline:
|
|
if theyFavoritedUs && !isFavorite {
|
|
return "🌙" // Crescent moon - they favorited us but we didn't reciprocate
|
|
} else {
|
|
return ""
|
|
}
|
|
}
|
|
}
|
|
|
|
// Initialize from mesh service data
|
|
init(
|
|
id: String,
|
|
noisePublicKey: Data,
|
|
nickname: String,
|
|
lastSeen: Date = Date(),
|
|
isConnected: Bool = false,
|
|
isReachable: Bool = false
|
|
) {
|
|
self.id = id
|
|
self.noisePublicKey = noisePublicKey
|
|
self.nickname = nickname
|
|
self.lastSeen = lastSeen
|
|
self.isConnected = isConnected
|
|
self.isReachable = isReachable
|
|
|
|
// Load favorite status - will be set later by the manager
|
|
self.favoriteStatus = nil
|
|
self.nostrPublicKey = nil
|
|
}
|
|
|
|
static func == (lhs: BitchatPeer, rhs: BitchatPeer) -> Bool {
|
|
lhs.id == rhs.id
|
|
}
|
|
}
|
|
|
|
//
|