Skip to content

Commit

Permalink
ice: Fix USE-CANDIDATE in controlled agent (#647)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
anders-avos authored Jan 9, 2025
1 parent 397356d commit 26d9167
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
15 changes: 10 additions & 5 deletions ice/src/agent/agent_selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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
Expand All @@ -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;
}
}
}
3 changes: 3 additions & 0 deletions ice/src/candidate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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),
}
}
}
Expand Down Expand Up @@ -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),
}
}

Expand Down

0 comments on commit 26d9167

Please sign in to comment.