diff --git a/ice/src/agent/agent_selector.rs b/ice/src/agent/agent_selector.rs index b7e05fc40..c029ab887 100644 --- a/ice/src/agent/agent_selector.rs +++ b/ice/src/agent/agent_selector.rs @@ -488,6 +488,12 @@ impl ControlledSelector for AgentInternal { p.state .store(CandidatePairState::Succeeded as u8, Ordering::SeqCst); log::trace!("Found valid candidate pair: {}", p); + + if p.nominate_on_binding_success.load(Ordering::SeqCst) + && self.agent_conn.get_selected_pair().is_none() + { + self.set_selected_pair(Some(Arc::clone(&p))).await; + } } else { // This shouldn't happen log::error!("Success response from invalid candidate pair"); @@ -524,7 +530,6 @@ impl ControlledSelector for AgentInternal { if self.agent_conn.get_selected_pair().is_none() { self.set_selected_pair(Some(Arc::clone(&p))).await; } - self.send_binding_success(m, local, remote).await; } else { // If the received Binding request triggered a new check to be // enqueued in the triggered-check queue (Section 7.3.1.4), once the @@ -534,12 +539,12 @@ impl ControlledSelector for AgentInternal { // MUST remove the candidate pair from the valid list, set the // candidate pair state to Failed, and set the checklist state to // Failed. - self.ping_candidate(local, remote).await; + p.nominate_on_binding_success.store(true, Ordering::SeqCst); } - } else { - self.send_binding_success(m, local, remote).await; - self.ping_candidate(local, remote).await; } + + self.send_binding_success(m, local, remote).await; + self.ping_candidate(local, remote).await; } } } diff --git a/ice/src/candidate/mod.rs b/ice/src/candidate/mod.rs index d764d44c7..dbc814d6d 100644 --- a/ice/src/candidate/mod.rs +++ b/ice/src/candidate/mod.rs @@ -234,6 +234,7 @@ pub struct CandidatePair { pub(crate) binding_request_count: AtomicU16, pub(crate) state: AtomicU8, // convert it to CandidatePairState, pub(crate) nominated: AtomicBool, + pub(crate) nominate_on_binding_success: AtomicBool, } impl Default for CandidatePair { @@ -245,6 +246,7 @@ impl Default for CandidatePair { state: AtomicU8::new(CandidatePairState::Waiting as u8), binding_request_count: AtomicU16::new(0), nominated: AtomicBool::new(false), + nominate_on_binding_success: AtomicBool::new(false), } } } @@ -297,6 +299,7 @@ impl CandidatePair { state: AtomicU8::new(CandidatePairState::Waiting as u8), binding_request_count: AtomicU16::new(0), nominated: AtomicBool::new(false), + nominate_on_binding_success: AtomicBool::new(false), } }