Repository navigation
Stabilize ICE-lite priorities like libwebrtc - #1060
Conversation
519478e to
88558a6
Compare
|
I'll add tests shortly, I'll also add an e2e test in https://github.com/pion/browser-tests against browsers. |
3210a5b to
838e6dc
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The 257th UDP host candidate in a group receives a duplicate priority, making pair selection insertion-order dependent and potentially causing lite peers to disagree.
1 open issue
What changed in this PR
This PR refines ICE-lite candidate priorities to reduce migration and restart inconsistencies caused by IPv4/IPv6 gather order, building on the earlier lite-to-lite selection fixes.
Changes:
- Partition local preference by address precedence, with a counter separating otherwise colliding candidates.
- Preserve explicit candidate priority overrides.
- Add tests for cross-family gather ordering, priority uniqueness, and override preservation.
| File | Description |
|---|---|
| candidate.go | Adds an internal priority-override check to the candidate interface. |
| candidate_base.go | Implements priority-override detection. |
| agent.go | Uses address precedence and counter-based ICE-lite priority allocation. |
| agent_test.go | Updates uniqueness expectations and tests ordering and overrides. |
| addr.go | Adds address-precedence classification and family fallbacks. |
Review effort: Balanced
| if priority&counterMask == 0 { | ||
| a.log.Warnf("No unique priority left for ICE-lite candidate %s, using %d", cand, priority) | ||
|
|
||
| break |
There was a problem hiding this comment.
an extremely unrealistic scenario, I copied this from libwebrtc anyways https://webrtc.googlesource.com/src/+/refs/heads/main/rtc_base/network.cc#517
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## v4 #1060 +/- ##
==========================================
- Coverage 88.42% 88.32% -0.10%
==========================================
Files 47 48 +1
Lines 6600 6682 +82
==========================================
+ Hits 5836 5902 +66
- Misses 515 524 +9
- Partials 249 256 +7
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
History: PR #959 let ICE-lite agents pick the best pair locally without sending checks. All lite host candidates had the same priority, so with several candidates the two sides could pick different pairs and fail to connect. #968 fixed that by stepping each new lite candidate down from the default until its priority was unique. That made priorities depend on gather order: the same address could get a different priority on another node, or depending on whether the node was single- or dual-stack. The main problem is that Pion doesn't have local preference like libwebrtc, instead of doing other hacks this adds: `(counter << 8) | address precedence`. The low byte is the RFC 6724 precedence of the address (IPv6 40, IPv4 30, and so on), so address families never collide. The counter drops only to separate candidates of the same family. A candidate's priority no longer depends on gather order or on whether the agent is single- or dual-stack. Unlike libwebrtc, the high byte is not a network adapter preference, since Pion has no adapter types.
838e6dc to
6063b76
Compare
|
@JoTurk Thank you for the quick reply, I'll test it soon! |
cnderrauber
left a comment
There was a problem hiding this comment.
It works well, thank you!
|
Thank you for the report and the quick test, I'll merge and tag it now, and will add a migration test against browsers in pion/browser-tests, so we catch future issues :) |
#### Description #1060 Stabilize ICE-lite priorities like libwebrtc, but full-ice still use the defaultLocalPreference(65535), so a candidate can has different priority in different mode. This PR apply the local preference calculation to both modes.

Description
History:
PR #959 let ICE-lite agents pick the best pair locally without sending checks. All lite host candidates had the same priority, so with several candidates the two sides could pick different pairs and fail to connect. #968 fixed that by stepping each new lite candidate down from the default until its priority was unique. That made priorities depend on gather order: the same address could get a different priority on another node, or depending on whether the node was single- or dual-stack.
The main problem is that Pion doesn't have local preference like libwebrtc, instead of doing other hacks this adds:
(counter << 8) | address precedence. The low byte is the RFC 6724 precedence of the address (IPv6 40, IPv4 30, and so on), so address families never collide. The counter drops only to separate candidates of the same family. A candidate's priority no longer depends on gather order or on whether the agent is single- or dual-stack.Edit: for what it's worth, Unlike libwebrtc, the high byte is not a network adapter preference, since Pion has no adapter types.
Reference issue
closes #1059