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

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

Issue 1362503003: Use suffixed {uint,int}{8,16,32,64}_t types. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: google::int32 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 unified diff | Download patch
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 12 matching lines...) Expand all
23 #include "webrtc/base/scoped_ptr.h" 23 #include "webrtc/base/scoped_ptr.h"
24 #include "webrtc/base/stringencode.h" 24 #include "webrtc/base/stringencode.h"
25 #include "webrtc/base/stringutils.h" 25 #include "webrtc/base/stringutils.h"
26 26
27 namespace { 27 namespace {
28 28
29 // Determines whether we have seen at least the given maximum number of 29 // Determines whether we have seen at least the given maximum number of
30 // pings fail to have a response. 30 // pings fail to have a response.
31 inline bool TooManyFailures( 31 inline bool TooManyFailures(
32 const std::vector<cricket::Connection::SentPing>& pings_since_last_response, 32 const std::vector<cricket::Connection::SentPing>& pings_since_last_response,
33 uint32 maximum_failures, 33 uint32_t maximum_failures,
34 uint32 rtt_estimate, 34 uint32_t rtt_estimate,
35 uint32 now) { 35 uint32_t now) {
36
37 // If we haven't sent that many pings, then we can't have failed that many. 36 // 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) 37 if (pings_since_last_response.size() < maximum_failures)
39 return false; 38 return false;
40 39
41 // Check if the window in which we would expect a response to the ping has 40 // Check if the window in which we would expect a response to the ping has
42 // already elapsed. 41 // already elapsed.
43 uint32 expected_response_time = 42 uint32_t expected_response_time =
44 pings_since_last_response[maximum_failures - 1].sent_time + rtt_estimate; 43 pings_since_last_response[maximum_failures - 1].sent_time + rtt_estimate;
45 return now > expected_response_time; 44 return now > expected_response_time;
46 } 45 }
47 46
48 // Determines whether we have gone too long without seeing any response. 47 // Determines whether we have gone too long without seeing any response.
49 inline bool TooLongWithoutResponse( 48 inline bool TooLongWithoutResponse(
50 const std::vector<cricket::Connection::SentPing>& pings_since_last_response, 49 const std::vector<cricket::Connection::SentPing>& pings_since_last_response,
51 uint32 maximum_time, 50 uint32_t maximum_time,
52 uint32 now) { 51 uint32_t now) {
53
54 if (pings_since_last_response.size() == 0) 52 if (pings_since_last_response.size() == 0)
55 return false; 53 return false;
56 54
57 auto first = pings_since_last_response[0]; 55 auto first = pings_since_last_response[0];
58 return now > (first.sent_time + maximum_time); 56 return now > (first.sent_time + maximum_time);
59 } 57 }
60 58
61 // We will restrict RTT estimates (when used for determining state) to be 59 // We will restrict RTT estimates (when used for determining state) to be
62 // within a reasonable range. 60 // within a reasonable range.
63 const uint32 MINIMUM_RTT = 100; // 0.1 seconds 61 const uint32_t MINIMUM_RTT = 100; // 0.1 seconds
64 const uint32 MAXIMUM_RTT = 3000; // 3 seconds 62 const uint32_t MAXIMUM_RTT = 3000; // 3 seconds
65 63
66 // When we don't have any RTT data, we have to pick something reasonable. We 64 // When we don't have any RTT data, we have to pick something reasonable. We
67 // use a large value just in case the connection is really slow. 65 // use a large value just in case the connection is really slow.
68 const uint32 DEFAULT_RTT = MAXIMUM_RTT; 66 const uint32_t DEFAULT_RTT = MAXIMUM_RTT;
69 67
70 // Computes our estimate of the RTT given the current estimate. 68 // Computes our estimate of the RTT given the current estimate.
71 inline uint32 ConservativeRTTEstimate(uint32 rtt) { 69 inline uint32_t ConservativeRTTEstimate(uint32_t rtt) {
72 return std::max(MINIMUM_RTT, std::min(MAXIMUM_RTT, 2 * rtt)); 70 return std::max(MINIMUM_RTT, std::min(MAXIMUM_RTT, 2 * rtt));
73 } 71 }
74 72
75 // Weighting of the old rtt value to new data. 73 // Weighting of the old rtt value to new data.
76 const int RTT_RATIO = 3; // 3 : 1 74 const int RTT_RATIO = 3; // 3 : 1
77 75
78 // The delay before we begin checking if this port is useless. 76 // The delay before we begin checking if this port is useless.
79 const int kPortTimeoutDelay = 30 * 1000; // 30 seconds 77 const int kPortTimeoutDelay = 30 * 1000; // 30 seconds
80 } 78 }
81 79
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 // etc.), and STUN or TURN server. If any of these are different, 119 // etc.), and STUN or TURN server. If any of these are different,
122 // then the foundation will be different. Two candidate pairs with 120 // then the foundation will be different. Two candidate pairs with
123 // the same foundation pairs are likely to have similar network 121 // the same foundation pairs are likely to have similar network
124 // characteristics. Foundations are used in the frozen algorithm. 122 // characteristics. Foundations are used in the frozen algorithm.
125 static std::string ComputeFoundation( 123 static std::string ComputeFoundation(
126 const std::string& type, 124 const std::string& type,
127 const std::string& protocol, 125 const std::string& protocol,
128 const rtc::SocketAddress& base_address) { 126 const rtc::SocketAddress& base_address) {
129 std::ostringstream ost; 127 std::ostringstream ost;
130 ost << type << base_address.ipaddr().ToString() << protocol; 128 ost << type << base_address.ipaddr().ToString() << protocol;
131 return rtc::ToString<uint32>(rtc::ComputeCrc32(ost.str())); 129 return rtc::ToString<uint32_t>(rtc::ComputeCrc32(ost.str()));
132 } 130 }
133 131
134 Port::Port(rtc::Thread* thread, 132 Port::Port(rtc::Thread* thread,
135 rtc::PacketSocketFactory* factory, 133 rtc::PacketSocketFactory* factory,
136 rtc::Network* network, 134 rtc::Network* network,
137 const rtc::IPAddress& ip, 135 const rtc::IPAddress& ip,
138 const std::string& username_fragment, 136 const std::string& username_fragment,
139 const std::string& password) 137 const std::string& password)
140 : thread_(thread), 138 : thread_(thread),
141 factory_(factory), 139 factory_(factory),
(...skipping 13 matching lines...) Expand all
155 shared_socket_(true), 153 shared_socket_(true),
156 candidate_filter_(CF_ALL) { 154 candidate_filter_(CF_ALL) {
157 Construct(); 155 Construct();
158 } 156 }
159 157
160 Port::Port(rtc::Thread* thread, 158 Port::Port(rtc::Thread* thread,
161 const std::string& type, 159 const std::string& type,
162 rtc::PacketSocketFactory* factory, 160 rtc::PacketSocketFactory* factory,
163 rtc::Network* network, 161 rtc::Network* network,
164 const rtc::IPAddress& ip, 162 const rtc::IPAddress& ip,
165 uint16 min_port, 163 uint16_t min_port,
166 uint16 max_port, 164 uint16_t max_port,
167 const std::string& username_fragment, 165 const std::string& username_fragment,
168 const std::string& password) 166 const std::string& password)
169 : thread_(thread), 167 : thread_(thread),
170 factory_(factory), 168 factory_(factory),
171 type_(type), 169 type_(type),
172 send_retransmit_count_attribute_(false), 170 send_retransmit_count_attribute_(false),
173 network_(network), 171 network_(network),
174 ip_(ip), 172 ip_(ip),
175 min_port_(min_port), 173 min_port_(min_port),
176 max_port_(max_port), 174 max_port_(max_port),
(...skipping 28 matching lines...) Expand all
205 // because each deletion will cause it to be modified. 203 // because each deletion will cause it to be modified.
206 204
207 std::vector<Connection*> list; 205 std::vector<Connection*> list;
208 206
209 AddressMap::iterator iter = connections_.begin(); 207 AddressMap::iterator iter = connections_.begin();
210 while (iter != connections_.end()) { 208 while (iter != connections_.end()) {
211 list.push_back(iter->second); 209 list.push_back(iter->second);
212 ++iter; 210 ++iter;
213 } 211 }
214 212
215 for (uint32 i = 0; i < list.size(); i++) 213 for (uint32_t i = 0; i < list.size(); i++)
216 delete list[i]; 214 delete list[i];
217 } 215 }
218 216
219 Connection* Port::GetConnection(const rtc::SocketAddress& remote_addr) { 217 Connection* Port::GetConnection(const rtc::SocketAddress& remote_addr) {
220 AddressMap::const_iterator iter = connections_.find(remote_addr); 218 AddressMap::const_iterator iter = connections_.find(remote_addr);
221 if (iter != connections_.end()) 219 if (iter != connections_.end())
222 return iter->second; 220 return iter->second;
223 else 221 else
224 return NULL; 222 return NULL;
225 } 223 }
226 224
227 void Port::AddAddress(const rtc::SocketAddress& address, 225 void Port::AddAddress(const rtc::SocketAddress& address,
228 const rtc::SocketAddress& base_address, 226 const rtc::SocketAddress& base_address,
229 const rtc::SocketAddress& related_address, 227 const rtc::SocketAddress& related_address,
230 const std::string& protocol, 228 const std::string& protocol,
231 const std::string& relay_protocol, 229 const std::string& relay_protocol,
232 const std::string& tcptype, 230 const std::string& tcptype,
233 const std::string& type, 231 const std::string& type,
234 uint32 type_preference, 232 uint32_t type_preference,
235 uint32 relay_preference, 233 uint32_t relay_preference,
236 bool final) { 234 bool final) {
237 if (protocol == TCP_PROTOCOL_NAME && type == LOCAL_PORT_TYPE) { 235 if (protocol == TCP_PROTOCOL_NAME && type == LOCAL_PORT_TYPE) {
238 ASSERT(!tcptype.empty()); 236 ASSERT(!tcptype.empty());
239 } 237 }
240 238
241 Candidate c; 239 Candidate c;
242 c.set_id(rtc::CreateRandomString(8)); 240 c.set_id(rtc::CreateRandomString(8));
243 c.set_component(component_); 241 c.set_component(component_);
244 c.set_type(type); 242 c.set_type(type);
245 c.set_protocol(protocol); 243 c.set_protocol(protocol);
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 *remote_ufrag = username.substr(colon_pos + 1, username.size()); 456 *remote_ufrag = username.substr(colon_pos + 1, username.size());
459 return true; 457 return true;
460 } 458 }
461 459
462 bool Port::MaybeIceRoleConflict( 460 bool Port::MaybeIceRoleConflict(
463 const rtc::SocketAddress& addr, IceMessage* stun_msg, 461 const rtc::SocketAddress& addr, IceMessage* stun_msg,
464 const std::string& remote_ufrag) { 462 const std::string& remote_ufrag) {
465 // Validate ICE_CONTROLLING or ICE_CONTROLLED attributes. 463 // Validate ICE_CONTROLLING or ICE_CONTROLLED attributes.
466 bool ret = true; 464 bool ret = true;
467 IceRole remote_ice_role = ICEROLE_UNKNOWN; 465 IceRole remote_ice_role = ICEROLE_UNKNOWN;
468 uint64 remote_tiebreaker = 0; 466 uint64_t remote_tiebreaker = 0;
469 const StunUInt64Attribute* stun_attr = 467 const StunUInt64Attribute* stun_attr =
470 stun_msg->GetUInt64(STUN_ATTR_ICE_CONTROLLING); 468 stun_msg->GetUInt64(STUN_ATTR_ICE_CONTROLLING);
471 if (stun_attr) { 469 if (stun_attr) {
472 remote_ice_role = ICEROLE_CONTROLLING; 470 remote_ice_role = ICEROLE_CONTROLLING;
473 remote_tiebreaker = stun_attr->value(); 471 remote_tiebreaker = stun_attr->value();
474 } 472 }
475 473
476 // If |remote_ufrag| is same as port local username fragment and 474 // If |remote_ufrag| is same as port local username fragment and
477 // tie breaker value received in the ping message matches port 475 // tie breaker value received in the ping message matches port
478 // tiebreaker value this must be a loopback call. 476 // tiebreaker value this must be a loopback call.
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 std::string username; 695 std::string username;
698 connection_->port()->CreateStunUsername( 696 connection_->port()->CreateStunUsername(
699 connection_->remote_candidate().username(), &username); 697 connection_->remote_candidate().username(), &username);
700 request->AddAttribute( 698 request->AddAttribute(
701 new StunByteStringAttribute(STUN_ATTR_USERNAME, username)); 699 new StunByteStringAttribute(STUN_ATTR_USERNAME, username));
702 700
703 // connection_ already holds this ping, so subtract one from count. 701 // connection_ already holds this ping, so subtract one from count.
704 if (connection_->port()->send_retransmit_count_attribute()) { 702 if (connection_->port()->send_retransmit_count_attribute()) {
705 request->AddAttribute(new StunUInt32Attribute( 703 request->AddAttribute(new StunUInt32Attribute(
706 STUN_ATTR_RETRANSMIT_COUNT, 704 STUN_ATTR_RETRANSMIT_COUNT,
707 static_cast<uint32>( 705 static_cast<uint32_t>(connection_->pings_since_last_response_.size() -
708 connection_->pings_since_last_response_.size() - 1))); 706 1)));
709 } 707 }
710 708
711 // Adding ICE_CONTROLLED or ICE_CONTROLLING attribute based on the role. 709 // Adding ICE_CONTROLLED or ICE_CONTROLLING attribute based on the role.
712 if (connection_->port()->GetIceRole() == ICEROLE_CONTROLLING) { 710 if (connection_->port()->GetIceRole() == ICEROLE_CONTROLLING) {
713 request->AddAttribute(new StunUInt64Attribute( 711 request->AddAttribute(new StunUInt64Attribute(
714 STUN_ATTR_ICE_CONTROLLING, connection_->port()->IceTiebreaker())); 712 STUN_ATTR_ICE_CONTROLLING, connection_->port()->IceTiebreaker()));
715 // Since we are trying aggressive nomination, sending USE-CANDIDATE 713 // Since we are trying aggressive nomination, sending USE-CANDIDATE
716 // attribute in every ping. 714 // attribute in every ping.
717 // If we are dealing with a ice-lite end point, nomination flag 715 // If we are dealing with a ice-lite end point, nomination flag
718 // in Connection will be set to false by default. Once the connection 716 // in Connection will be set to false by default. Once the connection
719 // becomes "best connection", nomination flag will be turned on. 717 // becomes "best connection", nomination flag will be turned on.
720 if (connection_->use_candidate_attr()) { 718 if (connection_->use_candidate_attr()) {
721 request->AddAttribute(new StunByteStringAttribute( 719 request->AddAttribute(new StunByteStringAttribute(
722 STUN_ATTR_USE_CANDIDATE)); 720 STUN_ATTR_USE_CANDIDATE));
723 } 721 }
724 } else if (connection_->port()->GetIceRole() == ICEROLE_CONTROLLED) { 722 } else if (connection_->port()->GetIceRole() == ICEROLE_CONTROLLED) {
725 request->AddAttribute(new StunUInt64Attribute( 723 request->AddAttribute(new StunUInt64Attribute(
726 STUN_ATTR_ICE_CONTROLLED, connection_->port()->IceTiebreaker())); 724 STUN_ATTR_ICE_CONTROLLED, connection_->port()->IceTiebreaker()));
727 } else { 725 } else {
728 ASSERT(false); 726 ASSERT(false);
729 } 727 }
730 728
731 // Adding PRIORITY Attribute. 729 // Adding PRIORITY Attribute.
732 // Changing the type preference to Peer Reflexive and local preference 730 // Changing the type preference to Peer Reflexive and local preference
733 // and component id information is unchanged from the original priority. 731 // and component id information is unchanged from the original priority.
734 // priority = (2^24)*(type preference) + 732 // priority = (2^24)*(type preference) +
735 // (2^8)*(local preference) + 733 // (2^8)*(local preference) +
736 // (2^0)*(256 - component ID) 734 // (2^0)*(256 - component ID)
737 uint32 prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24 | 735 uint32_t prflx_priority =
736 ICE_TYPE_PREFERENCE_PRFLX << 24 |
738 (connection_->local_candidate().priority() & 0x00FFFFFF); 737 (connection_->local_candidate().priority() & 0x00FFFFFF);
739 request->AddAttribute( 738 request->AddAttribute(
740 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority)); 739 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority));
741 740
742 // Adding Message Integrity attribute. 741 // Adding Message Integrity attribute.
743 request->AddMessageIntegrity(connection_->remote_candidate().password()); 742 request->AddMessageIntegrity(connection_->remote_candidate().password());
744 // Adding Fingerprint. 743 // Adding Fingerprint.
745 request->AddFingerprint(); 744 request->AddFingerprint();
746 } 745 }
747 746
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 } 809 }
811 810
812 Connection::~Connection() { 811 Connection::~Connection() {
813 } 812 }
814 813
815 const Candidate& Connection::local_candidate() const { 814 const Candidate& Connection::local_candidate() const {
816 ASSERT(local_candidate_index_ < port_->Candidates().size()); 815 ASSERT(local_candidate_index_ < port_->Candidates().size());
817 return port_->Candidates()[local_candidate_index_]; 816 return port_->Candidates()[local_candidate_index_];
818 } 817 }
819 818
820 uint64 Connection::priority() const { 819 uint64_t Connection::priority() const {
821 uint64 priority = 0; 820 uint64_t priority = 0;
822 // RFC 5245 - 5.7.2. Computing Pair Priority and Ordering Pairs 821 // RFC 5245 - 5.7.2. Computing Pair Priority and Ordering Pairs
823 // Let G be the priority for the candidate provided by the controlling 822 // Let G be the priority for the candidate provided by the controlling
824 // agent. Let D be the priority for the candidate provided by the 823 // agent. Let D be the priority for the candidate provided by the
825 // controlled agent. 824 // controlled agent.
826 // pair priority = 2^32*MIN(G,D) + 2*MAX(G,D) + (G>D?1:0) 825 // pair priority = 2^32*MIN(G,D) + 2*MAX(G,D) + (G>D?1:0)
827 IceRole role = port_->GetIceRole(); 826 IceRole role = port_->GetIceRole();
828 if (role != ICEROLE_UNKNOWN) { 827 if (role != ICEROLE_UNKNOWN) {
829 uint32 g = 0; 828 uint32_t g = 0;
830 uint32 d = 0; 829 uint32_t d = 0;
831 if (role == ICEROLE_CONTROLLING) { 830 if (role == ICEROLE_CONTROLLING) {
832 g = local_candidate().priority(); 831 g = local_candidate().priority();
833 d = remote_candidate_.priority(); 832 d = remote_candidate_.priority();
834 } else { 833 } else {
835 g = remote_candidate_.priority(); 834 g = remote_candidate_.priority();
836 d = local_candidate().priority(); 835 d = local_candidate().priority();
837 } 836 }
838 priority = std::min(g, d); 837 priority = std::min(g, d);
839 priority = priority << 32; 838 priority = priority << 32;
840 priority += 2 * std::max(g, d) + (g > d ? 1 : 0); 839 priority += 2 * std::max(g, d) + (g > d ? 1 : 0);
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
1022 } 1021 }
1023 oss << "... " << (pings_since_last_response_.size() - max) << " more"; 1022 oss << "... " << (pings_since_last_response_.size() - max) << " more";
1024 } else { 1023 } else {
1025 for (const SentPing& ping : pings_since_last_response_) { 1024 for (const SentPing& ping : pings_since_last_response_) {
1026 oss << rtc::hex_encode(ping.id) << " "; 1025 oss << rtc::hex_encode(ping.id) << " ";
1027 } 1026 }
1028 } 1027 }
1029 *s = oss.str(); 1028 *s = oss.str();
1030 } 1029 }
1031 1030
1032 void Connection::UpdateState(uint32 now) { 1031 void Connection::UpdateState(uint32_t now) {
1033 uint32 rtt = ConservativeRTTEstimate(rtt_); 1032 uint32_t rtt = ConservativeRTTEstimate(rtt_);
1034 1033
1035 if (LOG_CHECK_LEVEL(LS_VERBOSE)) { 1034 if (LOG_CHECK_LEVEL(LS_VERBOSE)) {
1036 std::string pings; 1035 std::string pings;
1037 PrintPingsSinceLastResponse(&pings, 5); 1036 PrintPingsSinceLastResponse(&pings, 5);
1038 LOG_J(LS_VERBOSE, this) << "UpdateState()" 1037 LOG_J(LS_VERBOSE, this) << "UpdateState()"
1039 << ", ms since last received response=" 1038 << ", ms since last received response="
1040 << now - last_ping_response_received_ 1039 << now - last_ping_response_received_
1041 << ", ms since last received data=" 1040 << ", ms since last received data="
1042 << now - last_data_received_ 1041 << now - last_data_received_
1043 << ", rtt=" << rtt 1042 << ", rtt=" << rtt
(...skipping 10 matching lines...) Expand all
1054 // allow for changes in network conditions. 1053 // allow for changes in network conditions.
1055 1054
1056 if ((write_state_ == STATE_WRITABLE) && 1055 if ((write_state_ == STATE_WRITABLE) &&
1057 TooManyFailures(pings_since_last_response_, 1056 TooManyFailures(pings_since_last_response_,
1058 CONNECTION_WRITE_CONNECT_FAILURES, 1057 CONNECTION_WRITE_CONNECT_FAILURES,
1059 rtt, 1058 rtt,
1060 now) && 1059 now) &&
1061 TooLongWithoutResponse(pings_since_last_response_, 1060 TooLongWithoutResponse(pings_since_last_response_,
1062 CONNECTION_WRITE_CONNECT_TIMEOUT, 1061 CONNECTION_WRITE_CONNECT_TIMEOUT,
1063 now)) { 1062 now)) {
1064 uint32 max_pings = CONNECTION_WRITE_CONNECT_FAILURES; 1063 uint32_t max_pings = CONNECTION_WRITE_CONNECT_FAILURES;
1065 LOG_J(LS_INFO, this) << "Unwritable after " << max_pings 1064 LOG_J(LS_INFO, this) << "Unwritable after " << max_pings
1066 << " ping failures and " 1065 << " ping failures and "
1067 << now - pings_since_last_response_[0].sent_time 1066 << now - pings_since_last_response_[0].sent_time
1068 << " ms without a response," 1067 << " ms without a response,"
1069 << " ms since last received ping=" 1068 << " ms since last received ping="
1070 << now - last_ping_received_ 1069 << now - last_ping_received_
1071 << " ms since last received data=" 1070 << " ms since last received data="
1072 << now - last_data_received_ 1071 << now - last_data_received_
1073 << " rtt=" << rtt; 1072 << " rtt=" << rtt;
1074 set_write_state(STATE_WRITE_UNRELIABLE); 1073 set_write_state(STATE_WRITE_UNRELIABLE);
1075 } 1074 }
1076 if ((write_state_ == STATE_WRITE_UNRELIABLE || 1075 if ((write_state_ == STATE_WRITE_UNRELIABLE ||
1077 write_state_ == STATE_WRITE_INIT) && 1076 write_state_ == STATE_WRITE_INIT) &&
1078 TooLongWithoutResponse(pings_since_last_response_, 1077 TooLongWithoutResponse(pings_since_last_response_,
1079 CONNECTION_WRITE_TIMEOUT, 1078 CONNECTION_WRITE_TIMEOUT,
1080 now)) { 1079 now)) {
1081 LOG_J(LS_INFO, this) << "Timed out after " 1080 LOG_J(LS_INFO, this) << "Timed out after "
1082 << now - pings_since_last_response_[0].sent_time 1081 << now - pings_since_last_response_[0].sent_time
1083 << " ms without a response" 1082 << " ms without a response"
1084 << ", rtt=" << rtt; 1083 << ", rtt=" << rtt;
1085 set_write_state(STATE_WRITE_TIMEOUT); 1084 set_write_state(STATE_WRITE_TIMEOUT);
1086 } 1085 }
1087 1086
1088 // Check the receiving state. 1087 // Check the receiving state.
1089 uint32 last_recv_time = last_received(); 1088 uint32_t last_recv_time = last_received();
1090 bool receiving = now <= last_recv_time + receiving_timeout_; 1089 bool receiving = now <= last_recv_time + receiving_timeout_;
1091 set_receiving(receiving); 1090 set_receiving(receiving);
1092 } 1091 }
1093 1092
1094 void Connection::Ping(uint32 now) { 1093 void Connection::Ping(uint32_t now) {
1095 last_ping_sent_ = now; 1094 last_ping_sent_ = now;
1096 ConnectionRequest *req = new ConnectionRequest(this); 1095 ConnectionRequest *req = new ConnectionRequest(this);
1097 pings_since_last_response_.push_back(SentPing(req->id(), now)); 1096 pings_since_last_response_.push_back(SentPing(req->id(), now));
1098 LOG_J(LS_VERBOSE, this) << "Sending STUN ping " 1097 LOG_J(LS_VERBOSE, this) << "Sending STUN ping "
1099 << ", id=" << rtc::hex_encode(req->id()); 1098 << ", id=" << rtc::hex_encode(req->id());
1100 requests_.Send(req); 1099 requests_.Send(req);
1101 state_ = STATE_INPROGRESS; 1100 state_ = STATE_INPROGRESS;
1102 } 1101 }
1103 1102
1104 void Connection::ReceivedPing() { 1103 void Connection::ReceivedPing() {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1175 std::string Connection::ToSensitiveString() const { 1174 std::string Connection::ToSensitiveString() const {
1176 return ToString(); 1175 return ToString();
1177 } 1176 }
1178 1177
1179 void Connection::OnConnectionRequestResponse(ConnectionRequest* request, 1178 void Connection::OnConnectionRequestResponse(ConnectionRequest* request,
1180 StunMessage* response) { 1179 StunMessage* response) {
1181 // Log at LS_INFO if we receive a ping response on an unwritable 1180 // Log at LS_INFO if we receive a ping response on an unwritable
1182 // connection. 1181 // connection.
1183 rtc::LoggingSeverity sev = !writable() ? rtc::LS_INFO : rtc::LS_VERBOSE; 1182 rtc::LoggingSeverity sev = !writable() ? rtc::LS_INFO : rtc::LS_VERBOSE;
1184 1183
1185 uint32 rtt = request->Elapsed(); 1184 uint32_t rtt = request->Elapsed();
1186 1185
1187 ReceivedPingResponse(); 1186 ReceivedPingResponse();
1188 1187
1189 if (LOG_CHECK_LEVEL_V(sev)) { 1188 if (LOG_CHECK_LEVEL_V(sev)) {
1190 bool use_candidate = ( 1189 bool use_candidate = (
1191 response->GetByteString(STUN_ATTR_USE_CANDIDATE) != nullptr); 1190 response->GetByteString(STUN_ATTR_USE_CANDIDATE) != nullptr);
1192 std::string pings; 1191 std::string pings;
1193 PrintPingsSinceLastResponse(&pings, 5); 1192 PrintPingsSinceLastResponse(&pings, 5);
1194 LOG_JV(sev, this) << "Received STUN ping response" 1193 LOG_JV(sev, this) << "Received STUN ping response"
1195 << ", id=" << rtc::hex_encode(request->id()) 1194 << ", id=" << rtc::hex_encode(request->id())
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1283 } 1282 }
1284 } 1283 }
1285 1284
1286 void Connection::OnMessage(rtc::Message *pmsg) { 1285 void Connection::OnMessage(rtc::Message *pmsg) {
1287 ASSERT(pmsg->message_id == MSG_DELETE); 1286 ASSERT(pmsg->message_id == MSG_DELETE);
1288 LOG_J(LS_INFO, this) << "Connection deleted due to read or write timeout"; 1287 LOG_J(LS_INFO, this) << "Connection deleted due to read or write timeout";
1289 SignalDestroyed(this); 1288 SignalDestroyed(this);
1290 delete this; 1289 delete this;
1291 } 1290 }
1292 1291
1293 uint32 Connection::last_received() { 1292 uint32_t Connection::last_received() {
1294 return std::max(last_data_received_, 1293 return std::max(last_data_received_,
1295 std::max(last_ping_received_, last_ping_response_received_)); 1294 std::max(last_ping_received_, last_ping_response_received_));
1296 } 1295 }
1297 1296
1298 size_t Connection::recv_bytes_second() { 1297 size_t Connection::recv_bytes_second() {
1299 return recv_rate_tracker_.ComputeRate(); 1298 return recv_rate_tracker_.ComputeRate();
1300 } 1299 }
1301 1300
1302 size_t Connection::recv_total_bytes() { 1301 size_t Connection::recv_total_bytes() {
1303 return recv_rate_tracker_.TotalSampleCount(); 1302 return recv_rate_tracker_.TotalSampleCount();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1350 // Its priority is set equal to the value of the PRIORITY attribute 1349 // Its priority is set equal to the value of the PRIORITY attribute
1351 // in the Binding request. 1350 // in the Binding request.
1352 const StunUInt32Attribute* priority_attr = 1351 const StunUInt32Attribute* priority_attr =
1353 request->msg()->GetUInt32(STUN_ATTR_PRIORITY); 1352 request->msg()->GetUInt32(STUN_ATTR_PRIORITY);
1354 if (!priority_attr) { 1353 if (!priority_attr) {
1355 LOG(LS_WARNING) << "Connection::OnConnectionRequestResponse - " 1354 LOG(LS_WARNING) << "Connection::OnConnectionRequestResponse - "
1356 << "No STUN_ATTR_PRIORITY found in the " 1355 << "No STUN_ATTR_PRIORITY found in the "
1357 << "stun response message"; 1356 << "stun response message";
1358 return; 1357 return;
1359 } 1358 }
1360 const uint32 priority = priority_attr->value(); 1359 const uint32_t priority = priority_attr->value();
1361 std::string id = rtc::CreateRandomString(8); 1360 std::string id = rtc::CreateRandomString(8);
1362 1361
1363 Candidate new_local_candidate; 1362 Candidate new_local_candidate;
1364 new_local_candidate.set_id(id); 1363 new_local_candidate.set_id(id);
1365 new_local_candidate.set_component(local_candidate().component()); 1364 new_local_candidate.set_component(local_candidate().component());
1366 new_local_candidate.set_type(PRFLX_PORT_TYPE); 1365 new_local_candidate.set_type(PRFLX_PORT_TYPE);
1367 new_local_candidate.set_protocol(local_candidate().protocol()); 1366 new_local_candidate.set_protocol(local_candidate().protocol());
1368 new_local_candidate.set_address(addr->GetAddress()); 1367 new_local_candidate.set_address(addr->GetAddress());
1369 new_local_candidate.set_priority(priority); 1368 new_local_candidate.set_priority(priority);
1370 new_local_candidate.set_username(local_candidate().username()); 1369 new_local_candidate.set_username(local_candidate().username());
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1402 ASSERT(sent < 0); 1401 ASSERT(sent < 0);
1403 error_ = port_->GetError(); 1402 error_ = port_->GetError();
1404 sent_packets_discarded_++; 1403 sent_packets_discarded_++;
1405 } else { 1404 } else {
1406 send_rate_tracker_.AddSamples(sent); 1405 send_rate_tracker_.AddSamples(sent);
1407 } 1406 }
1408 return sent; 1407 return sent;
1409 } 1408 }
1410 1409
1411 } // namespace cricket 1410 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698