Browse Source

Add option to restrict positive reports to 1 per bridge per cred

Vecna 9 months ago
parent
commit
bbf582078a
3 changed files with 13 additions and 2 deletions
  1. 2 0
      src/bin/simulation.rs
  2. 10 2
      src/simulation/censor.rs
  3. 1 0
      src/simulation/config.rs

+ 2 - 0
src/bin/simulation.rs

@@ -55,6 +55,7 @@ pub struct Config {
     pub num_days: u32,
     // We start with this many level 4 users
     pub num_initial_trusted_users: u32,
+    pub one_positive_report_per_cred: bool,
     pub prob_connection_fails: f64,
     pub prob_user_invites_friend: f64,
     pub prob_user_is_censor: f64,
@@ -98,6 +99,7 @@ pub async fn main() {
         censor_totality: config.censor_totality,
         censor_partial_blocking_percent: config.censor_partial_blocking_percent,
         country: config.country,
+        one_positive_report_per_cred: config.one_positive_report_per_cred,
         prob_connection_fails: config.prob_connection_fails,
         prob_user_invites_friend: config.prob_user_invites_friend,
         prob_user_is_censor: config.prob_user_is_censor,

+ 10 - 2
src/simulation/censor.rs

@@ -97,6 +97,7 @@ impl Censor {
                     || config.censor_speed == Speed::Random && self.delay_date <= get_date()
                 {
                     let bridge = bridges.get_mut(fingerprint).unwrap();
+
                     let mut rng = rand::thread_rng();
                     let num_connections = rng.gen_range(1000..30000);
 
@@ -107,11 +108,18 @@ impl Censor {
                     // positive reports
                     if self.has_lox_cred(fingerprint) {
                         let lox_pub = get_lox_pub(&config.la_pubkeys);
-                        for _ in 0..num_connections {
+                        let (cred, cred_count) =
+                            &self.lox_credentials.get(&bridge.fingerprint).unwrap();
+                        let num_prs = if config.one_positive_report_per_cred {
+                            *cred_count
+                        } else {
+                            rng.gen_range(1000..30000)
+                        };
+                        for _ in 0..num_prs {
                             let pr = PositiveReport::from_lox_credential(
                                 bridge.fingerprint,
                                 None,
-                                &self.lox_credentials.get(&bridge.fingerprint).unwrap().0,
+                                cred,
                                 lox_pub,
                                 config.country.clone(),
                             )

+ 1 - 0
src/simulation/config.rs

@@ -16,6 +16,7 @@ pub struct Config {
     // We model only one country at a time because Lox assumes censors
     // share information with each other.
     pub country: String,
+    pub one_positive_report_per_cred: bool,
     // Probability that a connection randomly fails, even though censor
     // does not block the bridge
     pub prob_connection_fails: f64,