Skip to content

Commit de4b786

Browse files
committed
mitm: add HU/MD to logger
1 parent a905805 commit de4b786

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

src/mitm.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@ use crate::io_uring::Endpoint;
2424
use crate::io_uring::BUFFER_LEN;
2525

2626
// module name for logging engine
27-
const NAME: &str = "<i><bright-black> mitm: </>";
27+
fn get_name(proxy_type: ProxyType) -> String {
28+
let proxy = match proxy_type {
29+
ProxyType::HeadUnit => "HU",
30+
ProxyType::MobileDevice => "MD",
31+
};
32+
format!("<i><bright-black> mitm/{}: </>", proxy)
33+
}
2834

2935
// Just a generic Result type to ease error handling for us. Errors in multithreaded
3036
// async contexts needs some extra restrictions
@@ -219,6 +225,7 @@ pub async fn pkt_debug(payload: &[u8]) -> Result<()> {
219225

220226
/// packet modification hook
221227
pub async fn pkt_modify_hook(
228+
proxy_type: ProxyType,
222229
pkt: &mut Packet,
223230
dpi: Option<u16>,
224231
developer_mode: bool,
@@ -254,7 +261,7 @@ pub async fn pkt_modify_hook(
254261
.set_density(new_dpi.into());
255262
info!(
256263
"{} <yellow>{:?}</>: replacing DPI value: from <b>{}</> to <b>{}</>",
257-
NAME,
264+
get_name(proxy_type),
258265
control.unwrap(),
259266
prev_val,
260267
new_dpi
@@ -267,7 +274,7 @@ pub async fn pkt_modify_hook(
267274
.retain(|svc| svc.media_sink_service.audio_type() != AUDIO_STREAM_MEDIA);
268275
info!(
269276
"{} <yellow>{:?}</>: media sink disabled",
270-
NAME,
277+
get_name(proxy_type),
271278
control.unwrap(),
272279
);
273280
}
@@ -278,7 +285,7 @@ pub async fn pkt_modify_hook(
278285
msg.set_model("Desktop Head Unit".into());
279286
info!(
280287
"{} <yellow>{:?}</>: enabling developer mode",
281-
NAME,
288+
get_name(proxy_type),
282289
control.unwrap(),
283290
);
284291
}
@@ -455,7 +462,7 @@ pub async fn proxy<A: Endpoint<A> + 'static>(
455462
let _ = server.accept();
456463
info!(
457464
"{} 🔒 stage #{} of {}: SSL handshake: {}",
458-
NAME,
465+
get_name(proxy_type),
459466
i,
460467
STEPS,
461468
server.ssl().state_string_long()
@@ -479,7 +486,7 @@ pub async fn proxy<A: Endpoint<A> + 'static>(
479486
let _ = server.do_handshake();
480487
info!(
481488
"{} 🔒 stage #{} of {}: SSL handshake: {}",
482-
NAME,
489+
get_name(proxy_type),
483490
i,
484491
STEPS,
485492
server.ssl().state_string_long()
@@ -498,7 +505,14 @@ pub async fn proxy<A: Endpoint<A> + 'static>(
498505
loop {
499506
// handling data from opposite device's thread, which needs to be transmitted
500507
if let Ok(mut pkt) = rx.try_recv() {
501-
pkt_modify_hook(&mut pkt, dpi, developer_mode, disable_media_sink).await?;
508+
pkt_modify_hook(
509+
proxy_type,
510+
&mut pkt,
511+
dpi,
512+
developer_mode,
513+
disable_media_sink,
514+
)
515+
.await?;
502516
pkt.encrypt_payload(&mut mem_buf, &mut server).await?;
503517
pkt.transmit(&mut device).await?;
504518

0 commit comments

Comments
 (0)