Skip to content

Commit d787847

Browse files
fmt: fix cargo clippy warnings
1 parent ef9af9d commit d787847

File tree

7 files changed

+47
-51
lines changed

7 files changed

+47
-51
lines changed

lightway-client/src/io/inside/tun.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ impl InsideIORecv for Tun {
5959
// Update source IP from server DNS ip to TUN DNS ip
6060
if let Some(ip_config) = ip_config {
6161
let packet = Ipv4Packet::new(pkt.as_ref());
62-
if let Some(packet) = packet {
63-
if packet.get_source() == ip_config.dns_ip {
64-
ipv4_update_source(pkt.as_mut(), self.dns_ip);
65-
}
62+
if let Some(packet) = packet
63+
&& packet.get_source() == ip_config.dns_ip
64+
{
65+
ipv4_update_source(pkt.as_mut(), self.dns_ip);
6666
};
6767
}
6868

@@ -83,10 +83,10 @@ impl<T: Send + Sync> InsideIOSendCallback<ConnectionState<T>> for Tun {
8383
// Update source IP from server DNS ip to TUN DNS ip
8484
if let Some(ip_config) = state.ip_config {
8585
let packet = Ipv4Packet::new(buf.as_ref());
86-
if let Some(packet) = packet {
87-
if packet.get_source() == ip_config.dns_ip {
88-
ipv4_update_source(buf.as_mut(), self.dns_ip);
89-
}
86+
if let Some(packet) = packet
87+
&& packet.get_source() == ip_config.dns_ip
88+
{
89+
ipv4_update_source(buf.as_mut(), self.dns_ip);
9090
};
9191
}
9292

lightway-client/src/lib.rs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -280,13 +280,10 @@ async fn handle_events<A: 'static + Send + EventCallback>(
280280

281281
conn.lock().unwrap().inside_io(inside_io.clone());
282282

283-
if enable_encoding_when_online {
284-
if let Err(e) = conn.lock().unwrap().set_encoding(true) {
285-
tracing::error!(
286-
"Error encoutered when trying to toggle encoding. {}",
287-
e
288-
);
289-
}
283+
if enable_encoding_when_online
284+
&& let Err(e) = conn.lock().unwrap().set_encoding(true)
285+
{
286+
tracing::error!("Error encoutered when trying to toggle encoding. {}", e);
290287
}
291288
}
292289
}
@@ -369,10 +366,10 @@ pub async fn inside_io_task<T: Send + Sync>(
369366

370367
// Update TUN device DNS IP address to server provided DNS address
371368
let packet = Ipv4Packet::new(buf.as_ref());
372-
if let Some(packet) = packet {
373-
if packet.get_destination() == tun_dns_ip {
374-
ipv4_update_destination(buf.as_mut(), ip_config.dns_ip);
375-
}
369+
if let Some(packet) = packet
370+
&& packet.get_destination() == tun_dns_ip
371+
{
372+
ipv4_update_destination(buf.as_mut(), ip_config.dns_ip);
376373
};
377374
}
378375

@@ -525,14 +522,13 @@ fn validate_client_config<A: 'static + Send + EventCallback, T: Send + Sync>(
525522
));
526523
}
527524

528-
if let Some(inside_pkt_codec_config) = &config.inside_pkt_codec_config {
529-
if inside_pkt_codec_config.enable_encoding_at_connect
530-
&& matches!(config.mode, ClientConnectionMode::Stream(_))
531-
{
532-
return Err(anyhow!(
533-
"inside pkt encoding should not be enabled with TCP"
534-
));
535-
}
525+
if let Some(inside_pkt_codec_config) = &config.inside_pkt_codec_config
526+
&& inside_pkt_codec_config.enable_encoding_at_connect
527+
&& matches!(config.mode, ClientConnectionMode::Stream(_))
528+
{
529+
return Err(anyhow!(
530+
"inside pkt encoding should not be enabled with TCP"
531+
));
536532
}
537533

538534
Ok(())

lightway-client/src/routing_table.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -273,13 +273,13 @@ impl RoutingTable {
273273
}
274274
}
275275

276-
if let Some(route) = &self.server_route {
277-
if let Err(e) = self.route_manager.delete(route) {
278-
warn!(
279-
"Failed to delete server route during drop: {}, error: {}",
280-
route, e
281-
);
282-
}
276+
if let Some(route) = &self.server_route
277+
&& let Err(e) = self.route_manager.delete(route)
278+
{
279+
warn!(
280+
"Failed to delete server route during drop: {}, error: {}",
281+
route, e
282+
);
283283
}
284284
}
285285
pub async fn initialize_routing_table(

lightway-core/src/connection.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -558,10 +558,10 @@ impl<AppState: Send> Connection<AppState> {
558558
}
559559
}
560560

561-
if matches!(new_state, State::LinkUp) {
562-
if let ConnectionMode::Client { auth_method, .. } = &self.mode {
563-
self.authenticate(auth_method.clone())?;
564-
}
561+
if matches!(new_state, State::LinkUp)
562+
&& let ConnectionMode::Client { auth_method, .. } = &self.mode
563+
{
564+
self.authenticate(auth_method.clone())?;
565565
};
566566
Ok(())
567567
}
@@ -859,11 +859,11 @@ impl<AppState: Send> Connection<AppState> {
859859
// This should be enabled only for client for now.
860860
// But since we enable PMTU check only on client, there is no direct
861861
// check for client/server
862-
if let Some(pmtud) = self.pmtud.as_ref() {
863-
if let Some((mps, _)) = pmtud.maximum_packet_sizes() {
864-
let tcp_mss = mps - (IPV4_HEADER_SIZE + TCP_HEADER_SIZE);
865-
tcp_clamp_mss(pkt.as_mut(), tcp_mss as _);
866-
}
862+
if let Some(pmtud) = self.pmtud.as_ref()
863+
&& let Some((mps, _)) = pmtud.maximum_packet_sizes()
864+
{
865+
let tcp_mss = mps - (IPV4_HEADER_SIZE + TCP_HEADER_SIZE);
866+
tcp_clamp_mss(pkt.as_mut(), tcp_mss as _);
867867
}
868868

869869
match self.inside_plugins.do_ingress(pkt) {

lightway-core/src/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ impl<AppState: Send + 'static> ServerContext<AppState> {
312312
&self,
313313
protocol_version: Version,
314314
outside_io: OutsideIOSendCallbackArg,
315-
) -> Result<ServerConnectionBuilder<AppState>, ContextError> {
315+
) -> Result<ServerConnectionBuilder<'_, AppState>, ContextError> {
316316
Ok(ServerConnectionBuilder::new(
317317
self,
318318
protocol_version,

lightway-server/src/connection_manager.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,11 @@ async fn handle_events(mut stream: EventStream, conn: Weak<Connection>) {
167167
#[instrument(level = "trace", skip_all)]
168168
async fn handle_stale(conn: Weak<Connection>) {
169169
tokio::time::sleep(CONNECTION_STALE_AGE).await;
170-
if let Some(conn) = conn.upgrade() {
171-
if !matches!(conn.state(), State::Online) {
172-
metrics::connection_stale_closed();
173-
let _ = conn.disconnect();
174-
}
170+
if let Some(conn) = conn.upgrade()
171+
&& !matches!(conn.state(), State::Online)
172+
{
173+
metrics::connection_stale_closed();
174+
let _ = conn.disconnect();
175175
};
176176
}
177177

lightway-server/src/io/outside/udp/cmsg.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl<const N: usize> Buffer<N> {
2222
///
2323
/// `control_len` must have been set to the number of bytes of the
2424
/// buffer which have been initialized.
25-
pub(crate) unsafe fn iter(&self, control_len: LibcControlLen) -> Iter<N> {
25+
pub(crate) unsafe fn iter(&self, control_len: LibcControlLen) -> Iter<'_, N> {
2626
// Build a `msghdr` so we can use the `CMSG_*` functionality in
2727
// libc. We will only use the `CMSG_*` macros which only use
2828
// the `msg_control*` fields.
@@ -123,7 +123,7 @@ impl<const N: usize> BufferMut<N> {
123123
///
124124
/// Note that this is not mentioned in
125125
/// <https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/basedefs/sys_socket.h.html>.
126-
pub(crate) fn builder(&mut self) -> BufferBuilder<N> {
126+
pub(crate) fn builder(&mut self) -> BufferBuilder<'_, N> {
127127
// Build a `msghdr` so we can use the `CMSG_*` functionality in
128128
// libc. We will only use the `CMSG_*` macros which only use
129129
// the `msg_control*` fields.

0 commit comments

Comments
 (0)