diff options
| author | tv <tv@krebsco.de> | 2026-10-19 23:56:33 +0200 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-10-19 23:56:33 +0200 |
| commit | 2dd4712902c63bfe393933ed165bb7481aa932ec (patch) | |
| tree | 8b66447844e643a82bd8d5df62442610d469a67b /src/main.rs | |
| parent | d3a9d5d3ebff98e342dff1df0ebad86f346719f5 (diff) | |
add epochs
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs index 9774d78..61e484e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,6 +24,7 @@ mod bootstrap; mod firewall; mod mycelium; mod peer; +mod replica; mod state; mod store; mod sync; @@ -32,6 +33,7 @@ mod transport; use auth::AuthState; use firewall::{Firewall, FirewallTransport}; use mycelium::{MyceliumSetup, MyceliumSpawnConfig}; +use replica::{Epoch, Replica}; use state::{AppState, NodeLifecycle, Timing}; use transport::Transport; @@ -80,6 +82,11 @@ struct Args { /// Keepalive interval; dormancy, resync and probe timings derive from it. #[arg(long, value_name = "SECONDS", default_value_t = 60)] keepalive_secs: u64, + + /// Test hook: start on a non-genesis epoch of this generation (with a fixed dummy + /// id), to check that nodes on different epochs refuse to sync. + #[arg(long, hide = true, requires = "debug_api", value_name = "GENERATION")] + debug_epoch: Option<u64>, } #[tokio::main] @@ -117,6 +124,16 @@ async fn main() -> Result<()> { let (change_tx, _) = watch::channel(0_u64); let (change_events, _) = broadcast::channel(256); + let initial_epoch = match args.debug_epoch { + Some(generation) => Epoch { + generation, + id: [0xee; 32], + }, + None => Epoch::GENESIS, + }; + let (epoch_tx, _) = watch::channel(initial_epoch); + info!(epoch = %initial_epoch, "Local epoch"); + let firewall = Arc::new(Firewall::default()); let mycelium_transport = @@ -124,7 +141,8 @@ async fn main() -> Result<()> { info!(local_id = mycelium_transport.local_id(), "Transport ready"); let state = AppState { - doc: Arc::new(RwLock::new(AutoCommit::new())), + doc: Arc::new(RwLock::new(Replica::new(initial_epoch, AutoCommit::new()))), + epoch_tx, lifecycle: Arc::new(RwLock::new(NodeLifecycle::Joining { discovered_cluster_id: None, })), @@ -228,3 +246,6 @@ async fn main() -> Result<()> { info!("HTTP API server stopped"); Ok(()) } + +// === Footnotes =============================================================== +// [concurrent]: these comments are in place so we remember what to do if we go from async to concurrent. |
