improve logging

This commit is contained in:
Toshit Chawda 2024-08-24 10:42:00 -07:00
parent a7211264aa
commit 52da4eb0fb
No known key found for this signature in database
GPG key ID: 91480ED99E2B3D9D
3 changed files with 32 additions and 4 deletions

View file

@ -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(())
}

View file

@ -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(())
}

View file

@ -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());
}