diff options
| author | tv <tv@krebsco.de> | 2026-10-21 03:22:55 +0200 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-10-21 03:22:55 +0200 |
| commit | 215735c94b57fc190ec2adc77f9af500c00f0d41 (patch) | |
| tree | 3f3313c2ba03eab41b9bc25af148e812b2c58637 /src | |
| parent | 13d3fa4ca2d50b61cab8a9410d097f93797defce (diff) | |
reorganize all the modules
Diffstat (limited to 'src')
| -rw-r--r-- | src/api/auth.rs (renamed from src/auth.rs) | 0 | ||||
| -rw-r--r-- | src/api/debug.rs | 2 | ||||
| -rw-r--r-- | src/api/mod.rs | 5 | ||||
| -rw-r--r-- | src/api/peers.rs | 6 | ||||
| -rw-r--r-- | src/api/store.rs | 4 | ||||
| -rw-r--r-- | src/compaction/api.rs | 2 | ||||
| -rw-r--r-- | src/compaction/catchup.rs | 2 | ||||
| -rw-r--r-- | src/compaction/coordinator.rs | 2 | ||||
| -rw-r--r-- | src/compaction/delta.rs | 2 | ||||
| -rw-r--r-- | src/compaction/local.rs | 2 | ||||
| -rw-r--r-- | src/compaction/mod.rs | 4 | ||||
| -rw-r--r-- | src/compaction/quarantine.rs | 2 | ||||
| -rw-r--r-- | src/compaction/records.rs | 4 | ||||
| -rw-r--r-- | src/compaction/snapshot.rs | 4 | ||||
| -rw-r--r-- | src/compaction/switch.rs | 6 | ||||
| -rw-r--r-- | src/document/mod.rs | 5 | ||||
| -rw-r--r-- | src/document/replica.rs (renamed from src/replica.rs) | 0 | ||||
| -rw-r--r-- | src/document/store.rs (renamed from src/store.rs) | 0 | ||||
| -rw-r--r-- | src/main.rs | 19 | ||||
| -rw-r--r-- | src/state.rs | 8 | ||||
| -rw-r--r-- | src/swarm/bootstrap.rs (renamed from src/bootstrap.rs) | 2 | ||||
| -rw-r--r-- | src/swarm/mod.rs | 6 | ||||
| -rw-r--r-- | src/swarm/peer.rs (renamed from src/peer.rs) | 6 | ||||
| -rw-r--r-- | src/swarm/sync.rs (renamed from src/sync.rs) | 2 | ||||
| -rw-r--r-- | src/transport/firewall.rs (renamed from src/firewall.rs) | 0 | ||||
| -rw-r--r-- | src/transport/mod.rs (renamed from src/transport.rs) | 5 | ||||
| -rw-r--r-- | src/transport/mycelium.rs (renamed from src/mycelium.rs) | 0 |
27 files changed, 55 insertions, 45 deletions
diff --git a/src/auth.rs b/src/api/auth.rs index 3926c70..3926c70 100644 --- a/src/auth.rs +++ b/src/api/auth.rs diff --git a/src/api/debug.rs b/src/api/debug.rs index 3c24f62..929d665 100644 --- a/src/api/debug.rs +++ b/src/api/debug.rs @@ -5,8 +5,8 @@ use std::collections::HashSet; use axum::{body::Bytes, extract::State, http::StatusCode, Json}; use tracing::{info, warn}; -use crate::firewall::FirewallRules; use crate::state::AppState; +use crate::transport::firewall::FirewallRules; pub(crate) async fn get_debug_firewall(State(state): State<AppState>) -> Json<FirewallRules> { Json(state.firewall.rules()) diff --git a/src/api/mod.rs b/src/api/mod.rs index 98400c7..ac6f2d0 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -1,5 +1,6 @@ //! HTTP API: router, OpenAPI document and shared response helpers. +pub(crate) mod auth; mod debug; mod peers; mod store; @@ -19,9 +20,9 @@ use tracing::{error, warn}; use utoipa::OpenApi; use utoipa_swagger_ui::SwaggerUi; -use crate::auth::{basic_auth, AuthState}; +use crate::api::auth::{basic_auth, AuthState}; +use crate::document::store::StoreError; use crate::state::AppState; -use crate::store::StoreError; /// Builds the complete HTTP router. Everything except Swagger is authenticated. pub(crate) fn router(state: AppState, auth_state: AuthState, debug_api: bool) -> Router { diff --git a/src/api/peers.rs b/src/api/peers.rs index b12e3bf..5308eb9 100644 --- a/src/api/peers.rs +++ b/src/api/peers.rs @@ -14,10 +14,10 @@ use tracing::warn; use utoipa::ToSchema; use super::store_status; -use crate::peer::forgotten_path; -use crate::replica::Epoch; +use crate::document::replica::Epoch; +use crate::document::store; use crate::state::{unix_millis, AppState, HelloState, Liveness, PeerMembership, PeerState}; -use crate::store; +use crate::swarm::peer::forgotten_path; #[derive(Debug, Serialize, ToSchema)] #[serde(rename_all = "lowercase")] diff --git a/src/api/store.rs b/src/api/store.rs index e991005..8ea0202 100644 --- a/src/api/store.rs +++ b/src/api/store.rs @@ -17,9 +17,9 @@ use tokio::sync::broadcast; use tracing::{debug, error, instrument}; use super::{parse_key_path, response_for_value, store_status}; +use crate::document::store::{self, StoreError}; use crate::state::{AppState, ReadSource}; -use crate::store::{self, StoreError}; -use crate::sync::paths_related; +use crate::swarm::sync::paths_related; #[derive(Debug, Default, Deserialize)] pub(crate) struct ReadQuery { diff --git a/src/compaction/api.rs b/src/compaction/api.rs index 21cdf7b..f972809 100644 --- a/src/compaction/api.rs +++ b/src/compaction/api.rs @@ -40,7 +40,7 @@ use super::records::{ self, unix_millis, AbortRequest, EpochRecord, Phase, Policy, Proposal, Record, Retention, }; use super::Host; -use crate::store::StoreError; +use crate::document::store::StoreError; #[derive(Debug, Default, Deserialize)] pub(crate) struct WaitQuery { diff --git a/src/compaction/catchup.rs b/src/compaction/catchup.rs index d8bac74..5085669 100644 --- a/src/compaction/catchup.rs +++ b/src/compaction/catchup.rs @@ -37,7 +37,7 @@ use super::local::{CatchUp, LocalStatus, Quarantined, Rejoin}; use super::records::unix_millis; use super::snapshot::{self, EpochMetadata}; use super::Host; -use crate::replica::Epoch; +use crate::document::replica::Epoch; /// Pause before trying the same target again after a failed rejoin. const RETRY: Duration = Duration::from_secs(30); diff --git a/src/compaction/coordinator.rs b/src/compaction/coordinator.rs index 1b41faf..8ce3928 100644 --- a/src/compaction/coordinator.rs +++ b/src/compaction/coordinator.rs @@ -23,7 +23,7 @@ use tracing::{info, warn}; use super::records::{self, Decision, Record}; use super::snapshot; use super::Host; -use crate::store::StoreError; +use crate::document::store::StoreError; const TICK: Duration = Duration::from_secs(1); diff --git a/src/compaction/delta.rs b/src/compaction/delta.rs index ba04799..cf556b2 100644 --- a/src/compaction/delta.rs +++ b/src/compaction/delta.rs @@ -23,7 +23,7 @@ use automerge::{ActorId, AutoCommit, ChangeHash, PatchAction, Prop}; use tracing::warn; use super::snapshot::{COMPACTIONS, EPOCHS, META_ROOT}; -use crate::store::{self, StoreError}; +use crate::document::store::{self, StoreError}; #[derive(Debug, Default, Clone, Copy)] pub(crate) struct ReplayStats { diff --git a/src/compaction/local.rs b/src/compaction/local.rs index c798a4c..ec40b06 100644 --- a/src/compaction/local.rs +++ b/src/compaction/local.rs @@ -14,7 +14,7 @@ use tokio::time::Instant; use super::records::{unix_millis, Retention}; use super::snapshot::Snapshot; -use crate::replica::Epoch; +use crate::document::replica::Epoch; #[derive(Default)] pub(crate) struct Compaction { diff --git a/src/compaction/mod.rs b/src/compaction/mod.rs index e3cdf55..5322058 100644 --- a/src/compaction/mod.rs +++ b/src/compaction/mod.rs @@ -38,8 +38,8 @@ use axum::{ }; use tokio::sync::broadcast; -use crate::replica::Epoch; -use crate::sync::ChangeSet; +use crate::document::replica::Epoch; +use crate::swarm::sync::ChangeSet; /// What compaction needs from the node. Implemented by `AppState`. /// diff --git a/src/compaction/quarantine.rs b/src/compaction/quarantine.rs index da39ec0..ad3c616 100644 --- a/src/compaction/quarantine.rs +++ b/src/compaction/quarantine.rs @@ -28,7 +28,7 @@ use super::api::error_response; use super::delta; use super::local::Quarantined; use super::Host; -use crate::store; +use crate::document::store; #[derive(Debug, Serialize)] #[serde(rename_all = "camelCase")] diff --git a/src/compaction/records.rs b/src/compaction/records.rs index ccd52c3..f533ee2 100644 --- a/src/compaction/records.rs +++ b/src/compaction/records.rs @@ -20,8 +20,8 @@ use serde::{Deserialize, Serialize}; use tracing::warn; use super::snapshot::{SnapshotRequest, COMPACTIONS, META_ROOT}; -use crate::replica::Epoch; -use crate::store::{self, StoreError}; +use crate::document::replica::Epoch; +use crate::document::store::{self, StoreError}; /// One day, for retention defaults. const DAY_SECS: u64 = 24 * 60 * 60; diff --git a/src/compaction/snapshot.rs b/src/compaction/snapshot.rs index 0a89e23..0d49d48 100644 --- a/src/compaction/snapshot.rs +++ b/src/compaction/snapshot.rs @@ -29,8 +29,8 @@ use serde_json::{json, Map as JsonMap, Value as JsonValue}; use sha2::{Digest, Sha256}; use super::records::{EpochRecord, Policy}; -use crate::replica::Epoch; -use crate::store::{self, StoreError}; +use crate::document::replica::Epoch; +use crate::document::store::{self, StoreError}; pub(crate) const META_ROOT: &str = "_continuum"; pub(crate) const COMPACTIONS: &str = "compactions"; diff --git a/src/compaction/switch.rs b/src/compaction/switch.rs index 24bcee0..67ff471 100644 --- a/src/compaction/switch.rs +++ b/src/compaction/switch.rs @@ -30,9 +30,9 @@ use super::local::LocalStatus; use super::records::{self, unix_millis, EpochRecord, Record}; use super::snapshot::{self, COMPACTIONS, META_ROOT}; use super::Host; -use crate::replica::Epoch; -use crate::store; -use crate::sync::paths_related; +use crate::document::replica::Epoch; +use crate::document::store; +use crate::swarm::sync::paths_related; const TICK: Duration = Duration::from_secs(1); diff --git a/src/document/mod.rs b/src/document/mod.rs new file mode 100644 index 0000000..ce24815 --- /dev/null +++ b/src/document/mod.rs @@ -0,0 +1,5 @@ +//! The replicated document: the replica with its epoch, and the store semantics +//! (merged-view paths over JSON) the HTTP API and remakes work with. + +pub mod replica; +pub mod store; diff --git a/src/replica.rs b/src/document/replica.rs index 4579029..4579029 100644 --- a/src/replica.rs +++ b/src/document/replica.rs diff --git a/src/store.rs b/src/document/store.rs index 1815635..1815635 100644 --- a/src/store.rs +++ b/src/document/store.rs diff --git a/src/main.rs b/src/main.rs index c98596b..1793523 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,23 +19,18 @@ use tracing::{debug, error, info, trace}; use url::Url; mod api; -mod auth; -mod bootstrap; mod compaction; -mod firewall; -mod mycelium; -mod peer; -mod replica; +mod document; mod state; -mod store; -mod sync; +mod swarm; mod transport; -use auth::AuthState; -use firewall::{Firewall, FirewallTransport}; -use mycelium::{MyceliumSetup, MyceliumSpawnConfig}; -use replica::{Epoch, Replica}; +use api::auth::AuthState; +use document::replica::{Epoch, Replica}; use state::{AppState, NodeLifecycle, Timing}; +use swarm::{bootstrap, peer, sync}; +use transport::firewall::{Firewall, FirewallTransport}; +use transport::mycelium::{self, MyceliumSetup, MyceliumSpawnConfig}; use transport::Transport; #[derive(Parser, Debug)] diff --git a/src/state.rs b/src/state.rs index 9db5ce9..0f981e6 100644 --- a/src/state.rs +++ b/src/state.rs @@ -13,10 +13,10 @@ use tokio::time::Instant; use tracing::{debug, error, warn}; use crate::compaction::{Compaction, Host, PeerSummary}; -use crate::firewall::Firewall; -use crate::replica::{Epoch, Replica}; -use crate::sync::{ChangeSet, SyncEvent}; +use crate::document::replica::{Epoch, Replica}; +use crate::swarm::sync::{ChangeSet, SyncEvent}; use crate::transport; +use crate::transport::firewall::Firewall; #[derive(Debug, Clone, PartialEq, Eq)] pub(crate) enum NodeLifecycle { @@ -539,7 +539,7 @@ impl AppState { // Tell peers about the new epoch now instead of with the next keepalive (up to a // keepalive interval later): sync with peers already on it resumes right away, // and peers that never saw the commit start catching up. - let keepalive = crate::peer::local_keepalive(self).await; + let keepalive = crate::swarm::peer::local_keepalive(self).await; for (id, _) in &peers { if let Err(error) = self .transport diff --git a/src/bootstrap.rs b/src/swarm/bootstrap.rs index d3ac94d..2907e93 100644 --- a/src/bootstrap.rs +++ b/src/swarm/bootstrap.rs @@ -7,8 +7,8 @@ use anyhow::{bail, Result}; use tracing::{debug, error, info, warn}; use uuid::Uuid; -use crate::peer::{remember_peer, send_hello_once}; use crate::state::{AppState, PeerMembership}; +use crate::swarm::peer::{remember_peer, send_hello_once}; const BOOTSTRAP_TIMEOUT: Duration = Duration::from_secs(300); const BOOTSTRAP_RETRY: Duration = Duration::from_millis(500); diff --git a/src/swarm/mod.rs b/src/swarm/mod.rs new file mode 100644 index 0000000..7316146 --- /dev/null +++ b/src/swarm/mod.rs @@ -0,0 +1,6 @@ +//! The swarm of peers: bootstrap, handshake, keepalive and dormancy (`peer`), and +//! Automerge synchronization with every member (`sync`). + +pub(crate) mod bootstrap; +pub(crate) mod peer; +pub(crate) mod sync; diff --git a/src/peer.rs b/src/swarm/peer.rs index d27cda8..eb97a7e 100644 --- a/src/peer.rs +++ b/src/swarm/peer.rs @@ -11,10 +11,10 @@ use tokio::sync::Mutex; use tokio::time::{Instant, MissedTickBehavior}; use tracing::{debug, info, instrument, trace, warn}; -use crate::replica::{Epoch, EpochRelation}; +use crate::document::replica::{Epoch, EpochRelation}; +use crate::document::store::{self, StoreError}; use crate::state::{AppState, HelloState, Liveness, PeerMembership, PeerState}; -use crate::store::{self, StoreError}; -use crate::sync::{handle_sync, SyncEvent}; +use crate::swarm::sync::{handle_sync, SyncEvent}; use crate::transport::{self, ParsedMessage}; const HELLO_RETRY_INITIAL: Duration = Duration::from_secs(1); diff --git a/src/sync.rs b/src/swarm/sync.rs index 9db4b40..115d5c0 100644 --- a/src/sync.rs +++ b/src/swarm/sync.rs @@ -12,8 +12,8 @@ use tokio::sync::mpsc; use tokio::time::Instant; use tracing::{debug, info, trace, warn}; -use crate::peer::{peer_cluster, send_hello_once}; use crate::state::{AppState, Liveness, PeerMembership, PeerState, PendingOutbound}; +use crate::swarm::peer::{peer_cluster, send_hello_once}; use crate::transport::{self, ParsedMessage}; const INITIAL_SYNC_RETRY: Duration = Duration::from_millis(500); diff --git a/src/firewall.rs b/src/transport/firewall.rs index 917fe5f..917fe5f 100644 --- a/src/firewall.rs +++ b/src/transport/firewall.rs diff --git a/src/transport.rs b/src/transport/mod.rs index 9cfb026..6accf81 100644 --- a/src/transport.rs +++ b/src/transport/mod.rs @@ -5,7 +5,10 @@ use std::boxed::Box; use std::future::Future; use std::pin::Pin; -pub use crate::replica::Epoch; +pub use crate::document::replica::Epoch; + +pub mod firewall; +pub mod mycelium; pub type HeadsDigest = [u8; 32]; diff --git a/src/mycelium.rs b/src/transport/mycelium.rs index 3a08b76..3a08b76 100644 --- a/src/mycelium.rs +++ b/src/transport/mycelium.rs |
