Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix remote candidate deduplication #578

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions src/ice/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,22 +383,18 @@ impl IceAgent {
}

/// Determine whether an equivalent remote candidate is part of a viable candidate pair.
pub fn find_viable_pair_for_equivalent_remote_candidate(
pub fn find_pair_for_equivalent_remote_candidate(
&self,
c: &Candidate,
) -> Option<&CandidatePair> {
self.candidate_pairs
.iter()
.filter(|cand| cand.state() == CheckState::Succeeded)
.find(|pair| {
let o = &self.remote_candidates[pair.remote_idx()];

c.addr() == o.addr()
&& c.base() == o.base()
&& c.proto() == o.proto()
&& c.kind() == o.kind()
&& c.raddr() == o.raddr()
})
self.candidate_pairs.iter().find(|pair| {
let o = &self.remote_candidates[pair.remote_idx()];
c.addr() == o.addr()
&& c.base() == o.base()
&& c.proto() == o.proto()
&& c.kind() == o.kind()
&& c.raddr() == o.raddr()
})
}

/// Credentials for STUN.
Expand Down Expand Up @@ -642,7 +638,7 @@ impl IceAgent {
// confusing inspecting the state.
c.clear_ufrag();

let existing_pair = self.find_viable_pair_for_equivalent_remote_candidate(&c);
let existing_pair = self.find_pair_for_equivalent_remote_candidate(&c);
let existing_candidate =
existing_pair.map(|p| (p.remote_idx(), &self.remote_candidates[p.remote_idx()]));

Expand Down Expand Up @@ -752,13 +748,13 @@ impl IceAgent {
);
} else {
// replace the existing candidate pair, since the new one got a higher prio.
pair.copy_nominated_and_success_state(&self.candidate_pairs[check_idx]);

debug!(
"Replace redundant pair, current: {:?} replaced with: {:?}",
check, pair
);

pair.copy_nominated_and_success_state(&self.candidate_pairs[check_idx]);

if self.ice_lite {
debug!("Retain incoming binding requests for pair");
pair.copy_remote_binding_requests(&self.candidate_pairs[check_idx]);
Expand Down
Loading