#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)
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;
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);
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);
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
};
-
- static LockGuarded<fails_t<ComboAddress>> s_fails;
- static LockGuarded<fails_t<DNSName>> s_nonresolving;
-
struct ThreadLocalStorage {
nsspeeds_t nsSpeeds;
throttle_t throttle;
{
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();