diff --git a/commons/zenoh-config/src/connection_retry.rs b/commons/zenoh-config/src/connection_retry.rs index 55234dcc91..0a50495eb7 100644 --- a/commons/zenoh-config/src/connection_retry.rs +++ b/commons/zenoh-config/src/connection_retry.rs @@ -22,7 +22,7 @@ use crate::{ DEFAULT_LISTEN_EXIT_ON_FAIL, DEFAULT_LISTEN_TIMEOUT_MS, }, mode_dependent::*, - Config, + InternalConfig, }; #[derive(Debug, Deserialize, Serialize, Clone)] @@ -121,7 +121,7 @@ fn ms_to_duration(ms: i64) -> std::time::Duration { } } -pub fn get_global_listener_timeout(config: &Config) -> std::time::Duration { +pub fn get_global_listener_timeout(config: &InternalConfig) -> std::time::Duration { let whatami = config.mode().unwrap_or(defaults::mode); ms_to_duration( *config @@ -132,7 +132,7 @@ pub fn get_global_listener_timeout(config: &Config) -> std::time::Duration { ) } -pub fn get_global_connect_timeout(config: &Config) -> std::time::Duration { +pub fn get_global_connect_timeout(config: &InternalConfig) -> std::time::Duration { let whatami = config.mode().unwrap_or(defaults::mode); ms_to_duration( *config @@ -144,7 +144,7 @@ pub fn get_global_connect_timeout(config: &Config) -> std::time::Duration { } pub fn get_retry_config( - config: &Config, + config: &InternalConfig, endpoint: Option<&EndPoint>, listen: bool, ) -> ConnectionRetryConf { diff --git a/commons/zenoh-config/src/lib.rs b/commons/zenoh-config/src/lib.rs index b57c62edde..3f4dffc850 100644 --- a/commons/zenoh-config/src/lib.rs +++ b/commons/zenoh-config/src/lib.rs @@ -25,6 +25,7 @@ use std::{ fmt, io::Read, net::SocketAddr, + ops::DerefMut, path::Path, sync::{Arc, Mutex, MutexGuard, Weak}, }; @@ -197,25 +198,29 @@ pub trait ConfigValidator: Send + Sync { impl ConfigValidator for () {} /// Creates an empty zenoh net Session configuration. -pub fn empty() -> Config { - Config::default() +#[zenoh_macros::internal] +pub fn empty() -> InternalConfig { + InternalConfig::default() } /// Creates a default zenoh net Session configuration (equivalent to `peer`). -pub fn default() -> Config { +#[zenoh_macros::internal] +pub fn default() -> InternalConfig { peer() } /// Creates a default `'peer'` mode zenoh net Session configuration. -pub fn peer() -> Config { - let mut config = Config::default(); +#[zenoh_macros::internal] +pub fn peer() -> InternalConfig { + let mut config = InternalConfig::default(); config.set_mode(Some(WhatAmI::Peer)).unwrap(); config } /// Creates a default `'client'` mode zenoh net Session configuration. -pub fn client, T: Into>(peers: I) -> Config { - let mut config = Config::default(); +#[zenoh_macros::internal] +pub fn client, T: Into>(peers: I) -> InternalConfig { + let mut config = InternalConfig::default(); config.set_mode(Some(WhatAmI::Client)).unwrap(); config.connect.endpoints = ModeDependentValue::Unique(peers.into_iter().map(|t| t.into()).collect()); @@ -224,22 +229,61 @@ pub fn client, T: Into>(peers: I) -> Config #[test] fn config_keys() { - let c = Config::default(); + let c = InternalConfig::default(); 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)] +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)?)) + } +} + +#[zenoh_macros::internal] +impl Deref for Config { + type Target = InternalConfig; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +#[zenoh_macros::internal] +impl DerefMut for Config { + fn deref_mut(&mut self) -> &mut ::Target { + &mut self.0 + } +} + +#[zenoh_macros::internal] +impl From for InternalConfig { + fn from(value: Config) -> Self { + value.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 { + 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 +623,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 +650,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 +674,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 +691,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 +770,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 +786,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 +800,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 +812,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 +839,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 +856,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,7 +880,7 @@ impl Clone for Notifier { } } } -impl Notifier { +impl Notifier { pub fn remove>(&self, key: K) -> ZResult<()> { let key = key.as_ref(); self._remove(key) diff --git a/examples/src/lib.rs b/examples/src/lib.rs index 20409b4f85..47b2b623f6 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; #[derive(clap::ValueEnum, Clone, Copy, PartialEq, Eq, Hash, Debug)] pub enum Wai { diff --git a/io/zenoh-link/src/lib.rs b/io/zenoh-link/src/lib.rs index 7898cf087d..4c2dc4ae7b 100644 --- a/io/zenoh-link/src/lib.rs +++ b/io/zenoh-link/src/lib.rs @@ -19,7 +19,7 @@ //! [Click here for Zenoh's documentation](../zenoh/index.html) use std::collections::HashMap; -use zenoh_config::Config; +use zenoh_config::InternalConfig; pub use zenoh_link_commons::*; #[cfg(feature = "transport_quic")] pub use zenoh_link_quic as quic; @@ -157,7 +157,7 @@ impl LinkConfigurator { #[allow(unused_variables, unused_mut)] pub fn configurations( &self, - config: &Config, + config: &InternalConfig, ) -> ( HashMap, HashMap, diff --git a/io/zenoh-links/zenoh-link-quic/src/utils.rs b/io/zenoh-links/zenoh-link-quic/src/utils.rs index b5cc7c49f8..9b51a373f5 100644 --- a/io/zenoh-links/zenoh-link-quic/src/utils.rs +++ b/io/zenoh-links/zenoh-link-quic/src/utils.rs @@ -27,7 +27,7 @@ use rustls::{ }; use secrecy::ExposeSecret; use webpki::anchor_from_trusted_cert; -use zenoh_config::Config as ZenohConfig; +use zenoh_config::InternalConfig as ZenohConfig; use zenoh_link_commons::{tls::WebPkiVerifierAnyServerName, ConfigurationInspector}; use zenoh_protocol::core::{ endpoint::{Address, Config}, diff --git a/io/zenoh-links/zenoh-link-tls/src/utils.rs b/io/zenoh-links/zenoh-link-tls/src/utils.rs index d6fde3d243..656172af52 100644 --- a/io/zenoh-links/zenoh-link-tls/src/utils.rs +++ b/io/zenoh-links/zenoh-link-tls/src/utils.rs @@ -29,7 +29,7 @@ use rustls::{ use rustls_pki_types::ServerName; use secrecy::ExposeSecret; use webpki::anchor_from_trusted_cert; -use zenoh_config::Config as ZenohConfig; +use zenoh_config::InternalConfig as ZenohConfig; use zenoh_link_commons::{tls::WebPkiVerifierAnyServerName, ConfigurationInspector}; use zenoh_protocol::core::{ endpoint::{Address, Config}, diff --git a/io/zenoh-links/zenoh-link-unixpipe/src/unix/mod.rs b/io/zenoh-links/zenoh-link-unixpipe/src/unix/mod.rs index ff1c2f983b..377aafe4be 100644 --- a/io/zenoh-links/zenoh-link-unixpipe/src/unix/mod.rs +++ b/io/zenoh-links/zenoh-link-unixpipe/src/unix/mod.rs @@ -21,7 +21,7 @@ pub mod unicast; use async_trait::async_trait; pub use unicast::*; -use zenoh_config::Config; +use zenoh_config::InternalConfig; use zenoh_core::zconfigurable; use zenoh_link_commons::{ConfigurationInspector, LocatorInspector}; use zenoh_protocol::core::{parameters, Locator}; @@ -45,8 +45,8 @@ impl LocatorInspector for UnixPipeLocatorInspector { #[derive(Default, Clone, Copy, Debug)] pub struct UnixPipeConfigurator; -impl ConfigurationInspector for UnixPipeConfigurator { - fn inspect_config(&self, config: &Config) -> ZResult { +impl ConfigurationInspector for UnixPipeConfigurator { + fn inspect_config(&self, config: &InternalConfig) -> ZResult { let mut properties: Vec<(&str, &str)> = vec![]; let c = config.transport().link().unixpipe(); diff --git a/io/zenoh-transport/src/manager.rs b/io/zenoh-transport/src/manager.rs index 305ccab574..4994218fff 100644 --- a/io/zenoh-transport/src/manager.rs +++ b/io/zenoh-transport/src/manager.rs @@ -15,7 +15,7 @@ use std::{collections::HashMap, sync::Arc, time::Duration}; use rand::{RngCore, SeedableRng}; use tokio::sync::Mutex as AsyncMutex; -use zenoh_config::{Config, LinkRxConf, QueueConf, QueueSizeConf}; +use zenoh_config::{InternalConfig, LinkRxConf, QueueConf, QueueSizeConf}; use zenoh_crypto::{BlockCipher, PseudoRng}; use zenoh_link::NewLinkChannelSender; use zenoh_protocol::{ @@ -227,7 +227,7 @@ impl TransportManagerBuilder { self } - pub async fn from_config(mut self, config: &Config) -> ZResult { + pub async fn from_config(mut self, config: &InternalConfig) -> ZResult { self = self.zid((*config.id()).into()); if let Some(v) = config.mode() { self = self.whatami(*v); diff --git a/io/zenoh-transport/src/multicast/manager.rs b/io/zenoh-transport/src/multicast/manager.rs index e2899b1d1a..fcd84e4bf6 100644 --- a/io/zenoh-transport/src/multicast/manager.rs +++ b/io/zenoh-transport/src/multicast/manager.rs @@ -18,7 +18,7 @@ use tokio::sync::Mutex; use zenoh_config::CompressionMulticastConf; #[cfg(feature = "shared-memory")] use zenoh_config::ShmConf; -use zenoh_config::{Config, LinkTxConf}; +use zenoh_config::{InternalConfig, LinkTxConf}; use zenoh_core::zasynclock; use zenoh_link::*; use zenoh_protocol::{ @@ -106,7 +106,7 @@ impl TransportManagerBuilderMulticast { self } - pub fn from_config(mut self, config: &Config) -> ZResult { + pub fn from_config(mut self, config: &InternalConfig) -> ZResult { self = self.lease(Duration::from_millis( *config.transport().link().tx().lease(), )); @@ -167,7 +167,7 @@ impl Default for TransportManagerBuilderMulticast { #[cfg(feature = "transport_compression")] is_compression: *compression.enabled(), }; - tmb.from_config(&Config::default()).unwrap() + tmb.from_config(&InternalConfig::default()).unwrap() } } diff --git a/io/zenoh-transport/src/unicast/establishment/ext/auth/mod.rs b/io/zenoh-transport/src/unicast/establishment/ext/auth/mod.rs index 8b7125de6d..a267e42d45 100644 --- a/io/zenoh-transport/src/unicast/establishment/ext/auth/mod.rs +++ b/io/zenoh-transport/src/unicast/establishment/ext/auth/mod.rs @@ -31,7 +31,7 @@ use zenoh_buffers::{ ZBuf, }; use zenoh_codec::{RCodec, WCodec, Zenoh080}; -use zenoh_config::Config; +use zenoh_config::InternalConfig; use zenoh_core::{bail, zerror, Error as ZError, Result as ZResult}; use zenoh_crypto::PseudoRng; use zenoh_protocol::{ @@ -57,7 +57,7 @@ pub struct Auth { } impl Auth { - pub(crate) async fn from_config(config: &Config) -> ZResult { + pub(crate) async fn from_config(config: &InternalConfig) -> ZResult { let auth = config.transport().auth(); Ok(Self { diff --git a/io/zenoh-transport/src/unicast/manager.rs b/io/zenoh-transport/src/unicast/manager.rs index bff221323e..ae1f79f306 100644 --- a/io/zenoh-transport/src/unicast/manager.rs +++ b/io/zenoh-transport/src/unicast/manager.rs @@ -25,7 +25,7 @@ use tokio::sync::{Mutex as AsyncMutex, MutexGuard as AsyncMutexGuard}; use zenoh_config::CompressionUnicastConf; #[cfg(feature = "shared-memory")] use zenoh_config::ShmConf; -use zenoh_config::{Config, LinkTxConf, QoSUnicastConf, TransportUnicastConf}; +use zenoh_config::{InternalConfig, LinkTxConf, QoSUnicastConf, TransportUnicastConf}; use zenoh_core::{zasynclock, zcondfeat}; use zenoh_crypto::PseudoRng; use zenoh_link::*; @@ -180,7 +180,10 @@ impl TransportManagerBuilderUnicast { self } - pub async fn from_config(mut self, config: &Config) -> ZResult { + pub async fn from_config( + mut self, + config: &InternalConfig, + ) -> ZResult { self = self.lease(Duration::from_millis( *config.transport().link().tx().lease(), )); diff --git a/plugins/zenoh-plugin-rest/examples/z_serve_sse.rs b/plugins/zenoh-plugin-rest/examples/z_serve_sse.rs index fd81ff279f..ee13e81869 100644 --- a/plugins/zenoh-plugin-rest/examples/z_serve_sse.rs +++ b/plugins/zenoh-plugin-rest/examples/z_serve_sse.rs @@ -14,7 +14,7 @@ use std::time::Duration; use clap::{arg, Command}; -use zenoh::{config::Config, key_expr::keyexpr, qos::CongestionControl}; +use zenoh::{key_expr::keyexpr, qos::CongestionControl, Config}; const HTML: &str = r#"
diff --git a/plugins/zenoh-plugin-storage-manager/tests/operations.rs b/plugins/zenoh-plugin-storage-manager/tests/operations.rs index c3ddf67d2e..6e3b5c84e4 100644 --- a/plugins/zenoh-plugin-storage-manager/tests/operations.rs +++ b/plugins/zenoh-plugin-storage-manager/tests/operations.rs @@ -20,7 +20,7 @@ use std::{borrow::Cow, str::FromStr, thread::sleep}; use tokio::runtime::Runtime; use zenoh::{ - internal::zasync_executor_init, query::Reply, sample::Sample, time::Timestamp, Config, Session, + internal::zasync_executor_init, query::Reply, sample::Sample, time::Timestamp, InternalConfig, Session, }; use zenoh_plugin_trait::Plugin; @@ -54,7 +54,7 @@ async fn test_updates_in_order() { zasync_executor_init!(); } .await; - let mut config = Config::default(); + let mut config = InternalConfig::default(); config .insert_json5( "plugins/storage-manager", diff --git a/plugins/zenoh-plugin-storage-manager/tests/wildcard.rs b/plugins/zenoh-plugin-storage-manager/tests/wildcard.rs index b4c7ddd8f2..c8065a064d 100644 --- a/plugins/zenoh-plugin-storage-manager/tests/wildcard.rs +++ b/plugins/zenoh-plugin-storage-manager/tests/wildcard.rs @@ -21,7 +21,7 @@ use std::{borrow::Cow, str::FromStr, thread::sleep}; // use std::collections::HashMap; use tokio::runtime::Runtime; use zenoh::{ - internal::zasync_executor_init, query::Reply, sample::Sample, time::Timestamp, Config, Session, + internal::zasync_executor_init, query::Reply, sample::Sample, time::Timestamp, InternalConfig, Session, }; use zenoh_plugin_trait::Plugin; @@ -52,7 +52,7 @@ async fn get_data(session: &Session, key_expr: &str) -> Vec { async fn test_wild_card_in_order() { zasync_executor_init!(); - let mut config = Config::default(); + let mut config = InternalConfig::default(); config .insert_json5( "plugins/storage-manager", diff --git a/zenoh-ext/examples/examples/z_pub_cache.rs b/zenoh-ext/examples/examples/z_pub_cache.rs index 6c47fb0862..7a4bdc03c4 100644 --- a/zenoh-ext/examples/examples/z_pub_cache.rs +++ b/zenoh-ext/examples/examples/z_pub_cache.rs @@ -14,10 +14,7 @@ use std::time::Duration; use clap::{arg, Parser}; -use zenoh::{ - config::{Config, ModeDependentValue}, - key_expr::KeyExpr, -}; +use zenoh::{config::ModeDependentValue, key_expr::KeyExpr, Config}; use zenoh_ext::*; use zenoh_ext_examples::CommonArgs; diff --git a/zenoh-ext/examples/examples/z_query_sub.rs b/zenoh-ext/examples/examples/z_query_sub.rs index 0d01cb20c7..ebeffba067 100644 --- a/zenoh-ext/examples/examples/z_query_sub.rs +++ b/zenoh-ext/examples/examples/z_query_sub.rs @@ -12,7 +12,7 @@ // ZettaScale Zenoh Team, // use clap::{arg, Parser}; -use zenoh::{config::Config, query::ReplyKeyExpr}; +use zenoh::{query::ReplyKeyExpr, Config}; use zenoh_ext::*; use zenoh_ext_examples::CommonArgs; diff --git a/zenoh-ext/examples/examples/z_view_size.rs b/zenoh-ext/examples/examples/z_view_size.rs index 79eb5bd3c1..da411ef8e4 100644 --- a/zenoh-ext/examples/examples/z_view_size.rs +++ b/zenoh-ext/examples/examples/z_view_size.rs @@ -14,7 +14,7 @@ use std::{sync::Arc, time::Duration}; use clap::{arg, Parser}; -use zenoh::config::Config; +use zenoh::Config; use zenoh_ext::group::*; use zenoh_ext_examples::CommonArgs; diff --git a/zenoh-ext/examples/src/lib.rs b/zenoh-ext/examples/src/lib.rs index 881d60c138..c84139f8c7 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; #[derive(clap::ValueEnum, Clone, Copy, PartialEq, Eq, Hash, Debug)] pub enum Wai { diff --git a/zenoh/src/api/loader.rs b/zenoh/src/api/loader.rs index 175e0c6816..43626d6147 100644 --- a/zenoh/src/api/loader.rs +++ b/zenoh/src/api/loader.rs @@ -11,7 +11,7 @@ // Contributors: // ZettaScale Zenoh Team, // -use zenoh_config::{Config, PluginLoad}; +use zenoh_config::{InternalConfig, PluginLoad}; use zenoh_result::ZResult; use super::plugins::{PluginsManager, PLUGIN_PREFIX}; @@ -45,7 +45,7 @@ pub(crate) fn load_plugin( Ok(()) } -pub(crate) fn load_plugins(config: &Config) -> PluginsManager { +pub(crate) fn load_plugins(config: &InternalConfig) -> PluginsManager { let mut manager = PluginsManager::dynamic(config.libloader(), PLUGIN_PREFIX.to_string()); // Static plugins are to be added here, with `.add_static::()` for plugin_load in config.plugins().load_requests() { diff --git a/zenoh/src/api/publisher.rs b/zenoh/src/api/publisher.rs index 4870fac445..b1a1f84a14 100644 --- a/zenoh/src/api/publisher.rs +++ b/zenoh/src/api/publisher.rs @@ -856,7 +856,7 @@ impl IntoFuture for MatchingListenerUndeclaration { #[cfg(test)] mod tests { - use zenoh_config::Config; + use zenoh_config::InternalConfig; use zenoh_core::Wait; use crate::api::sample::SampleKind; @@ -896,7 +896,7 @@ mod tests { const VALUE: &str = "zenoh"; fn sample_kind_integrity_in_publication_with(kind: SampleKind) { - let session = open(Config::default()).wait().unwrap(); + let session = open(InternalConfig::default()).wait().unwrap(); let sub = session.declare_subscriber(KEY_EXPR).wait().unwrap(); let pub_ = session.declare_publisher(KEY_EXPR).wait().unwrap(); @@ -924,7 +924,7 @@ mod tests { const VALUE: &str = "zenoh"; fn sample_kind_integrity_in_put_builder_with(kind: SampleKind) { - let session = open(Config::default()).wait().unwrap(); + let session = open(InternalConfig::default()).wait().unwrap(); let sub = session.declare_subscriber(KEY_EXPR).wait().unwrap(); match kind { diff --git a/zenoh/src/api/scouting.rs b/zenoh/src/api/scouting.rs index 73c0afcbdf..584054afb0 100644 --- a/zenoh/src/api/scouting.rs +++ b/zenoh/src/api/scouting.rs @@ -51,7 +51,7 @@ use crate::{ #[derive(Debug)] pub struct ScoutBuilder { pub(crate) what: WhatAmIMatcher, - pub(crate) config: ZResult, + pub(crate) config: ZResult, pub(crate) handler: Handler, } @@ -285,7 +285,7 @@ impl Scout { fn _scout( what: WhatAmIMatcher, - config: zenoh_config::Config, + config: zenoh_config::InternalConfig, callback: Callback, ) -> ZResult { tracing::trace!("scout({}, {})", what, &config); @@ -365,8 +365,8 @@ pub fn scout, TryIntoConfig>( config: TryIntoConfig, ) -> ScoutBuilder where - TryIntoConfig: std::convert::TryInto + Send + 'static, - >::Error: + TryIntoConfig: std::convert::TryInto + Send + 'static, + >::Error: Into, { ScoutBuilder { diff --git a/zenoh/src/api/session.rs b/zenoh/src/api/session.rs index 4d98820468..b1dd5f6927 100644 --- a/zenoh/src/api/session.rs +++ b/zenoh/src/api/session.rs @@ -30,7 +30,7 @@ use tracing::{error, info, trace, warn}; use uhlc::{Timestamp, HLC}; use zenoh_buffers::ZBuf; use zenoh_collections::SingleOrVec; -use zenoh_config::{unwrap_or_default, wrappers::ZenohId, Config, Notifier}; +use zenoh_config::{unwrap_or_default, wrappers::ZenohId, InternalConfig, Notifier}; use zenoh_core::{zconfigurable, zread, Resolvable, Resolve, ResolveClosure, ResolveFuture, Wait}; #[cfg(feature = "unstable")] use zenoh_protocol::network::{ @@ -647,7 +647,7 @@ impl Session { /// let _ = session.config().insert_json5("connect/endpoints", r#"["tcp/127.0.0.1/7447"]"#); /// # } /// ``` - pub fn config(&self) -> &Notifier { + pub fn config(&self) -> &Notifier { self.0.runtime.config() } @@ -1031,7 +1031,7 @@ impl Session { impl Session { #[allow(clippy::new_ret_no_self)] pub(super) fn new( - config: Config, + config: InternalConfig, #[cfg(feature = "shared-memory")] shm_clients: Option>, ) -> impl Resolve> { ResolveFuture::new(async move { @@ -2863,8 +2863,8 @@ where #[cfg(feature = "shared-memory")] impl OpenBuilder where - TryIntoConfig: std::convert::TryInto + Send + 'static, - >::Error: std::fmt::Debug, + TryIntoConfig: std::convert::TryInto + Send + 'static, + >::Error: std::fmt::Debug, { pub fn with_shm_clients(mut self, shm_clients: Arc) -> Self { self.shm_clients = Some(shm_clients); @@ -2891,7 +2891,7 @@ where .try_into() .map_err(|e| zerror!("Invalid Zenoh configuration {:?}", &e))?; Session::new( - config, + config.into(), #[cfg(feature = "shared-memory")] self.shm_clients, ) diff --git a/zenoh/src/lib.rs b/zenoh/src/lib.rs index 3fa24e3c36..565bc96320 100644 --- a/zenoh/src/lib.rs +++ b/zenoh/src/lib.rs @@ -125,6 +125,9 @@ pub use crate::{ session::{open, Session}, }; +#[zenoh_macros::internal] +pub use crate::config::InternalConfig; + #[deprecated(since = "1.0.0")] pub mod prelude; diff --git a/zenoh/src/net/routing/dispatcher/tables.rs b/zenoh/src/net/routing/dispatcher/tables.rs index 2c5cfffffb..0de798be91 100644 --- a/zenoh/src/net/routing/dispatcher/tables.rs +++ b/zenoh/src/net/routing/dispatcher/tables.rs @@ -19,7 +19,7 @@ use std::{ }; use uhlc::HLC; -use zenoh_config::{unwrap_or_default, Config}; +use zenoh_config::{unwrap_or_default, InternalConfig}; use zenoh_protocol::{ core::{ExprId, WhatAmI, ZenohIdProto}, network::Mapping, @@ -82,7 +82,7 @@ impl Tables { zid: ZenohIdProto, whatami: WhatAmI, hlc: Option>, - config: &Config, + config: &InternalConfig, ) -> ZResult { let drop_future_timestamp = unwrap_or_default!(config.timestamping().drop_future_timestamp()); diff --git a/zenoh/src/net/routing/hat/mod.rs b/zenoh/src/net/routing/hat/mod.rs index 8a8ddfebf2..e5528969b1 100644 --- a/zenoh/src/net/routing/hat/mod.rs +++ b/zenoh/src/net/routing/hat/mod.rs @@ -19,7 +19,7 @@ //! [Click here for Zenoh's documentation](../zenoh/index.html) use std::{any::Any, sync::Arc}; -use zenoh_config::{unwrap_or_default, Config, WhatAmI}; +use zenoh_config::{unwrap_or_default, InternalConfig, WhatAmI}; use zenoh_protocol::{ core::ZenohIdProto, network::{ @@ -240,7 +240,7 @@ pub(crate) trait HatQueriesTrait { fn get_query_routes_entries(&self, tables: &Tables) -> RoutesIndexes; } -pub(crate) fn new_hat(whatami: WhatAmI, config: &Config) -> Box { +pub(crate) fn new_hat(whatami: WhatAmI, config: &InternalConfig) -> Box { match whatami { WhatAmI::Client => Box::new(client::HatCode {}), WhatAmI::Peer => { diff --git a/zenoh/src/net/routing/interceptor/mod.rs b/zenoh/src/net/routing/interceptor/mod.rs index ba0209de2d..378de4c0a5 100644 --- a/zenoh/src/net/routing/interceptor/mod.rs +++ b/zenoh/src/net/routing/interceptor/mod.rs @@ -24,7 +24,7 @@ use access_control::acl_interceptor_factories; mod authorization; use std::any::Any; -use zenoh_config::Config; +use zenoh_config::InternalConfig; use zenoh_protocol::network::NetworkMessage; use zenoh_result::ZResult; use zenoh_transport::{multicast::TransportMulticast, unicast::TransportUnicast}; @@ -60,7 +60,7 @@ pub(crate) trait InterceptorFactoryTrait { pub(crate) type InterceptorFactory = Box; -pub(crate) fn interceptor_factories(config: &Config) -> ZResult> { +pub(crate) fn interceptor_factories(config: &InternalConfig) -> ZResult> { let mut res: Vec = vec![]; // Uncomment to log the interceptors initialisation // res.push(Box::new(LoggerInterceptor {})); diff --git a/zenoh/src/net/routing/router.rs b/zenoh/src/net/routing/router.rs index cd525189d3..2c44544403 100644 --- a/zenoh/src/net/routing/router.rs +++ b/zenoh/src/net/routing/router.rs @@ -17,7 +17,7 @@ use std::{ }; use uhlc::HLC; -use zenoh_config::Config; +use zenoh_config::InternalConfig; use zenoh_protocol::core::{WhatAmI, ZenohIdProto}; // use zenoh_collections::Timer; use zenoh_result::ZResult; @@ -49,7 +49,7 @@ impl Router { zid: ZenohIdProto, whatami: WhatAmI, hlc: Option>, - config: &Config, + config: &InternalConfig, ) -> ZResult { Ok(Router { // whatami, diff --git a/zenoh/src/net/runtime/mod.rs b/zenoh/src/net/runtime/mod.rs index 1a02513494..8eb5c17caf 100644 --- a/zenoh/src/net/runtime/mod.rs +++ b/zenoh/src/net/runtime/mod.rs @@ -62,7 +62,7 @@ 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}, + config::{unwrap_or_default, InternalConfig, ModeDependent, Notifier}, GIT_VERSION, LONG_VERSION, }; @@ -71,7 +71,7 @@ pub(crate) struct RuntimeState { whatami: WhatAmI, next_id: AtomicU32, router: Arc, - config: Notifier, + config: Notifier, manager: TransportManager, transport_handlers: std::sync::RwLock>>, locators: std::sync::RwLock>, @@ -93,7 +93,7 @@ impl WeakRuntime { } pub struct RuntimeBuilder { - config: Config, + config: InternalConfig, #[cfg(feature = "plugins")] plugins_manager: Option, #[cfg(feature = "shared-memory")] @@ -101,7 +101,7 @@ pub struct RuntimeBuilder { } impl RuntimeBuilder { - pub fn new(config: Config) -> Self { + pub fn new(config: InternalConfig) -> Self { Self { config, #[cfg(feature = "plugins")] @@ -329,7 +329,7 @@ impl Runtime { self.state.router.clone() } - pub fn config(&self) -> &Notifier { + pub fn config(&self) -> &Notifier { &self.state.config } diff --git a/zenoh/src/net/tests/tables.rs b/zenoh/src/net/tests/tables.rs index 23c0d9c053..cc2c70c4bd 100644 --- a/zenoh/src/net/tests/tables.rs +++ b/zenoh/src/net/tests/tables.rs @@ -18,7 +18,7 @@ use std::{ use uhlc::HLC; use zenoh_buffers::ZBuf; -use zenoh_config::Config; +use zenoh_config::InternalConfig; use zenoh_core::zlock; use zenoh_protocol::{ core::{ @@ -43,7 +43,7 @@ use crate::net::{ #[test] fn base_test() { - let config = Config::default(); + let config = InternalConfig::default(); let router = Router::new( ZenohIdProto::try_from([1]).unwrap(), WhatAmI::Client, @@ -138,7 +138,7 @@ fn match_test() { ] .map(|s| keyexpr::new(s).unwrap()); - let config = Config::default(); + let config = InternalConfig::default(); let router = Router::new( ZenohIdProto::try_from([1]).unwrap(), WhatAmI::Client, @@ -178,7 +178,7 @@ fn match_test() { #[test] fn multisub_test() { - let config = Config::default(); + let config = InternalConfig::default(); let router = Router::new( ZenohIdProto::try_from([1]).unwrap(), WhatAmI::Client, @@ -249,7 +249,7 @@ fn multisub_test() { #[tokio::test(flavor = "multi_thread", worker_threads = 1)] async fn clean_test() { - let config = Config::default(); + let config = InternalConfig::default(); let router = Router::new( ZenohIdProto::try_from([1]).unwrap(), WhatAmI::Client, @@ -579,7 +579,7 @@ impl EPrimitives for ClientPrimitives { #[test] fn client_test() { - let config = Config::default(); + let config = InternalConfig::default(); let router = Router::new( ZenohIdProto::try_from([1]).unwrap(), WhatAmI::Client, diff --git a/zenoh/tests/acl.rs b/zenoh/tests/acl.rs index 285e68b254..47d7dfaf66 100644 --- a/zenoh/tests/acl.rs +++ b/zenoh/tests/acl.rs @@ -23,7 +23,7 @@ mod test { config, config::{EndPoint, WhatAmI}, sample::SampleKind, - Config, Session, + InternalConfig, Session, }; use zenoh_core::{zlock, ztimeout}; @@ -58,7 +58,7 @@ mod test { test_reply_allow_then_deny(27449).await; } - async fn get_basic_router_config(port: u16) -> Config { + async fn get_basic_router_config(port: u16) -> InternalConfig { let mut config = config::default(); config.set_mode(Some(WhatAmI::Router)).unwrap(); config diff --git a/zenoh/tests/attachments.rs b/zenoh/tests/attachments.rs index dd9e287428..9abf3c05e9 100644 --- a/zenoh/tests/attachments.rs +++ b/zenoh/tests/attachments.rs @@ -12,11 +12,11 @@ // ZettaScale Zenoh Team, // #![cfg(feature = "unstable")] -use zenoh::{bytes::ZBytes, config::Config, Wait}; +use zenoh::{bytes::ZBytes, config::InternalConfig, Wait}; #[test] fn attachment_pubsub() { - let zenoh = zenoh::open(Config::default()).wait().unwrap(); + let zenoh = zenoh::open(InternalConfig::default()).wait().unwrap(); let _sub = zenoh .declare_subscriber("test/attachment") .callback(|sample| { @@ -61,7 +61,7 @@ fn attachment_pubsub() { #[test] fn attachment_queries() { - let zenoh = zenoh::open(Config::default()).wait().unwrap(); + let zenoh = zenoh::open(InternalConfig::default()).wait().unwrap(); let _sub = zenoh .declare_queryable("test/attachment") .callback(|query| { diff --git a/zenoh/tests/authentication.rs b/zenoh/tests/authentication.rs index 63ddfcc03c..2248b3d8f3 100644 --- a/zenoh/tests/authentication.rs +++ b/zenoh/tests/authentication.rs @@ -24,7 +24,7 @@ mod test { use zenoh::{ config, config::{EndPoint, WhatAmI}, - Config, Session, + InternalConfig, Session, }; use zenoh_core::{zlock, ztimeout}; @@ -268,7 +268,7 @@ client2name:client2passwd"; Ok(()) } - async fn get_basic_router_config_tls(port: u16, lowlatency: bool) -> Config { + async fn get_basic_router_config_tls(port: u16, lowlatency: bool) -> InternalConfig { let cert_path = TESTFILES_PATH.to_string_lossy(); let mut config = config::default(); config.set_mode(Some(WhatAmI::Router)).unwrap(); @@ -321,7 +321,7 @@ client2name:client2passwd"; .unwrap(); config } - async fn get_basic_router_config_quic(port: u16) -> Config { + async fn get_basic_router_config_quic(port: u16) -> InternalConfig { let cert_path = TESTFILES_PATH.to_string_lossy(); let mut config = config::default(); config.set_mode(Some(WhatAmI::Router)).unwrap(); @@ -368,7 +368,7 @@ client2name:client2passwd"; config } - async fn get_basic_router_config_usrpswd(port: u16) -> Config { + async fn get_basic_router_config_usrpswd(port: u16) -> InternalConfig { let mut config = config::default(); config.set_mode(Some(WhatAmI::Router)).unwrap(); config @@ -406,7 +406,7 @@ client2name:client2passwd"; ztimeout!(s.close()).unwrap(); } - async fn get_basic_router_config_quic_usrpswd(port: u16) -> Config { + async fn get_basic_router_config_quic_usrpswd(port: u16) -> InternalConfig { let cert_path = TESTFILES_PATH.to_string_lossy(); let mut config = config::default(); config.set_mode(Some(WhatAmI::Router)).unwrap(); diff --git a/zenoh/tests/connection_retry.rs b/zenoh/tests/connection_retry.rs index 6bb655851b..9683f0914e 100644 --- a/zenoh/tests/connection_retry.rs +++ b/zenoh/tests/connection_retry.rs @@ -13,12 +13,12 @@ // use zenoh::{ config::{ConnectionRetryConf, EndPoint, ModeDependent}, - Config, Wait, + InternalConfig, Wait, }; #[test] fn retry_config_overriding() { - let mut config = Config::default(); + let mut config = InternalConfig::default(); config .insert_json5( "listen/endpoints", @@ -88,7 +88,7 @@ fn retry_config_overriding() { #[test] fn retry_config_parsing() { - let mut config = Config::default(); + let mut config = InternalConfig::default(); config .insert_json5( "listen/retry", @@ -116,7 +116,7 @@ fn retry_config_parsing() { #[test] fn retry_config_const_period() { - let mut config = Config::default(); + let mut config = InternalConfig::default(); config .insert_json5( "listen/retry", @@ -143,7 +143,7 @@ fn retry_config_const_period() { #[test] fn retry_config_infinite_period() { - let mut config = Config::default(); + let mut config = InternalConfig::default(); config .insert_json5( "listen/retry", @@ -168,7 +168,7 @@ fn retry_config_infinite_period() { #[test] #[should_panic(expected = "Can not create a new TCP listener")] fn listen_no_retry() { - let mut config = Config::default(); + let mut config = InternalConfig::default(); config .insert_json5("listen/endpoints", r#"["tcp/8.8.8.8:8"]"#) .unwrap(); @@ -180,7 +180,7 @@ fn listen_no_retry() { #[test] #[should_panic(expected = "value: Elapsed(())")] fn listen_with_retry() { - let mut config = Config::default(); + let mut config = InternalConfig::default(); config .insert_json5("listen/endpoints", r#"["tcp/8.8.8.8:8"]"#) .unwrap(); diff --git a/zenoh/tests/handler.rs b/zenoh/tests/handler.rs index d87917a0dd..1e21a8981d 100644 --- a/zenoh/tests/handler.rs +++ b/zenoh/tests/handler.rs @@ -13,11 +13,11 @@ // use std::{thread, time::Duration}; -use zenoh::{handlers::RingChannel, Config, Wait}; +use zenoh::{handlers::RingChannel, InternalConfig, Wait}; #[test] fn pubsub_with_ringbuffer() { - let zenoh = zenoh::open(Config::default()).wait().unwrap(); + let zenoh = zenoh::open(InternalConfig::default()).wait().unwrap(); let sub = zenoh .declare_subscriber("test/ringbuffer") .with(RingChannel::new(3)) @@ -46,7 +46,7 @@ fn pubsub_with_ringbuffer() { #[test] fn query_with_ringbuffer() { - let zenoh = zenoh::open(Config::default()).wait().unwrap(); + let zenoh = zenoh::open(InternalConfig::default()).wait().unwrap(); let queryable = zenoh .declare_queryable("test/ringbuffer_query") .with(RingChannel::new(1)) diff --git a/zenoh/tests/interceptors.rs b/zenoh/tests/interceptors.rs index 57ba51d5ba..959a4b561f 100644 --- a/zenoh/tests/interceptors.rs +++ b/zenoh/tests/interceptors.rs @@ -24,7 +24,7 @@ use std::{ use zenoh::{ config::{DownsamplingItemConf, DownsamplingRuleConf, InterceptorFlow}, key_expr::KeyExpr, - Config, Wait, + InternalConfig, Wait, }; // Tokio's time granularity on different platforms @@ -40,15 +40,15 @@ fn build_config( locator: &str, ds_config: Vec, flow: InterceptorFlow, -) -> (Config, Config) { - let mut pub_config = Config::default(); +) -> (InternalConfig, InternalConfig) { + let mut pub_config = InternalConfig::default(); pub_config .scouting .multicast .set_enabled(Some(false)) .unwrap(); - let mut sub_config = Config::default(); + let mut sub_config = InternalConfig::default(); sub_config .scouting .multicast @@ -75,8 +75,8 @@ fn build_config( } fn downsampling_test( - pub_config: Config, - sub_config: Config, + pub_config: InternalConfig, + sub_config: InternalConfig, ke_prefix: &str, ke_of_rates: Vec>, rate_check: F, @@ -254,7 +254,7 @@ fn downsampling_by_interface() { fn downsampling_config_error_wrong_strategy() { zenoh::init_log_from_env_or("error"); - let mut config = Config::default(); + let mut config = InternalConfig::default(); config .insert_json5( "downsampling", diff --git a/zenoh/tests/open_time.rs b/zenoh/tests/open_time.rs index 98714c39c5..c835ccaf92 100644 --- a/zenoh/tests/open_time.rs +++ b/zenoh/tests/open_time.rs @@ -17,7 +17,7 @@ use std::{ time::{Duration, Instant}, }; -use zenoh_config::Config; +use zenoh_config::InternalConfig; use zenoh_link::EndPoint; use zenoh_protocol::core::WhatAmI; @@ -37,7 +37,7 @@ async fn time_open( lowlatency: bool, ) { /* [ROUTER] */ - let mut router_config = Config::default(); + let mut router_config = InternalConfig::default(); router_config.set_mode(Some(WhatAmI::Router)).unwrap(); router_config .listen @@ -67,7 +67,7 @@ async fn time_open( ); /* [APP] */ - let mut app_config = Config::default(); + let mut app_config = InternalConfig::default(); app_config.set_mode(Some(connect_mode)).unwrap(); app_config .connect diff --git a/zenoh/tests/routing.rs b/zenoh/tests/routing.rs index e9c8fd899f..7ce394df9e 100644 --- a/zenoh/tests/routing.rs +++ b/zenoh/tests/routing.rs @@ -23,7 +23,7 @@ use tokio_util::sync::CancellationToken; use zenoh::{ config::{ModeDependentValue, WhatAmI, WhatAmIMatcher}, qos::CongestionControl, - Config, Result, Session, + InternalConfig, Result, Session, }; use zenoh_core::ztimeout; use zenoh_result::bail; @@ -277,7 +277,7 @@ struct Node { listen: Vec, connect: Vec, con_task: ConcurrentTask, - config: Option, + config: Option, warmup: Duration, } @@ -534,7 +534,7 @@ async fn static_failover_brokering() -> Result<()> { let msg_size = 8; let disable_autoconnect_config = || { - let mut config = Config::default(); + let mut config = InternalConfig::default(); config .scouting .gossip diff --git a/zenohd/src/main.rs b/zenohd/src/main.rs index 85a063e3a2..34a80b87b6 100644 --- a/zenohd/src/main.rs +++ b/zenohd/src/main.rs @@ -18,7 +18,7 @@ use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilte #[cfg(feature = "loki")] use url::Url; use zenoh::{ - config::{Config, EndPoint, ModeDependentValue, PermissionsConf, WhatAmI}, + config::{InternalConfig, EndPoint, ModeDependentValue, PermissionsConf, WhatAmI}, Result, }; use zenoh_util::LibSearchDirs; @@ -115,12 +115,12 @@ fn main() { }); } -fn config_from_args(args: &Args) -> Config { +fn config_from_args(args: &Args) -> InternalConfig { let mut config = args .config .as_ref() - .map_or_else(Config::default, |conf_file| { - Config::from_file(conf_file).unwrap() + .map_or_else(InternalConfig::default, |conf_file| { + InternalConfig::from_file(conf_file).unwrap() }); if config.mode().is_none() {