diff --git a/Cargo.lock b/Cargo.lock index 07bc510ab..874a17425 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -703,7 +703,7 @@ checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" [[package]] name = "clash" -version = "0.1.0" +version = "0.1.5" dependencies = [ "clap 4.4.7", "clash_lib", @@ -711,14 +711,14 @@ dependencies = [ [[package]] name = "clash_doc" -version = "0.1.0" +version = "0.1.5" dependencies = [ "clash_lib", ] [[package]] name = "clash_lib" -version = "0.1.0" +version = "0.1.5" dependencies = [ "aes-gcm", "anyhow", diff --git a/Cargo.toml b/Cargo.toml index 9af2ebc58..c3891851d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,12 @@ members = [ "clash_doc", ] + +[workspace.package] +version = "0.1.5" +repository = "https://github.com/Watfaq/clash-rs.git" +edition = "2021" + [profile.release] opt-level = "s" codegen-units = 1 diff --git a/clash/Cargo.toml b/clash/Cargo.toml index 80ad757c6..5a5baecf3 100644 --- a/clash/Cargo.toml +++ b/clash/Cargo.toml @@ -1,7 +1,8 @@ [package] name = "clash" -version = "0.1.0" -edition = "2021" +repository = { workspace = true } +version = { workspace = true } +edition = { workspace = true } [[bin]] name = "clash" diff --git a/clash_doc/Cargo.toml b/clash_doc/Cargo.toml index 1b5e5221e..80c87bd5f 100644 --- a/clash_doc/Cargo.toml +++ b/clash_doc/Cargo.toml @@ -1,7 +1,8 @@ [package] name = "clash_doc" -version = "0.1.0" -edition = "2021" +repository = { workspace = true } +version = { workspace = true } +edition = { workspace = true } # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/clash_lib/Cargo.toml b/clash_lib/Cargo.toml index b170ddca3..7ccd052d7 100644 --- a/clash_lib/Cargo.toml +++ b/clash_lib/Cargo.toml @@ -1,7 +1,8 @@ [package] name = "clash_lib" -version = "0.1.0" -edition = "2021" +repository = { workspace = true } +version = { workspace = true } +edition = { workspace = true } [features] default = ["shadowsocks"] diff --git a/clash_lib/src/app/dispatcher/dispatcher.rs b/clash_lib/src/app/dispatcher/dispatcher.rs index a2fc86e7f..a87a166d5 100644 --- a/clash_lib/src/app/dispatcher/dispatcher.rs +++ b/clash_lib/src/app/dispatcher/dispatcher.rs @@ -108,13 +108,14 @@ impl Dispatcher { }; let mode = **self.mode.load(); - debug!("dispatching {} with mode {}", sess, mode); let (outbound_name, rule) = match mode { RunMode::Global => (PROXY_GLOBAL, None), RunMode::Rule => self.router.match_route(&sess).await, RunMode::Direct => (PROXY_DIRECT, None), }; + debug!("dispatching {} to {}[{}]", sess, outbound_name, mode); + let mgr = self.outbound_manager.clone(); let handler = mgr.get_outbound(outbound_name).unwrap_or_else(|| { debug!("unknown rule: {}, fallback to direct", outbound_name); @@ -224,7 +225,7 @@ impl Dispatcher { } None => { error!("failed to reverse lookup fake ip: {}", ip); - return; + continue; } } } else { @@ -242,15 +243,16 @@ impl Dispatcher { packet.dst_addr = sess.destination.clone(); let mode = mode.clone(); - trace!("dispatching {} with mode {}", sess, mode); let (outbound_name, rule) = match mode { RunMode::Global => (PROXY_GLOBAL, None), RunMode::Rule => router.match_route(&sess).await, RunMode::Direct => (PROXY_DIRECT, None), }; + let outbound_name = outbound_name.to_string(); - debug!("dispatching {} to {}", sess, outbound_name); + + debug!("dispatching {} to {}[{}]", sess, outbound_name, mode); let remote_receiver_w = remote_receiver_w.clone(); @@ -274,7 +276,7 @@ impl Dispatcher { Ok(v) => v, Err(err) => { error!("failed to connect outbound: {}", err); - return; + continue; } }; @@ -312,10 +314,8 @@ impl Dispatcher { // local -> remote let w_handle = tokio::spawn(async move { while let Some(packet) = remote_forwarder.recv().await { - match remote_w.send(packet.clone()).await { - Ok(_) => { - debug!("{} sent to remote", packet); - } + match remote_w.send(packet).await { + Ok(_) => {} Err(err) => { warn!("failed to send packet to remote: {}", err); } @@ -333,7 +333,7 @@ impl Dispatcher { ) .await; - match remote_sender.send(packet.clone()).await { + match remote_sender.send(packet).await { Ok(_) => {} Err(err) => { error!("failed to send packet to remote: {}", err); @@ -406,10 +406,13 @@ impl TimeoutUdpSessionManager { let map_cloned = map.clone(); let cleaner = tokio::spawn(async move { + trace!("timeout udp session cleaner scanning"); + let mut interval = tokio::time::interval(timeout); + loop { - tokio::time::sleep(Duration::from_secs(10)).await; + interval.tick().await; + trace!("timeout udp session cleaner ticking"); - trace!("timeout udp session cleaner scanning"); let mut g = map_cloned.write().await; let mut alived = 0; let mut expired = 0; diff --git a/clash_lib/src/app/dns/resolver.rs b/clash_lib/src/app/dns/resolver.rs index a5450d2d6..e3941dd00 100644 --- a/clash_lib/src/app/dns/resolver.rs +++ b/clash_lib/src/app/dns/resolver.rs @@ -629,7 +629,7 @@ mod tests { } #[tokio::test] - #[ignore = "figure out failure on CI"] + #[ignore = "network unstable on CI"] async fn test_dot_resolve() { let c = DnsClient::new(Opts { r: Some(Arc::new(Resolver::new_default().await)), @@ -645,6 +645,7 @@ mod tests { } #[tokio::test] + #[ignore = "network unstable on CI"] async fn test_doh_resolve() { let default_resolver = Arc::new(Resolver::new_default().await); diff --git a/clash_lib/src/app/remote_content_manager/providers/http_vehicle.rs b/clash_lib/src/app/remote_content_manager/providers/http_vehicle.rs index a4fa04c8c..32d1afa5e 100644 --- a/clash_lib/src/app/remote_content_manager/providers/http_vehicle.rs +++ b/clash_lib/src/app/remote_content_manager/providers/http_vehicle.rs @@ -71,7 +71,7 @@ mod tests { #[tokio::test] async fn test_http_vehicle() { - let u = "http://mockbin.org/bin/db6924ba-6b95-4766-b926-e609e1ce49d2" + let u = "https://httpbin.yba.dev/base64/SFRUUEJJTiBpcyBhd2Vzb21l" .parse::() .unwrap(); let r = Arc::new(Resolver::new_default().await); @@ -83,6 +83,6 @@ mod tests { ); let data = v.read().await.unwrap(); - assert_eq!(str::from_utf8(&data).unwrap(), "ok"); + assert_eq!(str::from_utf8(&data).unwrap(), "HTTPBIN is awesome"); } } diff --git a/clash_lib/src/app/remote_content_manager/providers/proxy_provider/proxy_set_provider.rs b/clash_lib/src/app/remote_content_manager/providers/proxy_provider/proxy_set_provider.rs index d6f7bb7a2..163374090 100644 --- a/clash_lib/src/app/remote_content_manager/providers/proxy_provider/proxy_set_provider.rs +++ b/clash_lib/src/app/remote_content_manager/providers/proxy_provider/proxy_set_provider.rs @@ -102,7 +102,7 @@ impl ProxySetProvider { OutboundProxyProtocol::Reject => Ok(reject::Handler::new()), OutboundProxyProtocol::Ss(s) => s.try_into(), OutboundProxyProtocol::Socks5(_) => todo!("socks5 not supported yet"), - OutboundProxyProtocol::Trojan(_) => todo!("trojan not supported yet"), + OutboundProxyProtocol::Trojan(tr) => tr.try_into(), OutboundProxyProtocol::Vmess(vm) => vm.try_into(), }) .collect::, _>>(); diff --git a/clash_lib/src/app/router/rules/geoip.rs b/clash_lib/src/app/router/rules/geoip.rs index 2cbc12217..25a7b2fcf 100644 --- a/clash_lib/src/app/router/rules/geoip.rs +++ b/clash_lib/src/app/router/rules/geoip.rs @@ -1,5 +1,7 @@ use std::sync::Arc; +use tracing::debug; + use crate::{common::mmdb, session::Session}; use super::RuleMatcher; @@ -24,7 +26,10 @@ impl RuleMatcher for GeoIP { .unwrap_or_default() == self.country_code } - Err(_) => todo!(), + Err(e) => { + debug!("GeoIP lookup failed: {}", e); + false + } }, crate::session::SocksAddr::Domain(_, _) => false, } diff --git a/clash_lib/src/lib.rs b/clash_lib/src/lib.rs index c820685c1..a06d862fe 100644 --- a/clash_lib/src/lib.rs +++ b/clash_lib/src/lib.rs @@ -21,6 +21,7 @@ use state::InitCell; use std::io; use std::path::PathBuf; use tokio::task::JoinHandle; +use tracing::error; use std::sync::Arc; use thiserror::Error; @@ -144,6 +145,12 @@ async fn start_async(opts: Options) -> Result<(), Error> { ) .map_err(|x| Error::InvalidConfig(format!("failed to setup logging: {}", x.to_string())))?; + let default_panic = std::panic::take_hook(); + std::panic::set_hook(Box::new(move |info| { + default_panic(info); + error!("panic hook: {:?}", info); + })); + let mut tasks = Vec::::new(); let mut runners = Vec::new();