Skip to content

Commit

Permalink
Add option to disable mDNS
Browse files Browse the repository at this point in the history
  • Loading branch information
jkcoxson committed May 29, 2022
1 parent 01cc291 commit 1275069
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
28 changes: 20 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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:");
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
}

}

0 comments on commit 1275069

Please sign in to comment.