diff --git a/Cargo.lock b/Cargo.lock index 17699ad0dfc8e7ce0b6b4c6ba8826c400117793a..a1fb5571f657b4b048918b11b93f801ef503f90f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -884,6 +884,17 @@ dependencies = [ "dup-crypto-tests-tools", ] +[[package]] +name = "dubp-wot" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3df40557ee4babc98bfef0763b374c8087d7b4a1709160576f1788ba2edcbdd7" +dependencies = [ + "log", + "rayon", + "serde", +] + [[package]] name = "dunitrust" version = "0.3.0-dev" @@ -933,6 +944,7 @@ dependencies = [ "dubp-currency-params", "dubp-user-docs", "dubp-user-docs-tests-tools", + "dubp-wot", "dup-crypto", "dup-crypto-tests-tools", "durs-bc-db-reader", @@ -944,7 +956,6 @@ dependencies = [ "durs-module", "durs-network", "durs-network-documents", - "durs-wot", "failure", "json-pest-parser", "log", @@ -973,6 +984,7 @@ dependencies = [ "dubp-indexes", "dubp-user-docs", "dubp-user-docs-tests-tools", + "dubp-wot", "dup-crypto", "dup-crypto-tests-tools", "durs-common-tests-tools", @@ -980,7 +992,6 @@ dependencies = [ "durs-conf", "durs-dbs-tools", "durs-module", - "durs-wot", "log", "maplit", "mockall", @@ -1000,6 +1011,7 @@ dependencies = [ "dubp-indexes", "dubp-user-docs", "dubp-user-docs-tests-tools", + "dubp-wot", "dup-crypto", "dup-crypto-tests-tools", "durs-bc-db-reader", @@ -1008,7 +1020,6 @@ dependencies = [ "durs-conf", "durs-dbs-tools", "durs-module", - "durs-wot", "log", "serde", "serde_derive", @@ -1252,18 +1263,6 @@ dependencies = [ "unwrap", ] -[[package]] -name = "durs-wot" -version = "0.8.0-a0.9" -dependencies = [ - "bincode", - "dup-crypto", - "durs-common-tools", - "log", - "rayon", - "serde", -] - [[package]] name = "durs-ws2p" version = "0.3.0-dev" @@ -1345,6 +1344,7 @@ dependencies = [ "dubp-common-doc", "dubp-currency-params", "dubp-user-docs", + "dubp-wot", "dup-crypto", "durs-common-tools", "durs-conf", @@ -1352,7 +1352,6 @@ dependencies = [ "durs-module", "durs-network", "durs-network-documents", - "durs-wot", "failure", "log", "maplit", diff --git a/Cargo.toml b/Cargo.toml index 93eac8aad6fe96141f1bbfc74d36b8ac7ead91e7..52a53a308c9abd9cbdfa92ba20fe032ac265c1ed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,6 @@ members = [ "lib/dubp/currency-params", "lib/dubp/indexes", "lib/dubp/user-docs", - "lib/dubp/wot", "lib/dunp/network-documents", "lib/modules-lib/bc-db-reader", "lib/modules/blockchain/blockchain", diff --git a/lib/dubp/wot/Cargo.toml b/lib/dubp/wot/Cargo.toml deleted file mode 100644 index aa99c9b7a263edd5745063fd88212eabdaa7a119..0000000000000000000000000000000000000000 --- a/lib/dubp/wot/Cargo.toml +++ /dev/null @@ -1,25 +0,0 @@ -[package] -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 Dunitrust project." -repository = "https://git.duniter.org/nodes/rust/duniter-rs" -readme = "README.md" -keywords = ["duniter", "dunitrust", "wot", "trust"] -license = "AGPL-3.0" -edition = "2018" - -[lib] -path = "lib.rs" - -[dependencies] -dup-crypto = "0.8.4" -durs-common-tools = { path = "../../tools/common-tools", version = "0.2.0" } -log = "0.4.*" -rayon = "1.3.0" -serde = { version = "1.0.*", features = ["derive"] } - -[dev-dependencies] -bincode = "1.2.0" - -[features] \ No newline at end of file diff --git a/lib/dubp/wot/README.md b/lib/dubp/wot/README.md deleted file mode 100644 index 3092a7fbaf898259f142ef8163e7d65b0f48509c..0000000000000000000000000000000000000000 --- a/lib/dubp/wot/README.md +++ /dev/null @@ -1,10 +0,0 @@ -# wot - -`wot` is a crate making "Web of Trust" computations for -the [Duniter] project. - -[Duniter]: https://duniter.org/en/ - -## How to use it - -You can add `durs-wot` as a `cargo` dependency in your Rust project. \ No newline at end of file diff --git a/lib/dubp/wot/data/mod.rs b/lib/dubp/wot/data/mod.rs deleted file mode 100644 index 2180a7eaf6afac4004a88fb952b161fa25f75cc7..0000000000000000000000000000000000000000 --- a/lib/dubp/wot/data/mod.rs +++ /dev/null @@ -1,187 +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 data structures to manage web of trusts. -//! `LegacyWebOfTrust` is almost a translation of the legacy C++ coden while -//! `RustyWebOfTrust` is a brand new implementation with a more "rusty" style. - -pub mod rusty; - -use serde::de::{self, Deserialize, DeserializeOwned, Deserializer, Visitor}; -use serde::{Serialize, Serializer}; -use std::fmt::{self, Debug}; - -/// Wrapper for a node id. -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub struct WotId(pub usize); - -impl Serialize for WotId { - fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> - where - S: Serializer, - { - serializer.serialize_u32(self.0 as u32) - } -} - -struct WotIdVisitor; - -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<WotId, E> - where - E: de::Error, - { - Ok(WotId(value as usize)) - } - - fn visit_u32<E>(self, value: u32) -> Result<WotId, E> - where - E: de::Error, - { - Ok(WotId(value as usize)) - } - - 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(WotId(value as usize)) - } else { - Err(E::custom(format!("u32 out of range: {}", value))) - } - } -} - -impl<'de> Deserialize<'de> for WotId { - fn deserialize<D>(deserializer: D) -> Result<WotId, D::Error> - where - D: Deserializer<'de>, - { - deserializer.deserialize_u32(WotIdVisitor) - } -} - -/// Results of a certification, with the current certification count -/// of the destination as parameter. -#[derive(Debug, Copy, Clone, PartialEq, Eq)] -pub enum NewLinkResult { - /// Certification worked. - Ok(usize), - /// All available certifications has been used. - AllCertificationsUsed(usize), - /// Unknown source. - UnknownSource(), - /// Unknown target. - UnknownTarget(), - /// Self linking is forbidden. - SelfLinkingForbidden(), -} - -/// Results of a certification removal, with the current certification count -/// of the destination as parameter. -#[derive(Debug, Copy, Clone, PartialEq, Eq)] -pub enum RemLinkResult { - /// Certification has been removed. - Removed(usize), - /// Requested certification doesn't exist. - UnknownCert(usize), - /// Unknown source. - UnknownSource(), - /// Unknown target. - UnknownTarget(), -} - -/// Results of a certification test. -#[derive(Debug, Copy, Clone, PartialEq, Eq)] -pub enum HasLinkResult { - /// Both nodes are known, here is the result. - Link(bool), - /// Unknown source. - UnknownSource(), - /// Unknown target. - UnknownTarget(), -} - -/// Trait for a Web Of Trust. -/// Allow to provide other implementations of the `WoT` logic instead of the legacy C++ -/// translated one. -pub trait WebOfTrust: Clone + Debug + Default + DeserializeOwned + Send + Serialize + Sync { - /// Create a new Web of Trust with the maximum of links a node can issue. - fn new(max_links: usize) -> Self; - - /// Get the maximum number of links per user. - fn get_max_link(&self) -> usize; - - /// Set the maximum number of links per user. - fn set_max_link(&mut self, max_link: usize); - - /// Add a new node. - 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<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: 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: WotId, enabled: bool) -> Option<bool>; - - /// Get enabled node array. - fn get_enabled(&self) -> Vec<WotId>; - - /// Get disabled node array. - fn get_disabled(&self) -> Vec<WotId>; - - /// Try to add a link from the source to the target. - 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: WotId, target: WotId) -> RemLinkResult; - - /// Test if there is a link from the source to the target. - 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: 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: WotId) -> Option<usize>; - - /// Test if a node is a sentry. - fn is_sentry(&self, node: WotId, sentry_requirement: usize) -> Option<bool>; - - /// Get sentries array. - fn get_sentries(&self, sentry_requirement: usize) -> Vec<WotId>; - - /// Get non sentries array. - 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 deleted file mode 100644 index 8d84423e62e7436f605baed3d2444e85af4a5c75..0000000000000000000000000000000000000000 --- a/lib/dubp/wot/data/rusty.rs +++ /dev/null @@ -1,229 +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/>. - -//! Experimental implementation of the Web of Trust in a more "rusty" style. - -use super::{HasLinkResult, NewLinkResult, RemLinkResult}; -use crate::WebOfTrust; -use crate::WotId; -use rayon::prelude::*; -use serde::{Deserialize, Serialize}; -use std::collections::HashSet; - -/// A node in the `WoT` graph. -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -struct Node { - /// Is this node enabled ? - enabled: bool, - /// Set of links this node is the target. - links_source: HashSet<WotId>, - /// Number of links the node issued. - issued_count: usize, -} - -impl Node { - /// Create a new node. - pub fn new() -> Node { - Node { - enabled: true, - links_source: HashSet::new(), - issued_count: 0, - } - } -} - -/// A more idiomatic implementation of a Web of Trust. -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub struct RustyWebOfTrust { - /// List of nodes in the WoT. - nodes: Vec<Node>, - /// Maximum number of links a node can issue. - max_links: usize, -} - -impl Default for RustyWebOfTrust { - fn default() -> RustyWebOfTrust { - RustyWebOfTrust { - nodes: Vec::new(), - max_links: 4_000_000_000, - } - } -} - -impl WebOfTrust for RustyWebOfTrust { - fn new(max_links: usize) -> RustyWebOfTrust { - RustyWebOfTrust { - nodes: vec![], - max_links, - } - } - - fn get_max_link(&self) -> usize { - self.max_links - } - - fn set_max_link(&mut self, max_links: usize) { - self.max_links = max_links; - } - - fn add_node(&mut self) -> WotId { - self.nodes.push(Node::new()); - WotId(self.nodes.len() - 1) - } - - fn rem_node(&mut self) -> Option<WotId> { - self.nodes.pop(); - - if !self.nodes.is_empty() { - Some(WotId(self.nodes.len() - 1)) - } else { - None - } - } - - fn size(&self) -> usize { - self.nodes.len() - } - - fn is_enabled(&self, id: WotId) -> Option<bool> { - self.nodes.get(id.0).map(|n| n.enabled) - } - - 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<WotId> { - self.nodes - .par_iter() - .enumerate() - .filter(|&(_, n)| n.enabled) - .map(|(i, _)| WotId(i)) - .collect() - } - - fn get_disabled(&self) -> Vec<WotId> { - self.nodes - .par_iter() - .enumerate() - .filter(|&(_, n)| !n.enabled) - .map(|(i, _)| WotId(i)) - .collect() - } - - fn add_link(&mut self, source: WotId, target: WotId) -> NewLinkResult { - if source == target { - NewLinkResult::SelfLinkingForbidden() - } else if source.0 >= self.size() { - NewLinkResult::UnknownSource() - } else if target.0 >= self.size() { - NewLinkResult::UnknownTarget() - } else if self.nodes[source.0].issued_count >= self.max_links { - NewLinkResult::AllCertificationsUsed(self.nodes[target.0].links_source.len()) - } else { - self.nodes[source.0].issued_count += 1; - self.nodes[target.0].links_source.insert(source); - NewLinkResult::Ok(self.nodes[target.0].links_source.len()) - } - } - - fn rem_link(&mut self, source: WotId, target: WotId) -> RemLinkResult { - if source.0 >= self.size() { - RemLinkResult::UnknownSource() - } else if target.0 >= self.size() { - RemLinkResult::UnknownTarget() - } else if !self.nodes[target.0].links_source.contains(&source) { - RemLinkResult::UnknownCert(self.nodes[target.0].links_source.len()) - } else { - self.nodes[source.0].issued_count -= 1; - self.nodes[target.0].links_source.remove(&source); - RemLinkResult::Removed(self.nodes[target.0].links_source.len()) - } - } - - fn has_link(&self, source: WotId, target: WotId) -> HasLinkResult { - if source.0 >= self.size() { - HasLinkResult::UnknownSource() - } else if target.0 >= self.size() { - HasLinkResult::UnknownTarget() - } else { - HasLinkResult::Link(self.nodes[target.0].links_source.contains(&source)) - } - } - - 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: WotId) -> Option<usize> { - self.nodes.get(id.0).map(|n| n.issued_count) - } - - fn is_sentry(&self, node: WotId, sentry_requirement: usize) -> Option<bool> { - if node.0 >= self.size() { - return None; - } - - let node = &self.nodes[node.0]; - - Some( - node.enabled - && node.issued_count >= sentry_requirement - && node.links_source.len() >= sentry_requirement, - ) - } - - fn get_sentries(&self, sentry_requirement: usize) -> Vec<WotId> { - self.nodes - .par_iter() - .enumerate() - .filter(|&(_, n)| { - n.enabled - && n.issued_count >= sentry_requirement - && n.links_source.len() >= sentry_requirement - }) - .map(|(i, _)| WotId(i)) - .collect() - } - - fn get_non_sentries(&self, sentry_requirement: usize) -> Vec<WotId> { - self.nodes - .par_iter() - .enumerate() - .filter(|&(_, n)| { - n.enabled - && (n.issued_count < sentry_requirement - || n.links_source.len() < sentry_requirement) - }) - .map(|(i, _)| WotId(i)) - .collect() - } -} - -#[cfg(test)] -mod tests { - use super::*; - use crate::tests::generic_wot_test; - - #[test] - fn wot_tests() { - generic_wot_test::<RustyWebOfTrust>(); - } -} diff --git a/lib/dubp/wot/lib.rs b/lib/dubp/wot/lib.rs deleted file mode 100644 index 56e38493378299d04e1d981b3028f26c3ca25ade..0000000000000000000000000000000000000000 --- a/lib/dubp/wot/lib.rs +++ /dev/null @@ -1,516 +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/>. - -//! `wot` is a crate making "Web of Trust" computations for -//! the [Duniter] project. -//! -//! [Duniter]: https://duniter.org/ -//! -//! It defines a trait representing a Web of Trust and allow to do calculations on it. -//! -//! It also contains an "legacy" implementation translated from the original C++ code. -//! -//! Web of Trust tests are translated from [duniter/wot Javascript test][js-tests]. -//! -//! [js-tests]: https://github.com/duniter/wot/blob/master/wotcpp/webOfTrust.cpp - -#![deny( - clippy::option_unwrap_used, - clippy::result_unwrap_used, - missing_docs, - missing_debug_implementations, - missing_copy_implementations, - trivial_casts, - trivial_numeric_casts, - unsafe_code, - unstable_features, - unused_import_braces, - unused_qualifications -)] - -pub mod data; -pub mod operations; - -pub use crate::data::{WebOfTrust, WotId}; - -#[cfg(test)] -mod tests { - use super::*; - use crate::data::*; - use crate::operations::centrality::*; - use crate::operations::distance::*; - use crate::operations::path::*; - use std::path::Path; - - /// Test translated from https://github.com/duniter/wot/blob/master/tests/test.js - /// - /// Clone and file tests are not included in this generic test and should be done in - /// the implementation test. - #[allow(clippy::cognitive_complexity)] - pub fn generic_wot_test<W>() - where - W: WebOfTrust + Sync, - { - let centralities_calculator = UlrikBrandesCentralityCalculator {}; - let distance_calculator = RustyDistanceCalculator {}; - let path_finder = RustyPathFinder {}; - let mut wot = W::new(3); - - // should have an initial size of 0 - assert_eq!(wot.size(), 0); - - // should return `None()` if testing `is_enabled()` with out-of-bounds node - 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(), WotId(0)); - assert_eq!(wot.size(), 1); - assert_eq!(wot.get_disabled().len(), 0); - - // - add another - 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(), WotId(i + 2)); - } - - assert_eq!(wot.size(), 12); - - // shouldn't be able to self cert - assert_eq!( - wot.add_link(WotId(0), WotId(0)), - NewLinkResult::SelfLinkingForbidden() - ); - - // should add certs only in the boundaries of max_cert - 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(WotId(0), WotId(4)), - NewLinkResult::AllCertificationsUsed(0) - ); - - assert_eq!(wot.get_max_link(), 3); - 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(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(WotId(23), WotId(0)), - HasLinkResult::UnknownSource() - ); - assert_eq!( - wot.has_link(WotId(2), WotId(53)), - HasLinkResult::UnknownTarget() - ); - - // created nodes should be enabled - 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(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(WotId(1), true), Some(true)); - - // node 0 and 2 should be disabled - 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(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(WotId(2), WotId(0)), HasLinkResult::Link(false)); - - // 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)); - assert_eq!(wot.add_link(WotId(5), WotId(0)), NewLinkResult::Ok(3)); - - // should exist new links - /* WoT is: - * - * 2 --> 0 - * 4 --> 0 - * 5 --> 0 - */ - - 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(WotId(4), WotId(0)), RemLinkResult::Removed(2)); - /* - * WoT is now: - * - * 2 --> 0 - * 5 --> 0 - */ - - // should exist less links - 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: WotId(0), - sentry_requirement: 1, - step_max: 1, - x_percent: 1.0, - }, - ), - Some(false) - ); - // => no because 2,4,5 have certified him - assert_eq!( - distance_calculator.is_outdistanced( - &wot, - WotDistanceParameters { - node: WotId(0), - sentry_requirement: 2, - step_max: 1, - x_percent: 1.0, - }, - ), - Some(false) - ); - // => no because only member 2 has 2 certs, and has certified him - assert_eq!( - distance_calculator.is_outdistanced( - &wot, - WotDistanceParameters { - node: WotId(0), - sentry_requirement: 3, - step_max: 1, - x_percent: 1.0, - }, - ), - Some(false) - ); - // => no because no member has issued 3 certifications - - // - we add links from member 3 - 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: - * - * 2 --> 0 - * 5 --> 0 - * 3 --> 1 - * 3 --> 2 - */ - assert_eq!(wot.size(), 12); - assert_eq!(wot.get_sentries(1).len(), 1); - 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, 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, WotId(3), WotId(0), 2) - .contains(&vec![WotId(3), WotId(2), WotId(0)])); - - assert_eq!( - distance_calculator.is_outdistanced( - &wot, - WotDistanceParameters { - node: WotId(0), - sentry_requirement: 1, - step_max: 1, - x_percent: 1.0, - }, - ), - Some(false) - ); // OK : 2 -> 0 - assert_eq!( - distance_calculator.is_outdistanced( - &wot, - WotDistanceParameters { - node: WotId(0), - sentry_requirement: 2, - step_max: 1, - x_percent: 1.0, - }, - ), - Some(false) - ); // OK : 2 -> 0 - assert_eq!( - distance_calculator.is_outdistanced( - &wot, - WotDistanceParameters { - node: WotId(0), - sentry_requirement: 3, - step_max: 1, - x_percent: 1.0, - }, - ), - Some(false) - ); // OK : no stry \w 3 lnk - assert_eq!( - distance_calculator.is_outdistanced( - &wot, - WotDistanceParameters { - node: WotId(0), - sentry_requirement: 2, - step_max: 2, - x_percent: 1.0, - }, - ), - Some(false) - ); // OK : 2 -> 0 - - 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], 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], 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, 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, WotId(3), WotId(0), 2) - .contains(&vec![WotId(3), WotId(2), WotId(0)])); - - assert_eq!( - distance_calculator.is_outdistanced( - &wot, - WotDistanceParameters { - node: WotId(0), - sentry_requirement: 1, - step_max: 1, - x_percent: 1.0, - }, - ), - Some(true) - ); // KO : No path 3 -> 0 - assert_eq!( - distance_calculator.is_outdistanced( - &wot, - WotDistanceParameters { - node: WotId(0), - sentry_requirement: 2, - step_max: 1, - x_percent: 1.0, - }, - ), - Some(true) - ); // KO : No path 3 -> 0 - assert_eq!( - distance_calculator.is_outdistanced( - &wot, - WotDistanceParameters { - node: WotId(0), - sentry_requirement: 3, - step_max: 1, - x_percent: 1.0, - }, - ), - Some(false) - ); // OK : no stry \w 3 lnk - assert_eq!( - distance_calculator.is_outdistanced( - &wot, - WotDistanceParameters { - node: WotId(0), - sentry_requirement: 2, - step_max: 2, - x_percent: 1.0, - }, - ), - Some(false) - ); // OK : 3 -> 2 -> 0 - - // should have 12 nodes - assert_eq!(wot.size(), 12); - - // delete top node (return new top node id) - 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(WotId(3), false), Some(false)); - assert_eq!(wot.get_disabled().len(), 1); - assert_eq!( - distance_calculator.is_outdistanced( - &wot, - WotDistanceParameters { - node: WotId(0), - sentry_requirement: 2, - step_max: 1, - x_percent: 1.0, - }, - ), - Some(false) - ); // OK : Disabled - - // Write wot in file - 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_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!(wot.size(), wot2.size()); - assert_eq!( - wot.get_non_sentries(1).len(), - wot2.get_non_sentries(1).len() - ); - assert_eq!(wot.get_disabled().len(), wot2.get_disabled().len()); - assert_eq!(wot2.get_disabled().len(), 1); - assert_eq!(wot2.is_enabled(WotId(3)), Some(false)); - assert_eq!( - distance_calculator.is_outdistanced( - &wot2, - WotDistanceParameters { - node: WotId(0), - sentry_requirement: 2, - step_max: 1, - x_percent: 1.0, - }, - ), - Some(false) - ); - } - - // Read g1_genesis wot - 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; - assert_eq!(members_count, 59); - - // Test compute_distance in g1_genesis wot - assert_eq!( - distance_calculator.compute_distance( - &wot3, - WotDistanceParameters { - node: WotId(37), - sentry_requirement: 3, - step_max: 5, - x_percent: 0.8, - }, - ), - Some(WotDistance { - sentries: 48, - success: 48, - success_at_border: 3, - reached: 51, - reached_at_border: 3, - outdistanced: false, - },) - ); - - // Test betweenness centralities computation in g1_genesis wot - let centralities = centralities_calculator.betweenness_centralities(&wot3); - assert_eq!(centralities.len(), 59); - assert_eq!( - centralities, - vec![ - 148, 30, 184, 11, 60, 51, 40, 115, 24, 140, 47, 69, 16, 34, 94, 126, 151, 0, 34, - 133, 20, 103, 38, 144, 73, 523, 124, 23, 47, 17, 9, 64, 77, 281, 6, 105, 54, 0, - 111, 21, 6, 2, 0, 1, 47, 59, 28, 236, 0, 0, 0, 0, 60, 6, 0, 1, 8, 33, 169, - ] - ); - - // Test stress centralities computation in g1_genesis wot - let stress_centralities = centralities_calculator.stress_centralities(&wot3); - assert_eq!(stress_centralities.len(), 59); - assert_eq!( - stress_centralities, - vec![ - 848, 240, 955, 80, 416, 203, 290, 645, 166, 908, 313, 231, 101, 202, 487, 769, 984, - 0, 154, 534, 105, 697, 260, 700, 496, 1726, 711, 160, 217, 192, 89, 430, 636, 1276, - 41, 420, 310, 0, 357, 125, 50, 15, 0, 12, 275, 170, 215, 1199, 0, 0, 0, 0, 201, 31, - 0, 9, 55, 216, 865, - ] - ); - - // Test distance stress centralities computation in g1_genesis wot - let distance_stress_centralities = - centralities_calculator.distance_stress_centralities(&wot3, 5); - assert_eq!(distance_stress_centralities.len(), 59); - assert_eq!( - distance_stress_centralities, - vec![ - 848, 240, 955, 80, 416, 203, 290, 645, 166, 908, 313, 231, 101, 202, 487, 769, 984, - 0, 154, 534, 105, 697, 260, 700, 496, 1726, 711, 160, 217, 192, 89, 430, 636, 1276, - 41, 420, 310, 0, 357, 125, 50, 15, 0, 12, 275, 170, 215, 1199, 0, 0, 0, 0, 201, 31, - 0, 9, 55, 216, 865, - ] - ); - } -} diff --git a/lib/dubp/wot/operations/centrality.rs b/lib/dubp/wot/operations/centrality.rs deleted file mode 100644 index 029d8927a4d00bf0bee1ca8c610f1d8bc231b9e5..0000000000000000000000000000000000000000 --- a/lib/dubp/wot/operations/centrality.rs +++ /dev/null @@ -1,192 +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 implementations to find paths between nodes. - -use crate::data::WebOfTrust; -use crate::data::WotId; -use std::collections::{HashMap, VecDeque}; - -/// Find paths between 2 nodes of a `WebOfTrust`. -pub trait CentralitiesCalculator<T: WebOfTrust> { - /// Compute betweenness centrality of all members. - fn betweenness_centralities(&self, wot: &T) -> Vec<u64>; - /// Compute stress centrality of all members. - fn stress_centralities(&self, wot: &T) -> Vec<u64>; - /// Compute distance stress centrality of all members. - fn distance_stress_centralities(&self, wot: &T, step_max: usize) -> Vec<u64>; -} - -/// An implementation based on "Ulrik brandes" algo. -#[derive(Debug, Clone, Copy)] -pub struct UlrikBrandesCentralityCalculator; - -impl<T: WebOfTrust> CentralitiesCalculator<T> for UlrikBrandesCentralityCalculator { - fn betweenness_centralities(&self, wot: &T) -> Vec<u64> { - let wot_size = wot.size(); - let mut centralities = vec![0.0; wot_size]; - let enabled_nodes = wot.get_enabled(); - - // The source of any path belongs to enabled_nodes - for s in enabled_nodes.clone() { - 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<WotId> = VecDeque::with_capacity(wot_size); - - sigma[s.0] = 1.0; - d[s.0] = 0; - q.push_back(s); - while let Some(v) = q.pop_front() { - stack.push(v); - for w in wot.get_links_source(v).expect("v don't have any source !") { - // w found for the first time ? - if d[w.0] < 0 { - q.push_back(w); - d[w.0] = d[v.0] + 1; - } - // Shortest path to w via v - if d[w.0] == d[v.0] + 1 { - sigma[w.0] += sigma[v.0]; - paths.entry(w).or_insert_with(Vec::new).push(v); - } - } - } - let mut delta = vec![0.0; wot_size]; - // stack returns vertices in order of non-increasing distance from s - while let Some(w) = stack.pop() { - if paths.contains_key(&w) { - for v in paths.get(&w).expect("Not found w in p !") { - if enabled_nodes.contains(&w) { - delta[v.0] += (sigma[v.0] / sigma[w.0]) * (1.0 + delta[w.0]); - } else { - // If w not in enabled_nodes, no path can end at w - delta[v.0] += (sigma[v.0] / sigma[w.0]) * delta[w.0]; - } - } - } - if w != s { - centralities[w.0] += delta[w.0]; - } - } - } - centralities.into_iter().map(|c| c as u64).collect() - } - fn stress_centralities(&self, wot: &T) -> Vec<u64> { - let wot_size = wot.size(); - let mut centralities = vec![0.0; wot_size]; - let enabled_nodes = wot.get_enabled(); - - // The source of any path belongs to enabled_nodes - for s in enabled_nodes.clone() { - 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<WotId> = VecDeque::with_capacity(wot_size); - - sigma[s.0] = 1.0; - d[s.0] = 0; - q.push_back(s); - while let Some(v) = q.pop_front() { - stack.push(v); - for w in wot.get_links_source(v).expect("v don't have any source !") { - // w found for the first time ? - if d[w.0] < 0 { - q.push_back(w); - d[w.0] = d[v.0] + 1; - } - // Shortest path to w via v - if d[w.0] == d[v.0] + 1 { - sigma[w.0] += sigma[v.0]; - paths.entry(w).or_insert_with(Vec::new).push(v); - } - } - } - let mut delta = vec![0.0; wot_size]; - // stack returns vertices in order of non-increasing distance from s - while let Some(w) = stack.pop() { - if paths.contains_key(&w) { - for v in paths.get(&w).expect("Not found w in p !") { - if enabled_nodes.contains(&w) { - delta[v.0] += sigma[v.0] * (1.0 + (delta[w.0] / sigma[w.0])); - } else { - // If w not in enabled_nodes, no path can end at w - delta[v.0] += sigma[v.0] * (delta[w.0] / sigma[w.0]); - } - } - } - if w != s { - centralities[w.0] += delta[w.0]; - } - } - } - centralities.into_iter().map(|c| c as u64).collect() - } - fn distance_stress_centralities(&self, wot: &T, step_max: usize) -> Vec<u64> { - let wot_size = wot.size(); - let mut centralities = vec![0.0; wot_size]; - let enabled_nodes = wot.get_enabled(); - - // The source of any path belongs to enabled_nodes - for s in enabled_nodes.clone() { - 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<WotId> = VecDeque::with_capacity(wot_size); - - sigma[s.0] = 1.0; - d[s.0] = 0; - q.push_back(s); - while let Some(v) = q.pop_front() { - stack.push(v); - if d[v.0] < step_max as isize { - for w in wot.get_links_source(v).expect("v don't have any source !") { - // w found for the first time ? - if d[w.0] < 0 { - q.push_back(w); - d[w.0] = d[v.0] + 1; - } - // Shortest path to w via v - if d[w.0] == d[v.0] + 1 { - sigma[w.0] += sigma[v.0]; - paths.entry(w).or_insert_with(Vec::new).push(v); - } - } - } - } - let mut delta = vec![0.0; wot_size]; - // stack returns vertices in order of non-increasing distance from s - while let Some(w) = stack.pop() { - if paths.contains_key(&w) { - for v in paths.get(&w).expect("Not found w in p !") { - if enabled_nodes.contains(&w) { - delta[v.0] += sigma[v.0] * (1.0 + (delta[w.0] / sigma[w.0])); - } else { - // If w not in enabled_nodes, no path can end at w - delta[v.0] += sigma[v.0] * (delta[w.0] / sigma[w.0]); - } - } - } - if w != s { - centralities[w.0] += delta[w.0]; - } - } - } - centralities.into_iter().map(|c| c as u64).collect() - } -} diff --git a/lib/dubp/wot/operations/density.rs b/lib/dubp/wot/operations/density.rs deleted file mode 100644 index e24584ee5f7fed1ff21d349acc8b0c2b64ea5413..0000000000000000000000000000000000000000 --- a/lib/dubp/wot/operations/density.rs +++ /dev/null @@ -1,32 +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 function to compute average density. - -use crate::data::WebOfTrust; -use durs_common_tools::fatal_error; - -/// Compute average density -pub fn calculate_average_density<T: WebOfTrust>(wot: &T) -> usize { - let enabled_members = wot.get_enabled(); - let enabled_members_count = enabled_members.len(); - let mut count_actives_links: usize = 0; - for member in &enabled_members { - count_actives_links += wot - .issued_count(*member) - .unwrap_or_else(|| fatal_error!("Fail to get issued_count of wot_id {}", (*member).0)); - } - ((count_actives_links as f32 / enabled_members_count as f32) * 1_000.0) as usize -} diff --git a/lib/dubp/wot/operations/distance.rs b/lib/dubp/wot/operations/distance.rs deleted file mode 100644 index 53d77f43cc7ee041b74ed41164bf6ed5a37ef93a..0000000000000000000000000000000000000000 --- a/lib/dubp/wot/operations/distance.rs +++ /dev/null @@ -1,186 +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 implementations to compute distances. - -use crate::data::WebOfTrust; -use crate::data::WotId; -use rayon::prelude::*; -use std::collections::HashSet; - -/// Paramters for `WoT` distance calculations -#[derive(Debug, Copy, Clone, PartialEq)] -pub struct WotDistanceParameters { - /// Node from where distances are calculated. - pub node: WotId, - /// Links count received AND issued to be a sentry. - pub sentry_requirement: u32, - /// Currency parameter. - pub step_max: u32, - /// Currency parameter. - pub x_percent: f64, -} - -/// Results of `WebOfTrust::compute_distance`. -#[derive(Debug, Copy, Clone, PartialEq, Eq)] -pub struct WotDistance { - /// Sentries count - pub sentries: u32, - /// Success count - pub success: u32, - /// Succes at border count - pub success_at_border: u32, - /// Reached count - pub reached: u32, - /// Reached at border count - pub reached_at_border: u32, - /// Is the node outdistanced ? - pub outdistanced: bool, -} - -/// Compute distance between nodes of a `WebOfTrust`. -pub trait DistanceCalculator<T: WebOfTrust> { - /// Compute distance between a node and the network. - /// Returns `None` if this node doesn't exist. - fn compute_distance(&self, wot: &T, params: WotDistanceParameters) -> Option<WotDistance>; - - /// Compute distances of all members - fn compute_distances( - &self, - wot: &T, - sentry_requirement: u32, - step_max: u32, - x_percent: f64, - ) -> (usize, Vec<usize>, usize, Vec<usize>); - - /// Test if a node is outdistanced in the network. - /// Returns `Node` if this node doesn't exist. - fn is_outdistanced(&self, wot: &T, params: WotDistanceParameters) -> Option<bool>; -} - -/// Calculate distances between 2 members in a `WebOfTrust`. -#[derive(Debug, Clone, Copy)] -pub struct RustyDistanceCalculator; - -impl<T: WebOfTrust + Sync> DistanceCalculator<T> for RustyDistanceCalculator { - fn compute_distance(&self, wot: &T, params: WotDistanceParameters) -> Option<WotDistance> { - let WotDistanceParameters { - node, - sentry_requirement, - step_max, - x_percent, - } = params; - - if node.0 >= wot.size() { - return None; - } - - let mut area = HashSet::new(); - area.insert(node); - let mut border = HashSet::new(); - border.insert(node); - - for _ in 0..step_max { - border = border - .par_iter() - .map(|&id| { - wot.get_links_source(id) - .expect("get_links_source must return a value") - .iter() - .filter(|source| !area.contains(source)) - .cloned() - .collect::<HashSet<_>>() - }) - .reduce(HashSet::new, |mut acc, sources| { - for source in sources { - acc.insert(source); - } - acc - }); - area.extend(border.iter()); - } - - let sentries: Vec<_> = wot.get_sentries(sentry_requirement as usize); - let mut success = area.iter().filter(|n| sentries.contains(n)).count() as u32; - let success_at_border = border.iter().filter(|n| sentries.contains(n)).count() as u32; - let mut sentries = sentries.len() as u32; - if wot - .is_sentry(node, sentry_requirement as usize) - .expect("is_sentry must return a value") - { - sentries -= 1; - success -= 1; - } - - Some(WotDistance { - sentries, - reached: area.len() as u32 - 1, - reached_at_border: border.len() as u32, - success, - success_at_border, - outdistanced: f64::from(success) < x_percent * f64::from(sentries), - }) - } - - fn is_outdistanced(&self, wot: &T, params: WotDistanceParameters) -> Option<bool> { - Self::compute_distance(&self, wot, params).map(|result| result.outdistanced) - } - - fn compute_distances( - &self, - wot: &T, - sentry_requirement: u32, - step_max: u32, - x_percent: f64, - ) -> (usize, Vec<usize>, usize, Vec<usize>) { - let members_count = wot.get_enabled().len(); - let mut distances = Vec::new(); - let mut average_distance: usize = 0; - let mut connectivities = Vec::new(); - let mut average_connectivity: usize = 0; - for i in 0..wot.size() { - let distance_datas: WotDistance = Self::compute_distance( - &self, - wot, - WotDistanceParameters { - node: WotId(i), - sentry_requirement, - step_max, - x_percent, - }, - ) - .expect("Fatal Error: compute_distance return None !"); - let distance = ((f64::from(distance_datas.success) - / (x_percent * f64::from(distance_datas.sentries))) - * 100.0) as usize; - distances.push(distance); - average_distance += distance; - let connectivity = - ((f64::from(distance_datas.success - distance_datas.success_at_border) - / (x_percent * f64::from(distance_datas.sentries))) - * 100.0) as usize; - connectivities.push(connectivity); - average_connectivity += connectivity; - } - average_distance /= members_count; - average_connectivity /= members_count; - ( - average_distance, - distances, - average_connectivity, - connectivities, - ) - } -} diff --git a/lib/dubp/wot/operations/mod.rs b/lib/dubp/wot/operations/mod.rs deleted file mode 100644 index 376ad1c281812d82094c2a66810bedaf351051ee..0000000000000000000000000000000000000000 --- a/lib/dubp/wot/operations/mod.rs +++ /dev/null @@ -1,21 +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 operation traits and implementations on `WebOfTrust` objects. - -pub mod centrality; -pub mod density; -pub mod distance; -pub mod path; diff --git a/lib/dubp/wot/operations/path.rs b/lib/dubp/wot/operations/path.rs deleted file mode 100644 index 5ca9b70283c86827ea6da7b1699ec2fa8fb8db85..0000000000000000000000000000000000000000 --- a/lib/dubp/wot/operations/path.rs +++ /dev/null @@ -1,107 +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 implementations to find paths between nodes. - -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: WotId, to: WotId, k_max: u32) -> Vec<Vec<WotId>>; -} - -/// A new "rusty-er" implementation of `WoT` path finding. -#[derive(Debug, Clone, Copy)] -pub struct RustyPathFinder; - -impl<T: WebOfTrust> PathFinder<T> for RustyPathFinder { - 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![]; - } - - // 1. We explore the k_max area around `to`, and only remember backward - // links of the smallest distance. - - // 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<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![]); - // Explored zone border. - let mut border = HashSet::new(); - border.insert(to); - - for distance in 1..=k_max { - let mut next_border = HashSet::new(); - - for node in border { - for source in &wot - .get_links_source(node) - .expect("links source must not be None") - { - match graph[source.0].0 { - path_distance if path_distance > distance => { - // shorter path, we replace - graph[source.0] = (distance, vec![node]); - next_border.insert(*source); - } - path_distance if path_distance == distance => { - // same length, we combine - graph[source.0].1.push(node); - next_border.insert(*source); - } - _ => unreachable!(), - } - } - } - - border = next_border; - } - - // 2. If `from` is found, we follow the backward links and build paths. - // For each path, we look at the last element sources and build new paths with them. - let mut paths = vec![vec![from]]; - - for _ in 1..=k_max { - let mut new_paths = vec![]; - - for path in &paths { - let node = path.last().expect("path should not be empty"); - - if node == &to { - // If path is complete, we keep it. - new_paths.push(path.clone()) - } else { - // If not complete we comlete paths - let sources = &graph[node.0]; - for source in &sources.1 { - let mut new_path = path.clone(); - new_path.push(*source); - new_paths.push(new_path); - } - } - } - - paths = new_paths; - } - - paths - } -} diff --git a/lib/dubp/wot/tests/g1_genesis.bin b/lib/dubp/wot/tests/g1_genesis.bin deleted file mode 100644 index d684f6197a5442ff4860dec581a65b19456a51d4..0000000000000000000000000000000000000000 Binary files a/lib/dubp/wot/tests/g1_genesis.bin and /dev/null differ diff --git a/lib/modules-lib/bc-db-reader/Cargo.toml b/lib/modules-lib/bc-db-reader/Cargo.toml index 69ba1889ec1b8b402e0a4b9e760e7465ceb03fc4..bf2b0475cd02a8a195e0bf9a639ec2419620d8b4 100644 --- a/lib/modules-lib/bc-db-reader/Cargo.toml +++ b/lib/modules-lib/bc-db-reader/Cargo.toml @@ -20,7 +20,7 @@ durs-conf = { path = "../../core/conf" } durs-module = { path = "../../core/module" } durs-common-tools = { path = "../../tools/common-tools" } durs-dbs-tools = { path = "../../tools/dbs-tools" } -durs-wot = { path = "../../dubp/wot" } +dubp-wot = "0.10.1" log = "0.4.*" maplit = "1.0.1" mockall = { version = "0.6.0", optional = true } diff --git a/lib/modules-lib/bc-db-reader/src/blocks.rs b/lib/modules-lib/bc-db-reader/src/blocks.rs index 58ee8f8364672d7c6603d794cf4b4ce9fa3de183..488247f408168196a4719ceb362fc4b3610ab1d5 100644 --- a/lib/modules-lib/bc-db-reader/src/blocks.rs +++ b/lib/modules-lib/bc-db-reader/src/blocks.rs @@ -22,10 +22,10 @@ use crate::*; use dubp_block_doc::block::{BlockDocument, BlockDocumentTrait}; use dubp_common_doc::traits::Document; use dubp_common_doc::{BlockHash, BlockNumber, Blockstamp, PreviousBlockstamp}; +use dubp_wot::WotId; use dup_crypto::hashs::Hash; use dup_crypto::keys::*; use durs_dbs_tools::DbError; -use durs_wot::WotId; use serde::{Deserialize, Serialize}; use std::collections::HashMap; diff --git a/lib/modules-lib/bc-db-reader/src/current_metadata.rs b/lib/modules-lib/bc-db-reader/src/current_metadata.rs index 183c822508ecf52e017bed0183f52d9f802b9fd2..b14aa9e431677905fe3ddf85bb60c5db3e9d3fea 100644 --- a/lib/modules-lib/bc-db-reader/src/current_metadata.rs +++ b/lib/modules-lib/bc-db-reader/src/current_metadata.rs @@ -23,8 +23,8 @@ use crate::constants::*; use crate::*; use crate::{DbReadable, DbValue}; use dubp_common_doc::{Blockstamp, CurrencyName}; +use dubp_wot::WotId; use durs_dbs_tools::DbError; -use durs_wot::WotId; #[derive(Clone, Copy, Debug)] /// Current meta data key diff --git a/lib/modules-lib/bc-db-reader/src/indexes/certs.rs b/lib/modules-lib/bc-db-reader/src/indexes/certs.rs index 237604c83b8cae896ada952e925e5c8ae0970162..c64f509daa975240caa9702872b76bebcf58ee3b 100644 --- a/lib/modules-lib/bc-db-reader/src/indexes/certs.rs +++ b/lib/modules-lib/bc-db-reader/src/indexes/certs.rs @@ -17,8 +17,8 @@ use crate::*; use dubp_common_doc::BlockNumber; +use dubp_wot::WotId; use durs_dbs_tools::DbError; -use durs_wot::WotId; use std::collections::HashMap; /// Find certifications that emitted in indicated blocks expiring diff --git a/lib/modules-lib/bc-db-reader/src/indexes/identities.rs b/lib/modules-lib/bc-db-reader/src/indexes/identities.rs index 48fae0f611fc7f0e3f2f7bd1a31d0ee31840e9b1..522f0d006f811eb87c97d588f03f4268e5afdd07 100644 --- a/lib/modules-lib/bc-db-reader/src/indexes/identities.rs +++ b/lib/modules-lib/bc-db-reader/src/indexes/identities.rs @@ -21,9 +21,9 @@ use crate::*; use dubp_common_doc::traits::Document; use dubp_common_doc::{BlockNumber, Blockstamp}; use dubp_user_docs::documents::identity::IdentityDocumentV10; +use dubp_wot::WotId; use dup_crypto::keys::*; use durs_dbs_tools::DbError; -use durs_wot::WotId; use serde::{Deserialize, Serialize}; use std::collections::HashMap; diff --git a/lib/modules/blockchain/bc-db-writer/Cargo.toml b/lib/modules/blockchain/bc-db-writer/Cargo.toml index 038fd31e3e77c4c52ab3688942eec1578315ce53..5ce7bab40e5fb4ee8b0979297a1b8d407e239614 100644 --- a/lib/modules/blockchain/bc-db-writer/Cargo.toml +++ b/lib/modules/blockchain/bc-db-writer/Cargo.toml @@ -21,7 +21,7 @@ durs-common-tools = { path = "../../../tools/common-tools" } durs-conf = { path = "../../../core/conf" } durs-dbs-tools = { path = "../../../tools/dbs-tools" } durs-module = { path = "../../../core/module" } -durs-wot = { path = "../../../dubp/wot" } +dubp-wot = "0.10.1" log = "0.4.*" serde = "1.0.*" serde_derive = "1.0.*" diff --git a/lib/modules/blockchain/bc-db-writer/src/indexes/certs.rs b/lib/modules/blockchain/bc-db-writer/src/indexes/certs.rs index fdfae05a0eda189f5a17204ddca9ecddec890b96..4b1bbf08e6d61c843b608ced1d5a0800b91ef90c 100644 --- a/lib/modules/blockchain/bc-db-writer/src/indexes/certs.rs +++ b/lib/modules/blockchain/bc-db-writer/src/indexes/certs.rs @@ -19,10 +19,10 @@ use crate::{BcDbRwWithWriter, Db, DbError, DbWriter}; use dubp_common_doc::BlockNumber; use dubp_currency_params::CurrencyParameters; use dubp_user_docs::documents::certification::CompactCertificationDocumentV10; +use dubp_wot::WotId; use durs_bc_db_reader::constants::*; use durs_bc_db_reader::indexes::identities::IdentityDb; use durs_bc_db_reader::{from_db_value, DbReadable, DbValue}; -use durs_wot::WotId; /// Apply "certification" event in databases pub fn write_certification( diff --git a/lib/modules/blockchain/bc-db-writer/src/indexes/identities.rs b/lib/modules/blockchain/bc-db-writer/src/indexes/identities.rs index 5152f1a2ab0e5e81165e553d42f674ed8f9a3cce..2f4edb819d820881e6d986438c0ff2912a2af0d9 100644 --- a/lib/modules/blockchain/bc-db-writer/src/indexes/identities.rs +++ b/lib/modules/blockchain/bc-db-writer/src/indexes/identities.rs @@ -20,6 +20,7 @@ use dubp_common_doc::traits::Document; use dubp_common_doc::{BlockNumber, Blockstamp}; use dubp_currency_params::CurrencyParameters; use dubp_user_docs::documents::identity::IdentityDocumentV10; +use dubp_wot::WotId; use dup_crypto::keys::PubKey; use dup_crypto::keys::PublicKey; use durs_bc_db_reader::constants::*; @@ -28,7 +29,6 @@ use durs_bc_db_reader::indexes::identities::get_wot_id; use durs_bc_db_reader::indexes::identities::{IdentityDb, IdentityStateDb}; use durs_bc_db_reader::{DbReadable, DbValue}; use durs_common_tools::fatal_error; -use durs_wot::WotId; /// Remove identity from databases pub fn revert_create_identity(db: &Db, w: &mut DbWriter, pubkey: &PubKey) -> Result<(), DbError> { diff --git a/lib/modules/blockchain/bc-db-writer/src/lib.rs b/lib/modules/blockchain/bc-db-writer/src/lib.rs index 76dff17f2c4d59448611857ac7d21062072674be..d4aae6f829802de3749c62f0f538b2e4156c9c13 100644 --- a/lib/modules/blockchain/bc-db-writer/src/lib.rs +++ b/lib/modules/blockchain/bc-db-writer/src/lib.rs @@ -49,9 +49,9 @@ pub use durs_dbs_tools::{BinFreeStructDb, DbError}; use dubp_common_doc::{BlockNumber, Blockstamp}; use dubp_indexes::sindex::UniqueIdUTXOv10; use dubp_user_docs::documents::transaction::*; +use dubp_wot::data::rusty::RustyWebOfTrust; use dup_crypto::hashs::Hash; use dup_crypto::keys::*; -use durs_wot::data::rusty::RustyWebOfTrust; use std::collections::{HashMap, HashSet}; use std::path::{Path, PathBuf}; diff --git a/lib/modules/blockchain/bc-db-writer/src/writers/requests.rs b/lib/modules/blockchain/bc-db-writer/src/writers/requests.rs index 09f8f9a13a3d3cf1de430517dcde64194b4c9080..2c9078d351500010d6a2cdce745fe99d7f402611 100644 --- a/lib/modules/blockchain/bc-db-writer/src/writers/requests.rs +++ b/lib/modules/blockchain/bc-db-writer/src/writers/requests.rs @@ -19,11 +19,11 @@ use dubp_common_doc::Blockstamp; use dubp_currency_params::CurrencyParameters; use dubp_user_docs::documents::certification::CompactCertificationDocumentV10; use dubp_user_docs::documents::identity::IdentityDocumentV10; +use dubp_wot::WotId; use dup_crypto::keys::PubKey; use durs_bc_db_reader::blocks::fork_tree::ForkTree; use durs_bc_db_reader::blocks::BlockDb; use durs_bc_db_reader::indexes::sources::SourceAmount; -use durs_wot::WotId; use std::ops::Deref; #[derive(Debug, Clone)] diff --git a/lib/modules/blockchain/blockchain/Cargo.toml b/lib/modules/blockchain/blockchain/Cargo.toml index 53407dd076f98050b2b0b0889371905161198ed2..e4c1dd43c1ea6e3b1954054a35ec282ae0000708 100644 --- a/lib/modules/blockchain/blockchain/Cargo.toml +++ b/lib/modules/blockchain/blockchain/Cargo.toml @@ -23,7 +23,7 @@ durs-network-documents = { path = "../../../dunp/network-documents" } durs-message = { path = "../../../core/message" } durs-module = { path = "../../../core/module" } durs-network = { path = "../../../core/network" } -durs-wot = { path = "../../../dubp/wot" } +dubp-wot = "0.10.1" failure = "0.1.5" json-pest-parser = { path = "../../../tools/json-pest-parser" } log = "0.4.*" diff --git a/lib/modules/blockchain/blockchain/src/dbex.rs b/lib/modules/blockchain/blockchain/src/dbex.rs index 2888c1f575946c756bf48017a75fd3dca8e9ce7a..5a460827d0dc391763048f40e96110af0cb06afc 100644 --- a/lib/modules/blockchain/blockchain/src/dbex.rs +++ b/lib/modules/blockchain/blockchain/src/dbex.rs @@ -18,12 +18,12 @@ use crate::*; use dubp_block_doc::block::BlockDocumentTrait; use dubp_common_doc::BlockNumber; +use dubp_wot::data::rusty::RustyWebOfTrust; +use dubp_wot::data::WebOfTrust; +use dubp_wot::operations::distance::{DistanceCalculator, WotDistance, WotDistanceParameters}; use dup_crypto::keys::*; use durs_bc_db_reader::constants::*; use durs_bc_db_reader::{BcDbRead, BcDbRo, DbValue}; -use durs_wot::data::rusty::RustyWebOfTrust; -use durs_wot::data::WebOfTrust; -use durs_wot::operations::distance::{DistanceCalculator, WotDistance, WotDistanceParameters}; use std::str::FromStr; use std::time::*; use unwrap::unwrap; diff --git a/lib/modules/blockchain/blockchain/src/dubp/apply/mod.rs b/lib/modules/blockchain/blockchain/src/dubp/apply/mod.rs index d7d384a023266f6481bf4adeb495c23902ecdf1e..59df348f8584bc034a9b66aaed535f476a973001 100644 --- a/lib/modules/blockchain/blockchain/src/dubp/apply/mod.rs +++ b/lib/modules/blockchain/blockchain/src/dubp/apply/mod.rs @@ -19,6 +19,8 @@ use dubp_block_doc::block::{BlockDocument, BlockDocumentV10}; use dubp_common_doc::traits::Document; use dubp_common_doc::BlockNumber; use dubp_user_docs::documents::transaction::{TransactionDocument, TxAmount, TxBase}; +use dubp_wot::data::NewLinkResult; +use dubp_wot::{WebOfTrust, WotId}; use dup_crypto::keys::*; use durs_bc_db_reader::blocks::BlockDb; use durs_bc_db_reader::indexes::sources::get_block_consumed_sources_; @@ -26,8 +28,6 @@ use durs_bc_db_reader::indexes::sources::SourceAmount; use durs_bc_db_writer::writers::requests::*; use durs_bc_db_writer::{BcDbRwWithWriter, BinFreeStructDb, Db, DbError, DbWriter}; use durs_common_tools::{fatal_error, UsizeSer32}; -use durs_wot::data::NewLinkResult; -use durs_wot::{WebOfTrust, WotId}; use std::collections::{HashMap, HashSet}; #[derive(Debug, Clone)] diff --git a/lib/modules/blockchain/blockchain/src/dubp/check/global.rs b/lib/modules/blockchain/blockchain/src/dubp/check/global.rs index 5baceee970b57b33b5c294eb65bae345394d6dcb..dd95afcbb9996a0c3694c8a93db647b25e0262b5 100644 --- a/lib/modules/blockchain/blockchain/src/dubp/check/global.rs +++ b/lib/modules/blockchain/blockchain/src/dubp/check/global.rs @@ -24,11 +24,11 @@ use self::rules::RuleNotSyncDatas; use dubp_block_doc::block::{BlockDocument, BlockDocumentTrait}; use dubp_common_doc::traits::Document; use dubp_common_doc::BlockNumber; +use dubp_wot::*; use dup_crypto::keys::PubKey; use durs_bc_db_reader::{BcDbInReadTx, DbError}; use durs_bc_db_writer::BinFreeStructDb; use durs_common_tools::traits::bool_ext::BoolExt; -use durs_wot::*; use rules_engine::{EngineError, ProtocolVersion, RulesEngine}; use std::collections::HashMap; diff --git a/lib/modules/blockchain/blockchain/src/dubp/check/global/rules.rs b/lib/modules/blockchain/blockchain/src/dubp/check/global/rules.rs index bc5c5e5979cdd4927a5fd03dedd4e26c6de5efa5..147a49a109422fed66fa14edcb162b9d510e93c1 100644 --- a/lib/modules/blockchain/blockchain/src/dubp/check/global/rules.rs +++ b/lib/modules/blockchain/blockchain/src/dubp/check/global/rules.rs @@ -23,7 +23,7 @@ use dubp_block_doc::BlockDocument; //use dup_crypto::keys::PubKey; use durs_bc_db_reader::indexes::identities::IdentityStateDb; use durs_bc_db_reader::{BcDbInReadTx, DbError}; -//use durs_wot::*; +//use dubp_wot::*; use failure::Fail; //use std::collections::HashMap; diff --git a/lib/modules/blockchain/blockchain/src/fork/revert_block.rs b/lib/modules/blockchain/blockchain/src/fork/revert_block.rs index b05355d2c8a1e8ed0e88824b1764e386c82c04e0..a59380afbd5724295cccbcdb515ff1367642c2c9 100644 --- a/lib/modules/blockchain/blockchain/src/fork/revert_block.rs +++ b/lib/modules/blockchain/blockchain/src/fork/revert_block.rs @@ -19,14 +19,14 @@ use dubp_block_doc::block::{BlockDocument, BlockDocumentTrait, BlockDocumentV10} use dubp_common_doc::traits::Document; use dubp_common_doc::{BlockNumber, Blockstamp}; use dubp_user_docs::documents::transaction::{TransactionDocument, TxAmount, TxBase}; +use dubp_wot::data::{NewLinkResult, RemLinkResult}; +use dubp_wot::{WebOfTrust, WotId}; use dup_crypto::keys::*; use durs_bc_db_reader::blocks::BlockDb; use durs_bc_db_reader::indexes::sources::SourceAmount; use durs_bc_db_writer::writers::requests::*; use durs_bc_db_writer::{BinFreeStructDb, DbError}; use durs_common_tools::{fatal_error, UsizeSer32}; -use durs_wot::data::{NewLinkResult, RemLinkResult}; -use durs_wot::{WebOfTrust, WotId}; use std::collections::HashMap; use unwrap::unwrap; diff --git a/lib/modules/blockchain/blockchain/src/lib.rs b/lib/modules/blockchain/blockchain/src/lib.rs index eddc37d11669623a18a47505df166cd137d09b1a..f36724d746e0a675145851bb57715629fe5bac2d 100644 --- a/lib/modules/blockchain/blockchain/src/lib.rs +++ b/lib/modules/blockchain/blockchain/src/lib.rs @@ -74,9 +74,9 @@ use durs_network::{ events::NetworkEvent, requests::{NetworkResponse, OldNetworkRequest}, }; -// use durs_wot::data::rusty::RustyWebOfTrust; -use durs_wot::operations::distance::RustyDistanceCalculator; -use durs_wot::WotId; +// use dubp_wot::data::rusty::RustyWebOfTrust; +use dubp_wot::operations::distance::RustyDistanceCalculator; +use dubp_wot::WotId; use failure::Error; /// The blocks are requested by packet groups. This constant sets the block packet size. diff --git a/lib/modules/blockchain/blockchain/src/sync/apply/mod.rs b/lib/modules/blockchain/blockchain/src/sync/apply/mod.rs index 46bfd528d63a26cd482ff26e49046b3798552e0e..eb3bfefce78eb4f0512c0ecd0752e186dacc22f6 100644 --- a/lib/modules/blockchain/blockchain/src/sync/apply/mod.rs +++ b/lib/modules/blockchain/blockchain/src/sync/apply/mod.rs @@ -26,14 +26,14 @@ use dubp_block_doc::block::{BlockDocument, BlockDocumentTrait}; use dubp_common_doc::traits::Document; use dubp_common_doc::{BlockNumber, Blockstamp}; use dubp_currency_params::{CurrencyName, CurrencyParameters}; +use dubp_wot::data::rusty::RustyWebOfTrust; +use dubp_wot::data::WotId; use dup_crypto::keys::PubKey; use durs_bc_db_reader::BcDbRead; use durs_bc_db_writer::writers::requests::WotsDBsWriteQuery; use durs_bc_db_writer::{WotsV10DBs, WriteResp}; use durs_common_tools::fatal_error; use durs_network_documents::url::Url; -use durs_wot::data::rusty::RustyWebOfTrust; -use durs_wot::data::WotId; use std::collections::{HashMap, VecDeque}; use std::path::PathBuf; use std::sync::mpsc; diff --git a/lib/modules/blockchain/blockchain/src/sync/mod.rs b/lib/modules/blockchain/blockchain/src/sync/mod.rs index 77f4deed445a2988563b9b6c4a6b741d81bb77c8..1a6f4ec94e87582126f7b40270876e5ba30cd174 100644 --- a/lib/modules/blockchain/blockchain/src/sync/mod.rs +++ b/lib/modules/blockchain/blockchain/src/sync/mod.rs @@ -22,11 +22,11 @@ use dubp_block_doc::block::BlockDocumentTrait; use dubp_common_doc::Blockstamp; use dubp_common_doc::{BlockHash, BlockNumber}; use dubp_currency_params::{CurrencyName, CurrencyParameters}; +use dubp_wot::WotId; use dup_crypto::keys::*; use durs_bc_db_reader::BcDbRead; use durs_bc_db_writer::writers::requests::*; use durs_common_tools::fatal_error; -use durs_wot::WotId; use failure::Fail; use pbr::ProgressBar; use std::collections::{HashMap, VecDeque}; diff --git a/lib/modules/ws2p-v1-legacy/Cargo.toml b/lib/modules/ws2p-v1-legacy/Cargo.toml index 1cae331daf0ad07ce80770276ea6b6f749195076..d78a9d0bfa6ed3b385d0238f32bf24d66b65d00d 100644 --- a/lib/modules/ws2p-v1-legacy/Cargo.toml +++ b/lib/modules/ws2p-v1-legacy/Cargo.toml @@ -22,7 +22,7 @@ durs-network = { path = "../../core/network" } durs-network-documents = { path = "../../dunp/network-documents" } durs-message = { path = "../../core/message" } durs-common-tools = { path = "../../tools/common-tools" } -durs-wot = { path = "../../dubp/wot" } +dubp-wot = "0.10.1" failure = "0.1.5" log = "0.4.*" maplit = "1.0.1"