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

Side by Side Diff: net/dns/host_resolver_impl.cc

Issue 13812002: [net/dns] Test IPv6 support via UDP connect (measurement) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use old probe for assignment, but measure performance of new test Created 7 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/dns/host_resolver_impl.h" 5 #include "net/dns/host_resolver_impl.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <Winsock2.h> 8 #include <Winsock2.h>
9 #elif defined(OS_POSIX) 9 #elif defined(OS_POSIX)
10 #include <netdb.h> 10 #include <netdb.h>
(...skipping 26 matching lines...) Expand all
37 #include "net/base/net_errors.h" 37 #include "net/base/net_errors.h"
38 #include "net/base/net_log.h" 38 #include "net/base/net_log.h"
39 #include "net/base/net_util.h" 39 #include "net/base/net_util.h"
40 #include "net/dns/address_sorter.h" 40 #include "net/dns/address_sorter.h"
41 #include "net/dns/dns_client.h" 41 #include "net/dns/dns_client.h"
42 #include "net/dns/dns_config_service.h" 42 #include "net/dns/dns_config_service.h"
43 #include "net/dns/dns_protocol.h" 43 #include "net/dns/dns_protocol.h"
44 #include "net/dns/dns_response.h" 44 #include "net/dns/dns_response.h"
45 #include "net/dns/dns_transaction.h" 45 #include "net/dns/dns_transaction.h"
46 #include "net/dns/host_resolver_proc.h" 46 #include "net/dns/host_resolver_proc.h"
47 #include "net/socket/client_socket_factory.h"
48 #include "net/udp/datagram_client_socket.h"
47 49
48 #if defined(OS_WIN) 50 #if defined(OS_WIN)
49 #include "net/base/winsock_init.h" 51 #include "net/base/winsock_init.h"
50 #endif 52 #endif
51 53
52 namespace net { 54 namespace net {
53 55
54 namespace { 56 namespace {
55 57
56 // Limit the size of hostnames that will be resolved to combat issues in 58 // Limit the size of hostnames that will be resolved to combat issues in
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 const size_t kSuffixLenTrimmed = kSuffixLen - 1; 162 const size_t kSuffixLenTrimmed = kSuffixLen - 1;
161 if (hostname[hostname.size() - 1] == '.') { 163 if (hostname[hostname.size() - 1] == '.') {
162 return hostname.size() > kSuffixLen && 164 return hostname.size() > kSuffixLen &&
163 !hostname.compare(hostname.size() - kSuffixLen, kSuffixLen, kSuffix); 165 !hostname.compare(hostname.size() - kSuffixLen, kSuffixLen, kSuffix);
164 } 166 }
165 return hostname.size() > kSuffixLenTrimmed && 167 return hostname.size() > kSuffixLenTrimmed &&
166 !hostname.compare(hostname.size() - kSuffixLenTrimmed, kSuffixLenTrimmed, 168 !hostname.compare(hostname.size() - kSuffixLenTrimmed, kSuffixLenTrimmed,
167 kSuffix, kSuffixLenTrimmed); 169 kSuffix, kSuffixLenTrimmed);
168 } 170 }
169 171
172 // Attempts to connect a UDP socket to |dest|:80.
173 int AttemptRoute(const IPAddressNumber& dest) {
174 scoped_ptr<DatagramClientSocket> socket(
175 ClientSocketFactory::GetDefaultFactory()->CreateDatagramClientSocket(
176 DatagramSocket::DEFAULT_BIND,
177 RandIntCallback(),
178 NULL,
179 NetLog::Source()));
180 return socket->Connect(IPEndPoint(dest, 80));
lorenzo 2013/04/11 07:28:14 Do you need to check that the address is a global
181 }
182
170 // Provide a common macro to simplify code and readability. We must use a 183 // Provide a common macro to simplify code and readability. We must use a
171 // macro as the underlying HISTOGRAM macro creates static variables. 184 // macro as the underlying HISTOGRAM macro creates static variables.
172 #define DNS_HISTOGRAM(name, time) UMA_HISTOGRAM_CUSTOM_TIMES(name, time, \ 185 #define DNS_HISTOGRAM(name, time) UMA_HISTOGRAM_CUSTOM_TIMES(name, time, \
173 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromHours(1), 100) 186 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromHours(1), 100)
174 187
175 // A macro to simplify code and readability. 188 // A macro to simplify code and readability.
176 #define DNS_HISTOGRAM_BY_PRIORITY(basename, priority, time) \ 189 #define DNS_HISTOGRAM_BY_PRIORITY(basename, priority, time) \
177 do { \ 190 do { \
178 switch (priority) { \ 191 switch (priority) { \
179 case HIGHEST: DNS_HISTOGRAM(basename "_HIGHEST", time); break; \ 192 case HIGHEST: DNS_HISTOGRAM(basename "_HIGHEST", time); break; \
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 894
882 BoundNetLog net_log_; 895 BoundNetLog net_log_;
883 896
884 DISALLOW_COPY_AND_ASSIGN(ProcTask); 897 DISALLOW_COPY_AND_ASSIGN(ProcTask);
885 }; 898 };
886 899
887 //----------------------------------------------------------------------------- 900 //-----------------------------------------------------------------------------
888 901
889 // Wraps a call to TestIPv6Support to be executed on the WorkerPool as it takes 902 // Wraps a call to TestIPv6Support to be executed on the WorkerPool as it takes
890 // 40-100ms. 903 // 40-100ms.
904 // TODO(szym): Remove altogether, if IPv6ActiveProbe works.
891 class HostResolverImpl::IPv6ProbeJob { 905 class HostResolverImpl::IPv6ProbeJob {
892 public: 906 public:
893 IPv6ProbeJob(const base::WeakPtr<HostResolverImpl>& resolver, NetLog* net_log) 907 IPv6ProbeJob(const base::WeakPtr<HostResolverImpl>& resolver, NetLog* net_log)
894 : resolver_(resolver), 908 : resolver_(resolver),
895 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_IPV6_PROBE_JOB)), 909 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_IPV6_PROBE_JOB)),
896 result_(false, IPV6_SUPPORT_MAX, OK) { 910 result_(false, IPV6_SUPPORT_MAX, OK) {
897 DCHECK(resolver); 911 DCHECK(resolver);
898 net_log_.BeginEvent(NetLog::TYPE_IPV6_PROBE_RUNNING); 912 net_log_.BeginEvent(NetLog::TYPE_IPV6_PROBE_RUNNING);
899 const bool kIsSlow = true; 913 const bool kIsSlow = true;
900 base::WorkerPool::PostTaskAndReply( 914 base::WorkerPool::PostTaskAndReply(
(...skipping 950 matching lines...) Expand 10 before | Expand all | Expand 10 after
1851 void HostResolverImpl::SetDefaultAddressFamily(AddressFamily address_family) { 1865 void HostResolverImpl::SetDefaultAddressFamily(AddressFamily address_family) {
1852 DCHECK(CalledOnValidThread()); 1866 DCHECK(CalledOnValidThread());
1853 default_address_family_ = address_family; 1867 default_address_family_ = address_family;
1854 ipv6_probe_monitoring_ = false; 1868 ipv6_probe_monitoring_ = false;
1855 } 1869 }
1856 1870
1857 AddressFamily HostResolverImpl::GetDefaultAddressFamily() const { 1871 AddressFamily HostResolverImpl::GetDefaultAddressFamily() const {
1858 return default_address_family_; 1872 return default_address_family_;
1859 } 1873 }
1860 1874
1875 // TODO(szym): Remove this API altogether if IPv6ActiveProbe works.
1861 void HostResolverImpl::ProbeIPv6Support() { 1876 void HostResolverImpl::ProbeIPv6Support() {
1862 DCHECK(CalledOnValidThread()); 1877 DCHECK(CalledOnValidThread());
1863 DCHECK(!ipv6_probe_monitoring_); 1878 DCHECK(!ipv6_probe_monitoring_);
1864 ipv6_probe_monitoring_ = true; 1879 ipv6_probe_monitoring_ = true;
1865 OnIPAddressChanged(); 1880 OnIPAddressChanged();
1866 } 1881 }
1867 1882
1868 void HostResolverImpl::SetDnsClientEnabled(bool enabled) { 1883 void HostResolverImpl::SetDnsClientEnabled(bool enabled) {
1869 DCHECK(CalledOnValidThread()); 1884 DCHECK(CalledOnValidThread());
1870 #if defined(ENABLE_BUILT_IN_DNS) 1885 #if defined(ENABLE_BUILT_IN_DNS)
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
2016 } else { 2031 } else {
2017 additional_resolver_flags_ &= ~HOST_RESOLVER_LOOPBACK_ONLY; 2032 additional_resolver_flags_ &= ~HOST_RESOLVER_LOOPBACK_ONLY;
2018 } 2033 }
2019 } 2034 }
2020 2035
2021 HostResolverImpl::Key HostResolverImpl::GetEffectiveKeyForRequest( 2036 HostResolverImpl::Key HostResolverImpl::GetEffectiveKeyForRequest(
2022 const RequestInfo& info) const { 2037 const RequestInfo& info) const {
2023 HostResolverFlags effective_flags = 2038 HostResolverFlags effective_flags =
2024 info.host_resolver_flags() | additional_resolver_flags_; 2039 info.host_resolver_flags() | additional_resolver_flags_;
2025 AddressFamily effective_address_family = info.address_family(); 2040 AddressFamily effective_address_family = info.address_family();
2041
2042 if (info.address_family() == ADDRESS_FAMILY_UNSPECIFIED) {
2043 base::TimeTicks start_time = base::TimeTicks::Now();
2044 // Google DNS address.
2045 const uint8 kIPv6Address[] =
2046 { 0x20, 0x01, 0x48, 0x60, 0x48, 0x60, 0x00, 0x00,
2047 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x88 };
2048 int rv6 = AttemptRoute(
2049 IPAddressNumber(kIPv6Address, kIPv6Address + arraysize(kIPv6Address)));
2050
2051 UMA_HISTOGRAM_TIMES("Net.IPv6ConnectDuration",
2052 base::TimeTicks::Now() - start_time);
2053 if (rv6 == OK) {
2054 UMA_HISTOGRAM_BOOLEAN("Net.IPv6ConnectSuccessMatch",
2055 default_address_family_ == ADDRESS_FAMILY_UNSPECIFIED);
2056 } else {
2057 UMA_HISTOGRAM_BOOLEAN("Net.IPv6ConnectFailureMatch",
2058 default_address_family_ != ADDRESS_FAMILY_UNSPECIFIED);
2059 }
2060 }
2061
2026 if (effective_address_family == ADDRESS_FAMILY_UNSPECIFIED && 2062 if (effective_address_family == ADDRESS_FAMILY_UNSPECIFIED &&
2027 default_address_family_ != ADDRESS_FAMILY_UNSPECIFIED) { 2063 default_address_family_ != ADDRESS_FAMILY_UNSPECIFIED) {
2028 effective_address_family = default_address_family_; 2064 effective_address_family = default_address_family_;
2029 if (ipv6_probe_monitoring_) 2065 if (ipv6_probe_monitoring_)
2030 effective_flags |= HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6; 2066 effective_flags |= HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6;
2031 } 2067 }
2068
2032 return Key(info.hostname(), effective_address_family, effective_flags); 2069 return Key(info.hostname(), effective_address_family, effective_flags);
2033 } 2070 }
2034 2071
2035 void HostResolverImpl::AbortAllInProgressJobs() { 2072 void HostResolverImpl::AbortAllInProgressJobs() {
2036 // In Abort, a Request callback could spawn new Jobs with matching keys, so 2073 // In Abort, a Request callback could spawn new Jobs with matching keys, so
2037 // first collect and remove all running jobs from |jobs_|. 2074 // first collect and remove all running jobs from |jobs_|.
2038 ScopedVector<Job> jobs_to_abort; 2075 ScopedVector<Job> jobs_to_abort;
2039 for (JobMap::iterator it = jobs_.begin(); it != jobs_.end(); ) { 2076 for (JobMap::iterator it = jobs_.begin(); it != jobs_.end(); ) {
2040 Job* job = it->second; 2077 Job* job = it->second;
2041 if (job->is_running()) { 2078 if (job->is_running()) {
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
2176 } 2213 }
2177 DnsConfig dns_config; 2214 DnsConfig dns_config;
2178 NetworkChangeNotifier::GetDnsConfig(&dns_config); 2215 NetworkChangeNotifier::GetDnsConfig(&dns_config);
2179 dns_client_->SetConfig(dns_config); 2216 dns_client_->SetConfig(dns_config);
2180 num_dns_failures_ = 0; 2217 num_dns_failures_ = 0;
2181 if (dns_config.IsValid()) 2218 if (dns_config.IsValid())
2182 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); 2219 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true);
2183 } 2220 }
2184 2221
2185 } // namespace net 2222 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698