From 3a4b5a8c63cb7283ccb3aa7ef125e5b4df9dc68d Mon Sep 17 00:00:00 2001 From: ospab Date: Sun, 17 May 2026 22:22:21 +0300 Subject: [PATCH] chore: fix cargo clippy warnings - Boxed HandshakeState in NoiseSession to reduce enum variant sizes - Used is_ok() instead of let Ok(_) pattern - Applied automatic clippy fixes for minor warnings --- ostp-client/src/app.rs | 6 ++++++ ostp-client/src/config.rs | 11 +---------- ostp-client/src/runner.rs | 2 +- ostp-client/src/tunnel/proxy.rs | 4 +--- ostp-client/src/turn.rs | 2 +- ostp-core/src/crypto/noise.rs | 4 ++-- ostp-core/src/framing/padding.rs | 4 ++-- ostp-core/src/protocol.rs | 7 +++---- ostp-core/src/resumption.rs | 4 ++-- ostp-server/src/lib.rs | 2 +- ostp/src/main.rs | 2 +- 11 files changed, 21 insertions(+), 27 deletions(-) diff --git a/ostp-client/src/app.rs b/ostp-client/src/app.rs index 261a9bc..0b6c80f 100644 --- a/ostp-client/src/app.rs +++ b/ostp-client/src/app.rs @@ -54,6 +54,12 @@ pub struct AppState { pub log_scroll: u16, } +impl Default for AppState { + fn default() -> Self { + Self::new() + } +} + impl AppState { pub fn new() -> Self { Self { diff --git a/ostp-client/src/config.rs b/ostp-client/src/config.rs index 91f2547..b43a9f0 100644 --- a/ostp-client/src/config.rs +++ b/ostp-client/src/config.rs @@ -53,6 +53,7 @@ pub struct LocalProxyConfig { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Default)] pub struct TurnConfig { pub enabled: bool, pub server_addr: String, @@ -81,16 +82,6 @@ impl Default for LocalProxyConfig { } } -impl Default for TurnConfig { - fn default() -> Self { - Self { - enabled: false, - server_addr: String::new(), - username: String::new(), - access_key: String::new(), - } - } -} impl Default for ClientConfig { fn default() -> Self { diff --git a/ostp-client/src/runner.rs b/ostp-client/src/runner.rs index c3e13dc..15b7b09 100644 --- a/ostp-client/src/runner.rs +++ b/ostp-client/src/runner.rs @@ -133,7 +133,7 @@ pub async fn run_client(config: crate::config::ClientConfig) -> Result<()> { let (shutdown_tx, shutdown_rx) = watch::channel(false); tokio::spawn(async move { - if let Ok(_) = wait_for_shutdown_signal().await { + if wait_for_shutdown_signal().await.is_ok() { let _ = shutdown_tx.send(true); } }); diff --git a/ostp-client/src/tunnel/proxy.rs b/ostp-client/src/tunnel/proxy.rs index 617642d..bac23b3 100644 --- a/ostp-client/src/tunnel/proxy.rs +++ b/ostp-client/src/tunnel/proxy.rs @@ -73,11 +73,9 @@ pub async fn run_local_socks5_proxy( && !msg.contains("Connection reset") && !msg.contains("Broken pipe") && !msg.contains("unsupported SOCKS5 command") - { - if debug { + && debug { tracing::warn!("proxy client error: {err}"); } - } } }); } diff --git a/ostp-client/src/turn.rs b/ostp-client/src/turn.rs index 04f54a8..e6acb2b 100644 --- a/ostp-client/src/turn.rs +++ b/ostp-client/src/turn.rs @@ -247,7 +247,7 @@ fn stun_attr(attr_type: u16, value: &[u8]) -> Vec { out.extend_from_slice(value); // Pad to 4-byte boundary let pad = (4 - (value.len() % 4)) % 4; - out.extend(std::iter::repeat(0u8).take(pad)); + out.extend(std::iter::repeat_n(0u8, pad)); out } diff --git a/ostp-core/src/crypto/noise.rs b/ostp-core/src/crypto/noise.rs index d899349..d89eaa4 100644 --- a/ostp-core/src/crypto/noise.rs +++ b/ostp-core/src/crypto/noise.rs @@ -11,7 +11,7 @@ pub enum NoiseRole { } pub enum NoiseSession { - Handshake(HandshakeState), + Handshake(Box), Transport(TransportState), } @@ -36,7 +36,7 @@ impl NoiseSession { .map_err(|_| ProtocolError::Crypto("noise-responder".to_string()))?, }; - Ok(Self::Handshake(handshake)) + Ok(Self::Handshake(Box::new(handshake))) } pub fn write_handshake(&mut self, payload: &[u8], out: &mut [u8]) -> Result { diff --git a/ostp-core/src/framing/padding.rs b/ostp-core/src/framing/padding.rs index 900d757..d56f38e 100644 --- a/ostp-core/src/framing/padding.rs +++ b/ostp-core/src/framing/padding.rs @@ -18,7 +18,7 @@ impl TrafficProfile { } fn align_up(v: usize, align: usize) -> usize { - ((v + align - 1) / align) * align + v.div_ceil(align) * align } #[derive(Debug, Clone, Copy)] @@ -49,7 +49,7 @@ impl AdaptivePadder { PaddingStrategy::Fixed(target) => target.saturating_sub(payload_len), PaddingStrategy::Adaptive => { let base_bucket = 64; - let bucketized = ((payload_len + base_bucket - 1) / base_bucket) * base_bucket; + let bucketized = payload_len.div_ceil(base_bucket) * base_bucket; let mut target = bucketized.clamp(base_bucket, self.mtu_hint); if target < payload_len { target = payload_len; diff --git a/ostp-core/src/protocol.rs b/ostp-core/src/protocol.rs index cf542c0..062b10c 100644 --- a/ostp-core/src/protocol.rs +++ b/ostp-core/src/protocol.rs @@ -261,7 +261,7 @@ impl ProtocolMachine { let extracted_payload = read_out[..n].to_vec(); - return Ok(ProtocolAction::HandshakePayload(Bytes::from(extracted_payload), response)); + Ok(ProtocolAction::HandshakePayload(Bytes::from(extracted_payload), response)) } else if self.state == OstpState::Established { if raw_vec.len() < 12 { return Err(ProtocolError::Framing("data datagram too short".to_string())); @@ -304,8 +304,8 @@ impl ProtocolMachine { let mut outbound_actions = Vec::new(); // Fast path processing for Nacks: act immediately, bypass sequence queue - if packet.header.kind == FrameKind::Nack { - if packet.payload.len() >= 8 { + if packet.header.kind == FrameKind::Nack + && packet.payload.len() >= 8 { let req_nonce = u64::from_be_bytes(packet.payload[..8].try_into().unwrap()); if let Some(cached_frame) = self.lookup_sent_frame(req_nonce) { tracing::debug!("NACK received: retransmitting nonce={}", req_nonce); @@ -317,7 +317,6 @@ impl ProtocolMachine { self.cc.on_loss(1200); } } - } if packet.header.kind == FrameKind::Ack { let ranges = parse_ack_ranges(&packet.payload)?; diff --git a/ostp-core/src/resumption.rs b/ostp-core/src/resumption.rs index d3753ad..dab1c74 100644 --- a/ostp-core/src/resumption.rs +++ b/ostp-core/src/resumption.rs @@ -55,7 +55,7 @@ impl SessionTicket { // Derive ticket ID from key material + timestamp let mut hasher = Sha256::new(); hasher.update(transport_key); - hasher.update(&now.to_be_bytes()); + hasher.update(now.to_be_bytes()); hasher.update(b"ostp-ticket-id"); let hash = hasher.finalize(); let mut ticket_id = [0u8; 16]; @@ -64,7 +64,7 @@ impl SessionTicket { // Derive cipher key for early data from PSK + ticket let mut key_hasher = Sha256::new(); key_hasher.update(psk); - key_hasher.update(&ticket_id); + key_hasher.update(ticket_id); key_hasher.update(b"ostp-early-data-key"); let cipher_key_hash = key_hasher.finalize(); let mut cipher_key = [0u8; 32]; diff --git a/ostp-server/src/lib.rs b/ostp-server/src/lib.rs index de0f177..f46da6b 100644 --- a/ostp-server/src/lib.rs +++ b/ostp-server/src/lib.rs @@ -396,7 +396,7 @@ async fn run_server_loop( for sid in dropped_sessions { let _ = ui_event_tx.send(UiEvent::Log(format!("Session {sid} expired, releasing resources"))); let mut streams_to_cancel = Vec::new(); - for (&(session_id, stream_id), _) in &remotes { + for &(session_id, stream_id) in remotes.keys() { if session_id == sid { streams_to_cancel.push((session_id, stream_id)); } diff --git a/ostp/src/main.rs b/ostp/src/main.rs index 9dfcafa..909112e 100644 --- a/ostp/src/main.rs +++ b/ostp/src/main.rs @@ -634,7 +634,7 @@ async fn run_client_directly(client_cfg: ClientConfig) -> Result<()> { }, turn: ostp_client::config::TurnConfig { enabled: turn_cfg.map(|t| t.enabled).unwrap_or(false), - server_addr: turn_cfg.and_then(|t| Some(t.server_addr.clone())).unwrap_or_default(), + server_addr: turn_cfg.map(|t| t.server_addr.clone()).unwrap_or_default(), username: turn_cfg.and_then(|t| t.username.clone()).unwrap_or_default(), access_key: turn_cfg.and_then(|t| t.access_key.clone()).unwrap_or_default(), },