diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index f65f55a5..97b8be72 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -28,8 +28,8 @@ jobs: run: rustup toolchain install nightly - name: Build & Test (Default) run: cargo +nightly test --verbose --no-fail-fast - - name: Build & Test (--no-default-feature) - run: cargo +nightly test --verbose --no-default-feature --no-fail-fast + - name: Build & Test (--no-default-features) + run: cargo +nightly test --verbose --no-default-features --no-fail-fast - name: Build with All Features Enabled run: cargo +nightly build --verbose --features "local-redir local-dns local-http-rustls dns-over-tls dns-over-https" @@ -49,8 +49,8 @@ jobs: run: rustup toolchain install nightly - name: Build & Test (Default) run: cargo +nightly test --verbose --no-fail-fast - - name: Build & Test (--no-default-feature) - run: cargo +nightly test --verbose --no-default-feature --no-fail-fast + - name: Build & Test (--no-default-features) + run: cargo +nightly test --verbose --no-default-features --no-fail-fast - name: Build with All Features Enabled run: cargo +nightly build --verbose --features "local-dns local-http-rustls dns-over-tls dns-over-https" @@ -75,7 +75,7 @@ jobs: run: rustup toolchain install nightly - name: Build & Test (Default) run: cargo +nightly test --verbose --no-fail-fast - - name: Build & Test (--no-default-feature) - run: cargo +nightly test --verbose --no-default-feature --no-fail-fast + - name: Build & Test (--no-default-features) + run: cargo +nightly test --verbose --no-default-features --no-fail-fast - name: Build with All Features Enabled run: cargo +nightly build --verbose --features "local-redir local-dns local-http-rustls dns-over-tls dns-over-https" diff --git a/Cargo.lock b/Cargo.lock index 277fdc4a..29d3ebae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -21,7 +21,7 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] @@ -49,7 +49,7 @@ checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ "hermit-abi", "libc", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -190,7 +190,7 @@ dependencies = [ "num-integer", "num-traits", "time", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -385,22 +385,6 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2022715d62ab30faffd124d40b76f4134a550a87792276512b18d63272333394" -[[package]] -name = "fuchsia-zircon" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" -dependencies = [ - "bitflags", - "fuchsia-zircon-sys", -] - -[[package]] -name = "fuchsia-zircon-sys" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" - [[package]] name = "futures" version = "0.3.8" @@ -567,7 +551,7 @@ checksum = "3c731c3e10504cc8ed35cfe2f1db4c9274c3d35fa486e3b31df46f068ef3e867" dependencies = [ "libc", "match_cfg", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -670,15 +654,6 @@ dependencies = [ "cfg-if 1.0.0", ] -[[package]] -name = "iovec" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" -dependencies = [ - "libc", -] - [[package]] name = "ipconfig" version = "0.2.2" @@ -687,7 +662,7 @@ checksum = "f7e2f18aece9709094573a9f24f483c4f65caa4298e2f7ae1b71cc65d853fad7" dependencies = [ "socket2", "widestring", - "winapi 0.3.9", + "winapi", "winreg", ] @@ -753,16 +728,6 @@ dependencies = [ "serde", ] -[[package]] -name = "kernel32-sys" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" -dependencies = [ - "winapi 0.2.8", - "winapi-build", -] - [[package]] name = "lazy_static" version = "1.4.0" @@ -837,7 +802,7 @@ dependencies = [ "serde_yaml", "thread-id", "typemap", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -898,25 +863,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "mio" -version = "0.6.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fce347092656428bc8eaf6201042cb551b8d67855af7374542a92a0fbfcac430" -dependencies = [ - "cfg-if 0.1.10", - "fuchsia-zircon", - "fuchsia-zircon-sys", - "iovec", - "kernel32-sys", - "libc", - "log", - "miow 0.2.1", - "net2", - "slab", - "winapi 0.2.8", -] - [[package]] name = "mio" version = "0.7.6" @@ -925,32 +871,9 @@ checksum = "f33bc887064ef1fd66020c9adfc45bb9f33d75a42096c81e7c56c65b75dd1a8b" dependencies = [ "libc", "log", - "miow 0.3.6", + "miow", "ntapi", - "winapi 0.3.9", -] - -[[package]] -name = "mio-uds" -version = "0.6.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afcb699eb26d4332647cc848492bbc15eafb26f08d0304550d5aa1f612e066f0" -dependencies = [ - "iovec", - "libc", - "mio 0.6.22", -] - -[[package]] -name = "miow" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919" -dependencies = [ - "kernel32-sys", - "net2", - "winapi 0.2.8", - "ws2_32-sys", + "winapi", ] [[package]] @@ -960,7 +883,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a33c1b55807fbed163481b5ba66db4b2fa6cde694a5027be10fb724206c5897" dependencies = [ "socket2", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -981,17 +904,6 @@ dependencies = [ "tempfile", ] -[[package]] -name = "net2" -version = "0.2.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ebc3ec692ed7c9a255596c67808dee269f64655d8baf7b4f0638e51ba1d6853" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "winapi 0.3.9", -] - [[package]] name = "nix" version = "0.19.0" @@ -1010,7 +922,7 @@ version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1119,7 +1031,7 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1357,7 +1269,7 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1382,7 +1294,7 @@ dependencies = [ "spin 0.5.2", "untrusted", "web-sys", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1423,7 +1335,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75" dependencies = [ "lazy_static", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1585,7 +1497,7 @@ dependencies = [ "bloomfilter", "byte_string", "byteorder", - "bytes 0.5.6", + "bytes 0.6.0", "cfg-if 1.0.0", "clap", "daemonize", @@ -1603,8 +1515,7 @@ dependencies = [ "log4rs", "lru_time_cache", "mimalloc", - "mio 0.6.22", - "mio-uds", + "mio", "native-tls", "nix", "pin-project 1.0.2", @@ -1630,7 +1541,7 @@ dependencies = [ "trust-dns-resolver", "url", "webpki-roots", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1662,14 +1573,14 @@ checksum = "7acad6f34eb9e8a259d3283d1e8c1d34d7415943d4895f65cc73813c7396fc85" [[package]] name = "socket2" -version = "0.3.16" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fd8b795c389288baa5f355489c65e71fd48a02104600d15c4cfbc561e9e429d" +checksum = "2c29947abdee2a218277abeca306f25789c938e500ea5a9d4b12a5a504466902" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", "libc", "redox_syscall", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1745,7 +1656,7 @@ dependencies = [ "rand", "redox_syscall", "remove_dir_all", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1755,7 +1666,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e4129646ca0ed8f45d09b929036bafad5377103edd06e50bf574b353d2b08d9" dependencies = [ "libc", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1805,7 +1716,7 @@ checksum = "c7fbf4c9d56b320106cd64fd024dadfa0be7cb4706725fc44a7d7ce952d820c1" dependencies = [ "libc", "redox_syscall", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1825,7 +1736,7 @@ checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" dependencies = [ "libc", "wasi 0.10.0+wasi-snapshot-preview1", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1855,14 +1766,14 @@ dependencies = [ "lazy_static", "libc", "memchr", - "mio 0.7.6", + "mio", "num_cpus", "parking_lot", "pin-project-lite 0.2.0", "signal-hook-registry", "slab", "tokio-macros", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -2283,12 +2194,6 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c168940144dd21fd8046987c16a46a33d5fc84eec29ef9dcddc2ac9e31526b7c" -[[package]] -name = "winapi" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" - [[package]] name = "winapi" version = "0.3.9" @@ -2299,12 +2204,6 @@ dependencies = [ "winapi-x86_64-pc-windows-gnu", ] -[[package]] -name = "winapi-build" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" - [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" @@ -2317,7 +2216,7 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] @@ -2332,17 +2231,7 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b2986deb581c4fe11b621998a5e53361efe6b48a151178d0cd9eeffa4dc6acc9" dependencies = [ - "winapi 0.3.9", -] - -[[package]] -name = "ws2_32-sys" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" -dependencies = [ - "winapi 0.2.8", - "winapi-build", + "winapi", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 34120fe2..43cd8192 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -77,71 +77,13 @@ tcmalloc-vendored = ["tcmalloc/bundled"] [target.'cfg(any(target_arch = "x86", target_arch = "x86_64"))'.dependencies] -shadowsocks-crypto = { version = "0.1", features = [ "ring" ] } +shadowsocks-crypto = { version = "0.1", features = ["ring"] } [target.'cfg(any(target_arch = "arm", target_arch = "aarch64"))'.dependencies] -shadowsocks-crypto = { version = "0.1", features = [ "ring" ] } +shadowsocks-crypto = { version = "0.1", features = ["ring"] } [target.'cfg(not(any(target_arch = "x86", target_arch = "x86_64", target_arch = "arm", target_arch = "aarch64")))'.dependencies] -shadowsocks-crypto = { version = "0.1", features = [ ] } - -[dependencies] -log = "0.4" -rand = "0.7" -clap = { version = "2.33", features = ["wrap_help", "suggestions"] } -log4rs = "0.13" -libc = "0.2" -bytes = "0.5" -url = "2.1" -regex = "1" -cfg-if = "1.0" -base64 = "0.13" -byteorder = "1" -byte_string = "1.0" -lazy_static = "1.4" - -ring = "0.16" - -spin = "0.7" -mio = "0.6" -mio-uds = "0.6" -socket2 = "0.3" -pin-project = "1.0" -bloomfilter = "^1.0.2" - -json5 = "0.2" -futures = "0.3" -async-trait = "0.1" - -tokio = { version = "^0.3", features = [ "full" ] } -tokio-native-tls = { version = "0.2", optional = true } -native-tls = { version = "0.2", optional = true } -tokio-rustls = { version = "0.20", optional = true } -webpki-roots = { version = "0.20", optional = true } -rustls-native-certs = { version = "0.4", optional = true } - -qrcode = { version = "0.12", default-features = false } -serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" -serde_urlencoded = "0.7" - -lru_time_cache = "0.11" -http = { version = "0.2", optional = true } -# trust-dns-resolver = { version = "0.19", optional = true } -# trust-dns-proto = "0.19" -trust-dns-resolver = { git = "https://github.com/bluejekyll/trust-dns.git", optional = true, branch = "upgrade-to-tokio-0.3", features = ["serde-config"] } -trust-dns-proto = { git = "https://github.com/bluejekyll/trust-dns.git", optional = true, branch = "upgrade-to-tokio-0.3" } -hyper = { git = "https://github.com/hyperium/hyper.git", optional = true, features = ["full"] } -tower = { git = "https://github.com/tower-rs/tower.git", optional = true } - -strum = "0.19" -strum_macros = "0.19" -ipnet = "2.2" -iprange = "0.6" - -mimalloc = { version = "0.1", optional = true } -tcmalloc = { version = "0.3", optional = true } -jemallocator = { version = "0.3", optional = true } +shadowsocks-crypto = { version = "0.1", features = [] } [target.'cfg(windows)'.dependencies] @@ -152,7 +94,64 @@ winapi = { version = "0.3", features = ["mswsock", "winsock2"] } nix = "0.19" [target.'cfg(unix)'.dependencies] -daemonize = "^0.4.1" +daemonize = "0.4" + +[dependencies] +log = "0.4" +log4rs = "0.13" + +rand = "0.7" +clap = { version = "2", features = ["wrap_help", "suggestions"] } +libc = "0.2" +bytes = "0.6" +url = "2.2" +regex = "1.4" +cfg-if = "1" +byteorder = "1.3" +byte_string = "1.0" +lazy_static = "1.4" +spin = "0.7" +pin-project = "1.0" +bloomfilter = "1.0.2" +lru_time_cache = "0.11" + +ring = "0.16" + +futures = "0.3" +async-trait = "0.1" + +mio = "0.7" +socket2 = "0.3" +tokio = { version = "0.3.1", features = [ "full" ] } +tokio-native-tls = { version = "0.2", optional = true } +native-tls = { version = "0.2", optional = true } +tokio-rustls = { version = "0.20", optional = true } +webpki-roots = { version = "0.20", optional = true } +rustls-native-certs = { version = "0.4", optional = true } + +json5 = "0.2" +base64 = "0.13" +qrcode = { version = "0.12", default-features = false } +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" +serde_urlencoded = "0.7" +strum = "0.19" +strum_macros = "0.19" + +http = { version = "0.2", optional = true } +# trust-dns-resolver = { version = "0.19", optional = true } +# trust-dns-proto = "0.19" +trust-dns-resolver = { git = "https://github.com/bluejekyll/trust-dns.git", optional = true, branch = "upgrade-to-tokio-0.3", features = ["serde-config"] } +trust-dns-proto = { git = "https://github.com/bluejekyll/trust-dns.git", optional = true, branch = "upgrade-to-tokio-0.3" } +hyper = { git = "https://github.com/hyperium/hyper.git", optional = true, features = ["full"] } +tower = { git = "https://github.com/tower-rs/tower.git", optional = true } + +ipnet = "2.3" +iprange = "0.6" + +mimalloc = { version = "0.1", optional = true } +tcmalloc = { version = "0.3", optional = true } +jemallocator = { version = "0.3", optional = true } [dev-dependencies] env_logger = "0.8" diff --git a/src/relay/socks5.rs b/src/relay/socks5.rs index 7c2d07f5..5a936751 100644 --- a/src/relay/socks5.rs +++ b/src/relay/socks5.rs @@ -13,7 +13,7 @@ use std::{ vec, }; -use bytes::{buf::BufExt, Buf, BufMut, BytesMut}; +use bytes::{Buf, BufMut, BytesMut}; use tokio::prelude::*; pub use self::consts::{ @@ -229,7 +229,7 @@ impl Address { buf.resize(6, 0); let _ = stream.read_exact(&mut buf).await?; - let mut cursor = buf.to_bytes(); + let mut cursor = buf.freeze(); let v4addr = Ipv4Addr::new(cursor.get_u8(), cursor.get_u8(), cursor.get_u8(), cursor.get_u8()); let port = cursor.get_u16(); Ok(Address::SocketAddress(SocketAddr::V4(SocketAddrV4::new(v4addr, port)))) @@ -266,9 +266,9 @@ impl Address { buf.resize(buf_length, 0); let _ = stream.read_exact(&mut buf).await?; - let mut cursor = buf.to_bytes(); + let mut cursor = buf.freeze(); let mut raw_addr = Vec::with_capacity(length); - raw_addr.put(&mut BufExt::take(&mut cursor, length)); + raw_addr.put(&mut Buf::take(&mut cursor, length)); let addr = match String::from_utf8(raw_addr) { Ok(addr) => addr, Err(..) => return Err(Error::new(Reply::GeneralFailure, "invalid address encoding")), diff --git a/src/relay/tcprelay/aead.rs b/src/relay/tcprelay/aead.rs index f49249c7..1b36725b 100644 --- a/src/relay/tcprelay/aead.rs +++ b/src/relay/tcprelay/aead.rs @@ -208,7 +208,11 @@ impl DecryptedReader { { let mut remaining = size - self.buffer.len(); while remaining > 0 { - let mut buffer = ReadBuf::uninit(&mut self.buffer.bytes_mut()[..remaining]); + let raw_buffer = &mut self.buffer.bytes_mut()[..remaining]; + assert_eq!(raw_buffer.len(), remaining); + + let mut buffer = + unsafe { ReadBuf::uninit(slice::from_raw_parts_mut(raw_buffer.as_mut_ptr() as *mut _, remaining)) }; // It has enough space, I am sure about that ready!(Pin::new(&mut *r).poll_read(ctx, &mut buffer))?; diff --git a/src/relay/tcprelay/crypto_io.rs b/src/relay/tcprelay/crypto_io.rs index ff355e77..3062dea3 100644 --- a/src/relay/tcprelay/crypto_io.rs +++ b/src/relay/tcprelay/crypto_io.rs @@ -4,16 +4,12 @@ use std::{ io, marker::Unpin, pin::Pin, + slice, task::{Context, Poll}, }; use byte_string::ByteStr; -use bytes::{ - buf::ext::{BufMutExt, Limit}, - BufMut, - Bytes, - BytesMut, -}; +use bytes::{buf::Limit, BufMut, Bytes, BytesMut}; use futures::ready; use log::trace; use tokio::io::{AsyncRead, AsyncWrite, ReadBuf, ReadHalf, WriteHalf}; @@ -156,7 +152,13 @@ where fn poll_read_handshake(&mut self, cx: &mut Context<'_>) -> Poll> { if let ReadStatus::WaitIv(ref ctx, ref mut buf, method, ref key) = self.read_status { while buf.has_remaining_mut() { - let mut buffer = ReadBuf::uninit(buf.bytes_mut()); + let raw_buffer = buf.bytes_mut(); + let mut buffer = unsafe { + ReadBuf::uninit(slice::from_raw_parts_mut( + raw_buffer.as_mut_ptr() as *mut _, + raw_buffer.len(), + )) + }; ready!(Pin::new(&mut self.stream).poll_read(cx, &mut buffer))?; let n = buffer.filled().len(); unsafe {