diff --git a/Cargo.lock b/Cargo.lock index ce52b969520558ed5e04c31b74a25086056a5b31..f1f4cc636a9011212f306fa3f575d2f00aaa3cbf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -107,7 +107,7 @@ dependencies = [ [[package]] name = "duniter-wotb" -version = "0.6.2" +version = "0.7.0" dependencies = [ "bincode 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/wotb/Cargo.toml b/wotb/Cargo.toml index 213c02a862276a8249dfb1cbd0d5915d4416caae..b37f08c63dca1e32ea16e19de9c27fc8343f536a 100644 --- a/wotb/Cargo.toml +++ b/wotb/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "duniter-wotb" -version = "0.6.2" +version = "0.7.0" authors = ["nanocryk <nanocryk@duniter.org>", "elois <elois@duniter.org>"] description = "Makes Web of Trust computations for the Duniter project." repository = "https://git.duniter.org/nodes/rust/duniter-rs" diff --git a/wotb/legacy.rs b/wotb/legacy.rs index f70da9e47aeb2567fce7f3aaa50b860f92aaa784..402288a35ed1420d851fefd76f980b3aefc4773d 100644 --- a/wotb/legacy.rs +++ b/wotb/legacy.rs @@ -398,7 +398,9 @@ impl WebOfTrust for LegacyWebOfTrust { let mut result = WotDistance { sentries: 0, success: 0, + success_at_border: 0, reached: 0, + reached_at_border: 0, outdistanced: false, }; @@ -412,17 +414,30 @@ impl WebOfTrust for LegacyWebOfTrust { sentries[node.0] = false; let mut checked: Vec<bool> = self.nodes.iter().map(|_| false).collect(); + let mut checked_without_border: Vec<bool> = checked.clone(); if step_max >= 1 { checked = self.check_matches(node, 1, step_max, checked); + if step_max >= 2 { + checked_without_border = + self.check_matches(node, 1, step_max - 1, checked_without_border); + } } - for (&sentry, &check) in sentries.iter().zip(checked.iter()) { + for ((&sentry, &check), &check_without_border) in sentries + .iter() + .zip(checked.iter()) + .zip(checked_without_border.iter()) + { if sentry { result.sentries += 1; if check { result.success += 1; result.reached += 1; + if !check_without_border { + result.success_at_border += 1; + result.reached_at_border += 1; + } } } else if check { result.reached += 1; diff --git a/wotb/lib.rs b/wotb/lib.rs index b0f9af3d5bed6afcebfcbbd2e92d02b794488c3b..4d6d80be930f1db278e2024d50d36e2469c6c9a8 100644 --- a/wotb/lib.rs +++ b/wotb/lib.rs @@ -151,8 +151,12 @@ pub struct WotDistance { pub sentries: u32, /// Success count pub success: u32, + /// Succes at border count + pub success_at_border: u32, /// Reached count pub reached: u32, + /// Reached at border count + pub reached_at_border: u32, /// Is the node outdistanced ? pub outdistanced: bool, } @@ -588,7 +592,7 @@ mod tests { sentry_requirement: 1, step_max: 1, x_percent: 1.0, - }), + },), Some(false) ); // => no because 2,4,5 have certified him @@ -598,7 +602,7 @@ mod tests { sentry_requirement: 2, step_max: 1, x_percent: 1.0, - }), + },), Some(false) ); // => no because only member 2 has 2 certs, and has certified him @@ -608,7 +612,7 @@ mod tests { sentry_requirement: 3, step_max: 1, x_percent: 1.0, - }), + },), Some(false) ); // => no because no member has issued 3 certifications @@ -646,7 +650,7 @@ mod tests { sentry_requirement: 1, step_max: 1, x_percent: 1.0, - }), + },), Some(false) ); // OK : 2 -> 0 assert_eq!( @@ -655,7 +659,7 @@ mod tests { sentry_requirement: 2, step_max: 1, x_percent: 1.0, - }), + },), Some(false) ); // OK : 2 -> 0 assert_eq!( @@ -664,7 +668,7 @@ mod tests { sentry_requirement: 3, step_max: 1, x_percent: 1.0, - }), + },), Some(false) ); // OK : no stry \w 3 lnk assert_eq!( @@ -673,7 +677,7 @@ mod tests { sentry_requirement: 2, step_max: 2, x_percent: 1.0, - }), + },), Some(false) ); // OK : 2 -> 0 @@ -706,7 +710,7 @@ mod tests { sentry_requirement: 1, step_max: 1, x_percent: 1.0, - }), + },), Some(true) ); // KO : No path 3 -> 0 assert_eq!( @@ -715,7 +719,7 @@ mod tests { sentry_requirement: 2, step_max: 1, x_percent: 1.0, - }), + },), Some(true) ); // KO : No path 3 -> 0 assert_eq!( @@ -724,7 +728,7 @@ mod tests { sentry_requirement: 3, step_max: 1, x_percent: 1.0, - }), + },), Some(false) ); // OK : no stry \w 3 lnk assert_eq!( @@ -733,7 +737,7 @@ mod tests { sentry_requirement: 2, step_max: 2, x_percent: 1.0, - }), + },), Some(false) ); // OK : 3 -> 2 -> 0 @@ -756,7 +760,7 @@ mod tests { sentry_requirement: 2, step_max: 1, x_percent: 1.0, - }), + },), Some(false) ); // OK : Disabled @@ -791,7 +795,7 @@ mod tests { sentry_requirement: 2, step_max: 1, x_percent: 1.0, - }), + },), Some(false) ); } diff --git a/wotb/rusty.rs b/wotb/rusty.rs index b7ae38b6e8cfe6afa64d0b60bff84bb76446e98c..aa2d9e3de24f098dd96f5e6a73923df299e18c3f 100644 --- a/wotb/rusty.rs +++ b/wotb/rusty.rs @@ -286,8 +286,8 @@ impl WebOfTrust for RustyWebOfTrust { } let sentries: Vec<_> = self.get_sentries(sentry_requirement as usize); - let success = area.iter().filter(|n| sentries.contains(n)).count() as u32; + let success_at_border = border.iter().filter(|n| sentries.contains(n)).count() as u32; let sentries = sentries.len() as u32 - if self.is_sentry(node, sentry_requirement as usize).unwrap() { 1 @@ -298,7 +298,9 @@ impl WebOfTrust for RustyWebOfTrust { Some(WotDistance { sentries, reached: (area.len() - 1) as u32, + reached_at_border: (border.len() - 1) as u32, success, + success_at_border, outdistanced: f64::from(success) < x_percent * f64::from(sentries), }) }