mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-08-08 06:46:11 +00:00
Merge pull request #829 from TheCodeSmith404/fix/panic-mode-memory-purge-807
fix(panic): clear in-memory networking caches, router outbox, and Nostr queues on panic wipe (#807)
This commit is contained in:
commit
aaac810f4f
@ -1583,6 +1583,7 @@ class BluetoothMeshService(private val context: Context) : TransportBridgeServic
|
||||
securityManager.clearAllData()
|
||||
peerManager.clearAllPeers()
|
||||
peerManager.clearAllFingerprints()
|
||||
try { gossipSyncManager.clear() } catch (_: Exception) { }
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Error clearing mesh service internal data: ${e.message}")
|
||||
}
|
||||
|
||||
@ -987,6 +987,7 @@ class MeshCore(
|
||||
securityManager.clearAllData()
|
||||
peerManager.clearAllPeers()
|
||||
peerManager.clearAllFingerprints()
|
||||
try { gossipSyncManager.clear() } catch (_: Exception) { }
|
||||
}
|
||||
|
||||
fun clearAllEncryptionData() {
|
||||
|
||||
@ -679,6 +679,24 @@ class NostrRelayManager private constructor() {
|
||||
Log.e(TAG, "Failed to clear subscriptions: ${e.message}")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all subscription tracking, deduplication cache, message queue, and connections for panic mode.
|
||||
*/
|
||||
fun clearAllOnPanic() {
|
||||
try {
|
||||
val wasConnected = desiredConnected.get()
|
||||
clearAllSubscriptions()
|
||||
clearDeduplicationCache()
|
||||
disconnect()
|
||||
if (wasConnected) {
|
||||
desiredConnected.set(true)
|
||||
}
|
||||
Log.w(TAG, "🚨 Cleared NostrRelayManager subscriptions, cache, and connections for panic mode")
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Failed to clear NostrRelayManager on panic: ${e.message}")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get detailed status for all relays
|
||||
|
||||
@ -136,6 +136,7 @@ object MeshServiceHolder {
|
||||
@Synchronized
|
||||
fun clear() {
|
||||
android.util.Log.d(TAG, "Clearing BluetoothMeshService from holder")
|
||||
try { sharedGossipSyncManager?.clear() } catch (_: Exception) { }
|
||||
try { sharedGossipSyncManager?.stop() } catch (_: Exception) { }
|
||||
sharedGossipSyncManager = null
|
||||
activeGossipOwners.clear()
|
||||
|
||||
@ -99,6 +99,12 @@ class MessageRouter private constructor(
|
||||
startOutboxScheduler()
|
||||
}
|
||||
|
||||
fun clearAll() {
|
||||
outbox.clear()
|
||||
retryState.clear()
|
||||
Log.d(TAG, "Cleared all MessageRouter outbox messages and retry state")
|
||||
}
|
||||
|
||||
// Listener for favorites changes to flush outbox when npub mapping appears/changes
|
||||
private val favoriteListener = object: com.bitchat.android.favorites.FavoritesChangeListener {
|
||||
|
||||
|
||||
@ -79,6 +79,15 @@ class GossipSyncManager(
|
||||
cleanupJob?.cancel(); cleanupJob = null
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun clear() {
|
||||
synchronized(messages) {
|
||||
messages.clear()
|
||||
}
|
||||
latestAnnouncementByPeer.clear()
|
||||
Log.d(TAG, "Cleared all gossip sync messages and announcements")
|
||||
}
|
||||
|
||||
fun scheduleInitialSync(delayMs: Long = 5_000L) {
|
||||
scope.launch(Dispatchers.IO) {
|
||||
delay(delayMs)
|
||||
|
||||
@ -1445,10 +1445,13 @@ class ChatViewModel(
|
||||
dataManager.clearAllData()
|
||||
conversationListPreferences.clearAll()
|
||||
|
||||
// Clear seen message store
|
||||
// Clear seen message store and MessageRouter outbox
|
||||
try {
|
||||
com.bitchat.android.services.SeenMessageStore.getInstance(getApplication()).clear()
|
||||
} catch (_: Exception) { }
|
||||
try {
|
||||
com.bitchat.android.services.MessageRouter.tryGetInstance()?.clearAll()
|
||||
} catch (_: Exception) { }
|
||||
|
||||
// Clear all cryptographic data
|
||||
clearAllCryptographicData()
|
||||
|
||||
@ -119,6 +119,8 @@ class GeohashViewModel(
|
||||
geoTimer = null
|
||||
try { NostrIdentityBridge.clearAllAssociations(getApplication()) } catch (_: Exception) {}
|
||||
NostrBackgroundRuntime.resetSubscriptions()
|
||||
try { com.bitchat.android.nostr.NostrRelayManager.getInstance(getApplication()).clearAllOnPanic() } catch (_: Exception) {}
|
||||
try { com.bitchat.android.nostr.LocationNotesManager.getInstance().stop() } catch (_: Exception) {}
|
||||
}
|
||||
|
||||
fun sendGeohashMessage(content: String, channel: com.bitchat.android.geohash.GeohashChannel, myPeerID: String, nickname: String?) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user