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