summaryrefslogtreecommitdiffstats
path: root/src/node.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/node.rs')
-rw-r--r--src/node.rs24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/node.rs b/src/node.rs
index 57ee302..8e4ace7 100644
--- a/src/node.rs
+++ b/src/node.rs
@@ -24,12 +24,18 @@ use crate::swarm::sync::SyncEvent;
use crate::swarm::{self, peer, sync};
use crate::transport::Transport;
use crate::transport::firewall::{Firewall, FirewallTransport};
+use crate::transport::identity::{IdentityConfig, IdentityTransport};
use crate::transport::traffic::{CountingTransport, Traffic};
/// What a node is built from.
pub(crate) struct NodeConfig {
- /// The node's transport, without the counting and firewall layers (added here).
+ /// The node's transport, without the identity, counting and firewall layers (added
+ /// here).
pub(crate) transport: Arc<dyn Transport>,
+ /// The node key and the transport's address scheme: the transport goes under the
+ /// identity layer (`transport::identity`), and the node is its node ID. Without it
+ /// (simulations only), the node is its transport identity.
+ pub(crate) identity: Option<IdentityConfig>,
pub(crate) initial_epoch: Epoch,
pub(crate) initial_doc: AutoCommit,
/// Actors this node wrote with in earlier runs (`--document-file`).
@@ -66,6 +72,14 @@ impl Node {
let firewall = Arc::new(Firewall::default());
let traffic = Arc::new(Traffic::default());
let initial_actor = config.initial_doc.get_actor().clone();
+ let transport = match config.identity {
+ Some(identity) => Arc::new(IdentityTransport::new(
+ config.transport,
+ identity,
+ Arc::clone(&traffic),
+ )) as Arc<dyn Transport>,
+ None => config.transport,
+ };
let replica = Replica::new(config.initial_epoch, config.initial_doc);
let stamp = replica.stamps();
@@ -78,12 +92,10 @@ impl Node {
})),
peer_states: Arc::new(RwLock::new(HashMap::new())),
// Counted outside the firewall: what it drops outbound counts as sent (it
- // plays a lossy network), what it drops inbound never arrived.
+ // plays a lossy network), what it drops inbound never arrived. Both above
+ // the identity layer, so by node ID.
transport: Arc::new(CountingTransport::new(
- Arc::new(FirewallTransport::new(
- config.transport,
- Arc::clone(&firewall),
- )),
+ Arc::new(FirewallTransport::new(transport, Arc::clone(&firewall))),
Arc::clone(&traffic),
)),
firewall,