Commit | Line | Data |
---|---|---|
36ad976b CH |
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 | ||
4e7b6ff9 CH |
26 | #include <boost/asio/ip/address.hpp> |
27 | #include "dns/hostaddress.h" | |
c5b4902d CH |
28 | #include "dns/resolverbase.h" |
29 | #include "dns/dnsmaster.h" | |
36ad976b | 30 | |
96779587 CH |
31 | namespace Config |
32 | { | |
33 | uint32_t DefaultTtl = 60*60*24*356; // 1 year in seconds (approx) | |
34 | } | |
35 | ||
36ad976b CH |
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: | |
96779587 | 49 | friend ResolverItem& DnsMaster::get_resolver_for( |
923626c0 CH |
50 | const std::string &hostname, |
51 | const DnsIpProtocol &protocol); | |
36ad976b | 52 | private: |
4e7b6ff9 CH |
53 | IpPseudoResolver(const IoServiceItem io_serv, |
54 | const std::string &ip_string, | |
96779587 | 55 | const DnsCacheItem &cache ) |
4e7b6ff9 CH |
56 | : ResolverBase( io_serv, ip_string, cache ) |
57 | , IpAddress( boost::asio::ip::address::from_string(ip_string), | |
58 | Config::DefaultTtl ) | |
96779587 | 59 | {} |
36ad976b CH |
60 | |
61 | private: | |
4e7b6ff9 | 62 | HostAddress IpAddress; |
36ad976b | 63 | |
4e7b6ff9 | 64 | // only real public function |
36ad976b | 65 | public: |
26b0f687 | 66 | HostAddress get_next_ip(const bool check_up_to_date=true) |
72be9e7d CH |
67 | { return IpAddress; } |
68 | bool have_up_to_date_ip() { return true; } | |
fd62d09f CH |
69 | int get_resolved_ip_count(const bool check_up_to_date=true) |
70 | { return 1; } | |
72be9e7d CH |
71 | bool is_resolving() const { return false; } |
72 | bool is_waiting_to_resolve() const { return false; } | |
e18c1337 | 73 | void cancel_resolve() {} |
4e7b6ff9 CH |
74 | |
75 | // implementation of ResolverBase::async_resolve | |
76 | protected: | |
cd71d095 | 77 | void do_resolve(const int recursion_count) |
923626c0 | 78 | { ResolverBase::schedule_callbacks(true, 0); } |
36ad976b CH |
79 | }; |
80 | #endif | |
81 | ||
82 | // (created using vim -- the world's best text editor) | |
83 |