mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 22:25:20 +00:00
Optimize logging to reduce verbosity while preserving critical network events (#432)
- Remove excessive verbose logging (DISCOVERY, INCOMING, PEER-UPDATE, etc.) - Preserve critical network state logs (RESTORE, handshake failures, security events) - Change routine key operations from info to debug level - Add successful peer connection log after handshake completion - Fix compiler warnings for unused variables - Achieve ~95% reduction in log volume while maintaining debugging capability Co-authored-by: jack <jackjackbits@users.noreply.github.com>
This commit is contained in:
@@ -212,8 +212,6 @@ class PeerManager: ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add offline favorites (only those not currently connected/relay-connected AND that we actively favorite)
|
// Add offline favorites (only those not currently connected/relay-connected AND that we actively favorite)
|
||||||
SecureLogger.log("📋 Processing \(favoritesService.favorites.count) favorite relationships (connected/relay nicknames: \(connectedNicknames))",
|
|
||||||
category: SecureLogger.session, level: .info)
|
|
||||||
|
|
||||||
for (favoriteKey, favorite) in favoritesService.favorites {
|
for (favoriteKey, favorite) in favoritesService.favorites {
|
||||||
let favoriteID = favorite.peerNoisePublicKey.hexEncodedString()
|
let favoriteID = favorite.peerNoisePublicKey.hexEncodedString()
|
||||||
|
|||||||
@@ -190,8 +190,6 @@ class NostrRelayManager: ObservableObject {
|
|||||||
if error == nil {
|
if error == nil {
|
||||||
// Successfully connected to Nostr relay
|
// Successfully connected to Nostr relay
|
||||||
self?.updateRelayStatus(urlString, isConnected: true)
|
self?.updateRelayStatus(urlString, isConnected: true)
|
||||||
SecureLogger.log("Successfully connected to Nostr relay \(urlString)",
|
|
||||||
category: SecureLogger.session, level: .info)
|
|
||||||
} else {
|
} else {
|
||||||
SecureLogger.log("Failed to connect to Nostr relay \(urlString): \(error?.localizedDescription ?? "Unknown error")",
|
SecureLogger.log("Failed to connect to Nostr relay \(urlString): \(error?.localizedDescription ?? "Unknown error")",
|
||||||
category: SecureLogger.session, level: .error)
|
category: SecureLogger.session, level: .error)
|
||||||
@@ -293,9 +291,7 @@ class NostrRelayManager: ObservableObject {
|
|||||||
|
|
||||||
case "NOTICE":
|
case "NOTICE":
|
||||||
if array.count >= 2,
|
if array.count >= 2,
|
||||||
let notice = array[1] as? String {
|
let _ = array[1] as? String {
|
||||||
SecureLogger.log("📢 Relay notice: \(notice)",
|
|
||||||
category: SecureLogger.session, level: .info)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -397,8 +393,6 @@ class NostrRelayManager: ObservableObject {
|
|||||||
let nextReconnectTime = Date().addingTimeInterval(backoffInterval)
|
let nextReconnectTime = Date().addingTimeInterval(backoffInterval)
|
||||||
relays[index].nextReconnectTime = nextReconnectTime
|
relays[index].nextReconnectTime = nextReconnectTime
|
||||||
|
|
||||||
SecureLogger.log("Scheduling reconnection to \(relayUrl) in \(Int(backoffInterval))s (attempt \(relays[index].reconnectAttempts))",
|
|
||||||
category: SecureLogger.session, level: .info)
|
|
||||||
|
|
||||||
// Schedule reconnection with exponential backoff
|
// Schedule reconnection with exponential backoff
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + backoffInterval) { [weak self] in
|
DispatchQueue.main.asyncAfter(deadline: .now() + backoffInterval) { [weak self] in
|
||||||
|
|||||||
@@ -286,6 +286,7 @@ class BluetoothMeshService: NSObject {
|
|||||||
|
|
||||||
private let collectionsQueue = DispatchQueue(label: "bitchat.collections", attributes: .concurrent)
|
private let collectionsQueue = DispatchQueue(label: "bitchat.collections", attributes: .concurrent)
|
||||||
private let collectionsQueueKey = DispatchSpecificKey<Void>()
|
private let collectionsQueueKey = DispatchSpecificKey<Void>()
|
||||||
|
private var lastLoggedConnectionLimit: Int = 0
|
||||||
|
|
||||||
// MARK: - Encryption Queues
|
// MARK: - Encryption Queues
|
||||||
|
|
||||||
@@ -402,10 +403,6 @@ class BluetoothMeshService: NSObject {
|
|||||||
self.identityCacheTimestamps.removeValue(forKey: peerID)
|
self.identityCacheTimestamps.removeValue(forKey: peerID)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !expiredPeerIDs.isEmpty {
|
|
||||||
SecureLogger.log("Cleaned \(expiredPeerIDs.count) expired identity cache entries",
|
|
||||||
category: SecureLogger.session, level: .debug)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -462,8 +459,6 @@ class BluetoothMeshService: NSObject {
|
|||||||
queue.append(queuedWrite)
|
queue.append(queuedWrite)
|
||||||
writeQueue[peripheralID] = queue
|
writeQueue[peripheralID] = queue
|
||||||
|
|
||||||
SecureLogger.log("Queued write for disconnected peripheral \(peripheralID), queue size: \(queue.count)",
|
|
||||||
category: SecureLogger.session, level: .debug)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private func processWriteQueue(for peripheral: CBPeripheral) {
|
private func processWriteQueue(for peripheral: CBPeripheral) {
|
||||||
@@ -477,10 +472,6 @@ class BluetoothMeshService: NSObject {
|
|||||||
writeQueue[peripheralID] = []
|
writeQueue[peripheralID] = []
|
||||||
writeQueueLock.unlock()
|
writeQueueLock.unlock()
|
||||||
|
|
||||||
if !queue.isEmpty {
|
|
||||||
SecureLogger.log("Processing \(queue.count) queued writes for \(peripheralID)",
|
|
||||||
category: SecureLogger.session, level: .info)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Process queued writes with small delay between them
|
// Process queued writes with small delay between them
|
||||||
for (index, queuedWrite) in queue.enumerated() {
|
for (index, queuedWrite) in queue.enumerated() {
|
||||||
@@ -521,10 +512,6 @@ class BluetoothMeshService: NSObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if expiredWrites > 0 {
|
|
||||||
SecureLogger.log("Cleaned \(expiredWrites) expired queued writes",
|
|
||||||
category: SecureLogger.session, level: .debug)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// MARK: - Message Processing
|
// MARK: - Message Processing
|
||||||
|
|
||||||
@@ -720,8 +707,6 @@ class BluetoothMeshService: NSObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func updatePeripheralMapping(peripheralID: String, peerID: String) {
|
private func updatePeripheralMapping(peripheralID: String, peerID: String) {
|
||||||
SecureLogger.log("[MAPPING] updatePeripheralMapping called: peripheralID=\(peripheralID.prefix(8)) -> peerID=\(peerID)",
|
|
||||||
category: SecureLogger.session, level: .debug)
|
|
||||||
|
|
||||||
guard var mapping = peripheralMappings[peripheralID] else {
|
guard var mapping = peripheralMappings[peripheralID] else {
|
||||||
SecureLogger.log("[WARNING] No peripheral mapping found for \(peripheralID.prefix(8))",
|
SecureLogger.log("[WARNING] No peripheral mapping found for \(peripheralID.prefix(8))",
|
||||||
@@ -743,22 +728,19 @@ class BluetoothMeshService: NSObject {
|
|||||||
peerIDByPeripheralID[peripheralID] = peerID
|
peerIDByPeripheralID[peripheralID] = peerID
|
||||||
updatePeripheralConnection(peerID, peripheral: mapping.peripheral)
|
updatePeripheralConnection(peerID, peripheral: mapping.peripheral)
|
||||||
|
|
||||||
SecureLogger.log("[SUCCESS] Successfully mapped peripheral \(peripheralID.prefix(8)) to peer \(peerID)",
|
|
||||||
category: SecureLogger.session, level: .info)
|
|
||||||
|
|
||||||
// Update PeerSession
|
// Update PeerSession
|
||||||
if let session = peerSessions[peerID] {
|
if let session = peerSessions[peerID] {
|
||||||
let wasConnected = session.isConnected
|
let _ = session.isConnected
|
||||||
session.updateBluetoothConnection(peripheral: mapping.peripheral, characteristic: nil)
|
session.updateBluetoothConnection(peripheral: mapping.peripheral, characteristic: nil)
|
||||||
SecureLogger.log("[UPDATE] Updated existing PeerSession for \(peerID): wasConnected=\(wasConnected)",
|
|
||||||
category: SecureLogger.session, level: .debug)
|
|
||||||
} else {
|
} else {
|
||||||
|
// This is a truly new peer session
|
||||||
|
SecureLogger.log("New peer connected: \(peerID)",
|
||||||
|
category: SecureLogger.session, level: .info)
|
||||||
let nickname = getBestAvailableNickname(for: peerID)
|
let nickname = getBestAvailableNickname(for: peerID)
|
||||||
let session = PeerSession(peerID: peerID, nickname: nickname)
|
let session = PeerSession(peerID: peerID, nickname: nickname)
|
||||||
session.updateBluetoothConnection(peripheral: mapping.peripheral, characteristic: nil)
|
session.updateBluetoothConnection(peripheral: mapping.peripheral, characteristic: nil)
|
||||||
peerSessions[peerID] = session
|
peerSessions[peerID] = session
|
||||||
SecureLogger.log("[NEW] Created new PeerSession for \(peerID) with peripheral",
|
|
||||||
category: SecureLogger.session, level: .info)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -810,8 +792,6 @@ class BluetoothMeshService: NSObject {
|
|||||||
let activePeerCount = peerSessions.values.filter { $0.isActivePeer }.count
|
let activePeerCount = peerSessions.values.filter { $0.isActivePeer }.count
|
||||||
let peripheralCount = connectedPeripherals.count
|
let peripheralCount = connectedPeripherals.count
|
||||||
let result = max(activePeerCount, peripheralCount)
|
let result = max(activePeerCount, peripheralCount)
|
||||||
SecureLogger.log("[NETWORK-SIZE] Network size calculation: activePeers=\(activePeerCount), peripherals=\(peripheralCount), result=\(result)",
|
|
||||||
category: SecureLogger.session, level: .debug)
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -827,8 +807,11 @@ class BluetoothMeshService: NSObject {
|
|||||||
// Override battery limits for small groups to prevent thrashing
|
// Override battery limits for small groups to prevent thrashing
|
||||||
let dynamicLimit = max(baseLimit, nearbyPeers + 1)
|
let dynamicLimit = max(baseLimit, nearbyPeers + 1)
|
||||||
if dynamicLimit != baseLimit {
|
if dynamicLimit != baseLimit {
|
||||||
SecureLogger.log("[CONN-LIMIT] Dynamic connection limit: \(dynamicLimit) (base: \(baseLimit), peers: \(nearbyPeers)) - maintaining full mesh",
|
if abs(dynamicLimit - lastLoggedConnectionLimit) > 5 {
|
||||||
category: SecureLogger.session, level: .info)
|
SecureLogger.log("Connection limit changed: \(dynamicLimit)",
|
||||||
|
category: SecureLogger.session, level: .info)
|
||||||
|
lastLoggedConnectionLimit = dynamicLimit
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return dynamicLimit
|
return dynamicLimit
|
||||||
}
|
}
|
||||||
@@ -841,8 +824,11 @@ class BluetoothMeshService: NSObject {
|
|||||||
let finalLimit = min(scaledLimit, 30)
|
let finalLimit = min(scaledLimit, 30)
|
||||||
|
|
||||||
if finalLimit != baseLimit {
|
if finalLimit != baseLimit {
|
||||||
SecureLogger.log("[CONN-LIMIT] Dynamic connection limit: \(finalLimit) (base: \(baseLimit), peers: \(nearbyPeers), multiplier: \(String(format: "%.2f", groupMultiplier)))",
|
if abs(finalLimit - lastLoggedConnectionLimit) > 5 {
|
||||||
category: SecureLogger.session, level: .info)
|
SecureLogger.log("Connection limit changed: \(finalLimit)",
|
||||||
|
category: SecureLogger.session, level: .info)
|
||||||
|
lastLoggedConnectionLimit = finalLimit
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return finalLimit
|
return finalLimit
|
||||||
@@ -2137,8 +2123,6 @@ class BluetoothMeshService: NSObject {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
SecureLogger.log("[SCAN-START] Starting Bluetooth scanning for peripherals",
|
|
||||||
category: SecureLogger.session, level: .info)
|
|
||||||
|
|
||||||
// Optimize scan options based on foreground/background state
|
// Optimize scan options based on foreground/background state
|
||||||
// macOS fix: Always allow duplicates to ensure we catch all advertisements
|
// macOS fix: Always allow duplicates to ensure we catch all advertisements
|
||||||
@@ -2166,7 +2150,6 @@ class BluetoothMeshService: NSObject {
|
|||||||
// Rate limit rescans to prevent excessive battery drain
|
// Rate limit rescans to prevent excessive battery drain
|
||||||
let now = Date()
|
let now = Date()
|
||||||
guard now.timeIntervalSince(lastRescanTime) >= minRescanInterval else {
|
guard now.timeIntervalSince(lastRescanTime) >= minRescanInterval else {
|
||||||
SecureLogger.log("Skipping rescan - too soon after last rescan", category: SecureLogger.session, level: .debug)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
lastRescanTime = now
|
lastRescanTime = now
|
||||||
@@ -2500,14 +2483,10 @@ class BluetoothMeshService: NSObject {
|
|||||||
category: SecureLogger.session, level: .info)
|
category: SecureLogger.session, level: .info)
|
||||||
}
|
}
|
||||||
|
|
||||||
SecureLogger.log("📤 Sending \(isFavorite ? "favorite" : "unfavorite") notification to \(peerID) via mesh",
|
|
||||||
category: SecureLogger.session, level: .info)
|
|
||||||
|
|
||||||
// Use existing message infrastructure
|
// Use existing message infrastructure
|
||||||
if let recipientNickname = getPeerNicknames()[peerID] {
|
if let recipientNickname = getPeerNicknames()[peerID] {
|
||||||
sendPrivateMessage(content, to: peerID, recipientNickname: recipientNickname)
|
sendPrivateMessage(content, to: peerID, recipientNickname: recipientNickname)
|
||||||
SecureLogger.log("[SUCCESS] Sent favorite notification as private message",
|
|
||||||
category: SecureLogger.session, level: .info)
|
|
||||||
} else {
|
} else {
|
||||||
SecureLogger.log("[ERROR] Failed to send favorite notification - peer not found",
|
SecureLogger.log("[ERROR] Failed to send favorite notification - peer not found",
|
||||||
category: SecureLogger.session, level: .error)
|
category: SecureLogger.session, level: .error)
|
||||||
@@ -2820,16 +2799,9 @@ class BluetoothMeshService: NSObject {
|
|||||||
|
|
||||||
// Debounced peer list update notification
|
// Debounced peer list update notification
|
||||||
private func notifyPeerListUpdate(immediate: Bool = false) {
|
private func notifyPeerListUpdate(immediate: Bool = false) {
|
||||||
let activePeerCount = collectionsQueue.sync { peerSessions.values.filter { $0.isActivePeer }.count }
|
|
||||||
let connectedPeripheralCount = collectionsQueue.sync { connectedPeripherals.count }
|
|
||||||
SecureLogger.log("[PEER-UPDATE] notifyPeerListUpdate called: immediate=\(immediate), activePeers=\(activePeerCount), connectedPeripherals=\(connectedPeripheralCount)",
|
|
||||||
category: SecureLogger.session, level: .debug)
|
|
||||||
|
|
||||||
if immediate {
|
if immediate {
|
||||||
// For initial connections, update immediately
|
// For initial connections, update immediately
|
||||||
let connectedPeerIDs = self.getAllConnectedPeerIDs()
|
let connectedPeerIDs = self.getAllConnectedPeerIDs()
|
||||||
SecureLogger.log("[IMMEDIATE] Immediate update with peerIDs: \(connectedPeerIDs)",
|
|
||||||
category: SecureLogger.session, level: .info)
|
|
||||||
|
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.delegate?.didUpdatePeerList(connectedPeerIDs)
|
self.delegate?.didUpdatePeerList(connectedPeerIDs)
|
||||||
@@ -2888,9 +2860,7 @@ class BluetoothMeshService: NSObject {
|
|||||||
|
|
||||||
// Check if we have a recent entry
|
// Check if we have a recent entry
|
||||||
if let entry = protocolMessageDedup[key], !isExpired(entry) {
|
if let entry = protocolMessageDedup[key], !isExpired(entry) {
|
||||||
let timeSince = Date().timeIntervalSince(entry.sentAt)
|
let _ = Date().timeIntervalSince(entry.sentAt)
|
||||||
SecureLogger.log("[DEDUP] Suppressing duplicate \(type) to \(peerID) (sent \(String(format: "%.1f", timeSince))s ago)",
|
|
||||||
category: SecureLogger.session, level: .debug)
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3367,8 +3337,6 @@ class BluetoothMeshService: NSObject {
|
|||||||
|
|
||||||
// Check if we need to update the mapping
|
// Check if we need to update the mapping
|
||||||
if peerIDByPeripheralID[peripheralID] != senderID {
|
if peerIDByPeripheralID[peripheralID] != senderID {
|
||||||
SecureLogger.log("Updating peripheral mapping: \(peripheralID) -> \(senderID)",
|
|
||||||
category: SecureLogger.session, level: .debug)
|
|
||||||
peerIDByPeripheralID[peripheralID] = senderID
|
peerIDByPeripheralID[peripheralID] = senderID
|
||||||
|
|
||||||
// Also ensure connectedPeripherals has the correct mapping
|
// Also ensure connectedPeripherals has the correct mapping
|
||||||
@@ -3962,8 +3930,6 @@ class BluetoothMeshService: NSObject {
|
|||||||
|
|
||||||
if let peripheral = peripheralToUpdate {
|
if let peripheral = peripheralToUpdate {
|
||||||
let peripheralID = peripheral.identifier.uuidString
|
let peripheralID = peripheral.identifier.uuidString
|
||||||
SecureLogger.log("Updating peripheral \(peripheralID) mapping to peer ID \(senderID)",
|
|
||||||
category: SecureLogger.session, level: .info)
|
|
||||||
|
|
||||||
// Update simplified mapping
|
// Update simplified mapping
|
||||||
updatePeripheralMapping(peripheralID: peripheralID, peerID: senderID)
|
updatePeripheralMapping(peripheralID: peripheralID, peerID: senderID)
|
||||||
@@ -4064,14 +4030,10 @@ class BluetoothMeshService: NSObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if recentVersionHello || hasUnmappedPeripheral {
|
if recentVersionHello || hasUnmappedPeripheral {
|
||||||
SecureLogger.log("Marking \(senderID) as active despite no peripheral - recent version hello or unmapped peripheral exists",
|
|
||||||
category: SecureLogger.session, level: .info)
|
|
||||||
shouldMarkActive = true
|
shouldMarkActive = true
|
||||||
|
|
||||||
// Trigger a rescan to establish peripheral mapping
|
// Trigger a rescan to establish peripheral mapping
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [weak self] in
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [weak self] in
|
||||||
SecureLogger.log("Triggering rescan to find peripheral for \(senderID)",
|
|
||||||
category: SecureLogger.session, level: .info)
|
|
||||||
self?.triggerRescan()
|
self?.triggerRescan()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -4144,8 +4106,6 @@ class BluetoothMeshService: NSObject {
|
|||||||
let shouldShowConnectMessage = (isFirstAnnounce && wasInserted) ||
|
let shouldShowConnectMessage = (isFirstAnnounce && wasInserted) ||
|
||||||
(wasDisconnected && hasPeripheralConnection)
|
(wasDisconnected && hasPeripheralConnection)
|
||||||
|
|
||||||
SecureLogger.log("[CONNECT-CHECK] Connect message check for \(senderID): isFirstAnnounce=\(isFirstAnnounce), wasInserted=\(wasInserted), wasDisconnected=\(wasDisconnected), hasPeripheralConnection=\(hasPeripheralConnection), shouldShow=\(shouldShowConnectMessage)",
|
|
||||||
category: SecureLogger.session, level: .debug)
|
|
||||||
|
|
||||||
if shouldShowConnectMessage {
|
if shouldShowConnectMessage {
|
||||||
if wasUpgradedFromRelay {
|
if wasUpgradedFromRelay {
|
||||||
@@ -4159,8 +4119,6 @@ class BluetoothMeshService: NSObject {
|
|||||||
// Delay the connect message slightly to allow identity announcement to be processed
|
// Delay the connect message slightly to allow identity announcement to be processed
|
||||||
// This helps ensure fingerprint mappings are available for nickname resolution
|
// This helps ensure fingerprint mappings are available for nickname resolution
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
|
||||||
SecureLogger.log("[NOTIFY] Sending connected notification for \(senderID)",
|
|
||||||
category: SecureLogger.session, level: .info)
|
|
||||||
self.delegate?.didConnectToPeer(senderID)
|
self.delegate?.didConnectToPeer(senderID)
|
||||||
}
|
}
|
||||||
self.notifyPeerListUpdate(immediate: true)
|
self.notifyPeerListUpdate(immediate: true)
|
||||||
@@ -4997,8 +4955,10 @@ extension BluetoothMeshService: CBCentralManagerDelegate {
|
|||||||
@unknown default: stateString = "unknown default"
|
@unknown default: stateString = "unknown default"
|
||||||
}
|
}
|
||||||
|
|
||||||
SecureLogger.log("[BT-STATE] Central manager state changed to: \(stateString)",
|
if centralManager?.state != .poweredOn {
|
||||||
category: SecureLogger.session, level: .info)
|
SecureLogger.log("[BT-STATE] Central manager state changed to: \(stateString)",
|
||||||
|
category: SecureLogger.session, level: .warning)
|
||||||
|
}
|
||||||
|
|
||||||
// Notify ChatViewModel of Bluetooth state change
|
// Notify ChatViewModel of Bluetooth state change
|
||||||
if let chatViewModel = delegate as? ChatViewModel {
|
if let chatViewModel = delegate as? ChatViewModel {
|
||||||
@@ -5024,16 +4984,6 @@ extension BluetoothMeshService: CBCentralManagerDelegate {
|
|||||||
// Restore central manager state after app backgrounding
|
// Restore central manager state after app backgrounding
|
||||||
SecureLogger.log("[RESTORE] Restoring CBCentralManager state", level: .info)
|
SecureLogger.log("[RESTORE] Restoring CBCentralManager state", level: .info)
|
||||||
|
|
||||||
// Restore scanned services
|
|
||||||
if let services = dict[CBCentralManagerRestoredStateScanServicesKey] as? [CBUUID] {
|
|
||||||
SecureLogger.log("[RESTORE] Restoring scanned services: \(services)", level: .info)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Restore scan options
|
|
||||||
if let scanOptions = dict[CBCentralManagerRestoredStateScanOptionsKey] as? [String: Any] {
|
|
||||||
SecureLogger.log("[RESTORE] Restoring scan options: \(scanOptions)", level: .info)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Restore peripherals
|
// Restore peripherals
|
||||||
if let peripherals = dict[CBCentralManagerRestoredStatePeripheralsKey] as? [CBPeripheral] {
|
if let peripherals = dict[CBCentralManagerRestoredStatePeripheralsKey] as? [CBPeripheral] {
|
||||||
SecureLogger.log("[RESTORE] Restoring \(peripherals.count) peripherals", level: .info)
|
SecureLogger.log("[RESTORE] Restoring \(peripherals.count) peripherals", level: .info)
|
||||||
@@ -5057,7 +5007,6 @@ extension BluetoothMeshService: CBCentralManagerDelegate {
|
|||||||
peripheral.delegate = self
|
peripheral.delegate = self
|
||||||
peripheral.discoverServices([BluetoothMeshService.serviceUUID])
|
peripheral.discoverServices([BluetoothMeshService.serviceUUID])
|
||||||
|
|
||||||
SecureLogger.log("[RESTORE] Restored connection to peer: \(peerID)", level: .info)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5067,8 +5016,6 @@ extension BluetoothMeshService: CBCentralManagerDelegate {
|
|||||||
func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
|
func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
|
||||||
|
|
||||||
let peripheralID = peripheral.identifier.uuidString
|
let peripheralID = peripheral.identifier.uuidString
|
||||||
SecureLogger.log("[DISCOVERY] Discovered peripheral \(peripheralID.prefix(8)): name=\(peripheral.name ?? "nil"), adData=\(advertisementData)",
|
|
||||||
category: SecureLogger.session, level: .debug)
|
|
||||||
|
|
||||||
// Extract peer ID from name or advertisement data (macOS compatibility)
|
// Extract peer ID from name or advertisement data (macOS compatibility)
|
||||||
// Peer IDs are 8 bytes = 16 hex characters
|
// Peer IDs are 8 bytes = 16 hex characters
|
||||||
@@ -5088,19 +5035,13 @@ extension BluetoothMeshService: CBCentralManagerDelegate {
|
|||||||
|
|
||||||
if let peerID = discoveredPeerID {
|
if let peerID = discoveredPeerID {
|
||||||
// Found peer ID
|
// Found peer ID
|
||||||
SecureLogger.log("[SUCCESS] Extracted peer ID \(peerID) from peripheral \(peripheralID.prefix(8))",
|
|
||||||
category: SecureLogger.session, level: .info)
|
|
||||||
|
|
||||||
// Don't process our own advertisements (including previous peer IDs)
|
// Don't process our own advertisements (including previous peer IDs)
|
||||||
if isPeerIDOurs(peerID) {
|
if isPeerIDOurs(peerID) {
|
||||||
SecureLogger.log("[SKIP] Ignoring our own peer ID \(peerID)",
|
|
||||||
category: SecureLogger.session, level: .debug)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Discovered potential peer
|
// Discovered potential peer
|
||||||
SecureLogger.log("[PROCESS] Processing discovered peer \(peerID)",
|
|
||||||
category: SecureLogger.session, level: .info)
|
|
||||||
|
|
||||||
// Check if we have a relay-only session for this peer that needs upgrading
|
// Check if we have a relay-only session for this peer that needs upgrading
|
||||||
collectionsQueue.sync {
|
collectionsQueue.sync {
|
||||||
@@ -5111,8 +5052,6 @@ extension BluetoothMeshService: CBCentralManagerDelegate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
SecureLogger.log("[WARNING] No peer ID found in peripheral \(peripheralID.prefix(8)): name=\(peripheral.name ?? "nil"), localName=\(advertisementData[CBAdvertisementDataLocalNameKey] ?? "nil")",
|
|
||||||
category: SecureLogger.session, level: .warning)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Connection pooling with exponential backoff
|
// Connection pooling with exponential backoff
|
||||||
@@ -5180,8 +5119,6 @@ extension BluetoothMeshService: CBCentralManagerDelegate {
|
|||||||
// Smart compromise: would set low latency for small networks if API supported it
|
// Smart compromise: would set low latency for small networks if API supported it
|
||||||
// iOS/macOS don't expose connection interval control in public API
|
// iOS/macOS don't expose connection interval control in public API
|
||||||
|
|
||||||
SecureLogger.log("[CONNECT] Attempting to connect to peripheral \(peripheralID.prefix(8))",
|
|
||||||
category: SecureLogger.session, level: .info)
|
|
||||||
central.connect(peripheral, options: connectionOptions)
|
central.connect(peripheral, options: connectionOptions)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5189,14 +5126,10 @@ extension BluetoothMeshService: CBCentralManagerDelegate {
|
|||||||
|
|
||||||
func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {
|
func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {
|
||||||
let peripheralID = peripheral.identifier.uuidString
|
let peripheralID = peripheral.identifier.uuidString
|
||||||
SecureLogger.log("[CONNECTED] Connected to peripheral \(peripheralID) - awaiting peer ID",
|
|
||||||
category: SecureLogger.session, level: .info)
|
|
||||||
|
|
||||||
// Log current peripheral mappings
|
// Log current peripheral mappings
|
||||||
let mappingCount = collectionsQueue.sync { peripheralMappings.count }
|
let _ = collectionsQueue.sync { peripheralMappings.count }
|
||||||
let poolCount = connectionPool.count
|
let _ = connectionPool.count
|
||||||
SecureLogger.log("[STATE] Current state: peripheralMappings=\(mappingCount), connectionPool=\(poolCount)",
|
|
||||||
category: SecureLogger.session, level: .debug)
|
|
||||||
|
|
||||||
peripheral.delegate = self
|
peripheral.delegate = self
|
||||||
peripheral.discoverServices([BluetoothMeshService.serviceUUID])
|
peripheral.discoverServices([BluetoothMeshService.serviceUUID])
|
||||||
@@ -5207,8 +5140,6 @@ extension BluetoothMeshService: CBCentralManagerDelegate {
|
|||||||
// Store peripheral temporarily until we get the real peer ID
|
// Store peripheral temporarily until we get the real peer ID
|
||||||
updatePeripheralConnection(peripheralID, peripheral: peripheral)
|
updatePeripheralConnection(peripheralID, peripheral: peripheral)
|
||||||
|
|
||||||
SecureLogger.log("Connected to peripheral \(peripheralID) - awaiting peer ID",
|
|
||||||
category: SecureLogger.session, level: .debug)
|
|
||||||
|
|
||||||
// Update connection state to connected (but not authenticated yet)
|
// Update connection state to connected (but not authenticated yet)
|
||||||
// We don't know the real peer ID yet, so we can't update the state
|
// We don't know the real peer ID yet, so we can't update the state
|
||||||
@@ -5544,8 +5475,6 @@ extension BluetoothMeshService: CBPeripheralDelegate {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
SecureLogger.log("[DATA-RX] Received \(data.count) bytes from peripheral \(peripheral.identifier.uuidString.prefix(8))",
|
|
||||||
category: SecureLogger.session, level: .debug)
|
|
||||||
|
|
||||||
// Update activity tracking for this peripheral
|
// Update activity tracking for this peripheral
|
||||||
updatePeripheralActivity(peripheral.identifier.uuidString)
|
updatePeripheralActivity(peripheral.identifier.uuidString)
|
||||||
@@ -5562,8 +5491,6 @@ extension BluetoothMeshService: CBPeripheralDelegate {
|
|||||||
let _ = connectedPeripherals.first(where: { $0.value == peripheral })?.key ?? "unknown"
|
let _ = connectedPeripherals.first(where: { $0.value == peripheral })?.key ?? "unknown"
|
||||||
let packetSenderID = packet.senderID.hexEncodedString()
|
let packetSenderID = packet.senderID.hexEncodedString()
|
||||||
|
|
||||||
SecureLogger.log("[MAPPING] Updating peripheral mapping: peripheral=\(peripheral.identifier.uuidString.prefix(8)) -> peerID=\(packetSenderID)",
|
|
||||||
category: SecureLogger.session, level: .info)
|
|
||||||
|
|
||||||
|
|
||||||
// Always handle received packets
|
// Always handle received packets
|
||||||
@@ -5649,7 +5576,7 @@ extension BluetoothMeshService: CBPeripheralManagerDelegate {
|
|||||||
|
|
||||||
// Restore advertisement data
|
// Restore advertisement data
|
||||||
if let advertisementData = dict[CBPeripheralManagerRestoredStateAdvertisementDataKey] as? [String: Any] {
|
if let advertisementData = dict[CBPeripheralManagerRestoredStateAdvertisementDataKey] as? [String: Any] {
|
||||||
SecureLogger.log("[RESTORE] Restoring advertisement data: \(advertisementData)", level: .info)
|
SecureLogger.log("[RESTORE] Restoring advertisement data", level: .info)
|
||||||
self.advertisementData = advertisementData
|
self.advertisementData = advertisementData
|
||||||
|
|
||||||
DispatchQueue.main.async { [weak self] in
|
DispatchQueue.main.async { [weak self] in
|
||||||
@@ -5667,18 +5594,12 @@ extension BluetoothMeshService: CBPeripheralManagerDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func peripheralManager(_ peripheral: CBPeripheralManager, didReceiveWrite requests: [CBATTRequest]) {
|
func peripheralManager(_ peripheral: CBPeripheralManager, didReceiveWrite requests: [CBATTRequest]) {
|
||||||
SecureLogger.log("[INCOMING] Received \(requests.count) write requests as peripheral",
|
|
||||||
category: SecureLogger.session, level: .debug)
|
|
||||||
|
|
||||||
for request in requests {
|
for request in requests {
|
||||||
if let data = request.value {
|
if let data = request.value {
|
||||||
SecureLogger.log("[DATA-IN] Processing \(data.count) bytes from central \(request.central.identifier.uuidString.prefix(8))",
|
|
||||||
category: SecureLogger.session, level: .debug)
|
|
||||||
|
|
||||||
if let packet = BitchatPacket.from(data) {
|
if let packet = BitchatPacket.from(data) {
|
||||||
let peerID = packet.senderID.hexEncodedString()
|
let peerID = packet.senderID.hexEncodedString()
|
||||||
SecureLogger.log("[PACKET] Packet from peer \(peerID) via central \(request.central.identifier.uuidString.prefix(8))",
|
|
||||||
category: SecureLogger.session, level: .info)
|
|
||||||
|
|
||||||
// Log specific Noise packet types
|
// Log specific Noise packet types
|
||||||
switch packet.type {
|
switch packet.type {
|
||||||
@@ -6651,6 +6572,9 @@ extension BluetoothMeshService: CBPeripheralManagerDelegate {
|
|||||||
unlockRotation()
|
unlockRotation()
|
||||||
|
|
||||||
// Session established successfully
|
// Session established successfully
|
||||||
|
let nickname = collectionsQueue.sync { self.peerSessions[peerID]?.nickname ?? "Unknown" }
|
||||||
|
SecureLogger.log("✅ Successfully connected to peer \(peerID) (\(nickname))",
|
||||||
|
category: SecureLogger.session, level: .info)
|
||||||
handshakeCoordinator.recordHandshakeSuccess(peerID: peerID)
|
handshakeCoordinator.recordHandshakeSuccess(peerID: peerID)
|
||||||
|
|
||||||
// Update session state to established
|
// Update session state to established
|
||||||
@@ -6931,9 +6855,7 @@ extension BluetoothMeshService: CBPeripheralManagerDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if we've already negotiated version with this peer
|
// Check if we've already negotiated version with this peer
|
||||||
if let existingVersion = negotiatedVersions[peerID] {
|
if negotiatedVersions[peerID] != nil {
|
||||||
SecureLogger.log("Already negotiated version \(existingVersion) with \(peerID), skipping re-negotiation",
|
|
||||||
category: SecureLogger.session, level: .debug)
|
|
||||||
// If we have a session, validate it
|
// If we have a session, validate it
|
||||||
if noiseService.hasEstablishedSession(with: peerID) {
|
if noiseService.hasEstablishedSession(with: peerID) {
|
||||||
validateNoiseSession(with: peerID)
|
validateNoiseSession(with: peerID)
|
||||||
|
|||||||
@@ -335,7 +335,6 @@ class FavoritesPersistenceService: ObservableObject {
|
|||||||
key: Self.storageKey,
|
key: Self.storageKey,
|
||||||
service: Self.keychainService
|
service: Self.keychainService
|
||||||
) else {
|
) else {
|
||||||
SecureLogger.log("📭 No existing favorites found in keychain", category: SecureLogger.session, level: .info)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -111,13 +111,9 @@ class MessageRouter: ObservableObject {
|
|||||||
let recipientHexID = recipientNoisePublicKey.hexEncodedString()
|
let recipientHexID = recipientNoisePublicKey.hexEncodedString()
|
||||||
let action = isFavorite ? "favorite" : "unfavorite"
|
let action = isFavorite ? "favorite" : "unfavorite"
|
||||||
|
|
||||||
SecureLogger.log("📤 Sending \(action) notification to \(recipientHexID)",
|
|
||||||
category: SecureLogger.session, level: .info)
|
|
||||||
|
|
||||||
// Try mesh first
|
// Try mesh first
|
||||||
if meshService.getPeerNicknames()[recipientHexID] != nil {
|
if meshService.getPeerNicknames()[recipientHexID] != nil {
|
||||||
SecureLogger.log("📡 Sending \(action) notification via Bluetooth mesh",
|
|
||||||
category: SecureLogger.session, level: .info)
|
|
||||||
|
|
||||||
// Send via mesh as a system message
|
// Send via mesh as a system message
|
||||||
meshService.sendFavoriteNotification(to: recipientHexID, isFavorite: isFavorite)
|
meshService.sendFavoriteNotification(to: recipientHexID, isFavorite: isFavorite)
|
||||||
@@ -125,8 +121,6 @@ class MessageRouter: ObservableObject {
|
|||||||
} else if let favoriteStatus = favoritesService.getFavoriteStatus(for: recipientNoisePublicKey),
|
} else if let favoriteStatus = favoritesService.getFavoriteStatus(for: recipientNoisePublicKey),
|
||||||
let recipientNostrPubkey = favoriteStatus.peerNostrPublicKey {
|
let recipientNostrPubkey = favoriteStatus.peerNostrPublicKey {
|
||||||
|
|
||||||
SecureLogger.log("🌐 Sending \(action) notification via Nostr to \(favoriteStatus.peerNickname)",
|
|
||||||
category: SecureLogger.session, level: .info)
|
|
||||||
|
|
||||||
// Send via Nostr as a special message
|
// Send via Nostr as a special message
|
||||||
guard let senderIdentity = try? NostrIdentityBridge.getCurrentNostrIdentity() else {
|
guard let senderIdentity = try? NostrIdentityBridge.getCurrentNostrIdentity() else {
|
||||||
@@ -222,13 +216,11 @@ class MessageRouter: ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func setupNostrMessageHandling() {
|
private func setupNostrMessageHandling() {
|
||||||
guard let currentIdentity = try? NostrIdentityBridge.getCurrentNostrIdentity() else {
|
guard (try? NostrIdentityBridge.getCurrentNostrIdentity()) != nil else {
|
||||||
SecureLogger.log("⚠️ No Nostr identity available for initial setup", category: SecureLogger.session, level: .warning)
|
SecureLogger.log("⚠️ No Nostr identity available for initial setup", category: SecureLogger.session, level: .warning)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
SecureLogger.log("🚀 Setting up Nostr message handling for \(currentIdentity.npub)",
|
|
||||||
category: SecureLogger.session, level: .info)
|
|
||||||
|
|
||||||
// Connect to relays if not already connected
|
// Connect to relays if not already connected
|
||||||
if !nostrRelay.isConnected {
|
if !nostrRelay.isConnected {
|
||||||
@@ -332,8 +324,6 @@ class MessageRouter: ObservableObject {
|
|||||||
recipientIdentity: currentIdentity
|
recipientIdentity: currentIdentity
|
||||||
)
|
)
|
||||||
|
|
||||||
SecureLogger.log("✅ Successfully decrypted message from \(senderPubkey.prefix(8))...: \(content)",
|
|
||||||
category: SecureLogger.session, level: .info)
|
|
||||||
|
|
||||||
// Mark this event as processed to avoid duplicates on app restart
|
// Mark this event as processed to avoid duplicates on app restart
|
||||||
let eventTimestamp = Date(timeIntervalSince1970: TimeInterval(giftWrap.created_at))
|
let eventTimestamp = Date(timeIntervalSince1970: TimeInterval(giftWrap.created_at))
|
||||||
@@ -457,8 +447,6 @@ class MessageRouter: ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func handleDeliveryAcknowledgment(messageId: String, from senderPubkey: String) {
|
private func handleDeliveryAcknowledgment(messageId: String, from senderPubkey: String) {
|
||||||
SecureLogger.log("✅ Received delivery acknowledgment for message \(messageId) from \(senderPubkey)",
|
|
||||||
category: SecureLogger.session, level: .info)
|
|
||||||
|
|
||||||
// Find the sender's Noise public key
|
// Find the sender's Noise public key
|
||||||
guard let senderNoiseKey = findNoisePublicKey(for: senderPubkey) else { return }
|
guard let senderNoiseKey = findNoisePublicKey(for: senderPubkey) else { return }
|
||||||
@@ -475,8 +463,6 @@ class MessageRouter: ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func handleReadReceipt(_ receipt: ReadReceipt, from senderPubkey: String) {
|
private func handleReadReceipt(_ receipt: ReadReceipt, from senderPubkey: String) {
|
||||||
SecureLogger.log("📖 Received read receipt for message \(receipt.originalMessageID) from \(senderPubkey)",
|
|
||||||
category: SecureLogger.session, level: .info)
|
|
||||||
|
|
||||||
// Find the sender's Noise public key
|
// Find the sender's Noise public key
|
||||||
guard let senderNoiseKey = findNoisePublicKey(for: senderPubkey) else { return }
|
guard let senderNoiseKey = findNoisePublicKey(for: senderPubkey) else { return }
|
||||||
@@ -499,8 +485,6 @@ class MessageRouter: ObservableObject {
|
|||||||
to recipientNoisePublicKey: Data,
|
to recipientNoisePublicKey: Data,
|
||||||
preferredTransport: Transport? = nil
|
preferredTransport: Transport? = nil
|
||||||
) async throws {
|
) async throws {
|
||||||
SecureLogger.log("📖 Sending read receipt for message \(originalMessageID)",
|
|
||||||
category: SecureLogger.session, level: .info)
|
|
||||||
|
|
||||||
// Get nickname from delegate or use default
|
// Get nickname from delegate or use default
|
||||||
let nickname = (meshService.delegate as? ChatViewModel)?.nickname ?? "Anonymous"
|
let nickname = (meshService.delegate as? ChatViewModel)?.nickname ?? "Anonymous"
|
||||||
|
|||||||
@@ -74,8 +74,6 @@ final class ProcessedMessagesService {
|
|||||||
lastProcessedTimestamp = Date(timeIntervalSince1970: timestampInterval)
|
lastProcessedTimestamp = Date(timeIntervalSince1970: timestampInterval)
|
||||||
}
|
}
|
||||||
|
|
||||||
SecureLogger.log("📋 Loaded \(processedMessageIDs.count) processed message IDs, last timestamp: \(lastProcessedTimestamp?.description ?? "nil")",
|
|
||||||
category: SecureLogger.session, level: .info)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private func saveProcessedMessages() {
|
private func saveProcessedMessages() {
|
||||||
|
|||||||
@@ -229,7 +229,7 @@ extension SecureLogger {
|
|||||||
/// Log key management operations
|
/// Log key management operations
|
||||||
static func logKeyOperation(_ operation: String, keyType: String, success: Bool = true,
|
static func logKeyOperation(_ operation: String, keyType: String, success: Bool = true,
|
||||||
file: String = #file, line: Int = #line, function: String = #function) {
|
file: String = #file, line: Int = #line, function: String = #function) {
|
||||||
let level: LogLevel = success ? .info : .error
|
let level: LogLevel = success ? .debug : .error
|
||||||
log("Key operation '\(operation)' for \(keyType) \(success ? "succeeded" : "failed")",
|
log("Key operation '\(operation)' for \(keyType) \(success ? "succeeded" : "failed")",
|
||||||
category: keychain, level: level, file: file, line: line, function: function)
|
category: keychain, level: level, file: file, line: line, function: function)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -217,12 +217,6 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
let cancellable = peerManager?.$peers
|
let cancellable = peerManager?.$peers
|
||||||
.receive(on: DispatchQueue.main)
|
.receive(on: DispatchQueue.main)
|
||||||
.sink { [weak self] peers in
|
.sink { [weak self] peers in
|
||||||
SecureLogger.log("📱 UI: Received \(peers.count) peers from PeerManager",
|
|
||||||
category: SecureLogger.session, level: .info)
|
|
||||||
for peer in peers {
|
|
||||||
SecureLogger.log(" - \(peer.displayName): connected=\(peer.isConnected), state=\(peer.connectionState)",
|
|
||||||
category: SecureLogger.session, level: .debug)
|
|
||||||
}
|
|
||||||
// Update peers directly
|
// Update peers directly
|
||||||
self?.allPeers = peers
|
self?.allPeers = peers
|
||||||
// Update peer index for O(1) lookups
|
// Update peer index for O(1) lookups
|
||||||
@@ -464,8 +458,6 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
|
|
||||||
let isFavorite = currentStatus?.isFavorite ?? false
|
let isFavorite = currentStatus?.isFavorite ?? false
|
||||||
|
|
||||||
SecureLogger.log("📊 Current favorite status for \(peerID): isFavorite=\(isFavorite), isMutual=\(currentStatus?.isMutual ?? false)",
|
|
||||||
category: SecureLogger.session, level: .info)
|
|
||||||
|
|
||||||
if isFavorite {
|
if isFavorite {
|
||||||
// Remove from favorites
|
// Remove from favorites
|
||||||
@@ -614,8 +606,6 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
if let currentPeerID = getCurrentPeerIDForFingerprint(chatFingerprint) {
|
if let currentPeerID = getCurrentPeerIDForFingerprint(chatFingerprint) {
|
||||||
// Update the selected peer if it's different
|
// Update the selected peer if it's different
|
||||||
if let oldPeerID = selectedPrivateChatPeer, oldPeerID != currentPeerID {
|
if let oldPeerID = selectedPrivateChatPeer, oldPeerID != currentPeerID {
|
||||||
SecureLogger.log("📱 Updating private chat peer from \(oldPeerID) to \(currentPeerID)",
|
|
||||||
category: SecureLogger.session, level: .debug)
|
|
||||||
|
|
||||||
// Migrate messages from old peer ID to new peer ID
|
// Migrate messages from old peer ID to new peer ID
|
||||||
if let oldMessages = privateChats[oldPeerID] {
|
if let oldMessages = privateChats[oldPeerID] {
|
||||||
@@ -797,8 +787,6 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
} else if let favoriteStatus = FavoritesPersistenceService.shared.getFavoriteStatus(for: noiseKey),
|
} else if let favoriteStatus = FavoritesPersistenceService.shared.getFavoriteStatus(for: noiseKey),
|
||||||
favoriteStatus.isMutual {
|
favoriteStatus.isMutual {
|
||||||
// Mutual favorite offline - send via Nostr
|
// Mutual favorite offline - send via Nostr
|
||||||
SecureLogger.log("🌐 Sending private message to offline mutual favorite \(recipientNickname) via Nostr",
|
|
||||||
category: SecureLogger.session, level: .info)
|
|
||||||
|
|
||||||
Task {
|
Task {
|
||||||
do {
|
do {
|
||||||
@@ -938,8 +926,6 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
migratedMessages.append(contentsOf: messages)
|
migratedMessages.append(contentsOf: messages)
|
||||||
oldPeerIDsToRemove.append(oldPeerID)
|
oldPeerIDsToRemove.append(oldPeerID)
|
||||||
|
|
||||||
SecureLogger.log("📦 Migrating \(messages.count) messages from old peer ID \(oldPeerID) to \(peerID) based on fingerprint match",
|
|
||||||
category: SecureLogger.session, level: .info)
|
|
||||||
} else if currentFingerprint == nil || oldFingerprint == nil {
|
} else if currentFingerprint == nil || oldFingerprint == nil {
|
||||||
// Fallback: use nickname matching only if we don't have fingerprints
|
// Fallback: use nickname matching only if we don't have fingerprints
|
||||||
// This is less reliable but handles legacy data
|
// This is less reliable but handles legacy data
|
||||||
@@ -1052,10 +1038,8 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
guard let messageId = notification.userInfo?["messageId"] as? String,
|
guard let messageId = notification.userInfo?["messageId"] as? String,
|
||||||
let senderNoiseKey = notification.userInfo?["senderNoiseKey"] as? Data else { return }
|
let senderNoiseKey = notification.userInfo?["senderNoiseKey"] as? Data else { return }
|
||||||
|
|
||||||
let senderHexId = senderNoiseKey.hexEncodedString()
|
let _ = senderNoiseKey.hexEncodedString()
|
||||||
|
|
||||||
SecureLogger.log("✅ Handling delivery acknowledgment for message \(messageId) from \(senderHexId)",
|
|
||||||
category: SecureLogger.session, level: .info)
|
|
||||||
|
|
||||||
// Update the delivery status for the message
|
// Update the delivery status for the message
|
||||||
if let index = messages.firstIndex(where: { $0.id == messageId }) {
|
if let index = messages.firstIndex(where: { $0.id == messageId }) {
|
||||||
|
|||||||
Reference in New Issue
Block a user