Disable open invites when censor shows up
The censor just wins the open-entry game when it shows up. Doing it this way is much more efficient.
This commit is contained in:
parent
4f66b01ed3
commit
5e7961df52
86
src/main.rs
86
src/main.rs
|
@ -13,6 +13,7 @@ use lox_simulation::{
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use lox_cli::{networking::*, *};
|
use lox_cli::{networking::*, *};
|
||||||
|
use lox_library::cred::Invitation;
|
||||||
use memory_stats::memory_stats;
|
use memory_stats::memory_stats;
|
||||||
use rand::{prelude::SliceRandom, Rng};
|
use rand::{prelude::SliceRandom, Rng};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
@ -118,6 +119,9 @@ pub async fn main() {
|
||||||
// Set up users
|
// Set up users
|
||||||
let mut users = Vec::<User>::new();
|
let mut users = Vec::<User>::new();
|
||||||
|
|
||||||
|
// We have some pool of invitations available
|
||||||
|
let mut invites = Vec::<Invitation>::new();
|
||||||
|
|
||||||
// Set up extra-infos server
|
// Set up extra-infos server
|
||||||
spawn(async move {
|
spawn(async move {
|
||||||
extra_infos_server::server().await;
|
extra_infos_server::server().await;
|
||||||
|
@ -136,6 +140,9 @@ pub async fn main() {
|
||||||
let mut total_tn = 0;
|
let mut total_tn = 0;
|
||||||
let mut total_tp = 0;
|
let mut total_tp = 0;
|
||||||
|
|
||||||
|
// Get starting date
|
||||||
|
let start_date = get_date();
|
||||||
|
|
||||||
// Track daily percentage of users who have at least one working bridge
|
// Track daily percentage of users who have at least one working bridge
|
||||||
let mut percent_users_can_connect = Vec::<f64>::new();
|
let mut percent_users_can_connect = Vec::<f64>::new();
|
||||||
|
|
||||||
|
@ -193,12 +200,7 @@ pub async fn main() {
|
||||||
// Users do daily actions
|
// Users do daily actions
|
||||||
for user in &mut users {
|
for user in &mut users {
|
||||||
let invited_friends = user
|
let invited_friends = user
|
||||||
.daily_tasks(
|
.daily_tasks(&sconfig, &mut bridges, &mut censor, &mut invites)
|
||||||
&sconfig,
|
|
||||||
num_users_requesting_invites,
|
|
||||||
&mut bridges,
|
|
||||||
&mut censor,
|
|
||||||
)
|
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
if invited_friends.is_ok() {
|
if invited_friends.is_ok() {
|
||||||
|
@ -208,9 +210,9 @@ pub async fn main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Count the number of non-censor users who are able to
|
// Count the number of non-censor users who were able to
|
||||||
// connect to at least one bridge
|
// connect to at least one bridge today
|
||||||
if !user.is_censor {
|
if !user.is_censor && user.attempted_connection {
|
||||||
if user.able_to_connect {
|
if user.able_to_connect {
|
||||||
count_users_can_connect += 1;
|
count_users_can_connect += 1;
|
||||||
} else {
|
} else {
|
||||||
|
@ -233,31 +235,63 @@ pub async fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add percent of users who can connect to vector
|
// Add percent of users who can connect to vector
|
||||||
percent_users_can_connect.push(
|
let percent_connect_today = count_users_can_connect as f64
|
||||||
count_users_can_connect as f64
|
/ (count_users_can_connect + count_users_cannot_connect) as f64;
|
||||||
/ (count_users_can_connect + count_users_cannot_connect) as f64,
|
println!(
|
||||||
|
" Percent of users who can connect today: {}",
|
||||||
|
percent_connect_today
|
||||||
);
|
);
|
||||||
|
percent_users_can_connect.push(percent_connect_today);
|
||||||
|
|
||||||
// Add new users
|
// Add new users
|
||||||
users.append(&mut new_users);
|
users.append(&mut new_users);
|
||||||
|
|
||||||
// If any users couldn't get invites, they join with open-entry
|
// For each user requesting an invite, see if one is available.
|
||||||
// invitations
|
// If not, they can try to join via open-entry invitation if the
|
||||||
|
// censor is not active.
|
||||||
for _ in 0..num_users_requesting_invites {
|
for _ in 0..num_users_requesting_invites {
|
||||||
let user = User::new(&sconfig, false, &mut bridges, &mut censor).await;
|
let mut user_created = false;
|
||||||
if user.is_ok() {
|
|
||||||
users.push(user.unwrap());
|
// Try invites until one works or we run out
|
||||||
} else {
|
while let Some(invite) = invites.pop() {
|
||||||
eprintln!("Failed to create new user.");
|
if let Ok(user) =
|
||||||
|
User::from_invite(invite, &sconfig, false, &mut bridges, &mut censor).await
|
||||||
|
{
|
||||||
|
users.push(user);
|
||||||
|
user_created = true;
|
||||||
|
|
||||||
|
// We got a user. Stop now.
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we couldn't get a working invite, try open-entry invite
|
||||||
|
if !user_created && !censor.is_active() {
|
||||||
|
if let Ok(user) = User::new(&sconfig, false, &mut bridges, &mut censor).await {
|
||||||
|
users.push(user);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// CENSOR TASKS
|
// CENSOR TASKS
|
||||||
if censor.is_active() {
|
|
||||||
// Censor gets as many open-entry invites as possible
|
// On the day the censor activates, learn only the next 3 bridges (for efficiency)
|
||||||
|
if date == censor.start_date {
|
||||||
|
let num_bridges_before = censor.known_bridges.len();
|
||||||
|
|
||||||
|
// Censor gets as many invites as possible for 3 bridges
|
||||||
while let Ok(new_user) = User::new(&sconfig, true, &mut bridges, &mut censor).await {
|
while let Ok(new_user) = User::new(&sconfig, true, &mut bridges, &mut censor).await {
|
||||||
|
// Add new censor user
|
||||||
users.push(new_user);
|
users.push(new_user);
|
||||||
|
|
||||||
|
// If we now know 3 more bridges, break
|
||||||
|
if censor.known_bridges.len() >= num_bridges_before + 3 {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if censor.is_active() {
|
||||||
censor.end_of_day_tasks(&sconfig, &mut bridges).await;
|
censor.end_of_day_tasks(&sconfig, &mut bridges).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -429,4 +463,14 @@ pub async fn main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
println!("End which users can connect");
|
println!("End which users can connect");
|
||||||
|
|
||||||
|
println!("\nSimulation began on day {}", start_date);
|
||||||
|
println!("Censor began on day {}\n", censor.start_date);
|
||||||
|
|
||||||
|
println!("\nPercent of users who can connect per day:");
|
||||||
|
println!("date,percent");
|
||||||
|
for i in 0..percent_users_can_connect.len() {
|
||||||
|
println!("{},{}", start_date + i as u32, percent_users_can_connect[i]);
|
||||||
|
}
|
||||||
|
println!("End percent of users who can connect per day");
|
||||||
}
|
}
|
||||||
|
|
214
src/user.rs
214
src/user.rs
|
@ -9,10 +9,13 @@ use crate::{
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use lox_cli::{networking::*, *};
|
use lox_cli::{networking::*, *};
|
||||||
use lox_library::{
|
use lox_library::{
|
||||||
bridge_table::BridgeLine, cred::Lox, proto::check_blockage::MIN_TRUST_LEVEL, scalar_u32,
|
bridge_table::BridgeLine,
|
||||||
|
cred::{Invitation, Lox},
|
||||||
|
proto::check_blockage::MIN_TRUST_LEVEL,
|
||||||
|
scalar_u32,
|
||||||
};
|
};
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use std::{cmp::min, collections::HashMap};
|
use std::collections::HashMap;
|
||||||
use troll_patrol::{
|
use troll_patrol::{
|
||||||
get_date, negative_report::NegativeReport, positive_report::PositiveReport, BridgeDistributor,
|
get_date, negative_report::NegativeReport, positive_report::PositiveReport, BridgeDistributor,
|
||||||
};
|
};
|
||||||
|
@ -47,6 +50,8 @@ pub struct User {
|
||||||
// Track date the user joined and whether they're able to connect
|
// Track date the user joined and whether they're able to connect
|
||||||
pub join_date: u32,
|
pub join_date: u32,
|
||||||
pub able_to_connect: bool,
|
pub able_to_connect: bool,
|
||||||
|
// Attempted to connect today
|
||||||
|
pub attempted_connection: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl User {
|
impl User {
|
||||||
|
@ -56,6 +61,10 @@ impl User {
|
||||||
bridges: &mut HashMap<[u8; 20], Bridge>,
|
bridges: &mut HashMap<[u8; 20], Bridge>,
|
||||||
censor: &mut Censor,
|
censor: &mut Censor,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
|
if censor.is_active() && !is_censor {
|
||||||
|
return Err(anyhow!("Censor is active; open invites disabled"));
|
||||||
|
}
|
||||||
|
|
||||||
let cred = Self::get_new_credential(&config).await?.0;
|
let cred = Self::get_new_credential(&config).await?.0;
|
||||||
|
|
||||||
// Decide how likely this user is to use bridges on a given day
|
// Decide how likely this user is to use bridges on a given day
|
||||||
|
@ -123,17 +132,17 @@ impl User {
|
||||||
in_censorship_range,
|
in_censorship_range,
|
||||||
join_date: get_date(),
|
join_date: get_date(),
|
||||||
able_to_connect,
|
able_to_connect,
|
||||||
|
attempted_connection: true,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: This should probably return an actual error type
|
// Get an invite if able
|
||||||
pub async fn invite(
|
pub async fn get_invite(
|
||||||
&mut self,
|
&mut self,
|
||||||
config: &Config,
|
config: &Config,
|
||||||
bridges: &mut HashMap<[u8; 20], Bridge>,
|
bridges: &mut HashMap<[u8; 20], Bridge>,
|
||||||
censor: &mut Censor,
|
censor: &mut Censor,
|
||||||
invited_user_is_censor: bool,
|
) -> Result<Invitation> {
|
||||||
) -> Result<Self> {
|
|
||||||
let etable = get_reachability_credential(&config.la_net).await?;
|
let etable = get_reachability_credential(&config.la_net).await?;
|
||||||
let (new_cred, invite) = issue_invite(
|
let (new_cred, invite) = issue_invite(
|
||||||
&config.la_net,
|
&config.la_net,
|
||||||
|
@ -166,8 +175,17 @@ impl User {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Ok(invite)
|
||||||
|
}
|
||||||
|
|
||||||
let friend_cred = redeem_invite(
|
pub async fn from_invite(
|
||||||
|
invite: Invitation,
|
||||||
|
config: &Config,
|
||||||
|
is_censor: bool,
|
||||||
|
bridges: &mut HashMap<[u8; 20], Bridge>,
|
||||||
|
censor: &mut Censor,
|
||||||
|
) -> Result<Self> {
|
||||||
|
let cred = redeem_invite(
|
||||||
&config.la_net,
|
&config.la_net,
|
||||||
&invite,
|
&invite,
|
||||||
get_lox_pub(&config.la_pubkeys),
|
get_lox_pub(&config.la_pubkeys),
|
||||||
|
@ -176,9 +194,6 @@ impl User {
|
||||||
.await?
|
.await?
|
||||||
.0;
|
.0;
|
||||||
|
|
||||||
// Calling function decides if the invited user is a censor
|
|
||||||
let is_censor = invited_user_is_censor;
|
|
||||||
|
|
||||||
// Decide how likely this user is to use bridges on a given day
|
// Decide how likely this user is to use bridges on a given day
|
||||||
// and whether they submit reports
|
// and whether they submit reports
|
||||||
let (prob_use_bridges, submits_reports) = if is_censor {
|
let (prob_use_bridges, submits_reports) = if is_censor {
|
||||||
|
@ -201,7 +216,7 @@ impl User {
|
||||||
// Immediately download bucket and test bridges or give them to
|
// Immediately download bucket and test bridges or give them to
|
||||||
// the censor
|
// the censor
|
||||||
let mut negative_reports = Vec::<NegativeReport>::new();
|
let mut negative_reports = Vec::<NegativeReport>::new();
|
||||||
let (bucket, _reachcred) = get_bucket(&config.la_net, &friend_cred).await?;
|
let (bucket, _reachcred) = get_bucket(&config.la_net, &cred).await?;
|
||||||
for bridgeline in bucket {
|
for bridgeline in bucket {
|
||||||
let fingerprint = bridgeline.get_hashed_fingerprint();
|
let fingerprint = bridgeline.get_hashed_fingerprint();
|
||||||
if bridgeline != BridgeLine::default() {
|
if bridgeline != BridgeLine::default() {
|
||||||
|
@ -244,13 +259,14 @@ impl User {
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
is_censor,
|
is_censor,
|
||||||
primary_cred: friend_cred,
|
primary_cred: cred,
|
||||||
secondary_cred: None,
|
secondary_cred: None,
|
||||||
submits_reports: submits_reports,
|
submits_reports: submits_reports,
|
||||||
prob_use_bridges: prob_use_bridges,
|
prob_use_bridges: prob_use_bridges,
|
||||||
in_censorship_range,
|
in_censorship_range,
|
||||||
join_date: get_date(),
|
join_date: get_date(),
|
||||||
able_to_connect,
|
able_to_connect,
|
||||||
|
attempted_connection: true,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -359,14 +375,14 @@ impl User {
|
||||||
pub async fn daily_tasks(
|
pub async fn daily_tasks(
|
||||||
&mut self,
|
&mut self,
|
||||||
config: &Config,
|
config: &Config,
|
||||||
num_users_requesting_invites: u32,
|
|
||||||
bridges: &mut HashMap<[u8; 20], Bridge>,
|
bridges: &mut HashMap<[u8; 20], Bridge>,
|
||||||
censor: &mut Censor,
|
censor: &mut Censor,
|
||||||
|
invites: &mut Vec<Invitation>,
|
||||||
) -> Result<Vec<User>> {
|
) -> Result<Vec<User>> {
|
||||||
if self.is_censor {
|
if self.is_censor {
|
||||||
self.daily_tasks_censor(config, bridges, censor).await
|
self.daily_tasks_censor(config, bridges, censor).await
|
||||||
} else {
|
} else {
|
||||||
self.daily_tasks_non_censor(config, num_users_requesting_invites, bridges, censor)
|
self.daily_tasks_non_censor(config, bridges, censor, invites)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -378,12 +394,38 @@ impl User {
|
||||||
pub async fn daily_tasks_non_censor(
|
pub async fn daily_tasks_non_censor(
|
||||||
&mut self,
|
&mut self,
|
||||||
config: &Config,
|
config: &Config,
|
||||||
num_users_requesting_invites: u32,
|
|
||||||
bridges: &mut HashMap<[u8; 20], Bridge>,
|
bridges: &mut HashMap<[u8; 20], Bridge>,
|
||||||
censor: &mut Censor,
|
censor: &mut Censor,
|
||||||
|
invites: &mut Vec<Invitation>,
|
||||||
) -> Result<Vec<User>> {
|
) -> Result<Vec<User>> {
|
||||||
// Probabilistically decide if the user should use bridges today
|
// Probabilistically decide if the user should use bridges today
|
||||||
if event_happens(self.prob_use_bridges) {
|
if event_happens(self.prob_use_bridges) {
|
||||||
|
self.attempted_connection = true;
|
||||||
|
|
||||||
|
// If we couldn't connect yesterday, try to get a new credential via invite.
|
||||||
|
if !self.able_to_connect {
|
||||||
|
while let Some(invite) = invites.pop() {
|
||||||
|
match redeem_invite(
|
||||||
|
&config.la_net,
|
||||||
|
&invite,
|
||||||
|
get_lox_pub(&config.la_pubkeys),
|
||||||
|
get_invitation_pub(&config.la_pubkeys),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok((cred, _bucket)) => {
|
||||||
|
self.primary_cred = cred;
|
||||||
|
|
||||||
|
// We got a credential. Stop now.
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
println!("Failed to redeem invite. Error: {}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Start with the assumption that we can't connect, change
|
// Start with the assumption that we can't connect, change
|
||||||
// only if we can
|
// only if we can
|
||||||
self.able_to_connect = false;
|
self.able_to_connect = false;
|
||||||
|
@ -456,12 +498,17 @@ impl User {
|
||||||
if self.secondary_cred.is_some() {
|
if self.secondary_cred.is_some() {
|
||||||
std::mem::replace(&mut self.secondary_cred, None)
|
std::mem::replace(&mut self.secondary_cred, None)
|
||||||
} else {
|
} else {
|
||||||
// Get new credential
|
// If the censor is in play, we cannot get open-entry invites
|
||||||
match Self::get_new_credential(&config).await {
|
if censor.is_active() {
|
||||||
Ok((cred, _bl)) => Some(cred),
|
None
|
||||||
Err(e) => {
|
} else {
|
||||||
eprintln!("Failed to get new Lox credential. Error: {}", e);
|
// Get new credential
|
||||||
None
|
match Self::get_new_credential(&config).await {
|
||||||
|
Ok((cred, _bl)) => Some(cred),
|
||||||
|
Err(e) => {
|
||||||
|
eprintln!("Failed to get new Lox credential. Error: {}", e);
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -629,7 +676,11 @@ impl User {
|
||||||
Some(v) => v,
|
Some(v) => v,
|
||||||
None => 0, // This is probably an error case that should not happen
|
None => 0, // This is probably an error case that should not happen
|
||||||
};
|
};
|
||||||
let mut new_friends = Vec::<User>::new();
|
|
||||||
|
// It's just more convenient in the code to do this this way.
|
||||||
|
// Invite censors directly as new users. If the invited user is
|
||||||
|
// not a censor, instead add the invitation to a global list.
|
||||||
|
let mut new_censors = Vec::<User>::new();
|
||||||
|
|
||||||
// Scale the probability of inviting a censor, based on the
|
// Scale the probability of inviting a censor, based on the
|
||||||
// user's own trust level. We assume that users with
|
// user's own trust level. We assume that users with
|
||||||
|
@ -642,24 +693,33 @@ impl User {
|
||||||
Some(2) => 0.5,
|
Some(2) => 0.5,
|
||||||
_ => 1.0,
|
_ => 1.0,
|
||||||
};
|
};
|
||||||
for _i in 0..min(invitations, num_users_requesting_invites) {
|
for _ in 0..invitations {
|
||||||
if event_happens(config.prob_user_invites_friend) {
|
if event_happens(config.prob_user_invites_friend) {
|
||||||
// With some probability, the user is convinced to
|
match self.get_invite(config, bridges, censor).await {
|
||||||
// invite a censor. We assume users with higher
|
Ok(invite) => {
|
||||||
// trust levels will be more cautious with
|
// With some probability, the user is convinced to
|
||||||
// invitations because they have more to lose.
|
// invite a censor. We assume users with higher
|
||||||
let invited_friend_is_censor = censor.is_active()
|
// trust levels will be more cautious with
|
||||||
&& event_happens(config.prob_censor_gets_invite * level_scale);
|
// invitations because they have more to lose.
|
||||||
// Invite friend (who might be a censor)
|
if censor.is_active()
|
||||||
match self
|
&& event_happens(config.prob_censor_gets_invite * level_scale)
|
||||||
.invite(&config, bridges, censor, invited_friend_is_censor)
|
{
|
||||||
.await
|
// Invite friend (who might be a censor)
|
||||||
{
|
match Self::from_invite(invite, config, true, bridges, censor).await
|
||||||
Ok(friend) => {
|
{
|
||||||
// You really shouldn't push your friends,
|
Ok(friend) => {
|
||||||
// especially new ones whose boundaries you
|
// You really shouldn't push your friends,
|
||||||
// might not know well.
|
// especially new ones whose boundaries you
|
||||||
new_friends.push(friend);
|
// might not know well.
|
||||||
|
new_censors.push(friend);
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
println!("{}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
invites.push(invite);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
println!("{}", e);
|
println!("{}", e);
|
||||||
|
@ -668,8 +728,12 @@ impl User {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(new_friends)
|
Ok(new_censors)
|
||||||
} else {
|
} else {
|
||||||
|
// If we didn't try to connect, indicate so. This is to
|
||||||
|
// prevent users from being counted as able/unable to
|
||||||
|
// connect when they just haven't tried.
|
||||||
|
self.attempted_connection = false;
|
||||||
Ok(Vec::<User>::new())
|
Ok(Vec::<User>::new())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -791,47 +855,63 @@ impl User {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// If unable to migrate, try to get a new open-entry
|
// Removing this case for efficiency. If the censor is in
|
||||||
// credential and start over
|
// play, we just assume it wins the open-entry game and stop
|
||||||
|
// distributing open-entry invites altogether.
|
||||||
|
/*
|
||||||
|
} else {
|
||||||
|
// If unable to migrate, try to get a new open-entry
|
||||||
|
// credential and start over
|
||||||
|
let res = Self::get_new_credential(&config).await;
|
||||||
|
if res.is_ok() {
|
||||||
|
let (new_cred, bl) = res.unwrap();
|
||||||
|
let fingerprint = bl.get_hashed_fingerprint();
|
||||||
|
if !bridges.contains_key(&fingerprint) {
|
||||||
|
let bridge = Bridge::from_bridge_line(&bl);
|
||||||
|
bridges.insert(fingerprint, bridge);
|
||||||
|
}
|
||||||
|
censor.learn_bridge(&fingerprint);
|
||||||
|
// Censor doesn't want new_cred yet
|
||||||
|
self.primary_cred = new_cred;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Also removing this case for efficiency.
|
||||||
|
/*
|
||||||
|
// Separately from primary credential, censor user requests a
|
||||||
|
// new secondary credential each day just to block the
|
||||||
|
// open-entry bridges. This is stored but not reused.
|
||||||
let res = Self::get_new_credential(&config).await;
|
let res = Self::get_new_credential(&config).await;
|
||||||
if res.is_ok() {
|
if res.is_ok() {
|
||||||
let (new_cred, bl) = res.unwrap();
|
let (_new_cred, bl) = res.unwrap();
|
||||||
let fingerprint = bl.get_hashed_fingerprint();
|
let fingerprint = bl.get_hashed_fingerprint();
|
||||||
if !bridges.contains_key(&fingerprint) {
|
if !bridges.contains_key(&fingerprint) {
|
||||||
let bridge = Bridge::from_bridge_line(&bl);
|
let bridge = Bridge::from_bridge_line(&bl);
|
||||||
bridges.insert(fingerprint, bridge);
|
bridges.insert(fingerprint, bridge);
|
||||||
}
|
}
|
||||||
censor.learn_bridge(&fingerprint);
|
censor.learn_bridge(&fingerprint);
|
||||||
// Censor doesn't want new_cred yet
|
// Censor doesn't want new_cred. User doesn't actually use
|
||||||
self.primary_cred = new_cred;
|
// secondary_cred, so don't store it.
|
||||||
}
|
}
|
||||||
}
|
*/
|
||||||
}
|
|
||||||
|
|
||||||
// Separately from primary credential, censor user requests a
|
|
||||||
// new secondary credential each day just to block the
|
|
||||||
// open-entry bridges. This is stored but not reused.
|
|
||||||
let res = Self::get_new_credential(&config).await;
|
|
||||||
if res.is_ok() {
|
|
||||||
let (_new_cred, bl) = res.unwrap();
|
|
||||||
let fingerprint = bl.get_hashed_fingerprint();
|
|
||||||
if !bridges.contains_key(&fingerprint) {
|
|
||||||
let bridge = Bridge::from_bridge_line(&bl);
|
|
||||||
bridges.insert(fingerprint, bridge);
|
|
||||||
}
|
|
||||||
censor.learn_bridge(&fingerprint);
|
|
||||||
// Censor doesn't want new_cred. User doesn't actually use
|
|
||||||
// secondary_cred, so don't store it.
|
|
||||||
}
|
|
||||||
|
|
||||||
// Censor user invites as many censor friends as possible
|
// Censor user invites as many censor friends as possible
|
||||||
let invitations = scalar_u32(&self.primary_cred.invites_remaining).unwrap();
|
let invitations = scalar_u32(&self.primary_cred.invites_remaining).unwrap();
|
||||||
let mut new_friends = Vec::<User>::new();
|
let mut new_friends = Vec::<User>::new();
|
||||||
for _ in 0..invitations {
|
for _ in 0..invitations {
|
||||||
match self.invite(&config, bridges, censor, true).await {
|
match self.get_invite(config, bridges, censor).await {
|
||||||
Ok(friend) => {
|
Ok(invite) => {
|
||||||
new_friends.push(friend);
|
match Self::from_invite(invite, &config, true, bridges, censor).await {
|
||||||
|
Ok(friend) => {
|
||||||
|
new_friends.push(friend);
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
println!("{}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
println!("{}", e);
|
println!("{}", e);
|
||||||
|
|
Loading…
Reference in New Issue