clippy all codes (#1214)

1. clippy code
2. add fmt and clippy check in ci
This commit is contained in:
Sijie.Sun
2025-08-10 22:56:41 +08:00
committed by GitHub
parent 0087ac3ffc
commit e43537939a
144 changed files with 1475 additions and 1531 deletions
@@ -389,7 +389,7 @@ pub mod tests {
let udp1 = Arc::new(UdpSocket::bind("0.0.0.0:40164").await.unwrap());
// 144 - DST_PORT_OFFSET = 124
let udp2 = Arc::new(UdpSocket::bind("0.0.0.0:40124").await.unwrap());
let udps = vec![udp1, udp2];
let udps = [udp1, udp2];
let counter = Arc::new(AtomicU32::new(0));
@@ -67,9 +67,9 @@ impl From<NatType> for UdpNatType {
}
}
impl Into<NatType> for UdpNatType {
fn into(self) -> NatType {
match self {
impl From<UdpNatType> for NatType {
fn from(val: UdpNatType) -> Self {
match val {
UdpNatType::Unknown => NatType::Unknown,
UdpNatType::Open(nat_type) => nat_type,
UdpNatType::Cone(nat_type) => nat_type,
@@ -249,7 +249,7 @@ impl UdpSocketArray {
tracing::info!(?addr, ?tid, "got hole punching packet with intreast tid");
tid_to_socket
.entry(tid)
.or_insert_with(Vec::new)
.or_default()
.push(PunchedUdpSocket {
socket: socket.clone(),
tid,
@@ -556,7 +556,7 @@ impl PunchHoleServerCommon {
#[tracing::instrument(err, ret(level=Level::DEBUG), skip(ports))]
pub(crate) async fn send_symmetric_hole_punch_packet(
ports: &Vec<u16>,
ports: &[u16],
udp: Arc<UdpSocket>,
transaction_id: u32,
public_ips: &Vec<Ipv4Addr>,
@@ -628,5 +628,5 @@ pub(crate) async fn try_connect_with_socket(
connector
.try_connect_with_socket(socket, remote_mapped_addr)
.await
.map_err(|e| Error::from(e))
.map_err(Error::from)
}
@@ -172,7 +172,7 @@ impl PunchConeHoleClient {
udp_array
.send_with_all(
&new_hole_punch_packet(tid, HOLE_PUNCH_PACKET_BODY_LEN).into_bytes(),
remote_mapped_addr.clone().into(),
remote_mapped_addr.into(),
)
.await
.with_context(|| "failed to send hole punch packet from local")
@@ -188,7 +188,7 @@ impl PunchConeHoleClient {
..Default::default()
},
SendPunchPacketConeRequest {
listener_mapped_addr: Some(remote_mapped_addr.into()),
listener_mapped_addr: Some(remote_mapped_addr),
dest_addr: Some(local_mapped_addr.into()),
transaction_id: tid,
packet_count_per_batch: 2,
+5 -7
View File
@@ -39,7 +39,7 @@ pub(crate) mod cone;
pub(crate) mod sym_to_cone;
// sym punch should be serialized
static SYM_PUNCH_LOCK: Lazy<DashMap<PeerId, Arc<Mutex<()>>>> = Lazy::new(|| DashMap::new());
static SYM_PUNCH_LOCK: Lazy<DashMap<PeerId, Arc<Mutex<()>>>> = Lazy::new(DashMap::new);
pub static RUN_TESTING: Lazy<AtomicBool> = Lazy::new(|| AtomicBool::new(false));
// Blacklist timeout in seconds
@@ -223,7 +223,7 @@ impl UdpHoePunchConnectorData {
#[tracing::instrument(skip(self))]
async fn handle_punch_result(
self: &Self,
&self,
ret: Result<Option<Box<dyn Tunnel>>, Error>,
backoff: Option<&mut BackOff>,
round: Option<&mut u32>,
@@ -236,10 +236,8 @@ impl UdpHoePunchConnectorData {
if let Some(round) = round {
*round = round.saturating_sub(1);
}
} else {
if let Some(round) = round {
*round += 1;
}
} else if let Some(round) = round {
*round += 1;
}
};
@@ -464,7 +462,7 @@ impl PeerTaskLauncher for UdpHolePunchPeerTaskLauncher {
}
let conns = data.peer_mgr.list_peer_conns(peer_id).await;
if conns.is_some() && conns.unwrap().len() > 0 {
if conns.is_some() && !conns.unwrap().is_empty() {
continue;
}
@@ -80,9 +80,9 @@ impl PunchSymToConeHoleServer {
let public_ips = request
.public_ips
.into_iter()
.map(|ip| std::net::Ipv4Addr::from(ip))
.map(std::net::Ipv4Addr::from)
.collect::<Vec<_>>();
if public_ips.len() == 0 {
if public_ips.is_empty() {
tracing::warn!("send_punch_packet_easy_sym got zero len public ip");
return Err(
anyhow::anyhow!("send_punch_packet_easy_sym got zero len public ip").into(),
@@ -158,9 +158,9 @@ impl PunchSymToConeHoleServer {
let public_ips = request
.public_ips
.into_iter()
.map(|ip| std::net::Ipv4Addr::from(ip))
.map(std::net::Ipv4Addr::from)
.collect::<Vec<_>>();
if public_ips.len() == 0 {
if public_ips.is_empty() {
tracing::warn!("try_punch_symmetric got zero len public ip");
return Err(anyhow::anyhow!("try_punch_symmetric got zero len public ip").into());
}
@@ -281,7 +281,7 @@ impl PunchSymToConeHoleClient {
return;
};
let req = SendPunchPacketEasySymRequest {
listener_mapped_addr: remote_mapped_addr.clone().into(),
listener_mapped_addr: remote_mapped_addr.into(),
public_ips: public_ips.clone().into_iter().map(|x| x.into()).collect(),
transaction_id: tid,
base_port_num: base_port_for_easy_sym.unwrap() as u32,
@@ -313,7 +313,7 @@ impl PunchSymToConeHoleClient {
port_index: u32,
) -> Option<u32> {
let req = SendPunchPacketHardSymRequest {
listener_mapped_addr: remote_mapped_addr.clone().into(),
listener_mapped_addr: remote_mapped_addr.into(),
public_ips: public_ips.clone().into_iter().map(|x| x.into()).collect(),
transaction_id: tid,
round,
@@ -333,9 +333,9 @@ impl PunchSymToConeHoleClient {
{
Err(e) => {
tracing::error!(?e, "failed to send punch packet for hard sym");
return None;
None
}
Ok(resp) => return Some(resp.next_port_index),
Ok(resp) => Some(resp.next_port_index),
}
}
@@ -366,7 +366,7 @@ impl PunchSymToConeHoleClient {
let mut finish_time: Option<Instant> = None;
while finish_time.is_none() || finish_time.as_ref().unwrap().elapsed().as_millis() < 1000 {
udp_array
.send_with_all(&packet, remote_mapped_addr.into())
.send_with_all(packet, remote_mapped_addr.into())
.await?;
tokio::time::sleep(Duration::from_millis(200)).await;
@@ -484,7 +484,7 @@ impl PunchSymToConeHoleClient {
rpc_stub,
base_port_for_easy_sym,
my_nat_info,
remote_mapped_addr.clone(),
remote_mapped_addr,
public_ips.clone(),
tid,
))
@@ -494,7 +494,7 @@ impl PunchSymToConeHoleClient {
&udp_array,
&packet,
tid,
remote_mapped_addr.clone(),
remote_mapped_addr,
&scoped_punch_task,
)
.await?;
@@ -510,7 +510,7 @@ impl PunchSymToConeHoleClient {
let scoped_punch_task: ScopedTask<Option<u32>> =
tokio::spawn(Self::remote_send_hole_punch_packet_random(
rpc_stub,
remote_mapped_addr.clone(),
remote_mapped_addr,
public_ips.clone(),
tid,
round,
@@ -522,7 +522,7 @@ impl PunchSymToConeHoleClient {
&udp_array,
&packet,
tid,
remote_mapped_addr.clone(),
remote_mapped_addr,
&scoped_punch_task,
)
.await?;