docs/sync.md
This document specifies the gossip-based synchronization feature for BitChat, inspired by Plumtree. It ensures eventual consistency of public packets (ANNOUNCE and broadcast MESSAGE) across nodes via periodic sync requests containing a compact Golomb‑Coded Set (GCS) of recently seen packets.
This synchronization is strictly local (not relayed), ensuring only immediate neighbors participate and preventing wide-area flooding while converging content across the mesh.
To compare packets across peers, a deterministic packet ID is used:
Implementation: com.bitchat.android.sync.PacketIdUtil.
Implementation: com.bitchat.android.sync.GCSFilter.
min(N_max, maxPacketsPerSync) items from this ordered list.Hashing scheme (fixed for cross‑impl compatibility):
MessageType: REQUEST_SYNC (0x21)
Notes:
Encode/Decode implementation: com.bitchat.android.model.RequestSyncPacket.
Sender behavior:
Receiver behavior:
ttl=0 to the requester only.Announcement retention and pruning (consensus):
Important: original packets are sent unmodified to preserve original signatures (e.g., ANNOUNCE). They MUST NOT be relayed beyond immediate neighbors. Implementations SHOULD send these response packets with TTL=0 (local-only) and, when possible, route them only to the requesting peer without altering the original packet contents.
Included in sync:
MessageType.MESSAGE with BROADCAST recipient (or null recipient).MessageType.ANNOUNCE.Not included:
Exposed under “sync settings” in the debug settings sheet:
Backed by DebugPreferenceManager getters and setters:
getSeenPacketCapacity / setSeenPacketCapacitygetGcsMaxFilterBytes / setGcsMaxFilterBytesgetGcsFprPercent / setGcsFprPercentMessageType.REQUEST_SYNC (0x21) in BinaryProtocol.ktRequestSyncPacket in model/RequestSyncPacket.ktGCSFilter and PacketIdUtil in sync/GossipSyncManager in sync/BluetoothMeshService wires and starts the sync manager, schedules per-peer initial (unicast) and periodic (broadcast) syncs, and forwards seen public packets (including our own) to the manager.PacketProcessor handles REQUEST_SYNC and forwards to BluetoothMeshService which responds via the sync manager with responses targeted only to the requester.The following items require consensus across all implementations to ensure interoperability:
The following are requester‑defined and communicated or local policy (no global agreement required):
Validation and limits (recommended):
Versioning: