OLD | NEW |
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 1335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1346 void P2PTransportChannel::PruneConnections() { | 1346 void P2PTransportChannel::PruneConnections() { |
1347 // We can prune any connection for which there is a connected, writable | 1347 // We can prune any connection for which there is a connected, writable |
1348 // connection on the same network with better or equal priority. We leave | 1348 // connection on the same network with better or equal priority. We leave |
1349 // those with better priority just in case they become writable later (at | 1349 // those with better priority just in case they become writable later (at |
1350 // which point, we would prune out the current selected connection). We leave | 1350 // which point, we would prune out the current selected connection). We leave |
1351 // connections on other networks because they may not be using the same | 1351 // connections on other networks because they may not be using the same |
1352 // resources and they may represent very distinct paths over which we can | 1352 // resources and they may represent very distinct paths over which we can |
1353 // switch. If |best_conn_on_network| is not connected, we may be reconnecting | 1353 // switch. If |best_conn_on_network| is not connected, we may be reconnecting |
1354 // a TCP connection and should not prune connections in this network. | 1354 // a TCP connection and should not prune connections in this network. |
1355 // See the big comment in CompareConnectionStates. | 1355 // See the big comment in CompareConnectionStates. |
| 1356 // |
| 1357 // An exception is made for connections on an "any address" network, meaning |
| 1358 // not bound to any specific network interface. We don't want to keep one of |
| 1359 // these alive as a backup, since it could be using the same network |
| 1360 // interface as the higher-priority, selected candidate pair. |
1356 auto best_connection_by_network = GetBestConnectionByNetwork(); | 1361 auto best_connection_by_network = GetBestConnectionByNetwork(); |
1357 for (Connection* conn : connections_) { | 1362 for (Connection* conn : connections_) { |
1358 // Do not prune connections if the current best connection on this network | 1363 // Compare aainst the best connection across all networks for a connection |
1359 // is weak. Otherwise, it may delete connections prematurely. | 1364 // on an "any address" network, and otherwise compare only against the |
1360 Connection* best_conn_on_network = | 1365 // per-network best connection, to ensure one connection per network stays |
1361 best_connection_by_network[conn->port()->Network()]; | 1366 // active. |
1362 if (best_conn_on_network && conn != best_conn_on_network && | 1367 Connection* to_compare; |
1363 !best_conn_on_network->weak() && | 1368 if (rtc::IPIsAny(conn->port()->Network()->ip())) { |
1364 CompareConnectionCandidates(best_conn_on_network, conn) >= 0) { | 1369 to_compare = selected_connection_; |
| 1370 } else { |
| 1371 to_compare = best_connection_by_network[conn->port()->Network()]; |
| 1372 } |
| 1373 // Do not prune connections if the connection being compared against is |
| 1374 // weak. Otherwise, it may delete connections prematurely. |
| 1375 if (to_compare && conn != to_compare && !to_compare->weak() && |
| 1376 CompareConnectionCandidates(to_compare, conn) >= 0) { |
1365 conn->Prune(); | 1377 conn->Prune(); |
1366 } | 1378 } |
1367 } | 1379 } |
1368 } | 1380 } |
1369 | 1381 |
1370 // Change the selected connection, and let listeners know. | 1382 // Change the selected connection, and let listeners know. |
1371 void P2PTransportChannel::SwitchSelectedConnection(Connection* conn) { | 1383 void P2PTransportChannel::SwitchSelectedConnection(Connection* conn) { |
1372 // Note: if conn is NULL, the previous |selected_connection_| has been | 1384 // Note: if conn is NULL, the previous |selected_connection_| has been |
1373 // destroyed, so don't use it. | 1385 // destroyed, so don't use it. |
1374 Connection* old_selected_connection = selected_connection_; | 1386 Connection* old_selected_connection = selected_connection_; |
(...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2049 | 2061 |
2050 void P2PTransportChannel::set_receiving(bool receiving) { | 2062 void P2PTransportChannel::set_receiving(bool receiving) { |
2051 if (receiving_ == receiving) { | 2063 if (receiving_ == receiving) { |
2052 return; | 2064 return; |
2053 } | 2065 } |
2054 receiving_ = receiving; | 2066 receiving_ = receiving; |
2055 SignalReceivingState(this); | 2067 SignalReceivingState(this); |
2056 } | 2068 } |
2057 | 2069 |
2058 } // namespace cricket | 2070 } // namespace cricket |
OLD | NEW |