]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Move implemenation of failed and non-resolving table to .cc file 11443/head
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 23 Mar 2022 09:38:59 +0000 (10:38 +0100)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 23 Mar 2022 09:38:59 +0000 (10:38 +0100)
pdns/syncres.cc
pdns/syncres.hh

index 6a39c7ea160c75e1959eff18b14f9628e3280001..51f9a7e56e4654c4c43473d8fe7a37fa509463a1 100644 (file)
 #include "validate-recursor.hh"
 #include "rec-taskqueue.hh"
 
+template<class T>
+class fails_t : public boost::noncopyable
+{
+public:
+  typedef uint64_t counter_t;
+  struct value_t {
+    value_t(const T &a) : key(a) {}
+    T key;
+    mutable counter_t value{0};
+    time_t last{0};
+  };
+
+  typedef multi_index_container<value_t,
+                                indexed_by<
+                                  ordered_unique<tag<T>, member<value_t, T, &value_t::key>>,
+                                  ordered_non_unique<tag<time_t>, member<value_t, time_t, &value_t::last>>
+                                  >> cont_t;
+
+  cont_t getMapCopy() const {
+    return d_cont;
+  }
+
+  counter_t value(const T& t) const
+  {
+    auto i = d_cont.find(t);
+
+    if (i == d_cont.end()) {
+      return 0;
+    }
+    return i->value;
+  }
+
+  counter_t incr(const T& key, const struct timeval& now)
+  {
+    auto i = d_cont.insert(key).first;
+
+    if (i->value < std::numeric_limits<counter_t>::max()) {
+      i->value++;
+    }
+    auto &ind = d_cont.template get<T>();
+    time_t tm = now.tv_sec;
+    ind.modify(i, [tm](value_t &val) { val.last = tm; });
+    return i->value;
+  }
+
+  void clear(const T& a)
+  {
+    d_cont.erase(a);
+  }
+
+  void clear()
+  {
+    d_cont.clear();
+  }
+
+  size_t size() const
+  {
+    return d_cont.size();
+  }
+
+  void prune(time_t cutoff) {
+    auto &ind = d_cont.template get<time_t>();
+    ind.erase(ind.begin(), ind.upper_bound(cutoff));
+  }
+
+private:
+  cont_t d_cont;
+};
+
 struct SavedParentEntry
 {
   SavedParentEntry(const DNSName& name, map<DNSName, vector<ComboAddress>>&& nsAddresses, time_t ttd)
@@ -90,8 +159,8 @@ EDNSSubnetOpts SyncRes::s_ecsScopeZero;
 string SyncRes::s_serverID;
 SyncRes::LogMode SyncRes::s_lm;
 const std::unordered_set<QType> SyncRes::s_redirectionQTypes = {QType::CNAME, QType::DNAME};
-LockGuarded<fails_t<ComboAddress>> SyncRes::s_fails;
-LockGuarded<fails_t<DNSName>> SyncRes::s_nonresolving;
+static LockGuarded<fails_t<ComboAddress>> s_fails;
+static LockGuarded<fails_t<DNSName>> s_nonresolving;
 
 unsigned int SyncRes::s_maxnegttl;
 unsigned int SyncRes::s_maxbogusttl;
@@ -723,6 +792,26 @@ uint64_t SyncRes::doDumpThrottleMap(int fd)
   return count;
 }
 
+uint64_t SyncRes::getFailedServersSize()
+{
+  return s_fails.lock()->size();
+}
+
+void SyncRes::clearFailedServers()
+{
+  s_fails.lock()->clear();
+}
+
+void SyncRes::pruneFailedServers(time_t cutoff)
+{
+  s_fails.lock()->prune(cutoff);
+}
+
+unsigned long SyncRes::getServerFailsCount(const ComboAddress& server)
+{
+  return s_fails.lock()->value(server);
+}
+
 uint64_t SyncRes::doDumpFailedServers(int fd)
 {
   int newfd = dup(fd);
@@ -750,6 +839,21 @@ uint64_t SyncRes::doDumpFailedServers(int fd)
   return count;
 }
 
