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

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

Issue 1793553002: Using 64-bit timestamp in webrtc/p2p (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 9 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/port_unittest.cc » ('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 14 matching lines...) Expand all
25 #include "webrtc/base/stringencode.h" 25 #include "webrtc/base/stringencode.h"
26 #include "webrtc/base/stringutils.h" 26 #include "webrtc/base/stringutils.h"
27 27
28 namespace { 28 namespace {
29 29
30 // Determines whether we have seen at least the given maximum number of 30 // Determines whether we have seen at least the given maximum number of
31 // pings fail to have a response. 31 // pings fail to have a response.
32 inline bool TooManyFailures( 32 inline bool TooManyFailures(
33 const std::vector<cricket::Connection::SentPing>& pings_since_last_response, 33 const std::vector<cricket::Connection::SentPing>& pings_since_last_response,
34 uint32_t maximum_failures, 34 uint32_t maximum_failures,
35 uint32_t rtt_estimate, 35 int rtt_estimate,
36 uint32_t now) { 36 int64_t now) {
37 // If we haven't sent that many pings, then we can't have failed that many. 37 // If we haven't sent that many pings, then we can't have failed that many.
38 if (pings_since_last_response.size() < maximum_failures) 38 if (pings_since_last_response.size() < maximum_failures)
39 return false; 39 return false;
40 40
41 // Check if the window in which we would expect a response to the ping has 41 // Check if the window in which we would expect a response to the ping has
42 // already elapsed. 42 // already elapsed.
43 uint32_t expected_response_time = 43 int64_t expected_response_time =
44 pings_since_last_response[maximum_failures - 1].sent_time + rtt_estimate; 44 pings_since_last_response[maximum_failures - 1].sent_time + rtt_estimate;
45 return now > expected_response_time; 45 return now > expected_response_time;
46 } 46 }
47 47
48 // Determines whether we have gone too long without seeing any response. 48 // Determines whether we have gone too long without seeing any response.
49 inline bool TooLongWithoutResponse( 49 inline bool TooLongWithoutResponse(
50 const std::vector<cricket::Connection::SentPing>& pings_since_last_response, 50 const std::vector<cricket::Connection::SentPing>& pings_since_last_response,
51 uint32_t maximum_time, 51 int64_t maximum_time,
52 uint32_t now) { 52 int64_t now) {
53 if (pings_since_last_response.size() == 0) 53 if (pings_since_last_response.size() == 0)
54 return false; 54 return false;
55 55
56 auto first = pings_since_last_response[0]; 56 auto first = pings_since_last_response[0];
57 return now > (first.sent_time + maximum_time); 57 return now > (first.sent_time + maximum_time);
58 } 58 }
59 59
60 // We will restrict RTT estimates (when used for determining state) to be 60 // We will restrict RTT estimates (when used for determining state) to be
61 // within a reasonable range. 61 // within a reasonable range.
62 const uint32_t MINIMUM_RTT = 100; // 0.1 seconds 62 const int MINIMUM_RTT = 100; // 0.1 seconds
63 const uint32_t MAXIMUM_RTT = 3000; // 3 seconds 63 const int MAXIMUM_RTT = 3000; // 3 seconds
64 64
65 // When we don't have any RTT data, we have to pick something reasonable. We 65 // When we don't have any RTT data, we have to pick something reasonable. We
66 // use a large value just in case the connection is really slow. 66 // use a large value just in case the connection is really slow.
67 const uint32_t DEFAULT_RTT = MAXIMUM_RTT; 67 const int DEFAULT_RTT = MAXIMUM_RTT;
68 68
69 // Computes our estimate of the RTT given the current estimate. 69 // Computes our estimate of the RTT given the current estimate.
70 inline uint32_t ConservativeRTTEstimate(uint32_t rtt) { 70 inline int ConservativeRTTEstimate(int rtt) {
71 return std::max(MINIMUM_RTT, std::min(MAXIMUM_RTT, 2 * rtt)); 71 return std::max(MINIMUM_RTT, std::min(MAXIMUM_RTT, 2 * rtt));
72 } 72 }
73 73
74 // Weighting of the old rtt value to new data. 74 // Weighting of the old rtt value to new data.
75 const int RTT_RATIO = 3; // 3 : 1 75 const int RTT_RATIO = 3; // 3 : 1
76 76
77 // The delay before we begin checking if this port is useless. 77 // The delay before we begin checking if this port is useless.
78 const int kPortTimeoutDelay = 30 * 1000; // 30 seconds 78 const int kPortTimeoutDelay = 30 * 1000; // 30 seconds
79 } 79 }
80 80
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 last_ping_received_(0), 798 last_ping_received_(0),
799 last_data_received_(0), 799 last_data_received_(0),
800 last_ping_response_received_(0), 800 last_ping_response_received_(0),
801 recv_rate_tracker_(100u, 10u), 801 recv_rate_tracker_(100u, 10u),
802 send_rate_tracker_(100u, 10u), 802 send_rate_tracker_(100u, 10u),
803 sent_packets_discarded_(0), 803 sent_packets_discarded_(0),
804 sent_packets_total_(0), 804 sent_packets_total_(0),
805 reported_(false), 805 reported_(false),
806 state_(STATE_WAITING), 806 state_(STATE_WAITING),
807 receiving_timeout_(WEAK_CONNECTION_RECEIVE_TIMEOUT), 807 receiving_timeout_(WEAK_CONNECTION_RECEIVE_TIMEOUT),
808 time_created_ms_(rtc::Time()) { 808 time_created_ms_(rtc::Time64()) {
809 // All of our connections start in WAITING state. 809 // All of our connections start in WAITING state.
810 // TODO(mallinath) - Start connections from STATE_FROZEN. 810 // TODO(mallinath) - Start connections from STATE_FROZEN.
811 // Wire up to send stun packets 811 // Wire up to send stun packets
812 requests_.SignalSendPacket.connect(this, &Connection::OnSendStunPacket); 812 requests_.SignalSendPacket.connect(this, &Connection::OnSendStunPacket);
813 LOG_J(LS_INFO, this) << "Connection created"; 813 LOG_J(LS_INFO, this) << "Connection created";
814 } 814 }
815 815
816 Connection::~Connection() { 816 Connection::~Connection() {
817 } 817 }
818 818
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 899
900 void Connection::OnReadPacket( 900 void Connection::OnReadPacket(
901 const char* data, size_t size, const rtc::PacketTime& packet_time) { 901 const char* data, size_t size, const rtc::PacketTime& packet_time) {
902 rtc::scoped_ptr<IceMessage> msg; 902 rtc::scoped_ptr<IceMessage> msg;
903 std::string remote_ufrag; 903 std::string remote_ufrag;
904 const rtc::SocketAddress& addr(remote_candidate_.address()); 904 const rtc::SocketAddress& addr(remote_candidate_.address());
905 if (!port_->GetStunMessage(data, size, addr, msg.accept(), &remote_ufrag)) { 905 if (!port_->GetStunMessage(data, size, addr, msg.accept(), &remote_ufrag)) {
906 // The packet did not parse as a valid STUN message 906 // The packet did not parse as a valid STUN message
907 // This is a data packet, pass it along. 907 // This is a data packet, pass it along.
908 set_receiving(true); 908 set_receiving(true);
909 last_data_received_ = rtc::Time(); 909 last_data_received_ = rtc::Time64();
910 recv_rate_tracker_.AddSamples(size); 910 recv_rate_tracker_.AddSamples(size);
911 SignalReadPacket(this, data, size, packet_time); 911 SignalReadPacket(this, data, size, packet_time);
912 912
913 // If timed out sending writability checks, start up again 913 // If timed out sending writability checks, start up again
914 if (!pruned_ && (write_state_ == STATE_WRITE_TIMEOUT)) { 914 if (!pruned_ && (write_state_ == STATE_WRITE_TIMEOUT)) {
915 LOG(LS_WARNING) << "Received a data packet on a timed-out Connection. " 915 LOG(LS_WARNING) << "Received a data packet on a timed-out Connection. "
916 << "Resetting state to STATE_WRITE_INIT."; 916 << "Resetting state to STATE_WRITE_INIT.";
917 set_write_state(STATE_WRITE_INIT); 917 set_write_state(STATE_WRITE_INIT);
918 } 918 }
919 } else if (!msg) { 919 } else if (!msg) {
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1037 } 1037 }
1038 oss << "... " << (pings_since_last_response_.size() - max) << " more"; 1038 oss << "... " << (pings_since_last_response_.size() - max) << " more";
1039 } else { 1039 } else {
1040 for (const SentPing& ping : pings_since_last_response_) { 1040 for (const SentPing& ping : pings_since_last_response_) {
1041 oss << rtc::hex_encode(ping.id) << " "; 1041 oss << rtc::hex_encode(ping.id) << " ";
1042 } 1042 }
1043 } 1043 }
1044 *s = oss.str(); 1044 *s = oss.str();
1045 } 1045 }
1046 1046
1047 void Connection::UpdateState(uint32_t now) { 1047 void Connection::UpdateState(int64_t now) {
1048 uint32_t rtt = ConservativeRTTEstimate(rtt_); 1048 int rtt = ConservativeRTTEstimate(rtt_);
1049 1049
1050 if (LOG_CHECK_LEVEL(LS_VERBOSE)) { 1050 if (LOG_CHECK_LEVEL(LS_VERBOSE)) {
1051 std::string pings; 1051 std::string pings;
1052 PrintPingsSinceLastResponse(&pings, 5); 1052 PrintPingsSinceLastResponse(&pings, 5);
1053 LOG_J(LS_VERBOSE, this) << "UpdateState()" 1053 LOG_J(LS_VERBOSE, this) << "UpdateState()"
1054 << ", ms since last received response=" 1054 << ", ms since last received response="
1055 << now - last_ping_response_received_ 1055 << now - last_ping_response_received_
1056 << ", ms since last received data=" 1056 << ", ms since last received data="
1057 << now - last_data_received_ 1057 << now - last_data_received_
1058 << ", rtt=" << rtt 1058 << ", rtt=" << rtt
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1094 CONNECTION_WRITE_TIMEOUT, 1094 CONNECTION_WRITE_TIMEOUT,
1095 now)) { 1095 now)) {
1096 LOG_J(LS_INFO, this) << "Timed out after " 1096 LOG_J(LS_INFO, this) << "Timed out after "
1097 << now - pings_since_last_response_[0].sent_time 1097 << now - pings_since_last_response_[0].sent_time
1098 << " ms without a response" 1098 << " ms without a response"
1099 << ", rtt=" << rtt; 1099 << ", rtt=" << rtt;
1100 set_write_state(STATE_WRITE_TIMEOUT); 1100 set_write_state(STATE_WRITE_TIMEOUT);
1101 } 1101 }
1102 1102
1103 // Check the receiving state. 1103 // Check the receiving state.
1104 uint32_t last_recv_time = last_received(); 1104 int64_t last_recv_time = last_received();
1105 bool receiving = now <= last_recv_time + receiving_timeout_; 1105 bool receiving = now <= last_recv_time + receiving_timeout_;
1106 set_receiving(receiving); 1106 set_receiving(receiving);
1107 if (dead(now)) { 1107 if (dead(now)) {
1108 Destroy(); 1108 Destroy();
1109 } 1109 }
1110 } 1110 }
1111 1111
1112 void Connection::Ping(uint32_t now) { 1112 void Connection::Ping(int64_t now) {
1113 last_ping_sent_ = now; 1113 last_ping_sent_ = now;
1114 ConnectionRequest *req = new ConnectionRequest(this); 1114 ConnectionRequest *req = new ConnectionRequest(this);
1115 pings_since_last_response_.push_back(SentPing(req->id(), now)); 1115 pings_since_last_response_.push_back(SentPing(req->id(), now));
1116 LOG_J(LS_VERBOSE, this) << "Sending STUN ping " 1116 LOG_J(LS_VERBOSE, this) << "Sending STUN ping "
1117 << ", id=" << rtc::hex_encode(req->id()); 1117 << ", id=" << rtc::hex_encode(req->id());
1118 requests_.Send(req); 1118 requests_.Send(req);
1119 state_ = STATE_INPROGRESS; 1119 state_ = STATE_INPROGRESS;
1120 } 1120 }
1121 1121
1122 void Connection::ReceivedPing() { 1122 void Connection::ReceivedPing() {
1123 set_receiving(true); 1123 set_receiving(true);
1124 last_ping_received_ = rtc::Time(); 1124 last_ping_received_ = rtc::Time64();
1125 } 1125 }
1126 1126
1127 void Connection::ReceivedPingResponse() { 1127 void Connection::ReceivedPingResponse() {
1128 // We've already validated that this is a STUN binding response with 1128 // We've already validated that this is a STUN binding response with
1129 // the correct local and remote username for this connection. 1129 // the correct local and remote username for this connection.
1130 // So if we're not already, become writable. We may be bringing a pruned 1130 // So if we're not already, become writable. We may be bringing a pruned
1131 // connection back to life, but if we don't really want it, we can always 1131 // connection back to life, but if we don't really want it, we can always
1132 // prune it again. 1132 // prune it again.
1133 set_receiving(true); 1133 set_receiving(true);
1134 set_write_state(STATE_WRITABLE); 1134 set_write_state(STATE_WRITABLE);
1135 set_state(STATE_SUCCEEDED); 1135 set_state(STATE_SUCCEEDED);
1136 pings_since_last_response_.clear(); 1136 pings_since_last_response_.clear();
1137 last_ping_response_received_ = rtc::Time(); 1137 last_ping_response_received_ = rtc::Time64();
1138 } 1138 }
1139 1139
1140 bool Connection::dead(uint32_t now) const { 1140 bool Connection::dead(int64_t now) const {
1141 if (last_received() > 0) { 1141 if (last_received() > 0) {
1142 // If it has ever received anything, we keep it alive until it hasn't 1142 // If it has ever received anything, we keep it alive until it hasn't
1143 // received anything for DEAD_CONNECTION_RECEIVE_TIMEOUT. This covers the 1143 // received anything for DEAD_CONNECTION_RECEIVE_TIMEOUT. This covers the
1144 // normal case of a successfully used connection that stops working. This 1144 // normal case of a successfully used connection that stops working. This
1145 // also allows a remote peer to continue pinging over a locally inactive 1145 // also allows a remote peer to continue pinging over a locally inactive
1146 // (pruned) connection. 1146 // (pruned) connection.
1147 return (now > (last_received() + DEAD_CONNECTION_RECEIVE_TIMEOUT)); 1147 return (now > (last_received() + DEAD_CONNECTION_RECEIVE_TIMEOUT));
1148 } 1148 }
1149 1149
1150 if (active()) { 1150 if (active()) {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1223 std::string Connection::ToSensitiveString() const { 1223 std::string Connection::ToSensitiveString() const {
1224 return ToString(); 1224 return ToString();
1225 } 1225 }
1226 1226
1227 void Connection::OnConnectionRequestResponse(ConnectionRequest* request, 1227 void Connection::OnConnectionRequestResponse(ConnectionRequest* request,
1228 StunMessage* response) { 1228 StunMessage* response) {
1229 // Log at LS_INFO if we receive a ping response on an unwritable 1229 // Log at LS_INFO if we receive a ping response on an unwritable
1230 // connection. 1230 // connection.
1231 rtc::LoggingSeverity sev = !writable() ? rtc::LS_INFO : rtc::LS_VERBOSE; 1231 rtc::LoggingSeverity sev = !writable() ? rtc::LS_INFO : rtc::LS_VERBOSE;
1232 1232
1233 uint32_t rtt = request->Elapsed(); 1233 int rtt = request->Elapsed();
1234 1234
1235 ReceivedPingResponse(); 1235 ReceivedPingResponse();
1236 1236
1237 if (LOG_CHECK_LEVEL_V(sev)) { 1237 if (LOG_CHECK_LEVEL_V(sev)) {
1238 bool use_candidate = ( 1238 bool use_candidate = (
1239 response->GetByteString(STUN_ATTR_USE_CANDIDATE) != nullptr); 1239 response->GetByteString(STUN_ATTR_USE_CANDIDATE) != nullptr);
1240 std::string pings; 1240 std::string pings;
1241 PrintPingsSinceLastResponse(&pings, 5); 1241 PrintPingsSinceLastResponse(&pings, 5);
1242 LOG_JV(sev, this) << "Received STUN ping response" 1242 LOG_JV(sev, this) << "Received STUN ping response"
1243 << ", id=" << rtc::hex_encode(request->id()) 1243 << ", id=" << rtc::hex_encode(request->id())
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1323 } 1323 }
1324 } 1324 }
1325 1325
1326 void Connection::OnMessage(rtc::Message *pmsg) { 1326 void Connection::OnMessage(rtc::Message *pmsg) {
1327 ASSERT(pmsg->message_id == MSG_DELETE); 1327 ASSERT(pmsg->message_id == MSG_DELETE);
1328 LOG_J(LS_INFO, this) << "Connection deleted"; 1328 LOG_J(LS_INFO, this) << "Connection deleted";
1329 SignalDestroyed(this); 1329 SignalDestroyed(this);
1330 delete this; 1330 delete this;
1331 } 1331 }
1332 1332
1333 uint32_t Connection::last_received() const { 1333 int64_t Connection::last_received() const {
1334 return std::max(last_data_received_, 1334 return std::max(last_data_received_,
1335 std::max(last_ping_received_, last_ping_response_received_)); 1335 std::max(last_ping_received_, last_ping_response_received_));
1336 } 1336 }
1337 1337
1338 size_t Connection::recv_bytes_second() { 1338 size_t Connection::recv_bytes_second() {
1339 return round(recv_rate_tracker_.ComputeRate()); 1339 return round(recv_rate_tracker_.ComputeRate());
1340 } 1340 }
1341 1341
1342 size_t Connection::recv_total_bytes() { 1342 size_t Connection::recv_total_bytes() {
1343 return recv_rate_tracker_.TotalSampleCount(); 1343 return recv_rate_tracker_.TotalSampleCount();
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1443 ASSERT(sent < 0); 1443 ASSERT(sent < 0);
1444 error_ = port_->GetError(); 1444 error_ = port_->GetError();
1445 sent_packets_discarded_++; 1445 sent_packets_discarded_++;
1446 } else { 1446 } else {
1447 send_rate_tracker_.AddSamples(sent); 1447 send_rate_tracker_.AddSamples(sent);
1448 } 1448 }
1449 return sent; 1449 return sent;
1450 } 1450 }
1451 1451
1452 } // namespace cricket 1452 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/p2p/base/port.h ('k') | webrtc/p2p/base/port_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698