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 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 AddressList& current_list = consolidated_address_list[key]; | 259 AddressList& current_list = consolidated_address_list[key]; |
260 for (const InterfaceAddress& address : addresses) { | 260 for (const InterfaceAddress& address : addresses) { |
261 current_list.ips.push_back(address); | 261 current_list.ips.push_back(address); |
262 } | 262 } |
263 if (!might_add_to_merged_list) { | 263 if (!might_add_to_merged_list) { |
264 delete network; | 264 delete network; |
265 } else { | 265 } else { |
266 if (current_list.ips[0].family() == AF_INET) { | 266 if (current_list.ips[0].family() == AF_INET) { |
267 stats->ipv4_network_count++; | 267 stats->ipv4_network_count++; |
268 } else { | 268 } else { |
269 ASSERT(current_list.ips[0].family() == AF_INET6); | 269 RTC_DCHECK(current_list.ips[0].family() == AF_INET6); |
270 stats->ipv6_network_count++; | 270 stats->ipv6_network_count++; |
271 } | 271 } |
272 } | 272 } |
273 } | 273 } |
274 | 274 |
275 // Next, look for existing network objects to re-use. | 275 // Next, look for existing network objects to re-use. |
276 // Result of Network merge. Element in this list should have unique key. | 276 // Result of Network merge. Element in this list should have unique key. |
277 NetworkList merged_list; | 277 NetworkList merged_list; |
278 for (const auto& kv : consolidated_address_list) { | 278 for (const auto& kv : consolidated_address_list) { |
279 const std::string& key = kv.first; | 279 const std::string& key = kv.first; |
(...skipping 15 matching lines...) Expand all Loading... |
295 merged_list.push_back(existing_net); | 295 merged_list.push_back(existing_net); |
296 if (net->type() != ADAPTER_TYPE_UNKNOWN && | 296 if (net->type() != ADAPTER_TYPE_UNKNOWN && |
297 net->type() != existing_net->type()) { | 297 net->type() != existing_net->type()) { |
298 existing_net->set_type(net->type()); | 298 existing_net->set_type(net->type()); |
299 *changed = true; | 299 *changed = true; |
300 } | 300 } |
301 // If the existing network was not active, networks have changed. | 301 // If the existing network was not active, networks have changed. |
302 if (!existing_net->active()) { | 302 if (!existing_net->active()) { |
303 *changed = true; | 303 *changed = true; |
304 } | 304 } |
305 ASSERT(net->active()); | 305 RTC_DCHECK(net->active()); |
306 if (existing_net != net) { | 306 if (existing_net != net) { |
307 delete net; | 307 delete net; |
308 } | 308 } |
309 } | 309 } |
310 } | 310 } |
311 // It may still happen that the merged list is a subset of |networks_|. | 311 // It may still happen that the merged list is a subset of |networks_|. |
312 // To detect this change, we compare their sizes. | 312 // To detect this change, we compare their sizes. |
313 if (merged_list.size() != networks_.size()) { | 313 if (merged_list.size() != networks_.size()) { |
314 *changed = true; | 314 *changed = true; |
315 } | 315 } |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 if (sent_first_update_) | 733 if (sent_first_update_) |
734 thread_->Post(RTC_FROM_HERE, this, kSignalNetworksMessage); | 734 thread_->Post(RTC_FROM_HERE, this, kSignalNetworksMessage); |
735 } else { | 735 } else { |
736 thread_->Post(RTC_FROM_HERE, this, kUpdateNetworksMessage); | 736 thread_->Post(RTC_FROM_HERE, this, kUpdateNetworksMessage); |
737 StartNetworkMonitor(); | 737 StartNetworkMonitor(); |
738 } | 738 } |
739 ++start_count_; | 739 ++start_count_; |
740 } | 740 } |
741 | 741 |
742 void BasicNetworkManager::StopUpdating() { | 742 void BasicNetworkManager::StopUpdating() { |
743 ASSERT(Thread::Current() == thread_); | 743 RTC_DCHECK(Thread::Current() == thread_); |
744 if (!start_count_) | 744 if (!start_count_) |
745 return; | 745 return; |
746 | 746 |
747 --start_count_; | 747 --start_count_; |
748 if (!start_count_) { | 748 if (!start_count_) { |
749 thread_->Clear(this); | 749 thread_->Clear(this); |
750 sent_first_update_ = false; | 750 sent_first_update_ = false; |
751 StopNetworkMonitor(); | 751 StopNetworkMonitor(); |
752 } | 752 } |
753 } | 753 } |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
819 } | 819 } |
820 if (strncmp(network_name, "wlan", 4) == 0) { | 820 if (strncmp(network_name, "wlan", 4) == 0) { |
821 return ADAPTER_TYPE_WIFI; | 821 return ADAPTER_TYPE_WIFI; |
822 } | 822 } |
823 #endif | 823 #endif |
824 | 824 |
825 return ADAPTER_TYPE_UNKNOWN; | 825 return ADAPTER_TYPE_UNKNOWN; |
826 } | 826 } |
827 | 827 |
828 IPAddress BasicNetworkManager::QueryDefaultLocalAddress(int family) const { | 828 IPAddress BasicNetworkManager::QueryDefaultLocalAddress(int family) const { |
829 ASSERT(thread_ == Thread::Current()); | 829 RTC_DCHECK(thread_ == Thread::Current()); |
830 ASSERT(thread_->socketserver() != nullptr); | 830 RTC_DCHECK(thread_->socketserver() != nullptr); |
831 ASSERT(family == AF_INET || family == AF_INET6); | 831 RTC_DCHECK(family == AF_INET || family == AF_INET6); |
832 | 832 |
833 std::unique_ptr<AsyncSocket> socket( | 833 std::unique_ptr<AsyncSocket> socket( |
834 thread_->socketserver()->CreateAsyncSocket(family, SOCK_DGRAM)); | 834 thread_->socketserver()->CreateAsyncSocket(family, SOCK_DGRAM)); |
835 if (!socket) { | 835 if (!socket) { |
836 LOG_ERR(LERROR) << "Socket creation failed"; | 836 LOG_ERR(LERROR) << "Socket creation failed"; |
837 return IPAddress(); | 837 return IPAddress(); |
838 } | 838 } |
839 | 839 |
840 if (socket->Connect(SocketAddress( | 840 if (socket->Connect(SocketAddress( |
841 family == AF_INET ? kPublicIPv4Host : kPublicIPv6Host, kPublicPort)) < | 841 family == AF_INET ? kPublicIPv4Host : kPublicIPv6Host, kPublicPort)) < |
842 0) { | 842 0) { |
843 if (socket->GetError() != ENETUNREACH | 843 if (socket->GetError() != ENETUNREACH |
844 && socket->GetError() != EHOSTUNREACH) { | 844 && socket->GetError() != EHOSTUNREACH) { |
845 // Ignore the expected case of "host/net unreachable" - which happens if | 845 // Ignore the expected case of "host/net unreachable" - which happens if |
846 // the network is V4- or V6-only. | 846 // the network is V4- or V6-only. |
847 LOG(LS_INFO) << "Connect failed with " << socket->GetError(); | 847 LOG(LS_INFO) << "Connect failed with " << socket->GetError(); |
848 } | 848 } |
849 return IPAddress(); | 849 return IPAddress(); |
850 } | 850 } |
851 return socket->GetLocalAddress().ipaddr(); | 851 return socket->GetLocalAddress().ipaddr(); |
852 } | 852 } |
853 | 853 |
854 void BasicNetworkManager::UpdateNetworksOnce() { | 854 void BasicNetworkManager::UpdateNetworksOnce() { |
855 if (!start_count_) | 855 if (!start_count_) |
856 return; | 856 return; |
857 | 857 |
858 ASSERT(Thread::Current() == thread_); | 858 RTC_DCHECK(Thread::Current() == thread_); |
859 | 859 |
860 NetworkList list; | 860 NetworkList list; |
861 if (!CreateNetworks(false, &list)) { | 861 if (!CreateNetworks(false, &list)) { |
862 SignalError(); | 862 SignalError(); |
863 } else { | 863 } else { |
864 bool changed; | 864 bool changed; |
865 NetworkManager::Stats stats; | 865 NetworkManager::Stats stats; |
866 MergeNetworkList(list, &changed, &stats); | 866 MergeNetworkList(list, &changed, &stats); |
867 set_default_local_addresses(QueryDefaultLocalAddress(AF_INET), | 867 set_default_local_addresses(QueryDefaultLocalAddress(AF_INET), |
868 QueryDefaultLocalAddress(AF_INET6)); | 868 QueryDefaultLocalAddress(AF_INET6)); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
982 std::stringstream ss; | 982 std::stringstream ss; |
983 // Print out the first space-terminated token of the network desc, plus | 983 // Print out the first space-terminated token of the network desc, plus |
984 // the IP address. | 984 // the IP address. |
985 ss << "Net[" << description_.substr(0, description_.find(' ')) | 985 ss << "Net[" << description_.substr(0, description_.find(' ')) |
986 << ":" << prefix_.ToSensitiveString() << "/" << prefix_length_ | 986 << ":" << prefix_.ToSensitiveString() << "/" << prefix_length_ |
987 << ":" << AdapterTypeToString(type_) << "]"; | 987 << ":" << AdapterTypeToString(type_) << "]"; |
988 return ss.str(); | 988 return ss.str(); |
989 } | 989 } |
990 | 990 |
991 } // namespace rtc | 991 } // namespace rtc |
OLD | NEW |