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

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: rebase + revert basictypes.h (to be landed separately just in case of a revert due to unexpected us… Created 5 years, 2 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 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 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 std::string username; 688 std::string username;
691 connection_->port()->CreateStunUsername( 689 connection_->port()->CreateStunUsername(
692 connection_->remote_candidate().username(), &username); 690 connection_->remote_candidate().username(), &username);
693 request->AddAttribute( 691 request->AddAttribute(
694 new StunByteStringAttribute(STUN_ATTR_USERNAME, username)); 692 new StunByteStringAttribute(STUN_ATTR_USERNAME, username));
695 693
696 // connection_ already holds this ping, so subtract one from count. 694 // connection_ already holds this ping, so subtract one from count.
697 if (connection_->port()->send_retransmit_count_attribute()) { 695 if (connection_->port()->send_retransmit_count_attribute()) {
698 request->AddAttribute(new StunUInt32Attribute( 696 request->AddAttribute(new StunUInt32Attribute(
699 STUN_ATTR_RETRANSMIT_COUNT, 697 STUN_ATTR_RETRANSMIT_COUNT,
700 static_cast<uint32>( 698 static_cast<uint32_t>(connection_->pings_since_last_response_.size() -
701 connection_->pings_since_last_response_.size() - 1))); 699 1)));
702 } 700 }
703 701
704 // Adding ICE_CONTROLLED or ICE_CONTROLLING attribute based on the role. 702 // Adding ICE_CONTROLLED or ICE_CONTROLLING attribute based on the role.
705 if (connection_->port()->GetIceRole() == ICEROLE_CONTROLLING) { 703 if (connection_->port()->GetIceRole() == ICEROLE_CONTROLLING) {
706 request->AddAttribute(new StunUInt64Attribute( 704 request->AddAttribute(new StunUInt64Attribute(
707 STUN_ATTR_ICE_CONTROLLING, connection_->port()->IceTiebreaker())); 705 STUN_ATTR_ICE_CONTROLLING, connection_->port()->IceTiebreaker()));
708 // Since we are trying aggressive nomination, sending USE-CANDIDATE 706 // Since we are trying aggressive nomination, sending USE-CANDIDATE
709 // attribute in every ping. 707 // attribute in every ping.
710 // If we are dealing with a ice-lite end point, nomination flag 708 // If we are dealing with a ice-lite end point, nomination flag
711 // in Connection will be set to false by default. Once the connection 709 // in Connection will be set to false by default. Once the connection
712 // becomes "best connection", nomination flag will be turned on. 710 // becomes "best connection", nomination flag will be turned on.
713 if (connection_->use_candidate_attr()) { 711 if (connection_->use_candidate_attr()) {
714 request->AddAttribute(new StunByteStringAttribute( 712 request->AddAttribute(new StunByteStringAttribute(
715 STUN_ATTR_USE_CANDIDATE)); 713 STUN_ATTR_USE_CANDIDATE));
716 } 714 }
717 } else if (connection_->port()->GetIceRole() == ICEROLE_CONTROLLED) { 715 } else if (connection_->port()->GetIceRole() == ICEROLE_CONTROLLED) {
718 request->AddAttribute(new StunUInt64Attribute( 716 request->AddAttribute(new StunUInt64Attribute(
719 STUN_ATTR_ICE_CONTROLLED, connection_->port()->IceTiebreaker())); 717 STUN_ATTR_ICE_CONTROLLED, connection_->port()->IceTiebreaker()));
720 } else { 718 } else {
721 ASSERT(false); 719 ASSERT(false);
722 } 720 }
723 721
724 // Adding PRIORITY Attribute. 722 // Adding PRIORITY Attribute.
725 // Changing the type preference to Peer Reflexive and local preference 723 // Changing the type preference to Peer Reflexive and local preference
726 // and component id information is unchanged from the original priority. 724 // and component id information is unchanged from the original priority.
727 // priority = (2^24)*(type preference) + 725 // priority = (2^24)*(type preference) +
728 // (2^8)*(local preference) + 726 // (2^8)*(local preference) +
729 // (2^0)*(256 - component ID) 727 // (2^0)*(256 - component ID)
730 uint32 prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24 | 728 uint32_t prflx_priority =
729 ICE_TYPE_PREFERENCE_PRFLX << 24 |
731 (connection_->local_candidate().priority() & 0x00FFFFFF); 730 (connection_->local_candidate().priority() & 0x00FFFFFF);
732 request->AddAttribute( 731 request->AddAttribute(
733 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority)); 732 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority));
734 733
735 // Adding Message Integrity attribute. 734 // Adding Message Integrity attribute.
736 request->AddMessageIntegrity(connection_->remote_candidate().password()); 735 request->AddMessageIntegrity(connection_->remote_candidate().password());
737 // Adding Fingerprint. 736 // Adding Fingerprint.
738 request->AddFingerprint(); 737 request->AddFingerprint();
739 } 738 }
740 739
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 } 803 }
805 804
806 Connection::~Connection() { 805 Connection::~Connection() {
807 } 806 }
808 807
809 const Candidate& Connection::local_candidate() const { 808 const Candidate& Connection::local_candidate() const {
810 ASSERT(local_candidate_index_ < port_->Candidates().size()); 809 ASSERT(local_candidate_index_ < port_->Candidates().size());
811 return port_->Candidates()[local_candidate_index_]; 810 return port_->Candidates()[local_candidate_index_];
812 } 811 }
813 812
814 uint64 Connection::priority() const { 813 uint64_t Connection::priority() const {
815 uint64 priority = 0; 814 uint64_t priority = 0;
816 // RFC 5245 - 5.7.2. Computing Pair Priority and Ordering Pairs 815 // RFC 5245 - 5.7.2. Computing Pair Priority and Ordering Pairs
817 // Let G be the priority for the candidate provided by the controlling 816 // Let G be the priority for the candidate provided by the controlling
818 // agent. Let D be the priority for the candidate provided by the 817 // agent. Let D be the priority for the candidate provided by the
819 // controlled agent. 818 // controlled agent.
820 // pair priority = 2^32*MIN(G,D) + 2*MAX(G,D) + (G>D?1:0) 819 // pair priority = 2^32*MIN(G,D) + 2*MAX(G,D) + (G>D?1:0)
821 IceRole role = port_->GetIceRole(); 820 IceRole role = port_->GetIceRole();
822 if (role != ICEROLE_UNKNOWN) { 821 if (role != ICEROLE_UNKNOWN) {
823 uint32 g = 0; 822 uint32_t g = 0;
824 uint32 d = 0; 823 uint32_t d = 0;
825 if (role == ICEROLE_CONTROLLING) { 824 if (role == ICEROLE_CONTROLLING) {
826 g = local_candidate().priority(); 825 g = local_candidate().priority();
827 d = remote_candidate_.priority(); 826 d = remote_candidate_.priority();
828 } else { 827 } else {
829 g = remote_candidate_.priority(); 828 g = remote_candidate_.priority();
830 d = local_candidate().priority(); 829 d = local_candidate().priority();
831 } 830 }
832 priority = std::min(g, d); 831 priority = std::min(g, d);
833 priority = priority << 32; 832 priority = priority << 32;
834 priority += 2 * std::max(g, d) + (g > d ? 1 : 0); 833 priority += 2 * std::max(g, d) + (g > d ? 1 : 0);
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 } 1012 }
1014 oss << "... " << (pings_since_last_response_.size() - max) << " more"; 1013 oss << "... " << (pings_since_last_response_.size() - max) << " more";
1015 } else { 1014 } else {
1016 for (const SentPing& ping : pings_since_last_response_) { 1015 for (const SentPing& ping : pings_since_last_response_) {
1017 oss << rtc::hex_encode(ping.id) << " "; 1016 oss << rtc::hex_encode(ping.id) << " ";
1018 } 1017 }
1019 } 1018 }
1020 *s = oss.str(); 1019 *s = oss.str();
1021 } 1020 }
1022 1021
1023 void Connection::UpdateState(uint32 now) { 1022 void Connection::UpdateState(uint32_t now) {
1024 uint32 rtt = ConservativeRTTEstimate(rtt_); 1023 uint32_t rtt = ConservativeRTTEstimate(rtt_);
1025 1024
1026 if (LOG_CHECK_LEVEL(LS_VERBOSE)) { 1025 if (LOG_CHECK_LEVEL(LS_VERBOSE)) {
1027 std::string pings; 1026 std::string pings;
1028 PrintPingsSinceLastResponse(&pings, 5); 1027 PrintPingsSinceLastResponse(&pings, 5);
1029 LOG_J(LS_VERBOSE, this) << "UpdateState()" 1028 LOG_J(LS_VERBOSE, this) << "UpdateState()"
1030 << ", ms since last received response=" 1029 << ", ms since last received response="
1031 << now - last_ping_response_received_ 1030 << now - last_ping_response_received_
1032 << ", ms since last received data=" 1031 << ", ms since last received data="
1033 << now - last_data_received_ 1032 << now - last_data_received_
1034 << ", rtt=" << rtt 1033 << ", rtt=" << rtt
(...skipping 10 matching lines...) Expand all
1045 // allow for changes in network conditions. 1044 // allow for changes in network conditions.
1046 1045
1047 if ((write_state_ == STATE_WRITABLE) && 1046 if ((write_state_ == STATE_WRITABLE) &&
1048 TooManyFailures(pings_since_last_response_, 1047 TooManyFailures(pings_since_last_response_,
1049 CONNECTION_WRITE_CONNECT_FAILURES, 1048 CONNECTION_WRITE_CONNECT_FAILURES,
1050 rtt, 1049 rtt,
1051 now) && 1050 now) &&
1052 TooLongWithoutResponse(pings_since_last_response_, 1051 TooLongWithoutResponse(pings_since_last_response_,
1053 CONNECTION_WRITE_CONNECT_TIMEOUT, 1052 CONNECTION_WRITE_CONNECT_TIMEOUT,
1054 now)) { 1053 now)) {
1055 uint32 max_pings = CONNECTION_WRITE_CONNECT_FAILURES; 1054 uint32_t max_pings = CONNECTION_WRITE_CONNECT_FAILURES;
1056 LOG_J(LS_INFO, this) << "Unwritable after " << max_pings 1055 LOG_J(LS_INFO, this) << "Unwritable after " << max_pings
1057 << " ping failures and " 1056 << " ping failures and "
1058 << now - pings_since_last_response_[0].sent_time 1057 << now - pings_since_last_response_[0].sent_time
1059 << " ms without a response," 1058 << " ms without a response,"
1060 << " ms since last received ping=" 1059 << " ms since last received ping="
1061 << now - last_ping_received_ 1060 << now - last_ping_received_
1062 << " ms since last received data=" 1061 << " ms since last received data="
1063 << now - last_data_received_ 1062 << now - last_data_received_
1064 << " rtt=" << rtt; 1063 << " rtt=" << rtt;
1065 set_write_state(STATE_WRITE_UNRELIABLE); 1064 set_write_state(STATE_WRITE_UNRELIABLE);
1066 } 1065 }
1067 if ((write_state_ == STATE_WRITE_UNRELIABLE || 1066 if ((write_state_ == STATE_WRITE_UNRELIABLE ||
1068 write_state_ == STATE_WRITE_INIT) && 1067 write_state_ == STATE_WRITE_INIT) &&
1069 TooLongWithoutResponse(pings_since_last_response_, 1068 TooLongWithoutResponse(pings_since_last_response_,
1070 CONNECTION_WRITE_TIMEOUT, 1069 CONNECTION_WRITE_TIMEOUT,
1071 now)) { 1070 now)) {
1072 LOG_J(LS_INFO, this) << "Timed out after " 1071 LOG_J(LS_INFO, this) << "Timed out after "
1073 << now - pings_since_last_response_[0].sent_time 1072 << now - pings_since_last_response_[0].sent_time
1074 << " ms without a response" 1073 << " ms without a response"
1075 << ", rtt=" << rtt; 1074 << ", rtt=" << rtt;
1076 set_write_state(STATE_WRITE_TIMEOUT); 1075 set_write_state(STATE_WRITE_TIMEOUT);
1077 } 1076 }
1078 1077
1079 // Check the receiving state. 1078 // Check the receiving state.
1080 uint32 last_recv_time = last_received(); 1079 uint32_t last_recv_time = last_received();
1081 bool receiving = now <= last_recv_time + receiving_timeout_; 1080 bool receiving = now <= last_recv_time + receiving_timeout_;
1082 set_receiving(receiving); 1081 set_receiving(receiving);
1083 if (dead(now)) { 1082 if (dead(now)) {
1084 Destroy(); 1083 Destroy();
1085 } 1084 }
1086 } 1085 }
1087 1086
1088 void Connection::Ping(uint32 now) { 1087 void Connection::Ping(uint32_t now) {
1089 last_ping_sent_ = now; 1088 last_ping_sent_ = now;
1090 ConnectionRequest *req = new ConnectionRequest(this); 1089 ConnectionRequest *req = new ConnectionRequest(this);
1091 pings_since_last_response_.push_back(SentPing(req->id(), now)); 1090 pings_since_last_response_.push_back(SentPing(req->id(), now));
1092 LOG_J(LS_VERBOSE, this) << "Sending STUN ping " 1091 LOG_J(LS_VERBOSE, this) << "Sending STUN ping "
1093 << ", id=" << rtc::hex_encode(req->id()); 1092 << ", id=" << rtc::hex_encode(req->id());
1094 requests_.Send(req); 1093 requests_.Send(req);
1095 state_ = STATE_INPROGRESS; 1094 state_ = STATE_INPROGRESS;
1096 } 1095 }
1097 1096
1098 void Connection::ReceivedPing() { 1097 void Connection::ReceivedPing() {
1099 set_receiving(true); 1098 set_receiving(true);
1100 last_ping_received_ = rtc::Time(); 1099 last_ping_received_ = rtc::Time();
1101 } 1100 }
1102 1101
1103 void Connection::ReceivedPingResponse() { 1102 void Connection::ReceivedPingResponse() {
1104 // We've already validated that this is a STUN binding response with 1103 // We've already validated that this is a STUN binding response with
1105 // the correct local and remote username for this connection. 1104 // the correct local and remote username for this connection.
1106 // So if we're not already, become writable. We may be bringing a pruned 1105 // So if we're not already, become writable. We may be bringing a pruned
1107 // connection back to life, but if we don't really want it, we can always 1106 // connection back to life, but if we don't really want it, we can always
1108 // prune it again. 1107 // prune it again.
1109 set_receiving(true); 1108 set_receiving(true);
1110 set_write_state(STATE_WRITABLE); 1109 set_write_state(STATE_WRITABLE);
1111 set_state(STATE_SUCCEEDED); 1110 set_state(STATE_SUCCEEDED);
1112 pings_since_last_response_.clear(); 1111 pings_since_last_response_.clear();
1113 last_ping_response_received_ = rtc::Time(); 1112 last_ping_response_received_ = rtc::Time();
1114 } 1113 }
1115 1114
1116 bool Connection::dead(uint32 now) const { 1115 bool Connection::dead(uint32_t now) const {
1117 if (now < (time_created_ms_ + MIN_CONNECTION_LIFETIME)) { 1116 if (now < (time_created_ms_ + MIN_CONNECTION_LIFETIME)) {
1118 // A connection that hasn't passed its minimum lifetime is still alive. 1117 // A connection that hasn't passed its minimum lifetime is still alive.
1119 // We do this to prevent connections from being pruned too quickly 1118 // We do this to prevent connections from being pruned too quickly
1120 // during a network change event when two networks would be up 1119 // during a network change event when two networks would be up
1121 // simultaneously but only for a brief period. 1120 // simultaneously but only for a brief period.
1122 return false; 1121 return false;
1123 } 1122 }
1124 1123
1125 if (receiving_) { 1124 if (receiving_) {
1126 // A connection that is receiving is alive. 1125 // A connection that is receiving is alive.
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1191 std::string Connection::ToSensitiveString() const { 1190 std::string Connection::ToSensitiveString() const {
1192 return ToString(); 1191 return ToString();
1193 } 1192 }
1194 1193
1195 void Connection::OnConnectionRequestResponse(ConnectionRequest* request, 1194 void Connection::OnConnectionRequestResponse(ConnectionRequest* request,
1196 StunMessage* response) { 1195 StunMessage* response) {
1197 // Log at LS_INFO if we receive a ping response on an unwritable 1196 // Log at LS_INFO if we receive a ping response on an unwritable
1198 // connection. 1197 // connection.
1199 rtc::LoggingSeverity sev = !writable() ? rtc::LS_INFO : rtc::LS_VERBOSE; 1198 rtc::LoggingSeverity sev = !writable() ? rtc::LS_INFO : rtc::LS_VERBOSE;
1200 1199
1201 uint32 rtt = request->Elapsed(); 1200 uint32_t rtt = request->Elapsed();
1202 1201
1203 ReceivedPingResponse(); 1202 ReceivedPingResponse();
1204 1203
1205 if (LOG_CHECK_LEVEL_V(sev)) { 1204 if (LOG_CHECK_LEVEL_V(sev)) {
1206 bool use_candidate = ( 1205 bool use_candidate = (
1207 response->GetByteString(STUN_ATTR_USE_CANDIDATE) != nullptr); 1206 response->GetByteString(STUN_ATTR_USE_CANDIDATE) != nullptr);
1208 std::string pings; 1207 std::string pings;
1209 PrintPingsSinceLastResponse(&pings, 5); 1208 PrintPingsSinceLastResponse(&pings, 5);
1210 LOG_JV(sev, this) << "Received STUN ping response" 1209 LOG_JV(sev, this) << "Received STUN ping response"
1211 << ", id=" << rtc::hex_encode(request->id()) 1210 << ", id=" << rtc::hex_encode(request->id())
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1292 } 1291 }
1293 } 1292 }
1294 1293
1295 void Connection::OnMessage(rtc::Message *pmsg) { 1294 void Connection::OnMessage(rtc::Message *pmsg) {
1296 ASSERT(pmsg->message_id == MSG_DELETE); 1295 ASSERT(pmsg->message_id == MSG_DELETE);
1297 LOG_J(LS_INFO, this) << "Connection deleted"; 1296 LOG_J(LS_INFO, this) << "Connection deleted";
1298 SignalDestroyed(this); 1297 SignalDestroyed(this);
1299 delete this; 1298 delete this;
1300 } 1299 }
1301 1300
1302 uint32 Connection::last_received() { 1301 uint32_t Connection::last_received() {
1303 return std::max(last_data_received_, 1302 return std::max(last_data_received_,
1304 std::max(last_ping_received_, last_ping_response_received_)); 1303 std::max(last_ping_received_, last_ping_response_received_));
1305 } 1304 }
1306 1305
1307 size_t Connection::recv_bytes_second() { 1306 size_t Connection::recv_bytes_second() {
1308 return recv_rate_tracker_.ComputeRate(); 1307 return recv_rate_tracker_.ComputeRate();
1309 } 1308 }
1310 1309
1311 size_t Connection::recv_total_bytes() { 1310 size_t Connection::recv_total_bytes() {
1312 return recv_rate_tracker_.TotalSampleCount(); 1311 return recv_rate_tracker_.TotalSampleCount();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1359 // Its priority is set equal to the value of the PRIORITY attribute 1358 // Its priority is set equal to the value of the PRIORITY attribute
1360 // in the Binding request. 1359 // in the Binding request.
1361 const StunUInt32Attribute* priority_attr = 1360 const StunUInt32Attribute* priority_attr =
1362 request->msg()->GetUInt32(STUN_ATTR_PRIORITY); 1361 request->msg()->GetUInt32(STUN_ATTR_PRIORITY);
1363 if (!priority_attr) { 1362 if (!priority_attr) {
1364 LOG(LS_WARNING) << "Connection::OnConnectionRequestResponse - " 1363 LOG(LS_WARNING) << "Connection::OnConnectionRequestResponse - "
1365 << "No STUN_ATTR_PRIORITY found in the " 1364 << "No STUN_ATTR_PRIORITY found in the "
1366 << "stun response message"; 1365 << "stun response message";
1367 return; 1366 return;
1368 } 1367 }
1369 const uint32 priority = priority_attr->value(); 1368 const uint32_t priority = priority_attr->value();
1370 std::string id = rtc::CreateRandomString(8); 1369 std::string id = rtc::CreateRandomString(8);
1371 1370
1372 Candidate new_local_candidate; 1371 Candidate new_local_candidate;
1373 new_local_candidate.set_id(id); 1372 new_local_candidate.set_id(id);
1374 new_local_candidate.set_component(local_candidate().component()); 1373 new_local_candidate.set_component(local_candidate().component());
1375 new_local_candidate.set_type(PRFLX_PORT_TYPE); 1374 new_local_candidate.set_type(PRFLX_PORT_TYPE);
1376 new_local_candidate.set_protocol(local_candidate().protocol()); 1375 new_local_candidate.set_protocol(local_candidate().protocol());
1377 new_local_candidate.set_address(addr->GetAddress()); 1376 new_local_candidate.set_address(addr->GetAddress());
1378 new_local_candidate.set_priority(priority); 1377 new_local_candidate.set_priority(priority);
1379 new_local_candidate.set_username(local_candidate().username()); 1378 new_local_candidate.set_username(local_candidate().username());
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1411 ASSERT(sent < 0); 1410 ASSERT(sent < 0);
1412 error_ = port_->GetError(); 1411 error_ = port_->GetError();
1413 sent_packets_discarded_++; 1412 sent_packets_discarded_++;
1414 } else { 1413 } else {
1415 send_rate_tracker_.AddSamples(sent); 1414 send_rate_tracker_.AddSamples(sent);
1416 } 1415 }
1417 return sent; 1416 return sent;
1418 } 1417 }
1419 1418
1420 } // namespace cricket 1419 } // 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