@@ -388,38 +388,39 @@ impl Agent {
388
388
389
389
let udp_mux = Arc :: clone ( & udp_mux) ;
390
390
391
- // There's actually only one, but `local_interfaces` requires a slice.
392
391
let local_ips =
393
392
local_interfaces ( & net, & interface_filter, & ip_filter, & relevant_network_types) . await ;
394
393
395
- let candidate_ip = ext_ip_mapper
394
+ let candidate_ips : Vec < std :: net :: IpAddr > = ext_ip_mapper
396
395
. as_ref ( ) // Arc
397
396
. as_ref ( ) // Option
398
397
. and_then ( |mapper| {
399
398
if mapper. candidate_type != CandidateType :: Host {
400
399
return None ;
401
400
}
402
401
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!(
409
409
"1:1 NAT mapping is enabled but not external IP is found for {}: {}" ,
410
410
ip,
411
411
err
412
412
) ;
413
- None
414
- }
415
- } )
413
+ None
414
+ }
415
+ } )
416
+ . collect ( ) ,
417
+ )
416
418
} )
417
- . or_else ( || local_ips. iter ( ) . copied ( ) . next ( ) ) ;
419
+ . unwrap_or_else ( || local_ips. iter ( ) . copied ( ) . collect ( ) ) ;
418
420
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
+ }
423
424
424
425
let ufrag = {
425
426
let ufrag_pwd = agent_internal. ufrag_pwd . lock ( ) . await ;
@@ -430,22 +431,24 @@ impl Agent {
430
431
let conn = udp_mux. get_conn ( & ufrag) . await ?;
431
432
let port = conn. local_addr ( ) ?. port ( ) ;
432
433
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
+ } ;
444
446
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 ( ) ?) ;
447
449
448
- agent_internal. add_candidate ( & candidate) . await ?;
450
+ agent_internal. add_candidate ( & candidate) . await ?;
451
+ }
449
452
450
453
Ok ( ( ) )
451
454
}
0 commit comments