Skip to content

Commit

Permalink
fix clippy and fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
yngrtc committed Jan 26, 2025
1 parent 0aa7c07 commit 5402eaf
Show file tree
Hide file tree
Showing 31 changed files with 68 additions and 125 deletions.
2 changes: 1 addition & 1 deletion dtls/src/extension/extension_server_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl ExtensionServerName {

pub fn size(&self) -> usize {
//TODO: check how to do cryptobyte?
2 + 2 + 1 + 2 + self.server_name.as_bytes().len()
2 + 2 + 1 + 2 + self.server_name.len()
}

pub fn marshal<W: Write>(&self, writer: &mut W) -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion ice/src/agent/agent_internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ impl AgentInternal {
) -> bool {
self.find_remote_candidate(local.network_type(), remote)
.await
.map_or(false, |remote_candidate| {
.is_some_and(|remote_candidate| {
remote_candidate.seen(false);
true
})
Expand Down
52 changes: 26 additions & 26 deletions ice/src/agent/agent_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ async fn test_pair_priority() -> Result<()> {
local: host_local.clone(),
..Default::default()
}
.to_string(),
.to_string(),
"Unexpected bestPair {best_pair} (expected remote: {remote})",
);
} else {
Expand Down Expand Up @@ -662,7 +662,7 @@ async fn test_inbound_validity() -> Result<()> {
},
..Default::default()
}
.new_candidate_host()?,
.new_candidate_host()?,
);

//"Invalid Binding requests should be discarded"
Expand Down Expand Up @@ -1064,7 +1064,7 @@ async fn test_candidate_pair_stats() -> Result<()> {
},
..Default::default()
}
.new_candidate_host()?,
.new_candidate_host()?,
);

let relay_remote: Arc<dyn Candidate + Send + Sync> = Arc::new(
Expand All @@ -1080,7 +1080,7 @@ async fn test_candidate_pair_stats() -> Result<()> {
rel_port: 43210,
..Default::default()
}
.new_candidate_relay()?,
.new_candidate_relay()?,
);

let srflx_remote: Arc<dyn Candidate + Send + Sync> = Arc::new(
Expand All @@ -1095,7 +1095,7 @@ async fn test_candidate_pair_stats() -> Result<()> {
rel_addr: "4.3.2.1".to_owned(),
rel_port: 43212,
}
.new_candidate_server_reflexive()?,
.new_candidate_server_reflexive()?,
);

let prflx_remote: Arc<dyn Candidate + Send + Sync> = Arc::new(
Expand All @@ -1110,7 +1110,7 @@ async fn test_candidate_pair_stats() -> Result<()> {
rel_addr: "4.3.2.1".to_owned(),
rel_port: 43211,
}
.new_candidate_peer_reflexive()?,
.new_candidate_peer_reflexive()?,
);

let host_remote: Arc<dyn Candidate + Send + Sync> = Arc::new(
Expand All @@ -1124,7 +1124,7 @@ async fn test_candidate_pair_stats() -> Result<()> {
},
..Default::default()
}
.new_candidate_host()?,
.new_candidate_host()?,
);

for remote in &[
Expand Down Expand Up @@ -1226,7 +1226,7 @@ async fn test_local_candidate_stats() -> Result<()> {
},
..Default::default()
}
.new_candidate_host()?,
.new_candidate_host()?,
);

let srflx_local: Arc<dyn Candidate + Send + Sync> = Arc::new(
Expand All @@ -1241,7 +1241,7 @@ async fn test_local_candidate_stats() -> Result<()> {
rel_addr: "4.3.2.1".to_owned(),
rel_port: 43212,
}
.new_candidate_server_reflexive()?,
.new_candidate_server_reflexive()?,
);

{
Expand Down Expand Up @@ -1319,7 +1319,7 @@ async fn test_remote_candidate_stats() -> Result<()> {
rel_port: 43210,
..Default::default()
}
.new_candidate_relay()?,
.new_candidate_relay()?,
);

let srflx_remote: Arc<dyn Candidate + Send + Sync> = Arc::new(
Expand All @@ -1334,7 +1334,7 @@ async fn test_remote_candidate_stats() -> Result<()> {
rel_addr: "4.3.2.1".to_owned(),
rel_port: 43212,
}
.new_candidate_server_reflexive()?,
.new_candidate_server_reflexive()?,
);

let prflx_remote: Arc<dyn Candidate + Send + Sync> = Arc::new(
Expand All @@ -1349,7 +1349,7 @@ async fn test_remote_candidate_stats() -> Result<()> {
rel_addr: "4.3.2.1".to_owned(),
rel_port: 43211,
}
.new_candidate_peer_reflexive()?,
.new_candidate_peer_reflexive()?,
);

let host_remote: Arc<dyn Candidate + Send + Sync> = Arc::new(
Expand All @@ -1363,7 +1363,7 @@ async fn test_remote_candidate_stats() -> Result<()> {
},
..Default::default()
}
.new_candidate_host()?,
.new_candidate_host()?,
);

