userver
C++ Async Framework
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
17
USERVER_NAMESPACE_BEGIN
18
19
namespace
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.
28
class
Resolver
{
29
public
:
30
struct
LookupSourceCounters
{
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.
56
const
LookupSourceCounters
&
GetLookupSourceCounters
()
const
;
57
58
/// Forces the reload of lookup table file. Waits until the reload is done.
59
void
ReloadHosts
();
60
61
/// Resets the network results cache.
62
void
FlushNetworkCache
();
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
69
private
:
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
78
USERVER_NAMESPACE_END
userver
clients
dns
resolver.hpp
Generated on Thu May 21 2026 16:16:13 for userver by
Doxygen
1.13.2