Skip to content

Commit

Permalink
Add more trace logging
Browse files Browse the repository at this point in the history
  • Loading branch information
jkcoxson committed Jan 7, 2025
1 parent 0cd929c commit 3a23670
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
18 changes: 11 additions & 7 deletions src/devices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,18 @@ impl SharedDevices {
}
}
};
let mac_addr = match plist.clone().dict_get_item("WiFiMACAddress") {
Ok(item) => match item.get_string_val() {
Ok(val) => val,
Err(_) => {
warn!("Could not get string value of WiFiMACAddress");
continue;
let wifi_plist = plist.clone();
let mac_addr = match wifi_plist.dict_get_item("WiFiMACAddress") {
Ok(item) => {
log::debug!("WiFi plist item: {:?}", item.get_string_val());
match item.get_string_val() {
Ok(val) => val,
Err(e) => {
warn!("Could not get string value of WiFiMACAddress: {e:?}");
continue;
}
}
},
}
Err(_) => {
warn!("Plist did not contain WiFiMACAddress");
continue;
Expand Down
8 changes: 6 additions & 2 deletions src/heartbeat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub fn heartbeat(
let pls_stop_clone = pls_stop.clone();
tokio::task::spawn_blocking(move || {
let device = idevice::Device::new(udid.clone(), Some(ip_addr), 0);
log::debug!("Created device struct {udid}");
let hb_client = match HeartbeatClient::new(&device, "netmuxd".to_string()) {
Ok(hb_client) => hb_client,
Err(e) => {
Expand All @@ -33,15 +34,18 @@ pub fn heartbeat(
return;
}
};
log::debug!("Created device heartbeat client for {udid}");

let mut heartbeat_tries = 0;
loop {
match hb_client.receive(10000) {
Ok(plist) => match hb_client.send(plist) {
Ok(_) => {
log::debug!("Heartbeat recv {udid}");
heartbeat_tries = 0;
}
Err(_) => {
Err(e) => {
info!("Heartbeat send failed for {}: {:?}", udid, e);
tokio::spawn(async move {
remove_from_data(data, udid).await;
});
Expand All @@ -51,7 +55,7 @@ pub fn heartbeat(
Err(e) => {
heartbeat_tries += 1;
if heartbeat_tries > 5 {
info!("Heartbeat failed for {}: {:?}", udid, e);
info!("Heartbeat recv failed for {}: {:?}", udid, e);
tokio::spawn(async move {
remove_from_data(data, udid).await;
});
Expand Down
8 changes: 6 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{fs, os::unix::prelude::PermissionsExt};

use crate::raw_packet::RawPacket;
use devices::SharedDevices;
use log::{error, info, warn};
use log::{error, info, trace, warn};
use plist_plus::Plist;
use tokio::{
io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt},
Expand Down Expand Up @@ -199,14 +199,16 @@ async fn handle_stream(
loop {
// Wait for a message from the client
let mut buf = [0; 1024];
trace!("Waiting for data from client...");
let size = match socket.read(&mut buf).await {
Ok(s) => s,
Err(_) => {
return;
}
};
trace!("Recv'd {size} bytes");
if size == 0 {
info!("Unix size is zero, closing connection");
info!("Received size is zero, closing connection");
return;
}

Expand Down Expand Up @@ -252,6 +254,8 @@ async fn handle_stream(
.get_string_val()
.unwrap();

trace!("usbmuxd client sent {packet_type}");

match packet_type.as_str() {
//////////////////////////////
// netmuxd specific packets //
Expand Down

0 comments on commit 3a23670

Please sign in to comment.