Compare commits

...

2 Commits

Author SHA1 Message Date
d4bd0ef1ca
Use store instead of fetch_add for atomics
All checks were successful
Build and deploy / Build container and manifests (push) Successful in 2m48s
2025-04-18 14:58:15 +02:00
95e47c708c
Highlight port in red if tunnel failed to open 2025-04-18 14:57:31 +02:00
3 changed files with 26 additions and 6 deletions

View File

@ -1,6 +1,6 @@
use std::pin::Pin;
use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
use std::task::{Context, Poll};
use pin_project_lite::pin_project;
@ -14,25 +14,34 @@ pub struct Stats {
connections: AtomicUsize,
rx: AtomicUsize,
tx: AtomicUsize,
failed: AtomicBool,
}
impl Stats {
pub fn add_connection(&self) {
self.connections.fetch_add(1, Ordering::Relaxed);
self.connections.store(1, Ordering::Relaxed);
}
pub fn add_rx_bytes(&self, n: usize) {
self.rx.fetch_add(n, Ordering::Relaxed);
self.rx.store(n, Ordering::Relaxed);
}
pub fn add_tx_bytes(&self, n: usize) {
self.tx.fetch_add(n, Ordering::Relaxed);
self.tx.store(n, Ordering::Relaxed);
}
pub fn connections(&self) -> usize {
self.connections.load(Ordering::Relaxed)
}
pub fn failed(&self) -> bool {
self.failed.load(Ordering::Relaxed)
}
pub fn set_failed(&self, failed: bool) {
self.failed.store(failed, Ordering::Relaxed);
}
pub fn rx(&self) -> Unit {
Unit::new(self.rx.load(Ordering::Relaxed), "B")
}

View File

@ -40,7 +40,12 @@ impl TunnelInner {
&self.internal_address,
self.port,
)
.await?;
.await
.inspect_err(|_| {
self.stats.set_failed(true);
})?;
self.stats.set_failed(false);
Ok(TrackStats::new(channel.into_stream(), self.stats.clone()))
}

View File

@ -17,9 +17,15 @@ pub struct TunnelRow {
impl From<&TunnelRow> for Vec<Span<'static>> {
fn from(row: &TunnelRow) -> Self {
let port = if row.stats.failed() {
row.port.clone().red()
} else {
row.port.clone()
};
vec![
row.name.clone(),
row.port.clone(),
port,
row.access.clone(),
row.address.clone(),
row.stats.connections().to_string().into(),