🔊 counting active QUIC connections for P3
parent
24d04f2b1f
commit
26135471cb
|
@ -16,7 +16,16 @@ async fn main () -> anyhow::Result <()> {
|
||||||
|
|
||||||
// Each new peer QUIC connection gets its own task
|
// Each new peer QUIC connection gets its own task
|
||||||
tokio::spawn (async move {
|
tokio::spawn (async move {
|
||||||
handle_quic_connection (relay_state, conn).await
|
let active = relay_state.stats.quic.connect ();
|
||||||
|
debug! ("QUIC connections: {}", active);
|
||||||
|
|
||||||
|
match handle_quic_connection (Arc::clone (&relay_state), conn).await {
|
||||||
|
Ok (_) => (),
|
||||||
|
Err (e) => warn! ("handle_quic_connection {:?}", e),
|
||||||
|
}
|
||||||
|
|
||||||
|
let active = relay_state.stats.quic.disconnect ();
|
||||||
|
debug! ("QUIC connections: {}", active);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,10 +35,43 @@ async fn main () -> anyhow::Result <()> {
|
||||||
#[derive (Default)]
|
#[derive (Default)]
|
||||||
struct RelayState {
|
struct RelayState {
|
||||||
p4_server_proxies: Mutex <HashMap <u8, P4State>>,
|
p4_server_proxies: Mutex <HashMap <u8, P4State>>,
|
||||||
|
stats: Stats,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive (Default)]
|
||||||
|
struct Stats {
|
||||||
|
quic: ConnectEvents,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive (Default)]
|
||||||
|
struct ConnectEvents {
|
||||||
|
connects: AtomicU64,
|
||||||
|
disconnects: AtomicU64,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ConnectEvents {
|
||||||
|
fn connect (&self) -> u64 {
|
||||||
|
let connects = self.connects.fetch_add (1, Ordering::Relaxed) + 1;
|
||||||
|
let disconnects = self.disconnects.load (Ordering::Relaxed);
|
||||||
|
connects - disconnects
|
||||||
|
}
|
||||||
|
|
||||||
|
fn disconnect (&self) -> u64 {
|
||||||
|
let disconnects = self.disconnects.fetch_add (1, Ordering::Relaxed) + 1;
|
||||||
|
let connects = self.connects.load (Ordering::Relaxed);
|
||||||
|
connects - disconnects
|
||||||
|
}
|
||||||
|
|
||||||
|
fn active (&self) -> u64 {
|
||||||
|
let connects = self.connects.load (Ordering::Relaxed);
|
||||||
|
let disconnects = self.disconnects.load (Ordering::Relaxed);
|
||||||
|
connects - disconnects
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct P4State {
|
struct P4State {
|
||||||
req_channel: mpsc::Sender <RequestP2ToP4>,
|
req_channel: mpsc::Sender <RequestP2ToP4>,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RelayState {
|
impl RelayState {
|
||||||
|
|
|
@ -1,6 +1,12 @@
|
||||||
pub use std::{
|
pub use std::{
|
||||||
collections::*,
|
collections::*,
|
||||||
sync::Arc,
|
sync::{
|
||||||
|
Arc,
|
||||||
|
atomic::{
|
||||||
|
AtomicU64,
|
||||||
|
Ordering,
|
||||||
|
},
|
||||||
|
},
|
||||||
time::Duration,
|
time::Duration,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue