join 1.0
lightweight network framework library
Loading...
Searching...
No Matches
join::BasicDatagramResolver< Protocol > Class Template Reference

basic DNS resolver over datagram socket. More...

#include <resolver.hpp>

Inheritance diagram for join::BasicDatagramResolver< Protocol >:
Collaboration diagram for join::BasicDatagramResolver< Protocol >:

Classes

struct  PendingRequest
 pending synchronous request. More...
 

Public Types

using Socket = typename Protocol::Socket
 
using Endpoint = typename Protocol::Endpoint
 
using State = typename Socket::State
 
using DnsNotify = std::function<void (const DnsPacket&)>
 notification callback definition.
 

Public Member Functions

 BasicDatagramResolver (const std::string &server={}, uint16_t port=Protocol::defaultPort, Reactor *reactor=nullptr)
 construct the resolver instance.
 
 BasicDatagramResolver (const BasicDatagramResolver &other)=delete
 copy constructor.
 
BasicDatagramResolveroperator= (const BasicDatagramResolver &other)=delete
 copy assignment operator.
 
 BasicDatagramResolver (BasicDatagramResolver &&other)=delete
 move constructor.
 
BasicDatagramResolveroperator= (BasicDatagramResolver &&other)=delete
 move assignment operator.
 
virtual ~BasicDatagramResolver () noexcept=default
 destroy instance.
 
virtual int connect (const Endpoint &endpoint) override
 make a connection to the given endpoint.
 
virtual int disconnect () override
 shutdown the connection.
 
IpAddressList resolveAllAddress (const std::string &host, int family, std::chrono::milliseconds timeout=std::chrono::seconds(5))
 resolve host name and return all IP addresses found.
 
IpAddressList resolveAllAddress (const std::string &host, std::chrono::milliseconds timeout=std::chrono::seconds(5))
 resolve host name and return all IP addresses found.
 
IpAddress resolveAddress (const std::string &host, int family, std::chrono::milliseconds timeout=std::chrono::seconds(5))
 resolve host name using address family.
 
IpAddress resolveAddress (const std::string &host, std::chrono::milliseconds timeout=std::chrono::seconds(5))
 resolve host name.
 
AliasList resolveAllName (const IpAddress &address, std::chrono::milliseconds timeout=std::chrono::seconds(5))
 resolve all host address.
 
std::string resolveName (const IpAddress &address, std::chrono::milliseconds timeout=std::chrono::seconds(5))
 resolve host address.
 
ServerList resolveAllNameServer (const std::string &host, std::chrono::milliseconds timeout=std::chrono::seconds(5))
 resolve all host name server.
 
std::string resolveNameServer (const std::string &host, std::chrono::milliseconds timeout=std::chrono::seconds(5))
 resolve host name server.
 
std::string resolveAuthority (const std::string &host, std::chrono::milliseconds timeout=std::chrono::seconds(5))
 resolve host start of authority name server.
 
ExchangerList resolveAllMailExchanger (const std::string &host, std::chrono::milliseconds timeout=std::chrono::seconds(5))
 resolve all host mail exchanger.
 
std::string resolveMailExchanger (const std::string &host, std::chrono::milliseconds timeout=std::chrono::seconds(5))
 resolve host mail exchanger.
 

Static Public Member Functions

static IpAddressList lookupAllAddress (const std::string &host, int family)
 resolve host name using system name servers and return all IP addresses found.
 
static IpAddressList lookupAllAddress (const std::string &host)
 resolve host name using system name servers and return all IP addresses found.
 
static IpAddress lookupAddress (const std::string &host, int family)
 resolve host name using system name servers.
 
static IpAddress lookupAddress (const std::string &host)
 resolve host name using system name servers.
 
static AliasList lookupAllName (const IpAddress &address)
 resolve all host address.
 
static std::string lookupName (const IpAddress &address)
 resolve host address.
 
static ServerList lookupAllNameServer (const std::string &host)
 resolve all host name server.
 
static std::string lookupNameServer (const std::string &host)
 resolve host name server.
 
static std::string lookupAuthority (const std::string &host)
 resolve host start of authority name server.
 