+uint64_t SyncRes::getNonResolvingNSSize()
+{
+  return s_nonresolving.lock()->size();
+}
+
+void SyncRes::clearNonResolvingNS()
+{
+  s_nonresolving.lock()->clear();
+}
+
+void SyncRes::pruneNonResolving(time_t cutoff)
+{
+  s_nonresolving.lock()->prune(cutoff);
+}
+
 uint64_t SyncRes::doDumpNonResolvingNS(int fd)
 {
   int newfd = dup(fd);
index 3d9adb755cf390e69811dda46be7fc13bc665b15..cc37ca462971932ed8ec438c69ecab360e58430c 100644 (file)
@@ -192,75 +192,6 @@ private:
   float d_val{0};
 };
 
-template<class T>
-class fails_t : public boost::noncopyable
-{
-public:
-  typedef uint64_t counter_t;
-  struct value_t {
-    value_t(const T &a) : key(a) {}
-    T key;
-    mutable counter_t value{0};
-    time_t last{0};
-  };
-
-  typedef multi_index_container<value_t,
-                                indexed_by<
-                                  ordered_unique<tag<T>, member<value_t, T, &value_t::key>>,
-                                  ordered_non_unique<tag<time_t>, member<value_t, time_t, &value_t::last>>
-                                  >> cont_t;
-
-  cont_t getMapCopy() const {
-    return d_cont;
-  }
-
-  counter_t value(const T& t) const
-  {
-    auto i = d_cont.find(t);
-
-    if (i == d_cont.end()) {
-      return 0;
-    }
-    return i->value;
-  }
-
-  counter_t incr(const T& key, const struct timeval& now)
-  {
-    auto i = d_cont.insert(key).first;
-
-    if (i->value < std::numeric_limits<counter_t>::max()) {
-      i->value++;
-    }
-    auto &ind = d_cont.template get<T>();
-    time_t tm = now.tv_sec;
-    ind.modify(i, [tm](value_t &val) { val.last = tm; });
-    return i->value;
-  }
-
-  void clear(const T& a)
-  {
-    d_cont.erase(a);
-  }
-
-  void clear()
-  {
-    d_cont.clear();
-  }
-
-  size_t size() const
-  {
-    return d_cont.size();
-  }
-
-  void prune(time_t cutoff) {
-    auto &ind = d_cont.template get<time_t>();
-    ind.erase(ind.begin(), ind.upper_bound(cutoff));
-  }
-
-private:
-  cont_t d_cont;
-};
-
 extern std::unique_ptr<NegCache> g_negCache;
 
 class SyncRes : public boost::noncopyable
@@ -407,10 +338,6 @@ public:
 
   };
 
-
-  static LockGuarded<fails_t<ComboAddress>> s_fails;
-  static LockGuarded<fails_t<DNSName>> s_nonresolving;
-
   struct ThreadLocalStorage {
     nsspeeds_t nsSpeeds;
     throttle_t throttle;
@@ -545,34 +472,15 @@ public:
   {
     t_sstorage.throttle.throttle(now, std::make_tuple(server, g_rootdnsname, 0), duration, tries);
   }
-  static uint64_t getFailedServersSize()
-  {
-    return s_fails.lock()->size();
-  }
-  static uint64_t getNonResolvingNSSize()
-  {
-    return s_nonresolving.lock()->size();
-  }
-  static void clearFailedServers()
-  {
-    s_fails.lock()->clear();
-  }
-  static void clearNonResolvingNS()
-  {
-    s_nonresolving.lock()->clear();
-  }
-  static void pruneFailedServers(time_t cutoff)
-  {
-    s_fails.lock()->prune(cutoff);
-  }
-  static unsigned long getServerFailsCount(const ComboAddress& server)
-  {
-    return s_fails.lock()->value(server);
-  }
-  static void pruneNonResolving(time_t cutoff)
-  {
-    s_nonresolving.lock()->prune(cutoff);
-  }
+
+  static uint64_t getFailedServersSize();
+  static void clearFailedServers();
+  static void pruneFailedServers(time_t cutoff);
+  static unsigned long getServerFailsCount(const ComboAddress& server);
+
+  static void clearNonResolvingNS();
+  static uint64_t getNonResolvingNSSize();
+  static void pruneNonResolving(time_t cutoff);
 
   static void clearSaveParentsNSSets();
   static size_t getSaveParentsNSSetsSize();