// db_sync.h — Distributed content-addressed table with LMDB storage and peer sync via etcp_router #ifndef DB_SYNC_H #define DB_SYNC_H #include #include struct UTUN_INSTANCE; // etcp_router service ID #define ETCP_RT_ID_DB_SYNC 0x20 // Message types #define DB_MSG_INIT_SYNC 0x01 #define DB_MSG_INIT_RESP 0x02 #define DB_MSG_REFINE 0x03 #define DB_MSG_SEND_DATA 0x04 #define DB_MSG_PUSH 0x05 #define DB_MSG_ACK_PUSH 0x06 #define DB_MSG_SYNC_DONE 0x07 // Defaults #define DB_SYNC_DEFAULT_TTL 86400 #define DB_SYNC_DEFAULT_MAPSIZE (100UL * 1024 * 1024) #define DB_SYNC_PEER_CHECK_INTERVAL 5 #define DB_SYNC_TTL_INTERVAL 3600 // Record flags #define DB_REC_FLAG_WAS_SENT 0x01 // Sync protocol constants #define DB_REFINE_HASHES 16 #define DB_SEND_DATA_MAX 32 int db_sync_init(struct UTUN_INSTANCE* inst); void db_sync_destroy(struct UTUN_INSTANCE* inst); int db_sync_insert(struct UTUN_INSTANCE* inst, const char* json_data); int db_sync_insert_len(struct UTUN_INSTANCE* inst, const char* json_data, size_t len); uint32_t db_sync_count(struct UTUN_INSTANCE* inst); #endif // DB_SYNC_H