diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 084a3b148f..cb57db3abe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,7 +47,7 @@ jobs: uses: Swatinem/rust-cache@v2 - name: Code format check - run: cargo fmt --check + run: cargo fmt --check -- --config "unstable_features=true,imports_granularity=Crate,group_imports=StdExternalCrate" - name: Clippy run: cargo +stable clippy --all-targets -- --deny warnings diff --git a/.github/workflows/pre-release.yml b/.github/workflows/pre-release.yml index 9452e0da86..bb245d4747 100644 --- a/.github/workflows/pre-release.yml +++ b/.github/workflows/pre-release.yml @@ -53,7 +53,7 @@ jobs: run: rustup component add rustfmt clippy - name: Code format check - run: cargo fmt --check + run: cargo fmt --check -- cargo fmt --check -- --config "unstable_features=true,imports_granularity=Crate,group_imports=StdExternalCrate" env: CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse diff --git a/commons/zenoh-buffers/src/bbuf.rs b/commons/zenoh-buffers/src/bbuf.rs index 687961aa5e..72491ae704 100644 --- a/commons/zenoh-buffers/src/bbuf.rs +++ b/commons/zenoh-buffers/src/bbuf.rs @@ -11,6 +11,11 @@ // Contributors: // ZettaScale Zenoh Team, // +#[cfg(not(feature = "std"))] +use alloc::boxed::Box; +use alloc::sync::Arc; +use core::{fmt, num::NonZeroUsize, option}; + use crate::{ buffer::{Buffer, SplitBuffer}, reader::HasReader, @@ -18,11 +23,6 @@ use crate::{ writer::{BacktrackableWriter, DidntWrite, HasWriter, Writer}, ZSlice, }; -use alloc::sync::Arc; -use core::{fmt, num::NonZeroUsize, option}; - -#[cfg(not(feature = "std"))] -use alloc::boxed::Box; #[derive(Clone, PartialEq, Eq)] pub struct BBuf { @@ -199,6 +199,7 @@ impl BBuf { pub fn rand(len: usize) -> Self { #[cfg(not(feature = "std"))] use alloc::vec::Vec; + use rand::Rng; let mut rng = rand::thread_rng(); diff --git a/commons/zenoh-buffers/src/lib.rs b/commons/zenoh-buffers/src/lib.rs index 117fb412b7..da0cdd4030 100644 --- a/commons/zenoh-buffers/src/lib.rs +++ b/commons/zenoh-buffers/src/lib.rs @@ -113,9 +113,10 @@ pub mod buffer { } pub mod writer { - use crate::ZSlice; use core::num::NonZeroUsize; + use crate::ZSlice; + #[derive(Debug, Clone, Copy)] pub struct DidntWrite; @@ -156,9 +157,10 @@ pub mod writer { } pub mod reader { - use crate::ZSlice; use core::num::NonZeroUsize; + use crate::ZSlice; + #[derive(Debug, Clone, Copy)] pub struct DidntRead; diff --git a/commons/zenoh-buffers/src/slice.rs b/commons/zenoh-buffers/src/slice.rs index a652c6930e..f26e37a2aa 100644 --- a/commons/zenoh-buffers/src/slice.rs +++ b/commons/zenoh-buffers/src/slice.rs @@ -11,12 +11,6 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::{ - buffer::{Buffer, SplitBuffer}, - reader::{BacktrackableReader, DidntRead, DidntSiphon, HasReader, Reader, SiphonableReader}, - writer::{BacktrackableWriter, DidntWrite, HasWriter, Writer}, - ZSlice, -}; use core::{ marker::PhantomData, mem, @@ -25,6 +19,13 @@ use core::{ slice::{self}, }; +use crate::{ + buffer::{Buffer, SplitBuffer}, + reader::{BacktrackableReader, DidntRead, DidntSiphon, HasReader, Reader, SiphonableReader}, + writer::{BacktrackableWriter, DidntWrite, HasWriter, Writer}, + ZSlice, +}; + // Buffer impl Buffer for &[u8] { #[inline(always)] diff --git a/commons/zenoh-buffers/src/vec.rs b/commons/zenoh-buffers/src/vec.rs index bc2edf87bb..9d63880aea 100644 --- a/commons/zenoh-buffers/src/vec.rs +++ b/commons/zenoh-buffers/src/vec.rs @@ -11,15 +11,15 @@ // Contributors: // ZettaScale Zenoh Team, // +#[cfg(not(feature = "std"))] +use alloc::vec::Vec; +use core::{mem, num::NonZeroUsize, option}; + use crate::{ buffer::{Buffer, SplitBuffer}, reader::HasReader, writer::{BacktrackableWriter, DidntWrite, HasWriter, Writer}, }; -use core::{mem, num::NonZeroUsize, option}; - -#[cfg(not(feature = "std"))] -use alloc::vec::Vec; /// Allocate a vector with a given capacity and sets the length to that capacity. #[must_use] diff --git a/commons/zenoh-buffers/src/zbuf.rs b/commons/zenoh-buffers/src/zbuf.rs index 616dbb1b96..50eb54c923 100644 --- a/commons/zenoh-buffers/src/zbuf.rs +++ b/commons/zenoh-buffers/src/zbuf.rs @@ -11,6 +11,13 @@ // Contributors: // ZettaScale Zenoh Team, // +use alloc::{sync::Arc, vec::Vec}; +use core::{cmp, iter, mem, num::NonZeroUsize, ops::RangeBounds, ptr}; +#[cfg(feature = "std")] +use std::io; + +use zenoh_collections::SingleOrVec; + #[cfg(feature = "shared-memory")] use crate::ZSliceKind; use crate::{ @@ -22,11 +29,6 @@ use crate::{ writer::{BacktrackableWriter, DidntWrite, HasWriter, Writer}, ZSlice, ZSliceBuffer, }; -use alloc::{sync::Arc, vec::Vec}; -use core::{cmp, iter, mem, num::NonZeroUsize, ops::RangeBounds, ptr}; -#[cfg(feature = "std")] -use std::io; -use zenoh_collections::SingleOrVec; fn get_mut_unchecked(arc: &mut Arc) -> &mut T { unsafe { &mut (*(Arc::as_ptr(arc) as *mut T)) } @@ -776,9 +778,10 @@ mod tests { #[cfg(feature = "std")] #[test] fn zbuf_seek() { + use std::io::Seek; + use super::{HasReader, ZBuf}; use crate::reader::Reader; - use std::io::Seek; let mut buf = ZBuf::empty(); buf.push_zslice([0u8, 1u8, 2u8, 3u8].into()); diff --git a/commons/zenoh-buffers/src/zslice.rs b/commons/zenoh-buffers/src/zslice.rs index 60dbdab5e1..c169fcd4c0 100644 --- a/commons/zenoh-buffers/src/zslice.rs +++ b/commons/zenoh-buffers/src/zslice.rs @@ -11,10 +11,6 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::{ - buffer::{Buffer, SplitBuffer}, - reader::{BacktrackableReader, DidntRead, HasReader, Reader}, -}; use alloc::{boxed::Box, sync::Arc, vec::Vec}; use core::{ any::Any, @@ -25,6 +21,11 @@ use core::{ option, }; +use crate::{ + buffer::{Buffer, SplitBuffer}, + reader::{BacktrackableReader, DidntRead, HasReader, Reader}, +}; + /*************************************/ /* ZSLICE BUFFER */ /*************************************/ diff --git a/commons/zenoh-buffers/tests/readwrite.rs b/commons/zenoh-buffers/tests/readwrite.rs index ea48218a85..cdfc8fea05 100644 --- a/commons/zenoh-buffers/tests/readwrite.rs +++ b/commons/zenoh-buffers/tests/readwrite.rs @@ -14,8 +14,8 @@ use zenoh_buffers::{ reader::{HasReader, Reader, SiphonableReader}, writer::{BacktrackableWriter, HasWriter, Writer}, + BBuf, ZBuf, ZSlice, }; -use zenoh_buffers::{BBuf, ZBuf, ZSlice}; const BYTES: usize = 18; diff --git a/commons/zenoh-codec/src/common/extension.rs b/commons/zenoh-codec/src/common/extension.rs index 6c22f8ff01..21d716a769 100644 --- a/commons/zenoh-codec/src/common/extension.rs +++ b/commons/zenoh-codec/src/common/extension.rs @@ -11,8 +11,8 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::{RCodec, WCodec, Zenoh080, Zenoh080Bounded, Zenoh080Header}; use alloc::vec::Vec; + use zenoh_buffers::{ reader::{DidntRead, Reader}, writer::{DidntWrite, Writer}, @@ -22,6 +22,8 @@ use zenoh_protocol::common::{ iext, imsg::has_flag, ZExtBody, ZExtUnit, ZExtUnknown, ZExtZ64, ZExtZBuf, ZExtZBufHeader, }; +use crate::{RCodec, WCodec, Zenoh080, Zenoh080Bounded, Zenoh080Header}; + fn read_inner(reader: &mut R, _s: &str, header: u8) -> Result<(ZExtUnknown, bool), DidntRead> where R: Reader, diff --git a/commons/zenoh-codec/src/core/encoding.rs b/commons/zenoh-codec/src/core/encoding.rs index c8033cdd5f..abe33f6ab8 100644 --- a/commons/zenoh-codec/src/core/encoding.rs +++ b/commons/zenoh-codec/src/core/encoding.rs @@ -11,7 +11,6 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::{LCodec, RCodec, WCodec, Zenoh080, Zenoh080Bounded}; use zenoh_buffers::{ reader::{DidntRead, Reader}, writer::{DidntWrite, Writer}, @@ -21,6 +20,8 @@ use zenoh_protocol::{ core::encoding::{flag, Encoding, EncodingId}, }; +use crate::{LCodec, RCodec, WCodec, Zenoh080, Zenoh080Bounded}; + impl LCodec<&Encoding> for Zenoh080 { fn w_len(self, x: &Encoding) -> usize { let mut len = self.w_len((x.id as u32) << 1); diff --git a/commons/zenoh-codec/src/core/locator.rs b/commons/zenoh-codec/src/core/locator.rs index 0bbd28a189..464b1bbb05 100644 --- a/commons/zenoh-codec/src/core/locator.rs +++ b/commons/zenoh-codec/src/core/locator.rs @@ -11,15 +11,17 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::{RCodec, WCodec, Zenoh080, Zenoh080Bounded}; use alloc::{string::String, vec::Vec}; use core::convert::TryFrom; + use zenoh_buffers::{ reader::{DidntRead, Reader}, writer::{DidntWrite, Writer}, }; use zenoh_protocol::core::Locator; +use crate::{RCodec, WCodec, Zenoh080, Zenoh080Bounded}; + impl WCodec<&Locator, &mut W> for Zenoh080 where W: Writer, diff --git a/commons/zenoh-codec/src/core/mod.rs b/commons/zenoh-codec/src/core/mod.rs index c8e19f057f..8230cdd9ac 100644 --- a/commons/zenoh-codec/src/core/mod.rs +++ b/commons/zenoh-codec/src/core/mod.rs @@ -22,13 +22,15 @@ mod zenohid; mod zint; mod zslice; -use crate::{LCodec, RCodec, WCodec, Zenoh080, Zenoh080Bounded}; use alloc::{string::String, vec::Vec}; + use zenoh_buffers::{ reader::{DidntRead, Reader}, writer::{DidntWrite, Writer}, }; +use crate::{LCodec, RCodec, WCodec, Zenoh080, Zenoh080Bounded}; + // [u8; N] macro_rules! array_impl { ($n:expr) => { diff --git a/commons/zenoh-codec/src/core/shm.rs b/commons/zenoh-codec/src/core/shm.rs index 2548e4ed14..e25496a268 100644 --- a/commons/zenoh-codec/src/core/shm.rs +++ b/commons/zenoh-codec/src/core/shm.rs @@ -11,7 +11,6 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::{RCodec, WCodec, Zenoh080}; use zenoh_buffers::{ reader::{DidntRead, Reader}, writer::{DidntWrite, Writer}, @@ -21,6 +20,8 @@ use zenoh_shm::{ watchdog::descriptor::Descriptor, SharedMemoryBufInfo, }; +use crate::{RCodec, WCodec, Zenoh080}; + impl WCodec<&Descriptor, &mut W> for Zenoh080 where W: Writer, diff --git a/commons/zenoh-codec/src/core/timestamp.rs b/commons/zenoh-codec/src/core/timestamp.rs index 4891643192..025f8f8bf5 100644 --- a/commons/zenoh-codec/src/core/timestamp.rs +++ b/commons/zenoh-codec/src/core/timestamp.rs @@ -11,14 +11,16 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::{LCodec, RCodec, WCodec, Zenoh080}; use core::convert::TryFrom; + use zenoh_buffers::{ reader::{DidntRead, Reader}, writer::{DidntWrite, Writer}, }; use zenoh_protocol::core::{Timestamp, ZenohId}; +use crate::{LCodec, RCodec, WCodec, Zenoh080}; + impl LCodec<&Timestamp> for Zenoh080 { fn w_len(self, x: &Timestamp) -> usize { self.w_len(x.get_time().as_u64()) + self.w_len(x.get_id().size()) diff --git a/commons/zenoh-codec/src/core/wire_expr.rs b/commons/zenoh-codec/src/core/wire_expr.rs index aa6f77b379..d5b91f75ed 100644 --- a/commons/zenoh-codec/src/core/wire_expr.rs +++ b/commons/zenoh-codec/src/core/wire_expr.rs @@ -11,8 +11,8 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::{core::Zenoh080Bounded, RCodec, WCodec, Zenoh080, Zenoh080Condition}; use alloc::string::String; + use zenoh_buffers::{ reader::{DidntRead, Reader}, writer::{DidntWrite, Writer}, @@ -22,6 +22,8 @@ use zenoh_protocol::{ network::Mapping, }; +use crate::{core::Zenoh080Bounded, RCodec, WCodec, Zenoh080, Zenoh080Condition}; + impl WCodec<&WireExpr<'_>, &mut W> for Zenoh080 where W: Writer, diff --git a/commons/zenoh-codec/src/core/zbuf.rs b/commons/zenoh-codec/src/core/zbuf.rs index 137030e66c..8b8ead6ca0 100644 --- a/commons/zenoh-codec/src/core/zbuf.rs +++ b/commons/zenoh-codec/src/core/zbuf.rs @@ -11,7 +11,6 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::{LCodec, RCodec, WCodec, Zenoh080, Zenoh080Bounded}; use zenoh_buffers::{ buffer::Buffer, reader::{DidntRead, Reader}, @@ -19,6 +18,8 @@ use zenoh_buffers::{ ZBuf, }; +use crate::{LCodec, RCodec, WCodec, Zenoh080, Zenoh080Bounded}; + // ZBuf bounded macro_rules! zbuf_impl { ($bound:ty) => { @@ -100,9 +101,10 @@ impl LCodec<&ZBuf> for Zenoh080 { // ZBuf sliced #[cfg(feature = "shared-memory")] mod shm { + use zenoh_buffers::{ZSlice, ZSliceKind}; + use super::*; use crate::Zenoh080Sliced; - use zenoh_buffers::{ZSlice, ZSliceKind}; const RAW: u8 = 0; const SHM_PTR: u8 = 1; diff --git a/commons/zenoh-codec/src/core/zenohid.rs b/commons/zenoh-codec/src/core/zenohid.rs index 6c53d4e63f..5098cad534 100644 --- a/commons/zenoh-codec/src/core/zenohid.rs +++ b/commons/zenoh-codec/src/core/zenohid.rs @@ -11,14 +11,16 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::{LCodec, RCodec, WCodec, Zenoh080, Zenoh080Length}; use core::convert::TryFrom; + use zenoh_buffers::{ reader::{DidntRead, Reader}, writer::{DidntWrite, Writer}, }; use zenoh_protocol::core::ZenohId; +use crate::{LCodec, RCodec, WCodec, Zenoh080, Zenoh080Length}; + impl LCodec<&ZenohId> for Zenoh080 { fn w_len(self, x: &ZenohId) -> usize { x.size() diff --git a/commons/zenoh-codec/src/core/zint.rs b/commons/zenoh-codec/src/core/zint.rs index d5160e2ee6..a29f88f3d5 100644 --- a/commons/zenoh-codec/src/core/zint.rs +++ b/commons/zenoh-codec/src/core/zint.rs @@ -11,12 +11,13 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::{LCodec, RCodec, WCodec, Zenoh080, Zenoh080Bounded}; use zenoh_buffers::{ reader::{DidntRead, Reader}, writer::{DidntWrite, Writer}, }; +use crate::{LCodec, RCodec, WCodec, Zenoh080, Zenoh080Bounded}; + const VLE_LEN_MAX: usize = vle_len(u64::MAX); const fn vle_len(x: u64) -> usize { diff --git a/commons/zenoh-codec/src/core/zslice.rs b/commons/zenoh-codec/src/core/zslice.rs index cea0961b51..fe907ed273 100644 --- a/commons/zenoh-codec/src/core/zslice.rs +++ b/commons/zenoh-codec/src/core/zslice.rs @@ -11,13 +11,14 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::{RCodec, WCodec, Zenoh080, Zenoh080Bounded}; use zenoh_buffers::{ reader::{DidntRead, Reader}, writer::{DidntWrite, Writer}, ZSlice, }; +use crate::{RCodec, WCodec, Zenoh080, Zenoh080Bounded}; + // ZSlice - Bounded macro_rules! zslice_impl { ($bound:ty) => { diff --git a/commons/zenoh-codec/src/network/declare.rs b/commons/zenoh-codec/src/network/declare.rs index ed3d019950..faffb04952 100644 --- a/commons/zenoh-codec/src/network/declare.rs +++ b/commons/zenoh-codec/src/network/declare.rs @@ -11,8 +11,8 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::{common::extension, RCodec, WCodec, Zenoh080, Zenoh080Condition, Zenoh080Header}; use alloc::string::String; + use zenoh_buffers::{ reader::{DidntRead, Reader}, writer::{DidntWrite, HasWriter, Writer}, @@ -27,6 +27,8 @@ use zenoh_protocol::{ }, }; +use crate::{common::extension, RCodec, WCodec, Zenoh080, Zenoh080Condition, Zenoh080Header}; + // Declaration impl WCodec<&DeclareBody, &mut W> for Zenoh080 where diff --git a/commons/zenoh-codec/src/network/interest.rs b/commons/zenoh-codec/src/network/interest.rs index 852e106f98..2deda7748a 100644 --- a/commons/zenoh-codec/src/network/interest.rs +++ b/commons/zenoh-codec/src/network/interest.rs @@ -11,7 +11,6 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::{common::extension, RCodec, WCodec, Zenoh080, Zenoh080Condition, Zenoh080Header}; use zenoh_buffers::{ reader::{DidntRead, Reader}, writer::{DidntWrite, Writer}, @@ -29,6 +28,8 @@ use zenoh_protocol::{ }, }; +use crate::{common::extension, RCodec, WCodec, Zenoh080, Zenoh080Condition, Zenoh080Header}; + // Interest impl WCodec<&Interest, &mut W> for Zenoh080 where diff --git a/commons/zenoh-codec/src/network/mod.rs b/commons/zenoh-codec/src/network/mod.rs index 5ebdb17b8e..fe9d254ee8 100644 --- a/commons/zenoh-codec/src/network/mod.rs +++ b/commons/zenoh-codec/src/network/mod.rs @@ -18,9 +18,6 @@ mod push; mod request; mod response; -use crate::{ - LCodec, RCodec, WCodec, Zenoh080, Zenoh080Header, Zenoh080Length, Zenoh080Reliability, -}; use zenoh_buffers::{ reader::{DidntRead, Reader}, writer::{DidntWrite, Writer}, @@ -31,6 +28,10 @@ use zenoh_protocol::{ network::{ext::EntityGlobalIdType, *}, }; +use crate::{ + LCodec, RCodec, WCodec, Zenoh080, Zenoh080Header, Zenoh080Length, Zenoh080Reliability, +}; + // NetworkMessage impl WCodec<&NetworkMessage, &mut W> for Zenoh080 where diff --git a/commons/zenoh-codec/src/network/oam.rs b/commons/zenoh-codec/src/network/oam.rs index 9751e9952d..172b3f1058 100644 --- a/commons/zenoh-codec/src/network/oam.rs +++ b/commons/zenoh-codec/src/network/oam.rs @@ -11,7 +11,6 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::{common::extension, RCodec, WCodec, Zenoh080, Zenoh080Header}; use zenoh_buffers::{ reader::{DidntRead, Reader}, writer::{DidntWrite, Writer}, @@ -25,6 +24,8 @@ use zenoh_protocol::{ }, }; +use crate::{common::extension, RCodec, WCodec, Zenoh080, Zenoh080Header}; + impl WCodec<&Oam, &mut W> for Zenoh080 where W: Writer, diff --git a/commons/zenoh-codec/src/network/push.rs b/commons/zenoh-codec/src/network/push.rs index b9ec2ba5db..2c2e11a718 100644 --- a/commons/zenoh-codec/src/network/push.rs +++ b/commons/zenoh-codec/src/network/push.rs @@ -11,7 +11,6 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::{common::extension, RCodec, WCodec, Zenoh080, Zenoh080Condition, Zenoh080Header}; use zenoh_buffers::{ reader::{DidntRead, Reader}, writer::{DidntWrite, Writer}, @@ -27,6 +26,8 @@ use zenoh_protocol::{ zenoh::PushBody, }; +use crate::{common::extension, RCodec, WCodec, Zenoh080, Zenoh080Condition, Zenoh080Header}; + impl WCodec<&Push, &mut W> for Zenoh080 where W: Writer, diff --git a/commons/zenoh-codec/src/network/request.rs b/commons/zenoh-codec/src/network/request.rs index 6173840d7e..21f42709c4 100644 --- a/commons/zenoh-codec/src/network/request.rs +++ b/commons/zenoh-codec/src/network/request.rs @@ -11,9 +11,6 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::{ - common::extension, RCodec, WCodec, Zenoh080, Zenoh080Bounded, Zenoh080Condition, Zenoh080Header, -}; use zenoh_buffers::{ reader::{DidntRead, Reader}, writer::{DidntWrite, Writer}, @@ -29,6 +26,10 @@ use zenoh_protocol::{ zenoh::RequestBody, }; +use crate::{ + common::extension, RCodec, WCodec, Zenoh080, Zenoh080Bounded, Zenoh080Condition, Zenoh080Header, +}; + // Target impl WCodec<(&ext::TargetType, bool), &mut W> for Zenoh080 where diff --git a/commons/zenoh-codec/src/network/response.rs b/commons/zenoh-codec/src/network/response.rs index 5b69e8b109..d94316de8e 100644 --- a/commons/zenoh-codec/src/network/response.rs +++ b/commons/zenoh-codec/src/network/response.rs @@ -11,9 +11,6 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::{ - common::extension, RCodec, WCodec, Zenoh080, Zenoh080Bounded, Zenoh080Condition, Zenoh080Header, -}; use zenoh_buffers::{ reader::{DidntRead, Reader}, writer::{DidntWrite, Writer}, @@ -29,6 +26,10 @@ use zenoh_protocol::{ zenoh::ResponseBody, }; +use crate::{ + common::extension, RCodec, WCodec, Zenoh080, Zenoh080Bounded, Zenoh080Condition, Zenoh080Header, +}; + // Response impl WCodec<&Response, &mut W> for Zenoh080 where diff --git a/commons/zenoh-codec/src/scouting/hello.rs b/commons/zenoh-codec/src/scouting/hello.rs index 430201133e..c3aff83667 100644 --- a/commons/zenoh-codec/src/scouting/hello.rs +++ b/commons/zenoh-codec/src/scouting/hello.rs @@ -11,8 +11,8 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::{RCodec, WCodec, Zenoh080, Zenoh080Header, Zenoh080Length}; use alloc::{vec, vec::Vec}; + use zenoh_buffers::{ reader::{DidntRead, Reader}, writer::{DidntWrite, Writer}, @@ -26,6 +26,8 @@ use zenoh_protocol::{ }, }; +use crate::{RCodec, WCodec, Zenoh080, Zenoh080Header, Zenoh080Length}; + impl WCodec<&Hello, &mut W> for Zenoh080 where W: Writer, diff --git a/commons/zenoh-codec/src/scouting/mod.rs b/commons/zenoh-codec/src/scouting/mod.rs index bbedce4282..d1f0b883a1 100644 --- a/commons/zenoh-codec/src/scouting/mod.rs +++ b/commons/zenoh-codec/src/scouting/mod.rs @@ -14,7 +14,6 @@ mod hello; mod scout; -use crate::{RCodec, WCodec, Zenoh080, Zenoh080Header}; use zenoh_buffers::{ reader::{DidntRead, Reader}, writer::{DidntWrite, Writer}, @@ -24,6 +23,8 @@ use zenoh_protocol::{ scouting::{id, ScoutingBody, ScoutingMessage}, }; +use crate::{RCodec, WCodec, Zenoh080, Zenoh080Header}; + impl WCodec<&ScoutingMessage, &mut W> for Zenoh080 where W: Writer, diff --git a/commons/zenoh-codec/src/scouting/scout.rs b/commons/zenoh-codec/src/scouting/scout.rs index 02d5294047..888ce2954f 100644 --- a/commons/zenoh-codec/src/scouting/scout.rs +++ b/commons/zenoh-codec/src/scouting/scout.rs @@ -11,8 +11,8 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::{RCodec, WCodec, Zenoh080, Zenoh080Header, Zenoh080Length}; use core::convert::TryFrom; + use zenoh_buffers::{ reader::{DidntRead, Reader}, writer::{DidntWrite, Writer}, @@ -26,6 +26,8 @@ use zenoh_protocol::{ }, }; +use crate::{RCodec, WCodec, Zenoh080, Zenoh080Header, Zenoh080Length}; + impl WCodec<&Scout, &mut W> for Zenoh080 where W: Writer, diff --git a/commons/zenoh-codec/src/transport/batch.rs b/commons/zenoh-codec/src/transport/batch.rs index 525336d6e8..a08e796358 100644 --- a/commons/zenoh-codec/src/transport/batch.rs +++ b/commons/zenoh-codec/src/transport/batch.rs @@ -11,17 +11,23 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::{RCodec, WCodec, Zenoh080}; use core::num::NonZeroUsize; -use zenoh_buffers::reader::{BacktrackableReader, DidntRead, Reader, SiphonableReader}; -use zenoh_buffers::writer::{BacktrackableWriter, DidntWrite, Writer}; -use zenoh_buffers::ZBufReader; -use zenoh_protocol::core::Reliability; -use zenoh_protocol::network::NetworkMessage; -use zenoh_protocol::transport::{ - Fragment, FragmentHeader, Frame, FrameHeader, TransportBody, TransportMessage, TransportSn, + +use zenoh_buffers::{ + reader::{BacktrackableReader, DidntRead, Reader, SiphonableReader}, + writer::{BacktrackableWriter, DidntWrite, Writer}, + ZBufReader, +}; +use zenoh_protocol::{ + core::Reliability, + network::NetworkMessage, + transport::{ + Fragment, FragmentHeader, Frame, FrameHeader, TransportBody, TransportMessage, TransportSn, + }, }; +use crate::{RCodec, WCodec, Zenoh080}; + #[derive(Clone, Copy, Debug)] #[repr(u8)] pub enum CurrentFrame { diff --git a/commons/zenoh-codec/src/transport/close.rs b/commons/zenoh-codec/src/transport/close.rs index 9771b9e1e9..62d9e542b7 100644 --- a/commons/zenoh-codec/src/transport/close.rs +++ b/commons/zenoh-codec/src/transport/close.rs @@ -11,7 +11,6 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::{common::extension, RCodec, WCodec, Zenoh080, Zenoh080Header}; use zenoh_buffers::{ reader::{DidntRead, Reader}, writer::{DidntWrite, Writer}, @@ -24,6 +23,8 @@ use zenoh_protocol::{ }, }; +use crate::{common::extension, RCodec, WCodec, Zenoh080, Zenoh080Header}; + impl WCodec<&Close, &mut W> for Zenoh080 where W: Writer, diff --git a/commons/zenoh-codec/src/transport/fragment.rs b/commons/zenoh-codec/src/transport/fragment.rs index b01e2c2bae..fc30abce9d 100644 --- a/commons/zenoh-codec/src/transport/fragment.rs +++ b/commons/zenoh-codec/src/transport/fragment.rs @@ -11,7 +11,6 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::{common::extension, RCodec, WCodec, Zenoh080, Zenoh080Header}; use zenoh_buffers::{ reader::{BacktrackableReader, DidntRead, Reader}, writer::{DidntWrite, Writer}, @@ -25,6 +24,8 @@ use zenoh_protocol::{ }, }; +use crate::{common::extension, RCodec, WCodec, Zenoh080, Zenoh080Header}; + // FragmentHeader impl WCodec<&FragmentHeader, &mut W> for Zenoh080 where diff --git a/commons/zenoh-codec/src/transport/frame.rs b/commons/zenoh-codec/src/transport/frame.rs index ab82a024c4..6db4e70652 100644 --- a/commons/zenoh-codec/src/transport/frame.rs +++ b/commons/zenoh-codec/src/transport/frame.rs @@ -11,8 +11,8 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::{common::extension, RCodec, WCodec, Zenoh080, Zenoh080Header, Zenoh080Reliability}; use alloc::vec::Vec; + use zenoh_buffers::{ reader::{BacktrackableReader, DidntRead, Reader}, writer::{DidntWrite, Writer}, @@ -27,6 +27,8 @@ use zenoh_protocol::{ }, }; +use crate::{common::extension, RCodec, WCodec, Zenoh080, Zenoh080Header, Zenoh080Reliability}; + // FrameHeader impl WCodec<&FrameHeader, &mut W> for Zenoh080 where diff --git a/commons/zenoh-codec/src/transport/init.rs b/commons/zenoh-codec/src/transport/init.rs index fec9f07afd..55e129799c 100644 --- a/commons/zenoh-codec/src/transport/init.rs +++ b/commons/zenoh-codec/src/transport/init.rs @@ -11,9 +11,6 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::{ - common::extension, RCodec, WCodec, Zenoh080, Zenoh080Bounded, Zenoh080Header, Zenoh080Length, -}; use zenoh_buffers::{ reader::{DidntRead, Reader}, writer::{DidntWrite, Writer}, @@ -29,6 +26,10 @@ use zenoh_protocol::{ }, }; +use crate::{ + common::extension, RCodec, WCodec, Zenoh080, Zenoh080Bounded, Zenoh080Header, Zenoh080Length, +}; + // InitSyn impl WCodec<&InitSyn, &mut W> for Zenoh080 where diff --git a/commons/zenoh-codec/src/transport/join.rs b/commons/zenoh-codec/src/transport/join.rs index d87ceecc78..896d7f6290 100644 --- a/commons/zenoh-codec/src/transport/join.rs +++ b/commons/zenoh-codec/src/transport/join.rs @@ -11,9 +11,9 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::{common::extension, LCodec, RCodec, WCodec, Zenoh080, Zenoh080Header, Zenoh080Length}; use alloc::boxed::Box; use core::time::Duration; + use zenoh_buffers::{ reader::{DidntRead, Reader}, writer::{DidntWrite, Writer}, @@ -28,6 +28,8 @@ use zenoh_protocol::{ }, }; +use crate::{common::extension, LCodec, RCodec, WCodec, Zenoh080, Zenoh080Header, Zenoh080Length}; + impl LCodec<&PrioritySn> for Zenoh080 { fn w_len(self, p: &PrioritySn) -> usize { let PrioritySn { diff --git a/commons/zenoh-codec/src/transport/keepalive.rs b/commons/zenoh-codec/src/transport/keepalive.rs index aa6726f50b..44ef4c676a 100644 --- a/commons/zenoh-codec/src/transport/keepalive.rs +++ b/commons/zenoh-codec/src/transport/keepalive.rs @@ -11,7 +11,6 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::{common::extension, RCodec, WCodec, Zenoh080, Zenoh080Header}; use zenoh_buffers::{ reader::{DidntRead, Reader}, writer::{DidntWrite, Writer}, @@ -24,6 +23,8 @@ use zenoh_protocol::{ }, }; +use crate::{common::extension, RCodec, WCodec, Zenoh080, Zenoh080Header}; + impl WCodec<&KeepAlive, &mut W> for Zenoh080 where W: Writer, diff --git a/commons/zenoh-codec/src/transport/mod.rs b/commons/zenoh-codec/src/transport/mod.rs index 559b5b5fda..3adae0fb72 100644 --- a/commons/zenoh-codec/src/transport/mod.rs +++ b/commons/zenoh-codec/src/transport/mod.rs @@ -21,7 +21,6 @@ mod keepalive; mod oam; mod open; -use crate::{RCodec, WCodec, Zenoh080, Zenoh080Header}; use zenoh_buffers::{ reader::{BacktrackableReader, DidntRead, Reader}, writer::{DidntWrite, Writer}, @@ -32,6 +31,8 @@ use zenoh_protocol::{ transport::*, }; +use crate::{RCodec, WCodec, Zenoh080, Zenoh080Header}; + // TransportMessageLowLatency impl WCodec<&TransportMessageLowLatency, &mut W> for Zenoh080 where diff --git a/commons/zenoh-codec/src/transport/oam.rs b/commons/zenoh-codec/src/transport/oam.rs index 6861f638d3..156a0ce1ff 100644 --- a/commons/zenoh-codec/src/transport/oam.rs +++ b/commons/zenoh-codec/src/transport/oam.rs @@ -11,7 +11,6 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::{common::extension, RCodec, WCodec, Zenoh080, Zenoh080Header}; use zenoh_buffers::{ reader::{DidntRead, Reader}, writer::{DidntWrite, Writer}, @@ -25,6 +24,8 @@ use zenoh_protocol::{ }, }; +use crate::{common::extension, RCodec, WCodec, Zenoh080, Zenoh080Header}; + impl WCodec<&Oam, &mut W> for Zenoh080 where W: Writer, diff --git a/commons/zenoh-codec/src/transport/open.rs b/commons/zenoh-codec/src/transport/open.rs index d539526715..712fe5ca95 100644 --- a/commons/zenoh-codec/src/transport/open.rs +++ b/commons/zenoh-codec/src/transport/open.rs @@ -11,8 +11,8 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::{common::extension, RCodec, WCodec, Zenoh080, Zenoh080Header}; use core::time::Duration; + use zenoh_buffers::{ reader::{DidntRead, Reader}, writer::{DidntWrite, Writer}, @@ -27,6 +27,8 @@ use zenoh_protocol::{ }, }; +use crate::{common::extension, RCodec, WCodec, Zenoh080, Zenoh080Header}; + // OpenSyn impl WCodec<&OpenSyn, &mut W> for Zenoh080 where diff --git a/commons/zenoh-codec/src/zenoh/del.rs b/commons/zenoh-codec/src/zenoh/del.rs index 3d0a64f428..07df1affc7 100644 --- a/commons/zenoh-codec/src/zenoh/del.rs +++ b/commons/zenoh-codec/src/zenoh/del.rs @@ -11,8 +11,8 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::{common::extension, RCodec, WCodec, Zenoh080, Zenoh080Header}; use alloc::vec::Vec; + use zenoh_buffers::{ reader::{DidntRead, Reader}, writer::{DidntWrite, Writer}, @@ -25,6 +25,8 @@ use zenoh_protocol::{ }, }; +use crate::{common::extension, RCodec, WCodec, Zenoh080, Zenoh080Header}; + impl WCodec<&Del, &mut W> for Zenoh080 where W: Writer, diff --git a/commons/zenoh-codec/src/zenoh/err.rs b/commons/zenoh-codec/src/zenoh/err.rs index 5291645bf0..e19b11f70d 100644 --- a/commons/zenoh-codec/src/zenoh/err.rs +++ b/commons/zenoh-codec/src/zenoh/err.rs @@ -11,8 +11,8 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::{common::extension, RCodec, WCodec, Zenoh080, Zenoh080Bounded, Zenoh080Header}; use alloc::vec::Vec; + use zenoh_buffers::{ reader::{DidntRead, Reader}, writer::{DidntWrite, Writer}, @@ -27,6 +27,8 @@ use zenoh_protocol::{ }, }; +use crate::{common::extension, RCodec, WCodec, Zenoh080, Zenoh080Bounded, Zenoh080Header}; + impl WCodec<&Err, &mut W> for Zenoh080 where W: Writer, diff --git a/commons/zenoh-codec/src/zenoh/mod.rs b/commons/zenoh-codec/src/zenoh/mod.rs index dc38e5ee84..aeb8f53102 100644 --- a/commons/zenoh-codec/src/zenoh/mod.rs +++ b/commons/zenoh-codec/src/zenoh/mod.rs @@ -17,11 +17,6 @@ pub mod put; pub mod query; pub mod reply; -#[cfg(not(feature = "shared-memory"))] -use crate::Zenoh080Bounded; -#[cfg(feature = "shared-memory")] -use crate::Zenoh080Sliced; -use crate::{LCodec, RCodec, WCodec, Zenoh080, Zenoh080Header, Zenoh080Length}; use zenoh_buffers::{ reader::{DidntRead, Reader}, writer::{DidntWrite, Writer}, @@ -35,6 +30,12 @@ use zenoh_protocol::{ zenoh::{ext, id, PushBody, RequestBody, ResponseBody}, }; +#[cfg(not(feature = "shared-memory"))] +use crate::Zenoh080Bounded; +#[cfg(feature = "shared-memory")] +use crate::Zenoh080Sliced; +use crate::{LCodec, RCodec, WCodec, Zenoh080, Zenoh080Header, Zenoh080Length}; + // Push impl WCodec<&PushBody, &mut W> for Zenoh080 where diff --git a/commons/zenoh-codec/src/zenoh/put.rs b/commons/zenoh-codec/src/zenoh/put.rs index 776b47245f..c10a98f6d8 100644 --- a/commons/zenoh-codec/src/zenoh/put.rs +++ b/commons/zenoh-codec/src/zenoh/put.rs @@ -11,12 +11,8 @@ // Contributors: // ZettaScale Zenoh Team, // -#[cfg(not(feature = "shared-memory"))] -use crate::Zenoh080Bounded; -#[cfg(feature = "shared-memory")] -use crate::Zenoh080Sliced; -use crate::{common::extension, RCodec, WCodec, Zenoh080, Zenoh080Header}; use alloc::vec::Vec; + use zenoh_buffers::{ reader::{DidntRead, Reader}, writer::{DidntWrite, Writer}, @@ -31,6 +27,12 @@ use zenoh_protocol::{ }, }; +#[cfg(not(feature = "shared-memory"))] +use crate::Zenoh080Bounded; +#[cfg(feature = "shared-memory")] +use crate::Zenoh080Sliced; +use crate::{common::extension, RCodec, WCodec, Zenoh080, Zenoh080Header}; + impl WCodec<&Put, &mut W> for Zenoh080 where W: Writer, diff --git a/commons/zenoh-codec/src/zenoh/query.rs b/commons/zenoh-codec/src/zenoh/query.rs index efac7b5671..c9b1cc196e 100644 --- a/commons/zenoh-codec/src/zenoh/query.rs +++ b/commons/zenoh-codec/src/zenoh/query.rs @@ -11,13 +11,12 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::{common::extension, RCodec, WCodec, Zenoh080, Zenoh080Header}; use alloc::{string::String, vec::Vec}; + use zenoh_buffers::{ reader::{DidntRead, Reader}, writer::{DidntWrite, Writer}, }; - use zenoh_protocol::{ common::{iext, imsg}, zenoh::{ @@ -26,6 +25,8 @@ use zenoh_protocol::{ }, }; +use crate::{common::extension, RCodec, WCodec, Zenoh080, Zenoh080Header}; + // Consolidation impl WCodec for Zenoh080 where diff --git a/commons/zenoh-codec/src/zenoh/reply.rs b/commons/zenoh-codec/src/zenoh/reply.rs index 308004a1c2..a8d6a2afdc 100644 --- a/commons/zenoh-codec/src/zenoh/reply.rs +++ b/commons/zenoh-codec/src/zenoh/reply.rs @@ -11,8 +11,8 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::{common::extension, RCodec, WCodec, Zenoh080, Zenoh080Header}; use alloc::vec::Vec; + use zenoh_buffers::{ reader::{DidntRead, Reader}, writer::{DidntWrite, Writer}, @@ -26,6 +26,8 @@ use zenoh_protocol::{ }, }; +use crate::{common::extension, RCodec, WCodec, Zenoh080, Zenoh080Header}; + impl WCodec<&Reply, &mut W> for Zenoh080 where W: Writer, diff --git a/commons/zenoh-codec/tests/codec.rs b/commons/zenoh-codec/tests/codec.rs index e9b8140f21..c26b681336 100644 --- a/commons/zenoh-codec/tests/codec.rs +++ b/commons/zenoh-codec/tests/codec.rs @@ -11,11 +11,12 @@ // Contributors: // ZettaScale Zenoh Team, // +use std::convert::TryFrom; + use rand::{ distributions::{Alphanumeric, DistString}, *, }; -use std::convert::TryFrom; use zenoh_buffers::{ reader::{HasReader, Reader}, writer::HasWriter, @@ -360,9 +361,10 @@ fn codec_encoding() { #[cfg(feature = "shared-memory")] #[test] fn codec_shm_info() { - use zenoh_shm::api::provider::chunk::ChunkDescriptor; - use zenoh_shm::header::descriptor::HeaderDescriptor; - use zenoh_shm::{watchdog::descriptor::Descriptor, SharedMemoryBufInfo}; + use zenoh_shm::{ + api::provider::chunk::ChunkDescriptor, header::descriptor::HeaderDescriptor, + watchdog::descriptor::Descriptor, SharedMemoryBufInfo, + }; run!(SharedMemoryBufInfo, { let mut rng = rand::thread_rng(); diff --git a/commons/zenoh-collections/src/single_or_vec.rs b/commons/zenoh-collections/src/single_or_vec.rs index ed82bf49af..7b2391197d 100644 --- a/commons/zenoh-collections/src/single_or_vec.rs +++ b/commons/zenoh-collections/src/single_or_vec.rs @@ -13,6 +13,8 @@ // use alloc::vec; +#[cfg(not(feature = "std"))] +use alloc::vec::Vec; use core::{ cmp::PartialEq, fmt, iter, @@ -20,9 +22,6 @@ use core::{ ptr, slice, }; -#[cfg(not(feature = "std"))] -use alloc::vec::Vec; - #[derive(Clone, Eq)] enum SingleOrVecInner { Single(T), diff --git a/commons/zenoh-config/src/connection_retry.rs b/commons/zenoh-config/src/connection_retry.rs index a845fbfe6a..e5f88a05f3 100644 --- a/commons/zenoh-config/src/connection_retry.rs +++ b/commons/zenoh-config/src/connection_retry.rs @@ -12,18 +12,18 @@ // ZettaScale Zenoh Team, // +use serde::{Deserialize, Serialize}; +use zenoh_core::zparse_default; +use zenoh_protocol::core::WhatAmI; + use crate::{ defaults::{ self, DEFAULT_CONNECT_EXIT_ON_FAIL, DEFAULT_CONNECT_TIMEOUT_MS, DEFAULT_LISTEN_EXIT_ON_FAIL, DEFAULT_LISTEN_TIMEOUT_MS, }, + mode_dependent::*, Config, }; -use serde::{Deserialize, Serialize}; -use zenoh_core::zparse_default; -use zenoh_protocol::core::WhatAmI; - -use crate::mode_dependent::*; #[derive(Debug, Deserialize, Serialize, Clone)] pub struct ConnectionRetryModeDependentConf { diff --git a/commons/zenoh-config/src/lib.rs b/commons/zenoh-config/src/lib.rs index 26f7cfefaa..c55480b2c5 100644 --- a/commons/zenoh-config/src/lib.rs +++ b/commons/zenoh-config/src/lib.rs @@ -16,10 +16,6 @@ pub mod defaults; mod include; -use include::recursive_include; -use secrecy::{CloneableSecret, DebugSecret, Secret, SerializableSecret, Zeroize}; -use serde::{Deserialize, Serialize}; -use serde_json::{Map, Value}; #[allow(unused_imports)] use std::convert::TryFrom; // This is a false positive from the rust analyser use std::{ @@ -31,6 +27,11 @@ use std::{ path::Path, sync::{Arc, Mutex, MutexGuard, Weak}, }; + +use include::recursive_include; +use secrecy::{CloneableSecret, DebugSecret, Secret, SerializableSecret, Zeroize}; +use serde::{Deserialize, Serialize}; +use serde_json::{Map, Value}; use validated_struct::ValidatedMapAssociatedTypes; pub use validated_struct::{GetError, ValidatedMap}; use zenoh_core::zlock; diff --git a/commons/zenoh-config/src/mode_dependent.rs b/commons/zenoh-config/src/mode_dependent.rs index 9f6cc2c7e4..074dd823d9 100644 --- a/commons/zenoh-config/src/mode_dependent.rs +++ b/commons/zenoh-config/src/mode_dependent.rs @@ -12,12 +12,12 @@ // ZettaScale Zenoh Team, // +use std::{fmt, marker::PhantomData}; + use serde::{ de::{self, MapAccess, Visitor}, Deserialize, Serialize, }; -use std::fmt; -use std::marker::PhantomData; pub use zenoh_protocol::core::{ whatami, EndPoint, Locator, WhatAmI, WhatAmIMatcher, WhatAmIMatcherVisitor, ZenohId, }; diff --git a/commons/zenoh-core/src/lib.rs b/commons/zenoh-core/src/lib.rs index 19cf3751ff..8d6fbfcc0a 100644 --- a/commons/zenoh-core/src/lib.rs +++ b/commons/zenoh-core/src/lib.rs @@ -27,8 +27,7 @@ pub use zenoh_result::{bail, to_zerror, zerror}; pub mod zresult { pub use zenoh_result::*; } -pub use zresult::Error; -pub use zresult::ZResult as Result; +pub use zresult::{Error, ZResult as Result}; /// A resolvable execution, either sync or async pub trait Resolvable { diff --git a/commons/zenoh-crypto/src/cipher.rs b/commons/zenoh-crypto/src/cipher.rs index 3d12712e56..aa78b97b46 100644 --- a/commons/zenoh-crypto/src/cipher.rs +++ b/commons/zenoh-crypto/src/cipher.rs @@ -11,12 +11,15 @@ // Contributors: // ZettaScale Zenoh Team, // -use super::PseudoRng; -use aes::cipher::{generic_array::GenericArray, BlockDecrypt, BlockEncrypt, KeyInit}; -use aes::Aes128; +use aes::{ + cipher::{generic_array::GenericArray, BlockDecrypt, BlockEncrypt, KeyInit}, + Aes128, +}; use rand::Rng; use zenoh_result::{bail, ZResult}; +use super::PseudoRng; + pub struct BlockCipher { inner: Aes128, } @@ -68,9 +71,10 @@ impl BlockCipher { mod tests { #[test] fn cipher() { - use super::{BlockCipher, PseudoRng}; use rand::{RngCore, SeedableRng}; + use super::{BlockCipher, PseudoRng}; + fn encrypt_decrypt(cipher: &BlockCipher, prng: &mut PseudoRng) { println!("\n[1]"); let t1 = "A".as_bytes().to_vec(); diff --git a/commons/zenoh-keyexpr/benches/keyexpr_tree.rs b/commons/zenoh-keyexpr/benches/keyexpr_tree.rs index 4047e3cf5c..7048521eda 100644 --- a/commons/zenoh-keyexpr/benches/keyexpr_tree.rs +++ b/commons/zenoh-keyexpr/benches/keyexpr_tree.rs @@ -18,12 +18,15 @@ use std::{ }; use rand::SeedableRng; -use zenoh_keyexpr::keyexpr_tree::{ - impls::{HashMapProvider, VecSetProvider}, - traits::*, - KeArcTree, KeBoxTree, +use zenoh_keyexpr::{ + fuzzer::KeyExprFuzzer, + keyexpr_tree::{ + impls::{HashMapProvider, VecSetProvider}, + traits::*, + KeArcTree, KeBoxTree, + }, + OwnedKeyExpr, }; -use zenoh_keyexpr::{fuzzer::KeyExprFuzzer, OwnedKeyExpr}; #[derive(Clone, Copy, Debug, Default)] pub struct Averager { diff --git a/commons/zenoh-keyexpr/src/key_expr/borrowed.rs b/commons/zenoh-keyexpr/src/key_expr/borrowed.rs index 85b4ef79e2..fd87cef55f 100644 --- a/commons/zenoh-keyexpr/src/key_expr/borrowed.rs +++ b/commons/zenoh-keyexpr/src/key_expr/borrowed.rs @@ -12,7 +12,6 @@ // ZettaScale Zenoh Team, // -use super::{canon::Canonizable, OwnedKeyExpr, FORBIDDEN_CHARS}; use alloc::{ borrow::{Borrow, ToOwned}, format, @@ -24,8 +23,11 @@ use core::{ fmt, ops::{Deref, Div}, }; + use zenoh_result::{bail, Error as ZError, ZResult}; +use super::{canon::Canonizable, OwnedKeyExpr, FORBIDDEN_CHARS}; + /// A [`str`] newtype that is statically known to be a valid key expression. /// /// The exact key expression specification can be found [here](https://github.com/eclipse-zenoh/roadmap/blob/main/rfcs/ALL/Key%20Expressions.md). Here are the major lines: diff --git a/commons/zenoh-keyexpr/src/key_expr/canon.rs b/commons/zenoh-keyexpr/src/key_expr/canon.rs index 00e79b0c08..cccccdfba3 100644 --- a/commons/zenoh-keyexpr/src/key_expr/canon.rs +++ b/commons/zenoh-keyexpr/src/key_expr/canon.rs @@ -11,12 +11,13 @@ // Contributors: // ZettaScale Zenoh Team, // +use alloc::string::String; +use core::{slice, str}; + use crate::key_expr::{ utils::{Split, Writer}, DELIMITER, DOUBLE_WILD, SINGLE_WILD, }; -use alloc::string::String; -use core::{slice, str}; pub trait Canonizable { fn canonize(&mut self); diff --git a/commons/zenoh-keyexpr/src/key_expr/format/parsing.rs b/commons/zenoh-keyexpr/src/key_expr/format/parsing.rs index 52f01c5b6a..a6329cdf73 100644 --- a/commons/zenoh-keyexpr/src/key_expr/format/parsing.rs +++ b/commons/zenoh-keyexpr/src/key_expr/format/parsing.rs @@ -230,8 +230,9 @@ fn do_parse<'a>( #[test] fn parsing() { - use crate::key_expr::OwnedKeyExpr; use core::convert::TryFrom; + + use crate::key_expr::OwnedKeyExpr; for a_spec in ["${a:*}", "a/${a:*}"] { for b_spec in ["b/${b:**}", "${b:**}"] { let specs = [a_spec, b_spec, "c"]; diff --git a/commons/zenoh-keyexpr/src/key_expr/intersect/classical.rs b/commons/zenoh-keyexpr/src/key_expr/intersect/classical.rs index fa346a2d4a..77388a55c9 100644 --- a/commons/zenoh-keyexpr/src/key_expr/intersect/classical.rs +++ b/commons/zenoh-keyexpr/src/key_expr/intersect/classical.rs @@ -119,8 +119,7 @@ pub fn intersect(s1: &[u8], s2: &[u8]) -> bool { it_intersect::(s1, s2) } -use super::restiction::NoSubWilds; -use super::{Intersector, MayHaveVerbatim}; +use super::{restiction::NoSubWilds, Intersector, MayHaveVerbatim}; pub struct ClassicIntersector; impl Intersector, NoSubWilds<&[u8]>> for ClassicIntersector { diff --git a/commons/zenoh-keyexpr/src/key_expr/intersect/mod.rs b/commons/zenoh-keyexpr/src/key_expr/intersect/mod.rs index f5d7735d9e..06b990ee72 100644 --- a/commons/zenoh-keyexpr/src/key_expr/intersect/mod.rs +++ b/commons/zenoh-keyexpr/src/key_expr/intersect/mod.rs @@ -12,9 +12,8 @@ // ZettaScale Zenoh Team, // -use crate::DELIMITER; - use super::keyexpr; +use crate::DELIMITER; mod classical; pub use classical::ClassicIntersector; diff --git a/commons/zenoh-keyexpr/src/key_expr/owned.rs b/commons/zenoh-keyexpr/src/key_expr/owned.rs index 5164e4762c..a53fdec2f0 100644 --- a/commons/zenoh-keyexpr/src/key_expr/owned.rs +++ b/commons/zenoh-keyexpr/src/key_expr/owned.rs @@ -13,7 +13,6 @@ // extern crate alloc; -use super::{canon::Canonizable, keyexpr}; // use crate::core::WireExpr; use alloc::{borrow::ToOwned, boxed::Box, string::String, sync::Arc}; use core::{ @@ -23,6 +22,8 @@ use core::{ str::FromStr, }; +use super::{canon::Canonizable, keyexpr}; + /// A [`Arc`] newtype that is statically known to be a valid key expression. /// /// See [`keyexpr`](super::borrowed::keyexpr). diff --git a/commons/zenoh-keyexpr/src/key_expr/tests.rs b/commons/zenoh-keyexpr/src/key_expr/tests.rs index 6d9e64896e..c004666776 100644 --- a/commons/zenoh-keyexpr/src/key_expr/tests.rs +++ b/commons/zenoh-keyexpr/src/key_expr/tests.rs @@ -12,9 +12,10 @@ // ZettaScale Zenoh Team, // -use crate::key_expr::{fuzzer, intersect::*, keyexpr}; use std::{convert::TryInto, fmt::Debug}; +use crate::key_expr::{fuzzer, intersect::*, keyexpr}; + type BoxedIntersectors = Vec Intersector<&'a keyexpr, &'a keyexpr> + Send + Sync>>; lazy_static::lazy_static! { diff --git a/commons/zenoh-keyexpr/src/keyexpr_tree/arc_tree.rs b/commons/zenoh-keyexpr/src/keyexpr_tree/arc_tree.rs index a0428ac563..e800697bef 100644 --- a/commons/zenoh-keyexpr/src/keyexpr_tree/arc_tree.rs +++ b/commons/zenoh-keyexpr/src/keyexpr_tree/arc_tree.rs @@ -20,10 +20,11 @@ use core::fmt::Debug; use token_cell::prelude::*; -use super::box_tree::PruneResult; -use super::support::IterOrOption; -use crate::keyexpr; -use crate::keyexpr_tree::{support::IWildness, *}; +use super::{box_tree::PruneResult, support::IterOrOption}; +use crate::{ + keyexpr, + keyexpr_tree::{support::IWildness, *}, +}; pub struct KeArcTreeInner< Weight, @@ -428,6 +429,7 @@ where pub(crate) mod sealed { use alloc::sync::Arc; use core::ops::{Deref, DerefMut}; + use token_cell::prelude::{TokenCell, TokenTrait}; pub struct Tokenized(pub A, pub(crate) B); diff --git a/commons/zenoh-keyexpr/src/keyexpr_tree/box_tree.rs b/commons/zenoh-keyexpr/src/keyexpr_tree/box_tree.rs index 5aa23e78ac..fcf230731a 100644 --- a/commons/zenoh-keyexpr/src/keyexpr_tree/box_tree.rs +++ b/commons/zenoh-keyexpr/src/keyexpr_tree/box_tree.rs @@ -17,15 +17,15 @@ use alloc::boxed::Box; use alloc::string::String; use core::ptr::NonNull; -use crate::keyexpr; -use crate::keyexpr_tree::{ - support::{IWildness, NonWild, UnknownWildness}, - *, +use super::{impls::KeyedSetProvider, support::IterOrOption}; +use crate::{ + keyexpr, + keyexpr_tree::{ + support::{IWildness, NonWild, UnknownWildness}, + *, + }, }; -use super::impls::KeyedSetProvider; -use super::support::IterOrOption; - /// A fully owned KeTree. /// /// Note that most of `KeBoxTree`'s methods are declared in the [`IKeyExprTree`] and [`IKeyExprTreeMut`] traits. diff --git a/commons/zenoh-keyexpr/src/keyexpr_tree/impls/hashmap_impl.rs b/commons/zenoh-keyexpr/src/keyexpr_tree/impls/hashmap_impl.rs index 72f830a912..a5a16e1d82 100644 --- a/commons/zenoh-keyexpr/src/keyexpr_tree/impls/hashmap_impl.rs +++ b/commons/zenoh-keyexpr/src/keyexpr_tree/impls/hashmap_impl.rs @@ -17,17 +17,18 @@ use core::hash::Hasher; // `SipHasher` is deprecated in favour of a symbol that only exists in `std` #[allow(deprecated)] use core::hash::SipHasher as DefaultHasher; -#[cfg(not(feature = "std"))] -use hashbrown::{ - hash_map::{Entry, Iter, IterMut, Values, ValuesMut}, - HashMap, -}; #[cfg(feature = "std")] use std::collections::{ hash_map::{DefaultHasher, Entry, Iter, IterMut, Values, ValuesMut}, HashMap, }; +#[cfg(not(feature = "std"))] +use hashbrown::{ + hash_map::{Entry, Iter, IterMut, Values, ValuesMut}, + HashMap, +}; + use crate::keyexpr_tree::*; #[cfg_attr(not(feature = "std"), allow(deprecated))] diff --git a/commons/zenoh-keyexpr/src/keyexpr_tree/impls/keyed_set_impl.rs b/commons/zenoh-keyexpr/src/keyexpr_tree/impls/keyed_set_impl.rs index 4fab65a850..a6b1847697 100644 --- a/commons/zenoh-keyexpr/src/keyexpr_tree/impls/keyed_set_impl.rs +++ b/commons/zenoh-keyexpr/src/keyexpr_tree/impls/keyed_set_impl.rs @@ -20,9 +20,10 @@ use core::hash::SipHasher as DefaultHasher; #[cfg(feature = "std")] use std::collections::hash_map::DefaultHasher; -use crate::keyexpr_tree::*; use keyed_set::{KeyExtractor, KeyedSet}; +use crate::keyexpr_tree::*; + #[cfg_attr(not(feature = "std"), allow(deprecated))] pub struct KeyedSetProvider( core::marker::PhantomData, diff --git a/commons/zenoh-keyexpr/src/keyexpr_tree/impls/mod.rs b/commons/zenoh-keyexpr/src/keyexpr_tree/impls/mod.rs index 2645c9d95b..48547429f3 100644 --- a/commons/zenoh-keyexpr/src/keyexpr_tree/impls/mod.rs +++ b/commons/zenoh-keyexpr/src/keyexpr_tree/impls/mod.rs @@ -12,10 +12,11 @@ // ZettaScale Zenoh Team, // -use crate::keyexpr; pub use hashmap_impl::HashMapProvider; pub use keyed_set_impl::KeyedSetProvider; pub use vec_set_impl::VecSetProvider; + +use crate::keyexpr; mod hashmap_impl; mod keyed_set_impl; mod vec_set_impl; diff --git a/commons/zenoh-keyexpr/src/keyexpr_tree/impls/vec_set_impl.rs b/commons/zenoh-keyexpr/src/keyexpr_tree/impls/vec_set_impl.rs index 96877ebda6..510755e3c4 100644 --- a/commons/zenoh-keyexpr/src/keyexpr_tree/impls/vec_set_impl.rs +++ b/commons/zenoh-keyexpr/src/keyexpr_tree/impls/vec_set_impl.rs @@ -13,6 +13,7 @@ // use alloc::vec::Vec; + use zenoh_result::unlikely; use crate::keyexpr_tree::*; diff --git a/commons/zenoh-keyexpr/src/keyexpr_tree/iters/includer.rs b/commons/zenoh-keyexpr/src/keyexpr_tree/iters/includer.rs index a22d0804b1..bf09714f29 100644 --- a/commons/zenoh-keyexpr/src/keyexpr_tree/iters/includer.rs +++ b/commons/zenoh-keyexpr/src/keyexpr_tree/iters/includer.rs @@ -12,9 +12,10 @@ // ZettaScale Zenoh Team, // -use crate::keyexpr_tree::*; use alloc::vec::Vec; +use crate::keyexpr_tree::*; + struct StackFrame<'a, Children: IChildrenProvider, Node: UIKeyExprTreeNode, Weight> where Children::Assoc: IChildren + 'a, diff --git a/commons/zenoh-keyexpr/src/keyexpr_tree/iters/inclusion.rs b/commons/zenoh-keyexpr/src/keyexpr_tree/iters/inclusion.rs index 0ed2c96645..87e5af90a9 100644 --- a/commons/zenoh-keyexpr/src/keyexpr_tree/iters/inclusion.rs +++ b/commons/zenoh-keyexpr/src/keyexpr_tree/iters/inclusion.rs @@ -12,10 +12,12 @@ // ZettaScale Zenoh Team, // -use crate::keyexpr_tree::*; use alloc::vec::Vec; + use zenoh_result::unlikely; +use crate::keyexpr_tree::*; + struct StackFrame<'a, Children: IChildrenProvider, Node: UIKeyExprTreeNode, Weight> where Children::Assoc: IChildren + 'a, diff --git a/commons/zenoh-keyexpr/src/keyexpr_tree/iters/intersection.rs b/commons/zenoh-keyexpr/src/keyexpr_tree/iters/intersection.rs index 34902810f0..dccd571911 100644 --- a/commons/zenoh-keyexpr/src/keyexpr_tree/iters/intersection.rs +++ b/commons/zenoh-keyexpr/src/keyexpr_tree/iters/intersection.rs @@ -12,10 +12,12 @@ // ZettaScale Zenoh Team, // -use crate::keyexpr_tree::*; use alloc::vec::Vec; + use zenoh_result::unlikely; +use crate::keyexpr_tree::*; + struct StackFrame<'a, Children: IChildrenProvider, Node: UIKeyExprTreeNode, Weight> where Children::Assoc: IChildren + 'a, diff --git a/commons/zenoh-keyexpr/src/keyexpr_tree/iters/tree_iter.rs b/commons/zenoh-keyexpr/src/keyexpr_tree/iters/tree_iter.rs index 666f0cb2c2..05afae3885 100644 --- a/commons/zenoh-keyexpr/src/keyexpr_tree/iters/tree_iter.rs +++ b/commons/zenoh-keyexpr/src/keyexpr_tree/iters/tree_iter.rs @@ -12,9 +12,8 @@ // ZettaScale Zenoh Team, // -use core::num::NonZeroUsize; - use alloc::vec::Vec; +use core::num::NonZeroUsize; use crate::keyexpr_tree::*; pub struct TreeIter<'a, Children: IChildrenProvider, Node: UIKeyExprTreeNode, Weight> diff --git a/commons/zenoh-keyexpr/src/keyexpr_tree/test.rs b/commons/zenoh-keyexpr/src/keyexpr_tree/test.rs index fc2372a67b..ac3d15c6ec 100644 --- a/commons/zenoh-keyexpr/src/keyexpr_tree/test.rs +++ b/commons/zenoh-keyexpr/src/keyexpr_tree/test.rs @@ -12,24 +12,25 @@ // ZettaScale Zenoh Team, // -use crate::fuzzer::KeyExprFuzzer; use alloc::vec::Vec; -use rand::Rng; - -use super::{ - impls::{KeyedSetProvider, VecSetProvider}, - *, -}; use core::{ convert::{TryFrom, TryInto}, fmt::Debug, ops::Deref, }; -#[cfg(not(feature = "std"))] -use hashbrown::HashMap; #[cfg(feature = "std")] use std::collections::HashMap; +#[cfg(not(feature = "std"))] +use hashbrown::HashMap; +use rand::Rng; + +use super::{ + impls::{KeyedSetProvider, VecSetProvider}, + *, +}; +use crate::fuzzer::KeyExprFuzzer; + fn insert<'a, K: TryInto<&'a keyexpr>, V: Clone + PartialEq + Debug + 'static>( ketree: &mut KeBoxTree, map: &mut HashMap>, diff --git a/commons/zenoh-keyexpr/src/keyexpr_tree/traits/default_impls.rs b/commons/zenoh-keyexpr/src/keyexpr_tree/traits/default_impls.rs index e6def16608..6a043ccda0 100644 --- a/commons/zenoh-keyexpr/src/keyexpr_tree/traits/default_impls.rs +++ b/commons/zenoh-keyexpr/src/keyexpr_tree/traits/default_impls.rs @@ -13,6 +13,7 @@ // use alloc::{boxed::Box, sync::Arc}; + use token_cell::prelude::{TokenCell, TokenCellTrait, TokenTrait}; use super::*; diff --git a/commons/zenoh-keyexpr/src/keyexpr_tree/traits/mod.rs b/commons/zenoh-keyexpr/src/keyexpr_tree/traits/mod.rs index dd06cf14b8..03a97f5063 100644 --- a/commons/zenoh-keyexpr/src/keyexpr_tree/traits/mod.rs +++ b/commons/zenoh-keyexpr/src/keyexpr_tree/traits/mod.rs @@ -12,8 +12,9 @@ // ZettaScale Zenoh Team, // -use crate::{keyexpr, OwnedKeyExpr}; use alloc::boxed::Box; + +use crate::{keyexpr, OwnedKeyExpr}; pub mod default_impls; /// The basic immutable methods of all KeTrees. diff --git a/commons/zenoh-protocol/src/common/extension.rs b/commons/zenoh-protocol/src/common/extension.rs index f61df61cc6..1d9ff41d50 100644 --- a/commons/zenoh-protocol/src/common/extension.rs +++ b/commons/zenoh-protocol/src/common/extension.rs @@ -15,6 +15,7 @@ use core::{ convert::TryFrom, fmt::{self, Debug}, }; + use zenoh_buffers::ZBuf; /// # Zenoh extensions diff --git a/commons/zenoh-protocol/src/core/cowstr.rs b/commons/zenoh-protocol/src/core/cowstr.rs index 209d020f40..b31c1c4a5d 100644 --- a/commons/zenoh-protocol/src/core/cowstr.rs +++ b/commons/zenoh-protocol/src/core/cowstr.rs @@ -12,8 +12,10 @@ // ZettaScale Zenoh Team, // use alloc::{borrow::ToOwned, boxed::Box, string::String, vec::Vec}; -use core::fmt::{Debug, Display, Formatter}; -use core::num::NonZeroUsize; +use core::{ + fmt::{Debug, Display, Formatter}, + num::NonZeroUsize, +}; enum CowStrInner<'a> { Borrowed(&'a str), diff --git a/commons/zenoh-protocol/src/core/encoding.rs b/commons/zenoh-protocol/src/core/encoding.rs index 70afdbf143..e58088b581 100644 --- a/commons/zenoh-protocol/src/core/encoding.rs +++ b/commons/zenoh-protocol/src/core/encoding.rs @@ -12,6 +12,7 @@ // ZettaScale Zenoh Team, // use core::fmt::Debug; + use zenoh_buffers::ZSlice; pub type EncodingId = u16; diff --git a/commons/zenoh-protocol/src/core/endpoint.rs b/commons/zenoh-protocol/src/core/endpoint.rs index a61fdd8e89..8b2c4ad01c 100644 --- a/commons/zenoh-protocol/src/core/endpoint.rs +++ b/commons/zenoh-protocol/src/core/endpoint.rs @@ -11,11 +11,13 @@ // Contributors: // ZettaScale Zenoh Team, // -use super::{locator::*, parameters::Parameters}; use alloc::{borrow::ToOwned, format, string::String}; use core::{borrow::Borrow, convert::TryFrom, fmt, str::FromStr}; + use zenoh_result::{bail, zerror, Error as ZError, ZResult}; +use super::{locator::*, parameters::Parameters}; + // Parsing chars pub const PROTO_SEPARATOR: char = '/'; pub const METADATA_SEPARATOR: char = '?'; diff --git a/commons/zenoh-protocol/src/core/locator.rs b/commons/zenoh-protocol/src/core/locator.rs index 50b909b12f..14f899e7c6 100644 --- a/commons/zenoh-protocol/src/core/locator.rs +++ b/commons/zenoh-protocol/src/core/locator.rs @@ -11,11 +11,13 @@ // Contributors: // ZettaScale Zenoh Team, // -use super::endpoint::*; use alloc::{borrow::ToOwned, string::String}; use core::{convert::TryFrom, fmt, hash::Hash, str::FromStr}; + use zenoh_result::{Error as ZError, ZResult}; +use super::endpoint::*; + /// A string that respects the [`Locator`] canon form: `/
[?]`. /// /// `` is of the form `=;...;=` where keys are alphabetically sorted. diff --git a/commons/zenoh-protocol/src/core/mod.rs b/commons/zenoh-protocol/src/core/mod.rs index 0920d55d01..9f10cab391 100644 --- a/commons/zenoh-protocol/src/core/mod.rs +++ b/commons/zenoh-protocol/src/core/mod.rs @@ -23,6 +23,7 @@ use core::{ hash::Hash, str::FromStr, }; + pub use uhlc::{Timestamp, NTP64}; use zenoh_keyexpr::OwnedKeyExpr; use zenoh_result::{bail, zerror}; @@ -33,7 +34,6 @@ pub type TimestampId = uhlc::ID; /// Constants and helpers for zenoh `whatami` flags. pub mod whatami; pub use whatami::*; - pub use zenoh_keyexpr::key_expr; pub mod wire_expr; diff --git a/commons/zenoh-protocol/src/core/properties.rs b/commons/zenoh-protocol/src/core/properties.rs index a4c2c35197..5264288448 100644 --- a/commons/zenoh-protocol/src/core/properties.rs +++ b/commons/zenoh-protocol/src/core/properties.rs @@ -11,7 +11,6 @@ // Contributors: // ZettaScale Zenoh Team, // -use super::parameters::{Parameters, FIELD_SEPARATOR, LIST_SEPARATOR, VALUE_SEPARATOR}; use alloc::{ borrow::Cow, string::{String, ToString}, @@ -20,6 +19,8 @@ use core::{borrow::Borrow, fmt}; #[cfg(feature = "std")] use std::collections::HashMap; +use super::parameters::{Parameters, FIELD_SEPARATOR, LIST_SEPARATOR, VALUE_SEPARATOR}; + /// A map of key/value (String,String) properties. /// It can be parsed from a String, using `;` or `` as separator between each properties /// and `=` as separator between a key and its value. Keys and values are trimed. diff --git a/commons/zenoh-protocol/src/core/resolution.rs b/commons/zenoh-protocol/src/core/resolution.rs index 093fd33bb4..fb16a5c713 100644 --- a/commons/zenoh-protocol/src/core/resolution.rs +++ b/commons/zenoh-protocol/src/core/resolution.rs @@ -11,11 +11,13 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::{network::RequestId, transport::TransportSn}; use alloc::string::String; use core::{fmt, str::FromStr}; + use zenoh_result::{bail, ZError}; +use crate::{network::RequestId, transport::TransportSn}; + #[repr(u8)] // The value represents the 2-bit encoded value #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] diff --git a/commons/zenoh-protocol/src/core/whatami.rs b/commons/zenoh-protocol/src/core/whatami.rs index 6aacb0d356..10c5b42c78 100644 --- a/commons/zenoh-protocol/src/core/whatami.rs +++ b/commons/zenoh-protocol/src/core/whatami.rs @@ -12,8 +12,9 @@ // ZettaScale Zenoh Team, // use alloc::string::String; -use const_format::formatcp; use core::{convert::TryFrom, fmt, num::NonZeroU8, ops::BitOr, str::FromStr}; + +use const_format::formatcp; use zenoh_result::{bail, ZError}; #[repr(u8)] diff --git a/commons/zenoh-protocol/src/core/wire_expr.rs b/commons/zenoh-protocol/src/core/wire_expr.rs index a66b1aa212..9f5c432665 100644 --- a/commons/zenoh-protocol/src/core/wire_expr.rs +++ b/commons/zenoh-protocol/src/core/wire_expr.rs @@ -18,6 +18,7 @@ use alloc::{ string::{String, ToString}, }; use core::{convert::TryInto, fmt, sync::atomic::AtomicU16}; + use zenoh_keyexpr::{keyexpr, OwnedKeyExpr}; use zenoh_result::{bail, ZResult}; diff --git a/commons/zenoh-protocol/src/network/declare.rs b/commons/zenoh-protocol/src/network/declare.rs index 9a41f42e56..a5373cd5f4 100644 --- a/commons/zenoh-protocol/src/network/declare.rs +++ b/commons/zenoh-protocol/src/network/declare.rs @@ -11,19 +11,21 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::{ - common::{imsg, ZExtZ64, ZExtZBuf}, - core::{ExprId, Reliability, WireExpr}, - network::Mapping, - zextz64, zextzbuf, -}; use alloc::borrow::Cow; + pub use common::*; pub use keyexpr::*; pub use queryable::*; pub use subscriber::*; pub use token::*; +use crate::{ + common::{imsg, ZExtZ64, ZExtZBuf}, + core::{ExprId, Reliability, WireExpr}, + network::Mapping, + zextz64, zextzbuf, +}; + pub mod flag { pub const I: u8 = 1 << 5; // 0x20 Interest if I==1 then the declare is in a response to an Interest with future==false // pub const X: u8 = 1 << 6; // 0x40 Reserved @@ -288,9 +290,8 @@ pub mod keyexpr { } pub mod subscriber { - use crate::core::EntityId; - use super::*; + use crate::core::EntityId; pub type SubscriberId = EntityId; @@ -448,9 +449,8 @@ pub mod subscriber { } pub mod queryable { - use crate::core::EntityId; - use super::*; + use crate::core::EntityId; pub type QueryableId = EntityId; diff --git a/commons/zenoh-protocol/src/network/interest.rs b/commons/zenoh-protocol/src/network/interest.rs index e7eb75787e..46797b72ee 100644 --- a/commons/zenoh-protocol/src/network/interest.rs +++ b/commons/zenoh-protocol/src/network/interest.rs @@ -11,13 +11,14 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::{common::imsg, core::WireExpr, network::Mapping}; use core::{ fmt::{self, Debug}, ops::{Add, AddAssign, Sub, SubAssign}, sync::atomic::AtomicU32, }; +use crate::{common::imsg, core::WireExpr, network::Mapping}; + pub type InterestId = u32; pub mod flag { diff --git a/commons/zenoh-protocol/src/network/mod.rs b/commons/zenoh-protocol/src/network/mod.rs index 5a0635c9e0..952fe74e89 100644 --- a/commons/zenoh-protocol/src/network/mod.rs +++ b/commons/zenoh-protocol/src/network/mod.rs @@ -217,11 +217,12 @@ impl From for NetworkMessage { // Extensions pub mod ext { + use core::fmt; + use crate::{ common::{imsg, ZExtZ64}, core::{CongestionControl, EntityId, Priority, ZenohId}, }; - use core::fmt; /// ```text /// 7 6 5 4 3 2 1 0 diff --git a/commons/zenoh-protocol/src/network/request.rs b/commons/zenoh-protocol/src/network/request.rs index ff978744e8..09e8e6b2b6 100644 --- a/commons/zenoh-protocol/src/network/request.rs +++ b/commons/zenoh-protocol/src/network/request.rs @@ -11,9 +11,10 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::{core::WireExpr, zenoh::RequestBody}; use core::sync::atomic::AtomicU32; +use crate::{core::WireExpr, zenoh::RequestBody}; + /// The resolution of a RequestId pub type RequestId = u32; pub type AtomicRequestId = AtomicU32; @@ -64,11 +65,12 @@ pub struct Request { } pub mod ext { + use core::{num::NonZeroU32, time::Duration}; + use crate::{ common::{ZExtZ64, ZExtZBuf}, zextz64, zextzbuf, }; - use core::{num::NonZeroU32, time::Duration}; pub type QoS = zextz64!(0x1, false); pub type QoSType = crate::network::ext::QoSType<{ QoS::ID }>; diff --git a/commons/zenoh-protocol/src/scouting/hello.rs b/commons/zenoh-protocol/src/scouting/hello.rs index 562e2fb8c4..62ea915e5a 100644 --- a/commons/zenoh-protocol/src/scouting/hello.rs +++ b/commons/zenoh-protocol/src/scouting/hello.rs @@ -11,10 +11,11 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::core::{Locator, WhatAmI, ZenohId}; use alloc::vec::Vec; use core::fmt; +use crate::core::{Locator, WhatAmI, ZenohId}; + /// # Hello message /// /// The [`Hello`] message is used to advertise the locators a zenoh node is reachable at. diff --git a/commons/zenoh-protocol/src/transport/fragment.rs b/commons/zenoh-protocol/src/transport/fragment.rs index 3e80c9cfbf..0a1df1fdf5 100644 --- a/commons/zenoh-protocol/src/transport/fragment.rs +++ b/commons/zenoh-protocol/src/transport/fragment.rs @@ -11,9 +11,10 @@ // Contributors: // ZettaScale Zenoh Team, // +use zenoh_buffers::ZSlice; + use crate::core::Reliability; pub use crate::transport::TransportSn; -use zenoh_buffers::ZSlice; /// # Fragment message /// diff --git a/commons/zenoh-protocol/src/transport/frame.rs b/commons/zenoh-protocol/src/transport/frame.rs index 184784f9f1..02a4ead48f 100644 --- a/commons/zenoh-protocol/src/transport/frame.rs +++ b/commons/zenoh-protocol/src/transport/frame.rs @@ -11,9 +11,10 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::{core::Reliability, network::NetworkMessage, transport::TransportSn}; use alloc::vec::Vec; +use crate::{core::Reliability, network::NetworkMessage, transport::TransportSn}; + /// # Frame message /// /// The [`Frame`] message is used to transmit one ore more complete serialized diff --git a/commons/zenoh-protocol/src/transport/init.rs b/commons/zenoh-protocol/src/transport/init.rs index 7e86d17af2..b1febac4b5 100644 --- a/commons/zenoh-protocol/src/transport/init.rs +++ b/commons/zenoh-protocol/src/transport/init.rs @@ -11,11 +11,12 @@ // Contributors: // ZettaScale Zenoh Team, // +use zenoh_buffers::ZSlice; + use crate::{ core::{Resolution, WhatAmI, ZenohId}, transport::BatchSize, }; -use zenoh_buffers::ZSlice; /// # Init message /// @@ -158,9 +159,10 @@ pub mod ext { impl InitSyn { #[cfg(feature = "test")] pub fn rand() -> Self { - use crate::common::{ZExtUnit, ZExtZBuf}; use rand::Rng; + use crate::common::{ZExtUnit, ZExtZBuf}; + let mut rng = rand::thread_rng(); let version: u8 = rng.gen(); @@ -213,9 +215,10 @@ pub struct InitAck { impl InitAck { #[cfg(feature = "test")] pub fn rand() -> Self { - use crate::common::{ZExtUnit, ZExtZBuf}; use rand::Rng; + use crate::common::{ZExtUnit, ZExtZBuf}; + let mut rng = rand::thread_rng(); let version: u8 = rng.gen(); diff --git a/commons/zenoh-protocol/src/transport/join.rs b/commons/zenoh-protocol/src/transport/join.rs index a5cf1422a6..9918de6acf 100644 --- a/commons/zenoh-protocol/src/transport/join.rs +++ b/commons/zenoh-protocol/src/transport/join.rs @@ -11,11 +11,12 @@ // Contributors: // ZettaScale Zenoh Team, // +use core::time::Duration; + use crate::{ core::{Priority, Resolution, WhatAmI, ZenohId}, transport::{BatchSize, PrioritySn}, }; -use core::time::Duration; /// # Join message /// @@ -115,9 +116,10 @@ pub struct Join { // Extensions pub mod ext { + use alloc::boxed::Box; + use super::{Priority, PrioritySn}; use crate::{common::ZExtZBuf, zextzbuf}; - use alloc::boxed::Box; /// # QoS extension /// Used to announce next sn when QoS is enabled @@ -132,9 +134,10 @@ pub mod ext { impl Join { #[cfg(feature = "test")] pub fn rand() -> Self { - use crate::common::ZExtZBuf; use rand::Rng; + use crate::common::ZExtZBuf; + let mut rng = rand::thread_rng(); let version: u8 = rng.gen(); diff --git a/commons/zenoh-protocol/src/transport/open.rs b/commons/zenoh-protocol/src/transport/open.rs index c643286193..8c2e1429ec 100644 --- a/commons/zenoh-protocol/src/transport/open.rs +++ b/commons/zenoh-protocol/src/transport/open.rs @@ -11,10 +11,12 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::transport::TransportSn; use core::time::Duration; + use zenoh_buffers::ZSlice; +use crate::transport::TransportSn; + /// # Open message /// /// After having succesfully complete the [`super::InitSyn`]-[`super::InitAck`] message exchange, @@ -88,15 +90,14 @@ pub struct OpenSyn { // Extensions pub mod ext { - use crate::{ - common::{ZExtUnit, ZExtZBuf}, - zextunit, zextzbuf, - }; - #[cfg(feature = "shared-memory")] use crate::common::ZExtZ64; #[cfg(feature = "shared-memory")] use crate::zextz64; + use crate::{ + common::{ZExtUnit, ZExtZBuf}, + zextunit, zextzbuf, + }; /// # QoS extension /// Used to negotiate the use of QoS @@ -128,11 +129,11 @@ pub mod ext { impl OpenSyn { #[cfg(feature = "test")] pub fn rand() -> Self { - use crate::common::{ZExtUnit, ZExtZBuf}; use rand::Rng; #[cfg(feature = "shared-memory")] use crate::common::ZExtZ64; + use crate::common::{ZExtUnit, ZExtZBuf}; const MIN: usize = 32; const MAX: usize = 1_024; @@ -186,11 +187,11 @@ pub struct OpenAck { impl OpenAck { #[cfg(feature = "test")] pub fn rand() -> Self { - use crate::common::{ZExtUnit, ZExtZBuf}; use rand::Rng; #[cfg(feature = "shared-memory")] use crate::common::ZExtZ64; + use crate::common::{ZExtUnit, ZExtZBuf}; let mut rng = rand::thread_rng(); diff --git a/commons/zenoh-protocol/src/zenoh/del.rs b/commons/zenoh-protocol/src/zenoh/del.rs index 84fec5bc08..4723cd5415 100644 --- a/commons/zenoh-protocol/src/zenoh/del.rs +++ b/commons/zenoh-protocol/src/zenoh/del.rs @@ -11,10 +11,12 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::common::ZExtUnknown; use alloc::vec::Vec; + use uhlc::Timestamp; +use crate::common::ZExtUnknown; + /// # Put message /// /// ```text @@ -62,8 +64,9 @@ pub mod ext { impl Del { #[cfg(feature = "test")] pub fn rand() -> Self { - use crate::{common::iext, core::ZenohId}; use rand::Rng; + + use crate::{common::iext, core::ZenohId}; let mut rng = rand::thread_rng(); let timestamp = rng.gen_bool(0.5).then_some({ diff --git a/commons/zenoh-protocol/src/zenoh/err.rs b/commons/zenoh-protocol/src/zenoh/err.rs index b6aa5f4954..b8808d96d7 100644 --- a/commons/zenoh-protocol/src/zenoh/err.rs +++ b/commons/zenoh-protocol/src/zenoh/err.rs @@ -11,10 +11,12 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::{common::ZExtUnknown, core::Encoding}; use alloc::vec::Vec; + use zenoh_buffers::ZBuf; +use crate::{common::ZExtUnknown, core::Encoding}; + /// # Err message /// /// ```text @@ -71,8 +73,9 @@ pub mod ext { impl Err { #[cfg(feature = "test")] pub fn rand() -> Self { - use crate::common::iext; use rand::Rng; + + use crate::common::iext; let mut rng = rand::thread_rng(); let encoding = Encoding::rand(); diff --git a/commons/zenoh-protocol/src/zenoh/mod.rs b/commons/zenoh-protocol/src/zenoh/mod.rs index 7bca48f3ba..af9ba853f5 100644 --- a/commons/zenoh-protocol/src/zenoh/mod.rs +++ b/commons/zenoh-protocol/src/zenoh/mod.rs @@ -17,13 +17,14 @@ pub mod put; pub mod query; pub mod reply; -use crate::core::Encoding; pub use del::Del; pub use err::Err; pub use put::Put; pub use query::{Consolidation, Query}; pub use reply::Reply; +use crate::core::Encoding; + pub mod id { pub const OAM: u8 = 0x00; pub const PUT: u8 = 0x01; diff --git a/commons/zenoh-protocol/src/zenoh/put.rs b/commons/zenoh-protocol/src/zenoh/put.rs index 14674e9ad9..ef0a71db09 100644 --- a/commons/zenoh-protocol/src/zenoh/put.rs +++ b/commons/zenoh-protocol/src/zenoh/put.rs @@ -11,11 +11,13 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::{common::ZExtUnknown, core::Encoding}; use alloc::vec::Vec; + use uhlc::Timestamp; use zenoh_buffers::ZBuf; +use crate::{common::ZExtUnknown, core::Encoding}; + /// # Put message /// /// ```text @@ -80,8 +82,9 @@ pub mod ext { impl Put { #[cfg(feature = "test")] pub fn rand() -> Self { - use crate::{common::iext, core::ZenohId}; use rand::Rng; + + use crate::{common::iext, core::ZenohId}; let mut rng = rand::thread_rng(); let timestamp = rng.gen_bool(0.5).then_some({ diff --git a/commons/zenoh-protocol/src/zenoh/query.rs b/commons/zenoh-protocol/src/zenoh/query.rs index f1baaebe20..988447b835 100644 --- a/commons/zenoh-protocol/src/zenoh/query.rs +++ b/commons/zenoh-protocol/src/zenoh/query.rs @@ -11,9 +11,10 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::common::ZExtUnknown; use alloc::{string::String, vec::Vec}; +use crate::common::ZExtUnknown; + /// The kind of consolidation. #[repr(u8)] #[derive(Debug, Default, Clone, PartialEq, Eq, Copy)] @@ -108,11 +109,12 @@ pub mod ext { impl Query { #[cfg(feature = "test")] pub fn rand() -> Self { - use crate::common::iext; use rand::{ distributions::{Alphanumeric, DistString}, Rng, }; + + use crate::common::iext; let mut rng = rand::thread_rng(); const MIN: usize = 2; diff --git a/commons/zenoh-protocol/src/zenoh/reply.rs b/commons/zenoh-protocol/src/zenoh/reply.rs index 7cbab4ca0a..f29521a4a9 100644 --- a/commons/zenoh-protocol/src/zenoh/reply.rs +++ b/commons/zenoh-protocol/src/zenoh/reply.rs @@ -11,11 +11,12 @@ // Contributors: // ZettaScale Zenoh Team, // +use alloc::vec::Vec; + use crate::{ common::ZExtUnknown, zenoh::{query::Consolidation, PushBody}, }; -use alloc::vec::Vec; /// # Reply message /// diff --git a/commons/zenoh-result/src/lib.rs b/commons/zenoh-result/src/lib.rs index 60148c763f..79de74f4eb 100644 --- a/commons/zenoh-result/src/lib.rs +++ b/commons/zenoh-result/src/lib.rs @@ -20,9 +20,10 @@ #![cfg_attr(not(feature = "std"), no_std)] extern crate alloc; -use anyhow::Error as AnyError; use core::fmt; +use anyhow::Error as AnyError; + #[cold] pub const fn cold() {} pub const fn likely(b: bool) -> bool { diff --git a/commons/zenoh-runtime/src/lib.rs b/commons/zenoh-runtime/src/lib.rs index cb58cac570..b8c3d23b9d 100644 --- a/commons/zenoh-runtime/src/lib.rs +++ b/commons/zenoh-runtime/src/lib.rs @@ -12,8 +12,6 @@ // ZettaScale Zenoh Team, // use core::panic; -use lazy_static::lazy_static; -use serde::Deserialize; use std::{ borrow::Borrow, collections::HashMap, @@ -26,6 +24,9 @@ use std::{ }, time::Duration, }; + +use lazy_static::lazy_static; +use serde::Deserialize; use tokio::runtime::{Handle, Runtime, RuntimeFlavor}; use zenoh_macros::{GenericRuntimeParam, RegisterParam}; use zenoh_result::ZResult as Result; diff --git a/commons/zenoh-shm/src/api/client/shared_memory_client.rs b/commons/zenoh-shm/src/api/client/shared_memory_client.rs index abc7221300..dd3cf5db12 100644 --- a/commons/zenoh-shm/src/api/client/shared_memory_client.rs +++ b/commons/zenoh-shm/src/api/client/shared_memory_client.rs @@ -12,15 +12,12 @@ // ZettaScale Zenoh Team, // -use std::fmt::Debug; - -use std::sync::Arc; +use std::{fmt::Debug, sync::Arc}; use zenoh_result::ZResult; -use crate::api::common::types::SegmentID; - use super::shared_memory_segment::SharedMemorySegment; +use crate::api::common::types::SegmentID; /// SharedMemoryClient - client factory implementation for particular shared memory protocol #[zenoh_macros::unstable_doc] diff --git a/commons/zenoh-shm/src/api/client/shared_memory_segment.rs b/commons/zenoh-shm/src/api/client/shared_memory_segment.rs index 88eaf8761f..e3aaf9ba39 100644 --- a/commons/zenoh-shm/src/api/client/shared_memory_segment.rs +++ b/commons/zenoh-shm/src/api/client/shared_memory_segment.rs @@ -12,9 +12,7 @@ // ZettaScale Zenoh Team, // -use std::fmt::Debug; - -use std::sync::atomic::AtomicPtr; +use std::{fmt::Debug, sync::atomic::AtomicPtr}; use zenoh_result::ZResult; diff --git a/commons/zenoh-shm/src/api/client_storage/mod.rs b/commons/zenoh-shm/src/api/client_storage/mod.rs index 0ce1a8af11..7b78c23182 100644 --- a/commons/zenoh-shm/src/api/client_storage/mod.rs +++ b/commons/zenoh-shm/src/api/client_storage/mod.rs @@ -12,26 +12,27 @@ // ZettaScale Zenoh Team, // -use lazy_static::lazy_static; use std::{ collections::HashMap, sync::{Arc, RwLock}, }; +use lazy_static::lazy_static; use zenoh_result::{bail, ZResult}; -use crate::api::{ - client::{ - shared_memory_client::SharedMemoryClient, shared_memory_segment::SharedMemorySegment, - }, - common::types::ProtocolID, - protocol_implementations::posix::{ - posix_shared_memory_client::PosixSharedMemoryClient, protocol_id::POSIX_PROTOCOL_ID, +use crate::{ + api::{ + client::{ + shared_memory_client::SharedMemoryClient, shared_memory_segment::SharedMemorySegment, + }, + common::types::ProtocolID, + protocol_implementations::posix::{ + posix_shared_memory_client::PosixSharedMemoryClient, protocol_id::POSIX_PROTOCOL_ID, + }, }, + reader::{ClientStorage, GlobalDataSegmentID}, }; -use crate::reader::{ClientStorage, GlobalDataSegmentID}; - lazy_static! { /// A global lazily-initialized SHM client storage. /// When initialized, contains default client set, diff --git a/commons/zenoh-shm/src/api/protocol_implementations/posix/posix_shared_memory_client.rs b/commons/zenoh-shm/src/api/protocol_implementations/posix/posix_shared_memory_client.rs index 0184f50036..5684b0b15f 100644 --- a/commons/zenoh-shm/src/api/protocol_implementations/posix/posix_shared_memory_client.rs +++ b/commons/zenoh-shm/src/api/protocol_implementations/posix/posix_shared_memory_client.rs @@ -16,6 +16,7 @@ use std::sync::Arc; use zenoh_result::ZResult; +use super::posix_shared_memory_segment::PosixSharedMemorySegment; use crate::api::{ client::{ shared_memory_client::SharedMemoryClient, shared_memory_segment::SharedMemorySegment, @@ -23,8 +24,6 @@ use crate::api::{ common::types::SegmentID, }; -use super::posix_shared_memory_segment::PosixSharedMemorySegment; - /// Client factory implementation for particular shared memory protocol #[zenoh_macros::unstable_doc] #[derive(Debug)] diff --git a/commons/zenoh-shm/src/api/protocol_implementations/posix/posix_shared_memory_provider_backend.rs b/commons/zenoh-shm/src/api/protocol_implementations/posix/posix_shared_memory_provider_backend.rs index 89c1b91387..60e2a10891 100644 --- a/commons/zenoh-shm/src/api/protocol_implementations/posix/posix_shared_memory_provider_backend.rs +++ b/commons/zenoh-shm/src/api/protocol_implementations/posix/posix_shared_memory_provider_backend.rs @@ -25,6 +25,7 @@ use std::{ use zenoh_core::zlock; use zenoh_result::ZResult; +use super::posix_shared_memory_segment::PosixSharedMemorySegment; use crate::api::{ common::types::ChunkID, provider::{ @@ -34,8 +35,6 @@ use crate::api::{ }, }; -use super::posix_shared_memory_segment::PosixSharedMemorySegment; - // TODO: MIN_FREE_CHUNK_SIZE limitation is made to reduce memory fragmentation and lower // the CPU time needed to defragment() - that's reasonable, and there is additional thing here: // our SHM\zerocopy functionality outperforms common buffer transmission only starting from 1K diff --git a/commons/zenoh-shm/src/api/protocol_implementations/posix/posix_shared_memory_segment.rs b/commons/zenoh-shm/src/api/protocol_implementations/posix/posix_shared_memory_segment.rs index eb49d141ca..3f74594ad0 100644 --- a/commons/zenoh-shm/src/api/protocol_implementations/posix/posix_shared_memory_segment.rs +++ b/commons/zenoh-shm/src/api/protocol_implementations/posix/posix_shared_memory_segment.rs @@ -16,10 +16,13 @@ use std::sync::atomic::AtomicPtr; use zenoh_result::ZResult; -use crate::api::common::types::SegmentID; -use crate::api::{client::shared_memory_segment::SharedMemorySegment, common::types::ChunkID}; - -use crate::posix_shm::array::ArrayInSHM; +use crate::{ + api::{ + client::shared_memory_segment::SharedMemorySegment, + common::types::{ChunkID, SegmentID}, + }, + posix_shm::array::ArrayInSHM, +}; const POSIX_SHM_SEGMENT_PREFIX: &str = "posix_shm_provider_segment"; diff --git a/commons/zenoh-shm/src/api/provider/shared_memory_provider.rs b/commons/zenoh-shm/src/api/provider/shared_memory_provider.rs index c3b8128300..58109a699d 100644 --- a/commons/zenoh-shm/src/api/provider/shared_memory_provider.rs +++ b/commons/zenoh-shm/src/api/provider/shared_memory_provider.rs @@ -22,6 +22,11 @@ use std::{ use async_trait::async_trait; use zenoh_result::ZResult; +use super::{ + chunk::{AllocatedChunk, ChunkDescriptor}, + shared_memory_provider_backend::SharedMemoryProviderBackend, + types::{AllocAlignment, BufAllocResult, ChunkAllocResult, MemoryLayout, ZAllocError}, +}; use crate::{ api::{common::types::ProtocolID, slice::zsliceshmmut::ZSliceShmMut}, header::{ @@ -38,12 +43,6 @@ use crate::{ SharedMemoryBuf, SharedMemoryBufInfo, }; -use super::{ - chunk::{AllocatedChunk, ChunkDescriptor}, - shared_memory_provider_backend::SharedMemoryProviderBackend, - types::{AllocAlignment, BufAllocResult, ChunkAllocResult, MemoryLayout, ZAllocError}, -}; - #[derive(Debug)] struct BusyChunk { descriptor: ChunkDescriptor, diff --git a/commons/zenoh-shm/src/api/provider/types.rs b/commons/zenoh-shm/src/api/provider/types.rs index 662482f567..ddf949ee75 100644 --- a/commons/zenoh-shm/src/api/provider/types.rs +++ b/commons/zenoh-shm/src/api/provider/types.rs @@ -16,9 +16,8 @@ use std::fmt::Display; use zenoh_result::{bail, ZResult}; -use crate::api::slice::zsliceshmmut::ZSliceShmMut; - use super::chunk::AllocatedChunk; +use crate::api::slice::zsliceshmmut::ZSliceShmMut; /// Allocation errors /// diff --git a/commons/zenoh-shm/src/api/slice/zsliceshm.rs b/commons/zenoh-shm/src/api/slice/zsliceshm.rs index 86f4395ebb..b2ba611b3c 100644 --- a/commons/zenoh-shm/src/api/slice/zsliceshm.rs +++ b/commons/zenoh-shm/src/api/slice/zsliceshm.rs @@ -20,9 +20,8 @@ use std::{ use zenoh_buffers::{ZBuf, ZSlice}; -use crate::SharedMemoryBuf; - use super::{traits::SHMBuf, zsliceshmmut::zsliceshmmut}; +use crate::SharedMemoryBuf; /// An immutable SHM slice #[zenoh_macros::unstable_doc] diff --git a/commons/zenoh-shm/src/api/slice/zsliceshmmut.rs b/commons/zenoh-shm/src/api/slice/zsliceshmmut.rs index 62823785da..d866e4173e 100644 --- a/commons/zenoh-shm/src/api/slice/zsliceshmmut.rs +++ b/commons/zenoh-shm/src/api/slice/zsliceshmmut.rs @@ -17,12 +17,11 @@ use std::borrow::{Borrow, BorrowMut}; use zenoh_buffers::{ZBuf, ZSlice}; -use crate::SharedMemoryBuf; - use super::{ traits::{SHMBuf, SHMBufMut}, zsliceshm::{zsliceshm, ZSliceShm}, }; +use crate::SharedMemoryBuf; /// A mutable SHM slice #[zenoh_macros::unstable_doc] diff --git a/commons/zenoh-shm/src/header/segment.rs b/commons/zenoh-shm/src/header/segment.rs index e36e54a233..ab2353c35d 100644 --- a/commons/zenoh-shm/src/header/segment.rs +++ b/commons/zenoh-shm/src/header/segment.rs @@ -14,12 +14,11 @@ use zenoh_result::ZResult; -use crate::posix_shm::array::ArrayInSHM; - use super::{ chunk_header::ChunkHeaderType, descriptor::{HeaderIndex, HeaderSegmentID}, }; +use crate::posix_shm::array::ArrayInSHM; const HEADER_SEGMENT_PREFIX: &str = "header"; diff --git a/commons/zenoh-shm/src/lib.rs b/commons/zenoh-shm/src/lib.rs index abcdd558fb..316477d26e 100644 --- a/commons/zenoh-shm/src/lib.rs +++ b/commons/zenoh-shm/src/lib.rs @@ -11,8 +11,6 @@ // Contributors: // ZettaScale Zenoh Team, // -use api::{common::types::ProtocolID, provider::chunk::ChunkDescriptor}; -use header::descriptor::{HeaderDescriptor, OwnedHeaderDescriptor}; use std::{ any::Any, sync::{ @@ -20,6 +18,9 @@ use std::{ Arc, }, }; + +use api::{common::types::ProtocolID, provider::chunk::ChunkDescriptor}; +use header::descriptor::{HeaderDescriptor, OwnedHeaderDescriptor}; use watchdog::{confirmator::ConfirmedDescriptor, descriptor::Descriptor}; use zenoh_buffers::ZSliceBuffer; diff --git a/commons/zenoh-shm/src/watchdog/segment.rs b/commons/zenoh-shm/src/watchdog/segment.rs index b4a273c01c..5943a10153 100644 --- a/commons/zenoh-shm/src/watchdog/segment.rs +++ b/commons/zenoh-shm/src/watchdog/segment.rs @@ -16,9 +16,8 @@ use std::sync::atomic::AtomicU64; use zenoh_result::ZResult; -use crate::posix_shm::array::ArrayInSHM; - use super::descriptor::SegmentID; +use crate::posix_shm::array::ArrayInSHM; const WATCHDOG_SEGMENT_PREFIX: &str = "watchdog"; diff --git a/commons/zenoh-sync/src/condition.rs b/commons/zenoh-sync/src/condition.rs index 098aa05411..99ba6d4ca2 100644 --- a/commons/zenoh-sync/src/condition.rs +++ b/commons/zenoh-sync/src/condition.rs @@ -11,8 +11,9 @@ // Contributors: // ZettaScale Zenoh Team, // -use event_listener::{Event, EventListener}; use std::{pin::Pin, sync::MutexGuard}; + +use event_listener::{Event, EventListener}; use tokio::sync::MutexGuard as AysncMutexGuard; pub type ConditionWaiter = Pin>; diff --git a/commons/zenoh-sync/src/fifo_queue.rs b/commons/zenoh-sync/src/fifo_queue.rs index e0ce57cb36..44bc2a5b17 100644 --- a/commons/zenoh-sync/src/fifo_queue.rs +++ b/commons/zenoh-sync/src/fifo_queue.rs @@ -11,11 +11,12 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::Condition; use tokio::sync::Mutex; use zenoh_collections::RingBuffer; use zenoh_core::zasynclock; +use crate::Condition; + pub struct FifoQueue { not_empty: Condition, not_full: Condition, diff --git a/commons/zenoh-sync/src/lib.rs b/commons/zenoh-sync/src/lib.rs index 419246dc9d..20e95d2bb8 100644 --- a/commons/zenoh-sync/src/lib.rs +++ b/commons/zenoh-sync/src/lib.rs @@ -17,10 +17,13 @@ //! This module is intended for Zenoh's internal use. //! //! [Click here for Zenoh's documentation](../zenoh/index.html) +use std::{ + future::Future, + pin::Pin, + task::{Context, Poll}, +}; + use futures::FutureExt; -use std::future::Future; -use std::pin::Pin; -use std::task::{Context, Poll}; pub mod fifo_queue; pub use fifo_queue::*; diff --git a/commons/zenoh-sync/src/lifo_queue.rs b/commons/zenoh-sync/src/lifo_queue.rs index f29614d4b2..9fe541da36 100644 --- a/commons/zenoh-sync/src/lifo_queue.rs +++ b/commons/zenoh-sync/src/lifo_queue.rs @@ -12,6 +12,7 @@ // ZettaScale Zenoh Team, // use std::sync::{Condvar, Mutex}; + use zenoh_collections::StackBuffer; use zenoh_core::zlock; diff --git a/commons/zenoh-sync/src/mvar.rs b/commons/zenoh-sync/src/mvar.rs index 1b4a90e1e2..f818b44071 100644 --- a/commons/zenoh-sync/src/mvar.rs +++ b/commons/zenoh-sync/src/mvar.rs @@ -11,11 +11,13 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::Condition; use std::sync::atomic::{AtomicUsize, Ordering}; + use tokio::sync::Mutex; use zenoh_core::zasynclock; +use crate::Condition; + pub struct Mvar { inner: Mutex>, cond_put: Condition, @@ -96,9 +98,9 @@ mod tests { #[tokio::test(flavor = "multi_thread", worker_threads = 4)] async fn mvar() -> ZResult<()> { + use std::{sync::Arc, time::Duration}; + use super::Mvar; - use std::sync::Arc; - use std::time::Duration; const TIMEOUT: Duration = Duration::from_secs(60); diff --git a/commons/zenoh-sync/src/object_pool.rs b/commons/zenoh-sync/src/object_pool.rs index 3386b2058b..ee6eed881b 100644 --- a/commons/zenoh-sync/src/object_pool.rs +++ b/commons/zenoh-sync/src/object_pool.rs @@ -11,15 +11,17 @@ // Contributors: // ZettaScale Zenoh Team, // -use super::LifoQueue; use std::{ any::Any, fmt, ops::{Deref, DerefMut, Drop}, sync::{Arc, Weak}, }; + use zenoh_buffers::ZSliceBuffer; +use super::LifoQueue; + /// Provides a pool of pre-allocated objects that are automaticlaly reinserted into /// the pool when dropped. pub struct RecyclingObjectPool diff --git a/commons/zenoh-sync/src/signal.rs b/commons/zenoh-sync/src/signal.rs index 74dd3e5199..053f5a13aa 100644 --- a/commons/zenoh-sync/src/signal.rs +++ b/commons/zenoh-sync/src/signal.rs @@ -11,8 +11,11 @@ // Contributors: // ZettaScale Zenoh Team, // -use std::sync::atomic::{AtomicBool, Ordering::*}; -use std::sync::Arc; +use std::sync::{ + atomic::{AtomicBool, Ordering::*}, + Arc, +}; + use tokio::sync::Semaphore; #[derive(Debug, Clone)] @@ -68,9 +71,10 @@ impl Default for Signal { #[cfg(test)] mod tests { - use super::*; use std::time::Duration; + use super::*; + #[tokio::test(flavor = "multi_thread", worker_threads = 4)] async fn signal_test() { let signal = Signal::new(); diff --git a/commons/zenoh-task/src/lib.rs b/commons/zenoh-task/src/lib.rs index d41eb50f34..7eab9d316f 100644 --- a/commons/zenoh-task/src/lib.rs +++ b/commons/zenoh-task/src/lib.rs @@ -18,12 +18,11 @@ //! //! [Click here for Zenoh's documentation](../zenoh/index.html) +use std::{future::Future, time::Duration}; + use futures::future::FutureExt; -use std::future::Future; -use std::time::Duration; use tokio::task::JoinHandle; -use tokio_util::sync::CancellationToken; -use tokio_util::task::TaskTracker; +use tokio_util::{sync::CancellationToken, task::TaskTracker}; use zenoh_core::{ResolveFuture, Wait}; use zenoh_runtime::ZRuntime; diff --git a/commons/zenoh-util/src/std_only/ffi/win.rs b/commons/zenoh-util/src/std_only/ffi/win.rs index 3a15871c20..7f0bbd986a 100644 --- a/commons/zenoh-util/src/std_only/ffi/win.rs +++ b/commons/zenoh-util/src/std_only/ffi/win.rs @@ -11,9 +11,11 @@ // Contributors: // ZettaScale Zenoh Team, // -use std::io; -use std::mem; -use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6}; +use std::{ + io, mem, + net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6}, +}; + use winapi::shared::{ws2def, ws2ipdef}; #[allow(clippy::many_single_char_names)] diff --git a/commons/zenoh-util/src/std_only/lib_loader.rs b/commons/zenoh-util/src/std_only/lib_loader.rs index 9c682e4343..d6b254eb35 100644 --- a/commons/zenoh-util/src/std_only/lib_loader.rs +++ b/commons/zenoh-util/src/std_only/lib_loader.rs @@ -11,11 +11,14 @@ // Contributors: // ZettaScale Zenoh Team, // +use std::{ + env::consts::{DLL_PREFIX, DLL_SUFFIX}, + ffi::OsString, + ops::Deref, + path::PathBuf, +}; + use libloading::Library; -use std::env::consts::{DLL_PREFIX, DLL_SUFFIX}; -use std::ffi::OsString; -use std::ops::Deref; -use std::path::PathBuf; use tracing::{debug, warn}; use zenoh_core::zconfigurable; use zenoh_result::{bail, ZResult}; diff --git a/commons/zenoh-util/src/std_only/net/mod.rs b/commons/zenoh-util/src/std_only/net/mod.rs index 83ab08d678..65b665d31b 100644 --- a/commons/zenoh-util/src/std_only/net/mod.rs +++ b/commons/zenoh-util/src/std_only/net/mod.rs @@ -12,6 +12,7 @@ // ZettaScale Zenoh Team, // use std::net::{IpAddr, Ipv6Addr}; + use tokio::net::{TcpSocket, UdpSocket}; use zenoh_core::zconfigurable; #[cfg(unix)] @@ -78,9 +79,10 @@ pub fn get_interface(name: &str) -> ZResult> { #[cfg(windows)] { unsafe { - use crate::ffi; use winapi::um::iptypes::IP_ADAPTER_ADDRESSES_LH; + use crate::ffi; + let buffer = get_adapters_adresses(winapi::shared::ws2def::AF_INET)?; let mut next_iface = (buffer.as_ptr() as *mut IP_ADAPTER_ADDRESSES_LH).as_ref(); @@ -162,9 +164,10 @@ pub fn get_local_addresses(interface: Option<&str>) -> ZResult> { #[cfg(windows)] { unsafe { - use crate::ffi; use winapi::um::iptypes::IP_ADAPTER_ADDRESSES_LH; + use crate::ffi; + let buffer = get_adapters_adresses(winapi::shared::ws2def::AF_UNSPEC)?; let mut result = vec![]; @@ -242,9 +245,10 @@ pub fn get_unicast_addresses_of_interface(name: &str) -> ZResult> { #[cfg(windows)] { unsafe { - use crate::ffi; use winapi::um::iptypes::IP_ADAPTER_ADDRESSES_LH; + use crate::ffi; + let buffer = get_adapters_adresses(winapi::shared::ws2def::AF_INET)?; let mut addrs = vec![]; @@ -281,9 +285,10 @@ pub fn get_index_of_interface(addr: IpAddr) -> ZResult { #[cfg(windows)] { unsafe { - use crate::ffi; use winapi::um::iptypes::IP_ADAPTER_ADDRESSES_LH; + use crate::ffi; + let buffer = get_adapters_adresses(winapi::shared::ws2def::AF_INET)?; let mut next_iface = (buffer.as_ptr() as *mut IP_ADAPTER_ADDRESSES_LH).as_ref(); @@ -324,9 +329,10 @@ pub fn get_interface_names_by_addr(addr: IpAddr) -> ZResult> { { let mut result = vec![]; unsafe { - use crate::ffi; use winapi::um::iptypes::IP_ADAPTER_ADDRESSES_LH; + use crate::ffi; + let buffer = get_adapters_adresses(winapi::shared::ws2def::AF_UNSPEC)?; if addr.is_unspecified() { diff --git a/commons/zenoh-util/src/std_only/time_range.rs b/commons/zenoh-util/src/std_only/time_range.rs index 9cfaf32655..51bff157ba 100644 --- a/commons/zenoh-util/src/std_only/time_range.rs +++ b/commons/zenoh-util/src/std_only/time_range.rs @@ -12,7 +12,6 @@ // ZettaScale Zenoh Team, // -use humantime::{format_rfc3339, parse_rfc3339_weak}; use std::{ convert::{TryFrom, TryInto}, fmt::Display, @@ -20,6 +19,8 @@ use std::{ str::FromStr, time::{Duration, SystemTime}, }; + +use humantime::{format_rfc3339, parse_rfc3339_weak}; use zenoh_result::{bail, zerror, ZError}; const U_TO_SECS: f64 = 0.000001; diff --git a/commons/zenoh-util/src/std_only/timer.rs b/commons/zenoh-util/src/std_only/timer.rs index 6e7dde065a..d18b9192a4 100644 --- a/commons/zenoh-util/src/std_only/timer.rs +++ b/commons/zenoh-util/src/std_only/timer.rs @@ -11,16 +11,19 @@ // Contributors: // ZettaScale Zenoh Team, // -use async_std::prelude::*; -use async_std::sync::Mutex; -use async_std::task; +use std::{ + cmp::Ordering as ComparisonOrdering, + collections::BinaryHeap, + sync::{ + atomic::{AtomicBool, Ordering as AtomicOrdering}, + Arc, Weak, + }, + time::{Duration, Instant}, +}; + +use async_std::{prelude::*, sync::Mutex, task}; use async_trait::async_trait; use flume::{bounded, Receiver, RecvError, Sender}; -use std::cmp::Ordering as ComparisonOrdering; -use std::collections::BinaryHeap; -use std::sync::atomic::{AtomicBool, Ordering as AtomicOrdering}; -use std::sync::{Arc, Weak}; -use std::time::{Duration, Instant}; use zenoh_core::zconfigurable; zconfigurable! { @@ -296,12 +299,18 @@ impl Default for Timer { mod tests { #[test] fn timer() { - use super::{Timed, TimedEvent, Timer}; + use std::{ + sync::{ + atomic::{AtomicUsize, Ordering}, + Arc, + }, + time::{Duration, Instant}, + }; + use async_std::task; use async_trait::async_trait; - use std::sync::atomic::{AtomicUsize, Ordering}; - use std::sync::Arc; - use std::time::{Duration, Instant}; + + use super::{Timed, TimedEvent, Timer}; #[derive(Clone)] struct MyEvent { diff --git a/examples/examples/z_get.rs b/examples/examples/z_get.rs index 6b6326ebcf..2b5ba011f6 100644 --- a/examples/examples/z_get.rs +++ b/examples/examples/z_get.rs @@ -11,8 +11,9 @@ // Contributors: // ZettaScale Zenoh Team, // -use clap::Parser; use std::time::Duration; + +use clap::Parser; use zenoh::prelude::*; use zenoh_examples::CommonArgs; diff --git a/examples/examples/z_get_liveliness.rs b/examples/examples/z_get_liveliness.rs index 43747697b6..6a616bfa2d 100644 --- a/examples/examples/z_get_liveliness.rs +++ b/examples/examples/z_get_liveliness.rs @@ -11,8 +11,9 @@ // Contributors: // ZettaScale Zenoh Team, // -use clap::Parser; use std::time::Duration; + +use clap::Parser; use zenoh::prelude::*; use zenoh_examples::CommonArgs; diff --git a/examples/examples/z_ping.rs b/examples/examples/z_ping.rs index 81181f1a81..ad761bddd2 100644 --- a/examples/examples/z_ping.rs +++ b/examples/examples/z_ping.rs @@ -11,8 +11,9 @@ // Contributors: // ZettaScale Zenoh Team, // -use clap::Parser; use std::time::{Duration, Instant}; + +use clap::Parser; use zenoh::prelude::*; use zenoh_examples::CommonArgs; diff --git a/examples/examples/z_ping_shm.rs b/examples/examples/z_ping_shm.rs index 7a7bd61580..d4c5b4f162 100644 --- a/examples/examples/z_ping_shm.rs +++ b/examples/examples/z_ping_shm.rs @@ -11,8 +11,9 @@ // Contributors: // ZettaScale Zenoh Team, // -use clap::Parser; use std::time::{Duration, Instant}; + +use clap::Parser; use zenoh::prelude::*; use zenoh_examples::CommonArgs; diff --git a/examples/examples/z_pub.rs b/examples/examples/z_pub.rs index 7c2c9f2c65..0a2e4e09c1 100644 --- a/examples/examples/z_pub.rs +++ b/examples/examples/z_pub.rs @@ -11,8 +11,9 @@ // Contributors: // ZettaScale Zenoh Team, // -use clap::Parser; use std::time::Duration; + +use clap::Parser; use zenoh::prelude::*; use zenoh_examples::CommonArgs; diff --git a/examples/examples/z_pub_thr.rs b/examples/examples/z_pub_thr.rs index 5eb4f9e96e..d047d63203 100644 --- a/examples/examples/z_pub_thr.rs +++ b/examples/examples/z_pub_thr.rs @@ -12,8 +12,9 @@ // ZettaScale Zenoh Team, // -use clap::Parser; use std::convert::TryInto; + +use clap::Parser; use zenoh::prelude::*; use zenoh_examples::CommonArgs; diff --git a/examples/examples/z_pull.rs b/examples/examples/z_pull.rs index 55f211f111..1e13cefb2f 100644 --- a/examples/examples/z_pull.rs +++ b/examples/examples/z_pull.rs @@ -11,8 +11,9 @@ // Contributors: // ZettaScale Zenoh Team, // -use clap::Parser; use std::time::Duration; + +use clap::Parser; use zenoh::prelude::*; use zenoh_examples::CommonArgs; diff --git a/examples/examples/z_storage.rs b/examples/examples/z_storage.rs index 2b03e32d06..46ccfc8193 100644 --- a/examples/examples/z_storage.rs +++ b/examples/examples/z_storage.rs @@ -13,9 +13,10 @@ // #![recursion_limit = "256"] +use std::collections::HashMap; + use clap::Parser; use futures::select; -use std::collections::HashMap; use zenoh::prelude::*; use zenoh_examples::CommonArgs; diff --git a/examples/examples/z_sub_shm.rs b/examples/examples/z_sub_shm.rs index 5f5c77633f..9914539ed5 100644 --- a/examples/examples/z_sub_shm.rs +++ b/examples/examples/z_sub_shm.rs @@ -12,8 +12,7 @@ // ZettaScale Zenoh Team, // use clap::Parser; -use zenoh::config::Config; -use zenoh::prelude::*; +use zenoh::{config::Config, prelude::*}; use zenoh_examples::CommonArgs; #[tokio::main] diff --git a/examples/examples/z_sub_thr.rs b/examples/examples/z_sub_thr.rs index 6913a7bf08..1006fdb434 100644 --- a/examples/examples/z_sub_thr.rs +++ b/examples/examples/z_sub_thr.rs @@ -11,8 +11,9 @@ // Contributors: // ZettaScale Zenoh Team, // -use clap::Parser; use std::time::Instant; + +use clap::Parser; use zenoh::prelude::*; use zenoh_examples::CommonArgs; diff --git a/io/zenoh-link-commons/src/lib.rs b/io/zenoh-link-commons/src/lib.rs index 138726fd4f..5a41050e94 100644 --- a/io/zenoh-link-commons/src/lib.rs +++ b/io/zenoh-link-commons/src/lib.rs @@ -25,14 +25,14 @@ pub mod tls; mod unicast; use alloc::{borrow::ToOwned, boxed::Box, string::String, vec, vec::Vec}; -use async_trait::async_trait; use core::{cmp::PartialEq, fmt, hash::Hash}; + +use async_trait::async_trait; pub use listener::*; pub use multicast::*; use serde::Serialize; pub use unicast::*; -use zenoh_protocol::core::Locator; -use zenoh_protocol::transport::BatchSize; +use zenoh_protocol::{core::Locator, transport::BatchSize}; use zenoh_result::ZResult; /*************************************/ diff --git a/io/zenoh-link-commons/src/listener.rs b/io/zenoh-link-commons/src/listener.rs index be61e9cf89..48930a7a65 100644 --- a/io/zenoh-link-commons/src/listener.rs +++ b/io/zenoh-link-commons/src/listener.rs @@ -11,11 +11,13 @@ // Contributors: // ZettaScale Zenoh Team, // +use std::{ + collections::HashMap, + net::{IpAddr, SocketAddr}, + sync::{Arc, RwLock}, +}; + use futures::Future; -use std::collections::HashMap; -use std::net::IpAddr; -use std::net::SocketAddr; -use std::sync::{Arc, RwLock}; use tokio::task::JoinHandle; use tokio_util::sync::CancellationToken; use zenoh_core::{zread, zwrite}; diff --git a/io/zenoh-link-commons/src/multicast.rs b/io/zenoh-link-commons/src/multicast.rs index ccfe6842c1..ee07c4eb58 100644 --- a/io/zenoh-link-commons/src/multicast.rs +++ b/io/zenoh-link-commons/src/multicast.rs @@ -12,12 +12,13 @@ // ZettaScale Zenoh Team, // use alloc::{borrow::Cow, boxed::Box, sync::Arc, vec::Vec}; -use async_trait::async_trait; use core::{ fmt, hash::{Hash, Hasher}, ops::Deref, }; + +use async_trait::async_trait; use zenoh_buffers::{reader::HasReader, writer::HasWriter}; use zenoh_codec::{RCodec, WCodec, Zenoh080}; use zenoh_protocol::{ diff --git a/io/zenoh-link-commons/src/tls.rs b/io/zenoh-link-commons/src/tls.rs index 562b02c81e..427880b812 100644 --- a/io/zenoh-link-commons/src/tls.rs +++ b/io/zenoh-link-commons/src/tls.rs @@ -1,4 +1,5 @@ use alloc::vec::Vec; + use rustls::{ client::{ danger::{ServerCertVerified, ServerCertVerifier}, diff --git a/io/zenoh-link-commons/src/unicast.rs b/io/zenoh-link-commons/src/unicast.rs index 2bd1808acf..add4c3a27b 100644 --- a/io/zenoh-link-commons/src/unicast.rs +++ b/io/zenoh-link-commons/src/unicast.rs @@ -12,13 +12,14 @@ // ZettaScale Zenoh Team, // use alloc::{boxed::Box, string::String, sync::Arc, vec::Vec}; -use async_trait::async_trait; use core::{ fmt, hash::{Hash, Hasher}, ops::Deref, }; use std::net::SocketAddr; + +use async_trait::async_trait; use zenoh_protocol::{ core::{EndPoint, Locator}, transport::BatchSize, diff --git a/io/zenoh-link/src/lib.rs b/io/zenoh-link/src/lib.rs index 21f26ecf1b..7898cf087d 100644 --- a/io/zenoh-link/src/lib.rs +++ b/io/zenoh-link/src/lib.rs @@ -18,40 +18,41 @@ //! //! [Click here for Zenoh's documentation](../zenoh/index.html) use std::collections::HashMap; -use zenoh_config::Config; -use zenoh_result::{bail, ZResult}; +use zenoh_config::Config; +pub use zenoh_link_commons::*; +#[cfg(feature = "transport_quic")] +pub use zenoh_link_quic as quic; +#[cfg(feature = "transport_quic")] +use zenoh_link_quic::{ + LinkManagerUnicastQuic, QuicConfigurator, QuicLocatorInspector, QUIC_LOCATOR_PREFIX, +}; +#[cfg(feature = "transport_serial")] +pub use zenoh_link_serial as serial; +#[cfg(feature = "transport_serial")] +use zenoh_link_serial::{LinkManagerUnicastSerial, SerialLocatorInspector, SERIAL_LOCATOR_PREFIX}; #[cfg(feature = "transport_tcp")] pub use zenoh_link_tcp as tcp; #[cfg(feature = "transport_tcp")] use zenoh_link_tcp::{LinkManagerUnicastTcp, TcpLocatorInspector, TCP_LOCATOR_PREFIX}; - -#[cfg(feature = "transport_udp")] -pub use zenoh_link_udp as udp; -#[cfg(feature = "transport_udp")] -use zenoh_link_udp::{ - LinkManagerMulticastUdp, LinkManagerUnicastUdp, UdpLocatorInspector, UDP_LOCATOR_PREFIX, -}; - #[cfg(feature = "transport_tls")] pub use zenoh_link_tls as tls; #[cfg(feature = "transport_tls")] use zenoh_link_tls::{ LinkManagerUnicastTls, TlsConfigurator, TlsLocatorInspector, TLS_LOCATOR_PREFIX, }; - -#[cfg(feature = "transport_quic")] -pub use zenoh_link_quic as quic; -#[cfg(feature = "transport_quic")] -use zenoh_link_quic::{ - LinkManagerUnicastQuic, QuicConfigurator, QuicLocatorInspector, QUIC_LOCATOR_PREFIX, +#[cfg(feature = "transport_udp")] +pub use zenoh_link_udp as udp; +#[cfg(feature = "transport_udp")] +use zenoh_link_udp::{ + LinkManagerMulticastUdp, LinkManagerUnicastUdp, UdpLocatorInspector, UDP_LOCATOR_PREFIX, +}; +#[cfg(feature = "transport_unixpipe")] +pub use zenoh_link_unixpipe as unixpipe; +#[cfg(feature = "transport_unixpipe")] +use zenoh_link_unixpipe::{ + LinkManagerUnicastPipe, UnixPipeConfigurator, UnixPipeLocatorInspector, UNIXPIPE_LOCATOR_PREFIX, }; - -#[cfg(feature = "transport_ws")] -pub use zenoh_link_ws as ws; -#[cfg(feature = "transport_ws")] -use zenoh_link_ws::{LinkManagerUnicastWs, WsLocatorInspector, WS_LOCATOR_PREFIX}; - #[cfg(all(feature = "transport_unixsock-stream", target_family = "unix"))] pub use zenoh_link_unixsock_stream as unixsock_stream; #[cfg(all(feature = "transport_unixsock-stream", target_family = "unix"))] @@ -59,26 +60,16 @@ use zenoh_link_unixsock_stream::{ LinkManagerUnicastUnixSocketStream, UnixSockStreamLocatorInspector, UNIXSOCKSTREAM_LOCATOR_PREFIX, }; - -#[cfg(feature = "transport_serial")] -pub use zenoh_link_serial as serial; -#[cfg(feature = "transport_serial")] -use zenoh_link_serial::{LinkManagerUnicastSerial, SerialLocatorInspector, SERIAL_LOCATOR_PREFIX}; - -#[cfg(feature = "transport_unixpipe")] -pub use zenoh_link_unixpipe as unixpipe; -#[cfg(feature = "transport_unixpipe")] -use zenoh_link_unixpipe::{ - LinkManagerUnicastPipe, UnixPipeConfigurator, UnixPipeLocatorInspector, UNIXPIPE_LOCATOR_PREFIX, -}; - #[cfg(all(feature = "transport_vsock", target_os = "linux"))] pub use zenoh_link_vsock as vsock; #[cfg(all(feature = "transport_vsock", target_os = "linux"))] use zenoh_link_vsock::{LinkManagerUnicastVsock, VsockLocatorInspector, VSOCK_LOCATOR_PREFIX}; - -pub use zenoh_link_commons::*; +#[cfg(feature = "transport_ws")] +pub use zenoh_link_ws as ws; +#[cfg(feature = "transport_ws")] +use zenoh_link_ws::{LinkManagerUnicastWs, WsLocatorInspector, WS_LOCATOR_PREFIX}; pub use zenoh_protocol::core::{EndPoint, Locator}; +use zenoh_result::{bail, ZResult}; pub const PROTOCOLS: &[&str] = &[ #[cfg(feature = "transport_quic")] diff --git a/io/zenoh-links/zenoh-link-quic/src/lib.rs b/io/zenoh-links/zenoh-link-quic/src/lib.rs index a60f84c559..a7303a9622 100644 --- a/io/zenoh-links/zenoh-link-quic/src/lib.rs +++ b/io/zenoh-links/zenoh-link-quic/src/lib.rs @@ -18,7 +18,6 @@ //! //! [Click here for Zenoh's documentation](../zenoh/index.html) use async_trait::async_trait; - use zenoh_core::zconfigurable; use zenoh_link_commons::LocatorInspector; use zenoh_protocol::{core::Locator, transport::BatchSize}; diff --git a/io/zenoh-links/zenoh-link-quic/src/unicast.rs b/io/zenoh-links/zenoh-link-quic/src/unicast.rs index 05d33dff49..a3b2687b6f 100644 --- a/io/zenoh-links/zenoh-link-quic/src/unicast.rs +++ b/io/zenoh-links/zenoh-link-quic/src/unicast.rs @@ -12,17 +12,14 @@ // ZettaScale Zenoh Team, // -use crate::{ - config::*, - utils::{get_quic_addr, TlsClientConfig, TlsServerConfig}, - ALPN_QUIC_HTTP, QUIC_ACCEPT_THROTTLE_TIME, QUIC_DEFAULT_MTU, QUIC_LOCATOR_PREFIX, +use std::{ + fmt, + net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr}, + sync::Arc, + time::Duration, }; + use async_trait::async_trait; -use std::fmt; -use std::net::IpAddr; -use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr}; -use std::sync::Arc; -use std::time::Duration; use tokio::sync::Mutex as AsyncMutex; use tokio_util::sync::CancellationToken; use zenoh_core::zasynclock; @@ -30,10 +27,18 @@ use zenoh_link_commons::{ get_ip_interface_names, LinkManagerUnicastTrait, LinkUnicast, LinkUnicastTrait, ListenersUnicastIP, NewLinkChannelSender, }; -use zenoh_protocol::core::{EndPoint, Locator}; -use zenoh_protocol::transport::BatchSize; +use zenoh_protocol::{ + core::{EndPoint, Locator}, + transport::BatchSize, +}; use zenoh_result::{bail, zerror, ZResult}; +use crate::{ + config::*, + utils::{get_quic_addr, TlsClientConfig, TlsServerConfig}, + ALPN_QUIC_HTTP, QUIC_ACCEPT_THROTTLE_TIME, QUIC_DEFAULT_MTU, QUIC_LOCATOR_PREFIX, +}; + pub struct LinkUnicastQuic { connection: quinn::Connection, src_addr: SocketAddr, diff --git a/io/zenoh-links/zenoh-link-quic/src/utils.rs b/io/zenoh-links/zenoh-link-quic/src/utils.rs index e7537bd658..1eb8f94380 100644 --- a/io/zenoh-links/zenoh-link-quic/src/utils.rs +++ b/io/zenoh-links/zenoh-link-quic/src/utils.rs @@ -11,30 +11,32 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::config::*; -use crate::verify::WebPkiVerifierAnyServerName; -use rustls::OwnedTrustAnchor; -use rustls::{ - server::AllowAnyAuthenticatedClient, version::TLS13, Certificate, ClientConfig, PrivateKey, - RootCertStore, ServerConfig, -}; -use rustls_pki_types::{CertificateDer, TrustAnchor}; -use secrecy::ExposeSecret; -use zenoh_link_commons::ConfigurationInspector; // use rustls_pki_types::{CertificateDer, PrivateKeyDer, TrustAnchor}; -use std::fs::File; -use std::io; -use std::net::SocketAddr; use std::{ + fs::File, + io, io::{BufReader, Cursor}, + net::SocketAddr, sync::Arc, }; + +use rustls::{ + server::AllowAnyAuthenticatedClient, version::TLS13, Certificate, ClientConfig, + OwnedTrustAnchor, PrivateKey, RootCertStore, ServerConfig, +}; +use rustls_pki_types::{CertificateDer, TrustAnchor}; +use secrecy::ExposeSecret; use webpki::anchor_from_trusted_cert; use zenoh_config::Config as ZenohConfig; -use zenoh_protocol::core::endpoint::{Address, Config}; -use zenoh_protocol::core::Parameters; +use zenoh_link_commons::ConfigurationInspector; +use zenoh_protocol::core::{ + endpoint::{Address, Config}, + Parameters, +}; use zenoh_result::{bail, zerror, ZError, ZResult}; +use crate::{config::*, verify::WebPkiVerifierAnyServerName}; + #[derive(Default, Clone, Copy, Debug)] pub struct TlsConfigurator; @@ -498,8 +500,7 @@ pub async fn get_quic_addr(address: &Address<'_>) -> ZResult { } pub fn base64_decode(data: &str) -> ZResult> { - use base64::engine::general_purpose; - use base64::Engine; + use base64::{engine::general_purpose, Engine}; Ok(general_purpose::STANDARD .decode(data) .map_err(|e| zerror!("Unable to perform base64 decoding: {e:?}"))?) diff --git a/io/zenoh-links/zenoh-link-quic/src/verify.rs b/io/zenoh-links/zenoh-link-quic/src/verify.rs index baa7864246..544d7c8a65 100644 --- a/io/zenoh-links/zenoh-link-quic/src/verify.rs +++ b/io/zenoh-links/zenoh-link-quic/src/verify.rs @@ -1,6 +1,6 @@ -use rustls::client::verify_server_cert_signed_by_trust_anchor; -use rustls::server::ParsedCertificate; use std::time::SystemTime; + +use rustls::{client::verify_server_cert_signed_by_trust_anchor, server::ParsedCertificate}; use tokio_rustls::rustls::{ client::{ServerCertVerified, ServerCertVerifier}, Certificate, RootCertStore, ServerName, diff --git a/io/zenoh-links/zenoh-link-serial/src/lib.rs b/io/zenoh-links/zenoh-link-serial/src/lib.rs index f7b0b7afeb..3d2ddcd0e6 100644 --- a/io/zenoh-links/zenoh-link-serial/src/lib.rs +++ b/io/zenoh-links/zenoh-link-serial/src/lib.rs @@ -19,13 +19,16 @@ //! [Click here for Zenoh's documentation](../zenoh/index.html) mod unicast; -use async_trait::async_trait; use std::str::FromStr; + +use async_trait::async_trait; pub use unicast::*; use zenoh_core::zconfigurable; use zenoh_link_commons::LocatorInspector; -use zenoh_protocol::core::{endpoint::Address, EndPoint, Locator}; -use zenoh_protocol::transport::BatchSize; +use zenoh_protocol::{ + core::{endpoint::Address, EndPoint, Locator}, + transport::BatchSize, +}; use zenoh_result::ZResult; // Maximum MTU (Serial PDU) in bytes. diff --git a/io/zenoh-links/zenoh-link-serial/src/unicast.rs b/io/zenoh-links/zenoh-link-serial/src/unicast.rs index 239ff6bb9d..ca4efacdc6 100644 --- a/io/zenoh-links/zenoh-link-serial/src/unicast.rs +++ b/io/zenoh-links/zenoh-link-serial/src/unicast.rs @@ -12,35 +12,40 @@ // ZettaScale Zenoh Team, // +use std::{ + cell::UnsafeCell, + collections::HashMap, + fmt, + sync::{ + atomic::{AtomicBool, Ordering}, + Arc, + }, + time::Duration, +}; + use async_trait::async_trait; -use std::cell::UnsafeCell; -use std::collections::HashMap; -use std::fmt; -use std::sync::{ - atomic::{AtomicBool, Ordering}, - Arc, +use tokio::{ + sync::{Mutex as AsyncMutex, RwLock as AsyncRwLock}, + task::JoinHandle, }; -use std::time::Duration; -use tokio::sync::{Mutex as AsyncMutex, RwLock as AsyncRwLock}; -use tokio::task::JoinHandle; use tokio_util::sync::CancellationToken; +use z_serial::ZSerial; use zenoh_core::{zasynclock, zasyncread, zasyncwrite}; use zenoh_link_commons::{ ConstructibleLinkManagerUnicast, LinkManagerUnicastTrait, LinkUnicast, LinkUnicastTrait, NewLinkChannelSender, }; -use zenoh_protocol::core::{EndPoint, Locator}; -use zenoh_protocol::transport::BatchSize; +use zenoh_protocol::{ + core::{EndPoint, Locator}, + transport::BatchSize, +}; use zenoh_result::{zerror, ZResult}; -use z_serial::ZSerial; - -use crate::get_exclusive; - use super::{ get_baud_rate, get_unix_path_as_string, SERIAL_ACCEPT_THROTTLE_TIME, SERIAL_DEFAULT_MTU, SERIAL_LOCATOR_PREFIX, }; +use crate::get_exclusive; struct LinkUnicastSerial { // The underlying serial port as returned by ZSerial (tokio-serial) diff --git a/io/zenoh-links/zenoh-link-tcp/src/lib.rs b/io/zenoh-links/zenoh-link-tcp/src/lib.rs index 0b075d9bf8..ebc2bba70b 100644 --- a/io/zenoh-links/zenoh-link-tcp/src/lib.rs +++ b/io/zenoh-links/zenoh-link-tcp/src/lib.rs @@ -17,12 +17,15 @@ //! This crate is intended for Zenoh's internal use. //! //! [Click here for Zenoh's documentation](../zenoh/index.html) -use async_trait::async_trait; use std::net::SocketAddr; + +use async_trait::async_trait; use zenoh_core::zconfigurable; use zenoh_link_commons::LocatorInspector; -use zenoh_protocol::core::{endpoint::Address, Locator}; -use zenoh_protocol::transport::BatchSize; +use zenoh_protocol::{ + core::{endpoint::Address, Locator}, + transport::BatchSize, +}; use zenoh_result::{zerror, ZResult}; mod unicast; diff --git a/io/zenoh-links/zenoh-link-tcp/src/unicast.rs b/io/zenoh-links/zenoh-link-tcp/src/unicast.rs index 1a8a2302d1..79812c526e 100644 --- a/io/zenoh-links/zenoh-link-tcp/src/unicast.rs +++ b/io/zenoh-links/zenoh-link-tcp/src/unicast.rs @@ -11,28 +11,28 @@ // Contributors: // ZettaScale Zenoh Team, // +use std::{cell::UnsafeCell, convert::TryInto, fmt, net::SocketAddr, sync::Arc, time::Duration}; + use async_trait::async_trait; -use std::cell::UnsafeCell; -use std::convert::TryInto; -use std::fmt; -use std::net::SocketAddr; -use std::sync::Arc; -use std::time::Duration; -use tokio::io::{AsyncReadExt, AsyncWriteExt}; +use tokio::{ + io::{AsyncReadExt, AsyncWriteExt}, + net::{TcpListener, TcpSocket, TcpStream}, +}; use tokio_util::sync::CancellationToken; use zenoh_link_commons::{ get_ip_interface_names, LinkManagerUnicastTrait, LinkUnicast, LinkUnicastTrait, ListenersUnicastIP, NewLinkChannelSender, BIND_INTERFACE, }; -use zenoh_protocol::core::{EndPoint, Locator}; -use zenoh_protocol::transport::BatchSize; +use zenoh_protocol::{ + core::{EndPoint, Locator}, + transport::BatchSize, +}; use zenoh_result::{bail, zerror, Error as ZError, ZResult}; use super::{ get_tcp_addrs, TCP_ACCEPT_THROTTLE_TIME, TCP_DEFAULT_MTU, TCP_LINGER_TIMEOUT, TCP_LOCATOR_PREFIX, }; -use tokio::net::{TcpListener, TcpSocket, TcpStream}; pub struct LinkUnicastTcp { // The underlying socket as returned from the tokio library diff --git a/io/zenoh-links/zenoh-link-tls/src/unicast.rs b/io/zenoh-links/zenoh-link-tls/src/unicast.rs index 5cf686cdc5..1ced1a26b1 100644 --- a/io/zenoh-links/zenoh-link-tls/src/unicast.rs +++ b/io/zenoh-links/zenoh-link-tls/src/unicast.rs @@ -11,21 +11,14 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::{ - utils::{get_tls_addr, get_tls_host, get_tls_server_name, TlsClientConfig, TlsServerConfig}, - TLS_ACCEPT_THROTTLE_TIME, TLS_DEFAULT_MTU, TLS_LINGER_TIMEOUT, TLS_LOCATOR_PREFIX, -}; +use std::{cell::UnsafeCell, convert::TryInto, fmt, net::SocketAddr, sync::Arc, time::Duration}; use async_trait::async_trait; -use std::cell::UnsafeCell; -use std::convert::TryInto; -use std::fmt; -use std::net::SocketAddr; -use std::sync::Arc; -use std::time::Duration; -use tokio::io::{AsyncReadExt, AsyncWriteExt}; -use tokio::net::{TcpListener, TcpStream}; -use tokio::sync::Mutex as AsyncMutex; +use tokio::{ + io::{AsyncReadExt, AsyncWriteExt}, + net::{TcpListener, TcpStream}, + sync::Mutex as AsyncMutex, +}; use tokio_rustls::{TlsAcceptor, TlsConnector, TlsStream}; use tokio_util::sync::CancellationToken; use zenoh_core::zasynclock; @@ -33,10 +26,17 @@ use zenoh_link_commons::{ get_ip_interface_names, LinkManagerUnicastTrait, LinkUnicast, LinkUnicastTrait, ListenersUnicastIP, NewLinkChannelSender, }; -use zenoh_protocol::core::{EndPoint, Locator}; -use zenoh_protocol::transport::BatchSize; +use zenoh_protocol::{ + core::{EndPoint, Locator}, + transport::BatchSize, +}; use zenoh_result::{zerror, ZResult}; +use crate::{ + utils::{get_tls_addr, get_tls_host, get_tls_server_name, TlsClientConfig, TlsServerConfig}, + TLS_ACCEPT_THROTTLE_TIME, TLS_DEFAULT_MTU, TLS_LINGER_TIMEOUT, TLS_LOCATOR_PREFIX, +}; + pub struct LinkUnicastTls { // The underlying socket as returned from the async-rustls library // NOTE: TlsStream requires &mut for read and write operations. This means diff --git a/io/zenoh-links/zenoh-link-tls/src/utils.rs b/io/zenoh-links/zenoh-link-tls/src/utils.rs index d51a17c694..b646c6e80d 100644 --- a/io/zenoh-links/zenoh-link-tls/src/utils.rs +++ b/io/zenoh-links/zenoh-link-tls/src/utils.rs @@ -11,7 +11,15 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::config::*; +use std::{ + convert::TryFrom, + fs::File, + io, + io::{BufReader, Cursor}, + net::SocketAddr, + sync::Arc, +}; + use rustls::{ pki_types::{CertificateDer, PrivateKeyDer, TrustAnchor}, server::WebPkiClientVerifier, @@ -20,20 +28,17 @@ use rustls::{ }; use rustls_pki_types::ServerName; use secrecy::ExposeSecret; -use std::fs::File; -use std::io; -use std::{convert::TryFrom, net::SocketAddr}; -use std::{ - io::{BufReader, Cursor}, - sync::Arc, -}; use webpki::anchor_from_trusted_cert; use zenoh_config::Config as ZenohConfig; use zenoh_link_commons::{tls::WebPkiVerifierAnyServerName, ConfigurationInspector}; -use zenoh_protocol::core::endpoint::{Address, Config}; -use zenoh_protocol::core::Parameters; +use zenoh_protocol::core::{ + endpoint::{Address, Config}, + Parameters, +}; use zenoh_result::{bail, zerror, ZError, ZResult}; +use crate::config::*; + #[derive(Default, Clone, Copy, Debug)] pub struct TlsConfigurator; @@ -450,8 +455,7 @@ fn load_trust_anchors(config: &Config<'_>) -> ZResult> { } pub fn base64_decode(data: &str) -> ZResult> { - use base64::engine::general_purpose; - use base64::Engine; + use base64::{engine::general_purpose, Engine}; Ok(general_purpose::STANDARD .decode(data) .map_err(|e| zerror!("Unable to perform base64 decoding: {e:?}"))?) diff --git a/io/zenoh-links/zenoh-link-udp/src/lib.rs b/io/zenoh-links/zenoh-link-udp/src/lib.rs index 86db845d8f..c89708fe5d 100644 --- a/io/zenoh-links/zenoh-link-udp/src/lib.rs +++ b/io/zenoh-links/zenoh-link-udp/src/lib.rs @@ -20,14 +20,17 @@ mod multicast; mod unicast; +use std::net::SocketAddr; + use async_trait::async_trait; pub use multicast::*; -use std::net::SocketAddr; pub use unicast::*; use zenoh_core::zconfigurable; use zenoh_link_commons::LocatorInspector; -use zenoh_protocol::core::{endpoint::Address, Locator}; -use zenoh_protocol::transport::BatchSize; +use zenoh_protocol::{ + core::{endpoint::Address, Locator}, + transport::BatchSize, +}; use zenoh_result::{zerror, ZResult}; // NOTE: In case of using UDP in high-throughput scenarios, it is recommended to set the diff --git a/io/zenoh-links/zenoh-link-udp/src/multicast.rs b/io/zenoh-links/zenoh-link-udp/src/multicast.rs index f4a23ced93..280f5eb203 100644 --- a/io/zenoh-links/zenoh-link-udp/src/multicast.rs +++ b/io/zenoh-links/zenoh-link-udp/src/multicast.rs @@ -11,19 +11,26 @@ // Contributors: // ZettaScale Zenoh Team, // -use super::{config::*, UDP_DEFAULT_MTU}; -use crate::{get_udp_addrs, socket_addr_to_udp_locator}; +use std::{ + borrow::Cow, + fmt, + net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr}, + sync::Arc, +}; + use async_trait::async_trait; use socket2::{Domain, Protocol, Socket, Type}; -use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr}; -use std::sync::Arc; -use std::{borrow::Cow, fmt}; use tokio::net::UdpSocket; use zenoh_link_commons::{LinkManagerMulticastTrait, LinkMulticast, LinkMulticastTrait}; -use zenoh_protocol::core::{Config, EndPoint, Locator}; -use zenoh_protocol::transport::BatchSize; +use zenoh_protocol::{ + core::{Config, EndPoint, Locator}, + transport::BatchSize, +}; use zenoh_result::{bail, zerror, Error as ZError, ZResult}; +use super::{config::*, UDP_DEFAULT_MTU}; +use crate::{get_udp_addrs, socket_addr_to_udp_locator}; + pub struct LinkMulticastUdp { // The unicast socket address of this link unicast_addr: SocketAddr, diff --git a/io/zenoh-links/zenoh-link-udp/src/unicast.rs b/io/zenoh-links/zenoh-link-udp/src/unicast.rs index 9526ca74dd..79f980ca96 100644 --- a/io/zenoh-links/zenoh-link-udp/src/unicast.rs +++ b/io/zenoh-links/zenoh-link-udp/src/unicast.rs @@ -11,29 +11,34 @@ // Contributors: // ZettaScale Zenoh Team, // -use super::{ - get_udp_addrs, socket_addr_to_udp_locator, UDP_ACCEPT_THROTTLE_TIME, UDP_DEFAULT_MTU, - UDP_MAX_MTU, +use std::{ + collections::HashMap, + fmt, + net::{Ipv4Addr, Ipv6Addr, SocketAddr}, + sync::{Arc, Mutex, Weak}, + time::Duration, }; + use async_trait::async_trait; -use std::collections::HashMap; -use std::fmt; -use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr}; -use std::sync::{Arc, Mutex, Weak}; -use std::time::Duration; -use tokio::net::UdpSocket; -use tokio::sync::Mutex as AsyncMutex; +use tokio::{net::UdpSocket, sync::Mutex as AsyncMutex}; use tokio_util::sync::CancellationToken; use zenoh_core::{zasynclock, zlock}; use zenoh_link_commons::{ get_ip_interface_names, ConstructibleLinkManagerUnicast, LinkManagerUnicastTrait, LinkUnicast, LinkUnicastTrait, ListenersUnicastIP, NewLinkChannelSender, BIND_INTERFACE, }; -use zenoh_protocol::core::{EndPoint, Locator}; -use zenoh_protocol::transport::BatchSize; +use zenoh_protocol::{ + core::{EndPoint, Locator}, + transport::BatchSize, +}; use zenoh_result::{bail, zerror, Error as ZError, ZResult}; use zenoh_sync::Mvar; +use super::{ + get_udp_addrs, socket_addr_to_udp_locator, UDP_ACCEPT_THROTTLE_TIME, UDP_DEFAULT_MTU, + UDP_MAX_MTU, +}; + type LinkHashMap = Arc>>>; type LinkInput = (Vec, usize); type LinkLeftOver = (Vec, usize, usize); diff --git a/io/zenoh-links/zenoh-link-unixpipe/src/unix/unicast.rs b/io/zenoh-links/zenoh-link-unixpipe/src/unix/unicast.rs index ea90630523..1b30ceb553 100644 --- a/io/zenoh-links/zenoh-link-unixpipe/src/unix/unicast.rs +++ b/io/zenoh-links/zenoh-link-unixpipe/src/unix/unicast.rs @@ -11,41 +11,43 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::config; +use std::{ + cell::UnsafeCell, + collections::HashMap, + fmt, + fs::{File, OpenOptions}, + io::{ErrorKind, Read, Write}, + os::unix::fs::OpenOptionsExt, + sync::Arc, +}; + #[cfg(not(target_os = "macos"))] use advisory_lock::{AdvisoryFileLock, FileLockMode}; use async_trait::async_trait; use filepath::FilePath; -use nix::libc; -use nix::unistd::unlink; +use nix::{libc, unistd::unlink}; use rand::Rng; -use std::cell::UnsafeCell; -use std::collections::HashMap; -use std::fmt; -use std::fs::{File, OpenOptions}; -use std::io::ErrorKind; -use std::io::{Read, Write}; -use std::os::unix::fs::OpenOptionsExt; -use std::sync::Arc; -use tokio::fs::remove_file; -use tokio::io::unix::AsyncFd; -use tokio::io::Interest; -use tokio::task::JoinHandle; +use tokio::{ + fs::remove_file, + io::{unix::AsyncFd, Interest}, + task::JoinHandle, +}; use tokio_util::sync::CancellationToken; -use zenoh_core::{zasyncread, zasyncwrite, ResolveFuture, Wait}; -use zenoh_protocol::core::{EndPoint, Locator}; -use zenoh_protocol::transport::BatchSize; -use zenoh_runtime::ZRuntime; - use unix_named_pipe::{create, open_write}; - +use zenoh_core::{zasyncread, zasyncwrite, ResolveFuture, Wait}; use zenoh_link_commons::{ ConstructibleLinkManagerUnicast, LinkManagerUnicastTrait, LinkUnicast, LinkUnicastTrait, NewLinkChannelSender, }; +use zenoh_protocol::{ + core::{EndPoint, Locator}, + transport::BatchSize, +}; use zenoh_result::{bail, ZResult}; +use zenoh_runtime::ZRuntime; use super::FILE_ACCESS_MASK; +use crate::config; const LINUX_PIPE_MAX_MTU: BatchSize = BatchSize::MAX; const LINUX_PIPE_DEDICATE_TRIES: usize = 100; diff --git a/io/zenoh-links/zenoh-link-unixsock_stream/src/lib.rs b/io/zenoh-links/zenoh-link-unixsock_stream/src/lib.rs index ce067c1aa2..771782e62a 100644 --- a/io/zenoh-links/zenoh-link-unixsock_stream/src/lib.rs +++ b/io/zenoh-links/zenoh-link-unixsock_stream/src/lib.rs @@ -20,8 +20,10 @@ use async_trait::async_trait; use zenoh_core::zconfigurable; use zenoh_link_commons::LocatorInspector; -use zenoh_protocol::core::{endpoint::Address, Locator}; -use zenoh_protocol::transport::BatchSize; +use zenoh_protocol::{ + core::{endpoint::Address, Locator}, + transport::BatchSize, +}; use zenoh_result::ZResult; #[cfg(target_family = "unix")] mod unicast; diff --git a/io/zenoh-links/zenoh-link-unixsock_stream/src/unicast.rs b/io/zenoh-links/zenoh-link-unixsock_stream/src/unicast.rs index 4ad1b68d88..cc7147c9e0 100644 --- a/io/zenoh-links/zenoh-link-unixsock_stream/src/unicast.rs +++ b/io/zenoh-links/zenoh-link-unixsock_stream/src/unicast.rs @@ -11,31 +11,34 @@ // Contributors: // ZettaScale Zenoh Team, // -use super::UNIXSOCKSTREAM_ACCEPT_THROTTLE_TIME; +use std::{ + cell::UnsafeCell, collections::HashMap, fmt, fs::remove_file, os::unix::io::RawFd, + path::PathBuf, sync::Arc, time::Duration, +}; + use async_trait::async_trait; -use std::cell::UnsafeCell; -use std::collections::HashMap; -use std::fmt; -use std::fs::remove_file; -use std::os::unix::io::RawFd; -use std::path::PathBuf; -use std::sync::Arc; -use std::time::Duration; -use tokio::io::{AsyncReadExt, AsyncWriteExt}; -use tokio::net::{UnixListener, UnixStream}; -use tokio::sync::RwLock as AsyncRwLock; -use tokio::task::JoinHandle; +use tokio::{ + io::{AsyncReadExt, AsyncWriteExt}, + net::{UnixListener, UnixStream}, + sync::RwLock as AsyncRwLock, + task::JoinHandle, +}; use tokio_util::sync::CancellationToken; use uuid::Uuid; use zenoh_core::{zasyncread, zasyncwrite}; use zenoh_link_commons::{ LinkManagerUnicastTrait, LinkUnicast, LinkUnicastTrait, NewLinkChannelSender, }; -use zenoh_protocol::core::{EndPoint, Locator}; -use zenoh_protocol::transport::BatchSize; +use zenoh_protocol::{ + core::{EndPoint, Locator}, + transport::BatchSize, +}; use zenoh_result::{zerror, ZResult}; -use super::{get_unix_path_as_string, UNIXSOCKSTREAM_DEFAULT_MTU, UNIXSOCKSTREAM_LOCATOR_PREFIX}; +use super::{ + get_unix_path_as_string, UNIXSOCKSTREAM_ACCEPT_THROTTLE_TIME, UNIXSOCKSTREAM_DEFAULT_MTU, + UNIXSOCKSTREAM_LOCATOR_PREFIX, +}; pub struct LinkUnicastUnixSocketStream { // The underlying socket as returned from the tokio library diff --git a/io/zenoh-links/zenoh-link-vsock/src/unicast.rs b/io/zenoh-links/zenoh-link-vsock/src/unicast.rs index 6616790a28..605f114173 100644 --- a/io/zenoh-links/zenoh-link-vsock/src/unicast.rs +++ b/io/zenoh-links/zenoh-link-vsock/src/unicast.rs @@ -12,17 +12,20 @@ // ZettaScale Zenoh Team, // +use std::{cell::UnsafeCell, collections::HashMap, fmt, sync::Arc, time::Duration}; + use async_trait::async_trait; use libc::VMADDR_PORT_ANY; -use std::cell::UnsafeCell; -use std::collections::HashMap; -use std::fmt; -use std::sync::Arc; -use std::time::Duration; -use tokio::io::{AsyncReadExt, AsyncWriteExt}; -use tokio::sync::RwLock as AsyncRwLock; -use tokio::task::JoinHandle; +use tokio::{ + io::{AsyncReadExt, AsyncWriteExt}, + sync::RwLock as AsyncRwLock, + task::JoinHandle, +}; use tokio_util::sync::CancellationToken; +use tokio_vsock::{ + VsockAddr, VsockListener, VsockStream, VMADDR_CID_ANY, VMADDR_CID_HOST, VMADDR_CID_HYPERVISOR, + VMADDR_CID_LOCAL, +}; use zenoh_core::{zasyncread, zasyncwrite}; use zenoh_link_commons::{ LinkManagerUnicastTrait, LinkUnicast, LinkUnicastTrait, NewLinkChannelSender, @@ -34,10 +37,6 @@ use zenoh_protocol::{ use zenoh_result::{bail, zerror, ZResult}; use super::{VSOCK_ACCEPT_THROTTLE_TIME, VSOCK_DEFAULT_MTU, VSOCK_LOCATOR_PREFIX}; -use tokio_vsock::{ - VsockAddr, VsockListener, VsockStream, VMADDR_CID_ANY, VMADDR_CID_HOST, VMADDR_CID_HYPERVISOR, - VMADDR_CID_LOCAL, -}; pub const VSOCK_VMADDR_CID_ANY: &str = "VMADDR_CID_ANY"; pub const VSOCK_VMADDR_CID_HYPERVISOR: &str = "VMADDR_CID_HYPERVISOR"; diff --git a/io/zenoh-links/zenoh-link-ws/src/lib.rs b/io/zenoh-links/zenoh-link-ws/src/lib.rs index d165b480a9..6a97ed99b6 100644 --- a/io/zenoh-links/zenoh-link-ws/src/lib.rs +++ b/io/zenoh-links/zenoh-link-ws/src/lib.rs @@ -17,13 +17,16 @@ //! This crate is intended for Zenoh's internal use. //! //! [Click here for Zenoh's documentation](../zenoh/index.html) -use async_trait::async_trait; use std::net::SocketAddr; + +use async_trait::async_trait; use url::Url; use zenoh_core::zconfigurable; use zenoh_link_commons::LocatorInspector; -use zenoh_protocol::core::{endpoint::Address, Locator}; -use zenoh_protocol::transport::BatchSize; +use zenoh_protocol::{ + core::{endpoint::Address, Locator}, + transport::BatchSize, +}; use zenoh_result::{bail, ZResult}; mod unicast; pub use unicast::*; diff --git a/io/zenoh-links/zenoh-link-ws/src/unicast.rs b/io/zenoh-links/zenoh-link-ws/src/unicast.rs index 635f3b8808..b671bf67f2 100644 --- a/io/zenoh-links/zenoh-link-ws/src/unicast.rs +++ b/io/zenoh-links/zenoh-link-ws/src/unicast.rs @@ -12,29 +12,34 @@ // ZettaScale Zenoh Team, // +use std::{ + collections::HashMap, + fmt, + net::{Ipv4Addr, Ipv6Addr, SocketAddr}, + sync::Arc, + time::Duration, +}; + use async_trait::async_trait; -use futures_util::stream::SplitSink; -use futures_util::stream::SplitStream; -use futures_util::SinkExt; -use futures_util::StreamExt; -use std::collections::HashMap; -use std::fmt; -use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr}; -use std::sync::Arc; -use std::time::Duration; -use tokio::net::{TcpListener, TcpStream}; -use tokio::sync::{Mutex as AsyncMutex, RwLock as AsyncRwLock}; -use tokio::task::JoinHandle; -use tokio_tungstenite::accept_async; -use tokio_tungstenite::tungstenite::Message; -use tokio_tungstenite::{MaybeTlsStream, WebSocketStream}; +use futures_util::{ + stream::{SplitSink, SplitStream}, + SinkExt, StreamExt, +}; +use tokio::{ + net::{TcpListener, TcpStream}, + sync::{Mutex as AsyncMutex, RwLock as AsyncRwLock}, + task::JoinHandle, +}; +use tokio_tungstenite::{accept_async, tungstenite::Message, MaybeTlsStream, WebSocketStream}; use tokio_util::sync::CancellationToken; use zenoh_core::{zasynclock, zasyncread, zasyncwrite}; use zenoh_link_commons::{ LinkManagerUnicastTrait, LinkUnicast, LinkUnicastTrait, NewLinkChannelSender, }; -use zenoh_protocol::core::{EndPoint, Locator}; -use zenoh_protocol::transport::BatchSize; +use zenoh_protocol::{ + core::{EndPoint, Locator}, + transport::BatchSize, +}; use zenoh_result::{bail, zerror, ZResult}; use super::{get_ws_addr, get_ws_url, TCP_ACCEPT_THROTTLE_TIME, WS_DEFAULT_MTU, WS_LOCATOR_PREFIX}; diff --git a/io/zenoh-transport/src/common/batch.rs b/io/zenoh-transport/src/common/batch.rs index 8048d9ff49..b91acdc7ff 100644 --- a/io/zenoh-transport/src/common/batch.rs +++ b/io/zenoh-transport/src/common/batch.rs @@ -12,6 +12,7 @@ // ZettaScale Zenoh Team, // use std::num::NonZeroUsize; + use zenoh_buffers::{ buffer::Buffer, reader::{DidntRead, HasReader}, @@ -497,7 +498,6 @@ impl Decode<(TransportMessage, BatchSize)> for &mut RBatch { mod tests { use std::vec; - use super::*; use rand::Rng; use zenoh_buffers::ZBuf; use zenoh_core::zcondfeat; @@ -511,6 +511,8 @@ mod tests { zenoh::{PushBody, Put}, }; + use super::*; + #[test] fn rw_batch() { let mut rng = rand::thread_rng(); diff --git a/io/zenoh-transport/src/common/defragmentation.rs b/io/zenoh-transport/src/common/defragmentation.rs index 8fab075fe4..476fad632c 100644 --- a/io/zenoh-transport/src/common/defragmentation.rs +++ b/io/zenoh-transport/src/common/defragmentation.rs @@ -11,7 +11,6 @@ // Contributors: // ZettaScale Zenoh Team, // -use super::seq_num::SeqNum; use zenoh_buffers::{buffer::Buffer, reader::HasReader, ZBuf, ZSlice}; use zenoh_codec::{RCodec, Zenoh080Reliability}; use zenoh_protocol::{ @@ -21,6 +20,8 @@ use zenoh_protocol::{ }; use zenoh_result::{bail, ZResult}; +use super::seq_num::SeqNum; + #[derive(Debug)] pub(crate) struct DefragBuffer { reliability: Reliability, diff --git a/io/zenoh-transport/src/common/pipeline.rs b/io/zenoh-transport/src/common/pipeline.rs index fe4e567617..349f9ed560 100644 --- a/io/zenoh-transport/src/common/pipeline.rs +++ b/io/zenoh-transport/src/common/pipeline.rs @@ -1,30 +1,13 @@ -use crate::common::batch::BatchConfig; - -// -// Copyright (c) 2023 ZettaScale Technology -// -// This program and the accompanying materials are made available under the -// terms of the Eclipse Public License 2.0 which is available at -// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 -// which is available at https://www.apache.org/licenses/LICENSE-2.0. -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// -// Contributors: -// ZettaScale Zenoh Team, -// -use super::{ - batch::{Encode, WBatch}, - priority::{TransportChannelTx, TransportPriorityTx}, +use std::{ + sync::{ + atomic::{AtomicBool, Ordering}, + Arc, Mutex, MutexGuard, + }, + time::{Duration, Instant}, }; + use flume::{bounded, Receiver, Sender}; use ringbuffer_spsc::{RingBuffer, RingBufferReader, RingBufferWriter}; -use std::sync::{Arc, Mutex, MutexGuard}; -use std::time::Duration; -use std::{ - sync::atomic::{AtomicBool, Ordering}, - time::Instant, -}; use zenoh_buffers::{ reader::{HasReader, Reader}, writer::HasWriter, @@ -33,10 +16,9 @@ use zenoh_buffers::{ use zenoh_codec::{transport::batch::BatchError, WCodec, Zenoh080}; use zenoh_config::QueueSizeConf; use zenoh_core::zlock; -use zenoh_protocol::core::Reliability; -use zenoh_protocol::network::NetworkMessage; use zenoh_protocol::{ - core::Priority, + core::{Priority, Reliability}, + network::NetworkMessage, transport::{ fragment::FragmentHeader, frame::{self, FrameHeader}, @@ -44,6 +26,25 @@ use zenoh_protocol::{ }, }; +// +// Copyright (c) 2023 ZettaScale Technology +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License 2.0 which is available at +// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 +// which is available at https://www.apache.org/licenses/LICENSE-2.0. +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// +// Contributors: +// ZettaScale Zenoh Team, +// +use super::{ + batch::{Encode, WBatch}, + priority::{TransportChannelTx, TransportPriorityTx}, +}; +use crate::common::batch::BatchConfig; + // It's faster to work directly with nanoseconds. // Backoff will never last more the u32::MAX nanoseconds. type NanoSeconds = u32; @@ -719,7 +720,6 @@ impl TransmissionPipelineConsumer { #[cfg(test)] mod tests { - use super::*; use std::{ convert::TryFrom, sync::{ @@ -728,8 +728,8 @@ mod tests { }, time::{Duration, Instant}, }; - use tokio::task; - use tokio::time::timeout; + + use tokio::{task, time::timeout}; use zenoh_buffers::{ reader::{DidntRead, HasReader}, ZBuf, @@ -743,6 +743,8 @@ mod tests { }; use zenoh_result::ZResult; + use super::*; + const SLEEP: Duration = Duration::from_millis(100); const TIMEOUT: Duration = Duration::from_secs(60); diff --git a/io/zenoh-transport/src/common/priority.rs b/io/zenoh-transport/src/common/priority.rs index 8644cdacb7..fb5c520e3d 100644 --- a/io/zenoh-transport/src/common/priority.rs +++ b/io/zenoh-transport/src/common/priority.rs @@ -11,9 +11,8 @@ // Contributors: // ZettaScale Zenoh Team, // -use super::defragmentation::DefragBuffer; -use super::seq_num::{SeqNum, SeqNumGenerator}; use std::sync::{Arc, Mutex}; + use zenoh_core::zlock; use zenoh_protocol::{ core::{Bits, Reliability}, @@ -21,6 +20,11 @@ use zenoh_protocol::{ }; use zenoh_result::ZResult; +use super::{ + defragmentation::DefragBuffer, + seq_num::{SeqNum, SeqNumGenerator}, +}; + #[derive(Debug)] pub(crate) struct TransportChannelTx { pub(crate) sn: SeqNumGenerator, diff --git a/io/zenoh-transport/src/common/stats.rs b/io/zenoh-transport/src/common/stats.rs index aaf39641c0..da6e57d518 100644 --- a/io/zenoh-transport/src/common/stats.rs +++ b/io/zenoh-transport/src/common/stats.rs @@ -167,8 +167,9 @@ macro_rules! stats_struct { } } -use serde::{Deserialize, Serialize}; use std::sync::atomic::{AtomicUsize, Ordering}; + +use serde::{Deserialize, Serialize}; stats_struct! { #[derive(Clone, Debug, Deserialize, Serialize)] pub struct DiscriminatedStats { diff --git a/io/zenoh-transport/src/lib.rs b/io/zenoh-transport/src/lib.rs index 5e00bed2e7..f4c135c9d6 100644 --- a/io/zenoh-transport/src/lib.rs +++ b/io/zenoh-transport/src/lib.rs @@ -28,16 +28,19 @@ pub use common::stats; #[cfg(feature = "shared-memory")] mod shm; -use crate::{multicast::TransportMulticast, unicast::TransportUnicast}; +use std::{any::Any, sync::Arc}; + pub use manager::*; use serde::Serialize; -use std::any::Any; -use std::sync::Arc; use zenoh_link::Link; -use zenoh_protocol::core::{WhatAmI, ZenohId}; -use zenoh_protocol::network::NetworkMessage; +use zenoh_protocol::{ + core::{WhatAmI, ZenohId}, + network::NetworkMessage, +}; use zenoh_result::ZResult; +use crate::{multicast::TransportMulticast, unicast::TransportUnicast}; + /*************************************/ /* TRANSPORT */ /*************************************/ diff --git a/io/zenoh-transport/src/manager.rs b/io/zenoh-transport/src/manager.rs index ddf1fe23c1..3f57b3ceae 100644 --- a/io/zenoh-transport/src/manager.rs +++ b/io/zenoh-transport/src/manager.rs @@ -11,18 +11,9 @@ // Contributors: // ZettaScale Zenoh Team, // -use super::unicast::manager::{ - TransportManagerBuilderUnicast, TransportManagerConfigUnicast, TransportManagerStateUnicast, -}; -use super::TransportEventHandler; -use crate::multicast::manager::{ - TransportManagerBuilderMulticast, TransportManagerConfigMulticast, - TransportManagerStateMulticast, -}; +use std::{collections::HashMap, sync::Arc, time::Duration}; + use rand::{RngCore, SeedableRng}; -use std::collections::HashMap; -use std::sync::Arc; -use std::time::Duration; use tokio::sync::Mutex as AsyncMutex; use zenoh_config::{Config, LinkRxConf, QueueConf, QueueSizeConf}; use zenoh_crypto::{BlockCipher, PseudoRng}; @@ -39,6 +30,17 @@ use zenoh_shm::api::client_storage::GLOBAL_CLIENT_STORAGE; use zenoh_shm::reader::SharedMemoryReader; use zenoh_task::TaskController; +use super::{ + unicast::manager::{ + TransportManagerBuilderUnicast, TransportManagerConfigUnicast, TransportManagerStateUnicast, + }, + TransportEventHandler, +}; +use crate::multicast::manager::{ + TransportManagerBuilderMulticast, TransportManagerConfigMulticast, + TransportManagerStateMulticast, +}; + /// # Examples /// ``` /// use std::sync::Arc; diff --git a/io/zenoh-transport/src/multicast/establishment.rs b/io/zenoh-transport/src/multicast/establishment.rs index a0b7576f03..0c24626697 100644 --- a/io/zenoh-transport/src/multicast/establishment.rs +++ b/io/zenoh-transport/src/multicast/establishment.rs @@ -11,6 +11,17 @@ // Contributors: // ZettaScale Zenoh Team, // +use std::sync::Arc; + +use rand::Rng; +use zenoh_core::zasynclock; +use zenoh_link::LinkMulticast; +use zenoh_protocol::{ + core::{Field, Priority}, + transport::PrioritySn, +}; +use zenoh_result::{bail, ZResult}; + use crate::{ common::{batch::BatchConfig, seq_num}, multicast::{ @@ -20,15 +31,6 @@ use crate::{ }, TransportManager, }; -use rand::Rng; -use std::sync::Arc; -use zenoh_core::zasynclock; -use zenoh_link::LinkMulticast; -use zenoh_protocol::{ - core::{Field, Priority}, - transport::PrioritySn, -}; -use zenoh_result::{bail, ZResult}; pub(crate) async fn open_link( manager: &TransportManager, diff --git a/io/zenoh-transport/src/multicast/link.rs b/io/zenoh-transport/src/multicast/link.rs index 883f978684..a1c9c2bae8 100644 --- a/io/zenoh-transport/src/multicast/link.rs +++ b/io/zenoh-transport/src/multicast/link.rs @@ -11,25 +11,13 @@ // Contributors: // ZettaScale Zenoh Team, // -#[cfg(feature = "stats")] -use crate::stats::TransportStats; -use crate::{ - common::{ - batch::{BatchConfig, Encode, Finalize, RBatch, WBatch}, - pipeline::{ - TransmissionPipeline, TransmissionPipelineConf, TransmissionPipelineConsumer, - TransmissionPipelineProducer, - }, - priority::TransportPriorityTx, - }, - multicast::transport::TransportMulticastInner, -}; use std::{ convert::TryInto, fmt, sync::Arc, time::{Duration, Instant}, }; + use tokio::task::JoinHandle; use zenoh_buffers::{BBuf, ZSlice, ZSliceBuffer}; use zenoh_core::{zcondfeat, zlock}; @@ -41,6 +29,20 @@ use zenoh_protocol::{ use zenoh_result::{zerror, ZResult}; use zenoh_sync::{RecyclingObject, RecyclingObjectPool, Signal}; +#[cfg(feature = "stats")] +use crate::stats::TransportStats; +use crate::{ + common::{ + batch::{BatchConfig, Encode, Finalize, RBatch, WBatch}, + pipeline::{ + TransmissionPipeline, TransmissionPipelineConf, TransmissionPipelineConsumer, + TransmissionPipelineProducer, + }, + priority::TransportPriorityTx, + }, + multicast::transport::TransportMulticastInner, +}; + /****************************/ /* TRANSPORT MULTICAST LINK */ /****************************/ diff --git a/io/zenoh-transport/src/multicast/manager.rs b/io/zenoh-transport/src/multicast/manager.rs index ebc51a2ec6..3c04cf6425 100644 --- a/io/zenoh-transport/src/multicast/manager.rs +++ b/io/zenoh-transport/src/multicast/manager.rs @@ -11,11 +11,8 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::multicast::{transport::TransportMulticastInner, TransportMulticast}; -use crate::TransportManager; -use std::collections::HashMap; -use std::sync::Arc; -use std::time::Duration; +use std::{collections::HashMap, sync::Arc, time::Duration}; + use tokio::sync::Mutex; #[cfg(feature = "transport_compression")] use zenoh_config::CompressionMulticastConf; @@ -30,6 +27,11 @@ use zenoh_protocol::{ }; use zenoh_result::{bail, zerror, ZResult}; +use crate::{ + multicast::{transport::TransportMulticastInner, TransportMulticast}, + TransportManager, +}; + pub struct TransportManagerConfigMulticast { pub lease: Duration, pub keep_alive: usize, diff --git a/io/zenoh-transport/src/multicast/mod.rs b/io/zenoh-transport/src/multicast/mod.rs index e205125b39..78d76bb6c8 100644 --- a/io/zenoh-transport/src/multicast/mod.rs +++ b/io/zenoh-transport/src/multicast/mod.rs @@ -17,18 +17,15 @@ pub(crate) mod rx; pub(crate) mod transport; pub(crate) mod tx; -use super::common; -use crate::{ - multicast::link::TransportLinkMulticast, TransportMulticastEventHandler, TransportPeer, +use std::{ + fmt::{self, Write}, + sync::{Arc, Weak}, }; + pub use manager::{ TransportManagerBuilderMulticast, TransportManagerConfigMulticast, TransportManagerParamsMulticast, }; -use std::{ - fmt::{self, Write}, - sync::{Arc, Weak}, -}; use transport::TransportMulticastInner; use zenoh_core::{zcondfeat, zread}; use zenoh_link::Link; @@ -39,6 +36,11 @@ use zenoh_protocol::{ }; use zenoh_result::{zerror, ZResult}; +use super::common; +use crate::{ + multicast::link::TransportLinkMulticast, TransportMulticastEventHandler, TransportPeer, +}; + /*************************************/ /* TRANSPORT MULTICAST */ /*************************************/ diff --git a/io/zenoh-transport/src/multicast/rx.rs b/io/zenoh-transport/src/multicast/rx.rs index 1576d65cd6..ee8e024bb6 100644 --- a/io/zenoh-transport/src/multicast/rx.rs +++ b/io/zenoh-transport/src/multicast/rx.rs @@ -11,12 +11,8 @@ // Contributors: // ZettaScale Zenoh Team, // -use super::transport::{TransportMulticastInner, TransportMulticastPeer}; -use crate::common::{ - batch::{Decode, RBatch}, - priority::TransportChannelRx, -}; use std::sync::MutexGuard; + use zenoh_core::{zlock, zread}; use zenoh_protocol::{ core::{Locator, Priority, Reliability}, @@ -28,6 +24,12 @@ use zenoh_protocol::{ }; use zenoh_result::{bail, zerror, ZResult}; +use super::transport::{TransportMulticastInner, TransportMulticastPeer}; +use crate::common::{ + batch::{Decode, RBatch}, + priority::TransportChannelRx, +}; + /*************************************/ /* TRANSPORT RX */ /*************************************/ diff --git a/io/zenoh-transport/src/multicast/transport.rs b/io/zenoh-transport/src/multicast/transport.rs index babf68ce61..a60ed180ee 100644 --- a/io/zenoh-transport/src/multicast/transport.rs +++ b/io/zenoh-transport/src/multicast/transport.rs @@ -11,18 +11,6 @@ // Contributors: // ZettaScale Zenoh Team, // -use super::common::priority::{TransportPriorityRx, TransportPriorityTx}; -use super::link::{TransportLinkMulticastConfigUniversal, TransportLinkMulticastUniversal}; -#[cfg(feature = "shared-memory")] -use crate::shm::MulticastTransportShmConfig; -#[cfg(feature = "stats")] -use crate::stats::TransportStats; -use crate::{ - multicast::{ - link::TransportLinkMulticast, TransportConfigMulticast, TransportMulticastEventHandler, - }, - TransportManager, TransportPeer, TransportPeerEventHandler, -}; use std::{ collections::HashMap, sync::{ @@ -31,17 +19,31 @@ use std::{ }, time::Duration, }; + use tokio_util::sync::CancellationToken; use zenoh_core::{zcondfeat, zread, zwrite}; use zenoh_link::{Link, Locator}; -use zenoh_protocol::core::Resolution; -use zenoh_protocol::transport::{batch_size, Close, TransportMessage}; use zenoh_protocol::{ - core::{Bits, Field, Priority, WhatAmI, ZenohId}, - transport::{close, Join}, + core::{Bits, Field, Priority, Resolution, WhatAmI, ZenohId}, + transport::{batch_size, close, Close, Join, TransportMessage}, }; use zenoh_result::{bail, ZResult}; use zenoh_task::TaskController; + +use super::{ + common::priority::{TransportPriorityRx, TransportPriorityTx}, + link::{TransportLinkMulticastConfigUniversal, TransportLinkMulticastUniversal}, +}; +#[cfg(feature = "shared-memory")] +use crate::shm::MulticastTransportShmConfig; +#[cfg(feature = "stats")] +use crate::stats::TransportStats; +use crate::{ + multicast::{ + link::TransportLinkMulticast, TransportConfigMulticast, TransportMulticastEventHandler, + }, + TransportManager, TransportPeer, TransportPeerEventHandler, +}; // use zenoh_util::{Timed, TimedEvent, TimedHandle, Timer}; /*************************************/ diff --git a/io/zenoh-transport/src/multicast/tx.rs b/io/zenoh-transport/src/multicast/tx.rs index ee7715d38b..775131703a 100644 --- a/io/zenoh-transport/src/multicast/tx.rs +++ b/io/zenoh-transport/src/multicast/tx.rs @@ -11,10 +11,10 @@ // Contributors: // ZettaScale Zenoh Team, // -use super::transport::TransportMulticastInner; use zenoh_core::zread; use zenoh_protocol::network::NetworkMessage; +use super::transport::TransportMulticastInner; #[cfg(feature = "shared-memory")] use crate::shm::map_zmsg_to_partner; diff --git a/io/zenoh-transport/src/shm.rs b/io/zenoh-transport/src/shm.rs index 6dd65aab16..7a50a68742 100644 --- a/io/zenoh-transport/src/shm.rs +++ b/io/zenoh-transport/src/shm.rs @@ -12,6 +12,7 @@ // ZettaScale Zenoh Team, // use std::collections::HashSet; + use zenoh_buffers::{reader::HasReader, writer::HasWriter, ZBuf, ZSlice, ZSliceKind}; use zenoh_codec::{RCodec, WCodec, Zenoh080}; use zenoh_core::zerror; diff --git a/io/zenoh-transport/src/unicast/establishment/accept.rs b/io/zenoh-transport/src/unicast/establishment/accept.rs index 48638834e0..d074ea9642 100644 --- a/io/zenoh-transport/src/unicast/establishment/accept.rs +++ b/io/zenoh-transport/src/unicast/establishment/accept.rs @@ -11,26 +11,10 @@ // Contributors: // ZettaScale Zenoh Team, // -#[cfg(feature = "shared-memory")] -use super::ext::shm::AuthSegment; -#[cfg(feature = "shared-memory")] -use crate::shm::TransportShmConfig; +use std::time::Duration; -use crate::{ - common::batch::BatchConfig, - unicast::{ - establishment::{compute_sn, ext, AcceptFsm, Cookie, Zenoh080Cookie}, - link::{ - LinkUnicastWithOpenAck, TransportLinkUnicast, TransportLinkUnicastConfig, - TransportLinkUnicastDirection, - }, - TransportConfigUnicast, - }, - TransportManager, -}; use async_trait::async_trait; use rand::Rng; -use std::time::Duration; use tokio::sync::Mutex; use zenoh_buffers::{reader::HasReader, writer::HasWriter, ZSlice}; use zenoh_codec::{RCodec, WCodec, Zenoh080}; @@ -47,6 +31,23 @@ use zenoh_protocol::{ }; use zenoh_result::ZResult; +#[cfg(feature = "shared-memory")] +use super::ext::shm::AuthSegment; +#[cfg(feature = "shared-memory")] +use crate::shm::TransportShmConfig; +use crate::{ + common::batch::BatchConfig, + unicast::{ + establishment::{compute_sn, ext, AcceptFsm, Cookie, Zenoh080Cookie}, + link::{ + LinkUnicastWithOpenAck, TransportLinkUnicast, TransportLinkUnicastConfig, + TransportLinkUnicastDirection, + }, + TransportConfigUnicast, + }, + TransportManager, +}; + pub(super) type AcceptError = (zenoh_result::Error, Option); struct StateTransport { diff --git a/io/zenoh-transport/src/unicast/establishment/cookie.rs b/io/zenoh-transport/src/unicast/establishment/cookie.rs index 6f0295601c..fccce5e672 100644 --- a/io/zenoh-transport/src/unicast/establishment/cookie.rs +++ b/io/zenoh-transport/src/unicast/establishment/cookie.rs @@ -11,8 +11,8 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::unicast::establishment::ext; use std::convert::TryFrom; + use zenoh_buffers::{ reader::{DidntRead, HasReader, Reader}, writer::{DidntWrite, HasWriter, Writer}, @@ -24,6 +24,8 @@ use zenoh_protocol::{ transport::BatchSize, }; +use crate::unicast::establishment::ext; + #[derive(Debug, PartialEq)] pub(crate) struct Cookie { pub(crate) zid: ZenohId, @@ -193,10 +195,11 @@ impl Cookie { mod tests { #[test] fn codec_cookie() { - use super::*; use rand::{Rng, SeedableRng}; use zenoh_buffers::ZBuf; + use super::*; + const NUM_ITER: usize = 1_000; macro_rules! run_single { diff --git a/io/zenoh-transport/src/unicast/establishment/ext/auth/mod.rs b/io/zenoh-transport/src/unicast/establishment/ext/auth/mod.rs index beab85d18a..8d57434bc3 100644 --- a/io/zenoh-transport/src/unicast/establishment/ext/auth/mod.rs +++ b/io/zenoh-transport/src/unicast/establishment/ext/auth/mod.rs @@ -16,21 +16,19 @@ pub(crate) mod pubkey; #[cfg(feature = "auth_usrpwd")] pub(crate) mod usrpwd; -use crate::unicast::establishment::{AcceptFsm, OpenFsm}; +use std::{convert::TryInto, marker::PhantomData}; + use async_trait::async_trait; #[cfg(feature = "auth_pubkey")] pub use pubkey::*; use rand::{CryptoRng, Rng}; -use std::convert::TryInto; -use std::marker::PhantomData; use tokio::sync::{Mutex, RwLock}; #[cfg(feature = "auth_usrpwd")] pub use usrpwd::*; -use zenoh_buffers::reader::SiphonableReader; -use zenoh_buffers::ZBuf; use zenoh_buffers::{ - reader::{DidntRead, HasReader, Reader}, + reader::{DidntRead, HasReader, Reader, SiphonableReader}, writer::{DidntWrite, HasWriter, Writer}, + ZBuf, }; use zenoh_codec::{RCodec, WCodec, Zenoh080}; use zenoh_config::Config; @@ -41,6 +39,8 @@ use zenoh_protocol::{ transport::{init, open}, }; +use crate::unicast::establishment::{AcceptFsm, OpenFsm}; + pub(crate) mod id { #[cfg(feature = "auth_pubkey")] pub(crate) const PUBKEY: u8 = 0x1; diff --git a/io/zenoh-transport/src/unicast/establishment/ext/auth/pubkey.rs b/io/zenoh-transport/src/unicast/establishment/ext/auth/pubkey.rs index 9a7c3d8f32..69b4707bf0 100644 --- a/io/zenoh-transport/src/unicast/establishment/ext/auth/pubkey.rs +++ b/io/zenoh-transport/src/unicast/establishment/ext/auth/pubkey.rs @@ -11,7 +11,8 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::unicast::establishment::{ext::auth::id, AcceptFsm, OpenFsm}; +use std::{collections::HashSet, fmt, ops::Deref, path::Path}; + use async_trait::async_trait; use rand::Rng; use rsa::{ @@ -19,7 +20,6 @@ use rsa::{ traits::PublicKeyParts, BigUint, Pkcs1v15Encrypt, RsaPrivateKey, RsaPublicKey, }; -use std::{collections::HashSet, fmt, ops::Deref, path::Path}; use tokio::sync::{Mutex, RwLock}; use zenoh_buffers::{ reader::{DidntRead, HasReader, Reader}, @@ -31,10 +31,13 @@ use zenoh_core::{bail, zasynclock, zasyncread, zerror, Error as ZError, Result a use zenoh_crypto::PseudoRng; use zenoh_protocol::common::{ZExtUnit, ZExtZBuf}; +use crate::unicast::establishment::{ext::auth::id, AcceptFsm, OpenFsm}; + mod ext { - use super::{id::PUBKEY, ZExtUnit, ZExtZBuf}; use zenoh_protocol::{zextunit, zextzbuf}; + use super::{id::PUBKEY, ZExtUnit, ZExtZBuf}; + pub(super) type InitSyn = zextzbuf!(PUBKEY, false); pub(super) type InitAck = zextzbuf!(PUBKEY, false); pub(super) type OpenSyn = zextzbuf!(PUBKEY, false); diff --git a/io/zenoh-transport/src/unicast/establishment/ext/auth/usrpwd.rs b/io/zenoh-transport/src/unicast/establishment/ext/auth/usrpwd.rs index 23560e307e..be24337fad 100644 --- a/io/zenoh-transport/src/unicast/establishment/ext/auth/usrpwd.rs +++ b/io/zenoh-transport/src/unicast/establishment/ext/auth/usrpwd.rs @@ -11,10 +11,10 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::unicast::establishment::{ext::auth::id, AcceptFsm, OpenFsm}; +use std::{collections::HashMap, fmt}; + use async_trait::async_trait; use rand::{CryptoRng, Rng}; -use std::{collections::HashMap, fmt}; use tokio::sync::RwLock; use zenoh_buffers::{ reader::{DidntRead, HasReader, Reader}, @@ -26,10 +26,13 @@ use zenoh_core::{bail, zasyncread, zerror, Error as ZError, Result as ZResult}; use zenoh_crypto::hmac; use zenoh_protocol::common::{ZExtUnit, ZExtZ64, ZExtZBuf}; +use crate::unicast::establishment::{ext::auth::id, AcceptFsm, OpenFsm}; + mod ext { - use super::{id::USRPWD, ZExtUnit, ZExtZ64, ZExtZBuf}; use zenoh_protocol::{zextunit, zextz64, zextzbuf}; + use super::{id::USRPWD, ZExtUnit, ZExtZ64, ZExtZBuf}; + pub(super) type InitSyn = zextunit!(USRPWD, false); pub(super) type InitAck = zextz64!(USRPWD, false); pub(super) type OpenSyn = zextzbuf!(USRPWD, false); @@ -451,10 +454,12 @@ mod tests { #[tokio::test(flavor = "multi_thread", worker_threads = 4)] async fn authenticator_usrpwd_config() { async fn inner() { - use super::AuthUsrPwd; use std::{fs::File, io::Write}; + use zenoh_config::UsrPwdConf; + use super::AuthUsrPwd; + /* [CONFIG] */ let f1 = "zenoh-test-auth-usrpwd.txt"; diff --git a/io/zenoh-transport/src/unicast/establishment/ext/compression.rs b/io/zenoh-transport/src/unicast/establishment/ext/compression.rs index 2b57eb85db..1d4e995af6 100644 --- a/io/zenoh-transport/src/unicast/establishment/ext/compression.rs +++ b/io/zenoh-transport/src/unicast/establishment/ext/compression.rs @@ -11,9 +11,9 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::unicast::establishment::{AcceptFsm, OpenFsm}; -use async_trait::async_trait; use core::marker::PhantomData; + +use async_trait::async_trait; use zenoh_buffers::{ reader::{DidntRead, Reader}, writer::{DidntWrite, Writer}, @@ -22,6 +22,8 @@ use zenoh_codec::{RCodec, WCodec, Zenoh080}; use zenoh_protocol::transport::{init, open}; use zenoh_result::Error as ZError; +use crate::unicast::establishment::{AcceptFsm, OpenFsm}; + // Extension Fsm pub(crate) struct CompressionFsm<'a> { _a: PhantomData<&'a ()>, diff --git a/io/zenoh-transport/src/unicast/establishment/ext/lowlatency.rs b/io/zenoh-transport/src/unicast/establishment/ext/lowlatency.rs index 9dda9175b1..ff1efc90b9 100644 --- a/io/zenoh-transport/src/unicast/establishment/ext/lowlatency.rs +++ b/io/zenoh-transport/src/unicast/establishment/ext/lowlatency.rs @@ -11,9 +11,9 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::unicast::establishment::{AcceptFsm, OpenFsm}; -use async_trait::async_trait; use core::marker::PhantomData; + +use async_trait::async_trait; use zenoh_buffers::{ reader::{DidntRead, Reader}, writer::{DidntWrite, Writer}, @@ -22,6 +22,8 @@ use zenoh_codec::{RCodec, WCodec, Zenoh080}; use zenoh_protocol::transport::{init, open}; use zenoh_result::Error as ZError; +use crate::unicast::establishment::{AcceptFsm, OpenFsm}; + // Extension Fsm pub(crate) struct LowLatencyFsm<'a> { _a: PhantomData<&'a ()>, diff --git a/io/zenoh-transport/src/unicast/establishment/ext/multilink.rs b/io/zenoh-transport/src/unicast/establishment/ext/multilink.rs index f8e74779cf..8980766888 100644 --- a/io/zenoh-transport/src/unicast/establishment/ext/multilink.rs +++ b/io/zenoh-transport/src/unicast/establishment/ext/multilink.rs @@ -11,10 +11,6 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::unicast::establishment::{ - ext::auth::pubkey::{self, AuthPubKey, AuthPubKeyFsm, ZPublicKey}, - AcceptFsm, OpenFsm, -}; use async_trait::async_trait; use rand::{CryptoRng, Rng}; use rsa::{BigUint, RsaPrivateKey, RsaPublicKey}; @@ -28,6 +24,11 @@ use zenoh_core::{zerror, Error as ZError, Result as ZResult}; use zenoh_crypto::PseudoRng; use zenoh_protocol::transport::{init, open}; +use crate::unicast::establishment::{ + ext::auth::pubkey::{self, AuthPubKey, AuthPubKeyFsm, ZPublicKey}, + AcceptFsm, OpenFsm, +}; + const KEY_SIZE: usize = 512; // Extension Fsm diff --git a/io/zenoh-transport/src/unicast/establishment/ext/qos.rs b/io/zenoh-transport/src/unicast/establishment/ext/qos.rs index 4626ec5998..f749073805 100644 --- a/io/zenoh-transport/src/unicast/establishment/ext/qos.rs +++ b/io/zenoh-transport/src/unicast/establishment/ext/qos.rs @@ -11,9 +11,9 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::unicast::establishment::{AcceptFsm, OpenFsm}; -use async_trait::async_trait; use core::marker::PhantomData; + +use async_trait::async_trait; use zenoh_buffers::{ reader::{DidntRead, Reader}, writer::{DidntWrite, Writer}, @@ -22,6 +22,8 @@ use zenoh_codec::{RCodec, WCodec, Zenoh080}; use zenoh_protocol::transport::{init, open}; use zenoh_result::Error as ZError; +use crate::unicast::establishment::{AcceptFsm, OpenFsm}; + // Extension Fsm pub(crate) struct QoSFsm<'a> { _a: PhantomData<&'a ()>, diff --git a/io/zenoh-transport/src/unicast/establishment/ext/shm.rs b/io/zenoh-transport/src/unicast/establishment/ext/shm.rs index 1287095a51..bc96d2e34a 100644 --- a/io/zenoh-transport/src/unicast/establishment/ext/shm.rs +++ b/io/zenoh-transport/src/unicast/establishment/ext/shm.rs @@ -11,10 +11,10 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::unicast::establishment::{AcceptFsm, OpenFsm}; +use std::ops::Deref; + use async_trait::async_trait; use rand::{Rng, SeedableRng}; -use std::ops::Deref; use zenoh_buffers::{ reader::{DidntRead, HasReader, Reader}, writer::{DidntWrite, HasWriter, Writer}, @@ -26,6 +26,8 @@ use zenoh_protocol::transport::{init, open}; use zenoh_result::{zerror, Error as ZError, ZResult}; use zenoh_shm::{api::common::types::ProtocolID, posix_shm::array::ArrayInSHM}; +use crate::unicast::establishment::{AcceptFsm, OpenFsm}; + /*************************************/ /* Segment */ /*************************************/ diff --git a/io/zenoh-transport/src/unicast/establishment/mod.rs b/io/zenoh-transport/src/unicast/establishment/mod.rs index f79aa826d0..79627f4c49 100644 --- a/io/zenoh-transport/src/unicast/establishment/mod.rs +++ b/io/zenoh-transport/src/unicast/establishment/mod.rs @@ -16,7 +16,6 @@ pub(super) mod cookie; pub mod ext; pub(crate) mod open; -use crate::common::seq_num; use async_trait::async_trait; use cookie::*; use sha3::{ @@ -28,6 +27,8 @@ use zenoh_protocol::{ transport::TransportSn, }; +use crate::common::seq_num; + /*************************************/ /* TRAITS */ /*************************************/ diff --git a/io/zenoh-transport/src/unicast/establishment/open.rs b/io/zenoh-transport/src/unicast/establishment/open.rs index 40aa959d10..49c57d9e9a 100644 --- a/io/zenoh-transport/src/unicast/establishment/open.rs +++ b/io/zenoh-transport/src/unicast/establishment/open.rs @@ -11,6 +11,23 @@ // Contributors: // ZettaScale Zenoh Team, // +use std::time::Duration; + +use async_trait::async_trait; +use zenoh_buffers::ZSlice; +#[cfg(feature = "transport_auth")] +use zenoh_core::zasynclock; +use zenoh_core::{zcondfeat, zerror}; +use zenoh_link::LinkUnicast; +use zenoh_protocol::{ + core::{Field, Resolution, WhatAmI, ZenohId}, + transport::{ + batch_size, close, BatchSize, Close, InitSyn, OpenSyn, TransportBody, TransportMessage, + TransportSn, + }, +}; +use zenoh_result::ZResult; + #[cfg(feature = "shared-memory")] use super::ext::shm::AuthSegment; #[cfg(feature = "shared-memory")] @@ -27,21 +44,6 @@ use crate::{ }, TransportManager, }; -use async_trait::async_trait; -use std::time::Duration; -use zenoh_buffers::ZSlice; -#[cfg(feature = "transport_auth")] -use zenoh_core::zasynclock; -use zenoh_core::{zcondfeat, zerror}; -use zenoh_link::LinkUnicast; -use zenoh_protocol::{ - core::{Field, Resolution, WhatAmI, ZenohId}, - transport::{ - batch_size, close, BatchSize, Close, InitSyn, OpenSyn, TransportBody, TransportMessage, - TransportSn, - }, -}; -use zenoh_result::ZResult; type OpenError = (zenoh_result::Error, Option); diff --git a/io/zenoh-transport/src/unicast/link.rs b/io/zenoh-transport/src/unicast/link.rs index 1c9c190aae..b76bc764ef 100644 --- a/io/zenoh-transport/src/unicast/link.rs +++ b/io/zenoh-transport/src/unicast/link.rs @@ -11,15 +11,16 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::common::batch::{BatchConfig, Decode, Encode, Finalize, RBatch, WBatch}; -use std::fmt; -use std::sync::Arc; +use std::{fmt, sync::Arc}; + use zenoh_buffers::{BBuf, ZSlice, ZSliceBuffer}; use zenoh_core::zcondfeat; use zenoh_link::{Link, LinkUnicast}; use zenoh_protocol::transport::{BatchSize, Close, OpenAck, TransportMessage}; use zenoh_result::{zerror, ZResult}; +use crate::common::batch::{BatchConfig, Decode, Encode, Finalize, RBatch, WBatch}; + #[derive(Clone, Copy, PartialEq, Eq, Debug)] pub(crate) enum TransportLinkUnicastDirection { Inbound, diff --git a/io/zenoh-transport/src/unicast/lowlatency/link.rs b/io/zenoh-transport/src/unicast/lowlatency/link.rs index 7958631a8b..6dcd2fde44 100644 --- a/io/zenoh-transport/src/unicast/lowlatency/link.rs +++ b/io/zenoh-transport/src/unicast/lowlatency/link.rs @@ -11,24 +11,23 @@ // Contributors: // ZettaScale Zenoh Team, // -use super::transport::TransportUnicastLowlatency; -#[cfg(feature = "stats")] -use crate::stats::TransportStats; -use crate::unicast::link::TransportLinkUnicast; -use crate::unicast::link::TransportLinkUnicastRx; -use std::sync::Arc; -use std::time::Duration; +use std::{sync::Arc, time::Duration}; + use tokio::sync::RwLock; use tokio_util::sync::CancellationToken; use zenoh_buffers::{writer::HasWriter, ZSlice}; use zenoh_codec::*; use zenoh_core::{zasyncread, zasyncwrite}; use zenoh_link::LinkUnicast; -use zenoh_protocol::transport::TransportMessageLowLatency; -use zenoh_protocol::transport::{KeepAlive, TransportBodyLowLatency}; +use zenoh_protocol::transport::{KeepAlive, TransportBodyLowLatency, TransportMessageLowLatency}; use zenoh_result::{zerror, ZResult}; use zenoh_runtime::ZRuntime; +use super::transport::TransportUnicastLowlatency; +#[cfg(feature = "stats")] +use crate::stats::TransportStats; +use crate::unicast::link::{TransportLinkUnicast, TransportLinkUnicastRx}; + pub(crate) async fn send_with_link( link: &LinkUnicast, msg: TransportMessageLowLatency, diff --git a/io/zenoh-transport/src/unicast/lowlatency/rx.rs b/io/zenoh-transport/src/unicast/lowlatency/rx.rs index de0b62354f..c82e172c7b 100644 --- a/io/zenoh-transport/src/unicast/lowlatency/rx.rs +++ b/io/zenoh-transport/src/unicast/lowlatency/rx.rs @@ -11,7 +11,6 @@ // Contributors: // ZettaScale Zenoh Team, // -use super::transport::TransportUnicastLowlatency; use zenoh_buffers::{ reader::{HasReader, Reader}, ZSlice, @@ -22,6 +21,8 @@ use zenoh_link::LinkUnicast; use zenoh_protocol::{network::NetworkMessage, transport::TransportMessageLowLatency}; use zenoh_result::{zerror, ZResult}; +use super::transport::TransportUnicastLowlatency; + /*************************************/ /* TRANSPORT RX */ /*************************************/ diff --git a/io/zenoh-transport/src/unicast/lowlatency/transport.rs b/io/zenoh-transport/src/unicast/lowlatency/transport.rs index 726d21bb84..9f122e9c72 100644 --- a/io/zenoh-transport/src/unicast/lowlatency/transport.rs +++ b/io/zenoh-transport/src/unicast/lowlatency/transport.rs @@ -11,6 +11,23 @@ // Contributors: // ZettaScale Zenoh Team, // +use std::{ + sync::{Arc, RwLock as SyncRwLock}, + time::Duration, +}; + +use async_trait::async_trait; +use tokio::sync::{Mutex as AsyncMutex, MutexGuard as AsyncMutexGuard, RwLock}; +use tokio_util::{sync::CancellationToken, task::TaskTracker}; +use zenoh_core::{zasynclock, zasyncread, zasyncwrite, zread, zwrite}; +use zenoh_link::Link; +use zenoh_protocol::{ + core::{WhatAmI, ZenohId}, + network::NetworkMessage, + transport::{close, Close, TransportBodyLowLatency, TransportMessageLowLatency, TransportSn}, +}; +use zenoh_result::{zerror, ZResult}; + #[cfg(feature = "stats")] use crate::stats::TransportStats; use crate::{ @@ -21,23 +38,6 @@ use crate::{ }, TransportManager, TransportPeerEventHandler, }; -use async_trait::async_trait; -use std::sync::{Arc, RwLock as SyncRwLock}; -use std::time::Duration; -use tokio::sync::{Mutex as AsyncMutex, MutexGuard as AsyncMutexGuard, RwLock}; -use tokio_util::sync::CancellationToken; -use tokio_util::task::TaskTracker; -use zenoh_core::{zasynclock, zasyncread, zasyncwrite, zread, zwrite}; -use zenoh_link::Link; -use zenoh_protocol::network::NetworkMessage; -use zenoh_protocol::transport::TransportBodyLowLatency; -use zenoh_protocol::transport::TransportMessageLowLatency; -use zenoh_protocol::transport::{Close, TransportSn}; -use zenoh_protocol::{ - core::{WhatAmI, ZenohId}, - transport::close, -}; -use zenoh_result::{zerror, ZResult}; /*************************************/ /* LOW-LATENCY TRANSPORT */ diff --git a/io/zenoh-transport/src/unicast/lowlatency/tx.rs b/io/zenoh-transport/src/unicast/lowlatency/tx.rs index d573544340..90304a196d 100644 --- a/io/zenoh-transport/src/unicast/lowlatency/tx.rs +++ b/io/zenoh-transport/src/unicast/lowlatency/tx.rs @@ -11,7 +11,6 @@ // Contributors: // ZettaScale Zenoh Team, // -use super::transport::TransportUnicastLowlatency; use zenoh_protocol::{ network::NetworkMessage, transport::{TransportBodyLowLatency, TransportMessageLowLatency}, @@ -20,6 +19,7 @@ use zenoh_protocol::{ use zenoh_result::bail; use zenoh_result::ZResult; +use super::transport::TransportUnicastLowlatency; #[cfg(feature = "shared-memory")] use crate::shm::map_zmsg_to_partner; diff --git a/io/zenoh-transport/src/unicast/manager.rs b/io/zenoh-transport/src/unicast/manager.rs index 6844f30163..b92462276a 100644 --- a/io/zenoh-transport/src/unicast/manager.rs +++ b/io/zenoh-transport/src/unicast/manager.rs @@ -11,22 +11,6 @@ // Contributors: // ZettaScale Zenoh Team, // -#[cfg(feature = "shared-memory")] -use super::establishment::ext::shm::AuthUnicast; -use super::{link::LinkUnicastWithOpenAck, transport_unicast_inner::InitTransportResult}; -#[cfg(feature = "transport_auth")] -use crate::unicast::establishment::ext::auth::Auth; -#[cfg(feature = "transport_multilink")] -use crate::unicast::establishment::ext::multilink::MultiLink; -use crate::{ - unicast::{ - lowlatency::transport::TransportUnicastLowlatency, - transport_unicast_inner::{InitTransportError, TransportUnicastTrait}, - universal::transport::TransportUnicastUniversal, - TransportConfigUnicast, TransportUnicast, - }, - TransportManager, TransportPeer, -}; use std::{ collections::HashMap, sync::{ @@ -35,6 +19,7 @@ use std::{ }, time::Duration, }; + use tokio::sync::{Mutex as AsyncMutex, MutexGuard as AsyncMutexGuard}; #[cfg(feature = "transport_compression")] use zenoh_config::CompressionUnicastConf; @@ -52,6 +37,23 @@ use zenoh_result::{bail, zerror, ZResult}; #[cfg(feature = "shared-memory")] use zenoh_shm::reader::SharedMemoryReader; +#[cfg(feature = "shared-memory")] +use super::establishment::ext::shm::AuthUnicast; +use super::{link::LinkUnicastWithOpenAck, transport_unicast_inner::InitTransportResult}; +#[cfg(feature = "transport_auth")] +use crate::unicast::establishment::ext::auth::Auth; +#[cfg(feature = "transport_multilink")] +use crate::unicast::establishment::ext::multilink::MultiLink; +use crate::{ + unicast::{ + lowlatency::transport::TransportUnicastLowlatency, + transport_unicast_inner::{InitTransportError, TransportUnicastTrait}, + universal::transport::TransportUnicastUniversal, + TransportConfigUnicast, TransportUnicast, + }, + TransportManager, TransportPeer, +}; + /*************************************/ /* TRANSPORT CONFIG */ /*************************************/ diff --git a/io/zenoh-transport/src/unicast/mod.rs b/io/zenoh-transport/src/unicast/mod.rs index 630b56aa1b..1726ba2559 100644 --- a/io/zenoh-transport/src/unicast/mod.rs +++ b/io/zenoh-transport/src/unicast/mod.rs @@ -21,26 +21,28 @@ pub(crate) mod universal; #[cfg(feature = "test")] pub mod test_helpers; -#[cfg(feature = "shared-memory")] -use crate::shm::TransportShmConfig; - -use self::transport_unicast_inner::TransportUnicastTrait; +use std::{ + fmt, + sync::{Arc, Weak}, +}; -use super::{TransportPeer, TransportPeerEventHandler}; #[cfg(feature = "transport_multilink")] use establishment::ext::auth::ZPublicKey; pub use manager::*; -use std::fmt; -use std::sync::{Arc, Weak}; use zenoh_core::zcondfeat; use zenoh_link::Link; -use zenoh_protocol::network::NetworkMessage; use zenoh_protocol::{ core::{Bits, WhatAmI, ZenohId}, + network::NetworkMessage, transport::{close, TransportSn}, }; use zenoh_result::{zerror, ZResult}; +use self::transport_unicast_inner::TransportUnicastTrait; +use super::{TransportPeer, TransportPeerEventHandler}; +#[cfg(feature = "shared-memory")] +use crate::shm::TransportShmConfig; + /*************************************/ /* TRANSPORT UNICAST */ /*************************************/ diff --git a/io/zenoh-transport/src/unicast/test_helpers.rs b/io/zenoh-transport/src/unicast/test_helpers.rs index 42ed6db927..6d25ae0d77 100644 --- a/io/zenoh-transport/src/unicast/test_helpers.rs +++ b/io/zenoh-transport/src/unicast/test_helpers.rs @@ -11,9 +11,10 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::{unicast::TransportManagerBuilderUnicast, TransportManager}; use zenoh_core::zcondfeat; +use crate::{unicast::TransportManagerBuilderUnicast, TransportManager}; + pub fn make_transport_manager_builder( #[cfg(feature = "transport_multilink")] max_links: usize, #[cfg(feature = "shared-memory")] with_shm: bool, diff --git a/io/zenoh-transport/src/unicast/transport_unicast_inner.rs b/io/zenoh-transport/src/unicast/transport_unicast_inner.rs index f6dc39529d..fcc5d41029 100644 --- a/io/zenoh-transport/src/unicast/transport_unicast_inner.rs +++ b/io/zenoh-transport/src/unicast/transport_unicast_inner.rs @@ -12,12 +12,9 @@ // ZettaScale Zenoh Team, // -use crate::{ - unicast::{link::TransportLinkUnicast, TransportConfigUnicast}, - TransportPeerEventHandler, -}; -use async_trait::async_trait; use std::{fmt::DebugStruct, sync::Arc, time::Duration}; + +use async_trait::async_trait; use tokio::sync::MutexGuard as AsyncMutexGuard; use zenoh_link::Link; use zenoh_protocol::{ @@ -28,6 +25,10 @@ use zenoh_protocol::{ use zenoh_result::ZResult; use super::link::{LinkUnicastWithOpenAck, MaybeOpenAck}; +use crate::{ + unicast::{link::TransportLinkUnicast, TransportConfigUnicast}, + TransportPeerEventHandler, +}; pub(crate) type LinkError = (zenoh_result::Error, TransportLinkUnicast, u8); pub(crate) type TransportError = (zenoh_result::Error, Arc, u8); diff --git a/io/zenoh-transport/src/unicast/universal/link.rs b/io/zenoh-transport/src/unicast/universal/link.rs index 8d5d703be1..e0c3cd3db5 100644 --- a/io/zenoh-transport/src/unicast/universal/link.rs +++ b/io/zenoh-transport/src/unicast/universal/link.rs @@ -11,6 +11,16 @@ // Contributors: // ZettaScale Zenoh Team, // +use std::time::Duration; + +use tokio_util::{sync::CancellationToken, task::TaskTracker}; +use zenoh_buffers::ZSliceBuffer; +use zenoh_protocol::transport::{KeepAlive, TransportMessage}; +use zenoh_result::{zerror, ZResult}; +use zenoh_sync::{RecyclingObject, RecyclingObjectPool}; +#[cfg(feature = "stats")] +use {crate::common::stats::TransportStats, std::sync::Arc}; + use super::transport::TransportUnicastUniversal; use crate::{ common::{ @@ -23,14 +33,6 @@ use crate::{ }, unicast::link::{TransportLinkUnicast, TransportLinkUnicastRx, TransportLinkUnicastTx}, }; -use std::time::Duration; -use tokio_util::{sync::CancellationToken, task::TaskTracker}; -use zenoh_buffers::ZSliceBuffer; -use zenoh_protocol::transport::{KeepAlive, TransportMessage}; -use zenoh_result::{zerror, ZResult}; -use zenoh_sync::{RecyclingObject, RecyclingObjectPool}; -#[cfg(feature = "stats")] -use {crate::common::stats::TransportStats, std::sync::Arc}; #[derive(Clone)] pub(super) struct TransportLinkUnicastUniversal { diff --git a/io/zenoh-transport/src/unicast/universal/rx.rs b/io/zenoh-transport/src/unicast/universal/rx.rs index 3edf57f507..f97f29b0c7 100644 --- a/io/zenoh-transport/src/unicast/universal/rx.rs +++ b/io/zenoh-transport/src/unicast/universal/rx.rs @@ -11,16 +11,8 @@ // Contributors: // ZettaScale Zenoh Team, // -use super::transport::TransportUnicastUniversal; -use crate::{ - common::{ - batch::{Decode, RBatch}, - priority::TransportChannelRx, - }, - unicast::transport_unicast_inner::TransportUnicastTrait, - TransportPeerEventHandler, -}; use std::sync::MutexGuard; + use zenoh_core::{zlock, zread}; use zenoh_link::Link; use zenoh_protocol::{ @@ -30,6 +22,16 @@ use zenoh_protocol::{ }; use zenoh_result::{bail, zerror, ZResult}; +use super::transport::TransportUnicastUniversal; +use crate::{ + common::{ + batch::{Decode, RBatch}, + priority::TransportChannelRx, + }, + unicast::transport_unicast_inner::TransportUnicastTrait, + TransportPeerEventHandler, +}; + /*************************************/ /* TRANSPORT RX */ /*************************************/ diff --git a/io/zenoh-transport/src/unicast/universal/transport.rs b/io/zenoh-transport/src/unicast/universal/transport.rs index 5f581673e9..52b4769e82 100644 --- a/io/zenoh-transport/src/unicast/universal/transport.rs +++ b/io/zenoh-transport/src/unicast/universal/transport.rs @@ -11,6 +11,23 @@ // Contributors: // ZettaScale Zenoh Team, // +use std::{ + fmt::DebugStruct, + sync::{Arc, RwLock}, + time::Duration, +}; + +use async_trait::async_trait; +use tokio::sync::{Mutex as AsyncMutex, MutexGuard as AsyncMutexGuard}; +use zenoh_core::{zasynclock, zcondfeat, zread, zwrite}; +use zenoh_link::Link; +use zenoh_protocol::{ + core::{Priority, WhatAmI, ZenohId}, + network::NetworkMessage, + transport::{close, Close, PrioritySn, TransportMessage, TransportSn}, +}; +use zenoh_result::{bail, zerror, ZResult}; + #[cfg(feature = "stats")] use crate::stats::TransportStats; use crate::{ @@ -23,19 +40,6 @@ use crate::{ }, TransportManager, TransportPeerEventHandler, }; -use async_trait::async_trait; -use std::fmt::DebugStruct; -use std::sync::{Arc, RwLock}; -use std::time::Duration; -use tokio::sync::{Mutex as AsyncMutex, MutexGuard as AsyncMutexGuard}; -use zenoh_core::{zasynclock, zcondfeat, zread, zwrite}; -use zenoh_link::Link; -use zenoh_protocol::{ - core::{Priority, WhatAmI, ZenohId}, - network::NetworkMessage, - transport::{close, Close, PrioritySn, TransportMessage, TransportSn}, -}; -use zenoh_result::{bail, zerror, ZResult}; macro_rules! zlinkget { ($guard:expr, $link:expr) => { diff --git a/io/zenoh-transport/src/unicast/universal/tx.rs b/io/zenoh-transport/src/unicast/universal/tx.rs index a381bb4d29..f7754489ef 100644 --- a/io/zenoh-transport/src/unicast/universal/tx.rs +++ b/io/zenoh-transport/src/unicast/universal/tx.rs @@ -11,10 +11,10 @@ // Contributors: // ZettaScale Zenoh Team, // -use super::transport::TransportUnicastUniversal; use zenoh_core::zread; use zenoh_protocol::network::NetworkMessage; +use super::transport::TransportUnicastUniversal; #[cfg(feature = "shared-memory")] use crate::shm::map_zmsg_to_partner; diff --git a/io/zenoh-transport/tests/endpoints.rs b/io/zenoh-transport/tests/endpoints.rs index daf79d3e98..e765165a81 100644 --- a/io/zenoh-transport/tests/endpoints.rs +++ b/io/zenoh-transport/tests/endpoints.rs @@ -12,6 +12,7 @@ // ZettaScale Zenoh Team, // use std::{any::Any, convert::TryFrom, sync::Arc, time::Duration}; + use zenoh_core::ztimeout; use zenoh_link::{EndPoint, Link}; use zenoh_protocol::{ diff --git a/io/zenoh-transport/tests/multicast_compression.rs b/io/zenoh-transport/tests/multicast_compression.rs index d5eb62c961..124dfeaad8 100644 --- a/io/zenoh-transport/tests/multicast_compression.rs +++ b/io/zenoh-transport/tests/multicast_compression.rs @@ -24,6 +24,7 @@ mod tests { }, time::Duration, }; + use zenoh_core::ztimeout; use zenoh_link::Link; use zenoh_protocol::{ diff --git a/io/zenoh-transport/tests/multicast_transport.rs b/io/zenoh-transport/tests/multicast_transport.rs index d0bb603836..e1d5bfc52c 100644 --- a/io/zenoh-transport/tests/multicast_transport.rs +++ b/io/zenoh-transport/tests/multicast_transport.rs @@ -25,6 +25,7 @@ mod tests { }, time::Duration, }; + use zenoh_core::ztimeout; use zenoh_link::Link; use zenoh_protocol::{ diff --git a/io/zenoh-transport/tests/transport_whitelist.rs b/io/zenoh-transport/tests/transport_whitelist.rs index a859a1c0c9..4ace68a87b 100644 --- a/io/zenoh-transport/tests/transport_whitelist.rs +++ b/io/zenoh-transport/tests/transport_whitelist.rs @@ -12,6 +12,7 @@ // ZettaScale Zenoh Team, // use std::{any::Any, convert::TryFrom, iter::FromIterator, sync::Arc, time::Duration}; + use zenoh_core::ztimeout; use zenoh_link::Link; use zenoh_protocol::{ diff --git a/io/zenoh-transport/tests/unicast_authenticator.rs b/io/zenoh-transport/tests/unicast_authenticator.rs index abcf011eed..b25fb77a63 100644 --- a/io/zenoh-transport/tests/unicast_authenticator.rs +++ b/io/zenoh-transport/tests/unicast_authenticator.rs @@ -12,6 +12,7 @@ // ZettaScale Zenoh Team, // use std::{any::Any, sync::Arc, time::Duration}; + use zenoh_core::{zasyncwrite, ztimeout}; use zenoh_link::Link; use zenoh_protocol::{ @@ -20,11 +21,9 @@ use zenoh_protocol::{ }; use zenoh_result::ZResult; use zenoh_transport::{ - multicast::TransportMulticast, unicast::establishment::ext::auth::Auth, - TransportMulticastEventHandler, -}; -use zenoh_transport::{ - unicast::TransportUnicast, DummyTransportPeerEventHandler, TransportEventHandler, + multicast::TransportMulticast, + unicast::{establishment::ext::auth::Auth, TransportUnicast}, + DummyTransportPeerEventHandler, TransportEventHandler, TransportMulticastEventHandler, TransportPeer, TransportPeerEventHandler, }; diff --git a/io/zenoh-transport/tests/unicast_compression.rs b/io/zenoh-transport/tests/unicast_compression.rs index 6f80e7dd58..df122eeedd 100644 --- a/io/zenoh-transport/tests/unicast_compression.rs +++ b/io/zenoh-transport/tests/unicast_compression.rs @@ -13,16 +13,17 @@ // #[cfg(feature = "transport_compression")] mod tests { - use std::fmt::Write as _; use std::{ any::Any, convert::TryFrom, + fmt::Write as _, sync::{ atomic::{AtomicUsize, Ordering}, Arc, }, time::Duration, }; + use zenoh_core::ztimeout; use zenoh_link::Link; use zenoh_protocol::{ diff --git a/io/zenoh-transport/tests/unicast_concurrent.rs b/io/zenoh-transport/tests/unicast_concurrent.rs index dc4c0fbd3d..9c9b58acde 100644 --- a/io/zenoh-transport/tests/unicast_concurrent.rs +++ b/io/zenoh-transport/tests/unicast_concurrent.rs @@ -10,11 +10,16 @@ // Contributors: // ZettaScale Zenoh Team, // -use std::any::Any; -use std::convert::TryFrom; -use std::sync::atomic::{AtomicUsize, Ordering}; -use std::sync::Arc; -use std::time::Duration; +use std::{ + any::Any, + convert::TryFrom, + sync::{ + atomic::{AtomicUsize, Ordering}, + Arc, + }, + time::Duration, +}; + use tokio::sync::Barrier; use zenoh_core::ztimeout; use zenoh_link::Link; diff --git a/io/zenoh-transport/tests/unicast_defragmentation.rs b/io/zenoh-transport/tests/unicast_defragmentation.rs index 40a513b874..28b085ab39 100644 --- a/io/zenoh-transport/tests/unicast_defragmentation.rs +++ b/io/zenoh-transport/tests/unicast_defragmentation.rs @@ -12,6 +12,7 @@ // ZettaScale Zenoh Team, // use std::{convert::TryFrom, sync::Arc, time::Duration}; + use zenoh_core::ztimeout; use zenoh_protocol::{ core::{ diff --git a/io/zenoh-transport/tests/unicast_intermittent.rs b/io/zenoh-transport/tests/unicast_intermittent.rs index 14670bf532..9830820cf1 100644 --- a/io/zenoh-transport/tests/unicast_intermittent.rs +++ b/io/zenoh-transport/tests/unicast_intermittent.rs @@ -11,12 +11,17 @@ // Contributors: // ZettaScale Zenoh Team, // -use std::any::Any; -use std::convert::TryFrom; -use std::io::Write; -use std::sync::atomic::{AtomicUsize, Ordering}; -use std::sync::Arc; -use std::time::Duration; +use std::{ + any::Any, + convert::TryFrom, + io::Write, + sync::{ + atomic::{AtomicUsize, Ordering}, + Arc, + }, + time::Duration, +}; + use zenoh_core::ztimeout; use zenoh_link::Link; use zenoh_protocol::{ diff --git a/io/zenoh-transport/tests/unicast_multilink.rs b/io/zenoh-transport/tests/unicast_multilink.rs index c06485fd06..d9337b790d 100644 --- a/io/zenoh-transport/tests/unicast_multilink.rs +++ b/io/zenoh-transport/tests/unicast_multilink.rs @@ -14,6 +14,7 @@ #[cfg(feature = "transport_multilink")] mod tests { use std::{convert::TryFrom, sync::Arc, time::Duration}; + use zenoh_core::ztimeout; use zenoh_link::EndPoint; use zenoh_protocol::core::{WhatAmI, ZenohId}; diff --git a/io/zenoh-transport/tests/unicast_openclose.rs b/io/zenoh-transport/tests/unicast_openclose.rs index 3c46fc9a80..03af046a3d 100644 --- a/io/zenoh-transport/tests/unicast_openclose.rs +++ b/io/zenoh-transport/tests/unicast_openclose.rs @@ -12,6 +12,7 @@ // ZettaScale Zenoh Team, // use std::{convert::TryFrom, sync::Arc, time::Duration}; + use zenoh_core::ztimeout; use zenoh_link::EndPoint; use zenoh_protocol::core::{WhatAmI, ZenohId}; @@ -22,7 +23,6 @@ use zenoh_transport::{ DummyTransportPeerEventHandler, TransportEventHandler, TransportManager, TransportMulticastEventHandler, TransportPeer, TransportPeerEventHandler, }; - #[cfg(target_os = "linux")] #[cfg(any(feature = "transport_tcp", feature = "transport_udp"))] use zenoh_util::net::get_ipv4_ipaddrs; diff --git a/io/zenoh-transport/tests/unicast_priorities.rs b/io/zenoh-transport/tests/unicast_priorities.rs index fa7f68a8a9..c7e468b5c5 100644 --- a/io/zenoh-transport/tests/unicast_priorities.rs +++ b/io/zenoh-transport/tests/unicast_priorities.rs @@ -11,15 +11,19 @@ // Contributors: // ZettaScale Zenoh Team, // -use std::any::Any; -use std::convert::TryFrom; -use std::fmt::Write as _; -use std::sync::atomic::{AtomicUsize, Ordering}; -use std::sync::Arc; -use std::time::Duration; +use std::{ + any::Any, + convert::TryFrom, + fmt::Write as _, + sync::{ + atomic::{AtomicUsize, Ordering}, + Arc, + }, + time::Duration, +}; + use zenoh_core::ztimeout; use zenoh_link::Link; -use zenoh_protocol::network::NetworkBody; use zenoh_protocol::{ core::{CongestionControl, Encoding, EndPoint, Priority, WhatAmI, ZenohId}, network::{ @@ -27,7 +31,7 @@ use zenoh_protocol::{ ext::{NodeIdType, QoSType}, Push, }, - NetworkMessage, + NetworkBody, NetworkMessage, }, zenoh::Put, }; diff --git a/io/zenoh-transport/tests/unicast_shm.rs b/io/zenoh-transport/tests/unicast_shm.rs index 637f9f8a86..f7b884f6b9 100644 --- a/io/zenoh-transport/tests/unicast_shm.rs +++ b/io/zenoh-transport/tests/unicast_shm.rs @@ -22,6 +22,7 @@ mod tests { }, time::Duration, }; + use zenoh_buffers::buffer::SplitBuffer; use zenoh_core::ztimeout; use zenoh_link::Link; diff --git a/io/zenoh-transport/tests/unicast_simultaneous.rs b/io/zenoh-transport/tests/unicast_simultaneous.rs index 92267458f0..8f9b23a6f1 100644 --- a/io/zenoh-transport/tests/unicast_simultaneous.rs +++ b/io/zenoh-transport/tests/unicast_simultaneous.rs @@ -13,11 +13,16 @@ // #[cfg(target_family = "unix")] mod tests { - use std::any::Any; - use std::convert::TryFrom; - use std::sync::atomic::{AtomicUsize, Ordering}; - use std::sync::Arc; - use std::time::Duration; + use std::{ + any::Any, + convert::TryFrom, + sync::{ + atomic::{AtomicUsize, Ordering}, + Arc, + }, + time::Duration, + }; + use zenoh_core::ztimeout; use zenoh_link::Link; use zenoh_protocol::{ diff --git a/io/zenoh-transport/tests/unicast_time.rs b/io/zenoh-transport/tests/unicast_time.rs index 5b9209ada3..efe8842c12 100644 --- a/io/zenoh-transport/tests/unicast_time.rs +++ b/io/zenoh-transport/tests/unicast_time.rs @@ -16,6 +16,7 @@ use std::{ sync::Arc, time::{Duration, Instant}, }; + use zenoh_core::ztimeout; use zenoh_link::EndPoint; use zenoh_protocol::core::{WhatAmI, ZenohId}; diff --git a/io/zenoh-transport/tests/unicast_transport.rs b/io/zenoh-transport/tests/unicast_transport.rs index 4b833bc5e7..8fed09e8c2 100644 --- a/io/zenoh-transport/tests/unicast_transport.rs +++ b/io/zenoh-transport/tests/unicast_transport.rs @@ -11,16 +11,17 @@ // Contributors: // ZettaScale Zenoh Team, // -use std::fmt::Write as _; use std::{ any::Any, convert::TryFrom, + fmt::Write as _, sync::{ atomic::{AtomicUsize, Ordering}, Arc, }, time::Duration, }; + use zenoh_core::ztimeout; use zenoh_link::Link; use zenoh_protocol::{ @@ -1158,6 +1159,7 @@ async fn transport_unicast_tls_only_mutual_success() { #[tokio::test(flavor = "multi_thread", worker_threads = 4)] async fn transport_unicast_tls_only_mutual_no_client_certs_failure() { use std::vec; + use zenoh_link::tls::config::*; zenoh_util::try_init_log_from_env(); @@ -1373,6 +1375,7 @@ async fn transport_unicast_quic_only_mutual_success() { #[tokio::test(flavor = "multi_thread", worker_threads = 4)] async fn transport_unicast_quic_only_mutual_no_client_certs_failure() { use std::vec; + use zenoh_link::quic::config::*; zenoh_util::try_init_log_from_env(); diff --git a/plugins/zenoh-backend-example/src/lib.rs b/plugins/zenoh-backend-example/src/lib.rs index 3663f3249e..13cc427268 100644 --- a/plugins/zenoh-backend-example/src/lib.rs +++ b/plugins/zenoh-backend-example/src/lib.rs @@ -11,9 +11,10 @@ // Contributors: // ZettaScale Zenoh Team, // +use std::collections::{hash_map::Entry, HashMap}; + use async_std::sync::RwLock; use async_trait::async_trait; -use std::collections::{hash_map::Entry, HashMap}; use zenoh::{key_expr::OwnedKeyExpr, time::Timestamp, value::Value}; use zenoh_backend_traits::{ config::{StorageConfig, VolumeConfig}, diff --git a/plugins/zenoh-backend-traits/src/config.rs b/plugins/zenoh-backend-traits/src/config.rs index 096255fb59..9f5e9bb25a 100644 --- a/plugins/zenoh-backend-traits/src/config.rs +++ b/plugins/zenoh-backend-traits/src/config.rs @@ -11,13 +11,16 @@ // Contributors: // ZettaScale Zenoh Team, // +use std::{convert::TryFrom, time::Duration}; + use const_format::concatcp; use derive_more::{AsMut, AsRef}; use schemars::JsonSchema; use serde_json::{Map, Value}; -use std::convert::TryFrom; -use std::time::Duration; -use zenoh::{core::Result as ZResult, key_expr::keyexpr, key_expr::OwnedKeyExpr}; +use zenoh::{ + core::Result as ZResult, + key_expr::{keyexpr, OwnedKeyExpr}, +}; use zenoh_plugin_trait::{PluginStartArgs, StructVersion}; use zenoh_result::{bail, zerror, Error}; diff --git a/plugins/zenoh-backend-traits/src/lib.rs b/plugins/zenoh-backend-traits/src/lib.rs index 761f653064..61d70b28b1 100644 --- a/plugins/zenoh-backend-traits/src/lib.rs +++ b/plugins/zenoh-backend-traits/src/lib.rs @@ -123,10 +123,12 @@ use async_trait::async_trait; use const_format::concatcp; -use zenoh::core::Result as ZResult; -use zenoh::key_expr::{keyexpr, OwnedKeyExpr}; -use zenoh::time::Timestamp; -use zenoh::value::Value; +use zenoh::{ + core::Result as ZResult, + key_expr::{keyexpr, OwnedKeyExpr}, + time::Timestamp, + value::Value, +}; use zenoh_plugin_trait::{PluginControl, PluginInstance, PluginStatusRec, StructVersion}; use zenoh_util::concat_enabled_features; diff --git a/plugins/zenoh-plugin-example/src/lib.rs b/plugins/zenoh-plugin-example/src/lib.rs index 3c84e039a8..41e88fb417 100644 --- a/plugins/zenoh-plugin-example/src/lib.rs +++ b/plugins/zenoh-plugin-example/src/lib.rs @@ -13,20 +13,25 @@ // #![recursion_limit = "256"] -use futures::select; -use std::borrow::Cow; -use std::collections::HashMap; -use std::convert::TryFrom; -use std::sync::{ - atomic::{AtomicBool, Ordering::Relaxed}, - Arc, Mutex, +use std::{ + borrow::Cow, + collections::HashMap, + convert::TryFrom, + sync::{ + atomic::{AtomicBool, Ordering::Relaxed}, + Arc, Mutex, + }, }; + +use futures::select; use tracing::{debug, info}; -use zenoh::key_expr::{keyexpr, KeyExpr}; -use zenoh::plugins::{RunningPluginTrait, ZenohPlugin}; -use zenoh::runtime::Runtime; -use zenoh::sample::Sample; -use zenoh::session::SessionDeclarations; +use zenoh::{ + key_expr::{keyexpr, KeyExpr}, + plugins::{RunningPluginTrait, ZenohPlugin}, + runtime::Runtime, + sample::Sample, + session::SessionDeclarations, +}; use zenoh_core::zlock; use zenoh_plugin_trait::{plugin_long_version, plugin_version, Plugin, PluginControl}; use zenoh_result::{bail, ZResult}; diff --git a/plugins/zenoh-plugin-rest/examples/z_serve_sse.rs b/plugins/zenoh-plugin-rest/examples/z_serve_sse.rs index 59562391ea..c1c8f69ce7 100644 --- a/plugins/zenoh-plugin-rest/examples/z_serve_sse.rs +++ b/plugins/zenoh-plugin-rest/examples/z_serve_sse.rs @@ -11,14 +11,13 @@ // Contributors: // ZettaScale Zenoh Team, // -use clap::{arg, Command}; use std::time::Duration; -use zenoh::config::Config; -use zenoh::core::try_init_log_from_env; -use zenoh::key_expr::keyexpr; -use zenoh::publication::CongestionControl; -use zenoh::sample::QoSBuilderTrait; -use zenoh::session::SessionDeclarations; + +use clap::{arg, Command}; +use zenoh::{ + config::Config, core::try_init_log_from_env, key_expr::keyexpr, publication::CongestionControl, + sample::QoSBuilderTrait, session::SessionDeclarations, +}; const HTML: &str = r#"
diff --git a/plugins/zenoh-plugin-rest/src/config.rs b/plugins/zenoh-plugin-rest/src/config.rs index 56b9960467..719dc79fbf 100644 --- a/plugins/zenoh-plugin-rest/src/config.rs +++ b/plugins/zenoh-plugin-rest/src/config.rs @@ -11,11 +11,15 @@ // Contributors: // ZettaScale Zenoh Team, // -use schemars::JsonSchema; -use serde::de::{Unexpected, Visitor}; -use serde::{de, Deserialize, Deserializer}; use std::fmt; +use schemars::JsonSchema; +use serde::{ + de, + de::{Unexpected, Visitor}, + Deserialize, Deserializer, +}; + const DEFAULT_HTTP_INTERFACE: &str = "[::]"; #[derive(JsonSchema, Deserialize, serde::Serialize, Clone, Debug)] diff --git a/plugins/zenoh-plugin-rest/src/lib.rs b/plugins/zenoh-plugin-rest/src/lib.rs index c712a1add6..4dd30f9a5f 100644 --- a/plugins/zenoh-plugin-rest/src/lib.rs +++ b/plugins/zenoh-plugin-rest/src/lib.rs @@ -17,29 +17,27 @@ //! This crate is intended for Zenoh's internal use. //! //! [Click here for Zenoh's documentation](../zenoh/index.html) +use std::{borrow::Cow, convert::TryFrom, str::FromStr, sync::Arc}; + use async_std::prelude::FutureExt; use base64::Engine; use futures::StreamExt; use http_types::Method; use serde::{Deserialize, Serialize}; -use std::borrow::Cow; -use std::convert::TryFrom; -use std::str::FromStr; -use std::sync::Arc; -use tide::http::Mime; -use tide::sse::Sender; -use tide::{Request, Response, Server, StatusCode}; -use zenoh::bytes::{StringOrBase64, ZBytes}; -use zenoh::core::try_init_log_from_env; -use zenoh::encoding::Encoding; -use zenoh::key_expr::{keyexpr, KeyExpr}; -use zenoh::plugins::{RunningPluginTrait, ZenohPlugin}; -use zenoh::query::{QueryConsolidation, Reply}; -use zenoh::runtime::Runtime; -use zenoh::sample::{Sample, SampleKind, ValueBuilderTrait}; -use zenoh::selector::{Selector, TIME_RANGE_KEY}; -use zenoh::session::{Session, SessionDeclarations}; -use zenoh::value::Value; +use tide::{http::Mime, sse::Sender, Request, Response, Server, StatusCode}; +use zenoh::{ + bytes::{StringOrBase64, ZBytes}, + core::try_init_log_from_env, + encoding::Encoding, + key_expr::{keyexpr, KeyExpr}, + plugins::{RunningPluginTrait, ZenohPlugin}, + query::{QueryConsolidation, Reply}, + runtime::Runtime, + sample::{Sample, SampleKind, ValueBuilderTrait}, + selector::{Selector, TIME_RANGE_KEY}, + session::{Session, SessionDeclarations}, + value::Value, +}; use zenoh_plugin_trait::{plugin_long_version, plugin_version, Plugin, PluginControl}; use zenoh_result::{bail, zerror, ZResult}; diff --git a/plugins/zenoh-plugin-storage-manager/src/backends_mgt.rs b/plugins/zenoh-plugin-storage-manager/src/backends_mgt.rs index dcdefda406..1bb8af4330 100644 --- a/plugins/zenoh-plugin-storage-manager/src/backends_mgt.rs +++ b/plugins/zenoh-plugin-storage-manager/src/backends_mgt.rs @@ -11,13 +11,13 @@ // Contributors: // ZettaScale Zenoh Team, // -use super::storages_mgt::*; -use flume::Sender; use std::sync::Arc; -use zenoh::core::Result as ZResult; -use zenoh::session::Session; -use zenoh_backend_traits::config::StorageConfig; -use zenoh_backend_traits::{Capability, VolumeInstance}; + +use flume::Sender; +use zenoh::{core::Result as ZResult, session::Session}; +use zenoh_backend_traits::{config::StorageConfig, Capability, VolumeInstance}; + +use super::storages_mgt::*; pub struct StoreIntercept { pub storage: Box, diff --git a/plugins/zenoh-plugin-storage-manager/src/lib.rs b/plugins/zenoh-plugin-storage-manager/src/lib.rs index 8818d44688..3415f6db65 100644 --- a/plugins/zenoh-plugin-storage-manager/src/lib.rs +++ b/plugins/zenoh-plugin-storage-manager/src/lib.rs @@ -19,34 +19,32 @@ //! [Click here for Zenoh's documentation](../zenoh/index.html) #![recursion_limit = "512"] +use std::{ + collections::HashMap, + convert::TryFrom, + sync::{Arc, Mutex}, +}; + use async_std::task; use flume::Sender; use memory_backend::MemoryBackend; -use std::collections::HashMap; -use std::convert::TryFrom; -use std::sync::Arc; -use std::sync::Mutex; use storages_mgt::StorageMessage; -use zenoh::core::try_init_log_from_env; -use zenoh::core::Result as ZResult; -use zenoh::internal::zlock; -use zenoh::internal::LibLoader; -use zenoh::key_expr::keyexpr; -use zenoh::plugins::{RunningPluginTrait, ZenohPlugin}; -use zenoh::runtime::Runtime; -use zenoh::selector::Selector; -use zenoh::session::Session; -use zenoh_backend_traits::config::ConfigDiff; -use zenoh_backend_traits::config::PluginConfig; -use zenoh_backend_traits::config::StorageConfig; -use zenoh_backend_traits::config::VolumeConfig; -use zenoh_backend_traits::VolumeInstance; -use zenoh_plugin_trait::plugin_long_version; -use zenoh_plugin_trait::plugin_version; -use zenoh_plugin_trait::Plugin; -use zenoh_plugin_trait::PluginControl; -use zenoh_plugin_trait::PluginReport; -use zenoh_plugin_trait::PluginStatusRec; +use zenoh::{ + core::{try_init_log_from_env, Result as ZResult}, + internal::{zlock, LibLoader}, + key_expr::keyexpr, + plugins::{RunningPluginTrait, ZenohPlugin}, + runtime::Runtime, + selector::Selector, + session::Session, +}; +use zenoh_backend_traits::{ + config::{ConfigDiff, PluginConfig, StorageConfig, VolumeConfig}, + VolumeInstance, +}; +use zenoh_plugin_trait::{ + plugin_long_version, plugin_version, Plugin, PluginControl, PluginReport, PluginStatusRec, +}; mod backends_mgt; use backends_mgt::*; diff --git a/plugins/zenoh-plugin-storage-manager/src/memory_backend/mod.rs b/plugins/zenoh-plugin-storage-manager/src/memory_backend/mod.rs index 60982c350d..1534d95e32 100644 --- a/plugins/zenoh-plugin-storage-manager/src/memory_backend/mod.rs +++ b/plugins/zenoh-plugin-storage-manager/src/memory_backend/mod.rs @@ -11,16 +11,15 @@ // Contributors: // ZettaScale Zenoh Team, // +use std::{collections::HashMap, sync::Arc}; + use async_std::sync::RwLock; use async_trait::async_trait; -use std::collections::HashMap; -use std::sync::Arc; -use zenoh::core::Result as ZResult; -use zenoh::key_expr::OwnedKeyExpr; -use zenoh::time::Timestamp; -use zenoh::value::Value; -use zenoh_backend_traits::config::{StorageConfig, VolumeConfig}; -use zenoh_backend_traits::*; +use zenoh::{core::Result as ZResult, key_expr::OwnedKeyExpr, time::Timestamp, value::Value}; +use zenoh_backend_traits::{ + config::{StorageConfig, VolumeConfig}, + *, +}; use zenoh_plugin_trait::{plugin_long_version, plugin_version, Plugin}; use crate::MEMORY_BACKEND_NAME; diff --git a/plugins/zenoh-plugin-storage-manager/src/replica/align_queryable.rs b/plugins/zenoh-plugin-storage-manager/src/replica/align_queryable.rs index 694e259a18..50c93fe3dd 100644 --- a/plugins/zenoh-plugin-storage-manager/src/replica/align_queryable.rs +++ b/plugins/zenoh-plugin-storage-manager/src/replica/align_queryable.rs @@ -11,15 +11,18 @@ // Contributors: // ZettaScale Zenoh Team, // -use super::digest::*; -use super::Snapshotter; +use std::{ + cmp::Ordering, + collections::{BTreeSet, HashMap, HashSet}, + str, + str::FromStr, +}; + use async_std::sync::Arc; -use std::cmp::Ordering; -use std::collections::{BTreeSet, HashMap, HashSet}; -use std::str; -use std::str::FromStr; use zenoh::prelude::*; +use super::{digest::*, Snapshotter}; + pub struct AlignQueryable { session: Arc, digest_key: OwnedKeyExpr, diff --git a/plugins/zenoh-plugin-storage-manager/src/replica/aligner.rs b/plugins/zenoh-plugin-storage-manager/src/replica/aligner.rs index 46ccdc2935..e0301f1a4e 100644 --- a/plugins/zenoh-plugin-storage-manager/src/replica/aligner.rs +++ b/plugins/zenoh-plugin-storage-manager/src/replica/aligner.rs @@ -12,14 +12,17 @@ // ZettaScale Zenoh Team, // -use super::{Digest, EraType, LogEntry, Snapshotter}; -use super::{CONTENTS, ERA, INTERVALS, SUBINTERVALS}; +use std::{ + collections::{HashMap, HashSet}, + str, +}; + use async_std::sync::{Arc, RwLock}; use flume::{Receiver, Sender}; -use std::collections::{HashMap, HashSet}; -use std::str; use zenoh::prelude::*; +use super::{Digest, EraType, LogEntry, Snapshotter, CONTENTS, ERA, INTERVALS, SUBINTERVALS}; + pub struct Aligner { session: Arc, digest_key: OwnedKeyExpr, diff --git a/plugins/zenoh-plugin-storage-manager/src/replica/digest.rs b/plugins/zenoh-plugin-storage-manager/src/replica/digest.rs index c70f26ea1f..bf06c61f25 100644 --- a/plugins/zenoh-plugin-storage-manager/src/replica/digest.rs +++ b/plugins/zenoh-plugin-storage-manager/src/replica/digest.rs @@ -12,16 +12,18 @@ // ZettaScale Zenoh Team, // +use std::{ + collections::{BTreeMap, BTreeSet, HashMap, HashSet}, + convert::TryFrom, + str::FromStr, + string::ParseError, + time::Duration, +}; + use crc::{Crc, CRC_64_ECMA_182}; use derive_new::new; use serde::{Deserialize, Serialize}; -use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet}; -use std::convert::TryFrom; -use std::str::FromStr; -use std::string::ParseError; -use std::time::Duration; -use zenoh::key_expr::OwnedKeyExpr; -use zenoh::time::Timestamp; +use zenoh::{key_expr::OwnedKeyExpr, time::Timestamp}; #[derive(Eq, PartialEq, Clone, Debug, Deserialize, Serialize)] pub struct DigestConfig { diff --git a/plugins/zenoh-plugin-storage-manager/src/replica/mod.rs b/plugins/zenoh-plugin-storage-manager/src/replica/mod.rs index c9d9e03bcf..421d45ade6 100644 --- a/plugins/zenoh-plugin-storage-manager/src/replica/mod.rs +++ b/plugins/zenoh-plugin-storage-manager/src/replica/mod.rs @@ -14,21 +14,25 @@ // This module extends Storage with alignment protocol that aligns storages subscribing to the same key_expr -use crate::backends_mgt::StoreIntercept; -use crate::storages_mgt::StorageMessage; -use async_std::stream::{interval, StreamExt}; -use async_std::sync::Arc; -use async_std::sync::RwLock; +use std::{ + collections::{HashMap, HashSet}, + str, + str::FromStr, + time::{Duration, SystemTime}, +}; + +use async_std::{ + stream::{interval, StreamExt}, + sync::{Arc, RwLock}, +}; use flume::{Receiver, Sender}; use futures::{pin_mut, select, FutureExt}; -use std::collections::{HashMap, HashSet}; -use std::str; -use std::str::FromStr; -use std::time::{Duration, SystemTime}; use urlencoding::encode; use zenoh::prelude::*; use zenoh_backend_traits::config::{ReplicaConfig, StorageConfig}; +use crate::{backends_mgt::StoreIntercept, storages_mgt::StorageMessage}; + pub mod align_queryable; pub mod aligner; pub mod digest; diff --git a/plugins/zenoh-plugin-storage-manager/src/replica/snapshotter.rs b/plugins/zenoh-plugin-storage-manager/src/replica/snapshotter.rs index e66a6e88ca..d5708686ee 100644 --- a/plugins/zenoh-plugin-storage-manager/src/replica/snapshotter.rs +++ b/plugins/zenoh-plugin-storage-manager/src/replica/snapshotter.rs @@ -11,20 +11,24 @@ // Contributors: // ZettaScale Zenoh Team, // -use super::{Digest, DigestConfig, LogEntry}; -use async_std::stream::{interval, StreamExt}; -use async_std::sync::Arc; -use async_std::sync::RwLock; -use async_std::task::sleep; +use std::{ + collections::{HashMap, HashSet}, + convert::TryFrom, + time::Duration, +}; + +use async_std::{ + stream::{interval, StreamExt}, + sync::{Arc, RwLock}, + task::sleep, +}; use flume::Receiver; use futures::join; -use std::collections::{HashMap, HashSet}; -use std::convert::TryFrom; -use std::time::Duration; -use zenoh::key_expr::OwnedKeyExpr; -use zenoh::time::Timestamp; +use zenoh::{key_expr::OwnedKeyExpr, time::Timestamp}; use zenoh_backend_traits::config::ReplicaConfig; +use super::{Digest, DigestConfig, LogEntry}; + pub struct Snapshotter { // channel to get updates from the storage storage_update: Receiver<(OwnedKeyExpr, Timestamp)>, diff --git a/plugins/zenoh-plugin-storage-manager/src/replica/storage.rs b/plugins/zenoh-plugin-storage-manager/src/replica/storage.rs index 476893539e..bd7d56f7fc 100644 --- a/plugins/zenoh-plugin-storage-manager/src/replica/storage.rs +++ b/plugins/zenoh-plugin-storage-manager/src/replica/storage.rs @@ -11,35 +11,39 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::backends_mgt::StoreIntercept; -use crate::storages_mgt::StorageMessage; -use async_std::sync::Arc; -use async_std::sync::{Mutex, RwLock}; +use std::{ + collections::{HashMap, HashSet}, + str::{self, FromStr}, + time::{SystemTime, UNIX_EPOCH}, +}; + +use async_std::sync::{Arc, Mutex, RwLock}; use async_trait::async_trait; use flume::{Receiver, Sender}; use futures::select; -use std::collections::{HashMap, HashSet}; -use std::str::{self, FromStr}; -use std::time::{SystemTime, UNIX_EPOCH}; -use zenoh::buffers::SplitBuffer; -use zenoh::buffers::ZBuf; -use zenoh::internal::bail; -use zenoh::internal::{zenoh_home, Timed, TimedEvent, Timer}; -use zenoh::key_expr::keyexpr_tree::KeyedSetProvider; -use zenoh::key_expr::keyexpr_tree::{IKeyExprTree, IKeyExprTreeMut}; -use zenoh::key_expr::keyexpr_tree::{KeBoxTree, NonWild, UnknownWildness}; -use zenoh::key_expr::KeyExpr; -use zenoh::key_expr::OwnedKeyExpr; -use zenoh::query::{ConsolidationMode, QueryTarget}; -use zenoh::sample::{Sample, SampleKind, TimestampBuilderTrait}; -use zenoh::sample::{SampleBuilder, ValueBuilderTrait}; -use zenoh::selector::Selector; -use zenoh::session::SessionDeclarations; -use zenoh::time::{new_reception_timestamp, Timestamp, NTP64}; -use zenoh::value::Value; -use zenoh::{core::Result as ZResult, session::Session}; -use zenoh_backend_traits::config::{GarbageCollectionConfig, StorageConfig}; -use zenoh_backend_traits::{Capability, History, Persistence, StorageInsertionResult, StoredData}; +use zenoh::{ + buffers::{SplitBuffer, ZBuf}, + core::Result as ZResult, + internal::{bail, zenoh_home, Timed, TimedEvent, Timer}, + key_expr::{ + keyexpr_tree::{ + IKeyExprTree, IKeyExprTreeMut, KeBoxTree, KeyedSetProvider, NonWild, UnknownWildness, + }, + KeyExpr, OwnedKeyExpr, + }, + query::{ConsolidationMode, QueryTarget}, + sample::{Sample, SampleBuilder, SampleKind, TimestampBuilderTrait, ValueBuilderTrait}, + selector::Selector, + session::{Session, SessionDeclarations}, + time::{new_reception_timestamp, Timestamp, NTP64}, + value::Value, +}; +use zenoh_backend_traits::{ + config::{GarbageCollectionConfig, StorageConfig}, + Capability, History, Persistence, StorageInsertionResult, StoredData, +}; + +use crate::{backends_mgt::StoreIntercept, storages_mgt::StorageMessage}; pub const WILDCARD_UPDATES_FILENAME: &str = "wildcard_updates"; pub const TOMBSTONE_FILENAME: &str = "tombstones"; diff --git a/plugins/zenoh-plugin-storage-manager/src/storages_mgt.rs b/plugins/zenoh-plugin-storage-manager/src/storages_mgt.rs index a77cdd936f..1670310fcf 100644 --- a/plugins/zenoh-plugin-storage-manager/src/storages_mgt.rs +++ b/plugins/zenoh-plugin-storage-manager/src/storages_mgt.rs @@ -12,8 +12,7 @@ // ZettaScale Zenoh Team, // use async_std::sync::Arc; -use zenoh::core::Result as ZResult; -use zenoh::session::Session; +use zenoh::{core::Result as ZResult, session::Session}; use zenoh_backend_traits::config::StorageConfig; pub use super::replica::{Replica, StorageService}; diff --git a/plugins/zenoh-plugin-storage-manager/tests/operations.rs b/plugins/zenoh-plugin-storage-manager/tests/operations.rs index b5384e13be..89f6e73f97 100644 --- a/plugins/zenoh-plugin-storage-manager/tests/operations.rs +++ b/plugins/zenoh-plugin-storage-manager/tests/operations.rs @@ -16,12 +16,10 @@ // 1. normal case, just some wild card puts and deletes on existing keys and ensure it works // 2. check for dealing with out of order updates -use std::str::FromStr; -use std::thread::sleep; +use std::{str::FromStr, thread::sleep}; use async_std::task; -use zenoh::internal::zasync_executor_init; -use zenoh::prelude::*; +use zenoh::{internal::zasync_executor_init, prelude::*}; use zenoh_plugin_trait::Plugin; async fn put_data(session: &Session, key_expr: &str, value: &str, _timestamp: Timestamp) { diff --git a/plugins/zenoh-plugin-storage-manager/tests/wildcard.rs b/plugins/zenoh-plugin-storage-manager/tests/wildcard.rs index bd38e834d7..484a37e36a 100644 --- a/plugins/zenoh-plugin-storage-manager/tests/wildcard.rs +++ b/plugins/zenoh-plugin-storage-manager/tests/wildcard.rs @@ -16,13 +16,11 @@ // 1. normal case, just some wild card puts and deletes on existing keys and ensure it works // 2. check for dealing with out of order updates -use std::str::FromStr; -use std::thread::sleep; +use std::{str::FromStr, thread::sleep}; // use std::collections::HashMap; use async_std::task; -use zenoh::internal::zasync_executor_init; -use zenoh::prelude::*; +use zenoh::{internal::zasync_executor_init, prelude::*}; use zenoh_plugin_trait::Plugin; async fn put_data(session: &Session, key_expr: &str, value: &str, _timestamp: Timestamp) { diff --git a/plugins/zenoh-plugin-trait/src/manager.rs b/plugins/zenoh-plugin-trait/src/manager.rs index a205c3972d..2f5336d1fc 100644 --- a/plugins/zenoh-plugin-trait/src/manager.rs +++ b/plugins/zenoh-plugin-trait/src/manager.rs @@ -13,7 +13,6 @@ mod dynamic_plugin; mod static_plugin; -use crate::*; use zenoh_keyexpr::keyexpr; use zenoh_result::ZResult; use zenoh_util::LibLoader; @@ -22,6 +21,7 @@ use self::{ dynamic_plugin::{DynamicPlugin, DynamicPluginSource}, static_plugin::StaticPlugin, }; +use crate::*; pub trait DeclaredPlugin: PluginStatus { fn as_status(&self) -> &dyn PluginStatus; diff --git a/plugins/zenoh-plugin-trait/src/manager/dynamic_plugin.rs b/plugins/zenoh-plugin-trait/src/manager/dynamic_plugin.rs index 90008aad36..36a23a1015 100644 --- a/plugins/zenoh-plugin-trait/src/manager/dynamic_plugin.rs +++ b/plugins/zenoh-plugin-trait/src/manager/dynamic_plugin.rs @@ -10,13 +10,14 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::*; use std::path::{Path, PathBuf}; use libloading::Library; use zenoh_result::{bail, ZResult}; use zenoh_util::LibLoader; +use crate::*; + /// This enum contains information where to load the plugin from. pub enum DynamicPluginSource { /// Load plugin with the name in String + `.so | .dll | .dylib` diff --git a/plugins/zenoh-plugin-trait/src/manager/static_plugin.rs b/plugins/zenoh-plugin-trait/src/manager/static_plugin.rs index 6d1bcae278..756f67fd02 100644 --- a/plugins/zenoh-plugin-trait/src/manager/static_plugin.rs +++ b/plugins/zenoh-plugin-trait/src/manager/static_plugin.rs @@ -11,10 +11,12 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::*; use std::marker::PhantomData; + use zenoh_result::ZResult; +use crate::*; + pub struct StaticPlugin where P: Plugin, diff --git a/plugins/zenoh-plugin-trait/src/plugin.rs b/plugins/zenoh-plugin-trait/src/plugin.rs index 6911d614d5..703f4fb0b1 100644 --- a/plugins/zenoh-plugin-trait/src/plugin.rs +++ b/plugins/zenoh-plugin-trait/src/plugin.rs @@ -11,12 +11,14 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::StructVersion; -use serde::{Deserialize, Serialize}; use std::{borrow::Cow, ops::BitOrAssign}; + +use serde::{Deserialize, Serialize}; use zenoh_keyexpr::keyexpr; use zenoh_result::ZResult; +use crate::StructVersion; + /// The plugin can be in one of these states: /// - Declared: the plugin is declared in the configuration file, but not loaded yet or failed to load /// - Loaded: the plugin is loaded, but not started yet or failed to start diff --git a/zenoh-ext/examples/examples/z_member.rs b/zenoh-ext/examples/examples/z_member.rs index 35513b1b56..783ee97a9e 100644 --- a/zenoh-ext/examples/examples/z_member.rs +++ b/zenoh-ext/examples/examples/z_member.rs @@ -11,9 +11,9 @@ // Contributors: // ZettaScale Zenoh Team, // +use std::{sync::Arc, time::Duration}; + use futures::StreamExt; -use std::sync::Arc; -use std::time::Duration; use zenoh::prelude::*; use zenoh_ext::group::*; diff --git a/zenoh-ext/examples/examples/z_pub_cache.rs b/zenoh-ext/examples/examples/z_pub_cache.rs index 09c888cb0b..684cc7cb75 100644 --- a/zenoh-ext/examples/examples/z_pub_cache.rs +++ b/zenoh-ext/examples/examples/z_pub_cache.rs @@ -11,10 +11,13 @@ // Contributors: // ZettaScale Zenoh Team, // -use clap::{arg, Parser}; use std::time::Duration; -use zenoh::config::{Config, ModeDependentValue}; -use zenoh::prelude::*; + +use clap::{arg, Parser}; +use zenoh::{ + config::{Config, ModeDependentValue}, + prelude::*, +}; use zenoh_ext::*; use zenoh_ext_examples::CommonArgs; diff --git a/zenoh-ext/examples/examples/z_query_sub.rs b/zenoh-ext/examples/examples/z_query_sub.rs index a735ecec66..2fa077eba1 100644 --- a/zenoh-ext/examples/examples/z_query_sub.rs +++ b/zenoh-ext/examples/examples/z_query_sub.rs @@ -11,10 +11,8 @@ // Contributors: // ZettaScale Zenoh Team, // -use clap::arg; -use clap::Parser; -use zenoh::config::Config; -use zenoh::prelude::*; +use clap::{arg, Parser}; +use zenoh::{config::Config, prelude::*}; use zenoh_ext::*; use zenoh_ext_examples::CommonArgs; diff --git a/zenoh-ext/examples/examples/z_view_size.rs b/zenoh-ext/examples/examples/z_view_size.rs index 52e78790bb..fd8220d506 100644 --- a/zenoh-ext/examples/examples/z_view_size.rs +++ b/zenoh-ext/examples/examples/z_view_size.rs @@ -11,9 +11,9 @@ // Contributors: // ZettaScale Zenoh Team, // +use std::{sync::Arc, time::Duration}; + use clap::{arg, Parser}; -use std::sync::Arc; -use std::time::Duration; use zenoh::config::Config; use zenoh_ext::group::*; use zenoh_ext_examples::CommonArgs; diff --git a/zenoh-ext/src/group.rs b/zenoh-ext/src/group.rs index d764e5ed9c..44600b038c 100644 --- a/zenoh-ext/src/group.rs +++ b/zenoh-ext/src/group.rs @@ -14,18 +14,22 @@ //! To manage groups and group memeberships +use std::{ + collections::HashMap, + convert::TryInto, + ops::Add, + sync::Arc, + time::{Duration, Instant}, +}; + use flume::{Receiver, Sender}; -use futures::prelude::*; -use futures::select; +use futures::{prelude::*, select}; use serde::{Deserialize, Serialize}; -use std::collections::HashMap; -use std::convert::TryInto; -use std::ops::Add; -use std::sync::Arc; -use std::time::{Duration, Instant}; use tokio::sync::Mutex; -use zenoh::internal::{bail, Condition, TaskController}; -use zenoh::prelude::*; +use zenoh::{ + internal::{bail, Condition, TaskController}, + prelude::*, +}; const GROUP_PREFIX: &str = "zenoh/ext/net/group"; const EVENT_POSTFIX: &str = "evt"; diff --git a/zenoh-ext/src/lib.rs b/zenoh-ext/src/lib.rs index 41eea0b074..9802d04e3a 100644 --- a/zenoh-ext/src/lib.rs +++ b/zenoh-ext/src/lib.rs @@ -21,11 +21,8 @@ pub use querying_subscriber::{ FetchingSubscriber, FetchingSubscriberBuilder, QueryingSubscriberBuilder, }; pub use session_ext::SessionExt; -pub use subscriber_ext::SubscriberBuilderExt; -pub use subscriber_ext::SubscriberForward; -use zenoh::internal::zerror; -use zenoh::query::Reply; -use zenoh::{core::Result as ZResult, sample::Sample}; +pub use subscriber_ext::{SubscriberBuilderExt, SubscriberForward}; +use zenoh::{core::Result as ZResult, internal::zerror, query::Reply, sample::Sample}; /// The space of keys to use in a [`FetchingSubscriber`]. pub enum KeySpace { diff --git a/zenoh-ext/src/publication_cache.rs b/zenoh-ext/src/publication_cache.rs index 11fb8fb72a..1796668f1c 100644 --- a/zenoh-ext/src/publication_cache.rs +++ b/zenoh-ext/src/publication_cache.rs @@ -11,21 +11,24 @@ // Contributors: // ZettaScale Zenoh Team, // -use std::collections::{HashMap, VecDeque}; -use std::convert::TryInto; -use std::future::{IntoFuture, Ready}; -use std::time::Duration; -use zenoh::core::Error; -use zenoh::core::{Resolvable, Resolve}; -use zenoh::internal::{ResolveFuture, TerminatableTask}; -use zenoh::key_expr::{keyexpr, KeyExpr, OwnedKeyExpr}; -use zenoh::prelude::Wait; -use zenoh::queryable::{Query, Queryable}; -use zenoh::runtime::ZRuntime; -use zenoh::sample::{Locality, Sample}; -use zenoh::session::{SessionDeclarations, SessionRef}; -use zenoh::subscriber::FlumeSubscriber; -use zenoh::{core::Result as ZResult, internal::bail}; +use std::{ + collections::{HashMap, VecDeque}, + convert::TryInto, + future::{IntoFuture, Ready}, + time::Duration, +}; + +use zenoh::{ + core::{Error, Resolvable, Resolve, Result as ZResult}, + internal::{bail, ResolveFuture, TerminatableTask}, + key_expr::{keyexpr, KeyExpr, OwnedKeyExpr}, + prelude::Wait, + queryable::{Query, Queryable}, + runtime::ZRuntime, + sample::{Locality, Sample}, + session::{SessionDeclarations, SessionRef}, + subscriber::FlumeSubscriber, +}; /// The builder of PublicationCache, allowing to configure it. #[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"] diff --git a/zenoh-ext/src/querying_subscriber.rs b/zenoh-ext/src/querying_subscriber.rs index 6febef7395..e76c6f7f5c 100644 --- a/zenoh-ext/src/querying_subscriber.rs +++ b/zenoh-ext/src/querying_subscriber.rs @@ -11,24 +11,28 @@ // Contributors: // ZettaScale Zenoh Team, // -use std::collections::{btree_map, BTreeMap, VecDeque}; -use std::convert::TryInto; -use std::future::{IntoFuture, Ready}; -use std::mem::swap; -use std::sync::{Arc, Mutex}; -use std::time::Duration; -use zenoh::core::{Resolvable, Resolve}; -use zenoh::handlers::{locked, DefaultHandler, IntoHandler}; -use zenoh::internal::zlock; -use zenoh::key_expr::KeyExpr; -use zenoh::prelude::Wait; -use zenoh::query::{QueryConsolidation, QueryTarget, ReplyKeyExpr}; -use zenoh::sample::{Locality, Sample, SampleBuilder, TimestampBuilderTrait}; -use zenoh::selector::Selector; -use zenoh::session::{SessionDeclarations, SessionRef}; -use zenoh::subscriber::{Reliability, Subscriber}; -use zenoh::time::{new_reception_timestamp, Timestamp}; -use zenoh::{core::Error, core::Result as ZResult}; +use std::{ + collections::{btree_map, BTreeMap, VecDeque}, + convert::TryInto, + future::{IntoFuture, Ready}, + mem::swap, + sync::{Arc, Mutex}, + time::Duration, +}; + +use zenoh::{ + core::{Error, Resolvable, Resolve, Result as ZResult}, + handlers::{locked, DefaultHandler, IntoHandler}, + internal::zlock, + key_expr::KeyExpr, + prelude::Wait, + query::{QueryConsolidation, QueryTarget, ReplyKeyExpr}, + sample::{Locality, Sample, SampleBuilder, TimestampBuilderTrait}, + selector::Selector, + session::{SessionDeclarations, SessionRef}, + subscriber::{Reliability, Subscriber}, + time::{new_reception_timestamp, Timestamp}, +}; use crate::ExtractSample; diff --git a/zenoh-ext/src/session_ext.rs b/zenoh-ext/src/session_ext.rs index d005cafc86..3b33bc9b16 100644 --- a/zenoh-ext/src/session_ext.rs +++ b/zenoh-ext/src/session_ext.rs @@ -11,15 +11,16 @@ // Contributors: // ZettaScale Zenoh Team, // -use super::PublicationCacheBuilder; -use std::convert::TryInto; -use std::sync::Arc; +use std::{convert::TryInto, sync::Arc}; + use zenoh::{ core::Error, key_expr::KeyExpr, session::{Session, SessionRef}, }; +use super::PublicationCacheBuilder; + /// Some extensions to the [`zenoh::Session`](zenoh::Session) pub trait SessionExt<'s, 'a> { fn declare_publication_cache<'b, 'c, TryIntoKeyExpr>( diff --git a/zenoh-ext/src/subscriber_ext.rs b/zenoh-ext/src/subscriber_ext.rs index 8c3b1239b6..81c969a223 100644 --- a/zenoh-ext/src/subscriber_ext.rs +++ b/zenoh-ext/src/subscriber_ext.rs @@ -11,21 +11,21 @@ // Contributors: // ZettaScale Zenoh Team, // +use std::time::Duration; + use flume::r#async::RecvStream; use futures::stream::{Forward, Map}; -use std::time::Duration; -use zenoh::core::Result as ZResult; -use zenoh::query::ReplyKeyExpr; -use zenoh::sample::Locality; use zenoh::{ + core::Result as ZResult, liveliness::LivelinessSubscriberBuilder, - query::{QueryConsolidation, QueryTarget}, - sample::Sample, + query::{QueryConsolidation, QueryTarget, ReplyKeyExpr}, + sample::{Locality, Sample}, subscriber::{Reliability, Subscriber, SubscriberBuilder}, }; -use crate::ExtractSample; -use crate::{querying_subscriber::QueryingSubscriberBuilder, FetchingSubscriberBuilder}; +use crate::{ + querying_subscriber::QueryingSubscriberBuilder, ExtractSample, FetchingSubscriberBuilder, +}; /// Allows writing `subscriber.forward(receiver)` instead of `subscriber.stream().map(Ok).forward(publisher)` pub trait SubscriberForward<'a, S> { diff --git a/zenoh/src/api/admin.rs b/zenoh/src/api/admin.rs index e720fde1c3..6e7605e95b 100644 --- a/zenoh/src/api/admin.rs +++ b/zenoh/src/api/admin.rs @@ -11,20 +11,12 @@ // Contributors: // ZettaScale Zenoh Team, // -use super::{ - bytes::ZBytes, - encoding::Encoding, - key_expr::KeyExpr, - queryable::Query, - sample::Locality, - sample::{DataInfo, SampleKind}, - session::Session, -}; use std::{ collections::hash_map::DefaultHasher, hash::{Hash, Hasher}, sync::Arc, }; + use zenoh_core::{Result as ZResult, Wait}; use zenoh_keyexpr::keyexpr; use zenoh_protocol::{core::WireExpr, network::NetworkMessage}; @@ -32,6 +24,15 @@ use zenoh_transport::{ TransportEventHandler, TransportMulticastEventHandler, TransportPeer, TransportPeerEventHandler, }; +use super::{ + bytes::ZBytes, + encoding::Encoding, + key_expr::KeyExpr, + queryable::Query, + sample::{DataInfo, Locality, SampleKind}, + session::Session, +}; + macro_rules! ke_for_sure { ($val:expr) => { unsafe { keyexpr::from_str_unchecked($val) } diff --git a/zenoh/src/api/builders/publication.rs b/zenoh/src/api/builders/publication.rs index 5285825b29..d4dc1b54d2 100644 --- a/zenoh/src/api/builders/publication.rs +++ b/zenoh/src/api/builders/publication.rs @@ -11,24 +11,27 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::api::builders::sample::SampleBuilderTrait; -use crate::api::builders::sample::{QoSBuilderTrait, TimestampBuilderTrait, ValueBuilderTrait}; +use std::future::{IntoFuture, Ready}; + +use zenoh_core::{Resolvable, Result as ZResult, Wait}; +use zenoh_protocol::{core::CongestionControl, network::Mapping}; + #[cfg(feature = "unstable")] use crate::api::bytes::OptionZBytes; -use crate::api::bytes::ZBytes; -use crate::api::key_expr::KeyExpr; -use crate::api::publication::Priority; -use crate::api::sample::Locality; -use crate::api::sample::SampleKind; #[cfg(feature = "unstable")] use crate::api::sample::SourceInfo; -use crate::api::session::SessionRef; -use crate::api::value::Value; -use crate::api::{encoding::Encoding, publication::Publisher}; -use std::future::{IntoFuture, Ready}; -use zenoh_core::{Resolvable, Result as ZResult, Wait}; -use zenoh_protocol::core::CongestionControl; -use zenoh_protocol::network::Mapping; +use crate::api::{ + builders::sample::{ + QoSBuilderTrait, SampleBuilderTrait, TimestampBuilderTrait, ValueBuilderTrait, + }, + bytes::ZBytes, + encoding::Encoding, + key_expr::KeyExpr, + publication::{Priority, Publisher}, + sample::{Locality, SampleKind}, + session::SessionRef, + value::Value, +}; pub type SessionPutBuilder<'a, 'b> = PublicationBuilder, PublicationBuilderPut>; diff --git a/zenoh/src/api/builders/sample.rs b/zenoh/src/api/builders/sample.rs index 0335949b82..56ae8c6c1b 100644 --- a/zenoh/src/api/builders/sample.rs +++ b/zenoh/src/api/builders/sample.rs @@ -11,22 +11,23 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::api::bytes::ZBytes; -use crate::api::encoding::Encoding; -use crate::api::key_expr::KeyExpr; -use crate::api::publication::Priority; -use crate::api::sample::QoS; -use crate::api::sample::QoSBuilder; -use crate::api::sample::Sample; -use crate::api::sample::SampleKind; -use crate::api::value::Value; -#[cfg(feature = "unstable")] -use crate::{api::bytes::OptionZBytes, sample::SourceInfo}; use std::marker::PhantomData; + use uhlc::Timestamp; use zenoh_core::zresult; use zenoh_protocol::core::CongestionControl; +use crate::api::{ + bytes::ZBytes, + encoding::Encoding, + key_expr::KeyExpr, + publication::Priority, + sample::{QoS, QoSBuilder, Sample, SampleKind}, + value::Value, +}; +#[cfg(feature = "unstable")] +use crate::{api::bytes::OptionZBytes, sample::SourceInfo}; + pub trait QoSBuilderTrait { /// Change the `congestion_control` to apply when routing the data. fn congestion_control(self, congestion_control: CongestionControl) -> Self; diff --git a/zenoh/src/api/bytes.rs b/zenoh/src/api/bytes.rs index c36136ef81..fb32910b54 100644 --- a/zenoh/src/api/bytes.rs +++ b/zenoh/src/api/bytes.rs @@ -13,11 +13,11 @@ // //! ZBytes primitives. -use crate::buffers::ZBuf; use std::{ borrow::Cow, convert::Infallible, fmt::Debug, marker::PhantomData, ops::Deref, str::Utf8Error, string::FromUtf8Error, sync::Arc, }; + use unwrap_infallible::UnwrapInfallible; use zenoh_buffers::{ buffer::{Buffer, SplitBuffer}, @@ -37,6 +37,8 @@ use zenoh_shm::{ SharedMemoryBuf, }; +use crate::buffers::ZBuf; + /// Trait to encode a type `T` into a [`Value`]. pub trait Serialize { type Output; @@ -1825,12 +1827,11 @@ impl From> for ZBytes { mod tests { #[test] fn serializer() { - use super::ZBytes; - use rand::Rng; use std::borrow::Cow; + + use rand::Rng; use zenoh_buffers::{ZBuf, ZSlice}; use zenoh_protocol::core::Properties; - #[cfg(all(feature = "shared-memory", feature = "unstable"))] use zenoh_shm::api::{ protocol_implementations::posix::{ @@ -1841,6 +1842,8 @@ mod tests { slice::zsliceshm::{zsliceshm, ZSliceShm}, }; + use super::ZBytes; + const NUM: usize = 1_000; macro_rules! serialize_deserialize { diff --git a/zenoh/src/api/encoding.rs b/zenoh/src/api/encoding.rs index 6c08303612..f1be92c7ac 100644 --- a/zenoh/src/api/encoding.rs +++ b/zenoh/src/api/encoding.rs @@ -11,14 +11,16 @@ // Contributors: // ZettaScale Zenoh Team, // -use super::bytes::ZBytes; -use phf::phf_map; use std::{borrow::Cow, convert::Infallible, fmt, str::FromStr}; + +use phf::phf_map; use zenoh_buffers::{ZBuf, ZSlice}; use zenoh_protocol::core::EncodingId; #[cfg(feature = "shared-memory")] use zenoh_shm::api::slice::{zsliceshm::ZSliceShm, zsliceshmmut::ZSliceShmMut}; +use super::bytes::ZBytes; + /// Default encoding values used by Zenoh. /// /// An encoding has a similar role to Content-type in HTTP: it indicates, when present, how data should be interpreted by the application. diff --git a/zenoh/src/api/handlers/ring.rs b/zenoh/src/api/handlers/ring.rs index 755c6d9bce..77ad867d36 100644 --- a/zenoh/src/api/handlers/ring.rs +++ b/zenoh/src/api/handlers/ring.rs @@ -13,13 +13,14 @@ // //! Callback handler trait. -use crate::api::session::API_DATA_RECEPTION_CHANNEL_SIZE; - -use super::{callback::Callback, Dyn, IntoHandler}; use std::sync::{Arc, Weak}; + use zenoh_collections::RingBuffer; use zenoh_result::ZResult; +use super::{callback::Callback, Dyn, IntoHandler}; +use crate::api::session::API_DATA_RECEPTION_CHANNEL_SIZE; + /// A synchrounous ring channel with a limited size that allows users to keep the last N data. pub struct RingChannel { capacity: usize, diff --git a/zenoh/src/api/info.rs b/zenoh/src/api/info.rs index a6f8ff1629..bc813219b9 100644 --- a/zenoh/src/api/info.rs +++ b/zenoh/src/api/info.rs @@ -13,11 +13,13 @@ // //! Tools to access information about the current zenoh [`Session`](crate::Session). -use super::session::SessionRef; use std::future::{IntoFuture, Ready}; + use zenoh_core::{Resolvable, Wait}; use zenoh_protocol::core::{WhatAmI, ZenohId}; +use super::session::SessionRef; + /// A builder retuned by [`SessionInfo::zid()`](SessionInfo::zid) that allows /// to access the [`ZenohId`] of the current zenoh [`Session`](crate::Session). /// diff --git a/zenoh/src/api/key_expr.rs b/zenoh/src/api/key_expr.rs index 20dcf9cbee..c5fdf12609 100644 --- a/zenoh/src/api/key_expr.rs +++ b/zenoh/src/api/key_expr.rs @@ -12,14 +12,12 @@ // ZettaScale Zenoh Team, // -use super::session::{Session, Undeclarable}; -use crate::net::primitives::Primitives; -use std::future::IntoFuture; use std::{ convert::{TryFrom, TryInto}, - future::Ready, + future::{IntoFuture, Ready}, str::FromStr, }; + use zenoh_core::{Resolvable, Wait}; use zenoh_keyexpr::{keyexpr, OwnedKeyExpr}; use zenoh_protocol::{ @@ -28,6 +26,9 @@ use zenoh_protocol::{ }; use zenoh_result::ZResult; +use super::session::{Session, Undeclarable}; +use crate::net::primitives::Primitives; + #[derive(Clone, Debug)] pub(crate) enum KeyExprInner<'a> { Borrowed(&'a keyexpr), diff --git a/zenoh/src/api/liveliness.rs b/zenoh/src/api/liveliness.rs index f7235426c3..640c639dec 100644 --- a/zenoh/src/api/liveliness.rs +++ b/zenoh/src/api/liveliness.rs @@ -12,6 +12,18 @@ // ZettaScale Zenoh Team, // +use std::{ + convert::TryInto, + future::{IntoFuture, Ready}, + sync::Arc, + time::Duration, +}; + +use zenoh_config::unwrap_or_default; +use zenoh_core::{Resolvable, Resolve, Result as ZResult, Wait}; +use zenoh_keyexpr::keyexpr; +use zenoh_protocol::network::{declare::subscriber::ext::SubscriberInfo, request}; + use super::{ handlers::{locked, DefaultHandler, IntoHandler}, key_expr::KeyExpr, @@ -21,13 +33,6 @@ use super::{ subscriber::{Subscriber, SubscriberInner}, Id, }; -use std::future::IntoFuture; -use std::{convert::TryInto, future::Ready, sync::Arc, time::Duration}; -use zenoh_config::unwrap_or_default; -use zenoh_core::{Resolvable, Result as ZResult}; -use zenoh_core::{Resolve, Wait}; -use zenoh_keyexpr::keyexpr; -use zenoh_protocol::network::{declare::subscriber::ext::SubscriberInfo, request}; #[zenoh_macros::unstable] pub(crate) static PREFIX_LIVELINESS: &str = crate::net::routing::PREFIX_LIVELINESS; diff --git a/zenoh/src/api/loader.rs b/zenoh/src/api/loader.rs index e4a28de02e..ad4dac61fb 100644 --- a/zenoh/src/api/loader.rs +++ b/zenoh/src/api/loader.rs @@ -11,11 +11,12 @@ // Contributors: // ZettaScale Zenoh Team, // -use super::plugins::{PluginsManager, PLUGIN_PREFIX}; -use crate::runtime::Runtime; use zenoh_config::{Config, PluginLoad}; use zenoh_result::ZResult; +use super::plugins::{PluginsManager, PLUGIN_PREFIX}; +use crate::runtime::Runtime; + pub(crate) fn load_plugin( plugin_mgr: &mut PluginsManager, name: &str, diff --git a/zenoh/src/api/plugins.rs b/zenoh/src/api/plugins.rs index 27f6f18d7a..b7f1954a6b 100644 --- a/zenoh/src/api/plugins.rs +++ b/zenoh/src/api/plugins.rs @@ -14,8 +14,6 @@ //! `zenohd`'s plugin system. For more details, consult the [detailed documentation](https://github.com/eclipse-zenoh/roadmap/blob/main/rfcs/ALL/Plugins/Zenoh%20Plugins.md). -use super::selector::Selector; -use crate::net::runtime::Runtime; use zenoh_core::zconfigurable; use zenoh_plugin_trait::{ Plugin, PluginControl, PluginInstance, PluginReport, PluginStatusRec, StructVersion, @@ -23,6 +21,9 @@ use zenoh_plugin_trait::{ use zenoh_protocol::core::key_expr::keyexpr; use zenoh_result::ZResult; +use super::selector::Selector; +use crate::net::runtime::Runtime; + zconfigurable! { pub static ref PLUGIN_PREFIX: String = "zenoh_plugin_".to_string(); } diff --git a/zenoh/src/api/publication.rs b/zenoh/src/api/publication.rs index 518ddc4d1b..553170e76a 100644 --- a/zenoh/src/api/publication.rs +++ b/zenoh/src/api/publication.rs @@ -12,26 +12,14 @@ // ZettaScale Zenoh Team, // -use super::{ - builders::publication::{ - PublicationBuilder, PublicationBuilderDelete, PublicationBuilderPut, - PublisherDeleteBuilder, PublisherPutBuilder, - }, - bytes::ZBytes, - encoding::Encoding, - key_expr::KeyExpr, - sample::{DataInfo, Locality, QoS, Sample, SampleFields, SampleKind}, - session::{SessionRef, Undeclarable}, -}; -use crate::net::primitives::Primitives; -use futures::Sink; -use std::future::IntoFuture; use std::{ convert::TryFrom, - future::Ready, + future::{IntoFuture, Ready}, pin::Pin, task::{Context, Poll}, }; + +use futures::Sink; use zenoh_core::{zread, Resolvable, Resolve, Wait}; use zenoh_keyexpr::keyexpr; use zenoh_protocol::{ @@ -40,7 +28,6 @@ use zenoh_protocol::{ zenoh::{Del, PushBody, Put}, }; use zenoh_result::{Error, ZResult}; - #[zenoh_macros::unstable] use { crate::api::handlers::{Callback, DefaultHandler, IntoHandler}, @@ -50,6 +37,19 @@ use { zenoh_protocol::core::EntityId, }; +use super::{ + builders::publication::{ + PublicationBuilder, PublicationBuilderDelete, PublicationBuilderPut, + PublisherDeleteBuilder, PublisherPutBuilder, + }, + bytes::ZBytes, + encoding::Encoding, + key_expr::KeyExpr, + sample::{DataInfo, Locality, QoS, Sample, SampleFields, SampleKind}, + session::{SessionRef, Undeclarable}, +}; +use crate::net::primitives::Primitives; + #[zenoh_macros::unstable] #[derive(Clone)] pub enum PublisherRef<'a> { @@ -1087,16 +1087,19 @@ impl Drop for MatchingListenerInner<'_> { #[cfg(test)] mod tests { - use crate::api::{sample::SampleKind, session::SessionDeclarations}; use zenoh_config::Config; use zenoh_core::Wait; + use crate::api::{sample::SampleKind, session::SessionDeclarations}; + #[test] fn priority_from() { - use super::Priority as APrio; use std::convert::TryInto; + use zenoh_protocol::core::Priority as TPrio; + use super::Priority as APrio; + for i in APrio::MAX as u8..=APrio::MIN as u8 { let p: APrio = i.try_into().unwrap(); diff --git a/zenoh/src/api/query.rs b/zenoh/src/api/query.rs index 311402b618..e344237087 100644 --- a/zenoh/src/api/query.rs +++ b/zenoh/src/api/query.rs @@ -12,6 +12,19 @@ // ZettaScale Zenoh Team, // +use std::{ + collections::HashMap, + future::{IntoFuture, Ready}, + time::Duration, +}; + +use zenoh_core::{Resolvable, Wait}; +use zenoh_keyexpr::OwnedKeyExpr; +use zenoh_protocol::core::{CongestionControl, ZenohId}; +use zenoh_result::ZResult; + +#[zenoh_macros::unstable] +use super::{builders::sample::SampleBuilderTrait, bytes::OptionZBytes, sample::SourceInfo}; use super::{ builders::sample::{QoSBuilderTrait, ValueBuilderTrait}, bytes::ZBytes, @@ -24,15 +37,6 @@ use super::{ session::Session, value::Value, }; -use std::future::IntoFuture; -use std::{collections::HashMap, future::Ready, time::Duration}; -use zenoh_core::{Resolvable, Wait}; -use zenoh_keyexpr::OwnedKeyExpr; -use zenoh_protocol::core::{CongestionControl, ZenohId}; -use zenoh_result::ZResult; - -#[zenoh_macros::unstable] -use super::{builders::sample::SampleBuilderTrait, bytes::OptionZBytes, sample::SourceInfo}; /// The [`Queryable`](crate::queryable::Queryable)s that should be target of a [`get`](Session::get). pub type QueryTarget = zenoh_protocol::network::request::ext::TargetType; diff --git a/zenoh/src/api/queryable.rs b/zenoh/src/api/queryable.rs index c83b4b6081..e2343811db 100644 --- a/zenoh/src/api/queryable.rs +++ b/zenoh/src/api/queryable.rs @@ -11,27 +11,13 @@ // Contributors: // ZettaScale Zenoh Team, // -use super::{ - builders::sample::{QoSBuilderTrait, SampleBuilder, TimestampBuilderTrait, ValueBuilderTrait}, - bytes::ZBytes, - encoding::Encoding, - handlers::{locked, DefaultHandler, IntoHandler}, - key_expr::KeyExpr, - publication::Priority, - sample::{Locality, QoSBuilder, Sample, SampleKind}, - selector::{Parameters, Selector}, - session::{SessionRef, Undeclarable}, - value::Value, - Id, -}; -use crate::net::primitives::Primitives; -use std::future::IntoFuture; use std::{ fmt, - future::Ready, + future::{IntoFuture, Ready}, ops::{Deref, DerefMut}, sync::Arc, }; + use uhlc::Timestamp; use zenoh_core::{Resolvable, Resolve, Wait}; use zenoh_protocol::{ @@ -40,7 +26,6 @@ use zenoh_protocol::{ zenoh::{self, reply::ReplyBody, Del, Put, ResponseBody}, }; use zenoh_result::ZResult; - #[zenoh_macros::unstable] use { super::{ @@ -50,6 +35,21 @@ use { zenoh_protocol::core::EntityGlobalId, }; +use super::{ + builders::sample::{QoSBuilderTrait, SampleBuilder, TimestampBuilderTrait, ValueBuilderTrait}, + bytes::ZBytes, + encoding::Encoding, + handlers::{locked, DefaultHandler, IntoHandler}, + key_expr::KeyExpr, + publication::Priority, + sample::{Locality, QoSBuilder, Sample, SampleKind}, + selector::{Parameters, Selector}, + session::{SessionRef, Undeclarable}, + value::Value, + Id, +}; +use crate::net::primitives::Primitives; + pub(crate) struct QueryInner { /// The key expression of this Query. pub(crate) key_expr: KeyExpr<'static>, diff --git a/zenoh/src/api/sample.rs b/zenoh/src/api/sample.rs index ca2354db85..2551a2a0d9 100644 --- a/zenoh/src/api/sample.rs +++ b/zenoh/src/api/sample.rs @@ -13,18 +13,20 @@ // //! Sample primitives -use super::{ - builders::sample::QoSBuilderTrait, bytes::ZBytes, encoding::Encoding, key_expr::KeyExpr, - publication::Priority, value::Value, -}; +use std::{convert::TryFrom, fmt}; + #[cfg(feature = "unstable")] use serde::Serialize; -use std::{convert::TryFrom, fmt}; use zenoh_protocol::{ core::{CongestionControl, EntityGlobalId, Timestamp}, network::declare::ext::QoSType, }; +use super::{ + builders::sample::QoSBuilderTrait, bytes::ZBytes, encoding::Encoding, key_expr::KeyExpr, + publication::Priority, value::Value, +}; + pub type SourceSn = u64; /// The locality of samples to be received by subscribers or targeted by publishers. @@ -150,9 +152,10 @@ pub struct SourceInfo { #[test] #[cfg(feature = "unstable")] fn source_info_stack_size() { - use crate::api::sample::{SourceInfo, SourceSn}; use zenoh_protocol::core::ZenohId; + use crate::api::sample::{SourceInfo, SourceSn}; + assert_eq!(std::mem::size_of::(), 16); assert_eq!(std::mem::size_of::>(), 17); assert_eq!(std::mem::size_of::>(), 16); diff --git a/zenoh/src/api/scouting.rs b/zenoh/src/api/scouting.rs index 8e7853a411..8963d37e30 100644 --- a/zenoh/src/api/scouting.rs +++ b/zenoh/src/api/scouting.rs @@ -11,17 +11,25 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::api::handlers::{locked, Callback, DefaultHandler, IntoHandler}; -use crate::net::runtime::{orchestrator::Loop, Runtime}; -use std::future::IntoFuture; -use std::time::Duration; -use std::{fmt, future::Ready, net::SocketAddr, ops::Deref}; +use std::{ + fmt, + future::{IntoFuture, Ready}, + net::SocketAddr, + ops::Deref, + time::Duration, +}; + use tokio::net::UdpSocket; use zenoh_core::{Resolvable, Wait}; use zenoh_protocol::{core::WhatAmIMatcher, scouting::Hello}; use zenoh_result::ZResult; use zenoh_task::TerminatableTask; +use crate::{ + api::handlers::{locked, Callback, DefaultHandler, IntoHandler}, + net::runtime::{orchestrator::Loop, Runtime}, +}; + /// A builder for initializing a [`Scout`]. /// /// # Examples diff --git a/zenoh/src/api/selector.rs b/zenoh/src/api/selector.rs index 59e52edc62..2dc77dc967 100644 --- a/zenoh/src/api/selector.rs +++ b/zenoh/src/api/selector.rs @@ -13,13 +13,13 @@ // //! [Selector](https://github.com/eclipse-zenoh/roadmap/tree/main/rfcs/ALL/Selectors) to issue queries -use super::{key_expr::KeyExpr, queryable::Query}; use std::{ collections::HashMap, convert::TryFrom, ops::{Deref, DerefMut}, str::FromStr, }; + use zenoh_protocol::core::{ key_expr::{keyexpr, OwnedKeyExpr}, Properties, @@ -29,6 +29,8 @@ use zenoh_result::ZResult; #[cfg(feature = "unstable")] use zenoh_util::time_range::TimeRange; +use super::{key_expr::KeyExpr, queryable::Query}; + /// A selector is the combination of a [Key Expression](crate::prelude::KeyExpr), which defines the /// set of keys that are relevant to an operation, and a set of parameters /// with a few intendend uses: diff --git a/zenoh/src/api/session.rs b/zenoh/src/api/session.rs index dea322419c..e442a9e11a 100644 --- a/zenoh/src/api/session.rs +++ b/zenoh/src/api/session.rs @@ -11,33 +11,11 @@ // Contributors: // ZettaScale Zenoh Team, // -use super::{ - admin, - builders::publication::{ - PublicationBuilderDelete, PublicationBuilderPut, PublisherBuilder, SessionDeleteBuilder, - SessionPutBuilder, - }, - bytes::ZBytes, - encoding::Encoding, - handlers::{Callback, DefaultHandler}, - info::SessionInfo, - key_expr::{KeyExpr, KeyExprInner}, - publication::Priority, - query::{ConsolidationMode, GetBuilder, QueryConsolidation, QueryState, QueryTarget, Reply}, - queryable::{Query, QueryInner, QueryableBuilder, QueryableState}, - sample::{DataInfo, DataInfoIntoSample, Locality, QoS, Sample, SampleKind}, - selector::{Selector, TIME_RANGE_KEY}, - subscriber::{SubscriberBuilder, SubscriberState}, - value::Value, - Id, -}; -use crate::net::{primitives::Primitives, routing::dispatcher::face::Face, runtime::Runtime}; -use std::future::IntoFuture; use std::{ collections::HashMap, convert::{TryFrom, TryInto}, fmt, - future::Ready, + future::{IntoFuture, Ready}, ops::Deref, sync::{ atomic::{AtomicU16, Ordering}, @@ -45,6 +23,7 @@ use std::{ }, time::Duration, }; + use tracing::{error, trace, warn}; use uhlc::HLC; use zenoh_buffers::ZBuf; @@ -78,6 +57,26 @@ use zenoh_result::ZResult; use zenoh_shm::api::client_storage::SharedMemoryClientStorage; use zenoh_task::TaskController; +use super::{ + admin, + builders::publication::{ + PublicationBuilderDelete, PublicationBuilderPut, PublisherBuilder, SessionDeleteBuilder, + SessionPutBuilder, + }, + bytes::ZBytes, + encoding::Encoding, + handlers::{Callback, DefaultHandler}, + info::SessionInfo, + key_expr::{KeyExpr, KeyExprInner}, + publication::Priority, + query::{ConsolidationMode, GetBuilder, QueryConsolidation, QueryState, QueryTarget, Reply}, + queryable::{Query, QueryInner, QueryableBuilder, QueryableState}, + sample::{DataInfo, DataInfoIntoSample, Locality, QoS, Sample, SampleKind}, + selector::{Selector, TIME_RANGE_KEY}, + subscriber::{SubscriberBuilder, SubscriberState}, + value::Value, + Id, +}; #[cfg(feature = "unstable")] use super::{ liveliness::{Liveliness, LivelinessTokenState}, @@ -86,6 +85,7 @@ use super::{ query::_REPLY_KEY_EXPR_ANY_SEL_PARAM, sample::SourceInfo, }; +use crate::net::{primitives::Primitives, routing::dispatcher::face::Face, runtime::Runtime}; zconfigurable! { pub(crate) static ref API_DATA_RECEPTION_CHANNEL_SIZE: usize = 256; diff --git a/zenoh/src/api/subscriber.rs b/zenoh/src/api/subscriber.rs index 0c4e21b547..ba345f5116 100644 --- a/zenoh/src/api/subscriber.rs +++ b/zenoh/src/api/subscriber.rs @@ -12,26 +12,26 @@ // ZettaScale Zenoh Team, // -use super::{ - handlers::{locked, Callback, DefaultHandler, IntoHandler}, - key_expr::KeyExpr, - sample::{Locality, Sample}, - session::{SessionRef, Undeclarable}, - Id, -}; -use std::future::IntoFuture; use std::{ fmt, - future::Ready, + future::{IntoFuture, Ready}, ops::{Deref, DerefMut}, sync::Arc, }; + use zenoh_core::{Resolvable, Wait}; +#[cfg(feature = "unstable")] +use zenoh_protocol::core::EntityGlobalId; use zenoh_protocol::{core::Reliability, network::declare::subscriber::ext::SubscriberInfo}; use zenoh_result::ZResult; -#[cfg(feature = "unstable")] -use zenoh_protocol::core::EntityGlobalId; +use super::{ + handlers::{locked, Callback, DefaultHandler, IntoHandler}, + key_expr::KeyExpr, + sample::{Locality, Sample}, + session::{SessionRef, Undeclarable}, + Id, +}; pub(crate) struct SubscriberState { pub(crate) id: Id, diff --git a/zenoh/src/api/time.rs b/zenoh/src/api/time.rs index 5d0d06765d..cbdabe3a7e 100644 --- a/zenoh/src/api/time.rs +++ b/zenoh/src/api/time.rs @@ -12,6 +12,7 @@ // ZettaScale Zenoh Team, // use std::convert::TryFrom; + use zenoh_protocol::core::{Timestamp, TimestampId}; /// Generates a reception [`Timestamp`] with id=0x01. diff --git a/zenoh/src/lib.rs b/zenoh/src/lib.rs index c4247b73da..f6f78e8096 100644 --- a/zenoh/src/lib.rs +++ b/zenoh/src/lib.rs @@ -110,8 +110,7 @@ pub const FEATURES: &str = zenoh_util::concat_enabled_features!( ); // Expose some functions directly to root `zenoh::`` namespace for convenience -pub use crate::api::scouting::scout; -pub use crate::api::session::open; +pub use crate::api::{scouting::scout, session::open}; pub mod prelude; @@ -119,27 +118,24 @@ pub mod prelude; pub mod core { #[allow(deprecated)] pub use zenoh_core::AsyncResolve; - pub use zenoh_core::Resolvable; - pub use zenoh_core::Resolve; #[allow(deprecated)] pub use zenoh_core::SyncResolve; - pub use zenoh_core::Wait; + pub use zenoh_core::{Resolvable, Resolve, Wait}; /// A zenoh error. pub use zenoh_result::Error; /// A zenoh result. pub use zenoh_result::ZResult as Result; - pub use zenoh_util::core::zresult::ErrNo; - pub use zenoh_util::try_init_log_from_env; + pub use zenoh_util::{core::zresult::ErrNo, try_init_log_from_env}; } /// A collection of useful buffers used by zenoh internally and exposed to the user to facilitate /// reading and writing data. pub mod buffers { - pub use zenoh_buffers::buffer::SplitBuffer; - pub use zenoh_buffers::reader::HasReader; - pub use zenoh_buffers::reader::Reader; - pub use zenoh_buffers::ZBufReader; - pub use zenoh_buffers::{ZBuf, ZSlice, ZSliceBuffer}; + pub use zenoh_buffers::{ + buffer::SplitBuffer, + reader::{HasReader, Reader}, + ZBuf, ZBufReader, ZSlice, ZSliceBuffer, + }; } /// [Key expression](https://github.com/eclipse-zenoh/roadmap/blob/main/rfcs/ALL/Key%20Expressions.md) are Zenoh's address space. @@ -174,18 +170,16 @@ pub mod buffers { /// as the [`keformat`] and [`kewrite`] macros will be able to tell you if you're attempting to set fields of the format that do not exist. pub mod key_expr { pub mod keyexpr_tree { - pub use zenoh_keyexpr::keyexpr_tree::impls::KeyedSetProvider; pub use zenoh_keyexpr::keyexpr_tree::{ - support::NonWild, support::UnknownWildness, KeBoxTree, + impls::KeyedSetProvider, + support::{NonWild, UnknownWildness}, + IKeyExprTree, IKeyExprTreeMut, KeBoxTree, }; - pub use zenoh_keyexpr::keyexpr_tree::{IKeyExprTree, IKeyExprTreeMut}; } - pub use crate::api::key_expr::KeyExpr; - pub use crate::api::key_expr::KeyExprUndeclaration; - pub use zenoh_keyexpr::keyexpr; - pub use zenoh_keyexpr::OwnedKeyExpr; - pub use zenoh_keyexpr::SetIntersectionLevel; + pub use zenoh_keyexpr::{keyexpr, OwnedKeyExpr, SetIntersectionLevel}; pub use zenoh_macros::{kedefine, keformat, kewrite}; + + pub use crate::api::key_expr::{KeyExpr, KeyExprUndeclaration}; // keyexpr format macro support pub mod format { pub use zenoh_keyexpr::format::*; @@ -197,48 +191,36 @@ pub mod key_expr { /// Zenoh [`Session`](crate::session::Session) and associated types pub mod session { - pub use crate::api::builders::publication::SessionDeleteBuilder; - pub use crate::api::builders::publication::SessionPutBuilder; #[zenoh_macros::unstable] #[doc(hidden)] pub use crate::api::session::init; - pub use crate::api::session::open; #[zenoh_macros::unstable] #[doc(hidden)] pub use crate::api::session::InitBuilder; - pub use crate::api::session::OpenBuilder; - pub use crate::api::session::Session; - pub use crate::api::session::SessionDeclarations; - pub use crate::api::session::SessionRef; - pub use crate::api::session::Undeclarable; + pub use crate::api::{ + builders::publication::{SessionDeleteBuilder, SessionPutBuilder}, + session::{open, OpenBuilder, Session, SessionDeclarations, SessionRef, Undeclarable}, + }; } /// Tools to access information about the current zenoh [`Session`](crate::Session). pub mod info { - pub use crate::api::info::PeersZidBuilder; - pub use crate::api::info::RoutersZidBuilder; - pub use crate::api::info::SessionInfo; - pub use crate::api::info::ZidBuilder; + pub use crate::api::info::{PeersZidBuilder, RoutersZidBuilder, SessionInfo, ZidBuilder}; } /// Sample primitives pub mod sample { - pub use crate::api::builders::sample::QoSBuilderTrait; - pub use crate::api::builders::sample::SampleBuilder; - pub use crate::api::builders::sample::SampleBuilderAny; - pub use crate::api::builders::sample::SampleBuilderDelete; - pub use crate::api::builders::sample::SampleBuilderPut; - pub use crate::api::builders::sample::SampleBuilderTrait; - pub use crate::api::builders::sample::TimestampBuilderTrait; - pub use crate::api::builders::sample::ValueBuilderTrait; #[zenoh_macros::unstable] pub use crate::api::sample::Locality; - pub use crate::api::sample::Sample; - pub use crate::api::sample::SampleFields; - pub use crate::api::sample::SampleKind; #[zenoh_macros::unstable] pub use crate::api::sample::SourceInfo; - pub use crate::api::sample::SourceSn; + pub use crate::api::{ + builders::sample::{ + QoSBuilderTrait, SampleBuilder, SampleBuilderAny, SampleBuilderDelete, + SampleBuilderPut, SampleBuilderTrait, TimestampBuilderTrait, ValueBuilderTrait, + }, + sample::{Sample, SampleFields, SampleKind, SourceSn}, + }; } /// Value primitives @@ -253,42 +235,32 @@ pub mod encoding { /// Payload primitives pub mod bytes { - pub use crate::api::bytes::Deserialize; - pub use crate::api::bytes::OptionZBytes; - pub use crate::api::bytes::Serialize; - pub use crate::api::bytes::StringOrBase64; - pub use crate::api::bytes::ZBytes; - pub use crate::api::bytes::ZBytesIterator; - pub use crate::api::bytes::ZBytesReader; - pub use crate::api::bytes::ZBytesWriter; - pub use crate::api::bytes::ZDeserializeError; - pub use crate::api::bytes::ZSerde; + pub use crate::api::bytes::{ + Deserialize, OptionZBytes, Serialize, StringOrBase64, ZBytes, ZBytesIterator, ZBytesReader, + ZBytesWriter, ZDeserializeError, ZSerde, + }; } /// [Selector](https://github.com/eclipse-zenoh/roadmap/tree/main/rfcs/ALL/Selectors) to issue queries pub mod selector { - pub use crate::api::selector::Parameters; - pub use crate::api::selector::Selector; - pub use crate::api::selector::TIME_RANGE_KEY; pub use zenoh_protocol::core::Properties; pub use zenoh_util::time_range::{TimeBound, TimeExpr, TimeRange}; + + pub use crate::api::selector::{Parameters, Selector, TIME_RANGE_KEY}; } /// Subscribing primitives pub mod subscriber { - pub use crate::api::subscriber::FlumeSubscriber; - pub use crate::api::subscriber::Subscriber; - pub use crate::api::subscriber::SubscriberBuilder; /// The kind of reliability. pub use zenoh_protocol::core::Reliability; + + pub use crate::api::subscriber::{FlumeSubscriber, Subscriber, SubscriberBuilder}; } /// Publishing primitives pub mod publication { - pub use crate::api::builders::publication::PublicationBuilderDelete; - pub use crate::api::builders::publication::PublicationBuilderPut; - pub use crate::api::builders::publication::PublisherBuilder; - pub use crate::api::builders::publication::PublisherDeleteBuilder; + pub use zenoh_protocol::core::CongestionControl; + #[zenoh_macros::unstable] pub use crate::api::publication::MatchingListener; #[zenoh_macros::unstable] @@ -297,88 +269,81 @@ pub mod publication { pub use crate::api::publication::MatchingListenerUndeclaration; #[zenoh_macros::unstable] pub use crate::api::publication::MatchingStatus; - pub use crate::api::publication::Priority; - pub use crate::api::publication::Publisher; #[zenoh_macros::unstable] pub use crate::api::publication::PublisherDeclarations; #[zenoh_macros::unstable] pub use crate::api::publication::PublisherRef; - pub use crate::api::publication::PublisherUndeclaration; - pub use zenoh_protocol::core::CongestionControl; + pub use crate::api::{ + builders::publication::{ + PublicationBuilderDelete, PublicationBuilderPut, PublisherBuilder, + PublisherDeleteBuilder, + }, + publication::{Priority, Publisher, PublisherUndeclaration}, + }; } /// Query primitives pub mod query { - pub use crate::api::query::GetBuilder; - pub use crate::api::query::Reply; #[zenoh_macros::unstable] pub use crate::api::query::ReplyKeyExpr; #[zenoh_macros::unstable] pub use crate::api::query::REPLY_KEY_EXPR_ANY_SEL_PARAM; - pub use crate::api::query::{ConsolidationMode, QueryConsolidation, QueryTarget}; + pub use crate::api::query::{ + ConsolidationMode, GetBuilder, QueryConsolidation, QueryTarget, Reply, + }; } /// Queryable primitives pub mod queryable { - pub use crate::api::queryable::Query; - pub use crate::api::queryable::Queryable; - pub use crate::api::queryable::QueryableBuilder; - pub use crate::api::queryable::QueryableUndeclaration; - pub use crate::api::queryable::ReplyBuilder; - pub use crate::api::queryable::ReplyBuilderDelete; - pub use crate::api::queryable::ReplyBuilderPut; - pub use crate::api::queryable::ReplyErrBuilder; #[zenoh_macros::unstable] pub use crate::api::queryable::ReplySample; + pub use crate::api::queryable::{ + Query, Queryable, QueryableBuilder, QueryableUndeclaration, ReplyBuilder, + ReplyBuilderDelete, ReplyBuilderPut, ReplyErrBuilder, + }; } /// Callback handler trait pub mod handlers { - pub use crate::api::handlers::locked; - pub use crate::api::handlers::Callback; - pub use crate::api::handlers::CallbackDrop; - pub use crate::api::handlers::DefaultHandler; - pub use crate::api::handlers::FifoChannel; - pub use crate::api::handlers::IntoHandler; - pub use crate::api::handlers::RingChannel; - pub use crate::api::handlers::RingChannelHandler; + pub use crate::api::handlers::{ + locked, Callback, CallbackDrop, DefaultHandler, FifoChannel, IntoHandler, RingChannel, + RingChannelHandler, + }; } /// Scouting primitives pub mod scouting { - pub use crate::api::scouting::scout; - pub use crate::api::scouting::Scout; - pub use crate::api::scouting::ScoutBuilder; /// Constants and helpers for zenoh `whatami` flags. pub use zenoh_protocol::core::WhatAmI; /// A zenoh Hello message. pub use zenoh_protocol::scouting::Hello; + + pub use crate::api::scouting::{scout, Scout, ScoutBuilder}; } /// Liveliness primitives #[cfg(feature = "unstable")] pub mod liveliness { - pub use crate::api::liveliness::Liveliness; - pub use crate::api::liveliness::LivelinessGetBuilder; - pub use crate::api::liveliness::LivelinessSubscriberBuilder; - pub use crate::api::liveliness::LivelinessToken; - pub use crate::api::liveliness::LivelinessTokenBuilder; - pub use crate::api::liveliness::LivelinessTokenUndeclaration; + pub use crate::api::liveliness::{ + Liveliness, LivelinessGetBuilder, LivelinessSubscriberBuilder, LivelinessToken, + LivelinessTokenBuilder, LivelinessTokenUndeclaration, + }; } /// Timestamp support pub mod time { - pub use crate::api::time::new_reception_timestamp; pub use zenoh_protocol::core::{Timestamp, TimestampId, NTP64}; + + pub use crate::api::time::new_reception_timestamp; } /// Initialize a Session with an existing Runtime. /// This operation is used by the plugins to share the same Runtime as the router. #[doc(hidden)] pub mod runtime { - pub use crate::net::runtime::RuntimeBuilder; - pub use crate::net::runtime::{AdminSpace, Runtime}; pub use zenoh_runtime::ZRuntime; + + pub use crate::net::runtime::{AdminSpace, Runtime, RuntimeBuilder}; } /// Configuration to pass to [`open`](crate::session::open) and [`scout`](crate::scouting::scout) functions and associated constants @@ -393,42 +358,39 @@ pub mod config { #[doc(hidden)] #[cfg(all(feature = "unstable", feature = "plugins"))] pub mod plugins { - pub use crate::api::plugins::PluginsManager; - pub use crate::api::plugins::Response; - pub use crate::api::plugins::RunningPlugin; - pub use crate::api::plugins::PLUGIN_PREFIX; - pub use crate::api::plugins::{RunningPluginTrait, ZenohPlugin}; + pub use crate::api::plugins::{ + PluginsManager, Response, RunningPlugin, RunningPluginTrait, ZenohPlugin, PLUGIN_PREFIX, + }; } #[doc(hidden)] pub mod internal { - pub use zenoh_core::zasync_executor_init; - pub use zenoh_core::zerror; - pub use zenoh_core::zlock; - pub use zenoh_core::ztimeout; + pub use zenoh_core::{zasync_executor_init, zerror, zlock, ztimeout}; pub use zenoh_result::bail; pub use zenoh_sync::Condition; - pub use zenoh_task::TaskController; - pub use zenoh_task::TerminatableTask; - pub use zenoh_util::core::ResolveFuture; - pub use zenoh_util::LibLoader; - pub use zenoh_util::{zenoh_home, Timed, TimedEvent, Timer, ZENOH_HOME_ENV_VAR}; + pub use zenoh_task::{TaskController, TerminatableTask}; + pub use zenoh_util::{ + core::ResolveFuture, zenoh_home, LibLoader, Timed, TimedEvent, Timer, ZENOH_HOME_ENV_VAR, + }; } #[cfg(all(feature = "unstable", feature = "shared-memory"))] pub mod shm { - pub use zenoh_shm::api::client_storage::SharedMemoryClientStorage; - pub use zenoh_shm::api::provider::shared_memory_provider::{BlockOn, GarbageCollect}; - pub use zenoh_shm::api::provider::shared_memory_provider::{Deallocate, Defragment}; - pub use zenoh_shm::api::provider::types::AllocAlignment; - pub use zenoh_shm::api::provider::types::MemoryLayout; - pub use zenoh_shm::api::slice::zsliceshm::{zsliceshm, ZSliceShm}; - pub use zenoh_shm::api::slice::zsliceshmmut::{zsliceshmmut, ZSliceShmMut}; pub use zenoh_shm::api::{ + client_storage::SharedMemoryClientStorage, protocol_implementations::posix::{ posix_shared_memory_provider_backend::PosixSharedMemoryProviderBackend, protocol_id::POSIX_PROTOCOL_ID, }, - provider::shared_memory_provider::SharedMemoryProviderBuilder, + provider::{ + shared_memory_provider::{ + BlockOn, Deallocate, Defragment, GarbageCollect, SharedMemoryProviderBuilder, + }, + types::{AllocAlignment, MemoryLayout}, + }, + slice::{ + zsliceshm::{zsliceshm, ZSliceShm}, + zsliceshmmut::{zsliceshmmut, ZSliceShmMut}, + }, }; } diff --git a/zenoh/src/net/codec/linkstate.rs b/zenoh/src/net/codec/linkstate.rs index 4954062a3d..a66163728c 100644 --- a/zenoh/src/net/codec/linkstate.rs +++ b/zenoh/src/net/codec/linkstate.rs @@ -11,12 +11,8 @@ // Contributors: // ZettaScale Zenoh Team, // -use super::Zenoh080Routing; -use crate::net::protocol::{ - linkstate, - linkstate::{LinkState, LinkStateList}, -}; use core::convert::TryFrom; + use zenoh_buffers::{ reader::{DidntRead, Reader}, writer::{DidntWrite, Writer}, @@ -27,6 +23,12 @@ use zenoh_protocol::{ core::{Locator, WhatAmI, ZenohId}, }; +use super::Zenoh080Routing; +use crate::net::protocol::{ + linkstate, + linkstate::{LinkState, LinkStateList}, +}; + // LinkState impl WCodec<&LinkState, &mut W> for Zenoh080Routing where diff --git a/zenoh/src/net/primitives/demux.rs b/zenoh/src/net/primitives/demux.rs index e58e01a1b5..b400d1a254 100644 --- a/zenoh/src/net/primitives/demux.rs +++ b/zenoh/src/net/primitives/demux.rs @@ -11,18 +11,19 @@ // Contributors: // ZettaScale Zenoh Team, // +use std::{any::Any, sync::Arc}; + +use zenoh_link::Link; +use zenoh_protocol::network::{NetworkBody, NetworkMessage}; +use zenoh_result::ZResult; +use zenoh_transport::{unicast::TransportUnicast, TransportPeerEventHandler}; + use super::Primitives; use crate::net::routing::{ dispatcher::face::Face, interceptor::{InterceptorTrait, InterceptorsChain}, RoutingContext, }; -use std::{any::Any, sync::Arc}; -use zenoh_link::Link; -use zenoh_protocol::network::{NetworkBody, NetworkMessage}; -use zenoh_result::ZResult; -use zenoh_transport::unicast::TransportUnicast; -use zenoh_transport::TransportPeerEventHandler; pub struct DeMux { face: Face, diff --git a/zenoh/src/net/primitives/mux.rs b/zenoh/src/net/primitives/mux.rs index 8589fab518..df292b4315 100644 --- a/zenoh/src/net/primitives/mux.rs +++ b/zenoh/src/net/primitives/mux.rs @@ -11,19 +11,21 @@ // Contributors: // ZettaScale Zenoh Team, // -use super::{EPrimitives, Primitives}; -use crate::net::routing::{ - dispatcher::face::{Face, WeakFace}, - interceptor::{InterceptorTrait, InterceptorsChain}, - RoutingContext, -}; use std::sync::OnceLock; + use zenoh_protocol::network::{ interest::Interest, Declare, NetworkBody, NetworkMessage, Push, Request, Response, ResponseFinal, }; use zenoh_transport::{multicast::TransportMulticast, unicast::TransportUnicast}; +use super::{EPrimitives, Primitives}; +use crate::net::routing::{ + dispatcher::face::{Face, WeakFace}, + interceptor::{InterceptorTrait, InterceptorsChain}, + RoutingContext, +}; + pub struct Mux { pub handler: TransportUnicast, pub(crate) face: OnceLock, diff --git a/zenoh/src/net/routing/dispatcher/face.rs b/zenoh/src/net/routing/dispatcher/face.rs index 06d55de920..c5129f76e2 100644 --- a/zenoh/src/net/routing/dispatcher/face.rs +++ b/zenoh/src/net/routing/dispatcher/face.rs @@ -11,21 +11,18 @@ // Contributors: // ZettaScale Zenoh Team, // -use super::super::router::*; -use super::tables::TablesLock; -use super::{resource::*, tables}; -use crate::api::key_expr::KeyExpr; -use crate::net::primitives::{McastMux, Mux, Primitives}; -use crate::net::routing::interceptor::{InterceptorTrait, InterceptorsChain}; -use std::any::Any; -use std::collections::HashMap; -use std::fmt; -use std::sync::{Arc, Weak}; +use std::{ + any::Any, + collections::HashMap, + fmt, + sync::{Arc, Weak}, +}; + use tokio_util::sync::CancellationToken; -use zenoh_protocol::zenoh::RequestBody; use zenoh_protocol::{ core::{ExprId, WhatAmI, ZenohId}, network::{Mapping, Push, Request, RequestId, Response, ResponseFinal}, + zenoh::RequestBody, }; use zenoh_sync::get_mut_unchecked; use zenoh_task::TaskController; @@ -33,6 +30,15 @@ use zenoh_transport::multicast::TransportMulticast; #[cfg(feature = "stats")] use zenoh_transport::stats::TransportStats; +use super::{super::router::*, resource::*, tables, tables::TablesLock}; +use crate::{ + api::key_expr::KeyExpr, + net::{ + primitives::{McastMux, Mux, Primitives}, + routing::interceptor::{InterceptorTrait, InterceptorsChain}, + }, +}; + pub struct FaceState { pub(crate) id: usize, pub(crate) zid: ZenohId, diff --git a/zenoh/src/net/routing/dispatcher/pubsub.rs b/zenoh/src/net/routing/dispatcher/pubsub.rs index fe2274ed64..94c6f7b1a6 100644 --- a/zenoh/src/net/routing/dispatcher/pubsub.rs +++ b/zenoh/src/net/routing/dispatcher/pubsub.rs @@ -11,23 +11,26 @@ // Contributors: // ZettaScale Zenoh Team, // -use super::face::FaceState; -use super::resource::{DataRoutes, Direction, Resource}; -use super::tables::{NodeId, Route, RoutingExpr, Tables, TablesLock}; -use crate::net::routing::hat::HatTrait; -use std::collections::HashMap; -use std::sync::Arc; +use std::{collections::HashMap, sync::Arc}; + use zenoh_core::zread; -use zenoh_protocol::core::key_expr::keyexpr; -use zenoh_protocol::network::declare::subscriber::ext::SubscriberInfo; -use zenoh_protocol::network::declare::SubscriberId; use zenoh_protocol::{ - core::{WhatAmI, WireExpr}, - network::{declare::ext, Push}, + core::{key_expr::keyexpr, WhatAmI, WireExpr}, + network::{ + declare::{ext, subscriber::ext::SubscriberInfo, SubscriberId}, + Push, + }, zenoh::PushBody, }; use zenoh_sync::get_mut_unchecked; +use super::{ + face::FaceState, + resource::{DataRoutes, Direction, Resource}, + tables::{NodeId, Route, RoutingExpr, Tables, TablesLock}, +}; +use crate::net::routing::hat::HatTrait; + pub(crate) fn declare_subscription( hat_code: &(dyn HatTrait + Send + Sync), tables: &TablesLock, diff --git a/zenoh/src/net/routing/dispatcher/queries.rs b/zenoh/src/net/routing/dispatcher/queries.rs index cd17f1339f..2bbc924e0b 100644 --- a/zenoh/src/net/routing/dispatcher/queries.rs +++ b/zenoh/src/net/routing/dispatcher/queries.rs @@ -11,16 +11,13 @@ // Contributors: // ZettaScale Zenoh Team, // -use super::face::FaceState; -use super::resource::{QueryRoute, QueryRoutes, QueryTargetQablSet, Resource}; -use super::tables::NodeId; -use super::tables::{RoutingExpr, Tables, TablesLock}; -use crate::net::routing::hat::HatTrait; -use crate::net::routing::RoutingContext; +use std::{ + collections::HashMap, + sync::{Arc, Weak}, + time::Duration, +}; + use async_trait::async_trait; -use std::collections::HashMap; -use std::sync::{Arc, Weak}; -use std::time::Duration; use tokio_util::sync::CancellationToken; use zenoh_config::WhatAmI; use zenoh_protocol::{ @@ -35,6 +32,13 @@ use zenoh_protocol::{ use zenoh_sync::get_mut_unchecked; use zenoh_util::Timed; +use super::{ + face::FaceState, + resource::{QueryRoute, QueryRoutes, QueryTargetQablSet, Resource}, + tables::{NodeId, RoutingExpr, Tables, TablesLock}, +}; +use crate::net::routing::{hat::HatTrait, RoutingContext}; + pub(crate) struct Query { src_face: Arc, src_qid: RequestId, diff --git a/zenoh/src/net/routing/dispatcher/resource.rs b/zenoh/src/net/routing/dispatcher/resource.rs index bc0aecb9bb..d8765e16ae 100644 --- a/zenoh/src/net/routing/dispatcher/resource.rs +++ b/zenoh/src/net/routing/dispatcher/resource.rs @@ -11,17 +11,15 @@ // Contributors: // ZettaScale Zenoh Team, // -use super::face::FaceState; -use super::tables::{Tables, TablesLock}; -use crate::net::routing::dispatcher::face::Face; -use crate::net::routing::RoutingContext; -use std::any::Any; -use std::collections::HashMap; -use std::convert::TryInto; -use std::hash::{Hash, Hasher}; -use std::sync::{Arc, Weak}; +use std::{ + any::Any, + collections::HashMap, + convert::TryInto, + hash::{Hash, Hasher}, + sync::{Arc, Weak}, +}; + use zenoh_config::WhatAmI; -use zenoh_protocol::network::RequestId; use zenoh_protocol::{ core::{key_expr::keyexpr, ExprId, WireExpr}, network::{ @@ -29,11 +27,17 @@ use zenoh_protocol::{ ext, queryable::ext::QueryableInfoType, subscriber::ext::SubscriberInfo, Declare, DeclareBody, DeclareKeyExpr, }, - Mapping, + Mapping, RequestId, }, }; use zenoh_sync::get_mut_unchecked; +use super::{ + face::FaceState, + tables::{Tables, TablesLock}, +}; +use crate::net::routing::{dispatcher::face::Face, RoutingContext}; + pub(crate) type NodeId = u16; pub(crate) type Direction = (Arc, WireExpr<'static>, NodeId); diff --git a/zenoh/src/net/routing/dispatcher/tables.rs b/zenoh/src/net/routing/dispatcher/tables.rs index 72cee0b452..2853cc5a9f 100644 --- a/zenoh/src/net/routing/dispatcher/tables.rs +++ b/zenoh/src/net/routing/dispatcher/tables.rs @@ -11,27 +11,30 @@ // Contributors: // ZettaScale Zenoh Team, // -use super::face::FaceState; -pub use super::pubsub::*; -pub use super::queries::*; -pub use super::resource::*; -use crate::net::routing::hat; -use crate::net::routing::hat::HatTrait; -use crate::net::routing::interceptor::interceptor_factories; -use crate::net::routing::interceptor::InterceptorFactory; -use std::any::Any; -use std::collections::HashMap; -use std::sync::{Arc, Weak}; -use std::sync::{Mutex, RwLock}; -use std::time::Duration; +use std::{ + any::Any, + collections::HashMap, + sync::{Arc, Mutex, RwLock, Weak}, + time::Duration, +}; + use uhlc::HLC; -use zenoh_config::unwrap_or_default; -use zenoh_config::Config; -use zenoh_protocol::core::{ExprId, WhatAmI, ZenohId}; -use zenoh_protocol::network::Mapping; +use zenoh_config::{unwrap_or_default, Config}; +use zenoh_protocol::{ + core::{ExprId, WhatAmI, ZenohId}, + network::Mapping, +}; use zenoh_result::ZResult; use zenoh_sync::get_mut_unchecked; +use super::face::FaceState; +pub use super::{pubsub::*, queries::*, resource::*}; +use crate::net::routing::{ + hat, + hat::HatTrait, + interceptor::{interceptor_factories, InterceptorFactory}, +}; + pub(crate) struct RoutingExpr<'a> { pub(crate) prefix: &'a Arc, pub(crate) suffix: &'a str, diff --git a/zenoh/src/net/routing/hat/client/mod.rs b/zenoh/src/net/routing/hat/client/mod.rs index 6ca0af1e17..3b4e7c7103 100644 --- a/zenoh/src/net/routing/hat/client/mod.rs +++ b/zenoh/src/net/routing/hat/client/mod.rs @@ -17,14 +17,21 @@ //! This module is intended for Zenoh's internal use. //! //! [Click here for Zenoh's documentation](../zenoh/index.html) -use crate::{ - net::routing::{ - dispatcher::face::Face, - router::{compute_data_routes, compute_query_routes, RoutesIndexes}, - }, - net::runtime::Runtime, +use std::{ + any::Any, + collections::HashMap, + sync::{atomic::AtomicU32, Arc}, }; +use zenoh_config::WhatAmI; +use zenoh_protocol::network::{ + declare::{queryable::ext::QueryableInfoType, QueryableId, SubscriberId}, + Oam, +}; +use zenoh_result::ZResult; +use zenoh_sync::get_mut_unchecked; +use zenoh_transport::unicast::TransportUnicast; + use self::{ pubsub::{pubsub_new_face, undeclare_client_subscription}, queries::{queries_new_face, undeclare_client_queryable}, @@ -36,19 +43,13 @@ use super::{ }, HatBaseTrait, HatTrait, }; -use std::{ - any::Any, - collections::HashMap, - sync::{atomic::AtomicU32, Arc}, -}; -use zenoh_config::WhatAmI; -use zenoh_protocol::network::declare::{ - queryable::ext::QueryableInfoType, QueryableId, SubscriberId, +use crate::net::{ + routing::{ + dispatcher::face::Face, + router::{compute_data_routes, compute_query_routes, RoutesIndexes}, + }, + runtime::Runtime, }; -use zenoh_protocol::network::Oam; -use zenoh_result::ZResult; -use zenoh_sync::get_mut_unchecked; -use zenoh_transport::unicast::TransportUnicast; mod pubsub; mod queries; diff --git a/zenoh/src/net/routing/hat/client/pubsub.rs b/zenoh/src/net/routing/hat/client/pubsub.rs index dd35cf24c8..3334fbfb14 100644 --- a/zenoh/src/net/routing/hat/client/pubsub.rs +++ b/zenoh/src/net/routing/hat/client/pubsub.rs @@ -11,30 +11,33 @@ // Contributors: // ZettaScale Zenoh Team, // -use super::{face_hat, face_hat_mut, get_routes_entries}; -use super::{HatCode, HatFace}; -use crate::net::routing::dispatcher::face::FaceState; -use crate::net::routing::dispatcher::resource::{NodeId, Resource, SessionContext}; -use crate::net::routing::dispatcher::tables::Tables; -use crate::net::routing::dispatcher::tables::{Route, RoutingExpr}; -use crate::net::routing::hat::{HatPubSubTrait, Sources}; -use crate::net::routing::router::RoutesIndexes; -use crate::net::routing::{RoutingContext, PREFIX_LIVELINESS}; -use std::borrow::Cow; -use std::collections::HashMap; -use std::sync::atomic::Ordering; -use std::sync::Arc; -use zenoh_protocol::core::key_expr::OwnedKeyExpr; -use zenoh_protocol::network::declare::SubscriberId; +use std::{ + borrow::Cow, + collections::HashMap, + sync::{atomic::Ordering, Arc}, +}; + use zenoh_protocol::{ - core::{Reliability, WhatAmI}, + core::{key_expr::OwnedKeyExpr, Reliability, WhatAmI}, network::declare::{ common::ext::WireExprType, ext, subscriber::ext::SubscriberInfo, Declare, DeclareBody, - DeclareSubscriber, UndeclareSubscriber, + DeclareSubscriber, SubscriberId, UndeclareSubscriber, }, }; use zenoh_sync::get_mut_unchecked; +use super::{face_hat, face_hat_mut, get_routes_entries, HatCode, HatFace}; +use crate::net::routing::{ + dispatcher::{ + face::FaceState, + resource::{NodeId, Resource, SessionContext}, + tables::{Route, RoutingExpr, Tables}, + }, + hat::{HatPubSubTrait, Sources}, + router::RoutesIndexes, + RoutingContext, PREFIX_LIVELINESS, +}; + #[inline] fn propagate_simple_subscription_to( _tables: &mut Tables, diff --git a/zenoh/src/net/routing/hat/client/queries.rs b/zenoh/src/net/routing/hat/client/queries.rs index 777198ed95..c915d788a9 100644 --- a/zenoh/src/net/routing/hat/client/queries.rs +++ b/zenoh/src/net/routing/hat/client/queries.rs @@ -11,33 +11,41 @@ // Contributors: // ZettaScale Zenoh Team, // -use super::{face_hat, face_hat_mut, get_routes_entries}; -use super::{HatCode, HatFace}; -use crate::net::routing::dispatcher::face::FaceState; -use crate::net::routing::dispatcher::resource::{NodeId, Resource, SessionContext}; -use crate::net::routing::dispatcher::tables::Tables; -use crate::net::routing::dispatcher::tables::{QueryTargetQabl, QueryTargetQablSet, RoutingExpr}; -use crate::net::routing::hat::{HatQueriesTrait, Sources}; -use crate::net::routing::router::RoutesIndexes; -use crate::net::routing::{RoutingContext, PREFIX_LIVELINESS}; +use std::{ + borrow::Cow, + collections::HashMap, + sync::{atomic::Ordering, Arc}, +}; + use ordered_float::OrderedFloat; -use std::borrow::Cow; -use std::collections::HashMap; -use std::sync::atomic::Ordering; -use std::sync::Arc; use zenoh_buffers::ZBuf; -use zenoh_protocol::core::key_expr::include::{Includer, DEFAULT_INCLUDER}; -use zenoh_protocol::core::key_expr::OwnedKeyExpr; -use zenoh_protocol::network::declare::QueryableId; use zenoh_protocol::{ - core::{WhatAmI, WireExpr}, + core::{ + key_expr::{ + include::{Includer, DEFAULT_INCLUDER}, + OwnedKeyExpr, + }, + WhatAmI, WireExpr, + }, network::declare::{ common::ext::WireExprType, ext, queryable::ext::QueryableInfoType, Declare, DeclareBody, - DeclareQueryable, UndeclareQueryable, + DeclareQueryable, QueryableId, UndeclareQueryable, }, }; use zenoh_sync::get_mut_unchecked; +use super::{face_hat, face_hat_mut, get_routes_entries, HatCode, HatFace}; +use crate::net::routing::{ + dispatcher::{ + face::FaceState, + resource::{NodeId, Resource, SessionContext}, + tables::{QueryTargetQabl, QueryTargetQablSet, RoutingExpr, Tables}, + }, + hat::{HatQueriesTrait, Sources}, + router::RoutesIndexes, + RoutingContext, PREFIX_LIVELINESS, +}; + #[inline] fn merge_qabl_infos(mut this: QueryableInfoType, info: &QueryableInfoType) -> QueryableInfoType { this.complete = this.complete || info.complete; diff --git a/zenoh/src/net/routing/hat/linkstate_peer/mod.rs b/zenoh/src/net/routing/hat/linkstate_peer/mod.rs index beb2d6ef68..e76f53a0dd 100644 --- a/zenoh/src/net/routing/hat/linkstate_peer/mod.rs +++ b/zenoh/src/net/routing/hat/linkstate_peer/mod.rs @@ -17,36 +17,13 @@ //! This module is intended for Zenoh's internal use. //! //! [Click here for Zenoh's documentation](../zenoh/index.html) -use self::{ - network::Network, - pubsub::{pubsub_new_face, pubsub_remove_node, undeclare_client_subscription}, - queries::{queries_new_face, queries_remove_node, undeclare_client_queryable}, -}; -use super::{ - super::dispatcher::{ - face::FaceState, - tables::{NodeId, Resource, RoutingExpr, Tables, TablesLock}, - }, - HatBaseTrait, HatTrait, -}; -use crate::{ - net::runtime::Runtime, - net::{ - codec::Zenoh080Routing, - protocol::linkstate::LinkStateList, - routing::{ - dispatcher::face::Face, - hat::TREES_COMPUTATION_DELAY_MS, - router::{compute_data_routes, compute_query_routes, RoutesIndexes}, - }, - }, -}; use std::{ any::Any, collections::{HashMap, HashSet}, sync::{atomic::AtomicU32, Arc}, time::Duration, }; + use zenoh_config::{unwrap_or_default, ModeDependent, WhatAmI, WhatAmIMatcher, ZenohId}; use zenoh_protocol::{ common::ZExtBody, @@ -61,6 +38,29 @@ use zenoh_sync::get_mut_unchecked; use zenoh_task::TerminatableTask; use zenoh_transport::unicast::TransportUnicast; +use self::{ + network::Network, + pubsub::{pubsub_new_face, pubsub_remove_node, undeclare_client_subscription}, + queries::{queries_new_face, queries_remove_node, undeclare_client_queryable}, +}; +use super::{ + super::dispatcher::{ + face::FaceState, + tables::{NodeId, Resource, RoutingExpr, Tables, TablesLock}, + }, + HatBaseTrait, HatTrait, +}; +use crate::net::{ + codec::Zenoh080Routing, + protocol::linkstate::LinkStateList, + routing::{ + dispatcher::face::Face, + hat::TREES_COMPUTATION_DELAY_MS, + router::{compute_data_routes, compute_query_routes, RoutesIndexes}, + }, + runtime::Runtime, +}; + mod network; mod pubsub; mod queries; diff --git a/zenoh/src/net/routing/hat/linkstate_peer/network.rs b/zenoh/src/net/routing/hat/linkstate_peer/network.rs index 9c8e0c8860..2a26b1f583 100644 --- a/zenoh/src/net/routing/hat/linkstate_peer/network.rs +++ b/zenoh/src/net/routing/hat/linkstate_peer/network.rs @@ -11,26 +11,34 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::net::codec::Zenoh080Routing; -use crate::net::protocol::linkstate::{LinkState, LinkStateList}; -use crate::net::routing::dispatcher::tables::NodeId; -use crate::net::runtime::Runtime; -use crate::net::runtime::WeakRuntime; -use petgraph::graph::NodeIndex; -use petgraph::visit::{VisitMap, Visitable}; -use rand::Rng; use std::convert::TryInto; + +use petgraph::{ + graph::NodeIndex, + visit::{VisitMap, Visitable}, +}; +use rand::Rng; use vec_map::VecMap; -use zenoh_buffers::writer::{DidntWrite, HasWriter}; -use zenoh_buffers::ZBuf; +use zenoh_buffers::{ + writer::{DidntWrite, HasWriter}, + ZBuf, +}; use zenoh_codec::WCodec; use zenoh_link::Locator; -use zenoh_protocol::common::ZExtBody; -use zenoh_protocol::core::{WhatAmI, WhatAmIMatcher, ZenohId}; -use zenoh_protocol::network::oam::id::OAM_LINKSTATE; -use zenoh_protocol::network::{oam, NetworkBody, NetworkMessage, Oam}; +use zenoh_protocol::{ + common::ZExtBody, + core::{WhatAmI, WhatAmIMatcher, ZenohId}, + network::{oam, oam::id::OAM_LINKSTATE, NetworkBody, NetworkMessage, Oam}, +}; use zenoh_transport::unicast::TransportUnicast; +use crate::net::{ + codec::Zenoh080Routing, + protocol::linkstate::{LinkState, LinkStateList}, + routing::dispatcher::tables::NodeId, + runtime::{Runtime, WeakRuntime}, +}; + #[derive(Clone)] struct Details { zid: bool, diff --git a/zenoh/src/net/routing/hat/linkstate_peer/pubsub.rs b/zenoh/src/net/routing/hat/linkstate_peer/pubsub.rs index 2c1cbb23e7..e5f7da81f7 100644 --- a/zenoh/src/net/routing/hat/linkstate_peer/pubsub.rs +++ b/zenoh/src/net/routing/hat/linkstate_peer/pubsub.rs @@ -11,33 +11,38 @@ // Contributors: // ZettaScale Zenoh Team, // -use super::network::Network; -use super::{face_hat, face_hat_mut, get_routes_entries, hat, hat_mut, res_hat, res_hat_mut}; -use super::{get_peer, HatCode, HatContext, HatFace, HatTables}; -use crate::net::routing::dispatcher::face::FaceState; -use crate::net::routing::dispatcher::pubsub::*; -use crate::net::routing::dispatcher::resource::{NodeId, Resource, SessionContext}; -use crate::net::routing::dispatcher::tables::Tables; -use crate::net::routing::dispatcher::tables::{Route, RoutingExpr}; -use crate::net::routing::hat::{HatPubSubTrait, Sources}; -use crate::net::routing::router::RoutesIndexes; -use crate::net::routing::{RoutingContext, PREFIX_LIVELINESS}; +use std::{ + borrow::Cow, + collections::{HashMap, HashSet}, + sync::{atomic::Ordering, Arc}, +}; + use petgraph::graph::NodeIndex; -use std::borrow::Cow; -use std::collections::{HashMap, HashSet}; -use std::sync::atomic::Ordering; -use std::sync::Arc; -use zenoh_protocol::core::key_expr::OwnedKeyExpr; -use zenoh_protocol::network::declare::SubscriberId; use zenoh_protocol::{ - core::{Reliability, WhatAmI, ZenohId}, + core::{key_expr::OwnedKeyExpr, Reliability, WhatAmI, ZenohId}, network::declare::{ common::ext::WireExprType, ext, subscriber::ext::SubscriberInfo, Declare, DeclareBody, - DeclareSubscriber, UndeclareSubscriber, + DeclareSubscriber, SubscriberId, UndeclareSubscriber, }, }; use zenoh_sync::get_mut_unchecked; +use super::{ + face_hat, face_hat_mut, get_peer, get_routes_entries, hat, hat_mut, network::Network, res_hat, + res_hat_mut, HatCode, HatContext, HatFace, HatTables, +}; +use crate::net::routing::{ + dispatcher::{ + face::FaceState, + pubsub::*, + resource::{NodeId, Resource, SessionContext}, + tables::{Route, RoutingExpr, Tables}, + }, + hat::{HatPubSubTrait, Sources}, + router::RoutesIndexes, + RoutingContext, PREFIX_LIVELINESS, +}; + #[inline] fn send_sourced_subscription_to_net_childs( tables: &Tables, diff --git a/zenoh/src/net/routing/hat/linkstate_peer/queries.rs b/zenoh/src/net/routing/hat/linkstate_peer/queries.rs index a227d845ba..bed683f717 100644 --- a/zenoh/src/net/routing/hat/linkstate_peer/queries.rs +++ b/zenoh/src/net/routing/hat/linkstate_peer/queries.rs @@ -11,36 +11,46 @@ // Contributors: // ZettaScale Zenoh Team, // -use super::network::Network; -use super::{face_hat, face_hat_mut, get_routes_entries, hat, hat_mut, res_hat, res_hat_mut}; -use super::{get_peer, HatCode, HatContext, HatFace, HatTables}; -use crate::net::routing::dispatcher::face::FaceState; -use crate::net::routing::dispatcher::queries::*; -use crate::net::routing::dispatcher::resource::{NodeId, Resource, SessionContext}; -use crate::net::routing::dispatcher::tables::Tables; -use crate::net::routing::dispatcher::tables::{QueryTargetQabl, QueryTargetQablSet, RoutingExpr}; -use crate::net::routing::hat::{HatQueriesTrait, Sources}; -use crate::net::routing::router::RoutesIndexes; -use crate::net::routing::{RoutingContext, PREFIX_LIVELINESS}; +use std::{ + borrow::Cow, + collections::HashMap, + sync::{atomic::Ordering, Arc}, +}; + use ordered_float::OrderedFloat; use petgraph::graph::NodeIndex; -use std::borrow::Cow; -use std::collections::HashMap; -use std::sync::atomic::Ordering; -use std::sync::Arc; use zenoh_buffers::ZBuf; -use zenoh_protocol::core::key_expr::include::{Includer, DEFAULT_INCLUDER}; -use zenoh_protocol::core::key_expr::OwnedKeyExpr; -use zenoh_protocol::network::declare::QueryableId; use zenoh_protocol::{ - core::{WhatAmI, WireExpr, ZenohId}, + core::{ + key_expr::{ + include::{Includer, DEFAULT_INCLUDER}, + OwnedKeyExpr, + }, + WhatAmI, WireExpr, ZenohId, + }, network::declare::{ common::ext::WireExprType, ext, queryable::ext::QueryableInfoType, Declare, DeclareBody, - DeclareQueryable, UndeclareQueryable, + DeclareQueryable, QueryableId, UndeclareQueryable, }, }; use zenoh_sync::get_mut_unchecked; +use super::{ + face_hat, face_hat_mut, get_peer, get_routes_entries, hat, hat_mut, network::Network, res_hat, + res_hat_mut, HatCode, HatContext, HatFace, HatTables, +}; +use crate::net::routing::{ + dispatcher::{ + face::FaceState, + queries::*, + resource::{NodeId, Resource, SessionContext}, + tables::{QueryTargetQabl, QueryTargetQablSet, RoutingExpr, Tables}, + }, + hat::{HatQueriesTrait, Sources}, + router::RoutesIndexes, + RoutingContext, PREFIX_LIVELINESS, +}; + #[inline] fn merge_qabl_infos(mut this: QueryableInfoType, info: &QueryableInfoType) -> QueryableInfoType { this.complete = this.complete || info.complete; diff --git a/zenoh/src/net/routing/hat/mod.rs b/zenoh/src/net/routing/hat/mod.rs index ee6557aac3..5eb812df71 100644 --- a/zenoh/src/net/routing/hat/mod.rs +++ b/zenoh/src/net/routing/hat/mod.rs @@ -17,15 +17,8 @@ //! This module is intended for Zenoh's internal use. //! //! [Click here for Zenoh's documentation](../zenoh/index.html) -use super::{ - dispatcher::{ - face::{Face, FaceState}, - tables::{NodeId, QueryTargetQablSet, Resource, Route, RoutingExpr, Tables, TablesLock}, - }, - router::RoutesIndexes, -}; -use crate::net::runtime::Runtime; use std::{any::Any, sync::Arc}; + use zenoh_buffers::ZBuf; use zenoh_config::{unwrap_or_default, Config, WhatAmI, ZenohId}; use zenoh_protocol::{ @@ -41,6 +34,15 @@ use zenoh_protocol::{ use zenoh_result::ZResult; use zenoh_transport::unicast::TransportUnicast; +use super::{ + dispatcher::{ + face::{Face, FaceState}, + tables::{NodeId, QueryTargetQablSet, Resource, Route, RoutingExpr, Tables, TablesLock}, + }, + router::RoutesIndexes, +}; +use crate::net::runtime::Runtime; + mod client; mod linkstate_peer; mod p2p_peer; diff --git a/zenoh/src/net/routing/hat/p2p_peer/gossip.rs b/zenoh/src/net/routing/hat/p2p_peer/gossip.rs index df04b396ab..57b76fc086 100644 --- a/zenoh/src/net/routing/hat/p2p_peer/gossip.rs +++ b/zenoh/src/net/routing/hat/p2p_peer/gossip.rs @@ -11,24 +11,30 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::net::codec::Zenoh080Routing; -use crate::net::protocol::linkstate::{LinkState, LinkStateList}; -use crate::net::runtime::Runtime; -use crate::net::runtime::WeakRuntime; +use std::convert::TryInto; + use petgraph::graph::NodeIndex; use rand::Rng; -use std::convert::TryInto; use vec_map::VecMap; -use zenoh_buffers::writer::{DidntWrite, HasWriter}; -use zenoh_buffers::ZBuf; +use zenoh_buffers::{ + writer::{DidntWrite, HasWriter}, + ZBuf, +}; use zenoh_codec::WCodec; use zenoh_link::Locator; -use zenoh_protocol::common::ZExtBody; -use zenoh_protocol::core::{WhatAmI, WhatAmIMatcher, ZenohId}; -use zenoh_protocol::network::oam::id::OAM_LINKSTATE; -use zenoh_protocol::network::{oam, NetworkBody, NetworkMessage, Oam}; +use zenoh_protocol::{ + common::ZExtBody, + core::{WhatAmI, WhatAmIMatcher, ZenohId}, + network::{oam, oam::id::OAM_LINKSTATE, NetworkBody, NetworkMessage, Oam}, +}; use zenoh_transport::unicast::TransportUnicast; +use crate::net::{ + codec::Zenoh080Routing, + protocol::linkstate::{LinkState, LinkStateList}, + runtime::{Runtime, WeakRuntime}, +}; + #[derive(Clone)] struct Details { zid: bool, diff --git a/zenoh/src/net/routing/hat/p2p_peer/mod.rs b/zenoh/src/net/routing/hat/p2p_peer/mod.rs index ba41e0f114..530c181335 100644 --- a/zenoh/src/net/routing/hat/p2p_peer/mod.rs +++ b/zenoh/src/net/routing/hat/p2p_peer/mod.rs @@ -17,17 +17,24 @@ //! This module is intended for Zenoh's internal use. //! //! [Click here for Zenoh's documentation](../zenoh/index.html) -use crate::{ - net::runtime::Runtime, - net::{ - codec::Zenoh080Routing, - protocol::linkstate::LinkStateList, - routing::{ - dispatcher::face::Face, - router::{compute_data_routes, compute_query_routes, RoutesIndexes}, - }, +use std::{ + any::Any, + collections::HashMap, + sync::{atomic::AtomicU32, Arc}, +}; + +use zenoh_config::{unwrap_or_default, ModeDependent, WhatAmI, WhatAmIMatcher}; +use zenoh_protocol::{ + common::ZExtBody, + network::{ + declare::{queryable::ext::QueryableInfoType, QueryableId, SubscriberId}, + oam::id::OAM_LINKSTATE, + Oam, }, }; +use zenoh_result::ZResult; +use zenoh_sync::get_mut_unchecked; +use zenoh_transport::unicast::TransportUnicast; use self::{ gossip::Network, @@ -41,23 +48,15 @@ use super::{ }, HatBaseTrait, HatTrait, }; -use std::{ - any::Any, - collections::HashMap, - sync::{atomic::AtomicU32, Arc}, -}; -use zenoh_config::{unwrap_or_default, ModeDependent, WhatAmI, WhatAmIMatcher}; -use zenoh_protocol::network::{ - declare::{QueryableId, SubscriberId}, - Oam, -}; -use zenoh_protocol::{ - common::ZExtBody, - network::{declare::queryable::ext::QueryableInfoType, oam::id::OAM_LINKSTATE}, +use crate::net::{ + codec::Zenoh080Routing, + protocol::linkstate::LinkStateList, + routing::{ + dispatcher::face::Face, + router::{compute_data_routes, compute_query_routes, RoutesIndexes}, + }, + runtime::Runtime, }; -use zenoh_result::ZResult; -use zenoh_sync::get_mut_unchecked; -use zenoh_transport::unicast::TransportUnicast; mod gossip; mod pubsub; diff --git a/zenoh/src/net/routing/hat/p2p_peer/pubsub.rs b/zenoh/src/net/routing/hat/p2p_peer/pubsub.rs index d57c2ac665..e7cf0c5e5d 100644 --- a/zenoh/src/net/routing/hat/p2p_peer/pubsub.rs +++ b/zenoh/src/net/routing/hat/p2p_peer/pubsub.rs @@ -11,30 +11,33 @@ // Contributors: // ZettaScale Zenoh Team, // -use super::{face_hat, face_hat_mut, get_routes_entries}; -use super::{HatCode, HatFace}; -use crate::net::routing::dispatcher::face::FaceState; -use crate::net::routing::dispatcher::resource::{NodeId, Resource, SessionContext}; -use crate::net::routing::dispatcher::tables::Tables; -use crate::net::routing::dispatcher::tables::{Route, RoutingExpr}; -use crate::net::routing::hat::{HatPubSubTrait, Sources}; -use crate::net::routing::router::RoutesIndexes; -use crate::net::routing::{RoutingContext, PREFIX_LIVELINESS}; -use std::borrow::Cow; -use std::collections::HashMap; -use std::sync::atomic::Ordering; -use std::sync::Arc; -use zenoh_protocol::core::key_expr::OwnedKeyExpr; -use zenoh_protocol::network::declare::SubscriberId; +use std::{ + borrow::Cow, + collections::HashMap, + sync::{atomic::Ordering, Arc}, +}; + use zenoh_protocol::{ - core::{Reliability, WhatAmI}, + core::{key_expr::OwnedKeyExpr, Reliability, WhatAmI}, network::declare::{ common::ext::WireExprType, ext, subscriber::ext::SubscriberInfo, Declare, DeclareBody, - DeclareSubscriber, UndeclareSubscriber, + DeclareSubscriber, SubscriberId, UndeclareSubscriber, }, }; use zenoh_sync::get_mut_unchecked; +use super::{face_hat, face_hat_mut, get_routes_entries, HatCode, HatFace}; +use crate::net::routing::{ + dispatcher::{ + face::FaceState, + resource::{NodeId, Resource, SessionContext}, + tables::{Route, RoutingExpr, Tables}, + }, + hat::{HatPubSubTrait, Sources}, + router::RoutesIndexes, + RoutingContext, PREFIX_LIVELINESS, +}; + #[inline] fn propagate_simple_subscription_to( _tables: &mut Tables, diff --git a/zenoh/src/net/routing/hat/p2p_peer/queries.rs b/zenoh/src/net/routing/hat/p2p_peer/queries.rs index 25fed11842..f0de12d7b9 100644 --- a/zenoh/src/net/routing/hat/p2p_peer/queries.rs +++ b/zenoh/src/net/routing/hat/p2p_peer/queries.rs @@ -11,33 +11,41 @@ // Contributors: // ZettaScale Zenoh Team, // -use super::{face_hat, face_hat_mut, get_routes_entries}; -use super::{HatCode, HatFace}; -use crate::net::routing::dispatcher::face::FaceState; -use crate::net::routing::dispatcher::resource::{NodeId, Resource, SessionContext}; -use crate::net::routing::dispatcher::tables::Tables; -use crate::net::routing::dispatcher::tables::{QueryTargetQabl, QueryTargetQablSet, RoutingExpr}; -use crate::net::routing::hat::{HatQueriesTrait, Sources}; -use crate::net::routing::router::RoutesIndexes; -use crate::net::routing::{RoutingContext, PREFIX_LIVELINESS}; +use std::{ + borrow::Cow, + collections::HashMap, + sync::{atomic::Ordering, Arc}, +}; + use ordered_float::OrderedFloat; -use std::borrow::Cow; -use std::collections::HashMap; -use std::sync::atomic::Ordering; -use std::sync::Arc; use zenoh_buffers::ZBuf; -use zenoh_protocol::core::key_expr::include::{Includer, DEFAULT_INCLUDER}; -use zenoh_protocol::core::key_expr::OwnedKeyExpr; -use zenoh_protocol::network::declare::QueryableId; use zenoh_protocol::{ - core::{WhatAmI, WireExpr}, + core::{ + key_expr::{ + include::{Includer, DEFAULT_INCLUDER}, + OwnedKeyExpr, + }, + WhatAmI, WireExpr, + }, network::declare::{ common::ext::WireExprType, ext, queryable::ext::QueryableInfoType, Declare, DeclareBody, - DeclareQueryable, UndeclareQueryable, + DeclareQueryable, QueryableId, UndeclareQueryable, }, }; use zenoh_sync::get_mut_unchecked; +use super::{face_hat, face_hat_mut, get_routes_entries, HatCode, HatFace}; +use crate::net::routing::{ + dispatcher::{ + face::FaceState, + resource::{NodeId, Resource, SessionContext}, + tables::{QueryTargetQabl, QueryTargetQablSet, RoutingExpr, Tables}, + }, + hat::{HatQueriesTrait, Sources}, + router::RoutesIndexes, + RoutingContext, PREFIX_LIVELINESS, +}; + #[inline] fn merge_qabl_infos(mut this: QueryableInfoType, info: &QueryableInfoType) -> QueryableInfoType { this.complete = this.complete || info.complete; diff --git a/zenoh/src/net/routing/hat/router/mod.rs b/zenoh/src/net/routing/hat/router/mod.rs index 85ce0e6916..f573acee43 100644 --- a/zenoh/src/net/routing/hat/router/mod.rs +++ b/zenoh/src/net/routing/hat/router/mod.rs @@ -17,34 +17,6 @@ //! This module is intended for Zenoh's internal use. //! //! [Click here for Zenoh's documentation](../zenoh/index.html) -use self::{ - network::{shared_nodes, Network}, - pubsub::{ - pubsub_linkstate_change, pubsub_new_face, pubsub_remove_node, undeclare_client_subscription, - }, - queries::{ - queries_linkstate_change, queries_new_face, queries_remove_node, undeclare_client_queryable, - }, -}; -use super::{ - super::dispatcher::{ - face::FaceState, - tables::{NodeId, Resource, RoutingExpr, Tables, TablesLock}, - }, - HatBaseTrait, HatTrait, -}; -use crate::{ - net::runtime::Runtime, - net::{ - codec::Zenoh080Routing, - protocol::linkstate::LinkStateList, - routing::{ - dispatcher::face::Face, - hat::TREES_COMPUTATION_DELAY_MS, - router::{compute_data_routes, compute_query_routes, RoutesIndexes}, - }, - }, -}; use std::{ any::Any, collections::{hash_map::DefaultHasher, HashMap, HashSet}, @@ -52,6 +24,7 @@ use std::{ sync::{atomic::AtomicU32, Arc}, time::Duration, }; + use zenoh_config::{unwrap_or_default, ModeDependent, WhatAmI, WhatAmIMatcher, ZenohId}; use zenoh_protocol::{ common::ZExtBody, @@ -66,6 +39,33 @@ use zenoh_sync::get_mut_unchecked; use zenoh_task::TerminatableTask; use zenoh_transport::unicast::TransportUnicast; +use self::{ + network::{shared_nodes, Network}, + pubsub::{ + pubsub_linkstate_change, pubsub_new_face, pubsub_remove_node, undeclare_client_subscription, + }, + queries::{ + queries_linkstate_change, queries_new_face, queries_remove_node, undeclare_client_queryable, + }, +}; +use super::{ + super::dispatcher::{ + face::FaceState, + tables::{NodeId, Resource, RoutingExpr, Tables, TablesLock}, + }, + HatBaseTrait, HatTrait, +}; +use crate::net::{ + codec::Zenoh080Routing, + protocol::linkstate::LinkStateList, + routing::{ + dispatcher::face::Face, + hat::TREES_COMPUTATION_DELAY_MS, + router::{compute_data_routes, compute_query_routes, RoutesIndexes}, + }, + runtime::Runtime, +}; + mod network; mod pubsub; mod queries; diff --git a/zenoh/src/net/routing/hat/router/network.rs b/zenoh/src/net/routing/hat/router/network.rs index 3ff59b5ede..ae435a6871 100644 --- a/zenoh/src/net/routing/hat/router/network.rs +++ b/zenoh/src/net/routing/hat/router/network.rs @@ -11,25 +11,34 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::net::codec::Zenoh080Routing; -use crate::net::protocol::linkstate::{LinkState, LinkStateList}; -use crate::net::routing::dispatcher::tables::NodeId; -use crate::net::runtime::Runtime; -use petgraph::graph::NodeIndex; -use petgraph::visit::{IntoNodeReferences, VisitMap, Visitable}; -use rand::Rng; use std::convert::TryInto; + +use petgraph::{ + graph::NodeIndex, + visit::{IntoNodeReferences, VisitMap, Visitable}, +}; +use rand::Rng; use vec_map::VecMap; -use zenoh_buffers::writer::{DidntWrite, HasWriter}; -use zenoh_buffers::ZBuf; +use zenoh_buffers::{ + writer::{DidntWrite, HasWriter}, + ZBuf, +}; use zenoh_codec::WCodec; use zenoh_link::Locator; -use zenoh_protocol::common::ZExtBody; -use zenoh_protocol::core::{WhatAmI, WhatAmIMatcher, ZenohId}; -use zenoh_protocol::network::oam::id::OAM_LINKSTATE; -use zenoh_protocol::network::{oam, NetworkBody, NetworkMessage, Oam}; +use zenoh_protocol::{ + common::ZExtBody, + core::{WhatAmI, WhatAmIMatcher, ZenohId}, + network::{oam, oam::id::OAM_LINKSTATE, NetworkBody, NetworkMessage, Oam}, +}; use zenoh_transport::unicast::TransportUnicast; +use crate::net::{ + codec::Zenoh080Routing, + protocol::linkstate::{LinkState, LinkStateList}, + routing::dispatcher::tables::NodeId, + runtime::Runtime, +}; + #[derive(Clone)] struct Details { zid: bool, diff --git a/zenoh/src/net/routing/hat/router/pubsub.rs b/zenoh/src/net/routing/hat/router/pubsub.rs index 99b7eb3c12..14726ac970 100644 --- a/zenoh/src/net/routing/hat/router/pubsub.rs +++ b/zenoh/src/net/routing/hat/router/pubsub.rs @@ -11,33 +11,38 @@ // Contributors: // ZettaScale Zenoh Team, // -use super::network::Network; -use super::{face_hat, face_hat_mut, get_routes_entries, hat, hat_mut, res_hat, res_hat_mut}; -use super::{get_peer, get_router, HatCode, HatContext, HatFace, HatTables}; -use crate::net::routing::dispatcher::face::FaceState; -use crate::net::routing::dispatcher::pubsub::*; -use crate::net::routing::dispatcher::resource::{NodeId, Resource, SessionContext}; -use crate::net::routing::dispatcher::tables::Tables; -use crate::net::routing::dispatcher::tables::{Route, RoutingExpr}; -use crate::net::routing::hat::{HatPubSubTrait, Sources}; -use crate::net::routing::router::RoutesIndexes; -use crate::net::routing::{RoutingContext, PREFIX_LIVELINESS}; +use std::{ + borrow::Cow, + collections::{HashMap, HashSet}, + sync::{atomic::Ordering, Arc}, +}; + use petgraph::graph::NodeIndex; -use std::borrow::Cow; -use std::collections::{HashMap, HashSet}; -use std::sync::atomic::Ordering; -use std::sync::Arc; -use zenoh_protocol::core::key_expr::OwnedKeyExpr; -use zenoh_protocol::network::declare::SubscriberId; use zenoh_protocol::{ - core::{Reliability, WhatAmI, ZenohId}, + core::{key_expr::OwnedKeyExpr, Reliability, WhatAmI, ZenohId}, network::declare::{ common::ext::WireExprType, ext, subscriber::ext::SubscriberInfo, Declare, DeclareBody, - DeclareSubscriber, UndeclareSubscriber, + DeclareSubscriber, SubscriberId, UndeclareSubscriber, }, }; use zenoh_sync::get_mut_unchecked; +use super::{ + face_hat, face_hat_mut, get_peer, get_router, get_routes_entries, hat, hat_mut, + network::Network, res_hat, res_hat_mut, HatCode, HatContext, HatFace, HatTables, +}; +use crate::net::routing::{ + dispatcher::{ + face::FaceState, + pubsub::*, + resource::{NodeId, Resource, SessionContext}, + tables::{Route, RoutingExpr, Tables}, + }, + hat::{HatPubSubTrait, Sources}, + router::RoutesIndexes, + RoutingContext, PREFIX_LIVELINESS, +}; + #[inline] fn send_sourced_subscription_to_net_childs( tables: &Tables, diff --git a/zenoh/src/net/routing/hat/router/queries.rs b/zenoh/src/net/routing/hat/router/queries.rs index dbd7da8629..9defb80081 100644 --- a/zenoh/src/net/routing/hat/router/queries.rs +++ b/zenoh/src/net/routing/hat/router/queries.rs @@ -11,36 +11,46 @@ // Contributors: // ZettaScale Zenoh Team, // -use super::network::Network; -use super::{face_hat, face_hat_mut, get_routes_entries, hat, hat_mut, res_hat, res_hat_mut}; -use super::{get_peer, get_router, HatCode, HatContext, HatFace, HatTables}; -use crate::net::routing::dispatcher::face::FaceState; -use crate::net::routing::dispatcher::queries::*; -use crate::net::routing::dispatcher::resource::{NodeId, Resource, SessionContext}; -use crate::net::routing::dispatcher::tables::Tables; -use crate::net::routing::dispatcher::tables::{QueryTargetQabl, QueryTargetQablSet, RoutingExpr}; -use crate::net::routing::hat::{HatQueriesTrait, Sources}; -use crate::net::routing::router::RoutesIndexes; -use crate::net::routing::{RoutingContext, PREFIX_LIVELINESS}; +use std::{ + borrow::Cow, + collections::HashMap, + sync::{atomic::Ordering, Arc}, +}; + use ordered_float::OrderedFloat; use petgraph::graph::NodeIndex; -use std::borrow::Cow; -use std::collections::HashMap; -use std::sync::atomic::Ordering; -use std::sync::Arc; use zenoh_buffers::ZBuf; -use zenoh_protocol::core::key_expr::include::{Includer, DEFAULT_INCLUDER}; -use zenoh_protocol::core::key_expr::OwnedKeyExpr; -use zenoh_protocol::network::declare::QueryableId; use zenoh_protocol::{ - core::{WhatAmI, WireExpr, ZenohId}, + core::{ + key_expr::{ + include::{Includer, DEFAULT_INCLUDER}, + OwnedKeyExpr, + }, + WhatAmI, WireExpr, ZenohId, + }, network::declare::{ common::ext::WireExprType, ext, queryable::ext::QueryableInfoType, Declare, DeclareBody, - DeclareQueryable, UndeclareQueryable, + DeclareQueryable, QueryableId, UndeclareQueryable, }, }; use zenoh_sync::get_mut_unchecked; +use super::{ + face_hat, face_hat_mut, get_peer, get_router, get_routes_entries, hat, hat_mut, + network::Network, res_hat, res_hat_mut, HatCode, HatContext, HatFace, HatTables, +}; +use crate::net::routing::{ + dispatcher::{ + face::FaceState, + queries::*, + resource::{NodeId, Resource, SessionContext}, + tables::{QueryTargetQabl, QueryTargetQablSet, RoutingExpr, Tables}, + }, + hat::{HatQueriesTrait, Sources}, + router::RoutesIndexes, + RoutingContext, PREFIX_LIVELINESS, +}; + #[inline] fn merge_qabl_infos(mut this: QueryableInfoType, info: &QueryableInfoType) -> QueryableInfoType { this.complete = this.complete || info.complete; diff --git a/zenoh/src/net/routing/interceptor/access_control.rs b/zenoh/src/net/routing/interceptor/access_control.rs index b23db9765e..b58a76b2b9 100644 --- a/zenoh/src/net/routing/interceptor/access_control.rs +++ b/zenoh/src/net/routing/interceptor/access_control.rs @@ -18,14 +18,8 @@ //! //! [Click here for Zenoh's documentation](../zenoh/index.html) -use super::{ - authorization::PolicyEnforcer, EgressInterceptor, IngressInterceptor, InterceptorFactory, - InterceptorFactoryTrait, InterceptorTrait, -}; -use crate::api::key_expr::KeyExpr; -use crate::net::routing::RoutingContext; -use std::any::Any; -use std::sync::Arc; +use std::{any::Any, sync::Arc}; + use zenoh_config::{AclConfig, Action, InterceptorFlow, Permission, Subject, ZenohId}; use zenoh_protocol::{ network::{Declare, DeclareBody, NetworkBody, NetworkMessage, Push, Request}, @@ -33,6 +27,12 @@ use zenoh_protocol::{ }; use zenoh_result::ZResult; use zenoh_transport::{multicast::TransportMulticast, unicast::TransportUnicast}; + +use super::{ + authorization::PolicyEnforcer, EgressInterceptor, IngressInterceptor, InterceptorFactory, + InterceptorFactoryTrait, InterceptorTrait, +}; +use crate::{api::key_expr::KeyExpr, net::routing::RoutingContext}; pub struct AclEnforcer { enforcer: Arc, } diff --git a/zenoh/src/net/routing/interceptor/authorization.rs b/zenoh/src/net/routing/interceptor/authorization.rs index 61c1cba217..f1cdb1ca4e 100644 --- a/zenoh/src/net/routing/interceptor/authorization.rs +++ b/zenoh/src/net/routing/interceptor/authorization.rs @@ -17,13 +17,16 @@ //! This module is intended for Zenoh's internal use. //! //! [Click here for Zenoh's documentation](../zenoh/index.html) -use ahash::RandomState; use std::collections::HashMap; + +use ahash::RandomState; use zenoh_config::{ AclConfig, AclConfigRules, Action, InterceptorFlow, Permission, PolicyRule, Subject, }; -use zenoh_keyexpr::keyexpr; -use zenoh_keyexpr::keyexpr_tree::{IKeyExprTree, IKeyExprTreeMut, KeBoxTree}; +use zenoh_keyexpr::{ + keyexpr, + keyexpr_tree::{IKeyExprTree, IKeyExprTreeMut, KeBoxTree}, +}; use zenoh_result::ZResult; type PolicyForSubject = FlowPolicy; diff --git a/zenoh/src/net/routing/interceptor/downsampling.rs b/zenoh/src/net/routing/interceptor/downsampling.rs index cda132e806..06e86ec3ce 100644 --- a/zenoh/src/net/routing/interceptor/downsampling.rs +++ b/zenoh/src/net/routing/interceptor/downsampling.rs @@ -18,17 +18,21 @@ //! //! [Click here for Zenoh's documentation](../zenoh/index.html) -use crate::net::routing::interceptor::*; -use std::collections::HashMap; -use std::sync::{Arc, Mutex}; +use std::{ + collections::HashMap, + sync::{Arc, Mutex}, +}; + use zenoh_config::{DownsamplingItemConf, DownsamplingRuleConf, InterceptorFlow}; use zenoh_core::zlock; -use zenoh_keyexpr::keyexpr_tree::impls::KeyedSetProvider; -use zenoh_keyexpr::keyexpr_tree::{support::UnknownWildness, KeBoxTree}; -use zenoh_keyexpr::keyexpr_tree::{IKeyExprTree, IKeyExprTreeMut}; +use zenoh_keyexpr::keyexpr_tree::{ + impls::KeyedSetProvider, support::UnknownWildness, IKeyExprTree, IKeyExprTreeMut, KeBoxTree, +}; use zenoh_protocol::network::NetworkBody; use zenoh_result::ZResult; +use crate::net::routing::interceptor::*; + pub(crate) fn downsampling_interceptor_factories( config: &Vec, ) -> ZResult> { diff --git a/zenoh/src/net/routing/interceptor/mod.rs b/zenoh/src/net/routing/interceptor/mod.rs index 6d9391ce15..3be30e9205 100644 --- a/zenoh/src/net/routing/interceptor/mod.rs +++ b/zenoh/src/net/routing/interceptor/mod.rs @@ -22,8 +22,6 @@ mod access_control; use access_control::acl_interceptor_factories; mod authorization; -use super::RoutingContext; -use crate::api::key_expr::KeyExpr; use std::any::Any; use zenoh_config::Config; @@ -31,6 +29,9 @@ use zenoh_protocol::network::NetworkMessage; use zenoh_result::ZResult; use zenoh_transport::{multicast::TransportMulticast, unicast::TransportUnicast}; +use super::RoutingContext; +use crate::api::key_expr::KeyExpr; + pub mod downsampling; use crate::net::routing::interceptor::downsampling::downsampling_interceptor_factories; diff --git a/zenoh/src/net/routing/mod.rs b/zenoh/src/net/routing/mod.rs index 75b4d4ef6a..9601465326 100644 --- a/zenoh/src/net/routing/mod.rs +++ b/zenoh/src/net/routing/mod.rs @@ -24,11 +24,12 @@ pub mod router; use std::{cell::OnceCell, sync::Arc}; -use zenoh_protocol::core::key_expr::OwnedKeyExpr; -use zenoh_protocol::{core::WireExpr, network::NetworkMessage}; +use zenoh_protocol::{ + core::{key_expr::OwnedKeyExpr, WireExpr}, + network::NetworkMessage, +}; use self::{dispatcher::face::Face, router::Resource}; - use super::runtime; pub(crate) static PREFIX_LIVELINESS: &str = "@/liveliness"; @@ -100,8 +101,7 @@ impl RoutingContext { impl RoutingContext { #[inline] pub(crate) fn wire_expr(&self) -> Option<&WireExpr> { - use zenoh_protocol::network::DeclareBody; - use zenoh_protocol::network::NetworkBody; + use zenoh_protocol::network::{DeclareBody, NetworkBody}; match &self.msg.body { NetworkBody::Push(m) => Some(&m.wire_expr), NetworkBody::Request(m) => Some(&m.wire_expr), diff --git a/zenoh/src/net/routing/router.rs b/zenoh/src/net/routing/router.rs index 87766f021b..630253e1c6 100644 --- a/zenoh/src/net/routing/router.rs +++ b/zenoh/src/net/routing/router.rs @@ -11,33 +11,32 @@ // Contributors: // ZettaScale Zenoh Team, // -use super::dispatcher::face::{Face, FaceState}; -pub use super::dispatcher::pubsub::*; -pub use super::dispatcher::queries::*; -pub use super::dispatcher::resource::*; -use super::dispatcher::tables::Tables; -use super::dispatcher::tables::TablesLock; -use super::hat; -use super::interceptor::EgressInterceptor; -use super::interceptor::InterceptorsChain; -use super::runtime::Runtime; -use crate::net::primitives::DeMux; -use crate::net::primitives::DummyPrimitives; -use crate::net::primitives::EPrimitives; -use crate::net::primitives::McastMux; -use crate::net::primitives::Mux; -use crate::net::routing::interceptor::IngressInterceptor; -use std::str::FromStr; -use std::sync::Arc; -use std::sync::{Mutex, RwLock}; +use std::{ + str::FromStr, + sync::{Arc, Mutex, RwLock}, +}; + use uhlc::HLC; use zenoh_config::Config; use zenoh_protocol::core::{WhatAmI, ZenohId}; -use zenoh_transport::multicast::TransportMulticast; -use zenoh_transport::unicast::TransportUnicast; -use zenoh_transport::TransportPeer; // use zenoh_collections::Timer; use zenoh_result::ZResult; +use zenoh_transport::{multicast::TransportMulticast, unicast::TransportUnicast, TransportPeer}; + +pub use super::dispatcher::{pubsub::*, queries::*, resource::*}; +use super::{ + dispatcher::{ + face::{Face, FaceState}, + tables::{Tables, TablesLock}, + }, + hat, + interceptor::{EgressInterceptor, InterceptorsChain}, + runtime::Runtime, +}; +use crate::net::{ + primitives::{DeMux, DummyPrimitives, EPrimitives, McastMux, Mux}, + routing::interceptor::IngressInterceptor, +}; pub struct Router { // whatami: WhatAmI, diff --git a/zenoh/src/net/runtime/adminspace.rs b/zenoh/src/net/runtime/adminspace.rs index 9ea54b8d88..5a471bbe14 100644 --- a/zenoh/src/net/runtime/adminspace.rs +++ b/zenoh/src/net/runtime/adminspace.rs @@ -10,24 +10,13 @@ // // Contributors: // ZettaScale Zenoh Team, -use super::routing::dispatcher::face::Face; -use super::Runtime; -use crate::api::builders::sample::ValueBuilderTrait; -use crate::api::bytes::ZBytes; -use crate::api::key_expr::KeyExpr; -#[cfg(all(feature = "unstable", feature = "plugins"))] -use crate::api::plugins::PluginsManager; -use crate::api::queryable::Query; -use crate::api::queryable::QueryInner; -use crate::api::value::Value; -use crate::encoding::Encoding; -use crate::net::primitives::Primitives; +use std::{ + collections::HashMap, + convert::{TryFrom, TryInto}, + sync::{Arc, Mutex}, +}; + use serde_json::json; -use std::collections::HashMap; -use std::convert::TryFrom; -use std::convert::TryInto; -use std::sync::Arc; -use std::sync::Mutex; use tracing::{error, trace}; use zenoh_buffers::buffer::SplitBuffer; use zenoh_config::{unwrap_or_default, ConfigValidator, ValidatedMap, WhatAmI}; @@ -36,20 +25,35 @@ use zenoh_core::Wait; use zenoh_plugin_trait::{PluginControl, PluginStatus}; #[cfg(all(feature = "unstable", feature = "plugins"))] use zenoh_protocol::core::key_expr::keyexpr; -use zenoh_protocol::network::declare::QueryableId; -use zenoh_protocol::network::Interest; use zenoh_protocol::{ core::{key_expr::OwnedKeyExpr, ExprId, WireExpr, ZenohId, EMPTY_EXPR_ID}, network::{ - declare::{queryable::ext::QueryableInfoType, subscriber::ext::SubscriberInfo}, - ext, Declare, DeclareBody, DeclareQueryable, DeclareSubscriber, Push, Request, Response, - ResponseFinal, + declare::{ + queryable::ext::QueryableInfoType, subscriber::ext::SubscriberInfo, QueryableId, + }, + ext, Declare, DeclareBody, DeclareQueryable, DeclareSubscriber, Interest, Push, Request, + Response, ResponseFinal, }, zenoh::{PushBody, RequestBody}, }; use zenoh_result::ZResult; use zenoh_transport::unicast::TransportUnicast; +use super::{routing::dispatcher::face::Face, Runtime}; +#[cfg(all(feature = "unstable", feature = "plugins"))] +use crate::api::plugins::PluginsManager; +use crate::{ + api::{ + builders::sample::ValueBuilderTrait, + bytes::ZBytes, + key_expr::KeyExpr, + queryable::{Query, QueryInner}, + value::Value, + }, + encoding::Encoding, + net::primitives::Primitives, +}; + pub struct AdminContext { runtime: Runtime, version: String, diff --git a/zenoh/src/net/runtime/mod.rs b/zenoh/src/net/runtime/mod.rs index 4991844650..f620d1c30b 100644 --- a/zenoh/src/net/runtime/mod.rs +++ b/zenoh/src/net/runtime/mod.rs @@ -20,31 +20,28 @@ mod adminspace; pub mod orchestrator; -use super::primitives::DeMux; -use super::routing; -use super::routing::router::Router; -#[cfg(all(feature = "unstable", feature = "plugins"))] -use crate::api::loader::{load_plugins, start_plugins}; -#[cfg(all(feature = "unstable", feature = "plugins"))] -use crate::api::plugins::PluginsManager; -use crate::config::{unwrap_or_default, Config, ModeDependent, Notifier}; -use crate::{GIT_VERSION, LONG_VERSION}; -pub use adminspace::AdminSpace; -use futures::stream::StreamExt; -use futures::Future; -use std::any::Any; -use std::sync::atomic::{AtomicU32, Ordering}; -use std::sync::{Arc, Weak}; #[cfg(all(feature = "unstable", feature = "plugins"))] use std::sync::{Mutex, MutexGuard}; -use std::time::Duration; +use std::{ + any::Any, + sync::{ + atomic::{AtomicU32, Ordering}, + Arc, Weak, + }, + time::Duration, +}; + +pub use adminspace::AdminSpace; +use futures::{stream::StreamExt, Future}; use tokio::task::JoinHandle; use tokio_util::sync::CancellationToken; use uhlc::{HLCBuilder, HLC}; use zenoh_link::{EndPoint, Link}; use zenoh_plugin_trait::{PluginStartArgs, StructVersion}; -use zenoh_protocol::core::{Locator, WhatAmI, ZenohId}; -use zenoh_protocol::network::NetworkMessage; +use zenoh_protocol::{ + core::{Locator, WhatAmI, ZenohId}, + network::NetworkMessage, +}; use zenoh_result::{bail, ZResult}; #[cfg(all(feature = "unstable", feature = "shared-memory"))] use zenoh_shm::api::client_storage::SharedMemoryClientStorage; @@ -57,6 +54,16 @@ use zenoh_transport::{ TransportManager, TransportMulticastEventHandler, TransportPeer, TransportPeerEventHandler, }; +use super::{primitives::DeMux, routing, routing::router::Router}; +#[cfg(all(feature = "unstable", feature = "plugins"))] +use crate::api::loader::{load_plugins, start_plugins}; +#[cfg(all(feature = "unstable", feature = "plugins"))] +use crate::api::plugins::PluginsManager; +use crate::{ + config::{unwrap_or_default, Config, ModeDependent, Notifier}, + GIT_VERSION, LONG_VERSION, +}; + pub(crate) struct RuntimeState { zid: ZenohId, whatami: WhatAmI, diff --git a/zenoh/src/net/runtime/orchestrator.rs b/zenoh/src/net/runtime/orchestrator.rs index 687fa90649..cad6c7bdbc 100644 --- a/zenoh/src/net/runtime/orchestrator.rs +++ b/zenoh/src/net/runtime/orchestrator.rs @@ -11,14 +11,18 @@ // Contributors: // ZettaScale Zenoh Team, // -use super::{Runtime, RuntimeSession}; +use std::{ + net::{IpAddr, Ipv6Addr, SocketAddr}, + time::Duration, +}; + use futures::prelude::*; use socket2::{Domain, Socket, Type}; -use std::net::{IpAddr, Ipv6Addr, SocketAddr}; -use std::time::Duration; use tokio::net::UdpSocket; -use zenoh_buffers::reader::DidntRead; -use zenoh_buffers::{reader::HasReader, writer::HasWriter}; +use zenoh_buffers::{ + reader::{DidntRead, HasReader}, + writer::HasWriter, +}; use zenoh_codec::{RCodec, WCodec, Zenoh080}; use zenoh_config::{ get_global_connect_timeout, get_global_listener_timeout, unwrap_or_default, ModeDependent, @@ -30,6 +34,8 @@ use zenoh_protocol::{ }; use zenoh_result::{bail, zerror, ZResult}; +use super::{Runtime, RuntimeSession}; + const RCV_BUF_SIZE: usize = u16::MAX as usize; const SCOUT_INITIAL_PERIOD: Duration = Duration::from_millis(1_000); const SCOUT_MAX_PERIOD: Duration = Duration::from_millis(8_000); diff --git a/zenoh/src/net/tests/tables.rs b/zenoh/src/net/tests/tables.rs index 841bc209f6..5f04b73d53 100644 --- a/zenoh/src/net/tests/tables.rs +++ b/zenoh/src/net/tests/tables.rs @@ -11,23 +11,33 @@ // Contributors: // ZettaScale Zenoh Team, // -use crate::net::primitives::{DummyPrimitives, EPrimitives, Primitives}; -use crate::net::routing::dispatcher::tables::{self, Tables}; -use crate::net::routing::router::*; -use crate::net::routing::RoutingContext; -use std::convert::{TryFrom, TryInto}; -use std::sync::Arc; +use std::{ + convert::{TryFrom, TryInto}, + sync::Arc, +}; + use uhlc::HLC; use zenoh_buffers::ZBuf; use zenoh_config::Config; use zenoh_core::zlock; -use zenoh_protocol::core::Encoding; -use zenoh_protocol::core::{ - key_expr::keyexpr, ExprId, Reliability, WhatAmI, WireExpr, ZenohId, EMPTY_EXPR_ID, +use zenoh_protocol::{ + core::{ + key_expr::keyexpr, Encoding, ExprId, Reliability, WhatAmI, WireExpr, ZenohId, EMPTY_EXPR_ID, + }, + network::{ + declare::subscriber::ext::SubscriberInfo, ext, Declare, DeclareBody, DeclareKeyExpr, + }, + zenoh::{PushBody, Put}, +}; + +use crate::net::{ + primitives::{DummyPrimitives, EPrimitives, Primitives}, + routing::{ + dispatcher::tables::{self, Tables}, + router::*, + RoutingContext, + }, }; -use zenoh_protocol::network::declare::subscriber::ext::SubscriberInfo; -use zenoh_protocol::network::{ext, Declare, DeclareBody, DeclareKeyExpr}; -use zenoh_protocol::zenoh::{PushBody, Put}; #[test] fn base_test() { diff --git a/zenoh/src/prelude.rs b/zenoh/src/prelude.rs index ac466ae50b..54418d9f78 100644 --- a/zenoh/src/prelude.rs +++ b/zenoh/src/prelude.rs @@ -26,71 +26,59 @@ // Reexport API in flat namespace pub(crate) mod flat { - pub use crate::buffers::*; - pub use crate::bytes::*; - pub use crate::config::*; - pub use crate::core::{Error as ZError, Resolvable, Resolve, Result as ZResult}; - pub use crate::encoding::*; - pub use crate::handlers::*; - pub use crate::key_expr::*; - pub use crate::publication::*; - pub use crate::query::*; - pub use crate::queryable::*; - pub use crate::sample::*; - pub use crate::scouting::*; - pub use crate::selector::*; - pub use crate::session::*; #[cfg(feature = "shared-memory")] pub use crate::shm::*; - pub use crate::subscriber::*; - pub use crate::time::*; - pub use crate::value::*; + pub use crate::{ + buffers::*, + bytes::*, + config::*, + core::{Error as ZError, Resolvable, Resolve, Result as ZResult}, + encoding::*, + handlers::*, + key_expr::*, + publication::*, + query::*, + queryable::*, + sample::*, + scouting::*, + selector::*, + session::*, + subscriber::*, + time::*, + value::*, + }; } // Reexport API in hierarchical namespace pub(crate) mod mods { - pub use crate::buffers; - pub use crate::bytes; - pub use crate::config; - pub use crate::core; - pub use crate::encoding; - pub use crate::handlers; - pub use crate::key_expr; - pub use crate::publication; - pub use crate::query; - pub use crate::queryable; - pub use crate::sample; - pub use crate::scouting; - pub use crate::selector; - pub use crate::session; #[cfg(feature = "shared-memory")] pub use crate::shm; - pub use crate::subscriber; - pub use crate::time; - pub use crate::value; + pub use crate::{ + buffers, bytes, config, core, encoding, handlers, key_expr, publication, query, queryable, + sample, scouting, selector, session, subscriber, time, value, + }; } +pub use flat::*; +pub use mods::*; + #[allow(deprecated)] pub use crate::core::AsyncResolve; #[allow(deprecated)] pub use crate::core::SyncResolve; pub use crate::core::Wait; -pub use flat::*; -pub use mods::*; /// Prelude to import when using Zenoh's sync API. #[deprecated = "use `zenoh::prelude` instead"] pub mod sync { - pub use super::flat::*; - pub use super::mods::*; + pub use super::{flat::*, mods::*}; #[allow(deprecated)] pub use crate::core::SyncResolve; } /// Prelude to import when using Zenoh's async API. #[deprecated = "use `zenoh::prelude` instead"] pub mod r#async { - pub use super::flat::*; - pub use super::mods::*; + pub use super::{flat::*, mods::*}; #[allow(deprecated)] pub use crate::core::AsyncResolve; } diff --git a/zenoh/tests/acl.rs b/zenoh/tests/acl.rs index 5f3c482581..1889a9f9fa 100644 --- a/zenoh/tests/acl.rs +++ b/zenoh/tests/acl.rs @@ -13,8 +13,11 @@ // #![cfg(target_family = "unix")] mod test { - use std::sync::{Arc, Mutex}; - use std::time::Duration; + use std::{ + sync::{Arc, Mutex}, + time::Duration, + }; + use tokio::runtime::Handle; use zenoh::prelude::*; use zenoh_core::{zlock, ztimeout}; diff --git a/zenoh/tests/attachments.rs b/zenoh/tests/attachments.rs index 836845a645..a63137ccfc 100644 --- a/zenoh/tests/attachments.rs +++ b/zenoh/tests/attachments.rs @@ -14,8 +14,7 @@ #[cfg(feature = "unstable")] #[test] fn attachment_pubsub() { - use zenoh::bytes::ZBytes; - use zenoh::prelude::*; + use zenoh::{bytes::ZBytes, prelude::*}; let zenoh = zenoh::open(Config::default()).wait().unwrap(); let _sub = zenoh .declare_subscriber("test/attachment") diff --git a/zenoh/tests/events.rs b/zenoh/tests/events.rs index 99ca6055da..41a681dc8f 100644 --- a/zenoh/tests/events.rs +++ b/zenoh/tests/events.rs @@ -12,8 +12,8 @@ // ZettaScale Zenoh Team, // use std::time::Duration; -use zenoh::internal::ztimeout; -use zenoh::prelude::*; + +use zenoh::{internal::ztimeout, prelude::*}; const TIMEOUT: Duration = Duration::from_secs(10); diff --git a/zenoh/tests/handler.rs b/zenoh/tests/handler.rs index 0862f9ee89..55f9368a87 100644 --- a/zenoh/tests/handler.rs +++ b/zenoh/tests/handler.rs @@ -12,6 +12,7 @@ // ZettaScale Zenoh Team, // use std::{thread, time::Duration}; + use zenoh::prelude::*; #[test] diff --git a/zenoh/tests/interceptors.rs b/zenoh/tests/interceptors.rs index f6e876d92e..d1ed9b7551 100644 --- a/zenoh/tests/interceptors.rs +++ b/zenoh/tests/interceptors.rs @@ -12,8 +12,8 @@ // ZettaScale Zenoh Team, // use std::sync::{Arc, Mutex}; -use zenoh::internal::zlock; -use zenoh::prelude::*; + +use zenoh::{internal::zlock, prelude::*}; struct IntervalCounter { first_tick: bool, diff --git a/zenoh/tests/liveliness.rs b/zenoh/tests/liveliness.rs index 0456361419..b974b5d705 100644 --- a/zenoh/tests/liveliness.rs +++ b/zenoh/tests/liveliness.rs @@ -14,7 +14,9 @@ #[cfg(feature = "unstable")] #[tokio::test(flavor = "multi_thread", worker_threads = 4)] async fn zenoh_liveliness() { - use {std::time::Duration, zenoh::internal::ztimeout, zenoh::prelude::*}; + use std::time::Duration; + + use zenoh::{internal::ztimeout, prelude::*}; const TIMEOUT: Duration = Duration::from_secs(60); const SLEEP: Duration = Duration::from_secs(1); diff --git a/zenoh/tests/qos.rs b/zenoh/tests/qos.rs index 6f44b2d0be..3a75cc9f37 100644 --- a/zenoh/tests/qos.rs +++ b/zenoh/tests/qos.rs @@ -12,8 +12,8 @@ // ZettaScale Zenoh Team, // use std::time::Duration; -use zenoh::internal::ztimeout; -use zenoh::prelude::*; + +use zenoh::{internal::ztimeout, prelude::*}; const TIMEOUT: Duration = Duration::from_secs(60); const SLEEP: Duration = Duration::from_secs(1); diff --git a/zenoh/tests/routing.rs b/zenoh/tests/routing.rs index 3c9f2723a6..fac785d7c0 100644 --- a/zenoh/tests/routing.rs +++ b/zenoh/tests/routing.rs @@ -11,14 +11,21 @@ // Contributors: // ZettaScale Zenoh Team, // -use std::str::FromStr; -use std::sync::atomic::Ordering; -use std::sync::{atomic::AtomicUsize, Arc}; -use std::time::Duration; +use std::{ + str::FromStr, + sync::{ + atomic::{AtomicUsize, Ordering}, + Arc, + }, + time::Duration, +}; + use tokio_util::{sync::CancellationToken, task::TaskTracker}; -use zenoh::core::Result; -use zenoh::internal::{bail, ztimeout}; -use zenoh::prelude::*; +use zenoh::{ + core::Result, + internal::{bail, ztimeout}, + prelude::*, +}; const TIMEOUT: Duration = Duration::from_secs(10); const MSG_COUNT: usize = 50; diff --git a/zenoh/tests/session.rs b/zenoh/tests/session.rs index b52dbb90b8..0065a37459 100644 --- a/zenoh/tests/session.rs +++ b/zenoh/tests/session.rs @@ -11,13 +11,17 @@ // Contributors: // ZettaScale Zenoh Team, // -use std::sync::atomic::{AtomicUsize, Ordering}; -use std::sync::Arc; -use std::time::Duration; -use zenoh::internal::ztimeout; -use zenoh::prelude::*; +use std::{ + sync::{ + atomic::{AtomicUsize, Ordering}, + Arc, + }, + time::Duration, +}; + #[cfg(feature = "unstable")] use zenoh::runtime::Runtime; +use zenoh::{internal::ztimeout, prelude::*}; const TIMEOUT: Duration = Duration::from_secs(60); const SLEEP: Duration = Duration::from_secs(1); diff --git a/zenoh/tests/shm.rs b/zenoh/tests/shm.rs index ec77890c1e..14f6985414 100644 --- a/zenoh/tests/shm.rs +++ b/zenoh/tests/shm.rs @@ -13,11 +13,15 @@ // #[cfg(all(feature = "unstable", feature = "shared-memory"))] mod tests { - use std::sync::atomic::{AtomicUsize, Ordering}; - use std::sync::Arc; - use std::time::Duration; - use zenoh::internal::ztimeout; - use zenoh::prelude::*; + use std::{ + sync::{ + atomic::{AtomicUsize, Ordering}, + Arc, + }, + time::Duration, + }; + + use zenoh::{internal::ztimeout, prelude::*}; const TIMEOUT: Duration = Duration::from_secs(60); const SLEEP: Duration = Duration::from_secs(1); diff --git a/zenoh/tests/unicity.rs b/zenoh/tests/unicity.rs index c5be555a00..b62a842b28 100644 --- a/zenoh/tests/unicity.rs +++ b/zenoh/tests/unicity.rs @@ -11,12 +11,16 @@ // Contributors: // ZettaScale Zenoh Team, // -use std::sync::atomic::{AtomicUsize, Ordering}; -use std::sync::Arc; -use std::time::Duration; +use std::{ + sync::{ + atomic::{AtomicUsize, Ordering}, + Arc, + }, + time::Duration, +}; + use tokio::runtime::Handle; -use zenoh::internal::ztimeout; -use zenoh::prelude::*; +use zenoh::{internal::ztimeout, prelude::*}; const TIMEOUT: Duration = Duration::from_secs(60); const SLEEP: Duration = Duration::from_secs(1); diff --git a/zenohd/src/main.rs b/zenohd/src/main.rs index cabee33333..229352e5db 100644 --- a/zenohd/src/main.rs +++ b/zenohd/src/main.rs @@ -14,16 +14,14 @@ use clap::Parser; use futures::future; use git_version::git_version; -use tracing_subscriber::layer::SubscriberExt; -use tracing_subscriber::util::SubscriberInitExt; -use tracing_subscriber::EnvFilter; -use zenoh::config::EndPoint; -use zenoh::config::{Config, ModeDependentValue, PermissionsConf, ValidatedMap}; -use zenoh::core::Result; -use zenoh::scouting::WhatAmI; - +use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter}; #[cfg(feature = "loki")] use url::Url; +use zenoh::{ + config::{Config, EndPoint, ModeDependentValue, PermissionsConf, ValidatedMap}, + core::Result, + scouting::WhatAmI, +}; #[cfg(feature = "loki")] const LOKI_ENDPOINT_VAR: &str = "LOKI_ENDPOINT";