Module document_sync

Module document_sync 

Source
Expand description

Document synchronization for HIVE BLE mesh

This module provides centralized document state management for HIVE-Lite nodes. It manages the local CRDT state (GCounter) and handles merging with received documents.

§Design Notes

This implementation uses a simple GCounter for resource-constrained devices (ESP32, smartwatches). For full HIVE nodes using AutomergeIroh, this component can be replaced or extended - the observer pattern and BLE transport layer are independent of the document format.

§Usage

use hive_btle::document_sync::DocumentSync;
use hive_btle::NodeId;

let sync = DocumentSync::new(NodeId::new(0x12345678), "SOLDIER-1");

// Trigger an emergency
let doc_bytes = sync.send_emergency();
// ... broadcast doc_bytes over BLE

// Handle received document
if let Some(result) = sync.merge_document(&received_data) {
    if result.is_emergency() {
        println!("EMERGENCY from {:08X}", result.source_node.as_u32());
    }
}

Structs§

DocumentCheck
Result from checking if a document contains an emergency
DocumentSync
Document synchronization manager for HIVE-Lite nodes