Skip to content

Commit 3fffe97

Browse files
author
Rain
authored
Merge pull request #7 from u-03c9/main
Fix some warnings
2 parents e85cb48 + eb1285e commit 3fffe97

File tree

12 files changed

+85
-104
lines changed

12 files changed

+85
-104
lines changed

crates/ice/examples/ping_pong.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,17 @@ use webrtc_ice::agent::Agent;
2121
#[macro_use]
2222
extern crate lazy_static;
2323

24+
type SenderType = Arc<Mutex<mpsc::Sender<String>>>;
25+
type ReceiverType = Arc<Mutex<mpsc::Receiver<String>>>;
26+
2427
lazy_static! {
2528
// ErrUnknownType indicates an error with Unknown info.
26-
static ref REMOTE_AUTH_CHANNEL: (Arc<Mutex<mpsc::Sender<String>>>, Arc<Mutex<mpsc::Receiver<String>>>) = {
29+
static ref REMOTE_AUTH_CHANNEL: (SenderType, ReceiverType ) = {
2730
let (tx, rx) = mpsc::channel::<String>(3);
2831
(Arc::new(Mutex::new(tx)), Arc::new(Mutex::new(rx)))
2932
};
3033

31-
static ref REMOTE_CAND_CHANNEL: (Arc<Mutex<mpsc::Sender<String>>>, Arc<Mutex<mpsc::Receiver<String>>>) = {
34+
static ref REMOTE_CAND_CHANNEL: (SenderType, ReceiverType) = {
3235
let (tx, rx) = mpsc::channel::<String>(10);
3336
(Arc::new(Mutex::new(tx)), Arc::new(Mutex::new(rx)))
3437
};
@@ -180,7 +183,7 @@ async fn main() -> Result<(), Error> {
180183
remote_http_port
181184
))
182185
.header("content-type", "application/json")
183-
.body(Body::from(format!("{}", c.marshal())))
186+
.body(Body::from(c.marshal()))
184187
{
185188
Ok(req) => req,
186189
Err(err) => {

crates/ice/src/agent/agent_gather_test.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ async fn test_vnet_gather_dynamic_ip_address() -> Result<(), Error> {
4747

4848
for ip in &local_ips {
4949
if ip.is_loopback() {
50-
assert!(false, "should not return loopback IP");
50+
panic!("should not return loopback IP");
5151
}
5252
if !ipnet.contains(ip) {
53-
assert!(false, "{} should be contained in the CIDR {}", ip, ipnet);
53+
panic!("{} should be contained in the CIDR {}", ip, ipnet);
5454
}
5555
}
5656

@@ -180,7 +180,7 @@ async fn test_vnet_gather_with_nat_1to1_as_host_candidates() -> Result<(), Error
180180
}
181181
}
182182

183-
if &candidates[0].address() == external_ip0 {
183+
if candidates[0].address() == external_ip0 {
184184
assert_eq!(
185185
candidates[1].address(),
186186
external_ip1,
@@ -199,7 +199,7 @@ async fn test_vnet_gather_with_nat_1to1_as_host_candidates() -> Result<(), Error
199199
"Unexpected listen IP: {}",
200200
laddrs[1].ip()
201201
);
202-
} else if &candidates[0].address() == external_ip1 {
202+
} else if candidates[0].address() == external_ip1 {
203203
assert_eq!(
204204
candidates[1].address(),
205205
external_ip0,
@@ -296,7 +296,7 @@ async fn test_vnet_gather_with_nat_1to1_as_srflx_candidates() -> Result<(), Erro
296296
candi_srflx = Some(candidate);
297297
}
298298
_ => {
299-
assert!(false, "Unexpected candidate type");
299+
panic!("Unexpected candidate type");
300300
}
301301
}
302302
}
@@ -346,11 +346,7 @@ async fn test_vnet_gather_with_interface_filter() -> Result<(), Error> {
346346
let a = Agent::new(AgentConfig {
347347
net: Some(Arc::clone(&nw)),
348348
interface_filter: Some(Box::new(|interface_name: &str| -> bool {
349-
if "eth0" == interface_name {
350-
true
351-
} else {
352-
false
353-
}
349+
"eth0" == interface_name
354350
})),
355351
..Default::default()
356352
})
@@ -378,7 +374,6 @@ async fn test_vnet_gather_turn_connection_leak() -> Result<(), Error> {
378374
username: "user".to_owned(),
379375
password: "pass".to_owned(),
380376
proto: ProtoType::Udp,
381-
..Default::default()
382377
};
383378

384379
// buildVNet with a Symmetric NATs for both LANs

crates/ice/src/agent/agent_test.rs

Lines changed: 42 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ async fn test_pair_priority() -> Result<(), Error> {
9090
},
9191
rel_addr: "4.3.2.1".to_owned(),
9292
rel_port: 43212,
93-
..Default::default()
9493
};
9594

9695
let srflx_remote = srflx_config
@@ -107,7 +106,6 @@ async fn test_pair_priority() -> Result<(), Error> {
107106
},
108107
rel_addr: "4.3.2.1".to_owned(),
109108
rel_port: 43211,
110-
..Default::default()
111109
};
112110

113111
let prflx_remote = prflx_config
@@ -161,7 +159,7 @@ async fn test_pair_priority() -> Result<(), Error> {
161159
remote.to_string(),
162160
);
163161
} else {
164-
assert!(false, "expected Some, but got None");
162+
panic!("expected Some, but got None");
165163
}
166164
}
167165
}
@@ -310,8 +308,7 @@ async fn test_handle_peer_reflexive_udp_pflx_candidate() -> Result<(), Error> {
310308

311309
assert_eq!(c.port(), 999, "Port number mismatch");
312310
} else {
313-
assert!(
314-
false,
311+
panic!(
315312
"expected non-empty remote candidate for network type {}",
316313
local.network_type()
317314
);
@@ -914,18 +911,18 @@ async fn test_connection_state_callback() -> Result<(), Error> {
914911
let cfg0 = AgentConfig {
915912
urls: vec![],
916913
network_types: supported_network_types(),
917-
disconnected_timeout: Some(disconnected_duration.clone()),
918-
failed_timeout: Some(failed_duration.clone()),
919-
keepalive_interval: Some(keepalive_interval.clone()),
914+
disconnected_timeout: Some(disconnected_duration),
915+
failed_timeout: Some(failed_duration),
916+
keepalive_interval: Some(keepalive_interval),
920917
..Default::default()
921918
};
922919

923920
let cfg1 = AgentConfig {
924921
urls: vec![],
925922
network_types: supported_network_types(),
926-
disconnected_timeout: Some(disconnected_duration.clone()),
927-
failed_timeout: Some(failed_duration.clone()),
928-
keepalive_interval: Some(keepalive_interval.clone()),
923+
disconnected_timeout: Some(disconnected_duration),
924+
failed_timeout: Some(failed_duration),
925+
keepalive_interval: Some(keepalive_interval),
929926
..Default::default()
930927
};
931928

@@ -1068,7 +1065,6 @@ async fn test_candidate_pair_stats() -> Result<(), Error> {
10681065
},
10691066
rel_addr: "4.3.2.1".to_owned(),
10701067
rel_port: 43212,
1071-
..Default::default()
10721068
}
10731069
.new_candidate_server_reflexive(Some(Arc::clone(&a.agent_internal)))
10741070
.await?,
@@ -1085,7 +1081,6 @@ async fn test_candidate_pair_stats() -> Result<(), Error> {
10851081
},
10861082
rel_addr: "4.3.2.1".to_owned(),
10871083
rel_port: 43211,
1088-
..Default::default()
10891084
}
10901085
.new_candidate_peer_reflexive(Some(Arc::clone(&a.agent_internal)))
10911086
.await?,
@@ -1113,10 +1108,10 @@ async fn test_candidate_pair_stats() -> Result<(), Error> {
11131108
Arc::clone(&host_remote),
11141109
] {
11151110
let mut ai = a.agent_internal.lock().await;
1116-
let p = ai.find_pair(&host_local, &remote).await;
1111+
let p = ai.find_pair(&host_local, remote).await;
11171112

11181113
if p.is_none() {
1119-
ai.add_pair(Arc::clone(&host_local), Arc::clone(&remote))
1114+
ai.add_pair(Arc::clone(&host_local), Arc::clone(remote))
11201115
.await;
11211116
}
11221117
}
@@ -1155,7 +1150,7 @@ async fn test_candidate_pair_stats() -> Result<(), Error> {
11551150
} else if cps.remote_candidate_id == host_remote.id() {
11561151
host_pair_stat = cps;
11571152
} else {
1158-
assert!(false, "invalid remote candidate ID");
1153+
panic!("invalid remote candidate ID");
11591154
}
11601155
}
11611156

