2 The software in this package is distributed under the GNU General
3 Public License version 2 (with a special exception described below).
5 A copy of GNU General Public License (GPL) is included in this distribution,
6 in the file COPYING.GPL.
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.
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.
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.
20 Christian Herdtweck, Intra2net AG 2015
28 #include <boost/shared_ptr.hpp>
29 #include <boost/asio/deadline_timer.hpp>
30 #include <boost/system/error_code.hpp>
31 #include <boost/archive/xml_oarchive.hpp>
32 #include <boost/archive/xml_iarchive.hpp>
33 #include <boost/serialization/access.hpp>
34 #include <boost/serialization/nvp.hpp>
35 #include <boost/serialization/split_member.hpp>
36 #include <boost/serialization/string.hpp>
38 #include "host/pinger.h" // for IoserviceItem
39 #include "dns/hostaddress.h"
40 #include "dns/timetolive.h"
42 typedef std::vector<HostAddress> HostAddressVec;
43 typedef std::map<std::string, HostAddressVec> ip_map_type;
45 // -----------------------------------------------------------------------------
47 // -----------------------------------------------------------------------------
55 Cname(const std::string &host, const uint32_t ttl);
58 friend class boost::serialization::access;
59 template<class Archive>
60 void save(Archive & ar, const unsigned int version) const
62 ar & BOOST_SERIALIZATION_NVP(Host);
63 ar & BOOST_SERIALIZATION_NVP(Ttl);
65 template<class Archive>
66 void load(Archive & ar, const unsigned int version)
68 ar & BOOST_SERIALIZATION_NVP(Host);
69 ar & BOOST_SERIALIZATION_NVP(Ttl);
71 BOOST_SERIALIZATION_SPLIT_MEMBER()
73 typedef std::map<std::string, Cname> cname_map_type;
76 // -----------------------------------------------------------------------------
78 // -----------------------------------------------------------------------------
83 DnsCache( const IoServiceItem &io_serv,
84 const std::string &cache_file );
87 // accessed from ResolverBase subclasses
88 void update(const std::string &hostname, const HostAddressVec &new_data);
89 void update(const std::string &hostname, const Cname &cname);
90 void update(const std::string &hostname, const uint32_t ttl);
93 HostAddressVec get_ips(const std::string &hostname,
94 const bool check_up_to_date=false);
95 Cname get_cname(const std::string &hostname,
96 const bool check_up_to_date=false);
97 HostAddressVec get_ips_recursive(const std::string &hostname,
98 const bool check_up_to_date=false);
99 std::string get_first_outdated_cname(const std::string &hostname,
100 const uint32_t ttl_thresh);
105 cname_map_type CnameCache;
106 boost::asio::deadline_timer SaveTimer;
107 std::string CacheFile;
110 // internal functions
112 void schedule_save(const boost::system::error_code &error);
113 void save_to_cachefile();
114 void load_from_cachefile();
118 typedef boost::shared_ptr<DnsCache> DnsCacheItem;
122 // (created using vim -- the world's best text editor)