mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 18:05:19 +00:00
Gate Nostr init/subscription logs until Tor is ready
- ChatViewModel: await Tor readiness before initializing Nostr and logging - Only log GeoDM subscription when Tor is ready to avoid early noise
This commit is contained in:
@@ -554,17 +554,19 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
addGeohashOnlySystemMessage("development build: tor bypass enabled.")
|
addGeohashOnlySystemMessage("development build: tor bypass enabled.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize Nostr services
|
// Initialize Nostr services only after Tor is fully ready, to avoid
|
||||||
|
// interleaving setup logs during Tor startup.
|
||||||
Task { @MainActor in
|
Task { @MainActor in
|
||||||
|
// Wait for Tor readiness before Nostr init
|
||||||
|
let ready = await TorManager.shared.awaitReady(timeout: 60)
|
||||||
|
guard ready else {
|
||||||
|
SecureLogger.log("Nostr init skipped: Tor not ready", category: SecureLogger.session, level: .error)
|
||||||
|
return
|
||||||
|
}
|
||||||
nostrRelayManager = NostrRelayManager.shared
|
nostrRelayManager = NostrRelayManager.shared
|
||||||
SecureLogger.log("Initializing Nostr relay connections", category: SecureLogger.session, level: .debug)
|
SecureLogger.log("Initializing Nostr relay connections", category: SecureLogger.session, level: .debug)
|
||||||
nostrRelayManager?.connect()
|
nostrRelayManager?.connect()
|
||||||
|
// Set up Nostr message handling directly once Tor is ready
|
||||||
// Small delay to ensure read receipts are fully loaded
|
|
||||||
// This prevents race conditions where messages arrive before initialization completes
|
|
||||||
try? await Task.sleep(nanoseconds: TransportConfig.uiStartupShortSleepNs) // 0.2 seconds
|
|
||||||
|
|
||||||
// Set up Nostr message handling directly
|
|
||||||
setupNostrMessageHandling()
|
setupNostrMessageHandling()
|
||||||
|
|
||||||
// Attempt to flush any queued outbox after Nostr comes online
|
// Attempt to flush any queued outbox after Nostr comes online
|
||||||
@@ -1653,8 +1655,11 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
let dmSub = "geo-dm-\(ch.geohash)"
|
let dmSub = "geo-dm-\(ch.geohash)"
|
||||||
geoDmSubscriptionID = dmSub
|
geoDmSubscriptionID = dmSub
|
||||||
// pared back logging: subscribe debug only
|
// pared back logging: subscribe debug only
|
||||||
SecureLogger.log("GeoDM: subscribing DMs pub=\(id.publicKeyHex.prefix(8))… sub=\(dmSub)",
|
// Log GeoDM subscribe only when Tor is ready to avoid early noise
|
||||||
category: SecureLogger.session, level: .debug)
|
if TorManager.shared.isReady {
|
||||||
|
SecureLogger.log("GeoDM: subscribing DMs pub=\(id.publicKeyHex.prefix(8))… sub=\(dmSub)",
|
||||||
|
category: SecureLogger.session, level: .debug)
|
||||||
|
}
|
||||||
let dmFilter = NostrFilter.giftWrapsFor(pubkey: id.publicKeyHex, since: Date().addingTimeInterval(-TransportConfig.nostrDMSubscribeLookbackSeconds))
|
let dmFilter = NostrFilter.giftWrapsFor(pubkey: id.publicKeyHex, since: Date().addingTimeInterval(-TransportConfig.nostrDMSubscribeLookbackSeconds))
|
||||||
NostrRelayManager.shared.subscribe(filter: dmFilter, id: dmSub) { [weak self] giftWrap in
|
NostrRelayManager.shared.subscribe(filter: dmFilter, id: dmSub) { [weak self] giftWrap in
|
||||||
guard let self = self else { return }
|
guard let self = self else { return }
|
||||||
|
|||||||
Reference in New Issue
Block a user