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

refactor(ss): adapt to ss-rust latest api #607

Merged
merged 14 commits into from
Sep 24, 2024
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
11 changes: 9 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ env:
PACKAGE: "clash"
REGISTRY: "ghcr.io"
IMAGE_NAME: "clash-rs"
RUST_LOG: "clash=TRACE"


# Arm builder https://github.blog/changelog/2024-09-03-github-actions-arm64-linux-and-windows-runners-are-now-generally-available/
Expand Down Expand Up @@ -221,13 +222,17 @@ jobs:
use-cross: ${{ matrix.cross }}
command: fmt
args: --all -- --check

env:
CLASH_DOCKER_TEST: "true"

- name: Cargo clippy
uses: clechasseur/rs-cargo@v2
with:
use-cross: ${{ matrix.cross }}
command: clippy
args: --all --target ${{ matrix.target }} ${{ matrix.extra-args }} -- -D warnings
env:
CLASH_DOCKER_TEST: "true"

- name: Cargo test (docker test on linux)
uses: clechasseur/rs-cargo@v2
Expand Down Expand Up @@ -306,7 +311,9 @@ jobs:
# Deleted latest tag and push it
git tag -d latest || true
git push origin :refs/tags/latest || true
# Deleted all drafts
# Create local tag
git tag latest
# Delete all drafts
gh release list | grep Draft | awk '{print $1 " \t"}' | while read -r line; do gh release delete -y "$line"; done
env:
GH_TOKEN: ${{ github.token }}
Expand Down
29 changes: 27 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cross.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pre-build = [

[build.env]
volumes = ["/var/run/docker.sock=/var/run/docker.sock"] # Docker in docker
passthrough = ["CLASH_GIT_REF", "CLASH_GIT_SHA", "RUSTFLAGS", "CLASH_DOCKER_TEST"]
passthrough = ["CLASH_GIT_REF", "CLASH_GIT_SHA", "RUSTFLAGS", "RUST_LOG", "CLASH_DOCKER_TEST"]

[target.x86_64-unknown-linux-gnu]
image = "ghcr.io/cross-rs/x86_64-unknown-linux-gnu:main"
Expand Down
8 changes: 7 additions & 1 deletion clash/tests/data/config/ss.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ proxies:
password: "password"
udp: true

proxy-groups:
- name: "udp-relay"
type: relay
proxies:
- ss-01
- ss-02
rules:
- MATCH, ss-01
- MATCH, udp-relay
...
5 changes: 3 additions & 2 deletions clash_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] }
tracing-oslog = { branch = "main", git = "https://github.com/Absolucy/tracing-oslog.git" }
tracing-appender = "0.2"

shadowsocks = { git = "https://github.com/Watfaq/shadowsocks-rust", rev = "c6cb7fd906fe9f4126f724ae252f8a67cc1926b1", optional = true, features=["aead-cipher-2022","stream-cipher"] }
shadowsocks = { version="1.21", optional = true, features=["aead-cipher-2022","stream-cipher"] }
maxminddb = "0.24"
public-suffix = "0.1"
murmur3 = "0.5"
Expand All @@ -138,7 +138,8 @@ mockall = "0.13.0"
tokio-test = "0.4.4"
axum-macros = "0.4.0"
bollard = "0.17"
serial_test = "3.1.1"
serial_test = "3.1"
env_logger = "0.11"

