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

fix: implement simple obfs for shadowsocks #189

Merged
merged 5 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,7 @@ venv/
# don't check in this real config
ignore*.yaml
cache.db
Country.mmdb
ruleset/

rust-project.json
1 change: 1 addition & 0 deletions clash_lib/src/config/internal/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ pub struct OutboundShadowsocks {
#[serde(default = "default_bool_true")]
pub udp: bool,
pub plugin: Option<String>,
#[serde(alias = "plugin-opts")]
pub plugin_opts: Option<HashMap<String, serde_yaml::Value>>,
}

Expand Down
31 changes: 19 additions & 12 deletions clash_lib/src/proxy/shadowsocks/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
mod datagram;
mod obfs;
mod simple_obfs;
mod stream;
mod v2ray;

use async_trait::async_trait;
use futures::TryFutureExt;
use futures::{Stream, TryFutureExt};
use shadowsocks::{
config::ServerType, context::Context, crypto::CipherKind,
relay::udprelay::proxy_socket::UdpSocketType, ProxyClientStream, ProxySocket, ServerConfig,
Expand Down Expand Up @@ -209,19 +209,26 @@ impl OutboundHandler for Handler {
sess: &Session,
#[allow(unused_variables)] _resolver: ThreadSafeDNSResolver,
) -> std::io::Result<AnyStream> {
if let Some(plugin) = &self.opts.plugin_opts {
match plugin {
OBFSOption::Simple(_) => {
return Err(io::Error::new(
io::ErrorKind::Other,
"simple-obfs is deprecated, please use v2ray-plugin instead",
))
let stream: AnyStream = match &self.opts.plugin_opts {
Some(plugin) => match plugin {
OBFSOption::Simple(opts) => {
tracing::warn!("simple-obfs is deprecated, please use v2ray-plugin instead");
match opts.mode {
SimpleOBFSMode::Http => {
simple_obfs::SimpleObfsHTTP::new(s, opts.host.clone(), self.opts.port)
.into()
}
SimpleOBFSMode::Tls => {
simple_obfs::SimpleObfsTLS::new(s, opts.host.clone()).into()
}
}
}
OBFSOption::V2Ray(_opt) => {
todo!("v2ray-plugin is not implemented yet")
}
}
}
},
None => s,
};

let ctx = Context::new_shared(ServerType::Local);
let cfg = ServerConfig::new(
Expand All @@ -237,7 +244,7 @@ impl OutboundHandler for Handler {

let stream = ProxyClientStream::from_stream(
ctx,
s,
stream,
&cfg,
(sess.destination.host(), sess.destination.port()),
);
Expand Down
4 changes: 0 additions & 4 deletions clash_lib/src/proxy/shadowsocks/obfs/mod.rs

This file was deleted.

133 changes: 0 additions & 133 deletions clash_lib/src/proxy/shadowsocks/obfs/simple.rs

This file was deleted.

Loading
Loading