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

mDNS peer. More...

#include <nameserver.hpp>

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

Classes

struct  PendingRequest
 pending synchronous request. More...
 

Public Types

using Socket = typename BasicDatagramNameServer<Protocol>::Socket
 
using Endpoint = typename BasicDatagramNameServer<Protocol>::Endpoint
 
using DnsNotify = std::function<void (const DnsPacket&)>
 DNS notification callback type.
 
- Public Types inherited from join::BasicDatagramNameServer< Protocol >
using Socket = typename Protocol::Socket
 
using Endpoint = typename Protocol::Endpoint
 

Public Member Functions

 BasicDatagramPeer (unsigned int ifindex, Reactor &reactor=ReactorThread::reactor())
 construct the mDNS peer instance.
 
 BasicDatagramPeer (const std::string &interface, Reactor &reactor=ReactorThread::reactor())
 construct the mDNS peer instance.
 
 BasicDatagramPeer (const BasicDatagramPeer &other)=delete
 copy constructor.
 
BasicDatagramPeeroperator= (const BasicDatagramPeer &other)=delete
 copy assignment operator.
 
 BasicDatagramPeer (BasicDatagramPeer &&other)=delete
 move constructor.
 
BasicDatagramPeeroperator= (BasicDatagramPeer &&other)=delete
 move assignment operator.
 
virtual ~BasicDatagramPeer () noexcept=default
 destroy instance.
 
int bind (int family) noexcept
 bind the socket to specified address family.
 
int probe (const std::vector< ResourceRecord > &records)
 probe the local network for the presence of a service.
 
int announce (const std::vector< ResourceRecord > &records)
 announce the presence of a service on the local network.
 
int goodbye (const std::vector< ResourceRecord > &records)
 send a goodbye message.
 
int browse (const std::string &serviceType)
 browse for services on the local network.
 
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.
 
virtual void onAnnouncement (const DnsPacket &packet)=0
 method called when a DNS query is received.
 
- Public Member Functions inherited from join::BasicDatagramNameServer< Protocol >
 BasicDatagramNameServer (Reactor &reactor=ReactorThread::reactor())
 construct the name server instance.
 
 BasicDatagramNameServer (const BasicDatagramNameServer &other)=delete
 copy constructor.
 
BasicDatagramNameServeroperator= (const BasicDatagramNameServer &other)=delete
 copy assignment operator.
 
 BasicDatagramNameServer (BasicDatagramNameServer &&other)=delete
 move constructor.
 
BasicDatagramNameServeroperator= (BasicDatagramNameServer &&other)=delete
 move assignment operator.
 
virtual ~BasicDatagramNameServer () noexcept=default
 destroy instance.
 
virtual int bind (const Endpoint &endpoint) noexcept override
 bind the socket to the given endpoint and register with the reactor.
 
virtual void close () noexcept override
 close the socket and unregister from the reactor.
 
int reply (const DnsPacket &query, const std::vector< ResourceRecord > &answers={}, const std::vector< ResourceRecord > &authorities={}, const std::vector< ResourceRecord > &additionals={}, uint16_t rcode=0)
 reply to a DNS query.
 
virtual void onQuery (const DnsPacket &packet)=0
 method called when a DNS query is received.
 
- Public Member Functions inherited from join::EventHandler
 EventHandler ()=default
 create instance.
 
 EventHandler (const EventHandler &other)=default
 copy constructor.
 
EventHandleroperator= (const EventHandler &other)=default
 copy assignment operator.
 
 EventHandler (EventHandler &&other)=default
 move constructor.
 
EventHandleroperator= (EventHandler &&other)=default
 move assignment operator.
 
virtual ~EventHandler ()=default
 destroy instance.
 

Public Attributes

DnsNotify onSuccess
 callback called when a lookup sequence succeed.
 
DnsNotify onFailure
 callback called when a lookup sequence failed.
 

Protected Member Functions

void onReadable (int fd) override final
 method called when data are ready to be read on handle.
 
void notify (const DnsNotify &func, const DnsPacket &packet) const noexcept
 safe way to notify DNS events.
 
int query (DnsPacket &packet, std::chrono::milliseconds timeout)
 serialize and send a DNS query, waiting for a response.
 
- Protected Member Functions inherited from join::BasicDatagramNameServer< Protocol >
int send (DnsPacket &packet)
 serialize and send a DNS packet.
 
- Protected Member Functions inherited from join::EventHandler
virtual void onWriteable (int fd)
 method called when data are ready to be written on handle.
 
virtual void onClose (int fd)
 method called when handle was closed by the peer.
 
virtual void onError (int fd)
 method called when an error occurred on handle.
 

Protected Attributes

unsigned int _ifindex
 interface index.
 
std::unordered_map< uint16_t, std::unique_ptr< PendingRequest > > _pending
 synchronous requests indexed by sequence number.
 
Mutex _syncMutex
 protection mutex.
 
- Protected Attributes inherited from join::BasicDatagramNameServer< Protocol >
DnsMessage _message
 DNS message codec.
 
Reactor_reactor
 event loop reactor.
 
std::unique_ptr< char[]> _buffer
 reception buffer.
 

Additional Inherited Members

- Static Protected Attributes inherited from join::BasicDatagramNameServer< Protocol >
static constexpr size_t _headerSize = 12
 DNS message header size.
 

Detailed Description

template<typename Protocol>
class join::BasicDatagramPeer< Protocol >

mDNS peer.

Member Typedef Documentation

◆ DnsNotify

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

DNS notification callback type.

◆ Endpoint

template<typename Protocol >
using join::BasicDatagramPeer< Protocol >::Endpoint = typename BasicDatagramNameServer<Protocol>::Endpoint

