Skip to content

Commit

Permalink
session count on server and client
Browse files Browse the repository at this point in the history
  • Loading branch information
ssrlive committed May 15, 2024
1 parent a9f748c commit 266ade4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ nginx_signing.key
overtls-daemon.sh
project.xcworkspace/
xcuserdata/
.vs/
.vscode/
.VSCodeCounter/
.env
Expand Down
10 changes: 10 additions & 0 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ where
let (udp_tx, _, incomings) = udprelay::create_udp_tunnel();
udprelay::udp_handler_watchdog(config, &incomings, &udp_tx, quit.clone()).await?;

let session_id = Arc::new(std::sync::atomic::AtomicUsize::new(0));
let session_count = Arc::new(std::sync::atomic::AtomicUsize::new(0));

loop {
tokio::select! {
_ = quit.cancelled() => {
Expand All @@ -84,10 +87,17 @@ where
let config = config.clone();
let udp_tx = udp_tx.clone();
let incomings = incomings.clone();
let session_id = session_id.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
let session_count = session_count.clone();
let peer_addr = conn.peer_addr()?;
tokio::spawn(async move {
let count = session_count.fetch_add(1, std::sync::atomic::Ordering::SeqCst) + 1;
log::debug!("session #{} from {} started, session count {}", session_id, peer_addr, count);
if let Err(e) = handle_incoming(conn, config, Some(udp_tx), incomings).await {
log::debug!("{}", e);
}
let count = session_count.fetch_sub(1, std::sync::atomic::Ordering::SeqCst) - 1;
log::debug!("session #{} from {} ended, session count {}", session_id, peer_addr, count);
});
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ pub async fn run_server(config: &Config, exiting_flag: crate::CancellationToken)
}
};

let session_id = Arc::new(std::sync::atomic::AtomicUsize::new(0));
let session_count = Arc::new(std::sync::atomic::AtomicUsize::new(0));

loop {
tokio::select! {
_ = exiting_flag.cancelled() => {
Expand All @@ -105,10 +108,17 @@ pub async fn run_server(config: &Config, exiting_flag: crate::CancellationToken)
Ok::<_, Error>(())
};

let session_id = session_id.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
let session_count = session_count.clone();

tokio::spawn(async move {
let count = session_count.fetch_add(1, std::sync::atomic::Ordering::SeqCst) + 1;
log::debug!("session #{} from {} started, session count {}", session_id, peer_addr, count);
if let Err(e) = incoming_task.await {
log::debug!("{peer_addr}: {e}");
}
let count = session_count.fetch_sub(1, std::sync::atomic::Ordering::SeqCst) - 1;
log::debug!("session #{} from {} ended, session count {}", session_id, peer_addr, count);
});
}
}
Expand Down

0 comments on commit 266ade4

Please sign in to comment.