Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(500)

Unified Diff: webrtc/base/network.h

Issue 1411253008: WebRTC should generate default private address even when adapter enumeration is disabled. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: after rebase on master Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/base/ipaddress.cc ('k') | webrtc/base/network.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/base/network.h
diff --git a/webrtc/base/network.h b/webrtc/base/network.h
index ab3a88dc7dc0c4dd511d5da7aee4b7c035975657..ccd205e83d807cd87619732ef3dcc2527ec268ca 100644
--- a/webrtc/base/network.h
+++ b/webrtc/base/network.h
@@ -28,6 +28,9 @@ struct ifaddrs;
namespace rtc {
+extern const char kPublicIPv4Host[];
+extern const char kPublicIPv6Host[];
+
class Network;
class NetworkMonitorInterface;
class Thread;
@@ -51,9 +54,17 @@ const int kDefaultNetworkIgnoreMask = ADAPTER_TYPE_LOOPBACK;
std::string MakeNetworkKey(const std::string& name, const IPAddress& prefix,
int prefix_length);
+class DefaultLocalAddressProvider {
+ public:
+ virtual ~DefaultLocalAddressProvider() = default;
+ // The default local address is the local address used in multi-homed endpoint
+ // when the any address (0.0.0.0 or ::) is used as the local address.
+ virtual bool GetDefaultLocalAddress(int family, IPAddress* ipaddr) const = 0;
+};
+
// Generic network manager interface. It provides list of local
// networks.
-class NetworkManager {
+class NetworkManager : public DefaultLocalAddressProvider {
public:
typedef std::vector<Network*> NetworkList;
@@ -67,7 +78,7 @@ class NetworkManager {
};
NetworkManager();
- virtual ~NetworkManager();
+ ~NetworkManager() override;
// Called when network list is updated.
sigslot::signal0<> SignalNetworksChanged;
@@ -99,6 +110,8 @@ class NetworkManager {
// TODO(guoweis): remove this body when chromium implements this.
virtual void GetAnyAddressNetworks(NetworkList* networks) {}
+ bool GetDefaultLocalAddress(int family, IPAddress* ipaddr) const override;
+
// Dumps a list of networks available to LS_INFO.
virtual void DumpNetworks(bool include_ignored) {}
@@ -128,6 +141,8 @@ class NetworkManagerBase : public NetworkManager {
EnumerationPermission enumeration_permission() const override;
+ bool GetDefaultLocalAddress(int family, IPAddress* ipaddr) const override;
+
protected:
typedef std::map<std::string, Network*> NetworkMap;
// Updates |networks_| with the networks listed in |list|. If
@@ -146,6 +161,9 @@ class NetworkManagerBase : public NetworkManager {
enumeration_permission_ = state;
}
+ void set_default_local_addresses(const IPAddress& ipv4,
+ const IPAddress& ipv6);
+
private:
friend class NetworkTest;
@@ -159,6 +177,9 @@ class NetworkManagerBase : public NetworkManager {
rtc::scoped_ptr<rtc::Network> ipv4_any_address_network_;
rtc::scoped_ptr<rtc::Network> ipv6_any_address_network_;
+
+ IPAddress default_local_ipv4_address_;
+ IPAddress default_local_ipv6_address_;
};
// Basic implementation of the NetworkManager interface that gets list
@@ -220,6 +241,11 @@ class BasicNetworkManager : public NetworkManagerBase,
// based on the network's property instead of any individual IP.
bool IsIgnoredNetwork(const Network& network) const;
+ // This function connects a UDP socket to a public address and returns the
+ // local address associated it. Since it binds to the "any" address
+ // internally, it returns the default local address on a multi-homed endpoint.
+ IPAddress QueryDefaultLocalAddress(int family) const;
+
private:
friend class NetworkTest;
@@ -247,13 +273,26 @@ class BasicNetworkManager : public NetworkManagerBase,
// Represents a Unix-type network interface, with a name and single address.
class Network {
public:
- Network(const std::string& name, const std::string& description,
- const IPAddress& prefix, int prefix_length);
-
- Network(const std::string& name, const std::string& description,
- const IPAddress& prefix, int prefix_length, AdapterType type);
+ Network(const std::string& name,
+ const std::string& description,
+ const IPAddress& prefix,
+ int prefix_length);
+
+ Network(const std::string& name,
+ const std::string& description,
+ const IPAddress& prefix,
+ int prefix_length,
+ AdapterType type);
~Network();
+ const DefaultLocalAddressProvider* default_local_address_provider() {
+ return default_local_address_provider_;
+ }
+ void set_default_local_address_provider(
+ const DefaultLocalAddressProvider* provider) {
+ default_local_address_provider_ = provider;
+ }
+
// Returns the name of the interface this network is associated wtih.
const std::string& name() const { return name_; }
@@ -323,6 +362,7 @@ class Network {
std::string ToString() const;
private:
+ const DefaultLocalAddressProvider* default_local_address_provider_ = nullptr;
std::string name_;
std::string description_;
IPAddress prefix_;
« no previous file with comments | « webrtc/base/ipaddress.cc ('k') | webrtc/base/network.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698