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.
This commit is contained in:
jack
2025-07-23 11:16:13 +02:00
parent 1e67bb4fd1
commit 9cf59651bb
2 changed files with 19 additions and 0 deletions
@@ -254,4 +254,13 @@ class NoiseHandshakeCoordinator {
SecureLogger.log("========================", category: SecureLogger.handshake, level: .debug) 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()
}
}
} }
@@ -1159,6 +1159,16 @@ class BluetoothMeshService: NSObject {
// Clear persistent identity // Clear persistent identity
noiseService.clearPersistentIdentity() 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] { private func getAllConnectedPeerIDs() -> [String] {