mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 19:05:20 +00:00
Fix Noise handshake failures and implement binary protocol migration
- Fix asymmetric handshake state causing message delivery failures - Prevent duplicate handshake init messages from disrupting ongoing handshakes - Add defensive copying to all binary decoders to prevent thread safety issues - Implement binary encoding for all 9 message types (60-80% bandwidth reduction) - Fix delivery ACK decoding for Noise encrypted messages - Add comprehensive logging for debugging handshake and message flow - Fix race condition in delivery status updates - Add relay logic for handshake packets to ensure mesh delivery - Maintain backward compatibility with JSON fallback
This commit is contained in:
@@ -207,6 +207,11 @@ class NoiseEncryptionService {
|
||||
return sessionManager.getSession(for: peerID)?.isEstablished() ?? false
|
||||
}
|
||||
|
||||
/// Check if we have a session (established or handshaking) with a peer
|
||||
func hasSession(with peerID: String) -> Bool {
|
||||
return sessionManager.getSession(for: peerID) != nil
|
||||
}
|
||||
|
||||
// MARK: - Encryption/Decryption
|
||||
|
||||
/// Encrypt data for a specific peer
|
||||
@@ -471,11 +476,14 @@ struct NoiseMessage: Codable {
|
||||
}
|
||||
|
||||
static func fromBinaryData(_ data: Data) -> NoiseMessage? {
|
||||
// Create defensive copy
|
||||
let dataCopy = Data(data)
|
||||
|
||||
var offset = 0
|
||||
|
||||
guard let type = data.readUInt8(at: &offset),
|
||||
let sessionID = data.readUUID(at: &offset),
|
||||
let payload = data.readData(at: &offset) else { return nil }
|
||||
guard let type = dataCopy.readUInt8(at: &offset),
|
||||
let sessionID = dataCopy.readUUID(at: &offset),
|
||||
let payload = dataCopy.readData(at: &offset) else { return nil }
|
||||
|
||||
guard let messageType = NoiseMessageType(rawValue: type) else { return nil }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user