@@ -1221,7 +1216,6 @@ async fn test_local_candidate_stats() -> Result<(), Error> {
12211216
},
12221217
rel_addr: "4.3.2.1".to_owned(),
12231218
rel_port: 43212,
1224-
..Default::default()
12251219
}
12261220
.new_candidate_server_reflexive(Some(Arc::clone(&a.agent_internal)))
12271221
.await?,
@@ -1253,8 +1247,7 @@ async fn test_local_candidate_stats() -> Result<(), Error> {
12531247
srflx_local_stat = stats.clone();
12541248
Arc::clone(&srflx_local)
12551249
} else {
1256-
assert!(false, "invalid local candidate ID");
1257-
Arc::clone(&srflx_local)
1250+
panic!("invalid local candidate ID");
12581251
};
12591252

12601253
assert_eq!(
@@ -1318,7 +1311,6 @@ async fn test_remote_candidate_stats() -> Result<(), Error> {
13181311
},
13191312
rel_addr: "4.3.2.1".to_owned(),
13201313
rel_port: 43212,
1321-
..Default::default()
13221314
}
13231315
.new_candidate_server_reflexive(Some(Arc::clone(&a.agent_internal)))
13241316
.await?,
@@ -1335,7 +1327,6 @@ async fn test_remote_candidate_stats() -> Result<(), Error> {
13351327
},
13361328
rel_addr: "4.3.2.1".to_owned(),
13371329
rel_port: 43211,
1338-
..Default::default()
13391330
}
13401331
.new_candidate_peer_reflexive(Some(Arc::clone(&a.agent_internal)))
13411332
.await?,
@@ -1397,8 +1388,7 @@ async fn test_remote_candidate_stats() -> Result<(), Error> {
13971388
host_remote_stat = stats.clone();
13981389
Arc::clone(&host_remote)
13991390
} else {
1400-
assert!(false, "invalid remote candidate ID");
1401-
Arc::clone(&host_remote)
1391+
panic!("invalid remote candidate ID");
14021392
};
14031393

