Skip to content

Commit

Permalink
style: make clippy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
iHsin committed Apr 9, 2024
1 parent a55436d commit fcd403d
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 32 deletions.
1 change: 0 additions & 1 deletion clash_lib/src/app/dns/dhcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ async fn listen_dhcp_client(iface: &str) -> io::Result<UdpSocket> {
new_udp_socket(
Some(&listen_addr.parse().expect("must parse")),
Some(&Interface::Name(iface.to_string())),
#[cfg(any(target_os = "linux", target_os = "android"))]
None,
)
.await
Expand Down
1 change: 0 additions & 1 deletion clash_lib/src/common/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ impl Service<Uri> for LocalConnector {
},
}),
None,
#[cfg(any(target_os = "linux", target_os = "android"))]
None,
)
.await
Expand Down
1 change: 0 additions & 1 deletion clash_lib/src/proxy/http/inbound/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ impl tower::Service<Uri> for Connector {
typ: Type::Http,
source: src,
destination: destination.ok_or(ProxyError::InvalidUrl(url.to_string()))?,
..Default::default()
};

tokio::spawn(async move {
Expand Down
2 changes: 0 additions & 2 deletions clash_lib/src/proxy/http/inbound/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ async fn proxy(
typ: Type::HttpConnect,
source: src,
destination: addr,

..Default::default()
};

dispatcher.dispatch_stream(sess, upgraded).await
Expand Down
1 change: 0 additions & 1 deletion clash_lib/src/proxy/relay/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ impl OutboundHandler for Handler {
remote_addr.host().as_str(),
remote_addr.port(),
None,
#[cfg(any(target_os = "linux", target_os = "android"))]
None,
)
.await?;
Expand Down
8 changes: 1 addition & 7 deletions clash_lib/src/proxy/socks/inbound/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,7 @@ pub async fn handle_tcp<'a>(
}
socks_command::UDP_ASSOCIATE => {
let udp_addr = SocketAddr::new(s.local_addr()?.ip(), 0);
let udp_inbound = new_udp_socket(
Some(&udp_addr),
None,
#[cfg(any(target_os = "linux", target_os = "android"))]
None,
)
.await?;
let udp_inbound = new_udp_socket(Some(&udp_addr), None, None).await?;

trace!(
"Got a UDP_ASSOCIATE request from {}, UDP assigned at {}",
Expand Down
1 change: 0 additions & 1 deletion clash_lib/src/proxy/tun/inbound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ async fn handle_inbound_stream(
typ: Type::Tun,
source: local_addr,
destination: remote_addr.into(),
..Default::default()
};

dispatcher.dispatch_stream(sess, stream).await;
Expand Down
22 changes: 11 additions & 11 deletions clash_lib/src/proxy/utils/socket_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use tokio::{
use tracing::warn;

use super::Interface;
use crate::{app::dns::ThreadSafeDNSResolver, get_iface, proxy::AnyStream, session::get_somark};
use crate::{app::dns::ThreadSafeDNSResolver, proxy::AnyStream};

pub fn apply_tcp_options(s: TcpStream) -> std::io::Result<TcpStream> {
#[cfg(not(target_os = "windows"))]
Expand Down Expand Up @@ -67,9 +67,9 @@ fn must_bind_socket_on_interface(socket: &socket2::Socket, iface: &Interface) ->
}
}

pub async fn new_tcp_stream<'a>(
pub async fn new_tcp_stream(
resolver: ThreadSafeDNSResolver,
address: &'a str,
address: &str,
port: u16,
iface: Option<&Interface>,
packet_mark: Option<u32>,
Expand Down Expand Up @@ -99,13 +99,13 @@ pub async fn new_tcp_stream<'a>(
}
};

let global_iface = get_iface();
if let Some(iface) = iface.or_else(|| global_iface.as_ref()) {
must_bind_socket_on_interface(&socket, &iface)?;
let global_iface = crate::get_iface();
if let Some(iface) = iface.or(global_iface.as_ref()) {
must_bind_socket_on_interface(&socket, iface)?;
}

#[cfg(target_os = "linux")]
if let Some(packet_mark) = packet_mark.or_else(|| get_somark()) {
if let Some(packet_mark) = packet_mark.or_else(crate::get_somark) {
socket.set_mark(packet_mark)?;
}

Expand Down Expand Up @@ -142,13 +142,13 @@ pub async fn new_udp_socket(
socket.bind(&(*src).into())?;
}

let global_iface = get_iface();
if let Some(iface) = iface.or_else(|| global_iface.as_ref()) {
must_bind_socket_on_interface(&socket, &iface)?;
let global_iface = crate::get_iface();
if let Some(iface) = iface.or(global_iface.as_ref()) {
must_bind_socket_on_interface(&socket, iface)?;
}

#[cfg(target_os = "linux")]
if let Some(packet_mark) = packet_mark.or_else(|| get_somark()) {
if let Some(packet_mark) = packet_mark.or_else(crate::get_somark) {
socket.set_mark(packet_mark)?;
}

Expand Down
8 changes: 1 addition & 7 deletions clash_lib/src/proxy/wg/wireguard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,7 @@ impl WireguardTunnel {

let remote_endpoint = config.remote_endpoint;

let udp = new_udp_socket(
None,
None,
#[cfg(any(target_os = "linux", target_os = "android"))]
None,
)
.await?;
let udp = new_udp_socket(None, None, None).await?;

Ok(Self {
source_peer_ip: config.source_peer_ip,
Expand Down

0 comments on commit fcd403d

Please sign in to comment.