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
This commit is contained in:
ospab 2026-05-17 22:22:21 +03:00
parent 990af12fbe
commit 3a4b5a8c63
11 changed files with 21 additions and 27 deletions

View File

@ -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 {

View File

@ -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 {

View File

@ -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);
}
});

View File

@ -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}");
}
}
}
});
}

View File

@ -247,7 +247,7 @@ fn stun_attr(attr_type: u16, value: &[u8]) -> Vec<u8> {
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
}

View File

@ -11,7 +11,7 @@ pub enum NoiseRole {
}
pub enum NoiseSession {
Handshake(HandshakeState),
Handshake(Box<HandshakeState>),
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<usize, ProtocolError> {

View File

@ -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;

View File

@ -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)?;

View File

@ -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];

View File

@ -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));
}

View File

@ -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(),
},