Prechádzať zdrojové kódy

peer: only parse default dist config once

Justin Tracey 10 mesiacov pred
rodič
commit
95f8f9011b
2 zmenil súbory, kde vykonal 9 pridanie a 7 odobranie
  1. 3 3
      src/bin/messenger/dists.rs
  2. 6 4
      src/bin/mgen-peer.rs

+ 3 - 3
src/bin/messenger/dists.rs

@@ -13,7 +13,7 @@ use tokio::time::Duration;
 /// The set of Distributions we currently support for message sizes (in padding blocks).
 /// To modify the code to add support for more, one approach is to first add them here,
 /// then fix all the compiler errors and warnings that arise as a result.
-#[derive(Debug)]
+#[derive(Clone, Debug)]
 pub enum MessageDistribution {
     // Poisson is only defined for floats for technical reasons.
     // https://rust-random.github.io/book/guide-dist.html#integers
@@ -40,7 +40,7 @@ impl Distribution<u32> for MessageDistribution {
 /// The set of Distributions we currently support for timings.
 /// To modify the code to add support for more, one approach is to first add them here,
 /// then fix all the compiler errors and warnings that arise as a result.
-#[derive(Debug)]
+#[derive(Clone, Debug)]
 pub enum TimingDistribution {
     Normal(Normal<f64>),
     LogNormal(LogNormal<f64>),
@@ -65,7 +65,7 @@ impl Distribution<f64> for TimingDistribution {
 }
 
 /// The set of distributions necessary to represent the actions of the state machine.
-#[derive(Debug)]
+#[derive(Clone, Debug)]
 pub struct Distributions {
     pub m: MessageDistribution,
     pub i: TimingDistribution,

+ 6 - 4
src/bin/mgen-peer.rs

@@ -327,6 +327,8 @@ fn process_config(
         retry: f64,
     }
 
+    let default_dists: Distributions = config.distributions.try_into()?;
+
     // map from `recipient` to things the (user, recipient) reader/writer threads will need
     let mut recipient_map = HashMap::<String, ForIoThreads>::new();
     for conversation in config.conversations.into_iter() {
@@ -376,10 +378,10 @@ fn process_config(
             );
         }
 
-        let distributions: Distributions = conversation
-            .distributions
-            .unwrap_or_else(|| config.distributions.clone())
-            .try_into()?;
+        let distributions: Distributions = match conversation.distributions {
+            Some(dists) => dists.try_into()?,
+            None => default_dists.clone(),
+        };
         let bootstrap = conversation.bootstrap.unwrap_or(config.bootstrap);
 
         tokio::spawn(manage_conversation(