static ExchangerList lookupAllMailExchanger (const std::string &host)
 resolve all host mail exchanger.
 
static std::string lookupMailExchanger (const std::string &host)
 resolve host mail exchanger.
 
static IpAddressList nameServers () noexcept
 get IP address of the currently configured name servers.
 
static uint16_t resolveService (const std::string &service) noexcept
 resolve service name.
 

Public Attributes

DnsNotify _onSuccess
 callback called when a lookup sequence succeed.
 
DnsNotify _onFailure
 callback called when a lookup sequence failed.
 

Protected Member Functions

bool needReconnection () noexcept
 check if client must reconnect.
 
virtual int reconnect (const Endpoint &endpoint, std::chrono::milliseconds timeout)
 reconnect to the remote DNS server.
 
int query (DnsPacket &packet, std::chrono::milliseconds timeout)
 serialize and send a DNS query, waiting for a response.
 
void onReceive (int fd) override final
 method called when data are ready to be read on handle.
 
void onClose (int fd) override final
 method called when handle is closed.
 
void notify (const DnsNotify &func, const DnsPacket &packet) const noexcept
 safe way to notify DNS events.
 

Protected Attributes

DnsMessage _message
 DNS message codec.
 
std::string _server
 remote DNS server.
 
uint16_t _port
 remote DNS server port.
 
Reactor_reactor
 event loop reactor.
 
std::unique_ptr< char[]> _buffer
 reception buffer.
 
std::unordered_map< uint16_t, std::unique_ptr< PendingRequest > > _pending
 synchronous requests indexed by sequence number.
 
Mutex _syncMutex
 protection mutex.
 

Static Protected Attributes

static constexpr size_t _headerSize = 12
 DNS message header size.
 

Detailed Description

template<class Protocol>
class join::BasicDatagramResolver< Protocol >

basic DNS resolver over datagram socket.

Member Typedef Documentation

◆ DnsNotify

template<class Protocol >
using join::BasicDatagramResolver< Protocol >::DnsNotify = std::function<void (const DnsPacket&)>

notification callback definition.

◆ Endpoint

template<class Protocol >
using join::BasicDatagramResolver< Protocol >::Endpoint = typename Protocol::Endpoint

◆ Socket

template<class Protocol >
using join::BasicDatagramResolver< Protocol >::Socket = typename Protocol::Socket

◆ State

template<class Protocol >
using join::BasicDatagramResolver< Protocol >::State = typename Socket::State

Constructor & Destructor Documentation

◆ BasicDatagramResolver() [1/3]

template<class Protocol >
join::BasicDatagramResolver< Protocol >::BasicDatagramResolver ( const std::string & server = {},
uint16_t port = Protocol::defaultPort,
Reactor * reactor = nullptr )
inlineexplicit

construct the resolver instance.

Parameters
serverremote DNS server hostname or IP address.
portremote DNS server port.
reactorreactor instance.

◆ BasicDatagramResolver() [2/3]

template<class Protocol >
join::BasicDatagramResolver< Protocol >::BasicDatagramResolver ( const BasicDatagramResolver< Protocol > & other)
delete

copy constructor.

Parameters
otherother object to copy.

◆ BasicDatagramResolver() [3/3]

template<class Protocol >
join::BasicDatagramResolver< Protocol >::BasicDatagramResolver ( BasicDatagramResolver< Protocol > && other)
delete

move constructor.

Parameters
otherother object to move.

◆ ~BasicDatagramResolver()

template<class Protocol >
virtual join::BasicDatagramResolver< Protocol >::~BasicDatagramResolver ( )
virtualdefaultnoexcept

destroy instance.

Member Function Documentation

◆ connect()

template<class Protocol >
virtual int join::BasicDatagramResolver< Protocol >::connect ( const Endpoint & endpoint)
inlineoverridevirtual

make a connection to the given endpoint.

Parameters
endpointendpoint to connect to.
Returns
0 on success, -1 on failure.

Reimplemented in join::BasicTlsResolver< Protocol >.

◆ disconnect()

