make tun dependency optional (#142)

* remove log crates
* remove udp/raw of smoltcp
* make tun as optional dependancy, compile for freebsd works
This commit is contained in:
Sijie.Sun
2024-06-11 09:09:32 +08:00
committed by GitHub
parent 8aa57ebc22
commit 34f832bbad
26 changed files with 310 additions and 488 deletions
+3
View File
@@ -10,8 +10,11 @@ use super::PeerId;
pub enum Error {
#[error("io error")]
IOError(#[from] io::Error),
#[cfg(feature = "tun")]
#[error("rust tun error {0}")]
TunError(#[from] tun::Error),
#[error("tunnel error {0}")]
TunnelError(#[from] tunnel::TunnelError),
#[error("Peer has no conn, PeerId: {0}")]
+1 -1
View File
@@ -128,7 +128,7 @@ impl GlobalCtx {
if self.event_bus.receiver_count() != 0 {
self.event_bus.send(event).unwrap();
} else {
log::warn!("No subscriber for event: {:?}", event);
tracing::warn!("No subscriber for event: {:?}", event);
}
}
+2 -2
View File
@@ -43,7 +43,7 @@ impl NetNSGuard {
}
let ns = std::fs::File::open(ns_path).unwrap();
log::info!(
tracing::info!(
"[INIT NS] switching to new ns_name: {:?}, ns_file: {:?}",
name,
ns
@@ -59,7 +59,7 @@ impl Drop for NetNSGuard {
if self.old_ns.is_none() {
return;
}
log::info!("[INIT NS] switching back to old ns, ns: {:?}", self.old_ns);
tracing::info!("[INIT NS] switching back to old ns, ns: {:?}", self.old_ns);
setns(
self.old_ns.as_ref().unwrap().as_fd(),
CloneFlags::CLONE_NEWNET,
+1 -1
View File
@@ -51,7 +51,7 @@ impl InterfaceFilter {
}
}
#[cfg(target_os = "macos")]
#[cfg(any(target_os = "macos", target_os = "freebsd"))]
impl InterfaceFilter {
async fn is_interface_physical(interface_name: &str) -> bool {
let output = tokio::process::Command::new("networksetup")