1use std::str::FromStr;
23
24use async_trait::async_trait;
25use zenoh_core::zconfigurable;
26use zenoh_link_commons::LocatorInspector;
27use zenoh_protocol::{
28 core::{Locator, Metadata, Reliability},
29 transport::BatchSize,
30};
31use zenoh_result::ZResult;
32
33#[cfg(target_os = "linux")]
34mod unicast;
35#[cfg(target_os = "linux")]
36pub use unicast::*;
37
38pub const VSOCK_LOCATOR_PREFIX: &str = "vsock";
39
40const IS_RELIABLE: bool = true;
41
42#[derive(Default, Clone, Copy)]
43pub struct VsockLocatorInspector;
44#[async_trait]
45impl LocatorInspector for VsockLocatorInspector {
46 fn protocol(&self) -> &str {
47 VSOCK_LOCATOR_PREFIX
48 }
49
50 async fn is_multicast(&self, _locator: &Locator) -> ZResult<bool> {
51 Ok(false)
52 }
53
54 fn is_reliable(&self, locator: &Locator) -> ZResult<bool> {
55 if let Some(reliability) = locator
56 .metadata()
57 .get(Metadata::RELIABILITY)
58 .map(Reliability::from_str)
59 .transpose()?
60 {
61 Ok(reliability == Reliability::Reliable)
62 } else {
63 Ok(IS_RELIABLE)
64 }
65 }
66}
67
68zconfigurable! {
69 static ref VSOCK_DEFAULT_MTU: BatchSize = BatchSize::MAX;
71 static ref VSOCK_ACCEPT_THROTTLE_TIME: u64 = 100_000;
74}