| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #ifndef WEBRTC_BASE_NETWORK_H_ | 11 #ifndef WEBRTC_BASE_NETWORK_H_ |
| 12 #define WEBRTC_BASE_NETWORK_H_ | 12 #define WEBRTC_BASE_NETWORK_H_ |
| 13 | 13 |
| 14 #include <deque> | 14 #include <deque> |
| 15 #include <map> | 15 #include <map> |
| 16 #include <string> | 16 #include <string> |
| 17 #include <vector> | 17 #include <vector> |
| 18 | 18 |
| 19 #include "webrtc/base/basictypes.h" | 19 #include "webrtc/base/basictypes.h" |
| 20 #include "webrtc/base/ipaddress.h" | 20 #include "webrtc/base/ipaddress.h" |
| 21 #include "webrtc/base/messagehandler.h" | 21 #include "webrtc/base/messagehandler.h" |
| 22 #include "webrtc/base/scoped_ptr.h" | 22 #include "webrtc/base/scoped_ptr.h" |
| 23 #include "webrtc/base/sigslot.h" | 23 #include "webrtc/base/sigslot.h" |
| 24 #include "webrtc/base/networkmonitor.h" |
| 24 | 25 |
| 25 #if defined(WEBRTC_POSIX) | 26 #if defined(WEBRTC_POSIX) |
| 26 struct ifaddrs; | 27 struct ifaddrs; |
| 27 #endif // defined(WEBRTC_POSIX) | 28 #endif // defined(WEBRTC_POSIX) |
| 28 | 29 |
| 29 namespace rtc { | 30 namespace rtc { |
| 30 | 31 |
| 31 extern const char kPublicIPv4Host[]; | 32 extern const char kPublicIPv4Host[]; |
| 32 extern const char kPublicIPv6Host[]; | 33 extern const char kPublicIPv6Host[]; |
| 33 | 34 |
| 34 class Network; | 35 class Network; |
| 36 class NetworkInformation; |
| 35 class NetworkMonitorInterface; | 37 class NetworkMonitorInterface; |
| 36 class Thread; | 38 class Thread; |
| 37 | 39 |
| 38 enum AdapterType { | 40 enum AdapterType { |
| 39 // This enum resembles the one in Chromium net::ConnectionType. | 41 // This enum resembles the one in Chromium net::ConnectionType. |
| 40 ADAPTER_TYPE_UNKNOWN = 0, | 42 ADAPTER_TYPE_UNKNOWN = 0, |
| 41 ADAPTER_TYPE_ETHERNET = 1 << 0, | 43 ADAPTER_TYPE_ETHERNET = 1 << 0, |
| 42 ADAPTER_TYPE_WIFI = 1 << 1, | 44 ADAPTER_TYPE_WIFI = 1 << 1, |
| 43 ADAPTER_TYPE_CELLULAR = 1 << 2, | 45 ADAPTER_TYPE_CELLULAR = 1 << 2, |
| 44 ADAPTER_TYPE_VPN = 1 << 3, | 46 ADAPTER_TYPE_VPN = 1 << 3, |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 | 141 |
| 140 void set_max_ipv6_networks(int networks) { max_ipv6_networks_ = networks; } | 142 void set_max_ipv6_networks(int networks) { max_ipv6_networks_ = networks; } |
| 141 int max_ipv6_networks() { return max_ipv6_networks_; } | 143 int max_ipv6_networks() { return max_ipv6_networks_; } |
| 142 | 144 |
| 143 EnumerationPermission enumeration_permission() const override; | 145 EnumerationPermission enumeration_permission() const override; |
| 144 | 146 |
| 145 bool GetDefaultLocalAddress(int family, IPAddress* ipaddr) const override; | 147 bool GetDefaultLocalAddress(int family, IPAddress* ipaddr) const override; |
| 146 | 148 |
| 147 protected: | 149 protected: |
| 148 typedef std::map<std::string, Network*> NetworkMap; | 150 typedef std::map<std::string, Network*> NetworkMap; |
| 151 NetworkMap& networks_map() { return networks_map_; } |
| 149 // Updates |networks_| with the networks listed in |list|. If | 152 // Updates |networks_| with the networks listed in |list|. If |
| 150 // |network_map_| already has a Network object for a network listed | 153 // |network_map_| already has a Network object for a network listed |
| 151 // in the |list| then it is reused. Accept ownership of the Network | 154 // in the |list| then it is reused. Accept ownership of the Network |
| 152 // objects in the |list|. |changed| will be set to true if there is | 155 // objects in the |list|. |changed| will be set to true if there is |
| 153 // any change in the network list. | 156 // any change in the network list. |
| 154 void MergeNetworkList(const NetworkList& list, bool* changed); | 157 void MergeNetworkList(const NetworkList& list, bool* changed); |
| 155 | 158 |
| 156 // |stats| will be populated even if |*changed| is false. | 159 // |stats| will be populated even if |*changed| is false. |
| 157 void MergeNetworkList(const NetworkList& list, | 160 void MergeNetworkList(const NetworkList& list, |
| 158 bool* changed, | 161 bool* changed, |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 | 243 |
| 241 // Determines if a network should be ignored. This should only be determined | 244 // Determines if a network should be ignored. This should only be determined |
| 242 // based on the network's property instead of any individual IP. | 245 // based on the network's property instead of any individual IP. |
| 243 bool IsIgnoredNetwork(const Network& network) const; | 246 bool IsIgnoredNetwork(const Network& network) const; |
| 244 | 247 |
| 245 // This function connects a UDP socket to a public address and returns the | 248 // This function connects a UDP socket to a public address and returns the |
| 246 // local address associated it. Since it binds to the "any" address | 249 // local address associated it. Since it binds to the "any" address |
| 247 // internally, it returns the default local address on a multi-homed endpoint. | 250 // internally, it returns the default local address on a multi-homed endpoint. |
| 248 IPAddress QueryDefaultLocalAddress(int family) const; | 251 IPAddress QueryDefaultLocalAddress(int family) const; |
| 249 | 252 |
| 253 |
| 254 void OnNetworkAvailable(const NetworkInformation& network_info); |
| 255 |
| 250 private: | 256 private: |
| 251 friend class NetworkTest; | 257 friend class NetworkTest; |
| 252 | 258 |
| 253 // Creates a network monitor and listens for network updates. | 259 // Creates a network monitor and listens for network updates. |
| 254 void StartNetworkMonitor(); | 260 void StartNetworkMonitor(); |
| 255 // Stops and removes the network monitor. | 261 // Stops and removes the network monitor. |
| 256 void StopNetworkMonitor(); | 262 void StopNetworkMonitor(); |
| 257 // Called when it receives updates from the network monitor. | 263 // Called when it receives updates from the network monitor. |
| 258 void OnNetworksChanged(); | 264 void OnNetworksChanged(); |
| 259 | 265 |
| 260 // Updates the networks and reschedules the next update. | 266 // Updates the networks and reschedules the next update. |
| 261 void UpdateNetworksContinually(); | 267 void UpdateNetworksContinually(); |
| 262 // Only updates the networks; does not reschedule the next update. | 268 // Only updates the networks; does not reschedule the next update. |
| 263 void UpdateNetworksOnce(); | 269 void UpdateNetworksOnce(); |
| 264 | 270 |
| 271 void GetAndUpdateNetworkInfos(); |
| 272 // this changed network info ??? |
| 273 void UpdateNetworkInfo(Network* network) const; |
| 274 |
| 275 |
| 265 Thread* thread_; | 276 Thread* thread_; |
| 266 bool sent_first_update_; | 277 bool sent_first_update_; |
| 267 int start_count_; | 278 int start_count_; |
| 268 std::vector<std::string> network_ignore_list_; | 279 std::vector<std::string> network_ignore_list_; |
| 269 int network_ignore_mask_; | 280 int network_ignore_mask_; |
| 270 bool ignore_non_default_routes_; | 281 bool ignore_non_default_routes_; |
| 271 scoped_ptr<NetworkMonitorInterface> network_monitor_; | 282 scoped_ptr<NetworkMonitorInterface> network_monitor_; |
| 283 std::map<std::string, NetworkInformation> network_infos_; |
| 272 }; | 284 }; |
| 273 | 285 |
| 274 // Represents a Unix-type network interface, with a name and single address. | 286 // Represents a Unix-type network interface, with a name and single address. |
| 275 class Network { | 287 class Network { |
| 276 public: | 288 public: |
| 277 Network(const std::string& name, | 289 Network(const std::string& name, |
| 278 const std::string& description, | 290 const std::string& description, |
| 279 const IPAddress& prefix, | 291 const IPAddress& prefix, |
| 280 int prefix_length); | 292 int prefix_length); |
| 281 | 293 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 // Returns the scope-id of the network's address. | 360 // Returns the scope-id of the network's address. |
| 349 // Should only be relevant for link-local IPv6 addresses. | 361 // Should only be relevant for link-local IPv6 addresses. |
| 350 int scope_id() const { return scope_id_; } | 362 int scope_id() const { return scope_id_; } |
| 351 void set_scope_id(int id) { scope_id_ = id; } | 363 void set_scope_id(int id) { scope_id_ = id; } |
| 352 | 364 |
| 353 // Indicates whether this network should be ignored, perhaps because | 365 // Indicates whether this network should be ignored, perhaps because |
| 354 // the IP is 0, or the interface is one we know is invalid. | 366 // the IP is 0, or the interface is one we know is invalid. |
| 355 bool ignored() const { return ignored_; } | 367 bool ignored() const { return ignored_; } |
| 356 void set_ignored(bool ignored) { ignored_ = ignored; } | 368 void set_ignored(bool ignored) { ignored_ = ignored; } |
| 357 | 369 |
| 370 uint32_t handle() const { return handle_; } |
| 371 void set_handle(uint32_t handle) { handle_ = handle; } |
| 372 |
| 358 AdapterType type() const { return type_; } | 373 AdapterType type() const { return type_; } |
| 374 void set_type(AdapterType type) { type_ = type; } |
| 375 |
| 359 int preference() const { return preference_; } | 376 int preference() const { return preference_; } |
| 360 void set_preference(int preference) { preference_ = preference; } | 377 void set_preference(int preference) { preference_ = preference; } |
| 361 | 378 |
| 362 // Debugging description of this network | 379 // Debugging description of this network |
| 363 std::string ToString() const; | 380 std::string ToString() const; |
| 364 | 381 |
| 365 private: | 382 private: |
| 366 const DefaultLocalAddressProvider* default_local_address_provider_ = nullptr; | 383 const DefaultLocalAddressProvider* default_local_address_provider_ = nullptr; |
| 367 std::string name_; | 384 std::string name_; |
| 368 std::string description_; | 385 std::string description_; |
| 369 IPAddress prefix_; | 386 IPAddress prefix_; |
| 370 int prefix_length_; | 387 int prefix_length_; |
| 371 std::string key_; | 388 std::string key_; |
| 372 std::vector<InterfaceAddress> ips_; | 389 std::vector<InterfaceAddress> ips_; |
| 373 int scope_id_; | 390 int scope_id_; |
| 374 bool ignored_; | 391 bool ignored_; |
| 375 AdapterType type_; | 392 AdapterType type_; |
| 376 int preference_; | 393 int preference_; |
| 394 uint32_t handle_ = 0; |
| 377 | 395 |
| 378 friend class NetworkManager; | 396 friend class NetworkManager; |
| 379 }; | 397 }; |
| 380 | 398 |
| 381 } // namespace rtc | 399 } // namespace rtc |
| 382 | 400 |
| 383 #endif // WEBRTC_BASE_NETWORK_H_ | 401 #endif // WEBRTC_BASE_NETWORK_H_ |
| OLD | NEW |