Handle more errors

This commit is contained in:
Vecna 2024-06-09 10:46:55 -04:00
parent 498d6b4cee
commit 355dfc9226
2 changed files with 80 additions and 39 deletions

View File

@ -134,15 +134,20 @@ pub async fn main() {
// Level trusted users up to level 4 // Level trusted users up to level 4
// Advance LA's time // Advance LA's time
la_net_test let result = la_net_test
.request( .request(
"/advancedays".to_string(), "/advancedays".to_string(),
serde_json::to_string(&(UNTRUSTED_INTERVAL as u16)) serde_json::to_string(&(UNTRUSTED_INTERVAL as u16))
.unwrap() .unwrap()
.into(), .into(),
) )
.await .await;
.unwrap(); if result.is_ok() {
result.unwrap();
} else {
eprintln!("Failed to advance time for LA");
}
// Advance simulated time // Advance simulated time
set_simulated_date(get_date() + UNTRUSTED_INTERVAL); set_simulated_date(get_date() + UNTRUSTED_INTERVAL);
@ -170,15 +175,20 @@ pub async fn main() {
for i in 1..LEVEL_INTERVAL.len() - 2 { for i in 1..LEVEL_INTERVAL.len() - 2 {
// Advance LA's time // Advance LA's time
la_net_test let result = la_net_test
.request( .request(
"/advancedays".to_string(), "/advancedays".to_string(),
serde_json::to_string(&(LEVEL_INTERVAL[i] as u16)) serde_json::to_string(&(LEVEL_INTERVAL[i] as u16))
.unwrap() .unwrap()
.into(), .into(),
) )
.await .await;
.unwrap(); if result.is_ok() {
result.unwrap();
} else {
eprintln!("Failed to advance time for LA");
}
// Advance simulated time // Advance simulated time
set_simulated_date(get_date() + LEVEL_INTERVAL[i]); set_simulated_date(get_date() + LEVEL_INTERVAL[i]);
@ -186,16 +196,20 @@ pub async fn main() {
let reachcred_res = get_bucket(&sconfig.la_net, &user.primary_cred).await; let reachcred_res = get_bucket(&sconfig.la_net, &user.primary_cred).await;
if reachcred_res.is_ok() { if reachcred_res.is_ok() {
let reachcred = reachcred_res.unwrap().1; let reachcred = reachcred_res.unwrap().1;
let new_cred = level_up( if reachcred.is_some() {
&sconfig.la_net, let new_cred = level_up(
&user.primary_cred, &sconfig.la_net,
&reachcred.unwrap(), &user.primary_cred,
get_lox_pub(&sconfig.la_pubkeys), &reachcred.unwrap(),
get_reachability_pub(&sconfig.la_pubkeys), get_lox_pub(&sconfig.la_pubkeys),
) get_reachability_pub(&sconfig.la_pubkeys),
.await; )
if new_cred.is_ok() { .await;
user.primary_cred = new_cred.unwrap(); if new_cred.is_ok() {
user.primary_cred = new_cred.unwrap();
} else {
eprintln!("Failed to level up trusted user's credential at start");
}
} else { } else {
eprintln!("Failed to level up trusted user's credential at start"); eprintln!("Failed to level up trusted user's credential at start");
} }
@ -204,13 +218,17 @@ pub async fn main() {
} }
// Advance LA's time to tomorrow // Advance LA's time to tomorrow
la_net_test let result = la_net_test
.request( .request(
"/advancedays".to_string(), "/advancedays".to_string(),
serde_json::to_string(&(1 as u16)).unwrap().into(), serde_json::to_string(&(1 as u16)).unwrap().into(),
) )
.await .await;
.unwrap(); if result.is_ok() {
result.unwrap();
} else {
eprintln!("Failed to advance time for LA");
}
// Advance simulated time to tomorrow // Advance simulated time to tomorrow
increment_simulated_date(); increment_simulated_date();
@ -243,6 +261,11 @@ pub async fn main() {
" The censor has learned {} bridges", " The censor has learned {} bridges",
censor.known_bridges.len() censor.known_bridges.len()
); );
println!(" Accuracy thus far:");
println!(" True Positives: {}", true_pos);
println!(" True Negatives: {}", true_neg);
println!(" False Positives: {}", false_pos);
println!(" False Negatives: {}", false_neg);
if let Some(usage) = memory_stats() { if let Some(usage) = memory_stats() {
if usage.physical_mem > max_physical_mem { if usage.physical_mem > max_physical_mem {
@ -364,21 +387,36 @@ pub async fn main() {
} }
// Publish all the bridges' extra-infos for today // Publish all the bridges' extra-infos for today
extra_infos_net let result = extra_infos_net
.request( .request(
"/add".to_string(), "/add".to_string(),
serde_json::to_string(&new_extra_infos).unwrap().into(), serde_json::to_string(&new_extra_infos).unwrap().into(),
) )
.await .await;
.unwrap(); if result.is_ok() {
result.unwrap();
} else {
eprintln!("Failed to publish new extra-infos");
}
// TROLL PATROL TASKS // TROLL PATROL TASKS
let new_blockages_resp = tp_net_test let new_blockages_resp = tp_net_test.request("/update".to_string(), vec![]).await;
.request("/update".to_string(), vec![]) let new_blockages = match new_blockages_resp {
.await Ok(resp) => match serde_json::from_slice(&resp) {
.unwrap(); Ok(new_blockages) => new_blockages,
let new_blockages: HashMap<String, HashSet<String>> = Err(e) => {
serde_json::from_slice(&new_blockages_resp).unwrap(); eprintln!("Failed to deserialize new blockages, error: {}", e);
HashMap::<String, HashSet<String>>::new()
}
},
Err(e) => {
eprintln!(
"Failed to get new blockages from Troll Patrol, error: {}",
e
);
HashMap::<String, HashSet<String>>::new()
}
};
// Since we have only one censor, just convert to a set of bridges // Since we have only one censor, just convert to a set of bridges
let mut blocked_bridges = HashSet::<[u8; 20]>::new(); let mut blocked_bridges = HashSet::<[u8; 20]>::new();
@ -417,13 +455,17 @@ pub async fn main() {
// LOX AUTHORITY TASKS // LOX AUTHORITY TASKS
// Advance LA's time to tomorrow // Advance LA's time to tomorrow
la_net_test let result = la_net_test
.request( .request(
"/advancedays".to_string(), "/advancedays".to_string(),
serde_json::to_string(&(1 as u16)).unwrap().into(), serde_json::to_string(&(1 as u16)).unwrap().into(),
) )
.await .await;
.unwrap(); if result.is_ok() {
result.unwrap();
} else {
eprintln!("Failed to advance time for LA");
}
// SIMULATION TASKS // SIMULATION TASKS

View File

@ -210,22 +210,21 @@ impl User {
reports: Vec<NegativeReport>, reports: Vec<NegativeReport>,
) -> Result<()> { ) -> Result<()> {
let date = get_date(); let date = get_date();
let pubkey = serde_json::from_slice::<Option<PublicKey>>( let pubkey = match serde_json::from_slice::<Option<PublicKey>>(
&config &config
.tp_net .tp_net
.request( .request("/nrkey".to_string(), serde_json::to_string(&date)?.into())
"/nrkey".to_string(),
serde_json::to_string(&date).unwrap().into(),
)
.await?, .await?,
)? )? {
.unwrap(); Some(v) => v,
None => return Err(anyhow!("No available negative report encryption key")),
};
for report in reports { for report in reports {
config config
.tp_net .tp_net
.request( .request(
"/negativereport".to_string(), "/negativereport".to_string(),
bincode::serialize(&report.encrypt(&pubkey)).unwrap(), bincode::serialize(&report.encrypt(&pubkey))?,
) )
.await?; .await?;
} }