Skip to content

Commit

Permalink
server traffic logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ssrlive committed Dec 10, 2023
1 parent 1343531 commit fee30b0
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,11 @@ async fn normal_tunnel<S: AsyncRead + AsyncWrite + Unpin>(
tokio::select! {
msg = ws_stream.next() => {
let msg = msg.ok_or(format!("{peer} -> {dst_addr} no Websocket message"))??;
let len = (msg.len() + WS_MSG_HEADER_LEN) as u64;
if let Some(client_id) = &client_id {
let len = (msg.len() + WS_MSG_HEADER_LEN) as u64;
traffic_audit.lock().await.add_upstream_traffic_of(client_id, len);
}
log::trace!("{peer} -> {dst_addr} length {}", len);
match msg {
Message::Close(_) => {
log::trace!("{peer} <> {dst_addr} incoming connection closed normally");
Expand All @@ -336,10 +337,11 @@ async fn normal_tunnel<S: AsyncRead + AsyncWrite + Unpin>(
}
Ok(n) => {
let msg = Message::Binary(buffer[..n].to_vec());
let len = (msg.len() + WS_MSG_HEADER_LEN) as u64;
if let Some(client_id) = &client_id {
let len = (msg.len() + WS_MSG_HEADER_LEN) as u64;
traffic_audit.lock().await.add_downstream_traffic_of(client_id, len);
}
log::trace!("{peer} <- {dst_addr} length {}", len);
ws_stream.send(msg).await?;
}
Err(e) => {
Expand Down

0 comments on commit fee30b0

Please sign in to comment.