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

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

Issue 2369963004: Ping the premier connection on each network with higher priority. (Closed)
Patch Set: Add TODO for re-thinking prioritizing connections for ping requests. Created 4 years, 2 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
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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 } // unnamed namespace 59 } // unnamed namespace
60 60
61 namespace cricket { 61 namespace cricket {
62 62
63 // When the socket is unwritable, we will use 10 Kbps (ignoring IP+UDP headers) 63 // When the socket is unwritable, we will use 10 Kbps (ignoring IP+UDP headers)
64 // for pinging. When the socket is writable, we will use only 1 Kbps because 64 // for pinging. When the socket is writable, we will use only 1 Kbps because
65 // we don't want to degrade the quality on a modem. These numbers should work 65 // we don't want to degrade the quality on a modem. These numbers should work
66 // well on a 28.8K modem, which is the slowest connection on which the voice 66 // well on a 28.8K modem, which is the slowest connection on which the voice
67 // quality is reasonable at all. 67 // quality is reasonable at all.
68 static const int PING_PACKET_SIZE = 60 * 8; 68 static const int PING_PACKET_SIZE = 60 * 8;
69
70 // The next two ping intervals are at the channel level.
69 // STRONG_PING_INTERVAL (480ms) is applied when the selected connection is both 71 // STRONG_PING_INTERVAL (480ms) is applied when the selected connection is both
70 // writable and receiving. 72 // writable and receiving.
71 static const int STRONG_PING_INTERVAL = 1000 * PING_PACKET_SIZE / 1000; 73 static const int STRONG_PING_INTERVAL = 1000 * PING_PACKET_SIZE / 1000;
72 // WEAK_PING_INTERVAL (48ms) is applied when the selected connection is either 74 // WEAK_PING_INTERVAL (48ms) is applied when the selected connection is either
73 // not writable or not receiving. 75 // not writable or not receiving.
74 const int WEAK_PING_INTERVAL = 1000 * PING_PACKET_SIZE / 10000; 76 const int WEAK_PING_INTERVAL = 1000 * PING_PACKET_SIZE / 10000;
75 77
76 // Writable connections are pinged at a faster rate while stabilizing. 78 // The next two ping intervals are at the connection level.
77 const int STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL = 900; // ms 79 // Writable connections are pinged at a faster rate while the connections are
78 80 // stabilizing or the channel is weak.
79 // Writable connections are pinged at a slower rate once stabilized. 81 const int WEAK_OR_STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL = 900; // ms
80 const int STABLE_WRITABLE_CONNECTION_PING_INTERVAL = 2500; // ms 82 // Writable connections are pinged at a slower rate once they are stabilized and
83 // the channel is strongly connected.
84 const int STRONG_AND_STABLE_WRITABLE_CONNECTION_PING_INTERVAL = 2500; // ms
81 85
82 static const int MIN_CHECK_RECEIVING_INTERVAL = 50; // ms 86 static const int MIN_CHECK_RECEIVING_INTERVAL = 50; // ms
83 87
84 static const int RECEIVING_SWITCHING_DELAY = 1000; // ms 88 static const int RECEIVING_SWITCHING_DELAY = 1000; // ms
85 89
86 // We periodically check if any existing networks do not have any connection 90 // We periodically check if any existing networks do not have any connection
87 // and regather on those networks. 91 // and regather on those networks.
88 static const int DEFAULT_REGATHER_ON_FAILED_NETWORKS_INTERVAL = 5 * 60 * 1000; 92 static const int DEFAULT_REGATHER_ON_FAILED_NETWORKS_INTERVAL = 5 * 60 * 1000;
89 93
90 static constexpr int DEFAULT_BACKUP_CONNECTION_PING_INTERVAL = 25 * 1000; 94 static constexpr int DEFAULT_BACKUP_CONNECTION_PING_INTERVAL = 25 * 1000;
(...skipping 18 matching lines...) Expand all
109 sort_dirty_(false), 113 sort_dirty_(false),
110 remote_ice_mode_(ICEMODE_FULL), 114 remote_ice_mode_(ICEMODE_FULL),
111 ice_role_(ICEROLE_UNKNOWN), 115 ice_role_(ICEROLE_UNKNOWN),
112 tiebreaker_(0), 116 tiebreaker_(0),
113 gathering_state_(kIceGatheringNew), 117 gathering_state_(kIceGatheringNew),
114 check_receiving_interval_(MIN_CHECK_RECEIVING_INTERVAL * 5), 118 check_receiving_interval_(MIN_CHECK_RECEIVING_INTERVAL * 5),
115 config_(MIN_CHECK_RECEIVING_INTERVAL * 50 /* receiving_timeout */, 119 config_(MIN_CHECK_RECEIVING_INTERVAL * 50 /* receiving_timeout */,
116 DEFAULT_BACKUP_CONNECTION_PING_INTERVAL, 120 DEFAULT_BACKUP_CONNECTION_PING_INTERVAL,
117 GATHER_ONCE /* continual_gathering_policy */, 121 GATHER_ONCE /* continual_gathering_policy */,
118 false /* prioritize_most_likely_candidate_pairs */, 122 false /* prioritize_most_likely_candidate_pairs */,
119 STABLE_WRITABLE_CONNECTION_PING_INTERVAL, 123 STRONG_AND_STABLE_WRITABLE_CONNECTION_PING_INTERVAL,
120 true /* presume_writable_when_fully_relayed */, 124 true /* presume_writable_when_fully_relayed */,
121 DEFAULT_REGATHER_ON_FAILED_NETWORKS_INTERVAL, 125 DEFAULT_REGATHER_ON_FAILED_NETWORKS_INTERVAL,
122 RECEIVING_SWITCHING_DELAY) { 126 RECEIVING_SWITCHING_DELAY) {
123 uint32_t weak_ping_interval = ::strtoul( 127 uint32_t weak_ping_interval = ::strtoul(
124 webrtc::field_trial::FindFullName("WebRTC-StunInterPacketDelay").c_str(), 128 webrtc::field_trial::FindFullName("WebRTC-StunInterPacketDelay").c_str(),
125 nullptr, 10); 129 nullptr, 10);
126 if (weak_ping_interval) { 130 if (weak_ping_interval) {
127 weak_ping_interval_ = static_cast<int>(weak_ping_interval); 131 weak_ping_interval_ = static_cast<int>(weak_ping_interval);
128 } 132 }
129 } 133 }
(...skipping 1168 matching lines...) Expand 10 before | Expand all | Expand 10 after
1298 UpdateState(); 1302 UpdateState();
1299 1303
1300 // Also possibly start pinging. 1304 // Also possibly start pinging.
1301 // We could start pinging if: 1305 // We could start pinging if:
1302 // * The first connection was created. 1306 // * The first connection was created.
1303 // * ICE credentials were provided. 1307 // * ICE credentials were provided.
1304 // * A TCP connection became connected. 1308 // * A TCP connection became connected.
1305 MaybeStartPinging(); 1309 MaybeStartPinging();
1306 } 1310 }
1307 1311
1312 std::map<rtc::Network*, Connection*>
pthatcher1 2016/10/24 20:49:05 You don't need to return a map. You could instead
honghaiz3 2016/10/24 23:35:08 I wonder what was the concern about using a map. A
pthatcher1 2016/10/25 17:00:06 I thought it might be more readable. But what you
1313 P2PTransportChannel::GetPremierConnectionsByNetwork() const {
pthatcher1 2016/10/24 20:49:05 I'm not really a fan of the word "premier", since
honghaiz3 2016/10/24 23:35:08 Done. Changed Premier to best.
1314 // |connections_| has been sorted, so the first one in the list on a given
1315 // network is the premier connection, except that the selected connection
1316 // is always the premier connection on the network.
1317 std::map<rtc::Network*, Connection*> premier_connections_by_network;
1318 if (selected_connection_) {
1319 premier_connections_by_network[selected_connection_->port()->Network()] =
1320 selected_connection_;
1321 }
1322 for (Connection* conn : connections_) {
1323 rtc::Network* network = conn->port()->Network();
1324 // This only inserts when the network does not exist in the map.
1325 premier_connections_by_network.insert(std::make_pair(network, conn));
pthatcher1 2016/10/24 20:49:05 Instead of inserting in the map, you could just it
1326 }
1327 return premier_connections_by_network;
1328 }
1329
1308 void P2PTransportChannel::PruneConnections() { 1330 void P2PTransportChannel::PruneConnections() {
1309 // We can prune any connection for which there is a connected, writable 1331 // We can prune any connection for which there is a connected, writable
1310 // connection on the same network with better or equal priority. We leave 1332 // connection on the same network with better or equal priority. We leave
1311 // those with better priority just in case they become writable later (at 1333 // those with better priority just in case they become writable later (at
1312 // which point, we would prune out the current selected connection). We leave 1334 // which point, we would prune out the current selected connection). We leave
1313 // connections on other networks because they may not be using the same 1335 // connections on other networks because they may not be using the same
1314 // resources and they may represent very distinct paths over which we can 1336 // resources and they may represent very distinct paths over which we can
1315 // switch. If the |premier| connection is not connected, we may be 1337 // switch. If the |premier| connection is not connected, we may be
1316 // reconnecting a TCP connection and temporarily do not prune connections in 1338 // reconnecting a TCP connection and temporarily do not prune connections in
1317 // this network. See the big comment in CompareConnectionStates. 1339 // this network. See the big comment in CompareConnectionStates.
1318 1340 auto premier_connections_by_network = GetPremierConnectionsByNetwork();
1319 // Get a list of the networks that we are using. 1341 for (Connection* conn : connections_) {
1320 std::set<rtc::Network*> networks; 1342 // Do not prune connections if the current premier connection is weak on
1321 for (const Connection* conn : connections_) {
1322 networks.insert(conn->port()->Network());
1323 }
1324 for (rtc::Network* network : networks) {
1325 Connection* premier = GetBestConnectionOnNetwork(network);
1326 // Do not prune connections if the current selected connection is weak on
1327 // this network. Otherwise, it may delete connections prematurely. 1343 // this network. Otherwise, it may delete connections prematurely.
1328 if (!premier || premier->weak()) { 1344 Connection* premier =
1329 continue; 1345 premier_connections_by_network[conn->port()->Network()];
pthatcher1 2016/10/24 20:49:05 If GetBestConnectionForEachNetwork returns a vecto
honghaiz3 2016/10/24 23:35:09 Actually that is not enough. We will need to find
pthatcher1 2016/10/25 17:00:06 OK, I see the logic now.
1330 } 1346 if (premier && conn != premier && !premier->weak() &&
1331 1347 CompareConnectionCandidates(premier, conn) >= 0) {
1332 for (Connection* conn : connections_) { 1348 conn->Prune();
1333 if ((conn != premier) && (conn->port()->Network() == network) &&
1334 (CompareConnectionCandidates(premier, conn) >= 0)) {
1335 conn->Prune();
1336 }
1337 } 1349 }
1338 } 1350 }
1339 } 1351 }
1340 1352
1341 // Change the selected connection, and let listeners know. 1353 // Change the selected connection, and let listeners know.
1342 void P2PTransportChannel::SwitchSelectedConnection(Connection* conn) { 1354 void P2PTransportChannel::SwitchSelectedConnection(Connection* conn) {
1343 // Note: if conn is NULL, the previous |selected_connection_| has been 1355 // Note: if conn is NULL, the previous |selected_connection_| has been
1344 // destroyed, so don't use it. 1356 // destroyed, so don't use it.
1345 Connection* old_selected_connection = selected_connection_; 1357 Connection* old_selected_connection = selected_connection_;
1346 selected_connection_ = conn; 1358 selected_connection_ = conn;
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1464 bool P2PTransportChannel::ReadyToSend(Connection* connection) const { 1476 bool P2PTransportChannel::ReadyToSend(Connection* connection) const {
1465 // Note that we allow sending on an unreliable connection, because it's 1477 // Note that we allow sending on an unreliable connection, because it's
1466 // possible that it became unreliable simply due to bad chance. 1478 // possible that it became unreliable simply due to bad chance.
1467 // So this shouldn't prevent attempting to send media. 1479 // So this shouldn't prevent attempting to send media.
1468 return connection != nullptr && 1480 return connection != nullptr &&
1469 (connection->writable() || 1481 (connection->writable() ||
1470 connection->write_state() == Connection::STATE_WRITE_UNRELIABLE || 1482 connection->write_state() == Connection::STATE_WRITE_UNRELIABLE ||
1471 PresumedWritable(connection)); 1483 PresumedWritable(connection));
1472 } 1484 }
1473 1485
1474 // If we have a selected connection, return it, otherwise return top one in the
1475 // list (later we will mark it best).
1476 Connection* P2PTransportChannel::GetBestConnectionOnNetwork(
1477 rtc::Network* network) const {
1478 // If the selected connection is on this network, then it wins.
1479 if (selected_connection_ &&
1480 (selected_connection_->port()->Network() == network)) {
1481 return selected_connection_;
1482 }
1483
1484 // Otherwise, we return the top-most in sorted order.
1485 for (size_t i = 0; i < connections_.size(); ++i) {
1486 if (connections_[i]->port()->Network() == network) {
1487 return connections_[i];
1488 }
1489 }
1490
1491 return NULL;
1492 }
1493
1494 // Handle any queued up requests 1486 // Handle any queued up requests
1495 void P2PTransportChannel::OnMessage(rtc::Message *pmsg) { 1487 void P2PTransportChannel::OnMessage(rtc::Message *pmsg) {
1496 switch (pmsg->message_id) { 1488 switch (pmsg->message_id) {
1497 case MSG_SORT_AND_UPDATE_STATE: 1489 case MSG_SORT_AND_UPDATE_STATE:
1498 SortConnectionsAndUpdateState(); 1490 SortConnectionsAndUpdateState();
1499 break; 1491 break;
1500 case MSG_CHECK_AND_PING: 1492 case MSG_CHECK_AND_PING:
1501 OnCheckAndPing(); 1493 OnCheckAndPing();
1502 break; 1494 break;
1503 case MSG_REGATHER_ON_FAILED_NETWORKS: 1495 case MSG_REGATHER_ON_FAILED_NETWORKS:
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1589 if (!conn->writable()) { 1581 if (!conn->writable()) {
1590 return true; 1582 return true;
1591 } 1583 }
1592 1584
1593 // Ping writable, active connections if it's been long enough since the last 1585 // Ping writable, active connections if it's been long enough since the last
1594 // ping. 1586 // ping.
1595 int ping_interval = CalculateActiveWritablePingInterval(conn, now); 1587 int ping_interval = CalculateActiveWritablePingInterval(conn, now);
1596 return (now >= conn->last_ping_sent() + ping_interval); 1588 return (now >= conn->last_ping_sent() + ping_interval);
1597 } 1589 }
1598 1590
1599 bool P2PTransportChannel::IsSelectedConnectionPingable(int64_t now) { 1591 // TODO(honghaiz): Re-thinking the way of prioritizing connections for ping
1600 if (!selected_connection_ || !selected_connection_->connected() || 1592 // requests.
1601 !selected_connection_->writable()) { 1593 Connection* P2PTransportChannel::FindBestPremierConnectionToPing(int64_t now) {
pthatcher1 2016/10/24 20:49:05 Why not just put all of this logic into FindNextPi
honghaiz3 2016/10/24 23:35:09 Done.
1594 // If the selected connection is pingable, select it to ping.
1595 if (IsPremierConnectionPingable(selected_connection_, now)) {
1596 return selected_connection_;
1597 }
1598 // If the selected connection is strongly connected, don't bother to ping
pthatcher1 2016/10/24 20:49:05 bother to ping => bother pinging
honghaiz3 2016/10/24 23:35:08 Done.
1599 // premier connections on other networks at a higher priority. This prevents
1600 // a few premier connections from saturating all transmission slots for ping
1601 // and also prevents the backup connections from being pinged frequently.
1602 if (!weak()) {
1603 return nullptr;
1604 }
1605
1606 // Otherwise, find the premier connection that has not been pinged for the
1607 // longest time.
1608 auto premier_connections_by_network = GetPremierConnectionsByNetwork();
1609 Connection* oldest_pingable_premier_connection = nullptr;
1610 for (auto kv : premier_connections_by_network) {
pthatcher1 2016/10/24 20:49:05 If GetBestConnectionForEachNetwork returned a vect
1611 Connection* conn = kv.second;
1612 if (conn == nullptr || conn == selected_connection_) {
1613 continue;
1614 }
1615 if (IsPremierConnectionPingable(conn, now) &&
1616 (!oldest_pingable_premier_connection ||
1617 conn->last_ping_sent() <
1618 oldest_pingable_premier_connection->last_ping_sent())) {
1619 oldest_pingable_premier_connection = conn;
1620 }
1621 }
1622 return oldest_pingable_premier_connection;
1623 }
1624
1625 bool P2PTransportChannel::IsPremierConnectionPingable(
pthatcher1 2016/10/24 20:49:05 Can't this just be IsConnectionPingable?
honghaiz3 2016/10/24 23:35:09 No. In this method, it is critical to ping connect
pthatcher1 2016/10/25 17:00:06 What I mean is that since you're already passing i
Taylor Brandstetter 2016/10/25 18:29:28 Except there's a completely different method, "IsP
honghaiz3 2016/10/25 22:01:24 IsPremierConnectionPingable (now it is called IsPe
pthatcher1 2016/10/26 22:37:50 I agree with Taylor that this is confusing. IsPin
honghaiz3 2016/10/27 19:20:58 FindNextPingableConnection has the following steps
Taylor Brandstetter 2016/10/27 21:04:54 I had an idea similar to the "ping score" concept.
honghaiz3 2016/10/27 21:45:09 Note a few details: 1. The eligibility of a connec
1626 Connection* premier_connection,
1627 int64_t now) {
1628 if (!premier_connection || !premier_connection->connected() ||
1629 !premier_connection->writable()) {
1602 return false; 1630 return false;
1603 } 1631 }
1604 1632
1605 int interval = CalculateActiveWritablePingInterval(selected_connection_, now); 1633 int interval = CalculateActiveWritablePingInterval(premier_connection, now);
1606 return selected_connection_->last_ping_sent() + interval <= now; 1634 return premier_connection->last_ping_sent() + interval <= now;
1607 } 1635 }
1608 1636
1609 int P2PTransportChannel::CalculateActiveWritablePingInterval( 1637 int P2PTransportChannel::CalculateActiveWritablePingInterval(
1610 const Connection* conn, 1638 const Connection* conn,
1611 int64_t now) const { 1639 int64_t now) const {
1612 // Ping each connection at a higher rate at least 1640 // Ping each connection at a higher rate at least
1613 // MIN_PINGS_AT_WEAK_PING_INTERVAL times. 1641 // MIN_PINGS_AT_WEAK_PING_INTERVAL times.
1614 if (conn->num_pings_sent() < MIN_PINGS_AT_WEAK_PING_INTERVAL) { 1642 if (conn->num_pings_sent() < MIN_PINGS_AT_WEAK_PING_INTERVAL) {
1615 return weak_ping_interval_; 1643 return weak_ping_interval_;
1616 } 1644 }
1617 1645
1618 int stable_interval = config_.stable_writable_connection_ping_interval; 1646 int stable_interval = config_.stable_writable_connection_ping_interval;
1619 int stablizing_interval = 1647 int weak_or_stablizing_interval = std::min(
1620 std::min(stable_interval, STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL); 1648 stable_interval, WEAK_OR_STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL);
1621 1649 // If the channel is weak or the connection is not stable yet, use the
1622 return conn->stable(now) ? stable_interval : stablizing_interval; 1650 // weak_or_stablizing_interval.
1651 return (!weak() && conn->stable(now)) ? stable_interval
1652 : weak_or_stablizing_interval;
1623 } 1653 }
1624 1654
1625 // Returns the next pingable connection to ping. This will be the oldest 1655 // Returns the next pingable connection to ping. This will be the oldest
1626 // pingable connection unless we have a connected, writable connection that is 1656 // pingable connection unless we have a connected, writable connection that is
1627 // past the writable ping interval. When reconnecting a TCP 1657 // past the writable ping interval. When reconnecting a TCP
1628 // connection, the selected connection is disconnected, although still WRITABLE 1658 // connection, the selected connection is disconnected, although still WRITABLE
1629 // while reconnecting. The newly created connection should be selected as the 1659 // while reconnecting. The newly created connection should be selected as the
1630 // ping target to become writable instead. See the big comment in 1660 // ping target to become writable instead. See the big comment in
1631 // CompareConnectionStates. 1661 // CompareConnectionStates.
1632 Connection* P2PTransportChannel::FindNextPingableConnection() { 1662 Connection* P2PTransportChannel::FindNextPingableConnection() {
1633 int64_t now = rtc::TimeMillis(); 1663 int64_t now = rtc::TimeMillis();
1634 Connection* conn_to_ping = nullptr; 1664 Connection* conn_to_ping = FindBestPremierConnectionToPing(now);
1635 if (IsSelectedConnectionPingable(now)) { 1665 if (!conn_to_ping) {
1636 conn_to_ping = selected_connection_;
1637 } else {
1638 conn_to_ping = FindConnectionToPing(now); 1666 conn_to_ping = FindConnectionToPing(now);
1639 } 1667 }
1640 return conn_to_ping; 1668 return conn_to_ping;
1641 } 1669 }
1642 1670
1643 void P2PTransportChannel::MarkConnectionPinged(Connection* conn) { 1671 void P2PTransportChannel::MarkConnectionPinged(Connection* conn) {
1644 if (conn && pinged_connections_.insert(conn).second) { 1672 if (conn && pinged_connections_.insert(conn).second) {
1645 unpinged_connections_.erase(conn); 1673 unpinged_connections_.erase(conn);
1646 } 1674 }
1647 } 1675 }
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1742 // use it. 1770 // use it.
1743 1771
1744 // Remove this connection from the list. 1772 // Remove this connection from the list.
1745 std::vector<Connection*>::iterator iter = 1773 std::vector<Connection*>::iterator iter =
1746 std::find(connections_.begin(), connections_.end(), connection); 1774 std::find(connections_.begin(), connections_.end(), connection);
1747 ASSERT(iter != connections_.end()); 1775 ASSERT(iter != connections_.end());
1748 pinged_connections_.erase(*iter); 1776 pinged_connections_.erase(*iter);
1749 unpinged_connections_.erase(*iter); 1777 unpinged_connections_.erase(*iter);
1750 connections_.erase(iter); 1778 connections_.erase(iter);
1751 1779
1752 LOG_J(LS_INFO, this) << "Removed connection (" 1780 LOG_J(LS_INFO, this) << "Removed connection " << std::hex << connection
1753 << static_cast<int>(connections_.size()) << " remaining)"; 1781 << std::dec << " (" << connections_.size()
1782 << " remaining)";
1754 1783
1755 // If this is currently the selected connection, then we need to pick a new 1784 // If this is currently the selected connection, then we need to pick a new
1756 // one. The call to SortConnectionsAndUpdateState will pick a new one. It 1785 // one. The call to SortConnectionsAndUpdateState will pick a new one. It
1757 // looks at the current selected connection in order to avoid switching 1786 // looks at the current selected connection in order to avoid switching
1758 // between fairly similar ones. Since this connection is no longer an option, 1787 // between fairly similar ones. Since this connection is no longer an option,
1759 // we can just set selected to nullptr and re-choose a best assuming that 1788 // we can just set selected to nullptr and re-choose a best assuming that
1760 // there was no selected connection. 1789 // there was no selected connection.
1761 if (selected_connection_ == connection) { 1790 if (selected_connection_ == connection) {
1762 LOG(LS_INFO) << "Selected connection destroyed. Will choose a new one."; 1791 LOG(LS_INFO) << "Selected connection destroyed. Will choose a new one.";
1763 SwitchSelectedConnection(nullptr); 1792 SwitchSelectedConnection(nullptr);
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1871 } 1900 }
1872 1901
1873 void P2PTransportChannel::OnReadyToSend(Connection* connection) { 1902 void P2PTransportChannel::OnReadyToSend(Connection* connection) {
1874 if (connection == selected_connection_ && writable()) { 1903 if (connection == selected_connection_ && writable()) {
1875 SignalReadyToSend(this); 1904 SignalReadyToSend(this);
1876 } 1905 }
1877 } 1906 }
1878 1907
1879 // Find "triggered checks". We ping first those connections that have 1908 // Find "triggered checks". We ping first those connections that have
1880 // received a ping but have not sent a ping since receiving it 1909 // received a ping but have not sent a ping since receiving it
1881 // (last_received_ping > last_sent_ping). But we shouldn't do 1910 // (last_ping_received > last_ping_sent). But we shouldn't do
1882 // triggered checks if the connection is already writable. 1911 // triggered checks if the connection is already writable.
1883 Connection* P2PTransportChannel::FindOldestConnectionNeedingTriggeredCheck( 1912 Connection* P2PTransportChannel::FindOldestConnectionNeedingTriggeredCheck(
1884 int64_t now) { 1913 int64_t now) {
1885 Connection* oldest_needing_triggered_check = nullptr; 1914 Connection* oldest_needing_triggered_check = nullptr;
1886 for (auto conn : connections_) { 1915 for (auto conn : connections_) {
1887 if (!IsPingable(conn, now)) { 1916 if (!IsPingable(conn, now)) {
1888 continue; 1917 continue;
1889 } 1918 }
1890 bool needs_triggered_check = 1919 bool needs_triggered_check =
1891 (!conn->writable() && 1920 (!conn->writable() &&
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1987 2016
1988 // During the initial state when nothing has been pinged yet, return the first 2017 // During the initial state when nothing has been pinged yet, return the first
1989 // one in the ordered |connections_|. 2018 // one in the ordered |connections_|.
1990 return *(std::find_if(connections_.begin(), connections_.end(), 2019 return *(std::find_if(connections_.begin(), connections_.end(),
1991 [conn1, conn2](Connection* conn) { 2020 [conn1, conn2](Connection* conn) {
1992 return conn == conn1 || conn == conn2; 2021 return conn == conn1 || conn == conn2;
1993 })); 2022 }));
1994 } 2023 }
1995 2024
1996 } // namespace cricket 2025 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698