Skip to content

Commit

Permalink
Merge branch 'master' into ci/add-sha512sum-version
Browse files Browse the repository at this point in the history
  • Loading branch information
Itsusinn committed Sep 19, 2024
2 parents eadac38 + 96374d6 commit 0999a57
Show file tree
Hide file tree
Showing 51 changed files with 600 additions and 215 deletions.
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ target-dir = "target"
rustflags = ["--cfg", "tokio_unstable"]

[env]
RUST_LOG = { value = "clash=trace" }
RUST_LOG = { value = "clash=trace" }
19 changes: 16 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ env:
IMAGE_NAME: "clash-rs"


# Arm builder https://github.blog/changelog/2024-09-03-github-actions-arm64-linux-and-windows-runners-are-now-generally-available/
jobs:
compile:
name: ${{ matrix.release-name || matrix.target || 'Unknown' }}
Expand Down Expand Up @@ -117,6 +118,11 @@ jobs:
cross: false
postfix: ".exe"
extra-args: "--all-features"
- os: windows-latest
target: aarch64-pc-windows-msvc
cross: false
postfix: ".exe"
extra-args: --features "shadowsocks tuic"
# Windows static-crt
- os: windows-latest
target: x86_64-pc-windows-msvc
Expand All @@ -132,6 +138,13 @@ jobs:
postfix: ".exe"
extra-args: "--all-features"
rustflags: "-Ctarget-feature=+crt-static --cfg tokio_unstable"
- os: windows-latest
target: aarch64-pc-windows-msvc
release-name: aarch64-pc-windows-msvc-static-crt
cross: false
postfix: ".exe"
extra-args: --features "shadowsocks tuic"
rustflags: "-Ctarget-feature=+crt-static --cfg tokio_unstable"
# MacOSX
- os: macos-12
target: x86_64-apple-darwin
Expand Down Expand Up @@ -197,7 +210,7 @@ jobs:
env:
RUSTFLAGS: ${{ matrix.rustflags || '--cfg tokio_unstable' }}

- name: Cargo test
- name: Cargo test (docker test on linux)
uses: clechasseur/rs-cargo@v2
if: startsWith(matrix.os, 'ubuntu')
with:
Expand All @@ -208,9 +221,9 @@ jobs:
CROSS_CONTAINER_OPTS: "--network host"
RUSTFLAGS: ${{ matrix.rustflags || '--cfg tokio_unstable' }}

- name: Cargo test (no docker test)
- name: Cargo test (no docker test on windows-non-arm and macos)
uses: clechasseur/rs-cargo@v2
if: ${{ !startsWith(matrix.os, 'ubuntu') }}
if: ${{ !startsWith(matrix.os, 'ubuntu') && matrix.target != 'aarch64-pc-windows-msvc' }}
with:
use-cross: ${{ matrix.cross }}
command: test
Expand Down
6 changes: 4 additions & 2 deletions clash/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ struct Cli {
default_value = "false",
help = "Print clash-rs version and exit"
)]
version: bool
version: bool,
#[clap(short, long, help = "Additinally log to file")]
log_file: Option<String>,
}

