Add MDnsResponderInterface and obfuscate local IP addresses in gathering.

MDnsResponderInterface can be accessed by rtc::NetworkManager to
generate mDNS hostnames for local IP addresses, so that the addresses of
ICE host candidates are obfuscated in gathering whenever an mDNS
responder is present. The mDNS responder will handle incoming mDNS
queries about the generated mDNS hostnames, e.g. queries received from
the AsyncResolverInterface of the remote ICE endpoint.

Bug: webrtc:9605
Change-Id: Ib9e77427327b3d1fabdb1f3854d5e8457db40375
Reviewed-on: https://webrtc-review.googlesource.com/97881
Reviewed-by: Qingsi Wang <qingsi@webrtc.org>
Reviewed-by: Steve Anton <steveanton@webrtc.org>
Commit-Queue: Qingsi Wang <qingsi@google.com>
Cr-Commit-Position: refs/heads/master@{#24714}
diff --git a/rtc_base/network.h b/rtc_base/network.h
index ad932d0..601e39f 100644
--- a/rtc_base/network.h
+++ b/rtc_base/network.h
@@ -20,6 +20,7 @@
 #include <vector>
 
 #include "rtc_base/ipaddress.h"
+#include "rtc_base/mdns_responder_interface.h"
 #include "rtc_base/messagehandler.h"
 #include "rtc_base/networkmonitor.h"
 #include "rtc_base/third_party/sigslot/sigslot.h"
@@ -111,7 +112,7 @@
   // include ignored networks.
   virtual void GetNetworks(NetworkList* networks) const = 0;
 
-  // return the current permission state of GetNetworks()
+  // Returns the current permission state of GetNetworks().
   virtual EnumerationPermission enumeration_permission() const;
 
   // "AnyAddressNetwork" is a network which only contains single "any address"
@@ -137,6 +138,10 @@
       ipv6_network_count = 0;
     }
   };
+
+  // Returns the mDNS responder that can be used to obfuscate the local IP
+  // addresses of ICE host candidates by mDNS hostnames.
+  virtual webrtc::MDnsResponderInterface* GetMDnsResponder() const;
 };
 
 // Base class for NetworkManager implementations.
@@ -356,6 +361,19 @@
   const std::vector<InterfaceAddress>& GetIPs() const { return ips_; }
   // Clear the network's list of addresses.
   void ClearIPs() { ips_.clear(); }
+  // Sets the mDNS responder that can be used to obfuscate the local IP
+  // addresses of host candidates by mDNS names in ICE gathering. After a
+  // name-address mapping is created by the mDNS responder, queries for the
+  // created name will be resolved by the responder.
+  //
+  // The mDNS responder, if not null, should outlive this rtc::Network.
+  void SetMDnsResponder(webrtc::MDnsResponderInterface* mdns_responder) {
+    mdns_responder_ = mdns_responder;
+  }
+  // Returns the mDNS responder, which is null by default.
+  webrtc::MDnsResponderInterface* GetMDnsResponder() const {
+    return mdns_responder_;
+  }
 
   // Returns the scope-id of the network's address.
   // Should only be relevant for link-local IPv6 addresses.
@@ -428,6 +446,7 @@
   int prefix_length_;
   std::string key_;
   std::vector<InterfaceAddress> ips_;
+  webrtc::MDnsResponderInterface* mdns_responder_ = nullptr;
   int scope_id_;
   bool ignored_;
   AdapterType type_;