{
Expand Down Expand Up @@ -1465,7 +1465,7 @@ async fn test_init_ext_ip_mapping() -> Result<()> {
nat_1to1_ip_candidate_type: CandidateType::Host,
..Default::default()
})
.await?;
.await?;
assert!(
a.ext_ip_mapper.is_none(),
"a.extIPMapper should be none by default"
Expand All @@ -1480,7 +1480,7 @@ async fn test_init_ext_ip_mapping() -> Result<()> {
candidate_types: vec![CandidateType::Relay],
..Default::default()
})
.await
.await
{
assert_eq!(
Error::ErrIneffectiveNat1to1IpMappingHost,
Expand All @@ -1499,7 +1499,7 @@ async fn test_init_ext_ip_mapping() -> Result<()> {
candidate_types: vec![CandidateType::Relay],
..Default::default()
})
.await
.await
{
assert_eq!(
Error::ErrIneffectiveNat1to1IpMappingSrflx,
Expand All @@ -1518,7 +1518,7 @@ async fn test_init_ext_ip_mapping() -> Result<()> {
multicast_dns_mode: MulticastDnsMode::QueryAndGather,
..Default::default()
})
.await
.await
{
assert_eq!(
Error::ErrMulticastDnsWithNat1to1IpMapping,
Expand All @@ -1535,7 +1535,7 @@ async fn test_init_ext_ip_mapping() -> Result<()> {
nat_1to1_ip_candidate_type: CandidateType::Host,
..Default::default()
})
.await
.await
{
assert_eq!(
Error::ErrInvalidNat1to1IpMapping,
Expand Down Expand Up @@ -1599,8 +1599,8 @@ async fn test_agent_credentials() -> Result<()> {
let a = Agent::new(AgentConfig::default()).await?;
{
let ufrag_pwd = a.internal.ufrag_pwd.lock().await;
assert!(ufrag_pwd.local_ufrag.as_bytes().len() * 8 >= 24);
assert!(ufrag_pwd.local_pwd.as_bytes().len() * 8 >= 128);
assert!(ufrag_pwd.local_ufrag.len() * 8 >= 24);
assert!(ufrag_pwd.local_pwd.len() * 8 >= 128);
}
a.close().await?;

Expand All @@ -1613,7 +1613,7 @@ async fn test_agent_credentials() -> Result<()> {
local_ufrag: "xx".to_owned(),
..Default::default()
})
.await
.await
{
assert_eq!(Error::ErrLocalUfragInsufficientBits, err);
} else {
Expand All @@ -1624,7 +1624,7 @@ async fn test_agent_credentials() -> Result<()> {
local_pwd: "xxxxxx".to_owned(),
..Default::default()
})
.await
.await
{
assert_eq!(Error::ErrLocalPwdInsufficientBits, err);
} else {
Expand Down Expand Up @@ -1824,7 +1824,7 @@ async fn test_agent_restart_one_side() -> Result<()> {
..Default::default()
}),
)
.await?;
.await?;

let (cancel_tx, mut cancel_rx) = mpsc::channel::<()>(1);
let cancel_tx = Arc::new(Mutex::new(Some(cancel_tx)));
Expand Down Expand Up @@ -1882,7 +1882,7 @@ async fn test_agent_restart_both_side() -> Result<()> {
..Default::default()
}),
)
.await?;
.await?;

let conn_afirst_candidates =
generate_candidate_address_strings(agent_a.get_local_candidates().await);
Expand Down Expand Up @@ -2138,7 +2138,7 @@ async fn test_lite_lifecycle() -> Result<()> {
multicast_dns_mode: MulticastDnsMode::Disabled,
..Default::default()
})
.await?,
.await?,
);

a_agent.on_connection_state_change(a_notifier);
Expand All @@ -2159,7 +2159,7 @@ async fn test_lite_lifecycle() -> Result<()> {
check_interval: Duration::from_millis(500),
..Default::default()
})
.await?,
.await?,
);

let (b_connected_tx, mut b_connected_rx) = mpsc::channel::<()>(1);
Expand Down
27 changes: 13 additions & 14 deletions ice/src/agent/agent_vnet_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ pub(crate) async fn add_vnet_stun(wan_net: Arc<net::Net>) -> Result<turn::server
channel_bind_timeout: Duration::from_secs(0),
alloc_close_notify: None,
})
.await?;
.await?;

Ok(server)
}
Expand Down Expand Up @@ -683,8 +683,7 @@ async fn test_connectivity_vnet_1to1_nat_with_host_candidate_vs_symmetric_nats()
}

