From d6e4e7eeeec5b51d22d4aaa40d535119d1075bd8 Mon Sep 17 00:00:00 2001 From: EAimTY Date: Tue, 30 May 2023 19:49:23 +0900 Subject: [PATCH] better packet infomation logging --- tuic-client/src/connection/handle_task.rs | 14 ++++++++------ tuic-server/src/connection/handle_task.rs | 16 ++++++++-------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/tuic-client/src/connection/handle_task.rs b/tuic-client/src/connection/handle_task.rs index 47a4348..8f521af 100644 --- a/tuic-client/src/connection/handle_task.rs +++ b/tuic-client/src/connection/handle_task.rs @@ -39,11 +39,11 @@ impl Connection { match self.udp_relay_mode { UdpRelayMode::Native => { - log::info!("[relay] [packet] [{assoc_id:#06x}] [to-native] {addr_display}"); + log::info!("[relay] [packet] [{assoc_id:#06x}] [to-native] to {addr_display}"); match self.model.packet_native(pkt, addr, assoc_id) { Ok(()) => Ok(()), Err(err) => { - log::warn!("[relay] [packet] [{assoc_id:#06x}] [to-native] failed relaying packet to {addr_display}: {err}"); + log::warn!("[relay] [packet] [{assoc_id:#06x}] [to-native] to {addr_display}: {err}"); Err(Error::Model(err)) } } @@ -53,7 +53,9 @@ impl Connection { match self.model.packet_quic(pkt, addr, assoc_id).await { Ok(()) => Ok(()), Err(err) => { - log::warn!("[relay] [packet] [{assoc_id:#06x}] [to-quic] failed relaying packet to {addr_display}: {err}"); + log::warn!( + "[relay] [packet] [{assoc_id:#06x}] [to-quic] to {addr_display}: {err}" + ); Err(Error::Model(err)) } } @@ -66,7 +68,7 @@ impl Connection { match self.model.dissociate(assoc_id).await { Ok(()) => Ok(()), Err(err) => { - log::warn!("[relay] [dissociate] [{assoc_id:#06x}] failed dissociating: {err}"); + log::warn!("[relay] [dissociate] [{assoc_id:#06x}] {err}"); Err(Error::Model(err)) } } @@ -86,7 +88,7 @@ impl Connection { match self.model.heartbeat().await { Ok(()) => log::debug!("[relay] [heartbeat]"), - Err(err) => log::warn!("[relay] [heartbeat] heartbeat sending error: {err}"), + Err(err) => log::warn!("[relay] [heartbeat] {err}"), } } } @@ -105,7 +107,7 @@ impl Connection { match pkt.accept().await { Ok(Some((pkt, addr, _))) => { - log::info!("[relay] [packet] [{assoc_id:#06x}] [from-{mode}] [{pkt_id:#06x}] {addr}"); + log::info!("[relay] [packet] [{assoc_id:#06x}] [from-{mode}] [{pkt_id:#06x}] from {addr}"); let addr = match addr { Address::None => unreachable!(), diff --git a/tuic-server/src/connection/handle_task.rs b/tuic-server/src/connection/handle_task.rs index 0632563..8cda03f 100644 --- a/tuic-server/src/connection/handle_task.rs +++ b/tuic-server/src/connection/handle_task.rs @@ -86,7 +86,7 @@ impl Connection { let frag_total = pkt.frag_total(); log::info!( - "[{id:#010x}] [{addr}] [{user}] [packet] [{assoc_id:#06x}] [from-{mode}] [{pkt_id:#06x}] {frag_id}/{frag_total}", + "[{id:#010x}] [{addr}] [{user}] [packet] [{assoc_id:#06x}] [from-{mode}] [{pkt_id:#06x}] fragment {frag_id}/{frag_total}", id = self.id(), addr = self.inner.remote_address(), user = self.auth, @@ -99,7 +99,7 @@ impl Connection { Ok(Some(res)) => res, Err(err) => { log::warn!( - "[{id:#010x}] [{addr}] [{user}] [packet] [{assoc_id:#06x}] [from-{mode}] [{pkt_id:#06x}] {frag_id}/{frag_total}: {err}", + "[{id:#010x}] [{addr}] [{user}] [packet] [{assoc_id:#06x}] [from-{mode}] [{pkt_id:#06x}] fragment {frag_id}/{frag_total}: {err}", id = self.id(), addr = self.inner.remote_address(), user = self.auth, @@ -110,7 +110,7 @@ impl Connection { let process = async { log::info!( - "[{id:#010x}] [{addr}] [{user}] [packet] [{assoc_id:#06x}] [from-{mode}] [{pkt_id:#06x}] {src_addr}", + "[{id:#010x}] [{addr}] [{user}] [packet] [{assoc_id:#06x}] [from-{mode}] [{pkt_id:#06x}] to {src_addr}", id = self.id(), addr = self.inner.remote_address(), user = self.auth, @@ -140,7 +140,7 @@ impl Connection { if let Err(err) = process.await { log::warn!( - "[{id:#010x}] [{addr}] [{user}] [packet] [{assoc_id:#06x}] [from-{mode}] [{pkt_id:#06x}] {src_addr}: {err}", + "[{id:#010x}] [{addr}] [{user}] [packet] [{assoc_id:#06x}] [from-{mode}] [{pkt_id:#06x}] to {src_addr}: {err}", id = self.id(), addr = self.inner.remote_address(), user = self.auth, @@ -175,12 +175,12 @@ impl Connection { let addr_display = addr.to_string(); log::info!( - "[{id:#010x}] [{addr}] [{user}] [packet] [{assoc_id:#06x}] [to-{mode}] {target_addr}", + "[{id:#010x}] [{addr}] [{user}] [packet] [{assoc_id:#06x}] [to-{mode}] from {src_addr}", id = self.id(), addr = self.inner.remote_address(), user = self.auth, mode = self.udp_relay_mode.load().unwrap(), - target_addr = addr_display, + src_addr = addr_display, ); let res = match self.udp_relay_mode.load().unwrap() { @@ -190,12 +190,12 @@ impl Connection { if let Err(err) = res { log::warn!( - "[{id:#010x}] [{addr}] [{user}] [packet] [{assoc_id:#06x}] [to-{mode}] {target_addr}: {err}", + "[{id:#010x}] [{addr}] [{user}] [packet] [{assoc_id:#06x}] [to-{mode}] from {src_addr}: {err}", id = self.id(), addr = self.inner.remote_address(), user = self.auth, mode = self.udp_relay_mode.load().unwrap(), - target_addr = addr_display, + src_addr = addr_display, ); } }