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

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

Issue 2143653005: Dampening connection switch. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: . Created 4 years, 5 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 | « webrtc/p2p/base/port.h ('k') | webrtc/p2p/base/transport.h » ('j') | 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 880 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 void Connection::set_write_state(WriteState value) { 891 void Connection::set_write_state(WriteState value) {
892 WriteState old_value = write_state_; 892 WriteState old_value = write_state_;
893 write_state_ = value; 893 write_state_ = value;
894 if (value != old_value) { 894 if (value != old_value) {
895 LOG_J(LS_VERBOSE, this) << "set_write_state from: " << old_value << " to " 895 LOG_J(LS_VERBOSE, this) << "set_write_state from: " << old_value << " to "
896 << value; 896 << value;
897 SignalStateChange(this); 897 SignalStateChange(this);
898 } 898 }
899 } 899 }
900 900
901 void Connection::set_receiving(bool value) { 901 void Connection::UpdateReceiving(int64_t now) {
902 if (value != receiving_) { 902 bool receiving = now <= last_received() + receiving_timeout_;
903 LOG_J(LS_VERBOSE, this) << "set_receiving to " << value; 903 if (receiving_ == receiving) {
904 receiving_ = value; 904 return;
905 SignalStateChange(this);
906 } 905 }
906 LOG_J(LS_VERBOSE, this) << "set_receiving to " << receiving;
907 receiving_ = receiving;
908 receiving_unchanged_since_ = now;
909 SignalStateChange(this);
907 } 910 }
908 911
909 void Connection::set_state(State state) { 912 void Connection::set_state(State state) {
910 State old_state = state_; 913 State old_state = state_;
911 state_ = state; 914 state_ = state;
912 if (state != old_state) { 915 if (state != old_state) {
913 LOG_J(LS_VERBOSE, this) << "set_state"; 916 LOG_J(LS_VERBOSE, this) << "set_state";
914 } 917 }
915 } 918 }
916 919
(...skipping 24 matching lines...) Expand all
941 } 944 }
942 945
943 void Connection::OnReadPacket( 946 void Connection::OnReadPacket(
944 const char* data, size_t size, const rtc::PacketTime& packet_time) { 947 const char* data, size_t size, const rtc::PacketTime& packet_time) {
945 std::unique_ptr<IceMessage> msg; 948 std::unique_ptr<IceMessage> msg;
946 std::string remote_ufrag; 949 std::string remote_ufrag;
947 const rtc::SocketAddress& addr(remote_candidate_.address()); 950 const rtc::SocketAddress& addr(remote_candidate_.address());
948 if (!port_->GetStunMessage(data, size, addr, &msg, &remote_ufrag)) { 951 if (!port_->GetStunMessage(data, size, addr, &msg, &remote_ufrag)) {
949 // The packet did not parse as a valid STUN message 952 // The packet did not parse as a valid STUN message
950 // This is a data packet, pass it along. 953 // This is a data packet, pass it along.
951 set_receiving(true);
952 last_data_received_ = rtc::TimeMillis(); 954 last_data_received_ = rtc::TimeMillis();
955 UpdateReceiving(last_data_received_);
953 recv_rate_tracker_.AddSamples(size); 956 recv_rate_tracker_.AddSamples(size);
954 SignalReadPacket(this, data, size, packet_time); 957 SignalReadPacket(this, data, size, packet_time);
955 958
956 // If timed out sending writability checks, start up again 959 // If timed out sending writability checks, start up again
957 if (!pruned_ && (write_state_ == STATE_WRITE_TIMEOUT)) { 960 if (!pruned_ && (write_state_ == STATE_WRITE_TIMEOUT)) {
958 LOG(LS_WARNING) << "Received a data packet on a timed-out Connection. " 961 LOG(LS_WARNING) << "Received a data packet on a timed-out Connection. "
959 << "Resetting state to STATE_WRITE_INIT."; 962 << "Resetting state to STATE_WRITE_INIT.";
960 set_write_state(STATE_WRITE_INIT); 963 set_write_state(STATE_WRITE_INIT);
961 } 964 }
962 } else if (!msg) { 965 } else if (!msg) {
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
1158 TooLongWithoutResponse(pings_since_last_response_, 1161 TooLongWithoutResponse(pings_since_last_response_,
1159 CONNECTION_WRITE_TIMEOUT, 1162 CONNECTION_WRITE_TIMEOUT,
1160 now)) { 1163 now)) {
1161 LOG_J(LS_INFO, this) << "Timed out after " 1164 LOG_J(LS_INFO, this) << "Timed out after "
1162 << now - pings_since_last_response_[0].sent_time 1165 << now - pings_since_last_response_[0].sent_time
1163 << " ms without a response" 1166 << " ms without a response"
1164 << ", rtt=" << rtt; 1167 << ", rtt=" << rtt;
1165 set_write_state(STATE_WRITE_TIMEOUT); 1168 set_write_state(STATE_WRITE_TIMEOUT);
1166 } 1169 }
1167 1170
1168 // Check the receiving state. 1171 // Update the receiving state.
1169 int64_t last_recv_time = last_received(); 1172 UpdateReceiving(now);
1170 bool receiving = now <= last_recv_time + receiving_timeout_;
1171 set_receiving(receiving);
1172 if (dead(now)) { 1173 if (dead(now)) {
1173 Destroy(); 1174 Destroy();
1174 } 1175 }
1175 } 1176 }
1176 1177
1177 void Connection::Ping(int64_t now) { 1178 void Connection::Ping(int64_t now) {
1178 last_ping_sent_ = now; 1179 last_ping_sent_ = now;
1179 ConnectionRequest *req = new ConnectionRequest(this); 1180 ConnectionRequest *req = new ConnectionRequest(this);
1180 pings_since_last_response_.push_back(SentPing(req->id(), now)); 1181 pings_since_last_response_.push_back(SentPing(req->id(), now));
1181 LOG_J(LS_VERBOSE, this) << "Sending STUN ping " 1182 LOG_J(LS_VERBOSE, this) << "Sending STUN ping "
1182 << ", id=" << rtc::hex_encode(req->id()); 1183 << ", id=" << rtc::hex_encode(req->id());
1183 requests_.Send(req); 1184 requests_.Send(req);
1184 state_ = STATE_INPROGRESS; 1185 state_ = STATE_INPROGRESS;
1185 num_pings_sent_++; 1186 num_pings_sent_++;
1186 } 1187 }
1187 1188
1188 void Connection::ReceivedPing() { 1189 void Connection::ReceivedPing() {
1189 set_receiving(true);
1190 last_ping_received_ = rtc::TimeMillis(); 1190 last_ping_received_ = rtc::TimeMillis();
1191 UpdateReceiving(last_ping_received_);
1191 } 1192 }
1192 1193
1193 void Connection::ReceivedPingResponse(int rtt) { 1194 void Connection::ReceivedPingResponse(int rtt) {
1194 // We've already validated that this is a STUN binding response with 1195 // We've already validated that this is a STUN binding response with
1195 // the correct local and remote username for this connection. 1196 // the correct local and remote username for this connection.
1196 // So if we're not already, become writable. We may be bringing a pruned 1197 // So if we're not already, become writable. We may be bringing a pruned
1197 // connection back to life, but if we don't really want it, we can always 1198 // connection back to life, but if we don't really want it, we can always
1198 // prune it again. 1199 // prune it again.
1199 set_receiving(true); 1200 last_ping_response_received_ = rtc::TimeMillis();
1201 UpdateReceiving(last_ping_response_received_);
1200 set_write_state(STATE_WRITABLE); 1202 set_write_state(STATE_WRITABLE);
1201 set_state(STATE_SUCCEEDED); 1203 set_state(STATE_SUCCEEDED);
1202 pings_since_last_response_.clear(); 1204 pings_since_last_response_.clear();
1203 last_ping_response_received_ = rtc::TimeMillis();
1204 rtt_samples_++; 1205 rtt_samples_++;
1205 rtt_ = (RTT_RATIO * rtt_ + rtt) / (RTT_RATIO + 1); 1206 rtt_ = (RTT_RATIO * rtt_ + rtt) / (RTT_RATIO + 1);
1206 } 1207 }
1207 1208
1208 bool Connection::dead(int64_t now) const { 1209 bool Connection::dead(int64_t now) const {
1209 if (last_received() > 0) { 1210 if (last_received() > 0) {
1210 // If it has ever received anything, we keep it alive until it hasn't 1211 // If it has ever received anything, we keep it alive until it hasn't
1211 // received anything for DEAD_CONNECTION_RECEIVE_TIMEOUT. This covers the 1212 // received anything for DEAD_CONNECTION_RECEIVE_TIMEOUT. This covers the
1212 // normal case of a successfully used connection that stops working. This 1213 // normal case of a successfully used connection that stops working. This
1213 // also allows a remote peer to continue pinging over a locally inactive 1214 // also allows a remote peer to continue pinging over a locally inactive
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
1529 ASSERT(sent < 0); 1530 ASSERT(sent < 0);
1530 error_ = port_->GetError(); 1531 error_ = port_->GetError();
1531 stats_.sent_discarded_packets++; 1532 stats_.sent_discarded_packets++;
1532 } else { 1533 } else {
1533 send_rate_tracker_.AddSamples(sent); 1534 send_rate_tracker_.AddSamples(sent);
1534 } 1535 }
1535 return sent; 1536 return sent;
1536 } 1537 }
1537 1538
1538 } // namespace cricket 1539 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/p2p/base/port.h ('k') | webrtc/p2p/base/transport.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698