Sese Framework
2.3.0
A cross-platform framework
|
DNS service. More...
#include <DnsService.h>
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::Ptr > | v4map |
std::map< std::string, sese::net::IPv6Address::Ptr > | v6map |
sese::service::dns::Callback | callback |
Additional Inherited Members | |
Public Types inherited from sese::service::Service | |
using | Ptr = std::unique_ptr<Service> |
DNS service.
DnsService::DnsService | ( | ) |
void DnsService::addRecord | ( | const std::string & | name, |
const sese::net::IPAddress::Ptr & | address ) |
void DnsService::addUpstreamNameServer | ( | const sese::net::IPAddress::Ptr & | address | ) |
Add upstream DNS server.
address | The address |
References sese::net::dns::Resolver::addNameServer(), and resolver.
bool DnsService::addUpstreamNameServer | ( | const std::string & | ip, |
uint16_t | port = 53 ) |
Add upstream DNS server.
ip | IP address |
port | Port number |
References sese::net::dns::Resolver::addNameServer(), and resolver.
bool DnsService::bind | ( | const sese::net::IPAddress::Ptr & | address | ) |
Bind address.
address | The address |
References sese::internal::net::convert(), error, and socket.
|
overridevirtual |
|
overridevirtual |
|
private |
References buffer, callback, sese::internal::net::convert(), sese::net::dns::DnsPackage::decode(), error, handleBySelf(), handleByUpstream(), sese::net::dns::DnsPackage::new_(), running, and socket.
Referenced by startup().
|
private |
References sese::net::dns::DnsPackage::Answer::class_, sese::net::dns::CLASS_IN, sese::net::dns::DnsPackage::Answer::data, sese::net::dns::DnsPackage::Answer::data_length, sese::net::dns::DnsPackage::Answer::name, sese::net::dns::DnsPackage::Answer::ttl, sese::net::dns::DnsPackage::Answer::type, sese::net::dns::TYPE_A, sese::net::dns::TYPE_AAAA, v4map, and v6map.
Referenced by handle().
|
private |
References sese::net::dns::DnsPackage::Answer::class_, sese::net::dns::DnsPackage::Answer::data, sese::net::dns::DnsPackage::Answer::data_length, sese::net::dns::DnsPackage::Answer::name, sese::net::dns::Resolver::resolve(), resolver, sese::net::dns::DnsPackage::Answer::ttl, sese::net::dns::DnsPackage::Answer::type, v4map, and v6map.
Referenced by handle().
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.
callback | The callback function |
References callback.
|
overridevirtual |
|
overridevirtual |
|
private |
Referenced by handle().
|
private |
Referenced by handle(), and setCallback().
|
private |
Referenced by bind(), getLastError(), getLastErrorMessage(), and handle().
|
private |
|
private |
Referenced by addUpstreamNameServer(), addUpstreamNameServer(), and handleByUpstream().
|
private |
Referenced by handle(), shutdown(), and startup().
|
private |
Referenced by bind(), handle(), and shutdown().
|
private |
Referenced by shutdown(), and startup().
|
private |
Referenced by addRecord(), handleBySelf(), and handleByUpstream().
|
private |
Referenced by addRecord(), handleBySelf(), and handleByUpstream().