◆ Socket

template<typename Protocol >
using join::BasicDatagramPeer< Protocol >::Socket = typename BasicDatagramNameServer<Protocol>::Socket

Constructor & Destructor Documentation

◆ BasicDatagramPeer() [1/4]

template<typename Protocol >
join::BasicDatagramPeer< Protocol >::BasicDatagramPeer ( unsigned int ifindex,
Reactor & reactor = ReactorThread::reactor () )
inlineexplicit

construct the mDNS peer instance.

Parameters
ifindexinterface index.
reactorevent loop reactor.

◆ BasicDatagramPeer() [2/4]

template<typename Protocol >
join::BasicDatagramPeer< Protocol >::BasicDatagramPeer ( const std::string & interface,
Reactor & reactor = ReactorThread::reactor () )
inlineexplicit

construct the mDNS peer instance.

Parameters
interfaceinterface name.
reactorevent loop reactor.

◆ BasicDatagramPeer() [3/4]

template<typename Protocol >
join::BasicDatagramPeer< Protocol >::BasicDatagramPeer ( const BasicDatagramPeer< Protocol > & other)
delete

copy constructor.

Parameters
otherother object to copy.

◆ BasicDatagramPeer() [4/4]

template<typename Protocol >
join::BasicDatagramPeer< Protocol >::BasicDatagramPeer ( BasicDatagramPeer< Protocol > && other)
delete

move constructor.

Parameters
otherother object to move.

◆ ~BasicDatagramPeer()

template<typename Protocol >
virtual join::BasicDatagramPeer< Protocol >::~BasicDatagramPeer ( )
virtualdefaultnoexcept

destroy instance.

Member Function Documentation

◆ announce()

template<typename Protocol >
int join::BasicDatagramPeer< Protocol >::announce ( const std::vector< ResourceRecord > & records)
inline

announce the presence of a service on the local network.

Parameters
recordsresource records to announce.
Returns
0 on success, -1 on error.

◆ bind()

template<typename Protocol >
int join::BasicDatagramPeer< Protocol >::bind ( int family)
inlinenoexcept

bind the socket to specified address family.

Parameters
familyaddress family.
Returns
0 on success, -1 on failure.

◆ browse()

template<typename Protocol >
int join::BasicDatagramPeer< Protocol >::browse ( const std::string & serviceType)
inline

browse for services on the local network.

Parameters
serviceTypeservice type to browse for (e.g. "_http._tcp.local").
Returns
0 on success, -1 on error.

◆ goodbye()

template<typename Protocol >
int join::BasicDatagramPeer< Protocol >::goodbye ( const std::vector< ResourceRecord > & records)
inline

send a goodbye message.

Parameters
recordsresource records to send in goodbye message.
Returns
0 on success, -1 on error.

◆ notify()

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

safe way to notify DNS events.

Parameters
funcfunction to call.
packetDNS packet.

◆ onAnnouncement()

template<typename Protocol >
virtual void join::BasicDatagramPeer< Protocol >::onAnnouncement ( const DnsPacket & packet)
pure virtual

method called when a DNS query is received.

Parameters
packetparsed DNS query received.

◆ onReadable()

template<typename Protocol >
void join::BasicDatagramPeer< Protocol >::onReadable ( int fd)
inlinefinaloverrideprotectedvirtual

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

Parameters
fdfile descriptor.

Reimplemented from join::BasicDatagramNameServer< Protocol >.

◆ operator=() [1/2]

template<typename Protocol >
BasicDatagramPeer & join::BasicDatagramPeer< Protocol >::operator= ( BasicDatagramPeer< Protocol > && other)
delete

move assignment operator.

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

◆ operator=() [2/2]

template<typename Protocol >
BasicDatagramPeer & join::BasicDatagramPeer< Protocol >::operator= ( const BasicDatagramPeer< Protocol > & other)
delete

copy assignment operator.

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

◆ probe()

template<typename Protocol >
int join::BasicDatagramPeer< Protocol >::probe ( const std::vector< ResourceRecord > & records)
inline

probe the local network for the presence of a service.

Parameters
recordsresource records to query for.
Returns
0 on success, -1 on error.

◆ query()

template<typename Protocol >
int join::BasicDatagramPeer< 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.

◆ resolveAddress() [1/2]

template<typename Protocol >
IpAddress join::BasicDatagramPeer< 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<typename Protocol >
IpAddress join::BasicDatagramPeer< 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<typename Protocol >
IpAddressList join::BasicDatagramPeer< 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<typename Protocol >
IpAddressList join::BasicDatagramPeer< 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.

◆ resolveAllName()

template<typename Protocol >
AliasList join::BasicDatagramPeer< 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.

◆ resolveName()

template<typename Protocol >
std::string join::BasicDatagramPeer< 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.

Member Data Documentation

◆ _ifindex

template<typename Protocol >
unsigned int join::BasicDatagramPeer< Protocol >::_ifindex
protected

interface index.

◆ _pending

template<typename Protocol >
std::unordered_map<uint16_t, std::unique_ptr<PendingRequest> > join::BasicDatagramPeer< Protocol >::_pending
protected

synchronous requests indexed by sequence number.

◆ _syncMutex

template<typename Protocol >
Mutex join::BasicDatagramPeer< Protocol >::_syncMutex
protected

protection mutex.

◆ onFailure

template<typename Protocol >
DnsNotify join::BasicDatagramPeer< Protocol >::onFailure

callback called when a lookup sequence failed.

◆ onSuccess

template<typename Protocol >
DnsNotify join::BasicDatagramPeer< Protocol >::onSuccess

callback called when a lookup sequence succeed.


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