浏览代码

add required user default parameters

Justin Tracey 9 月之前
父节点
当前提交
c9e1287cd9

+ 40 - 35
README.md

@@ -64,53 +64,58 @@ user: "Alice"
 # Optional.
 socks: "127.0.0.1:9050"
 
-# The list of conversations associated with the user.
-conversations:
+# The <address>:<port> of the message server,
+# where <address> is an IP, onion address, or hostname.
+# Can override in the conversation settings.
+message_server: "server.maybe.onion:6397"
 
-  # A conversation name used for logs, server-side lookups,
-  # and unique circuits for each conversation,
-  # even when two chats share the same participants.
-  - group: "group1"
+# Similarly, but for the web server (must include protocol).
+web_server: "https://server.maybe.onion:6398"
 
-    # The <address>:<port> of the message server,
-    # where <address> is an IP, onion address, or hostname.
-    message_server: "server.maybe.onion:6397"
+# The number of seconds to wait until the client starts sending messages.
+# This should be long enough that all clients have had time to start
+# (sending messages to a client that isn't registered on the server is a
+# fatal error), but short enough all conversations will have started by
+# the experiment start.
+# Can override in the conversation settings.
+bootstrap: 5.0
 
-    # Similarly, but for the web server (must include protocol).
-    web_server: "https://server.maybe.onion:6398"
+# The number of seconds to wait after a network failure before retrying.
+# Can override in the conversation settings.
+retry: 5.0
 
-    # The number of seconds to wait until the client starts sending messages.
-    # This should be long enough that all clients have had time to start
-    # (sending messages to a client that isn't registered on the server is a
-    # fatal error), but short enough all conversations will have started by
-    # the experiment start.
-    bootstrap: 5.0
 
-    # The number of seconds to wait after a network failure before retrying.
-    retry: 5.0
+# Parameters for distributions used by the Markov model.
+# Can override in the conversation settings.
+distributions:
 
+  # Probability of Idle to Active transition with sent/received messages.
+  s: 0.5
+  r: 0.1
 
-    # Parameters for distributions used by the Markov model.
-    distributions:
+  # The distribution of message sizes, as measured in padding blocks.
+  m: { distribution: "Poisson", lambda: 1.0 }
 
-      # Probability of Idle to Active transition with sent/received messages.
-      s: 0.5
-      r: 0.1
+  # Distribution I, the amount of time Idle before sending a message.
+  i: { distribution: "Normal", mean: 30.0, std_dev: 100.0 }
 
-      # The distribution of message sizes, as measured in padding blocks.
-      m: { distribution: "Poisson", lambda: 1.0 }
+  # Distribution W, the amount of time Active without sending or receiving
+  # messages to transition to Idle.
+  w: { distribution: "Uniform", low: 0.0, high: 90.0 }
 
-      # Distribution I, the amount of time Idle before sending a message.
-      i: { distribution: "Normal", mean: 30.0, std_dev: 100.0 }
+  # Distribution A_{s/r}, the time Active since last sent/received
+  # message until the client sends a message.
+  a_s: { distribution: "Exp", lambda: 2.0 }
+  a_r: { distribution: "Pareto", scale: 1.0, shape: 3.0 }
 
-      # Distribution W, the amount of time Active without sending or receiving
-      # messages to transition to Idle.
-      w: { distribution: "Uniform", low: 0.0, high: 90.0 }
+# The list of conversations associated with the user.
+conversations:
 