14041394
assert_eq!(
@@ -1479,7 +1469,7 @@ async fn test_init_ext_ip_mapping() -> Result<(), Error> {
14791469
err
14801470
);
14811471
} else {
1482-
assert!(false, "expected error, but got ok");
1472+
panic!("expected error, but got ok");
14831473
}
14841474

14851475
// NewAgent should return an error when 1:1 NAT for srflx candidate is enabled
@@ -1498,7 +1488,7 @@ async fn test_init_ext_ip_mapping() -> Result<(), Error> {
14981488
err
14991489
);
15001490
} else {
1501-
assert!(false, "expected error, but got ok");
1491+
panic!("expected error, but got ok");
15021492
}
15031493

15041494
// NewAgent should return an error when 1:1 NAT for host candidate is enabled
@@ -1517,7 +1507,7 @@ async fn test_init_ext_ip_mapping() -> Result<(), Error> {
15171507
err
15181508
);
15191509
} else {
1520-
assert!(false, "expected error, but got ok");
1510+
panic!("expected error, but got ok");
15211511
}
15221512

15231513
// NewAgent should return if newExternalIPMapper() returns an error.
@@ -1534,7 +1524,7 @@ async fn test_init_ext_ip_mapping() -> Result<(), Error> {
15341524
err
15351525
);
15361526
} else {
1537-
assert!(false, "expected error, but got ok");
1527+
panic!("expected error, but got ok");
15381528
}
15391529

