OLD | NEW |
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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 // Computes our estimate of the RTT given the current estimate. | 68 // Computes our estimate of the RTT given the current estimate. |
69 inline int ConservativeRTTEstimate(int rtt) { | 69 inline int ConservativeRTTEstimate(int rtt) { |
70 return std::max(MINIMUM_RTT, std::min(MAXIMUM_RTT, 2 * rtt)); | 70 return std::max(MINIMUM_RTT, std::min(MAXIMUM_RTT, 2 * rtt)); |
71 } | 71 } |
72 | 72 |
73 // Weighting of the old rtt value to new data. | 73 // Weighting of the old rtt value to new data. |
74 const int RTT_RATIO = 3; // 3 : 1 | 74 const int RTT_RATIO = 3; // 3 : 1 |
75 | 75 |
76 // The delay before we begin checking if this port is useless. | 76 // The delay before we begin checking if this port is useless. |
77 const int kPortTimeoutDelay = 30 * 1000; // 30 seconds | 77 const int kPortTimeoutDelay = 30 * 1000; // 30 seconds |
| 78 |
| 79 // First N Pings are sent at a fast rate. |
| 80 const int kFirstNPingsWithFastRate = 10; |
78 } | 81 } |
79 | 82 |
80 namespace cricket { | 83 namespace cricket { |
81 | 84 |
82 // TODO(ronghuawu): Use "host", "srflx", "prflx" and "relay". But this requires | 85 // TODO(ronghuawu): Use "host", "srflx", "prflx" and "relay". But this requires |
83 // the signaling part be updated correspondingly as well. | 86 // the signaling part be updated correspondingly as well. |
84 const char LOCAL_PORT_TYPE[] = "local"; | 87 const char LOCAL_PORT_TYPE[] = "local"; |
85 const char STUN_PORT_TYPE[] = "stun"; | 88 const char STUN_PORT_TYPE[] = "stun"; |
86 const char PRFLX_PORT_TYPE[] = "prflx"; | 89 const char PRFLX_PORT_TYPE[] = "prflx"; |
87 const char RELAY_PORT_TYPE[] = "relay"; | 90 const char RELAY_PORT_TYPE[] = "relay"; |
(...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
802 last_ping_received_(0), | 805 last_ping_received_(0), |
803 last_data_received_(0), | 806 last_data_received_(0), |
804 last_ping_response_received_(0), | 807 last_ping_response_received_(0), |
805 recv_rate_tracker_(100, 10u), | 808 recv_rate_tracker_(100, 10u), |
806 send_rate_tracker_(100, 10u), | 809 send_rate_tracker_(100, 10u), |
807 sent_packets_discarded_(0), | 810 sent_packets_discarded_(0), |
808 sent_packets_total_(0), | 811 sent_packets_total_(0), |
809 reported_(false), | 812 reported_(false), |
810 state_(STATE_WAITING), | 813 state_(STATE_WAITING), |
811 receiving_timeout_(WEAK_CONNECTION_RECEIVE_TIMEOUT), | 814 receiving_timeout_(WEAK_CONNECTION_RECEIVE_TIMEOUT), |
812 time_created_ms_(rtc::TimeMillis()) { | 815 time_created_ms_(rtc::TimeMillis()), |
| 816 ping_sent_count_(0) { |
813 // All of our connections start in WAITING state. | 817 // All of our connections start in WAITING state. |
814 // TODO(mallinath) - Start connections from STATE_FROZEN. | 818 // TODO(mallinath) - Start connections from STATE_FROZEN. |
815 // Wire up to send stun packets | 819 // Wire up to send stun packets |
816 requests_.SignalSendPacket.connect(this, &Connection::OnSendStunPacket); | 820 requests_.SignalSendPacket.connect(this, &Connection::OnSendStunPacket); |
817 LOG_J(LS_INFO, this) << "Connection created"; | 821 LOG_J(LS_INFO, this) << "Connection created"; |
818 } | 822 } |
819 | 823 |
820 Connection::~Connection() { | 824 Connection::~Connection() { |
821 } | 825 } |
822 | 826 |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1118 } | 1122 } |
1119 | 1123 |
1120 void Connection::Ping(int64_t now) { | 1124 void Connection::Ping(int64_t now) { |
1121 last_ping_sent_ = now; | 1125 last_ping_sent_ = now; |
1122 ConnectionRequest *req = new ConnectionRequest(this); | 1126 ConnectionRequest *req = new ConnectionRequest(this); |
1123 pings_since_last_response_.push_back(SentPing(req->id(), now)); | 1127 pings_since_last_response_.push_back(SentPing(req->id(), now)); |
1124 LOG_J(LS_VERBOSE, this) << "Sending STUN ping " | 1128 LOG_J(LS_VERBOSE, this) << "Sending STUN ping " |
1125 << ", id=" << rtc::hex_encode(req->id()); | 1129 << ", id=" << rtc::hex_encode(req->id()); |
1126 requests_.Send(req); | 1130 requests_.Send(req); |
1127 state_ = STATE_INPROGRESS; | 1131 state_ = STATE_INPROGRESS; |
| 1132 ping_sent_count_++; |
1128 } | 1133 } |
1129 | 1134 |
1130 void Connection::ReceivedPing() { | 1135 void Connection::ReceivedPing() { |
1131 set_receiving(true); | 1136 set_receiving(true); |
1132 last_ping_received_ = rtc::TimeMillis(); | 1137 last_ping_received_ = rtc::TimeMillis(); |
1133 } | 1138 } |
1134 | 1139 |
1135 void Connection::ReceivedPingResponse() { | 1140 void Connection::ReceivedPingResponse() { |
1136 // We've already validated that this is a STUN binding response with | 1141 // We've already validated that this is a STUN binding response with |
1137 // the correct local and remote username for this connection. | 1142 // the correct local and remote username for this connection. |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1346 LOG_J(LS_INFO, this) << "Connection deleted"; | 1351 LOG_J(LS_INFO, this) << "Connection deleted"; |
1347 SignalDestroyed(this); | 1352 SignalDestroyed(this); |
1348 delete this; | 1353 delete this; |
1349 } | 1354 } |
1350 | 1355 |
1351 int64_t Connection::last_received() const { | 1356 int64_t Connection::last_received() const { |
1352 return std::max(last_data_received_, | 1357 return std::max(last_data_received_, |
1353 std::max(last_ping_received_, last_ping_response_received_)); | 1358 std::max(last_ping_received_, last_ping_response_received_)); |
1354 } | 1359 } |
1355 | 1360 |
| 1361 bool Connection::NeedToPingFast() { |
| 1362 return ping_sent_count_ <= kFirstNPingsWithFastRate; |
| 1363 } |
| 1364 |
1356 size_t Connection::recv_bytes_second() { | 1365 size_t Connection::recv_bytes_second() { |
1357 return round(recv_rate_tracker_.ComputeRate()); | 1366 return round(recv_rate_tracker_.ComputeRate()); |
1358 } | 1367 } |
1359 | 1368 |
1360 size_t Connection::recv_total_bytes() { | 1369 size_t Connection::recv_total_bytes() { |
1361 return recv_rate_tracker_.TotalSampleCount(); | 1370 return recv_rate_tracker_.TotalSampleCount(); |
1362 } | 1371 } |
1363 | 1372 |
1364 size_t Connection::sent_bytes_second() { | 1373 size_t Connection::sent_bytes_second() { |
1365 return round(send_rate_tracker_.ComputeRate()); | 1374 return round(send_rate_tracker_.ComputeRate()); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1462 ASSERT(sent < 0); | 1471 ASSERT(sent < 0); |
1463 error_ = port_->GetError(); | 1472 error_ = port_->GetError(); |
1464 sent_packets_discarded_++; | 1473 sent_packets_discarded_++; |
1465 } else { | 1474 } else { |
1466 send_rate_tracker_.AddSamples(sent); | 1475 send_rate_tracker_.AddSamples(sent); |
1467 } | 1476 } |
1468 return sent; | 1477 return sent; |
1469 } | 1478 } |
1470 | 1479 |
1471 } // namespace cricket | 1480 } // namespace cricket |
OLD | NEW |