From 9f60eee2e1db357c1683f06b756f121dbb356f5b Mon Sep 17 00:00:00 2001 From: ssrlive <30760636+ssrlive@users.noreply.github.com> Date: Sun, 11 Feb 2024 12:36:36 +0800 Subject: [PATCH] ArgProxy issues --- src/api.rs | 2 +- src/args.rs | 17 ++++++++++++++++- src/bin/main.rs | 2 ++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/api.rs b/src/api.rs index 04e08cb..84ae904 100644 --- a/src/api.rs +++ b/src/api.rs @@ -18,7 +18,7 @@ pub(crate) fn tun2proxy_internal_run(args: Args, tun_mtu: u16) -> c_int { } let block = async move { - log::info!("Proxy {} server: {}", args.proxy.proxy_type, args.proxy.addr); + log::info!("Proxying {}", args.proxy); let mut config = tun2::Configuration::default(); config.raw_fd(args.tun_fd.ok_or(crate::Error::from("tun_fd"))?); diff --git a/src/args.rs b/src/args.rs index 17783f2..362c7f5 100644 --- a/src/args.rs +++ b/src/args.rs @@ -190,6 +190,20 @@ impl Default for ArgProxy { } } +impl std::fmt::Display for ArgProxy { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let auth = match &self.credentials { + Some(creds) => format!("{}", creds), + None => "".to_owned(), + }; + if auth.is_empty() { + write!(f, "{}://{}", &self.proxy_type, &self.addr) + } else { + write!(f, "{}://{}@{}", &self.proxy_type, auth, &self.addr) + } + } +} + impl ArgProxy { pub fn from_url(s: &str) -> Result { let e = format!("`{s}` is not a valid proxy URL"); @@ -235,12 +249,13 @@ impl ArgProxy { } } +#[repr(C)] #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Default)] pub enum ProxyType { + Http = 0, Socks4, #[default] Socks5, - Http, } impl std::fmt::Display for ProxyType { diff --git a/src/bin/main.rs b/src/bin/main.rs index f6e5d25..95d42d5 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -63,6 +63,8 @@ async fn main() -> Result<(), Box> { tproxy_config::tproxy_setup(&tproxy_args)?; } + log::info!("Proxying {}", args.proxy); + let shutdown_token = CancellationToken::new(); let cloned_token = shutdown_token.clone(); let join_handle = tokio::spawn(tun2proxy::run(device, MTU, args, cloned_token));