diff --git a/crates/shadowsocks/Cargo.toml b/crates/shadowsocks/Cargo.toml index bb70b792cb47..fb0d568751e9 100644 --- a/crates/shadowsocks/Cargo.toml +++ b/crates/shadowsocks/Cargo.toml @@ -30,7 +30,12 @@ stream-cipher = ["shadowsocks-crypto/v1-stream"] aead-cipher-extra = ["shadowsocks-crypto/v1-aead-extra"] # Enable AEAD 2022 -aead-cipher-2022 = ["shadowsocks-crypto/v2", "rand/small_rng", "aes"] +aead-cipher-2022 = [ + "shadowsocks-crypto/v2", + "rand/small_rng", + "aes", + "lru_time_cache", +] # Enable AEAD 2022 with extra ciphers aead-cipher-2022-extra = ["aead-cipher-2022", "shadowsocks-crypto/v2-extra"] @@ -52,7 +57,7 @@ pin-project = "1.1" bloomfilter = { version = "1.0.8", optional = true } thiserror = "1.0" rand = { version = "0.8", optional = true } -lru_time_cache = "0.11" +lru_time_cache = { version = "0.11", optional = true } serde = { version = "1.0", features = ["derive"] } serde_urlencoded = "0.7" diff --git a/crates/shadowsocks/src/net/sys/windows/mod.rs b/crates/shadowsocks/src/net/sys/windows/mod.rs index 56fd13d10095..664f66ff2b70 100644 --- a/crates/shadowsocks/src/net/sys/windows/mod.rs +++ b/crates/shadowsocks/src/net/sys/windows/mod.rs @@ -1,4 +1,5 @@ use std::{ + collections::HashMap, ffi::{c_void, CStr, CString, OsString}, io::{self, ErrorKind}, mem, @@ -8,15 +9,13 @@ use std::{ io::{AsRawSocket, FromRawSocket, IntoRawSocket, RawSocket}, }, pin::Pin, - ptr, - slice, + ptr, slice, task::{self, Poll}, time::{Duration, Instant}, }; use bytes::BytesMut; use log::{error, warn}; -use lru_time_cache::LruCache; use once_cell::sync::Lazy; use pin_project::pin_project; use socket2::{Domain, Protocol, SockAddr, Socket, TcpKeepalive, Type}; @@ -31,32 +30,13 @@ use windows_sys::{ Win32::{ Foundation::{BOOL, ERROR_BUFFER_OVERFLOW, ERROR_NO_DATA, ERROR_SUCCESS}, NetworkManagement::IpHelper::{ - if_nametoindex, - GetAdaptersAddresses, - GAA_FLAG_SKIP_ANYCAST, - GAA_FLAG_SKIP_DNS_SERVER, - GAA_FLAG_SKIP_MULTICAST, - GAA_FLAG_SKIP_UNICAST, - IP_ADAPTER_ADDRESSES_LH, + if_nametoindex, GetAdaptersAddresses, GAA_FLAG_SKIP_ANYCAST, GAA_FLAG_SKIP_DNS_SERVER, + GAA_FLAG_SKIP_MULTICAST, GAA_FLAG_SKIP_UNICAST, IP_ADAPTER_ADDRESSES_LH, }, Networking::WinSock::{ - htonl, - setsockopt, - WSAGetLastError, - WSAIoctl, - AF_UNSPEC, - IPPROTO_IP, - IPPROTO_IPV6, - IPPROTO_TCP, - IPV6_MTU_DISCOVER, - IPV6_UNICAST_IF, - IP_MTU_DISCOVER, - IP_PMTUDISC_DO, - IP_UNICAST_IF, - SIO_UDP_CONNRESET, - SOCKET, - SOCKET_ERROR, - TCP_FASTOPEN, + htonl, setsockopt, WSAGetLastError, WSAIoctl, AF_UNSPEC, IPPROTO_IP, IPPROTO_IPV6, IPPROTO_TCP, + IPV6_MTU_DISCOVER, IPV6_UNICAST_IF, IP_MTU_DISCOVER, IP_PMTUDISC_DO, IP_UNICAST_IF, SIO_UDP_CONNRESET, + SOCKET, SOCKET_ERROR, TCP_FASTOPEN, }, }, }; @@ -67,9 +47,7 @@ const FALSE: BOOL = 0; use crate::net::{ is_dual_stack_addr, sys::{set_common_sockopt_for_connect, socket_bind_dual_stack}, - AcceptOpts, - AddrFamily, - ConnectOpts, + AcceptOpts, AddrFamily, ConnectOpts, }; /// A `TcpStream` that supports TFO (TCP Fast Open) @@ -291,8 +269,8 @@ fn find_adapter_interface_index(addr: &SocketAddr, iface: &str) -> io::Result io::Result { const INDEX_EXPIRE_DURATION: Duration = Duration::from_secs(5); - static INTERFACE_INDEX_CACHE: Lazy>> = - Lazy::new(|| Mutex::new(LruCache::with_expiry_duration(INDEX_EXPIRE_DURATION))); + static INTERFACE_INDEX_CACHE: Lazy>> = + Lazy::new(|| Mutex::new(HashMap::new())); let mut cache = INTERFACE_INDEX_CACHE.lock().await; if let Some((idx, insert_time)) = cache.get(iface) {