Skip to content

Commit

Permalink
Move get_ip_interface_names to commons
Browse files Browse the repository at this point in the history
  • Loading branch information
sashacmc committed Feb 22, 2024
1 parent a417356 commit 7118f0f
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 50 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions io/zenoh-link-commons/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ zenoh-sync = { workspace = true }
async-trait = { workspace = true }
flume = { workspace = true }
lz4_flex = { workspace = true }
log = { workspace = true }
serde = { workspace = true, features = ["default"] }
typenum = { workspace = true }
zenoh-buffers = { workspace = true }
Expand Down
14 changes: 14 additions & 0 deletions io/zenoh-link-commons/src/unicast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// ZettaScale Zenoh Team, <[email protected]>
//
use alloc::{boxed::Box, string::String, sync::Arc, vec::Vec};
use async_std::net::SocketAddr;
use async_trait::async_trait;
use core::{
fmt,
Expand Down Expand Up @@ -100,3 +101,16 @@ impl From<Arc<dyn LinkUnicastTrait>> for LinkUnicast {
LinkUnicast(link)
}
}

pub fn get_ip_interface_names(addr: &SocketAddr) -> Vec<String> {
match zenoh_util::net::get_interface_names_by_addr(addr.ip()) {
Ok(interfaces) => {
log::trace!("get_interface_names for {:?}: {:?}", addr.ip(), interfaces);
interfaces
}
Err(e) => {
log::debug!("get_interface_names for {:?} failed: {:?}", addr.ip(), e);
vec![]
}
}
}
8 changes: 3 additions & 5 deletions io/zenoh-links/zenoh-link-quic/src/unicast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ use std::sync::Arc;
use std::time::Duration;
use zenoh_core::zasynclock;
use zenoh_link_commons::{
LinkManagerUnicastTrait, LinkUnicast, LinkUnicastTrait, ListenersUnicastIP,
NewLinkChannelSender,
get_ip_interface_names, LinkManagerUnicastTrait, LinkUnicast, LinkUnicastTrait,
ListenersUnicastIP, NewLinkChannelSender,
};
use zenoh_protocol::core::{EndPoint, Locator};
use zenoh_result::{bail, zerror, ZError, ZResult};
Expand Down Expand Up @@ -144,9 +144,7 @@ impl LinkUnicastTrait for LinkUnicastQuic {

#[inline(always)]
fn get_interface_names(&self) -> Vec<String> {
// @TODO: Not supported for now
log::debug!("The get_interface_names for LinkUnicastQuic is not supported");
vec![]
get_ip_interface_names(&self.src_addr)
}

#[inline(always)]
Expand Down
23 changes: 3 additions & 20 deletions io/zenoh-links/zenoh-link-tcp/src/unicast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::time::Duration;
use zenoh_link_commons::{
LinkManagerUnicastTrait, LinkUnicast, LinkUnicastTrait, ListenersUnicastIP,
NewLinkChannelSender,
get_ip_interface_names, LinkManagerUnicastTrait, LinkUnicast, LinkUnicastTrait,
ListenersUnicastIP, NewLinkChannelSender,
};
use zenoh_protocol::core::{EndPoint, Locator};
use zenoh_result::{bail, zerror, Error as ZError, ZResult};
Expand Down Expand Up @@ -144,24 +144,7 @@ impl LinkUnicastTrait for LinkUnicastTcp {

#[inline(always)]
fn get_interface_names(&self) -> Vec<String> {
match zenoh_util::net::get_interface_names_by_addr(self.src_addr.ip()) {
Ok(interfaces) => {
log::trace!(
"get_interface_names for {:?}: {:?}",
self.src_addr.ip(),
interfaces
);
interfaces
}
Err(e) => {
log::debug!(
"get_interface_names for {:?} failed: {:?}",
self.src_addr.ip(),
e
);
vec![]
}
}
get_ip_interface_names(&self.src_addr)
}

#[inline(always)]
Expand Down
8 changes: 3 additions & 5 deletions io/zenoh-links/zenoh-link-tls/src/unicast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ use webpki::{
};
use zenoh_core::zasynclock;
use zenoh_link_commons::{
LinkManagerUnicastTrait, LinkUnicast, LinkUnicastTrait, ListenersUnicastIP,
NewLinkChannelSender,
get_ip_interface_names, LinkManagerUnicastTrait, LinkUnicast, LinkUnicastTrait,
ListenersUnicastIP, NewLinkChannelSender,
};
use zenoh_protocol::core::endpoint::Config;
use zenoh_protocol::core::{EndPoint, Locator};
Expand Down Expand Up @@ -196,9 +196,7 @@ impl LinkUnicastTrait for LinkUnicastTls {

#[inline(always)]
fn get_interface_names(&self) -> Vec<String> {
// @TODO: Not supported for now
log::debug!("The get_interface_names for LinkUnicastTls is not supported");
vec![]
get_ip_interface_names(&self.src_addr)
}

#[inline(always)]
Expand Down
23 changes: 3 additions & 20 deletions io/zenoh-links/zenoh-link-udp/src/unicast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ use std::sync::{Arc, Mutex, Weak};
use std::time::Duration;
use zenoh_core::{zasynclock, zlock};
use zenoh_link_commons::{
ConstructibleLinkManagerUnicast, LinkManagerUnicastTrait, LinkUnicast, LinkUnicastTrait,
ListenersUnicastIP, NewLinkChannelSender,
get_ip_interface_names, ConstructibleLinkManagerUnicast, LinkManagerUnicastTrait, LinkUnicast,
LinkUnicastTrait, ListenersUnicastIP, NewLinkChannelSender,
};
use zenoh_protocol::core::{EndPoint, Locator};
use zenoh_result::{bail, zerror, Error as ZError, ZResult};
Expand Down Expand Up @@ -208,24 +208,7 @@ impl LinkUnicastTrait for LinkUnicastUdp {

#[inline(always)]
fn get_interface_names(&self) -> Vec<String> {
match zenoh_util::net::get_interface_names_by_addr(self.src_addr.ip()) {
Ok(interfaces) => {
log::trace!(
"get_interface_names for {:?}: {:?}",
self.src_addr.ip(),
interfaces
);
interfaces
}
Err(e) => {
log::debug!(
"get_interface_names for {:?} failed: {:?}",
self.src_addr.ip(),
e
);
vec![]
}
}
get_ip_interface_names(&self.src_addr)
}

#[inline(always)]
Expand Down

0 comments on commit 7118f0f

Please sign in to comment.