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

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

Issue 2232563002: Do not switch to a high-cost connection that is not receiving (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: . Created 4 years, 4 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 | « no previous file | 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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 // and the last data received time. This prevents the controlled side from 176 // and the last data received time. This prevents the controlled side from
177 // switching the selected connection too frequently when the controlling side 177 // switching the selected connection too frequently when the controlling side
178 // is doing aggressive nominations. The precedence of the connection switching 178 // is doing aggressive nominations. The precedence of the connection switching
179 // criteria is as follows: 179 // criteria is as follows:
180 // i) write/receiving/connected states 180 // i) write/receiving/connected states
181 // ii) For controlled side, 181 // ii) For controlled side,
182 // a) nomination state, 182 // a) nomination state,
183 // b) last data received time. 183 // b) last data received time.
184 // iii) Lower cost / higher priority. 184 // iii) Lower cost / higher priority.
185 // iv) rtt. 185 // iv) rtt.
186 // To further prevent switching to high-cost networks, does not switch to
187 // a high-cost connection if it is not receiving.
186 // TODO(honghaiz): Stop the aggressive nomination on the controlling side and 188 // TODO(honghaiz): Stop the aggressive nomination on the controlling side and
187 // implement the ice-renomination option. 189 // implement the ice-renomination option.
188 bool P2PTransportChannel::ShouldSwitchSelectedConnection( 190 bool P2PTransportChannel::ShouldSwitchSelectedConnection(
189 Connection* new_connection, 191 Connection* new_connection,
190 bool* missed_receiving_unchanged_threshold) const { 192 bool* missed_receiving_unchanged_threshold) const {
191 if (!new_connection || selected_connection_ == new_connection) { 193 if (!new_connection || selected_connection_ == new_connection) {
192 return false; 194 return false;
193 } 195 }
194 196
195 if (selected_connection_ == nullptr) { 197 if (selected_connection_ == nullptr) {
196 return true; 198 return true;
197 } 199 }
198 200
201 // Do not switch to a connection that is not receiving if it has higher cost
202 // because it may be just spuriously better.
203 if (new_connection->ComputeNetworkCost() >
204 selected_connection_->ComputeNetworkCost() &&
205 !new_connection->receiving()) {
206 return false;
207 }
208
199 rtc::Optional<int64_t> receiving_unchanged_threshold( 209 rtc::Optional<int64_t> receiving_unchanged_threshold(
200 rtc::TimeMillis() - config_.receiving_switching_delay.value_or(0)); 210 rtc::TimeMillis() - config_.receiving_switching_delay.value_or(0));
201 int cmp = CompareConnections(selected_connection_, new_connection, 211 int cmp = CompareConnections(selected_connection_, new_connection,
202 receiving_unchanged_threshold, 212 receiving_unchanged_threshold,
203 missed_receiving_unchanged_threshold); 213 missed_receiving_unchanged_threshold);
204 if (cmp != 0) { 214 if (cmp != 0) {
205 return cmp < 0; 215 return cmp < 0;
206 } 216 }
207 217
208 // If everything else is the same, switch only if rtt has improved by 218 // If everything else is the same, switch only if rtt has improved by
(...skipping 1306 matching lines...) Expand 10 before | Expand all | Expand 10 after
1515 } 1525 }
1516 1526
1517 // If the channel is weakly connected, ping all connections. 1527 // If the channel is weakly connected, ping all connections.
1518 if (weak()) { 1528 if (weak()) {
1519 return true; 1529 return true;
1520 } 1530 }
1521 1531
1522 // Always ping active connections regardless whether the channel is completed 1532 // Always ping active connections regardless whether the channel is completed
1523 // or not, but backup connections are pinged at a slower rate. 1533 // or not, but backup connections are pinged at a slower rate.
1524 if (IsBackupConnection(conn)) { 1534 if (IsBackupConnection(conn)) {
1525 return (now >= conn->last_ping_response_received() + 1535 return conn->rtt_samples() == 0 ||
1536 (now >= conn->last_ping_response_received() +
1526 config_.backup_connection_ping_interval); 1537 config_.backup_connection_ping_interval);
1527 } 1538 }
1528 // Don't ping inactive non-backup connections. 1539 // Don't ping inactive non-backup connections.
1529 if (!conn->active()) { 1540 if (!conn->active()) {
1530 return false; 1541 return false;
1531 } 1542 }
1532 1543
1533 // Do ping unwritable, active connections. 1544 // Do ping unwritable, active connections.
1534 if (!conn->writable()) { 1545 if (!conn->writable()) {
1535 return true; 1546 return true;
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
1929 1940
1930 // During the initial state when nothing has been pinged yet, return the first 1941 // During the initial state when nothing has been pinged yet, return the first
1931 // one in the ordered |connections_|. 1942 // one in the ordered |connections_|.
1932 return *(std::find_if(connections_.begin(), connections_.end(), 1943 return *(std::find_if(connections_.begin(), connections_.end(),
1933 [conn1, conn2](Connection* conn) { 1944 [conn1, conn2](Connection* conn) {
1934 return conn == conn1 || conn == conn2; 1945 return conn == conn1 || conn == conn2;
1935 })); 1946 }));
1936 } 1947 }
1937 1948
1938 } // namespace cricket 1949 } // namespace cricket
OLDNEW
« no previous file with comments | « no previous file | webrtc/p2p/base/p2ptransportchannel_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698