| 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 30 matching lines...) Expand all Loading... |
| 41 #if defined(WEBRTC_WIN) | 41 #if defined(WEBRTC_WIN) |
| 42 #include "webrtc/base/win32.h" | 42 #include "webrtc/base/win32.h" |
| 43 #include <Iphlpapi.h> | 43 #include <Iphlpapi.h> |
| 44 #endif | 44 #endif |
| 45 | 45 |
| 46 #include <stdio.h> | 46 #include <stdio.h> |
| 47 | 47 |
| 48 #include <algorithm> | 48 #include <algorithm> |
| 49 | 49 |
| 50 #include "webrtc/base/logging.h" | 50 #include "webrtc/base/logging.h" |
| 51 #include "webrtc/base/networkmonitor.h" |
| 51 #include "webrtc/base/scoped_ptr.h" | 52 #include "webrtc/base/scoped_ptr.h" |
| 52 #include "webrtc/base/socket.h" // includes something that makes windows happy | 53 #include "webrtc/base/socket.h" // includes something that makes windows happy |
| 53 #include "webrtc/base/stream.h" | 54 #include "webrtc/base/stream.h" |
| 54 #include "webrtc/base/stringencode.h" | 55 #include "webrtc/base/stringencode.h" |
| 55 #include "webrtc/base/thread.h" | 56 #include "webrtc/base/thread.h" |
| 56 | 57 |
| 57 namespace rtc { | 58 namespace rtc { |
| 58 namespace { | 59 namespace { |
| 59 | 60 |
| 60 // Turning on IPv6 could make many IPv6 interfaces available for connectivity | 61 // Turning on IPv6 could make many IPv6 interfaces available for connectivity |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 | 323 |
| 323 BasicNetworkManager::BasicNetworkManager() | 324 BasicNetworkManager::BasicNetworkManager() |
| 324 : thread_(NULL), sent_first_update_(false), start_count_(0), | 325 : thread_(NULL), sent_first_update_(false), start_count_(0), |
| 325 network_ignore_mask_(kDefaultNetworkIgnoreMask), | 326 network_ignore_mask_(kDefaultNetworkIgnoreMask), |
| 326 ignore_non_default_routes_(false) { | 327 ignore_non_default_routes_(false) { |
| 327 } | 328 } |
| 328 | 329 |
| 329 BasicNetworkManager::~BasicNetworkManager() { | 330 BasicNetworkManager::~BasicNetworkManager() { |
| 330 } | 331 } |
| 331 | 332 |
| 333 void BasicNetworkManager::OnNetworksChanged() { |
| 334 LOG(LS_VERBOSE) << "Network change was observed at the network manager"; |
| 335 UpdateNetworksOnce(); |
| 336 } |
| 337 |
| 332 #if defined(__native_client__) | 338 #if defined(__native_client__) |
| 333 | 339 |
| 334 bool BasicNetworkManager::CreateNetworks(bool include_ignored, | 340 bool BasicNetworkManager::CreateNetworks(bool include_ignored, |
| 335 NetworkList* networks) const { | 341 NetworkList* networks) const { |
| 336 ASSERT(false); | 342 ASSERT(false); |
| 337 LOG(LS_WARNING) << "BasicNetworkManager doesn't work on NaCl yet"; | 343 LOG(LS_WARNING) << "BasicNetworkManager doesn't work on NaCl yet"; |
| 338 return false; | 344 return false; |
| 339 } | 345 } |
| 340 | 346 |
| 341 #elif defined(WEBRTC_POSIX) | 347 #elif defined(WEBRTC_POSIX) |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 656 void BasicNetworkManager::StartUpdating() { | 662 void BasicNetworkManager::StartUpdating() { |
| 657 thread_ = Thread::Current(); | 663 thread_ = Thread::Current(); |
| 658 if (start_count_) { | 664 if (start_count_) { |
| 659 // If network interfaces are already discovered and signal is sent, | 665 // If network interfaces are already discovered and signal is sent, |
| 660 // we should trigger network signal immediately for the new clients | 666 // we should trigger network signal immediately for the new clients |
| 661 // to start allocating ports. | 667 // to start allocating ports. |
| 662 if (sent_first_update_) | 668 if (sent_first_update_) |
| 663 thread_->Post(this, kSignalNetworksMessage); | 669 thread_->Post(this, kSignalNetworksMessage); |
| 664 } else { | 670 } else { |
| 665 thread_->Post(this, kUpdateNetworksMessage); | 671 thread_->Post(this, kUpdateNetworksMessage); |
| 672 StartNetworkMonitor(); |
| 666 } | 673 } |
| 667 ++start_count_; | 674 ++start_count_; |
| 668 } | 675 } |
| 669 | 676 |
| 670 void BasicNetworkManager::StopUpdating() { | 677 void BasicNetworkManager::StopUpdating() { |
| 671 ASSERT(Thread::Current() == thread_); | 678 ASSERT(Thread::Current() == thread_); |
| 672 if (!start_count_) | 679 if (!start_count_) |
| 673 return; | 680 return; |
| 674 | 681 |
| 675 --start_count_; | 682 --start_count_; |
| 676 if (!start_count_) { | 683 if (!start_count_) { |
| 677 thread_->Clear(this); | 684 thread_->Clear(this); |
| 678 sent_first_update_ = false; | 685 sent_first_update_ = false; |
| 686 StopNetworkMonitor(); |
| 679 } | 687 } |
| 680 } | 688 } |
| 681 | 689 |
| 690 void BasicNetworkManager::StartNetworkMonitor() { |
| 691 NetworkMonitorFactory* factory = NetworkMonitorFactory::GetFactory(); |
| 692 if (factory == nullptr) { |
| 693 return; |
| 694 } |
| 695 network_monitor_.reset(factory->CreateNetworkMonitor()); |
| 696 if (!network_monitor_) { |
| 697 return; |
| 698 } |
| 699 network_monitor_->SignalNetworksChanged.connect( |
| 700 this, &BasicNetworkManager::OnNetworksChanged); |
| 701 network_monitor_->Start(); |
| 702 } |
| 703 |
| 704 void BasicNetworkManager::StopNetworkMonitor() { |
| 705 if (!network_monitor_) { |
| 706 return; |
| 707 } |
| 708 network_monitor_->Stop(); |
| 709 network_monitor_.reset(); |
| 710 } |
| 711 |
| 682 void BasicNetworkManager::OnMessage(Message* msg) { | 712 void BasicNetworkManager::OnMessage(Message* msg) { |
| 683 switch (msg->message_id) { | 713 switch (msg->message_id) { |
| 684 case kUpdateNetworksMessage: { | 714 case kUpdateNetworksMessage: { |
| 685 DoUpdateNetworks(); | 715 UpdateNetworksContinually(); |
| 686 break; | 716 break; |
| 687 } | 717 } |
| 688 case kSignalNetworksMessage: { | 718 case kSignalNetworksMessage: { |
| 689 SignalNetworksChanged(); | 719 SignalNetworksChanged(); |
| 690 break; | 720 break; |
| 691 } | 721 } |
| 692 default: | 722 default: |
| 693 ASSERT(false); | 723 ASSERT(false); |
| 694 } | 724 } |
| 695 } | 725 } |
| 696 | 726 |
| 697 void BasicNetworkManager::DoUpdateNetworks() { | 727 void BasicNetworkManager::UpdateNetworksOnce() { |
| 698 if (!start_count_) | 728 if (!start_count_) |
| 699 return; | 729 return; |
| 700 | 730 |
| 701 ASSERT(Thread::Current() == thread_); | 731 ASSERT(Thread::Current() == thread_); |
| 702 | 732 |
| 703 NetworkList list; | 733 NetworkList list; |
| 704 if (!CreateNetworks(false, &list)) { | 734 if (!CreateNetworks(false, &list)) { |
| 705 SignalError(); | 735 SignalError(); |
| 706 } else { | 736 } else { |
| 707 bool changed; | 737 bool changed; |
| 708 MergeNetworkList(list, &changed); | 738 MergeNetworkList(list, &changed); |
| 709 if (changed || !sent_first_update_) { | 739 if (changed || !sent_first_update_) { |
| 710 SignalNetworksChanged(); | 740 SignalNetworksChanged(); |
| 711 sent_first_update_ = true; | 741 sent_first_update_ = true; |
| 712 } | 742 } |
| 713 } | 743 } |
| 744 } |
| 714 | 745 |
| 746 void BasicNetworkManager::UpdateNetworksContinually() { |
| 747 UpdateNetworksOnce(); |
| 715 thread_->PostDelayed(kNetworksUpdateIntervalMs, this, kUpdateNetworksMessage); | 748 thread_->PostDelayed(kNetworksUpdateIntervalMs, this, kUpdateNetworksMessage); |
| 716 } | 749 } |
| 717 | 750 |
| 718 void BasicNetworkManager::DumpNetworks(bool include_ignored) { | 751 void BasicNetworkManager::DumpNetworks(bool include_ignored) { |
| 719 NetworkList list; | 752 NetworkList list; |
| 720 CreateNetworks(include_ignored, &list); | 753 CreateNetworks(include_ignored, &list); |
| 721 LOG(LS_INFO) << "NetworkManager detected " << list.size() << " networks:"; | 754 LOG(LS_INFO) << "NetworkManager detected " << list.size() << " networks:"; |
| 722 for (const Network* network : list) { | 755 for (const Network* network : list) { |
| 723 if (!network->ignored() || include_ignored) { | 756 if (!network->ignored() || include_ignored) { |
| 724 LOG(LS_INFO) << network->ToString() << ": " | 757 LOG(LS_INFO) << network->ToString() << ": " |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 812 std::stringstream ss; | 845 std::stringstream ss; |
| 813 // Print out the first space-terminated token of the network desc, plus | 846 // Print out the first space-terminated token of the network desc, plus |
| 814 // the IP address. | 847 // the IP address. |
| 815 ss << "Net[" << description_.substr(0, description_.find(' ')) | 848 ss << "Net[" << description_.substr(0, description_.find(' ')) |
| 816 << ":" << prefix_.ToSensitiveString() << "/" << prefix_length_ | 849 << ":" << prefix_.ToSensitiveString() << "/" << prefix_length_ |
| 817 << ":" << AdapterTypeToString(type_) << "]"; | 850 << ":" << AdapterTypeToString(type_) << "]"; |
| 818 return ss.str(); | 851 return ss.str(); |
| 819 } | 852 } |
| 820 | 853 |
| 821 } // namespace rtc | 854 } // namespace rtc |
| OLD | NEW |