From 9ef9ef8056eb45a35782f909bb832171fae6b9c7 Mon Sep 17 00:00:00 2001 From: jack Date: Fri, 4 Jul 2025 16:07:49 +0200 Subject: [PATCH] Fix timestamp bug causing peer discovery failures - Fixed BitchatPacket convenience initializer to use milliseconds (was using seconds) - Fixed BitchatMessage binary encoding to use milliseconds for consistency - Updated decoding logic to properly handle millisecond timestamps - This resolves the issue where packets were being dropped due to timestamp validation failures All timestamps are now consistently in milliseconds throughout the codebase. --- bitchat/Protocols/BinaryProtocol.swift | 10 +++++----- bitchat/Protocols/BitchatProtocol.swift | 2 +- bitchat/Services/BluetoothMeshService.swift | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bitchat/Protocols/BinaryProtocol.swift b/bitchat/Protocols/BinaryProtocol.swift index fc8013ed..e781ae01 100644 --- a/bitchat/Protocols/BinaryProtocol.swift +++ b/bitchat/Protocols/BinaryProtocol.swift @@ -196,11 +196,11 @@ extension BitchatMessage { data.append(flags) - // Timestamp - let timestampSeconds = UInt64(timestamp.timeIntervalSince1970) + // Timestamp (in milliseconds) + let timestampMillis = UInt64(timestamp.timeIntervalSince1970 * 1000) // Encode as 8 bytes, big-endian for i in (0..<8).reversed() { - data.append(UInt8((timestampSeconds >> (i * 8)) & 0xFF)) + data.append(UInt8((timestampMillis >> (i * 8)) & 0xFF)) } // ID @@ -290,11 +290,11 @@ extension BitchatMessage { return nil } let timestampData = dataCopy[offset.. 300000 { // 5 minutes in milliseconds - print("[SECURITY] Dropping packet with timestamp too far from current time: \(timeDiff/1000) seconds") + print("[SECURITY] Dropping packet from \(peerID) type:\(packet.type) - timestamp diff: \(timeDiff/1000)s (packet:\(packet.timestamp) vs current:\(currentTime))") return }