Skip to content

p2p: sync ICE controller before send_ping_on_selected pings - #313

Open
lonely1986 wants to merge 1 commit into
livekit:m150_releasefrom
lonely1986:ice-sync-selected-before-ping
Open

lonely1986 wants to merge 1 commit into
livekit:m150_releasefrom
lonely1986:ice-sync-selected-before-ping

Conversation

@lonely1986

Copy link
Copy Markdown

When the controlling side selects a connection, the send_ping_on_selected_ice_controlling / send_ping_on_switch_ice_controlling field trials send an immediate ping from SwitchSelectedConnectionInternal(). However, ice_controller_->OnConnectionSwitched() was only called at the end of that function, after the ping had already been sent. The ICE controller therefore still saw the previous (or no) selected connection while deciding whether the ping should carry USE_CANDIDATE, so against an ICE-lite remote the nomination was deferred to the next scheduled ping, i.e. stable_writable_connection_ping_interval (2.5s) later, delaying DTLS.

Call OnConnectionSwitched() before the immediate ping so the controller is in sync when the nomination attributes are computed.

Tests: assert that the immediate ping carries use_candidate_attr() when the remote is ICE-lite in TestPingOnSwitch and TestPingOnSelected.

When the controlling side selects a connection, the
send_ping_on_selected_ice_controlling / send_ping_on_switch_ice_controlling
field trials send an immediate ping from SwitchSelectedConnectionInternal().
However, ice_controller_->OnConnectionSwitched() was only called at the end
of that function, after the ping had already been sent. The ICE controller
therefore still saw the previous (or no) selected connection while deciding
whether the ping should carry USE_CANDIDATE, so against an ICE-lite remote
the nomination was deferred to the next scheduled ping, i.e.
stable_writable_connection_ping_interval (2.5s) later, delaying DTLS.

Call OnConnectionSwitched() before the immediate ping so the controller is
in sync when the nomination attributes are computed.

Tests: assert that the immediate ping carries use_candidate_attr() when the
remote is ICE-lite in TestPingOnSwitch and TestPingOnSelected.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@lonely1986

Copy link
Copy Markdown
Author

Some context and test status for reviewers.

Problem

With WebRTC-IceFieldTrials/send_ping_on_selected_ice_controlling:true, the controlling side is supposed to send an immediate ping when it selects a connection. Against an ICE-lite SFU that ping should carry USE_CANDIDATE. But ice_controller_->OnConnectionSwitched() was only called at the end of SwitchSelectedConnectionInternal(), i.e. after the immediate ping had already been sent, so the controller still saw the previous (or no) selected connection when the ping's nomination attributes were computed. In that case nomination is deferred to the next scheduled ping (stable_writable_connection_ping_interval, 2.5s).

Fix

Call OnConnectionSwitched() right before the immediate ping, so the controller is in sync when use_candidate_attr is computed. No behavior change when the field trials are off.

What I observed on device (iOS, controlling role, ICE-lite SFU with ~230 ms RTT, field trial enabled). These lines come from a build that carries the same reordering plus extra debug logging, which is not part of this PR:

phase=selected  t_ms=87765310 role=controlling had_old=0 num_pings_sent=5 stable=0 remote_ice_mode=1
phase=controller_synced_before_ping selected=1 writable=1
phase=immediate_ping_attributes trigger=trial t_ms=87765311 selected=1 writable=1 use_candidate=1 nomination=0 num_pings_sent=5 stable=0

i.e. the ping sent 1 ms after selection carries USE_CANDIDATE.

Tests

TestPingOnSwitch and TestPingOnSelected now set ICEMODE_LITE on the remote and assert that the immediate ping has use_candidate_attr() set.

Status: I have verified the behavior above on device, but I have not yet run the updated unit tests locally. [Update this line once you have, e.g. "P2PTransportChannelPingTest.* passes locally".] CI shows no checks on this PR, so a maintainer-triggered run would be appreciated.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


mengrui seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants