From 1275069eda9fe19160f1d06b1017b84c15f3a089 Mon Sep 17 00:00:00 2001 From: Jackson Coxson Date: Sun, 29 May 2022 02:36:54 -0600 Subject: [PATCH] Add option to disable mDNS --- src/handle.rs | 1 + src/main.rs | 28 ++++++++++++++++++++-------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/handle.rs b/src/handle.rs index 155686c..44316d0 100644 --- a/src/handle.rs +++ b/src/handle.rs @@ -94,6 +94,7 @@ pub async fn instruction( .get_string_val()?; match packet_type.as_str() { "AddDevice" => { + info!("Adding manual device"); let connection_type = packet .plist .clone() diff --git a/src/main.rs b/src/main.rs index 5fd2112..272e809 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,6 +27,7 @@ async fn main() { let mut host = None; let mut plist_storage = None; let mut use_unix = true; + let mut use_mdns = true; // Loop through args let mut i = 0; @@ -48,6 +49,10 @@ async fn main() { use_unix = false; i += 1; } + "--disable-mdns" => { + use_mdns = false; + i += 1; + } "-h" | "--help" => { println!("netmuxd - a network multiplexer"); println!("Usage:"); @@ -76,12 +81,6 @@ async fn main() { info!("Created new central data"); let data_clone = data.clone(); - let local = tokio::task::LocalSet::new(); - local.spawn_local(async move { - mdns::discover(data_clone).await; - error!("mDNS discovery stopped, how the heck did you break this"); - }); - if let Some(host) = host { let tcp_data = data.clone(); tokio::spawn(async move { @@ -241,6 +240,7 @@ async fn main() { } let parsed: raw_packet::RawPacket = buffer.into(); + info!("Parsed packet: {:?}", parsed); if parsed.message == 69 && parsed.tag == 69 { match instruction(parsed, cloned_data.clone()).await { @@ -280,6 +280,18 @@ async fn main() { } }); } - local.await; - error!("mDNS discovery stopped"); + if use_mdns { + let local = tokio::task::LocalSet::new(); + local.spawn_local(async move { + mdns::discover(data_clone).await; + error!("mDNS discovery stopped, how the heck did you break this"); + }); + local.await; + error!("mDNS discovery stopped"); + } else { + loop { + tokio::time::sleep(std::time::Duration::from_secs(10)).await; + } + } + }