Skip to content
Snippets Groups Projects
Commit d107d019 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 #16715 waiting for manual action
......@@ -92,6 +92,8 @@ pub enum NewLinkResult {
Ok(usize),
/// All available certifications has been used.
AllCertificationsUsed(usize),
/// Already existing certification (maybe a replay).
AlreadyExistingCertification(),
/// Unknown source.
UnknownSource(),
/// Unknown target.
......
......@@ -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()
} else {
self.nodes[source.0].issued_count += 1;
self.nodes[target.0].links_source.insert(source);
......
......@@ -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()
);
// Check that certification re-replay is handled
assert_eq!(
wot.add_link(WotId(4), WotId(0)),
NewLinkResult::AlreadyExistingCertification()
);
assert_eq!(wot.add_link(WotId(5), WotId(0)), NewLinkResult::Ok(3));
// 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