Skip to content

Commit

Permalink
enable feature flags for outbounds (#492)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibigbug authored Jul 14, 2024
1 parent c0eb0b6 commit ed84bb6
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 6 deletions.
12 changes: 7 additions & 5 deletions clash_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ version = { workspace = true }
edition = { workspace = true }

[features]
default = ["shadowsocks"]
default = []
shadowsocks = ["dep:shadowsocks"]
tuic = ["dep:tuic", "dep:tuic-quinn", "dep:quinn", "dep:register-count"]
tracing = []
bench = ["criterion"]
onion = ["arti-client/onion-service-client"]
Expand Down Expand Up @@ -112,10 +114,10 @@ arti-client = { version = "0.20.0", default-features = false, features = ["tokio
tor-rtcompat = { version = "0.20.0" }

# tuic
tuic = { rev = "82fab62", git = "https://github.com/Itsusinn/tuic.git" }
tuic-quinn = { rev = "82fab62", git = "https://github.com/Itsusinn/tuic.git" }
quinn = { version = "0.10", default-features = false, features = ["futures-io", "runtime-tokio", "tls-rustls"] }
register-count = "0.1.0"
tuic = { rev = "82fab62", optional = true, git = "https://github.com/Itsusinn/tuic.git" }
tuic-quinn = { rev = "82fab62", optional = true, git = "https://github.com/Itsusinn/tuic.git" }
quinn = { version = "0.10", optional = true, default-features = false, features = ["futures-io", "runtime-tokio", "tls-rustls"] }
register-count = { version = "0.1.0", optional = true }

console-subscriber = { version = "0.3.0" }
tracing-timing = { version = "0.6.0" }
Expand Down
3 changes: 2 additions & 1 deletion clash_lib/src/app/outbound/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ impl OutboundManager {
handlers
.insert(PROXY_REJECT.to_string(), reject::Handler::new());
}

#[cfg(feature = "shadowsocks")]
OutboundProxyProtocol::Ss(s) => {
handlers.insert(s.name.clone(), s.try_into()?);
}
Expand All @@ -223,6 +223,7 @@ impl OutboundManager {
OutboundProxyProtocol::Tor(tor) => {
handlers.insert(tor.name.clone(), tor.try_into()?);
}
#[cfg(feature = "tuic")]
OutboundProxyProtocol::Tuic(tuic) => {
handlers.insert(tuic.name.clone(), tuic.try_into()?);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,14 @@ impl ProxySetProvider {
OutboundProxyProtocol::Reject => {
Ok(reject::Handler::new())
}
#[cfg(feature = "shadowsocks")]
OutboundProxyProtocol::Ss(s) => s.try_into(),
OutboundProxyProtocol::Socks5(s) => s.try_into(),
OutboundProxyProtocol::Trojan(tr) => tr.try_into(),
OutboundProxyProtocol::Vmess(vm) => vm.try_into(),
OutboundProxyProtocol::Wireguard(wg) => wg.try_into(),
OutboundProxyProtocol::Tor(tor) => tor.try_into(),
#[cfg(feature = "tuic")]
OutboundProxyProtocol::Tuic(tuic) => tuic.try_into(),
})
.collect::<Result<Vec<_>, _>>();
Expand Down
6 changes: 6 additions & 0 deletions clash_lib/src/config/internal/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub enum OutboundProxyProtocol {
Direct,
#[serde(skip)]
Reject,
#[cfg(feature = "shadowsocks")]
#[serde(rename = "ss")]
Ss(OutboundShadowsocks),
#[serde(rename = "socks5")]
Expand All @@ -67,6 +68,7 @@ pub enum OutboundProxyProtocol {
Wireguard(OutboundWireguard),
#[serde(rename = "tor")]
Tor(OutboundTor),
#[cfg(feature = "tuic")]
#[serde(rename = "tuic")]
Tuic(OutboundTuic),
}
Expand All @@ -76,12 +78,14 @@ impl OutboundProxyProtocol {
match &self {
OutboundProxyProtocol::Direct => PROXY_DIRECT,
OutboundProxyProtocol::Reject => PROXY_REJECT,
#[cfg(feature = "shadowsocks")]
OutboundProxyProtocol::Ss(ss) => &ss.name,
OutboundProxyProtocol::Socks5(socks5) => &socks5.name,
OutboundProxyProtocol::Trojan(trojan) => &trojan.name,
OutboundProxyProtocol::Vmess(vmess) => &vmess.name,
OutboundProxyProtocol::Wireguard(wireguard) => &wireguard.name,
OutboundProxyProtocol::Tor(tor) => &tor.name,
#[cfg(feature = "tuic")]
OutboundProxyProtocol::Tuic(tuic) => &tuic.name,
}
}
Expand All @@ -106,6 +110,7 @@ impl TryFrom<HashMap<String, Value>> for OutboundProxyProtocol {
impl Display for OutboundProxyProtocol {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
#[cfg(feature = "shadowsocks")]
OutboundProxyProtocol::Ss(_) => write!(f, "Shadowsocks"),
OutboundProxyProtocol::Socks5(_) => write!(f, "Socks5"),
OutboundProxyProtocol::Direct => write!(f, "{}", PROXY_DIRECT),
Expand All @@ -114,6 +119,7 @@ impl Display for OutboundProxyProtocol {
OutboundProxyProtocol::Vmess(_) => write!(f, "Vmess"),
OutboundProxyProtocol::Wireguard(_) => write!(f, "Wireguard"),
OutboundProxyProtocol::Tor(_) => write!(f, "Tor"),
#[cfg(feature = "tuic")]
OutboundProxyProtocol::Tuic(_) => write!(f, "Tuic"),
}
}
Expand Down
2 changes: 2 additions & 0 deletions clash_lib/src/proxy/converters/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#[cfg(feature = "shadowsocks")]
pub mod shadowsocks;
pub mod socks5;
pub mod tor;
pub mod trojan;
#[cfg(feature = "tuic")]
pub mod tuic;
pub mod vmess;
pub mod wireguard;
1 change: 1 addition & 0 deletions clash_lib/src/proxy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub mod shadowsocks;
pub mod socks;
pub mod tor;
pub mod trojan;
#[cfg(feature = "tuic")]
pub mod tuic;
pub mod tun;
pub mod utils;
Expand Down
1 change: 1 addition & 0 deletions clash_lib/src/proxy/relay/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ impl OutboundHandler for Handler {
}
}

#[cfg(feature = "shadowsocks")]
#[cfg(all(test, not(ci)))]
mod tests {

Expand Down
3 changes: 3 additions & 0 deletions clash_lib/src/proxy/utils/test_utils/consts.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
pub const LOCAL_ADDR: &str = "127.0.0.1";

pub const IMAGE_WG: &str = "lscr.io/linuxserver/wireguard:1.0.20210914-legacy";
#[cfg(feature = "shadowsocks")]
pub const IMAGE_SS_RUST: &str = "ghcr.io/shadowsocks/ssserver-rust:latest";
#[cfg(feature = "shadowsocks")]
pub const IMAGE_SHADOW_TLS: &str = "ghcr.io/ihciah/shadow-tls:latest";
#[cfg(feature = "shadowsocks")]
pub const IMAGE_OBFS: &str = "liaohuqiu/simple-obfs:latest";
pub const IMAGE_TROJAN_GO: &str = "p4gefau1t/trojan-go:latest";
pub const IMAGE_VMESS: &str = "v2fly/v2fly-core:v4.45.2";
Expand Down

0 comments on commit ed84bb6

Please sign in to comment.