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

Unified 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: First Serveral pings are sent at faster rate. 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/p2p/base/p2ptransportchannel.cc
diff --git a/webrtc/p2p/base/p2ptransportchannel.cc b/webrtc/p2p/base/p2ptransportchannel.cc
index 2801c446461679011e091ccd5fd5af46dcb81cdf..fc3c9e6efb7860b171ab7ffbc0d113bce6617d0d 100644
--- a/webrtc/p2p/base/p2ptransportchannel.cc
+++ b/webrtc/p2p/base/p2ptransportchannel.cc
@@ -217,11 +217,14 @@ static const int STRONG_PING_INTERVAL = 1000 * PING_PACKET_SIZE / 1000;
// writable or not receiving.
const int WEAK_PING_INTERVAL = 1000 * PING_PACKET_SIZE / 10000;
-// If the current best connection is both writable and receiving, then we will
-// also try hard to make sure it is pinged at this rate (a little less than
-// 2 * STRONG_PING_INTERVAL).
+// If the current best connection is both writable and receiving, first several
+// pings will be sent at this rate by default. If it pings too fast, other
+// connection may get starved.
Taylor Brandstetter 2016/05/27 20:11:00 "connection" -> "connections" Also, may want to me
static const int MAX_CURRENT_STRONG_INTERVAL = 900; // ms
+// Writable connections are pinged at a slower rate.
+static const int WRITABLE_CONNECTION_PING_INTERVAL = 2500; // ms
+
static const int MIN_CHECK_RECEIVING_INTERVAL = 50; // ms
P2PTransportChannel::P2PTransportChannel(const std::string& transport_name,
@@ -250,7 +253,7 @@ P2PTransportChannel::P2PTransportChannel(const std::string& transport_name,
0 /* backup_connection_ping_interval */,
false /* gather_continually */,
false /* prioritize_most_likely_candidate_pairs */,
- MAX_CURRENT_STRONG_INTERVAL /* max_strong_interval */) {
+ WRITABLE_CONNECTION_PING_INTERVAL) {
uint32_t weak_ping_interval = ::strtoul(
webrtc::field_trial::FindFullName("WebRTC-StunInterPacketDelay").c_str(),
nullptr, 10);
@@ -433,11 +436,13 @@ void P2PTransportChannel::SetIceConfig(const IceConfig& config) {
LOG(LS_INFO) << "Set ping most likely connection to "
<< config_.prioritize_most_likely_candidate_pairs;
- if (config.max_strong_interval >= 0 &&
- config_.max_strong_interval != config.max_strong_interval) {
- config_.max_strong_interval = config.max_strong_interval;
- LOG(LS_INFO) << "Set max strong interval to "
- << config_.max_strong_interval;
+ if (config.writable_connection_ping_interval >= 0 &&
+ config_.writable_connection_ping_interval !=
+ config.writable_connection_ping_interval) {
+ config_.writable_connection_ping_interval =
+ config.writable_connection_ping_interval;
+ LOG(LS_INFO) << "Set writable_connection_ping_interval to "
+ << config_.writable_connection_ping_interval;
}
}
@@ -1307,6 +1312,7 @@ void P2PTransportChannel::OnCheckAndPing() {
MarkConnectionPinged(conn);
}
}
+
int delay = std::min(ping_interval, check_receiving_interval_);
thread()->PostDelayed(delay, this, MSG_CHECK_AND_PING);
}
@@ -1318,6 +1324,27 @@ bool P2PTransportChannel::IsBackupConnection(Connection* conn) const {
conn->active();
}
+bool P2PTransportChannel::IsBestConnectionPingable() {
+ int64_t now = rtc::TimeMillis();
+ bool is_pingable = false;
+ if (best_connection_ && best_connection_->connected() &&
+ best_connection_->writable()) {
+ // The best_connection need to ping at a fast rate.
pthatcher1 2016/05/27 17:36:31 need => needs
+ is_pingable =
+ (best_connection_->NeedToPingFast() &&
+ best_connection_->last_ping_sent() + MAX_CURRENT_STRONG_INTERVAL <=
+ now);
+
+ // After passing writable_connection_ping_interval, the best connection
+ // becomes pingable no matter if it needs to ping fast or not.
+ is_pingable =
+ is_pingable || (best_connection_->last_ping_sent() +
+ config_.writable_connection_ping_interval <=
+ now);
pthatcher1 2016/05/27 17:36:31 This would be more clear with early returns and an
zhihuang1 2016/06/01 21:15:01 writable_connection_ping_interval may be smaller t
+ }
+ return is_pingable;
+}
+
// Is the connection in a state for us to even consider pinging the other side?
// We consider a connection pingable even if it's not connected because that's
// how a TCP connection is kicked into reconnecting on the active side.
@@ -1348,12 +1375,22 @@ bool P2PTransportChannel::IsPingable(Connection* conn, int64_t now) {
return (now >= conn->last_ping_response_received() +
config_.backup_connection_ping_interval);
}
+
+ // The connect will ping at a slower rate with two conditions:
+ // 1. The connection is writable.
+ // 2. The connection is not sending first several pings
Taylor Brandstetter 2016/05/27 20:11:00 "The connect" -> "The connection" "is not sending
+ // (kFirstNPingsWithFastRate)
+ if (conn->writable() && !conn->NeedToPingFast()) {
+ return (now >=
+ conn->last_ping_sent() + config_.writable_connection_ping_interval);
+ }
+
return conn->active();
}
// Returns the next pingable connection to ping. This will be the oldest
// pingable connection unless we have a connected, writable connection that is
-// past the maximum acceptable ping interval. When reconnecting a TCP
+// past the writable ping interval. When reconnecting a TCP
// connection, the best connection is disconnected, although still WRITABLE
// while reconnecting. The newly created connection should be selected as the
// ping target to become writable instead. See the big comment in
@@ -1361,10 +1398,7 @@ bool P2PTransportChannel::IsPingable(Connection* conn, int64_t now) {
Connection* P2PTransportChannel::FindNextPingableConnection() {
int64_t now = rtc::TimeMillis();
Connection* conn_to_ping = nullptr;
- if (best_connection_ && best_connection_->connected() &&
- best_connection_->writable() &&
- (best_connection_->last_ping_sent() + config_.max_strong_interval <=
- now)) {
+ if (IsBestConnectionPingable()) {
conn_to_ping = best_connection_;
} else {
conn_to_ping = FindConnectionToPing(now);

Powered by Google App Engine
This is Rietveld 408576698