Chromium Code Reviews

Side by Side Diff: webrtc/p2p/client/basicportallocator.cc

Issue 1987833002: Add a flag to filter out high-cost networks. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
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 375 matching lines...)
386 network_manager->GetAnyAddressNetworks(networks); 386 network_manager->GetAnyAddressNetworks(networks);
387 } else { 387 } else {
388 network_manager->GetNetworks(networks); 388 network_manager->GetNetworks(networks);
389 } 389 }
390 networks->erase(std::remove_if(networks->begin(), networks->end(), 390 networks->erase(std::remove_if(networks->begin(), networks->end(),
391 [this](rtc::Network* network) { 391 [this](rtc::Network* network) {
392 return allocator_->network_ignore_mask() & 392 return allocator_->network_ignore_mask() &
393 network->type(); 393 network->type();
394 }), 394 }),
395 networks->end()); 395 networks->end());
396
397 if (flags() & PORTALLOCATOR_GATHER_LOW_COST_NETWORK_ONLY) {
398 uint16_t lowest_cost = rtc::kMaxNetworkCost;
399 for (rtc::Network* network : *networks) {
400 uint16_t cost = network->GetCost();
401 if (cost < lowest_cost) {
402 lowest_cost = cost;
403 }
404 }
pthatcher1 2016/05/17 20:44:28 std::min might work here
honghaiz3 2016/05/18 05:55:02 Done.
405 networks->erase(std::remove_if(networks->begin(), networks->end(),
406 [lowest_cost](rtc::Network* network) {
407 return network->GetCost() > lowest_cost;
408 }),
409 networks->end());
pthatcher1 2016/05/17 20:44:28 We could use a threshold greater than zero (perhap
honghaiz3 2016/05/18 05:55:02 Done.
410 }
396 } 411 }
397 412
398 // For each network, see if we have a sequence that covers it already. If not, 413 // For each network, see if we have a sequence that covers it already. If not,
399 // create a new sequence to create the appropriate ports. 414 // create a new sequence to create the appropriate ports.
400 void BasicPortAllocatorSession::DoAllocate() { 415 void BasicPortAllocatorSession::DoAllocate() {
401 bool done_signal_needed = false; 416 bool done_signal_needed = false;
402 std::vector<rtc::Network*> networks; 417 std::vector<rtc::Network*> networks;
403 GetNetworks(&networks); 418 GetNetworks(&networks);
404 419
405 if (networks.empty()) { 420 if (networks.empty()) {
(...skipping 827 matching lines...)
1233 ServerAddresses servers; 1248 ServerAddresses servers;
1234 for (size_t i = 0; i < relays.size(); ++i) { 1249 for (size_t i = 0; i < relays.size(); ++i) {
1235 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) { 1250 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) {
1236 servers.insert(relays[i].ports.front().address); 1251 servers.insert(relays[i].ports.front().address);
1237 } 1252 }
1238 } 1253 }
1239 return servers; 1254 return servers;
1240 } 1255 }
1241 1256
1242 } // namespace cricket 1257 } // namespace cricket
OLDNEW

Powered by Google App Engine