Skip to content

Commit

Permalink
Add a feature flag for disabling heartbeat
Browse files Browse the repository at this point in the history
  • Loading branch information
jkcoxson committed Jan 8, 2025
1 parent b54f1c4 commit 0f77301
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
16 changes: 13 additions & 3 deletions src/devices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub struct SharedDevices {
pub last_index: u64,
pub last_interface_index: u64,
plist_storage: String,
use_heartbeat: bool,
known_mac_addresses: HashMap<String, String>,
paired_udids: Vec<String>,
}
Expand All @@ -42,7 +43,7 @@ pub struct MuxerDevice {
}

impl SharedDevices {
pub fn new(plist_storage: Option<String>) -> Self {
pub fn new(plist_storage: Option<String>, use_heartbeat: bool) -> Self {
let plist_storage = if let Some(plist_storage) = plist_storage {
info!("Plist storage specified, ensure the environment is aware");
plist_storage
Expand Down Expand Up @@ -71,6 +72,7 @@ impl SharedDevices {
last_index: 0,
last_interface_index: 0,
plist_storage,
use_heartbeat,
known_mac_addresses: HashMap::new(),
paired_udids: Vec::new(),
}
Expand All @@ -90,7 +92,15 @@ impl SharedDevices {
self.last_index += 1;
self.last_interface_index += 1;

let handle = heartbeat::heartbeat(udid.to_string(), network_address, data);
let handle = if self.use_heartbeat {
Some(heartbeat::heartbeat(
udid.to_string(),
network_address,
data,
))
} else {
None
};

let dev = MuxerDevice {
connection_type,
Expand All @@ -99,7 +109,7 @@ impl SharedDevices {
interface_index: self.last_interface_index,
network_address: Some(network_address),
serial_number: udid.clone(),
heartbeat_handle: Some(handle),
heartbeat_handle: handle,
connection_speed: None,
location_id: None,
product_id: None,
Expand Down
13 changes: 11 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ async fn main() {
#[cfg(windows)]
let mut host = Some("localhost".to_string());
let mut plist_storage = None;
let mut use_heartbeat = true;

#[cfg(unix)]
let mut use_unix = true;
Expand Down Expand Up @@ -71,6 +72,10 @@ async fn main() {
use_usb = true;
i += 1;
}
"--disable-heartbeat" => {
use_heartbeat = false;
i += 1;
}
"-h" | "--help" => {
println!("netmuxd - a network multiplexer");
println!("Usage:");
Expand All @@ -79,6 +84,7 @@ async fn main() {
println!(" -p, --port <port>");
println!(" --host <host>");
println!(" --plist-storage <path>");
println!(" --disable-heartbeat");
#[cfg(unix)]
println!(" --disable-unix");
println!(" --disable-mdns");
Expand All @@ -101,7 +107,10 @@ async fn main() {
}
info!("Collected arguments, proceeding");

let data = Arc::new(Mutex::new(devices::SharedDevices::new(plist_storage)));
let data = Arc::new(Mutex::new(devices::SharedDevices::new(
plist_storage,
use_heartbeat,
)));
info!("Created new central data");
let data_clone = data.clone();
#[cfg(feature = "usb")]
Expand Down Expand Up @@ -317,7 +326,7 @@ async fn handle_stream(
.get_string_val()
.unwrap();

let central_data = data.lock().await;
let mut central_data = data.lock().await;
central_data.remove_device(udid);
return;
}
Expand Down

0 comments on commit 0f77301

Please sign in to comment.