simplified dns (no self-made recursion); merge PingScheduler and PingRotate; make...
[pingcheck] / src / dns / dnscache.h
index c213777..7a0fbe8 100644 (file)
 #include <boost/shared_ptr.hpp>
 #include <boost/asio/deadline_timer.hpp>
 #include <boost/system/error_code.hpp>
+#include <boost/archive/xml_oarchive.hpp>
+#include <boost/archive/xml_iarchive.hpp>
+#include <boost/serialization/access.hpp>
+#include <boost/serialization/nvp.hpp>
+#include <boost/serialization/split_member.hpp>
+#include <boost/serialization/string.hpp>
 
 #include "host/pinger.h"    // for IoserviceItem
 #include "dns/hostaddress.h"
 
 typedef std::vector<HostAddress> HostAddressVec;
 typedef std::map<std::string, HostAddressVec> ip_map_type;
-typedef std::pair<std::string, TimeToLive> Cname;
+
+// -----------------------------------------------------------------------------
+// CNAME
+// -----------------------------------------------------------------------------
+
+struct Cname
+{   // all public:
+    std::string Host;
+    TimeToLive Ttl;
+
+    Cname();
+    Cname(const std::string &host, const uint32_t ttl);
+
+    // serialization
+    friend class boost::serialization::access;
+    template<class Archive>
+    void save(Archive & ar, const unsigned int version) const
+    {
+        ar & BOOST_SERIALIZATION_NVP(Host);
+        ar & BOOST_SERIALIZATION_NVP(Ttl);
+    }
+    template<class Archive>
+    void load(Archive & ar, const unsigned int version)
+    {
+        ar & BOOST_SERIALIZATION_NVP(Host);
+        ar & BOOST_SERIALIZATION_NVP(Ttl);
+    }
+    BOOST_SERIALIZATION_SPLIT_MEMBER()
+};
 typedef std::map<std::string, Cname> cname_map_type;
 
 
+// -----------------------------------------------------------------------------
+// DnsCache
+// -----------------------------------------------------------------------------
+
 class DnsCache
 {
 public:
@@ -50,12 +88,16 @@ public:
     void update(const std::string &hostname, const HostAddressVec &new_data);
     void update(const std::string &hostname, const Cname &cname);
     void update(const std::string &hostname, const uint32_t ttl);
+
+    // retrieval
     HostAddressVec get_ips(const std::string &hostname,
-                            const bool check_up_to_date=false);
-    std::string get_cname(const std::string &hostname,
-                          const bool check_up_to_date=false);
+                           const bool check_up_to_date=false);
+    Cname get_cname(const std::string &hostname,
+                     const bool check_up_to_date=false);
     HostAddressVec get_ips_recursive(const std::string &hostname,
-                                      const bool check_up_to_date=false);
+                                     const bool check_up_to_date=false);
+    std::string get_first_outdated_cname(const std::string &hostname,
+                                         const uint32_t ttl_thresh);
 
 // variables
 private:
@@ -65,7 +107,7 @@ private:
     std::string CacheFile;
     bool HasChanged;
 
-// functions
+// internal functions
 private:
     void schedule_save(const boost::system::error_code &error);
     void save_to_cachefile();