|
@@ -45,7 +45,7 @@ pub struct User {
|
|
|
}
|
|
|
|
|
|
impl User {
|
|
|
- pub async fn new(config: &Config) -> Result<Self, Error> {
|
|
|
+ pub async fn new(config: &Config, is_censor: bool) -> Result<Self, Error> {
|
|
|
let cred = get_lox_credential(
|
|
|
&config.la_net,
|
|
|
&get_open_invitation(&config.la_net).await?,
|
|
@@ -54,9 +54,6 @@ impl User {
|
|
|
.await?
|
|
|
.0;
|
|
|
|
|
|
- // Probabilistically decide whether this user cooperates with a censor
|
|
|
- let is_censor = event_happens(config.prob_user_is_censor);
|
|
|
-
|
|
|
// Probabilistically decide whether this user submits reports
|
|
|
let submits_reports = if is_censor {
|
|
|
false
|
|
@@ -96,7 +93,12 @@ impl User {
|
|
|
}
|
|
|
|
|
|
// TODO: This should probably return an actual error type
|
|
|
- pub async fn invite(&mut self, config: &Config, censor: &mut Censor) -> Result<Self, Error> {
|
|
|
+ pub async fn invite(
|
|
|
+ &mut self,
|
|
|
+ config: &Config,
|
|
|
+ censor: &mut Censor,
|
|
|
+ invited_user_is_censor: bool,
|
|
|
+ ) -> Result<Self, Error> {
|
|
|
let etable = get_reachability_credential(&config.la_net).await?;
|
|
|
let (new_cred, invite) = issue_invite(
|
|
|
&config.la_net,
|
|
@@ -127,13 +129,8 @@ impl User {
|
|
|
.await?
|
|
|
.0;
|
|
|
|
|
|
- // If the inviting user is a censor, the invitee will also be a
|
|
|
- // censor. If not, probabilistically decide.
|
|
|
- let is_censor = if self.is_censor {
|
|
|
- true
|
|
|
- } else {
|
|
|
- event_happens(config.prob_user_is_censor)
|
|
|
- };
|
|
|
+ // Calling function decides if the invited user is a censor
|
|
|
+ let is_censor = invited_user_is_censor;
|
|
|
|
|
|
// Probabilistically decide whether this user submits reports
|
|
|
let submits_reports = if is_censor {
|
|
@@ -254,14 +251,21 @@ impl User {
|
|
|
&mut self,
|
|
|
config: &Config,
|
|
|
num_users_requesting_invites: u32,
|
|
|
+ num_censor_invites: u32,
|
|
|
bridges: &mut HashMap<[u8; 20], Bridge>,
|
|
|
censor: &mut Censor,
|
|
|
) -> Result<Vec<User>, Error> {
|
|
|
if self.is_censor {
|
|
|
self.daily_tasks_censor(config, bridges, censor).await
|
|
|
} else {
|
|
|
- self.daily_tasks_non_censor(config, num_users_requesting_invites, bridges, censor)
|
|
|
- .await
|
|
|
+ self.daily_tasks_non_censor(
|
|
|
+ config,
|
|
|
+ num_users_requesting_invites,
|
|
|
+ num_censor_invites,
|
|
|
+ bridges,
|
|
|
+ censor,
|
|
|
+ )
|
|
|
+ .await
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -273,6 +277,7 @@ impl User {
|
|
|
&mut self,
|
|
|
config: &Config,
|
|
|
num_users_requesting_invites: u32,
|
|
|
+ num_censor_invites: u32,
|
|
|
bridges: &mut HashMap<[u8; 20], Bridge>,
|
|
|
censor: &mut Censor,
|
|
|
) -> Result<Vec<User>, Error> {
|
|
@@ -512,7 +517,8 @@ impl User {
|
|
|
let mut new_friends = Vec::<User>::new();
|
|
|
for _i in 0..min(invitations, num_users_requesting_invites) {
|
|
|
if event_happens(config.prob_user_invites_friend) {
|
|
|
- match self.invite(&config, censor).await {
|
|
|
+ // Invite non-censor friend
|
|
|
+ match self.invite(&config, censor, false).await {
|
|
|
Ok(friend) => {
|
|
|
// You really shouldn't push your friends,
|
|
|
// especially new ones whose boundaries you
|
|
@@ -526,6 +532,22 @@ impl User {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // Invite censor users if applicable
|
|
|
+ let invitations = invitations - new_friends.len() as u32;
|
|
|
+ for _i in 0..min(invitations, num_censor_invites) {
|
|
|
+ if event_happens(config.prob_user_invites_friend) {
|
|
|
+ // Invite non-censor friend
|
|
|
+ match self.invite(&config, censor, true).await {
|
|
|
+ Ok(friend) => {
|
|
|
+ new_friends.push(friend);
|
|
|
+ }
|
|
|
+ Err(e) => {
|
|
|
+ println!("{}", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
Ok(new_friends)
|
|
|
} else {
|
|
|
Ok(Vec::<User>::new())
|
|
@@ -643,7 +665,7 @@ impl User {
|
|
|
let invitations = scalar_u32(&self.primary_cred.invites_remaining).unwrap();
|
|
|
let mut new_friends = Vec::<User>::new();
|
|
|
for _ in 0..invitations {
|
|
|
- match self.invite(&config, censor).await {
|
|
|
+ match self.invite(&config, censor, true).await {
|
|
|
Ok(friend) => {
|
|
|
new_friends.push(friend);
|
|
|
}
|