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

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

Issue 1979573003: Revert of Increase the stun ping interval. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 7 months 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
« no previous file with comments | « no previous file | webrtc/p2p/base/p2ptransportchannel_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // Writable connections are pinged at a slower rate. 220 // If the current best connection is both writable and receiving, then we will
221 static const int WRITABLE_CONNECTION_PING_INTERVAL = 2500; // ms 221 // also try hard to make sure it is pinged at this rate (a little less than
222 // 2 * STRONG_PING_INTERVAL).
223 static const int MAX_CURRENT_STRONG_INTERVAL = 900; // ms
222 224
223 static const int MIN_CHECK_RECEIVING_INTERVAL = 50; // ms 225 static const int MIN_CHECK_RECEIVING_INTERVAL = 50; // ms
224 226
225 P2PTransportChannel::P2PTransportChannel(const std::string& transport_name, 227 P2PTransportChannel::P2PTransportChannel(const std::string& transport_name,
226 int component, 228 int component,
227 P2PTransport* transport, 229 P2PTransport* transport,
228 PortAllocator* allocator) 230 PortAllocator* allocator)
229 : P2PTransportChannel(transport_name, component, allocator) {} 231 : P2PTransportChannel(transport_name, component, allocator) {}
230 232
231 P2PTransportChannel::P2PTransportChannel(const std::string& transport_name, 233 P2PTransportChannel::P2PTransportChannel(const std::string& transport_name,
232 int component, 234 int component,
233 PortAllocator* allocator) 235 PortAllocator* allocator)
234 : TransportChannelImpl(transport_name, component), 236 : TransportChannelImpl(transport_name, component),
235 allocator_(allocator), 237 allocator_(allocator),
236 worker_thread_(rtc::Thread::Current()), 238 worker_thread_(rtc::Thread::Current()),
237 incoming_only_(false), 239 incoming_only_(false),
238 error_(0), 240 error_(0),
239 best_connection_(NULL), 241 best_connection_(NULL),
240 pending_best_connection_(NULL), 242 pending_best_connection_(NULL),
241 sort_dirty_(false), 243 sort_dirty_(false),
242 remote_ice_mode_(ICEMODE_FULL), 244 remote_ice_mode_(ICEMODE_FULL),
243 ice_role_(ICEROLE_UNKNOWN), 245 ice_role_(ICEROLE_UNKNOWN),
244 tiebreaker_(0), 246 tiebreaker_(0),
245 gathering_state_(kIceGatheringNew), 247 gathering_state_(kIceGatheringNew),
246 check_receiving_interval_(MIN_CHECK_RECEIVING_INTERVAL * 5), 248 check_receiving_interval_(MIN_CHECK_RECEIVING_INTERVAL * 5),
247 config_(MIN_CHECK_RECEIVING_INTERVAL * 50 /* receiving_timeout */, 249 config_(MIN_CHECK_RECEIVING_INTERVAL * 50 /* receiving_timeout */,
248 0 /* backup_connection_ping_interval */, 250 0 /* backup_connection_ping_interval */,
249 false /* gather_continually */, 251 false /* gather_continually */,
250 false /* prioritize_most_likely_candidate_pairs */, 252 false /* prioritize_most_likely_candidate_pairs */,
251 WRITABLE_CONNECTION_PING_INTERVAL) { 253 MAX_CURRENT_STRONG_INTERVAL /* max_strong_interval */) {
252 uint32_t weak_ping_interval = ::strtoul( 254 uint32_t weak_ping_interval = ::strtoul(
253 webrtc::field_trial::FindFullName("WebRTC-StunInterPacketDelay").c_str(), 255 webrtc::field_trial::FindFullName("WebRTC-StunInterPacketDelay").c_str(),
254 nullptr, 10); 256 nullptr, 10);
255 if (weak_ping_interval) { 257 if (weak_ping_interval) {
256 weak_ping_interval_ = static_cast<int>(weak_ping_interval); 258 weak_ping_interval_ = static_cast<int>(weak_ping_interval);
257 } 259 }
258 } 260 }
259 261
260 P2PTransportChannel::~P2PTransportChannel() { 262 P2PTransportChannel::~P2PTransportChannel() {
261 ASSERT(worker_thread_ == rtc::Thread::Current()); 263 ASSERT(worker_thread_ == rtc::Thread::Current());
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 } 429 }
428 LOG(LS_INFO) << "Set ICE receiving timeout to " << config_.receiving_timeout 430 LOG(LS_INFO) << "Set ICE receiving timeout to " << config_.receiving_timeout
429 << " milliseconds"; 431 << " milliseconds";
430 } 432 }
431 433
432 config_.prioritize_most_likely_candidate_pairs = 434 config_.prioritize_most_likely_candidate_pairs =
433 config.prioritize_most_likely_candidate_pairs; 435 config.prioritize_most_likely_candidate_pairs;
434 LOG(LS_INFO) << "Set ping most likely connection to " 436 LOG(LS_INFO) << "Set ping most likely connection to "
435 << config_.prioritize_most_likely_candidate_pairs; 437 << config_.prioritize_most_likely_candidate_pairs;
436 438
437 if (config.writable_connection_ping_interval >= 0 && 439 if (config.max_strong_interval >= 0 &&
438 config_.writable_connection_ping_interval != 440 config_.max_strong_interval != config.max_strong_interval) {
439 config.writable_connection_ping_interval) { 441 config_.max_strong_interval = config.max_strong_interval;
440 config_.writable_connection_ping_interval = 442 LOG(LS_INFO) << "Set max strong interval to "
441 config.writable_connection_ping_interval; 443 << config_.max_strong_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
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
1295 int delay = std::min(ping_interval, check_receiving_interval_); 1294 int delay = std::min(ping_interval, check_receiving_interval_);
1296 thread()->PostDelayed(delay, this, MSG_CHECK_AND_PING); 1295 thread()->PostDelayed(delay, this, MSG_CHECK_AND_PING);
1297 } 1296 }
1298 1297
1299 // A connection is considered a backup connection if the channel state 1298 // A connection is considered a backup connection if the channel state
1300 // 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.
1301 bool P2PTransportChannel::IsBackupConnection(Connection* conn) const { 1300 bool P2PTransportChannel::IsBackupConnection(Connection* conn) const {
1302 return state_ == STATE_COMPLETED && conn != best_connection_ && 1301 return state_ == STATE_COMPLETED && conn != best_connection_ &&
1303 conn->active(); 1302 conn->active();
1304 } 1303 }
(...skipping 21 matching lines...) Expand all
1326 if (weak()) { 1325 if (weak()) {
1327 return true; 1326 return true;
1328 } 1327 }
1329 1328
1330 // Always ping active connections regardless whether the channel is completed 1329 // Always ping active connections regardless whether the channel is completed
1331 // or not, but backup connections are pinged at a slower rate. 1330 // or not, but backup connections are pinged at a slower rate.
1332 if (IsBackupConnection(conn)) { 1331 if (IsBackupConnection(conn)) {
1333 return (now >= conn->last_ping_response_received() + 1332 return (now >= conn->last_ping_response_received() +
1334 config_.backup_connection_ping_interval); 1333 config_.backup_connection_ping_interval);
1335 } 1334 }
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
1343 return conn->active(); 1335 return conn->active();
1344 } 1336 }
1345 1337
1346 // Returns the next pingable connection to ping. This will be the oldest 1338 // Returns the next pingable connection to ping. This will be the oldest
1347 // pingable connection unless we have a connected, writable connection that is 1339 // pingable connection unless we have a connected, writable connection that is
1348 // past the maximum acceptable ping interval. When reconnecting a TCP 1340 // past the maximum acceptable ping interval. When reconnecting a TCP
1349 // connection, the best connection is disconnected, although still WRITABLE 1341 // connection, the best connection is disconnected, although still WRITABLE
1350 // while reconnecting. The newly created connection should be selected as the 1342 // while reconnecting. The newly created connection should be selected as the
1351 // ping target to become writable instead. See the big comment in 1343 // ping target to become writable instead. See the big comment in
1352 // CompareConnections. 1344 // CompareConnections.
1353 Connection* P2PTransportChannel::FindNextPingableConnection() { 1345 Connection* P2PTransportChannel::FindNextPingableConnection() {
1354 int64_t now = rtc::TimeMillis(); 1346 int64_t now = rtc::TimeMillis();
1355 Connection* conn_to_ping = nullptr; 1347 Connection* conn_to_ping = nullptr;
1356 if (best_connection_ && best_connection_->connected() && 1348 if (best_connection_ && best_connection_->connected() &&
1357 best_connection_->writable() && 1349 best_connection_->writable() &&
1358 (best_connection_->last_ping_sent() + 1350 (best_connection_->last_ping_sent() + config_.max_strong_interval <=
1359 config_.writable_connection_ping_interval <=
1360 now)) { 1351 now)) {
1361 conn_to_ping = best_connection_; 1352 conn_to_ping = best_connection_;
1362 } else { 1353 } else {
1363 conn_to_ping = FindConnectionToPing(now); 1354 conn_to_ping = FindConnectionToPing(now);
1364 } 1355 }
1365 return conn_to_ping; 1356 return conn_to_ping;
1366 } 1357 }
1367 1358
1368 void P2PTransportChannel::MarkConnectionPinged(Connection* conn) { 1359 void P2PTransportChannel::MarkConnectionPinged(Connection* conn) {
1369 if (conn && pinged_connections_.insert(conn).second) { 1360 if (conn && pinged_connections_.insert(conn).second) {
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
1651 1642
1652 // During the initial state when nothing has been pinged yet, return the first 1643 // During the initial state when nothing has been pinged yet, return the first
1653 // one in the ordered |connections_|. 1644 // one in the ordered |connections_|.
1654 return *(std::find_if(connections_.begin(), connections_.end(), 1645 return *(std::find_if(connections_.begin(), connections_.end(),
1655 [conn1, conn2](Connection* conn) { 1646 [conn1, conn2](Connection* conn) {
1656 return conn == conn1 || conn == conn2; 1647 return conn == conn1 || conn == conn2;
1657 })); 1648 }));
1658 } 1649 }
1659 1650
1660 } // namespace cricket 1651 } // namespace cricket
OLDNEW
« no previous file with comments | « no previous file | webrtc/p2p/base/p2ptransportchannel_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698