Add ADAPTER_TYPE_ANY in AdapterType.

ADAPTER_TYPE_ANY can be used to set the network ignore mask if an
application does not want candidates from the any address ports, the
underlying network interface types of which are not determined in
gathering. The ADAPTER_TYPE_ANY is also given the maximum network cost
so that when there are candidates from explicit network interfaces,
these candidates from the any address ports as backups, if they ever
surface, are not preferred if the other candidates have at least the
same network condition.

Bug: webrtc:9468
Change-Id: I20c3a40e9a75b8fb34fad741ba5f835ecc3b0d92
Reviewed-on: https://webrtc-review.googlesource.com/85880
Reviewed-by: Sami Kalliomäki <sakal@webrtc.org>
Reviewed-by: Tommi <tommi@webrtc.org>
Commit-Queue: Qingsi Wang <qingsi@google.com>
Cr-Commit-Position: refs/heads/master@{#23807}
diff --git a/rtc_base/network.cc b/rtc_base/network.cc
index 4bfbd0d..0f42d6f 100644
--- a/rtc_base/network.cc
+++ b/rtc_base/network.cc
@@ -94,6 +94,7 @@
 
 std::string AdapterTypeToString(AdapterType type) {
   switch (type) {
+    case ADAPTER_TYPE_ANY:
     case ADAPTER_TYPE_UNKNOWN:
       return "Unknown";
     case ADAPTER_TYPE_ETHERNET:
@@ -121,6 +122,17 @@
       return kNetworkCostLow;
     case rtc::ADAPTER_TYPE_CELLULAR:
       return kNetworkCostHigh;
+    case rtc::ADAPTER_TYPE_ANY:
+      // Candidates gathered from the any-address/wildcard ports, as backups,
+      // are given the maximum cost so that if there are other candidates with
+      // known interface types, we would not select candidate pairs using these
+      // backup candidates if other selection criteria with higher precedence
+      // (network conditions over the route) are the same. Note that setting the
+      // cost to kNetworkCostUnknown would be problematic since
+      // ADAPTER_TYPE_CELLULAR would then have a higher cost. See
+      // P2PTransportChannel::SortConnectionsAndUpdateState for how we rank and
+      // select candidate pairs, where the network cost is among the criteria.
+      return kNetworkCostMax;
     case rtc::ADAPTER_TYPE_VPN:
       // The cost of a VPN should be computed using its underlying network type.
       RTC_NOTREACHED();
@@ -265,7 +277,7 @@
   if (!ipv4_any_address_network_) {
     const rtc::IPAddress ipv4_any_address(INADDR_ANY);
     ipv4_any_address_network_.reset(
-        new rtc::Network("any", "any", ipv4_any_address, 0));
+        new rtc::Network("any", "any", ipv4_any_address, 0, ADAPTER_TYPE_ANY));
     ipv4_any_address_network_->set_default_local_address_provider(this);
     ipv4_any_address_network_->AddIP(ipv4_any_address);
   }
@@ -274,8 +286,8 @@
   if (ipv6_enabled()) {
     if (!ipv6_any_address_network_) {
       const rtc::IPAddress ipv6_any_address(in6addr_any);
-      ipv6_any_address_network_.reset(
-          new rtc::Network("any", "any", ipv6_any_address, 0));
+      ipv6_any_address_network_.reset(new rtc::Network(
+          "any", "any", ipv6_any_address, 0, ADAPTER_TYPE_ANY));
       ipv6_any_address_network_->set_default_local_address_provider(this);
       ipv6_any_address_network_->AddIP(ipv6_any_address);
     }