Simulation: Give user chance to use bridges each day

This commit is contained in:
Vecna 2024-05-21 22:35:42 -04:00
parent d9aa616d77
commit 6b6836dbae
1 changed files with 175 additions and 153 deletions

View File

@ -26,6 +26,9 @@ pub struct User {
// Does the user submit reports to Troll Patrol? // Does the user submit reports to Troll Patrol?
submits_reports: bool, submits_reports: bool,
// How likely is this user to use bridges on a given day?
prob_use_bridges: f64,
} }
impl User { impl User {
@ -63,12 +66,17 @@ impl User {
cc cc
}; };
// Randomly determine how likely this user is to use bridges on
// a given day
let prob_use_bridges = rng.gen_range(0.0..=1.0);
Self { Self {
censor: censor, censor: censor,
country: cc, country: cc,
primary_cred: cred, primary_cred: cred,
secondary_cred: None, secondary_cred: None,
submits_reports: submits_reports, submits_reports: submits_reports,
prob_use_bridges: prob_use_bridges,
} }
} }
@ -127,12 +135,17 @@ impl User {
cc cc
}; };
// Randomly determine how likely this user is to use bridges on
// a given day
let prob_use_bridges = rng.gen_range(0.0..=1.0);
Ok(Self { Ok(Self {
censor: censor, censor: censor,
country: cc, country: cc,
primary_cred: friend_cred, primary_cred: friend_cred,
secondary_cred: None, secondary_cred: None,
submits_reports: submits_reports, submits_reports: submits_reports,
prob_use_bridges: prob_use_bridges,
}) })
} }
@ -179,6 +192,10 @@ impl User {
// newly invited friends and a vector of fingerprints of successfully // newly invited friends and a vector of fingerprints of successfully
// contacted bridges. // contacted bridges.
pub async fn daily_tasks(&mut self, state: &State) -> (Vec<User>, Vec<[u8; 20]>) { pub async fn daily_tasks(&mut self, state: &State) -> (Vec<User>, Vec<[u8; 20]>) {
// Probabilistically decide if the user should use bridges today
let mut rng = rand::thread_rng();
let num: f64 = rng.gen_range(0.0..1.0);
if num < self.prob_use_bridges {
// Download bucket to see if bridge is still reachable // Download bucket to see if bridge is still reachable
// (We assume that this step can be done even if the user can't actually // (We assume that this step can be done even if the user can't actually
// talk to the LA.) // talk to the LA.)
@ -187,7 +204,8 @@ impl User {
// Can we level up the main credential? // Can we level up the main credential?
let can_level_up = reachcred.is_some() let can_level_up = reachcred.is_some()
&& (level == 0 && eligible_for_trust_promotion(&state.net, &self.primary_cred).await && (level == 0
&& eligible_for_trust_promotion(&state.net, &self.primary_cred).await
|| level > 0 && eligible_for_level_up(&state.net, &self.primary_cred).await); || level > 0 && eligible_for_level_up(&state.net, &self.primary_cred).await);
// Can we migrate the main credential? // Can we migrate the main credential?
@ -288,7 +306,8 @@ impl User {
let cred = trust_migration( let cred = trust_migration(
&state.net, &state.net,
&second_cred, &second_cred,
&trust_promotion(&state.net, &second_cred, get_lox_pub(&state.la_pubkeys)).await, &trust_promotion(&state.net, &second_cred, get_lox_pub(&state.la_pubkeys))
.await,
get_lox_pub(&state.la_pubkeys), get_lox_pub(&state.la_pubkeys),
get_migration_pub(&state.la_pubkeys), get_migration_pub(&state.la_pubkeys),
) )
@ -354,5 +373,8 @@ impl User {
} }
(new_friends, connections) (new_friends, connections)
} else {
(Vec::<User>::new(), Vec::<[u8; 20]>::new())
}
} }
} }