Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support shadow-tls(v3 only) #346

Merged
merged 10 commits into from
Apr 9, 2024
82 changes: 40 additions & 42 deletions Cargo.lock

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

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ edition = "2021"
opt-level = "s"
codegen-units = 1
lto = true
strip = true
strip = true

[patch.crates-io]
tokio-rustls = { git = "https://github.com/Watfaq/tokio-rustls.git", rev = "fcda89f6348c1e696b239bc7e0b168015cfb8c08"}
rustls = { git = "https://github.com/Watfaq/rustls.git", rev = "43ecd5c610741668488e6d57857f9900a2087a5b"}
2 changes: 1 addition & 1 deletion clash_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ opentelemetry-otlp = { version = "0.15.0", features = ["http-proto"] }
crc32fast = "1.4.0"
brotli = "4.0.0"
hmac = "0.12.1"
sha1 = "0.10"
sha2 = "0.10.8"
md-5 = "0.10.5"
chacha20poly1305 = "0.10"
Expand Down Expand Up @@ -126,7 +127,6 @@ tokio-test = "0.4.4"
axum-macros = "0.4.0"
bollard = "0.16"
serial_test = "3.0.0"
tracing-test = "0.2.4"

[target.'cfg(macos)'.dependencies]
security-framework = "2.10.0"
5 changes: 3 additions & 2 deletions clash_lib/src/app/inbound/network_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use tracing::{info, warn};
use std::net::{IpAddr, Ipv4Addr};
use std::sync::Arc;

#[derive(Eq, PartialEq, Hash)]
#[derive(Eq, PartialEq, Hash, Clone, Debug)]
pub enum ListenerType {
Http,
Socks5,
Expand Down Expand Up @@ -114,13 +114,14 @@ impl NetworkInboundListener {
};

if listener.handle_tcp() {
let listener_type = self.listener_type.clone();
info!("{} TCP listening at: {}:{}", self.name, ip, self.port);

let tcp_listener = listener.clone();
runners.push(
async move {
tcp_listener.listen_tcp().await.map_err(|e| {
warn!("handler tcp listen failed: {}", e);
warn!("handler of {:?} tcp listen failed: {}", listener_type, e);
e.into()
})
}
Expand Down
9 changes: 9 additions & 0 deletions clash_lib/src/proxy/converters/shadowsocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ impl TryFrom<&OutboundShadowsocks> for AnyOutboundHandler {
.try_into()
.map(OBFSOption::V2Ray)
.ok(),
"shadow-tls" => s
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mind adding a docker test for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, but need some modification of docker test. Since the shadow-tls is a plugin of shadowsocks, we need to extend the docker test's ability by enabling it to start multiple images altogether

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or we shall create a new docker images, including the binary of shadowsocks&shadow-tls. what do you think

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right. another option might be extending our tests to support building a local image and we make a Dockerfile for ss and the plugin.

this can be done in a separate PR later I guess.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i've extended the test utility and run multiple images at the same time as the preparation for the docker test. you can have a quick look, shall i merge it in this PR or in a separate one?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah i think it's better to separate for easier review

Copy link
Contributor Author

@VendettaReborn VendettaReborn Apr 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alright

.plugin_opts
.clone()
.ok_or(Error::InvalidConfig(
"plugin_opts is required for plugin obfs".to_owned(),
))?
.try_into()
.map(OBFSOption::ShadowTls)
.ok(),
_ => {
return Err(Error::InvalidConfig(format!(
"unsupported plugin: {}",
Expand Down
Loading