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

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: 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
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.
199 network_cost_ = (network_->type() == rtc::ADAPTER_TYPE_CELLULAR) ? 99 : 0;
pthatcher1 2016/02/04 23:16:20 Yeah, I definitely would prefer an enum, something
juberti2 2016/02/04 23:31:10 I don't really like the enum since it's not easily
pthatcher1 2016/02/04 23:51:18 The algorithm we have designed so far only works f
honghaiz3 2016/02/05 01:36:46 Perhaps, we can use enum to define a few integer v
pthatcher1 2016/02/05 01:42:35 Thinking about this some more: I do now see merit
200
198 LOG_J(LS_INFO, this) << "Port created"; 201 LOG_J(LS_INFO, this) << "Port created";
199 } 202 }
200 203
201 Port::~Port() { 204 Port::~Port() {
202 // Delete all of the remaining connections. We copy the list up front 205 // Delete all of the remaining connections. We copy the list up front
203 // because each deletion will cause it to be modified. 206 // because each deletion will cause it to be modified.
204 207
205 std::vector<Connection*> list; 208 std::vector<Connection*> list;
206 209
207 AddressMap::iterator iter = connections_.begin(); 210 AddressMap::iterator iter = connections_.begin();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 c.set_protocol(protocol); 246 c.set_protocol(protocol);
244 c.set_relay_protocol(relay_protocol); 247 c.set_relay_protocol(relay_protocol);
245 c.set_tcptype(tcptype); 248 c.set_tcptype(tcptype);
246 c.set_address(address); 249 c.set_address(address);
247 c.set_priority(c.GetPriority(type_preference, network_->preference(), 250 c.set_priority(c.GetPriority(type_preference, network_->preference(),
248 relay_preference)); 251 relay_preference));
249 c.set_username(username_fragment()); 252 c.set_username(username_fragment());
250 c.set_password(password_); 253 c.set_password(password_);
251 c.set_network_name(network_->name()); 254 c.set_network_name(network_->name());
252 c.set_network_type(network_->type()); 255 c.set_network_type(network_->type());
256 c.set_network_cost(network_cost_);
253 c.set_generation(generation_); 257 c.set_generation(generation_);
254 c.set_related_address(related_address); 258 c.set_related_address(related_address);
255 c.set_foundation( 259 c.set_foundation(
256 ComputeFoundation(type, protocol, relay_protocol, base_address)); 260 ComputeFoundation(type, protocol, relay_protocol, base_address));
257 candidates_.push_back(c); 261 candidates_.push_back(c);
258 SignalCandidateReady(this, c); 262 SignalCandidateReady(this, c);
259 263
260 if (final) { 264 if (final) {
261 SignalPortComplete(this); 265 SignalPortComplete(this);
262 } 266 }
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 request->AddAttribute( 689 request->AddAttribute(
686 new StunByteStringAttribute(STUN_ATTR_USERNAME, username)); 690 new StunByteStringAttribute(STUN_ATTR_USERNAME, username));
687 691
688 // connection_ already holds this ping, so subtract one from count. 692 // connection_ already holds this ping, so subtract one from count.
689 if (connection_->port()->send_retransmit_count_attribute()) { 693 if (connection_->port()->send_retransmit_count_attribute()) {
690 request->AddAttribute(new StunUInt32Attribute( 694 request->AddAttribute(new StunUInt32Attribute(
691 STUN_ATTR_RETRANSMIT_COUNT, 695 STUN_ATTR_RETRANSMIT_COUNT,
692 static_cast<uint32_t>(connection_->pings_since_last_response_.size() - 696 static_cast<uint32_t>(connection_->pings_since_last_response_.size() -
693 1))); 697 1)));
694 } 698 }
699 uint32_t network_cost = connection_->port()->network_cost();
700 if (network_cost > 0) {
701 request->AddAttribute(
702 new StunUInt32Attribute(STUN_ATTR_NETWORK_COST, network_cost));
703 }
695 704
696 // Adding ICE_CONTROLLED or ICE_CONTROLLING attribute based on the role. 705 // Adding ICE_CONTROLLED or ICE_CONTROLLING attribute based on the role.
697 if (connection_->port()->GetIceRole() == ICEROLE_CONTROLLING) { 706 if (connection_->port()->GetIceRole() == ICEROLE_CONTROLLING) {
698 request->AddAttribute(new StunUInt64Attribute( 707 request->AddAttribute(new StunUInt64Attribute(
699 STUN_ATTR_ICE_CONTROLLING, connection_->port()->IceTiebreaker())); 708 STUN_ATTR_ICE_CONTROLLING, connection_->port()->IceTiebreaker()));
700 // Since we are trying aggressive nomination, sending USE-CANDIDATE 709 // Since we are trying aggressive nomination, sending USE-CANDIDATE
701 // attribute in every ping. 710 // attribute in every ping.
702 // If we are dealing with a ice-lite end point, nomination flag 711 // 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 712 // in Connection will be set to false by default. Once the connection
704 // becomes "best connection", nomination flag will be turned on. 713 // 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. 1153 // networks would be up simultaneously but only for a brief period.
1145 return now > (time_created_ms_ + MIN_CONNECTION_LIFETIME); 1154 return now > (time_created_ms_ + MIN_CONNECTION_LIFETIME);
1146 } 1155 }
1147 1156
1148 std::string Connection::ToDebugId() const { 1157 std::string Connection::ToDebugId() const {
1149 std::stringstream ss; 1158 std::stringstream ss;
1150 ss << std::hex << this; 1159 ss << std::hex << this;
1151 return ss.str(); 1160 return ss.str();
1152 } 1161 }
1153 1162
1163 int Connection::ComputeNetworkCost() const {
pthatcher1 2016/02/04 23:16:20 Everwhere you have "networkcost", please just make
juberti2 2016/02/04 23:31:10 Not sure about this. Network cost seems clearer th
pthatcher1 2016/02/04 23:51:18 I don't feel strongly one way or the other, I just
honghaiz3 2016/02/05 01:36:46 When I put "cost" in the sdp, I intended to save a
pthatcher1 2016/02/12 00:07:12 Saving bytes in SDP is of minor importance. If so
honghaiz3 2016/02/12 19:28:43 Done.
1164 // TODO(honghaiz): Will add rtt as part of the network cost.
1165 return local_candidate().network_cost() + remote_candidate_.network_cost();
1166 }
1167
1154 std::string Connection::ToString() const { 1168 std::string Connection::ToString() const {
1155 const char CONNECT_STATE_ABBREV[2] = { 1169 const char CONNECT_STATE_ABBREV[2] = {
1156 '-', // not connected (false) 1170 '-', // not connected (false)
1157 'C', // connected (true) 1171 'C', // connected (true)
1158 }; 1172 };
1159 const char RECEIVE_STATE_ABBREV[2] = { 1173 const char RECEIVE_STATE_ABBREV[2] = {
1160 '-', // not receiving (false) 1174 '-', // not receiving (false)
1161 'R', // receiving (true) 1175 'R', // receiving (true)
1162 }; 1176 };
1163 const char WRITE_STATE_ABBREV[4] = { 1177 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); 1396 new_local_candidate.set_id(id);
1383 new_local_candidate.set_component(local_candidate().component()); 1397 new_local_candidate.set_component(local_candidate().component());
1384 new_local_candidate.set_type(PRFLX_PORT_TYPE); 1398 new_local_candidate.set_type(PRFLX_PORT_TYPE);
1385 new_local_candidate.set_protocol(local_candidate().protocol()); 1399 new_local_candidate.set_protocol(local_candidate().protocol());
1386 new_local_candidate.set_address(addr->GetAddress()); 1400 new_local_candidate.set_address(addr->GetAddress());
1387 new_local_candidate.set_priority(priority); 1401 new_local_candidate.set_priority(priority);
1388 new_local_candidate.set_username(local_candidate().username()); 1402 new_local_candidate.set_username(local_candidate().username());
1389 new_local_candidate.set_password(local_candidate().password()); 1403 new_local_candidate.set_password(local_candidate().password());
1390 new_local_candidate.set_network_name(local_candidate().network_name()); 1404 new_local_candidate.set_network_name(local_candidate().network_name());
1391 new_local_candidate.set_network_type(local_candidate().network_type()); 1405 new_local_candidate.set_network_type(local_candidate().network_type());
1406 new_local_candidate.set_network_cost(local_candidate().network_cost());
1392 new_local_candidate.set_related_address(local_candidate().address()); 1407 new_local_candidate.set_related_address(local_candidate().address());
1393 new_local_candidate.set_foundation(ComputeFoundation( 1408 new_local_candidate.set_foundation(ComputeFoundation(
1394 PRFLX_PORT_TYPE, local_candidate().protocol(), 1409 PRFLX_PORT_TYPE, local_candidate().protocol(),
1395 local_candidate().relay_protocol(), local_candidate().address())); 1410 local_candidate().relay_protocol(), local_candidate().address()));
1396 1411
1397 // Change the local candidate of this Connection to the new prflx candidate. 1412 // Change the local candidate of this Connection to the new prflx candidate.
1398 local_candidate_index_ = port_->AddPrflxCandidate(new_local_candidate); 1413 local_candidate_index_ = port_->AddPrflxCandidate(new_local_candidate);
1399 1414
1400 // SignalStateChange to force a re-sort in P2PTransportChannel as this 1415 // SignalStateChange to force a re-sort in P2PTransportChannel as this
1401 // Connection's local candidate has changed. 1416 // Connection's local candidate has changed.
(...skipping 18 matching lines...) Expand all
1420 ASSERT(sent < 0); 1435 ASSERT(sent < 0);
1421 error_ = port_->GetError(); 1436 error_ = port_->GetError();
1422 sent_packets_discarded_++; 1437 sent_packets_discarded_++;
1423 } else { 1438 } else {
1424 send_rate_tracker_.AddSamples(sent); 1439 send_rate_tracker_.AddSamples(sent);
1425 } 1440 }
1426 return sent; 1441 return sent;
1427 } 1442 }
1428 1443
1429 } // namespace cricket 1444 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698