template<class Protocol >
virtual int join::BasicDatagramResolver< Protocol >::disconnect ( )
inlineoverridevirtual

shutdown the connection.

Returns
0 on success, -1 on failure.

◆ lookupAddress() [1/2]

template<class Protocol >
static IpAddress join::BasicDatagramResolver< Protocol >::lookupAddress ( const std::string & host)
inlinestatic

resolve host name using system name servers.

Parameters
hosthost name to resolve.
Returns
the first resolved IP address found, wildcard address on error.

◆ lookupAddress() [2/2]

template<class Protocol >
static IpAddress join::BasicDatagramResolver< Protocol >::lookupAddress ( const std::string & host,
int family )
inlinestatic

resolve host name using system name servers.

Parameters
hosthost name to resolve.
familyaddress family.
Returns
the first resolved IP address found, wildcard address on error.

◆ lookupAllAddress() [1/2]

template<class Protocol >
static IpAddressList join::BasicDatagramResolver< Protocol >::lookupAllAddress ( const std::string & host)
inlinestatic

resolve host name using system name servers and return all IP addresses found.

Parameters
hosthost name to resolve.
Returns
the resolved IP address list, empty on error.

◆ lookupAllAddress() [2/2]

template<class Protocol >
static IpAddressList join::BasicDatagramResolver< Protocol >::lookupAllAddress ( const std::string & host,
int family )
inlinestatic

resolve host name using system name servers and return all IP addresses found.

Parameters
hosthost name to resolve.
familyaddress family.
Returns
the resolved IP address list, empty on error.

◆ lookupAllMailExchanger()

template<class Protocol >
static ExchangerList join::BasicDatagramResolver< Protocol >::lookupAllMailExchanger ( const std::string & host)
inlinestatic

resolve all host mail exchanger.

Parameters
hosthost name to resolve.
Returns
the resolved mail exchanger list.

◆ lookupAllName()

template<class Protocol >
static AliasList join::BasicDatagramResolver< Protocol >::lookupAllName ( const IpAddress & address)
inlinestatic

resolve all host address.

Parameters
addresshost address to resolve.
Returns
the resolved alias list.

◆ lookupAllNameServer()

template<class Protocol >
static ServerList join::BasicDatagramResolver< Protocol >::lookupAllNameServer ( const std::string & host)
inlinestatic

resolve all host name server.

Parameters
hosthost name to resolve.
Returns
the resolved name server list.

◆ lookupAuthority()

template<class Protocol >
static std::string join::BasicDatagramResolver< Protocol >::lookupAuthority ( const std::string & host)
inlinestatic

resolve host start of authority name server.

Parameters
hosthost name to resolve.
Returns
the start of authority name server.

◆ lookupMailExchanger()

template<class Protocol >
static std::string join::BasicDatagramResolver< Protocol >::lookupMailExchanger ( const std::string & host)
inlinestatic

resolve host mail exchanger.

Parameters
hosthost name to resolve.
Returns
the first resolved mail exchanger.

◆ lookupName()

template<class Protocol >
static std::string join::BasicDatagramResolver< Protocol >::lookupName ( const IpAddress & address)
inlinestatic

resolve host address.

Parameters
addresshost address to resolve.
Returns
the first resolved alias.

◆ lookupNameServer()

template<class Protocol >
static std::string join::BasicDatagramResolver< Protocol >::lookupNameServer ( const std::string & host)
inlinestatic

resolve host name server.

Parameters
hosthost name to resolve.
Returns
the first resolved name server.

◆ nameServers()

template<class Protocol >
static IpAddressList join::BasicDatagramResolver< Protocol >::nameServers ( )
inlinestaticnoexcept

get IP address of the currently configured name servers.

Returns
a list of configured name servers.

◆ needReconnection()

template<class Protocol >
bool join::BasicDatagramResolver< Protocol >::needReconnection ( )
inlineprotectednoexcept

check if client must reconnect.

Returns
true if reconnection is required.

◆ notify()

template<class Protocol >
void join::BasicDatagramResolver< Protocol >::notify ( const DnsNotify & func,
const DnsPacket & packet ) const
inlineprotectednoexcept

safe way to notify DNS events.

