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

Side by Side Diff: webrtc/base/network.h

Issue 1976683003: Update the type and cost of existing networks if its type is found later by network monitor (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Minor changes Created 4 years, 7 months 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 unified diff | Download patch
« no previous file with comments | « webrtc/api/webrtcsdp.cc ('k') | webrtc/base/network.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 kNetworkCostMax = 999;
41 static const uint16_t kNetworkCostHigh = 900;
42 static const uint16_t kNetworkCostUnknown = 50;
43 static const uint16_t kNetworkCostLow = 10;
44 static const uint16_t kNetworkCostMin = 0;
40 45
41 // By default, ignore loopback interfaces on the host. 46 // By default, ignore loopback interfaces on the host.
42 const int kDefaultNetworkIgnoreMask = ADAPTER_TYPE_LOOPBACK; 47 const int kDefaultNetworkIgnoreMask = ADAPTER_TYPE_LOOPBACK;
43 48
44 // Makes a string key for this network. Used in the network manager's maps. 49 // 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 50 // Network objects are keyed on interface name, network prefix and the
46 // length of that prefix. 51 // length of that prefix.
47 std::string MakeNetworkKey(const std::string& name, const IPAddress& prefix, 52 std::string MakeNetworkKey(const std::string& name, const IPAddress& prefix,
48 int prefix_length); 53 int prefix_length);
49 54
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 // Stops and removes the network monitor. 247 // Stops and removes the network monitor.
243 void StopNetworkMonitor(); 248 void StopNetworkMonitor();
244 // Called when it receives updates from the network monitor. 249 // Called when it receives updates from the network monitor.
245 void OnNetworksChanged(); 250 void OnNetworksChanged();
246 251
247 // Updates the networks and reschedules the next update. 252 // Updates the networks and reschedules the next update.
248 void UpdateNetworksContinually(); 253 void UpdateNetworksContinually();
249 // Only updates the networks; does not reschedule the next update. 254 // Only updates the networks; does not reschedule the next update.
250 void UpdateNetworksOnce(); 255 void UpdateNetworksOnce();
251 256
257 AdapterType GetAdapterTypeFromName(const char* network_name) const;
258
252 Thread* thread_; 259 Thread* thread_;
253 bool sent_first_update_; 260 bool sent_first_update_;
254 int start_count_; 261 int start_count_;
255 std::vector<std::string> network_ignore_list_; 262 std::vector<std::string> network_ignore_list_;
256 bool ignore_non_default_routes_; 263 bool ignore_non_default_routes_;
257 std::unique_ptr<NetworkMonitorInterface> network_monitor_; 264 std::unique_ptr<NetworkMonitorInterface> network_monitor_;
258 }; 265 };
259 266
260 // Represents a Unix-type network interface, with a name and single address. 267 // Represents a Unix-type network interface, with a name and single address.
261 class Network { 268 class Network {
262 public: 269 public:
263 Network(const std::string& name, 270 Network(const std::string& name,
264 const std::string& description, 271 const std::string& description,
265 const IPAddress& prefix, 272 const IPAddress& prefix,
266 int prefix_length); 273 int prefix_length);
267 274
268 Network(const std::string& name, 275 Network(const std::string& name,
269 const std::string& description, 276 const std::string& description,
270 const IPAddress& prefix, 277 const IPAddress& prefix,
271 int prefix_length, 278 int prefix_length,
272 AdapterType type); 279 AdapterType type);
273 ~Network(); 280 ~Network();
274 281
275 sigslot::signal1<const Network*> SignalInactive; 282 sigslot::signal1<const Network*> SignalInactive;
283 sigslot::signal1<const Network*> SignalTypeChanged;
276 284
277 const DefaultLocalAddressProvider* default_local_address_provider() { 285 const DefaultLocalAddressProvider* default_local_address_provider() {
278 return default_local_address_provider_; 286 return default_local_address_provider_;
279 } 287 }
280 void set_default_local_address_provider( 288 void set_default_local_address_provider(
281 const DefaultLocalAddressProvider* provider) { 289 const DefaultLocalAddressProvider* provider) {
282 default_local_address_provider_ = provider; 290 default_local_address_provider_ = provider;
283 } 291 }
284 292
285 // Returns the name of the interface this network is associated wtih. 293 // Returns the name of the interface this network is associated wtih.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 // Should only be relevant for link-local IPv6 addresses. 345 // Should only be relevant for link-local IPv6 addresses.
338 int scope_id() const { return scope_id_; } 346 int scope_id() const { return scope_id_; }
339 void set_scope_id(int id) { scope_id_ = id; } 347 void set_scope_id(int id) { scope_id_ = id; }
340 348
341 // Indicates whether this network should be ignored, perhaps because 349 // Indicates whether this network should be ignored, perhaps because
342 // the IP is 0, or the interface is one we know is invalid. 350 // the IP is 0, or the interface is one we know is invalid.
343 bool ignored() const { return ignored_; } 351 bool ignored() const { return ignored_; }
344 void set_ignored(bool ignored) { ignored_ = ignored; } 352 void set_ignored(bool ignored) { ignored_ = ignored; }
345 353
346 AdapterType type() const { return type_; } 354 AdapterType type() const { return type_; }
347 void set_type(AdapterType type) { type_ = type; } 355 void set_type(AdapterType type) {
356 if (type_ == type) {
357 return;
358 }
359 type_ = type;
360 SignalTypeChanged(this);
361 }
348 362
363 uint16_t GetCost() const {
364 switch (type_) {
365 case rtc::ADAPTER_TYPE_ETHERNET:
366 case rtc::ADAPTER_TYPE_LOOPBACK:
367 return kNetworkCostMin;
368 case rtc::ADAPTER_TYPE_WIFI:
369 case rtc::ADAPTER_TYPE_VPN:
370 return kNetworkCostLow;
371 case rtc::ADAPTER_TYPE_CELLULAR:
372 return kNetworkCostHigh;
373 default:
374 return kNetworkCostUnknown;
375 }
376 }
349 // A unique id assigned by the network manager, which may be signaled 377 // A unique id assigned by the network manager, which may be signaled
350 // to the remote side in the candidate. 378 // to the remote side in the candidate.
351 uint16_t id() const { return id_; } 379 uint16_t id() const { return id_; }
352 void set_id(uint16_t id) { id_ = id; } 380 void set_id(uint16_t id) { id_ = id; }
353 381
354 int preference() const { return preference_; } 382 int preference() const { return preference_; }
355 void set_preference(int preference) { preference_ = preference; } 383 void set_preference(int preference) { preference_ = preference; }
356 384
357 // When we enumerate networks and find a previously-seen network is missing, 385 // When we enumerate networks and find a previously-seen network is missing,
358 // we do not remove it (because it may be used elsewhere). Instead, we mark 386 // we do not remove it (because it may be used elsewhere). Instead, we mark
(...skipping 26 matching lines...) Expand all
385 int preference_; 413 int preference_;
386 bool active_ = true; 414 bool active_ = true;
387 uint16_t id_ = 0; 415 uint16_t id_ = 0;
388 416
389 friend class NetworkManager; 417 friend class NetworkManager;
390 }; 418 };
391 419
392 } // namespace rtc 420 } // namespace rtc
393 421
394 #endif // WEBRTC_BASE_NETWORK_H_ 422 #endif // WEBRTC_BASE_NETWORK_H_
OLDNEW
« no previous file with comments | « webrtc/api/webrtcsdp.cc ('k') | webrtc/base/network.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698