fmt: cargo fmt --all

This commit is contained in:
Siavash Sameni
2026-05-12 15:40:02 +04:00
parent dbbab0decf
commit fdfaed5390
9 changed files with 49 additions and 30 deletions

View File

@@ -215,7 +215,11 @@ impl AudioScorer {
if self.iat_samples.len() < 10 {
return None;
}
let mean = self.iat_samples.iter().map(|d| d.as_secs_f64()).sum::<f64>()
let mean = self
.iat_samples
.iter()
.map(|d| d.as_secs_f64())
.sum::<f64>()
/ self.iat_samples.len() as f64;
if mean == 0.0 {
return None;
@@ -257,7 +261,11 @@ impl AudioScorer {
if self.q_intervals.len() < 3 {
return None;
}
let mean = self.q_intervals.iter().map(|d| d.as_secs_f64()).sum::<f64>()
let mean = self
.q_intervals
.iter()
.map(|d| d.as_secs_f64())
.sum::<f64>()
/ self.q_intervals.len() as f64;
if mean == 0.0 {
return None;

View File

@@ -7,12 +7,11 @@
//! It operates on FEC-protected packets, managing loss recovery and adaptive
//! quality transitions.
pub mod audio_scorer;
pub mod auth;
pub mod call_registry;
pub mod config;
pub mod audio_scorer;
pub mod conformance;
pub mod response_policy;
pub mod event_log;
pub mod federation;
pub mod handshake;
@@ -21,6 +20,7 @@ pub mod pipeline;
pub mod presence;
pub mod probe;
pub mod relay_link;
pub mod response_policy;
pub mod room;
pub mod route;
pub mod session_mgr;

View File

@@ -60,12 +60,7 @@ impl ResponsePolicy {
///
/// `fingerprint` is the participant's identity string (or IP as fallback).
/// `code` is the specific violation type that triggered the verdict.
pub fn evaluate(
&mut self,
fingerprint: &str,
code: ViolationCode,
verdict: Verdict,
) -> Action {
pub fn evaluate(&mut self, fingerprint: &str, code: ViolationCode, verdict: Verdict) -> Action {
match verdict {
Verdict::Legitimate => Action::Allow,
Verdict::Suspect => Action::Throttle,
@@ -202,9 +197,10 @@ mod tests {
let _ = policy.evaluate("alice", ViolationCode::Bitrate, Verdict::Abusive);
assert_eq!(policy.len(), 1);
// Manually expire by moving cooldown back
policy
.cooldowns
.insert(("alice".to_string(), ViolationCode::Bitrate), Instant::now() - Duration::from_secs(90000));
policy.cooldowns.insert(
("alice".to_string(), ViolationCode::Bitrate),
Instant::now() - Duration::from_secs(90000),
);
policy.prune();
assert!(policy.is_empty());
}

View File

@@ -274,7 +274,9 @@ impl ReceiverState {
}
// Same candidate — check if hysteresis elapsed.
let elapsed = now.saturating_duration_since(self.candidate_since).as_millis() as u64;
let elapsed = now
.saturating_duration_since(self.candidate_since)
.as_millis() as u64;
if elapsed >= LAYER_SWITCH_HYSTERESIS_MS {
self.selected_layer = suggested;
}
@@ -879,11 +881,7 @@ impl RoomManager {
/// Return the selected simulcast layer (0/1/2) for a receiver.
///
/// Defaults to layer 0 (low) if no state has been recorded yet.
pub fn selected_layer(
&self,
room_name: &str,
receiver_id: ParticipantId,
) -> u8 {
pub fn selected_layer(&self, room_name: &str, receiver_id: ParticipantId) -> u8 {
self.receiver_states
.get(&(room_name.to_string(), receiver_id))
.map(|s| s.selected_layer)
@@ -1963,7 +1961,10 @@ mod tests {
let mut rs = ReceiverState::new();
let t0 = std::time::Instant::now();
rs.update(4000, 0, t0);
assert_eq!(rs.selected_layer, 2, ">3 Mbps + 0% loss → high layer immediately");
assert_eq!(
rs.selected_layer, 2,
">3 Mbps + 0% loss → high layer immediately"
);
}
#[test]
@@ -1985,12 +1986,18 @@ mod tests {
// Drop to low-bandwidth — should not switch immediately
let t1 = t0 + std::time::Duration::from_millis(100);
rs.update(100, 0, t1);
assert_eq!(rs.selected_layer, 2, "hysteresis prevents immediate downgrade");
assert_eq!(
rs.selected_layer, 2,
"hysteresis prevents immediate downgrade"
);
// After 3 s — switch should happen
let t2 = t0 + std::time::Duration::from_millis(3100);
rs.update(100, 0, t2);
assert_eq!(rs.selected_layer, 0, "after 3 s hysteresis, downgrade occurs");
assert_eq!(
rs.selected_layer, 0,
"after 3 s hysteresis, downgrade occurs"
);
}
#[test]