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

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: Merge with Issue 2009763002. 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 b1de3e91d3d4a3ee5bca7221e515a10c4aae090c..fc494293561d44b0dcf0f81b5b1138dd65cd049c 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
pthatcher1 2016/06/01 23:22:02 first several pings => the first several pings
+// pings will be sent at this rate by default in order for the RTT to converge
pthatcher1 2016/06/01 23:22:02 This is for all connections, not just the best con
+// faster. If it pings too fast, other connections may get starved.
pthatcher1 2016/06/01 23:22:02 Doesn't this apply to all connections, not just th
static const int MAX_CURRENT_STRONG_INTERVAL = 900; // ms
pthatcher1 2016/06/01 23:22:02 This needs to be renamed now. Perhaps: STABLIZIN
+// Writable connections are pinged at a slower rate.
pthatcher1 2016/06/01 23:22:03 once stablized
+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);
@@ -432,11 +435,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;
}
}
@@ -1347,6 +1352,7 @@ void P2PTransportChannel::OnCheckAndPing() {
MarkConnectionPinged(conn);
}
}
+
int delay = std::min(ping_interval, check_receiving_interval_);
thread()->PostDelayed(delay, this, MSG_CHECK_AND_PING);
}
@@ -1358,6 +1364,23 @@ bool P2PTransportChannel::IsBackupConnection(Connection* conn) const {
conn->active();
}
+bool P2PTransportChannel::IsBestConnectionPingable() {
+ if (!best_connection_ || !best_connection_->connected() ||
+ !best_connection_->writable()) {
+ return false;
+ }
+
+ int interval = NeedToPingFast(best_connection_)
+ ? std::min(MAX_CURRENT_STRONG_INTERVAL,
+ config_.writable_connection_ping_interval)
+ : config_.writable_connection_ping_interval;
+ return best_connection_->last_ping_sent() + interval <= rtc::TimeMillis();
+}
+
+bool P2PTransportChannel::NeedToPingFast(Connection* conn) {
pthatcher1 2016/06/01 23:22:02 This the code I wrote below, I think we don't need
honghaiz3 2016/06/02 00:03:57 Cannot do this. If the best_connection becomes un
pthatcher1 2016/06/02 18:03:02 Good catch. How about best_connection_ && best_co
honghaiz3 2016/06/02 19:20:25 That would work. It is more readable although at t
+ return conn->num_pings_sent() <= MIN_PINGS_FOR_RTT_CONVERGENCE;
+}
+
// 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.
@@ -1388,12 +1411,21 @@ bool P2PTransportChannel::IsPingable(Connection* conn, int64_t now) {
return (now >= conn->last_ping_response_received() +
config_.backup_connection_ping_interval);
}
+
pthatcher1 2016/06/01 23:22:02 I think instead of having NeedsToPingFast, we can
honghaiz3 2016/06/02 00:03:57 look good to me. This is just int ping_interval =
honghaiz3 2016/06/02 17:06:25 As I thought more about it, I think it may not be
pthatcher1 2016/06/02 18:03:02 Yes, except you still need the std::min in there i
pthatcher1 2016/06/02 18:03:02 Yes, that's the tradeoff with low-frequency keep-a
honghaiz3 2016/06/02 19:20:25 I did not realize that we may have a case of writa
+ // The connection will ping at a slower rate with two conditions:
+ // 1. The connection is writable.
+ // 2. The connection has sent enough initial pings for RTT to converge.
+ if (conn->writable() && !NeedToPingFast(conn)) {
+ 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
@@ -1401,10 +1433,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