fix: resolve clippy warnings across all crates
CI/CD / Test (ubuntu-latest) (push) Successful in 1m40s
CI/CD / Build Frontend (push) Failing after 12s
CI/CD / Test (macos-latest) (push) Has been cancelled
CI/CD / Test (windows-latest) (push) Has been cancelled
CI/CD / Build Desktop (linux) (push) Has been cancelled
CI/CD / Build Desktop (macos) (push) Has been cancelled
CI/CD / Build Desktop (windows) (push) Has been cancelled
CI/CD / Release (push) Has been cancelled

- Remove inherent to_string() methods shadowing Display (Command, CommandArgument)
- Fix empty line after doc comment in shared/types.rs
- Use sort_by_key with Reverse instead of sort_by in config.rs
- Remove redundant closures in client.rs
- Fix borrow patterns in ephemeral.rs and keys.rs
- Use abs_diff in resend.rs
- Fix needless Ok/? in tsdb/config.rs
- Allow too_many_arguments for create_message in tsdb/message.rs
- Allow dead_code on placeholder tsaudio structs
This commit is contained in:
ReTeamSpeak
2026-05-12 17:35:28 +09:00
parent 2b3ae9ae15
commit 3e7cee4893
13 changed files with 35 additions and 37 deletions
+1 -1
View File
@@ -94,7 +94,7 @@ impl ConfigManager {
}); });
} }
self.recent_servers self.recent_servers
.sort_by(|a, b| b.last_connected.cmp(&a.last_connected)); .sort_by_key(|b| std::cmp::Reverse(b.last_connected));
if self.recent_servers.len() > 20 { if self.recent_servers.len() > 20 {
self.recent_servers.truncate(20); self.recent_servers.truncate(20);
} }
+1 -1
View File
@@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};
use std::fmt; use std::fmt;
/// TeamSpeak 核心类型定义 /// TeamSpeak 核心类型定义
///
/// 客户端 ID /// 客户端 ID
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct ClientId(pub u16); pub struct ClientId(pub u16);
+1
View File
@@ -2,6 +2,7 @@
use super::{AudioConfig, AudioError, AudioFrame, AudioResult}; use super::{AudioConfig, AudioError, AudioFrame, AudioResult};
#[allow(dead_code)]
pub struct AudioCapture { pub struct AudioCapture {
config: AudioConfig, config: AudioConfig,
} }
+2
View File
@@ -2,6 +2,7 @@
use super::{AudioError, AudioResult}; use super::{AudioError, AudioResult};
#[allow(dead_code)]
pub struct OpusEncoder { pub struct OpusEncoder {
sample_rate: u32, sample_rate: u32,
channels: u16, channels: u16,
@@ -24,6 +25,7 @@ impl OpusEncoder {
} }
} }
#[allow(dead_code)]
pub struct OpusDecoder { pub struct OpusDecoder {
sample_rate: u32, sample_rate: u32,
channels: u16, channels: u16,
+1
View File
@@ -2,6 +2,7 @@
use super::{AudioConfig, AudioFrame, AudioResult}; use super::{AudioConfig, AudioFrame, AudioResult};
#[allow(dead_code)]
pub struct AudioPlayback { pub struct AudioPlayback {
config: AudioConfig, config: AudioConfig,
} }
+8 -8
View File
@@ -100,7 +100,7 @@ impl Client {
pub fn start_handshake(&mut self) -> Result<Vec<u8>, ProtocolError> { pub fn start_handshake(&mut self) -> Result<Vec<u8>, ProtocolError> {
self.state_machine self.state_machine
.transition(ConnectionState::Connecting) .transition(ConnectionState::Connecting)
.map_err(|e| ProtocolError::PacketParse(e))?; .map_err(ProtocolError::PacketParse)?;
// 生成随机数 A0 // 生成随机数 A0
let mut random0 = [0u8; 4]; let mut random0 = [0u8; 4];
@@ -209,7 +209,7 @@ impl Client {
} }
self.state_machine self.state_machine
.transition(ConnectionState::ChannelListFinished) .transition(ConnectionState::ChannelListFinished)
.map_err(|e| ProtocolError::PacketParse(e))?; .map_err(ProtocolError::PacketParse)?;
} }
"initivexpand" => { "initivexpand" => {
// 旧协议密钥交换 // 旧协议密钥交换
@@ -225,7 +225,7 @@ impl Client {
"channellistfinished" => { "channellistfinished" => {
self.state_machine self.state_machine
.transition(ConnectionState::ChannelListFinished) .transition(ConnectionState::ChannelListFinished)
.map_err(|e| ProtocolError::PacketParse(e))?; .map_err(ProtocolError::PacketParse)?;
} }
"notifycliententerview" => { "notifycliententerview" => {
// 客户端进入视图 // 客户端进入视图
@@ -269,7 +269,7 @@ impl Client {
self.state_machine self.state_machine
.transition(ConnectionState::IdentityLevelIncreasing) .transition(ConnectionState::IdentityLevelIncreasing)
.map_err(|e| ProtocolError::PacketParse(e))?; .map_err(ProtocolError::PacketParse)?;
Ok(init.to_c2s_packet_bytes()) Ok(init.to_c2s_packet_bytes())
} }
@@ -323,7 +323,7 @@ impl Client {
self.state_machine self.state_machine
.transition(ConnectionState::Connected) .transition(ConnectionState::Connected)
.map_err(|e| ProtocolError::PacketParse(e))?; .map_err(ProtocolError::PacketParse)?;
Ok(init.to_c2s_packet_bytes()) Ok(init.to_c2s_packet_bytes())
} }
@@ -359,7 +359,7 @@ impl Client {
// 发送 clientek // 发送 clientek
let ek = self.get_identity_omega()?; let ek = self.get_identity_omega()?;
let proof = self.generate_proof(&ek, &beta_b64); let proof = self.generate_proof(&ek, beta_b64);
let cmd = CommandBuilder::new("clientek") let cmd = CommandBuilder::new("clientek")
.arg("ek", &ek) .arg("ek", &ek)
@@ -507,14 +507,14 @@ impl Client {
.config .config
.channel_password .channel_password
.as_deref() .as_deref()
.map(|p| crypto::hash_password(p)) .map(crypto::hash_password)
.unwrap_or_default(); .unwrap_or_default();
let server_password = self let server_password = self
.config .config
.server_password .server_password
.as_deref() .as_deref()
.map(|p| crypto::hash_password(p)) .map(crypto::hash_password)
.unwrap_or_default(); .unwrap_or_default();
let cmd = CommandBuilder::new("clientinit") let cmd = CommandBuilder::new("clientinit")
+1 -5
View File
@@ -167,11 +167,7 @@ impl RttEstimator {
let alpha = 0.125; let alpha = 0.125;
let beta = 0.25; let beta = 0.25;
let diff = if measured_rtt > self.srtt { let diff = measured_rtt.abs_diff(self.srtt);
measured_rtt - self.srtt
} else {
self.srtt - measured_rtt
};
self.rtt_var = Duration::from_secs_f64( self.rtt_var = Duration::from_secs_f64(
(1.0 - beta) * self.rtt_var.as_secs_f64() + beta * diff.as_secs_f64(), (1.0 - beta) * self.rtt_var.as_secs_f64() + beta * diff.as_secs_f64(),
-2
View File
@@ -1,11 +1,9 @@
use std::net::SocketAddr;
use std::time::Duration; use std::time::Duration;
use tokio::net::UdpSocket; use tokio::net::UdpSocket;
use tokio::sync::mpsc; use tokio::sync::mpsc;
use super::client::{Client, ClientConfig}; use super::client::{Client, ClientConfig};
use super::state::ConnectionState; use super::state::ConnectionState;
use crate::protocol::{Command, Direction, InPacket, PacketType};
use crate::ProtocolError; use crate::ProtocolError;
pub enum SessionCommand { pub enum SessionCommand {
+4 -4
View File
@@ -14,13 +14,13 @@ impl EphemeralKey {
let mut bytes = [0u8; 32]; let mut bytes = [0u8; 32];
rand::Rng::fill(&mut rand::thread_rng(), &mut bytes); rand::Rng::fill(&mut rand::thread_rng(), &mut bytes);
let private = Scalar::from_bytes_mod_order(bytes); let private = Scalar::from_bytes_mod_order(bytes);
let public = &X25519_BASEPOINT * &private; let public = X25519_BASEPOINT * private;
Self { private, public } Self { private, public }
} }
pub fn from_private_bytes(bytes: &[u8; 32]) -> Self { pub fn from_private_bytes(bytes: &[u8; 32]) -> Self {
let private = Scalar::from_bytes_mod_order(*bytes); let private = Scalar::from_bytes_mod_order(*bytes);
let public = &X25519_BASEPOINT * &private; let public = X25519_BASEPOINT * private;
Self { private, public } Self { private, public }
} }
@@ -29,7 +29,7 @@ impl EphemeralKey {
} }
pub fn compute_shared_secret(&self, other_public: &MontgomeryPoint) -> [u8; 32] { pub fn compute_shared_secret(&self, other_public: &MontgomeryPoint) -> [u8; 32] {
let shared = other_public * &self.private; let shared = other_public * self.private;
shared.to_bytes() shared.to_bytes()
} }
@@ -58,7 +58,7 @@ pub fn compute_iv_mac(
} }
let mut hasher = Sha1::new(); let mut hasher = Sha1::new();
hasher.update(&iv); hasher.update(iv);
let mac_hash = hasher.finalize(); let mac_hash = hasher.finalize();
let mut mac = [0u8; 8]; let mut mac = [0u8; 8];
+3 -3
View File
@@ -46,7 +46,7 @@ impl SharedSecret {
} }
let mut hasher = Sha1::new(); let mut hasher = Sha1::new();
hasher.update(&iv); hasher.update(iv);
let mac_hash = hasher.finalize(); let mac_hash = hasher.finalize();
let mut mac = [0u8; 8]; let mut mac = [0u8; 8];
@@ -71,7 +71,7 @@ impl SharedSecret {
} }
let mut hasher = Sha1::new(); let mut hasher = Sha1::new();
hasher.update(&iv); hasher.update(iv);
let mac_hash = hasher.finalize(); let mac_hash = hasher.finalize();
let mut mac = [0u8; 8]; let mut mac = [0u8; 8];
@@ -181,7 +181,7 @@ pub fn create_key_nonce(
temp[6..].copy_from_slice(iv); temp[6..].copy_from_slice(iv);
let mut hasher = Sha256::new(); let mut hasher = Sha256::new();
hasher.update(&temp); hasher.update(temp);
let hash = hasher.finalize(); let hash = hasher.finalize();
let mut key = [0u8; 16]; let mut key = [0u8; 16];
+11 -12
View File
@@ -111,10 +111,13 @@ impl CommandArgument {
} }
} }
pub fn to_string(&self) -> String { }
impl fmt::Display for CommandArgument {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match &self.value { match &self.value {
Some(value) => format!("{}={}", escape::escape(&self.name), escape::escape(value)), Some(value) => write!(f, "{}={}", escape::escape(&self.name), escape::escape(value)),
None => escape::escape(&self.name), None => write!(f, "{}", escape::escape(&self.name)),
} }
} }
} }
@@ -224,19 +227,15 @@ impl Command {
.collect() .collect()
} }
pub fn to_string(&self) -> String {
let mut result = self.name.clone();
for arg in &self.args {
result.push(' ');
result.push_str(&arg.to_string());
}
result
}
} }
impl fmt::Display for Command { impl fmt::Display for Command {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.to_string()) write!(f, "{}", self.name)?;
for arg in &self.args {
write!(f, " {arg}")?;
}
Ok(())
} }
} }
+1 -1
View File
@@ -12,7 +12,7 @@ impl DatabaseManager {
let mut stmt = conn.prepare("SELECT value FROM settings WHERE key = ?1")?; let mut stmt = conn.prepare("SELECT value FROM settings WHERE key = ?1")?;
let result = stmt let result = stmt
.query_row(params![key], |row| Ok(row.get::<_, String>(0)?)) .query_row(params![key], |row| row.get::<_, String>(0))
.optional()?; .optional()?;
Ok(result) Ok(result)
+1
View File
@@ -22,6 +22,7 @@ pub struct Message {
impl DatabaseManager { impl DatabaseManager {
/// 创建消息 /// 创建消息
#[allow(clippy::too_many_arguments)]
pub fn create_message( pub fn create_message(
&self, &self,
server_address: &str, server_address: &str,