diff --git a/distant-net/src/common/packet/header.rs b/distant-net/src/common/packet/header.rs index 6712ea6..982c692 100644 --- a/distant-net/src/common/packet/header.rs +++ b/distant-net/src/common/packet/header.rs @@ -3,6 +3,7 @@ use derive_more::IntoIterator; use serde::de::DeserializeOwned; use serde::{Deserialize, Serialize}; use std::collections::HashMap; +use std::fmt; use std::io; use std::ops::{Deref, DerefMut}; @@ -90,3 +91,18 @@ impl DerefMut for Header { &mut self.0 } } + +impl fmt::Display for Header { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{{")?; + + for (key, value) in self.0.iter() { + let value = serde_json::to_string(value).unwrap_or_else(|_| String::from("--")); + write!(f, "\"{key}\" = {value}")?; + } + + write!(f, "}}")?; + + Ok(()) + } +} diff --git a/distant-net/src/server.rs b/distant-net/src/server.rs index 143e1c8..548dfd2 100644 --- a/distant-net/src/server.rs +++ b/distant-net/src/server.rs @@ -223,6 +223,9 @@ where .verifier(Arc::downgrade(&verifier)) .spawn(), ); + + // Clean up current tasks being tracked + connection_tasks.retain(|task| !task.is_finished()); } // Once we stop listening, we still want to wait until all connections have terminated diff --git a/distant-net/src/server/connection.rs b/distant-net/src/server/connection.rs index 7eac519..e6be9c6 100644 --- a/distant-net/src/server/connection.rs +++ b/distant-net/src/server/connection.rs @@ -425,7 +425,7 @@ where let id = connection.id(); // Create local data for the connection and then process it - debug!("[Conn {id}] Officially accepting connection"); + info!("[Conn {id}] Connection established"); if let Err(x) = await_or_shutdown!(handler.on_connect(id)) { terminate_connection!(@fatal "[Conn {id}] Accepting connection failed: {x}"); } @@ -477,6 +477,10 @@ where Ok(Some(frame)) => match UntypedRequest::from_slice(frame.as_item()) { Ok(request) => match request.to_typed_request() { Ok(request) => { + debug!( + "[Conn {id}] New request {} | header {}", + request.id, request.header + ); let origin_id = request.id.clone(); let ctx = RequestCtx { connection_id: id, @@ -493,8 +497,8 @@ where tokio::spawn(async move { handler.on_request(ctx).await }); } Err(x) => { - if log::log_enabled!(Level::Trace) { - trace!( + if log::log_enabled!(Level::Debug) { + error!( "[Conn {id}] Failed receiving {}", String::from_utf8_lossy(&request.payload), );