Skip to content

Commit

Permalink
fixed cwd for file vehicle & dns listen when disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
ibigbug committed Sep 26, 2023
1 parent 5f29ec8 commit e821d5c
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .cargo/config
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ rustflags = ["--cfg", "tokio_unstable"]

[env]
BORING_BSSL_SOURCE_PATH = { value = "deps/boringssl/src", relative = true}
RUST_LOG= { value = "clash=trace" }
RUST_LOG = { value = "clash=trace" }
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion clash/tests/data/config/rules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ socks-port: 8889
mixed-port: 8899

tun:
enable: false
enable: true
device-id: "dev://utun1989"

dns:
Expand Down
2 changes: 1 addition & 1 deletion clash_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ axum = { version = "0.6.20", features = ["ws"] }
tower-http = { version = "0.4.0", features = ["fs", "trace", "cors"] }
chrono = { version = "0.4.26", features = ["serde"] }

tun = { git = "https://github.com/Watfaq/rust-tun.git", rev = "5c0702b", features = ["async"] }
tun = { git = "https://github.com/Watfaq/rust-tun.git", rev = "28936b6", features = ["async"] }
netstack-lwip = { git = "https://github.com/Watfaq/netstack-lwip.git", rev = "8c8c0b0" }
boringtun = { version = "0.6.0", features = ["device"] }

Expand Down
5 changes: 5 additions & 0 deletions clash_lib/src/app/dispatcher/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ impl Dispatcher {
let (remote_receiver_w, mut remote_receiver_r) = tokio::sync::mpsc::channel(32);

let s = sess.clone();
let ss = sess.clone();
let t1 = tokio::spawn(async move {
while let Some(packet) = local_r.next().await {
let mut sess = sess.clone();
Expand Down Expand Up @@ -340,8 +341,11 @@ impl Dispatcher {
},
};
}

trace!("UDP session local -> remote finished for {}", ss);
});

let ss = s.clone();
let t2 = tokio::spawn(async move {
while let Some(packet) = remote_receiver_r.recv().await {
match local_w.send(packet.clone()).await {
Expand All @@ -354,6 +358,7 @@ impl Dispatcher {
}
}
}
trace!("UDP session remote -> local finished for {}", ss);
});

let (close_sender, close_receiver) = tokio::sync::oneshot::channel::<u8>();
Expand Down
4 changes: 4 additions & 0 deletions clash_lib/src/app/dns/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ impl RequestHandler for DnsHandler {
static DEFAULT_DNS_SERVER_TIMEOUT: Duration = Duration::from_secs(5);

pub async fn get_dns_listener(cfg: Config, resolver: ThreadSafeDNSResolver) -> Option<Runner> {
if !cfg.enable {
return None;
}

let h = DnsHandler { resolver };
let mut s = ServerFuture::new(h);

Expand Down
4 changes: 2 additions & 2 deletions clash_lib/src/app/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ pub fn setup_logging(level: LogLevel, collector: EventCollector) -> anyhow::Resu
};

let subscriber = tracing_subscriber::registry()
.with(ios_os_log)
.with(jaeger)
.with(filter)
.with(collector)
Expand All @@ -110,7 +109,8 @@ pub fn setup_logging(level: LogLevel, collector: EventCollector) -> anyhow::Resu
.with_file(true)
.with_line_number(true)
.with_writer(std::io::stdout),
);
)
.with(ios_os_log);

let v = tracing::subscriber::set_global_default(subscriber)
.map_err(|x| anyhow!("setup logging error: {}", x))?;
Expand Down
17 changes: 10 additions & 7 deletions clash_lib/src/app/outbound/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use anyhow::Result;
use erased_serde::Serialize;
use http::Uri;
use std::collections::HashMap;
use std::path::PathBuf;
use std::sync::Arc;
use std::time::Duration;
use tokio::sync::{Mutex, RwLock};
Expand Down Expand Up @@ -591,7 +592,12 @@ impl OutboundManager {
provider_registry.insert(name, Arc::new(RwLock::new(provider)));
}
OutboundProxyProviderDef::File(file) => {
let vehicle = file_vehicle::Vehicle::new(&file.path);
let vehicle = file_vehicle::Vehicle::new(
PathBuf::from(cwd.clone())
.join(&file.path)
.to_str()
.unwrap(),
);
let hc = HealthCheck::new(
vec![],
file.health_check.url,
Expand All @@ -616,14 +622,11 @@ impl OutboundManager {

for p in provider_registry.values() {
info!("initializing provider {}", p.read().await.name());
match p.write().await.initialize().await {
let p = p.write().await;
match p.initialize().await {
Ok(_) => {}
Err(err) => {
error!(
"failed to initialize proxy provider {}: {}",
p.read().await.name(),
err
);
error!("failed to initialize proxy provider {}: {}", p.name(), err);
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion clash_lib/src/app/router/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::session::{Session, SocksAddr};

use crate::app::router::rules::final_::Final;
use std::collections::HashMap;
use std::path::PathBuf;
use std::sync::Arc;
use std::time::Duration;

Expand Down Expand Up @@ -133,7 +134,12 @@ impl Router {
rule_provider_registry.insert(name, Arc::new(provider));
}
RuleProviderDef::File(file) => {
let vehicle = file_vehicle::Vehicle::new(&file.path);
let vehicle = file_vehicle::Vehicle::new(
PathBuf::from(cwd.clone())
.join(&file.path)
.to_str()
.unwrap(),
);

let provider = RuleProviderImpl::new(
name.clone(),
Expand Down
2 changes: 2 additions & 0 deletions clash_lib/src/proxy/tun/inbound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ async fn handle_inbound_datagram(
}
}
}

closer.send(0).ok();
});
}
Expand All @@ -120,6 +121,7 @@ pub fn get_runner(
resolver: ThreadSafeDNSResolver,
) -> Result<Option<Runner>, Error> {
if !cfg.enable {
trace!("tun is disabled");
return Ok(None);
}

Expand Down

0 comments on commit e821d5c

Please sign in to comment.