zenoh_link_unixpipe/unix/
mod.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//
// 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, <zenoh@zettascale.tech>
//

//! ⚠️ WARNING ⚠️
//!
//! This crate is intended for Zenoh's internal use.
//!
//! [Click here for Zenoh's documentation](https://docs.rs/zenoh/latest/zenoh)
pub mod unicast;

use std::str::FromStr;

use async_trait::async_trait;
pub use unicast::*;
use zenoh_config::Config;
use zenoh_core::zconfigurable;
use zenoh_link_commons::{ConfigurationInspector, LocatorInspector};
use zenoh_protocol::core::{parameters, Locator, Metadata, Reliability};
use zenoh_result::ZResult;

pub const UNIXPIPE_LOCATOR_PREFIX: &str = "unixpipe";

const IS_RELIABLE: bool = true;

#[derive(Default, Clone, Copy)]
pub struct UnixPipeLocatorInspector;
#[async_trait]
impl LocatorInspector for UnixPipeLocatorInspector {
    fn protocol(&self) -> &str {
        UNIXPIPE_LOCATOR_PREFIX
    }

    async fn is_multicast(&self, _locator: &Locator) -> ZResult<bool> {
        Ok(false)
    }

    fn is_reliable(&self, locator: &Locator) -> ZResult<bool> {
        if let Some(reliability) = locator
            .metadata()
            .get(Metadata::RELIABILITY)
            .map(Reliability::from_str)
            .transpose()?
        {
            Ok(reliability == Reliability::Reliable)
        } else {
            Ok(IS_RELIABLE)
        }
    }
}

#[derive(Default, Clone, Copy, Debug)]
pub struct UnixPipeConfigurator;

impl ConfigurationInspector<Config> for UnixPipeConfigurator {
    fn inspect_config(&self, config: &Config) -> ZResult<String> {
        let mut properties: Vec<(&str, &str)> = vec![];

        let c = config.transport().link().unixpipe();
        let file_access_mask_;
        if let Some(file_access_mask) = c.file_access_mask() {
            file_access_mask_ = file_access_mask.to_string();
            properties.push((config::FILE_ACCESS_MASK, &file_access_mask_));
        }

        let s = parameters::from_iter(properties.drain(..));

        Ok(s)
    }
}

zconfigurable! {
    // Default access mask for pipe files
    static ref FILE_ACCESS_MASK: u32 = config::FILE_ACCESS_MASK_DEFAULT;
}

pub mod config {
    pub const FILE_ACCESS_MASK: &str = "file_mask";
    pub const FILE_ACCESS_MASK_DEFAULT: u32 = 0o777;
}