diff --git a/.github/workflows/build-msrv.yml b/.github/workflows/build-msrv.yml index 6f40ce893a71..c0e4808c7cf4 100644 --- a/.github/workflows/build-msrv.yml +++ b/.github/workflows/build-msrv.yml @@ -28,9 +28,9 @@ jobs: - name: Install Rust run: | rustup set profile minimal - rustup toolchain install 1.74 - rustup default 1.74 - rustup override set 1.74 + rustup toolchain install 1.75 + rustup default 1.75 + rustup override set 1.75 - name: Build with All Features Enabled (Unix) if: ${{ runner.os == 'Linux' || runner.os == 'macOS' }} run: cargo build --verbose --features "full-extra local-flow-stat utility-url-outline" diff --git a/Cargo.lock b/Cargo.lock index cc983117a178..c4609e4bb199 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -212,7 +212,7 @@ checksum = "3b43422f69d8ff38f95f1b2bb76517c91589a924d1559a0e935d7c8ce0274c11" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", ] [[package]] @@ -229,7 +229,7 @@ checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", ] [[package]] @@ -411,7 +411,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", ] [[package]] @@ -642,9 +642,9 @@ checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" [[package]] name = "cpufeatures" -version = "0.2.15" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ca741a962e1b0bff6d724a1a0958b686406e853bb14061f218562e1896f95e6" +checksum = "16b80225097f2e5ae4e7179dd2266824648f3e2f49d9134d584b76389d31c4c3" dependencies = [ "libc", ] @@ -740,7 +740,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", ] [[package]] @@ -828,7 +828,28 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", +] + +[[package]] +name = "dynosaur" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92fac44672fabad44990176319b9e94393f3a38b960b5ca2af6cd90f5ecd1497" +dependencies = [ + "dynosaur_derive", + "trait-variant", +] + +[[package]] +name = "dynosaur_derive" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16c187d1e575ef546d24f0fcd7701cc04abfe6b5e7e2758aabc450b99e835ac3" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.89", ] [[package]] @@ -888,7 +909,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", ] [[package]] @@ -1119,7 +1140,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", ] [[package]] @@ -1214,9 +1235,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.4.6" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +checksum = "ccae279728d634d083c00f6099cb58f01cc99c145b84b8be2f6c74618d79922e" dependencies = [ "atomic-waker", "bytes", @@ -1270,9 +1291,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.15.1" +version = "0.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a9bfc1af68b1726ea47d3d5109de126281def866b33970e10fbab11b5dafab3" +checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" [[package]] name = "heapless" @@ -1663,7 +1684,7 @@ checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", ] [[package]] @@ -1780,9 +1801,9 @@ checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" [[package]] name = "itoa" -version = "1.0.11" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" +checksum = "540654e97a3f4470a492cd30ff187bc95d89557a903a2bbf112e2fae98104ef2" [[package]] name = "jemalloc-sys" @@ -1872,7 +1893,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" dependencies = [ "cfg-if", - "windows-targets 0.48.5", + "windows-targets 0.52.6", ] [[package]] @@ -1910,9 +1931,9 @@ checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" [[package]] name = "litemap" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "643cb0b8d4fcc284004d5fd0d67ccf61dfffadb7f75e1e71bc420f4688a3a704" +checksum = "4ee93343901ab17bd981295f2cf0026d4ad018c7c31ba84549a4ddbb47a45104" [[package]] name = "lock_api" @@ -2191,7 +2212,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", ] [[package]] @@ -2355,7 +2376,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", ] [[package]] @@ -2386,7 +2407,7 @@ checksum = "3c0f5fad0874fc7abcd4d750e76917eaebbecaa2c20bde22e1dbeeba8beb758c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", ] [[package]] @@ -2501,9 +2522,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.89" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e" +checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" dependencies = [ "unicode-ident", ] @@ -2570,7 +2591,7 @@ dependencies = [ "once_cell", "socket2", "tracing", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -2840,9 +2861,9 @@ checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustix" -version = "0.38.40" +version = "0.38.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99e4ea3e1cdc4b559b8e5650f9c8e5998e3e5c1343b4eaf034565f32318d63c0" +checksum = "d7f649912bc1495e167a6edee79151c84b1bad49748cb4f1f1167f459f6224f6" dependencies = [ "bitflags 2.6.0", "errno", @@ -2853,9 +2874,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.17" +version = "0.23.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f1a745511c54ba6d4465e8d5dfbd81b45791756de28d4981af70d6dca128f1e" +checksum = "9c9cc1d47e243d655ace55ed38201c19ae02c148ae56412ab8750e8f0166ab7f" dependencies = [ "log", "once_cell", @@ -2937,9 +2958,9 @@ dependencies = [ [[package]] name = "schannel" -version = "0.1.26" +version = "0.1.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" +checksum = "1f29ebaa345f945cec9fbbc532eb307f0fdad8161f281b6369539c8d84876b3d" dependencies = [ "windows-sys 0.59.0", ] @@ -3045,7 +3066,7 @@ checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", ] [[package]] @@ -3114,13 +3135,13 @@ version = "1.22.0" dependencies = [ "aes", "arc-swap", - "async-trait", "base64 0.22.1", "blake3", "bloomfilter", "byte_string", "bytes", "cfg-if", + "dynosaur", "env_logger", "futures", "hickory-resolver", @@ -3142,6 +3163,7 @@ dependencies = [ "thiserror 2.0.3", "tokio", "tokio-tfo", + "trait-variant", "url", "windows-sys 0.59.0", ] @@ -3220,7 +3242,6 @@ name = "shadowsocks-service" version = "1.22.0" dependencies = [ "arc-swap", - "async-trait", "brotli", "bson", "byte_string", @@ -3261,6 +3282,7 @@ dependencies = [ "tokio", "tokio-native-tls", "tokio-rustls", + "trait-variant", "tun2", "webpki-roots", "windows-sys 0.59.0", @@ -3439,9 +3461,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.87" +version = "2.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d" +checksum = "44d46482f1c1c87acd84dea20c1bf5ebff4c757009ed6bf19cfd36fb10e92c4e" dependencies = [ "proc-macro2", "quote", @@ -3450,9 +3472,9 @@ dependencies = [ [[package]] name = "sync_wrapper" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" dependencies = [ "futures-core", ] @@ -3465,7 +3487,7 @@ checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", ] [[package]] @@ -3526,7 +3548,7 @@ dependencies = [ "fastrand", "once_cell", "rustix", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -3565,7 +3587,7 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", ] [[package]] @@ -3576,7 +3598,7 @@ checksum = "f077553d607adc1caf65430528a576c757a71ed73944b66ebb58ef2bbd243568" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", ] [[package]] @@ -3683,7 +3705,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", ] [[package]] @@ -3763,7 +3785,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", ] [[package]] @@ -3806,6 +3828,17 @@ dependencies = [ "tracing-log", ] +[[package]] +name = "trait-variant" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70977707304198400eb4835a78f6a9f928bf41bba420deb8fdb175cd965d77a7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.89", +] + [[package]] name = "try-lock" version = "0.2.5" @@ -3862,9 +3895,9 @@ checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" [[package]] name = "unicode-ident" -version = "1.0.13" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" +checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" [[package]] name = "unicode-normalization" @@ -4011,7 +4044,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", "wasm-bindgen-shared", ] @@ -4045,7 +4078,7 @@ checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -4113,7 +4146,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys 0.48.0", + "windows-sys 0.59.0", ] [[package]] @@ -4374,9 +4407,9 @@ checksum = "213b7324336b53d2414b2db8537e56544d981803139155afa84f76eeebb7a546" [[package]] name = "yoke" -version = "0.7.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c5b1314b079b0930c31e3af543d8ee1757b1951ae1e1565ec704403a7240ca5" +checksum = "120e6aef9aa629e3d4f52dc8cc43a015c7724194c97dfaf45180d2daf2b77f40" dependencies = [ "serde", "stable_deref_trait", @@ -4386,13 +4419,13 @@ dependencies = [ [[package]] name = "yoke-derive" -version = "0.7.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28cc31741b18cb6f1d5ff12f5b7523e3d6eb0852bbbad19d73905511d9849b95" +checksum = "2380878cad4ac9aac1e2435f3eb4020e8374b5f13c296cb75b4620ff8e229154" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", "synstructure", ] @@ -4414,27 +4447,27 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", ] [[package]] name = "zerofrom" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91ec111ce797d0e0784a1116d0ddcdbea84322cd79e5d5ad173daeba4f93ab55" +checksum = "cff3ee08c995dee1859d998dea82f7374f2826091dd9cd47def953cae446cd2e" dependencies = [ "zerofrom-derive", ] [[package]] name = "zerofrom-derive" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ea7b4a3637ea8669cedf0f1fd5c286a17f3de97b8dd5a70a6c167a1730e63a5" +checksum = "595eed982f7d355beb85837f651fa22e90b3c044842dc7f2c2842c086f295808" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", "synstructure", ] @@ -4463,7 +4496,7 @@ checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 67404a8c1921..d353f2ade57b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ documentation = "https://docs.rs/shadowsocks-rust" keywords = ["shadowsocks", "proxy", "socks", "socks5", "firewall"] license = "MIT" edition = "2021" -rust-version = "1.74" +rust-version = "1.75" [badges] maintenance = { status = "passively-maintained" } diff --git a/crates/shadowsocks-service/Cargo.toml b/crates/shadowsocks-service/Cargo.toml index 5e87e32d2f74..9c08924e5a00 100644 --- a/crates/shadowsocks-service/Cargo.toml +++ b/crates/shadowsocks-service/Cargo.toml @@ -9,7 +9,7 @@ documentation = "https://docs.rs/shadowsocks-service" keywords = ["shadowsocks", "proxy", "socks", "socks5", "firewall"] license = "MIT" edition = "2021" -rust-version = "1.74" +rust-version = "1.75" [badges] maintenance = { status = "passively-maintained" } @@ -171,7 +171,7 @@ tokio-rustls = { version = "0.26", optional = true, default-features = false, fe "ring", ] } rustls-native-certs = { version = "0.8", optional = true } -async-trait = "0.1" +trait-variant = "0.1" socket2 = { version = "0.5", features = ["all"] } libc = "~0.2.141" diff --git a/crates/shadowsocks-service/src/local/dns/dns_resolver.rs b/crates/shadowsocks-service/src/local/dns/dns_resolver.rs index 065c28205501..6831578eccd6 100644 --- a/crates/shadowsocks-service/src/local/dns/dns_resolver.rs +++ b/crates/shadowsocks-service/src/local/dns/dns_resolver.rs @@ -5,7 +5,6 @@ use std::{ net::{Ipv4Addr, Ipv6Addr, SocketAddr}, }; -use async_trait::async_trait; use futures::future; use hickory_resolver::proto::{ op::{Message, Query}, @@ -104,7 +103,6 @@ impl DnsResolver { } } -#[async_trait] impl DnsResolve for DnsResolver { async fn resolve(&self, host: &str, port: u16) -> io::Result> { let mut name = Name::from_utf8(host)?; diff --git a/crates/shadowsocks-service/src/local/net/udp/association.rs b/crates/shadowsocks-service/src/local/net/udp/association.rs index 5ca4da94c6cb..d0563158ea7a 100644 --- a/crates/shadowsocks-service/src/local/net/udp/association.rs +++ b/crates/shadowsocks-service/src/local/net/udp/association.rs @@ -9,7 +9,6 @@ use std::{ time::Duration, }; -use async_trait::async_trait; use bytes::Bytes; use futures::future; use log::{debug, error, trace, warn}; @@ -35,10 +34,7 @@ use crate::{ }; /// Writer for sending packets back to client -/// -/// Currently it requires `async-trait` for `async fn` in trait, which will allocate a `Box`ed `Future` every call of `send_to`. -/// This performance issue could be solved when `generic_associated_types` and `generic_associated_types` are stabilized. -#[async_trait] +#[trait_variant::make(Send)] pub trait UdpInboundWrite { /// Sends packet `data` received from `remote_addr` back to `peer_addr` async fn send_to(&self, peer_addr: SocketAddr, remote_addr: &Address, data: &[u8]) -> io::Result<()>; diff --git a/crates/shadowsocks-service/src/local/redir/redir_ext.rs b/crates/shadowsocks-service/src/local/redir/redir_ext.rs index 071a2d1aea55..7caa03773eb2 100644 --- a/crates/shadowsocks-service/src/local/redir/redir_ext.rs +++ b/crates/shadowsocks-service/src/local/redir/redir_ext.rs @@ -8,14 +8,12 @@ use std::{ task::{Context, Poll}, }; -use async_trait::async_trait; use shadowsocks::net::AcceptOpts; use tokio::net::TcpListener; use crate::config::RedirType; /// Extension function for `TcpListener` for setting extra options before `bind()` -#[async_trait] pub trait TcpListenerRedirExt { // Create a TcpListener for transparent proxy // diff --git a/crates/shadowsocks-service/src/local/redir/tcprelay/sys/unix/bsd.rs b/crates/shadowsocks-service/src/local/redir/tcprelay/sys/unix/bsd.rs index 1c011f425160..7c860c7b38ee 100644 --- a/crates/shadowsocks-service/src/local/redir/tcprelay/sys/unix/bsd.rs +++ b/crates/shadowsocks-service/src/local/redir/tcprelay/sys/unix/bsd.rs @@ -3,7 +3,6 @@ use std::{ net::SocketAddr, }; -use async_trait::async_trait; use log::warn; use shadowsocks::net::{is_dual_stack_addr, set_tcp_fastopen, AcceptOpts}; use socket2::Protocol; @@ -17,7 +16,6 @@ use crate::{ }, }; -#[async_trait] impl TcpListenerRedirExt for TcpListener { async fn bind_redir(ty: RedirType, addr: SocketAddr, accept_opts: AcceptOpts) -> io::Result { match ty { diff --git a/crates/shadowsocks-service/src/local/redir/tcprelay/sys/unix/linux.rs b/crates/shadowsocks-service/src/local/redir/tcprelay/sys/unix/linux.rs index f0d32c60086f..dc12a3398f1d 100644 --- a/crates/shadowsocks-service/src/local/redir/tcprelay/sys/unix/linux.rs +++ b/crates/shadowsocks-service/src/local/redir/tcprelay/sys/unix/linux.rs @@ -5,7 +5,6 @@ use std::{ os::unix::io::AsRawFd, }; -use async_trait::async_trait; use log::warn; use shadowsocks::net::{is_dual_stack_addr, set_tcp_fastopen, AcceptOpts}; use socket2::SockAddr; @@ -19,7 +18,6 @@ use crate::{ }, }; -#[async_trait] impl TcpListenerRedirExt for TcpListener { async fn bind_redir(ty: RedirType, addr: SocketAddr, accept_opts: AcceptOpts) -> io::Result { match ty { diff --git a/crates/shadowsocks-service/src/local/redir/tcprelay/sys/windows/mod.rs b/crates/shadowsocks-service/src/local/redir/tcprelay/sys/windows/mod.rs index a15e239a1d66..257168740a29 100644 --- a/crates/shadowsocks-service/src/local/redir/tcprelay/sys/windows/mod.rs +++ b/crates/shadowsocks-service/src/local/redir/tcprelay/sys/windows/mod.rs @@ -3,7 +3,6 @@ use std::{ net::SocketAddr, }; -use async_trait::async_trait; use shadowsocks::net::AcceptOpts; use tokio::net::{TcpListener, TcpStream}; @@ -12,7 +11,6 @@ use crate::{ local::redir::redir_ext::{TcpListenerRedirExt, TcpStreamRedirExt}, }; -#[async_trait] impl TcpListenerRedirExt for TcpListener { async fn bind_redir(_ty: RedirType, _addr: SocketAddr, _accept_opts: AcceptOpts) -> io::Result { let err = Error::new( diff --git a/crates/shadowsocks-service/src/local/redir/udprelay/mod.rs b/crates/shadowsocks-service/src/local/redir/udprelay/mod.rs index 1c327a6c7790..cb16e68001db 100644 --- a/crates/shadowsocks-service/src/local/redir/udprelay/mod.rs +++ b/crates/shadowsocks-service/src/local/redir/udprelay/mod.rs @@ -7,7 +7,6 @@ use std::{ time::Duration, }; -use async_trait::async_trait; use log::{debug, error, info, trace, warn}; use lru_time_cache::LruCache; use shadowsocks::{ @@ -91,7 +90,6 @@ impl UdpRedirInboundWriter { } } -#[async_trait] impl UdpInboundWrite for UdpRedirInboundWriter { async fn send_to(&self, mut peer_addr: SocketAddr, remote_addr: &Address, data: &[u8]) -> io::Result<()> { // If IPv6 Transparent Proxy is supported on the current platform, diff --git a/crates/shadowsocks-service/src/local/socks/server/socks5/udprelay.rs b/crates/shadowsocks-service/src/local/socks/server/socks5/udprelay.rs index 7d36091b08cf..59190238821d 100644 --- a/crates/shadowsocks-service/src/local/socks/server/socks5/udprelay.rs +++ b/crates/shadowsocks-service/src/local/socks/server/socks5/udprelay.rs @@ -7,7 +7,6 @@ use std::{ time::Duration, }; -use async_trait::async_trait; use byte_string::ByteStr; use bytes::{BufMut, BytesMut}; use log::{debug, error, info, trace}; @@ -96,7 +95,6 @@ struct Socks5UdpInboundWriter { inbound: Arc, } -#[async_trait] impl UdpInboundWrite for Socks5UdpInboundWriter { async fn send_to(&self, peer_addr: SocketAddr, remote_addr: &Address, data: &[u8]) -> io::Result<()> { let remote_addr = match remote_addr { diff --git a/crates/shadowsocks-service/src/local/tun/udp.rs b/crates/shadowsocks-service/src/local/tun/udp.rs index 924f22a49625..2a25ba9de029 100644 --- a/crates/shadowsocks-service/src/local/tun/udp.rs +++ b/crates/shadowsocks-service/src/local/tun/udp.rs @@ -5,7 +5,6 @@ use std::{ time::Duration, }; -use async_trait::async_trait; use bytes::{BufMut, BytesMut}; use etherparse::PacketBuilder; use log::debug; @@ -93,7 +92,6 @@ impl UdpTunInboundWriter { } } -#[async_trait] impl UdpInboundWrite for UdpTunInboundWriter { async fn send_to(&self, peer_addr: SocketAddr, remote_addr: &Address, data: &[u8]) -> io::Result<()> { let addr = match *remote_addr { diff --git a/crates/shadowsocks-service/src/local/tunnel/udprelay.rs b/crates/shadowsocks-service/src/local/tunnel/udprelay.rs index daab725efdcc..4015a1195180 100644 --- a/crates/shadowsocks-service/src/local/tunnel/udprelay.rs +++ b/crates/shadowsocks-service/src/local/tunnel/udprelay.rs @@ -2,7 +2,6 @@ use std::{io, net::SocketAddr, sync::Arc, time::Duration}; -use async_trait::async_trait; use log::{debug, error, info}; use shadowsocks::{ relay::{socks5::Address, udprelay::MAXIMUM_UDP_PAYLOAD_SIZE}, @@ -87,7 +86,6 @@ struct TunnelUdpInboundWriter { inbound: Arc, } -#[async_trait] impl UdpInboundWrite for TunnelUdpInboundWriter { async fn send_to(&self, peer_addr: SocketAddr, _remote_addr: &Address, data: &[u8]) -> io::Result<()> { self.inbound.send_to(data, peer_addr).await.map(|_| ()) diff --git a/crates/shadowsocks/Cargo.toml b/crates/shadowsocks/Cargo.toml index ba3928baed6c..b4382d7ae25a 100644 --- a/crates/shadowsocks/Cargo.toml +++ b/crates/shadowsocks/Cargo.toml @@ -9,7 +9,7 @@ documentation = "https://docs.rs/shadowsocks-core" keywords = ["shadowsocks", "proxy", "socks", "socks5", "firewall"] license = "MIT" edition = "2021" -rust-version = "1.74" +rust-version = "1.75" [badges] maintenance = { status = "passively-maintained" } @@ -71,7 +71,8 @@ serde_json = "1.0" percent-encoding = "2.1" futures = "0.3" -async-trait = "0.1" +trait-variant = "0.1" +dynosaur = "0.1.2" socket2 = { version = "0.5", features = ["all"] } tokio = { version = "1.9.0", features = [ diff --git a/crates/shadowsocks/src/dns_resolver/resolver.rs b/crates/shadowsocks/src/dns_resolver/resolver.rs index 04bb6d15dc3f..dfd78b45e0d6 100644 --- a/crates/shadowsocks/src/dns_resolver/resolver.rs +++ b/crates/shadowsocks/src/dns_resolver/resolver.rs @@ -11,7 +11,6 @@ use std::{ #[cfg(feature = "hickory-dns")] use arc_swap::ArcSwap; -use async_trait::async_trait; use cfg_if::cfg_if; #[cfg(feature = "hickory-dns")] use hickory_resolver::config::ResolverConfig; @@ -31,12 +30,17 @@ use crate::net::ConnectOpts; use super::hickory_dns_resolver::DnsResolver as HickoryDnsResolver; /// Abstract DNS resolver -#[async_trait] +#[trait_variant::make(Send)] +#[dynosaur::dynosaur(DynDnsResolve)] pub trait DnsResolve { /// Resolves `addr:port` to a list of `SocketAddr` async fn resolve(&self, addr: &str, port: u16) -> io::Result>; } +// Equivalent to (dyn DnsResolve + Send + Sync) +unsafe impl Send for DynDnsResolve<'_> {} +unsafe impl Sync for DynDnsResolve<'_> {} + #[cfg(feature = "hickory-dns")] #[derive(Debug)] pub struct HickoryDnsSystemResolver { @@ -63,7 +67,7 @@ pub enum DnsResolver { #[cfg(feature = "hickory-dns")] HickoryDns(HickoryDnsResolver), /// Customized Resolver - Custom(Box), + Custom(Box>), } impl Default for DnsResolver { @@ -282,7 +286,7 @@ impl DnsResolver { where R: DnsResolve + Send + Sync + 'static, { - DnsResolver::Custom(Box::new(custom) as Box) + DnsResolver::Custom(DynDnsResolve::boxed(custom)) } /// Resolve address into `SocketAddr`s