mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-26 08:05:21 +00:00
* wip * woohooo * Plumtree gossip: don't subset REQUEST_SYNC fanout; make RequestSyncPacket.encode use const * bloom -> gcs [wip] * fix build * fix broadcast * prune old messages too * faster sync * prune better * adjust parameters * fix(sync): make cap a constant in GCSFilter.buildFilter to silence 'never mutated' warning * fix(mesh): surface self-origin public messages recovered via sync; only ignore self when TTL != 0 in handleMessage * sync: allow self messages via GCS restore and relax TTL==0 acceptance\n- Bypass dedup for self TTL==0 packets in handleReceivedPacket\n- Accept self TTL==0 in handleMessage and set nickname\n- Accept unknown senders for TTL==0 with anon# prefix to restore history --------- Co-authored-by: jack <jackjackbits@users.noreply.github.com>
22 lines
758 B
Swift
22 lines
758 B
Swift
import Foundation
|
|
import CryptoKit
|
|
|
|
// Deterministic packet ID used for gossip sync membership
|
|
// ID = first 16 bytes of SHA-256 over: [type | senderID | timestamp | payload]
|
|
enum PacketIdUtil {
|
|
static func computeId(_ packet: BitchatPacket) -> Data {
|
|
var hasher = SHA256()
|
|
hasher.update(data: Data([packet.type]))
|
|
hasher.update(data: packet.senderID)
|
|
var tsBE = packet.timestamp.bigEndian
|
|
withUnsafeBytes(of: &tsBE) { raw in hasher.update(data: Data(raw)) }
|
|
hasher.update(data: packet.payload)
|
|
let digest = hasher.finalize()
|
|
return Data(digest.prefix(16))
|
|
}
|
|
|
|
static func computeIdHex(_ packet: BitchatPacket) -> String {
|
|
return computeId(packet).hexEncodedString()
|
|
}
|
|
}
|