Crate entidb_sync_server

Crate entidb_sync_server 

Source
Expand description

§EntiDB Sync Server

Reference HTTP sync server for EntiDB.

This crate provides:

  • HTTP endpoints (handshake, pull, push)
  • Server oplog persistence
  • Authentication middleware (HMAC-SHA256 tokens)
  • Conflict detection

§Architecture

The sync server uses the same EntiDB core as clients (no external database). It maintains:

  • A server-side oplog of all operations
  • Current cursor position for each device
  • Authentication state

§Authentication

Authentication is optional but recommended for production:

use entidb_sync_server::{ServerConfig, AuthConfig, TokenValidator};

let secret = b"my-secure-secret-32-bytes-long!".to_vec();
let config = ServerConfig::default().with_auth(secret.clone());

// Create tokens for devices
let auth_config = AuthConfig::new(secret);
let validator = TokenValidator::new(auth_config);
let token = validator.create_token(device_id, db_id);

§Protocol

The server implements pull-then-push synchronization:

  1. Client handshakes with device credentials (+ auth token if enabled)
  2. Client pulls changes since last cursor
  3. Client pushes local changes
  4. Server detects conflicts and applies policy

Structs§

AuthConfig
Authentication configuration.
HandlerContext
Context for request handling.
RequestHandler
Handler for sync requests.
ServerConfig
Configuration for the sync server.
ServerOplog
Server-side operation log.
SimpleTokenValidator
Simple token validator that doesn’t check expiration. Useful for testing.
SyncServer
The sync server.
TokenValidator
Token validator for incoming requests.

Enums§

ServerError
Errors that can occur in the sync server.

Type Aliases§

ServerResult
Result type for server operations.