From 89f5a988c9b62e047d24c3815feb9f55672497cf Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Tue, 22 Mar 2022 15:19:50 -0400 Subject: [PATCH] TT#14008 attempt to match ICE foundations for learned prflx cands Instead of always generating a new ICE foundation string for every learned peer-reflexive candidate, try to use the same foundation string for candidates that belong together. We use the priority number plus the component ID for this to see if we've learned a candidate with a fitting priority number before. If we have then re-use the same ICE foundation string. This allows ICE to complete with only learned prflx candidates and without (or before) re-invite to communicate the correct ICE foundations. Change-Id: I74bde6ef22a164df57d0b77cbaef34e4a499da72 --- daemon/ice.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/daemon/ice.c b/daemon/ice.c index 5223f7a8f..ee0f8e59d 100644 --- a/daemon/ice.c +++ b/daemon/ice.c @@ -860,7 +860,27 @@ static struct ice_candidate_pair *__learned_candidate(struct ice_agent *ag, stru cand->priority = priority; cand->endpoint = *src; cand->type = ICT_PRFLX; - __cand_ice_foundation(call, cand); + + // check if we've already learned another candidate that belongs to this one. use the priority number + // together with the component to guess a matching other candidate. + unsigned long prio_base = priority + ps->component; + struct ice_candidate *known_cand = NULL; + for (unsigned int comp = 1; comp <= ag->active_components; comp++) { + if (comp == ps->component) + continue; + unsigned long prio = prio_base - comp; + known_cand = g_hash_table_lookup(ag->cand_prio_hash, GUINT_TO_POINTER(prio)); + if (known_cand) + break; + } + if (known_cand) { + // got one. use the previously learned generated ICE foundation string also for this one: + cand->foundation = known_cand->foundation; + } + else { + // make new: + __cand_ice_foundation(call, cand); + } old_cand = __foundation_lookup(ag, &cand->foundation, ps->component); if (old_cand && old_cand->priority > priority) {