Async DNS resolver over UDP. More...
#include <resolver.hpp>
Public Member Functions | |
| template<typename TPoller > | |
| TResolver (TPoller &poller, EDNSType defaultType=EDNSType::A) | |
| Constructs a TResolver using the default resolv configuration. | |
| template<typename TPoller > | |
| TResolver (const TResolvConf &conf, TPoller &poller, EDNSType defaultType=EDNSType::A) | |
| Constructs a TResolver with a specified DNS configuration. | |
| template<typename TPoller > | |
| TResolver (TAddress dnsAddr, TPoller &poller, EDNSType defaultType=EDNSType::A) | |
| Constructs a TResolver using a specific DNS address. | |
| TFuture< std::vector< TAddress > > | Resolve (const std::string &hostname, EDNSType type=EDNSType::DEFAULT) |
| Resolves a hostname to a list of IP addresses. | |
Async DNS resolver over UDP.
Sends DNS queries to a nameserver (from /etc/resolv.conf by default) and caches results. Multiple concurrent Resolve() calls for the same hostname share a single in-flight query — only one UDP packet is sent.
Owns three background coroutines (sender, receiver, timeouts) that run for the lifetime of the resolver. Construct once and reuse from multiple coroutines concurrently.
| NNet::TResolver::TResolver | ( | TPoller & | poller, |
| EDNSType | defaultType = EDNSType::A |
||
| ) |
Constructs a TResolver using the default resolv configuration.
The resolver uses DNS nameservers from the default configuration file or as determined by the system.
| poller | Reference to a poller used for asynchronous operations. |
| defaultType | The default DNS record type to use if none is specified in a request. |
| NNet::TResolver::TResolver | ( | const TResolvConf & | conf, |
| TPoller & | poller, | ||
| EDNSType | defaultType = EDNSType::A |
||
| ) |
Constructs a TResolver with a specified DNS configuration.
This constructor initializes the resolver with nameservers from a given TResolvConf object.
| conf | A TResolvConf object containing DNS configuration. |
| poller | Reference to a poller for asynchronous operations. |
| defaultType | The default DNS record type to use for resolution. |
| NNet::TResolver::TResolver | ( | TAddress | dnsAddr, |
| TPoller & | poller, | ||
| EDNSType | defaultType = EDNSType::A |
||
| ) |
Constructs a TResolver using a specific DNS address.
This variant allows specifying a single DNS nameserver for resolution.
| dnsAddr | The address of the DNS server. |
| poller | Reference to a poller used for asynchronous operations. |
| defaultType | The default DNS record type for resolution. |
| TFuture< std::vector< TAddress > > NNet::TResolver::Resolve | ( | const std::string & | hostname, |
| EDNSType | type = EDNSType::DEFAULT |
||
| ) |
Resolves a hostname to a list of IP addresses.
If a cached result exists it is returned immediately without a network round-trip. If another coroutine is already resolving the same {hostname, type} pair, this call joins that in-flight query. The result vector is empty if the DNS server returned NXDOMAIN or no records.
| hostname | Hostname to resolve (e.g. "example.com"). |
| type | Record type; EDNSType::DEFAULT uses the type passed to the constructor (typically EDNSType::A). |
std::vector<TAddress>.