Skip to content

Commit

Permalink
Add stat_set_num function and implement latency tracking in client_inner
Browse files Browse the repository at this point in the history
  • Loading branch information
nullchinchilla committed Sep 18, 2024
1 parent 54c4746 commit c189a1a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
6 changes: 4 additions & 2 deletions binaries/geph5-client/src/client_inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use crate::{
client::CtxField,
control_prot::{ConnectedInfo, CURRENT_CONN_INFO},
route::{deprioritize_route, get_dialer},
stats::stat_incr_num,
stats::{stat_incr_num, stat_set_num},
vpn::{fake_dns_backtranslate, vpn_whitelist},
ConnInfo,
};
Expand Down Expand Up @@ -236,7 +236,9 @@ async fn client_inner(ctx: AnyCtx<Config>, authed_pipe: impl Pipe) -> anyhow::Re
let mux = mux.clone();
let ctx = ctx.clone();
let (remote_addr, send_back) = ctx.get(CONN_REQ_CHAN).1.lock().await.recv().await?;

if let Some(latency) = mux.last_latency() {
stat_set_num(&ctx, "ping", latency.as_secs_f64());
}
spawn!(async move {
tracing::debug!(remote_addr = display(&remote_addr), "opening tunnel");
let stream = mux.open(remote_addr.as_bytes()).await;
Expand Down
12 changes: 6 additions & 6 deletions binaries/geph5-client/src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ use crate::{client::CtxField, Config};

static NUM_STATS: CtxField<DashMap<SmolStr, AtomicF64>> = |_| DashMap::new();

// pub fn stat_set_num(ctx: &AnyCtx<Config>, stat: &str, num: f64) {
// ctx.get(NUM_STATS)
// .entry(stat.into())
// .or_default()
// .store(num, Ordering::Relaxed);
// }
pub fn stat_set_num(ctx: &AnyCtx<Config>, stat: &str, num: f64) {
ctx.get(NUM_STATS)
.entry(stat.into())
.or_default()
.store(num, Ordering::Relaxed);
}

pub fn stat_incr_num(ctx: &AnyCtx<Config>, stat: &str, num: f64) {
ctx.get(NUM_STATS)
Expand Down

0 comments on commit c189a1a

Please sign in to comment.