#[tokio::test]
async fn test_connectivity_vnet_1to1_nat_with_srflx_candidate_vs_symmetric_nats(
) -> Result<(), Error> {
async fn test_connectivity_vnet_1to1_nat_with_srflx_candidate_vs_symmetric_nats() -> Result<(), Error> {
/*env_logger::Builder::new()
.format(|buf, record| {
writeln!(
Expand Down Expand Up @@ -775,7 +774,7 @@ async fn test_disconnected_to_connected() -> Result<(), Error> {
wan.add_chunk_filter(Box::new(move |_c: &(dyn Chunk + Send + Sync)| -> bool {
drop_all_data2.load(Ordering::SeqCst) != 1
}))
.await;
.await;
let wan = Arc::new(Mutex::new(wan));

let net0 = Arc::new(net::Net::new(Some(net::NetConfig {
Expand Down Expand Up @@ -805,7 +804,7 @@ async fn test_disconnected_to_connected() -> Result<(), Error> {
check_interval: keepalive_interval,
..Default::default()
})
.await?,
.await?,
);

let controlled_agent = Arc::new(
Expand All @@ -818,7 +817,7 @@ async fn test_disconnected_to_connected() -> Result<(), Error> {
check_interval: keepalive_interval,
..Default::default()
})
.await?,
.await?,
);

let (controlling_state_changes_tx, mut controlling_state_changes_rx) =
Expand Down Expand Up @@ -848,7 +847,7 @@ async fn test_disconnected_to_connected() -> Result<(), Error> {
ConnectionState::Connected,
&mut controlling_state_changes_rx,
)
.await;
.await;
block_until_state_seen(ConnectionState::Connected, &mut controlled_state_changes_rx).await;

// Drop all packets, and block until we have gone to disconnected
Expand All @@ -857,20 +856,20 @@ async fn test_disconnected_to_connected() -> Result<(), Error> {
ConnectionState::Disconnected,
&mut controlling_state_changes_rx,
)
.await;
.await;
block_until_state_seen(
ConnectionState::Disconnected,
&mut controlled_state_changes_rx,
)
.await;
.await;

// Allow all packets through again, block until we have gone to connected
drop_all_data.store(0, Ordering::SeqCst);
block_until_state_seen(
ConnectionState::Connected,
&mut controlling_state_changes_rx,
)
.await;
.await;
block_until_state_seen(ConnectionState::Connected, &mut controlled_state_changes_rx).await;

{
Expand Down Expand Up @@ -925,7 +924,7 @@ async fn test_write_use_valid_pair() -> Result<(), Error> {

true
}))
.await;
.await;
let wan = Arc::new(Mutex::new(wan));

let net0 = Arc::new(net::Net::new(Some(net::NetConfig {
Expand All @@ -949,7 +948,7 @@ async fn test_write_use_valid_pair() -> Result<(), Error> {
net: Some(Arc::clone(&net0)),
..Default::default()
})
.await?,
.await?,
);

let controlled_agent = Arc::new(
Expand All @@ -959,7 +958,7 @@ async fn test_write_use_valid_pair() -> Result<(), Error> {
net: Some(Arc::clone(&net1)),
..Default::default()
})
.await?,
.await?,
);

gather_and_exchange_candidates(&controlling_agent, &controlled_agent).await?;
Expand Down Expand Up @@ -1002,7 +1001,7 @@ async fn test_write_use_valid_pair() -> Result<(), Error> {
log::debug!("controlled_agent start_connectivity_checks done...");

let test_message = "Test Message";
let mut read_buf = vec![0u8; test_message.as_bytes().len()];
let mut read_buf = vec![0u8; test_message.len()];
controlled_agent_conn.recv(&mut read_buf).await?;

assert_eq!(read_buf, test_message.as_bytes(), "should match");
Expand Down
2 changes: 1 addition & 1 deletion mdns/src/message/resource/txt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl ResourceBody for TxtResource {
let (t, new_off) = unpack_str(msg, off)?;
off = new_off;
// Check if we got too many bytes.
if length < n + t.as_bytes().len() + 1 {
if length < n + t.len() + 1 {
return Err(Error::ErrCalcLen);
}
n += t.len() + 1;
Expand Down
5 changes: 1 addition & 4 deletions rtcp/src/compound_packet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,7 @@ impl Packet for CompoundPacket {
}

fn equal(&self, other: &(dyn Packet + Send + Sync)) -> bool {
other
.as_any()
.downcast_ref::<CompoundPacket>()
.map_or(false, |a| self == a)
other.as_any().downcast_ref::<CompoundPacket>() == Some(self)
}

fn cloned(&self) -> Box<dyn Packet + Send + Sync> {
Expand Down
5 changes: 1 addition & 4 deletions rtcp/src/extended_report/dlrr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,7 @@ impl Packet for DLRRReportBlock {
self
}
fn equal(&self, other: &(dyn Packet + Send + Sync)) -> bool {
other
.as_any()
.downcast_ref::<DLRRReportBlock>()
.map_or(false, |a| self == a)
other.as_any().downcast_ref::<DLRRReportBlock>() == Some(self)
}
fn cloned(&self) -> Box<dyn Packet + Send + Sync> {
Box::new(self.clone())
Expand Down
Loading

0 comments on commit 5402eaf

Please sign in to comment.