]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Moved SavedParentSet class to syncres.cc
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Fri, 18 Mar 2022 12:16:17 +0000 (13:16 +0100)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 21 Mar 2022 09:16:02 +0000 (10:16 +0100)
pdns/syncres.cc
pdns/syncres.hh

index 763ef7cc7b3b6dff38c9a60754bb455fb9c9a6ff..ab871984aff3fd7817fd6ced07d22b151bc9dfb8 100644 (file)
 #include "validate-recursor.hh"
 #include "rec-taskqueue.hh"
 
+struct SavedParentEntry
+{
+  SavedParentEntry(const DNSName& name, map<DNSName, vector<ComboAddress>>&& nsAddresses, time_t ttd)
+    : d_domain(name), d_nsAddresses(nsAddresses), d_ttd(ttd)
+  {
+  }
+  DNSName d_domain;
+  map<DNSName, vector<ComboAddress>> d_nsAddresses;
+  time_t d_ttd;
+  mutable uint64_t d_count{0};
+};
+
+typedef multi_index_container<
+  SavedParentEntry,
+  indexed_by<ordered_unique<tag<DNSName>, member<SavedParentEntry, DNSName, &SavedParentEntry::d_domain>>,
+             ordered_non_unique<tag<time_t>, member<SavedParentEntry, time_t, &SavedParentEntry::d_ttd>>
+             >> SavedParentNSSetBase;
+
+class SavedParentNSSet : public SavedParentNSSetBase
+{
+public:
+  void prune(time_t now)
+  {
+    auto &ind = get<time_t>();
+    ind.erase(ind.begin(), ind.upper_bound(now));
+  }
+  void inc(const DNSName& name)
+  {
+    auto it = find(name);
+    if (it != end()) {
+      ++(*it).d_count;
+    }
+  }
+  SavedParentNSSet getMapCopy() const
+  {
+    return *this;
+  }
+};
+
+static LockGuarded <SavedParentNSSet> s_savedParentNSSet;
+
 thread_local SyncRes::ThreadLocalStorage SyncRes::t_sstorage;
 thread_local std::unique_ptr<addrringbuf_t> t_timeouts;
 
@@ -51,7 +92,6 @@ 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;
-LockGuarded <SyncRes::SavedParentNSSet> SyncRes::s_savedParentNSSet;
 
 unsigned int SyncRes::s_maxnegttl;
 unsigned int SyncRes::s_maxbogusttl;
@@ -736,6 +776,21 @@ uint64_t SyncRes::doDumpNonResolvingNS(int fd)
   return count;
 }
 
+void SyncRes::clearSaveParentsNSSets()
+{
+  s_savedParentNSSet.lock()->clear();
+}
+
+size_t SyncRes::getSaveParentsNSSetsSize()
+{
+  return s_savedParentNSSet.lock()->size();
+}
+
+void SyncRes::pruneSaveParentsNSSets(time_t now)
+{
+  s_savedParentNSSet.lock()->prune(now);
+}
+
 uint64_t SyncRes::doDumpSavedParentNSSets(int fd)
 {
   int newfd = dup(fd);
index 989d1d6d5e63349a539ca009a51db051b0b43336..427869b54d0765349277886935167104db6d25dc 100644 (file)
@@ -407,48 +407,9 @@ public:
 
   };
 
-  struct SavedParentEntry
-  {
-    SavedParentEntry(const DNSName& name, map<DNSName, vector<ComboAddress>>&& nsAddresses, time_t ttd)
-      : d_domain(name), d_nsAddresses(nsAddresses), d_ttd(ttd)
-    {
-    }
-    DNSName d_domain;
-    map<DNSName, vector<ComboAddress>> d_nsAddresses;
-    time_t d_ttd;
-    mutable uint64_t d_count{0};
-  };
-
-  typedef multi_index_container<
-    SavedParentEntry,
-    indexed_by<ordered_unique<tag<DNSName>, member<SavedParentEntry, DNSName, &SavedParentEntry::d_domain>>,
-               ordered_non_unique<tag<time_t>, member<SavedParentEntry, time_t, &SavedParentEntry::d_ttd>>
-               >> SavedParentNSSetBase;
-
-  class SavedParentNSSet : public SavedParentNSSetBase
-  {
-  public:
-    void prune(time_t now)
-    {
-      auto &ind = get<time_t>();
-      ind.erase(ind.begin(), ind.upper_bound(now));
-    }
-    void inc(const DNSName& name)
-    {
-      auto it = find(name);
-      if (it != end()) {
-        ++(*it).d_count;
-      }
-    }
-    SavedParentNSSet getMapCopy() const
-    {
-      return *this;
-    }
-  };
 
   static LockGuarded<fails_t<ComboAddress>> s_fails;
   static LockGuarded<fails_t<DNSName>> s_nonresolving;
-  static LockGuarded <SavedParentNSSet> s_savedParentNSSet;
 
   struct ThreadLocalStorage {
     nsspeeds_t nsSpeeds;
@@ -612,18 +573,11 @@ public:
   {
     s_nonresolving.lock()->prune(cutoff);
   }
-  static void clearSaveParentsNSSets()
-  {
-    s_savedParentNSSet.lock()->clear();
-  }
-  static size_t getSaveParentsNSSetsSize()
-  {
-    return s_savedParentNSSet.lock()->size();
-  }
-  static void pruneSaveParentsNSSets(time_t now)
-  {
-    s_savedParentNSSet.lock()->prune(now);
-  }
+
+  static void clearSaveParentsNSSets();
+  static size_t getSaveParentsNSSetsSize();
+  static void pruneSaveParentsNSSets(time_t now);
+
   static void setDomainMap(std::shared_ptr<domainmap_t> newMap)
   {
     t_sstorage.domainmap = newMap;