#include "net/dns/resolve_context.h"
#include <cstdlib>
#include <limits>
#include <utility>
#include "base/check_op.h"
#include "base/containers/contains.h"
#include "base/metrics/bucket_ranges.h"
#include "base/metrics/histogram.h"
#include "base/metrics/histogram_base.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/sample_vector.h"
#include "base/no_destructor.h"
#include "base/numerics/safe_conversions.h"
#include "base/observer_list.h"
#include "base/ranges/algorithm.h"
#include "base/strings/stringprintf.h"
#include "net/base/features.h"
#include "net/base/ip_address.h"
#include "net/base/network_change_notifier.h"
#include "net/dns/dns_server_iterator.h"
#include "net/dns/dns_session.h"
#include "net/dns/dns_util.h"
#include "net/dns/host_cache.h"
#include "net/dns/host_resolver_cache.h"
#include "net/dns/public/dns_over_https_config.h"
#include "net/dns/public/doh_provider_entry.h"
#include "net/dns/public/secure_dns_mode.h"
#include "net/url_request/url_request_context.h"
namespace net {
namespace {
const base::TimeDelta kMinFallbackPeriod = …;
const base::TimeDelta kDefaultMaxFallbackPeriod = …;
const base::TimeDelta kRttMax = …;
const size_t kRttBucketCount = …;
const int kRttPercentile = …;
const base::HistogramBase::Count kNumSeeds = …;
DohProviderEntry::List FindDohProvidersMatchingServerConfig(
DnsOverHttpsServerConfig server_config) { … }
DohProviderEntry::List FindDohProvidersAssociatedWithAddress(
IPAddress server_address) { … }
base::TimeDelta GetDefaultFallbackPeriod(const DnsConfig& config) { … }
base::TimeDelta GetMaxFallbackPeriod() { … }
class RttBuckets : public base::BucketRanges { … };
static RttBuckets* GetRttBuckets() { … }
static std::unique_ptr<base::SampleVector> GetRttHistogram(
base::TimeDelta rtt_estimate) { … }
#if defined(ENABLE_BUILT_IN_DNS)
constexpr size_t kDefaultCacheSize = …;
#else
constexpr size_t kDefaultCacheSize = 100;
#endif
std::unique_ptr<HostCache> CreateHostCache(bool enable_caching) { … }
std::unique_ptr<HostResolverCache> CreateHostResolverCache(
bool enable_caching) { … }
}
ResolveContext::ServerStats::ServerStats(
std::unique_ptr<base::SampleVector> buckets)
: … { … }
ResolveContext::ServerStats::ServerStats(ServerStats&&) = default;
ResolveContext::ServerStats::~ServerStats() = default;
ResolveContext::ResolveContext(URLRequestContext* url_request_context,
bool enable_caching)
: … { … }
ResolveContext::~ResolveContext() = default;
std::unique_ptr<DnsServerIterator> ResolveContext::GetDohIterator(
const DnsConfig& config,
const SecureDnsMode& mode,
const DnsSession* session) { … }
std::unique_ptr<DnsServerIterator> ResolveContext::GetClassicDnsIterator(
const DnsConfig& config,
const DnsSession* session) { … }
bool ResolveContext::GetDohServerAvailability(size_t doh_server_index,
const DnsSession* session) const { … }
size_t ResolveContext::NumAvailableDohServers(const DnsSession* session) const { … }
void ResolveContext::RecordServerFailure(size_t server_index,
bool is_doh_server,
int rv,
const DnsSession* session) { … }
void ResolveContext::RecordServerSuccess(size_t server_index,
bool is_doh_server,
const DnsSession* session) { … }
void ResolveContext::RecordRtt(size_t server_index,
bool is_doh_server,
base::TimeDelta rtt,
int rv,
const DnsSession* session) { … }
base::TimeDelta ResolveContext::NextClassicFallbackPeriod(
size_t classic_server_index,
int attempt,
const DnsSession* session) { … }
base::TimeDelta ResolveContext::NextDohFallbackPeriod(
size_t doh_server_index,
const DnsSession* session) { … }
base::TimeDelta ResolveContext::ClassicTransactionTimeout(
const DnsSession* session) { … }
base::TimeDelta ResolveContext::SecureTransactionTimeout(
SecureDnsMode secure_dns_mode,
const DnsSession* session) { … }
void ResolveContext::RegisterDohStatusObserver(DohStatusObserver* observer) { … }
void ResolveContext::UnregisterDohStatusObserver(
const DohStatusObserver* observer) { … }
void ResolveContext::InvalidateCachesAndPerSessionData(
const DnsSession* new_session,
bool network_change) { … }
void ResolveContext::StartDohAutoupgradeSuccessTimer(
const DnsSession* session) { … }
handles::NetworkHandle ResolveContext::GetTargetNetwork() const { … }
size_t ResolveContext::FirstServerIndex(bool doh_server,
const DnsSession* session) { … }
bool ResolveContext::IsCurrentSession(const DnsSession* session) const { … }
ResolveContext::ServerStats* ResolveContext::GetServerStats(
size_t server_index,
bool is_doh_server) { … }
base::TimeDelta ResolveContext::NextFallbackPeriodHelper(
const ServerStats* server_stats,
int num_backoffs) { … }
template <typename Iterator>
base::TimeDelta ResolveContext::TransactionTimeoutHelper(
Iterator server_stats_begin,
Iterator server_stats_end) { … }
void ResolveContext::RecordRttForUma(size_t server_index,
bool is_doh_server,
base::TimeDelta rtt,
int rv,
base::TimeDelta base_fallback_period,
const DnsSession* session) { … }
std::string ResolveContext::GetQueryTypeForUma(size_t server_index,
bool is_doh_server,
const DnsSession* session) { … }
std::string ResolveContext::GetDohProviderIdForUma(size_t server_index,
bool is_doh_server,
const DnsSession* session) { … }
bool ResolveContext::GetProviderUseExtraLogging(size_t server_index,
bool is_doh_server,
const DnsSession* session) { … }
void ResolveContext::NotifyDohStatusObserversOfSessionChanged() { … }
void ResolveContext::NotifyDohStatusObserversOfUnavailable(
bool network_change) { … }
void ResolveContext::EmitDohAutoupgradeSuccessMetrics() { … }
bool ResolveContext::ServerStatsToDohAvailability(
const ResolveContext::ServerStats& stats) { … }
}