name change + specific inc and dec logging
This commit is contained in:
@@ -203,10 +203,10 @@
|
||||
|
||||
// TODO UPDATE EXAMPLE ONCE STABLE
|
||||
|
||||
mod connection_tracker;
|
||||
mod tcp_proxy_client;
|
||||
mod tcp_proxy_server;
|
||||
mod tcp_tracker;
|
||||
|
||||
pub use connection_tracker::ConnectionTracker;
|
||||
pub use tcp_proxy_client::NymProxyClient;
|
||||
pub use tcp_proxy_server::NymProxyServer;
|
||||
pub use tcp_tracker::TcpConnectionTracker;
|
||||
|
||||
+9
-9
@@ -3,11 +3,11 @@ use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct TcpConnectionTracker {
|
||||
pub struct ConnectionTracker {
|
||||
count: Arc<AtomicUsize>,
|
||||
}
|
||||
|
||||
impl TcpConnectionTracker {
|
||||
impl ConnectionTracker {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
count: Arc::new(AtomicUsize::new(0)),
|
||||
@@ -31,7 +31,7 @@ impl TcpConnectionTracker {
|
||||
}
|
||||
}
|
||||
|
||||
impl Clone for TcpConnectionTracker {
|
||||
impl Clone for ConnectionTracker {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
count: Arc::clone(&self.count),
|
||||
@@ -47,7 +47,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_increment_decrement() -> Result<()> {
|
||||
let tracker = TcpConnectionTracker::new();
|
||||
let tracker = ConnectionTracker::new();
|
||||
tracker.increment();
|
||||
tracker.increment();
|
||||
assert_eq!(tracker.get_count(), 2, "should be 2 after single increment");
|
||||
@@ -62,7 +62,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_clone() {
|
||||
let tracker = TcpConnectionTracker::new();
|
||||
let tracker = ConnectionTracker::new();
|
||||
let tracker_clone = tracker.clone();
|
||||
|
||||
tracker.increment();
|
||||
@@ -75,7 +75,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_multiple_threads() {
|
||||
let tracker = TcpConnectionTracker::new();
|
||||
let tracker = ConnectionTracker::new();
|
||||
let mut handles = vec![];
|
||||
|
||||
for _ in 0..10 {
|
||||
@@ -100,7 +100,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_concurrent_increment_decrement() -> Result<()> {
|
||||
let tracker = TcpConnectionTracker::new();
|
||||
let tracker = ConnectionTracker::new();
|
||||
let mut handles = vec![];
|
||||
|
||||
for i in 0..10 {
|
||||
@@ -131,13 +131,13 @@ mod tests {
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_zero_floor() {
|
||||
let tracker = TcpConnectionTracker::new();
|
||||
let tracker = ConnectionTracker::new();
|
||||
tracker.decrement().unwrap(); // should panic
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_stress() {
|
||||
let tracker = TcpConnectionTracker::new();
|
||||
let tracker = ConnectionTracker::new();
|
||||
let mut handles = vec![];
|
||||
let num_threads = 100;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use crate::mixnet::{IncludedSurbs, MixnetClientBuilder, MixnetMessageSender, NymNetworkDetails};
|
||||
use std::{sync::Arc, time::Duration};
|
||||
#[path = "tcp_tracker.rs"]
|
||||
mod tcp_tracker;
|
||||
use tcp_tracker::TcpConnectionTracker;
|
||||
#[path = "connection_tracker.rs"]
|
||||
mod connection_tracker;
|
||||
use connection_tracker::ConnectionTracker;
|
||||
#[path = "utils.rs"]
|
||||
mod utils;
|
||||
use anyhow::Result;
|
||||
@@ -27,7 +27,7 @@ pub struct NymProxyClient {
|
||||
listen_address: String,
|
||||
listen_port: String,
|
||||
close_timeout: u64,
|
||||
conn_tracker: TcpConnectionTracker,
|
||||
conn_tracker: ConnectionTracker,
|
||||
}
|
||||
|
||||
impl NymProxyClient {
|
||||
@@ -45,7 +45,7 @@ impl NymProxyClient {
|
||||
listen_address: listen_address.to_string(),
|
||||
listen_port: listen_port.to_string(),
|
||||
close_timeout,
|
||||
conn_tracker: TcpConnectionTracker::new(),
|
||||
conn_tracker: ConnectionTracker::new(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ impl NymProxyClient {
|
||||
listen_address: DEFAULT_LISTEN_HOST.to_string(),
|
||||
listen_port: DEFAULT_LISTEN_PORT.to_string(),
|
||||
close_timeout: DEFAULT_CLOSE_TIMEOUT,
|
||||
conn_tracker: TcpConnectionTracker::new(),
|
||||
conn_tracker: ConnectionTracker::new(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -104,9 +104,13 @@ impl NymProxyClient {
|
||||
stream: TcpStream,
|
||||
server_address: Recipient,
|
||||
close_timeout: u64,
|
||||
conn_tracker: TcpConnectionTracker,
|
||||
conn_tracker: ConnectionTracker,
|
||||
) -> Result<()> {
|
||||
conn_tracker.increment();
|
||||
info!(
|
||||
"new connection - current active tcp connections: {}",
|
||||
conn_tracker.get_count()
|
||||
);
|
||||
|
||||
// ID for creation of session abstraction; new session ID per new connection accepted by our tcp listener above.
|
||||
let session_id = uuid::Uuid::new_v4();
|
||||
@@ -234,6 +238,10 @@ impl NymProxyClient {
|
||||
info!(":: Triggering client shutdown");
|
||||
client.disconnect().await;
|
||||
conn_tracker.clone().decrement()?;
|
||||
info!(
|
||||
"dropped connection - current active tcp connections: {}",
|
||||
conn_tracker.get_count()
|
||||
);
|
||||
return Ok::<(), anyhow::Error>(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user