Skip to content

Commit 26d9167

Browse files
authored
ice: Fix USE-CANDIDATE in controlled agent (#647)
A controlled agent should reply to USE-CANDIDATE binding requests, also when the candidate pair state isn't already Succeeded. In this case the candidate pair should be nominated immediately if the ping succeeds. Ported from pion/ice@e0db6d2.
1 parent 397356d commit 26d9167

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

ice/src/agent/agent_selector.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,12 @@ impl ControlledSelector for AgentInternal {
488488
p.state
489489
.store(CandidatePairState::Succeeded as u8, Ordering::SeqCst);
490490
log::trace!("Found valid candidate pair: {}", p);
491+
492+
if p.nominate_on_binding_success.load(Ordering::SeqCst)
493+
&& self.agent_conn.get_selected_pair().is_none()
494+
{
495+
self.set_selected_pair(Some(Arc::clone(&p))).await;
496+
}
491497
} else {
492498
// This shouldn't happen
493499
log::error!("Success response from invalid candidate pair");
@@ -524,7 +530,6 @@ impl ControlledSelector for AgentInternal {
524530
if self.agent_conn.get_selected_pair().is_none() {
525531
self.set_selected_pair(Some(Arc::clone(&p))).await;
526532
}
527-
self.send_binding_success(m, local, remote).await;
528533
} else {
529534
// If the received Binding request triggered a new check to be
530535
// enqueued in the triggered-check queue (Section 7.3.1.4), once the
@@ -534,12 +539,12 @@ impl ControlledSelector for AgentInternal {
534539
// MUST remove the candidate pair from the valid list, set the
535540
// candidate pair state to Failed, and set the checklist state to
536541
// Failed.
537-
self.ping_candidate(local, remote).await;
542+
p.nominate_on_binding_success.store(true, Ordering::SeqCst);
538543
}
539-
} else {
540-
self.send_binding_success(m, local, remote).await;
541-
self.ping_candidate(local, remote).await;
542544
}
545+
546+
self.send_binding_success(m, local, remote).await;
547+
self.ping_candidate(local, remote).await;
543548
}
544549
}
545550
}

ice/src/candidate/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ pub struct CandidatePair {
234234
pub(crate) binding_request_count: AtomicU16,
235235
pub(crate) state: AtomicU8, // convert it to CandidatePairState,
236236
pub(crate) nominated: AtomicBool,
237+
pub(crate) nominate_on_binding_success: AtomicBool,
237238
}
238239

239240
impl Default for CandidatePair {
@@ -245,6 +246,7 @@ impl Default for CandidatePair {
245246
state: AtomicU8::new(CandidatePairState::Waiting as u8),
246247
binding_request_count: AtomicU16::new(0),
247248
nominated: AtomicBool::new(false),
249+
nominate_on_binding_success: AtomicBool::new(false),
248250
}
249251
}
250252
}
@@ -297,6 +299,7 @@ impl CandidatePair {
297299
state: AtomicU8::new(CandidatePairState::Waiting as u8),
298300
binding_request_count: AtomicU16::new(0),
299301
nominated: AtomicBool::new(false),
302+
nominate_on_binding_success: AtomicBool::new(false),
300303
}
301304
}
302305

0 commit comments

Comments
 (0)