Skip to content

Commit

Permalink
Handle role conflict in the standalone RTCIceTransport
Browse files Browse the repository at this point in the history
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}
  • Loading branch information
steveanton committed Jan 30, 2019
1 parent 10b73a9 commit f05eec2
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ IceTransportAdapterImpl::IceTransportAdapterImpl(
this, &IceTransportAdapterImpl::OnStateChanged);
p2p_transport_channel_->SignalNetworkRouteChanged.connect(
this, &IceTransportAdapterImpl::OnNetworkRouteChanged);
p2p_transport_channel_->SignalRoleConflict.connect(
this, &IceTransportAdapterImpl::OnRoleConflict);
// We need to set the ICE role even before Start is called since the Port
// assumes that the role has been set before receiving incoming connectivity
// checks. These checks can race with the information signaled for Start.
Expand Down Expand Up @@ -141,4 +143,37 @@ void IceTransportAdapterImpl::OnNetworkRouteChanged(
selected_connection->remote_candidate()));
}

static const char* IceRoleToString(cricket::IceRole role) {
switch (role) {
case cricket::ICEROLE_CONTROLLING:
return "controlling";
case cricket::ICEROLE_CONTROLLED:
return "controlled";
default:
return "unknown";
}
}

static cricket::IceRole IceRoleReversed(cricket::IceRole role) {
switch (role) {
case cricket::ICEROLE_CONTROLLING:
return cricket::ICEROLE_CONTROLLED;
case cricket::ICEROLE_CONTROLLED:
return cricket::ICEROLE_CONTROLLING;
default:
return cricket::ICEROLE_UNKNOWN;
}
}

void IceTransportAdapterImpl::OnRoleConflict(
cricket::IceTransportInternal* transport) {
DCHECK_EQ(transport, p2p_transport_channel_.get());
// This logic is copied from JsepTransportController.
cricket::IceRole reversed_role =
IceRoleReversed(p2p_transport_channel_->GetIceRole());
LOG(INFO) << "Got role conflict; switching to "
<< IceRoleToString(reversed_role) << " role.";
p2p_transport_channel_->SetIceRole(reversed_role);
}

} // namespace blink
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class IceTransportAdapterImpl final : public IceTransportAdapter,
void OnStateChanged(cricket::IceTransportInternal* transport);
void OnNetworkRouteChanged(
absl::optional<rtc::NetworkRoute> new_network_route);
void OnRoleConflict(cricket::IceTransportInternal* transport);

Delegate* const delegate_;
std::unique_ptr<cricket::PortAllocator> port_allocator_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,26 @@
]);
}, 'Two RTCIceTransports connect to each other');

['controlling', 'controlled'].forEach(role => {
promise_test(async t => {
const [ localTransport, remoteTransport ] =
makeAndGatherTwoIceTransports(t);
localTransport.start(remoteTransport.getLocalParameters(), role);
localTransport.start(remoteTransport.getLocalParameters(), role);
const localWatcher = new EventWatcher(t, localTransport, 'statechange');
const remoteWatcher = new EventWatcher(t, remoteTransport, 'statechange');
await Promise.all([
localWatcher.wait_for('statechange').then(() => {
assert_equals(localTransport.state, 'connected');
}),
remoteWatcher.wait_for('statechange').then(() => {
assert_equals(remoteTransport.state, 'connected');
}),
]);
}, `Two RTCIceTransports configured with the ${role} role resolve the ` +
'conflict in band and still connect.');
});

promise_test(async t => {
async function waitForConnectedThenSelectedCandidatePairChange(t, transport,
transportName) {
Expand Down

0 comments on commit f05eec2

Please sign in to comment.