From 4ace3ac8634d0279e8576c1b22db5531338e9b97 Mon Sep 17 00:00:00 2001 From: Hugo Tunius Date: Thu, 24 Oct 2024 10:51:39 +0100 Subject: [PATCH 1/2] Fix remote candidate de-duplication When considering whether to de-duplicate a remote candidate it's sufficient to verify that it exists in any pair. In particular, checking `state == CheckState::Succeeded` is problematic because in ICE lite this is never true(ICE lite agents don't send binding requests). --- src/ice/agent.rs | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/ice/agent.rs b/src/ice/agent.rs index 8359ac35..6c8be4bd 100644 --- a/src/ice/agent.rs +++ b/src/ice/agent.rs @@ -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. @@ -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()])); From 135da62762a562984963270b04a1c0a010be3f6b Mon Sep 17 00:00:00 2001 From: Hugo Tunius Date: Thu, 24 Oct 2024 10:57:13 +0100 Subject: [PATCH 2/2] Tweak log and copy order --- src/ice/agent.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ice/agent.rs b/src/ice/agent.rs index 6c8be4bd..1e8ba515 100644 --- a/src/ice/agent.rs +++ b/src/ice/agent.rs @@ -748,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]);