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

Unified Diff: net/dns/host_resolver_impl.cc

Issue 1138833003: Reduce frequency of IPv6 probes in HostResolverImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/dns/host_resolver_impl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/dns/host_resolver_impl.cc
diff --git a/net/dns/host_resolver_impl.cc b/net/dns/host_resolver_impl.cc
index bd6e43198dca94319fe32227f5bc89475634f90a..71cfdbd46adfdb066b89e62402df4a88e7b9b0d0 100644
--- a/net/dns/host_resolver_impl.cc
+++ b/net/dns/host_resolver_impl.cc
@@ -74,6 +74,10 @@ const unsigned kMinimumTTLSeconds = kCacheEntryTTLSeconds;
const char kLocalhost[] = "localhost.";
+// Time between IPv6 probes, i.e. for how long results of each IPv6 probe are
+// cached.
+const int kIpv6ProbePeriodMs = 1000;
pauljensen 2015/05/13 13:00:22 kIpv6->kIPv6 like kIPv6Address
Sergey Ulanov 2015/05/13 18:15:58 Done, though IMO this is not right. In CamelCase n
+
// We use a separate histogram name for each platform to facilitate the
// display of error codes by their symbolic name (since each platform has
// different mappings).
@@ -386,6 +390,15 @@ base::Value* NetLogDnsConfigCallback(const DnsConfig* config,
return config->ToValue();
}
+base::Value* NetLogIpv6AvailableCallback(bool ipv6_available,
+ bool cached,
+ NetLogCaptureMode /* capture_mode */) {
+ base::DictionaryValue* dict = new base::DictionaryValue();
+ dict->SetBoolean("ipv6_available", ipv6_available);
+ dict->SetBoolean("cached", cached);
+ return dict;
+}
+
// The logging routines are defined here because some requests are resolved
// without a Request object.
@@ -1815,6 +1828,7 @@ HostResolverImpl::HostResolverImpl(const Options& options, NetLog* net_log)
num_dns_failures_(0),
probe_ipv6_support_(true),
use_local_ipv6_(false),
+ last_ipv6_probe_result_(false),
pauljensen 2015/05/13 13:00:22 nit: Even though this initial value should never b
Sergey Ulanov 2015/05/13 18:15:59 Done.
resolved_known_ipv6_hostname_(false),
additional_resolver_flags_(0),
fallback_to_proctask_(true),
@@ -2167,7 +2181,7 @@ void HostResolverImpl::SetHaveOnlyLoopbackAddresses(bool result) {
HostResolverImpl::Key HostResolverImpl::GetEffectiveKeyForRequest(
const RequestInfo& info,
const IPAddressNumber* ip_number,
- const BoundNetLog& net_log) const {
+ const BoundNetLog& net_log) {
HostResolverFlags effective_flags =
info.host_resolver_flags() | additional_resolver_flags_;
AddressFamily effective_address_family = info.address_family();
@@ -2183,16 +2197,8 @@ HostResolverImpl::Key HostResolverImpl::GetEffectiveKeyForRequest(
// set) so the code requesting the resolution should be amenable to
// receiving a IPv6 resolution.
ip_number == nullptr) {
- // Google DNS address.
- const uint8 kIPv6Address[] =
- { 0x20, 0x01, 0x48, 0x60, 0x48, 0x60, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x88 };
- IPAddressNumber address(kIPv6Address,
- kIPv6Address + arraysize(kIPv6Address));
- bool rv6 = IsGloballyReachable(address, net_log);
- net_log.AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_IPV6_REACHABILITY_CHECK,
- NetLog::BoolCallback("ipv6_available", rv6));
- if (!rv6) {
+ bool ipv6_available = IsIpv6Reachable(net_log);
+ if (!ipv6_available) {
pauljensen 2015/05/13 13:00:22 Can we combine these two lines into "if (!IsIpv6Re
Sergey Ulanov 2015/05/13 18:15:58 Done.
effective_address_family = ADDRESS_FAMILY_IPV4;
effective_flags |= HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6;
}
@@ -2210,6 +2216,26 @@ HostResolverImpl::Key HostResolverImpl::GetEffectiveKeyForRequest(
return Key(hostname, effective_address_family, effective_flags);
}
+bool HostResolverImpl::IsIpv6Reachable(const BoundNetLog& net_log) {
+ base::TimeTicks now = base::TimeTicks::Now();
+ bool cached = true;
+ if ((now - last_ipv6_probe_time_).InMilliseconds() > kIpv6ProbePeriodMs) {
+ // Google DNS address.
+ const uint8 kIPv6Address[] =
+ { 0x20, 0x01, 0x48, 0x60, 0x48, 0x60, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x88 };
pauljensen 2015/05/13 13:00:22 Can we either move kIPv6Address up to the beginnin
Sergey Ulanov 2015/05/13 18:15:58 Done.
+ IPAddressNumber address(kIPv6Address,
+ kIPv6Address + arraysize(kIPv6Address));
+ last_ipv6_probe_result_ = IsGloballyReachable(address, net_log);
+ last_ipv6_probe_time_ = now;
+ cached = false;
+ }
+ net_log.AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_IPV6_REACHABILITY_CHECK,
+ base::Bind(&NetLogIpv6AvailableCallback,
+ last_ipv6_probe_result_, cached));
+ return last_ipv6_probe_result_;
+}
+
void HostResolverImpl::AbortAllInProgressJobs() {
// In Abort, a Request callback could spawn new Jobs with matching keys, so
// first collect and remove all running jobs from |jobs_|.
@@ -2279,6 +2305,7 @@ void HostResolverImpl::TryServingAllJobsFromHosts() {
void HostResolverImpl::OnIPAddressChanged() {
resolved_known_ipv6_hostname_ = false;
+ last_ipv6_probe_time_ = base::TimeTicks();
// Abandon all ProbeJobs.
probe_weak_ptr_factory_.InvalidateWeakPtrs();
if (cache_.get())
« no previous file with comments | « net/dns/host_resolver_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698