Skip to content

Commit 182406d

Browse files
authored
Use all local IP addresses as candidates for mux too (#504)
1 parent a83a63d commit 182406d

File tree

1 file changed

+33
-30
lines changed

1 file changed

+33
-30
lines changed

ice/src/agent/agent_gather.rs

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -388,38 +388,39 @@ impl Agent {
388388

389389
let udp_mux = Arc::clone(&udp_mux);
390390

391-
// There's actually only one, but `local_interfaces` requires a slice.
392391
let local_ips =
393392
local_interfaces(&net, &interface_filter, &ip_filter, &relevant_network_types).await;
394393

395-
let candidate_ip = ext_ip_mapper
394+
let candidate_ips: Vec<std::net::IpAddr> = ext_ip_mapper
396395
.as_ref() // Arc
397396
.as_ref() // Option
398397
.and_then(|mapper| {
399398
if mapper.candidate_type != CandidateType::Host {
400399
return None;
401400
}
402401

403-
local_ips
404-
.iter()
405-
.find_map(|ip| match mapper.find_external_ip(&ip.to_string()) {
406-
Ok(ip) => Some(ip),
407-
Err(err) => {
408-
log::warn!(
402+
Some(
403+
local_ips
404+
.iter()
405+
.filter_map(|ip| match mapper.find_external_ip(&ip.to_string()) {
406+
Ok(ip) => Some(ip),
407+
Err(err) => {
408+
log::warn!(
409409
"1:1 NAT mapping is enabled but not external IP is found for {}: {}",
410410
ip,
411411
err
412412
);
413-
None
414-
}
415-
})
413+
None
414+
}
415+
})
416+
.collect(),
417+
)
416418
})
417-
.or_else(|| local_ips.iter().copied().next());
419+
.unwrap_or_else(|| local_ips.iter().copied().collect());
418420

419-
let candidate_ip = match candidate_ip {
420-
None => return Err(Error::ErrCandidateIpNotFound),
421-
Some(ip) => ip,
422-
};
421+
if candidate_ips.is_empty() {
422+
return Err(Error::ErrCandidateIpNotFound);
423+
}
423424

424425
let ufrag = {
425426
let ufrag_pwd = agent_internal.ufrag_pwd.lock().await;
@@ -430,22 +431,24 @@ impl Agent {
430431
let conn = udp_mux.get_conn(&ufrag).await?;
431432
let port = conn.local_addr()?.port();
432433

433-
let host_config = CandidateHostConfig {
434-
base_config: CandidateBaseConfig {
435-
network: UDP.to_owned(),
436-
address: candidate_ip.to_string(),
437-
port,
438-
conn: Some(conn),
439-
component: COMPONENT_RTP,
440-
..Default::default()
441-
},
442-
tcp_type: TcpType::Unspecified,
443-
};
434+
for candidate_ip in candidate_ips {
435+
let host_config = CandidateHostConfig {
436+
base_config: CandidateBaseConfig {
437+
network: UDP.to_owned(),
438+
address: candidate_ip.to_string(),
439+
port,
440+
conn: Some(conn.clone()),
441+
component: COMPONENT_RTP,
442+
..Default::default()
443+
},
444+
tcp_type: TcpType::Unspecified,
445+
};
444446

445-
let candidate: Arc<dyn Candidate + Send + Sync> =
446-
Arc::new(host_config.new_candidate_host()?);
447+
let candidate: Arc<dyn Candidate + Send + Sync> =
448+
Arc::new(host_config.new_candidate_host()?);
447449

448-
agent_internal.add_candidate(&candidate).await?;
450+
agent_internal.add_candidate(&candidate).await?;
451+
}
449452

450453
Ok(())
451454
}

0 commit comments

Comments
 (0)