userver: userver/clients/dns/resolver.hpp Source File
Loading...
Searching...
No Matches
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/resource_scopes.hpp>
13#include <userver/utils/statistics/rate_counter.hpp>
14
15#include <userver/static_config/dns_client.hpp>
16
17USERVER_NAMESPACE_BEGIN
18
19namespace clients::dns {
20
21/// @ingroup userver_clients
22///
23/// @brief Caching DNS resolver implementation.
24///
25/// Usually retrieved from clients::dns::Component.
26///
27/// Combines file-based (/etc/hosts) name resolution with network-based one.
28class Resolver {
29public:
31 utils::statistics::RateCounter file;
32 utils::statistics::RateCounter cached;
33 utils::statistics::RateCounter cached_stale;
34 utils::statistics::RateCounter cached_failure;
35 utils::statistics::RateCounter network;
36 utils::statistics::RateCounter network_failure;
37 };
38
39 Resolver(engine::TaskProcessor& fs_task_processor, const ::userver::static_config::DnsClient& config);
40 Resolver(const Resolver&) = delete;
41 Resolver(Resolver&&) = delete;
42 ~Resolver();
43
44 /// Performs a domain name resolution.
45 ///
46 /// Sources are tried in the following order:
47 /// - Cached file lookup table
48 /// - Cached network resolution results
49 /// - Network name servers
50 ///
51 /// @throws clients::dns::NotResolvedException if none of the sources provide
52 /// a result within the specified deadline.
53 AddrVector Resolve(const std::string& name, engine::Deadline deadline);
54
55 /// Returns lookup source counters.
57
58 /// Forces the reload of lookup table file. Waits until the reload is done.
60
61 /// Resets the network results cache.
63
64 /// Removes the specified domain name from the network results cache.
65 void FlushNetworkCache(const std::string& name);
66
67 void WriteMetrics(utils::statistics::Writer& writer) const;
68
69private:
70 class Impl;
71 constexpr static size_t kSize = 1728;
72 constexpr static size_t kAlignment = 16;
73 utils::FastPimpl<Impl, kSize, kAlignment> impl_;
74};
75
76} // namespace clients::dns
77
78USERVER_NAMESPACE_END