Sese Framework  2.3.0
A cross-platform framework
Loading...
Searching...
No Matches
sese::internal::net::service::dns::DnsService Class Referencefinal

DNS service. More...

#include <DnsService.h>

Inheritance diagram for sese::internal::net::service::dns::DnsService:
sese::service::Service

Public Member Functions

 DnsService ()
 
bool bind (const sese::net::IPAddress::Ptr &address)
 Bind address.
 
void setCallback (const sese::service::dns::Callback &callback)
 Set callback, the callback function precedes domain judgment logic, similar to a filter. The return value indicates whether further processing is needed.
 
void addUpstreamNameServer (const sese::net::IPAddress::Ptr &address)
 Add upstream DNS server.
 
bool addUpstreamNameServer (const std::string &ip, uint16_t port=53)
 Add upstream DNS server.
 
void addRecord (const std::string &name, const sese::net::IPAddress::Ptr &address)
 Add record.
 
bool startup () override
 Start service.
 
bool shutdown () override
 Stop service.
 
int getLastError () override
 Get error code.
 
std::string getLastErrorMessage () override
 Get error message.
 
- Public Member Functions inherited from sese::service::Service
 Service ()=default
 
virtual ~Service ()=default
 
ErrorCode getErrorCode ()
 

Private Member Functions

void handleBySelf (std::vector< sese::net::dns::DnsPackage::Question > &questions, sese::net::dns::DnsPackage::Ptr &send_package)
 
void handleByUpstream (std::vector< sese::net::dns::DnsPackage::Question > &questions, sese::net::dns::DnsPackage::Ptr &send_package)
 
void handle ()
 

Private Attributes

asio::io_service io_service
 
asio::ip::udp::socket socket
 
asio::error_code error
 
std::array< uint8_t, 512 > buffer
 
sese::net::dns::Resolver resolver
 
Thread::Ptr thread
 
std::atomic_bool running
 
std::map< std::string, sese::net::IPv4Address::Ptrv4map
 
std::map< std::string, sese::net::IPv6Address::Ptrv6map
 
sese::service::dns::Callback callback
 

Additional Inherited Members

- Public Types inherited from sese::service::Service
using Ptr = std::unique_ptr<Service>
 

Detailed Description

DNS service.

Constructor & Destructor Documentation

◆ DnsService()

DnsService::DnsService ( )

Member Function Documentation

◆ addRecord()

void DnsService::addRecord ( const std::string & name,
const sese::net::IPAddress::Ptr & address )

Add record.

Parameters
nameDomain name
addressAddress

References v4map, and v6map.

◆ addUpstreamNameServer() [1/2]

void DnsService::addUpstreamNameServer ( const sese::net::IPAddress::Ptr & address)

Add upstream DNS server.

Parameters
addressThe address

References sese::net::dns::Resolver::addNameServer(), and resolver.

◆ addUpstreamNameServer() [2/2]

bool DnsService::addUpstreamNameServer ( const std::string & ip,
uint16_t port = 53 )

Add upstream DNS server.

Parameters
ipIP address
portPort number
Returns
Whether the addition was successful, which depends on the format of the provided IP address

References sese::net::dns::Resolver::addNameServer(), and resolver.

◆ bind()

bool DnsService::bind ( const sese::net::IPAddress::Ptr & address)

Bind address.

Parameters
addressThe address
Returns
Whether binding was successful

References sese::internal::net::convert(), error, and socket.

◆ getLastError()

int DnsService::getLastError ( )
overridevirtual

Get error code.

Returns
Error code

Implements sese::service::Service.

References error.

◆ getLastErrorMessage()

std::string DnsService::getLastErrorMessage ( )
overridevirtual

Get error message.

Returns
Error message

Implements sese::service::Service.

References error.

◆ handle()

◆ handleBySelf()

◆ handleByUpstream()

◆ setCallback()

void DnsService::setCallback ( const sese::service::dns::Callback & callback)

Set callback, the callback function precedes domain judgment logic, similar to a filter. The return value indicates whether further processing is needed.

Parameters
callbackThe callback function

References callback.

◆ shutdown()

bool DnsService::shutdown ( )
overridevirtual

Stop service.

Returns
Whether it was successful

Implements sese::service::Service.

References running, socket, and thread.

◆ startup()

bool DnsService::startup ( )
overridevirtual

Start service.

Returns
Whether it was successful

Implements sese::service::Service.

References handle(), running, and thread.

Member Data Documentation

◆ buffer

std::array<uint8_t, 512> sese::internal::net::service::dns::DnsService::buffer
private

Referenced by handle().

◆ callback

sese::service::dns::Callback sese::internal::net::service::dns::DnsService::callback
private

Referenced by handle(), and setCallback().

◆ error

asio::error_code sese::internal::net::service::dns::DnsService::error
private

◆ io_service

asio::io_service sese::internal::net::service::dns::DnsService::io_service
private

◆ resolver

sese::net::dns::Resolver sese::internal::net::service::dns::DnsService::resolver
private

◆ running

std::atomic_bool sese::internal::net::service::dns::DnsService::running
private

Referenced by handle(), shutdown(), and startup().

◆ socket

asio::ip::udp::socket sese::internal::net::service::dns::DnsService::socket
private

Referenced by bind(), handle(), and shutdown().

◆ thread

Thread::Ptr sese::internal::net::service::dns::DnsService::thread
private

Referenced by shutdown(), and startup().

◆ v4map

std::map<std::string, sese::net::IPv4Address::Ptr> sese::internal::net::service::dns::DnsService::v4map
private

◆ v6map

std::map<std::string, sese::net::IPv6Address::Ptr> sese::internal::net::service::dns::DnsService::v6map
private

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