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

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

Issue 1371623003: Delete a connection only if it has timed out on writing and not receiving for 10 seconds. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Rename a test Created 5 years, 3 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/port.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/p2p/base/port.cc
diff --git a/webrtc/p2p/base/port.cc b/webrtc/p2p/base/port.cc
index 842a26e8260df55b740eed7527c13a22698a7309..a5c7770f553d78314df54ebe9c27d0e877762953 100644
--- a/webrtc/p2p/base/port.cc
+++ b/webrtc/p2p/base/port.cc
@@ -801,7 +801,8 @@ Connection::Connection(Port* port,
sent_packets_total_(0),
reported_(false),
state_(STATE_WAITING),
- receiving_timeout_(WEAK_CONNECTION_RECEIVE_TIMEOUT) {
+ receiving_timeout_(WEAK_CONNECTION_RECEIVE_TIMEOUT),
+ time_created_ms_(rtc::Time()) {
// All of our connections start in WAITING state.
// TODO(mallinath) - Start connections from STATE_FROZEN.
// Wire up to send stun packets
@@ -849,7 +850,6 @@ void Connection::set_write_state(WriteState value) {
LOG_J(LS_VERBOSE, this) << "set_write_state from: " << old_value << " to "
<< value;
SignalStateChange(this);
- CheckTimeout();
}
}
@@ -858,7 +858,6 @@ void Connection::set_receiving(bool value) {
LOG_J(LS_VERBOSE, this) << "set_receiving to " << value;
receiving_ = value;
SignalStateChange(this);
- CheckTimeout();
}
}
@@ -999,7 +998,7 @@ void Connection::OnReadyToSend() {
}
void Connection::Prune() {
- if (!pruned_) {
+ if (!pruned_ || active()) {
LOG_J(LS_VERBOSE, this) << "Connection pruned";
pruned_ = true;
requests_.Clear();
@@ -1089,6 +1088,9 @@ void Connection::UpdateState(uint32 now) {
uint32 last_recv_time = last_received();
bool receiving = now <= last_recv_time + receiving_timeout_;
set_receiving(receiving);
+ if (dead(now)) {
+ Destroy();
+ }
}
void Connection::Ping(uint32 now) {
@@ -1119,6 +1121,28 @@ void Connection::ReceivedPingResponse() {
last_ping_response_received_ = rtc::Time();
}
+bool Connection::dead(uint32 now) const {
+ if (now < (time_created_ms_ + MIN_CONNECTION_LIFETIME)) {
+ // A connection that hasn't passed its minimum lifetime is still alive.
+ // We do this to prevent connections from being pruned too quickly
+ // during a network change event when two networks would be up
+ // simultaneously but only for a brief period.
+ return false;
+ }
+
+ if (receiving_) {
+ // A connection that is receiving is alive.
+ return false;
+ }
+
+ // A connection is alive until it is inactive.
+ return !active();
+
+ // TODO(honghaiz): Move from using the write state to using the receiving
+ // state with something like the following:
+ // return (now > (last_received() + DEAD_CONNECTION_RECEIVE_TIMEOUT));
+}
+
std::string Connection::ToDebugId() const {
std::stringstream ss;
ss << std::hex << this;
@@ -1230,7 +1254,7 @@ void Connection::OnConnectionRequestErrorResponse(ConnectionRequest* request,
LOG_J(LS_ERROR, this) << "Received STUN error response, code="
<< error_code << "; killing connection";
set_state(STATE_FAILED);
- set_write_state(STATE_WRITE_TIMEOUT);
+ Destroy();
}
}
@@ -1251,13 +1275,6 @@ void Connection::OnConnectionRequestSent(ConnectionRequest* request) {
<< ", use_candidate=" << use_candidate;
}
-void Connection::CheckTimeout() {
- // If write has timed out and it is not receiving, remove the connection.
- if (!receiving_ && write_state_ == STATE_WRITE_TIMEOUT) {
- Destroy();
- }
-}
-
void Connection::HandleRoleConflictFromPeer() {
port_->SignalRoleConflict(port_);
}
« no previous file with comments | « webrtc/p2p/base/port.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698