Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nullchinchilla committed Mar 14, 2024
1 parent 7e1cfe2 commit 6e59ade
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
14 changes: 9 additions & 5 deletions binaries/geph5-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,14 @@ impl Client {
pub type CtxField<T> = fn(&AnyCtx<Config>) -> T;

async fn client_main(ctx: AnyCtx<Config>) -> anyhow::Result<()> {
let _client_loop = Immortal::respawn(
RespawnStrategy::JitterDelay(Duration::from_secs(1), Duration::from_secs(5)),
clone!([ctx], move || client_inner(ctx.clone())
.inspect_err(|e| tracing::warn!("client_inner died: {:?}", e))),
);
let _client_loops: Vec<_> = (0..8)
.map(|_| {
Immortal::respawn(
RespawnStrategy::JitterDelay(Duration::from_secs(1), Duration::from_secs(5)),
clone!([ctx], move || client_inner(ctx.clone())
.inspect_err(|e| tracing::warn!("client_inner died: {:?}", e))),
)
})
.collect();
socks5_loop(ctx).await
}
11 changes: 9 additions & 2 deletions binaries/geph5-client/src/client/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ use sillad::{dialer::Dialer as _, Pipe};
use smol::future::FutureExt as _;
use smol_timeout::TimeoutExt;
use std::{
sync::Arc,
sync::{
atomic::{AtomicU64, Ordering},
Arc,
},
time::{Duration, Instant},
};

Expand All @@ -34,8 +37,11 @@ static CONN_REQ_CHAN: CtxField<(
smol::channel::Receiver<ChanElem>,
)> = |_| smol::channel::unbounded();

#[tracing::instrument(skip(ctx))]
static COUNTER: AtomicU64 = AtomicU64::new(0);

#[tracing::instrument(skip_all, fields(instance=COUNTER.fetch_add(1, Ordering::Relaxed)))]
pub async fn client_inner(ctx: AnyCtx<Config>) -> anyhow::Result<()> {
tracing::info!("(re)starting main logic");
let start = Instant::now();
let authed_pipe = async {
let (pubkey, raw_dialer) = ctx.init().exit_constraint.dialer(&ctx).await?;
Expand Down Expand Up @@ -72,6 +78,7 @@ pub async fn client_inner(ctx: AnyCtx<Config>) -> anyhow::Result<()> {
let send_stop = send_stop.clone();
let ctx = ctx.clone();
let (remote_addr, send_back) = ctx.get(CONN_REQ_CHAN).1.recv().await?;
smol::future::yield_now().await;
spawn!(async move {
tracing::debug!(remote_addr = display(&remote_addr), "connecting to remote");
let stream = mux.open(remote_addr.as_bytes()).await;
Expand Down

0 comments on commit 6e59ade

Please sign in to comment.