Relanding: Move "max IPv6 networks" logic to BasicPortAllocator, and fix sorting.

Relanding because the broken chromium test has been fixed:
https://chromium-review.googlesource.com/582196

This CL moves the responsibility for restricting the number of IPv6
interfaces used for ICE to BasicPortAllocator. This is the right place
to do it in the first place; it's where all the rest of the filtering
occurs. And NetworkManager shouldn't need to know about ICE limitations;
only the ICE classes should.

Part of the reason I'm doing this is that I want to add a
"max_ipv6_networks" API to RTCConfiguration, so that applications can
override the default easily (see linked bug). But that means that
PeerConnection would need to be able to call "set_max_ipv6_networks" on
the underlying object that does the filtering, and that method isn't
available on the "NetworkManager" base class. So rather than adding
another method to a place it doesn't belong, I'm moving it to the place
it does belong.

In the process, I noticed that "CompareNetworks" is inconsistent with
"SortNetworks"; the former orders interfaces alphabetically, and the
latter reverse-alphabetically. I believe this was unintentional, and
results in undesirable behavior (like "eth1" being preferred over
"eth0"), so I'm fixing it and adding a test.

BUG=webrtc:7703

Review-Url: https://codereview.webrtc.org/2983213002
Cr-Original-Commit-Position: refs/heads/master@{#19112}
Committed: ad9561404c
Review-Url: https://codereview.webrtc.org/2983213002
Cr-Commit-Position: refs/heads/master@{#19159}
This commit is contained in:
deadbeef
2017-07-26 16:09:33 -07:00
committed by Commit Bot
parent 58f1725ff1
commit 3427f538de
7 changed files with 148 additions and 91 deletions

View File

@ -45,11 +45,6 @@
namespace rtc {
namespace {
// Turning on IPv6 could make many IPv6 interfaces available for connectivity
// check and delay the call setup time. kMaxIPv6Networks is the default upper
// limit of IPv6 networks but could be changed by set_max_ipv6_networks().
const int kMaxIPv6Networks = 5;
const uint32_t kUpdateNetworksMessage = 1;
const uint32_t kSignalNetworksMessage = 2;
@ -93,7 +88,7 @@ bool SortNetworks(const Network* a, const Network* b) {
// TODO(mallinath) - Add VPN and Link speed conditions while sorting.
// Networks are sorted last by key.
return a->key() > b->key();
return a->key() < b->key();
}
std::string AdapterTypeToString(AdapterType type) {
@ -175,7 +170,6 @@ bool NetworkManager::GetDefaultLocalAddress(int family, IPAddress* addr) const {
NetworkManagerBase::NetworkManagerBase()
: enumeration_permission_(NetworkManager::ENUMERATION_ALLOWED),
max_ipv6_networks_(kMaxIPv6Networks),
ipv6_enabled_(true) {
}
@ -213,18 +207,8 @@ void NetworkManagerBase::GetAnyAddressNetworks(NetworkList* networks) {
}
void NetworkManagerBase::GetNetworks(NetworkList* result) const {
int ipv6_networks = 0;
result->clear();
for (Network* network : networks_) {
// Keep the number of IPv6 networks under |max_ipv6_networks_|.
if (network->prefix().family() == AF_INET6) {
if (ipv6_networks >= max_ipv6_networks_) {
continue;
}
++ipv6_networks;
}
result->push_back(network);
}
result->insert(result->begin(), networks_.begin(), networks_.end());
}
void NetworkManagerBase::MergeNetworkList(const NetworkList& new_networks,