diff --git a/Cargo.lock b/Cargo.lock index baee12803850c4405756aceac4807ce0b020ec03..789e36cd1b28cd4619d3f0f4f802521674a62ba7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -754,12 +754,9 @@ name = "durs-wot" version = "0.8.0-a0.9" dependencies = [ "bincode 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", "durs-common-tools 0.2.0", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] diff --git a/lib/dubp/wot/Cargo.toml b/lib/dubp/wot/Cargo.toml index c0625e72b71765b2b26af0687c3115820f1cd9c4..f7f0062e055f281079433a591ef59fe771a8dcb1 100644 --- a/lib/dubp/wot/Cargo.toml +++ b/lib/dubp/wot/Cargo.toml @@ -2,10 +2,10 @@ name = "durs-wot" version = "0.8.0-a0.9" authors = ["nanocryk <nanocryk@duniter.org>", "elois <elois@duniter.org>"] -description = "Makes Web of Trust computations for the Duniter project." +description = "Makes Web of Trust computations for the Dunitrust project." repository = "https://git.duniter.org/nodes/rust/duniter-rs" readme = "README.md" -keywords = ["duniter", "wot", "wot", "web", "trust"] +keywords = ["duniter", "dunitrust", "wot", "trust"] license = "AGPL-3.0" edition = "2018" @@ -13,12 +13,11 @@ edition = "2018" path = "lib.rs" [dependencies] -log = "0.4.*" -durs-common-tools = { path = "../../tools/common-tools" } -serde = "1.0.*" -serde_derive = "1.0.*" -bincode = "1.0.*" -byteorder = "1.2.*" rayon = "1.0.*" +serde = { version = "1.0.*", features = ["derive"] } + +[dev-dependencies] +bincode = "1.0.*" +durs-common-tools = { path = "../../tools/common-tools", version = "0.2.0" } [features] \ No newline at end of file diff --git a/lib/dubp/wot/data/mod.rs b/lib/dubp/wot/data/mod.rs index f574e5a2aa09ec76ec122e3d2ec899300526f3a6..2180a7eaf6afac4004a88fb952b161fa25f75cc7 100644 --- a/lib/dubp/wot/data/mod.rs +++ b/lib/dubp/wot/data/mod.rs @@ -25,9 +25,9 @@ use std::fmt::{self, Debug}; /// Wrapper for a node id. #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub struct NodeId(pub usize); +pub struct WotId(pub usize); -impl Serialize for NodeId { +impl Serialize for WotId { fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: Serializer, @@ -36,48 +36,48 @@ impl Serialize for NodeId { } } -struct NodeIdVisitor; +struct WotIdVisitor; -impl<'de> Visitor<'de> for NodeIdVisitor { - type Value = NodeId; +impl<'de> Visitor<'de> for WotIdVisitor { + type Value = WotId; fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { formatter.write_str("an integer between -2^31 and 2^31") } - fn visit_u8<E>(self, value: u8) -> Result<NodeId, E> + fn visit_u8<E>(self, value: u8) -> Result<WotId, E> where E: de::Error, { - Ok(NodeId(value as usize)) + Ok(WotId(value as usize)) } - fn visit_u32<E>(self, value: u32) -> Result<NodeId, E> + fn visit_u32<E>(self, value: u32) -> Result<WotId, E> where E: de::Error, { - Ok(NodeId(value as usize)) + Ok(WotId(value as usize)) } - fn visit_u64<E>(self, value: u64) -> Result<NodeId, E> + fn visit_u64<E>(self, value: u64) -> Result<WotId, E> where E: de::Error, { use std::usize; if value >= usize::MIN as u64 && value <= usize::MAX as u64 { - Ok(NodeId(value as usize)) + Ok(WotId(value as usize)) } else { Err(E::custom(format!("u32 out of range: {}", value))) } } } -impl<'de> Deserialize<'de> for NodeId { - fn deserialize<D>(deserializer: D) -> Result<NodeId, D::Error> +impl<'de> Deserialize<'de> for WotId { + fn deserialize<D>(deserializer: D) -> Result<WotId, D::Error> where D: Deserializer<'de>, { - deserializer.deserialize_u32(NodeIdVisitor) + deserializer.deserialize_u32(WotIdVisitor) } } @@ -136,52 +136,52 @@ pub trait WebOfTrust: Clone + Debug + Default + DeserializeOwned + Send + Serial fn set_max_link(&mut self, max_link: usize); /// Add a new node. - fn add_node(&mut self) -> NodeId; + fn add_node(&mut self) -> WotId; /// Remove the last node. /// Returns `None` if the WoT was empty, otherwise new top node id. - fn rem_node(&mut self) -> Option<NodeId>; + fn rem_node(&mut self) -> Option<WotId>; /// Get the size of the WoT. fn size(&self) -> usize; /// Check if given node is enabled. /// Returns `None` if this node doesn't exist. - fn is_enabled(&self, id: NodeId) -> Option<bool>; + fn is_enabled(&self, id: WotId) -> Option<bool>; /// Set the enabled state of given node. /// Returns `Null` if this node doesn't exist, `enabled` otherwise. - fn set_enabled(&mut self, id: NodeId, enabled: bool) -> Option<bool>; + fn set_enabled(&mut self, id: WotId, enabled: bool) -> Option<bool>; /// Get enabled node array. - fn get_enabled(&self) -> Vec<NodeId>; + fn get_enabled(&self) -> Vec<WotId>; /// Get disabled node array. - fn get_disabled(&self) -> Vec<NodeId>; + fn get_disabled(&self) -> Vec<WotId>; /// Try to add a link from the source to the target. - fn add_link(&mut self, source: NodeId, target: NodeId) -> NewLinkResult; + fn add_link(&mut self, source: WotId, target: WotId) -> NewLinkResult; /// Try to remove a link from the source to the target. - fn rem_link(&mut self, source: NodeId, target: NodeId) -> RemLinkResult; + fn rem_link(&mut self, source: WotId, target: WotId) -> RemLinkResult; /// Test if there is a link from the source to the target. - fn has_link(&self, source: NodeId, target: NodeId) -> HasLinkResult; + fn has_link(&self, source: WotId, target: WotId) -> HasLinkResult; /// Get the list of links source for this target. /// Returns `None` if this node doesn't exist. - fn get_links_source(&self, target: NodeId) -> Option<Vec<NodeId>>; + fn get_links_source(&self, target: WotId) -> Option<Vec<WotId>>; /// Get the number of issued links by a node. /// Returns `None` if this node doesn't exist. - fn issued_count(&self, id: NodeId) -> Option<usize>; + fn issued_count(&self, id: WotId) -> Option<usize>; /// Test if a node is a sentry. - fn is_sentry(&self, node: NodeId, sentry_requirement: usize) -> Option<bool>; + fn is_sentry(&self, node: WotId, sentry_requirement: usize) -> Option<bool>; /// Get sentries array. - fn get_sentries(&self, sentry_requirement: usize) -> Vec<NodeId>; + fn get_sentries(&self, sentry_requirement: usize) -> Vec<WotId>; /// Get non sentries array. - fn get_non_sentries(&self, sentry_requirement: usize) -> Vec<NodeId>; + fn get_non_sentries(&self, sentry_requirement: usize) -> Vec<WotId>; } diff --git a/lib/dubp/wot/data/rusty.rs b/lib/dubp/wot/data/rusty.rs index 1928bce6091c918a9c374ed95b86781635cbd5b1..8d84423e62e7436f605baed3d2444e85af4a5c75 100644 --- a/lib/dubp/wot/data/rusty.rs +++ b/lib/dubp/wot/data/rusty.rs @@ -16,9 +16,10 @@ //! Experimental implementation of the Web of Trust in a more "rusty" style. use super::{HasLinkResult, NewLinkResult, RemLinkResult}; -use crate::NodeId; use crate::WebOfTrust; +use crate::WotId; use rayon::prelude::*; +use serde::{Deserialize, Serialize}; use std::collections::HashSet; /// A node in the `WoT` graph. @@ -27,7 +28,7 @@ struct Node { /// Is this node enabled ? enabled: bool, /// Set of links this node is the target. - links_source: HashSet<NodeId>, + links_source: HashSet<WotId>, /// Number of links the node issued. issued_count: usize, } @@ -77,16 +78,16 @@ impl WebOfTrust for RustyWebOfTrust { self.max_links = max_links; } - fn add_node(&mut self) -> NodeId { + fn add_node(&mut self) -> WotId { self.nodes.push(Node::new()); - NodeId(self.nodes.len() - 1) + WotId(self.nodes.len() - 1) } - fn rem_node(&mut self) -> Option<NodeId> { + fn rem_node(&mut self) -> Option<WotId> { self.nodes.pop(); if !self.nodes.is_empty() { - Some(NodeId(self.nodes.len() - 1)) + Some(WotId(self.nodes.len() - 1)) } else { None } @@ -96,36 +97,36 @@ impl WebOfTrust for RustyWebOfTrust { self.nodes.len() } - fn is_enabled(&self, id: NodeId) -> Option<bool> { + fn is_enabled(&self, id: WotId) -> Option<bool> { self.nodes.get(id.0).map(|n| n.enabled) } - fn set_enabled(&mut self, id: NodeId, enabled: bool) -> Option<bool> { + fn set_enabled(&mut self, id: WotId, enabled: bool) -> Option<bool> { self.nodes .get_mut(id.0) .map(|n| n.enabled = enabled) .map(|_| enabled) } - fn get_enabled(&self) -> Vec<NodeId> { + fn get_enabled(&self) -> Vec<WotId> { self.nodes .par_iter() .enumerate() .filter(|&(_, n)| n.enabled) - .map(|(i, _)| NodeId(i)) + .map(|(i, _)| WotId(i)) .collect() } - fn get_disabled(&self) -> Vec<NodeId> { + fn get_disabled(&self) -> Vec<WotId> { self.nodes .par_iter() .enumerate() .filter(|&(_, n)| !n.enabled) - .map(|(i, _)| NodeId(i)) + .map(|(i, _)| WotId(i)) .collect() } - fn add_link(&mut self, source: NodeId, target: NodeId) -> NewLinkResult { + fn add_link(&mut self, source: WotId, target: WotId) -> NewLinkResult { if source == target { NewLinkResult::SelfLinkingForbidden() } else if source.0 >= self.size() { @@ -141,7 +142,7 @@ impl WebOfTrust for RustyWebOfTrust { } } - fn rem_link(&mut self, source: NodeId, target: NodeId) -> RemLinkResult { + fn rem_link(&mut self, source: WotId, target: WotId) -> RemLinkResult { if source.0 >= self.size() { RemLinkResult::UnknownSource() } else if target.0 >= self.size() { @@ -155,7 +156,7 @@ impl WebOfTrust for RustyWebOfTrust { } } - fn has_link(&self, source: NodeId, target: NodeId) -> HasLinkResult { + fn has_link(&self, source: WotId, target: WotId) -> HasLinkResult { if source.0 >= self.size() { HasLinkResult::UnknownSource() } else if target.0 >= self.size() { @@ -165,17 +166,17 @@ impl WebOfTrust for RustyWebOfTrust { } } - fn get_links_source(&self, target: NodeId) -> Option<Vec<NodeId>> { + fn get_links_source(&self, target: WotId) -> Option<Vec<WotId>> { self.nodes .get(target.0) .map(|n| n.links_source.iter().cloned().collect()) } - fn issued_count(&self, id: NodeId) -> Option<usize> { + fn issued_count(&self, id: WotId) -> Option<usize> { self.nodes.get(id.0).map(|n| n.issued_count) } - fn is_sentry(&self, node: NodeId, sentry_requirement: usize) -> Option<bool> { + fn is_sentry(&self, node: WotId, sentry_requirement: usize) -> Option<bool> { if node.0 >= self.size() { return None; } @@ -189,7 +190,7 @@ impl WebOfTrust for RustyWebOfTrust { ) } - fn get_sentries(&self, sentry_requirement: usize) -> Vec<NodeId> { + fn get_sentries(&self, sentry_requirement: usize) -> Vec<WotId> { self.nodes .par_iter() .enumerate() @@ -198,11 +199,11 @@ impl WebOfTrust for RustyWebOfTrust { && n.issued_count >= sentry_requirement && n.links_source.len() >= sentry_requirement }) - .map(|(i, _)| NodeId(i)) + .map(|(i, _)| WotId(i)) .collect() } - fn get_non_sentries(&self, sentry_requirement: usize) -> Vec<NodeId> { + fn get_non_sentries(&self, sentry_requirement: usize) -> Vec<WotId> { self.nodes .par_iter() .enumerate() @@ -211,7 +212,7 @@ impl WebOfTrust for RustyWebOfTrust { && (n.issued_count < sentry_requirement || n.links_source.len() < sentry_requirement) }) - .map(|(i, _)| NodeId(i)) + .map(|(i, _)| WotId(i)) .collect() } } diff --git a/lib/dubp/wot/lib.rs b/lib/dubp/wot/lib.rs index 86eeff90e00907a15f611b82cf893013f5e651a8..d092b6a3a0741892ca54cf9dea379f58ee88c338 100644 --- a/lib/dubp/wot/lib.rs +++ b/lib/dubp/wot/lib.rs @@ -38,15 +38,10 @@ unused_qualifications )] -#[macro_use] -extern crate serde_derive; -#[macro_use] -extern crate log; - pub mod data; pub mod operations; -pub use crate::data::{NodeId, WebOfTrust}; +pub use crate::data::{WebOfTrust, WotId}; #[cfg(test)] mod tests { @@ -54,8 +49,8 @@ mod tests { use crate::data::*; use crate::operations::centrality::*; use crate::operations::distance::*; - use crate::operations::file::*; use crate::operations::path::*; + use std::path::Path; /// Test translated from https://github.com/duniter/wot/blob/master/tests/test.js /// @@ -74,126 +69,102 @@ mod tests { assert_eq!(wot.size(), 0); // should return `None()` if testing `is_enabled()` with out-of-bounds node - assert_eq!(wot.is_enabled(NodeId(0)), None); - assert_eq!(wot.is_enabled(NodeId(23)), None); + assert_eq!(wot.is_enabled(WotId(0)), None); + assert_eq!(wot.is_enabled(WotId(23)), None); // should give nomber 0 if we add a node // - add a node - assert_eq!(wot.add_node(), NodeId(0)); + assert_eq!(wot.add_node(), WotId(0)); assert_eq!(wot.size(), 1); assert_eq!(wot.get_disabled().len(), 0); // - add another - assert_eq!(wot.add_node(), NodeId(1)); + assert_eq!(wot.add_node(), WotId(1)); assert_eq!(wot.size(), 2); assert_eq!(wot.get_disabled().len(), 0); // - add 10 nodes for i in 0..10 { - assert_eq!(wot.add_node(), NodeId(i + 2)); + assert_eq!(wot.add_node(), WotId(i + 2)); } assert_eq!(wot.size(), 12); // shouldn't be able to self cert assert_eq!( - wot.add_link(NodeId(0), NodeId(0)), + wot.add_link(WotId(0), WotId(0)), NewLinkResult::SelfLinkingForbidden() ); // should add certs only in the boundaries of max_cert - assert_eq!(wot.add_link(NodeId(0), NodeId(1)), NewLinkResult::Ok(1)); - assert_eq!(wot.add_link(NodeId(0), NodeId(2)), NewLinkResult::Ok(1)); - assert_eq!(wot.add_link(NodeId(0), NodeId(3)), NewLinkResult::Ok(1)); + assert_eq!(wot.add_link(WotId(0), WotId(1)), NewLinkResult::Ok(1)); + assert_eq!(wot.add_link(WotId(0), WotId(2)), NewLinkResult::Ok(1)); + assert_eq!(wot.add_link(WotId(0), WotId(3)), NewLinkResult::Ok(1)); assert_eq!( - wot.add_link(NodeId(0), NodeId(4)), + wot.add_link(WotId(0), WotId(4)), NewLinkResult::AllCertificationsUsed(0) ); assert_eq!(wot.get_max_link(), 3); - assert_eq!( - wot.has_link(NodeId(0), NodeId(1)), - HasLinkResult::Link(true) - ); - assert_eq!( - wot.has_link(NodeId(0), NodeId(2)), - HasLinkResult::Link(true) - ); - assert_eq!( - wot.has_link(NodeId(0), NodeId(3)), - HasLinkResult::Link(true) - ); - assert_eq!( - wot.has_link(NodeId(0), NodeId(4)), - HasLinkResult::Link(false) - ); + assert_eq!(wot.has_link(WotId(0), WotId(1)), HasLinkResult::Link(true)); + assert_eq!(wot.has_link(WotId(0), WotId(2)), HasLinkResult::Link(true)); + assert_eq!(wot.has_link(WotId(0), WotId(3)), HasLinkResult::Link(true)); + assert_eq!(wot.has_link(WotId(0), WotId(4)), HasLinkResult::Link(false)); wot.set_max_link(4); assert_eq!(wot.get_max_link(), 4); - assert_eq!( - wot.has_link(NodeId(0), NodeId(4)), - HasLinkResult::Link(false) - ); - wot.add_link(NodeId(0), NodeId(4)); - assert_eq!( - wot.has_link(NodeId(0), NodeId(4)), - HasLinkResult::Link(true) - ); - wot.rem_link(NodeId(0), NodeId(1)); - wot.rem_link(NodeId(0), NodeId(2)); - wot.rem_link(NodeId(0), NodeId(3)); - wot.rem_link(NodeId(0), NodeId(4)); + assert_eq!(wot.has_link(WotId(0), WotId(4)), HasLinkResult::Link(false)); + wot.add_link(WotId(0), WotId(4)); + assert_eq!(wot.has_link(WotId(0), WotId(4)), HasLinkResult::Link(true)); + wot.rem_link(WotId(0), WotId(1)); + wot.rem_link(WotId(0), WotId(2)); + wot.rem_link(WotId(0), WotId(3)); + wot.rem_link(WotId(0), WotId(4)); // false when not linked + test out of bounds + assert_eq!(wot.has_link(WotId(0), WotId(6)), HasLinkResult::Link(false)); assert_eq!( - wot.has_link(NodeId(0), NodeId(6)), - HasLinkResult::Link(false) - ); - assert_eq!( - wot.has_link(NodeId(23), NodeId(0)), + wot.has_link(WotId(23), WotId(0)), HasLinkResult::UnknownSource() ); assert_eq!( - wot.has_link(NodeId(2), NodeId(53)), + wot.has_link(WotId(2), WotId(53)), HasLinkResult::UnknownTarget() ); // created nodes should be enabled - assert_eq!(wot.is_enabled(NodeId(0)), Some(true)); - assert_eq!(wot.is_enabled(NodeId(1)), Some(true)); - assert_eq!(wot.is_enabled(NodeId(2)), Some(true)); - assert_eq!(wot.is_enabled(NodeId(3)), Some(true)); - assert_eq!(wot.is_enabled(NodeId(11)), Some(true)); + assert_eq!(wot.is_enabled(WotId(0)), Some(true)); + assert_eq!(wot.is_enabled(WotId(1)), Some(true)); + assert_eq!(wot.is_enabled(WotId(2)), Some(true)); + assert_eq!(wot.is_enabled(WotId(3)), Some(true)); + assert_eq!(wot.is_enabled(WotId(11)), Some(true)); // should be able to disable some nodes - assert_eq!(wot.set_enabled(NodeId(0), false), Some(false)); - assert_eq!(wot.set_enabled(NodeId(1), false), Some(false)); - assert_eq!(wot.set_enabled(NodeId(2), false), Some(false)); + assert_eq!(wot.set_enabled(WotId(0), false), Some(false)); + assert_eq!(wot.set_enabled(WotId(1), false), Some(false)); + assert_eq!(wot.set_enabled(WotId(2), false), Some(false)); assert_eq!(wot.get_disabled().len(), 3); - assert_eq!(wot.set_enabled(NodeId(1), true), Some(true)); + assert_eq!(wot.set_enabled(WotId(1), true), Some(true)); // node 0 and 2 should be disabled - assert_eq!(wot.is_enabled(NodeId(0)), Some(false)); - assert_eq!(wot.is_enabled(NodeId(1)), Some(true)); - assert_eq!(wot.is_enabled(NodeId(2)), Some(false)); - assert_eq!(wot.is_enabled(NodeId(3)), Some(true)); + assert_eq!(wot.is_enabled(WotId(0)), Some(false)); + assert_eq!(wot.is_enabled(WotId(1)), Some(true)); + assert_eq!(wot.is_enabled(WotId(2)), Some(false)); + assert_eq!(wot.is_enabled(WotId(3)), Some(true)); // - set enabled again - assert_eq!(wot.set_enabled(NodeId(0), true), Some(true)); - assert_eq!(wot.set_enabled(NodeId(1), true), Some(true)); - assert_eq!(wot.set_enabled(NodeId(2), true), Some(true)); - assert_eq!(wot.set_enabled(NodeId(1), true), Some(true)); + assert_eq!(wot.set_enabled(WotId(0), true), Some(true)); + assert_eq!(wot.set_enabled(WotId(1), true), Some(true)); + assert_eq!(wot.set_enabled(WotId(2), true), Some(true)); + assert_eq!(wot.set_enabled(WotId(1), true), Some(true)); assert_eq!(wot.get_disabled().len(), 0); // should not exist a link from 2 to 0 - assert_eq!( - wot.has_link(NodeId(2), NodeId(0)), - HasLinkResult::Link(false) - ); + assert_eq!(wot.has_link(WotId(2), WotId(0)), HasLinkResult::Link(false)); // should be able to add some links, cert count is returned - assert_eq!(wot.add_link(NodeId(2), NodeId(0)), NewLinkResult::Ok(1)); - assert_eq!(wot.add_link(NodeId(4), NodeId(0)), NewLinkResult::Ok(2)); - assert_eq!(wot.add_link(NodeId(5), NodeId(0)), NewLinkResult::Ok(3)); + 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(5), WotId(0)), NewLinkResult::Ok(3)); // should exist new links /* WoT is: @@ -203,28 +174,13 @@ mod tests { * 5 --> 0 */ - assert_eq!( - wot.has_link(NodeId(2), NodeId(0)), - HasLinkResult::Link(true) - ); - assert_eq!( - wot.has_link(NodeId(4), NodeId(0)), - HasLinkResult::Link(true) - ); - assert_eq!( - wot.has_link(NodeId(5), NodeId(0)), - HasLinkResult::Link(true) - ); - assert_eq!( - wot.has_link(NodeId(2), NodeId(1)), - HasLinkResult::Link(false) - ); + assert_eq!(wot.has_link(WotId(2), WotId(0)), HasLinkResult::Link(true)); + assert_eq!(wot.has_link(WotId(4), WotId(0)), HasLinkResult::Link(true)); + assert_eq!(wot.has_link(WotId(5), WotId(0)), HasLinkResult::Link(true)); + assert_eq!(wot.has_link(WotId(2), WotId(1)), HasLinkResult::Link(false)); // should be able to remove some links - assert_eq!( - wot.rem_link(NodeId(4), NodeId(0)), - RemLinkResult::Removed(2) - ); + assert_eq!(wot.rem_link(WotId(4), WotId(0)), RemLinkResult::Removed(2)); /* * WoT is now: * @@ -233,29 +189,17 @@ mod tests { */ // should exist less links - assert_eq!( - wot.has_link(NodeId(2), NodeId(0)), - HasLinkResult::Link(true) - ); - assert_eq!( - wot.has_link(NodeId(4), NodeId(0)), - HasLinkResult::Link(false) - ); - assert_eq!( - wot.has_link(NodeId(5), NodeId(0)), - HasLinkResult::Link(true) - ); - assert_eq!( - wot.has_link(NodeId(2), NodeId(1)), - HasLinkResult::Link(false) - ); + assert_eq!(wot.has_link(WotId(2), WotId(0)), HasLinkResult::Link(true)); + assert_eq!(wot.has_link(WotId(4), WotId(0)), HasLinkResult::Link(false)); + assert_eq!(wot.has_link(WotId(5), WotId(0)), HasLinkResult::Link(true)); + assert_eq!(wot.has_link(WotId(2), WotId(1)), HasLinkResult::Link(false)); // should successfully use distance rule assert_eq!( distance_calculator.is_outdistanced( &wot, WotDistanceParameters { - node: NodeId(0), + node: WotId(0), sentry_requirement: 1, step_max: 1, x_percent: 1.0, @@ -268,7 +212,7 @@ mod tests { distance_calculator.is_outdistanced( &wot, WotDistanceParameters { - node: NodeId(0), + node: WotId(0), sentry_requirement: 2, step_max: 1, x_percent: 1.0, @@ -281,7 +225,7 @@ mod tests { distance_calculator.is_outdistanced( &wot, WotDistanceParameters { - node: NodeId(0), + node: WotId(0), sentry_requirement: 3, step_max: 1, x_percent: 1.0, @@ -292,8 +236,8 @@ mod tests { // => no because no member has issued 3 certifications // - we add links from member 3 - assert_eq!(wot.add_link(NodeId(3), NodeId(1)), NewLinkResult::Ok(1)); - assert_eq!(wot.add_link(NodeId(3), NodeId(2)), NewLinkResult::Ok(1)); + assert_eq!(wot.add_link(WotId(3), WotId(1)), NewLinkResult::Ok(1)); + assert_eq!(wot.add_link(WotId(3), WotId(2)), NewLinkResult::Ok(1)); /* * WoT is now: * @@ -304,29 +248,23 @@ mod tests { */ assert_eq!(wot.size(), 12); assert_eq!(wot.get_sentries(1).len(), 1); - assert_eq!(wot.get_sentries(1)[0], NodeId(2)); + assert_eq!(wot.get_sentries(1)[0], WotId(2)); assert_eq!(wot.get_sentries(2).len(), 0); assert_eq!(wot.get_sentries(3).len(), 0); assert_eq!(wot.get_non_sentries(1).len(), 11); // 12 - 1 assert_eq!(wot.get_non_sentries(2).len(), 12); // 12 - 0 assert_eq!(wot.get_non_sentries(3).len(), 12); // 12 - 0 - assert_eq!( - path_finder.find_paths(&wot, NodeId(3), NodeId(0), 1).len(), - 0 - ); // KO - assert_eq!( - path_finder.find_paths(&wot, NodeId(3), NodeId(0), 2).len(), - 1 - ); // It exists 3 -> 2 -> 0 + assert_eq!(path_finder.find_paths(&wot, WotId(3), WotId(0), 1).len(), 0); // KO + assert_eq!(path_finder.find_paths(&wot, WotId(3), WotId(0), 2).len(), 1); // It exists 3 -> 2 -> 0 assert!(path_finder - .find_paths(&wot, NodeId(3), NodeId(0), 2) - .contains(&vec![NodeId(3), NodeId(2), NodeId(0)])); + .find_paths(&wot, WotId(3), WotId(0), 2) + .contains(&vec![WotId(3), WotId(2), WotId(0)])); assert_eq!( distance_calculator.is_outdistanced( &wot, WotDistanceParameters { - node: NodeId(0), + node: WotId(0), sentry_requirement: 1, step_max: 1, x_percent: 1.0, @@ -338,7 +276,7 @@ mod tests { distance_calculator.is_outdistanced( &wot, WotDistanceParameters { - node: NodeId(0), + node: WotId(0), sentry_requirement: 2, step_max: 1, x_percent: 1.0, @@ -350,7 +288,7 @@ mod tests { distance_calculator.is_outdistanced( &wot, WotDistanceParameters { - node: NodeId(0), + node: WotId(0), sentry_requirement: 3, step_max: 1, x_percent: 1.0, @@ -362,7 +300,7 @@ mod tests { distance_calculator.is_outdistanced( &wot, WotDistanceParameters { - node: NodeId(0), + node: WotId(0), sentry_requirement: 2, step_max: 2, x_percent: 1.0, @@ -371,38 +309,32 @@ mod tests { Some(false) ); // OK : 2 -> 0 - wot.add_link(NodeId(1), NodeId(3)); - wot.add_link(NodeId(2), NodeId(3)); + wot.add_link(WotId(1), WotId(3)); + wot.add_link(WotId(2), WotId(3)); assert_eq!(wot.size(), 12); assert_eq!(wot.get_sentries(1).len(), 3); - assert_eq!(wot.get_sentries(1)[0], NodeId(1)); - assert_eq!(wot.get_sentries(1)[1], NodeId(2)); - assert_eq!(wot.get_sentries(1)[2], NodeId(3)); + assert_eq!(wot.get_sentries(1)[0], WotId(1)); + assert_eq!(wot.get_sentries(1)[1], WotId(2)); + assert_eq!(wot.get_sentries(1)[2], WotId(3)); assert_eq!(wot.get_sentries(2).len(), 1); - assert_eq!(wot.get_sentries(2)[0], NodeId(3)); + assert_eq!(wot.get_sentries(2)[0], WotId(3)); assert_eq!(wot.get_sentries(3).len(), 0); assert_eq!(wot.get_non_sentries(1).len(), 9); // 12 - 3 assert_eq!(wot.get_non_sentries(2).len(), 11); // 12 - 1 assert_eq!(wot.get_non_sentries(3).len(), 12); // 12 - 0 - assert_eq!( - path_finder.find_paths(&wot, NodeId(3), NodeId(0), 1).len(), - 0 - ); // KO - assert_eq!( - path_finder.find_paths(&wot, NodeId(3), NodeId(0), 2).len(), - 1 - ); // It exists 3 -> 2 -> 0 + assert_eq!(path_finder.find_paths(&wot, WotId(3), WotId(0), 1).len(), 0); // KO + assert_eq!(path_finder.find_paths(&wot, WotId(3), WotId(0), 2).len(), 1); // It exists 3 -> 2 -> 0 assert!(path_finder - .find_paths(&wot, NodeId(3), NodeId(0), 2) - .contains(&vec![NodeId(3), NodeId(2), NodeId(0)])); + .find_paths(&wot, WotId(3), WotId(0), 2) + .contains(&vec![WotId(3), WotId(2), WotId(0)])); assert_eq!( distance_calculator.is_outdistanced( &wot, WotDistanceParameters { - node: NodeId(0), + node: WotId(0), sentry_requirement: 1, step_max: 1, x_percent: 1.0, @@ -414,7 +346,7 @@ mod tests { distance_calculator.is_outdistanced( &wot, WotDistanceParameters { - node: NodeId(0), + node: WotId(0), sentry_requirement: 2, step_max: 1, x_percent: 1.0, @@ -426,7 +358,7 @@ mod tests { distance_calculator.is_outdistanced( &wot, WotDistanceParameters { - node: NodeId(0), + node: WotId(0), sentry_requirement: 3, step_max: 1, x_percent: 1.0, @@ -438,7 +370,7 @@ mod tests { distance_calculator.is_outdistanced( &wot, WotDistanceParameters { - node: NodeId(0), + node: WotId(0), sentry_requirement: 2, step_max: 2, x_percent: 1.0, @@ -451,20 +383,20 @@ mod tests { assert_eq!(wot.size(), 12); // delete top node (return new top node id) - assert_eq!(wot.rem_node(), Some(NodeId(10))); + assert_eq!(wot.rem_node(), Some(WotId(10))); // should have 11 nodes assert_eq!(wot.size(), 11); // should work with member 3 disabled // - with member 3 disabled (non-member) - assert_eq!(wot.set_enabled(NodeId(3), false), Some(false)); + assert_eq!(wot.set_enabled(WotId(3), false), Some(false)); assert_eq!(wot.get_disabled().len(), 1); assert_eq!( distance_calculator.is_outdistanced( &wot, WotDistanceParameters { - node: NodeId(0), + node: WotId(0), sentry_requirement: 2, step_max: 1, x_percent: 1.0, @@ -473,28 +405,19 @@ mod tests { Some(false) ); // OK : Disabled - let file_formater = BinaryFileFormater {}; - // Write wot in file - assert_eq!( - file_formater - .to_file( - &wot, - &[0b0000_0000, 0b0000_0001, 0b0000_0001, 0b0000_0000], - "test.wot" - ) - .unwrap(), - () - ); + durs_common_tools::fns::bin_file::write_bin_file( + Path::new("test.wot"), + &bincode::serialize(&wot).expect("fail to serialize wot"), + ) + .expect("fail to write wot file"); - let (wot2, blockstamp2) = file_formater.from_file::<W>("test.wot", 3).unwrap(); + let wot2_bin = durs_common_tools::fns::bin_file::read_bin_file(Path::new("test.wot")) + .expect("fail to read wot file"); + let wot2: W = bincode::deserialize(&wot2_bin).expect("fail to deserialize wot"); // Read wot from file { - assert_eq!( - blockstamp2, - vec![0b0000_0000, 0b0000_0001, 0b0000_0001, 0b0000_0000] - ); assert_eq!(wot.size(), wot2.size()); assert_eq!( wot.get_non_sentries(1).len(), @@ -502,12 +425,12 @@ mod tests { ); assert_eq!(wot.get_disabled().len(), wot2.get_disabled().len()); assert_eq!(wot2.get_disabled().len(), 1); - assert_eq!(wot2.is_enabled(NodeId(3)), Some(false)); + assert_eq!(wot2.is_enabled(WotId(3)), Some(false)); assert_eq!( distance_calculator.is_outdistanced( &wot2, WotDistanceParameters { - node: NodeId(0), + node: WotId(0), sentry_requirement: 2, step_max: 1, x_percent: 1.0, @@ -518,18 +441,10 @@ mod tests { } // Read g1_genesis wot - let (wot3, blockstamp3) = file_formater - .from_file::<W>("tests/g1_genesis.bin", 100) - .unwrap(); - assert_eq!( - blockstamp3, - vec![ - 57, 57, 45, 48, 48, 48, 48, 49, 50, 65, 68, 52, 57, 54, 69, 67, 65, 53, 54, 68, 69, - 48, 66, 56, 69, 53, 68, 54, 70, 55, 52, 57, 66, 55, 67, 66, 69, 55, 56, 53, 53, 51, - 69, 54, 51, 56, 53, 51, 51, 51, 65, 52, 52, 69, 48, 52, 51, 55, 55, 69, 70, 70, 67, - 67, 65, 53, 51, - ] - ); + let wot3_bin = + durs_common_tools::fns::bin_file::read_bin_file(Path::new("tests/g1_genesis.bin")) + .expect("fail to read g1_genesis wot file"); + let wot3: W = bincode::deserialize(&wot3_bin).expect("fail to deserialize g1_genesis wot"); // Check g1_genesis wot members_count let members_count = wot3.get_enabled().len() as u64; @@ -540,7 +455,7 @@ mod tests { distance_calculator.compute_distance( &wot3, WotDistanceParameters { - node: NodeId(37), + node: WotId(37), sentry_requirement: 3, step_max: 5, x_percent: 0.8, diff --git a/lib/dubp/wot/operations/centrality.rs b/lib/dubp/wot/operations/centrality.rs index d15d63debfb70803b1b3e4b511561a19989d5819..f1225e1163649060cb5b36fc71205c8642eb9643 100644 --- a/lib/dubp/wot/operations/centrality.rs +++ b/lib/dubp/wot/operations/centrality.rs @@ -15,8 +15,8 @@ //! Provide a trait and implementations to find paths between nodes. -use crate::data::NodeId; use crate::data::WebOfTrust; +use crate::data::WotId; use std::collections::{HashMap, VecDeque}; /// Find paths between 2 nodes of a `WebOfTrust`. @@ -41,11 +41,11 @@ impl<T: WebOfTrust> CentralitiesCalculator<T> for UlrikBrandesCentralityCalculat // The source of any path belongs to enabled_nodes for s in enabled_nodes.clone() { - let mut stack: Vec<NodeId> = Vec::with_capacity(wot_size); - let mut paths: HashMap<NodeId, Vec<NodeId>> = HashMap::with_capacity(wot_size); + let mut stack: Vec<WotId> = Vec::with_capacity(wot_size); + let mut paths: HashMap<WotId, Vec<WotId>> = HashMap::with_capacity(wot_size); let mut sigma = vec![0.0; wot_size]; let mut d: Vec<isize> = vec![-1; wot_size]; - let mut q: VecDeque<NodeId> = VecDeque::with_capacity(wot_size); + let mut q: VecDeque<WotId> = VecDeque::with_capacity(wot_size); sigma[s.0] = 1.0; d[s.0] = 0; @@ -94,11 +94,11 @@ impl<T: WebOfTrust> CentralitiesCalculator<T> for UlrikBrandesCentralityCalculat // The source of any path belongs to enabled_nodes for s in enabled_nodes.clone() { - let mut stack: Vec<NodeId> = Vec::with_capacity(wot_size); - let mut paths: HashMap<NodeId, Vec<NodeId>> = HashMap::with_capacity(wot_size); + let mut stack: Vec<WotId> = Vec::with_capacity(wot_size); + let mut paths: HashMap<WotId, Vec<WotId>> = HashMap::with_capacity(wot_size); let mut sigma = vec![0.0; wot_size]; let mut d: Vec<isize> = vec![-1; wot_size]; - let mut q: VecDeque<NodeId> = VecDeque::with_capacity(wot_size); + let mut q: VecDeque<WotId> = VecDeque::with_capacity(wot_size); sigma[s.0] = 1.0; d[s.0] = 0; @@ -147,11 +147,11 @@ impl<T: WebOfTrust> CentralitiesCalculator<T> for UlrikBrandesCentralityCalculat // The source of any path belongs to enabled_nodes for s in enabled_nodes.clone() { - let mut stack: Vec<NodeId> = Vec::with_capacity(wot_size); - let mut paths: HashMap<NodeId, Vec<NodeId>> = HashMap::with_capacity(wot_size); + let mut stack: Vec<WotId> = Vec::with_capacity(wot_size); + let mut paths: HashMap<WotId, Vec<WotId>> = HashMap::with_capacity(wot_size); let mut sigma = vec![0.0; wot_size]; let mut d: Vec<isize> = vec![-1; wot_size]; - let mut q: VecDeque<NodeId> = VecDeque::with_capacity(wot_size); + let mut q: VecDeque<WotId> = VecDeque::with_capacity(wot_size); sigma[s.0] = 1.0; d[s.0] = 0; diff --git a/lib/dubp/wot/operations/distance.rs b/lib/dubp/wot/operations/distance.rs index 6e7c4b23ecaab2fd3ac03da32e83cd8385848384..4fb1dd12932b785766c48b7d82504c8852fcde8f 100644 --- a/lib/dubp/wot/operations/distance.rs +++ b/lib/dubp/wot/operations/distance.rs @@ -15,8 +15,8 @@ //! Provide a trait and implementations to compute distances. -use crate::data::NodeId; use crate::data::WebOfTrust; +use crate::data::WotId; use rayon::prelude::*; use std::collections::HashSet; @@ -24,7 +24,7 @@ use std::collections::HashSet; #[derive(Debug, Copy, Clone, PartialEq)] pub struct WotDistanceParameters { /// Node from where distances are calculated. - pub node: NodeId, + pub node: WotId, /// Links count received AND issued to be a sentry. pub sentry_requirement: u32, /// Currency parameter. diff --git a/lib/dubp/wot/operations/file.rs b/lib/dubp/wot/operations/file.rs deleted file mode 100644 index 2f4a87decb8f22b7b1ba94e6fa0d4c39d2c22a89..0000000000000000000000000000000000000000 --- a/lib/dubp/wot/operations/file.rs +++ /dev/null @@ -1,252 +0,0 @@ -// Copyright (C) 2017-2019 The AXIOM TEAM Association. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see <https://www.gnu.org/licenses/>. - -//! Provide a trait and implementation to read and write `WebOfTrust` to disk. - -use crate::data::NodeId; -use durs_common_tools::fatal_error; -use std::fs; -use std::fs::File; -use std::io; -use std::io::prelude::*; - -use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt}; - -use crate::data::WebOfTrust; - -/// Results of `WebOfTrust` parsing from binary file. -#[derive(Debug)] -pub enum WotParseError { - /// FailToOpenFile - FailToOpenFile(io::Error), - - /// IOError - IOError(io::Error), -} - -impl From<io::Error> for WotParseError { - fn from(e: io::Error) -> WotParseError { - WotParseError::IOError(e) - } -} - -/// Results of `WebOfTrust` writing to binary file. -#[derive(Debug)] -pub enum WotWriteError { - /// WrongWotSize - WrongWotSize(), - - /// FailToCreateFile - FailToCreateFile(io::Error), - - /// FailToWriteInFile - FailToWriteInFile(io::Error), -} - -impl From<io::Error> for WotWriteError { - fn from(e: io::Error) -> WotWriteError { - WotWriteError::FailToWriteInFile(e) - } -} - -/// Provide Read/Write functions for `WebOfTrust` objects. -pub trait FileFormater { - /// Try to read a `WebOfTrust` from a file. - fn from_file<T: WebOfTrust>( - &self, - path: &str, - max_links: usize, - ) -> Result<(T, Vec<u8>), WotParseError>; - - /// Tru to write a `WebOfTrust` in a file. - fn to_file<T: WebOfTrust>(&self, wot: &T, data: &[u8], path: &str) - -> Result<(), WotWriteError>; -} - -/// Read and write WebOfTrust in a binary format. -#[derive(Debug, Clone, Copy)] -pub struct BinaryFileFormater; - -impl FileFormater for BinaryFileFormater { - /// Try to read a `WebOfTrust` from a file. - fn from_file<T: WebOfTrust>( - &self, - path: &str, - max_links: usize, - ) -> Result<(T, Vec<u8>), WotParseError> { - let mut wot = T::new(max_links); - - let file_size = fs::metadata(path).expect("fail to read wot file !").len(); - let mut file_pointing_to_blockstamp_size: Vec<u8> = vec![0; file_size as usize]; - match File::open(path) { - Ok(mut file) => { - file.read_exact(&mut file_pointing_to_blockstamp_size.as_mut_slice())?; - } - Err(e) => return Err(WotParseError::FailToOpenFile(e)), - }; - // Read up to 4 bytes (blockstamp_size) - let mut file_pointing_to_blockstamp = file_pointing_to_blockstamp_size.split_off(4); - // Get blockstamp size - let mut buf = &file_pointing_to_blockstamp_size[..]; - let blockstamp_size = buf.read_u32::<BigEndian>().unwrap(); - // Read up to blockstamp_size bytes (blockstamp) - let mut file_pointing_to_nodes_count = - file_pointing_to_blockstamp.split_off(blockstamp_size as usize); - // Read up to 4 bytes (nodes_count) - let mut file_pointing_to_nodes_states = file_pointing_to_nodes_count.split_off(4); - // Read nodes_count - let mut buf = &file_pointing_to_nodes_count[..]; - let nodes_count = buf.read_u32::<BigEndian>().unwrap(); - // Calcule nodes_state size - let nodes_states_size = match nodes_count % 8 { - 0 => nodes_count / 8, - _ => (nodes_count / 8) + 1, - }; - // Read up to nodes_states_size bytes (nodes_states) - let file_pointing_to_links = - file_pointing_to_nodes_states.split_off(nodes_states_size as usize); - let count_total_bytes_read = file_pointing_to_links.len() - + nodes_states_size as usize - + 4 - + blockstamp_size as usize - + 4; - if count_total_bytes_read != file_size as usize { - fatal_error!("not read all wot file !"); - } - // Apply nodes state - let mut count_remaining_nodes = nodes_count; - for byte in file_pointing_to_nodes_states { - let mut byte_integer = u8::from_be(byte); - let mut factor: u8 = 128; - for _i in 0..8 { - if count_remaining_nodes > 0 { - wot.add_node(); - if byte_integer >= factor { - byte_integer -= factor; - } else { - let _test = wot.set_enabled( - NodeId((nodes_count - count_remaining_nodes) as usize), - false, - ); - } - count_remaining_nodes -= 1; - } - factor /= 2; - } - } - // Apply links - let mut buffer_3b: Vec<u8> = Vec::with_capacity(3); - let mut count_bytes = 0; - let mut remaining_links: u8 = 0; - let mut target: u32 = 0; - for byte in file_pointing_to_links { - if remaining_links == 0 { - target += 1; - remaining_links = u8::from_be(byte); - count_bytes = 0; - } else { - buffer_3b.push(byte); - if count_bytes % 3 == 2 { - let mut buf = &buffer_3b.clone()[..]; - let source = buf.read_u24::<BigEndian>().expect("fail to parse source"); - wot.add_link(NodeId(source as usize), NodeId((target - 1) as usize)); - remaining_links -= 1; - buffer_3b.clear(); - } - count_bytes += 1; - } - } - if count_bytes % 3 != 0 { - fatal_error!("not read all wot file !"); - } - Ok((wot, file_pointing_to_blockstamp)) - } - - /// Try to write a `WebOfTrust` in a file. - fn to_file<T: WebOfTrust>( - &self, - wot: &T, - data: &[u8], - path: &str, - ) -> Result<(), WotWriteError> { - let mut buffer: Vec<u8> = Vec::new(); - // Write blockstamp size - let blockstamp_size = data.len() as u32; - let mut bytes: Vec<u8> = Vec::with_capacity(4); - bytes.write_u32::<BigEndian>(blockstamp_size).unwrap(); - buffer.append(&mut bytes); - // Write blockstamp - buffer.append(&mut data.to_vec()); - // Write nodes_count - let nodes_count = wot.size() as u32; - let mut bytes: Vec<u8> = Vec::with_capacity(4); - bytes.write_u32::<BigEndian>(nodes_count).unwrap(); - buffer.append(&mut bytes); - // Write enable state by groups of 8 - let mut enable_states: u8 = 0; - let mut factor: u8 = 128; - for n in 0..nodes_count { - match wot.is_enabled(NodeId(n as usize)) { - Some(enable) => { - if enable { - enable_states += factor; - } - } - None => { - return Err(WotWriteError::WrongWotSize()); - } - } - if n % 8 == 7 { - factor = 128; - let mut tmp_buf = Vec::with_capacity(1); - tmp_buf.write_u8(enable_states).unwrap(); - buffer.append(&mut tmp_buf); - enable_states = 0; - } else { - factor /= 2; - } - } - // nodes_states padding - if nodes_count % 8 != 7 { - let mut tmp_buf = Vec::with_capacity(1); - tmp_buf.write_u8(enable_states).unwrap(); - buffer.append(&mut tmp_buf); - } - // Write links - for n in 0..nodes_count { - if let Some(sources) = wot.get_links_source(NodeId(n as usize)) { - // Write sources_counts - let mut bytes = Vec::with_capacity(1); - bytes.write_u8(sources.len() as u8).unwrap(); - buffer.append(&mut bytes); - for source in &sources { - // Write source - let mut bytes: Vec<u8> = Vec::with_capacity(3); - bytes.write_u24::<BigEndian>(source.0 as u32).unwrap(); - buffer.append(&mut bytes); - } - }; - } - // Create or open file - let mut file = match File::create(path) { - Ok(file) => file, - Err(e) => return Err(WotWriteError::FailToCreateFile(e)), - }; - // Write buffer in file - file.write_all(&buffer)?; - - Ok(()) - } -} diff --git a/lib/dubp/wot/operations/mod.rs b/lib/dubp/wot/operations/mod.rs index 4a1220464ab5600940b0dc0429c5fbc445ce16b0..cbb938ee7381e0f6cb5c1f21cacbb0f863e184c5 100644 --- a/lib/dubp/wot/operations/mod.rs +++ b/lib/dubp/wot/operations/mod.rs @@ -17,5 +17,4 @@ pub mod centrality; pub mod distance; -pub mod file; pub mod path; diff --git a/lib/dubp/wot/operations/path.rs b/lib/dubp/wot/operations/path.rs index 75e22f0a566a492a739c8b5705317bda530b2403..99a3a8e39fc78de0c3e3f36b9228ef0e99f8d763 100644 --- a/lib/dubp/wot/operations/path.rs +++ b/lib/dubp/wot/operations/path.rs @@ -15,14 +15,14 @@ //! Provide a trait and implementations to find paths between nodes. -use crate::data::NodeId; use crate::data::WebOfTrust; +use crate::data::WotId; use std::collections::HashSet; /// Find paths between 2 nodes of a `WebOfTrust`. pub trait PathFinder<T: WebOfTrust> { /// Get paths from one node to the other. - fn find_paths(&self, wot: &T, from: NodeId, to: NodeId, k_max: u32) -> Vec<Vec<NodeId>>; + fn find_paths(&self, wot: &T, from: WotId, to: WotId, k_max: u32) -> Vec<Vec<WotId>>; } /// A new "rusty-er" implementation of `WoT` path finding. @@ -30,7 +30,7 @@ pub trait PathFinder<T: WebOfTrust> { pub struct RustyPathFinder; impl<T: WebOfTrust> PathFinder<T> for RustyPathFinder { - fn find_paths(&self, wot: &T, from: NodeId, to: NodeId, k_max: u32) -> Vec<Vec<NodeId>> { + fn find_paths(&self, wot: &T, from: WotId, to: WotId, k_max: u32) -> Vec<Vec<WotId>> { if from.0 >= wot.size() || to.0 >= wot.size() { return vec![]; } @@ -40,7 +40,7 @@ impl<T: WebOfTrust> PathFinder<T> for RustyPathFinder { // Stores for each node its distance to `to` node and its backward links. // By default all nodes are out of range (`k_max + 1`) and links are known. - let mut graph: Vec<(u32, Vec<NodeId>)> = + let mut graph: Vec<(u32, Vec<WotId>)> = (0..wot.size()).map(|_| (k_max + 1, vec![])).collect(); // `to` node is at distance 0, and have no backward links. graph[to.0] = (0, vec![]); diff --git a/lib/dubp/wot/tests/g1_genesis.bin b/lib/dubp/wot/tests/g1_genesis.bin index e7838df9c9efb58d10cbbb7f8a3ba1a2a4407db5..d684f6197a5442ff4860dec581a65b19456a51d4 100644 Binary files a/lib/dubp/wot/tests/g1_genesis.bin and b/lib/dubp/wot/tests/g1_genesis.bin differ diff --git a/lib/modules/blockchain/blockchain-dal/src/entities/block.rs b/lib/modules/blockchain/blockchain-dal/src/entities/block.rs index e93bdd72b3a1b7004d2c191722cab6999009bdc6..67e27062cabcf6b1af837dd35566c3d682bcdbd8 100644 --- a/lib/modules/blockchain/blockchain-dal/src/entities/block.rs +++ b/lib/modules/blockchain/blockchain-dal/src/entities/block.rs @@ -17,7 +17,7 @@ use crate::*; use dubp_block_doc::block::{BlockDocument, BlockDocumentTrait}; use dubp_common_doc::traits::Document; use dubp_common_doc::BlockNumber; -use durs_wot::NodeId; +use durs_wot::WotId; use std::collections::HashMap; #[derive(Clone, Debug, Deserialize, Serialize)] @@ -28,7 +28,7 @@ pub struct DALBlock { /// List of certifications that expire in this block. /// Warning : BlockNumber contain the emission block, not the written block ! /// HashMap<(Source, Target), BlockNumber> - pub expire_certs: Option<HashMap<(NodeId, NodeId), BlockNumber>>, + pub expire_certs: Option<HashMap<(WotId, WotId), BlockNumber>>, } impl DALBlock { diff --git a/lib/modules/blockchain/blockchain-dal/src/entities/identity.rs b/lib/modules/blockchain/blockchain-dal/src/entities/identity.rs index ab1e1e4344a3899e68596474373e5daab8d056ca..934002ffea1942edb9c3c184820cadc7cc762423 100644 --- a/lib/modules/blockchain/blockchain-dal/src/entities/identity.rs +++ b/lib/modules/blockchain/blockchain-dal/src/entities/identity.rs @@ -15,7 +15,7 @@ use dubp_common_doc::{BlockNumber, Blockstamp}; use dubp_user_docs::documents::identity::IdentityDocumentV10; -use durs_wot::NodeId; +use durs_wot::WotId; #[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq, Hash)] /// Identity state @@ -48,7 +48,7 @@ pub struct DALIdentity { /// Identity document pub idty_doc: IdentityDocumentV10, /// Identity wot id - pub wot_id: NodeId, + pub wot_id: WotId, /// Membership created block number pub ms_created_block_id: BlockNumber, /// Timestamp from which membership can be renewed diff --git a/lib/modules/blockchain/blockchain-dal/src/lib.rs b/lib/modules/blockchain/blockchain-dal/src/lib.rs index 7b2d1158b81f81597768391f8a1378de0bd7f6c8..9335720fe7ad359cd5a9d9c50309727cf69ea183 100644 --- a/lib/modules/blockchain/blockchain-dal/src/lib.rs +++ b/lib/modules/blockchain/blockchain-dal/src/lib.rs @@ -56,7 +56,7 @@ use dubp_user_docs::documents::transaction::*; use dup_crypto::hashs::Hash; use dup_crypto::keys::*; use durs_common_tools::fatal_error; -use durs_wot::data::{rusty::RustyWebOfTrust, NodeId}; +use durs_wot::data::{rusty::RustyWebOfTrust, WotId}; use fnv::FnvHashMap; use rustbreak::backend::{FileBackend, MemoryBackend}; use rustbreak::error::{RustbreakError, RustbreakErrorKind}; @@ -89,9 +89,9 @@ pub type WotDB = RustyWebOfTrust; /// V10 Identities indexed by public key pub type IdentitiesV10Datas = HashMap<PubKey, DALIdentity>; /// Memberships sorted by created block -pub type MsExpirV10Datas = FnvHashMap<BlockNumber, HashSet<NodeId>>; +pub type MsExpirV10Datas = FnvHashMap<BlockNumber, HashSet<WotId>>; /// Certifications sorted by created block -pub type CertsExpirV10Datas = FnvHashMap<BlockNumber, HashSet<(NodeId, NodeId)>>; +pub type CertsExpirV10Datas = FnvHashMap<BlockNumber, HashSet<(WotId, WotId)>>; /// V10 Transactions indexed by their hashs pub type TxV10Datas = HashMap<Hash, DALTxV10>; /// V10 Unused Transaction Output (=sources) diff --git a/lib/modules/blockchain/blockchain-dal/src/readers/certs.rs b/lib/modules/blockchain/blockchain-dal/src/readers/certs.rs index f745d953c1fd8983009bac60aaba0c52d1907e68..2c65e770d63deee7646cc72254ffa084a7dcc4bd 100644 --- a/lib/modules/blockchain/blockchain-dal/src/readers/certs.rs +++ b/lib/modules/blockchain/blockchain-dal/src/readers/certs.rs @@ -15,14 +15,14 @@ use crate::{BinDB, CertsExpirV10Datas, DALError}; use dubp_common_doc::BlockNumber; -use durs_wot::NodeId; +use durs_wot::WotId; use std::collections::HashMap; /// Find certifications that emitted in indicated blocks expiring pub fn find_expire_certs( certs_db: &BinDB<CertsExpirV10Datas>, blocks_expiring: Vec<BlockNumber>, -) -> Result<HashMap<(NodeId, NodeId), BlockNumber>, DALError> { +) -> Result<HashMap<(WotId, WotId), BlockNumber>, DALError> { Ok(certs_db.read(|db| { let mut all_expire_certs = HashMap::new(); for expire_block_id in blocks_expiring { diff --git a/lib/modules/blockchain/blockchain-dal/src/readers/identity.rs b/lib/modules/blockchain/blockchain-dal/src/readers/identity.rs index 0e931916e8276ba72dceccc95a21b2334689f930..b6eb745a6e195ba2d590e7251857cb7d711bc93f 100644 --- a/lib/modules/blockchain/blockchain-dal/src/readers/identity.rs +++ b/lib/modules/blockchain/blockchain-dal/src/readers/identity.rs @@ -19,7 +19,7 @@ use crate::{BinDB, DALError, IdentitiesV10Datas}; use dubp_common_doc::traits::Document; use dubp_common_doc::BlockNumber; use dup_crypto::keys::*; -use durs_wot::NodeId; +use durs_wot::WotId; use std::collections::HashMap; /// Get identities in databases @@ -106,7 +106,7 @@ pub fn get_pubkey_from_uid( /// Get wot_id index pub fn get_wot_index( identities_db: &BinDB<IdentitiesV10Datas>, -) -> Result<HashMap<PubKey, NodeId>, DALError> { +) -> Result<HashMap<PubKey, WotId>, DALError> { Ok(identities_db.read(|db| { db.iter() .map(|(pubkey, member_datas)| (*pubkey, member_datas.wot_id)) @@ -136,7 +136,7 @@ mod test { pubkey, created_block_id, ), - wot_id: NodeId(0), + wot_id: WotId(0), ms_created_block_id: BlockNumber(0), ms_chainable_on: vec![], cert_chainable_on: vec![], diff --git a/lib/modules/blockchain/blockchain-dal/src/tools.rs b/lib/modules/blockchain/blockchain-dal/src/tools.rs index c3e3286acb0608faed8222c6189bf8c7cd3cfecb..507a31fe65ed2edd4fc02d009e7cc4b174ea01fa 100644 --- a/lib/modules/blockchain/blockchain-dal/src/tools.rs +++ b/lib/modules/blockchain/blockchain-dal/src/tools.rs @@ -21,7 +21,7 @@ use durs_wot::operations::centrality::{CentralitiesCalculator, UlrikBrandesCentr use durs_wot::operations::distance::{ DistanceCalculator, RustyDistanceCalculator, WotDistance, WotDistanceParameters, }; -use durs_wot::{NodeId, WebOfTrust}; +use durs_wot::{WebOfTrust, WotId}; use std::collections::HashMap; /// CENTRALITY_CALCULATOR @@ -109,7 +109,7 @@ pub fn compute_distances<T: WebOfTrust + Sync>( .compute_distance( wot, WotDistanceParameters { - node: NodeId(i), + node: WotId(i), sentry_requirement, step_max, x_percent, diff --git a/lib/modules/blockchain/blockchain-dal/src/writers/certification.rs b/lib/modules/blockchain/blockchain-dal/src/writers/certification.rs index 63cd60e48d6caa8600c82747d88fbcecc8575e10..730c994294d1fe399f4bfe9c97b94efac4542b22 100644 --- a/lib/modules/blockchain/blockchain-dal/src/writers/certification.rs +++ b/lib/modules/blockchain/blockchain-dal/src/writers/certification.rs @@ -18,7 +18,7 @@ use dubp_common_doc::BlockNumber; use dubp_currency_params::CurrencyParameters; use dubp_user_docs::documents::certification::CompactCertificationDocumentV10; use dup_crypto::keys::*; -use durs_wot::NodeId; +use durs_wot::WotId; /// Apply "certification" event in databases pub fn write_certification( @@ -26,8 +26,8 @@ pub fn write_certification( identities_db: &BinDB<IdentitiesV10Datas>, certs_db: &BinDB<CertsExpirV10Datas>, source_pubkey: PubKey, - source: NodeId, - target: NodeId, + source: WotId, + target: WotId, created_block_id: BlockNumber, written_timestamp: u64, ) -> Result<(), DALError> { @@ -59,8 +59,8 @@ pub fn revert_write_cert( identities_db: &BinDB<IdentitiesV10Datas>, certs_db: &BinDB<CertsExpirV10Datas>, compact_doc: CompactCertificationDocumentV10, - source: NodeId, - target: NodeId, + source: WotId, + target: WotId, ) -> Result<(), DALError> { // Remove CertsExpirV10Datas entry certs_db.write(|db| { @@ -84,8 +84,8 @@ pub fn revert_write_cert( /// Revert "certification expiry" event in databases pub fn revert_expire_cert( certs_db: &BinDB<CertsExpirV10Datas>, - source: NodeId, - target: NodeId, + source: WotId, + target: WotId, created_block_id: BlockNumber, ) -> Result<(), DALError> { // Reinsert CertsExpirV10Datas entry diff --git a/lib/modules/blockchain/blockchain-dal/src/writers/identity.rs b/lib/modules/blockchain/blockchain-dal/src/writers/identity.rs index b9ed989947e9f373dd04b0163ef101bb296a186d..2e8cb65de8b557c7a396040a01a01fd84596e349 100644 --- a/lib/modules/blockchain/blockchain-dal/src/writers/identity.rs +++ b/lib/modules/blockchain/blockchain-dal/src/writers/identity.rs @@ -21,7 +21,7 @@ use dubp_currency_params::CurrencyParameters; use dubp_user_docs::documents::identity::IdentityDocumentV10; use dup_crypto::keys::PubKey; use durs_common_tools::fatal_error; -use durs_wot::NodeId; +use durs_wot::WotId; /// Remove identity from databases pub fn revert_create_identity( @@ -57,7 +57,7 @@ pub fn create_identity( ms_db: &BinDB<MsExpirV10Datas>, idty_doc: &IdentityDocumentV10, ms_created_block_id: BlockNumber, - wot_id: NodeId, + wot_id: WotId, current_blockstamp: Blockstamp, current_bc_time: u64, ) -> Result<(), DALError> { @@ -181,7 +181,7 @@ pub fn renewal_identity( identities_db: &BinDB<IdentitiesV10Datas>, ms_db: &BinDB<MsExpirV10Datas>, pubkey: &PubKey, - idty_wot_id: NodeId, + idty_wot_id: WotId, renewal_timestamp: u64, ms_created_block_id: BlockNumber, revert: bool, diff --git a/lib/modules/blockchain/blockchain-dal/src/writers/requests.rs b/lib/modules/blockchain/blockchain-dal/src/writers/requests.rs index 7ece8baf5e3e16e099cd1d362bd0cdcfac57c53c..b79c7980c82674984a8fb3e4b4408df4cc6ca12a 100644 --- a/lib/modules/blockchain/blockchain-dal/src/writers/requests.rs +++ b/lib/modules/blockchain/blockchain-dal/src/writers/requests.rs @@ -23,7 +23,7 @@ use dubp_currency_params::CurrencyParameters; use dubp_user_docs::documents::certification::CompactCertificationDocumentV10; use dubp_user_docs::documents::identity::IdentityDocumentV10; use dup_crypto::keys::PubKey; -use durs_wot::NodeId; +use durs_wot::WotId; use std::ops::Deref; #[derive(Debug, Clone)] @@ -96,7 +96,7 @@ impl BlocksDBsWriteQuery { pub enum WotsDBsWriteQuery { /// Newcomer (wot_id, blockstamp, current_bc_time, idty_doc, ms_created_block_id) CreateIdentity( - NodeId, + WotId, Blockstamp, u64, Box<IdentityDocumentV10>, @@ -105,9 +105,9 @@ pub enum WotsDBsWriteQuery { /// Revert newcomer event (wot_id, blockstamp, current_bc_time, idty_doc, ms_created_block_id) RevertCreateIdentity(PubKey), /// Active (pubKey, idty_wot_id, current_bc_time, ms_created_block_id) - RenewalIdentity(PubKey, NodeId, u64, BlockNumber), + RenewalIdentity(PubKey, WotId, u64, BlockNumber), /// Revert active (pubKey, idty_wot_id, current_bc_time, ms_created_block_id) - RevertRenewalIdentity(PubKey, NodeId, u64, BlockNumber), + RevertRenewalIdentity(PubKey, WotId, u64, BlockNumber), /// Excluded ExcludeIdentity(PubKey, Blockstamp), /// Revert exclusion @@ -117,13 +117,13 @@ pub enum WotsDBsWriteQuery { /// Revert revocation RevertRevokeIdentity(PubKey, Blockstamp, bool), /// Certification (source_pubkey, source, target, created_block_id, median_time) - CreateCert(PubKey, NodeId, NodeId, BlockNumber, u64), + CreateCert(PubKey, WotId, WotId, BlockNumber, u64), /// Revert certification (source_pubkey, source, target, created_block_id, median_time) - RevertCert(CompactCertificationDocumentV10, NodeId, NodeId), + RevertCert(CompactCertificationDocumentV10, WotId, WotId), /// Certification expiry (source, target, created_block_id) ExpireCerts(BlockNumber), /// Revert certification expiry event (source, target, created_block_id) - RevertExpireCert(NodeId, NodeId, BlockNumber), + RevertExpireCert(WotId, WotId, BlockNumber), } impl WotsDBsWriteQuery { diff --git a/lib/modules/blockchain/blockchain/src/dbex.rs b/lib/modules/blockchain/blockchain/src/dbex.rs index cfd00ab2adffdb933c534b871b5b97e47aaaefe4..fe31cd626e3de6f9314a5a28bc3c6ac7956ecab8 100644 --- a/lib/modules/blockchain/blockchain/src/dbex.rs +++ b/lib/modules/blockchain/blockchain/src/dbex.rs @@ -289,11 +289,11 @@ pub fn dbex_wot(profile_path: PathBuf, csv: bool, query: &DbExWotQuery) { readers::identity::get_wot_index(&wot_databases.identities_db).expect("DALError"); // get wot_reverse_index - let wot_reverse_index: HashMap<NodeId, &PubKey> = + let wot_reverse_index: HashMap<WotId, &PubKey> = wot_index.iter().map(|(p, id)| (*id, p)).collect(); // get wot uid index - let wot_uid_index: HashMap<NodeId, String> = wot_databases + let wot_uid_index: HashMap<WotId, String> = wot_databases .identities_db .read(|db| { db.iter() @@ -320,7 +320,7 @@ pub fn dbex_wot(profile_path: PathBuf, csv: bool, query: &DbExWotQuery) { DbExWotQuery::AllDistances(ref reverse) => { println!("compute distances..."); let compute_distances_begin = SystemTime::now(); - let mut distances_datas: Vec<(NodeId, WotDistance)> = wot_db + let mut distances_datas: Vec<(WotId, WotDistance)> = wot_db .read(|db| { db.get_enabled() .iter() @@ -389,7 +389,7 @@ pub fn dbex_wot(profile_path: PathBuf, csv: bool, query: &DbExWotQuery) { .expect("Fail to read blockchain db"); // Get expire_dates let min_created_ms_time = current_bc_time - currency_params.ms_validity; - let mut expire_dates: Vec<(NodeId, u64)> = wot_databases + let mut expire_dates: Vec<(WotId, u64)> = wot_databases .ms_db .read(|db| { let mut expire_dates = Vec::new(); diff --git a/lib/modules/blockchain/blockchain/src/dubp/apply/mod.rs b/lib/modules/blockchain/blockchain/src/dubp/apply/mod.rs index 1ecda1f812ac0ded6050229a7a8a7ab2b190f716..b7047a04f24f0b05e0649570d8a6ce461501841f 100644 --- a/lib/modules/blockchain/blockchain/src/dubp/apply/mod.rs +++ b/lib/modules/blockchain/blockchain/src/dubp/apply/mod.rs @@ -26,7 +26,7 @@ use durs_blockchain_dal::writers::requests::*; use durs_blockchain_dal::BinDB; use durs_common_tools::fatal_error; use durs_wot::data::NewLinkResult; -use durs_wot::{NodeId, WebOfTrust}; +use durs_wot::{WebOfTrust, WotId}; use std::collections::{HashMap, HashSet}; #[derive(Debug, Clone)] @@ -48,9 +48,9 @@ pub enum ApplyValidBlockError { #[inline] pub fn apply_valid_block<W: WebOfTrust>( block: BlockDocument, - wot_index: &mut HashMap<PubKey, NodeId>, + wot_index: &mut HashMap<PubKey, WotId>, wot_db: &BinDB<W>, - expire_certs: &HashMap<(NodeId, NodeId), BlockNumber>, + expire_certs: &HashMap<(WotId, WotId), BlockNumber>, ) -> Result<ValidBlockApplyReqs, ApplyValidBlockError> { match block { BlockDocument::V10(block_v10) => { @@ -61,9 +61,9 @@ pub fn apply_valid_block<W: WebOfTrust>( pub fn apply_valid_block_v10<W: WebOfTrust>( mut block: BlockDocumentV10, - wot_index: &mut HashMap<PubKey, NodeId>, + wot_index: &mut HashMap<PubKey, WotId>, wot_db: &BinDB<W>, - expire_certs: &HashMap<(NodeId, NodeId), BlockNumber>, + expire_certs: &HashMap<(WotId, WotId), BlockNumber>, ) -> Result<ValidBlockApplyReqs, ApplyValidBlockError> { debug!( "BlockchainModule : apply_valid_block({})", @@ -80,7 +80,7 @@ pub fn apply_valid_block_v10<W: WebOfTrust>( let pubkey = joiner.issuers()[0]; if let Some(idty_doc) = identities.get(&pubkey) { // Newcomer - let wot_id = NodeId( + let wot_id = WotId( wot_db .read(WebOfTrust::size) .expect("Fatal error : fail to read WotDB !"), diff --git a/lib/modules/blockchain/blockchain/src/dubp/check/mod.rs b/lib/modules/blockchain/blockchain/src/dubp/check/mod.rs index 4ad8c2698152135cf03d980312cf0921a1ed1988..9d13dd06e322710a08c52e64a35b250694b89f70 100644 --- a/lib/modules/blockchain/blockchain/src/dubp/check/mod.rs +++ b/lib/modules/blockchain/blockchain/src/dubp/check/mod.rs @@ -36,7 +36,7 @@ pub fn verify_block_validity<W: WebOfTrust>( block: &BlockDocument, blockchain_db: &BinDB<LocalBlockchainV10Datas>, _certs_db: &BinDB<CertsExpirV10Datas>, - _wot_index: &HashMap<PubKey, NodeId>, + _wot_index: &HashMap<PubKey, WotId>, _wot_db: &BinDB<W>, ) -> Result<(), BlockError> { // Rules that do not concern genesis block diff --git a/lib/modules/blockchain/blockchain/src/fork/revert_block.rs b/lib/modules/blockchain/blockchain/src/fork/revert_block.rs index 2f1da648b112d54b38635fa6ead7dc2435d38ee2..16a457d860eb90fe53123865b4895644525556b6 100644 --- a/lib/modules/blockchain/blockchain/src/fork/revert_block.rs +++ b/lib/modules/blockchain/blockchain/src/fork/revert_block.rs @@ -28,7 +28,7 @@ use durs_blockchain_dal::writers::transaction::DALTxV10; use durs_blockchain_dal::{BinDB, DALError, TxV10Datas}; use durs_common_tools::fatal_error; use durs_wot::data::{NewLinkResult, RemLinkResult}; -use durs_wot::{NodeId, WebOfTrust}; +use durs_wot::{WebOfTrust, WotId}; use std::collections::HashMap; use unwrap::unwrap; @@ -57,7 +57,7 @@ impl From<DALError> for RevertValidBlockError { pub fn revert_block<W: WebOfTrust>( dal_block: DALBlock, - wot_index: &mut HashMap<PubKey, NodeId>, + wot_index: &mut HashMap<PubKey, WotId>, wot_db: &BinDB<W>, txs_db: &BinDB<TxV10Datas>, ) -> Result<ValidBlockRevertReqs, RevertValidBlockError> { @@ -74,8 +74,8 @@ pub fn revert_block<W: WebOfTrust>( pub fn revert_block_v10<W: WebOfTrust>( mut block: BlockDocumentV10, - expire_certs: HashMap<(NodeId, NodeId), BlockNumber>, - wot_index: &mut HashMap<PubKey, NodeId>, + expire_certs: HashMap<(WotId, WotId), BlockNumber>, + wot_index: &mut HashMap<PubKey, WotId>, wot_db: &BinDB<W>, txs_db: &BinDB<TxV10Datas>, ) -> Result<ValidBlockRevertReqs, RevertValidBlockError> { diff --git a/lib/modules/blockchain/blockchain/src/lib.rs b/lib/modules/blockchain/blockchain/src/lib.rs index 9662998b95d31a07aeccf7dfb90882da463f5417..3b08651bf9340da0ae74f2c5fd5a4d59606c73c6 100644 --- a/lib/modules/blockchain/blockchain/src/lib.rs +++ b/lib/modules/blockchain/blockchain/src/lib.rs @@ -76,7 +76,7 @@ use durs_network::{ }; // use durs_wot::data::rusty::RustyWebOfTrust; use durs_wot::operations::distance::RustyDistanceCalculator; -use durs_wot::NodeId; +use durs_wot::WotId; use failure::Error; /// The blocks are requested by packet groups. This constant sets the block packet size. @@ -102,7 +102,7 @@ pub struct BlockchainModule { /// Forks Databases pub forks_dbs: ForksDBs, /// Wot index - pub wot_index: HashMap<PubKey, NodeId>, + pub wot_index: HashMap<PubKey, WotId>, /// Wots Databases pub wot_databases: WotsV10DBs, /// Currency databases @@ -214,7 +214,7 @@ impl BlockchainModule { }; // Get wot index - let wot_index: HashMap<PubKey, NodeId> = + let wot_index: HashMap<PubKey, WotId> = readers::identity::get_wot_index(&wot_databases.identities_db) .expect("Fatal eror : get_wot_index : Fail to read blockchain databases"); diff --git a/lib/modules/blockchain/blockchain/src/sync/apply/mod.rs b/lib/modules/blockchain/blockchain/src/sync/apply/mod.rs index 449301d3b0b2207dfda37c4179cc4f1c21335ba0..d21117caa1fda5738ebd4e191c21225a73b1b298 100644 --- a/lib/modules/blockchain/blockchain/src/sync/apply/mod.rs +++ b/lib/modules/blockchain/blockchain/src/sync/apply/mod.rs @@ -31,7 +31,7 @@ use durs_blockchain_dal::{BinDB, CertsExpirV10Datas, WotsV10DBs}; use durs_common_tools::fatal_error; use durs_network_documents::url::Url; use durs_wot::data::rusty::RustyWebOfTrust; -use durs_wot::data::NodeId; +use durs_wot::data::WotId; use std::collections::{HashMap, VecDeque}; use std::path::PathBuf; use std::sync::mpsc; @@ -57,7 +57,7 @@ pub struct BlockApplicator { pub blocks_not_expiring: VecDeque<u64>, pub last_block_expiring: isize, // databases - pub wot_index: HashMap<PubKey, NodeId>, + pub wot_index: HashMap<PubKey, WotId>, pub wot_databases: WotsV10DBs, pub certs_db: BinDB<CertsExpirV10Datas>, // time measurement diff --git a/lib/modules/blockchain/blockchain/src/sync/mod.rs b/lib/modules/blockchain/blockchain/src/sync/mod.rs index d63ded78d8a739799abe916ff8c5c90de1352087..a5ddfa8f298e922990b50cec4ea822ef91717c68 100644 --- a/lib/modules/blockchain/blockchain/src/sync/mod.rs +++ b/lib/modules/blockchain/blockchain/src/sync/mod.rs @@ -26,7 +26,7 @@ use dup_crypto::keys::*; use durs_blockchain_dal::writers::requests::*; use durs_blockchain_dal::{open_memory_db, CertsExpirV10Datas}; use durs_common_tools::fatal_error; -use durs_wot::NodeId; +use durs_wot::WotId; use failure::Fail; use pbr::ProgressBar; use std::collections::{HashMap, VecDeque}; @@ -198,7 +198,7 @@ pub fn local_sync<DC: DursConfTrait>( } // Get wot index - let wot_index: HashMap<PubKey, NodeId> = + let wot_index: HashMap<PubKey, WotId> = readers::identity::get_wot_index(&wot_databases.identities_db) .expect("Fatal eror : get_wot_index : Fail to read blockchain databases");