Clean up
This commit is contained in:
parent
dbf7dfe929
commit
455452d64b
|
@ -1,4 +1,4 @@
|
||||||
use lox_cli::{networking::*, *};
|
use lox_cli::networking::*;
|
||||||
use lox_library::IssuerPubKey;
|
use lox_library::IssuerPubKey;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use x25519_dalek::PublicKey;
|
use x25519_dalek::PublicKey;
|
||||||
|
|
|
@ -6,10 +6,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
use lox_cli::{networking::*, *};
|
use lox_cli::{networking::*, *};
|
||||||
use lox_library::{
|
use lox_library::{
|
||||||
bridge_table::{BridgeLine, MAX_BRIDGES_PER_BUCKET},
|
bridge_table::BridgeLine, cred::Lox, proto::check_blockage::MIN_TRUST_LEVEL, scalar_u32,
|
||||||
cred::{Invitation, Lox},
|
|
||||||
proto::check_blockage::MIN_TRUST_LEVEL,
|
|
||||||
scalar_u32, IssuerPubKey,
|
|
||||||
};
|
};
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
|
|
||||||
|
@ -32,12 +29,13 @@ pub struct User {
|
||||||
|
|
||||||
impl User {
|
impl User {
|
||||||
pub async fn new(state: &State) -> Self {
|
pub async fn new(state: &State) -> Self {
|
||||||
let (cred, bl) = get_lox_credential(
|
let cred = get_lox_credential(
|
||||||
&state.net,
|
&state.net,
|
||||||
&get_open_invitation(&state.net).await,
|
&get_open_invitation(&state.net).await,
|
||||||
get_lox_pub(&state.la_pubkeys),
|
get_lox_pub(&state.la_pubkeys),
|
||||||
)
|
)
|
||||||
.await;
|
.await
|
||||||
|
.0;
|
||||||
|
|
||||||
// Probabilistically decide whether this user cooperates with a censor
|
// Probabilistically decide whether this user cooperates with a censor
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
|
@ -53,7 +51,7 @@ impl User {
|
||||||
let cc = {
|
let cc = {
|
||||||
let mut cc = String::default();
|
let mut cc = String::default();
|
||||||
for (country, prob) in &state.probs_user_in_country {
|
for (country, prob) in &state.probs_user_in_country {
|
||||||
let mut prob = *prob;
|
let prob = *prob;
|
||||||
if prob < num {
|
if prob < num {
|
||||||
cc = country.to_string();
|
cc = country.to_string();
|
||||||
break;
|
break;
|
||||||
|
@ -86,13 +84,14 @@ impl User {
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
self.primary_cred = new_cred;
|
self.primary_cred = new_cred;
|
||||||
let (friend_cred, bucket) = redeem_invite(
|
let friend_cred = redeem_invite(
|
||||||
&state.net,
|
&state.net,
|
||||||
&invite,
|
&invite,
|
||||||
get_lox_pub(&state.la_pubkeys),
|
get_lox_pub(&state.la_pubkeys),
|
||||||
get_invitation_pub(&state.la_pubkeys),
|
get_invitation_pub(&state.la_pubkeys),
|
||||||
)
|
)
|
||||||
.await;
|
.await
|
||||||
|
.0;
|
||||||
|
|
||||||
// Probabilistically decide whether this user cooperates with a censor
|
// Probabilistically decide whether this user cooperates with a censor
|
||||||
// We do not influence this by the inviting friend's status. Anyone
|
// We do not influence this by the inviting friend's status. Anyone
|
||||||
|
@ -205,12 +204,13 @@ impl User {
|
||||||
std::mem::replace(&mut self.secondary_cred, None)
|
std::mem::replace(&mut self.secondary_cred, None)
|
||||||
} else {
|
} else {
|
||||||
// Get new credential
|
// Get new credential
|
||||||
let (cred, bl) = get_lox_credential(
|
let cred = get_lox_credential(
|
||||||
&state.net,
|
&state.net,
|
||||||
&get_open_invitation(&state.net).await,
|
&get_open_invitation(&state.net).await,
|
||||||
get_lox_pub(&state.la_pubkeys),
|
get_lox_pub(&state.la_pubkeys),
|
||||||
)
|
)
|
||||||
.await;
|
.await
|
||||||
|
.0;
|
||||||
Some(cred)
|
Some(cred)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -320,7 +320,7 @@ impl User {
|
||||||
// Invite friends if applicable
|
// Invite friends if applicable
|
||||||
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 i in 0..invitations {
|
for _i in 0..invitations {
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
let num: f64 = rng.gen_range(0.0..1.0);
|
let num: f64 = rng.gen_range(0.0..1.0);
|
||||||
if num < state.prob_user_invites_friend {
|
if num < state.prob_user_invites_friend {
|
||||||
|
|
Loading…
Reference in New Issue