[build-dependencies]
prost-build = "0.13"
Expand Down
12 changes: 6 additions & 6 deletions clash_lib/src/app/inbound/network_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,21 @@ impl NetworkInboundListener {

fn build_and_insert_listener(&self, runners: &mut Vec<Runner>, ip: Ipv4Addr) {
let listener: AnyInboundListener = match self.listener_type {
ListenerType::Http => http::Listener::new(
ListenerType::Http => Arc::new(http::Listener::new(
(ip, self.port).into(),
self.dispatcher.clone(),
self.authenticator.clone(),
),
ListenerType::Socks5 => socks::Listener::new(
)),
ListenerType::Socks5 => Arc::new(socks::Listener::new(
(ip, self.port).into(),
self.dispatcher.clone(),
self.authenticator.clone(),
),
ListenerType::Mixed => mixed::Listener::new(
)),
ListenerType::Mixed => Arc::new(mixed::Listener::new(
(ip, self.port).into(),
self.dispatcher.clone(),
self.authenticator.clone(),
),
)),
};

if listener.handle_tcp() {
Expand Down
10 changes: 9 additions & 1 deletion clash_lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,15 @@
#[cfg(test)]
mod tests {
use crate::{shutdown, start, Config, Options};
use std::{thread, time::Duration};
use std::{sync::Once, thread, time::Duration};

static INIT: Once = Once::new();

Check warning on line 518 in clash_lib/src/lib.rs

View workflow job for this annotation

GitHub Actions / x86_64-pc-windows-msvc

static `INIT` is never used

Check warning on line 518 in clash_lib/src/lib.rs

View workflow job for this annotation

GitHub Actions / i686-pc-windows-msvc

static `INIT` is never used

Check warning on line 518 in clash_lib/src/lib.rs

View workflow job for this annotation

GitHub Actions / x86_64-pc-windows-msvc-static-crt

static `INIT` is never used

Check warning on line 518 in clash_lib/src/lib.rs

View workflow job for this annotation

GitHub Actions / i686-pc-windows-msvc-static-crt

static `INIT` is never used

Check warning on line 518 in clash_lib/src/lib.rs

View workflow job for this annotation

GitHub Actions / x86_64-apple-darwin

static `INIT` is never used

Check warning on line 518 in clash_lib/src/lib.rs

View workflow job for this annotation

GitHub Actions / aarch64-apple-darwin

static `INIT` is never used

Check warning on line 518 in clash_lib/src/lib.rs

View workflow job for this annotation

GitHub Actions / x86_64-apple-darwin-static-crt

static `INIT` is never used

Check warning on line 518 in clash_lib/src/lib.rs

View workflow job for this annotation

GitHub Actions / aarch64-apple-darwin-static-crt

static `INIT` is never used

pub fn initialize() {

Check warning on line 520 in clash_lib/src/lib.rs

View workflow job for this annotation

GitHub Actions / x86_64-pc-windows-msvc

function `initialize` is never used

Check warning on line 520 in clash_lib/src/lib.rs

View workflow job for this annotation

GitHub Actions / i686-pc-windows-msvc

function `initialize` is never used

Check warning on line 520 in clash_lib/src/lib.rs

View workflow job for this annotation

GitHub Actions / x86_64-pc-windows-msvc-static-crt

function `initialize` is never used

Check warning on line 520 in clash_lib/src/lib.rs

View workflow job for this annotation

GitHub Actions / i686-pc-windows-msvc-static-crt

function `initialize` is never used

Check warning on line 520 in clash_lib/src/lib.rs

View workflow job for this annotation

GitHub Actions / x86_64-apple-darwin

function `initialize` is never used

Check warning on line 520 in clash_lib/src/lib.rs

View workflow job for this annotation

GitHub Actions / aarch64-apple-darwin

function `initialize` is never used

Check warning on line 520 in clash_lib/src/lib.rs

View workflow job for this annotation

GitHub Actions / x86_64-apple-darwin-static-crt

function `initialize` is never used

Check warning on line 520 in clash_lib/src/lib.rs

View workflow job for this annotation

GitHub Actions / aarch64-apple-darwin-static-crt

function `initialize` is never used
INIT.call_once(|| {
env_logger::init();
});
}

#[test]
fn start_and_stop() {
Expand Down
15 changes: 6 additions & 9 deletions clash_lib/src/proxy/datagram.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
app::dns::ThreadSafeDNSResolver,
common::errors::new_io_error,
proxy::{socks::Socks5UDPCodec, AnyOutboundDatagram, InboundDatagram},
proxy::{socks::Socks5UDPCodec, InboundDatagram},
session::SocksAddr,
};
use bytes::Bytes;
Expand Down Expand Up @@ -149,6 +149,8 @@ impl Sink<UdpPacket> for InboundUdp<UdpFramed<Socks5UDPCodec>> {
impl InboundDatagram<UdpPacket> for InboundUdp<UdpFramed<Socks5UDPCodec>> {}

#[must_use = "sinks do nothing unless polled"]
// TODO: maybe we should use abstract datagram IO interface instead of the
// Stream + Sink trait
pub struct OutboundDatagramImpl {
inner: UdpSocket,
resolver: ThreadSafeDNSResolver,
Expand All @@ -157,18 +159,13 @@ pub struct OutboundDatagramImpl {
}

impl OutboundDatagramImpl {
#[allow(clippy::new_ret_no_self)]
pub fn new(
udp: UdpSocket,
resolver: ThreadSafeDNSResolver,
) -> AnyOutboundDatagram {
let s = Self {
pub fn new(udp: UdpSocket, resolver: ThreadSafeDNSResolver) -> Self {
Self {
inner: udp,
resolver,
flushed: true,
pkt: None,
};
Box::new(s) as _
}
}
}

Expand Down
9 changes: 4 additions & 5 deletions clash_lib/src/proxy/http/inbound/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mod proxy;

use crate::{
common::auth::ThreadSafeAuthenticator,
proxy::{utils::apply_tcp_options, AnyInboundListener, InboundListener},
proxy::{utils::apply_tcp_options, InboundListener},
Dispatcher,
};
use async_trait::async_trait;
Expand All @@ -29,17 +29,16 @@ impl Drop for Listener {
}

impl Listener {
#[allow(clippy::new_ret_no_self)]
pub fn new(
addr: SocketAddr,
dispatcher: Arc<Dispatcher>,
authenticator: ThreadSafeAuthenticator,
) -> AnyInboundListener {
Arc::new(Self {
) -> Self {
Self {
addr,
dispatcher,
authenticator,
}) as _
}
}
}

Expand Down
9 changes: 4 additions & 5 deletions clash_lib/src/proxy/mixed/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
common::auth::ThreadSafeAuthenticator,
proxy::{AnyInboundListener, InboundListener},
proxy::InboundListener,
session::{Network, Session},
Dispatcher,
};
Expand All @@ -25,17 +25,16 @@ impl Drop for Listener {
}

impl Listener {
#[allow(clippy::new_ret_no_self)]
pub fn new(
addr: SocketAddr,
dispatcher: Arc<Dispatcher>,
authenticator: ThreadSafeAuthenticator,
) -> AnyInboundListener {
Arc::new(Self {
) -> Self {
Self {
addr,
dispatcher,
authenticator,
}) as _
}
}
}

Expand Down
17 changes: 6 additions & 11 deletions clash_lib/src/proxy/relay/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,9 @@ mod tests {
provider.expect_touch().returning(|| ());
provider.expect_healthcheck().returning(|| ());

provider.expect_proxies().returning(move || {
let mut proxies = Vec::new();
proxies.push(ss_handler.clone());
proxies
});
provider
.expect_proxies()
.returning(move || vec![ss_handler.clone()]);

let handler =
Handler::new(Default::default(), vec![Arc::new(RwLock::new(provider))]);
Expand Down Expand Up @@ -288,12 +286,9 @@ mod tests {
provider.expect_touch().returning(|| ());
provider.expect_healthcheck().returning(|| ());

provider.expect_proxies().returning(move || {
let mut proxies = Vec::new();
proxies.push(ss_handler.clone());
proxies.push(ss_handler.clone());
proxies
});
provider
.expect_proxies()
.returning(move || vec![ss_handler.clone(), ss_handler.clone()]);

let handler =
Handler::new(Default::default(), vec![Arc::new(RwLock::new(provider))]);
Expand Down
Loading