Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: webrtc/p2p/base/p2ptransportchannel.cc

Issue 2163403002: Prepare for ICE-renomination (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: . Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/p2p/base/p2ptransportchannel.h ('k') | webrtc/p2p/base/p2ptransportchannel_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 1123 matching lines...) Expand 10 before | Expand all | Expand 10 after
1134 // been nominated by the controlling side. 1134 // been nominated by the controlling side.
1135 int state_cmp = CompareConnectionStates(a, b, receiving_unchanged_threshold, 1135 int state_cmp = CompareConnectionStates(a, b, receiving_unchanged_threshold,
1136 missed_receiving_unchanged_threshold); 1136 missed_receiving_unchanged_threshold);
1137 if (state_cmp != 0) { 1137 if (state_cmp != 0) {
1138 return state_cmp; 1138 return state_cmp;
1139 } 1139 }
1140 1140
1141 if (ice_role_ == ICEROLE_CONTROLLED) { 1141 if (ice_role_ == ICEROLE_CONTROLLED) {
1142 // Compare the connections based on the nomination states and the last data 1142 // Compare the connections based on the nomination states and the last data
1143 // received time if this is on the controlled side. 1143 // received time if this is on the controlled side.
1144 if (a->nominated() && !b->nominated()) { 1144 int cmp = a->nominated_value() - b->nominated_value();
1145 return a_is_better; 1145 if (cmp != 0) {
1146 } 1146 // A positive value indicates |a| is better.
1147 if (!a->nominated() && b->nominated()) { 1147 return cmp;
1148 return b_is_better;
1149 } 1148 }
1150 1149
1151 if (a->last_data_received() > b->last_data_received()) { 1150 if (a->last_data_received() > b->last_data_received()) {
1152 return a_is_better; 1151 return a_is_better;
1153 } 1152 }
1154 if (a->last_data_received() < b->last_data_received()) { 1153 if (a->last_data_received() < b->last_data_received()) {
1155 return b_is_better; 1154 return b_is_better;
1156 } 1155 }
1157 } 1156 }
1158 1157
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 (connections_.size() > 0) ? connections_[0] : nullptr; 1204 (connections_.size() > 0) ? connections_[0] : nullptr;
1206 1205
1207 // If necessary, switch to the new choice. Note that |top_connection| doesn't 1206 // If necessary, switch to the new choice. Note that |top_connection| doesn't
1208 // have to be writable to become the selected connection although it will 1207 // have to be writable to become the selected connection although it will
1209 // have higher priority if it is writable. 1208 // have higher priority if it is writable.
1210 MaybeSwitchSelectedConnection(top_connection, "sorting"); 1209 MaybeSwitchSelectedConnection(top_connection, "sorting");
1211 1210
1212 // The controlled side can prune only if the selected connection has been 1211 // The controlled side can prune only if the selected connection has been
1213 // nominated because otherwise it may prune the connection that will be 1212 // nominated because otherwise it may prune the connection that will be
1214 // selected by the controlling side. 1213 // selected by the controlling side.
1215 // TODO(honghaiz): This is not enough to prevent a connection from being
1216 // pruned too early because with aggressive nomination, the controlling side
1217 // will nominate every connection until it becomes writable.
1218 if (ice_role_ == ICEROLE_CONTROLLING || 1214 if (ice_role_ == ICEROLE_CONTROLLING ||
1219 (selected_connection_ && selected_connection_->nominated())) { 1215 (selected_connection_ && selected_connection_->nominated_value() > 0)) {
1220 PruneConnections(); 1216 PruneConnections();
1221 } 1217 }
1222 1218
1223 // Check if all connections are timedout. 1219 // Check if all connections are timedout.
1224 bool all_connections_timedout = true; 1220 bool all_connections_timedout = true;
1225 for (size_t i = 0; i < connections_.size(); ++i) { 1221 for (size_t i = 0; i < connections_.size(); ++i) {
1226 if (connections_[i]->write_state() != Connection::STATE_WRITE_TIMEOUT) { 1222 if (connections_[i]->write_state() != Connection::STATE_WRITE_TIMEOUT) {
1227 all_connections_timedout = false; 1223 all_connections_timedout = false;
1228 break; 1224 break;
1229 } 1225 }
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
1579 return conn_to_ping; 1575 return conn_to_ping;
1580 } 1576 }
1581 1577
1582 void P2PTransportChannel::MarkConnectionPinged(Connection* conn) { 1578 void P2PTransportChannel::MarkConnectionPinged(Connection* conn) {
1583 if (conn && pinged_connections_.insert(conn).second) { 1579 if (conn && pinged_connections_.insert(conn).second) {
1584 unpinged_connections_.erase(conn); 1580 unpinged_connections_.erase(conn);
1585 } 1581 }
1586 } 1582 }
1587 1583
1588 // Apart from sending ping from |conn| this method also updates 1584 // Apart from sending ping from |conn| this method also updates
1589 // |use_candidate_attr| flag. The criteria to update this flag is 1585 // |use_candidate_attr| and |nominating_value| flags. The criteria to update
1590 // explained below. 1586 // the flags is explained below.
1591 // Set USE-CANDIDATE if doing ICE AND this channel is in CONTROLLING AND 1587 // Set the flags to nominate |conn| if this channel is in CONTROLLING AND
1592 // a) Channel is in FULL ICE AND 1588 // 1) |conn| is the selected_connection AND
1593 // a.1) |conn| is the selected connection OR 1589 // 2) |conn| is writable.
1594 // a.2) there is no selected connection OR 1590 // This is very much like passive-aggressive nomination.
1595 // a.3) the selected connection is unwritable OR
1596 // a.4) |conn| has higher priority than selected_connection.
1597 // b) we're doing LITE ICE AND
1598 // b.1) |conn| is the selected_connection AND
1599 // b.2) |conn| is writable.
1600 void P2PTransportChannel::PingConnection(Connection* conn) { 1591 void P2PTransportChannel::PingConnection(Connection* conn) {
1601 bool use_candidate = false; 1592 bool use_candidate_attr = false;
1602 if (remote_ice_mode_ == ICEMODE_FULL && ice_role_ == ICEROLE_CONTROLLING) { 1593 int nominating_value = 0;
1603 use_candidate = 1594 if (ice_role_ == ICEROLE_CONTROLLING) {
1604 (conn == selected_connection_) || (selected_connection_ == NULL) || 1595 bool should_nominate =
1605 (!selected_connection_->writable()) || 1596 (conn == selected_connection_) && selected_connection_->writable();
1606 (CompareConnectionCandidates(selected_connection_, conn) < 0); 1597 if (should_nominate) {
1607 } else if (remote_ice_mode_ == ICEMODE_LITE && conn == selected_connection_) { 1598 if (peer_supports_renomination_) {
1608 use_candidate = selected_connection_->writable(); 1599 if (last_nominating_connection_ != conn) {
1600 ++nominating_value_;
1601 last_nominating_connection_ = conn;
1602 }
1603 nominating_value = nominating_value_;
Taylor Brandstetter 2016/07/22 23:48:29 Instead of using a temporary variable "nominating_
honghaiz3 2016/07/25 22:24:41 That's not the intended behavior. A connection ma
Taylor Brandstetter 2016/07/27 22:20:55 I understand. Previously, "set_nominating_value(0)
1604 } else {
1605 use_candidate_attr = true;
1606 }
1607 }
1609 } 1608 }
1610 conn->set_use_candidate_attr(use_candidate); 1609 conn->set_nominating_value(nominating_value);
1610 conn->set_use_candidate_attr(use_candidate_attr);
1611 last_ping_sent_ms_ = rtc::TimeMillis(); 1611 last_ping_sent_ms_ = rtc::TimeMillis();
1612 conn->Ping(last_ping_sent_ms_); 1612 conn->Ping(last_ping_sent_ms_);
1613 } 1613 }
1614 1614
1615 // When a connection's state changes, we need to figure out who to use as 1615 // When a connection's state changes, we need to figure out who to use as
1616 // the selected connection again. It could have become usable, or become 1616 // the selected connection again. It could have become usable, or become
1617 // unusable. 1617 // unusable.
1618 void P2PTransportChannel::OnConnectionStateChange(Connection* connection) { 1618 void P2PTransportChannel::OnConnectionStateChange(Connection* connection) {
1619 ASSERT(worker_thread_ == rtc::Thread::Current()); 1619 ASSERT(worker_thread_ == rtc::Thread::Current());
1620 1620
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
1893 1893
1894 // During the initial state when nothing has been pinged yet, return the first 1894 // During the initial state when nothing has been pinged yet, return the first
1895 // one in the ordered |connections_|. 1895 // one in the ordered |connections_|.
1896 return *(std::find_if(connections_.begin(), connections_.end(), 1896 return *(std::find_if(connections_.begin(), connections_.end(),
1897 [conn1, conn2](Connection* conn) { 1897 [conn1, conn2](Connection* conn) {
1898 return conn == conn1 || conn == conn2; 1898 return conn == conn1 || conn == conn2;
1899 })); 1899 }));
1900 } 1900 }
1901 1901
1902 } // namespace cricket 1902 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/p2p/base/p2ptransportchannel.h ('k') | webrtc/p2p/base/p2ptransportchannel_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698