From c6df26ac8508d53323e4729a150374b71a9e0c93 Mon Sep 17 00:00:00 2001 From: alex Date: Wed, 18 Mar 2026 16:37:40 +0800 Subject: [PATCH] fix some warnings --- .vscode/settings.json | 2 +- src/network/async_main.rs | 16 ++-------------- src/network/device.rs | 2 -- src/network/node.rs | 4 ++-- src/network/packet.rs | 1 - src/network/tun_linux.rs | 2 +- src/network/tuntap.rs | 2 +- src/tcp/identity_cache.rs | 4 ++-- src/tcp/quic.rs | 4 ++-- src/utils/encrypter.rs | 8 +++----- 10 files changed, 14 insertions(+), 31 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 9eb94d8..fb0827b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,4 @@ { - "rust-analyzer.cargo.target": "x86_64-pc-windows-gnu", + // "rust-analyzer.cargo.target": "x86_64-pc-windows-gnu", // "rust-analyzer.cargo.features": ["tun"] } \ No newline at end of file diff --git a/src/network/async_main.rs b/src/network/async_main.rs index fabd9c7..b7303a6 100755 --- a/src/network/async_main.rs +++ b/src/network/async_main.rs @@ -1,4 +1,4 @@ -use std::sync::atomic::{AtomicU64, Ordering}; +use std::sync::atomic::{Ordering}; use std::sync::Arc; use std::time::Duration; @@ -15,7 +15,6 @@ use sdlan_sn_rs::utils::{get_current_timestamp, is_multi_broadcast}; use sdlan_sn_rs::utils::{Mac, Result}; use tokio::net::{UdpSocket}; use tokio::sync::mpsc::{channel, Receiver, Sender}; -use tokio::time::sleep; use tokio_util::sync::CancellationToken; use super::{Node, StartStopInfo}; @@ -118,17 +117,6 @@ pub async fn async_main( Ok(()) } -async fn run_quic_loop( - edge: &Node, - quic_addr: &str, - pong_time: Arc, - start_stop_chan: Receiver, - connecting_chan: Sender, - ipv6_ntework_restarter: Option> -) { - -} - async fn run_edge_loop(eee: &'static Node, cancel: CancellationToken) { ping_to_sn().await; { @@ -251,7 +239,7 @@ async fn loop_tap(eee: &'static Node, cancel: CancellationToken) { packet.push(0x00); packet.extend_from_slice(&reply); - /// TODO: check the packet should + // TODO: check the packet should if let Err(_e) = eee.device.handle_packet_from_net(&packet).await { error!("failed to write dns packet to device"); } diff --git a/src/network/device.rs b/src/network/device.rs index ab8e1cd..5750b74 100755 --- a/src/network/device.rs +++ b/src/network/device.rs @@ -1,5 +1,3 @@ -use std::sync::RwLock; - use crate::utils::mac_to_string; use sdlan_sn_rs::{peer::IpSubnet, utils::Mac}; use tracing::debug; diff --git a/src/network/node.rs b/src/network/node.rs index 1a76743..1ee1578 100755 --- a/src/network/node.rs +++ b/src/network/node.rs @@ -13,12 +13,12 @@ use tokio::sync::oneshot; use tracing::{debug, error}; use crate::quic::quic_init; -use crate::{ConnectionInfo, Encryptor, MyEncryptor, get_base_dir}; +use crate::{ConnectionInfo, MyEncryptor, get_base_dir}; use crate::pb::{ encode_to_tcp_message, encode_to_udp_message, SdlEmpty, SdlStunProbe, SdlStunProbeReply, }; use crate::tcp::{NatType, PacketType, StunProbeAttr, get_quic_write_conn}; -use crate::utils::{Socket, create_or_load_mac}; +use crate::utils::{Socket}; use sdlan_sn_rs::peer::{IpSubnet, V6Info}; diff --git a/src/network/packet.rs b/src/network/packet.rs index 0c7ba0e..36fea60 100755 --- a/src/network/packet.rs +++ b/src/network/packet.rs @@ -1,6 +1,5 @@ use std::{net::SocketAddr, sync::atomic::Ordering, time::Duration}; -use crate::network::IdentityID; use crate::pb::SdlPolicyRequest; use crate::tcp::{NatType, get_quic_write_conn, is_identity_ok}; use crate::{network::TunTapPacketHandler, utils::mac_to_string}; diff --git a/src/network/tun_linux.rs b/src/network/tun_linux.rs index 398e7b1..e80c435 100755 --- a/src/network/tun_linux.rs +++ b/src/network/tun_linux.rs @@ -1,7 +1,7 @@ use etherparse::{Ethernet2Header}; use sdlan_sn_rs::config::SDLAN_DEFAULT_TTL; use sdlan_sn_rs::utils::{ - aes_encrypt, ip_to_string, is_ipv6_multicast, net_bit_len_to_mask, + ip_to_string, is_ipv6_multicast, net_bit_len_to_mask, SDLanError, }; use std::ffi::CStr; diff --git a/src/network/tuntap.rs b/src/network/tuntap.rs index 0bd42da..d53b816 100755 --- a/src/network/tuntap.rs +++ b/src/network/tuntap.rs @@ -5,7 +5,7 @@ use dashmap::DashMap; use once_cell::sync::OnceCell; use sdlan_sn_rs::{ config::SDLAN_DEFAULT_TTL, - utils::{aes_encrypt, get_current_timestamp, ip_to_string, Mac}, + utils::{get_current_timestamp, ip_to_string, Mac}, }; use tracing::debug; diff --git a/src/tcp/identity_cache.rs b/src/tcp/identity_cache.rs index c08997f..fa78a4e 100644 --- a/src/tcp/identity_cache.rs +++ b/src/tcp/identity_cache.rs @@ -1,6 +1,6 @@ -use std::{collections::{HashMap, HashSet}, sync::{OnceLock, atomic::{AtomicU64, Ordering}}, time::{SystemTime, UNIX_EPOCH}}; +use std::{collections::{HashMap, HashSet}, sync::{OnceLock}, time::{SystemTime, UNIX_EPOCH}}; -use dashmap::{DashMap, DashSet}; +use dashmap::{DashMap}; use tracing::debug; type IdentityID = u32; diff --git a/src/tcp/quic.rs b/src/tcp/quic.rs index 2f54b80..004fd6c 100644 --- a/src/tcp/quic.rs +++ b/src/tcp/quic.rs @@ -225,7 +225,7 @@ async fn handle_tcp_message(msg: SdlanTcp) { }; let data = hdr.marshal_to_bytes(); - if let Err(e) = edge.device.send(&data) { + if let Err(_e) = edge.device.send(&data) { error!("failed to write arp response to device"); } } @@ -692,7 +692,7 @@ async fn on_disconnected_callback() { *edge.encryptor.write().unwrap() = MyEncryptor::Invalid; } -async fn on_connected_callback(local_ip: Option, stream: &mut SendStream, pkt_id: Option) { +async fn on_connected_callback(local_ip: Option, stream: &mut SendStream, _pkt_id: Option) { let edge = get_edge(); // let installed_channel = install_channel.to_owned(); diff --git a/src/utils/encrypter.rs b/src/utils/encrypter.rs index d3ae351..aa2f3e7 100644 --- a/src/utils/encrypter.rs +++ b/src/utils/encrypter.rs @@ -1,12 +1,10 @@ -use std::{sync::{Arc, OnceLock, RwLock, atomic::{AtomicBool, AtomicU32, Ordering}}, time::{SystemTime, UNIX_EPOCH}}; +use std::{sync::atomic::{AtomicU32, Ordering}, time::{SystemTime, UNIX_EPOCH}}; -use tracing::debug; use chacha20poly1305::{KeyInit, aead::Aead}; -use dashmap::DashSet; use sdlan_sn_rs::utils::{Result, SDLanError, aes_decrypt, aes_encrypt}; -const CounterMask: u32 = (1<<24) - 1; +const COUNTER_MASK: u32 = (1<<24) - 1; pub trait Encryptor { fn is_setted(&self) -> bool; @@ -107,7 +105,7 @@ impl Encryptor for Chacha20Encryptor { let now = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis() as u64; let next_counter = self.next_counter.fetch_update(Ordering::Release, Ordering::Acquire, |current| { - Some((current + 1) & CounterMask) + Some((current + 1) & COUNTER_MASK) }).unwrap() as u64; let mut nonce = Vec::new();