userver: userver/clients/dns/resolver.hpp Source File
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
resolver.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/clients/dns/resolver.hpp
4/// @brief @copybrief clients::dns::Resolver
5
6#include <userver/clients/dns/common.hpp>
7#include <userver/clients/dns/exception.hpp>
8#include <userver/engine/deadline.hpp>
9#include <userver/engine/io/sockaddr.hpp>
10#include <userver/engine/task/task_processor_fwd.hpp>
11#include <userver/utils/fast_pimpl.hpp>
12#include <userver/utils/statistics/rate_counter.hpp>
13
14#include <userver/static_config/dns_client.hpp>
15
16USERVER_NAMESPACE_BEGIN
17
18namespace clients::dns {
19
20/// @ingroup userver_clients
21///
22/// @brief Caching DNS resolver implementation.
23///
24/// Usually retrieved from clients::dns::Component.
25///
26/// Combines file-based (/etc/hosts) name resolution with network-based one.
27class Resolver {
28public:
30 utils::statistics::RateCounter file;
31 utils::statistics::RateCounter cached;
32 utils::statistics::RateCounter cached_stale;
33 utils::statistics::RateCounter cached_failure;
34 utils::statistics::RateCounter network;
35 utils::statistics::RateCounter network_failure;
36 };
37
38 Resolver(engine::TaskProcessor& fs_task_processor, const ::userver::static_config::DnsClient& config);
39 Resolver(const Resolver&) = delete;
40 Resolver(Resolver&&) = delete;
41 ~Resolver();
42
43 /// Performs a domain name resolution.
44 ///
45 /// Sources are tried in the following order:
46 /// - Cached file lookup table
47 /// - Cached network resolution results
48 /// - Network name servers
49 ///
50 /// @throws clients::dns::NotResolvedException if none of the sources provide
51 /// a result within the specified deadline.
52 AddrVector Resolve(const std::string& name, engine::Deadline deadline);
53
54 /// Returns lookup source counters.
56
57 /// Forces the reload of lookup table file. Waits until the reload is done.
59
60 /// Resets the network results cache.
62
63 /// Removes the specified domain name from the network results cache.
64 void FlushNetworkCache(const std::string& name);
65
66private:
67 class Impl;
68 constexpr static size_t kSize = 1728;
69 constexpr static size_t kAlignment = 16;
70 utils::FastPimpl<Impl, kSize, kAlignment> impl_;
71};
72
73} // namespace clients::dns
74
75USERVER_NAMESPACE_END