21#ifndef G_NET_DNS_BLOCK_H
22#define G_NET_DNS_BLOCK_H
38 class DnsBlockResult ;
39 class DnsBlockServerResult ;
40 class DnsBlockCallback ;
52 void set(
const std::vector<Address> & ) ;
58 std::string
server()
const ;
61 const std::vector<Address> &
addresses()
const ;
66 std::string m_server ;
68 std::vector<Address> m_addresses ;
118 const std::vector<DnsBlockServerResult> &
list()
const ;
128 using ResultList = std::vector<DnsBlockServerResult> ;
129 Type m_type{Type::Inactive} ;
130 std::size_t m_threshold{0U} ;
147 G_EXCEPTION( Error ,
"dnsbl error" ) ;
148 using ResultList = std::vector<DnsBlockServerResult> ;
154 void configure(
const Address & dns_server , std::size_t threshold ,
bool allow_on_timeout ,
177 void operator=(
const DnsBlock & ) = delete ;
178 void operator=(
DnsBlock && ) = delete ;
181 void readEvent()
override ;
184 static void configureImp(
const std::string & ,
DnsBlock * ) ;
186 static std::string queryString(
const Address & ) ;
187 static std::size_t countResponders(
const ResultList & ) ;
188 static std::size_t countDeniers(
const ResultList & ) ;
195 std::size_t m_threshold ;
196 bool m_allow_on_timeout ;
200 unsigned int m_id_base ;
201 std::unique_ptr<DatagramSocket> m_socket_ptr ;
230 m_addresses = addresses ;
253 m_address(
Address::defaultAddress())
260 m_threshold = threshold ;
261 m_address = address ;
279 m_list.push_back( server_result ) ;
285 return m_list.at( i ) ;
The GNet::Address class encapsulates a TCP/UDP transport address.
A callback interface for GNet::DnsBlock.
virtual void onDnsBlockResult(const DnsBlockResult &)=0
Called with the results from DnsBlock::start().
virtual ~DnsBlockCallback()=default
Desstructor.
A result structure for GNet::DnsBlock, as delivered by the DnsBlockCallback interface.
void add(const DnsBlockServerResult &)
Appends the server result.
void warn() const
Emits warnings.
bool allow() const
Returns true if the type is Inactive, Local, TimeoutAllow or Allow.
G::StringArray laggards() const
Returns the list of slow or unresponsive servers.
void reset(std::size_t threshold, const Address &)
Initialiser.
Type & type()
Returns a settable reference to the overall result type.
DnsBlockServerResult & at(std::size_t)
Returns a reference to the given per-server result.
DnsBlockResult()
Constructor.
const std::vector< DnsBlockServerResult > & list() const
Returns a reference to the per-server results.
G::StringArray deniers() const
Returns the list of denying servers.
void log() const
Logs the results.
bool deny() const
Returns true if the type is TimeoutDeny or Deny.
A result structure for one DNSBL server.
bool valid() const
Returns true if the list() is valid.
const std::vector< Address > & addresses() const
Returns the result list, which is empty if there is no block or not valid().
std::string server() const
Returns the server.
DnsBlockServerResult(const std::string &server)
Constructor.
void set(const std::vector< Address > &)
Sets the result list().
Implements DNS blocklisting, as per RFC-5782.
static void checkConfig(const std::string &)
Checks the configure() string, throwing on error.
DnsBlock(DnsBlockCallback &, ExceptionSink, const std::string &config=std::string())
Constructor.
void configure(const Address &dns_server, std::size_t threshold, bool allow_on_timeout, G::TimeInterval timeout, const G::StringArray &servers)
Configures the object after construction.
void start(const Address &)
Starts an asychronous check on the given address.
bool busy() const
Returns true after start() and before the completion callback.
A base class for classes that handle asynchronous events from the event loop.
A tuple containing an ExceptionHandler interface pointer and a bound 'exception source' pointer.
A static class for getting information about the local machine's network name and address.
A timer class template in which the timeout is delivered to the specified method.
An interval between two G::SystemTime values or two G::TimerTime values.
std::vector< std::string > StringArray
A std::vector of std::strings.