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

basic DNS resolver over TLS socket (DNS over TLS). More...

#include <resolver.hpp>

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

Public Types

using Socket = typename Protocol::Socket
 
using Endpoint = typename Protocol::Endpoint
 
using State = typename Socket::State
 
- Public Types inherited from join::BasicDatagramResolver< Protocol >
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

 BasicTlsResolver (const std::string &server={}, uint16_t port=Protocol::defaultPort, Reactor *reactor=nullptr)
 construct the DoT resolver instance.
 
 BasicTlsResolver (const BasicTlsResolver &other)=delete
 copy constructor.
 
BasicTlsResolveroperator= (const BasicTlsResolver &other)=delete
 copy assignment operator.
 
 BasicTlsResolver (BasicTlsResolver &&other)=delete
 move constructor.
 
BasicTlsResolveroperator= (BasicTlsResolver &&other)=delete
 move assignment operator.
 
virtual ~BasicTlsResolver () noexcept=default
 destroy instance.
 
virtual int connect (const Endpoint &endpoint) override
 make a connection to the given endpoint.
 
virtual int connectEncrypted (const Endpoint &endpoint) override
 make an encrypted connection to the given endpoint.
 
virtual bool waitEncrypted (int timeout=0) override
 wait until TLS handshake is performed or timeout occur (non blocking socket).
 
virtual bool waitConnected (int timeout=0) override
 block until connected.
 
virtual void close () noexcept override
 close the TLS connection and reset framing state.
 
virtual int read (char *data, unsigned long maxSize) noexcept override
 read a framed DoT message (2-byte length prefix).
 
virtual int write (const char *data, unsigned long size) noexcept override
 write a framed DoT message (2-byte length prefix).
 
- Public Member Functions inherited from join::BasicDatagramResolver< Protocol >
 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 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)=delete
 resolve host name using system name servers and return all IP addresses found.
 
static IpAddressList lookupAllAddress (const std::string &host)=delete
 resolve host name using system name servers and return all IP addresses found.
 
static IpAddress lookupAddress (const std::string &host, int family)=delete
 resolve host name using system name servers.
 
static IpAddress lookupAddress (const std::string &host)=delete
 resolve host name using system name servers.
 
static AliasList lookupAllName (const IpAddress &address)=delete
 resolve all host address.
 
static std::string lookupName (const IpAddress &address)=delete
 resolve host address.
 
static ServerList lookupAllNameServer (const std::string &host)=delete
 resolve all host name server.
 
static std::string lookupNameServer (const std::string &host)=delete
 resolve host name server.
 
static std::string lookupAuthority (const std::string &host)=delete
 resolve host start of authority name server.
 
static ExchangerList lookupAllMailExchanger (const std::string &host)=delete
 resolve all host mail exchanger.
 
static std::string lookupMailExchanger (const std::string &host)=delete
 resolve host mail exchanger.
 
- Static Public Member Functions inherited from join::BasicDatagramResolver< Protocol >
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.
 

Additional Inherited Members

- Public Attributes inherited from join::BasicDatagramResolver< Protocol >
DnsNotify _onSuccess
 callback called when a lookup sequence succeed.
 
DnsNotify _onFailure
 callback called when a lookup sequence failed.
 
- Protected Member Functions inherited from join::BasicDatagramResolver< Protocol >
bool needReconnection () noexcept
 check if client must reconnect.
 
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 inherited from join::BasicDatagramResolver< Protocol >
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 inherited from join::BasicDatagramResolver< Protocol >
static constexpr size_t _headerSize = 12
 DNS message header size.
 

Detailed Description

template<class Protocol>
class join::BasicTlsResolver< Protocol >

basic DNS resolver over TLS socket (DNS over TLS).

Member Typedef Documentation

◆ Endpoint

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

◆ Socket

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

◆ State

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

Constructor & Destructor Documentation

◆ BasicTlsResolver() [1/3]

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

construct the DoT resolver instance.

Parameters
serverremote DNS server address.
portremote DNS server port.
reactorreactor instance.

◆ BasicTlsResolver() [2/3]

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

copy constructor.

Parameters
otherother object to copy.

◆ BasicTlsResolver() [3/3]

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

move constructor.

Parameters
otherother object to move.

◆ ~BasicTlsResolver()

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

destroy instance.

Member Function Documentation

◆ close()

template<class Protocol >
virtual void join::BasicTlsResolver< Protocol >::close ( )
inlineoverridevirtualnoexcept

close the TLS connection and reset framing state.

◆ connect()

template<class Protocol >
virtual int join::BasicTlsResolver< 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 from join::BasicDatagramResolver< Protocol >.

◆ connectEncrypted()

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

make an encrypted connection to the given endpoint.

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

◆ lookupAddress() [1/2]

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

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::BasicTlsResolver< Protocol >::lookupAddress ( const std::string & host,
int family )
staticdelete

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::BasicTlsResolver< Protocol >::lookupAllAddress ( const std::string & host)
staticdelete

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::BasicTlsResolver< Protocol >::lookupAllAddress ( const std::string & host,
int family )
staticdelete

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::BasicTlsResolver< Protocol >::lookupAllMailExchanger ( const std::string & host)
staticdelete

resolve all host mail exchanger.

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

◆ lookupAllName()

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

resolve all host address.

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

◆ lookupAllNameServer()

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

resolve all host name server.

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

◆ lookupAuthority()

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

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::BasicTlsResolver< Protocol >::lookupMailExchanger ( const std::string & host)
staticdelete

resolve host mail exchanger.

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

◆ lookupName()

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

resolve host address.

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

◆ lookupNameServer()

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

resolve host name server.

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

◆ operator=() [1/2]

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

move assignment operator.

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

◆ operator=() [2/2]

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

copy assignment operator.

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

◆ read()

template<class Protocol >
virtual int join::BasicTlsResolver< Protocol >::read ( char * data,
unsigned long maxSize )
inlineoverridevirtualnoexcept

read a framed DoT message (2-byte length prefix).

Parameters
datadestination buffer.
maxSizemaximum number of bytes to read.
Returns
number of bytes read, or -1 on error.

◆ waitConnected()

template<class Protocol >
virtual bool join::BasicTlsResolver< Protocol >::waitConnected ( int timeout = 0)
inlineoverridevirtual

block until connected.

Parameters
timeouttimeout in milliseconds.
Returns
true if connected, false otherwise.

◆ waitEncrypted()

template<class Protocol >
virtual bool join::BasicTlsResolver< Protocol >::waitEncrypted ( int timeout = 0)
inlineoverridevirtual

wait until TLS handshake is performed or timeout occur (non blocking socket).

Parameters
timeouttimeout in milliseconds (0: infinite). return true on success, false otherwise.

◆ write()

template<class Protocol >
virtual int join::BasicTlsResolver< Protocol >::write ( const char * data,
unsigned long size )
inlineoverridevirtualnoexcept

write a framed DoT message (2-byte length prefix).

Parameters
datasource buffer.
sizenumber of bytes to write.
Returns
number of bytes written, or -1 on error.

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