| 1 | /* |
| 2 | The software in this package is distributed under the GNU General |
| 3 | Public License version 2 (with a special exception described below). |
| 4 | |
| 5 | A copy of GNU General Public License (GPL) is included in this distribution, |
| 6 | in the file COPYING.GPL. |
| 7 | |
| 8 | As a special exception, if other files instantiate templates or use macros |
| 9 | or inline functions from this file, or you compile this file and link it |
| 10 | with other works to produce a work based on this file, this file |
| 11 | does not by itself cause the resulting work to be covered |
| 12 | by the GNU General Public License. |
| 13 | |
| 14 | However the source code for this file must still be made available |
| 15 | in accordance with section (3) of the GNU General Public License. |
| 16 | |
| 17 | This exception does not invalidate any other reasons why a work based |
| 18 | on this file might be covered by the GNU General Public License. |
| 19 | |
| 20 | Christian Herdtweck, Intra2net AG 2015 |
| 21 | */ |
| 22 | |
| 23 | #ifndef IP_PSEUDO_RESOLVER_H |
| 24 | #define IP_PSEUDO_RESOLVER_H |
| 25 | |
| 26 | #include <boost/asio/ip/address.hpp> |
| 27 | #include "dns/hostaddress.h" |
| 28 | #include "dns/resolverbase.h" |
| 29 | #include "dns/dnsmaster.h" |
| 30 | |
| 31 | namespace Config |
| 32 | { |
| 33 | uint32_t DefaultTtl = 60*60*24*356; // 1 year in seconds (approx) |
| 34 | } |
| 35 | |
| 36 | /** @brief Degenerate case of a resolver: hostname is already an IP |
| 37 | * |
| 38 | * created by DnsMaster if given an IP address as hostname |
| 39 | * |
| 40 | * Will do nothing, just remember that IP and return it for every call to |
| 41 | * get_next_ip |
| 42 | * |
| 43 | * Since this is so boring, I did not create an own .cpp for it |
| 44 | */ |
| 45 | class IpPseudoResolver : public ResolverBase |
| 46 | { |
| 47 | // constructor accessible from friend DnsMaster |
| 48 | public: |
| 49 | friend ResolverItem& DnsMaster::get_resolver_for( |
| 50 | const std::string &hostname, |
| 51 | const DnsIpProtocol &protocol); |
| 52 | private: |
| 53 | IpPseudoResolver(const IoServiceItem io_serv, |
| 54 | const std::string &ip_string, |
| 55 | const DnsIpProtocol &protocol, |
| 56 | const DnsCacheItem &cache ) |
| 57 | : ResolverBase( io_serv, ip_string, protocol, cache ) |
| 58 | , IpAddress( boost::asio::ip::address::from_string(ip_string), |
| 59 | Config::DefaultTtl ) |
| 60 | {} |
| 61 | |
| 62 | private: |
| 63 | HostAddress IpAddress; |
| 64 | |
| 65 | // only real public function |
| 66 | public: |
| 67 | HostAddress get_next_ip(const bool check_up_to_date=true) |
| 68 | { return IpAddress; } |
| 69 | bool have_up_to_date_ip() { return true; } |
| 70 | int get_resolved_ip_count(const bool check_up_to_date=true) |
| 71 | { return 1; } |
| 72 | bool is_resolving() const { return false; } |
| 73 | bool is_waiting_to_resolve() const { return false; } |
| 74 | void cancel_resolve() {} |
| 75 | |
| 76 | // implementation of ResolverBase::async_resolve |
| 77 | protected: |
| 78 | void do_resolve(const int recursion_count) |
| 79 | { ResolverBase::schedule_callbacks(true, 0); } |
| 80 | }; |
| 81 | #endif |
| 82 | |