From 29b2030edf46ece4ff252df8b7c12c7b524ef567 Mon Sep 17 00:00:00 2001 From: Marc Brinkmann Date: Mon, 27 Aug 2018 18:06:50 +0200 Subject: [PATCH] Partial docs. --- tests/net/mod.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/net/mod.rs b/tests/net/mod.rs index 14ac1b7..2f9e30b 100644 --- a/tests/net/mod.rs +++ b/tests/net/mod.rs @@ -110,22 +110,31 @@ impl Node { } } +/// A network message on the virtual network. // Note: We do not use `messaging::TargetedMessage` and `messaging::SourceMessage` here, since we // the nesting is inconvenient and we do not want to support broadcasts at this level. #[derive(Clone, Debug)] pub struct NetworkMessage { + /// Message sender. from: N, + /// Destined receiver. to: N, + /// The actual message contents. payload: M, } impl NetworkMessage { + /// Create a new network message. + #[inline] fn new(from: N, payload: M, to: N) -> NetworkMessage { NetworkMessage { from, to, payload } } } +/// Mapping from node IDs to actual node instances. pub type NodeMap = collections::BTreeMap<::NodeUid, Node>; + +/// A virtual network message tied to a distributed algorithm. pub type NetMessage = NetworkMessage<::Message, ::NodeUid>; @@ -161,9 +170,10 @@ where .is_faulty(); let mut message_count: usize = 0; - // First, queue all messages for processing. + // Queue all messages for processing. for tmsg in step.messages.iter() { match &tmsg.target { + /// Single target message. messaging::Target::Node(to) => { if !faulty { message_count = message_count.saturating_add(1); @@ -175,6 +185,7 @@ where to.clone(), )); } + /// Broadcast messages get expanded into multiple direct messages. messaging::Target::All => for to in nodes.keys() { if *to == sender { continue; @@ -203,12 +214,16 @@ where message_count } +/// Virtual network builder. pub struct NetBuilder where D: DistAlgorithm, { + /// Iterator used to create node ids. node_ids: I, + /// Number of faulty nodes in the network. num_faulty: usize, + /// Constructor function. cons: Option) -> (D, Step)>>, adversary: Option>>, trace: Option,