21#ifndef G_NET_DNS_BLOCK_H
22#define G_NET_DNS_BLOCK_H
40 class DnsBlockResult ;
41 class DnsBlockServerResult ;
42 class DnsBlockCallback ;
54 void set(
const std::vector<Address> & ) ;
60 std::string
server()
const ;
63 const std::vector<Address> &
addresses()
const ;
68 std::string m_server ;
69 bool m_valid {
false} ;
70 std::vector<Address> m_addresses ;
120 const std::vector<DnsBlockServerResult> &
list()
const ;
130 using ResultList = std::vector<DnsBlockServerResult> ;
131 Type m_type {Type::Inactive} ;
132 std::size_t m_threshold {0U} ;
148 G_EXCEPTION( Error ,
tx(
"dnsbl error") )
149 G_EXCEPTION( ConfigError ,
tx(
"invalid dnsbl configuration") )
150 G_EXCEPTION( BadFieldCount ,
tx(
"not enough comma-sparated fields") )
151 G_EXCEPTION( SendError ,
tx(
"socket send failed") )
152 G_EXCEPTION( BadDnsResponse ,
tx(
"invalid dns response") )
153 using ResultList = std::vector<DnsBlockServerResult> ;
186 void readEvent()
override ;
189 static void configureImp( std::string_view ,
DnsBlock * ) ;
191 static std::string queryString(
const Address & ) ;
192 static std::size_t countResponders(
const ResultList & ) ;
193 static std::size_t countDeniers(
const ResultList & ) ;
194 static Address nameServerAddress() ;
195 static Address nameServerAddress(
const std::string & ) ;
196 static bool isDomain( std::string_view ) noexcept ;
197 static bool isPositive( std::string_view ) noexcept ;
198 static unsigned int ms( std::string_view ) ;
205 std::size_t m_threshold {1U} ;
206 bool m_allow_on_timeout {
true} ;
210 unsigned int m_id_base {0U} ;
211 std::unique_ptr<DatagramSocket> m_socket_ptr ;
239 m_addresses = addresses ;
262 m_address(
Address::defaultAddress())
269 m_threshold = threshold ;
270 m_address = address ;
288 m_list.push_back( server_result ) ;
294 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
Destructor.
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.
void start(const Address &)
Starts an asychronous check on the given address.
void configure(const Address &dns_server, unsigned int threshold, bool allow_on_timeout, G::TimeInterval timeout, const G::StringArray &servers)
Configures the object after construction.
DnsBlock(DnsBlockCallback &, EventState, std::string_view config={})
Constructor.
bool busy() const
Returns true after start() and before the completion callback.
A base class for classes that have a file descriptor and handle asynchronous events from the event lo...
A lightweight object containing an ExceptionHandler pointer, optional ExceptionSource pointer and opt...
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.
constexpr const char * tx(const char *p) noexcept
A briefer alternative to G::gettext_noop().