Parameters
funcfunction to call.
packetDNS packet.

◆ onClose()

template<class Protocol >
void join::BasicDatagramResolver< Protocol >::onClose ( int fd)
inlinefinaloverrideprotected

method called when handle is closed.

Parameters
fdfile descriptor.

◆ onReceive()

template<class Protocol >
void join::BasicDatagramResolver< Protocol >::onReceive ( int fd)
inlinefinaloverrideprotected

method called when data are ready to be read on handle.

Parameters
fdfile descriptor.

◆ operator=() [1/2]

template<class Protocol >
BasicDatagramResolver & join::BasicDatagramResolver< Protocol >::operator= ( BasicDatagramResolver< Protocol > && other)
delete

move assignment operator.

Parameters
otherother object to move.
Returns
a reference to the current object.

◆ operator=() [2/2]

template<class Protocol >
BasicDatagramResolver & join::BasicDatagramResolver< Protocol >::operator= ( const BasicDatagramResolver< Protocol > & other)
delete

copy assignment operator.

Parameters
otherother object to copy.
Returns
a reference to the current object.

◆ query()

template<class Protocol >
int join::BasicDatagramResolver< Protocol >::query ( DnsPacket & packet,
std::chrono::milliseconds timeout )
inlineprotected

serialize and send a DNS query, waiting for a response.

Parameters
packetDNS packet to send, filled with the response on success.
timeoutquery timeout.
Returns
0 on success, -1 on error.

◆ reconnect()

template<class Protocol >
virtual int join::BasicDatagramResolver< Protocol >::reconnect ( const Endpoint & endpoint,
std::chrono::milliseconds timeout )
inlineprotectedvirtual

reconnect to the remote DNS server.

Parameters
endpointendpoint to connect to.
timeouttimeout in milliseconds.
Returns
0 on success, -1 on failure.

◆ resolveAddress() [1/2]

template<class Protocol >
IpAddress join::BasicDatagramResolver< Protocol >::resolveAddress ( const std::string & host,
int family,
std::chrono::milliseconds timeout = std::chrono::seconds (5) )
inline

resolve host name using address family.

Parameters
hosthost name to resolve.
familyaddress family.
timeouttimeout in milliseconds (default: 5000).
Returns
the first resolved IP address found matching address family.

◆ resolveAddress() [2/2]

template<class Protocol >
IpAddress join::BasicDatagramResolver< Protocol >::resolveAddress ( const std::string & host,
std::chrono::milliseconds timeout = std::chrono::seconds (5) )
inline

resolve host name.

Parameters
hosthost name to resolve.
timeouttimeout in milliseconds (default: 5000).
Returns
the first resolved IP address found.

◆ resolveAllAddress() [1/2]

template<class Protocol >
IpAddressList join::BasicDatagramResolver< Protocol >::resolveAllAddress ( const std::string & host,
int family,
std::chrono::milliseconds timeout = std::chrono::seconds (5) )
inline

resolve host name and return all IP addresses found.

Parameters
hosthost name to resolve.
familyaddress family.
timeouttimeout in milliseconds (default: 5000).
Returns
the resolved IP address list.

◆ resolveAllAddress() [2/2]

template<class Protocol >
IpAddressList join::BasicDatagramResolver< Protocol >::resolveAllAddress ( const std::string & host,
std::chrono::milliseconds timeout = std::chrono::seconds (5) )
inline

resolve host name and return all IP addresses found.

Parameters
hosthost name to resolve.
timeouttimeout in milliseconds (default: 5000).
Returns
the resolved IP address list.

◆ resolveAllMailExchanger()

template<class Protocol >
ExchangerList join::BasicDatagramResolver< Protocol >::resolveAllMailExchanger ( const std::string & host,
std::chrono::milliseconds timeout = std::chrono::seconds (5) )
inline

resolve all host mail exchanger.

Parameters
hosthost name to resolve.
timeouttimeout in milliseconds (default: 5000).
Returns
the resolved mail exchanger list.

◆ resolveAllName()

