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

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

Issue 2369963004: Ping the premier connection on each network with higher priority. (Closed)
Patch Set: . Created 4 years, 1 month 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*>
1313 P2PTransportChannel::GetBestConnectionsByNetwork() const {
1314 // |connections_| has been sorted, so the first one in the list on a given
1315 // network is the best connection on the network, except that the selected
1316 // connection is always the best connection on the network.
1317 std::map<rtc::Network*, Connection*> best_connections_by_network;
1318 if (selected_connection_) {
1319 best_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 best_connections_by_network.insert(std::make_pair(network, conn));
1326 }
1327 return best_connections_by_network;
pthatcher1 2016/10/25 17:00:06 best_connection_by_network (makes it clear there i
honghaiz3 2016/10/25 18:01:09 Done.
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 |best_conn_on_network| is not connected, we may be reconnecting
1316 // reconnecting a TCP connection and temporarily do not prune connections in 1338 // a TCP connection and should not prune connections in this network.
1317 // this network. See the big comment in CompareConnectionStates. 1339 // See the big comment in CompareConnectionStates.
1318 1340 auto best_connections_by_network = GetBestConnectionsByNetwork();
pthatcher1 2016/10/25 17:00:06 here too
honghaiz3 2016/10/25 18:01:09 Done.
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 best connection on this network
1321 for (const Connection* conn : connections_) { 1343 // is weak. Otherwise, it may delete connections prematurely.
1322 networks.insert(conn->port()->Network()); 1344 Connection* best_conn_on_network =
1323 } 1345 best_connections_by_network[conn->port()->Network()];
1324 for (rtc::Network* network : networks) { 1346 if (best_conn_on_network && conn != best_conn_on_network &&
1325 Connection* premier = GetBestConnectionOnNetwork(network); 1347 !best_conn_on_network->weak() &&
1326 // Do not prune connections if the current selected connection is weak on 1348 CompareConnectionCandidates(best_conn_on_network, conn) >= 0) {
1327 // this network. Otherwise, it may delete connections prematurely. 1349 conn->Prune();
1328 if (!premier || premier->weak()) {
1329 continue;
1330 }
1331
1332 for (Connection* conn : connections_) {
1333 if ((conn != premier) && (conn->port()->Network() == network) &&
1334 (CompareConnectionCandidates(premier, conn) >= 0)) {
1335 conn->Prune();
1336 }
1337 } 1350 }
1338 } 1351 }
1339 } 1352 }
1340 1353
1341 // Change the selected connection, and let listeners know. 1354 // Change the selected connection, and let listeners know.
1342 void P2PTransportChannel::SwitchSelectedConnection(Connection* conn) { 1355 void P2PTransportChannel::SwitchSelectedConnection(Connection* conn) {
1343 // Note: if conn is NULL, the previous |selected_connection_| has been 1356 // Note: if conn is NULL, the previous |selected_connection_| has been
1344 // destroyed, so don't use it. 1357 // destroyed, so don't use it.
1345 Connection* old_selected_connection = selected_connection_; 1358 Connection* old_selected_connection = selected_connection_;
1346 selected_connection_ = conn; 1359 selected_connection_ = conn;
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1464 bool P2PTransportChannel::ReadyToSend(Connection* connection) const { 1477 bool P2PTransportChannel::ReadyToSend(Connection* connection) const {
1465 // Note that we allow sending on an unreliable connection, because it's 1478 // Note that we allow sending on an unreliable connection, because it's
1466 // possible that it became unreliable simply due to bad chance. 1479 // possible that it became unreliable simply due to bad chance.
1467 // So this shouldn't prevent attempting to send media. 1480 // So this shouldn't prevent attempting to send media.
1468 return connection != nullptr && 1481 return connection != nullptr &&
1469 (connection->writable() || 1482 (connection->writable() ||
1470 connection->write_state() == Connection::STATE_WRITE_UNRELIABLE || 1483 connection->write_state() == Connection::STATE_WRITE_UNRELIABLE ||
1471 PresumedWritable(connection)); 1484 PresumedWritable(connection));
1472 } 1485 }
1473 1486
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 1487 // Handle any queued up requests
1495 void P2PTransportChannel::OnMessage(rtc::Message *pmsg) { 1488 void P2PTransportChannel::OnMessage(rtc::Message *pmsg) {
1496 switch (pmsg->message_id) { 1489 switch (pmsg->message_id) {
1497 case MSG_SORT_AND_UPDATE_STATE: 1490 case MSG_SORT_AND_UPDATE_STATE:
1498 SortConnectionsAndUpdateState(); 1491 SortConnectionsAndUpdateState();
1499 break; 1492 break;
1500 case MSG_CHECK_AND_PING: 1493 case MSG_CHECK_AND_PING:
1501 OnCheckAndPing(); 1494 OnCheckAndPing();
1502 break; 1495 break;
1503 case MSG_REGATHER_ON_FAILED_NETWORKS: 1496 case MSG_REGATHER_ON_FAILED_NETWORKS:
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1589 if (!conn->writable()) { 1582 if (!conn->writable()) {
1590 return true; 1583 return true;
1591 } 1584 }
1592 1585
1593 // Ping writable, active connections if it's been long enough since the last 1586 // Ping writable, active connections if it's been long enough since the last
1594 // ping. 1587 // ping.
1595 int ping_interval = CalculateActiveWritablePingInterval(conn, now); 1588 int ping_interval = CalculateActiveWritablePingInterval(conn, now);
1596 return (now >= conn->last_ping_sent() + ping_interval); 1589 return (now >= conn->last_ping_sent() + ping_interval);
1597 } 1590 }
1598 1591
1599 bool P2PTransportChannel::IsSelectedConnectionPingable(int64_t now) { 1592 bool P2PTransportChannel::IsPerNetworkBestConnectionPingable(
1600 if (!selected_connection_ || !selected_connection_->connected() || 1593 Connection* per_network_best_connection,
1601 !selected_connection_->writable()) { 1594 int64_t now) {
1595 if (!per_network_best_connection ||
1596 !per_network_best_connection->connected() ||
1597 !per_network_best_connection->writable()) {
1602 return false; 1598 return false;
1603 } 1599 }
1604 1600
1605 int interval = CalculateActiveWritablePingInterval(selected_connection_, now); 1601 int interval =
1606 return selected_connection_->last_ping_sent() + interval <= now; 1602 CalculateActiveWritablePingInterval(per_network_best_connection, now);
1603 return per_network_best_connection->last_ping_sent() + interval <= now;
pthatcher1 2016/10/25 17:00:06 I think you could just call this variable "connect
honghaiz3 2016/10/25 18:01:09 Done.
1607 } 1604 }
1608 1605
1609 int P2PTransportChannel::CalculateActiveWritablePingInterval( 1606 int P2PTransportChannel::CalculateActiveWritablePingInterval(
1610 const Connection* conn, 1607 const Connection* conn,
1611 int64_t now) const { 1608 int64_t now) const {
1612 // Ping each connection at a higher rate at least 1609 // Ping each connection at a higher rate at least
1613 // MIN_PINGS_AT_WEAK_PING_INTERVAL times. 1610 // MIN_PINGS_AT_WEAK_PING_INTERVAL times.
1614 if (conn->num_pings_sent() < MIN_PINGS_AT_WEAK_PING_INTERVAL) { 1611 if (conn->num_pings_sent() < MIN_PINGS_AT_WEAK_PING_INTERVAL) {
1615 return weak_ping_interval_; 1612 return weak_ping_interval_;
1616 } 1613 }
1617 1614
1618 int stable_interval = config_.stable_writable_connection_ping_interval; 1615 int stable_interval = config_.stable_writable_connection_ping_interval;
1619 int stablizing_interval = 1616 int weak_or_stablizing_interval = std::min(
1620 std::min(stable_interval, STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL); 1617 stable_interval, WEAK_OR_STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL);
1621 1618 // If the channel is weak or the connection is not stable yet, use the
1622 return conn->stable(now) ? stable_interval : stablizing_interval; 1619 // weak_or_stablizing_interval.
1620 return (!weak() && conn->stable(now)) ? stable_interval
1621 : weak_or_stablizing_interval;
1623 } 1622 }
1624 1623
1625 // Returns the next pingable connection to ping. This will be the oldest 1624 // Returns the next pingable connection to ping. This will be the oldest
1626 // pingable connection unless we have a connected, writable connection that is 1625 // pingable connection unless we have a connected, writable connection that is
1627 // past the writable ping interval. When reconnecting a TCP 1626 // past the writable ping interval. When reconnecting a TCP
1628 // connection, the selected connection is disconnected, although still WRITABLE 1627 // connection, the selected connection is disconnected, although still WRITABLE
1629 // while reconnecting. The newly created connection should be selected as the 1628 // while reconnecting. The newly created connection should be selected as the
1630 // ping target to become writable instead. See the big comment in 1629 // ping target to become writable instead. See the big comment in
1631 // CompareConnectionStates. 1630 // CompareConnectionStates.
1631 // TODO(honghaiz): Re-thinking the way of prioritizing connections for ping
1632 // requests.
1632 Connection* P2PTransportChannel::FindNextPingableConnection() { 1633 Connection* P2PTransportChannel::FindNextPingableConnection() {
1633 int64_t now = rtc::TimeMillis(); 1634 int64_t now = rtc::TimeMillis();
1634 Connection* conn_to_ping = nullptr; 1635
1635 if (IsSelectedConnectionPingable(now)) { 1636 // If the selected connection is pingable, select it to ping.
1636 conn_to_ping = selected_connection_; 1637 if (IsPerNetworkBestConnectionPingable(selected_connection_, now)) {
1637 } else { 1638 return selected_connection_;
1638 conn_to_ping = FindConnectionToPing(now);
1639 } 1639 }
1640 return conn_to_ping; 1640
1641 // If the selected connection is strongly connected, don't bother pinging
pthatcher1 2016/10/25 17:00:06 Now that you have this as if (weak()), you should
honghaiz3 2016/10/25 18:01:09 Done.
1642 // best connections on other networks at a higher priority. This prevents
1643 // a few best connections from saturating all transmission slots for ping
1644 // and also prevents the backup connections from being pinged frequently.
1645 // Otherwise, find the per-network best connection that has not been pinged
1646 // for the longest time.
1647 if (weak()) {
1648 auto best_connections_by_network = GetBestConnectionsByNetwork();
1649 Connection* oldest_pingable_best_connection = nullptr;
1650 for (auto kv : best_connections_by_network) {
1651 Connection* conn = kv.second;
1652 if (conn == nullptr || conn == selected_connection_) {
1653 continue;
1654 }
1655 if (IsPerNetworkBestConnectionPingable(conn, now) &&
1656 (!oldest_pingable_best_connection ||
1657 conn->last_ping_sent() <
1658 oldest_pingable_best_connection->last_ping_sent())) {
1659 oldest_pingable_best_connection = conn;
1660 }
pthatcher1 2016/10/25 17:00:06 Can we do something like this? auto oldest_best_c
honghaiz3 2016/10/25 18:01:09 It will need to be something like this: auto oldes
pthatcher1 2016/10/26 22:37:50 You don't need to call IsPerNetworkBestConnectionP
honghaiz3 2016/10/27 19:20:58 We can do that. Will defer this until the other, m
honghaiz3 2016/10/27 21:45:09 copy_if is the c++ filter but unfortunately, c++ m
1661 }
1662 if (oldest_pingable_best_connection) {
1663 return oldest_pingable_best_connection;
1664 }
1665 }
1666
1667 return FindConnectionToPing(now);
1641 } 1668 }
1642 1669
1643 void P2PTransportChannel::MarkConnectionPinged(Connection* conn) { 1670 void P2PTransportChannel::MarkConnectionPinged(Connection* conn) {
1644 if (conn && pinged_connections_.insert(conn).second) { 1671 if (conn && pinged_connections_.insert(conn).second) {
1645 unpinged_connections_.erase(conn); 1672 unpinged_connections_.erase(conn);
1646 } 1673 }
1647 } 1674 }
1648 1675
1649 // Apart from sending ping from |conn| this method also updates 1676 // Apart from sending ping from |conn| this method also updates
1650 // |use_candidate_attr| and |nomination| flags. One of the flags is set to 1677 // |use_candidate_attr| and |nomination| flags. One of the flags is set to
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1742 // use it. 1769 // use it.
1743 1770
1744 // Remove this connection from the list. 1771 // Remove this connection from the list.
1745 std::vector<Connection*>::iterator iter = 1772 std::vector<Connection*>::iterator iter =
1746 std::find(connections_.begin(), connections_.end(), connection); 1773 std::find(connections_.begin(), connections_.end(), connection);
1747 ASSERT(iter != connections_.end()); 1774 ASSERT(iter != connections_.end());
1748 pinged_connections_.erase(*iter); 1775 pinged_connections_.erase(*iter);
1749 unpinged_connections_.erase(*iter); 1776 unpinged_connections_.erase(*iter);
1750 connections_.erase(iter); 1777 connections_.erase(iter);
1751 1778
1752 LOG_J(LS_INFO, this) << "Removed connection (" 1779 LOG_J(LS_INFO, this) << "Removed connection " << std::hex << connection
1753 << static_cast<int>(connections_.size()) << " remaining)"; 1780 << std::dec << " (" << connections_.size()
1781 << " remaining)";
1754 1782
1755 // If this is currently the selected connection, then we need to pick a new 1783 // 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 1784 // one. The call to SortConnectionsAndUpdateState will pick a new one. It
1757 // looks at the current selected connection in order to avoid switching 1785 // looks at the current selected connection in order to avoid switching
1758 // between fairly similar ones. Since this connection is no longer an option, 1786 // 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 1787 // we can just set selected to nullptr and re-choose a best assuming that
1760 // there was no selected connection. 1788 // there was no selected connection.
1761 if (selected_connection_ == connection) { 1789 if (selected_connection_ == connection) {
1762 LOG(LS_INFO) << "Selected connection destroyed. Will choose a new one."; 1790 LOG(LS_INFO) << "Selected connection destroyed. Will choose a new one.";
1763 SwitchSelectedConnection(nullptr); 1791 SwitchSelectedConnection(nullptr);
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1871 } 1899 }
1872 1900
1873 void P2PTransportChannel::OnReadyToSend(Connection* connection) { 1901 void P2PTransportChannel::OnReadyToSend(Connection* connection) {
1874 if (connection == selected_connection_ && writable()) { 1902 if (connection == selected_connection_ && writable()) {
1875 SignalReadyToSend(this); 1903 SignalReadyToSend(this);
1876 } 1904 }
1877 } 1905 }
1878 1906
1879 // Find "triggered checks". We ping first those connections that have 1907 // Find "triggered checks". We ping first those connections that have
1880 // received a ping but have not sent a ping since receiving it 1908 // received a ping but have not sent a ping since receiving it
1881 // (last_received_ping > last_sent_ping). But we shouldn't do 1909 // (last_ping_received > last_ping_sent). But we shouldn't do
1882 // triggered checks if the connection is already writable. 1910 // triggered checks if the connection is already writable.
1883 Connection* P2PTransportChannel::FindOldestConnectionNeedingTriggeredCheck( 1911 Connection* P2PTransportChannel::FindOldestConnectionNeedingTriggeredCheck(
1884 int64_t now) { 1912 int64_t now) {
1885 Connection* oldest_needing_triggered_check = nullptr; 1913 Connection* oldest_needing_triggered_check = nullptr;
1886 for (auto conn : connections_) { 1914 for (auto conn : connections_) {
1887 if (!IsPingable(conn, now)) { 1915 if (!IsPingable(conn, now)) {
1888 continue; 1916 continue;
1889 } 1917 }
1890 bool needs_triggered_check = 1918 bool needs_triggered_check =
1891 (!conn->writable() && 1919 (!conn->writable() &&
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1987 2015
1988 // During the initial state when nothing has been pinged yet, return the first 2016 // During the initial state when nothing has been pinged yet, return the first
1989 // one in the ordered |connections_|. 2017 // one in the ordered |connections_|.
1990 return *(std::find_if(connections_.begin(), connections_.end(), 2018 return *(std::find_if(connections_.begin(), connections_.end(),
1991 [conn1, conn2](Connection* conn) { 2019 [conn1, conn2](Connection* conn) {
1992 return conn == conn1 || conn == conn2; 2020 return conn == conn1 || conn == conn2;
1993 })); 2021 }));
1994 } 2022 }
1995 2023
1996 } // namespace cricket 2024 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698