Skip to content

Commit f05eec2

Browse files
committed
Handle role conflict in the standalone RTCIceTransport
Bug: 926134 Change-Id: I202c76275a97d295866ea70079f95f814e6de5b6 Reviewed-on: https://chromium-review.googlesource.com/c/1443544 Commit-Queue: Steve Anton <[email protected]> Commit-Queue: Seth Hampson <[email protected]> Auto-Submit: Steve Anton <[email protected]> Reviewed-by: Seth Hampson <[email protected]> Cr-Original-Commit-Position: refs/heads/master@{#627108}(cherry picked from commit f1fbab6) Reviewed-on: https://chromium-review.googlesource.com/c/1446839 Reviewed-by: Steve Anton <[email protected]> Cr-Commit-Position: refs/branch-heads/3683@{#74} Cr-Branched-From: e510299-refs/heads/master@{#625896}
1 parent 10b73a9 commit f05eec2

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

third_party/blink/renderer/modules/peerconnection/adapters/ice_transport_adapter_impl.cc

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ IceTransportAdapterImpl::IceTransportAdapterImpl(
3737
this, &IceTransportAdapterImpl::OnStateChanged);
3838
p2p_transport_channel_->SignalNetworkRouteChanged.connect(
3939
this, &IceTransportAdapterImpl::OnNetworkRouteChanged);
40+
p2p_transport_channel_->SignalRoleConflict.connect(
41+
this, &IceTransportAdapterImpl::OnRoleConflict);
4042
// We need to set the ICE role even before Start is called since the Port
4143
// assumes that the role has been set before receiving incoming connectivity
4244
// checks. These checks can race with the information signaled for Start.
@@ -141,4 +143,37 @@ void IceTransportAdapterImpl::OnNetworkRouteChanged(
141143
selected_connection->remote_candidate()));
142144
}
143145

146+
static const char* IceRoleToString(cricket::IceRole role) {
147+
switch (role) {
148+
case cricket::ICEROLE_CONTROLLING:
149+
return "controlling";
150+
case cricket::ICEROLE_CONTROLLED:
151+
return "controlled";
152+
default:
153+
return "unknown";
154+
}
155+
}
156+
157+
static cricket::IceRole IceRoleReversed(cricket::IceRole role) {
158+
switch (role) {
159+
case cricket::ICEROLE_CONTROLLING:
160+
return cricket::ICEROLE_CONTROLLED;
161+
case cricket::ICEROLE_CONTROLLED:
162+
return cricket::ICEROLE_CONTROLLING;
163+
default:
164+
return cricket::ICEROLE_UNKNOWN;
165+
}
166+
}
167+
168+
void IceTransportAdapterImpl::OnRoleConflict(
169+
cricket::IceTransportInternal* transport) {
170+
DCHECK_EQ(transport, p2p_transport_channel_.get());
171+
// This logic is copied from JsepTransportController.
172+
cricket::IceRole reversed_role =
173+
IceRoleReversed(p2p_transport_channel_->GetIceRole());
174+
LOG(INFO) << "Got role conflict; switching to "
175+
<< IceRoleToString(reversed_role) << " role.";
176+
p2p_transport_channel_->SetIceRole(reversed_role);
177+
}
178+
144179
} // namespace blink

third_party/blink/renderer/modules/peerconnection/adapters/ice_transport_adapter_impl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class IceTransportAdapterImpl final : public IceTransportAdapter,
4747
void OnStateChanged(cricket::IceTransportInternal* transport);
4848
void OnNetworkRouteChanged(
4949
absl::optional<rtc::NetworkRoute> new_network_route);
50+
void OnRoleConflict(cricket::IceTransportInternal* transport);
5051

5152
Delegate* const delegate_;
5253
std::unique_ptr<cricket::PortAllocator> port_allocator_;

third_party/blink/web_tests/external/wpt/webrtc/RTCIceTransport-extension.https.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,26 @@
254254
]);
255255
}, 'Two RTCIceTransports connect to each other');
256256

257+
['controlling', 'controlled'].forEach(role => {
258+
promise_test(async t => {
259+
const [ localTransport, remoteTransport ] =
260+
makeAndGatherTwoIceTransports(t);
261+
localTransport.start(remoteTransport.getLocalParameters(), role);
262+
localTransport.start(remoteTransport.getLocalParameters(), role);
263+
const localWatcher = new EventWatcher(t, localTransport, 'statechange');
264+
const remoteWatcher = new EventWatcher(t, remoteTransport, 'statechange');
265+
await Promise.all([
266+
localWatcher.wait_for('statechange').then(() => {
267+
assert_equals(localTransport.state, 'connected');
268+
}),
269+
remoteWatcher.wait_for('statechange').then(() => {
270+
assert_equals(remoteTransport.state, 'connected');
271+
}),
272+
]);
273+
}, `Two RTCIceTransports configured with the ${role} role resolve the ` +
274+
'conflict in band and still connect.');
275+
});
276+
257277
promise_test(async t => {
258278
async function waitForConnectedThenSelectedCandidatePairChange(t, transport,
259279
transportName) {

0 commit comments

Comments
 (0)