diff --git a/server/src/handle/wisp.rs b/server/src/handle/wisp.rs index 1f75d79..428fb4a 100644 --- a/server/src/handle/wisp.rs +++ b/server/src/handle/wisp.rs @@ -1,6 +1,7 @@ use anyhow::Context; use cfg_if::cfg_if; use futures_util::FutureExt; +use log::{debug, trace}; use tokio::{ io::{AsyncBufReadExt, AsyncWriteExt, BufReader}, net::tcp::{OwnedReadHalf, OwnedWriteHalf}, @@ -90,6 +91,8 @@ async fn handle_stream( let uuid = Uuid::new_v4(); + trace!("new stream created for client id {:?}: (stream uuid {:?}) {:?} {:?}", id, uuid, requested_stream, resolved_stream); + CLIENTS .get(&id) .unwrap() @@ -180,6 +183,8 @@ async fn handle_stream( } }; + trace!("stream uuid {:?} disconnected for client id {:?}", uuid, id); + CLIENTS.get(&id).unwrap().0.remove(&uuid); } @@ -209,6 +214,8 @@ pub async fn handle_wisp(stream: WispResult, id: String) -> anyhow::Result<()> { .context("failed to create server multiplexor")? .with_no_required_extensions(); + debug!("new wisp client id {:?} connected with extensions {:?}", id, mux.supported_extension_ids); + let mut set: JoinSet<()> = JoinSet::new(); set.spawn(tokio::task::unconstrained(fut.map(|_| {}))); @@ -223,9 +230,13 @@ pub async fn handle_wisp(stream: WispResult, id: String) -> anyhow::Result<()> { ))); } + let _ = mux.close().await; + set.abort_all(); while set.join_next().await.is_some() {} + debug!("wisp client id {:?} disconnected", id); + Ok(()) } diff --git a/server/src/handle/wsproxy.rs b/server/src/handle/wsproxy.rs index 6d5dfbf..e066f6a 100644 --- a/server/src/handle/wsproxy.rs +++ b/server/src/handle/wsproxy.rs @@ -1,6 +1,7 @@ use std::str::FromStr; use fastwebsockets::CloseCode; +use log::debug; use tokio::{ io::{AsyncBufReadExt, AsyncWriteExt, BufReader}, select, @@ -84,6 +85,11 @@ pub async fn handle_wsproxy( let uuid = Uuid::new_v4(); + debug!( + "new wsproxy client id {:?} connected: (stream uuid {:?}) {:?} {:?}", + id, uuid, requested_stream, resolved_stream + ); + CLIENTS .get(&id) .unwrap() @@ -161,7 +167,9 @@ pub async fn handle_wsproxy( } #[cfg(feature = "twisp")] ClientStream::Pty(_, _) => { - let _ = ws.close(CloseCode::Error.into(), b"twisp is not supported").await; + let _ = ws + .close(CloseCode::Error.into(), b"twisp is not supported") + .await; } ClientStream::Blocked => { let _ = ws.close(CloseCode::Error.into(), b"host is blocked").await; @@ -171,5 +179,10 @@ pub async fn handle_wsproxy( } } + debug!( + "wsproxy client id {:?} disconnected (stream uuid {:?})", + id, uuid + ); + Ok(()) } diff --git a/server/src/listener.rs b/server/src/listener.rs index df62c2a..41fc736 100644 --- a/server/src/listener.rs +++ b/server/src/listener.rs @@ -9,7 +9,7 @@ use hyper::{ StatusCode, }; use hyper_util::rt::TokioIo; -use log::error; +use log::{debug, error}; use tokio::{ fs::{remove_file, try_exists}, io::AsyncReadExt, @@ -57,19 +57,22 @@ where { match generate_stats() { Ok(x) => { + debug!("sent server stats to http client"); return Ok(Response::builder() .status(StatusCode::OK) .body(Body::new(x.into())) - .unwrap()) + .unwrap()); } Err(x) => { + error!("failed to send stats to http client: {:?}", x); return Ok(Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::new(x.to_string().into())) - .unwrap()) + .unwrap()); } } } else if !is_upgrade { + debug!("sent non_ws_response to http client"); return Ok(non_ws_resp()); } @@ -95,6 +98,7 @@ where } }); } else { + debug!("sent non_ws_response to http client"); return Ok(non_ws_resp()); }