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

Unified Diff: webrtc/p2p/base/p2ptransportchannel.cc

Issue 2099563004: Start ICE connectivity checks as soon as the first pair is pingable. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Start pinging when we first have a connection AND ICE credentials. Created 4 years, 6 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
« no previous file with comments | « webrtc/p2p/base/p2ptransportchannel.h ('k') | webrtc/p2p/base/p2ptransportchannel_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/p2p/base/p2ptransportchannel.cc
diff --git a/webrtc/p2p/base/p2ptransportchannel.cc b/webrtc/p2p/base/p2ptransportchannel.cc
index 1eb63c5e69577269d7f0a8783a37c640246d337f..4d5e629450c8d2c6540fd8e0ad8a69f201a937bc 100644
--- a/webrtc/p2p/base/p2ptransportchannel.cc
+++ b/webrtc/p2p/base/p2ptransportchannel.cc
@@ -154,6 +154,9 @@ void P2PTransportChannel::AddConnection(Connection* connection) {
this, &P2PTransportChannel::OnConnectionDestroyed);
connection->SignalNominated.connect(this, &P2PTransportChannel::OnNominated);
had_connection_ = true;
+ // If this is the first connection and we have remote ICE credentials, we can
+ // start pinging.
+ MaybeStartPinging();
}
// Determines whether we should switch the selected connection to
@@ -288,6 +291,9 @@ void P2PTransportChannel::SetRemoteIceCredentials(const std::string& ice_ufrag,
}
// Updating the remote ICE candidate generation could change the sort order.
RequestSort();
+ // If this is the first time receiving ICE credentials and we already have a
+ // connection (for example, to a prflx candidate), we can start pinging.
+ MaybeStartPinging();
}
void P2PTransportChannel::SetRemoteIceMode(IceMode mode) {
@@ -352,21 +358,10 @@ const IceConfig& P2PTransportChannel::config() const {
return config_;
}
-// Go into the state of processing candidates, and running in general
-void P2PTransportChannel::Connect() {
- ASSERT(worker_thread_ == rtc::Thread::Current());
+void P2PTransportChannel::MaybeStartGathering() {
if (ice_ufrag_.empty() || ice_pwd_.empty()) {
- ASSERT(false);
- LOG(LS_ERROR) << "P2PTransportChannel::Connect: The ice_ufrag_ and the "
- << "ice_pwd_ are not set.";
return;
}
-
- // Start checking and pinging as the ports come in.
- thread()->Post(RTC_FROM_HERE, this, MSG_CHECK_AND_PING);
-}
-
-void P2PTransportChannel::MaybeStartGathering() {
// Start gathering if we never started before, or if an ICE restart occurred.
if (allocator_sessions_.empty() ||
IceCredentialsChanged(allocator_sessions_.back()->ice_ufrag(),
@@ -952,6 +947,23 @@ void P2PTransportChannel::RequestSort() {
}
}
+void P2PTransportChannel::MaybeStartPinging() {
+ if (started_pinging_) {
+ return;
+ }
+
+ int64_t now = rtc::TimeMillis();
+ for (const Connection* c : connections_) {
+ if (IsPingable(c, now)) {
pthatcher1 2016/06/28 01:16:32 Could be slightly more readable with: if (std::no
Taylor Brandstetter 2016/06/28 02:01:42 Done. Though I think: if (any_of) { do_thing();
+ LOG_J(LS_INFO, this) << "Have a pingable connection for the first time; "
+ << "starting to ping.";
+ thread()->Post(RTC_FROM_HERE, this, MSG_CHECK_AND_PING);
+ started_pinging_ = true;
+ return;
+ }
+ }
+}
+
// Compare two connections based on their writing, receiving, and connected
// states.
int P2PTransportChannel::CompareConnectionStates(const Connection* a,
@@ -1426,7 +1438,7 @@ void P2PTransportChannel::OnCheckAndPing() {
// A connection is considered a backup connection if the channel state
// is completed, the connection is not the selected connection and it is active.
-bool P2PTransportChannel::IsBackupConnection(Connection* conn) const {
+bool P2PTransportChannel::IsBackupConnection(const Connection* conn) const {
return state_ == STATE_COMPLETED && conn != selected_connection_ &&
conn->active();
}
@@ -1434,7 +1446,8 @@ bool P2PTransportChannel::IsBackupConnection(Connection* conn) const {
// 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.
-bool P2PTransportChannel::IsPingable(Connection* conn, int64_t now) {
+bool P2PTransportChannel::IsPingable(const Connection* conn,
+ int64_t now) const {
const Candidate& remote = conn->remote_candidate();
// We should never get this far with an empty remote ufrag.
ASSERT(!remote.username().empty());
@@ -1492,8 +1505,9 @@ bool P2PTransportChannel::IsSelectedConnectionPingable(int64_t now) {
return selected_connection_->last_ping_sent() + interval <= now;
}
-int P2PTransportChannel::CalculateActiveWritablePingInterval(Connection* conn,
- int64_t now) {
+int P2PTransportChannel::CalculateActiveWritablePingInterval(
+ const Connection* conn,
+ int64_t now) const {
// Ping each connection at a higher rate at least
// MIN_PINGS_AT_WEAK_PING_INTERVAL times.
if (conn->num_pings_sent() < MIN_PINGS_AT_WEAK_PING_INTERVAL) {
« no previous file with comments | « webrtc/p2p/base/p2ptransportchannel.h ('k') | webrtc/p2p/base/p2ptransportchannel_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698