| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 Loading... |
| 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 Loading... |
| 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::GetPremierConnectionsByNetwork() const { |
| 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)); |
| 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()]; |
| 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 Loading... |
| 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 Loading... |
| 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 Connection* P2PTransportChannel::FindBestPremierConnectionToPing(int64_t now) { |
| 1600 if (!selected_connection_ || !selected_connection_->connected() || | 1592 // If the selected connection is pingable, select it to ping. |
| 1601 !selected_connection_->writable()) { | 1593 if (IsPremierConnectionPingable(selected_connection_, now)) { |
| 1594 return selected_connection_; |
| 1595 } |
| 1596 // If the selected connection is strongly connected, don't bother to ping |
| 1597 // premier connections on other networks at a higher priority. This prevents |
| 1598 // a few premier connections from saturating all transmission slots for ping |
| 1599 // and also prevents the backup connections from being pinged frequently. |
| 1600 if (!weak()) { |
| 1601 return nullptr; |
| 1602 } |
| 1603 |
| 1604 // Otherwise, find the premier connection that has not been pinged for the |
| 1605 // longest time. |
| 1606 auto premier_connections_by_network = GetPremierConnectionsByNetwork(); |
| 1607 Connection* oldest_pingable_premier_connection = nullptr; |
| 1608 for (auto kv : premier_connections_by_network) { |
| 1609 Connection* conn = kv.second; |
| 1610 if (conn == nullptr || conn == selected_connection_) { |
| 1611 continue; |
| 1612 } |
| 1613 if (IsPremierConnectionPingable(conn, now) && |
| 1614 (!oldest_pingable_premier_connection || |
| 1615 conn->last_ping_sent() < |
| 1616 oldest_pingable_premier_connection->last_ping_sent())) { |
| 1617 oldest_pingable_premier_connection = conn; |
| 1618 } |
| 1619 } |
| 1620 return oldest_pingable_premier_connection; |
| 1621 } |
| 1622 |
| 1623 bool P2PTransportChannel::IsPremierConnectionPingable( |
| 1624 Connection* premier_connection, |
| 1625 int64_t now) { |
| 1626 if (!premier_connection || !premier_connection->connected() || |
| 1627 !premier_connection->writable()) { |
| 1602 return false; | 1628 return false; |
| 1603 } | 1629 } |
| 1604 | 1630 |
| 1605 int interval = CalculateActiveWritablePingInterval(selected_connection_, now); | 1631 int interval = CalculateActiveWritablePingInterval(premier_connection, now); |
| 1606 return selected_connection_->last_ping_sent() + interval <= now; | 1632 return premier_connection->last_ping_sent() + interval <= now; |
| 1607 } | 1633 } |
| 1608 | 1634 |
| 1609 int P2PTransportChannel::CalculateActiveWritablePingInterval( | 1635 int P2PTransportChannel::CalculateActiveWritablePingInterval( |
| 1610 const Connection* conn, | 1636 const Connection* conn, |
| 1611 int64_t now) const { | 1637 int64_t now) const { |
| 1612 // Ping each connection at a higher rate at least | 1638 // Ping each connection at a higher rate at least |
| 1613 // MIN_PINGS_AT_WEAK_PING_INTERVAL times. | 1639 // MIN_PINGS_AT_WEAK_PING_INTERVAL times. |
| 1614 if (conn->num_pings_sent() < MIN_PINGS_AT_WEAK_PING_INTERVAL) { | 1640 if (conn->num_pings_sent() < MIN_PINGS_AT_WEAK_PING_INTERVAL) { |
| 1615 return weak_ping_interval_; | 1641 return weak_ping_interval_; |
| 1616 } | 1642 } |
| 1617 | 1643 |
| 1618 int stable_interval = config_.stable_writable_connection_ping_interval; | 1644 int stable_interval = config_.stable_writable_connection_ping_interval; |
| 1619 int stablizing_interval = | 1645 int weak_or_stablizing_interval = std::min( |
| 1620 std::min(stable_interval, STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL); | 1646 stable_interval, WEAK_OR_STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL); |
| 1621 | 1647 // If the channel is weak or the connection is not stable yet, use the |
| 1622 return conn->stable(now) ? stable_interval : stablizing_interval; | 1648 // weak_or_stablizing_interval. |
| 1649 return (!weak() && conn->stable(now)) ? stable_interval |
| 1650 : weak_or_stablizing_interval; |
| 1623 } | 1651 } |
| 1624 | 1652 |
| 1625 // Returns the next pingable connection to ping. This will be the oldest | 1653 // Returns the next pingable connection to ping. This will be the oldest |
| 1626 // pingable connection unless we have a connected, writable connection that is | 1654 // pingable connection unless we have a connected, writable connection that is |
| 1627 // past the writable ping interval. When reconnecting a TCP | 1655 // past the writable ping interval. When reconnecting a TCP |
| 1628 // connection, the selected connection is disconnected, although still WRITABLE | 1656 // connection, the selected connection is disconnected, although still WRITABLE |
| 1629 // while reconnecting. The newly created connection should be selected as the | 1657 // while reconnecting. The newly created connection should be selected as the |
| 1630 // ping target to become writable instead. See the big comment in | 1658 // ping target to become writable instead. See the big comment in |
| 1631 // CompareConnectionStates. | 1659 // CompareConnectionStates. |
| 1632 Connection* P2PTransportChannel::FindNextPingableConnection() { | 1660 Connection* P2PTransportChannel::FindNextPingableConnection() { |
| 1633 int64_t now = rtc::TimeMillis(); | 1661 int64_t now = rtc::TimeMillis(); |
| 1634 Connection* conn_to_ping = nullptr; | 1662 Connection* conn_to_ping = FindBestPremierConnectionToPing(now); |
| 1635 if (IsSelectedConnectionPingable(now)) { | 1663 if (!conn_to_ping) { |
| 1636 conn_to_ping = selected_connection_; | |
| 1637 } else { | |
| 1638 conn_to_ping = FindConnectionToPing(now); | 1664 conn_to_ping = FindConnectionToPing(now); |
| 1639 } | 1665 } |
| 1640 return conn_to_ping; | 1666 return conn_to_ping; |
| 1641 } | 1667 } |
| 1642 | 1668 |
| 1643 void P2PTransportChannel::MarkConnectionPinged(Connection* conn) { | 1669 void P2PTransportChannel::MarkConnectionPinged(Connection* conn) { |
| 1644 if (conn && pinged_connections_.insert(conn).second) { | 1670 if (conn && pinged_connections_.insert(conn).second) { |
| 1645 unpinged_connections_.erase(conn); | 1671 unpinged_connections_.erase(conn); |
| 1646 } | 1672 } |
| 1647 } | 1673 } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1742 // use it. | 1768 // use it. |
| 1743 | 1769 |
| 1744 // Remove this connection from the list. | 1770 // Remove this connection from the list. |
| 1745 std::vector<Connection*>::iterator iter = | 1771 std::vector<Connection*>::iterator iter = |
| 1746 std::find(connections_.begin(), connections_.end(), connection); | 1772 std::find(connections_.begin(), connections_.end(), connection); |
| 1747 ASSERT(iter != connections_.end()); | 1773 ASSERT(iter != connections_.end()); |
| 1748 pinged_connections_.erase(*iter); | 1774 pinged_connections_.erase(*iter); |
| 1749 unpinged_connections_.erase(*iter); | 1775 unpinged_connections_.erase(*iter); |
| 1750 connections_.erase(iter); | 1776 connections_.erase(iter); |
| 1751 | 1777 |
| 1752 LOG_J(LS_INFO, this) << "Removed connection (" | 1778 LOG_J(LS_INFO, this) << "Removed connection " << std::hex << connection |
| 1753 << static_cast<int>(connections_.size()) << " remaining)"; | 1779 << std::dec << " (" << connections_.size() |
| 1780 << " remaining)"; |
| 1754 | 1781 |
| 1755 // If this is currently the selected connection, then we need to pick a new | 1782 // 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 | 1783 // one. The call to SortConnectionsAndUpdateState will pick a new one. It |
| 1757 // looks at the current selected connection in order to avoid switching | 1784 // looks at the current selected connection in order to avoid switching |
| 1758 // between fairly similar ones. Since this connection is no longer an option, | 1785 // 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 | 1786 // we can just set selected to nullptr and re-choose a best assuming that |
| 1760 // there was no selected connection. | 1787 // there was no selected connection. |
| 1761 if (selected_connection_ == connection) { | 1788 if (selected_connection_ == connection) { |
| 1762 LOG(LS_INFO) << "Selected connection destroyed. Will choose a new one."; | 1789 LOG(LS_INFO) << "Selected connection destroyed. Will choose a new one."; |
| 1763 SwitchSelectedConnection(nullptr); | 1790 SwitchSelectedConnection(nullptr); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1871 } | 1898 } |
| 1872 | 1899 |
| 1873 void P2PTransportChannel::OnReadyToSend(Connection* connection) { | 1900 void P2PTransportChannel::OnReadyToSend(Connection* connection) { |
| 1874 if (connection == selected_connection_ && writable()) { | 1901 if (connection == selected_connection_ && writable()) { |
| 1875 SignalReadyToSend(this); | 1902 SignalReadyToSend(this); |
| 1876 } | 1903 } |
| 1877 } | 1904 } |
| 1878 | 1905 |
| 1879 // Find "triggered checks". We ping first those connections that have | 1906 // Find "triggered checks". We ping first those connections that have |
| 1880 // received a ping but have not sent a ping since receiving it | 1907 // received a ping but have not sent a ping since receiving it |
| 1881 // (last_received_ping > last_sent_ping). But we shouldn't do | 1908 // (last_ping_received > last_ping_sent). But we shouldn't do |
| 1882 // triggered checks if the connection is already writable. | 1909 // triggered checks if the connection is already writable. |
| 1883 Connection* P2PTransportChannel::FindOldestConnectionNeedingTriggeredCheck( | 1910 Connection* P2PTransportChannel::FindOldestConnectionNeedingTriggeredCheck( |
| 1884 int64_t now) { | 1911 int64_t now) { |
| 1885 Connection* oldest_needing_triggered_check = nullptr; | 1912 Connection* oldest_needing_triggered_check = nullptr; |
| 1886 for (auto conn : connections_) { | 1913 for (auto conn : connections_) { |
| 1887 if (!IsPingable(conn, now)) { | 1914 if (!IsPingable(conn, now)) { |
| 1888 continue; | 1915 continue; |
| 1889 } | 1916 } |
| 1890 bool needs_triggered_check = | 1917 bool needs_triggered_check = |
| 1891 (!conn->writable() && | 1918 (!conn->writable() && |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1987 | 2014 |
| 1988 // During the initial state when nothing has been pinged yet, return the first | 2015 // During the initial state when nothing has been pinged yet, return the first |
| 1989 // one in the ordered |connections_|. | 2016 // one in the ordered |connections_|. |
| 1990 return *(std::find_if(connections_.begin(), connections_.end(), | 2017 return *(std::find_if(connections_.begin(), connections_.end(), |
| 1991 [conn1, conn2](Connection* conn) { | 2018 [conn1, conn2](Connection* conn) { |
| 1992 return conn == conn1 || conn == conn2; | 2019 return conn == conn1 || conn == conn2; |
| 1993 })); | 2020 })); |
| 1994 } | 2021 } |
| 1995 | 2022 |
| 1996 } // namespace cricket | 2023 } // namespace cricket |
| OLD | NEW |