diff --git a/Cargo.lock b/Cargo.lock index 7cff9c862c22dce6039af495a61b6b1efa348d2d..6abf32cbd0b553d0ae0e479a46fefb0d69c1ff65 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,7 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "aho-corasick" version = "0.7.15" @@ -773,7 +775,7 @@ dependencies = [ [[package]] name = "dubp-wot" -version = "0.11.0" +version = "0.11.1" dependencies = [ "bincode", "log", diff --git a/dubp-wot/Cargo.toml b/dubp-wot/Cargo.toml index 0821f2f5fd5a8a59f101ee8073275b8ed8151626..14ac5b9b3a6a7b523c802a003c9d721b01b24bbe 100644 --- a/dubp-wot/Cargo.toml +++ b/dubp-wot/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "dubp-wot" -version = "0.11.0" +version = "0.11.1" 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/typescript/duniter" diff --git a/dubp-wot/src/data/mod.rs b/dubp-wot/src/data/mod.rs index eddc11e19b5083148615cd53848fd212cd894f6d..6f7ec6b06ae51d97ed6bb3537ef90cfb8aca5cd5 100644 --- a/dubp-wot/src/data/mod.rs +++ b/dubp-wot/src/data/mod.rs @@ -92,6 +92,8 @@ pub enum NewLinkResult { Ok(usize), /// All available certifications has been used. AllCertificationsUsed(usize), + /// Already existing certification (maybe a replay). + AlreadyExistingCertification(usize), /// Unknown source. UnknownSource(), /// Unknown target. diff --git a/dubp-wot/src/data/rusty.rs b/dubp-wot/src/data/rusty.rs index 398027350a5fc2d25ea1da83ba0c58e252d2e7fc..5367b7c4e70f501b7190e1895eba43a40e4b5a5a 100644 --- a/dubp-wot/src/data/rusty.rs +++ b/dubp-wot/src/data/rusty.rs @@ -138,6 +138,8 @@ impl WebOfTrust for RustyWebOfTrust { NewLinkResult::UnknownTarget() } else if self.nodes[source.0].issued_count >= self.max_links { NewLinkResult::AllCertificationsUsed(self.nodes[target.0].links_source.len()) + } else if self.nodes[target.0].links_source.contains(&source) { + NewLinkResult::AlreadyExistingCertification(self.nodes[target.0].links_source.len()) } else { self.nodes[source.0].issued_count += 1; self.nodes[target.0].links_source.insert(source); diff --git a/dubp-wot/src/lib.rs b/dubp-wot/src/lib.rs index 06989dc3a1ffe8dc057ac5a8a457f72cc6babfe5..54dc4493ed71fbbc0632c3c2eca288b8c3033459 100644 --- a/dubp-wot/src/lib.rs +++ b/dubp-wot/src/lib.rs @@ -197,6 +197,16 @@ mod tests { // should be able to add some links, cert count is returned assert_eq!(wot.add_link(WotId(2), WotId(0)), NewLinkResult::Ok(1)); assert_eq!(wot.add_link(WotId(4), WotId(0)), NewLinkResult::Ok(2)); + // Check that certification replay is handled + assert_eq!( + wot.add_link(WotId(4), WotId(0)), + NewLinkResult::AlreadyExistingCertification(2) + ); + // Check that certification re-replay is handled + assert_eq!( + wot.add_link(WotId(4), WotId(0)), + NewLinkResult::AlreadyExistingCertification(2) + ); assert_eq!(wot.add_link(WotId(5), WotId(0)), NewLinkResult::Ok(3)); // should exist new links