diff --git a/Cargo.lock b/Cargo.lock index b3436f1b58991546d1abe6b5805f242901383147..7ca56d078be092e336f6801d53242460651d80ec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -451,6 +451,7 @@ version = "0.1.0-a0.1" dependencies = [ "dubp-documents 0.12.0", "dup-crypto 0.6.0", + "durs-common-tools 0.1.0", "durs-network-documents 0.3.1", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.86 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/lib/core/module/Cargo.toml b/lib/core/module/Cargo.toml index 1980be73f0d6da1d9967bf54f885f677e5168e68..31fd6ec86c40d9a13ba1e1e2d4a6ae07ec5b65b1 100644 --- a/lib/core/module/Cargo.toml +++ b/lib/core/module/Cargo.toml @@ -11,7 +11,8 @@ path = "src/lib.rs" [dependencies] dup-crypto = { path = "../../tools/crypto" } -dubp-documents= { path = "../../tools/documents" } +dubp-documents = { path = "../../tools/documents" } +durs-common-tools = { path = "../../tools/common-tools" } durs-network-documents = { path = "../../tools/network-documents" } failure = "0.1.5" serde = "1.0.*" diff --git a/lib/core/module/src/lib.rs b/lib/core/module/src/lib.rs index ff44aba4a0ffa9b4e742d078365812d727c514e2..629f84fa7b26153d0664a7a4f1ad47131a4668c1 100644 --- a/lib/core/module/src/lib.rs +++ b/lib/core/module/src/lib.rs @@ -33,6 +33,7 @@ extern crate serde_derive; use dubp_documents::CurrencyName; use dup_crypto::keys::{KeyPair, KeyPairEnum}; +use durs_common_tools::traits::merge::Merge; use durs_network_documents::network_endpoint::{ApiPart, EndpointEnum}; use failure::Fail; use serde::de::DeserializeOwned; @@ -395,7 +396,14 @@ impl From<ModuleConfError> for PlugModuleError { /// All Duniter-rs modules must implement this trait. pub trait DursModule<DC: DursConfTrait, M: ModuleMessage> { ///Module user configuration (configuration provided by the user) - type ModuleUserConf: Clone + Debug + Default + DeserializeOwned + Send + Serialize + Sync; + type ModuleUserConf: Clone + + Debug + + Default + + DeserializeOwned + + Merge + + Send + + Serialize + + Sync; /// Module real configuration (configuration calculated from the configuration provided by the user and the global configuration) type ModuleConf: 'static + Clone + Debug + Default + Send + Sync; /// Module subcommand options diff --git a/lib/modules/skeleton/lib.rs b/lib/modules/skeleton/lib.rs index 23e7d681d2e6b9567411efc5d75ba7542b76d48d..b4ce23f28bb3d5da79bb8d0f02975bfb1b7c48a2 100644 --- a/lib/modules/skeleton/lib.rs +++ b/lib/modules/skeleton/lib.rs @@ -35,6 +35,7 @@ extern crate serde_derive; extern crate structopt; use durs_common_tools::fatal_error; +use durs_common_tools::traits::merge::Merge; use durs_conf::DuRsConf; use durs_message::events::*; use durs_message::*; @@ -68,6 +69,14 @@ pub struct SkeletonUserConf { test_fake_conf_field: Option<String>, } +impl Merge for SkeletonUserConf { + fn merge(self, other: Self) -> Self { + SkeletonUserConf { + test_fake_conf_field: self.test_fake_conf_field.or(other.test_fake_conf_field), + } + } +} + #[derive(Debug, Copy, Clone)] /// Message from others thread of skeleton module pub enum SkeletonThreadMsg {} diff --git a/lib/modules/tui/lib.rs b/lib/modules/tui/lib.rs index 177124e91801fc905b65f2468288a1c0ff03895f..791c9e2717ed4eb348740e2757c3afe11941ced6 100644 --- a/lib/modules/tui/lib.rs +++ b/lib/modules/tui/lib.rs @@ -36,6 +36,7 @@ extern crate serde_derive; extern crate structopt; use durs_common_tools::fatal_error; +use durs_common_tools::traits::merge::Merge; use durs_conf::DuRsConf; use durs_message::events::*; use durs_message::*; @@ -64,6 +65,12 @@ impl Default for TuiConf { } } +impl Merge for TuiConf { + fn merge(self, _: Self) -> Self { + self + } +} + #[derive(Debug, Clone)] /// Format of messages received by the tui module pub enum TuiMess { diff --git a/lib/modules/ws2p-v1-legacy/src/lib.rs b/lib/modules/ws2p-v1-legacy/src/lib.rs index ed7c9e22f444df5faf193ec90c77cb6f74558b04..44a04e321c058a2301bfe1d3294853d7a52ce713 100644 --- a/lib/modules/ws2p-v1-legacy/src/lib.rs +++ b/lib/modules/ws2p-v1-legacy/src/lib.rs @@ -61,6 +61,7 @@ use crate::ws_connections::*; use dubp_documents::{Blockstamp, CurrencyName}; use dup_crypto::keys::*; use durs_common_tools::fatal_error; +use durs_common_tools::traits::merge::Merge; use durs_conf::DuRsConf; use durs_message::events::*; use durs_message::requests::*; @@ -111,6 +112,16 @@ pub struct WS2PUserConf { pub sync_endpoints: Option<Vec<EndpointV1>>, } +impl Merge for WS2PUserConf { + fn merge(self, other: Self) -> Self { + WS2PUserConf { + outcoming_quota: self.outcoming_quota.or(other.outcoming_quota), + prefered_pubkeys: self.prefered_pubkeys.or(other.prefered_pubkeys), + sync_endpoints: self.sync_endpoints.or(other.sync_endpoints), + } + } +} + #[derive(Debug, Clone, PartialEq, Eq)] /// WS2P Configuration pub struct WS2PConf { diff --git a/lib/modules/ws2p/ws2p/src/lib.rs b/lib/modules/ws2p/ws2p/src/lib.rs index e1ef857ad00199b5cb3cfde5f6f7bff87be1c78f..50528fef4c808881dcbccbddf5d320dfc601cb30 100644 --- a/lib/modules/ws2p/ws2p/src/lib.rs +++ b/lib/modules/ws2p/ws2p/src/lib.rs @@ -41,6 +41,7 @@ pub mod services; use crate::errors::WS2PError; use durs_common_tools::fatal_error; +use durs_common_tools::traits::merge::Merge; use durs_conf::DuRsConf; use durs_message::DursMsg; use durs_module::*; @@ -68,6 +69,15 @@ pub struct WS2PUserConf { pub sync_endpoints: Option<Vec<EndpointEnum>>, } +impl Merge for WS2PUserConf { + fn merge(self, other: Self) -> Self { + WS2PUserConf { + outcoming_quota: self.outcoming_quota.or(other.outcoming_quota), + sync_endpoints: self.sync_endpoints.or(other.sync_endpoints), + } + } +} + impl Default for WS2PConf { fn default() -> Self { WS2PConf {