OLD | NEW |
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 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 } else { | 581 } else { |
582 network_manager->GetNetworks(&networks); | 582 network_manager->GetNetworks(&networks); |
583 // If network enumeration fails, use the ANY address as a fallback, so we | 583 // If network enumeration fails, use the ANY address as a fallback, so we |
584 // can at least try gathering candidates using the default route chosen by | 584 // can at least try gathering candidates using the default route chosen by |
585 // the OS. Or, if the PORTALLOCATOR_ENABLE_ANY_ADDRESS_PORTS flag is | 585 // the OS. Or, if the PORTALLOCATOR_ENABLE_ANY_ADDRESS_PORTS flag is |
586 // set, we'll use ANY address candidates either way. | 586 // set, we'll use ANY address candidates either way. |
587 if (networks.empty() || flags() & PORTALLOCATOR_ENABLE_ANY_ADDRESS_PORTS) { | 587 if (networks.empty() || flags() & PORTALLOCATOR_ENABLE_ANY_ADDRESS_PORTS) { |
588 network_manager->GetAnyAddressNetworks(&networks); | 588 network_manager->GetAnyAddressNetworks(&networks); |
589 } | 589 } |
590 } | 590 } |
| 591 // Do some more filtering, depending on the network ignore mask and "disable |
| 592 // costly networks" flag. |
591 networks.erase(std::remove_if(networks.begin(), networks.end(), | 593 networks.erase(std::remove_if(networks.begin(), networks.end(), |
592 [this](rtc::Network* network) { | 594 [this](rtc::Network* network) { |
593 return allocator_->network_ignore_mask() & | 595 return allocator_->network_ignore_mask() & |
594 network->type(); | 596 network->type(); |
595 }), | 597 }), |
596 networks.end()); | 598 networks.end()); |
597 | |
598 if (flags() & PORTALLOCATOR_DISABLE_COSTLY_NETWORKS) { | 599 if (flags() & PORTALLOCATOR_DISABLE_COSTLY_NETWORKS) { |
599 uint16_t lowest_cost = rtc::kNetworkCostMax; | 600 uint16_t lowest_cost = rtc::kNetworkCostMax; |
600 for (rtc::Network* network : networks) { | 601 for (rtc::Network* network : networks) { |
601 lowest_cost = std::min<uint16_t>(lowest_cost, network->GetCost()); | 602 lowest_cost = std::min<uint16_t>(lowest_cost, network->GetCost()); |
602 } | 603 } |
603 networks.erase(std::remove_if(networks.begin(), networks.end(), | 604 networks.erase(std::remove_if(networks.begin(), networks.end(), |
604 [lowest_cost](rtc::Network* network) { | 605 [lowest_cost](rtc::Network* network) { |
605 return network->GetCost() > | 606 return network->GetCost() > |
606 lowest_cost + rtc::kNetworkCostLow; | 607 lowest_cost + rtc::kNetworkCostLow; |
607 }), | 608 }), |
608 networks.end()); | 609 networks.end()); |
609 } | 610 } |
| 611 // Lastly, if we have a limit for the number of IPv6 network interfaces (by |
| 612 // default, it's 5), remove networks to ensure that limit is satisfied. |
| 613 // |
| 614 // TODO(deadbeef): Instead of just taking the first N arbitrary IPv6 |
| 615 // networks, we could try to choose a set that's "most likely to work". It's |
| 616 // hard to define what that means though; it's not just "lowest cost". |
| 617 // Alternatively, we could just focus on making our ICE pinging logic smarter |
| 618 // such that this filtering isn't necessary in the first place. |
| 619 int ipv6_networks = 0; |
| 620 for (auto it = networks.begin(); it != networks.end();) { |
| 621 if ((*it)->prefix().family() == AF_INET6) { |
| 622 if (ipv6_networks >= allocator_->max_ipv6_networks()) { |
| 623 it = networks.erase(it); |
| 624 continue; |
| 625 } else { |
| 626 ++ipv6_networks; |
| 627 } |
| 628 } |
| 629 ++it; |
| 630 } |
610 return networks; | 631 return networks; |
611 } | 632 } |
612 | 633 |
613 // For each network, see if we have a sequence that covers it already. If not, | 634 // For each network, see if we have a sequence that covers it already. If not, |
614 // create a new sequence to create the appropriate ports. | 635 // create a new sequence to create the appropriate ports. |
615 void BasicPortAllocatorSession::DoAllocate(bool disable_equivalent) { | 636 void BasicPortAllocatorSession::DoAllocate(bool disable_equivalent) { |
616 bool done_signal_needed = false; | 637 bool done_signal_needed = false; |
617 std::vector<rtc::Network*> networks = GetNetworks(); | 638 std::vector<rtc::Network*> networks = GetNetworks(); |
618 if (networks.empty()) { | 639 if (networks.empty()) { |
619 LOG(LS_WARNING) << "Machine has no networks; no ports will be allocated"; | 640 LOG(LS_WARNING) << "Machine has no networks; no ports will be allocated"; |
(...skipping 938 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1558 ServerAddresses servers; | 1579 ServerAddresses servers; |
1559 for (size_t i = 0; i < relays.size(); ++i) { | 1580 for (size_t i = 0; i < relays.size(); ++i) { |
1560 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) { | 1581 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) { |
1561 servers.insert(relays[i].ports.front().address); | 1582 servers.insert(relays[i].ports.front().address); |
1562 } | 1583 } |
1563 } | 1584 } |
1564 return servers; | 1585 return servers; |
1565 } | 1586 } |
1566 | 1587 |
1567 } // namespace cricket | 1588 } // namespace cricket |
OLD | NEW |