Skip to content

Commit

Permalink
tags
Browse files Browse the repository at this point in the history
  • Loading branch information
milyin committed Feb 19, 2024
1 parent 52490a1 commit 3ba31a6
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 7 deletions.
16 changes: 16 additions & 0 deletions commons/zenoh-buffers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,15 @@
#![cfg_attr(not(feature = "std"), no_std)]
extern crate alloc;

// ignore_tagging
mod bbuf;
// ignore_tagging
mod slice;
// ignore_tagging
pub mod vec;
// ignore_tagging
mod zbuf;
// ignore_tagging
mod zslice;

pub use bbuf::*;
Expand Down Expand Up @@ -72,6 +77,7 @@ macro_rules! unsafe_slice_mut {
};
}

// tags{}
pub mod buffer {
use alloc::{borrow::Cow, vec::Vec};

Expand All @@ -86,6 +92,7 @@ pub mod buffer {
}

/// A trait for buffers that can be composed of multiple non contiguous slices.
// tags{}
pub trait SplitBuffer: Buffer {
type Slices<'a>: Iterator<Item = &'a [u8]> + ExactSizeIterator
where
Expand Down Expand Up @@ -116,6 +123,7 @@ pub mod writer {
use core::num::NonZeroUsize;

#[derive(Debug, Clone, Copy)]
// tags{}
pub struct DidntWrite;

pub trait Writer {
Expand All @@ -134,18 +142,21 @@ pub mod writer {
}
/// Provides a buffer of exactly `len` uninitialized bytes to `f` to allow in-place writing.
/// `f` must return the number of bytes it actually wrote.
// tags{}
fn with_slot<F>(&mut self, len: usize, f: F) -> Result<NonZeroUsize, DidntWrite>
where
F: FnOnce(&mut [u8]) -> usize;
}

// tags{}
pub trait BacktrackableWriter: Writer {
type Mark;

fn mark(&mut self) -> Self::Mark;
fn rewind(&mut self, mark: Self::Mark) -> bool;
}

// tags{}
pub trait HasWriter {
type Writer: Writer;

Expand All @@ -159,6 +170,7 @@ pub mod reader {
use core::num::NonZeroUsize;

#[derive(Debug, Clone, Copy)]
// tags{}
pub struct DidntRead;

pub trait Reader {
Expand Down Expand Up @@ -191,6 +203,7 @@ pub mod reader {
}
}

// tags{}
pub trait BacktrackableReader: Reader {
type Mark;

Expand All @@ -199,14 +212,17 @@ pub mod reader {
}

#[derive(Debug, Clone, Copy)]
// tags{}
pub struct DidntSiphon;

// tags{}
pub trait SiphonableReader: Reader {
fn siphon<W>(&mut self, writer: &mut W) -> Result<NonZeroUsize, DidntSiphon>
where
W: crate::writer::Writer;
}

// tags{}
pub trait HasReader {
type Reader: Reader;

Expand Down
2 changes: 1 addition & 1 deletion commons/zenoh-buffers/src/zbuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ impl<'a> SiphonableReader for ZBufReader<'a> {

#[cfg(feature = "std")]
impl<'a> std::io::Read for ZBufReader<'a> {
// tags{rust.zbuf_reader.read api.buffer.read}
// tags{rust.zbuf_reader.read, api.buffer.read}
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
match <Self as Reader>::read(self, buf) {
Ok(n) => Ok(n.get()),
Expand Down
1 change: 1 addition & 0 deletions commons/zenoh-config/src/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
//
use super::*;

// tag{}
pub const ENV: &str = "ZENOH_CONFIG";

macro_rules! mode_accessor {
Expand Down
42 changes: 42 additions & 0 deletions commons/zenoh-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
//

//! Configuration to pass to `zenoh::open()` and `zenoh::scout()` functions and associated constants.
// ignore_tagging
pub mod defaults;
mod include;
use include::recursive_include;
Expand Down Expand Up @@ -48,6 +49,7 @@ use zenoh_result::{bail, zerror, ZResult};
use zenoh_util::LibLoader;

// Wrappers for secrecy of values
// tags{}
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
pub struct SecretString(String);

Expand All @@ -70,6 +72,7 @@ impl Zeroize for SecretString {

pub type SecretValue = Secret<SecretString>;

// tags{}
pub trait ConfigValidator: Send + Sync {
fn check_config(
&self,
Expand All @@ -87,23 +90,27 @@ pub trait ConfigValidator: Send + Sync {
impl ConfigValidator for () {}

/// Creates an empty zenoh net Session configuration.
// tags{rust.config.empty, api.config.create.empty}
pub fn empty() -> Config {
Config::default()
}

/// Creates a default zenoh net Session configuration (equivalent to `peer`).
// tags{rust.config.default, api.config.create.default}
pub fn default() -> Config {
peer()
}

/// Creates a default `'peer'` mode zenoh net Session configuration.
// tags{rust.config.peer, api.config.create.peer}
pub fn peer() -> Config {
let mut config = Config::default();
config.set_mode(Some(WhatAmI::Peer)).unwrap();
config
}

/// Creates a default `'client'` mode zenoh net Session configuration.
// tags{rust.config.client, api.config.create.client}
pub fn client<I: IntoIterator<Item = T>, T: Into<EndPoint>>(peers: I) -> Config {
let mut config = Config::default();
config.set_mode(Some(WhatAmI::Client)).unwrap();
Expand Down Expand Up @@ -141,6 +148,7 @@ validated_struct::validator! {
#[derive(serde::Deserialize, serde::Serialize, Clone, Debug)]
#[serde(default)]
#[serde(deny_unknown_fields)]
// tags{rust.config. api.config}
Config {
/// The Zenoh ID of the instance. This ID MUST be unique throughout your Zenoh infrastructure and cannot exceed 16 bytes of length. If left unset, a random u128 will be generated.
id: ZenohId,
Expand All @@ -149,22 +157,26 @@ validated_struct::validator! {
/// The node's mode ("router" (default value in `zenohd`), "peer" or "client").
mode: Option<whatami::WhatAmI>,
/// Which zenoh nodes to connect to.
// tags{rust.config.connect, api.config.connect}
pub connect: #[derive(Default)]
ConnectConfig {
pub endpoints: Vec<EndPoint>,
},
/// Which endpoints to listen on. `zenohd` will add `tcp/[::]:7447` to these locators if left empty.
// tags{rust.config.listen, api.config.listen}
pub listen: #[derive(Default)]
ListenConfig {
pub endpoints: Vec<EndPoint>,
},
// tags{rust.config.scouting, api.config.scouting}
pub scouting: #[derive(Default)]
ScoutingConf {
/// In client mode, the period dedicated to scouting for a router before failing. In milliseconds.
timeout: Option<u64>,
/// In peer mode, the period dedicated to scouting remote peers before attempting other operations. In milliseconds.
delay: Option<u64>,
/// The multicast scouting configuration.
// tags{rust.config.scouting.multicast, api.config.scouting.multicast}
pub multicast: #[derive(Default)]
ScoutingMulticastConf {
/// Whether multicast scouting is enabled or not. If left empty, `zenohd` will set it according to the presence of the `--no-multicast-scouting` argument.
Expand All @@ -180,6 +192,7 @@ validated_struct::validator! {
listen: Option<ModeDependentValue<bool>>,
},
/// The gossip scouting configuration.
// tags{rust.config.scouting.gossip, api.config.scouting.gossip}
pub gossip: #[derive(Default)]
GossipConf {
/// Whether gossip scouting is enabled or not.
Expand All @@ -197,6 +210,7 @@ validated_struct::validator! {
},

/// Configuration of data messages timestamps management.
// tags{rust.config.timestamping, api.config.timestamping}
pub timestamping: #[derive(Default)]
TimestampingConf {
/// Whether data messages should be timestamped if not already.
Expand All @@ -211,9 +225,11 @@ validated_struct::validator! {
queries_default_timeout: Option<u64>,

/// The routing strategy to use and it's configuration.
// tags{rust.config.routing, api.config.routing}
pub routing: #[derive(Default)]
RoutingConf {
/// The routing strategy to use in routers and it's configuration.
// tags{rust.config.routing.router, api.config.routing.router}
pub router: #[derive(Default)]
RouterRoutingConf {
/// When set to true a router will forward data between two peers
Expand All @@ -223,6 +239,7 @@ validated_struct::validator! {
peers_failover_brokering: Option<bool>,
},
/// The routing strategy to use in peers and it's configuration.
// tags{rust.config.routing.peer, api.config.routing.peer}
pub peer: #[derive(Default)]
PeerRoutingConf {
/// The routing strategy to use in peers. ("peer_to_peer" or "linkstate").
Expand All @@ -231,15 +248,18 @@ validated_struct::validator! {
},

/// The declarations aggregation strategy.
// tags{rust.config.aggregation, api.config.aggregation}
pub aggregation: #[derive(Default)]
AggregationConf {
/// A list of key-expressions for which all included subscribers will be aggregated into.
subscribers: Vec<OwnedKeyExpr>,
/// A list of key-expressions for which all included publishers will be aggregated into.
publishers: Vec<OwnedKeyExpr>,
},
// tags{rust.config.transport, api.config.transport}
pub transport: #[derive(Default)]
TransportConf {
// tags{rust.config.transport.unicast, api.config.transport.unicast}
pub unicast: TransportUnicastConf {
/// Timeout in milliseconds when opening a link (default: 10000).
accept_timeout: u64,
Expand All @@ -253,38 +273,46 @@ validated_struct::validator! {
/// This option does not make LowLatency transport mandatory, the actual implementation of transport
/// used will depend on Establish procedure and other party's settings
lowlatency: bool,
// tags{rust.config.transport.unicast.qos, api.config.transport.unicast.qos}
pub qos: QoSUnicastConf {
/// Whether QoS is enabled or not.
/// If set to `false`, the QoS will be disabled. (default `true`).
enabled: bool
},
// tags{rust.config.transport.unicast.compression, api.config.transport.unicast.compression}
pub compression: CompressionUnicastConf {
/// You must compile zenoh with "transport_compression" feature to be able to enable compression.
/// When enabled is true, batches will be sent compressed. (default `false`).
enabled: bool,
},
},
// tags{rust.config.transport.multicast, api.config.transport.multicast}
pub multicast: TransportMulticastConf {
/// Link join interval duration in milliseconds (default: 2500)
join_interval: Option<u64>,
/// Maximum number of multicast sessions (default: 1000)
max_sessions: Option<usize>,
// tags{rust.config.transport.multicast.qos, api.config.transport.multicast.qos}
pub qos: QoSMulticastConf {
/// Whether QoS is enabled or not.
/// If set to `false`, the QoS will be disabled. (default `false`).
enabled: bool
},
// tags{rust.config.transport.multicast.compression, api.config.transport.multicast.compression}
pub compression: CompressionMulticastConf {
/// You must compile zenoh with "transport_compression" feature to be able to enable compression.
/// When enabled is true, batches will be sent compressed. (default `false`).
enabled: bool,
},
},
// tags{rust.config.transport.link, api.config.transport.link}
pub link: #[derive(Default)]
TransportLinkConf {
// An optional whitelist of protocols to be used for accepting and opening sessions.
// If not configured, all the supported protocols are automatically whitelisted.
// tags{rust.config.transport.link.protocols, api.config.transport.link.protocols}
pub protocols: Option<Vec<String>>,
// tags{rust.config.transport.link.tx, api.config.transport.link.tx}
pub tx: LinkTxConf {
/// The resolution in bits to be used for the message sequence numbers.
/// When establishing a session with another Zenoh instance, the lowest value of the two instances will be used.
Expand All @@ -296,12 +324,14 @@ validated_struct::validator! {
keep_alive: usize,
/// Zenoh's MTU equivalent (default: 2^16-1)
batch_size: BatchSize,
// tags{rust.config.transport.link.tx.queue, api.config.transport.link.tx.queue}
pub queue: QueueConf {
/// The size of each priority queue indicates the number of batches a given queue can contain.
/// The amount of memory being allocated for each queue is then SIZE_XXX * BATCH_SIZE.
/// In the case of the transport link MTU being smaller than the ZN_BATCH_SIZE,
/// then amount of memory being allocated for each queue is SIZE_XXX * LINK_MTU.
/// If qos is false, then only the DATA priority will be allocated.
// tags{rust.config.transport.link.tx.queue.size, api.config.transport.link.tx.queue.size}
pub size: QueueSizeConf {
control: usize,
real_time: usize,
Expand All @@ -319,6 +349,7 @@ validated_struct::validator! {
// Number of threads used for TX
threads: usize,
},
// tags{rust.config.transport.link.rx, api.config.transport.link.rx}
pub rx: LinkRxConf {
/// Receiving buffer size in bytes for each link
/// The default the rx_buffer_size value is the same as the default batch size: 65335.
Expand All @@ -330,6 +361,7 @@ validated_struct::validator! {
/// Fragmented messages that are larger than the configured size will be dropped.
max_message_size: usize,
},
// tags{rust.config.transport.link.tls, api.config.transport.link.tls}
pub tls: #[derive(Default)]
TLSConf {
root_ca_certificate: Option<String>,
Expand All @@ -351,29 +383,34 @@ validated_struct::validator! {
#[serde(skip_serializing)]
client_certificate_base64 : Option<SecretValue>,
},
// tags{rust.config.transport.link.unixpipe, api.config.transport.link.unixpipe}
pub unixpipe: #[derive(Default)]
UnixPipeConf {
file_access_mask: Option<u32>
},
},
// tags{rust.config.transport.shared_memory, api.config.transport.shared_memory}
pub shared_memory:
SharedMemoryConf {
/// Whether shared memory is enabled or not.
/// If set to `true`, the SHM buffer optimization support will be announced to other parties. (default `false`).
/// This option doesn't make SHM buffer optimization mandatory, the real support depends on other party setting
enabled: bool,
},
// tags{rust.config.transport.auth, api.config.transport.auth}
pub auth: #[derive(Default)]
AuthConf {
/// The configuration of authentification.
/// A password implies a username is required.
// tags{rust.config.transport.auth.usrpwd, api.config.transport.auth.usrpwd}
pub usrpwd: #[derive(Default)]
UsrPwdConf {
user: Option<String>,
password: Option<String>,
/// The path to a file containing the user password dictionary, a file containing `<user>:<password>`
dictionary_file: Option<String>,
} where (user_conf_validator),
// tags{rust.config.transport.auth.pubkey, api.config.transport.auth.pubkey}
pub pubkey: #[derive(Default)]
PubKeyConf {
public_key_pem: Option<String>,
Expand All @@ -386,6 +423,7 @@ validated_struct::validator! {
},
},
/// Configuration of the admin space.
// tags{rust.config.adminspace, api.config.adminspace}
pub adminspace: #[derive(Default)]
/// <div class="stab unstable">
/// <span class="emoji">🔬</span>
Expand All @@ -394,12 +432,15 @@ validated_struct::validator! {
/// </div>
AdminSpaceConf {
/// Permissions on the admin space
// tags{rust.config.adminspace.permissions, api.config.adminspace.permissions}
pub permissions:
PermissionsConf {
/// Whether the admin space replies to queries (true by default).
// tags{rust.config.adminspace.permissions.read, api.config.adminspace.permissions.read}
#[serde(default = "set_true")]
pub read: bool,
/// Whether the admin space accepts config changes at runtime (false by default).
// tags{rust.config.adminspace.permissions.write, api.config.adminspace.permissions.write}
#[serde(default = "set_false")]
pub write: bool,
},
Expand Down Expand Up @@ -432,6 +473,7 @@ fn set_false() -> bool {
false
}

// tags{}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct PluginSearchDirs(Vec<String>);
impl Default for PluginSearchDirs {
Expand Down
Loading

0 comments on commit 3ba31a6

Please sign in to comment.