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] {