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

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

Issue 1668073002: Add network cost as part of the connection comparison. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fix sdp test error (do not signal network cost if it is 0) Created 4 years, 10 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/stun.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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 188
189 void Port::Construct() { 189 void Port::Construct() {
190 // TODO(pthatcher): Remove this old behavior once we're sure no one 190 // TODO(pthatcher): Remove this old behavior once we're sure no one
191 // relies on it. If the username_fragment and password are empty, 191 // relies on it. If the username_fragment and password are empty,
192 // we should just create one. 192 // we should just create one.
193 if (ice_username_fragment_.empty()) { 193 if (ice_username_fragment_.empty()) {
194 ASSERT(password_.empty()); 194 ASSERT(password_.empty());
195 ice_username_fragment_ = rtc::CreateRandomString(ICE_UFRAG_LENGTH); 195 ice_username_fragment_ = rtc::CreateRandomString(ICE_UFRAG_LENGTH);
196 password_ = rtc::CreateRandomString(ICE_PWD_LENGTH); 196 password_ = rtc::CreateRandomString(ICE_PWD_LENGTH);
197 } 197 }
198 // TODO(honghaiz): Make it configurable from user setting.
199 network_cost_ =
200 (network_->type() == rtc::ADAPTER_TYPE_CELLULAR) ? kMaxNetworkCost : 0;
201
198 LOG_J(LS_INFO, this) << "Port created"; 202 LOG_J(LS_INFO, this) << "Port created";
199 } 203 }
200 204
201 Port::~Port() { 205 Port::~Port() {
202 // Delete all of the remaining connections. We copy the list up front 206 // Delete all of the remaining connections. We copy the list up front
203 // because each deletion will cause it to be modified. 207 // because each deletion will cause it to be modified.
204 208
205 std::vector<Connection*> list; 209 std::vector<Connection*> list;
206 210
207 AddressMap::iterator iter = connections_.begin(); 211 AddressMap::iterator iter = connections_.begin();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 c.set_protocol(protocol); 247 c.set_protocol(protocol);
244 c.set_relay_protocol(relay_protocol); 248 c.set_relay_protocol(relay_protocol);
245 c.set_tcptype(tcptype); 249 c.set_tcptype(tcptype);
246 c.set_address(address); 250 c.set_address(address);
247 c.set_priority(c.GetPriority(type_preference, network_->preference(), 251 c.set_priority(c.GetPriority(type_preference, network_->preference(),
248 relay_preference)); 252 relay_preference));
249 c.set_username(username_fragment()); 253 c.set_username(username_fragment());
250 c.set_password(password_); 254 c.set_password(password_);
251 c.set_network_name(network_->name()); 255 c.set_network_name(network_->name());
252 c.set_network_type(network_->type()); 256 c.set_network_type(network_->type());
257 c.set_network_cost(network_cost_);
253 c.set_generation(generation_); 258 c.set_generation(generation_);
254 c.set_related_address(related_address); 259 c.set_related_address(related_address);
255 c.set_foundation( 260 c.set_foundation(
256 ComputeFoundation(type, protocol, relay_protocol, base_address)); 261 ComputeFoundation(type, protocol, relay_protocol, base_address));
257 candidates_.push_back(c); 262 candidates_.push_back(c);
258 SignalCandidateReady(this, c); 263 SignalCandidateReady(this, c);
259 264
260 if (final) { 265 if (final) {
261 SignalPortComplete(this); 266 SignalPortComplete(this);
262 } 267 }
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 request->AddAttribute( 690 request->AddAttribute(
686 new StunByteStringAttribute(STUN_ATTR_USERNAME, username)); 691 new StunByteStringAttribute(STUN_ATTR_USERNAME, username));
687 692
688 // connection_ already holds this ping, so subtract one from count. 693 // connection_ already holds this ping, so subtract one from count.
689 if (connection_->port()->send_retransmit_count_attribute()) { 694 if (connection_->port()->send_retransmit_count_attribute()) {
690 request->AddAttribute(new StunUInt32Attribute( 695 request->AddAttribute(new StunUInt32Attribute(
691 STUN_ATTR_RETRANSMIT_COUNT, 696 STUN_ATTR_RETRANSMIT_COUNT,
692 static_cast<uint32_t>(connection_->pings_since_last_response_.size() - 697 static_cast<uint32_t>(connection_->pings_since_last_response_.size() -
693 1))); 698 1)));
694 } 699 }
700 uint32_t network_cost = connection_->port()->network_cost();
701 if (network_cost > 0) {
702 request->AddAttribute(
703 new StunUInt32Attribute(STUN_ATTR_NETWORK_COST, network_cost));
704 }
695 705
696 // Adding ICE_CONTROLLED or ICE_CONTROLLING attribute based on the role. 706 // Adding ICE_CONTROLLED or ICE_CONTROLLING attribute based on the role.
697 if (connection_->port()->GetIceRole() == ICEROLE_CONTROLLING) { 707 if (connection_->port()->GetIceRole() == ICEROLE_CONTROLLING) {
698 request->AddAttribute(new StunUInt64Attribute( 708 request->AddAttribute(new StunUInt64Attribute(
699 STUN_ATTR_ICE_CONTROLLING, connection_->port()->IceTiebreaker())); 709 STUN_ATTR_ICE_CONTROLLING, connection_->port()->IceTiebreaker()));
700 // Since we are trying aggressive nomination, sending USE-CANDIDATE 710 // Since we are trying aggressive nomination, sending USE-CANDIDATE
701 // attribute in every ping. 711 // attribute in every ping.
702 // If we are dealing with a ice-lite end point, nomination flag 712 // If we are dealing with a ice-lite end point, nomination flag
703 // in Connection will be set to false by default. Once the connection 713 // in Connection will be set to false by default. Once the connection
704 // becomes "best connection", nomination flag will be turned on. 714 // becomes "best connection", nomination flag will be turned on.
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
1144 // networks would be up simultaneously but only for a brief period. 1154 // networks would be up simultaneously but only for a brief period.
1145 return now > (time_created_ms_ + MIN_CONNECTION_LIFETIME); 1155 return now > (time_created_ms_ + MIN_CONNECTION_LIFETIME);
1146 } 1156 }
1147 1157
1148 std::string Connection::ToDebugId() const { 1158 std::string Connection::ToDebugId() const {
1149 std::stringstream ss; 1159 std::stringstream ss;
1150 ss << std::hex << this; 1160 ss << std::hex << this;
1151 return ss.str(); 1161 return ss.str();
1152 } 1162 }
1153 1163
1164 uint32_t Connection::ComputeNetworkCost() const {
1165 // TODO(honghaiz): Will add rtt as part of the network cost.
1166 return local_candidate().network_cost() + remote_candidate_.network_cost();
1167 }
1168
1154 std::string Connection::ToString() const { 1169 std::string Connection::ToString() const {
1155 const char CONNECT_STATE_ABBREV[2] = { 1170 const char CONNECT_STATE_ABBREV[2] = {
1156 '-', // not connected (false) 1171 '-', // not connected (false)
1157 'C', // connected (true) 1172 'C', // connected (true)
1158 }; 1173 };
1159 const char RECEIVE_STATE_ABBREV[2] = { 1174 const char RECEIVE_STATE_ABBREV[2] = {
1160 '-', // not receiving (false) 1175 '-', // not receiving (false)
1161 'R', // receiving (true) 1176 'R', // receiving (true)
1162 }; 1177 };
1163 const char WRITE_STATE_ABBREV[4] = { 1178 const char WRITE_STATE_ABBREV[4] = {
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
1382 new_local_candidate.set_id(id); 1397 new_local_candidate.set_id(id);
1383 new_local_candidate.set_component(local_candidate().component()); 1398 new_local_candidate.set_component(local_candidate().component());
1384 new_local_candidate.set_type(PRFLX_PORT_TYPE); 1399 new_local_candidate.set_type(PRFLX_PORT_TYPE);
1385 new_local_candidate.set_protocol(local_candidate().protocol()); 1400 new_local_candidate.set_protocol(local_candidate().protocol());
1386 new_local_candidate.set_address(addr->GetAddress()); 1401 new_local_candidate.set_address(addr->GetAddress());
1387 new_local_candidate.set_priority(priority); 1402 new_local_candidate.set_priority(priority);
1388 new_local_candidate.set_username(local_candidate().username()); 1403 new_local_candidate.set_username(local_candidate().username());
1389 new_local_candidate.set_password(local_candidate().password()); 1404 new_local_candidate.set_password(local_candidate().password());
1390 new_local_candidate.set_network_name(local_candidate().network_name()); 1405 new_local_candidate.set_network_name(local_candidate().network_name());
1391 new_local_candidate.set_network_type(local_candidate().network_type()); 1406 new_local_candidate.set_network_type(local_candidate().network_type());
1407 new_local_candidate.set_network_cost(local_candidate().network_cost());
1392 new_local_candidate.set_related_address(local_candidate().address()); 1408 new_local_candidate.set_related_address(local_candidate().address());
1393 new_local_candidate.set_foundation(ComputeFoundation( 1409 new_local_candidate.set_foundation(ComputeFoundation(
1394 PRFLX_PORT_TYPE, local_candidate().protocol(), 1410 PRFLX_PORT_TYPE, local_candidate().protocol(),
1395 local_candidate().relay_protocol(), local_candidate().address())); 1411 local_candidate().relay_protocol(), local_candidate().address()));
1396 1412
1397 // Change the local candidate of this Connection to the new prflx candidate. 1413 // Change the local candidate of this Connection to the new prflx candidate.
1398 local_candidate_index_ = port_->AddPrflxCandidate(new_local_candidate); 1414 local_candidate_index_ = port_->AddPrflxCandidate(new_local_candidate);
1399 1415
1400 // SignalStateChange to force a re-sort in P2PTransportChannel as this 1416 // SignalStateChange to force a re-sort in P2PTransportChannel as this
1401 // Connection's local candidate has changed. 1417 // Connection's local candidate has changed.
(...skipping 18 matching lines...) Expand all
1420 ASSERT(sent < 0); 1436 ASSERT(sent < 0);
1421 error_ = port_->GetError(); 1437 error_ = port_->GetError();
1422 sent_packets_discarded_++; 1438 sent_packets_discarded_++;
1423 } else { 1439 } else {
1424 send_rate_tracker_.AddSamples(sent); 1440 send_rate_tracker_.AddSamples(sent);
1425 } 1441 }
1426 return sent; 1442 return sent;
1427 } 1443 }
1428 1444
1429 } // namespace cricket 1445 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/p2p/base/port.h ('k') | webrtc/p2p/base/stun.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698