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:
@ -588,13 +588,14 @@ std::vector<rtc::Network*> BasicPortAllocatorSession::GetNetworks() {
|
||||
network_manager->GetAnyAddressNetworks(&networks);
|
||||
}
|
||||
}
|
||||
// Do some more filtering, depending on the network ignore mask and "disable
|
||||
// costly networks" flag.
|
||||
networks.erase(std::remove_if(networks.begin(), networks.end(),
|
||||
[this](rtc::Network* network) {
|
||||
return allocator_->network_ignore_mask() &
|
||||
network->type();
|
||||
}),
|
||||
networks.end());
|
||||
|
||||
if (flags() & PORTALLOCATOR_DISABLE_COSTLY_NETWORKS) {
|
||||
uint16_t lowest_cost = rtc::kNetworkCostMax;
|
||||
for (rtc::Network* network : networks) {
|
||||
@ -607,6 +608,26 @@ std::vector<rtc::Network*> BasicPortAllocatorSession::GetNetworks() {
|
||||
}),
|
||||
networks.end());
|
||||
}
|
||||
// Lastly, if we have a limit for the number of IPv6 network interfaces (by
|
||||
// default, it's 5), remove networks to ensure that limit is satisfied.
|
||||
//
|
||||
// TODO(deadbeef): Instead of just taking the first N arbitrary IPv6
|
||||
// networks, we could try to choose a set that's "most likely to work". It's
|
||||
// hard to define what that means though; it's not just "lowest cost".
|
||||
// Alternatively, we could just focus on making our ICE pinging logic smarter
|
||||
// such that this filtering isn't necessary in the first place.
|
||||
int ipv6_networks = 0;
|
||||
for (auto it = networks.begin(); it != networks.end();) {
|
||||
if ((*it)->prefix().family() == AF_INET6) {
|
||||
if (ipv6_networks >= allocator_->max_ipv6_networks()) {
|
||||
it = networks.erase(it);
|
||||
continue;
|
||||
} else {
|
||||
++ipv6_networks;
|
||||
}
|
||||
}
|
||||
++it;
|
||||
}
|
||||
return networks;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user