From 9cf59651bb18b56b2580231eaef13356ecc40b65 Mon Sep 17 00:00:00 2001 From: jack Date: Wed, 23 Jul 2025 11:16:13 +0200 Subject: [PATCH] Clear handshake coordinator state during panic mode When panic mode is triggered (triple tap on logo), it now properly clears: - All handshake coordinator states - Handshake attempt times - Notifies UI that all peers are disconnected This fixes the issue where handshake states would persist after clearing identity, causing confusion when the device showed "zero peers connected" but still had established handshake states in logs. Also ensures UI is properly notified to update the peer list to empty. --- bitchat/Noise/NoiseHandshakeCoordinator.swift | 9 +++++++++ bitchat/Services/BluetoothMeshService.swift | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/bitchat/Noise/NoiseHandshakeCoordinator.swift b/bitchat/Noise/NoiseHandshakeCoordinator.swift index 5a2d5d9d..c205cfa5 100644 --- a/bitchat/Noise/NoiseHandshakeCoordinator.swift +++ b/bitchat/Noise/NoiseHandshakeCoordinator.swift @@ -254,4 +254,13 @@ class NoiseHandshakeCoordinator { SecureLogger.log("========================", category: SecureLogger.handshake, level: .debug) } } + + /// Clear all handshake states - used during panic mode + func clearAllHandshakeStates() { + handshakeQueue.async(flags: .barrier) { + SecureLogger.log("Clearing all handshake states for panic mode", category: SecureLogger.handshake, level: .warning) + self.handshakeStates.removeAll() + self.processedHandshakeMessages.removeAll() + } + } } \ No newline at end of file diff --git a/bitchat/Services/BluetoothMeshService.swift b/bitchat/Services/BluetoothMeshService.swift index 38f03ec9..61e0a366 100644 --- a/bitchat/Services/BluetoothMeshService.swift +++ b/bitchat/Services/BluetoothMeshService.swift @@ -1159,6 +1159,16 @@ class BluetoothMeshService: NSObject { // Clear persistent identity noiseService.clearPersistentIdentity() + // Clear all handshake coordinator states + handshakeCoordinator.clearAllHandshakeStates() + + // Clear handshake attempt times + handshakeAttemptTimes.removeAll() + + // Notify UI that all peers are disconnected + DispatchQueue.main.async { [weak self] in + self?.delegate?.didUpdatePeerList([]) + } } private func getAllConnectedPeerIDs() -> [String] {