Simulation: Give user chance to use bridges each day
This commit is contained in:
parent
d9aa616d77
commit
6b6836dbae
|
@ -26,6 +26,9 @@ pub struct User {
|
|||
|
||||
// Does the user submit reports to Troll Patrol?
|
||||
submits_reports: bool,
|
||||
|
||||
// How likely is this user to use bridges on a given day?
|
||||
prob_use_bridges: f64,
|
||||
}
|
||||
|
||||
impl User {
|
||||
|
@ -63,12 +66,17 @@ impl User {
|
|||
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 {
|
||||
censor: censor,
|
||||
country: cc,
|
||||
primary_cred: cred,
|
||||
secondary_cred: None,
|
||||
submits_reports: submits_reports,
|
||||
prob_use_bridges: prob_use_bridges,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -127,12 +135,17 @@ impl User {
|
|||
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 {
|
||||
censor: censor,
|
||||
country: cc,
|
||||
primary_cred: friend_cred,
|
||||
secondary_cred: None,
|
||||
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
|
||||
// contacted bridges.
|
||||
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
|
||||
// (We assume that this step can be done even if the user can't actually
|
||||
// talk to the LA.)
|
||||
|
@ -187,7 +204,8 @@ impl User {
|
|||
|
||||
// Can we level up the main credential?
|
||||
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);
|
||||
|
||||
// Can we migrate the main credential?
|
||||
|
@ -288,7 +306,8 @@ impl User {
|
|||
let cred = trust_migration(
|
||||
&state.net,
|
||||
&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_migration_pub(&state.la_pubkeys),
|
||||
)
|
||||
|
@ -354,5 +373,8 @@ impl User {
|
|||
}
|
||||
|
||||
(new_friends, connections)
|
||||
} else {
|
||||
(Vec::<User>::new(), Vec::<[u8; 20]>::new())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue