zenoh_link_unixpipe/unix/
mod.rs

1//
2// Copyright (c) 2023 ZettaScale Technology
3//
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
7// which is available at https://www.apache.org/licenses/LICENSE-2.0.
8//
9// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
10//
11// Contributors:
12//   ZettaScale Zenoh Team, <zenoh@zettascale.tech>
13//
14
15//! ⚠️ WARNING ⚠️
16//!
17//! This crate is intended for Zenoh's internal use.
18//!
19//! [Click here for Zenoh's documentation](https://docs.rs/zenoh/latest/zenoh)
20pub mod unicast;
21
22use std::str::FromStr;
23
24use async_trait::async_trait;
25pub use unicast::*;
26use zenoh_config::Config;
27use zenoh_core::zconfigurable;
28use zenoh_link_commons::{ConfigurationInspector, LocatorInspector};
29use zenoh_protocol::core::{parameters, Locator, Metadata, Reliability};
30use zenoh_result::ZResult;
31
32pub const UNIXPIPE_LOCATOR_PREFIX: &str = "unixpipe";
33
34const IS_RELIABLE: bool = true;
35
36#[derive(Default, Clone, Copy)]
37pub struct UnixPipeLocatorInspector;
38#[async_trait]
39impl LocatorInspector for UnixPipeLocatorInspector {
40    fn protocol(&self) -> &str {
41        UNIXPIPE_LOCATOR_PREFIX
42    }
43
44    async fn is_multicast(&self, _locator: &Locator) -> ZResult<bool> {
45        Ok(false)
46    }
47
48    fn is_reliable(&self, locator: &Locator) -> ZResult<bool> {
49        if let Some(reliability) = locator
50            .metadata()
51            .get(Metadata::RELIABILITY)
52            .map(Reliability::from_str)
53            .transpose()?
54        {
55            Ok(reliability == Reliability::Reliable)
56        } else {
57            Ok(IS_RELIABLE)
58        }
59    }
60}
61
62#[derive(Default, Clone, Copy, Debug)]
63pub struct UnixPipeConfigurator;
64
65impl ConfigurationInspector<Config> for UnixPipeConfigurator {
66    fn inspect_config(&self, config: &Config) -> ZResult<String> {
67        let mut properties: Vec<(&str, &str)> = vec![];
68
69        let c = config.transport().link().unixpipe();
70        let file_access_mask_;
71        if let Some(file_access_mask) = c.file_access_mask() {
72            file_access_mask_ = file_access_mask.to_string();
73            properties.push((config::FILE_ACCESS_MASK, &file_access_mask_));
74        }
75
76        let s = parameters::from_iter(properties.drain(..));
77
78        Ok(s)
79    }
80}
81
82zconfigurable! {
83    // Default access mask for pipe files
84    static ref FILE_ACCESS_MASK: u32 = config::FILE_ACCESS_MASK_DEFAULT;
85}
86
87pub mod config {
88    pub const FILE_ACCESS_MASK: &str = "file_mask";
89    pub const FILE_ACCESS_MASK_DEFAULT: u32 = 0o777;
90}