fn main() {
Expand Down Expand Up @@ -79,7 +81,7 @@ fn main() {
config: clash::Config::File(file),
cwd: cli.directory.map(|x| x.to_string_lossy().to_string()),
rt: Some(TokioRuntime::MultiThread),
log_file: None,
log_file: cli.log_file,
}) {
Ok(_) => {}
Err(_) => {
Expand Down
1 change: 1 addition & 0 deletions clash/tests/data/config/rules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ tun:
device-id: "dev://utun1989"
route-all: true
gateway: "198.19.0.1/32"
so-mark: 3389
# routes:
# - 0.0.0.0/1
# - 128.0.0.0/1
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions clash_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ shadowsocks = ["dep:shadowsocks"]
tuic = ["dep:tuic", "dep:tuic-quinn", "dep:quinn", "dep:register-count"]
tracing = []
bench = ["dep:criterion"]
onion = ["arti-client/onion-service-client"]
onion = ["dep:arti-client", "dep:tor-rtcompat", "arti-client/onion-service-client"]

[dependencies]
# Async
Expand Down Expand Up @@ -117,8 +117,8 @@ maxminddb = "0.24"
public-suffix = "0.1"
murmur3 = "0.5"

arti-client = { version = "0.22", default-features = false, features = ["tokio", "rustls", "static-sqlite"] }
tor-rtcompat = { version = "0.22", default-features = false }
arti-client = { version = "0.22", optional = true, default-features = false, features = ["tokio", "rustls", "static-sqlite"] }
tor-rtcompat = { version = "0.22", optional = true, default-features = false }

# tuic
tuic = { tag = "v1.2.0", optional = true, git = "https://github.com/Itsusinn/tuic.git" }
Expand Down
32 changes: 10 additions & 22 deletions clash_lib/src/app/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use serde::Serialize;
use tokio::sync::broadcast::Sender;

use tracing::{debug, error};
use tracing_appender::non_blocking::{NonBlocking, WorkerGuard};
use tracing_appender::non_blocking::WorkerGuard;
use tracing_oslog::OsLogger;
use tracing_subscriber::{filter, filter::Directive, prelude::*, EnvFilter, Layer};

Expand Down Expand Up @@ -76,24 +76,6 @@ where
}
}

struct W(Option<NonBlocking>);

impl std::io::Write for W {
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
match self.0 {
Some(ref mut w) => w.write(buf),
None => Ok(buf.len()),
}
}

fn flush(&mut self) -> std::io::Result<()> {
match self.0 {
Some(ref mut w) => w.flush(),
None => Ok(()),
}
}
}