template<class Protocol >
AliasList join::BasicDatagramResolver< Protocol >::resolveAllName ( const IpAddress & address,
std::chrono::milliseconds timeout = std::chrono::seconds (5) )
inline

resolve all host address.

Parameters
addresshost address to resolve.
timeouttimeout in milliseconds (default: 5000).
Returns
the resolved alias list.

◆ resolveAllNameServer()

template<class Protocol >
ServerList join::BasicDatagramResolver< Protocol >::resolveAllNameServer ( const std::string & host,
std::chrono::milliseconds timeout = std::chrono::seconds (5) )
inline

resolve all host name server.

Parameters
hosthost name to resolve.
timeouttimeout in milliseconds (default: 5000).
Returns
the resolved name server list.

◆ resolveAuthority()

template<class Protocol >
std::string join::BasicDatagramResolver< Protocol >::resolveAuthority ( const std::string & host,
std::chrono::milliseconds timeout = std::chrono::seconds (5) )
inline

resolve host start of authority name server.

Parameters
hosthost name to resolve.
timeouttimeout in milliseconds (default: 5000).
Returns
the start of authority name server.

◆ resolveMailExchanger()

template<class Protocol >
std::string join::BasicDatagramResolver< Protocol >::resolveMailExchanger ( const std::string & host,
std::chrono::milliseconds timeout = std::chrono::seconds (5) )
inline

resolve host mail exchanger.

Parameters
hosthost name to resolve.
timeouttimeout in milliseconds (default: 5000).
Returns
the first resolved mail exchanger.

◆ resolveName()

template<class Protocol >
std::string join::BasicDatagramResolver< Protocol >::resolveName ( const IpAddress & address,
std::chrono::milliseconds timeout = std::chrono::seconds (5) )
inline

resolve host address.

Parameters
addresshost address to resolve.
timeouttimeout in milliseconds (default: 5000).
Returns
the first resolved alias.

◆ resolveNameServer()

template<class Protocol >
std::string join::BasicDatagramResolver< Protocol >::resolveNameServer ( const std::string & host,
std::chrono::milliseconds timeout = std::chrono::seconds (5) )
inline

resolve host name server.

Parameters
hosthost name to resolve.
timeouttimeout in milliseconds (default: 5000).
Returns
the first resolved name server.

◆ resolveService()

template<class Protocol >
static uint16_t join::BasicDatagramResolver< Protocol >::resolveService ( const std::string & service)
inlinestaticnoexcept

resolve service name.

Parameters
serviceservice name to resolve (ex. "http", "ftp", "ssh" etc...).
Returns
the port resolved.

Member Data Documentation

◆ _buffer

template<class Protocol >
std::unique_ptr<char[]> join::BasicDatagramResolver< Protocol >::_buffer
protected

reception buffer.

◆ _headerSize

template<class Protocol >
size_t join::BasicDatagramResolver< Protocol >::_headerSize = 12
staticconstexprprotected

DNS message header size.

◆ _message

template<class Protocol >
DnsMessage join::BasicDatagramResolver< Protocol >::_message
protected

DNS message codec.

◆ _onFailure

template<class Protocol >
DnsNotify join::BasicDatagramResolver< Protocol >::_onFailure

callback called when a lookup sequence failed.

◆ _onSuccess

template<class Protocol >
DnsNotify join::BasicDatagramResolver< Protocol >::_onSuccess

callback called when a lookup sequence succeed.

◆ _pending

template<class Protocol >
std::unordered_map<uint16_t, std::unique_ptr<PendingRequest> > join::BasicDatagramResolver< Protocol >::_pending
protected

synchronous requests indexed by sequence number.

◆ _port

template<class Protocol >
uint16_t join::BasicDatagramResolver< Protocol >::_port
protected

remote DNS server port.

◆ _reactor

template<class Protocol >
Reactor* join::BasicDatagramResolver< Protocol >::_reactor
protected

event loop reactor.

◆ _server

template<class Protocol >
std::string join::BasicDatagramResolver< Protocol >::_server
protected

remote DNS server.

◆ _syncMutex

template<class Protocol >
Mutex join::BasicDatagramResolver< Protocol >::_syncMutex
protected

protection mutex.


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