15401530
Ok(())
@@ -1603,7 +1593,7 @@ async fn test_agent_credentials() -> Result<(), Error> {
16031593
{
16041594
assert_eq!(err, *ERR_LOCAL_UFRAG_INSUFFICIENT_BITS);
16051595
} else {
1606-
assert!(false, "expected error, but got ok");
1596+
panic!("expected error, but got ok");
16071597
}
16081598

16091599
if let Err(err) = Agent::new(AgentConfig {
@@ -1614,7 +1604,7 @@ async fn test_agent_credentials() -> Result<(), Error> {
16141604
{
16151605
assert_eq!(err, *ERR_LOCAL_PWD_INSUFFICIENT_BITS);
16161606
} else {
1617-
assert!(false, "expected error, but got ok");
1607+
panic!("expected error, but got ok");
16181608
}
16191609

16201610
Ok(())
@@ -1629,16 +1619,16 @@ async fn test_connection_state_failed_delete_all_candidates() -> Result<(), Erro
16291619

16301620
let cfg0 = AgentConfig {
16311621
network_types: supported_network_types(),
1632-
disconnected_timeout: Some(one_second.clone()),
1633-
failed_timeout: Some(one_second.clone()),
1634-
keepalive_interval: Some(keepalive_interval.clone()),
1622+
disconnected_timeout: Some(one_second),
1623+
failed_timeout: Some(one_second),
1624+
keepalive_interval: Some(keepalive_interval),
16351625
..Default::default()
16361626
};
16371627
let cfg1 = AgentConfig {
16381628
network_types: supported_network_types(),
1639-
disconnected_timeout: Some(one_second.clone()),
1640-
failed_timeout: Some(one_second.clone()),
1641-
keepalive_interval: Some(keepalive_interval.clone()),
1629+
disconnected_timeout: Some(one_second),
1630+
failed_timeout: Some(one_second),
1631+
keepalive_interval: Some(keepalive_interval),
16421632
..Default::default()
16431633
};
16441634

@@ -1681,15 +1671,15 @@ async fn test_connection_state_connecting_to_failed() -> Result<(), Error> {
16811671
let keepalive_interval = Duration::from_secs(0);
16821672

16831673
let cfg0 = AgentConfig {
1684-
disconnected_timeout: Some(one_second.clone()),
1685-
failed_timeout: Some(one_second.clone()),
1686-
keepalive_interval: Some(keepalive_interval.clone()),
1674+
disconnected_timeout: Some(one_second),
1675+
failed_timeout: Some(one_second),
1676+
keepalive_interval: Some(keepalive_interval),
16871677
..Default::default()
16881678
};
16891679
let cfg1 = AgentConfig {
1690-
disconnected_timeout: Some(one_second.clone()),
1691-
failed_timeout: Some(one_second.clone()),
1692-
keepalive_interval: Some(keepalive_interval.clone()),
1680+
disconnected_timeout: Some(one_second),
1681+
failed_timeout: Some(one_second),
1682+
keepalive_interval: Some(keepalive_interval),
16931683
..Default::default()
16941684
};
16951685

@@ -1713,7 +1703,7 @@ async fn test_connection_state_connecting_to_failed() -> Result<(), Error> {
17131703
let mut c = wc_clone.lock().await;
17141704
c.take();
17151705
} else if c == ConnectionState::Connected || c == ConnectionState::Completed {
1716-
assert!(false, "Unexpected ConnectionState: {}", c);
1706+
panic!("Unexpected ConnectionState: {}", c);
17171707
}
17181708
})
17191709
});
@@ -1770,7 +1760,7 @@ async fn test_agent_restart_during_gather() -> Result<(), Error> {
17701760
if let Err(err) = agent.restart("".to_owned(), "".to_owned()).await {
17711761
assert_eq!(err, *ERR_RESTART_WHEN_GATHERING);
17721762
} else {
1773-
assert!(false, "expected error, but got ok");
1763+
panic!("expected error, but got ok");
17741764
}
17751765

17761766
agent.close().await?;
@@ -1788,7 +1778,7 @@ async fn test_agent_restart_when_closed() -> Result<(), Error> {
17881778
if let Err(err) = agent.restart("".to_owned(), "".to_owned()).await {
17891779
assert_eq!(err, *ERR_CLOSED);
17901780
} else {
1791-
assert!(false, "expected error, but got ok");
1781+
panic!("expected error, but got ok");
17921782
}
17931783

17941784
Ok(())
@@ -1801,13 +1791,13 @@ async fn test_agent_restart_one_side() -> Result<(), Error> {
18011791
//"Restart One Side"
18021792
let (_, _, agent_a, agent_b) = pipe(
18031793
Some(AgentConfig {
1804-
disconnected_timeout: Some(one_second.clone()),
1805-
failed_timeout: Some(one_second.clone()),
1794+
disconnected_timeout: Some(one_second),
1795+
failed_timeout: Some(one_second),
18061796
..Default::default()
18071797
}),
18081798
Some(AgentConfig {
1809-
disconnected_timeout: Some(one_second.clone()),
1810-
failed_timeout: Some(one_second.clone()),
1799+
disconnected_timeout: Some(one_second),
1800+
failed_timeout: Some(one_second),
18111801
..Default::default()
18121802
}),
18131803
)
@@ -1861,13 +1851,13 @@ async fn test_agent_restart_both_side() -> Result<(), Error> {
18611851
// Store the original candidates, confirm that after we reconnect we have new pairs
18621852
let (_, _, agent_a, agent_b) = pipe(
18631853
Some(AgentConfig {
1864-
disconnected_timeout: Some(one_second.clone()),
1865-
failed_timeout: Some(one_second.clone()),
1854+
disconnected_timeout: Some(one_second),
1855+
failed_timeout: Some(one_second),
18661856
..Default::default()
18671857
}),
18681858
Some(AgentConfig {
1869-
disconnected_timeout: Some(one_second.clone()),
1870-
failed_timeout: Some(one_second.clone()),
1859+
disconnected_timeout: Some(one_second),
1860+
failed_timeout: Some(one_second),
18711861
..Default::default()
18721862
}),
18731863
)

0 commit comments

Comments
 (0)