| 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 1284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1295 void P2PTransportChannel::OnSort() { | 1295 void P2PTransportChannel::OnSort() { |
| 1296 // Resort the connections based on the new statistics. | 1296 // Resort the connections based on the new statistics. |
| 1297 SortConnections(); | 1297 SortConnections(); |
| 1298 } | 1298 } |
| 1299 | 1299 |
| 1300 // Handle queued up check-and-ping request | 1300 // Handle queued up check-and-ping request |
| 1301 void P2PTransportChannel::OnCheckAndPing() { | 1301 void P2PTransportChannel::OnCheckAndPing() { |
| 1302 // Make sure the states of the connections are up-to-date (since this affects | 1302 // Make sure the states of the connections are up-to-date (since this affects |
| 1303 // which ones are pingable). | 1303 // which ones are pingable). |
| 1304 UpdateConnectionStates(); | 1304 UpdateConnectionStates(); |
| 1305 // When the best connection is either not receiving or not writable, | 1305 // When the best connection is not receiving or not writable, or any active |
| 1306 // switch to weak ping interval. | 1306 // connection has not been pinged enough times, use the weak ping interval. |
| 1307 int ping_interval = weak() ? weak_ping_interval_ : STRONG_PING_INTERVAL; | 1307 bool need_more_pings_at_weak_interval = std::any_of( |
| 1308 connections_.begin(), connections_.end(), [](Connection* conn) { |
| 1309 return conn->active() && |
| 1310 conn->num_pings_sent() < MIN_PINGS_AT_WEAK_PING_INTERVAL; |
| 1311 }); |
| 1312 int ping_interval = (weak() || need_more_pings_at_weak_interval) |
| 1313 ? weak_ping_interval_ |
| 1314 : STRONG_PING_INTERVAL; |
| 1308 if (rtc::TimeMillis() >= last_ping_sent_ms_ + ping_interval) { | 1315 if (rtc::TimeMillis() >= last_ping_sent_ms_ + ping_interval) { |
| 1309 Connection* conn = FindNextPingableConnection(); | 1316 Connection* conn = FindNextPingableConnection(); |
| 1310 if (conn) { | 1317 if (conn) { |
| 1311 PingConnection(conn); | 1318 PingConnection(conn); |
| 1312 MarkConnectionPinged(conn); | 1319 MarkConnectionPinged(conn); |
| 1313 } | 1320 } |
| 1314 } | 1321 } |
| 1315 int delay = std::min(ping_interval, check_receiving_interval_); | 1322 int delay = std::min(ping_interval, check_receiving_interval_); |
| 1316 thread()->PostDelayed(delay, this, MSG_CHECK_AND_PING); | 1323 thread()->PostDelayed(delay, this, MSG_CHECK_AND_PING); |
| 1317 } | 1324 } |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1660 | 1667 |
| 1661 // During the initial state when nothing has been pinged yet, return the first | 1668 // During the initial state when nothing has been pinged yet, return the first |
| 1662 // one in the ordered |connections_|. | 1669 // one in the ordered |connections_|. |
| 1663 return *(std::find_if(connections_.begin(), connections_.end(), | 1670 return *(std::find_if(connections_.begin(), connections_.end(), |
| 1664 [conn1, conn2](Connection* conn) { | 1671 [conn1, conn2](Connection* conn) { |
| 1665 return conn == conn1 || conn == conn2; | 1672 return conn == conn1 || conn == conn2; |
| 1666 })); | 1673 })); |
| 1667 } | 1674 } |
| 1668 | 1675 |
| 1669 } // namespace cricket | 1676 } // namespace cricket |
| OLD | NEW |