refactor: replace static with const for constants (#1805)

This commit is contained in:
Integral
2024-12-09 10:26:09 +08:00
committed by GitHub
parent 239c55a543
commit 6b672233ec
11 changed files with 14 additions and 14 deletions

View File

@@ -853,7 +853,7 @@ impl PingChecker {
async fn check_request_tcp_chromium(&self) -> io::Result<()> {
use std::io::{Error, ErrorKind};
static GET_BODY: &[u8] =
const GET_BODY: &[u8] =
b"GET /generate_204 HTTP/1.1\r\nHost: clients3.google.com\r\nConnection: close\r\nAccept: */*\r\n\r\n";
let addr = Address::DomainNameAddress("clients3.google.com".to_owned(), 80);
@@ -892,7 +892,7 @@ impl PingChecker {
async fn check_request_tcp_firefox(&self) -> io::Result<()> {
use std::io::{Error, ErrorKind};
static GET_BODY: &[u8] =
const GET_BODY: &[u8] =
b"GET /success.txt HTTP/1.1\r\nHost: detectportal.firefox.com\r\nConnection: close\r\nAccept: */*\r\n\r\n";
let addr = Address::DomainNameAddress("detectportal.firefox.com".to_owned(), 80);
@@ -938,7 +938,7 @@ impl PingChecker {
// - QNAME: \x07 firefox \x03 com \x00
// - QTYPE: 0x0001 A
// - QCLASS: 0x0001 IN
static DNS_QUERY: &[u8] =
const DNS_QUERY: &[u8] =
b"\x12\x34\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x07firefox\x03com\x00\x00\x01\x00\x01";
let addr = Address::SocketAddress(SocketAddr::new(Ipv4Addr::new(8, 8, 8, 8).into(), 53));

View File

@@ -84,7 +84,7 @@ impl OnlineConfigService {
}
async fn run_once_impl(&mut self) -> io::Result<()> {
static SHADOWSOCKS_USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"));
const SHADOWSOCKS_USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"));
let start_time = Instant::now();

View File

@@ -161,7 +161,7 @@ async fn hickory_dns_notify_update_dns(resolver: Arc<HickoryDnsSystemResolver>)
use super::hickory_dns_resolver::create_resolver;
static DNS_RESOLV_FILE_PATH: &str = "/etc/resolv.conf";
const DNS_RESOLV_FILE_PATH: &str = "/etc/resolv.conf";
if !Path::new(DNS_RESOLV_FILE_PATH).exists() {
trace!("resolv file {DNS_RESOLV_FILE_PATH} doesn't exist");

View File

@@ -529,7 +529,7 @@ pub struct EncryptedWriter {
impl EncryptedWriter {
/// Creates a new EncryptedWriter
pub fn new(stream_ty: StreamType, method: CipherKind, key: &[u8], nonce: &[u8]) -> EncryptedWriter {
static EMPTY_IDENTITY: [Bytes; 0] = [];
const EMPTY_IDENTITY: [Bytes; 0] = [];
EncryptedWriter::with_identity(stream_ty, method, key, nonce, &EMPTY_IDENTITY)
}

View File

@@ -363,7 +363,7 @@ impl<S> CryptoStream<S> {
method: CipherKind,
key: &[u8],
) -> CryptoStream<S> {
static EMPTY_IDENTITY: [Bytes; 0] = [];
const EMPTY_IDENTITY: [Bytes; 0] = [];
CryptoStream::from_stream_with_identity(context, stream, stream_ty, method, key, &EMPTY_IDENTITY, None)
}

View File

@@ -69,7 +69,7 @@ impl<S> ProxyServerStream<S> {
#[cfg(not(feature = "aead-cipher-2022"))]
let writer_state = ProxyServerStreamWriteState::Established;
static EMPTY_IDENTITY: [Bytes; 0] = [];
const EMPTY_IDENTITY: [Bytes; 0] = [];
ProxyServerStream {
stream: CryptoStream::from_stream_with_identity(
&context,

View File

@@ -135,7 +135,7 @@ async fn tcp_tunnel_example(
let mut client = TcpStream::connect(local_addr).await?;
static HTTP_REQUEST: &[u8] = b"GET / HTTP/1.0\r\nHost: www.example.com\r\nAccept: */*\r\nConnection: close\r\n\r\n";
const HTTP_REQUEST: &[u8] = b"GET / HTTP/1.0\r\nHost: www.example.com\r\nAccept: */*\r\nConnection: close\r\n\r\n";
client.write_all(HTTP_REQUEST).await?;
let mut reader = BufReader::new(client);
@@ -145,7 +145,7 @@ async fn tcp_tunnel_example(
println!("{:?}", ByteStr::new(&buffer));
static HTTP_RESPONSE_STATUS: &[u8] = b"HTTP/1.0 200 OK\r\n";
const HTTP_RESPONSE_STATUS: &[u8] = b"HTTP/1.0 200 OK\r\n";
assert!(buffer.starts_with(HTTP_RESPONSE_STATUS));
Ok(())

View File

@@ -97,6 +97,6 @@ async fn tcp_tunnel_tfo() {
println!("{:?}", ByteStr::new(&buffer));
static HTTP_RESPONSE_STATUS: &[u8] = b"HTTP/1.0 200 OK\r\n";
const HTTP_RESPONSE_STATUS: &[u8] = b"HTTP/1.0 200 OK\r\n";
assert!(buffer.starts_with(HTTP_RESPONSE_STATUS));
}

View File

@@ -125,7 +125,7 @@ async fn udp_tunnel_echo(
let socket = UdpSocket::bind("0.0.0.0:0").await?;
socket.connect(local_addr).await?;
static SEND_PAYLOAD: &[u8] = b"HELLO WORLD. \x0012345";
const SEND_PAYLOAD: &[u8] = b"HELLO WORLD. \x0012345";
socket.send(SEND_PAYLOAD).await?;
let mut buffer = [0u8; 65536];

View File

@@ -56,7 +56,7 @@ async fn dns_relay() {
time::sleep(Duration::from_secs(1)).await;
// Query firefox.com, TransactionID: 0x1234
static DNS_QUERY: &[u8] = b"\x12\x34\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x07firefox\x03com\x00\x00\x01\x00\x01";
const DNS_QUERY: &[u8] = b"\x12\x34\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x07firefox\x03com\x00\x00\x01\x00\x01";
// 1. DoT
{

View File

@@ -86,7 +86,7 @@ async fn socks4_relay_connect() {
let svr = Socks4TestServer::new(SERVER_ADDR, LOCAL_ADDR, PASSWORD, METHOD);
svr.run().await;
static HTTP_REQUEST: &[u8] = b"GET /success.txt HTTP/1.0\r\nHost: detectportal.firefox.com\r\nAccept: */*\r\n\r\n";
const HTTP_REQUEST: &[u8] = b"GET /success.txt HTTP/1.0\r\nHost: detectportal.firefox.com\r\nAccept: */*\r\n\r\n";
let mut c = Socks4TcpClient::connect(("detectportal.firefox.com", 80), LOCAL_ADDR, Vec::new())
.await