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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
211 // quality is reasonable at all. | 211 // quality is reasonable at all. |
212 static const int PING_PACKET_SIZE = 60 * 8; | 212 static const int PING_PACKET_SIZE = 60 * 8; |
213 // STRONG_PING_INTERVAL (480ms) is applied when the best connection is both | 213 // STRONG_PING_INTERVAL (480ms) is applied when the best connection is both |
214 // writable and receiving. | 214 // writable and receiving. |
215 static const int STRONG_PING_INTERVAL = 1000 * PING_PACKET_SIZE / 1000; | 215 static const int STRONG_PING_INTERVAL = 1000 * PING_PACKET_SIZE / 1000; |
216 // WEAK_PING_INTERVAL (48ms) is applied when the best connection is either not | 216 // WEAK_PING_INTERVAL (48ms) is applied when the best connection is either not |
217 // writable or not receiving. | 217 // writable or not receiving. |
218 const int WEAK_PING_INTERVAL = 1000 * PING_PACKET_SIZE / 10000; | 218 const int WEAK_PING_INTERVAL = 1000 * PING_PACKET_SIZE / 10000; |
219 | 219 |
220 // If the current best connection is both writable and receiving, then we will | 220 // If the current best connection is both writable and receiving, then we will |
221 // also try hard to make sure it is pinged at this rate (a little less than | 221 // also try hard to make sure it is pinged at this rate. |
pthatcher1
2016/05/05 20:46:13
This comment isn't accurate any more, because this
Zhi Huang
2016/05/06 01:43:39
Done.
| |
222 // 2 * STRONG_PING_INTERVAL). | 222 static const int MAX_CURRENT_STRONG_INTERVAL = 2500; // ms |
223 static const int MAX_CURRENT_STRONG_INTERVAL = 900; // ms | |
224 | 223 |
225 static const int MIN_CHECK_RECEIVING_INTERVAL = 50; // ms | 224 static const int MIN_CHECK_RECEIVING_INTERVAL = 50; // ms |
226 | 225 |
227 P2PTransportChannel::P2PTransportChannel(const std::string& transport_name, | 226 P2PTransportChannel::P2PTransportChannel(const std::string& transport_name, |
228 int component, | 227 int component, |
229 P2PTransport* transport, | 228 P2PTransport* transport, |
230 PortAllocator* allocator) | 229 PortAllocator* allocator) |
231 : P2PTransportChannel(transport_name, component, allocator) {} | 230 : P2PTransportChannel(transport_name, component, allocator) {} |
232 | 231 |
233 P2PTransportChannel::P2PTransportChannel(const std::string& transport_name, | 232 P2PTransportChannel::P2PTransportChannel(const std::string& transport_name, |
(...skipping 1050 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1284 // When the best connection is either not receiving or not writable, | 1283 // When the best connection is either not receiving or not writable, |
1285 // switch to weak ping interval. | 1284 // switch to weak ping interval. |
1286 int ping_interval = weak() ? weak_ping_interval_ : STRONG_PING_INTERVAL; | 1285 int ping_interval = weak() ? weak_ping_interval_ : STRONG_PING_INTERVAL; |
1287 if (rtc::TimeMillis() >= last_ping_sent_ms_ + ping_interval) { | 1286 if (rtc::TimeMillis() >= last_ping_sent_ms_ + ping_interval) { |
1288 Connection* conn = FindNextPingableConnection(); | 1287 Connection* conn = FindNextPingableConnection(); |
1289 if (conn) { | 1288 if (conn) { |
1290 PingConnection(conn); | 1289 PingConnection(conn); |
1291 MarkConnectionPinged(conn); | 1290 MarkConnectionPinged(conn); |
1292 } | 1291 } |
1293 } | 1292 } |
1293 | |
1294 int delay = std::min(ping_interval, check_receiving_interval_); | 1294 int delay = std::min(ping_interval, check_receiving_interval_); |
1295 thread()->PostDelayed(delay, this, MSG_CHECK_AND_PING); | 1295 thread()->PostDelayed(delay, this, MSG_CHECK_AND_PING); |
1296 } | 1296 } |
1297 | 1297 |
1298 // A connection is considered a backup connection if the channel state | 1298 // A connection is considered a backup connection if the channel state |
1299 // is completed, the connection is not the best connection and it is active. | 1299 // is completed, the connection is not the best connection and it is active. |
1300 bool P2PTransportChannel::IsBackupConnection(Connection* conn) const { | 1300 bool P2PTransportChannel::IsBackupConnection(Connection* conn) const { |
1301 return state_ == STATE_COMPLETED && conn != best_connection_ && | 1301 return state_ == STATE_COMPLETED && conn != best_connection_ && |
1302 conn->active(); | 1302 conn->active(); |
1303 } | 1303 } |
(...skipping 21 matching lines...) Expand all Loading... | |
1325 if (weak()) { | 1325 if (weak()) { |
1326 return true; | 1326 return true; |
1327 } | 1327 } |
1328 | 1328 |
1329 // Always ping active connections regardless whether the channel is completed | 1329 // Always ping active connections regardless whether the channel is completed |
1330 // or not, but backup connections are pinged at a slower rate. | 1330 // or not, but backup connections are pinged at a slower rate. |
1331 if (IsBackupConnection(conn)) { | 1331 if (IsBackupConnection(conn)) { |
1332 return (now >= conn->last_ping_response_received() + | 1332 return (now >= conn->last_ping_response_received() + |
1333 config_.backup_connection_ping_interval); | 1333 config_.backup_connection_ping_interval); |
1334 } | 1334 } |
1335 | |
1336 // Writable connections are ping at a slower rate. | |
1337 if (conn->writable()) { | |
1338 return now >= conn->last_ping_sent() + MAX_CURRENT_STRONG_INTERVAL; | |
pthatcher1
2016/05/05 20:46:13
This should use config_.max_strong_interval (or, b
Zhi Huang
2016/05/06 01:43:38
Agree. Hardcode is indeed inappropriate here.
| |
1339 } | |
1340 | |
1335 return conn->active(); | 1341 return conn->active(); |
1336 } | 1342 } |
1337 | 1343 |
1338 // Returns the next pingable connection to ping. This will be the oldest | 1344 // Returns the next pingable connection to ping. This will be the oldest |
1339 // pingable connection unless we have a connected, writable connection that is | 1345 // pingable connection unless we have a connected, writable connection that is |
1340 // past the maximum acceptable ping interval. When reconnecting a TCP | 1346 // past the maximum acceptable ping interval. When reconnecting a TCP |
1341 // connection, the best connection is disconnected, although still WRITABLE | 1347 // connection, the best connection is disconnected, although still WRITABLE |
1342 // while reconnecting. The newly created connection should be selected as the | 1348 // while reconnecting. The newly created connection should be selected as the |
1343 // ping target to become writable instead. See the big comment in | 1349 // ping target to become writable instead. See the big comment in |
1344 // CompareConnections. | 1350 // CompareConnections. |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1638 | 1644 |
1639 // During the initial state when nothing has been pinged yet, return the first | 1645 // During the initial state when nothing has been pinged yet, return the first |
1640 // one in the ordered |connections_|. | 1646 // one in the ordered |connections_|. |
1641 return *(std::find_if(connections_.begin(), connections_.end(), | 1647 return *(std::find_if(connections_.begin(), connections_.end(), |
1642 [conn1, conn2](Connection* conn) { | 1648 [conn1, conn2](Connection* conn) { |
1643 return conn == conn1 || conn == conn2; | 1649 return conn == conn1 || conn == conn2; |
1644 })); | 1650 })); |
1645 } | 1651 } |
1646 | 1652 |
1647 } // namespace cricket | 1653 } // namespace cricket |
OLD | NEW |