perf: simplify method signatures and reduce clone across multiple files (#1663)

This commit is contained in:
Tunglies
2025-12-09 16:47:57 +08:00
committed by GitHub
parent 2bc51daa98
commit fe4dff5df0
33 changed files with 62 additions and 81 deletions
+1 -1
View File
@@ -80,7 +80,7 @@ pub fn get_insecure_tls_cert<'a>() -> (Vec<CertificateDer<'a>>, PrivateKeyDer<'a
let cert_der = cert.serialize_der().unwrap();
let priv_key = cert.serialize_private_key_der();
let priv_key = rustls::pki_types::PrivatePkcs8KeyDer::from(priv_key);
let cert_chain = vec![cert_der.clone().into()];
let cert_chain = vec![cert_der.into()];
(cert_chain, priv_key.into())
}
+1 -1
View File
@@ -156,7 +156,7 @@ impl QUICTunnelListener {
}
}
async fn do_accept(&mut self) -> Result<Box<dyn Tunnel>, super::TunnelError> {
async fn do_accept(&self) -> Result<Box<dyn Tunnel>, super::TunnelError> {
// accept a single connection
let conn = self
.endpoint
+3 -3
View File
@@ -29,7 +29,7 @@ impl TcpTunnelListener {
}
}
async fn do_accept(&mut self) -> Result<Box<dyn Tunnel>, std::io::Error> {
async fn do_accept(&self) -> Result<Box<dyn Tunnel>, std::io::Error> {
let listener = self.listener.as_ref().unwrap();
let (stream, _) = listener.accept().await?;
@@ -149,7 +149,7 @@ impl TcpTunnelConnector {
}
async fn connect_with_default_bind(
&mut self,
&self,
addr: SocketAddr,
) -> Result<Box<dyn Tunnel>, super::TunnelError> {
tracing::info!(url = ?self.addr, ?addr, "connect tcp start, bind addrs: {:?}", self.bind_addrs);
@@ -159,7 +159,7 @@ impl TcpTunnelConnector {
}
async fn connect_with_custom_bind(
&mut self,
&self,
addr: SocketAddr,
) -> Result<Box<dyn Tunnel>, super::TunnelError> {
let futures = FuturesUnordered::new();
+2 -2
View File
@@ -798,7 +798,7 @@ impl UdpTunnelConnector {
}
async fn connect_with_default_bind(
&mut self,
&self,
addr: SocketAddr,
) -> Result<Box<dyn Tunnel>, super::TunnelError> {
let socket = if addr.is_ipv4() {
@@ -811,7 +811,7 @@ impl UdpTunnelConnector {
}
async fn connect_with_custom_bind(
&mut self,
&self,
addr: SocketAddr,
) -> Result<Box<dyn Tunnel>, super::TunnelError> {
let futures = FuturesUnordered::new();
+3 -3
View File
@@ -73,7 +73,7 @@ impl WSTunnelListener {
}
}
async fn try_accept(&mut self, stream: TcpStream) -> Result<Box<dyn Tunnel>, TunnelError> {
async fn try_accept(&self, stream: TcpStream) -> Result<Box<dyn Tunnel>, TunnelError> {
let info = TunnelInfo {
tunnel_type: self.addr.scheme().to_owned(),
local_addr: Some(self.local_url().into()),
@@ -223,7 +223,7 @@ impl WSTunnelConnector {
}
async fn connect_with_default_bind(
&mut self,
&self,
addr: SocketAddr,
) -> Result<Box<dyn Tunnel>, super::TunnelError> {
let socket = if addr.is_ipv4() {
@@ -235,7 +235,7 @@ impl WSTunnelConnector {
}
async fn connect_with_custom_bind(
&mut self,
&self,
addr: SocketAddr,
) -> Result<Box<dyn Tunnel>, super::TunnelError> {
let futures = FuturesUnordered::new();
+1 -4
View File
@@ -690,10 +690,7 @@ impl WgTunnelConnector {
Ok(ret)
}
async fn connect_with_ipv6(
&mut self,
addr: SocketAddr,
) -> Result<Box<dyn Tunnel>, TunnelError> {
async fn connect_with_ipv6(&self, addr: SocketAddr) -> Result<Box<dyn Tunnel>, TunnelError> {
let socket2_socket = socket2::Socket::new(
socket2::Domain::for_address(addr),
socket2::Type::DGRAM,