From fd76a918cd00bba1212950e4a781c5ec1357d937 Mon Sep 17 00:00:00 2001 From: Mahmoud Mazouz Date: Mon, 16 Sep 2024 10:03:51 +0200 Subject: [PATCH] Hide `zenoh_config` internals --- Cargo.lock | 3 + commons/zenoh-config/src/lib.rs | 93 ++++++++++++++-------- examples/src/lib.rs | 8 +- zenoh-ext/Cargo.toml | 1 + zenoh-ext/examples/Cargo.toml | 1 + zenoh-ext/examples/examples/z_pub_cache.rs | 6 +- zenoh-ext/examples/src/lib.rs | 8 +- zenoh-ext/tests/liveliness.rs | 31 ++++---- zenoh/src/lib.rs | 2 +- zenoh/src/net/runtime/adminspace.rs | 28 ++++--- zenoh/src/net/runtime/mod.rs | 7 +- zenoh/tests/acl.rs | 16 ++-- zenoh/tests/authentication.rs | 31 ++++---- zenoh/tests/connection_retry.rs | 6 +- zenoh/tests/events.rs | 4 +- zenoh/tests/interceptors.rs | 7 +- zenoh/tests/liveliness.rs | 41 +++++----- zenoh/tests/matching.rs | 15 ++-- zenoh/tests/routing.rs | 7 +- zenoh/tests/session.rs | 14 ++-- zenoh/tests/shm.rs | 9 +-- zenoh/tests/unicity.rs | 23 +++--- zenohd/Cargo.toml | 1 + zenohd/src/main.rs | 6 +- 24 files changed, 186 insertions(+), 182 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7c140c1c31..0235f6463f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5479,6 +5479,7 @@ dependencies = [ "tokio", "tracing", "zenoh", + "zenoh-config", "zenoh-macros", "zenoh-util", ] @@ -5491,6 +5492,7 @@ dependencies = [ "futures", "tokio", "zenoh", + "zenoh-config", "zenoh-ext", ] @@ -5987,6 +5989,7 @@ dependencies = [ "tracing-subscriber", "url", "zenoh", + "zenoh-config", "zenoh-util", ] diff --git a/commons/zenoh-config/src/lib.rs b/commons/zenoh-config/src/lib.rs index b57c62edde..8dfa1d5025 100644 --- a/commons/zenoh-config/src/lib.rs +++ b/commons/zenoh-config/src/lib.rs @@ -228,18 +228,57 @@ fn config_keys() { dbg!(Vec::from_iter(c.keys())); } +/// Zenoh configuration. +/// +/// Most options are optional as a way to keep defaults flexible. Some of the options have different +/// default values depending on the rest of the configuration. +/// +/// To construct a configuration, we advise that you use a configuration file (JSON, JSON5 and YAML +/// are currently supported, please use the proper extension for your format as the deserializer +/// will be picked according to it). +#[derive(Default, Debug, Clone)] +pub struct Config(InternalConfig); + +impl Config { + pub fn from_env() -> ZResult { + Ok(Config(InternalConfig::from_env()?)) + } + + pub fn from_file>(path: P) -> ZResult { + Ok(Config(InternalConfig::from_file(path)?)) + } +} + +#[doc(hidden)] +impl std::ops::Deref for Config { + type Target = InternalConfig; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +#[doc(hidden)] +impl std::ops::DerefMut for Config { + fn deref_mut(&mut self) -> &mut ::Target { + &mut self.0 + } +} + +impl fmt::Display for Config { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", &self.0) + } +} + validated_struct::validator! { - /// The main configuration structure for Zenoh. - /// - /// Most fields are optional as a way to keep defaults flexible. Some of the fields have different default values depending on the rest of the configuration. - /// - /// To construct a configuration, we advise that you use a configuration file (JSON, JSON5 and YAML are currently supported, please use the proper extension for your format as the deserializer will be picked according to it). #[derive(Default)] #[recursive_attrs] #[derive(serde::Deserialize, serde::Serialize, Clone, Debug)] #[serde(default)] #[serde(deny_unknown_fields)] - Config { + #[doc(hidden)] + InternalConfig { /// The Zenoh ID of the instance. This ID MUST be unique throughout your Zenoh infrastructure and cannot exceed 16 bytes of length. If left unset, a random u128 will be generated. id: ZenohId, /// The metadata of the instance. Arbitrary json data available from the admin space @@ -579,7 +618,7 @@ fn set_false() -> bool { #[test] fn config_deser() { - let config = Config::from_deserializer( + let config = InternalConfig::from_deserializer( &mut json5::Deserializer::from_str( r#"{ scouting: { @@ -606,7 +645,7 @@ fn config_deser() { config.scouting().multicast().autoconnect().client(), Some(&WhatAmIMatcher::empty().router().peer()) ); - let config = Config::from_deserializer( + let config = InternalConfig::from_deserializer( &mut json5::Deserializer::from_str( r#"{ scouting: { @@ -630,7 +669,7 @@ fn config_deser() { Some(&WhatAmIMatcher::empty().router().peer()) ); assert_eq!(config.scouting().multicast().autoconnect().client(), None); - let config = Config::from_deserializer( + let config = InternalConfig::from_deserializer( &mut json5::Deserializer::from_str( r#"{transport: { auth: { usrpwd: { user: null, password: null, dictionary_file: "file" }}}}"#, ) @@ -647,17 +686,17 @@ fn config_deser() { .map(|s| s.as_ref()), Some("file") ); - std::mem::drop(Config::from_deserializer( + std::mem::drop(InternalConfig::from_deserializer( &mut json5::Deserializer::from_str( r#"{transport: { auth: { usrpwd: { user: null, password: null, user_password_dictionary: "file" }}}}"#, ) .unwrap(), ) .unwrap_err()); - dbg!(Config::from_file("../../DEFAULT_CONFIG.json5").unwrap()); + dbg!(InternalConfig::from_file("../../DEFAULT_CONFIG.json5").unwrap()); } -impl Config { +impl InternalConfig { pub fn insert<'d, D: serde::Deserializer<'d>>( &mut self, key: &str, @@ -726,7 +765,7 @@ impl Config { pub enum ConfigOpenErr { IoError(std::io::Error), JsonParseErr(json5::Error), - InvalidConfiguration(Box), + InvalidConfiguration(Box), } impl std::fmt::Display for ConfigOpenErr { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { @@ -742,7 +781,7 @@ impl std::fmt::Display for ConfigOpenErr { } } impl std::error::Error for ConfigOpenErr {} -impl Config { +impl InternalConfig { pub fn from_env() -> ZResult { let path = std::env::var(defaults::ENV) .map_err(|e| zerror!("Invalid ENV variable ({}): {}", defaults::ENV, e))?; @@ -756,7 +795,7 @@ impl Config { Ok(config) } - fn _from_file(path: &Path) -> ZResult { + fn _from_file(path: &Path) -> ZResult { match std::fs::File::open(path) { Ok(mut f) => { let mut content = String::new(); @@ -768,13 +807,13 @@ impl Config { .map(|s| s.to_str().unwrap()) { Some("json") | Some("json5") => match json5::Deserializer::from_str(&content) { - Ok(mut d) => Config::from_deserializer(&mut d).map_err(|e| match e { + Ok(mut d) => InternalConfig::from_deserializer(&mut d).map_err(|e| match e { Ok(c) => zerror!("Invalid configuration: {}", c).into(), Err(e) => zerror!("JSON error: {}", e).into(), }), Err(e) => bail!(e), }, - Some("yaml") | Some("yml") => Config::from_deserializer(serde_yaml::Deserializer::from_str(&content)).map_err(|e| match e { + Some("yaml") | Some("yml") => InternalConfig::from_deserializer(serde_yaml::Deserializer::from_str(&content)).map_err(|e| match e { Ok(c) => zerror!("Invalid configuration: {}", c).into(), Err(e) => zerror!("YAML error: {}", e).into(), }), @@ -795,7 +834,7 @@ impl Config { } } -impl std::fmt::Display for Config { +impl std::fmt::Display for InternalConfig { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { serde_json::to_value(self) .map(|mut json| { @@ -812,7 +851,7 @@ impl std::fmt::Display for Config { #[test] fn config_from_json() { let from_str = serde_json::Deserializer::from_str; - let mut config = Config::from_deserializer(&mut from_str(r#"{}"#)).unwrap(); + let mut config = InternalConfig::from_deserializer(&mut from_str(r#"{}"#)).unwrap(); config .insert("transport/link/tx/lease", &mut from_str("168")) .unwrap(); @@ -836,22 +875,8 @@ impl Clone for Notifier { } } } -impl Notifier { - pub fn remove>(&self, key: K) -> ZResult<()> { - let key = key.as_ref(); - self._remove(key) - } - fn _remove(&self, key: &str) -> ZResult<()> { - { - let mut guard = zlock!(self.inner.inner); - guard.remove(key)?; - } - self.notify(key); - Ok(()) - } -} -impl Notifier { +impl Notifier { pub fn new(inner: T) -> Self { Notifier { inner: Arc::new(NotifierInner { diff --git a/examples/src/lib.rs b/examples/src/lib.rs index 20409b4f85..7766d379d2 100644 --- a/examples/src/lib.rs +++ b/examples/src/lib.rs @@ -3,7 +3,7 @@ //! Check ../README.md for usage. //! -use zenoh::config::Config; +use zenoh::{config::WhatAmI, Config}; #[derive(clap::ValueEnum, Clone, Copy, PartialEq, Eq, Hash, Debug)] pub enum Wai { @@ -59,9 +59,9 @@ impl From<&CommonArgs> for Config { None => Config::default(), }; match args.mode { - Some(Wai::Peer) => config.set_mode(Some(zenoh::config::WhatAmI::Peer)), - Some(Wai::Client) => config.set_mode(Some(zenoh::config::WhatAmI::Client)), - Some(Wai::Router) => config.set_mode(Some(zenoh::config::WhatAmI::Router)), + Some(Wai::Peer) => config.set_mode(Some(WhatAmI::Peer)), + Some(Wai::Client) => config.set_mode(Some(WhatAmI::Client)), + Some(Wai::Router) => config.set_mode(Some(WhatAmI::Router)), None => Ok(None), } .unwrap(); diff --git a/zenoh-ext/Cargo.toml b/zenoh-ext/Cargo.toml index 63516bb253..4b06a97264 100644 --- a/zenoh-ext/Cargo.toml +++ b/zenoh-ext/Cargo.toml @@ -50,6 +50,7 @@ zenoh-macros = { workspace = true } [dev-dependencies] zenoh = { workspace = true, features = ["unstable"], default-features = true } +zenoh-config = { workspace = true } [package.metadata.docs.rs] features = ["unstable"] diff --git a/zenoh-ext/examples/Cargo.toml b/zenoh-ext/examples/Cargo.toml index 8dae03e596..de8c5ad49a 100644 --- a/zenoh-ext/examples/Cargo.toml +++ b/zenoh-ext/examples/Cargo.toml @@ -39,6 +39,7 @@ clap = { workspace = true, features = ["derive"] } zenoh-ext = { workspace = true } [dev-dependencies] +zenoh-config = { workspace = true } [[example]] name = "z_query_sub" diff --git a/zenoh-ext/examples/examples/z_pub_cache.rs b/zenoh-ext/examples/examples/z_pub_cache.rs index 6c47fb0862..d8e13faec4 100644 --- a/zenoh-ext/examples/examples/z_pub_cache.rs +++ b/zenoh-ext/examples/examples/z_pub_cache.rs @@ -14,10 +14,8 @@ use std::time::Duration; use clap::{arg, Parser}; -use zenoh::{ - config::{Config, ModeDependentValue}, - key_expr::KeyExpr, -}; +use zenoh::{config::Config, key_expr::KeyExpr}; +use zenoh_config::ModeDependentValue; use zenoh_ext::*; use zenoh_ext_examples::CommonArgs; diff --git a/zenoh-ext/examples/src/lib.rs b/zenoh-ext/examples/src/lib.rs index 881d60c138..04d1223022 100644 --- a/zenoh-ext/examples/src/lib.rs +++ b/zenoh-ext/examples/src/lib.rs @@ -2,7 +2,7 @@ //! See the code in ../examples/ //! Check ../README.md for usage. //! -use zenoh::config::Config; +use zenoh::{config::WhatAmI, Config}; #[derive(clap::ValueEnum, Clone, Copy, PartialEq, Eq, Hash, Debug)] pub enum Wai { @@ -43,9 +43,9 @@ impl From<&CommonArgs> for Config { None => Config::default(), }; match value.mode { - Some(Wai::Peer) => config.set_mode(Some(zenoh::config::WhatAmI::Peer)), - Some(Wai::Client) => config.set_mode(Some(zenoh::config::WhatAmI::Client)), - Some(Wai::Router) => config.set_mode(Some(zenoh::config::WhatAmI::Router)), + Some(Wai::Peer) => config.set_mode(Some(WhatAmI::Peer)), + Some(Wai::Client) => config.set_mode(Some(WhatAmI::Client)), + Some(Wai::Router) => config.set_mode(Some(WhatAmI::Router)), None => Ok(None), } .unwrap(); diff --git a/zenoh-ext/tests/liveliness.rs b/zenoh-ext/tests/liveliness.rs index d211505c4c..7c1158a50c 100644 --- a/zenoh-ext/tests/liveliness.rs +++ b/zenoh-ext/tests/liveliness.rs @@ -12,11 +12,8 @@ // ZettaScale Zenoh Team, // -use zenoh::{ - config::{self, EndPoint, WhatAmI}, - sample::SampleKind, - Wait, -}; +use zenoh::{sample::SampleKind, Wait}; +use zenoh_config::{EndPoint, WhatAmI}; #[tokio::test(flavor = "multi_thread", worker_threads = 4)] async fn test_liveliness_querying_subscriber_clique() { @@ -36,7 +33,7 @@ async fn test_liveliness_querying_subscriber_clique() { zenoh_util::init_log_from_env_or("error"); let peer1 = { - let mut c = config::default(); + let mut c = zenoh_config::default(); c.listen .endpoints .set(vec![PEER1_ENDPOINT.parse::().unwrap()]) @@ -49,7 +46,7 @@ async fn test_liveliness_querying_subscriber_clique() { }; let peer2 = { - let mut c = config::default(); + let mut c = zenoh_config::default(); c.connect .endpoints .set(vec![PEER1_ENDPOINT.parse::().unwrap()]) @@ -114,7 +111,7 @@ async fn test_liveliness_querying_subscriber_brokered() { zenoh_util::init_log_from_env_or("error"); let router = { - let mut c = config::default(); + let mut c = zenoh_config::default(); c.listen .endpoints .set(vec![ROUTER_ENDPOINT.parse::().unwrap()]) @@ -127,7 +124,7 @@ async fn test_liveliness_querying_subscriber_brokered() { }; let client1 = { - let mut c = config::default(); + let mut c = zenoh_config::default(); c.connect .endpoints .set(vec![ROUTER_ENDPOINT.parse::().unwrap()]) @@ -140,7 +137,7 @@ async fn test_liveliness_querying_subscriber_brokered() { }; let client2 = { - let mut c = config::default(); + let mut c = zenoh_config::default(); c.connect .endpoints .set(vec![ROUTER_ENDPOINT.parse::().unwrap()]) @@ -153,7 +150,7 @@ async fn test_liveliness_querying_subscriber_brokered() { }; let client3 = { - let mut c = config::default(); + let mut c = zenoh_config::default(); c.connect .endpoints .set(vec![ROUTER_ENDPOINT.parse::().unwrap()]) @@ -220,7 +217,7 @@ async fn test_liveliness_fetching_subscriber_clique() { zenoh_util::init_log_from_env_or("error"); let peer1 = { - let mut c = config::default(); + let mut c = zenoh_config::default(); c.listen .endpoints .set(vec![PEER1_ENDPOINT.parse::().unwrap()]) @@ -233,7 +230,7 @@ async fn test_liveliness_fetching_subscriber_clique() { }; let peer2 = { - let mut c = config::default(); + let mut c = zenoh_config::default(); c.connect .endpoints .set(vec![PEER1_ENDPOINT.parse::().unwrap()]) @@ -302,7 +299,7 @@ async fn test_liveliness_fetching_subscriber_brokered() { zenoh_util::init_log_from_env_or("error"); let router = { - let mut c = config::default(); + let mut c = zenoh_config::default(); c.listen .endpoints .set(vec![ROUTER_ENDPOINT.parse::().unwrap()]) @@ -315,7 +312,7 @@ async fn test_liveliness_fetching_subscriber_brokered() { }; let client1 = { - let mut c = config::default(); + let mut c = zenoh_config::default(); c.connect .endpoints .set(vec![ROUTER_ENDPOINT.parse::().unwrap()]) @@ -328,7 +325,7 @@ async fn test_liveliness_fetching_subscriber_brokered() { }; let client2 = { - let mut c = config::default(); + let mut c = zenoh_config::default(); c.connect .endpoints .set(vec![ROUTER_ENDPOINT.parse::().unwrap()]) @@ -341,7 +338,7 @@ async fn test_liveliness_fetching_subscriber_brokered() { }; let client3 = { - let mut c = config::default(); + let mut c = zenoh_config::default(); c.connect .endpoints .set(vec![ROUTER_ENDPOINT.parse::().unwrap()]) diff --git a/zenoh/src/lib.rs b/zenoh/src/lib.rs index 3fa24e3c36..dc6b8f9778 100644 --- a/zenoh/src/lib.rs +++ b/zenoh/src/lib.rs @@ -355,7 +355,7 @@ pub mod config { // client, default, peer, Config, EndPoint, Locator, ModeDependentValue, PermissionsConf, // PluginLoad, ValidatedMap, ZenohId, // }; - pub use zenoh_config::*; + pub use zenoh_config::{Config, WhatAmI, WhatAmIMatcher}; } #[cfg(all( diff --git a/zenoh/src/net/runtime/adminspace.rs b/zenoh/src/net/runtime/adminspace.rs index e38847c249..d8a747c8d8 100644 --- a/zenoh/src/net/runtime/adminspace.rs +++ b/zenoh/src/net/runtime/adminspace.rs @@ -398,16 +398,17 @@ impl Primitives for AdminSpace { key, json ); - if let Err(e) = self.context.runtime.state.config.insert_json5(key, json) { - error!( - "Error inserting conf value @/{}/{}/config/{} : {} - {}", - self.context.runtime.state.zid, - self.context.runtime.state.whatami, - key, - json, - e - ); - } + // FIXME(fuzzypixelz): uncomment this + // if let Err(e) = self.context.runtime.state.config.insert_json5(key, json) { + // error!( + // "Error inserting conf value @/{}/{}/config/{} : {} - {}", + // self.context.runtime.state.zid, + // self.context.runtime.state.whatami, + // key, + // json, + // e + // ); + // } } Err(e) => error!( "Received non utf8 conf value on @/{}/{}/config/{} : {}", @@ -421,9 +422,10 @@ impl Primitives for AdminSpace { self.context.runtime.state.whatami, key ); - if let Err(e) = self.context.runtime.state.config.remove(key) { - tracing::error!("Error deleting conf value {} : {}", msg.wire_expr, e) - } + // FIXME(fuzzypixelz): uncomment this + // if let Err(e) = self.context.runtime.state.config.remove(key) { + // tracing::error!("Error deleting conf value {} : {}", msg.wire_expr, e) + // } } } } diff --git a/zenoh/src/net/runtime/mod.rs b/zenoh/src/net/runtime/mod.rs index 1a02513494..f688a67bf7 100644 --- a/zenoh/src/net/runtime/mod.rs +++ b/zenoh/src/net/runtime/mod.rs @@ -36,7 +36,7 @@ use futures::{stream::StreamExt, Future}; use tokio::task::JoinHandle; use tokio_util::sync::CancellationToken; use uhlc::{HLCBuilder, HLC}; -use zenoh_config::wrappers::ZenohId; +use zenoh_config::{unwrap_or_default, Config, ModeDependent, Notifier, ZenohId}; use zenoh_link::{EndPoint, Link}; use zenoh_plugin_trait::{PluginStartArgs, StructVersion}; use zenoh_protocol::{ @@ -61,10 +61,7 @@ use super::{primitives::DeMux, routing, routing::router::Router}; use crate::api::loader::{load_plugins, start_plugins}; #[cfg(feature = "plugins")] use crate::api::plugins::PluginsManager; -use crate::{ - config::{unwrap_or_default, Config, ModeDependent, Notifier}, - GIT_VERSION, LONG_VERSION, -}; +use crate::{GIT_VERSION, LONG_VERSION}; pub(crate) struct RuntimeState { zid: ZenohId, diff --git a/zenoh/tests/acl.rs b/zenoh/tests/acl.rs index 285e68b254..e076390078 100644 --- a/zenoh/tests/acl.rs +++ b/zenoh/tests/acl.rs @@ -19,12 +19,8 @@ mod test { }; use tokio::runtime::Handle; - use zenoh::{ - config, - config::{EndPoint, WhatAmI}, - sample::SampleKind, - Config, Session, - }; + use zenoh::{config::WhatAmI, sample::SampleKind, Config, Session}; + use zenoh_config::EndPoint; use zenoh_core::{zlock, ztimeout}; const TIMEOUT: Duration = Duration::from_secs(60); @@ -59,7 +55,7 @@ mod test { } async fn get_basic_router_config(port: u16) -> Config { - let mut config = config::default(); + let mut config = Config::default(); config.set_mode(Some(WhatAmI::Router)).unwrap(); config .listen @@ -77,9 +73,11 @@ mod test { async fn get_client_sessions(port: u16) -> (Session, Session) { println!("Opening client sessions"); - let config = config::client([format!("tcp/127.0.0.1:{port}").parse::().unwrap()]); + let config = + zenoh_config::client([format!("tcp/127.0.0.1:{port}").parse::().unwrap()]); let s01 = ztimeout!(zenoh::open(config)).unwrap(); - let config = config::client([format!("tcp/127.0.0.1:{port}").parse::().unwrap()]); + let config = + zenoh_config::client([format!("tcp/127.0.0.1:{port}").parse::().unwrap()]); let s02 = ztimeout!(zenoh::open(config)).unwrap(); (s01, s02) } diff --git a/zenoh/tests/authentication.rs b/zenoh/tests/authentication.rs index 63ddfcc03c..91e3f05397 100644 --- a/zenoh/tests/authentication.rs +++ b/zenoh/tests/authentication.rs @@ -21,11 +21,8 @@ mod test { use once_cell::sync::Lazy; use tokio::runtime::Handle; - use zenoh::{ - config, - config::{EndPoint, WhatAmI}, - Config, Session, - }; + use zenoh::{config::WhatAmI, Config, Session}; + use zenoh_config::EndPoint; use zenoh_core::{zlock, ztimeout}; const TIMEOUT: Duration = Duration::from_secs(60); @@ -270,7 +267,7 @@ client2name:client2passwd"; async fn get_basic_router_config_tls(port: u16, lowlatency: bool) -> Config { let cert_path = TESTFILES_PATH.to_string_lossy(); - let mut config = config::default(); + let mut config = zenoh_config::default(); config.set_mode(Some(WhatAmI::Router)).unwrap(); config .listen @@ -323,7 +320,7 @@ client2name:client2passwd"; } async fn get_basic_router_config_quic(port: u16) -> Config { let cert_path = TESTFILES_PATH.to_string_lossy(); - let mut config = config::default(); + let mut config = zenoh_config::default(); config.set_mode(Some(WhatAmI::Router)).unwrap(); config .listen @@ -369,7 +366,7 @@ client2name:client2passwd"; } async fn get_basic_router_config_usrpswd(port: u16) -> Config { - let mut config = config::default(); + let mut config = zenoh_config::default(); config.set_mode(Some(WhatAmI::Router)).unwrap(); config .listen @@ -408,7 +405,7 @@ client2name:client2passwd"; async fn get_basic_router_config_quic_usrpswd(port: u16) -> Config { let cert_path = TESTFILES_PATH.to_string_lossy(); - let mut config = config::default(); + let mut config = zenoh_config::default(); config.set_mode(Some(WhatAmI::Router)).unwrap(); config .listen @@ -474,7 +471,7 @@ client2name:client2passwd"; async fn get_client_sessions_tls(port: u16, lowlatency: bool) -> (Session, Session) { let cert_path = TESTFILES_PATH.to_string_lossy(); println!("Opening client sessions"); - let mut config = config::client([format!("tls/127.0.0.1:{}", port) + let mut config = zenoh_config::client([format!("tls/127.0.0.1:{}", port) .parse::() .unwrap()]); config @@ -520,7 +517,7 @@ client2name:client2passwd"; .unwrap(); let s01 = ztimeout!(zenoh::open(config)).unwrap(); - let mut config = config::client([format!("tls/127.0.0.1:{}", port) + let mut config = zenoh_config::client([format!("tls/127.0.0.1:{}", port) .parse::() .unwrap()]); config @@ -571,7 +568,7 @@ client2name:client2passwd"; async fn get_client_sessions_quic(port: u16) -> (Session, Session) { let cert_path = TESTFILES_PATH.to_string_lossy(); println!("Opening client sessions"); - let mut config = config::client([format!("quic/127.0.0.1:{}", port) + let mut config = zenoh_config::client([format!("quic/127.0.0.1:{}", port) .parse::() .unwrap()]); config @@ -609,7 +606,7 @@ client2name:client2passwd"; .set_root_ca_certificate(Some(format!("{}/ca.pem", cert_path))) .unwrap(); let s01 = ztimeout!(zenoh::open(config)).unwrap(); - let mut config = config::client([format!("quic/127.0.0.1:{}", port) + let mut config = zenoh_config::client([format!("quic/127.0.0.1:{}", port) .parse::() .unwrap()]); config @@ -653,7 +650,7 @@ client2name:client2passwd"; async fn get_client_sessions_usrpswd(port: u16) -> (Session, Session) { println!("Opening client sessions"); let mut config = - config::client([format!("tcp/127.0.0.1:{port}").parse::().unwrap()]); + zenoh_config::client([format!("tcp/127.0.0.1:{port}").parse::().unwrap()]); config .insert_json5( "transport", @@ -669,7 +666,7 @@ client2name:client2passwd"; .unwrap(); let s01 = ztimeout!(zenoh::open(config)).unwrap(); let mut config = - config::client([format!("tcp/127.0.0.1:{port}").parse::().unwrap()]); + zenoh_config::client([format!("tcp/127.0.0.1:{port}").parse::().unwrap()]); config .insert_json5( "transport", @@ -690,7 +687,7 @@ client2name:client2passwd"; async fn get_client_sessions_quic_usrpswd(port: u16) -> (Session, Session) { let cert_path = TESTFILES_PATH.to_string_lossy(); println!("Opening client sessions"); - let mut config = config::client([format!("quic/127.0.0.1:{port}") + let mut config = zenoh_config::client([format!("quic/127.0.0.1:{port}") .parse::() .unwrap()]); config @@ -735,7 +732,7 @@ client2name:client2passwd"; .unwrap(); let s01 = ztimeout!(zenoh::open(config)).unwrap(); - let mut config = config::client([format!("quic/127.0.0.1:{}", port) + let mut config = zenoh_config::client([format!("quic/127.0.0.1:{}", port) .parse::() .unwrap()]); config diff --git a/zenoh/tests/connection_retry.rs b/zenoh/tests/connection_retry.rs index 6bb655851b..6f0d8a6e47 100644 --- a/zenoh/tests/connection_retry.rs +++ b/zenoh/tests/connection_retry.rs @@ -11,10 +11,8 @@ // Contributors: // ZettaScale Zenoh Team, // -use zenoh::{ - config::{ConnectionRetryConf, EndPoint, ModeDependent}, - Config, Wait, -}; +use zenoh::{Config, Wait}; +use zenoh_config::{ConnectionRetryConf, EndPoint, ModeDependent}; #[test] fn retry_config_overriding() { diff --git a/zenoh/tests/events.rs b/zenoh/tests/events.rs index e3a4d61656..1e26ae0210 100644 --- a/zenoh/tests/events.rs +++ b/zenoh/tests/events.rs @@ -13,13 +13,13 @@ // use std::time::Duration; -use zenoh::{config, query::Reply, sample::SampleKind, Session}; +use zenoh::{query::Reply, sample::SampleKind, Session}; use zenoh_core::ztimeout; const TIMEOUT: Duration = Duration::from_secs(10); async fn open_session(listen: &[&str], connect: &[&str]) -> Session { - let mut config = config::peer(); + let mut config = zenoh_config::peer(); config .listen .endpoints diff --git a/zenoh/tests/interceptors.rs b/zenoh/tests/interceptors.rs index 57ba51d5ba..7559faf22d 100644 --- a/zenoh/tests/interceptors.rs +++ b/zenoh/tests/interceptors.rs @@ -21,11 +21,8 @@ use std::{ }, }; -use zenoh::{ - config::{DownsamplingItemConf, DownsamplingRuleConf, InterceptorFlow}, - key_expr::KeyExpr, - Config, Wait, -}; +use zenoh::{key_expr::KeyExpr, Config, Wait}; +use zenoh_config::{DownsamplingItemConf, DownsamplingRuleConf, InterceptorFlow}; // Tokio's time granularity on different platforms #[cfg(target_os = "windows")] diff --git a/zenoh/tests/liveliness.rs b/zenoh/tests/liveliness.rs index ff0bb4ee99..9f93f81ab9 100644 --- a/zenoh/tests/liveliness.rs +++ b/zenoh/tests/liveliness.rs @@ -19,9 +19,8 @@ use zenoh_core::ztimeout; async fn test_liveliness_subscriber_clique() { use std::time::Duration; - use zenoh::{config, sample::SampleKind}; - use zenoh_config::WhatAmI; - use zenoh_link::EndPoint; + use zenoh::{config::WhatAmI, sample::SampleKind}; + use zenoh_config::EndPoint; const TIMEOUT: Duration = Duration::from_secs(60); const SLEEP: Duration = Duration::from_secs(1); const PEER1_ENDPOINT: &str = "tcp/localhost:47447"; @@ -30,10 +29,10 @@ async fn test_liveliness_subscriber_clique() { zenoh_util::init_log_from_env_or("error"); let peer1 = { - let mut c = config::default(); + let mut c = zenoh_config::default(); c.listen .endpoints - .set(vec![PEER1_ENDPOINT.parse::().unwrap()]) + .set(vec![PEER1_ENDPOINT.parse::().unwrap()]) .unwrap(); c.scouting.multicast.set_enabled(Some(false)).unwrap(); let _ = c.set_mode(Some(WhatAmI::Peer)); @@ -43,7 +42,7 @@ async fn test_liveliness_subscriber_clique() { }; let peer2 = { - let mut c = config::default(); + let mut c = zenoh_config::default(); c.connect .endpoints .set(vec![PEER1_ENDPOINT.parse::().unwrap()]) @@ -83,7 +82,7 @@ async fn test_liveliness_subscriber_clique() { async fn test_liveliness_query_clique() { use std::time::Duration; - use zenoh::{config, sample::SampleKind}; + use zenoh::sample::SampleKind; use zenoh_config::WhatAmI; use zenoh_link::EndPoint; const TIMEOUT: Duration = Duration::from_secs(60); @@ -94,7 +93,7 @@ async fn test_liveliness_query_clique() { zenoh_util::init_log_from_env_or("error"); let peer1 = { - let mut c = config::default(); + let mut c = zenoh_config::default(); c.listen .endpoints .set(vec![PEER1_ENDPOINT.parse::().unwrap()]) @@ -107,7 +106,7 @@ async fn test_liveliness_query_clique() { }; let peer2 = { - let mut c = config::default(); + let mut c = zenoh_config::default(); c.connect .endpoints .set(vec![PEER1_ENDPOINT.parse::().unwrap()]) @@ -140,7 +139,7 @@ async fn test_liveliness_query_clique() { async fn test_liveliness_subscriber_brokered() { use std::time::Duration; - use zenoh::{config, sample::SampleKind}; + use zenoh::sample::SampleKind; use zenoh_config::WhatAmI; use zenoh_link::EndPoint; @@ -152,7 +151,7 @@ async fn test_liveliness_subscriber_brokered() { zenoh_util::init_log_from_env_or("error"); let router = { - let mut c = config::default(); + let mut c = zenoh_config::default(); c.listen .endpoints .set(vec![ROUTER_ENDPOINT.parse::().unwrap()]) @@ -165,7 +164,7 @@ async fn test_liveliness_subscriber_brokered() { }; let client1 = { - let mut c = config::default(); + let mut c = zenoh_config::default(); c.connect .endpoints .set(vec![ROUTER_ENDPOINT.parse::().unwrap()]) @@ -178,7 +177,7 @@ async fn test_liveliness_subscriber_brokered() { }; let client2 = { - let mut c = config::default(); + let mut c = zenoh_config::default(); c.connect .endpoints .set(vec![ROUTER_ENDPOINT.parse::().unwrap()]) @@ -219,7 +218,7 @@ async fn test_liveliness_subscriber_brokered() { async fn test_liveliness_query_brokered() { use std::time::Duration; - use zenoh::{config, sample::SampleKind}; + use zenoh::sample::SampleKind; use zenoh_config::WhatAmI; use zenoh_link::EndPoint; const TIMEOUT: Duration = Duration::from_secs(60); @@ -230,7 +229,7 @@ async fn test_liveliness_query_brokered() { zenoh_util::init_log_from_env_or("error"); let router = { - let mut c = config::default(); + let mut c = zenoh_config::default(); c.listen .endpoints .set(vec![ROUTER_ENDPOINT.parse::().unwrap()]) @@ -243,7 +242,7 @@ async fn test_liveliness_query_brokered() { }; let client1 = { - let mut c = config::default(); + let mut c = zenoh_config::default(); c.connect .endpoints .set(vec![ROUTER_ENDPOINT.parse::().unwrap()]) @@ -256,7 +255,7 @@ async fn test_liveliness_query_brokered() { }; let client2 = { - let mut c = config::default(); + let mut c = zenoh_config::default(); c.connect .endpoints .set(vec![ROUTER_ENDPOINT.parse::().unwrap()]) @@ -290,7 +289,7 @@ async fn test_liveliness_query_brokered() { async fn test_liveliness_subscriber_local() { use std::time::Duration; - use zenoh::{config, sample::SampleKind}; + use zenoh::sample::SampleKind; use zenoh_config::WhatAmI; const TIMEOUT: Duration = Duration::from_secs(60); const SLEEP: Duration = Duration::from_secs(1); @@ -299,7 +298,7 @@ async fn test_liveliness_subscriber_local() { zenoh_util::init_log_from_env_or("error"); let peer = { - let mut c = config::default(); + let mut c = zenoh_config::default(); c.scouting.multicast.set_enabled(Some(false)).unwrap(); let _ = c.set_mode(Some(WhatAmI::Peer)); let s = ztimeout!(zenoh::open(c)).unwrap(); @@ -333,7 +332,7 @@ async fn test_liveliness_subscriber_local() { async fn test_liveliness_query_local() { use std::time::Duration; - use zenoh::{config, sample::SampleKind}; + use zenoh::sample::SampleKind; use zenoh_config::WhatAmI; const TIMEOUT: Duration = Duration::from_secs(60); const SLEEP: Duration = Duration::from_secs(1); @@ -342,7 +341,7 @@ async fn test_liveliness_query_local() { zenoh_util::init_log_from_env_or("error"); let peer = { - let mut c = config::default(); + let mut c = zenoh_config::default(); c.scouting.multicast.set_enabled(Some(false)).unwrap(); let _ = c.set_mode(Some(WhatAmI::Peer)); let s = ztimeout!(zenoh::open(c)).unwrap(); diff --git a/zenoh/tests/matching.rs b/zenoh/tests/matching.rs index d7825e85b8..ae048f0203 100644 --- a/zenoh/tests/matching.rs +++ b/zenoh/tests/matching.rs @@ -15,7 +15,8 @@ use std::{str::FromStr, time::Duration}; use flume::RecvTimeoutError; -use zenoh::{config, config::Locator, sample::Locality, Result as ZResult, Session}; +use zenoh::{sample::Locality, Result as ZResult, Session}; +use zenoh_config::Locator; use zenoh_core::ztimeout; const TIMEOUT: Duration = Duration::from_secs(60); @@ -23,7 +24,7 @@ const RECV_TIMEOUT: Duration = Duration::from_secs(1); async fn create_session_pair(locator: &str) -> (Session, Session) { let config1 = { - let mut config = config::peer(); + let mut config = zenoh_config::peer(); config.scouting.multicast.set_enabled(Some(false)).unwrap(); config .listen @@ -32,7 +33,7 @@ async fn create_session_pair(locator: &str) -> (Session, Session) { .unwrap(); config }; - let config2 = config::client([Locator::from_str(locator).unwrap()]); + let config2 = zenoh_config::client([Locator::from_str(locator).unwrap()]); let session1 = ztimeout!(zenoh::open(config1)).unwrap(); let session2 = ztimeout!(zenoh::open(config2)).unwrap(); @@ -95,8 +96,8 @@ async fn zenoh_matching_status_any() -> ZResult<()> { async fn zenoh_matching_status_remote() -> ZResult<()> { zenoh_util::init_log_from_env_or("error"); - let session1 = ztimeout!(zenoh::open(config::peer())).unwrap(); - let session2 = ztimeout!(zenoh::open(config::peer())).unwrap(); + let session1 = ztimeout!(zenoh::open(zenoh_config::peer())).unwrap(); + let session2 = ztimeout!(zenoh::open(zenoh_config::peer())).unwrap(); let publisher1 = ztimeout!(session1 .declare_publisher("zenoh_matching_status_remote_test") @@ -150,8 +151,8 @@ async fn zenoh_matching_status_remote() -> ZResult<()> { async fn zenoh_matching_status_local() -> ZResult<()> { zenoh_util::init_log_from_env_or("error"); - let session1 = ztimeout!(zenoh::open(zenoh::config::peer())).unwrap(); - let session2 = ztimeout!(zenoh::open(zenoh::config::peer())).unwrap(); + let session1 = ztimeout!(zenoh::open(zenoh_config::peer())).unwrap(); + let session2 = ztimeout!(zenoh::open(zenoh_config::peer())).unwrap(); let publisher1 = ztimeout!(session1 .declare_publisher("zenoh_matching_status_local_test") diff --git a/zenoh/tests/routing.rs b/zenoh/tests/routing.rs index e9c8fd899f..c291ef4bf1 100644 --- a/zenoh/tests/routing.rs +++ b/zenoh/tests/routing.rs @@ -20,11 +20,8 @@ use std::{ }; use tokio_util::sync::CancellationToken; -use zenoh::{ - config::{ModeDependentValue, WhatAmI, WhatAmIMatcher}, - qos::CongestionControl, - Config, Result, Session, -}; +use zenoh::{config::WhatAmI, qos::CongestionControl, Config, Result, Session}; +use zenoh_config::{ModeDependentValue, WhatAmIMatcher}; use zenoh_core::ztimeout; use zenoh_result::bail; diff --git a/zenoh/tests/session.rs b/zenoh/tests/session.rs index 04f3bde4f9..72f870a1ab 100644 --- a/zenoh/tests/session.rs +++ b/zenoh/tests/session.rs @@ -23,7 +23,7 @@ use std::{ use zenoh::internal::runtime::{Runtime, RuntimeBuilder}; #[cfg(feature = "unstable")] use zenoh::pubsub::Reliability; -use zenoh::{config, key_expr::KeyExpr, qos::CongestionControl, sample::SampleKind, Session}; +use zenoh::{key_expr::KeyExpr, qos::CongestionControl, sample::SampleKind, Session}; use zenoh_core::ztimeout; #[cfg(not(feature = "unstable"))] use zenoh_protocol::core::Reliability; @@ -36,7 +36,7 @@ const MSG_SIZE: [usize; 2] = [1_024, 100_000]; async fn open_session_unicast(endpoints: &[&str]) -> (Session, Session) { // Open the sessions - let mut config = config::peer(); + let mut config = zenoh_config::peer(); config .listen .endpoints @@ -51,7 +51,7 @@ async fn open_session_unicast(endpoints: &[&str]) -> (Session, Session) { println!("[ ][01a] Opening peer01 session: {:?}", endpoints); let peer01 = ztimeout!(zenoh::open(config)).unwrap(); - let mut config = config::peer(); + let mut config = zenoh_config::peer(); config .connect .endpoints @@ -71,7 +71,7 @@ async fn open_session_unicast(endpoints: &[&str]) -> (Session, Session) { async fn open_session_multicast(endpoint01: &str, endpoint02: &str) -> (Session, Session) { // Open the sessions - let mut config = config::peer(); + let mut config = zenoh_config::peer(); config .listen .endpoints @@ -81,7 +81,7 @@ async fn open_session_multicast(endpoint01: &str, endpoint02: &str) -> (Session, println!("[ ][01a] Opening peer01 session: {}", endpoint01); let peer01 = ztimeout!(zenoh::open(config)).unwrap(); - let mut config = config::peer(); + let mut config = zenoh_config::peer(); config .listen .endpoints @@ -286,7 +286,7 @@ async fn zenoh_session_multicast() { #[cfg(feature = "internal")] async fn open_session_unicast_runtime(endpoints: &[&str]) -> (Runtime, Runtime) { // Open the sessions - let mut config = config::peer(); + let mut config = zenoh_config::peer(); config .listen .endpoints @@ -302,7 +302,7 @@ async fn open_session_unicast_runtime(endpoints: &[&str]) -> (Runtime, Runtime) let mut r1 = RuntimeBuilder::new(config).build().await.unwrap(); r1.start().await.unwrap(); - let mut config = config::peer(); + let mut config = zenoh_config::peer(); config .connect .endpoints diff --git a/zenoh/tests/shm.rs b/zenoh/tests/shm.rs index 8e1205f711..310f032148 100644 --- a/zenoh/tests/shm.rs +++ b/zenoh/tests/shm.rs @@ -21,7 +21,6 @@ use std::{ }; use zenoh::{ - config, pubsub::Reliability, qos::CongestionControl, shm::{ @@ -40,7 +39,7 @@ const MSG_SIZE: [usize; 2] = [1_024, 100_000]; async fn open_session_unicast(endpoints: &[&str]) -> (Session, Session) { // Open the sessions - let mut config = config::peer(); + let mut config = zenoh_config::peer(); config .listen .endpoints @@ -55,7 +54,7 @@ async fn open_session_unicast(endpoints: &[&str]) -> (Session, Session) { println!("[ ][01a] Opening peer01 session: {:?}", endpoints); let peer01 = ztimeout!(zenoh::open(config)).unwrap(); - let mut config = config::peer(); + let mut config = zenoh_config::peer(); config .connect .endpoints @@ -75,7 +74,7 @@ async fn open_session_unicast(endpoints: &[&str]) -> (Session, Session) { async fn open_session_multicast(endpoint01: &str, endpoint02: &str) -> (Session, Session) { // Open the sessions - let mut config = config::peer(); + let mut config = zenoh_config::peer(); config .listen .endpoints @@ -85,7 +84,7 @@ async fn open_session_multicast(endpoint01: &str, endpoint02: &str) -> (Session, println!("[ ][01a] Opening peer01 session: {}", endpoint01); let peer01 = ztimeout!(zenoh::open(config)).unwrap(); - let mut config = config::peer(); + let mut config = zenoh_config::peer(); config .listen .endpoints diff --git a/zenoh/tests/unicity.rs b/zenoh/tests/unicity.rs index de63b0a97e..4087ffc531 100644 --- a/zenoh/tests/unicity.rs +++ b/zenoh/tests/unicity.rs @@ -20,13 +20,8 @@ use std::{ }; use tokio::runtime::Handle; -use zenoh::{ - config, - config::{EndPoint, WhatAmI}, - key_expr::KeyExpr, - qos::CongestionControl, - Session, -}; +use zenoh::{config::WhatAmI, key_expr::KeyExpr, qos::CongestionControl, Session}; +use zenoh_config::EndPoint; use zenoh_core::ztimeout; const TIMEOUT: Duration = Duration::from_secs(60); @@ -36,7 +31,7 @@ const MSG_SIZE: [usize; 2] = [1_024, 100_000]; async fn open_p2p_sessions() -> (Session, Session, Session) { // Open the sessions - let mut config = config::peer(); + let mut config = zenoh_config::peer(); config .listen .endpoints @@ -46,7 +41,7 @@ async fn open_p2p_sessions() -> (Session, Session, Session) { println!("[ ][01a] Opening s01 session"); let s01 = ztimeout!(zenoh::open(config)).unwrap(); - let mut config = config::peer(); + let mut config = zenoh_config::peer(); config .listen .endpoints @@ -61,7 +56,7 @@ async fn open_p2p_sessions() -> (Session, Session, Session) { println!("[ ][02a] Opening s02 session"); let s02 = ztimeout!(zenoh::open(config)).unwrap(); - let mut config = config::peer(); + let mut config = zenoh_config::peer(); config .connect .endpoints @@ -79,7 +74,7 @@ async fn open_p2p_sessions() -> (Session, Session, Session) { async fn open_router_session() -> Session { // Open the sessions - let mut config = config::default(); + let mut config = zenoh_config::default(); config.set_mode(Some(WhatAmI::Router)).unwrap(); config .listen @@ -98,15 +93,15 @@ async fn close_router_session(s: Session) { async fn open_client_sessions() -> (Session, Session, Session) { // Open the sessions - let config = config::client(["tcp/127.0.0.1:37447".parse::().unwrap()]); + let config = zenoh_config::client(["tcp/127.0.0.1:37447".parse::().unwrap()]); println!("[ ][01a] Opening s01 session"); let s01 = ztimeout!(zenoh::open(config)).unwrap(); - let config = config::client(["tcp/127.0.0.1:37447".parse::().unwrap()]); + let config = zenoh_config::client(["tcp/127.0.0.1:37447".parse::().unwrap()]); println!("[ ][02a] Opening s02 session"); let s02 = ztimeout!(zenoh::open(config)).unwrap(); - let config = config::client(["tcp/127.0.0.1:37447".parse::().unwrap()]); + let config = zenoh_config::client(["tcp/127.0.0.1:37447".parse::().unwrap()]); println!("[ ][03a] Opening s03 session"); let s03 = ztimeout!(zenoh::open(config)).unwrap(); diff --git a/zenohd/Cargo.toml b/zenohd/Cargo.toml index b0320ce648..9347c7f8ee 100644 --- a/zenohd/Cargo.toml +++ b/zenohd/Cargo.toml @@ -43,6 +43,7 @@ tracing-subscriber = {workspace = true} tracing-loki = {workspace = true, optional = true } url = {workspace = true, optional = true } zenoh = { workspace = true, features = ["unstable", "internal", "plugins"] } +zenoh-config = { workspace = true } [dev-dependencies] rand = { workspace = true, features = ["default"] } diff --git a/zenohd/src/main.rs b/zenohd/src/main.rs index 85a063e3a2..e618b6f3db 100644 --- a/zenohd/src/main.rs +++ b/zenohd/src/main.rs @@ -17,10 +17,8 @@ use git_version::git_version; use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter}; #[cfg(feature = "loki")] use url::Url; -use zenoh::{ - config::{Config, EndPoint, ModeDependentValue, PermissionsConf, WhatAmI}, - Result, -}; +use zenoh::{config::WhatAmI, Config, Result}; +use zenoh_config::{EndPoint, ModeDependentValue, PermissionsConf}; use zenoh_util::LibSearchDirs; #[cfg(feature = "loki")]