diff options
| author | tv <tv@krebsco.de> | 2026-10-27 01:31:58 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-10-27 01:31:58 +0100 |
| commit | 4cdece6d0f8e25ac154c3fd0f30bca604b08c16a (patch) | |
| tree | 10a6aab1793d1c4fd0bd53c16b600f1adf986cb9 /src/simtest/mod.rs | |
| parent | 5fd686dcd8ddfbdf276c044e5acf03f744e03193 (diff) | |
add identity layer
Diffstat (limited to 'src/simtest/mod.rs')
| -rw-r--r-- | src/simtest/mod.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/simtest/mod.rs b/src/simtest/mod.rs index 531d1c6..4d7374a 100644 --- a/src/simtest/mod.rs +++ b/src/simtest/mod.rs @@ -10,6 +10,7 @@ //! (all nodes interleaved; messages name peers by ID). mod deltas; +mod identity; mod remakes; mod soak; mod timing; @@ -26,10 +27,12 @@ use tokio::time::Instant; use crate::document::replica::Epoch; use crate::document::store; use crate::files::Files; +use crate::identity::NodeKey; use crate::locks::RwLockExt; use crate::node::{self, Node, NodeConfig}; use crate::state::{AppState, PeerState, Timing}; use crate::swarm::bootstrap::{self, Start}; +use crate::transport::identity::IdentityConfig; use crate::transport::sim::SimNet; /// Keepalive of simulated nodes: dormancy after 1 s, probes of dormant peers every @@ -45,6 +48,9 @@ pub(crate) const DELIVERY_LIMIT: Duration = Duration::from_secs(3); /// A simulated swarm: the net and the nodes started on it. pub(crate) struct Sim { pub(crate) net: SimNet, + /// Nodes under the identity layer (`transport::identity`), named by node IDs; else + /// by their names on the net. + identity: bool, /// Every node started, for the description of a failed wait. nodes: std::sync::Mutex<Vec<(String, AppState)>>, } @@ -54,10 +60,20 @@ impl Sim { init_logging(); Self { net: SimNet::new(seed), + identity: false, nodes: Default::default(), } } + /// [`new`](Self::new), with every node under the identity layer: its key derived + /// from its name, its node ID as `local_id`. + pub(crate) fn with_identity(seed: u64) -> Self { + Self { + identity: true, + ..Self::new(seed) + } + } + /// Starts node `id` with the test defaults: builds it, starts its workers, and /// bootstraps it in the background (through `seeds`, other nodes' IDs). Returns at /// once; [`wait_ready`] waits for it. @@ -75,6 +91,10 @@ impl Sim { ) -> AppState { let mut config = NodeConfig { transport: self.net.transport(id), + identity: self.identity.then(|| IdentityConfig { + key: Arc::new(sim_key(id)), + scheme: "sim", + }), initial_epoch: Epoch::GENESIS, initial_doc: AutoCommit::new(), earlier_actors: Vec::new(), @@ -239,6 +259,12 @@ impl Sim { } } +/// The node key of simulated node `id`. +pub(crate) fn sim_key(id: &str) -> NodeKey { + use sha2::Digest; + NodeKey::from_seed(sha2::Sha256::digest(id.as_bytes()).into()) +} + fn path(path: &str) -> Vec<String> { path.split('/').map(str::to_owned).collect() } |
