From 490b37ae598ecb47d3cb227c11087a2a028d3417 Mon Sep 17 00:00:00 2001 From: Lee Smet Date: Wed, 17 Sep 2025 16:40:29 +0200 Subject: [PATCH] Add slightly more logging when connecting socks proxy Signed-off-by: Lee Smet --- mycelium/src/lib.rs | 2 +- mycelium/src/proxy.rs | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/mycelium/src/lib.rs b/mycelium/src/lib.rs index b4cc6f5..315961b 100644 --- a/mycelium/src/lib.rs +++ b/mycelium/src/lib.rs @@ -2,7 +2,7 @@ use std::future::Future; use std::net::{IpAddr, Ipv6Addr, SocketAddr}; use std::path::PathBuf; #[cfg(feature = "message")] -use std::{future::Future, time::Duration}; +use std::time::Duration; use crate::cdn::Cdn; use crate::proxy::{ConnectionError, Proxy}; diff --git a/mycelium/src/proxy.rs b/mycelium/src/proxy.rs index 02c3004..05b2d04 100644 --- a/mycelium/src/proxy.rs +++ b/mycelium/src/proxy.rs @@ -301,6 +301,12 @@ where .chosen_remote .lock() .expect("Can lock chosen remote; qed"); + if target.is_none() { + warn!("Can't start proxy if target is none, this should not happen"); + return; + } + let target = target.unwrap(); + info!(%target, "Starting Socks5 proxy forwarding"); // First cancel the old token, then set a new token let mut old_token = self.proxy_token.lock().expect("Can lock proxy token; qed"); old_token.cancel(); @@ -321,17 +327,11 @@ where Err(err) => { error!(%err, "Proxy listener accept error"); return Err(err) - } + } Ok((mut stream, source)) => { trace!(%source, "Got new proxy stream"); let proxy_token = proxy_token.clone(); - let target = target; - if target.is_none() { - warn!("Refusing to proxy Socks5 stream as we have no remote set - this should not happen"); - break - } // Unwrap is safe since we checked the none variant above - let target = target.unwrap(); tokio::spawn(async move { let mut con = TcpStream::connect(target).await?; select! {