Skip to content

Commit

Permalink
fix: implement simple obfs for shadowsocks (#189)
Browse files Browse the repository at this point in the history
* fix: make simple-opts a alias of plugin_opts

* fix: support simple-obfs http mode

* chore: fmt

* feat: support simple-opts tls mode

---------

Co-authored-by: Yuwei Ba <[email protected]>
  • Loading branch information
greenhat616 and ibigbug authored Nov 24, 2023
1 parent 0da9ea7 commit 6a8db70
Show file tree
Hide file tree
Showing 10 changed files with 573 additions and 150 deletions.
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

0 comments on commit 6a8db70

Please sign in to comment.