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

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

Issue 1944003002: 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 | no next file » | 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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 } // unnamed namespace 203 } // unnamed namespace
204 204
205 namespace cricket { 205 namespace cricket {
206 206
207 // When the socket is unwritable, we will use 10 Kbps (ignoring IP+UDP headers) 207 // When the socket is unwritable, we will use 10 Kbps (ignoring IP+UDP headers)
208 // for pinging. When the socket is writable, we will use only 1 Kbps because 208 // for pinging. When the socket is writable, we will use only 1 Kbps because
209 // we don't want to degrade the quality on a modem. These numbers should work 209 // we don't want to degrade the quality on a modem. These numbers should work
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 (2400ms) is applied to the Writable connections in the
214 // writable and receiving. 214 // channel when the best connection is both 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 / 200;
Taylor Brandstetter 2016/05/04 17:58:08 I don't think the strong ping interval should chan
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 (a little less than
222 // 2 * STRONG_PING_INTERVAL). 222 // 2 * STRONG_PING_INTERVAL).
223 static const int MAX_CURRENT_STRONG_INTERVAL = 900; // ms 223 static const int MAX_CURRENT_STRONG_INTERVAL = 4500; // ms
Taylor Brandstetter 2016/05/04 17:58:08 This can probably change to 2500 though.
224 224
225 static const int MIN_CHECK_RECEIVING_INTERVAL = 50; // ms 225 static const int MIN_CHECK_RECEIVING_INTERVAL = 50; // ms
226 226
227 P2PTransportChannel::P2PTransportChannel(const std::string& transport_name, 227 P2PTransportChannel::P2PTransportChannel(const std::string& transport_name,
228 int component, 228 int component,
229 P2PTransport* transport, 229 P2PTransport* transport,
230 PortAllocator* allocator) 230 PortAllocator* allocator)
231 : P2PTransportChannel(transport_name, component, allocator) {} 231 : P2PTransportChannel(transport_name, component, allocator) {}
232 232
233 P2PTransportChannel::P2PTransportChannel(const std::string& transport_name, 233 P2PTransportChannel::P2PTransportChannel(const std::string& transport_name,
(...skipping 1040 matching lines...) Expand 10 before | Expand all | Expand 10 after
1274 void P2PTransportChannel::OnSort() { 1274 void P2PTransportChannel::OnSort() {
1275 // Resort the connections based on the new statistics. 1275 // Resort the connections based on the new statistics.
1276 SortConnections(); 1276 SortConnections();
1277 } 1277 }
1278 1278
1279 // Handle queued up check-and-ping request 1279 // Handle queued up check-and-ping request
1280 void P2PTransportChannel::OnCheckAndPing() { 1280 void P2PTransportChannel::OnCheckAndPing() {
1281 // Make sure the states of the connections are up-to-date (since this affects 1281 // Make sure the states of the connections are up-to-date (since this affects
1282 // which ones are pingable). 1282 // which ones are pingable).
1283 UpdateConnectionStates(); 1283 UpdateConnectionStates();
1284 // When the best connection is either not receiving or not writable, 1284
1285 // switch to weak ping interval. 1285 if (rtc::TimeMillis() >= last_ping_sent_ms_ + weak_ping_interval_) {
honghaiz3 2016/05/03 19:15:22 Now after I see this, I realize it will ping all c
honghaiz3 2016/05/03 19:59:17 I think you remove the if condition here and take
Taylor Brandstetter 2016/05/04 17:58:08 I think the strong ping interval (if it stays ~500
1286 int ping_interval = weak() ? weak_ping_interval_ : STRONG_PING_INTERVAL;
1287 if (rtc::TimeMillis() >= last_ping_sent_ms_ + ping_interval) {
1288 Connection* conn = FindNextPingableConnection(); 1286 Connection* conn = FindNextPingableConnection();
1289 if (conn) { 1287 if (conn) {
1290 PingConnection(conn); 1288 PingConnection(conn);
1291 MarkConnectionPinged(conn); 1289 MarkConnectionPinged(conn);
1292 } 1290 }
1293 } 1291 }
1292 // When the best connection is either not receiving or not writable,
1293 // switch to weak ping interval.
1294 int ping_interval = weak() ? weak_ping_interval_ : STRONG_PING_INTERVAL;
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 15 matching lines...) Expand all
1319 // reconnecting state so ping is needed. 1320 // reconnecting state so ping is needed.
1320 if (!conn->connected() && !conn->writable()) { 1321 if (!conn->connected() && !conn->writable()) {
1321 return false; 1322 return false;
1322 } 1323 }
1323 1324
1324 // If the channel is weakly connected, ping all connections. 1325 // If the channel is weakly connected, ping all connections.
1325 if (weak()) { 1326 if (weak()) {
1326 return true; 1327 return true;
1327 } 1328 }
1328 1329
1330 // Writable connections are ping at a slower rate.
1331 if (conn->writable()) {
honghaiz3 2016/05/03 19:15:22 You may need to move this after the backupconnecti
1332 return now >= conn->last_ping_sent() + STRONG_PING_INTERVAL;
Taylor Brandstetter 2016/05/04 17:58:08 If STRONG_PING_INTERVAL is changed back to 500ms,
1333 }
1334
1329 // Always ping active connections regardless whether the channel is completed 1335 // Always ping active connections regardless whether the channel is completed
1330 // or not, but backup connections are pinged at a slower rate. 1336 // or not, but backup connections are pinged at a slower rate.
1331 if (IsBackupConnection(conn)) { 1337 if (IsBackupConnection(conn)) {
1332 return (now >= conn->last_ping_response_received() + 1338 return (now >= conn->last_ping_response_received() +
1333 config_.backup_connection_ping_interval); 1339 config_.backup_connection_ping_interval);
1334 } 1340 }
1341
1335 return conn->active(); 1342 return conn->active();
1336 } 1343 }
1337 1344
1338 // Returns the next pingable connection to ping. This will be the oldest 1345 // Returns the next pingable connection to ping. This will be the oldest
1339 // pingable connection unless we have a connected, writable connection that is 1346 // pingable connection unless we have a connected, writable connection that is
1340 // past the maximum acceptable ping interval. When reconnecting a TCP 1347 // past the maximum acceptable ping interval. When reconnecting a TCP
1341 // connection, the best connection is disconnected, although still WRITABLE 1348 // connection, the best connection is disconnected, although still WRITABLE
1342 // while reconnecting. The newly created connection should be selected as the 1349 // while reconnecting. The newly created connection should be selected as the
1343 // ping target to become writable instead. See the big comment in 1350 // ping target to become writable instead. See the big comment in
1344 // CompareConnections. 1351 // CompareConnections.
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
1638 1645
1639 // During the initial state when nothing has been pinged yet, return the first 1646 // During the initial state when nothing has been pinged yet, return the first
1640 // one in the ordered |connections_|. 1647 // one in the ordered |connections_|.
1641 return *(std::find_if(connections_.begin(), connections_.end(), 1648 return *(std::find_if(connections_.begin(), connections_.end(),
1642 [conn1, conn2](Connection* conn) { 1649 [conn1, conn2](Connection* conn) {
1643 return conn == conn1 || conn == conn2; 1650 return conn == conn1 || conn == conn2;
1644 })); 1651 }));
1645 } 1652 }
1646 1653
1647 } // namespace cricket 1654 } // namespace cricket
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698