-      # Distribution A_{s/r}, the time Active since last sent/received
-      # message until the client sends a message.
-      a_s: { distribution: "Exp", lambda: 2.0 }
-      a_r: { distribution: "Pareto", scale: 1.0, shape: 3.0 }
+  # A conversation name used for logs, server-side lookups,
+  # and unique circuits for each conversation,
+  # even when two chats share the same participants.
+  - group: "group1"
+    # Most of the global settings can be overridden here.
 ```
 
 Additional examples can be found in the [client shadow test configurations](/shadow/client/shadow.data.template/hosts).

+ 12 - 17
shadow/client/shadow.data.template/hosts/client1/alice.yaml

@@ -1,21 +1,16 @@
 user: "Alice"
+message_server: "server:6397"
+web_server: "https://web:6398"
+bootstrap: 5.0
+retry: 5.0
+distributions:
+  s: 0.5
+  r: 0.1
+  m: { distribution: "Poisson", lambda: 1.0 }
+  i: { distribution: "Normal", mean: 15.0, std_dev: 30.0 }
+  w: { distribution: "Normal", mean: 30.0, std_dev: 30.0 }
+  a_s: { distribution: "Normal", mean: 10.0, std_dev: 5.0 }
+  a_r: { distribution: "Normal", mean: 10.0, std_dev: 5.0 }
 conversations:
   - group: "group1"
-    message_server: "server:6397"
-    web_server: "https://web:6398"
-    bootstrap: 5.0
-    retry: 5.0
-    distributions: &dists
-      s: 0.5
-      r: 0.1
-      m: { distribution: "Poisson", lambda: 1.0 }
-      i: { distribution: "Normal", mean: 15.0, std_dev: 30.0 }
-      w: { distribution: "Normal", mean: 30.0, std_dev: 30.0 }
-      a_s: { distribution: "Normal", mean: 10.0, std_dev: 5.0 }
-      a_r: { distribution: "Normal", mean: 10.0, std_dev: 5.0 }
   - group: "group2"
-    message_server: "server:6397"
-    web_server: "https://web:6398"
-    bootstrap: 5.0
-    retry: 5.0
-    distributions: *dists

+ 12 - 17
shadow/client/shadow.data.template/hosts/client2/bob.yaml

@@ -1,21 +1,16 @@
 user: "Bob"
+message_server: "server:6397"
+web_server: "https://web:6398"
+bootstrap: 5.0
+retry: 5.0
+distributions: &dists
+  s: 0.5
+  r: 0.1
+  m: { distribution: "Binomial", n: 28, p: 0.5 }
+  i: { distribution: "Normal", mean: 15.0, std_dev: 30.0 }
+  w: { distribution: "Normal", mean: 30.0, std_dev: 30.0 }
+  a_s: { distribution: "Normal", mean: 10.0, std_dev: 5.0 }
+  a_r: { distribution: "Normal", mean: 10.0, std_dev: 5.0 }
 conversations:
   - group: "group1"
-    message_server: "server:6397"
-    web_server: "https://web:6398"
-    bootstrap: 5.0
-    retry: 5.0
-    distributions: &dists
-      s: 0.5
-      r: 0.1
-      m: { distribution: "Binomial", n: 28, p: 0.5 }
-      i: { distribution: "Normal", mean: 15.0, std_dev: 30.0 }
-      w: { distribution: "Normal", mean: 30.0, std_dev: 30.0 }
-      a_s: { distribution: "Normal", mean: 10.0, std_dev: 5.0 }
-      a_r: { distribution: "Normal", mean: 10.0, std_dev: 5.0 }
   - group: "group2"
-    message_server: "server:6397"
-    web_server: "https://web:6398"
-    bootstrap: 5.0
-    retry: 5.0
-    distributions: *dists

+ 12 - 12
shadow/client/shadow.data.template/hosts/client2/carol.yaml

@@ -1,15 +1,15 @@
 user: "Carol"
+message_server: "server:6397"
+web_server: "https://web:6398"
+bootstrap: 5.0
+retry: 5.0
+distributions:
+  s: 0.5
+  r: 0.1
+  m: { distribution: "Poisson", lambda: 1.0 }
+  i: { distribution: "Normal", mean: 15.0, std_dev: 30.0 }
+  w: { distribution: "Normal", mean: 30.0, std_dev: 30.0 }
+  a_s: { distribution: "Normal", mean: 10.0, std_dev: 5.0 }
+  a_r: { distribution: "Normal", mean: 10.0, std_dev: 5.0 }
 conversations:
   - group: "group1"
-    message_server: "server:6397"
-    web_server: "https://web:6398"
-    bootstrap: 5.0
-    retry: 5.0
-    distributions:
-      s: 0.5
-      r: 0.1
-      m: { distribution: "Poisson", lambda: 1.0 }
-      i: { distribution: "Normal", mean: 15.0, std_dev: 30.0 }
-      w: { distribution: "Normal", mean: 30.0, std_dev: 30.0 }
-      a_s: { distribution: "Normal", mean: 10.0, std_dev: 5.0 }
-      a_r: { distribution: "Normal", mean: 10.0, std_dev: 5.0 }

+ 12 - 12
shadow/client/shadow.data.template/hosts/client3/dave.yaml

@@ -1,15 +1,15 @@
 user: "Dave"
+message_server: "server:6397"
+web_server: "https://web:6398"
+bootstrap: 5.0
+retry: 5.0
+distributions:
+  s: 0.5
+  r: 0.1
+  m: { distribution: "Poisson", lambda: 1.0 }
+  i: { distribution: "Normal", mean: 15.0, std_dev: 30.0 }
+  w: { distribution: "Normal", mean: 30.0, std_dev: 30.0 }
+  a_s: { distribution: "Normal", mean: 10.0, std_dev: 5.0 }
+  a_r: { distribution: "Normal", mean: 10.0, std_dev: 5.0 }
 conversations:
   - group: "group2"
-    message_server: "server:6397"
-    web_server: "https://web:6398"
-    bootstrap: 5.0
-    retry: 5.0
-    distributions:
-      s: 0.5
-      r: 0.1
-      m: { distribution: "Poisson", lambda: 1.0 }
-      i: { distribution: "Normal", mean: 15.0, std_dev: 30.0 }
-      w: { distribution: "Normal", mean: 30.0, std_dev: 30.0 }
-      a_s: { distribution: "Normal", mean: 10.0, std_dev: 5.0 }
-      a_r: { distribution: "Normal", mean: 10.0, std_dev: 5.0 }

+ 10 - 13
shadow/peer/shadow.data.template/hosts/peer1/alice.yaml

@@ -1,19 +1,16 @@
 user: "Alice"
+bootstrap: 5.0
+retry: 5.0
+distributions:
+  s: 0.5
+  r: 0.1
+  m: { distribution: "Poisson", lambda: 1.0 }
+  i: { distribution: "Normal", mean: 15.0, std_dev: 30.0 }
+  w: { distribution: "Normal", mean: 30.0, std_dev: 30.0 }
+  a_s: { distribution: "Normal", mean: 10.0, std_dev: 5.0 }
+  a_r: { distribution: "Normal", mean: 10.0, std_dev: 5.0 }
 conversations:
   - group: "group1"
     recipients: ["Bob", "Carol"]
-    bootstrap: 5.0
-    retry: 5.0
-    distributions: &dists
-      s: 0.5
-      r: 0.1
-      m: { distribution: "Poisson", lambda: 1.0 }
-      i: { distribution: "Normal", mean: 15.0, std_dev: 30.0 }
-      w: { distribution: "Normal", mean: 30.0, std_dev: 30.0 }
-      a_s: { distribution: "Normal", mean: 10.0, std_dev: 5.0 }
-      a_r: { distribution: "Normal", mean: 10.0, std_dev: 5.0 }
   - group: "group2"
     recipients: ["Bob", "Dave"]
-    bootstrap: 5.0
-    retry: 5.0
-    distributions: *dists

+ 10 - 13
shadow/peer/shadow.data.template/hosts/peer2/bob.yaml

@@ -1,19 +1,16 @@
 user: "Bob"
+bootstrap: 5.0
+retry: 5.0
+distributions: &dists
+  s: 0.5
+  r: 0.1
+  m: { distribution: "Poisson", lambda: 1.0 }
+  i: { distribution: "Normal", mean: 15.0, std_dev: 30.0 }
+  w: { distribution: "Normal", mean: 30.0, std_dev: 30.0 }
+  a_s: { distribution: "Normal", mean: 10.0, std_dev: 5.0 }
+  a_r: { distribution: "Normal", mean: 10.0, std_dev: 5.0 }
 conversations:
   - group: "group1"
     recipients: ["Alice", "Carol"]
-    bootstrap: 5.0
-    retry: 5.0
-    distributions: &dists
-      s: 0.5
-      r: 0.1
-      m: { distribution: "Poisson", lambda: 1.0 }
-      i: { distribution: "Normal", mean: 15.0, std_dev: 30.0 }
-      w: { distribution: "Normal", mean: 30.0, std_dev: 30.0 }
-      a_s: { distribution: "Normal", mean: 10.0, std_dev: 5.0 }
-      a_r: { distribution: "Normal", mean: 10.0, std_dev: 5.0 }
   - group: "group2"
     recipients: ["Alice", "Dave"]
-    bootstrap: 5.0
-    retry: 5.0
-    distributions: *dists

+ 10 - 10
shadow/peer/shadow.data.template/hosts/peer2/carol.yaml

@@ -1,14 +1,14 @@
 user: "Carol"
+bootstrap: 5.0
+retry: 5.0
+distributions:
+  s: 0.5
+  r: 0.1
+  m: { distribution: "Poisson", lambda: 1.0 }
+  i: { distribution: "Normal", mean: 15.0, std_dev: 30.0 }
+  w: { distribution: "Normal", mean: 30.0, std_dev: 30.0 }
+  a_s: { distribution: "Normal", mean: 10.0, std_dev: 5.0 }
+  a_r: { distribution: "Normal", mean: 10.0, std_dev: 5.0 }
 conversations:
   - group: "group1"
     recipients: ["Alice", "Bob"]
-    bootstrap: 5.0
-    retry: 5.0
-    distributions:
-      s: 0.5
-      r: 0.1
-      m: { distribution: "Poisson", lambda: 1.0 }
-      i: { distribution: "Normal", mean: 15.0, std_dev: 30.0 }
-      w: { distribution: "Normal", mean: 30.0, std_dev: 30.0 }
-      a_s: { distribution: "Normal", mean: 10.0, std_dev: 5.0 }
-      a_r: { distribution: "Normal", mean: 10.0, std_dev: 5.0 }

+ 10 - 10
shadow/peer/shadow.data.template/hosts/peer3/dave.yaml

@@ -1,14 +1,14 @@
 user: "Dave"
+bootstrap: 5.0
+retry: 5.0
+distributions:
+  s: 0.5
+  r: 0.1
+  m: { distribution: "Poisson", lambda: 1.0 }
+  i: { distribution: "Normal", mean: 15.0, std_dev: 30.0 }
+  w: { distribution: "Normal", mean: 30.0, std_dev: 30.0 }
+  a_s: { distribution: "Normal", mean: 10.0, std_dev: 5.0 }
+  a_r: { distribution: "Normal", mean: 10.0, std_dev: 5.0 }
 conversations:
   - group: "group2"
     recipients: ["Alice", "Bob"]
-    bootstrap: 5.0
-    retry: 5.0
-    distributions:
-      s: 0.5
-      r: 0.1
-      m: { distribution: "Poisson", lambda: 1.0 }
-      i: { distribution: "Normal", mean: 15.0, std_dev: 30.0 }
-      w: { distribution: "Normal", mean: 30.0, std_dev: 30.0 }
-      a_s: { distribution: "Normal", mean: 10.0, std_dev: 5.0 }
-      a_r: { distribution: "Normal", mean: 10.0, std_dev: 5.0 }

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

@@ -83,7 +83,7 @@ impl TimingDistribution {
 }
 
 /// The same as Distributions, but designed for easier deserialization.
-#[derive(Debug, Deserialize)]
+#[derive(Clone, Debug, Deserialize)]
 pub struct ConfigDistributions {
     m: ConfigMessageDistribution,
     i: ConfigTimingDistribution,
@@ -95,7 +95,7 @@ pub struct ConfigDistributions {
 }
 
 /// The same as MessageDistribution, but designed for easier deserialization.
-#[derive(Debug, Deserialize)]
+#[derive(Clone, Debug, Deserialize)]
 #[serde(tag = "distribution")]
 enum ConfigMessageDistribution {
     Poisson {
@@ -119,7 +119,7 @@ enum ConfigMessageDistribution {
 }
 
 /// The same as TimingDistribution, but designed for easier deserialization.
-#[derive(Debug, Deserialize)]
+#[derive(Clone, Debug, Deserialize)]
 #[serde(tag = "distribution")]
 enum ConfigTimingDistribution {
     Normal { mean: f64, std_dev: f64 },

+ 43 - 16
src/bin/mgen-client.rs

@@ -325,25 +325,21 @@ async fn socket_updater(
 /// The thread responsible for handling the conversation state
 /// (i.e., whether the user is active or idle, and when to send messages).
 /// Spawns all other threads for this conversation.
-async fn manage_conversation(
-    user: String,
-    socks: Option<String>,
-    config: ConversationConfig,
-) -> Result<(), MessengerError> {
+async fn manage_conversation(config: FullConfig) -> Result<(), MessengerError> {
     let mut rng = Xoshiro256PlusPlus::from_entropy();
     let distributions: Distributions = config.distributions.try_into()?;
 
     let message_server_params = SocksParams {
-        socks: socks.clone(),
+        socks: config.socks.clone(),
         target: config.message_server,
-        user: user.clone(),
+        user: config.user.clone(),
         recipient: config.group.clone(),
     };
 
     let web_server_params = SocksParams {
-        socks,
+        socks: config.socks,
         target: config.web_server,
-        user: user.clone(),
+        user: config.user.clone(),
         recipient: config.group.clone(),
     };
 
@@ -405,7 +401,7 @@ async fn manage_conversation(
                     conversation,
                     &mut state_from_reader,
                     &mut state_to_writer,
-                    &user,
+                    &config.user,
                     &config.group,
                     &mut rng,
                 )
@@ -416,7 +412,7 @@ async fn manage_conversation(
                     conversation,
                     &mut state_from_reader,
                     &mut state_to_writer,
-                    &user,
+                    &config.user,
                     &config.group,
                     false,
                     &mut rng,
@@ -427,9 +423,10 @@ async fn manage_conversation(
     }
 }
 
-#[derive(Debug, Deserialize)]
-struct ConversationConfig {
+struct FullConfig {
+    user: String,
     group: String,
+    socks: Option<String>,
     message_server: String,
     web_server: String,
     bootstrap: f64,
@@ -437,10 +434,25 @@ struct ConversationConfig {
     distributions: ConfigDistributions,
 }
 
+#[derive(Debug, Deserialize)]
+struct ConversationConfig {
+    group: String,
+    message_server: Option<String>,
+    web_server: Option<String>,
+    bootstrap: Option<f64>,
+    retry: Option<f64>,
+    distributions: Option<ConfigDistributions>,
+}
+
 #[derive(Debug, Deserialize)]
 struct Config {
     user: String,
     socks: Option<String>,
+    message_server: String,
+    web_server: String,
+    bootstrap: f64,
+    retry: f64,
+    distributions: ConfigDistributions,
     conversations: Vec<ConversationConfig>,
 }
 
@@ -453,9 +465,24 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
         let yaml_s = std::fs::read_to_string(config_file?)?;
         let config: Config = serde_yaml::from_str(&yaml_s)?;
         for conversation in config.conversations.into_iter() {
-            let handle: task::JoinHandle<Result<(), MessengerError>> = tokio::spawn(
-                manage_conversation(config.user.clone(), config.socks.clone(), conversation),
-            );
+            let filled_conversation = FullConfig {
+                user: config.user.clone(),
+                group: conversation.group,
+                socks: config.socks.clone(),
+                message_server: conversation
+                    .message_server
+                    .unwrap_or_else(|| config.message_server.clone()),
+                web_server: conversation
+                    .web_server
+                    .unwrap_or_else(|| config.web_server.clone()),
+                bootstrap: conversation.bootstrap.unwrap_or(config.bootstrap),
+                retry: conversation.retry.unwrap_or(config.retry),
+                distributions: conversation
+                    .distributions
+                    .unwrap_or_else(|| config.distributions.clone()),
+            };
+            let handle: task::JoinHandle<Result<(), MessengerError>> =
+                tokio::spawn(manage_conversation(filled_conversation));
             handles.push(handle);
         }
     }

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

@@ -298,9 +298,9 @@ fn parse_hosts_file(file_contents: &str) -> HashMap<&str, &str> {
 struct ConversationConfig {
     group: String,
     recipients: Vec<String>,
-    bootstrap: f64,
-    retry: f64,
-    distributions: ConfigDistributions,
+    bootstrap: Option<f64>,
+    retry: Option<f64>,
+    distributions: Option<ConfigDistributions>,
 }
 
 #[derive(Debug, Deserialize)]
@@ -308,6 +308,9 @@ struct Config {
     user: String,
     socks: Option<String>,
     listen: Option<String>,
+    bootstrap: f64,
+    retry: f64,
+    distributions: ConfigDistributions,
     conversations: Vec<ConversationConfig>,
 }
 
@@ -355,12 +358,13 @@ fn process_config(
                         user: config.user.clone(),
                         recipient: recipient.clone(),
                     };
+                    let retry = conversation.retry.unwrap_or(config.retry);
                     ForIoThreads {
                         state_to_writer,
                         writer_from_state,
                         reader_to_states,
                         str_params,
-                        retry: conversation.retry,
+                        retry,
                     }
                 });
             let state_to_writer = for_io.state_to_writer.clone();
@@ -372,13 +376,17 @@ fn process_config(
             );
         }
 
-        let distributions: Distributions = conversation.distributions.try_into()?;
+        let distributions: Distributions = conversation
+            .distributions
+            .unwrap_or_else(|| config.distributions.clone())
+            .try_into()?;
+        let bootstrap = conversation.bootstrap.unwrap_or(config.bootstrap);
 
         tokio::spawn(manage_conversation(
             config.user.clone(),
             conversation.group,
             distributions,
-            conversation.bootstrap,
+            bootstrap,
             state_from_reader,
             conversation_recipient_map,
         ));