mirror of
https://github.com/shadowsocks/shadowsocks-rust.git
synced 2026-02-09 01:59:16 +08:00
chore: replace once_cell::sync::Lazy with std::sync::LazyLock (#1963)
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -3340,7 +3340,6 @@ dependencies = [
|
||||
"log",
|
||||
"lru_time_cache",
|
||||
"notify",
|
||||
"once_cell",
|
||||
"percent-encoding",
|
||||
"pin-project",
|
||||
"rand 0.9.1",
|
||||
@@ -3458,7 +3457,6 @@ dependencies = [
|
||||
"mime",
|
||||
"native-tls",
|
||||
"nix",
|
||||
"once_cell",
|
||||
"pin-project",
|
||||
"rand 0.9.1",
|
||||
"regex",
|
||||
|
||||
@@ -125,7 +125,6 @@ log = "0.4"
|
||||
|
||||
cfg-if = "1"
|
||||
pin-project = "1.1"
|
||||
once_cell = "1.17"
|
||||
thiserror = "2.0"
|
||||
arc-swap = "1.7"
|
||||
|
||||
|
||||
@@ -11,12 +11,12 @@ use std::{
|
||||
net::{IpAddr, SocketAddr},
|
||||
path::{Path, PathBuf},
|
||||
str,
|
||||
sync::LazyLock,
|
||||
};
|
||||
|
||||
use ipnet::{IpNet, Ipv4Net, Ipv6Net};
|
||||
use iprange::IpRange;
|
||||
use log::{trace, warn};
|
||||
use once_cell::sync::Lazy;
|
||||
use regex::bytes::{Regex, RegexBuilder, RegexSet, RegexSetBuilder};
|
||||
|
||||
use shadowsocks::{context::Context, relay::socks5::Address};
|
||||
@@ -190,7 +190,7 @@ impl ParsingRules {
|
||||
}
|
||||
|
||||
fn add_regex_rule(&mut self, mut rule: String) {
|
||||
static TREE_SET_RULE_EQUIV: Lazy<Regex> = Lazy::new(|| {
|
||||
static TREE_SET_RULE_EQUIV: LazyLock<Regex> = LazyLock::new(|| {
|
||||
RegexBuilder::new(
|
||||
r#"^(?:(?:\((?:\?:)?\^\|\\\.\)|(?:\^\.(?:\+|\*))?\\\.)((?:[\w-]+(?:\\\.)?)+)|\^((?:[\w-]+(?:\\\.)?)+))\$?$"#,
|
||||
)
|
||||
|
||||
@@ -61,15 +61,14 @@ impl ProxyHttpStream {
|
||||
#[cfg(feature = "local-http-rustls")]
|
||||
pub async fn connect_https(stream: AutoProxyClientStream, domain: &str) -> io::Result<ProxyHttpStream> {
|
||||
use log::warn;
|
||||
use once_cell::sync::Lazy;
|
||||
use rustls_native_certs::CertificateResult;
|
||||
use std::sync::Arc;
|
||||
use std::sync::{Arc, LazyLock};
|
||||
use tokio_rustls::{
|
||||
TlsConnector,
|
||||
rustls::{ClientConfig, RootCertStore, pki_types::ServerName},
|
||||
};
|
||||
|
||||
static TLS_CONFIG: Lazy<Arc<ClientConfig>> = Lazy::new(|| {
|
||||
static TLS_CONFIG: LazyLock<Arc<ClientConfig>> = LazyLock::new(|| {
|
||||
let mut config = ClientConfig::builder()
|
||||
.with_root_certificates({
|
||||
// Load WebPKI roots (Mozilla's root certificates)
|
||||
|
||||
@@ -5,12 +5,12 @@ use std::{
|
||||
mem,
|
||||
net::SocketAddr,
|
||||
ptr,
|
||||
sync::LazyLock,
|
||||
};
|
||||
|
||||
use cfg_if::cfg_if;
|
||||
use log::trace;
|
||||
use nix::ioctl_readwrite;
|
||||
use once_cell::sync::Lazy;
|
||||
use socket2::{Protocol, SockAddr};
|
||||
|
||||
use super::pfvar::{PF_OUT, in_addr, in6_addr, pfioc_natlook, sockaddr_in, sockaddr_in6};
|
||||
@@ -365,7 +365,7 @@ impl Drop for PacketFilter {
|
||||
}
|
||||
}
|
||||
|
||||
pub static PF: Lazy<PacketFilter> = Lazy::new(|| match PacketFilter::open() {
|
||||
pub static PF: LazyLock<PacketFilter> = LazyLock::new(|| match PacketFilter::open() {
|
||||
Ok(pf) => pf,
|
||||
Err(err) if err.kind() == ErrorKind::PermissionDenied => {
|
||||
panic!("open /dev/pf permission denied, consider restart with root user");
|
||||
|
||||
@@ -5,13 +5,12 @@ use std::{
|
||||
mem,
|
||||
ops::{Deref, DerefMut},
|
||||
sync::{
|
||||
Arc, Mutex,
|
||||
Arc, LazyLock, Mutex,
|
||||
atomic::{AtomicBool, Ordering},
|
||||
},
|
||||
};
|
||||
|
||||
use bytes::BytesMut;
|
||||
use once_cell::sync::Lazy;
|
||||
use smoltcp::{
|
||||
phy::{self, Device, DeviceCapabilities},
|
||||
time::Instant,
|
||||
@@ -111,16 +110,16 @@ impl phy::TxToken for VirtTxToken<'_> {
|
||||
}
|
||||
|
||||
let result = f(&mut buffer);
|
||||
self.0.out_buf.send(buffer).expect("channel closed unexpectly");
|
||||
self.0.out_buf.send(buffer).expect("channel closed unexpectedly");
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
// Maximun number of TokenBuffer cached globally.
|
||||
// Maximum number of TokenBuffer cached globally.
|
||||
//
|
||||
// Each of them has capacity 65536 (defined in tun/mod.rs), so 64 * 65536 = 4MB.
|
||||
const TOKEN_BUFFER_LIST_MAX_SIZE: usize = 64;
|
||||
static TOKEN_BUFFER_LIST: Lazy<Mutex<Vec<BytesMut>>> = Lazy::new(|| Mutex::new(Vec::new()));
|
||||
static TOKEN_BUFFER_LIST: LazyLock<Mutex<Vec<BytesMut>>> = LazyLock::new(|| Mutex::new(Vec::new()));
|
||||
|
||||
pub struct TokenBuffer {
|
||||
buffer: BytesMut,
|
||||
|
||||
@@ -57,7 +57,6 @@ cfg-if = "1"
|
||||
byte_string = "1.0"
|
||||
base64 = "0.22"
|
||||
url = "2.5"
|
||||
once_cell = "1.17"
|
||||
spin = { version = "0.10", features = ["std"] }
|
||||
pin-project = "1.1"
|
||||
bloomfilter = { version = "3.0.0", optional = true }
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
use std::{
|
||||
io::{self, ErrorKind},
|
||||
net::{Ipv4Addr, Ipv6Addr, SocketAddr},
|
||||
sync::LazyLock,
|
||||
};
|
||||
|
||||
use cfg_if::cfg_if;
|
||||
use log::{debug, warn};
|
||||
use once_cell::sync::Lazy;
|
||||
use socket2::{Domain, Protocol, SockAddr, Socket, Type};
|
||||
use tokio::net::TcpSocket;
|
||||
|
||||
@@ -151,7 +151,7 @@ pub struct IpStackCapabilities {
|
||||
pub support_ipv4_mapped_ipv6: bool,
|
||||
}
|
||||
|
||||
static IP_STACK_CAPABILITIES: Lazy<IpStackCapabilities> = Lazy::new(|| {
|
||||
static IP_STACK_CAPABILITIES: LazyLock<IpStackCapabilities> = LazyLock::new(|| {
|
||||
// Reference Implementation: https://github.com/golang/go/blob/master/src/net/ipsock_posix.go
|
||||
|
||||
let mut caps = IpStackCapabilities {
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
//! +--------+--------+--------+--------+--------+--------+--------+--------+--------+
|
||||
//! | ATYP | ADDRESS ... (Variable Length ...)
|
||||
//! +--------+--------+--------+--------+--------+--------+--------+--------+--------+
|
||||
//! | PORT (BE) | Padding Length | Padding (Variable Length ...)
|
||||
//! | PORT (BE) | Padding Length | Padding (Variable Length ...)
|
||||
//! +--------+--------+--------+--------+--------+--------+--------+--------+--------+
|
||||
//!
|
||||
//! TCP Request Header (after encryption, *ciphertext*)
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
//! A TCP listener for accepting shadowsocks' client connection
|
||||
|
||||
use std::{io, net::SocketAddr, sync::Arc};
|
||||
use std::{
|
||||
io,
|
||||
net::SocketAddr,
|
||||
sync::{Arc, LazyLock},
|
||||
};
|
||||
|
||||
use once_cell::sync::Lazy;
|
||||
use tokio::{
|
||||
io::{AsyncRead, AsyncWrite},
|
||||
net::TcpStream,
|
||||
@@ -26,7 +29,7 @@ pub struct ProxyListener {
|
||||
user_manager: Option<Arc<ServerUserManager>>,
|
||||
}
|
||||
|
||||
static DEFAULT_ACCEPT_OPTS: Lazy<AcceptOpts> = Lazy::new(Default::default);
|
||||
static DEFAULT_ACCEPT_OPTS: LazyLock<AcceptOpts> = LazyLock::new(Default::default);
|
||||
|
||||
impl ProxyListener {
|
||||
/// Create a `ProxyListener` binding to a specific address
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
use std::{
|
||||
io::{self, ErrorKind},
|
||||
pin::Pin,
|
||||
sync::LazyLock,
|
||||
task::{self, Poll},
|
||||
};
|
||||
|
||||
@@ -10,7 +11,6 @@ use bytes::{BufMut, BytesMut};
|
||||
use cfg_if::cfg_if;
|
||||
use futures::ready;
|
||||
use log::trace;
|
||||
use once_cell::sync::Lazy;
|
||||
use pin_project::pin_project;
|
||||
use tokio::{
|
||||
io::{AsyncRead, AsyncWrite, ReadBuf},
|
||||
@@ -55,7 +55,7 @@ pub struct ProxyClientStream<S> {
|
||||
context: SharedContext,
|
||||
}
|
||||
|
||||
static DEFAULT_CONNECT_OPTS: Lazy<ConnectOpts> = Lazy::new(Default::default);
|
||||
static DEFAULT_CONNECT_OPTS: LazyLock<ConnectOpts> = LazyLock::new(Default::default);
|
||||
|
||||
impl ProxyClientStream<OutboundTcpStream> {
|
||||
/// Connect to target `addr` via shadowsocks' server configured by `svr_cfg`
|
||||
|
||||
@@ -7,7 +7,7 @@ use std::os::windows::io::{AsRawSocket, AsSocket, BorrowedSocket, IntoRawSocket,
|
||||
use std::{
|
||||
io::{self, ErrorKind},
|
||||
net::SocketAddr,
|
||||
sync::Arc,
|
||||
sync::{Arc, LazyLock},
|
||||
task::{Context, Poll, ready},
|
||||
time::Duration,
|
||||
};
|
||||
@@ -15,7 +15,6 @@ use std::{
|
||||
use byte_string::ByteStr;
|
||||
use bytes::{Bytes, BytesMut};
|
||||
use log::{info, trace, warn};
|
||||
use once_cell::sync::Lazy;
|
||||
use tokio::{io::ReadBuf, time};
|
||||
|
||||
use crate::{
|
||||
@@ -34,8 +33,8 @@ use super::{
|
||||
},
|
||||
};
|
||||
|
||||
static DEFAULT_CONNECT_OPTS: Lazy<ConnectOpts> = Lazy::new(Default::default);
|
||||
static DEFAULT_SOCKET_CONTROL: Lazy<UdpSocketControlData> = Lazy::new(UdpSocketControlData::default);
|
||||
static DEFAULT_CONNECT_OPTS: LazyLock<ConnectOpts> = LazyLock::new(Default::default);
|
||||
static DEFAULT_SOCKET_CONTROL: LazyLock<UdpSocketControlData> = LazyLock::new(UdpSocketControlData::default);
|
||||
|
||||
/// UDP socket type, defining whether the socket is used in Client or Server
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
|
||||
Reference in New Issue
Block a user