pub fn setup_logging(
level: LogLevel,
collector: EventCollector,
Expand Down Expand Up @@ -165,6 +147,15 @@ pub fn setup_logging(
.with(filter)
.with(collector)
.with(console_layer)
.with(appender.map(|x| {
tracing_subscriber::fmt::Layer::new()
.with_ansi(false)
.compact()
.with_file(true)
.with_line_number(true)
.with_level(true)
.with_writer(x)
}))
.with(
tracing_subscriber::fmt::Layer::new()
.with_ansi(std::io::stdout().is_terminal())
Expand All @@ -174,9 +165,6 @@ pub fn setup_logging(
.with_line_number(true)
.with_level(true)
.with_thread_ids(true)
.with_writer(move || -> Box<dyn std::io::Write> {
Box::new(W(appender.clone()))
})
.with_writer(std::io::stdout),
)
.with(ios_os_log);
Expand Down
25 changes: 18 additions & 7 deletions clash_lib/src/app/outbound/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::{
OutboundProxyProviderDef, PROXY_DIRECT, PROXY_GLOBAL, PROXY_REJECT,
},
proxy::{
fallback, loadbalance, selector, socks, tor, trojan,
fallback, loadbalance, selector, socks, trojan,
utils::{DirectConnector, ProxyConnector},
vmess, wg, OutboundType,
},
Expand All @@ -44,6 +44,8 @@ use super::utils::proxy_groups_dag_sort;

#[cfg(feature = "shadowsocks")]
use crate::proxy::shadowsocks;
#[cfg(feature = "onion")]
use crate::proxy::tor;
#[cfg(feature = "tuic")]
use crate::proxy::tuic;

Expand Down Expand Up @@ -275,6 +277,7 @@ impl OutboundManager {
});
}

#[cfg(feature = "onion")]
OutboundProxyProtocol::Tor(tor) => {
handlers.insert(tor.name.clone(), {
let h: tor::Handler = tor.try_into()?;
Expand Down Expand Up @@ -390,8 +393,9 @@ impl OutboundManager {
let relay = relay::Handler::new(
relay::HandlerOptions {
name: proto.name.clone(),
shared_opts: crate::proxy::HandlerSharedOptions {
common_opts: crate::proxy::HandlerCommonOptions {
icon: proto.icon.clone(),
..Default::default()
},
},
providers,
Expand Down Expand Up @@ -443,8 +447,9 @@ impl OutboundManager {
let url_test = urltest::Handler::new(
urltest::HandlerOptions {
name: proto.name.clone(),
shared_opts: crate::proxy::HandlerSharedOptions {
common_opts: crate::proxy::HandlerCommonOptions {
icon: proto.icon.clone(),
..Default::default()
},
..Default::default()
},
Expand Down Expand Up @@ -499,8 +504,9 @@ impl OutboundManager {
let fallback = fallback::Handler::new(
fallback::HandlerOptions {
name: proto.name.clone(),
shared_opts: crate::proxy::HandlerSharedOptions {
common_opts: crate::proxy::HandlerCommonOptions {
icon: proto.icon.clone(),
..Default::default()
},
..Default::default()
},
Expand Down Expand Up @@ -554,8 +560,9 @@ impl OutboundManager {
let load_balance = loadbalance::Handler::new(
loadbalance::HandlerOptions {
name: proto.name.clone(),
shared_opts: crate::proxy::HandlerSharedOptions {
common_opts: crate::proxy::HandlerCommonOptions {
icon: proto.icon.clone(),
..Default::default()
},
..Default::default()
},
Expand Down Expand Up @@ -613,8 +620,9 @@ impl OutboundManager {
selector::HandlerOptions {
name: proto.name.clone(),
udp: proto.udp.unwrap_or(true),
shared_opts: crate::proxy::HandlerSharedOptions {
common_opts: crate::proxy::HandlerCommonOptions {
icon: proto.icon.clone(),
..Default::default()
},
},
providers,
Expand Down Expand Up @@ -651,7 +659,10 @@ impl OutboundManager {
selector::HandlerOptions {
name: PROXY_GLOBAL.to_owned(),
udp: true,
shared_opts: crate::proxy::HandlerSharedOptions { icon: None },
common_opts: crate::proxy::HandlerCommonOptions {
icon: None,
..Default::default()
},
},
vec![pd.clone()],
stored_selection,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ use crate::{
},
common::errors::map_io_error,
config::internal::proxy::OutboundProxyProtocol,
proxy::{direct, reject, socks, tor, trojan, vmess, wg, AnyOutboundHandler},
proxy::{direct, reject, socks, trojan, vmess, wg, AnyOutboundHandler},
Error,
};

#[cfg(feature = "shadowsocks")]
use crate::proxy::shadowsocks;
#[cfg(feature = "onion")]
use crate::proxy::tor;
#[cfg(feature = "tuic")]
use crate::proxy::tuic;

Expand Down Expand Up @@ -139,6 +141,7 @@ impl ProxySetProvider {
let h: wg::Handler = wg.try_into()?;
Ok(Arc::new(h) as _)
}
#[cfg(feature = "onion")]
OutboundProxyProtocol::Tor(tor) => {
let h: tor::Handler = tor.try_into()?;
Ok(Arc::new(h) as _)
Expand Down
4 changes: 4 additions & 0 deletions clash_lib/src/config/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ pub struct TunConfig {
#[serde(default)]
pub route_all: bool,
pub mtu: Option<i32>,
/// fwmark on Linux only
pub so_mark: Option<u32>,
/// policy routing table on Linux only
pub route_table: Option<u32>,
}

#[derive(Serialize, Deserialize, Default, Copy, Clone)]
Expand Down
4 changes: 4 additions & 0 deletions clash_lib/src/config/internal/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ impl TryFrom<def::Config> for Config {
Error::InvalidConfig(format!("parse tun gateway: {}", x))
})?,
mtu: t.mtu,
so_mark: t.so_mark,
route_table: t.route_table,
},
None => TunConfig::default(),
},
Expand Down Expand Up @@ -300,6 +302,8 @@ pub struct TunConfig {
pub routes: Vec<IpNet>,
pub gateway: IpNet,
pub mtu: Option<i32>,
pub so_mark: Option<u32>,
pub route_table: Option<u32>,
}

#[derive(Clone, Default)]
Expand Down
Loading

0 comments on commit 0999a57

Please sign in to comment.