From fd0ca470bdfd499368a3e11d4f706b09b46b19a0 Mon Sep 17 00:00:00 2001 From: Michael Ilyin Date: Sat, 27 Apr 2024 21:48:16 +0200 Subject: [PATCH] moved api to sealed --- zenoh/src/lib.rs | 60 +++++- zenoh/src/prelude.rs | 4 +- zenoh/src/sealed/api/admin.rs | 16 +- zenoh/src/sealed/api/builders.rs | 4 +- zenoh/src/sealed/api/builders/publication.rs | 26 +-- zenoh/src/sealed/api/builders/sample.rs | 2 +- zenoh/src/sealed/api/handlers/mod.rs | 13 +- zenoh/src/sealed/api/info.rs | 8 +- zenoh/src/sealed/api/key_expr.rs | 10 +- zenoh/src/sealed/api/liveliness.rs | 33 ++-- zenoh/src/sealed/api/loader.rs | 6 +- zenoh/src/sealed/api/mod.rs | 42 ++-- zenoh/src/sealed/api/publication.rs | 50 ++--- zenoh/src/sealed/api/query.rs | 50 ++--- zenoh/src/sealed/api/queryable.rs | 61 +++--- zenoh/src/sealed/api/sample.rs | 48 ++--- zenoh/src/sealed/api/scouting.rs | 16 +- zenoh/src/sealed/api/selector.rs | 4 +- zenoh/src/sealed/api/session.rs | 115 +++++------ zenoh/src/sealed/api/subscriber.rs | 38 ++-- zenoh/src/sealed/api/value.rs | 4 +- zenoh/src/sealed/mod.rs | 4 +- zenoh/src/sealed/net/codec/mod.rs | 6 +- zenoh/src/sealed/net/mod.rs | 10 +- zenoh/src/sealed/net/primitives/demux.rs | 8 +- zenoh/src/sealed/net/primitives/mod.rs | 10 +- zenoh/src/sealed/net/primitives/mux.rs | 23 ++- zenoh/src/sealed/net/protocol/linkstate.rs | 28 +-- zenoh/src/sealed/net/protocol/mod.rs | 2 +- .../src/sealed/net/routing/dispatcher/face.rs | 55 +++--- .../src/sealed/net/routing/dispatcher/mod.rs | 10 +- .../sealed/net/routing/dispatcher/pubsub.rs | 29 ++- .../sealed/net/routing/dispatcher/queries.rs | 36 ++-- .../sealed/net/routing/dispatcher/resource.rs | 184 +++++++++++------- .../sealed/net/routing/dispatcher/tables.rs | 68 +++---- .../src/sealed/net/routing/hat/client/mod.rs | 2 +- .../net/routing/hat/linkstate_peer/mod.rs | 2 +- zenoh/src/sealed/net/routing/hat/mod.rs | 22 ++- .../sealed/net/routing/hat/p2p_peer/mod.rs | 2 +- .../src/sealed/net/routing/hat/router/mod.rs | 2 +- .../net/routing/interceptor/access_control.rs | 8 +- .../net/routing/interceptor/authorization.rs | 30 +-- .../net/routing/interceptor/downsampling.rs | 14 +- .../src/sealed/net/routing/interceptor/mod.rs | 34 ++-- zenoh/src/sealed/net/routing/mod.rs | 42 ++-- zenoh/src/sealed/net/routing/router.rs | 28 +-- zenoh/src/sealed/net/runtime/adminspace.rs | 11 +- zenoh/src/sealed/net/runtime/mod.rs | 25 ++- zenoh/src/sealed/net/runtime/orchestrator.rs | 19 +- zenoh/src/sealed/net/tests/mod.rs | 2 +- zenoh/src/sealed/net/tests/tables.rs | 6 +- zenoh/tests/session.rs | 1 + 52 files changed, 736 insertions(+), 597 deletions(-) diff --git a/zenoh/src/lib.rs b/zenoh/src/lib.rs index 37f76bfe1c..7569a845c0 100644 --- a/zenoh/src/lib.rs +++ b/zenoh/src/lib.rs @@ -177,6 +177,7 @@ pub mod key_expr { pub use zenoh_keyexpr::keyexpr_tree::{IKeyExprTree, IKeyExprTreeMut}; } pub use crate::sealed::api::key_expr::KeyExpr; + pub use crate::sealed::api::key_expr::KeyExprUndeclaration; pub use zenoh_keyexpr::keyexpr; pub use zenoh_keyexpr::OwnedKeyExpr; pub use zenoh_keyexpr::SetIntersectionLevel; @@ -198,24 +199,42 @@ pub mod session { #[doc(hidden)] pub use crate::sealed::api::session::init; pub use crate::sealed::api::session::open; + #[zenoh_macros::unstable] + #[doc(hidden)] + pub use crate::sealed::api::session::InitBuilder; + pub use crate::sealed::api::session::OpenBuilder; pub use crate::sealed::api::session::Session; pub use crate::sealed::api::session::SessionDeclarations; pub use crate::sealed::api::session::SessionRef; + pub use crate::sealed::api::session::Undeclarable; +} + +/// Tools to access information about the current zenoh [`Session`](crate::Session). +pub mod info { + pub use crate::sealed::api::info::PeersZidBuilder; + pub use crate::sealed::api::info::RoutersZidBuilder; + pub use crate::sealed::api::info::SessionInfo; + pub use crate::sealed::api::info::ZidBuilder; } /// Sample primitives pub mod sample { pub use crate::sealed::api::builders::sample::QoSBuilderTrait; pub use crate::sealed::api::builders::sample::SampleBuilder; + pub use crate::sealed::api::builders::sample::SampleBuilderAny; + pub use crate::sealed::api::builders::sample::SampleBuilderDelete; + pub use crate::sealed::api::builders::sample::SampleBuilderPut; pub use crate::sealed::api::builders::sample::SampleBuilderTrait; pub use crate::sealed::api::builders::sample::TimestampBuilderTrait; pub use crate::sealed::api::builders::sample::ValueBuilderTrait; #[zenoh_macros::unstable] pub use crate::sealed::api::sample::Locality; pub use crate::sealed::api::sample::Sample; + pub use crate::sealed::api::sample::SampleFields; pub use crate::sealed::api::sample::SampleKind; #[zenoh_macros::unstable] pub use crate::sealed::api::sample::SourceInfo; + pub use crate::sealed::api::sample::SourceSn; } /// Value primitives @@ -231,10 +250,14 @@ pub mod encoding { /// Payload primitives pub mod bytes { pub use crate::sealed::api::bytes::Deserialize; + pub use crate::sealed::api::bytes::OptionZBytes; pub use crate::sealed::api::bytes::Serialize; pub use crate::sealed::api::bytes::StringOrBase64; pub use crate::sealed::api::bytes::ZBytes; + pub use crate::sealed::api::bytes::ZBytesIterator; pub use crate::sealed::api::bytes::ZBytesReader; + pub use crate::sealed::api::bytes::ZBytesWriter; + pub use crate::sealed::api::bytes::ZDeserializeError; pub use crate::sealed::api::bytes::ZSerde; } @@ -258,18 +281,33 @@ pub mod subscriber { /// Publishing primitives pub mod publication { + pub use crate::sealed::api::builders::publication::PublicationBuilderDelete; + pub use crate::sealed::api::builders::publication::PublicationBuilderPut; pub use crate::sealed::api::builders::publication::PublisherBuilder; + pub use crate::sealed::api::builders::publication::PublisherDeleteBuilder; #[zenoh_macros::unstable] pub use crate::sealed::api::publication::MatchingListener; + #[zenoh_macros::unstable] + pub use crate::sealed::api::publication::MatchingListenerBuilder; + #[zenoh_macros::unstable] + pub use crate::sealed::api::publication::MatchingListenerState; + #[zenoh_macros::unstable] + pub use crate::sealed::api::publication::MatchingListenerUndeclaration; + #[zenoh_macros::unstable] + pub use crate::sealed::api::publication::MatchingStatus; pub use crate::sealed::api::publication::Priority; pub use crate::sealed::api::publication::Publisher; #[zenoh_macros::unstable] pub use crate::sealed::api::publication::PublisherDeclarations; + #[zenoh_macros::unstable] + pub use crate::sealed::api::publication::PublisherRef; + pub use crate::sealed::api::publication::PublisherUndeclaration; pub use zenoh_protocol::core::CongestionControl; } /// Query primitives pub mod query { + pub use crate::sealed::api::query::GetBuilder; pub use crate::sealed::api::query::Reply; #[zenoh_macros::unstable] pub use crate::sealed::api::query::ReplyKeyExpr; @@ -283,19 +321,31 @@ pub mod queryable { pub use crate::sealed::api::queryable::Query; pub use crate::sealed::api::queryable::Queryable; pub use crate::sealed::api::queryable::QueryableBuilder; + pub use crate::sealed::api::queryable::QueryableUndeclaration; + pub use crate::sealed::api::queryable::ReplyBuilder; + pub use crate::sealed::api::queryable::ReplyBuilderDelete; + pub use crate::sealed::api::queryable::ReplyBuilderPut; + pub use crate::sealed::api::queryable::ReplyErrBuilder; + #[zenoh_macros::unstable] + pub use crate::sealed::api::queryable::ReplySample; } /// Callback handler trait pub mod handlers { - pub use crate::sealed::api::handlers::locked; + pub use crate::sealed::api::handlers::callback::locked; + pub use crate::sealed::api::handlers::callback::Callback; + pub use crate::sealed::api::handlers::callback::CallbackDrop; + pub use crate::sealed::api::handlers::fifo::FifoChannel; + pub use crate::sealed::api::handlers::ring::RingChannel; + pub use crate::sealed::api::handlers::ring::RingChannelHandler; pub use crate::sealed::api::handlers::DefaultHandler; pub use crate::sealed::api::handlers::IntoHandler; - pub use crate::sealed::api::handlers::RingChannel; } /// Scouting primitives pub mod scouting { pub use crate::sealed::api::scouting::scout; + pub use crate::sealed::api::scouting::Scout; pub use crate::sealed::api::scouting::ScoutBuilder; /// Constants and helpers for zenoh `whatami` flags. pub use zenoh_protocol::core::WhatAmI; @@ -307,8 +357,11 @@ pub mod scouting { #[cfg(feature = "unstable")] pub mod liveliness { pub use crate::sealed::api::liveliness::Liveliness; + pub use crate::sealed::api::liveliness::LivelinessGetBuilder; pub use crate::sealed::api::liveliness::LivelinessSubscriberBuilder; pub use crate::sealed::api::liveliness::LivelinessToken; + pub use crate::sealed::api::liveliness::LivelinessTokenBuilder; + pub use crate::sealed::api::liveliness::LivelinessTokenUndeclaration; } /// Timestamp support @@ -322,7 +375,7 @@ pub mod time { #[doc(hidden)] pub mod runtime { pub use crate::sealed::net::runtime::RuntimeBuilder; - pub use crate::sealed::net::runtime::{AdminSpace, Runtime}; + pub use crate::sealed::net::runtime::{adminspace::AdminSpace, Runtime}; pub use zenoh_runtime::ZRuntime; } @@ -341,6 +394,7 @@ pub mod plugins { pub use crate::sealed::api::plugins::PluginsManager; pub use crate::sealed::api::plugins::Response; pub use crate::sealed::api::plugins::RunningPlugin; + pub use crate::sealed::api::plugins::PLUGIN_PREFIX; pub use crate::sealed::api::plugins::{RunningPluginTrait, ZenohPlugin}; } diff --git a/zenoh/src/prelude.rs b/zenoh/src/prelude.rs index 17286ddeea..8f7676c51f 100644 --- a/zenoh/src/prelude.rs +++ b/zenoh/src/prelude.rs @@ -36,7 +36,7 @@ //! ``` // Reexport API in flat namespace -pub(crate) mod flat { +pub mod flat { pub use crate::buffers::*; pub use crate::bytes::*; pub use crate::config::*; @@ -59,7 +59,7 @@ pub(crate) mod flat { } // Reexport API in hierarchical namespace -pub(crate) mod mods { +pub mod mods { pub use crate::buffers; pub use crate::bytes; pub use crate::config; diff --git a/zenoh/src/sealed/api/admin.rs b/zenoh/src/sealed/api/admin.rs index c221d7f27c..d4f44e83f6 100644 --- a/zenoh/src/sealed/api/admin.rs +++ b/zenoh/src/sealed/api/admin.rs @@ -45,7 +45,7 @@ lazy_static::lazy_static!( static ref KE_LINK: &'static keyexpr = ke_for_sure!("link"); ); -pub(crate) fn init(session: &Session) { +pub(in crate::sealed) fn init(session: &Session) { if let Ok(own_zid) = keyexpr::new(&session.zid().to_string()) { let admin_key = KeyExpr::from(*KE_PREFIX / own_zid / *KE_STARSTAR) .to_wire(session) @@ -63,7 +63,7 @@ pub(crate) fn init(session: &Session) { } } -pub(crate) fn on_admin_query(session: &Session, query: Query) { +pub(in crate::sealed) fn on_admin_query(session: &Session, query: Query) { fn reply_peer(own_zid: &keyexpr, query: &Query, peer: TransportPeer) { let zid = peer.zid.to_string(); if let Ok(zid) = keyexpr::new(&zid) { @@ -119,12 +119,12 @@ pub(crate) fn on_admin_query(session: &Session, query: Query) { } #[derive(Clone)] -pub(crate) struct Handler { - pub(crate) session: Arc, +pub(in crate::sealed) struct Handler { + pub(in crate::sealed) session: Arc, } impl Handler { - pub(crate) fn new(session: Session) -> Self { + pub(in crate::sealed) fn new(session: Session) -> Self { Self { session: Arc::new(session), } @@ -190,9 +190,9 @@ impl TransportMulticastEventHandler for Handler { } } -pub(crate) struct PeerHandler { - pub(crate) expr: WireExpr<'static>, - pub(crate) session: Arc, +pub(in crate::sealed) struct PeerHandler { + pub(in crate::sealed) expr: WireExpr<'static>, + pub(in crate::sealed) session: Arc, } impl TransportPeerEventHandler for PeerHandler { diff --git a/zenoh/src/sealed/api/builders.rs b/zenoh/src/sealed/api/builders.rs index 94dbda2dd0..e7fd26137e 100644 --- a/zenoh/src/sealed/api/builders.rs +++ b/zenoh/src/sealed/api/builders.rs @@ -12,5 +12,5 @@ // ZettaScale Zenoh Team, // -pub(crate) mod publication; -pub(crate) mod sample; +pub mod publication; +pub mod sample; diff --git a/zenoh/src/sealed/api/builders/publication.rs b/zenoh/src/sealed/api/builders/publication.rs index 9a83f8c983..feae0d5fc1 100644 --- a/zenoh/src/sealed/api/builders/publication.rs +++ b/zenoh/src/sealed/api/builders/publication.rs @@ -46,8 +46,8 @@ pub type PublisherDeleteBuilder<'a> = #[derive(Debug, Clone)] pub struct PublicationBuilderPut { - pub(crate) payload: ZBytes, - pub(crate) encoding: Encoding, + pub(in crate::sealed) payload: ZBytes, + pub(in crate::sealed) encoding: Encoding, } #[derive(Debug, Clone)] pub struct PublicationBuilderDelete; @@ -74,13 +74,13 @@ pub struct PublicationBuilderDelete; #[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"] #[derive(Debug, Clone)] pub struct PublicationBuilder { - pub(crate) publisher: P, - pub(crate) kind: T, - pub(crate) timestamp: Option, + pub(in crate::sealed) publisher: P, + pub(in crate::sealed) kind: T, + pub(in crate::sealed) timestamp: Option, #[cfg(feature = "unstable")] - pub(crate) source_info: SourceInfo, + pub(in crate::sealed) source_info: SourceInfo, #[cfg(feature = "unstable")] - pub(crate) attachment: Option, + pub(in crate::sealed) attachment: Option, } impl QoSBuilderTrait for PublicationBuilder, T> { @@ -251,12 +251,12 @@ impl AsyncResolve for PublicationBuilder, PublicationBu #[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"] #[derive(Debug)] pub struct PublisherBuilder<'a, 'b: 'a> { - pub(crate) session: SessionRef<'a>, - pub(crate) key_expr: ZResult>, - pub(crate) congestion_control: CongestionControl, - pub(crate) priority: Priority, - pub(crate) is_express: bool, - pub(crate) destination: Locality, + pub(in crate::sealed) session: SessionRef<'a>, + pub(in crate::sealed) key_expr: ZResult>, + pub(in crate::sealed) congestion_control: CongestionControl, + pub(in crate::sealed) priority: Priority, + pub(in crate::sealed) is_express: bool, + pub(in crate::sealed) destination: Locality, } impl<'a, 'b> Clone for PublisherBuilder<'a, 'b> { diff --git a/zenoh/src/sealed/api/builders/sample.rs b/zenoh/src/sealed/api/builders/sample.rs index dd3724ccf3..dfc9322fde 100644 --- a/zenoh/src/sealed/api/builders/sample.rs +++ b/zenoh/src/sealed/api/builders/sample.rs @@ -141,7 +141,7 @@ impl SampleBuilder { } // Allows to change qos as a whole of [`Sample`] - pub(crate) fn qos(self, qos: QoS) -> Self { + pub(in crate::sealed) fn qos(self, qos: QoS) -> Self { Self { sample: Sample { qos, ..self.sample }, _t: PhantomData::, diff --git a/zenoh/src/sealed/api/handlers/mod.rs b/zenoh/src/sealed/api/handlers/mod.rs index a51f319203..1b8f1cf107 100644 --- a/zenoh/src/sealed/api/handlers/mod.rs +++ b/zenoh/src/sealed/api/handlers/mod.rs @@ -13,18 +13,15 @@ // //! Callback handler trait. -mod callback; -mod fifo; -mod ring; - -pub use callback::*; -pub use fifo::*; -pub use ring::*; +pub mod callback; +pub mod fifo; +pub mod ring; +use self::{callback::Callback, fifo::FifoChannel}; use crate::sealed::api::session::API_DATA_RECEPTION_CHANNEL_SIZE; /// An alias for `Arc`. -pub type Dyn = std::sync::Arc; +pub(in crate::sealed) type Dyn = std::sync::Arc; /// A type that can be converted into a [`Callback`]-Handler pair. /// diff --git a/zenoh/src/sealed/api/info.rs b/zenoh/src/sealed/api/info.rs index dbcad9c50c..8c942060da 100644 --- a/zenoh/src/sealed/api/info.rs +++ b/zenoh/src/sealed/api/info.rs @@ -34,7 +34,7 @@ use zenoh_protocol::core::{WhatAmI, ZenohId}; #[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"] #[derive(Debug)] pub struct ZidBuilder<'a> { - pub(crate) session: SessionRef<'a>, + pub(in crate::sealed) session: SessionRef<'a>, } impl<'a> Resolvable for ZidBuilder<'a> { @@ -73,7 +73,7 @@ impl<'a> AsyncResolve for ZidBuilder<'a> { #[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"] #[derive(Debug)] pub struct RoutersZidBuilder<'a> { - pub(crate) session: SessionRef<'a>, + pub(in crate::sealed) session: SessionRef<'a>, } impl<'a> Resolvable for RoutersZidBuilder<'a> { @@ -122,7 +122,7 @@ impl<'a> AsyncResolve for RoutersZidBuilder<'a> { #[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"] #[derive(Debug)] pub struct PeersZidBuilder<'a> { - pub(crate) session: SessionRef<'a>, + pub(in crate::sealed) session: SessionRef<'a>, } impl<'a> Resolvable for PeersZidBuilder<'a> { @@ -168,7 +168,7 @@ impl<'a> AsyncResolve for PeersZidBuilder<'a> { /// # } /// ``` pub struct SessionInfo<'a> { - pub(crate) session: SessionRef<'a>, + pub(in crate::sealed) session: SessionRef<'a>, } impl SessionInfo<'_> { diff --git a/zenoh/src/sealed/api/key_expr.rs b/zenoh/src/sealed/api/key_expr.rs index 11eec28afc..4722ea7c1f 100644 --- a/zenoh/src/sealed/api/key_expr.rs +++ b/zenoh/src/sealed/api/key_expr.rs @@ -28,7 +28,7 @@ use zenoh_protocol::{ use zenoh_result::ZResult; #[derive(Clone, Debug)] -pub(crate) enum KeyExprInner<'a> { +pub(in crate::sealed) enum KeyExprInner<'a> { Borrowed(&'a keyexpr), BorrowedWire { key_expr: &'a keyexpr, @@ -54,7 +54,7 @@ pub(crate) enum KeyExprInner<'a> { #[derive(Clone, serde::Deserialize, serde::Serialize)] #[serde(from = "OwnedKeyExpr")] #[serde(into = "OwnedKeyExpr")] -pub struct KeyExpr<'a>(pub(crate) KeyExprInner<'a>); +pub struct KeyExpr<'a>(pub(in crate::sealed) KeyExprInner<'a>); impl std::ops::Deref for KeyExpr<'_> { type Target = keyexpr; fn deref(&self) -> &Self::Target { @@ -487,10 +487,10 @@ impl std::ops::Div<&keyexpr> for &KeyExpr<'_> { } impl<'a> KeyExpr<'a> { - //pub(crate) fn is_optimized(&self, session: &Session) -> bool { + //pub(in crate::sealed) fn is_optimized(&self, session: &Session) -> bool { // matches!(&self.0, KeyExprInner::Wire { expr_id, session_id, .. } | KeyExprInner::BorrowedWire { expr_id, session_id, .. } if *expr_id != 0 && session.id == *session_id) //} - pub(crate) fn is_fully_optimized(&self, session: &Session) -> bool { + pub(in crate::sealed) fn is_fully_optimized(&self, session: &Session) -> bool { match &self.0 { KeyExprInner::Wire { key_expr, @@ -507,7 +507,7 @@ impl<'a> KeyExpr<'a> { _ => false, } } - pub(crate) fn to_wire(&'a self, session: &Session) -> WireExpr<'a> { + pub(in crate::sealed) fn to_wire(&'a self, session: &Session) -> WireExpr<'a> { match &self.0 { KeyExprInner::Wire { key_expr, diff --git a/zenoh/src/sealed/api/liveliness.rs b/zenoh/src/sealed/api/liveliness.rs index 30b0c6edff..56621444b7 100644 --- a/zenoh/src/sealed/api/liveliness.rs +++ b/zenoh/src/sealed/api/liveliness.rs @@ -13,7 +13,7 @@ // use super::{ - handlers::{locked, DefaultHandler, IntoHandler}, + handlers::{callback::locked, DefaultHandler, IntoHandler}, key_expr::KeyExpr, query::{QueryConsolidation, QueryTarget, Reply}, sample::{Locality, Sample, SourceInfo}, @@ -29,11 +29,12 @@ use zenoh_keyexpr::keyexpr; use zenoh_protocol::network::{declare::subscriber::ext::SubscriberInfo, request}; #[zenoh_macros::unstable] -pub(crate) static PREFIX_LIVELINESS: &str = crate::sealed::net::routing::PREFIX_LIVELINESS; +pub(in crate::sealed) static PREFIX_LIVELINESS: &str = + crate::sealed::net::routing::PREFIX_LIVELINESS; #[zenoh_macros::unstable] lazy_static::lazy_static!( - pub(crate) static ref KE_PREFIX_LIVELINESS: &'static keyexpr = unsafe { keyexpr::from_str_unchecked(PREFIX_LIVELINESS) }; + pub(in crate::sealed) static ref KE_PREFIX_LIVELINESS: &'static keyexpr = unsafe { keyexpr::from_str_unchecked(PREFIX_LIVELINESS) }; ); /// A structure with functions to declare a @@ -68,7 +69,7 @@ lazy_static::lazy_static!( /// ``` #[zenoh_macros::unstable] pub struct Liveliness<'a> { - pub(crate) session: SessionRef<'a>, + pub(in crate::sealed) session: SessionRef<'a>, } #[zenoh_macros::unstable] @@ -212,8 +213,8 @@ impl<'a> Liveliness<'a> { #[zenoh_macros::unstable] #[derive(Debug)] pub struct LivelinessTokenBuilder<'a, 'b> { - pub(crate) session: SessionRef<'a>, - pub(crate) key_expr: ZResult>, + pub(in crate::sealed) session: SessionRef<'a>, + pub(in crate::sealed) key_expr: ZResult>, } #[zenoh_macros::unstable] @@ -248,9 +249,9 @@ impl AsyncResolve for LivelinessTokenBuilder<'_, '_> { #[zenoh_macros::unstable] #[derive(Debug)] -pub(crate) struct LivelinessTokenState { - pub(crate) id: Id, - pub(crate) key_expr: KeyExpr<'static>, +pub(in crate::sealed) struct LivelinessTokenState { + pub(in crate::sealed) id: Id, + pub(in crate::sealed) key_expr: KeyExpr<'static>, } /// A token whose liveliness is tied to the Zenoh [`Session`](Session) @@ -286,9 +287,9 @@ pub(crate) struct LivelinessTokenState { #[zenoh_macros::unstable] #[derive(Debug)] pub struct LivelinessToken<'a> { - pub(crate) session: SessionRef<'a>, - pub(crate) state: Arc, - pub(crate) alive: bool, + pub(in crate::sealed) session: SessionRef<'a>, + pub(in crate::sealed) state: Arc, + pub(in crate::sealed) alive: bool, } /// A [`Resolvable`] returned when undeclaring a [`LivelinessToken`](LivelinessToken). @@ -603,10 +604,10 @@ where #[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"] #[derive(Debug)] pub struct LivelinessGetBuilder<'a, 'b, Handler> { - pub(crate) session: &'a Session, - pub(crate) key_expr: ZResult>, - pub(crate) timeout: Duration, - pub(crate) handler: Handler, + pub(in crate::sealed) session: &'a Session, + pub(in crate::sealed) key_expr: ZResult>, + pub(in crate::sealed) timeout: Duration, + pub(in crate::sealed) handler: Handler, } impl<'a, 'b> LivelinessGetBuilder<'a, 'b, DefaultHandler> { diff --git a/zenoh/src/sealed/api/loader.rs b/zenoh/src/sealed/api/loader.rs index bd067aee80..91966e4eab 100644 --- a/zenoh/src/sealed/api/loader.rs +++ b/zenoh/src/sealed/api/loader.rs @@ -16,7 +16,7 @@ use crate::sealed::net::runtime::Runtime; use zenoh_config::{Config, PluginLoad}; use zenoh_result::ZResult; -pub(crate) fn load_plugin( +pub(in crate::sealed) fn load_plugin( plugin_mgr: &mut PluginsManager, name: &str, paths: &Option>, @@ -43,7 +43,7 @@ pub(crate) fn load_plugin( Ok(()) } -pub(crate) fn load_plugins(config: &Config) -> PluginsManager { +pub(in crate::sealed) fn load_plugins(config: &Config) -> 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() { @@ -67,7 +67,7 @@ pub(crate) fn load_plugins(config: &Config) -> PluginsManager { manager } -pub(crate) fn start_plugins(runtime: &Runtime) { +pub(in crate::sealed) fn start_plugins(runtime: &Runtime) { let mut manager = runtime.plugins_manager(); for plugin in manager.loaded_plugins_iter_mut() { let required = plugin.required(); diff --git a/zenoh/src/sealed/api/mod.rs b/zenoh/src/sealed/api/mod.rs index 694890ad6c..9a46db20e0 100644 --- a/zenoh/src/sealed/api/mod.rs +++ b/zenoh/src/sealed/api/mod.rs @@ -12,28 +12,28 @@ // ZettaScale Zenoh Team, // -pub(crate) type Id = u32; +pub type Id = u32; -pub(crate) mod admin; -pub(crate) mod builders; -pub(crate) mod bytes; -pub(crate) mod encoding; -pub(crate) mod handlers; -pub(crate) mod info; -pub(crate) mod key_expr; +pub mod admin; +pub mod builders; +pub mod bytes; +pub mod encoding; +pub mod handlers; +pub mod info; +pub mod key_expr; #[cfg(feature = "unstable")] -pub(crate) mod liveliness; +pub mod liveliness; #[cfg(all(feature = "unstable", feature = "plugins"))] -pub(crate) mod loader; +pub mod loader; #[cfg(all(feature = "unstable", feature = "plugins"))] -pub(crate) mod plugins; -pub(crate) mod publication; -pub(crate) mod query; -pub(crate) mod queryable; -pub(crate) mod sample; -pub(crate) mod scouting; -pub(crate) mod selector; -pub(crate) mod session; -pub(crate) mod subscriber; -pub(crate) mod time; -pub(crate) mod value; +pub mod plugins; +pub mod publication; +pub mod query; +pub mod queryable; +pub mod sample; +pub mod scouting; +pub mod selector; +pub mod session; +pub mod subscriber; +pub mod time; +pub mod value; diff --git a/zenoh/src/sealed/api/publication.rs b/zenoh/src/sealed/api/publication.rs index ab262cc28b..f136f148c2 100644 --- a/zenoh/src/sealed/api/publication.rs +++ b/zenoh/src/sealed/api/publication.rs @@ -42,7 +42,7 @@ use zenoh_result::{Error, ZResult}; #[zenoh_macros::unstable] use { - super::handlers::{Callback, DefaultHandler, IntoHandler}, + super::handlers::{callback::locked, callback::Callback, DefaultHandler, IntoHandler}, super::sample::SourceInfo, super::Id, zenoh_protocol::core::EntityGlobalId, @@ -111,14 +111,14 @@ impl std::fmt::Debug for PublisherRef<'_> { /// ``` #[derive(Debug, Clone)] pub struct Publisher<'a> { - pub(crate) session: SessionRef<'a>, + pub(in crate::sealed) session: SessionRef<'a>, #[cfg(feature = "unstable")] - pub(crate) eid: EntityId, - pub(crate) key_expr: KeyExpr<'a>, - pub(crate) congestion_control: CongestionControl, - pub(crate) priority: Priority, - pub(crate) is_express: bool, - pub(crate) destination: Locality, + pub(in crate::sealed) eid: EntityId, + pub(in crate::sealed) key_expr: KeyExpr<'a>, + pub(in crate::sealed) congestion_control: CongestionControl, + pub(in crate::sealed) priority: Priority, + pub(in crate::sealed) is_express: bool, + pub(in crate::sealed) destination: Locality, } impl<'a> Publisher<'a> { @@ -531,7 +531,7 @@ impl<'a> Sink for Publisher<'a> { } impl Publisher<'_> { - pub(crate) fn resolve_put( + pub fn resolve_put( &self, payload: ZBytes, kind: SampleKind, @@ -736,7 +736,7 @@ impl TryFrom for Priority { #[zenoh_macros::unstable] #[derive(Copy, Clone, Debug)] pub struct MatchingStatus { - pub(crate) matching: bool, + pub(in crate::sealed) matching: bool, } #[zenoh_macros::unstable] @@ -768,8 +768,8 @@ impl MatchingStatus { #[zenoh_macros::unstable] #[derive(Debug)] pub struct MatchingListenerBuilder<'a, Handler> { - pub(crate) publisher: PublisherRef<'a>, - pub handler: Handler, + pub(in crate::sealed) publisher: PublisherRef<'a>, + pub(in crate::sealed) handler: Handler, } #[zenoh_macros::unstable] @@ -842,7 +842,7 @@ impl<'a> MatchingListenerBuilder<'a, DefaultHandler> { where CallbackMut: FnMut(MatchingStatus) + Send + Sync + 'static, { - self.callback(super::handlers::locked(callback)) + self.callback(locked(callback)) } /// Receive the MatchingStatuses for this listener with a [`Handler`](crate::prelude::IntoHandler). @@ -931,12 +931,12 @@ where } #[zenoh_macros::unstable] -pub(crate) struct MatchingListenerState { - pub(crate) id: Id, - pub(crate) current: std::sync::Mutex, - pub(crate) key_expr: KeyExpr<'static>, - pub(crate) destination: Locality, - pub(crate) callback: Callback<'static, MatchingStatus>, +pub struct MatchingListenerState { + pub(in crate::sealed) id: Id, + pub(in crate::sealed) current: std::sync::Mutex, + pub(in crate::sealed) key_expr: KeyExpr<'static>, + pub(in crate::sealed) destination: Locality, + pub(in crate::sealed) callback: Callback<'static, MatchingStatus>, } #[zenoh_macros::unstable] @@ -950,10 +950,10 @@ impl std::fmt::Debug for MatchingListenerState { } #[zenoh_macros::unstable] -pub(crate) struct MatchingListenerInner<'a> { - pub(crate) publisher: PublisherRef<'a>, - pub(crate) state: std::sync::Arc, - pub(crate) alive: bool, +pub(in crate::sealed) struct MatchingListenerInner<'a> { + pub(in crate::sealed) publisher: PublisherRef<'a>, + pub(in crate::sealed) state: std::sync::Arc, + pub(in crate::sealed) alive: bool, } #[zenoh_macros::unstable] @@ -994,8 +994,8 @@ impl<'a> Undeclarable<(), MatchingListenerUndeclaration<'a>> for MatchingListene /// ``` #[zenoh_macros::unstable] pub struct MatchingListener<'a, Receiver> { - pub(crate) listener: MatchingListenerInner<'a>, - pub(crate) receiver: Receiver, + pub(in crate::sealed) listener: MatchingListenerInner<'a>, + pub(in crate::sealed) receiver: Receiver, } #[zenoh_macros::unstable] diff --git a/zenoh/src/sealed/api/query.rs b/zenoh/src/sealed/api/query.rs index 1cb4078ee6..f3ff4341c5 100644 --- a/zenoh/src/sealed/api/query.rs +++ b/zenoh/src/sealed/api/query.rs @@ -16,7 +16,7 @@ use super::{ builders::sample::{QoSBuilderTrait, ValueBuilderTrait}, bytes::ZBytes, encoding::Encoding, - handlers::{locked, Callback, DefaultHandler, IntoHandler}, + handlers::{callback::locked, callback::Callback, DefaultHandler, IntoHandler}, key_expr::KeyExpr, publication::Priority, sample::{Locality, QoSBuilder, Sample}, @@ -42,7 +42,7 @@ pub type ConsolidationMode = zenoh_protocol::zenoh::query::Consolidation; /// The replies consolidation strategy to apply on replies to a [`get`](Session::get). #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct QueryConsolidation { - pub(crate) mode: ConsolidationMode, + pub(in crate::sealed) mode: ConsolidationMode, } impl QueryConsolidation { @@ -52,7 +52,7 @@ impl QueryConsolidation { mode: ConsolidationMode::Auto, }; - pub(crate) const fn from_mode(mode: ConsolidationMode) -> Self { + pub(in crate::sealed) const fn from_mode(mode: ConsolidationMode) -> Self { Self { mode } } @@ -78,8 +78,8 @@ impl Default for QueryConsolidation { #[non_exhaustive] #[derive(Clone, Debug)] pub struct Reply { - pub(crate) result: Result, - pub(crate) replier_id: ZenohId, + pub(in crate::sealed) result: Result, + pub(in crate::sealed) replier_id: ZenohId, } impl Reply { @@ -105,13 +105,13 @@ impl From for Result { } } -pub(crate) struct QueryState { - pub(crate) nb_final: usize, - pub(crate) selector: Selector<'static>, - pub(crate) scope: Option>, - pub(crate) reception_mode: ConsolidationMode, - pub(crate) replies: Option>, - pub(crate) callback: Callback<'static, Reply>, +pub(in crate::sealed) struct QueryState { + pub(in crate::sealed) nb_final: usize, + pub(in crate::sealed) selector: Selector<'static>, + pub(in crate::sealed) scope: Option>, + pub(in crate::sealed) reception_mode: ConsolidationMode, + pub(in crate::sealed) replies: Option>, + pub(in crate::sealed) callback: Callback<'static, Reply>, } /// A builder for initializing a `query`. @@ -138,20 +138,20 @@ pub(crate) struct QueryState { #[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"] #[derive(Debug)] pub struct GetBuilder<'a, 'b, Handler> { - pub(crate) session: &'a Session, - pub(crate) selector: ZResult>, - pub(crate) scope: ZResult>>, - pub(crate) target: QueryTarget, - pub(crate) consolidation: QueryConsolidation, - pub(crate) qos: QoSBuilder, - pub(crate) destination: Locality, - pub(crate) timeout: Duration, - pub(crate) handler: Handler, - pub(crate) value: Option, + pub(in crate::sealed) session: &'a Session, + pub(in crate::sealed) selector: ZResult>, + pub(in crate::sealed) scope: ZResult>>, + pub(in crate::sealed) target: QueryTarget, + pub(in crate::sealed) consolidation: QueryConsolidation, + pub(in crate::sealed) qos: QoSBuilder, + pub(in crate::sealed) destination: Locality, + pub(in crate::sealed) timeout: Duration, + pub(in crate::sealed) handler: Handler, + pub(in crate::sealed) value: Option, #[cfg(feature = "unstable")] - pub(crate) attachment: Option, + pub(in crate::sealed) attachment: Option, #[cfg(feature = "unstable")] - pub(crate) source_info: SourceInfo, + pub(in crate::sealed) source_info: SourceInfo, } #[zenoh_macros::unstable] @@ -418,7 +418,7 @@ impl<'a, 'b, Handler> GetBuilder<'a, 'b, Handler> { } } -pub(crate) const _REPLY_KEY_EXPR_ANY_SEL_PARAM: &str = "_anyke"; +pub(in crate::sealed) const _REPLY_KEY_EXPR_ANY_SEL_PARAM: &str = "_anyke"; #[zenoh_macros::unstable] pub const REPLY_KEY_EXPR_ANY_SEL_PARAM: &str = _REPLY_KEY_EXPR_ANY_SEL_PARAM; diff --git a/zenoh/src/sealed/api/queryable.rs b/zenoh/src/sealed/api/queryable.rs index 8846415105..909c07a522 100644 --- a/zenoh/src/sealed/api/queryable.rs +++ b/zenoh/src/sealed/api/queryable.rs @@ -15,7 +15,7 @@ use super::{ builders::sample::{QoSBuilderTrait, SampleBuilder, TimestampBuilderTrait, ValueBuilderTrait}, bytes::ZBytes, encoding::Encoding, - handlers::{locked, DefaultHandler, IntoHandler}, + handlers::{callback::locked, DefaultHandler, IntoHandler}, key_expr::KeyExpr, publication::Priority, sample::{Locality, QoSBuilder, Sample, SampleKind}, @@ -49,19 +49,19 @@ use { zenoh_protocol::core::EntityGlobalId, }; -pub(crate) struct QueryInner { +pub(in crate::sealed) struct QueryInner { /// The key expression of this Query. - pub(crate) key_expr: KeyExpr<'static>, + pub(in crate::sealed) key_expr: KeyExpr<'static>, /// This Query's selector parameters. - pub(crate) parameters: Parameters<'static>, + pub(in crate::sealed) parameters: Parameters<'static>, /// This Query's body. - pub(crate) value: Option, + pub(in crate::sealed) value: Option, - pub(crate) qid: RequestId, - pub(crate) zid: ZenohId, - pub(crate) primitives: Arc, + pub(in crate::sealed) qid: RequestId, + pub(in crate::sealed) zid: ZenohId, + pub(in crate::sealed) primitives: Arc, #[cfg(feature = "unstable")] - pub(crate) attachment: Option, + pub(in crate::sealed) attachment: Option, } impl Drop for QueryInner { @@ -77,8 +77,8 @@ impl Drop for QueryInner { /// Structs received by a [`Queryable`]. #[derive(Clone)] pub struct Query { - pub(crate) inner: Arc, - pub(crate) eid: EntityId, + pub(in crate::sealed) inner: Arc, + pub(in crate::sealed) eid: EntityId, } impl Query { @@ -256,21 +256,26 @@ impl fmt::Display for Query { } } +#[cfg(feature = "unstable")] +#[doc(hidden)] pub struct ReplySample<'a> { query: &'a Query, sample: Sample, } +#[cfg(feature = "unstable")] impl Resolvable for ReplySample<'_> { type To = ZResult<()>; } +#[cfg(feature = "unstable")] impl SyncResolve for ReplySample<'_> { fn res_sync(self) -> ::To { self.query._reply_sample(self.sample) } } +#[cfg(feature = "unstable")] impl AsyncResolve for ReplySample<'_> { type Future = Ready; @@ -557,12 +562,12 @@ impl<'a> AsyncResolve for ReplyErrBuilder<'a> { } } -pub(crate) struct QueryableState { - pub(crate) id: Id, - pub(crate) key_expr: WireExpr<'static>, - pub(crate) complete: bool, - pub(crate) origin: Locality, - pub(crate) callback: Arc, +pub(in crate::sealed) struct QueryableState { + pub(in crate::sealed) id: Id, + pub(in crate::sealed) key_expr: WireExpr<'static>, + pub(in crate::sealed) complete: bool, + pub(in crate::sealed) origin: Locality, + pub(in crate::sealed) callback: Arc, } impl fmt::Debug for QueryableState { @@ -603,10 +608,10 @@ impl fmt::Debug for QueryableState { /// # } /// ``` #[derive(Debug)] -pub(crate) struct CallbackQueryable<'a> { - pub(crate) session: SessionRef<'a>, - pub(crate) state: Arc, - pub(crate) alive: bool, +pub(in crate::sealed) struct CallbackQueryable<'a> { + pub(in crate::sealed) session: SessionRef<'a>, + pub(in crate::sealed) state: Arc, + pub(in crate::sealed) alive: bool, } impl<'a> Undeclarable<(), QueryableUndeclaration<'a>> for CallbackQueryable<'a> { @@ -677,11 +682,11 @@ impl Drop for CallbackQueryable<'_> { #[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"] #[derive(Debug)] pub struct QueryableBuilder<'a, 'b, Handler> { - pub(crate) session: SessionRef<'a>, - pub(crate) key_expr: ZResult>, - pub(crate) complete: bool, - pub(crate) origin: Locality, - pub(crate) handler: Handler, + pub(in crate::sealed) session: SessionRef<'a>, + pub(in crate::sealed) key_expr: ZResult>, + pub(in crate::sealed) complete: bool, + pub(in crate::sealed) origin: Locality, + pub(in crate::sealed) handler: Handler, } impl<'a, 'b> QueryableBuilder<'a, 'b, DefaultHandler> { @@ -848,8 +853,8 @@ impl<'a, 'b, Handler> QueryableBuilder<'a, 'b, Handler> { #[non_exhaustive] #[derive(Debug)] pub struct Queryable<'a, Handler> { - pub(crate) queryable: CallbackQueryable<'a>, - pub(crate) handler: Handler, + pub(in crate::sealed) queryable: CallbackQueryable<'a>, + pub(in crate::sealed) handler: Handler, } impl<'a, Handler> Queryable<'a, Handler> { diff --git a/zenoh/src/sealed/api/sample.rs b/zenoh/src/sealed/api/sample.rs index e5e386fdb0..7cae21bbe1 100644 --- a/zenoh/src/sealed/api/sample.rs +++ b/zenoh/src/sealed/api/sample.rs @@ -38,7 +38,7 @@ pub enum Locality { } #[cfg(not(feature = "unstable"))] #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] -pub(crate) enum Locality { +pub(in crate::sealed) enum Locality { SessionLocal, Remote, #[default] @@ -46,16 +46,16 @@ pub(crate) enum Locality { } #[derive(Debug, Clone, PartialEq, Eq, Default)] -pub(crate) struct DataInfo { - pub kind: SampleKind, - pub encoding: Option, - pub timestamp: Option, - pub source_id: Option, - pub source_sn: Option, - pub qos: QoS, +pub(in crate::sealed) struct DataInfo { + pub(in crate::sealed) kind: SampleKind, + pub(in crate::sealed) encoding: Option, + pub(in crate::sealed) timestamp: Option, + pub(in crate::sealed) source_id: Option, + pub(in crate::sealed) source_sn: Option, + pub(in crate::sealed) qos: QoS, } -pub(crate) trait DataInfoIntoSample { +pub(in crate::sealed) trait DataInfoIntoSample { fn into_sample( self, key_expr: IntoKeyExpr, @@ -161,13 +161,13 @@ fn source_info_stack_size() { #[zenoh_macros::unstable] impl SourceInfo { - pub(crate) fn empty() -> Self { + pub(in crate::sealed) fn empty() -> Self { SourceInfo { source_id: None, source_sn: None, } } - pub(crate) fn is_empty(&self) -> bool { + pub(in crate::sealed) fn is_empty(&self) -> bool { self.source_id.is_none() && self.source_sn.is_none() } } @@ -276,18 +276,18 @@ impl From for SampleFields { #[non_exhaustive] #[derive(Clone, Debug)] pub struct Sample { - pub(crate) key_expr: KeyExpr<'static>, - pub(crate) payload: ZBytes, - pub(crate) kind: SampleKind, - pub(crate) encoding: Encoding, - pub(crate) timestamp: Option, - pub(crate) qos: QoS, + pub(in crate::sealed) key_expr: KeyExpr<'static>, + pub(in crate::sealed) payload: ZBytes, + pub(in crate::sealed) kind: SampleKind, + pub(in crate::sealed) encoding: Encoding, + pub(in crate::sealed) timestamp: Option, + pub(in crate::sealed) qos: QoS, #[cfg(feature = "unstable")] - pub(crate) source_info: SourceInfo, + pub(in crate::sealed) source_info: SourceInfo, #[cfg(feature = "unstable")] - pub(crate) attachment: Option, + pub(in crate::sealed) attachment: Option, } impl Sample { @@ -359,12 +359,12 @@ impl From for Value { /// Structure containing quality of service data #[derive(Debug, Default, Copy, Clone, Eq, PartialEq)] -pub(crate) struct QoS { +pub(in crate::sealed) struct QoS { inner: QoSType, } #[derive(Debug)] -pub(crate) struct QoSBuilder(QoS); +pub(in crate::sealed) struct QoSBuilder(QoS); impl From for QoSBuilder { fn from(qos: QoS) -> Self { @@ -406,7 +406,7 @@ impl QoSBuilderTrait for QoSBuilder { impl QoS { /// Gets priority of the message. - pub fn priority(&self) -> Priority { + pub(in crate::sealed) fn priority(&self) -> Priority { match Priority::try_from(self.inner.get_priority()) { Ok(p) => p, Err(e) => { @@ -420,12 +420,12 @@ impl QoS { } /// Gets congestion control of the message. - pub fn congestion_control(&self) -> CongestionControl { + pub(in crate::sealed) fn congestion_control(&self) -> CongestionControl { self.inner.get_congestion_control() } /// Gets express flag value. If `true`, the message is not batched during transmission, in order to reduce latency. - pub fn express(&self) -> bool { + pub(in crate::sealed) fn express(&self) -> bool { self.inner.is_express() } } diff --git a/zenoh/src/sealed/api/scouting.rs b/zenoh/src/sealed/api/scouting.rs index be7432664d..dce6c77d22 100644 --- a/zenoh/src/sealed/api/scouting.rs +++ b/zenoh/src/sealed/api/scouting.rs @@ -11,7 +11,7 @@ // Contributors: // ZettaScale Zenoh Team, // -use super::handlers::{locked, Callback, DefaultHandler, IntoHandler}; +use super::handlers::{callback::locked, callback::Callback, DefaultHandler, IntoHandler}; use crate::sealed::net::runtime::{orchestrator::Loop, Runtime}; use std::time::Duration; use std::{fmt, future::Ready, net::SocketAddr, ops::Deref}; @@ -41,9 +41,9 @@ use zenoh_task::TerminatableTask; #[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"] #[derive(Debug)] pub struct ScoutBuilder { - pub(crate) what: WhatAmIMatcher, - pub(crate) config: ZResult, - pub(crate) handler: Handler, + pub(in crate::sealed) what: WhatAmIMatcher, + pub(in crate::sealed) config: ZResult, + pub(in crate::sealed) handler: Handler, } impl ScoutBuilder { @@ -191,9 +191,9 @@ where /// .unwrap(); /// # } /// ``` -pub(crate) struct ScoutInner { +pub(in crate::sealed) struct ScoutInner { #[allow(dead_code)] - pub(crate) scout_task: Option, + pub(in crate::sealed) scout_task: Option, } impl ScoutInner { @@ -254,8 +254,8 @@ impl fmt::Debug for ScoutInner { #[non_exhaustive] #[derive(Debug)] pub struct Scout { - pub(crate) scout: ScoutInner, - pub(crate) receiver: Receiver, + pub(in crate::sealed) scout: ScoutInner, + pub(in crate::sealed) receiver: Receiver, } impl Deref for Scout { diff --git a/zenoh/src/sealed/api/selector.rs b/zenoh/src/sealed/api/selector.rs index 11f74c18ed..7d38942b43 100644 --- a/zenoh/src/sealed/api/selector.rs +++ b/zenoh/src/sealed/api/selector.rs @@ -66,9 +66,9 @@ use zenoh_util::time_range::TimeRange; #[derive(Clone, PartialEq, Eq)] pub struct Selector<'a> { /// The part of this selector identifying which keys should be part of the selection. - pub(crate) key_expr: KeyExpr<'a>, + pub(in crate::sealed) key_expr: KeyExpr<'a>, /// the part of this selector identifying which values should be part of the selection. - pub(crate) parameters: Parameters<'a>, + pub(in crate::sealed) parameters: Parameters<'a>, } pub const TIME_RANGE_KEY: &str = "_time"; diff --git a/zenoh/src/sealed/api/session.rs b/zenoh/src/sealed/api/session.rs index 23e48dda9c..b7a2dc9f10 100644 --- a/zenoh/src/sealed/api/session.rs +++ b/zenoh/src/sealed/api/session.rs @@ -19,7 +19,7 @@ use super::{ }, bytes::ZBytes, encoding::Encoding, - handlers::{Callback, DefaultHandler}, + handlers::{callback::Callback, DefaultHandler}, info::SessionInfo, key_expr::{KeyExpr, KeyExprInner}, publication::Priority, @@ -92,35 +92,35 @@ use super::{ }; zconfigurable! { - pub(crate) static ref API_DATA_RECEPTION_CHANNEL_SIZE: usize = 256; - pub(crate) static ref API_QUERY_RECEPTION_CHANNEL_SIZE: usize = 256; - pub(crate) static ref API_REPLY_EMISSION_CHANNEL_SIZE: usize = 256; - pub(crate) static ref API_REPLY_RECEPTION_CHANNEL_SIZE: usize = 256; - pub(crate) static ref API_OPEN_SESSION_DELAY: u64 = 500; + pub(in crate::sealed) static ref API_DATA_RECEPTION_CHANNEL_SIZE: usize = 256; + pub(in crate::sealed) static ref API_QUERY_RECEPTION_CHANNEL_SIZE: usize = 256; + pub(in crate::sealed) static ref API_REPLY_EMISSION_CHANNEL_SIZE: usize = 256; + pub(in crate::sealed) static ref API_REPLY_RECEPTION_CHANNEL_SIZE: usize = 256; + pub(in crate::sealed) static ref API_OPEN_SESSION_DELAY: u64 = 500; } -pub(crate) struct SessionState { - pub(crate) primitives: Option>, // @TODO replace with MaybeUninit ?? - pub(crate) expr_id_counter: AtomicExprId, // @TODO: manage rollover and uniqueness - pub(crate) qid_counter: AtomicRequestId, - pub(crate) local_resources: HashMap, - pub(crate) remote_resources: HashMap, +pub(in crate::sealed) struct SessionState { + pub(in crate::sealed) primitives: Option>, // @TODO replace with MaybeUninit ?? + pub(in crate::sealed) expr_id_counter: AtomicExprId, // @TODO: manage rollover and uniqueness + pub(in crate::sealed) qid_counter: AtomicRequestId, + pub(in crate::sealed) local_resources: HashMap, + pub(in crate::sealed) remote_resources: HashMap, #[cfg(feature = "unstable")] - pub(crate) remote_subscribers: HashMap>, - //pub(crate) publications: Vec, - pub(crate) subscribers: HashMap>, - pub(crate) queryables: HashMap>, + pub(in crate::sealed) remote_subscribers: HashMap>, + //pub(in crate::sealed) publications: Vec, + pub(in crate::sealed) subscribers: HashMap>, + pub(in crate::sealed) queryables: HashMap>, #[cfg(feature = "unstable")] - pub(crate) tokens: HashMap>, + pub(in crate::sealed) tokens: HashMap>, #[cfg(feature = "unstable")] - pub(crate) matching_listeners: HashMap>, - pub(crate) queries: HashMap, - pub(crate) aggregated_subscribers: Vec, - //pub(crate) aggregated_publishers: Vec, + pub(in crate::sealed) matching_listeners: HashMap>, + pub(in crate::sealed) queries: HashMap, + pub(in crate::sealed) aggregated_subscribers: Vec, + //pub(in crate::sealed) aggregated_publishers: Vec, } impl SessionState { - pub(crate) fn new( + pub(in crate::sealed) fn new( aggregated_subscribers: Vec, _aggregated_publishers: Vec, ) -> SessionState { @@ -169,7 +169,10 @@ impl SessionState { } } - pub(crate) fn remote_key_to_expr<'a>(&'a self, key_expr: &'a WireExpr) -> ZResult> { + pub(in crate::sealed) fn remote_key_to_expr<'a>( + &'a self, + key_expr: &'a WireExpr, + ) -> ZResult> { if key_expr.scope == EMPTY_EXPR_ID { Ok(unsafe { keyexpr::from_str_unchecked(key_expr.suffix.as_ref()) }.into()) } else if key_expr.suffix.is_empty() { @@ -197,7 +200,7 @@ impl SessionState { } } - pub(crate) fn local_wireexpr_to_expr<'a>( + pub(in crate::sealed) fn local_wireexpr_to_expr<'a>( &'a self, key_expr: &'a WireExpr, ) -> ZResult> { @@ -228,7 +231,7 @@ impl SessionState { } } - pub(crate) fn wireexpr_to_keyexpr<'a>( + pub(in crate::sealed) fn wireexpr_to_keyexpr<'a>( &'a self, key_expr: &'a WireExpr, local: bool, @@ -251,36 +254,36 @@ impl fmt::Debug for SessionState { } } -pub(crate) struct ResourceNode { - pub(crate) key_expr: OwnedKeyExpr, - pub(crate) subscribers: Vec>, +pub(in crate::sealed) struct ResourceNode { + pub(in crate::sealed) key_expr: OwnedKeyExpr, + pub(in crate::sealed) subscribers: Vec>, } -pub(crate) enum Resource { +pub(in crate::sealed) enum Resource { Prefix { prefix: Box }, Node(ResourceNode), } impl Resource { - pub(crate) fn new(name: Box) -> Self { + pub(in crate::sealed) fn new(name: Box) -> Self { if keyexpr::new(name.as_ref()).is_ok() { Self::for_keyexpr(unsafe { OwnedKeyExpr::from_boxed_string_unchecked(name) }) } else { Self::Prefix { prefix: name } } } - pub(crate) fn for_keyexpr(key_expr: OwnedKeyExpr) -> Self { + pub(in crate::sealed) fn for_keyexpr(key_expr: OwnedKeyExpr) -> Self { Self::Node(ResourceNode { key_expr, subscribers: Vec::new(), }) } - pub(crate) fn name(&self) -> &str { + pub(in crate::sealed) fn name(&self) -> &str { match self { Resource::Prefix { prefix } => prefix.as_ref(), Resource::Node(ResourceNode { key_expr, .. }) => key_expr.as_str(), } } - pub(crate) fn as_node_mut(&mut self) -> Option<&mut ResourceNode> { + pub(in crate::sealed) fn as_node_mut(&mut self) -> Option<&mut ResourceNode> { match self { Resource::Prefix { .. } => None, Resource::Node(node) => Some(node), @@ -398,17 +401,17 @@ where /// A zenoh session. /// pub struct Session { - pub(crate) runtime: Runtime, - pub(crate) state: Arc>, - pub(crate) id: u16, - pub(crate) alive: bool, + pub(in crate::sealed) runtime: Runtime, + pub(in crate::sealed) state: Arc>, + pub(in crate::sealed) id: u16, + pub(in crate::sealed) alive: bool, owns_runtime: bool, task_controller: TaskController, } static SESSION_ID_COUNTER: AtomicU16 = AtomicU16::new(0); impl Session { - pub(crate) fn init( + pub fn init( runtime: Runtime, aggregated_subscribers: Vec, aggregated_publishers: Vec, @@ -826,7 +829,7 @@ impl Session { } impl Session { - pub(crate) fn clone(&self) -> Self { + pub(in crate::sealed) fn clone(&self) -> Self { Session { runtime: self.runtime.clone(), state: self.state.clone(), @@ -870,7 +873,7 @@ impl Session { }) } - pub(crate) fn declare_prefix<'a>(&'a self, prefix: &'a str) -> impl Resolve + 'a { + pub fn declare_prefix<'a>(&'a self, prefix: &'a str) -> impl Resolve + 'a { ResolveClosure::new(move || { trace!("declare_prefix({:?})", prefix); let mut state = zwrite!(self.state); @@ -926,7 +929,7 @@ impl Session { /// # Arguments /// /// * `key_expr` - The key expression to publish - pub(crate) fn declare_publication_intent<'a>( + pub(in crate::sealed) fn declare_publication_intent<'a>( &'a self, _key_expr: KeyExpr<'a>, ) -> impl Resolve> + 'a { @@ -962,7 +965,7 @@ impl Session { /// # Arguments /// /// * `key_expr` - The key expression of the publication to undeclarte - pub(crate) fn undeclare_publication_intent<'a>( + pub(in crate::sealed) fn undeclare_publication_intent<'a>( &'a self, _key_expr: KeyExpr<'a>, ) -> impl Resolve> + 'a { @@ -998,7 +1001,7 @@ impl Session { }) } - pub(crate) fn declare_subscriber_inner( + pub(in crate::sealed) fn declare_subscriber_inner( &self, key_expr: &KeyExpr, scope: &Option, @@ -1133,7 +1136,7 @@ impl Session { Ok(sub_state) } - pub(crate) fn unsubscribe(&self, sid: Id) -> ZResult<()> { + pub(in crate::sealed) fn unsubscribe(&self, sid: Id) -> ZResult<()> { let mut state = zwrite!(self.state); if let Some(sub_state) = state.subscribers.remove(&sid) { trace!("unsubscribe({:?})", sub_state); @@ -1193,7 +1196,7 @@ impl Session { } } - pub(crate) fn declare_queryable_inner( + pub(in crate::sealed) fn declare_queryable_inner( &self, key_expr: &WireExpr, complete: bool, @@ -1235,7 +1238,7 @@ impl Session { Ok(qable_state) } - pub(crate) fn close_queryable(&self, qid: Id) -> ZResult<()> { + pub(in crate::sealed) fn close_queryable(&self, qid: Id) -> ZResult<()> { let mut state = zwrite!(self.state); if let Some(qable_state) = state.queryables.remove(&qid) { trace!("close_queryable({:?})", qable_state); @@ -1262,7 +1265,7 @@ impl Session { } #[zenoh_macros::unstable] - pub(crate) fn declare_liveliness_inner( + pub(in crate::sealed) fn declare_liveliness_inner( &self, key_expr: &KeyExpr, ) -> ZResult> { @@ -1293,7 +1296,7 @@ impl Session { } #[zenoh_macros::unstable] - pub(crate) fn undeclare_liveliness(&self, tid: Id) -> ZResult<()> { + pub(in crate::sealed) fn undeclare_liveliness(&self, tid: Id) -> ZResult<()> { let mut state = zwrite!(self.state); if let Some(tok_state) = state.tokens.remove(&tid) { trace!("undeclare_liveliness({:?})", tok_state); @@ -1321,7 +1324,7 @@ impl Session { } #[zenoh_macros::unstable] - pub(crate) fn declare_matches_listener_inner( + pub(in crate::sealed) fn declare_matches_listener_inner( &self, publisher: &Publisher, callback: Callback<'static, MatchingStatus>, @@ -1355,7 +1358,7 @@ impl Session { } #[zenoh_macros::unstable] - pub(crate) fn matching_status( + pub(in crate::sealed) fn matching_status( &self, key_expr: &KeyExpr, destination: Locality, @@ -1396,7 +1399,7 @@ impl Session { } #[zenoh_macros::unstable] - pub(crate) fn update_status_up(&self, state: &SessionState, key_expr: &KeyExpr) { + pub(in crate::sealed) fn update_status_up(&self, state: &SessionState, key_expr: &KeyExpr) { for msub in state.matching_listeners.values() { if key_expr.intersects(&msub.key_expr) { // Cannot hold session lock when calling tables (matching_status()) @@ -1434,7 +1437,7 @@ impl Session { } #[zenoh_macros::unstable] - pub(crate) fn update_status_down(&self, state: &SessionState, key_expr: &KeyExpr) { + pub(in crate::sealed) fn update_status_down(&self, state: &SessionState, key_expr: &KeyExpr) { for msub in state.matching_listeners.values() { if key_expr.intersects(&msub.key_expr) { // Cannot hold session lock when calling tables (matching_status()) @@ -1472,7 +1475,7 @@ impl Session { } #[zenoh_macros::unstable] - pub(crate) fn undeclare_matches_listener_inner(&self, sid: Id) -> ZResult<()> { + pub(in crate::sealed) fn undeclare_matches_listener_inner(&self, sid: Id) -> ZResult<()> { let mut state = zwrite!(self.state); if let Some(state) = state.matching_listeners.remove(&sid) { trace!("undeclare_matches_listener_inner({:?})", state); @@ -1482,7 +1485,7 @@ impl Session { } } - pub(crate) fn handle_data( + pub(in crate::sealed) fn handle_data( &self, local: bool, key_expr: &WireExpr, @@ -1609,7 +1612,7 @@ impl Session { } #[allow(clippy::too_many_arguments)] - pub(crate) fn query( + pub(in crate::sealed) fn query( &self, selector: &Selector<'_>, scope: &Option>, @@ -1752,7 +1755,7 @@ impl Session { } #[allow(clippy::too_many_arguments)] - pub(crate) fn handle_query( + pub(in crate::sealed) fn handle_query( &self, local: bool, key_expr: &WireExpr, diff --git a/zenoh/src/sealed/api/subscriber.rs b/zenoh/src/sealed/api/subscriber.rs index 4ac035d736..bfc5fc1fb9 100644 --- a/zenoh/src/sealed/api/subscriber.rs +++ b/zenoh/src/sealed/api/subscriber.rs @@ -13,7 +13,7 @@ // use super::{ - handlers::{locked, Callback, DefaultHandler, IntoHandler}, + handlers::{callback::locked, callback::Callback, DefaultHandler, IntoHandler}, key_expr::KeyExpr, sample::{Locality, Sample}, session::{SessionRef, Undeclarable}, @@ -32,13 +32,13 @@ use zenoh_result::ZResult; #[cfg(feature = "unstable")] use zenoh_protocol::core::EntityGlobalId; -pub(crate) struct SubscriberState { - pub(crate) id: Id, - pub(crate) remote_id: Id, - pub(crate) key_expr: KeyExpr<'static>, - pub(crate) scope: Option>, - pub(crate) origin: Locality, - pub(crate) callback: Callback<'static, Sample>, +pub(in crate::sealed) struct SubscriberState { + pub(in crate::sealed) id: Id, + pub(in crate::sealed) remote_id: Id, + pub(in crate::sealed) key_expr: KeyExpr<'static>, + pub(in crate::sealed) scope: Option>, + pub(in crate::sealed) origin: Locality, + pub(in crate::sealed) callback: Callback<'static, Sample>, } impl fmt::Debug for SubscriberState { @@ -75,10 +75,10 @@ impl fmt::Debug for SubscriberState { /// # } /// ``` #[derive(Debug)] -pub(crate) struct SubscriberInner<'a> { - pub(crate) session: SessionRef<'a>, - pub(crate) state: Arc, - pub(crate) alive: bool, +pub(in crate::sealed) struct SubscriberInner<'a> { + pub(in crate::sealed) session: SessionRef<'a>, + pub(in crate::sealed) state: Arc, + pub(in crate::sealed) alive: bool, } impl<'a> SubscriberInner<'a> { @@ -190,27 +190,27 @@ pub struct SubscriberBuilder<'a, 'b, Handler> { #[cfg(feature = "unstable")] pub session: SessionRef<'a>, #[cfg(not(feature = "unstable"))] - pub(crate) session: SessionRef<'a>, + pub(in crate::sealed) session: SessionRef<'a>, #[cfg(feature = "unstable")] pub key_expr: ZResult>, #[cfg(not(feature = "unstable"))] - pub(crate) key_expr: ZResult>, + pub(in crate::sealed) key_expr: ZResult>, #[cfg(feature = "unstable")] pub reliability: Reliability, #[cfg(not(feature = "unstable"))] - pub(crate) reliability: Reliability, + pub(in crate::sealed) reliability: Reliability, #[cfg(feature = "unstable")] pub origin: Locality, #[cfg(not(feature = "unstable"))] - pub(crate) origin: Locality, + pub(in crate::sealed) origin: Locality, #[cfg(feature = "unstable")] pub handler: Handler, #[cfg(not(feature = "unstable"))] - pub(crate) handler: Handler, + pub(in crate::sealed) handler: Handler, } impl<'a, 'b> SubscriberBuilder<'a, 'b, DefaultHandler> { @@ -441,8 +441,8 @@ where #[non_exhaustive] #[derive(Debug)] pub struct Subscriber<'a, Handler> { - pub(crate) subscriber: SubscriberInner<'a>, - pub(crate) handler: Handler, + pub(in crate::sealed) subscriber: SubscriberInner<'a>, + pub(in crate::sealed) handler: Handler, } impl<'a, Handler> Subscriber<'a, Handler> { diff --git a/zenoh/src/sealed/api/value.rs b/zenoh/src/sealed/api/value.rs index 4d482da0b5..9262d9f598 100644 --- a/zenoh/src/sealed/api/value.rs +++ b/zenoh/src/sealed/api/value.rs @@ -19,8 +19,8 @@ use super::{bytes::ZBytes, encoding::Encoding}; #[non_exhaustive] #[derive(Clone, Debug, PartialEq, Eq)] pub struct Value { - pub(crate) payload: ZBytes, - pub(crate) encoding: Encoding, + pub(in crate::sealed) payload: ZBytes, + pub(in crate::sealed) encoding: Encoding, } impl Value { diff --git a/zenoh/src/sealed/mod.rs b/zenoh/src/sealed/mod.rs index 44a995d1cc..586dc9dbae 100644 --- a/zenoh/src/sealed/mod.rs +++ b/zenoh/src/sealed/mod.rs @@ -1,2 +1,2 @@ -pub(crate) mod api; -pub(crate) mod net; +pub mod api; +pub mod net; diff --git a/zenoh/src/sealed/net/codec/mod.rs b/zenoh/src/sealed/net/codec/mod.rs index 06154cd02c..afbb78602c 100644 --- a/zenoh/src/sealed/net/codec/mod.rs +++ b/zenoh/src/sealed/net/codec/mod.rs @@ -11,13 +11,13 @@ // Contributors: // ZettaScale Zenoh Team, // -pub(crate) mod linkstate; +pub(in crate::sealed) mod linkstate; #[derive(Clone, Copy)] -pub struct Zenoh080Routing; +pub(in crate::sealed) struct Zenoh080Routing; impl Zenoh080Routing { - pub const fn new() -> Self { + pub(in crate::sealed) const fn new() -> Self { Self } } diff --git a/zenoh/src/sealed/net/mod.rs b/zenoh/src/sealed/net/mod.rs index 346426a630..0d7008b816 100644 --- a/zenoh/src/sealed/net/mod.rs +++ b/zenoh/src/sealed/net/mod.rs @@ -18,15 +18,15 @@ //! //! [Click here for Zenoh's documentation](../zenoh/index.html) #[doc(hidden)] -pub(crate) mod codec; +pub(in crate::sealed) mod codec; #[doc(hidden)] -pub(crate) mod primitives; +pub(in crate::sealed) mod primitives; #[doc(hidden)] -pub(crate) mod protocol; +pub(in crate::sealed) mod protocol; #[doc(hidden)] -pub(crate) mod routing; +pub(in crate::sealed) mod routing; #[doc(hidden)] pub mod runtime; #[cfg(test)] -pub(crate) mod tests; +pub(in crate::sealed) mod tests; diff --git a/zenoh/src/sealed/net/primitives/demux.rs b/zenoh/src/sealed/net/primitives/demux.rs index 06a0249cd6..1f99441fe8 100644 --- a/zenoh/src/sealed/net/primitives/demux.rs +++ b/zenoh/src/sealed/net/primitives/demux.rs @@ -24,14 +24,14 @@ use zenoh_result::ZResult; use zenoh_transport::unicast::TransportUnicast; use zenoh_transport::TransportPeerEventHandler; -pub struct DeMux { +pub(in crate::sealed) struct DeMux { face: Face, - pub(crate) transport: Option, - pub(crate) interceptor: Arc, + pub(in crate::sealed) transport: Option, + pub(in crate::sealed) interceptor: Arc, } impl DeMux { - pub(crate) fn new( + pub(in crate::sealed) fn new( face: Face, transport: Option, interceptor: Arc, diff --git a/zenoh/src/sealed/net/primitives/mod.rs b/zenoh/src/sealed/net/primitives/mod.rs index d3aa8097ca..563258069f 100644 --- a/zenoh/src/sealed/net/primitives/mod.rs +++ b/zenoh/src/sealed/net/primitives/mod.rs @@ -16,15 +16,15 @@ mod mux; use std::any::Any; -pub use demux::*; -pub use mux::*; +pub(in crate::sealed) use demux::*; +pub(in crate::sealed) use mux::*; use zenoh_protocol::network::{ interest::Interest, Declare, Push, Request, Response, ResponseFinal, }; use super::routing::RoutingContext; -pub trait Primitives: Send + Sync { +pub(in crate::sealed) trait Primitives: Send + Sync { fn send_interest(&self, msg: Interest); fn send_declare(&self, msg: Declare); @@ -40,7 +40,7 @@ pub trait Primitives: Send + Sync { fn send_close(&self); } -pub(crate) trait EPrimitives: Send + Sync { +pub(in crate::sealed) trait EPrimitives: Send + Sync { fn as_any(&self) -> &dyn Any; fn send_declare(&self, ctx: RoutingContext); @@ -57,7 +57,7 @@ pub(crate) trait EPrimitives: Send + Sync { } #[derive(Default)] -pub struct DummyPrimitives; +pub(in crate::sealed) struct DummyPrimitives; impl Primitives for DummyPrimitives { fn send_interest(&self, _msg: Interest) {} diff --git a/zenoh/src/sealed/net/primitives/mux.rs b/zenoh/src/sealed/net/primitives/mux.rs index 79b68d791d..9e584ccaca 100644 --- a/zenoh/src/sealed/net/primitives/mux.rs +++ b/zenoh/src/sealed/net/primitives/mux.rs @@ -24,14 +24,14 @@ use zenoh_protocol::network::{ }; use zenoh_transport::{multicast::TransportMulticast, unicast::TransportUnicast}; -pub struct Mux { - pub handler: TransportUnicast, - pub(crate) face: OnceLock, - pub(crate) interceptor: InterceptorsChain, +pub(in crate::sealed) struct Mux { + pub(in crate::sealed) handler: TransportUnicast, + pub(in crate::sealed) face: OnceLock, + pub(in crate::sealed) interceptor: InterceptorsChain, } impl Mux { - pub(crate) fn new(handler: TransportUnicast, interceptor: InterceptorsChain) -> Mux { + pub(in crate::sealed) fn new(handler: TransportUnicast, interceptor: InterceptorsChain) -> Mux { Mux { handler, face: OnceLock::new(), @@ -328,14 +328,17 @@ impl EPrimitives for Mux { } } -pub struct McastMux { - pub handler: TransportMulticast, - pub(crate) face: OnceLock, - pub(crate) interceptor: InterceptorsChain, +pub(in crate::sealed) struct McastMux { + pub(in crate::sealed) handler: TransportMulticast, + pub(in crate::sealed) face: OnceLock, + pub(in crate::sealed) interceptor: InterceptorsChain, } impl McastMux { - pub(crate) fn new(handler: TransportMulticast, interceptor: InterceptorsChain) -> McastMux { + pub(in crate::sealed) fn new( + handler: TransportMulticast, + interceptor: InterceptorsChain, + ) -> McastMux { McastMux { handler, face: OnceLock::new(), diff --git a/zenoh/src/sealed/net/protocol/linkstate.rs b/zenoh/src/sealed/net/protocol/linkstate.rs index ccb5612011..121364497b 100644 --- a/zenoh/src/sealed/net/protocol/linkstate.rs +++ b/zenoh/src/sealed/net/protocol/linkstate.rs @@ -13,9 +13,9 @@ // use zenoh_protocol::core::{Locator, WhatAmI, ZenohId}; -pub const PID: u64 = 1; // 0x01 -pub const WAI: u64 = 1 << 1; // 0x02 -pub const LOC: u64 = 1 << 2; // 0x04 +pub(in crate::sealed) const PID: u64 = 1; // 0x01 +pub(in crate::sealed) const WAI: u64 = 1 << 1; // 0x02 +pub(in crate::sealed) const LOC: u64 = 1 << 2; // 0x04 // 7 6 5 4 3 2 1 0 // +-+-+-+-+-+-+-+-+ @@ -34,18 +34,18 @@ pub const LOC: u64 = 1 << 2; // 0x04 // ~ [links] ~ // +---------------+ #[derive(Debug, Clone, PartialEq, Eq)] -pub(crate) struct LinkState { - pub(crate) psid: u64, - pub(crate) sn: u64, - pub(crate) zid: Option, - pub(crate) whatami: Option, - pub(crate) locators: Option>, - pub(crate) links: Vec, +pub(in crate::sealed) struct LinkState { + pub(in crate::sealed) psid: u64, + pub(in crate::sealed) sn: u64, + pub(in crate::sealed) zid: Option, + pub(in crate::sealed) whatami: Option, + pub(in crate::sealed) locators: Option>, + pub(in crate::sealed) links: Vec, } impl LinkState { #[cfg(feature = "test")] - pub fn rand() -> Self { + pub(in crate::sealed) fn rand() -> Self { use rand::Rng; const MIN: usize = 1; @@ -93,13 +93,13 @@ impl LinkState { // ~ [link_states] ~ // +---------------+ #[derive(Debug, Clone, PartialEq, Eq)] -pub(crate) struct LinkStateList { - pub(crate) link_states: Vec, +pub(in crate::sealed) struct LinkStateList { + pub(in crate::sealed) link_states: Vec, } impl LinkStateList { #[cfg(feature = "test")] - pub fn rand() -> Self { + pub(in crate::sealed) fn rand() -> Self { use rand::Rng; const MIN: usize = 1; diff --git a/zenoh/src/sealed/net/protocol/mod.rs b/zenoh/src/sealed/net/protocol/mod.rs index 7343a07fd0..0c8f8c5358 100644 --- a/zenoh/src/sealed/net/protocol/mod.rs +++ b/zenoh/src/sealed/net/protocol/mod.rs @@ -11,4 +11,4 @@ // Contributors: // ZettaScale Zenoh Team, // -pub(crate) mod linkstate; +pub(in crate::sealed) mod linkstate; diff --git a/zenoh/src/sealed/net/routing/dispatcher/face.rs b/zenoh/src/sealed/net/routing/dispatcher/face.rs index 102e6576cb..f115e17865 100644 --- a/zenoh/src/sealed/net/routing/dispatcher/face.rs +++ b/zenoh/src/sealed/net/routing/dispatcher/face.rs @@ -33,26 +33,27 @@ use zenoh_transport::multicast::TransportMulticast; #[cfg(feature = "stats")] use zenoh_transport::stats::TransportStats; -pub struct FaceState { - pub(crate) id: usize, - pub(crate) zid: ZenohId, - pub(crate) whatami: WhatAmI, +pub(in crate::sealed) struct FaceState { + pub(in crate::sealed) id: usize, + pub(in crate::sealed) zid: ZenohId, + pub(in crate::sealed) whatami: WhatAmI, #[cfg(feature = "stats")] - pub(crate) stats: Option>, - pub(crate) primitives: Arc, - pub(crate) local_mappings: HashMap>, - pub(crate) remote_mappings: HashMap>, - pub(crate) next_qid: RequestId, - pub(crate) pending_queries: HashMap, CancellationToken)>, - pub(crate) mcast_group: Option, - pub(crate) in_interceptors: Option>, - pub(crate) hat: Box, - pub(crate) task_controller: TaskController, + pub(in crate::sealed) stats: Option>, + pub(in crate::sealed) primitives: + Arc, + pub(in crate::sealed) local_mappings: HashMap>, + pub(in crate::sealed) remote_mappings: HashMap>, + pub(in crate::sealed) next_qid: RequestId, + pub(in crate::sealed) pending_queries: HashMap, CancellationToken)>, + pub(in crate::sealed) mcast_group: Option, + pub(in crate::sealed) in_interceptors: Option>, + pub(in crate::sealed) hat: Box, + pub(in crate::sealed) task_controller: TaskController, } impl FaceState { #[allow(clippy::too_many_arguments)] // @TODO fix warning - pub(crate) fn new( + pub(in crate::sealed) fn new( id: usize, zid: ZenohId, whatami: WhatAmI, @@ -81,7 +82,7 @@ impl FaceState { } #[inline] - pub(crate) fn get_mapping( + pub(in crate::sealed) fn get_mapping( &self, prefixid: &ExprId, mapping: Mapping, @@ -93,7 +94,7 @@ impl FaceState { } #[inline] - pub(crate) fn get_sent_mapping( + pub(in crate::sealed) fn get_sent_mapping( &self, prefixid: &ExprId, mapping: Mapping, @@ -104,7 +105,7 @@ impl FaceState { } } - pub(crate) fn get_next_local_id(&self) -> ExprId { + pub(in crate::sealed) fn get_next_local_id(&self) -> ExprId { let mut id = 1; while self.local_mappings.get(&id).is_some() || self.remote_mappings.get(&id).is_some() { id += 1; @@ -112,7 +113,7 @@ impl FaceState { id } - pub(crate) fn update_interceptors_caches(&self, res: &mut Arc) { + pub(in crate::sealed) fn update_interceptors_caches(&self, res: &mut Arc) { if let Ok(expr) = KeyExpr::try_from(res.expr()) { if let Some(interceptor) = self.in_interceptors.as_ref() { let cache = interceptor.compute_keyexpr_cache(&expr); @@ -155,13 +156,13 @@ impl fmt::Display for FaceState { } #[derive(Clone, Debug)] -pub struct WeakFace { - pub(crate) tables: Weak, - pub(crate) state: Weak, +pub(in crate::sealed) struct WeakFace { + pub(in crate::sealed) tables: Weak, + pub(in crate::sealed) state: Weak, } impl WeakFace { - pub fn upgrade(&self) -> Option { + pub(in crate::sealed) fn upgrade(&self) -> Option { Some(Face { tables: self.tables.upgrade()?, state: self.state.upgrade()?, @@ -170,13 +171,13 @@ impl WeakFace { } #[derive(Clone)] -pub struct Face { - pub(crate) tables: Arc, - pub(crate) state: Arc, +pub(in crate::sealed) struct Face { + pub(in crate::sealed) tables: Arc, + pub(in crate::sealed) state: Arc, } impl Face { - pub fn downgrade(&self) -> WeakFace { + pub(in crate::sealed) fn downgrade(&self) -> WeakFace { WeakFace { tables: Arc::downgrade(&self.tables), state: Arc::downgrade(&self.state), diff --git a/zenoh/src/sealed/net/routing/dispatcher/mod.rs b/zenoh/src/sealed/net/routing/dispatcher/mod.rs index 53c32fb5ff..394388f7bb 100644 --- a/zenoh/src/sealed/net/routing/dispatcher/mod.rs +++ b/zenoh/src/sealed/net/routing/dispatcher/mod.rs @@ -17,8 +17,8 @@ //! This module is intended for Zenoh's internal use. //! //! [Click here for Zenoh's documentation](../zenoh/index.html) -pub mod face; -pub mod pubsub; -pub mod queries; -pub mod resource; -pub mod tables; +pub(in crate::sealed) mod face; +pub(in crate::sealed) mod pubsub; +pub(in crate::sealed) mod queries; +pub(in crate::sealed) mod resource; +pub(in crate::sealed) mod tables; diff --git a/zenoh/src/sealed/net/routing/dispatcher/pubsub.rs b/zenoh/src/sealed/net/routing/dispatcher/pubsub.rs index 5381149f14..41677df03a 100644 --- a/zenoh/src/sealed/net/routing/dispatcher/pubsub.rs +++ b/zenoh/src/sealed/net/routing/dispatcher/pubsub.rs @@ -28,7 +28,7 @@ use zenoh_protocol::{ }; use zenoh_sync::get_mut_unchecked; -pub(crate) fn declare_subscription( +pub(in crate::sealed) fn declare_subscription( hat_code: &(dyn HatTrait + Send + Sync), tables: &TablesLock, face: &mut Arc, @@ -97,7 +97,7 @@ pub(crate) fn declare_subscription( } } -pub(crate) fn undeclare_subscription( +pub(in crate::sealed) fn undeclare_subscription( hat_code: &(dyn HatTrait + Send + Sync), tables: &TablesLock, face: &mut Arc, @@ -196,13 +196,16 @@ fn compute_data_routes_(tables: &Tables, routes: &mut DataRoutes, expr: &mut Rou } } -pub(crate) fn compute_data_routes(tables: &Tables, expr: &mut RoutingExpr) -> DataRoutes { +pub(in crate::sealed) fn compute_data_routes( + tables: &Tables, + expr: &mut RoutingExpr, +) -> DataRoutes { let mut routes = DataRoutes::default(); compute_data_routes_(tables, &mut routes, expr); routes } -pub(crate) fn update_data_routes(tables: &Tables, res: &mut Arc) { +pub(in crate::sealed) fn update_data_routes(tables: &Tables, res: &mut Arc) { if res.context.is_some() { let mut res_mut = res.clone(); let res_mut = get_mut_unchecked(&mut res_mut); @@ -214,7 +217,7 @@ pub(crate) fn update_data_routes(tables: &Tables, res: &mut Arc) { } } -pub(crate) fn update_data_routes_from(tables: &mut Tables, res: &mut Arc) { +pub(in crate::sealed) fn update_data_routes_from(tables: &mut Tables, res: &mut Arc) { update_data_routes(tables, res); let res = get_mut_unchecked(res); for child in res.childs.values_mut() { @@ -222,7 +225,7 @@ pub(crate) fn update_data_routes_from(tables: &mut Tables, res: &mut Arc( +pub(in crate::sealed) fn compute_matches_data_routes<'a>( tables: &'a Tables, res: &'a Arc, ) -> Vec<(Arc, DataRoutes)> { @@ -242,7 +245,10 @@ pub(crate) fn compute_matches_data_routes<'a>( routes } -pub(crate) fn update_matches_data_routes<'a>(tables: &'a mut Tables, res: &'a mut Arc) { +pub(in crate::sealed) fn update_matches_data_routes<'a>( + tables: &'a mut Tables, + res: &'a mut Arc, +) { if res.context.is_some() { update_data_routes(tables, res); for match_ in &res.context().matches { @@ -254,7 +260,10 @@ pub(crate) fn update_matches_data_routes<'a>(tables: &'a mut Tables, res: &'a mu } } -pub(crate) fn disable_matches_data_routes(_tables: &mut Tables, res: &mut Arc) { +pub(in crate::sealed) fn disable_matches_data_routes( + _tables: &mut Tables, + res: &mut Arc, +) { if res.context.is_some() { get_mut_unchecked(res).context_mut().disable_data_routes(); for match_ in &res.context().matches { @@ -326,7 +335,7 @@ fn get_data_route( #[zenoh_macros::unstable] #[inline] -pub(crate) fn get_local_data_route( +pub(in crate::sealed) fn get_local_data_route( tables: &Tables, res: &Option>, expr: &mut RoutingExpr, @@ -374,7 +383,7 @@ macro_rules! inc_stats { }; } -pub fn full_reentrant_route_data( +pub(in crate::sealed) fn full_reentrant_route_data( tables_ref: &Arc, face: &FaceState, expr: &WireExpr, diff --git a/zenoh/src/sealed/net/routing/dispatcher/queries.rs b/zenoh/src/sealed/net/routing/dispatcher/queries.rs index b048c9a21c..f23441d864 100644 --- a/zenoh/src/sealed/net/routing/dispatcher/queries.rs +++ b/zenoh/src/sealed/net/routing/dispatcher/queries.rs @@ -35,12 +35,12 @@ use zenoh_protocol::{ use zenoh_sync::get_mut_unchecked; use zenoh_util::Timed; -pub(crate) struct Query { +pub(in crate::sealed) struct Query { src_face: Arc, src_qid: RequestId, } -pub(crate) fn declare_queryable( +pub(in crate::sealed) fn declare_queryable( hat_code: &(dyn HatTrait + Send + Sync), tables: &TablesLock, face: &mut Arc, @@ -109,7 +109,7 @@ pub(crate) fn declare_queryable( } } -pub(crate) fn undeclare_queryable( +pub(in crate::sealed) fn undeclare_queryable( hat_code: &(dyn HatTrait + Send + Sync), tables: &TablesLock, face: &mut Arc, @@ -207,13 +207,13 @@ fn compute_query_routes_(tables: &Tables, routes: &mut QueryRoutes, expr: &mut R } } -pub(crate) fn compute_query_routes(tables: &Tables, res: &Arc) -> QueryRoutes { +pub(in crate::sealed) fn compute_query_routes(tables: &Tables, res: &Arc) -> QueryRoutes { let mut routes = QueryRoutes::default(); compute_query_routes_(tables, &mut routes, &mut RoutingExpr::new(res, "")); routes } -pub(crate) fn update_query_routes(tables: &Tables, res: &Arc) { +pub(in crate::sealed) fn update_query_routes(tables: &Tables, res: &Arc) { if res.context.is_some() { let mut res_mut = res.clone(); let res_mut = get_mut_unchecked(&mut res_mut); @@ -225,7 +225,7 @@ pub(crate) fn update_query_routes(tables: &Tables, res: &Arc) { } } -pub(crate) fn update_query_routes_from(tables: &mut Tables, res: &mut Arc) { +pub(in crate::sealed) fn update_query_routes_from(tables: &mut Tables, res: &mut Arc) { update_query_routes(tables, res); let res = get_mut_unchecked(res); for child in res.childs.values_mut() { @@ -233,7 +233,7 @@ pub(crate) fn update_query_routes_from(tables: &mut Tables, res: &mut Arc, ) -> Vec<(Arc, QueryRoutes)> { @@ -251,7 +251,7 @@ pub(crate) fn compute_matches_query_routes( routes } -pub(crate) fn update_matches_query_routes(tables: &Tables, res: &Arc) { +pub(in crate::sealed) fn update_matches_query_routes(tables: &Tables, res: &Arc) { if res.context.is_some() { update_query_routes(tables, res); for match_ in &res.context().matches { @@ -345,7 +345,7 @@ struct QueryCleanup { } impl QueryCleanup { - pub fn spawn_query_clean_up_task( + pub(in crate::sealed) fn spawn_query_clean_up_task( face: &Arc, tables_ref: &Arc, qid: u32, @@ -391,7 +391,10 @@ impl Timed for QueryCleanup { } } -pub(crate) fn disable_matches_query_routes(_tables: &mut Tables, res: &mut Arc) { +pub(in crate::sealed) fn disable_matches_query_routes( + _tables: &mut Tables, + res: &mut Arc, +) { if res.context.is_some() { get_mut_unchecked(res).context_mut().disable_query_routes(); for match_ in &res.context().matches { @@ -491,7 +494,7 @@ macro_rules! inc_res_stats { }; } -pub fn route_query( +pub(in crate::sealed) fn route_query( tables_ref: &Arc, face: &Arc, expr: &WireExpr, @@ -665,7 +668,7 @@ pub fn route_query( } } -pub(crate) fn route_send_response( +pub(in crate::sealed) fn route_send_response( tables_ref: &Arc, face: &mut Arc, qid: RequestId, @@ -719,7 +722,7 @@ pub(crate) fn route_send_response( } } -pub(crate) fn route_send_response_final( +pub(in crate::sealed) fn route_send_response_final( tables_ref: &Arc, face: &mut Arc, qid: RequestId, @@ -745,7 +748,10 @@ pub(crate) fn route_send_response_final( } } -pub(crate) fn finalize_pending_queries(tables_ref: &TablesLock, face: &mut Arc) { +pub(in crate::sealed) fn finalize_pending_queries( + tables_ref: &TablesLock, + face: &mut Arc, +) { let queries_lock = zwrite!(tables_ref.queries_lock); for (_, query) in get_mut_unchecked(face).pending_queries.drain() { finalize_pending_query(query); @@ -753,7 +759,7 @@ pub(crate) fn finalize_pending_queries(tables_ref: &TablesLock, face: &mut Arc, CancellationToken)) { +pub(in crate::sealed) fn finalize_pending_query(query: (Arc, CancellationToken)) { let (query, cancellation_token) = query; cancellation_token.cancel(); if let Some(query) = Arc::into_inner(query) { diff --git a/zenoh/src/sealed/net/routing/dispatcher/resource.rs b/zenoh/src/sealed/net/routing/dispatcher/resource.rs index 7f16daa793..f8aada59f9 100644 --- a/zenoh/src/sealed/net/routing/dispatcher/resource.rs +++ b/zenoh/src/sealed/net/routing/dispatcher/resource.rs @@ -34,45 +34,49 @@ use zenoh_protocol::{ }; use zenoh_sync::get_mut_unchecked; -pub(crate) type NodeId = u16; - -pub(crate) type Direction = (Arc, WireExpr<'static>, NodeId); -pub(crate) type Route = HashMap; -pub(crate) type QueryRoute = HashMap; -pub(crate) struct QueryTargetQabl { - pub(crate) direction: Direction, - pub(crate) complete: u64, - pub(crate) distance: f64, +pub(in crate::sealed) type NodeId = u16; + +pub(in crate::sealed) type Direction = (Arc, WireExpr<'static>, NodeId); +pub(in crate::sealed) type Route = HashMap; +pub(in crate::sealed) type QueryRoute = HashMap; +pub(in crate::sealed) struct QueryTargetQabl { + pub(in crate::sealed) direction: Direction, + pub(in crate::sealed) complete: u64, + pub(in crate::sealed) distance: f64, } -pub(crate) type QueryTargetQablSet = Vec; - -pub(crate) struct SessionContext { - pub(crate) face: Arc, - pub(crate) local_expr_id: Option, - pub(crate) remote_expr_id: Option, - pub(crate) subs: Option, - pub(crate) qabl: Option, - pub(crate) in_interceptor_cache: Option>, - pub(crate) e_interceptor_cache: Option>, +pub(in crate::sealed) type QueryTargetQablSet = Vec; + +pub(in crate::sealed) struct SessionContext { + pub(in crate::sealed) face: Arc, + pub(in crate::sealed) local_expr_id: Option, + pub(in crate::sealed) remote_expr_id: Option, + pub(in crate::sealed) subs: Option, + pub(in crate::sealed) qabl: Option, + pub(in crate::sealed) in_interceptor_cache: Option>, + pub(in crate::sealed) e_interceptor_cache: Option>, } #[derive(Default)] -pub(crate) struct RoutesIndexes { - pub(crate) routers: Vec, - pub(crate) peers: Vec, - pub(crate) clients: Vec, +pub(in crate::sealed) struct RoutesIndexes { + pub(in crate::sealed) routers: Vec, + pub(in crate::sealed) peers: Vec, + pub(in crate::sealed) clients: Vec, } #[derive(Default)] -pub(crate) struct DataRoutes { - pub(crate) routers: Vec>, - pub(crate) peers: Vec>, - pub(crate) clients: Vec>, +pub(in crate::sealed) struct DataRoutes { + pub(in crate::sealed) routers: Vec>, + pub(in crate::sealed) peers: Vec>, + pub(in crate::sealed) clients: Vec>, } impl DataRoutes { #[inline] - pub(crate) fn get_route(&self, whatami: WhatAmI, context: NodeId) -> Option> { + pub(in crate::sealed) fn get_route( + &self, + whatami: WhatAmI, + context: NodeId, + ) -> Option> { match whatami { WhatAmI::Router => (self.routers.len() > context as usize) .then(|| self.routers[context as usize].clone()), @@ -86,15 +90,15 @@ impl DataRoutes { } #[derive(Default)] -pub(crate) struct QueryRoutes { - pub(crate) routers: Vec>, - pub(crate) peers: Vec>, - pub(crate) clients: Vec>, +pub(in crate::sealed) struct QueryRoutes { + pub(in crate::sealed) routers: Vec>, + pub(in crate::sealed) peers: Vec>, + pub(in crate::sealed) clients: Vec>, } impl QueryRoutes { #[inline] - pub(crate) fn get_route( + pub(in crate::sealed) fn get_route( &self, whatami: WhatAmI, context: NodeId, @@ -111,13 +115,13 @@ impl QueryRoutes { } } -pub(crate) struct ResourceContext { - pub(crate) matches: Vec>, - pub(crate) hat: Box, - pub(crate) valid_data_routes: bool, - pub(crate) data_routes: DataRoutes, - pub(crate) valid_query_routes: bool, - pub(crate) query_routes: QueryRoutes, +pub(in crate::sealed) struct ResourceContext { + pub(in crate::sealed) matches: Vec>, + pub(in crate::sealed) hat: Box, + pub(in crate::sealed) valid_data_routes: bool, + pub(in crate::sealed) data_routes: DataRoutes, + pub(in crate::sealed) valid_query_routes: bool, + pub(in crate::sealed) query_routes: QueryRoutes, } impl ResourceContext { @@ -132,32 +136,32 @@ impl ResourceContext { } } - pub(crate) fn update_data_routes(&mut self, data_routes: DataRoutes) { + pub(in crate::sealed) fn update_data_routes(&mut self, data_routes: DataRoutes) { self.valid_data_routes = true; self.data_routes = data_routes; } - pub(crate) fn disable_data_routes(&mut self) { + pub(in crate::sealed) fn disable_data_routes(&mut self) { self.valid_data_routes = false; } - pub(crate) fn update_query_routes(&mut self, query_routes: QueryRoutes) { + pub(in crate::sealed) fn update_query_routes(&mut self, query_routes: QueryRoutes) { self.valid_query_routes = true; self.query_routes = query_routes } - pub(crate) fn disable_query_routes(&mut self) { + pub(in crate::sealed) fn disable_query_routes(&mut self) { self.valid_query_routes = false; } } -pub struct Resource { - pub(crate) parent: Option>, - pub(crate) suffix: String, - pub(crate) nonwild_prefix: Option<(Arc, String)>, - pub(crate) childs: HashMap>, - pub(crate) context: Option, - pub(crate) session_ctxs: HashMap>, +pub(in crate::sealed) struct Resource { + pub(in crate::sealed) parent: Option>, + pub(in crate::sealed) suffix: String, + pub(in crate::sealed) nonwild_prefix: Option<(Arc, String)>, + pub(in crate::sealed) childs: HashMap>, + pub(in crate::sealed) context: Option, + pub(in crate::sealed) session_ctxs: HashMap>, } impl PartialEq for Resource { @@ -196,7 +200,7 @@ impl Resource { } } - pub fn expr(&self) -> String { + pub(in crate::sealed) fn expr(&self) -> String { match &self.parent { Some(parent) => parent.expr() + &self.suffix, None => String::from(""), @@ -204,16 +208,18 @@ impl Resource { } #[inline(always)] - pub(crate) fn context(&self) -> &ResourceContext { + pub(in crate::sealed) fn context(&self) -> &ResourceContext { self.context.as_ref().unwrap() } #[inline(always)] - pub(crate) fn context_mut(&mut self) -> &mut ResourceContext { + pub(in crate::sealed) fn context_mut(&mut self) -> &mut ResourceContext { self.context.as_mut().unwrap() } - pub fn nonwild_prefix(res: &Arc) -> (Option>, String) { + pub(in crate::sealed) fn nonwild_prefix( + res: &Arc, + ) -> (Option>, String) { match &res.nonwild_prefix { None => (Some(res.clone()), "".to_string()), Some((nonwild_prefix, wildsuffix)) => { @@ -227,7 +233,11 @@ impl Resource { } #[inline] - pub(crate) fn data_route(&self, whatami: WhatAmI, context: NodeId) -> Option> { + pub(in crate::sealed) fn data_route( + &self, + whatami: WhatAmI, + context: NodeId, + ) -> Option> { match &self.context { Some(ctx) => { if ctx.valid_data_routes { @@ -242,7 +252,7 @@ impl Resource { } #[inline(always)] - pub(crate) fn query_route( + pub(in crate::sealed) fn query_route( &self, whatami: WhatAmI, context: NodeId, @@ -259,7 +269,7 @@ impl Resource { } } - pub fn root() -> Arc { + pub(in crate::sealed) fn root() -> Arc { Arc::new(Resource { parent: None, suffix: String::from(""), @@ -270,7 +280,7 @@ impl Resource { }) } - pub fn clean(res: &mut Arc) { + pub(in crate::sealed) fn clean(res: &mut Arc) { let mut resclone = res.clone(); let mutres = get_mut_unchecked(&mut resclone); if let Some(ref mut parent) = mutres.parent { @@ -298,7 +308,7 @@ impl Resource { } } - pub fn close(self: &mut Arc) { + pub(in crate::sealed) fn close(self: &mut Arc) { let r = get_mut_unchecked(self); for c in r.childs.values_mut() { Self::close(c); @@ -310,7 +320,7 @@ impl Resource { } #[cfg(test)] - pub fn print_tree(from: &Arc) -> String { + pub(in crate::sealed) fn print_tree(from: &Arc) -> String { let mut result = from.expr(); result.push('\n'); for child in from.childs.values() { @@ -319,7 +329,7 @@ impl Resource { result } - pub fn make_resource( + pub(in crate::sealed) fn make_resource( tables: &mut Tables, from: &mut Arc, suffix: &str, @@ -378,7 +388,10 @@ impl Resource { } #[inline] - pub fn get_resource(from: &Arc, suffix: &str) -> Option> { + pub(in crate::sealed) fn get_resource( + from: &Arc, + suffix: &str, + ) -> Option> { if suffix.is_empty() { Some(from.clone()) } else if let Some(stripped_suffix) = suffix.strip_prefix('/') { @@ -426,7 +439,10 @@ impl Resource { } #[inline] - pub fn decl_key(res: &Arc, face: &mut Arc) -> WireExpr<'static> { + pub(in crate::sealed) fn decl_key( + res: &Arc, + face: &mut Arc, + ) -> WireExpr<'static> { let (nonwild_prefix, wildsuffix) = Resource::nonwild_prefix(res); match nonwild_prefix { Some(mut nonwild_prefix) => { @@ -489,7 +505,11 @@ impl Resource { } #[inline] - pub fn get_best_key<'a>(prefix: &Arc, suffix: &'a str, sid: usize) -> WireExpr<'a> { + pub(in crate::sealed) fn get_best_key<'a>( + prefix: &Arc, + suffix: &'a str, + sid: usize, + ) -> WireExpr<'a> { fn get_best_key_<'a>( prefix: &Arc, suffix: &'a str, @@ -527,7 +547,10 @@ impl Resource { get_best_key_(prefix, suffix, sid, true) } - pub fn get_matches(tables: &Tables, key_expr: &keyexpr) -> Vec> { + pub(in crate::sealed) fn get_matches( + tables: &Tables, + key_expr: &keyexpr, + ) -> Vec> { fn recursive_push(from: &Arc, matches: &mut Vec>) { if from.context.is_some() { matches.push(Arc::downgrade(from)); @@ -612,7 +635,11 @@ impl Resource { matches } - pub fn match_resource(_tables: &Tables, res: &mut Arc, matches: Vec>) { + pub(in crate::sealed) fn match_resource( + _tables: &Tables, + res: &mut Arc, + matches: Vec>, + ) { if res.context.is_some() { for match_ in &matches { let mut match_ = match_.upgrade().unwrap(); @@ -627,26 +654,35 @@ impl Resource { } } - pub fn upgrade_resource(res: &mut Arc, hat: Box) { + pub(in crate::sealed) fn upgrade_resource( + res: &mut Arc, + hat: Box, + ) { if res.context.is_none() { get_mut_unchecked(res).context = Some(ResourceContext::new(hat)); } } - pub(crate) fn get_ingress_cache(&self, face: &Face) -> Option<&Box> { + pub(in crate::sealed) fn get_ingress_cache( + &self, + face: &Face, + ) -> Option<&Box> { self.session_ctxs .get(&face.state.id) .and_then(|ctx| ctx.in_interceptor_cache.as_ref()) } - pub(crate) fn get_egress_cache(&self, face: &Face) -> Option<&Box> { + pub(in crate::sealed) fn get_egress_cache( + &self, + face: &Face, + ) -> Option<&Box> { self.session_ctxs .get(&face.state.id) .and_then(|ctx| ctx.e_interceptor_cache.as_ref()) } } -pub fn register_expr( +pub(in crate::sealed) fn register_expr( tables: &TablesLock, face: &mut Arc, expr_id: ExprId, @@ -724,7 +760,11 @@ pub fn register_expr( } } -pub fn unregister_expr(tables: &TablesLock, face: &mut Arc, expr_id: ExprId) { +pub(in crate::sealed) fn unregister_expr( + tables: &TablesLock, + face: &mut Arc, + expr_id: ExprId, +) { let wtables = zwrite!(tables.tables); match get_mut_unchecked(face).remote_mappings.remove(&expr_id) { Some(mut res) => Resource::clean(&mut res), diff --git a/zenoh/src/sealed/net/routing/dispatcher/tables.rs b/zenoh/src/sealed/net/routing/dispatcher/tables.rs index 28a7b0583c..e6e4119adb 100644 --- a/zenoh/src/sealed/net/routing/dispatcher/tables.rs +++ b/zenoh/src/sealed/net/routing/dispatcher/tables.rs @@ -12,9 +12,9 @@ // ZettaScale Zenoh Team, // use super::face::FaceState; -pub use super::pubsub::*; -pub use super::queries::*; -pub use super::resource::*; +pub(in crate::sealed) use super::pubsub::*; +pub(in crate::sealed) use super::queries::*; +pub(in crate::sealed) use super::resource::*; use crate::sealed::net::routing::hat; use crate::sealed::net::routing::hat::HatTrait; use crate::sealed::net::routing::interceptor::interceptor_factories; @@ -32,15 +32,15 @@ use zenoh_protocol::network::Mapping; use zenoh_result::ZResult; use zenoh_sync::get_mut_unchecked; -pub(crate) struct RoutingExpr<'a> { - pub(crate) prefix: &'a Arc, - pub(crate) suffix: &'a str, +pub(in crate::sealed) struct RoutingExpr<'a> { + pub(in crate::sealed) prefix: &'a Arc, + pub(in crate::sealed) suffix: &'a str, full: Option, } impl<'a> RoutingExpr<'a> { #[inline] - pub(crate) fn new(prefix: &'a Arc, suffix: &'a str) -> Self { + pub(in crate::sealed) fn new(prefix: &'a Arc, suffix: &'a str) -> Self { RoutingExpr { prefix, suffix, @@ -49,7 +49,7 @@ impl<'a> RoutingExpr<'a> { } #[inline] - pub(crate) fn full_expr(&mut self) -> &str { + pub(in crate::sealed) fn full_expr(&mut self) -> &str { if self.full.is_none() { self.full = Some(self.prefix.expr() + self.suffix); } @@ -57,25 +57,25 @@ impl<'a> RoutingExpr<'a> { } } -pub struct Tables { - pub(crate) zid: ZenohId, - pub(crate) whatami: WhatAmI, - pub(crate) face_counter: usize, +pub(in crate::sealed) struct Tables { + pub(in crate::sealed) zid: ZenohId, + pub(in crate::sealed) whatami: WhatAmI, + pub(in crate::sealed) face_counter: usize, #[allow(dead_code)] - pub(crate) hlc: Option>, - pub(crate) drop_future_timestamp: bool, - pub(crate) queries_default_timeout: Duration, - pub(crate) root_res: Arc, - pub(crate) faces: HashMap>, - pub(crate) mcast_groups: Vec>, - pub(crate) mcast_faces: Vec>, - pub(crate) interceptors: Vec, - pub(crate) hat: Box, - pub(crate) hat_code: Arc, // @TODO make this a Box + pub(in crate::sealed) hlc: Option>, + pub(in crate::sealed) drop_future_timestamp: bool, + pub(in crate::sealed) queries_default_timeout: Duration, + pub(in crate::sealed) root_res: Arc, + pub(in crate::sealed) faces: HashMap>, + pub(in crate::sealed) mcast_groups: Vec>, + pub(in crate::sealed) mcast_faces: Vec>, + pub(in crate::sealed) interceptors: Vec, + pub(in crate::sealed) hat: Box, + pub(in crate::sealed) hat_code: Arc, // @TODO make this a Box } impl Tables { - pub fn new( + pub(in crate::sealed) fn new( zid: ZenohId, whatami: WhatAmI, hlc: Option>, @@ -106,17 +106,17 @@ impl Tables { } #[doc(hidden)] - pub fn _get_root(&self) -> &Arc { + pub(in crate::sealed) fn _get_root(&self) -> &Arc { &self.root_res } #[cfg(test)] - pub fn print(&self) -> String { + pub(in crate::sealed) fn print(&self) -> String { Resource::print_tree(&self.root_res) } #[inline] - pub(crate) fn get_mapping<'a>( + pub(in crate::sealed) fn get_mapping<'a>( &'a self, face: &'a FaceState, expr_id: &ExprId, @@ -129,7 +129,7 @@ impl Tables { } #[inline] - pub(crate) fn get_sent_mapping<'a>( + pub(in crate::sealed) fn get_sent_mapping<'a>( &'a self, face: &'a FaceState, expr_id: &ExprId, @@ -142,7 +142,7 @@ impl Tables { } #[inline] - pub(crate) fn get_face(&self, zid: &ZenohId) -> Option<&Arc> { + pub(in crate::sealed) fn get_face(&self, zid: &ZenohId) -> Option<&Arc> { self.faces.values().find(|face| face.zid == *zid) } @@ -151,7 +151,7 @@ impl Tables { update_query_routes(self, res); } - pub(crate) fn update_matches_routes(&mut self, res: &mut Arc) { + pub(in crate::sealed) fn update_matches_routes(&mut self, res: &mut Arc) { if res.context.is_some() { self.update_routes(res); @@ -166,7 +166,7 @@ impl Tables { } } -pub fn close_face(tables: &TablesLock, face: &Weak) { +pub(in crate::sealed) fn close_face(tables: &TablesLock, face: &Weak) { match face.upgrade() { Some(mut face) => { tracing::debug!("Close {}", face); @@ -178,8 +178,8 @@ pub fn close_face(tables: &TablesLock, face: &Weak) { } } -pub struct TablesLock { - pub tables: RwLock, - pub(crate) ctrl_lock: Mutex>, - pub queries_lock: RwLock<()>, +pub(in crate::sealed) struct TablesLock { + pub(in crate::sealed) tables: RwLock, + pub(in crate::sealed) ctrl_lock: Mutex>, + pub(in crate::sealed) queries_lock: RwLock<()>, } diff --git a/zenoh/src/sealed/net/routing/hat/client/mod.rs b/zenoh/src/sealed/net/routing/hat/client/mod.rs index f6f30bfab6..31d5bff092 100644 --- a/zenoh/src/sealed/net/routing/hat/client/mod.rs +++ b/zenoh/src/sealed/net/routing/hat/client/mod.rs @@ -75,7 +75,7 @@ impl HatTables { } } -pub(crate) struct HatCode {} +pub(in crate::sealed) struct HatCode {} impl HatBaseTrait for HatCode { fn init(&self, _tables: &mut Tables, _runtime: Runtime) {} diff --git a/zenoh/src/sealed/net/routing/hat/linkstate_peer/mod.rs b/zenoh/src/sealed/net/routing/hat/linkstate_peer/mod.rs index cf35c97655..756600f29d 100644 --- a/zenoh/src/sealed/net/routing/hat/linkstate_peer/mod.rs +++ b/zenoh/src/sealed/net/routing/hat/linkstate_peer/mod.rs @@ -165,7 +165,7 @@ impl HatTables { } } -pub(crate) struct HatCode {} +pub(in crate::sealed) struct HatCode {} impl HatBaseTrait for HatCode { fn init(&self, tables: &mut Tables, runtime: Runtime) { diff --git a/zenoh/src/sealed/net/routing/hat/mod.rs b/zenoh/src/sealed/net/routing/hat/mod.rs index fd8ea16d22..c199586df2 100644 --- a/zenoh/src/sealed/net/routing/hat/mod.rs +++ b/zenoh/src/sealed/net/routing/hat/mod.rs @@ -47,18 +47,18 @@ mod p2p_peer; mod router; zconfigurable! { - pub static ref TREES_COMPUTATION_DELAY_MS: u64 = 100; + pub(in crate::sealed) static ref TREES_COMPUTATION_DELAY_MS: u64 = 100; } #[derive(serde::Serialize)] -pub(crate) struct Sources { +pub(in crate::sealed) struct Sources { routers: Vec, peers: Vec, clients: Vec, } impl Sources { - pub(crate) fn empty() -> Self { + pub(in crate::sealed) fn empty() -> Self { Self { routers: vec![], peers: vec![], @@ -67,9 +67,12 @@ impl Sources { } } -pub(crate) trait HatTrait: HatBaseTrait + HatPubSubTrait + HatQueriesTrait {} +pub(in crate::sealed) trait HatTrait: + HatBaseTrait + HatPubSubTrait + HatQueriesTrait +{ +} -pub(crate) trait HatBaseTrait { +pub(in crate::sealed) trait HatBaseTrait { fn as_any(&self) -> &dyn Any; fn init(&self, tables: &mut Tables, runtime: Runtime); @@ -132,7 +135,7 @@ pub(crate) trait HatBaseTrait { fn close_face(&self, tables: &TablesLock, face: &mut Arc); } -pub(crate) trait HatPubSubTrait { +pub(in crate::sealed) trait HatPubSubTrait { fn declare_subscription( &self, tables: &mut Tables, @@ -164,7 +167,7 @@ pub(crate) trait HatPubSubTrait { fn get_data_routes_entries(&self, tables: &Tables) -> RoutesIndexes; } -pub(crate) trait HatQueriesTrait { +pub(in crate::sealed) trait HatQueriesTrait { fn declare_queryable( &self, tables: &mut Tables, @@ -204,7 +207,10 @@ pub(crate) trait HatQueriesTrait { ) -> Vec<(WireExpr<'static>, ZBuf)>; } -pub(crate) fn new_hat(whatami: WhatAmI, config: &Config) -> Box { +pub(in crate::sealed) fn new_hat( + whatami: WhatAmI, + config: &Config, +) -> Box { match whatami { WhatAmI::Client => Box::new(client::HatCode {}), WhatAmI::Peer => { diff --git a/zenoh/src/sealed/net/routing/hat/p2p_peer/mod.rs b/zenoh/src/sealed/net/routing/hat/p2p_peer/mod.rs index b5bb8e69ec..fdeb82c51e 100644 --- a/zenoh/src/sealed/net/routing/hat/p2p_peer/mod.rs +++ b/zenoh/src/sealed/net/routing/hat/p2p_peer/mod.rs @@ -94,7 +94,7 @@ impl HatTables { } } -pub(crate) struct HatCode {} +pub(in crate::sealed) struct HatCode {} impl HatBaseTrait for HatCode { fn init(&self, tables: &mut Tables, runtime: Runtime) { diff --git a/zenoh/src/sealed/net/routing/hat/router/mod.rs b/zenoh/src/sealed/net/routing/hat/router/mod.rs index c43b69404d..f41c61a12b 100644 --- a/zenoh/src/sealed/net/routing/hat/router/mod.rs +++ b/zenoh/src/sealed/net/routing/hat/router/mod.rs @@ -296,7 +296,7 @@ impl HatTables { } } -pub(crate) struct HatCode {} +pub(in crate::sealed) struct HatCode {} impl HatBaseTrait for HatCode { fn init(&self, tables: &mut Tables, runtime: Runtime) { diff --git a/zenoh/src/sealed/net/routing/interceptor/access_control.rs b/zenoh/src/sealed/net/routing/interceptor/access_control.rs index b0ffc90eb6..b078a5b50c 100644 --- a/zenoh/src/sealed/net/routing/interceptor/access_control.rs +++ b/zenoh/src/sealed/net/routing/interceptor/access_control.rs @@ -33,11 +33,11 @@ use zenoh_protocol::{ }; use zenoh_result::ZResult; use zenoh_transport::{multicast::TransportMulticast, unicast::TransportUnicast}; -pub struct AclEnforcer { +pub(in crate::sealed) struct AclEnforcer { enforcer: Arc, } #[derive(Clone, Debug)] -pub struct Interface { +pub(in crate::sealed) struct Interface { id: usize, name: String, } @@ -52,7 +52,7 @@ struct IngressAclEnforcer { zid: ZenohId, } -pub(crate) fn acl_interceptor_factories( +pub(in crate::sealed) fn acl_interceptor_factories( acl_config: &AclConfig, ) -> ZResult> { let mut res: Vec = vec![]; @@ -280,7 +280,7 @@ impl InterceptorTrait for EgressAclEnforcer { Some(ctx) } } -pub trait AclActionMethods { +pub(in crate::sealed) trait AclActionMethods { fn policy_enforcer(&self) -> Arc; fn interface_list(&self) -> Vec; fn zid(&self) -> ZenohId; diff --git a/zenoh/src/sealed/net/routing/interceptor/authorization.rs b/zenoh/src/sealed/net/routing/interceptor/authorization.rs index 61c1cba217..04850a2ae8 100644 --- a/zenoh/src/sealed/net/routing/interceptor/authorization.rs +++ b/zenoh/src/sealed/net/routing/interceptor/authorization.rs @@ -80,7 +80,7 @@ impl ActionPolicy { } #[derive(Default)] -pub struct FlowPolicy { +pub(in crate::sealed) struct FlowPolicy { ingress: ActionPolicy, egress: ActionPolicy, } @@ -101,27 +101,27 @@ impl FlowPolicy { } #[derive(Default, Debug)] -pub struct InterfaceEnabled { - pub ingress: bool, - pub egress: bool, +pub(in crate::sealed) struct InterfaceEnabled { + pub(in crate::sealed) ingress: bool, + pub(in crate::sealed) egress: bool, } -pub struct PolicyEnforcer { - pub(crate) acl_enabled: bool, - pub(crate) default_permission: Permission, - pub(crate) subject_map: SubjectMap, - pub(crate) policy_map: PolicyMap, - pub(crate) interface_enabled: InterfaceEnabled, +pub(in crate::sealed) struct PolicyEnforcer { + pub(in crate::sealed) acl_enabled: bool, + pub(in crate::sealed) default_permission: Permission, + pub(in crate::sealed) subject_map: SubjectMap, + pub(in crate::sealed) policy_map: PolicyMap, + pub(in crate::sealed) interface_enabled: InterfaceEnabled, } #[derive(Debug, Clone)] -pub struct PolicyInformation { +pub(in crate::sealed) struct PolicyInformation { subject_map: SubjectMap, policy_rules: Vec, } impl PolicyEnforcer { - pub fn new() -> PolicyEnforcer { + pub(in crate::sealed) fn new() -> PolicyEnforcer { PolicyEnforcer { acl_enabled: true, default_permission: Permission::Deny, @@ -134,7 +134,7 @@ impl PolicyEnforcer { /* initializes the policy_enforcer */ - pub fn init(&mut self, acl_config: &AclConfig) -> ZResult<()> { + pub(in crate::sealed) fn init(&mut self, acl_config: &AclConfig) -> ZResult<()> { self.acl_enabled = acl_config.enabled; self.default_permission = acl_config.default_permission; if self.acl_enabled { @@ -193,7 +193,7 @@ impl PolicyEnforcer { /* converts the sets of rules from config format into individual rules for each subject, key-expr, action, permission */ - pub fn policy_information_point( + pub(in crate::sealed) fn policy_information_point( &self, config_rule_set: &Vec, ) -> ZResult { @@ -234,7 +234,7 @@ impl PolicyEnforcer { checks each msg against the ACL ruleset for allow/deny */ - pub fn policy_decision_point( + pub(in crate::sealed) fn policy_decision_point( &self, subject: usize, flow: InterceptorFlow, diff --git a/zenoh/src/sealed/net/routing/interceptor/downsampling.rs b/zenoh/src/sealed/net/routing/interceptor/downsampling.rs index 1f228d85ca..f9b1de5995 100644 --- a/zenoh/src/sealed/net/routing/interceptor/downsampling.rs +++ b/zenoh/src/sealed/net/routing/interceptor/downsampling.rs @@ -29,7 +29,7 @@ use zenoh_keyexpr::keyexpr_tree::{IKeyExprTree, IKeyExprTreeMut}; use zenoh_protocol::network::NetworkBody; use zenoh_result::ZResult; -pub(crate) fn downsampling_interceptor_factories( +pub(in crate::sealed) fn downsampling_interceptor_factories( config: &Vec, ) -> ZResult> { let mut res: Vec = vec![]; @@ -41,14 +41,14 @@ pub(crate) fn downsampling_interceptor_factories( Ok(res) } -pub struct DownsamplingInterceptorFactory { +pub(in crate::sealed) struct DownsamplingInterceptorFactory { interfaces: Option>, rules: Vec, flow: InterceptorFlow, } impl DownsamplingInterceptorFactory { - pub fn new(conf: DownsamplingItemConf) -> Self { + pub(in crate::sealed) fn new(conf: DownsamplingItemConf) -> Self { Self { interfaces: conf.interfaces, rules: conf.rules, @@ -110,11 +110,11 @@ impl InterceptorFactoryTrait for DownsamplingInterceptorFactory { } struct Timestate { - pub threshold: tokio::time::Duration, - pub latest_message_timestamp: tokio::time::Instant, + pub(in crate::sealed) threshold: tokio::time::Duration, + pub(in crate::sealed) latest_message_timestamp: tokio::time::Instant, } -pub(crate) struct DownsamplingInterceptor { +pub(in crate::sealed) struct DownsamplingInterceptor { ke_id: Arc>>, ke_state: Arc>>, } @@ -165,7 +165,7 @@ impl InterceptorTrait for DownsamplingInterceptor { const NANOS_PER_SEC: f64 = 1_000_000_000.0; impl DownsamplingInterceptor { - pub fn new(rules: Vec) -> Self { + pub(in crate::sealed) fn new(rules: Vec) -> Self { let mut ke_id = KeBoxTree::default(); let mut ke_state = HashMap::default(); for (id, rule) in rules.into_iter().enumerate() { diff --git a/zenoh/src/sealed/net/routing/interceptor/mod.rs b/zenoh/src/sealed/net/routing/interceptor/mod.rs index 6f85c24e25..7221a97c07 100644 --- a/zenoh/src/sealed/net/routing/interceptor/mod.rs +++ b/zenoh/src/sealed/net/routing/interceptor/mod.rs @@ -31,10 +31,10 @@ use zenoh_protocol::network::NetworkMessage; use zenoh_result::ZResult; use zenoh_transport::{multicast::TransportMulticast, unicast::TransportUnicast}; -pub mod downsampling; +pub(in crate::sealed) mod downsampling; use crate::sealed::net::routing::interceptor::downsampling::downsampling_interceptor_factories; -pub(crate) trait InterceptorTrait { +pub(in crate::sealed) trait InterceptorTrait { fn compute_keyexpr_cache(&self, key_expr: &KeyExpr<'_>) -> Option>; fn intercept( @@ -44,11 +44,11 @@ pub(crate) trait InterceptorTrait { ) -> Option>; } -pub(crate) type Interceptor = Box; -pub(crate) type IngressInterceptor = Interceptor; -pub(crate) type EgressInterceptor = Interceptor; +pub(in crate::sealed) type Interceptor = Box; +pub(in crate::sealed) type IngressInterceptor = Interceptor; +pub(in crate::sealed) type EgressInterceptor = Interceptor; -pub(crate) trait InterceptorFactoryTrait { +pub(in crate::sealed) trait InterceptorFactoryTrait { fn new_transport_unicast( &self, transport: &TransportUnicast, @@ -57,9 +57,11 @@ pub(crate) trait InterceptorFactoryTrait { fn new_peer_multicast(&self, transport: &TransportMulticast) -> Option; } -pub(crate) type InterceptorFactory = Box; +pub(in crate::sealed) type InterceptorFactory = Box; -pub(crate) fn interceptor_factories(config: &Config) -> ZResult> { +pub(in crate::sealed) fn interceptor_factories( + config: &Config, +) -> ZResult> { let mut res: Vec = vec![]; // Uncomment to log the interceptors initialisation // res.push(Box::new(LoggerInterceptor {})); @@ -68,13 +70,13 @@ pub(crate) fn interceptor_factories(config: &Config) -> ZResult, +pub(in crate::sealed) struct InterceptorsChain { + pub(in crate::sealed) interceptors: Vec, } impl InterceptorsChain { #[allow(dead_code)] - pub(crate) fn empty() -> Self { + pub(in crate::sealed) fn empty() -> Self { Self { interceptors: vec![], } @@ -120,13 +122,13 @@ impl InterceptorTrait for InterceptorsChain { } } -pub(crate) struct ComputeOnMiss { +pub(in crate::sealed) struct ComputeOnMiss { interceptor: T, } impl ComputeOnMiss { #[allow(dead_code)] - pub(crate) fn new(interceptor: T) -> Self { + pub(in crate::sealed) fn new(interceptor: T) -> Self { Self { interceptor } } } @@ -158,7 +160,7 @@ impl InterceptorTrait for ComputeOnMiss { } } -pub(crate) struct IngressMsgLogger {} +pub(in crate::sealed) struct IngressMsgLogger {} impl InterceptorTrait for IngressMsgLogger { fn compute_keyexpr_cache(&self, key_expr: &KeyExpr<'_>) -> Option> { @@ -185,7 +187,7 @@ impl InterceptorTrait for IngressMsgLogger { Some(ctx) } } -pub(crate) struct EgressMsgLogger {} +pub(in crate::sealed) struct EgressMsgLogger {} impl InterceptorTrait for EgressMsgLogger { fn compute_keyexpr_cache(&self, key_expr: &KeyExpr<'_>) -> Option> { @@ -212,7 +214,7 @@ impl InterceptorTrait for EgressMsgLogger { } } -pub(crate) struct LoggerInterceptor {} +pub(in crate::sealed) struct LoggerInterceptor {} impl InterceptorFactoryTrait for LoggerInterceptor { fn new_transport_unicast( diff --git a/zenoh/src/sealed/net/routing/mod.rs b/zenoh/src/sealed/net/routing/mod.rs index 75b4d4ef6a..1e7f86a2ce 100644 --- a/zenoh/src/sealed/net/routing/mod.rs +++ b/zenoh/src/sealed/net/routing/mod.rs @@ -17,10 +17,10 @@ //! This module is intended for Zenoh's internal use. //! //! [Click here for Zenoh's documentation](../zenoh/index.html) -pub mod dispatcher; -pub mod hat; -pub mod interceptor; -pub mod router; +pub(in crate::sealed) mod dispatcher; +pub(in crate::sealed) mod hat; +pub(in crate::sealed) mod interceptor; +pub(in crate::sealed) mod router; use std::{cell::OnceCell, sync::Arc}; @@ -31,19 +31,19 @@ use self::{dispatcher::face::Face, router::Resource}; use super::runtime; -pub(crate) static PREFIX_LIVELINESS: &str = "@/liveliness"; +pub(in crate::sealed) static PREFIX_LIVELINESS: &str = "@/liveliness"; -pub(crate) struct RoutingContext { - pub(crate) msg: Msg, - pub(crate) inface: OnceCell, - pub(crate) outface: OnceCell, - pub(crate) prefix: OnceCell>, - pub(crate) full_expr: OnceCell, +pub(in crate::sealed) struct RoutingContext { + pub(in crate::sealed) msg: Msg, + pub(in crate::sealed) inface: OnceCell, + pub(in crate::sealed) outface: OnceCell, + pub(in crate::sealed) prefix: OnceCell>, + pub(in crate::sealed) full_expr: OnceCell, } impl RoutingContext { #[allow(dead_code)] - pub(crate) fn new(msg: Msg) -> Self { + pub(in crate::sealed) fn new(msg: Msg) -> Self { Self { msg, inface: OnceCell::new(), @@ -54,7 +54,7 @@ impl RoutingContext { } #[allow(dead_code)] - pub(crate) fn new_in(msg: Msg, inface: Face) -> Self { + pub(in crate::sealed) fn new_in(msg: Msg, inface: Face) -> Self { Self { msg, inface: OnceCell::from(inface), @@ -65,7 +65,7 @@ impl RoutingContext { } #[allow(dead_code)] - pub(crate) fn new_out(msg: Msg, outface: Face) -> Self { + pub(in crate::sealed) fn new_out(msg: Msg, outface: Face) -> Self { Self { msg, inface: OnceCell::new(), @@ -76,7 +76,7 @@ impl RoutingContext { } #[allow(dead_code)] - pub(crate) fn with_expr(msg: Msg, expr: String) -> Self { + pub(in crate::sealed) fn with_expr(msg: Msg, expr: String) -> Self { Self { msg, inface: OnceCell::new(), @@ -87,19 +87,19 @@ impl RoutingContext { } #[allow(dead_code)] - pub(crate) fn inface(&self) -> Option<&Face> { + pub(in crate::sealed) fn inface(&self) -> Option<&Face> { self.inface.get() } #[allow(dead_code)] - pub(crate) fn outface(&self) -> Option<&Face> { + pub(in crate::sealed) fn outface(&self) -> Option<&Face> { self.outface.get() } } impl RoutingContext { #[inline] - pub(crate) fn wire_expr(&self) -> Option<&WireExpr> { + pub(in crate::sealed) fn wire_expr(&self) -> Option<&WireExpr> { use zenoh_protocol::network::DeclareBody; use zenoh_protocol::network::NetworkBody; match &self.msg.body { @@ -124,7 +124,7 @@ impl RoutingContext { } #[inline] - pub(crate) fn prefix(&self) -> Option<&Arc> { + pub(in crate::sealed) fn prefix(&self) -> Option<&Arc> { if let Some(face) = self.outface.get() { if let Some(wire_expr) = self.wire_expr() { let wire_expr = wire_expr.to_owned(); @@ -158,7 +158,7 @@ impl RoutingContext { #[inline] #[allow(dead_code)] - pub(crate) fn full_expr(&self) -> Option<&str> { + pub(in crate::sealed) fn full_expr(&self) -> Option<&str> { if self.full_expr.get().is_some() { return Some(self.full_expr.get().as_ref().unwrap()); } @@ -172,7 +172,7 @@ impl RoutingContext { } #[inline] - pub(crate) fn full_key_expr(&self) -> Option { + pub(in crate::sealed) fn full_key_expr(&self) -> Option { let full_expr = self.full_expr()?; OwnedKeyExpr::new(full_expr).ok() } diff --git a/zenoh/src/sealed/net/routing/router.rs b/zenoh/src/sealed/net/routing/router.rs index 6909e198a3..140da21a04 100644 --- a/zenoh/src/sealed/net/routing/router.rs +++ b/zenoh/src/sealed/net/routing/router.rs @@ -12,9 +12,9 @@ // ZettaScale Zenoh Team, // use super::dispatcher::face::{Face, FaceState}; -pub use super::dispatcher::pubsub::*; -pub use super::dispatcher::queries::*; -pub use super::dispatcher::resource::*; +pub(in crate::sealed) use super::dispatcher::pubsub::*; +pub(in crate::sealed) use super::dispatcher::queries::*; +pub(in crate::sealed) use super::dispatcher::resource::*; use super::dispatcher::tables::Tables; use super::dispatcher::tables::TablesLock; use super::hat; @@ -39,13 +39,13 @@ use zenoh_transport::TransportPeer; // use zenoh_collections::Timer; use zenoh_result::ZResult; -pub struct Router { +pub(in crate::sealed) struct Router { // whatami: WhatAmI, - pub tables: Arc, + pub(in crate::sealed) tables: Arc, } impl Router { - pub fn new( + pub(in crate::sealed) fn new( zid: ZenohId, whatami: WhatAmI, hlc: Option>, @@ -62,13 +62,13 @@ impl Router { } #[allow(clippy::too_many_arguments)] - pub fn init_link_state(&mut self, runtime: Runtime) { + pub(in crate::sealed) fn init_link_state(&mut self, runtime: Runtime) { let ctrl_lock = zlock!(self.tables.ctrl_lock); let mut tables = zwrite!(self.tables.tables); ctrl_lock.init(&mut tables, runtime) } - pub(crate) fn new_primitives( + pub(in crate::sealed) fn new_primitives( &self, primitives: Arc, ) -> Arc { @@ -109,7 +109,10 @@ impl Router { Arc::new(face) } - pub fn new_transport_unicast(&self, transport: TransportUnicast) -> ZResult> { + pub(in crate::sealed) fn new_transport_unicast( + &self, + transport: TransportUnicast, + ) -> ZResult> { let ctrl_lock = zlock!(self.tables.ctrl_lock); let mut tables = zwrite!(self.tables.tables); @@ -162,7 +165,10 @@ impl Router { Ok(Arc::new(DeMux::new(face, Some(transport), ingress))) } - pub fn new_transport_multicast(&self, transport: TransportMulticast) -> ZResult<()> { + pub(in crate::sealed) fn new_transport_multicast( + &self, + transport: TransportMulticast, + ) -> ZResult<()> { let ctrl_lock = zlock!(self.tables.ctrl_lock); let mut tables = zwrite!(self.tables.tables); let fid = tables.face_counter; @@ -198,7 +204,7 @@ impl Router { Ok(()) } - pub fn new_peer_multicast( + pub(in crate::sealed) fn new_peer_multicast( &self, transport: TransportMulticast, peer: TransportPeer, diff --git a/zenoh/src/sealed/net/runtime/adminspace.rs b/zenoh/src/sealed/net/runtime/adminspace.rs index 386f92a23c..8cf90e0133 100644 --- a/zenoh/src/sealed/net/runtime/adminspace.rs +++ b/zenoh/src/sealed/net/runtime/adminspace.rs @@ -12,9 +12,9 @@ // ZettaScale Zenoh Team, use super::routing::dispatcher::face::Face; use super::Runtime; -use crate::encoding::Encoding; use crate::sealed::api::builders::sample::ValueBuilderTrait; use crate::sealed::api::bytes::ZBytes; +use crate::sealed::api::encoding::Encoding; use crate::sealed::api::key_expr::KeyExpr; #[cfg(all(feature = "unstable", feature = "plugins"))] use crate::sealed::api::plugins::PluginsManager; @@ -52,7 +52,7 @@ use zenoh_protocol::{ use zenoh_result::ZResult; use zenoh_transport::unicast::TransportUnicast; -pub struct AdminContext { +pub(in crate::sealed) struct AdminContext { runtime: Runtime, version: String, metadata: serde_json::Value, @@ -146,7 +146,7 @@ impl AdminSpace { Ok(()) } - pub async fn start(runtime: &Runtime, version: String) { + pub(in crate::sealed) async fn start(runtime: &Runtime, version: String) { let zid_str = runtime.state.zid.to_string(); let whatami_str = runtime.state.whatami.to_str(); let mut config = runtime.config().lock(); @@ -332,7 +332,10 @@ impl AdminSpace { }); } - pub fn key_expr_to_string<'a>(&self, key_expr: &'a WireExpr) -> ZResult> { + pub(in crate::sealed) fn key_expr_to_string<'a>( + &self, + key_expr: &'a WireExpr, + ) -> ZResult> { if key_expr.scope == EMPTY_EXPR_ID { key_expr.suffix.as_ref().try_into() } else if key_expr.suffix.is_empty() { diff --git a/zenoh/src/sealed/net/runtime/mod.rs b/zenoh/src/sealed/net/runtime/mod.rs index 07ee11cc77..eb3e1354be 100644 --- a/zenoh/src/sealed/net/runtime/mod.rs +++ b/zenoh/src/sealed/net/runtime/mod.rs @@ -17,8 +17,8 @@ //! This module is intended for Zenoh's internal use. //! //! [Click here for Zenoh's documentation](../zenoh/index.html) -mod adminspace; -pub mod orchestrator; +pub mod adminspace; +pub(in crate::sealed) mod orchestrator; use super::primitives::DeMux; use super::routing; @@ -29,7 +29,6 @@ use crate::sealed::api::loader::{load_plugins, start_plugins}; #[cfg(all(feature = "unstable", feature = "plugins"))] use crate::sealed::api::plugins::PluginsManager; use crate::{GIT_VERSION, LONG_VERSION}; -pub use adminspace::AdminSpace; use futures::stream::StreamExt; use futures::Future; use std::any::Any; @@ -57,7 +56,7 @@ use zenoh_transport::{ TransportManager, TransportMulticastEventHandler, TransportPeer, TransportPeerEventHandler, }; -pub(crate) struct RuntimeState { +pub(in crate::sealed) struct RuntimeState { zid: ZenohId, whatami: WhatAmI, next_id: AtomicU32, @@ -78,7 +77,7 @@ pub struct WeakRuntime { } impl WeakRuntime { - pub fn upgrade(&self) -> Option { + pub(in crate::sealed) fn upgrade(&self) -> Option { self.state.upgrade().map(|state| Runtime { state }) } } @@ -217,7 +216,7 @@ impl RuntimeBuilder { // Admin space if start_admin_space { - AdminSpace::start(&runtime, LONG_VERSION.clone()).await; + adminspace::AdminSpace::start(&runtime, LONG_VERSION.clone()).await; } Ok(runtime) @@ -255,7 +254,7 @@ impl Runtime { } } - pub(crate) async fn init( + pub(in crate::sealed) async fn init( config: Config, #[cfg(all(feature = "unstable", feature = "shared-memory"))] shm_clients: Option< Arc, @@ -268,17 +267,17 @@ impl Runtime { } #[inline(always)] - pub(crate) fn manager(&self) -> &TransportManager { + pub(in crate::sealed) fn manager(&self) -> &TransportManager { &self.state.manager } #[cfg(all(feature = "unstable", feature = "plugins"))] #[inline(always)] - pub(crate) fn plugins_manager(&self) -> MutexGuard<'_, PluginsManager> { + pub(in crate::sealed) fn plugins_manager(&self) -> MutexGuard<'_, PluginsManager> { zlock!(self.state.plugins_manager) } - pub(crate) fn new_handler(&self, handler: Arc) { + pub(in crate::sealed) fn new_handler(&self, handler: Arc) { zwrite!(self.state.transport_handlers).push(handler); } @@ -322,7 +321,7 @@ impl Runtime { /// Spawns a task within runtime. /// Upon close runtime will block until this task completes - pub(crate) fn spawn(&self, future: F) -> JoinHandle<()> + pub(in crate::sealed) fn spawn(&self, future: F) -> JoinHandle<()> where F: Future + Send + 'static, T: Send + 'static, @@ -334,7 +333,7 @@ impl Runtime { /// Spawns a task within runtime. /// Upon runtime close the task will be automatically aborted. - pub(crate) fn spawn_abortable(&self, future: F) -> JoinHandle<()> + pub(in crate::sealed) fn spawn_abortable(&self, future: F) -> JoinHandle<()> where F: Future + Send + 'static, T: Send + 'static, @@ -344,7 +343,7 @@ impl Runtime { .spawn_abortable_with_rt(zenoh_runtime::ZRuntime::Net, future) } - pub(crate) fn router(&self) -> Arc { + pub(in crate::sealed) fn router(&self) -> Arc { self.state.router.clone() } diff --git a/zenoh/src/sealed/net/runtime/orchestrator.rs b/zenoh/src/sealed/net/runtime/orchestrator.rs index 687fa90649..f18f653f44 100644 --- a/zenoh/src/sealed/net/runtime/orchestrator.rs +++ b/zenoh/src/sealed/net/runtime/orchestrator.rs @@ -37,13 +37,13 @@ const SCOUT_PERIOD_INCREASE_FACTOR: u32 = 2; const ROUTER_DEFAULT_LISTENER: &str = "tcp/[::]:7447"; const PEER_DEFAULT_LISTENER: &str = "tcp/[::]:0"; -pub enum Loop { +pub(in crate::sealed) enum Loop { Continue, Break, } impl Runtime { - pub(crate) async fn start(&mut self) -> ZResult<()> { + pub(in crate::sealed) async fn start(&mut self) -> ZResult<()> { match self.whatami() { WhatAmI::Client => self.start_client().await, WhatAmI::Peer => self.start_peer().await, @@ -328,7 +328,7 @@ impl Runtime { } } - pub(crate) async fn update_peers(&self) -> ZResult<()> { + pub(in crate::sealed) async fn update_peers(&self) -> ZResult<()> { let peers = { self.state.config.lock().connect().endpoints().clone() }; let tranports = self.manager().get_transports_unicast().await; @@ -491,7 +491,7 @@ impl Runtime { } } - pub fn get_interfaces(names: &str) -> Vec { + pub(in crate::sealed) fn get_interfaces(names: &str) -> Vec { if names == "auto" { let ifaces = zenoh_util::net::get_multicast_interfaces(); if ifaces.is_empty() { @@ -525,7 +525,10 @@ impl Runtime { } } - pub async fn bind_mcast_port(sockaddr: &SocketAddr, ifaces: &[IpAddr]) -> ZResult { + pub(in crate::sealed) async fn bind_mcast_port( + sockaddr: &SocketAddr, + ifaces: &[IpAddr], + ) -> ZResult { let socket = match Socket::new(Domain::IPV4, Type::DGRAM, None) { Ok(socket) => socket, Err(err) => { @@ -610,7 +613,7 @@ impl Runtime { Ok(udp_socket) } - pub fn bind_ucast_port(addr: IpAddr) -> ZResult { + pub(in crate::sealed) fn bind_ucast_port(addr: IpAddr) -> ZResult { let socket = match Socket::new(Domain::IPV4, Type::DGRAM, None) { Ok(socket) => socket, Err(err) => { @@ -703,7 +706,7 @@ impl Runtime { } } - pub async fn scout( + pub(in crate::sealed) async fn scout( sockets: &[UdpSocket], matcher: WhatAmIMatcher, mcast_addr: &SocketAddr, @@ -861,7 +864,7 @@ impl Runtime { false } - pub async fn connect_peer(&self, zid: &ZenohId, locators: &[Locator]) { + pub(in crate::sealed) async fn connect_peer(&self, zid: &ZenohId, locators: &[Locator]) { let manager = self.manager(); if zid != &manager.zid() { let has_unicast = manager.get_transport_unicast(zid).await.is_some(); diff --git a/zenoh/src/sealed/net/tests/mod.rs b/zenoh/src/sealed/net/tests/mod.rs index b8b42bef12..f2da1d4677 100644 --- a/zenoh/src/sealed/net/tests/mod.rs +++ b/zenoh/src/sealed/net/tests/mod.rs @@ -1 +1 @@ -pub(crate) mod tables; +pub(in crate::sealed) mod tables; diff --git a/zenoh/src/sealed/net/tests/tables.rs b/zenoh/src/sealed/net/tests/tables.rs index 0821fd629d..ecf85bcdf7 100644 --- a/zenoh/src/sealed/net/tests/tables.rs +++ b/zenoh/src/sealed/net/tests/tables.rs @@ -443,20 +443,20 @@ async fn clean_test() { assert!(res3.upgrade().is_none()); } -pub struct ClientPrimitives { +pub(in crate::sealed) struct ClientPrimitives { data: std::sync::Mutex>>, mapping: std::sync::Mutex>, } impl ClientPrimitives { - pub fn new() -> ClientPrimitives { + pub(in crate::sealed) fn new() -> ClientPrimitives { ClientPrimitives { data: std::sync::Mutex::new(None), mapping: std::sync::Mutex::new(std::collections::HashMap::new()), } } - pub fn clear_data(&self) { + pub(in crate::sealed) fn clear_data(&self) { *self.data.lock().unwrap() = None; } } diff --git a/zenoh/tests/session.rs b/zenoh/tests/session.rs index 91d9b6d95b..27076e6c33 100644 --- a/zenoh/tests/session.rs +++ b/zenoh/tests/session.rs @@ -287,6 +287,7 @@ async fn open_session_unicast_runtime(endpoints: &[&str]) -> (Runtime, Runtime) (r1, r2) } +#[cfg(feature = "unstable")] #[tokio::test(flavor = "multi_thread", worker_threads = 4)] async fn zenoh_2sessions_1runtime_init() { let (r1, r2) = open_session_unicast_runtime(&["tcp/127.0.0.1:17449"]).await;