Chromium Code Reviews| 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 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 30 namespace rtc { | 30 namespace rtc { |
| 31 | 31 |
| 32 extern const char kPublicIPv4Host[]; | 32 extern const char kPublicIPv4Host[]; |
| 33 extern const char kPublicIPv6Host[]; | 33 extern const char kPublicIPv6Host[]; |
| 34 | 34 |
| 35 class IfAddrsConverter; | 35 class IfAddrsConverter; |
| 36 class Network; | 36 class Network; |
| 37 class NetworkMonitorInterface; | 37 class NetworkMonitorInterface; |
| 38 class Thread; | 38 class Thread; |
| 39 | 39 |
| 40 static const uint16_t kMaxNetworkCost = 999; | |
| 41 static const uint16_t kNetworkCostForUnknownType = 10; | |
|
pthatcher1
2016/05/17 21:23:11
See my comments about these names in another CL (I
honghaiz3
2016/05/18 07:41:46
Done. I once worried that one client may set its c
| |
| 40 | 42 |
| 41 // By default, ignore loopback interfaces on the host. | 43 // By default, ignore loopback interfaces on the host. |
| 42 const int kDefaultNetworkIgnoreMask = ADAPTER_TYPE_LOOPBACK; | 44 const int kDefaultNetworkIgnoreMask = ADAPTER_TYPE_LOOPBACK; |
| 43 | 45 |
| 44 // Makes a string key for this network. Used in the network manager's maps. | 46 // Makes a string key for this network. Used in the network manager's maps. |
| 45 // Network objects are keyed on interface name, network prefix and the | 47 // Network objects are keyed on interface name, network prefix and the |
| 46 // length of that prefix. | 48 // length of that prefix. |
| 47 std::string MakeNetworkKey(const std::string& name, const IPAddress& prefix, | 49 std::string MakeNetworkKey(const std::string& name, const IPAddress& prefix, |
| 48 int prefix_length); | 50 int prefix_length); |
| 49 | 51 |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 242 // Stops and removes the network monitor. | 244 // Stops and removes the network monitor. |
| 243 void StopNetworkMonitor(); | 245 void StopNetworkMonitor(); |
| 244 // Called when it receives updates from the network monitor. | 246 // Called when it receives updates from the network monitor. |
| 245 void OnNetworksChanged(); | 247 void OnNetworksChanged(); |
| 246 | 248 |
| 247 // Updates the networks and reschedules the next update. | 249 // Updates the networks and reschedules the next update. |
| 248 void UpdateNetworksContinually(); | 250 void UpdateNetworksContinually(); |
| 249 // Only updates the networks; does not reschedule the next update. | 251 // Only updates the networks; does not reschedule the next update. |
| 250 void UpdateNetworksOnce(); | 252 void UpdateNetworksOnce(); |
| 251 | 253 |
| 254 AdapterType GetAdapterTypeFromName(const char* network_name) const; | |
| 255 | |
| 252 Thread* thread_; | 256 Thread* thread_; |
| 253 bool sent_first_update_; | 257 bool sent_first_update_; |
| 254 int start_count_; | 258 int start_count_; |
| 255 std::vector<std::string> network_ignore_list_; | 259 std::vector<std::string> network_ignore_list_; |
| 256 bool ignore_non_default_routes_; | 260 bool ignore_non_default_routes_; |
| 257 std::unique_ptr<NetworkMonitorInterface> network_monitor_; | 261 std::unique_ptr<NetworkMonitorInterface> network_monitor_; |
| 258 }; | 262 }; |
| 259 | 263 |
| 260 // Represents a Unix-type network interface, with a name and single address. | 264 // Represents a Unix-type network interface, with a name and single address. |
| 261 class Network { | 265 class Network { |
| 262 public: | 266 public: |
| 263 Network(const std::string& name, | 267 Network(const std::string& name, |
| 264 const std::string& description, | 268 const std::string& description, |
| 265 const IPAddress& prefix, | 269 const IPAddress& prefix, |
| 266 int prefix_length); | 270 int prefix_length); |
| 267 | 271 |
| 268 Network(const std::string& name, | 272 Network(const std::string& name, |
| 269 const std::string& description, | 273 const std::string& description, |
| 270 const IPAddress& prefix, | 274 const IPAddress& prefix, |
| 271 int prefix_length, | 275 int prefix_length, |
| 272 AdapterType type); | 276 AdapterType type); |
| 273 ~Network(); | 277 ~Network(); |
| 274 | 278 |
| 275 sigslot::signal1<const Network*> SignalInactive; | 279 sigslot::signal1<const Network*> SignalInactive; |
| 280 sigslot::signal1<const Network*> SignalNetworkTypeChanged; | |
|
pthatcher1
2016/05/17 21:23:11
SignalTypeChanged would be enough, since this is a
honghaiz3
2016/05/18 07:41:46
Done.
| |
| 276 | 281 |
| 277 const DefaultLocalAddressProvider* default_local_address_provider() { | 282 const DefaultLocalAddressProvider* default_local_address_provider() { |
| 278 return default_local_address_provider_; | 283 return default_local_address_provider_; |
| 279 } | 284 } |
| 280 void set_default_local_address_provider( | 285 void set_default_local_address_provider( |
| 281 const DefaultLocalAddressProvider* provider) { | 286 const DefaultLocalAddressProvider* provider) { |
| 282 default_local_address_provider_ = provider; | 287 default_local_address_provider_ = provider; |
| 283 } | 288 } |
| 284 | 289 |
| 285 // Returns the name of the interface this network is associated wtih. | 290 // Returns the name of the interface this network is associated wtih. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 337 // Should only be relevant for link-local IPv6 addresses. | 342 // Should only be relevant for link-local IPv6 addresses. |
| 338 int scope_id() const { return scope_id_; } | 343 int scope_id() const { return scope_id_; } |
| 339 void set_scope_id(int id) { scope_id_ = id; } | 344 void set_scope_id(int id) { scope_id_ = id; } |
| 340 | 345 |
| 341 // Indicates whether this network should be ignored, perhaps because | 346 // Indicates whether this network should be ignored, perhaps because |
| 342 // the IP is 0, or the interface is one we know is invalid. | 347 // the IP is 0, or the interface is one we know is invalid. |
| 343 bool ignored() const { return ignored_; } | 348 bool ignored() const { return ignored_; } |
| 344 void set_ignored(bool ignored) { ignored_ = ignored; } | 349 void set_ignored(bool ignored) { ignored_ = ignored; } |
| 345 | 350 |
| 346 AdapterType type() const { return type_; } | 351 AdapterType type() const { return type_; } |
| 347 void set_type(AdapterType type) { type_ = type; } | 352 void set_type(AdapterType type) { |
| 353 if (type_ != type) { | |
|
pthatcher1
2016/05/17 21:23:11
I'd slightly prefer this with an early return:
if
honghaiz3
2016/05/18 07:41:46
Done.
| |
| 354 type_ = type; | |
| 355 SignalNetworkTypeChanged(this); | |
| 356 } | |
| 357 } | |
| 358 | |
| 359 uint16_t GetCost() const { | |
| 360 switch (type_) { | |
| 361 case rtc::ADAPTER_TYPE_UNKNOWN: | |
| 362 return kNetworkCostForUnknownType; | |
| 363 case rtc::ADAPTER_TYPE_CELLULAR: | |
| 364 return kMaxNetworkCost; | |
| 365 default: | |
|
pthatcher1
2016/05/17 21:23:11
Again, see my comments in the other CL where I thi
honghaiz3
2016/05/18 07:41:46
Done.
| |
| 366 return 0; | |
| 367 } | |
| 368 } | |
| 348 | 369 |
| 349 // A unique id assigned by the network manager, which may be signaled | 370 // A unique id assigned by the network manager, which may be signaled |
| 350 // to the remote side in the candidate. | 371 // to the remote side in the candidate. |
| 351 uint16_t id() const { return id_; } | 372 uint16_t id() const { return id_; } |
| 352 void set_id(uint16_t id) { id_ = id; } | 373 void set_id(uint16_t id) { id_ = id; } |
| 353 | 374 |
| 354 int preference() const { return preference_; } | 375 int preference() const { return preference_; } |
| 355 void set_preference(int preference) { preference_ = preference; } | 376 void set_preference(int preference) { preference_ = preference; } |
| 356 | 377 |
| 357 // When we enumerate networks and find a previously-seen network is missing, | 378 // When we enumerate networks and find a previously-seen network is missing, |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 385 int preference_; | 406 int preference_; |
| 386 bool active_ = true; | 407 bool active_ = true; |
| 387 uint16_t id_ = 0; | 408 uint16_t id_ = 0; |
| 388 | 409 |
| 389 friend class NetworkManager; | 410 friend class NetworkManager; |
| 390 }; | 411 }; |
| 391 | 412 |
| 392 } // namespace rtc | 413 } // namespace rtc |
| 393 | 414 |
| 394 #endif // WEBRTC_BASE_NETWORK_H_ | 415 #endif // WEBRTC_BASE_NETWORK_H_ |
| OLD | NEW |