COROIO: NNet::TResolver Class Reference
COROIO
 
Loading...
Searching...
No Matches
NNet::TResolver Class Reference

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.
 

Detailed Description

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.

TResolver resolver(loop.Poller());
TFuture<void> lookup = [&]() -> TFuture<void> {
auto addrs = co_await resolver.Resolve("example.com"); // A record
auto v6 = co_await resolver.Resolve("example.com", EDNSType::AAAA);
TAddress addr = co_await THostPort("example.com", 80).Resolve(resolver);
}();
while (!lookup.done()) loop.Step();
A class representing an IPv4 or IPv6 address (with port).
Definition address.hpp:38
A host:port pair that resolves to a TAddress.
Definition resolver.hpp:261
TFuture< TAddress > Resolve(TResolver &resolver)
Resolves the host to a TAddress using the given resolver.
Definition resolver.hpp:274
Event loop that drives a poller backend.
Definition loop.hpp:30
TPoller & Poller()
Provides access to the underlying poller instance.
Definition loop.hpp:57
void Step()
Runs one event-loop iteration: polls for I/O/timer events then resumes all coroutines whose events fi...
Definition loop.hpp:50
Async DNS resolver over UDP.
Definition resolver.hpp:115
Owned coroutine handle that carries a result of type T.
Definition corochain.hpp:185

Constructor & Destructor Documentation

◆ TResolver() [1/3]

template<typename TPoller >
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.

Parameters
pollerReference to a poller used for asynchronous operations.
defaultTypeThe default DNS record type to use if none is specified in a request.

◆ TResolver() [2/3]

template<typename TPoller >
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.

Parameters
confA TResolvConf object containing DNS configuration.
pollerReference to a poller for asynchronous operations.
defaultTypeThe default DNS record type to use for resolution.

◆ TResolver() [3/3]

template<typename TPoller >
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.

Parameters
dnsAddrThe address of the DNS server.
pollerReference to a poller used for asynchronous operations.
defaultTypeThe default DNS record type for resolution.

Member Function Documentation

◆ Resolve()

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.

Parameters
hostnameHostname to resolve (e.g. "example.com").
typeRecord type; EDNSType::DEFAULT uses the type passed to the constructor (typically EDNSType::A).
Returns
Awaitable resolving to a std::vector<TAddress>.

The documentation for this class was generated from the following files: