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
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:
@@ -94,7 +94,7 @@ impl ConfigManager {
|
||||
});
|
||||
}
|
||||
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 {
|
||||
self.recent_servers.truncate(20);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};
|
||||
use std::fmt;
|
||||
|
||||
/// TeamSpeak 核心类型定义
|
||||
|
||||
///
|
||||
/// 客户端 ID
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
pub struct ClientId(pub u16);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
use super::{AudioConfig, AudioError, AudioFrame, AudioResult};
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub struct AudioCapture {
|
||||
config: AudioConfig,
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
use super::{AudioError, AudioResult};
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub struct OpusEncoder {
|
||||
sample_rate: u32,
|
||||
channels: u16,
|
||||
@@ -24,6 +25,7 @@ impl OpusEncoder {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub struct OpusDecoder {
|
||||
sample_rate: u32,
|
||||
channels: u16,
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
use super::{AudioConfig, AudioFrame, AudioResult};
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub struct AudioPlayback {
|
||||
config: AudioConfig,
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ impl Client {
|
||||
pub fn start_handshake(&mut self) -> Result<Vec<u8>, ProtocolError> {
|
||||
self.state_machine
|
||||
.transition(ConnectionState::Connecting)
|
||||
.map_err(|e| ProtocolError::PacketParse(e))?;
|
||||
.map_err(ProtocolError::PacketParse)?;
|
||||
|
||||
// 生成随机数 A0
|
||||
let mut random0 = [0u8; 4];
|
||||
@@ -209,7 +209,7 @@ impl Client {
|
||||
}
|
||||
self.state_machine
|
||||
.transition(ConnectionState::ChannelListFinished)
|
||||
.map_err(|e| ProtocolError::PacketParse(e))?;
|
||||
.map_err(ProtocolError::PacketParse)?;
|
||||
}
|
||||
"initivexpand" => {
|
||||
// 旧协议密钥交换
|
||||
@@ -225,7 +225,7 @@ impl Client {
|
||||
"channellistfinished" => {
|
||||
self.state_machine
|
||||
.transition(ConnectionState::ChannelListFinished)
|
||||
.map_err(|e| ProtocolError::PacketParse(e))?;
|
||||
.map_err(ProtocolError::PacketParse)?;
|
||||
}
|
||||
"notifycliententerview" => {
|
||||
// 客户端进入视图
|
||||
@@ -269,7 +269,7 @@ impl Client {
|
||||
|
||||
self.state_machine
|
||||
.transition(ConnectionState::IdentityLevelIncreasing)
|
||||
.map_err(|e| ProtocolError::PacketParse(e))?;
|
||||
.map_err(ProtocolError::PacketParse)?;
|
||||
|
||||
Ok(init.to_c2s_packet_bytes())
|
||||
}
|
||||
@@ -323,7 +323,7 @@ impl Client {
|
||||
|
||||
self.state_machine
|
||||
.transition(ConnectionState::Connected)
|
||||
.map_err(|e| ProtocolError::PacketParse(e))?;
|
||||
.map_err(ProtocolError::PacketParse)?;
|
||||
|
||||
Ok(init.to_c2s_packet_bytes())
|
||||
}
|
||||
@@ -359,7 +359,7 @@ impl Client {
|
||||
|
||||
// 发送 clientek
|
||||
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")
|
||||
.arg("ek", &ek)
|
||||
@@ -507,14 +507,14 @@ impl Client {
|
||||
.config
|
||||
.channel_password
|
||||
.as_deref()
|
||||
.map(|p| crypto::hash_password(p))
|
||||
.map(crypto::hash_password)
|
||||
.unwrap_or_default();
|
||||
|
||||
let server_password = self
|
||||
.config
|
||||
.server_password
|
||||
.as_deref()
|
||||
.map(|p| crypto::hash_password(p))
|
||||
.map(crypto::hash_password)
|
||||
.unwrap_or_default();
|
||||
|
||||
let cmd = CommandBuilder::new("clientinit")
|
||||
|
||||
@@ -167,11 +167,7 @@ impl RttEstimator {
|
||||
let alpha = 0.125;
|
||||
let beta = 0.25;
|
||||
|
||||
let diff = if measured_rtt > self.srtt {
|
||||
measured_rtt - self.srtt
|
||||
} else {
|
||||
self.srtt - measured_rtt
|
||||
};
|
||||
let diff = measured_rtt.abs_diff(self.srtt);
|
||||
|
||||
self.rtt_var = Duration::from_secs_f64(
|
||||
(1.0 - beta) * self.rtt_var.as_secs_f64() + beta * diff.as_secs_f64(),
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
use std::net::SocketAddr;
|
||||
use std::time::Duration;
|
||||
use tokio::net::UdpSocket;
|
||||
use tokio::sync::mpsc;
|
||||
|
||||
use super::client::{Client, ClientConfig};
|
||||
use super::state::ConnectionState;
|
||||
use crate::protocol::{Command, Direction, InPacket, PacketType};
|
||||
use crate::ProtocolError;
|
||||
|
||||
pub enum SessionCommand {
|
||||
|
||||
@@ -14,13 +14,13 @@ impl EphemeralKey {
|
||||
let mut bytes = [0u8; 32];
|
||||
rand::Rng::fill(&mut rand::thread_rng(), &mut bytes);
|
||||
let private = Scalar::from_bytes_mod_order(bytes);
|
||||
let public = &X25519_BASEPOINT * &private;
|
||||
let public = X25519_BASEPOINT * private;
|
||||
Self { private, public }
|
||||
}
|
||||
|
||||
pub fn from_private_bytes(bytes: &[u8; 32]) -> Self {
|
||||
let private = Scalar::from_bytes_mod_order(*bytes);
|
||||
let public = &X25519_BASEPOINT * &private;
|
||||
let public = X25519_BASEPOINT * private;
|
||||
Self { private, public }
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ impl EphemeralKey {
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ pub fn compute_iv_mac(
|
||||
}
|
||||
|
||||
let mut hasher = Sha1::new();
|
||||
hasher.update(&iv);
|
||||
hasher.update(iv);
|
||||
let mac_hash = hasher.finalize();
|
||||
|
||||
let mut mac = [0u8; 8];
|
||||
|
||||
@@ -46,7 +46,7 @@ impl SharedSecret {
|
||||
}
|
||||
|
||||
let mut hasher = Sha1::new();
|
||||
hasher.update(&iv);
|
||||
hasher.update(iv);
|
||||
let mac_hash = hasher.finalize();
|
||||
|
||||
let mut mac = [0u8; 8];
|
||||
@@ -71,7 +71,7 @@ impl SharedSecret {
|
||||
}
|
||||
|
||||
let mut hasher = Sha1::new();
|
||||
hasher.update(&iv);
|
||||
hasher.update(iv);
|
||||
let mac_hash = hasher.finalize();
|
||||
|
||||
let mut mac = [0u8; 8];
|
||||
@@ -181,7 +181,7 @@ pub fn create_key_nonce(
|
||||
temp[6..].copy_from_slice(iv);
|
||||
|
||||
let mut hasher = Sha256::new();
|
||||
hasher.update(&temp);
|
||||
hasher.update(temp);
|
||||
let hash = hasher.finalize();
|
||||
|
||||
let mut key = [0u8; 16];
|
||||
|
||||
@@ -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 {
|
||||
Some(value) => format!("{}={}", escape::escape(&self.name), escape::escape(value)),
|
||||
None => escape::escape(&self.name),
|
||||
Some(value) => write!(f, "{}={}", escape::escape(&self.name), escape::escape(value)),
|
||||
None => write!(f, "{}", escape::escape(&self.name)),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -224,19 +227,15 @@ impl Command {
|
||||
.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 {
|
||||
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(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ impl DatabaseManager {
|
||||
let mut stmt = conn.prepare("SELECT value FROM settings WHERE key = ?1")?;
|
||||
|
||||
let result = stmt
|
||||
.query_row(params![key], |row| Ok(row.get::<_, String>(0)?))
|
||||
.query_row(params![key], |row| row.get::<_, String>(0))
|
||||
.optional()?;
|
||||
|
||||
Ok(result)
|
||||
|
||||
@@ -22,6 +22,7 @@ pub struct Message {
|
||||
|
||||
impl DatabaseManager {
|
||||
/// 创建消息
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn create_message(
|
||||
&self,
|
||||
server_address: &str,
|
||||
|
||||
Reference in New Issue
Block a user