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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
210 // well on a 28.8K modem, which is the slowest connection on which the voice | 210 // well on a 28.8K modem, which is the slowest connection on which the voice |
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 // Writable connections are pinged at a slower rate. |
221 // also try hard to make sure it is pinged at this rate (a little less than | 221 static const int WRITABLE_CONNECTION_PING_INTERVAL = 2500; // ms |
222 // 2 * STRONG_PING_INTERVAL). | |
223 static const int MAX_CURRENT_STRONG_INTERVAL = 900; // ms | |
224 | 222 |
225 static const int MIN_CHECK_RECEIVING_INTERVAL = 50; // ms | 223 static const int MIN_CHECK_RECEIVING_INTERVAL = 50; // ms |
226 | 224 |
227 P2PTransportChannel::P2PTransportChannel(const std::string& transport_name, | 225 P2PTransportChannel::P2PTransportChannel(const std::string& transport_name, |
228 int component, | 226 int component, |
229 P2PTransport* transport, | 227 P2PTransport* transport, |
230 PortAllocator* allocator) | 228 PortAllocator* allocator) |
231 : P2PTransportChannel(transport_name, component, allocator) {} | 229 : P2PTransportChannel(transport_name, component, allocator) {} |
232 | 230 |
233 P2PTransportChannel::P2PTransportChannel(const std::string& transport_name, | 231 P2PTransportChannel::P2PTransportChannel(const std::string& transport_name, |
234 int component, | 232 int component, |
235 PortAllocator* allocator) | 233 PortAllocator* allocator) |
236 : TransportChannelImpl(transport_name, component), | 234 : TransportChannelImpl(transport_name, component), |
237 allocator_(allocator), | 235 allocator_(allocator), |
238 worker_thread_(rtc::Thread::Current()), | 236 worker_thread_(rtc::Thread::Current()), |
239 incoming_only_(false), | 237 incoming_only_(false), |
240 error_(0), | 238 error_(0), |
241 best_connection_(NULL), | 239 best_connection_(NULL), |
242 pending_best_connection_(NULL), | 240 pending_best_connection_(NULL), |
243 sort_dirty_(false), | 241 sort_dirty_(false), |
244 remote_ice_mode_(ICEMODE_FULL), | 242 remote_ice_mode_(ICEMODE_FULL), |
245 ice_role_(ICEROLE_UNKNOWN), | 243 ice_role_(ICEROLE_UNKNOWN), |
246 tiebreaker_(0), | 244 tiebreaker_(0), |
247 gathering_state_(kIceGatheringNew), | 245 gathering_state_(kIceGatheringNew), |
248 check_receiving_interval_(MIN_CHECK_RECEIVING_INTERVAL * 5), | 246 check_receiving_interval_(MIN_CHECK_RECEIVING_INTERVAL * 5), |
249 config_(MIN_CHECK_RECEIVING_INTERVAL * 50 /* receiving_timeout */, | 247 config_(MIN_CHECK_RECEIVING_INTERVAL * 50 /* receiving_timeout */, |
250 0 /* backup_connection_ping_interval */, | 248 0 /* backup_connection_ping_interval */, |
251 false /* gather_continually */, | 249 false /* gather_continually */, |
252 false /* prioritize_most_likely_candidate_pairs */, | 250 false /* prioritize_most_likely_candidate_pairs */, |
253 MAX_CURRENT_STRONG_INTERVAL /* max_strong_interval */) { | 251 WRITABLE_CONNECTION_PING_INTERVAL /* max_strong_interval */) { |
pthatcher1
2016/05/06 23:34:38
The comment doesn't match. And the comment provid
| |
254 uint32_t weak_ping_interval = ::strtoul( | 252 uint32_t weak_ping_interval = ::strtoul( |
255 webrtc::field_trial::FindFullName("WebRTC-StunInterPacketDelay").c_str(), | 253 webrtc::field_trial::FindFullName("WebRTC-StunInterPacketDelay").c_str(), |
256 nullptr, 10); | 254 nullptr, 10); |
257 if (weak_ping_interval) { | 255 if (weak_ping_interval) { |
258 weak_ping_interval_ = static_cast<int>(weak_ping_interval); | 256 weak_ping_interval_ = static_cast<int>(weak_ping_interval); |
259 } | 257 } |
260 } | 258 } |
261 | 259 |
262 P2PTransportChannel::~P2PTransportChannel() { | 260 P2PTransportChannel::~P2PTransportChannel() { |
263 ASSERT(worker_thread_ == rtc::Thread::Current()); | 261 ASSERT(worker_thread_ == rtc::Thread::Current()); |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
429 } | 427 } |
430 LOG(LS_INFO) << "Set ICE receiving timeout to " << config_.receiving_timeout | 428 LOG(LS_INFO) << "Set ICE receiving timeout to " << config_.receiving_timeout |
431 << " milliseconds"; | 429 << " milliseconds"; |
432 } | 430 } |
433 | 431 |
434 config_.prioritize_most_likely_candidate_pairs = | 432 config_.prioritize_most_likely_candidate_pairs = |
435 config.prioritize_most_likely_candidate_pairs; | 433 config.prioritize_most_likely_candidate_pairs; |
436 LOG(LS_INFO) << "Set ping most likely connection to " | 434 LOG(LS_INFO) << "Set ping most likely connection to " |
437 << config_.prioritize_most_likely_candidate_pairs; | 435 << config_.prioritize_most_likely_candidate_pairs; |
438 | 436 |
439 if (config.max_strong_interval >= 0 && | 437 if (config.writable_connection_ping_interval >= 0 && |
440 config_.max_strong_interval != config.max_strong_interval) { | 438 config_.writable_connection_ping_interval != |
441 config_.max_strong_interval = config.max_strong_interval; | 439 config.writable_connection_ping_interval) { |
442 LOG(LS_INFO) << "Set max strong interval to " | 440 config_.writable_connection_ping_interval = |
443 << config_.max_strong_interval; | 441 config.writable_connection_ping_interval; |
442 LOG(LS_INFO) << "Set writable_connection_ping_interval to " | |
443 << config_.writable_connection_ping_interval; | |
444 } | 444 } |
445 } | 445 } |
446 | 446 |
447 const IceConfig& P2PTransportChannel::config() const { | 447 const IceConfig& P2PTransportChannel::config() const { |
448 return config_; | 448 return config_; |
449 } | 449 } |
450 | 450 |
451 // Go into the state of processing candidates, and running in general | 451 // Go into the state of processing candidates, and running in general |
452 void P2PTransportChannel::Connect() { | 452 void P2PTransportChannel::Connect() { |
453 ASSERT(worker_thread_ == rtc::Thread::Current()); | 453 ASSERT(worker_thread_ == rtc::Thread::Current()); |
(...skipping 830 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1284 // When the best connection is either not receiving or not writable, | 1284 // When the best connection is either not receiving or not writable, |
1285 // switch to weak ping interval. | 1285 // switch to weak ping interval. |
1286 int ping_interval = weak() ? weak_ping_interval_ : STRONG_PING_INTERVAL; | 1286 int ping_interval = weak() ? weak_ping_interval_ : STRONG_PING_INTERVAL; |
1287 if (rtc::TimeMillis() >= last_ping_sent_ms_ + ping_interval) { | 1287 if (rtc::TimeMillis() >= last_ping_sent_ms_ + ping_interval) { |
1288 Connection* conn = FindNextPingableConnection(); | 1288 Connection* conn = FindNextPingableConnection(); |
1289 if (conn) { | 1289 if (conn) { |
1290 PingConnection(conn); | 1290 PingConnection(conn); |
1291 MarkConnectionPinged(conn); | 1291 MarkConnectionPinged(conn); |
1292 } | 1292 } |
1293 } | 1293 } |
1294 | |
1294 int delay = std::min(ping_interval, check_receiving_interval_); | 1295 int delay = std::min(ping_interval, check_receiving_interval_); |
1295 thread()->PostDelayed(delay, this, MSG_CHECK_AND_PING); | 1296 thread()->PostDelayed(delay, this, MSG_CHECK_AND_PING); |
1296 } | 1297 } |
1297 | 1298 |
1298 // A connection is considered a backup connection if the channel state | 1299 // 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. | 1300 // is completed, the connection is not the best connection and it is active. |
1300 bool P2PTransportChannel::IsBackupConnection(Connection* conn) const { | 1301 bool P2PTransportChannel::IsBackupConnection(Connection* conn) const { |
1301 return state_ == STATE_COMPLETED && conn != best_connection_ && | 1302 return state_ == STATE_COMPLETED && conn != best_connection_ && |
1302 conn->active(); | 1303 conn->active(); |
1303 } | 1304 } |
(...skipping 21 matching lines...) Expand all Loading... | |
1325 if (weak()) { | 1326 if (weak()) { |
1326 return true; | 1327 return true; |
1327 } | 1328 } |
1328 | 1329 |
1329 // Always ping active connections regardless whether the channel is completed | 1330 // Always ping active connections regardless whether the channel is completed |
1330 // or not, but backup connections are pinged at a slower rate. | 1331 // or not, but backup connections are pinged at a slower rate. |
1331 if (IsBackupConnection(conn)) { | 1332 if (IsBackupConnection(conn)) { |
1332 return (now >= conn->last_ping_response_received() + | 1333 return (now >= conn->last_ping_response_received() + |
1333 config_.backup_connection_ping_interval); | 1334 config_.backup_connection_ping_interval); |
1334 } | 1335 } |
1336 | |
1337 // Writable connections are pinged at a slower rate. | |
1338 if (conn->writable()) { | |
1339 return (now >= | |
1340 conn->last_ping_sent() + config_.writable_connection_ping_interval); | |
1341 } | |
1342 | |
1335 return conn->active(); | 1343 return conn->active(); |
1336 } | 1344 } |
1337 | 1345 |
1338 // Returns the next pingable connection to ping. This will be the oldest | 1346 // Returns the next pingable connection to ping. This will be the oldest |
1339 // pingable connection unless we have a connected, writable connection that is | 1347 // pingable connection unless we have a connected, writable connection that is |
1340 // past the maximum acceptable ping interval. When reconnecting a TCP | 1348 // past the maximum acceptable ping interval. When reconnecting a TCP |
1341 // connection, the best connection is disconnected, although still WRITABLE | 1349 // connection, the best connection is disconnected, although still WRITABLE |
1342 // while reconnecting. The newly created connection should be selected as the | 1350 // while reconnecting. The newly created connection should be selected as the |
1343 // ping target to become writable instead. See the big comment in | 1351 // ping target to become writable instead. See the big comment in |
1344 // CompareConnections. | 1352 // CompareConnections. |
1345 Connection* P2PTransportChannel::FindNextPingableConnection() { | 1353 Connection* P2PTransportChannel::FindNextPingableConnection() { |
1346 int64_t now = rtc::TimeMillis(); | 1354 int64_t now = rtc::TimeMillis(); |
1347 Connection* conn_to_ping = nullptr; | 1355 Connection* conn_to_ping = nullptr; |
1348 if (best_connection_ && best_connection_->connected() && | 1356 if (best_connection_ && best_connection_->connected() && |
1349 best_connection_->writable() && | 1357 best_connection_->writable() && |
1350 (best_connection_->last_ping_sent() + config_.max_strong_interval <= | 1358 (best_connection_->last_ping_sent() + |
1359 config_.writable_connection_ping_interval <= | |
1351 now)) { | 1360 now)) { |
1352 conn_to_ping = best_connection_; | 1361 conn_to_ping = best_connection_; |
1353 } else { | 1362 } else { |
1354 conn_to_ping = FindConnectionToPing(now); | 1363 conn_to_ping = FindConnectionToPing(now); |
1355 } | 1364 } |
1356 return conn_to_ping; | 1365 return conn_to_ping; |
1357 } | 1366 } |
1358 | 1367 |
1359 void P2PTransportChannel::MarkConnectionPinged(Connection* conn) { | 1368 void P2PTransportChannel::MarkConnectionPinged(Connection* conn) { |
1360 if (conn && pinged_connections_.insert(conn).second) { | 1369 if (conn && pinged_connections_.insert(conn).second) { |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1642 | 1651 |
1643 // During the initial state when nothing has been pinged yet, return the first | 1652 // During the initial state when nothing has been pinged yet, return the first |
1644 // one in the ordered |connections_|. | 1653 // one in the ordered |connections_|. |
1645 return *(std::find_if(connections_.begin(), connections_.end(), | 1654 return *(std::find_if(connections_.begin(), connections_.end(), |
1646 [conn1, conn2](Connection* conn) { | 1655 [conn1, conn2](Connection* conn) { |
1647 return conn == conn1 || conn == conn2; | 1656 return conn == conn1 || conn == conn2; |
1648 })); | 1657 })); |
1649 } | 1658 } |
1650 | 1659 |
1651 } // namespace cricket | 1660 } // namespace cricket |
OLD | NEW |