const float c_fp_rate = 0.01;
const size_t c_num_cells = 67108864;
const uint8_t c_num_dec = 10;
-const unsigned int snapshot_interval_default = 600;
+ const unsigned int snapshot_interval_default = 30; // XXX 600;
const std::string bf_suffix = "bf";
const std::string sbf_prefix = "sbf";
void setSnapshotInterval(unsigned int secs) { d_snapshot_interval = secs; }
void setCacheDir(const std::string& cachedir) { d_psbf.setCacheDir(cachedir); }
bool snapshotCurrent(std::thread::id tid) { return d_psbf.snapshotCurrent(tid); }
- static void startHousekeepingThread(const std::shared_ptr<NODDB>& noddbp, std::thread::id tid)
- {
- noddbp->housekeepingThread(tid);
- }
+ void housekeepingThread(std::thread::id tid);
private:
PersistentSBF d_psbf;
unsigned int d_snapshot_interval{snapshot_interval_default}; // Number seconds between snapshots
- void housekeepingThread(std::thread::id tid);
};
class UniqueResponseDB
void setSnapshotInterval(unsigned int secs) { d_snapshot_interval = secs; }
void setCacheDir(const std::string& cachedir) { d_psbf.setCacheDir(cachedir); }
bool snapshotCurrent(std::thread::id tid) { return d_psbf.snapshotCurrent(tid); }
- static void startHousekeepingThread(const std::shared_ptr<UniqueResponseDB>& udrdbp, std::thread::id tid)
- {
- udrdbp->housekeepingThread(tid);
- }
+ void housekeepingThread(std::thread::id tid);
private:
PersistentSBF d_psbf;
unsigned int d_snapshot_interval{snapshot_interval_default}; // Number seconds between snapshots
- void housekeepingThread(std::thread::id tid);
};
}
// First check the (sub)domain isn't ignored for NOD purposes
if (!g_nodDomainWL.check(dname)) {
// Now check the NODDB (note this is probabilistic so can have FNs/FPs)
- if (t_nodDBp && t_nodDBp->isNewDomain(dname)) {
+ if (g_nodDBp && g_nodDBp->isNewDomain(dname)) {
if (g_nodLog) {
// This should probably log to a dedicated log file
SLOG(g_log << Logger::Notice << "Newly observed domain nod=" << dname << endl,
// Create a string that represent a triplet of (qname, qtype and RR[type, name, content])
std::stringstream strStream;
strStream << dname.toDNSStringLC() << ":" << qtype << ":" << qtype << ":" << record.d_type << ":" << record.d_name.toDNSStringLC() << ":" << record.getContent()->getZoneRepresentation();
- if (t_udrDBp && t_udrDBp->isUniqueResponse(strStream.str())) {
+ if (g_udrDBp && g_udrDBp->isUniqueResponse(strStream.str())) {
if (g_udrLog) {
// This should also probably log to a dedicated file.
SLOG(g_log << Logger::Notice << "Unique response observed: qname=" << dname << " qtype=" << QType(qtype) << " rrtype=" << QType(record.d_type) << " rrname=" << record.d_name << " rrcontent=" << record.getContent()->getZoneRepresentation() << endl,
bool g_udrEnabled;
bool g_udrLog;
std::string g_udr_pbtag;
-thread_local std::shared_ptr<nod::NODDB> t_nodDBp;
-thread_local std::shared_ptr<nod::UniqueResponseDB> t_udrDBp;
+std::unique_ptr<nod::NODDB> g_nodDBp;
+std::unique_ptr<nod::UniqueResponseDB> g_udrDBp;
#endif /* NOD_ENABLED */
std::atomic<bool> statsWanted;
{
if (g_nodEnabled) {
uint32_t num_cells = ::arg().asNum("new-domain-db-size");
- t_nodDBp = std::make_shared<nod::NODDB>(num_cells);
+ g_nodDBp = std::make_unique<nod::NODDB>(num_cells);
try {
- t_nodDBp->setCacheDir(::arg()["new-domain-history-dir"]);
+ g_nodDBp->setCacheDir(::arg()["new-domain-history-dir"]);
}
catch (const PDNSException& e) {
SLOG(g_log << Logger::Error << "new-domain-history-dir (" << ::arg()["new-domain-history-dir"] << ") is not readable or does not exist" << endl,
log->error(Logr::Error, e.reason, "new-domain-history-dir is not readable or does not exists", "dir", Logging::Loggable(::arg()["new-domain-history-dir"])));
_exit(1);
}
- if (!t_nodDBp->init()) {
+ if (!g_nodDBp->init()) {
SLOG(g_log << Logger::Error << "Could not initialize domain tracking" << endl,
log->info(Logr::Error, "Could not initialize domain tracking"));
_exit(1);
}
- std::thread thread(nod::NODDB::startHousekeepingThread, t_nodDBp, std::this_thread::get_id());
+ std::thread thread([tid = std::this_thread::get_id()]() {
+ g_nodDBp->housekeepingThread(tid);
+ });
thread.detach();
}
if (g_udrEnabled) {
uint32_t num_cells = ::arg().asNum("unique-response-db-size");
- t_udrDBp = std::make_shared<nod::UniqueResponseDB>(num_cells);
+ g_udrDBp = std::make_unique<nod::UniqueResponseDB>(num_cells);
try {
- t_udrDBp->setCacheDir(::arg()["unique-response-history-dir"]);
+ g_udrDBp->setCacheDir(::arg()["unique-response-history-dir"]);
}
catch (const PDNSException& e) {
SLOG(g_log << Logger::Error << "unique-response-history-dir (" << ::arg()["unique-response-history-dir"] << ") is not readable or does not exist" << endl,
log->info(Logr::Error, "unique-response-history-dir is not readable or does not exist", "dir", Logging::Loggable(::arg()["unique-response-history-dir"])));
_exit(1);
}
- if (!t_udrDBp->init()) {
+ if (!g_udrDBp->init()) {
SLOG(g_log << Logger::Error << "Could not initialize unique response tracking" << endl,
log->info(Logr::Error, "Could not initialize unique response tracking"));
_exit(1);
}
- std::thread thread(nod::UniqueResponseDB::startHousekeepingThread, t_udrDBp, std::this_thread::get_id());
+ std::thread thread([tid = std::this_thread::get_id()]() {
+ g_udrDBp->housekeepingThread(tid);
+ });
thread.detach();
}
}
return ret;
}
+#ifdef NOD_ENABLED
+ setupNODThread(log);
+#endif /* NOD_ENABLED */
+
return RecThreadInfo::runThreads(log);
}
}
}
-#ifdef NOD_ENABLED
- if (threadInfo.isWorker()) {
- setupNODThread(log);
- }
-#endif /* NOD_ENABLED */
-
/* the listener threads handle TCP queries */
if (threadInfo.isWorker() || threadInfo.isListener()) {
try {