Skip to content
Snippets Groups Projects
Commit dd523357 authored by Cédric Moreau's avatar Cédric Moreau
Browse files

fix #1: add_link without rem_link calls must be idempotent

parent eebd1685
No related branches found
No related tags found
No related merge requests found
Pipeline #16718 waiting for manual action
...@@ -92,6 +92,8 @@ pub enum NewLinkResult { ...@@ -92,6 +92,8 @@ pub enum NewLinkResult {
Ok(usize), Ok(usize),
/// All available certifications has been used. /// All available certifications has been used.
AllCertificationsUsed(usize), AllCertificationsUsed(usize),
/// Already existing certification (maybe a replay).
AlreadyExistingCertification(usize),
/// Unknown source. /// Unknown source.
UnknownSource(), UnknownSource(),
/// Unknown target. /// Unknown target.
......
...@@ -138,6 +138,8 @@ impl WebOfTrust for RustyWebOfTrust { ...@@ -138,6 +138,8 @@ impl WebOfTrust for RustyWebOfTrust {
NewLinkResult::UnknownTarget() NewLinkResult::UnknownTarget()
} else if self.nodes[source.0].issued_count >= self.max_links { } else if self.nodes[source.0].issued_count >= self.max_links {
NewLinkResult::AllCertificationsUsed(self.nodes[target.0].links_source.len()) 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 { } else {
self.nodes[source.0].issued_count += 1; self.nodes[source.0].issued_count += 1;
self.nodes[target.0].links_source.insert(source); self.nodes[target.0].links_source.insert(source);
......
...@@ -197,6 +197,16 @@ mod tests { ...@@ -197,6 +197,16 @@ mod tests {
// should be able to add some links, cert count is returned // 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(2), WotId(0)), NewLinkResult::Ok(1));
assert_eq!(wot.add_link(WotId(4), WotId(0)), NewLinkResult::Ok(2)); 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)); assert_eq!(wot.add_link(WotId(5), WotId(0)), NewLinkResult::Ok(3));
// should exist new links // should exist new links
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment