mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 01:05:19 +00:00
Sync cleanups: normalize SyncTypeFlags, single announce-ID path, TODO (#1373)
Follow-ups deferred from the REQUEST_SYNC review (#1371): - SyncTypeFlags.init(rawValue:) now masks to the union of bits that map to a known message type (derived from the bit↔type table, so it tracks new types automatically). Phantom bits from a truncated/garbled flags field — or a type a newer peer added — no longer live in the set as membership no contains() matches yet toData() re-serializes. - GossipSyncManager stored each latest announce as (hex-id string, packet) and diffed announces against the stored string while every other type recomputed the ID via PacketIdUtil. Collapsed the store to just the packet and recompute the ID everywhere, removing the latent dual-path divergence. - Documented the REQUEST_SYNC TLV table and marked fragmentIdFilter (0x06) with a TODO(v2): it's parsed/re-serialized but never populated or honored (reserved for incremental fragment sync) — finish or drop, not silent dead surface. Adds SyncTypeFlags phantom-bit/round-trip tests and a GossipSyncManager test that an announce already in the requester's filter is suppressed (guards the recompute path). Full suite: 1034 tests pass. Co-authored-by: jack <jackjackbits@users.noreply.github.com> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
jack
Claude Opus 4.8
parent
7341696280
commit
c2a5668569
@@ -7,9 +7,25 @@ struct SyncTypeFlags: OptionSet {
|
||||
let rawValue: UInt64
|
||||
|
||||
init(rawValue: UInt64) {
|
||||
self.rawValue = rawValue & 0x00FF_FFFF_FFFF_FFFF // Trim to max 8 bytes
|
||||
// Drop any bit that doesn't map to a known message type. Wire data can
|
||||
// carry up to 8 bytes of flags; without this mask, bits with no type
|
||||
// (a truncated/garbled field, or a type a newer peer added) would live
|
||||
// in the set as phantom membership that no `contains` check matches and
|
||||
// `toData` re-serializes — a meaningless "accepted but does nothing"
|
||||
// state. Masking here keeps every instance normalized at the source.
|
||||
self.rawValue = rawValue & SyncTypeFlags.knownTypeMask
|
||||
}
|
||||
|
||||
/// Union of every bit that maps to a message type. Derived from the
|
||||
/// bit↔type table so it tracks automatically when a type is added.
|
||||
private static let knownTypeMask: UInt64 = {
|
||||
var mask: UInt64 = 0
|
||||
for bit in 0..<64 where SyncTypeFlags.type(forBit: bit) != nil {
|
||||
mask |= (1 << UInt64(bit))
|
||||
}
|
||||
return mask
|
||||
}()
|
||||
|
||||
private static func bitIndex(for type: MessageType) -> Int? {
|
||||
switch type {
|
||||
case .announce: return 0
|
||||
|
||||
Reference in New Issue
Block a user