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

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..a93d460de24dc0e1f6858f30afb2f97396c049b8 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;
+
// 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).
@@ -1815,6 +1819,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),
resolved_known_ipv6_hostname_(false),
additional_resolver_flags_(0),
fallback_to_proctask_(true),
@@ -2167,7 +2172,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,19 +2188,13 @@ 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 = ProbeIpv6SupportCached(net_log);
+ if (!ipv6_available) {
effective_address_family = ADDRESS_FAMILY_IPV4;
effective_flags |= HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6;
}
+ net_log.AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_IPV6_REACHABILITY_CHECK,
+ NetLog::BoolCallback("ipv6_available", ipv6_available));
mmenke 2015/05/12 14:39:59 Think this makes more sense in ProbeIpv6SupportCac
Sergey Ulanov 2015/05/12 19:22:24 Done.
} else {
effective_address_family = default_address_family_;
}
@@ -2210,6 +2209,20 @@ HostResolverImpl::Key HostResolverImpl::GetEffectiveKeyForRequest(
return Key(hostname, effective_address_family, effective_flags);
}
+bool HostResolverImpl::ProbeIpv6SupportCached(const BoundNetLog& net_log) {
mmenke 2015/05/12 14:39:59 Think this method name is a little weird. Maybe I
Sergey Ulanov 2015/05/12 19:22:24 Done. Thanks for suggesting a better name!
+ base::TimeTicks now = base::TimeTicks::Now();
+
+ if ((now - last_ipv6_probe_time_).InMilliseconds() > kIpv6ProbePeriodMs) {
+ // Google DNS address.
+ IPAddressNumber address =
+ { 0x20, 0x01, 0x48, 0x60, 0x48, 0x60, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x88 };
+ last_ipv6_probe_result_ = IsGloballyReachable(address, net_log);
+ last_ipv6_probe_time_ = now;
+ }
+ 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 +2292,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