/* The software in this package is distributed under the GNU General Public License version 2 (with a special exception described below). A copy of GNU General Public License (GPL) is included in this distribution, in the file COPYING.GPL. As a special exception, if other files instantiate templates or use macros or inline functions from this file, or you compile this file and link it with other works to produce a work based on this file, this file does not by itself cause the resulting work to be covered by the GNU General Public License. However the source code for this file must still be made available in accordance with section (3) of the GNU General Public License. This exception does not invalidate any other reasons why a work based on this file might be covered by the GNU General Public License. Christian Herdtweck, Intra2net AG 2015 */ #ifndef IP_PSEUDO_RESOLVER_H #define IP_PSEUDO_RESOLVER_H #include #include "dns/hostaddress.h" #include "dns/resolverbase.h" #include "dns/dnsmaster.h" namespace Config { uint32_t DefaultTtl = 60*60*24*356; // 1 year in seconds (approx) } /** @brief Degenerate case of a resolver: hostname is already an IP * * created by DnsMaster if given an IP address as hostname * * Will do nothing, just remember that IP and return it for every call to * get_next_ip * * Since this is so boring, I did not create an own .cpp for it */ class IpPseudoResolver : public ResolverBase { // constructor accessible from friend DnsMaster public: friend ResolverItem& DnsMaster::get_resolver_for( const std::string &hostname, const DnsIpProtocol &protocol); private: IpPseudoResolver(const IoServiceItem io_serv, const std::string &ip_string, const DnsIpProtocol &protocol, const DnsCacheItem &cache ) : ResolverBase( io_serv, ip_string, protocol, cache ) , IpAddress( boost::asio::ip::address::from_string(ip_string), Config::DefaultTtl ) {} private: HostAddress IpAddress; // only real public function public: HostAddress get_next_ip(const bool check_up_to_date=true) { return IpAddress; } bool have_up_to_date_ip() { return true; } int get_resolved_ip_count(const bool check_up_to_date=true) { return 1; } bool is_resolving() const { return false; } bool is_waiting_to_resolve() const { return false; } void cancel_resolve() {} // implementation of ResolverBase::async_resolve protected: void do_resolve(const int recursion_count) { ResolverBase::schedule_callbacks(true, 0); } }; #endif