Skip to content

Commit

Permalink
More delinting
Browse files Browse the repository at this point in the history
A set of random files made clean. During this process .clang-tidy.full
was also amended a bit.
  • Loading branch information
omoerbeek committed May 31, 2023
1 parent d081c90 commit 7dcdce8
Show file tree
Hide file tree
Showing 9 changed files with 253 additions and 216 deletions.
60 changes: 31 additions & 29 deletions pdns/recursordist/rec-taskqueue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include "rec-taskqueue.hh"
#include "taskqueue.hh"
#include "lock.hh"
Expand All @@ -30,8 +31,8 @@
class TimedSet
{
public:
TimedSet(time_t t) :
d_expiry_seconds(t)
TimedSet(time_t time) :
d_expiry_seconds(time)
{
}

Expand All @@ -40,11 +41,11 @@ class TimedSet
// This purge is relatively cheap, as we're walking an ordered index
uint64_t erased = 0;
auto& ind = d_set.template get<time_t>();
auto it = ind.begin();
while (it != ind.end()) {
if (it->d_ttd < now) {
auto iter = ind.begin();
while (iter != ind.end()) {
if (iter->d_ttd < now) {
++erased;
it = ind.erase(it);
iter = ind.erase(iter);
}
else {
break;
Expand Down Expand Up @@ -79,17 +80,18 @@ class TimedSet
private:
struct Entry
{
Entry(const pdns::ResolveTask& task, time_t ttd) :
d_task(task), d_ttd(ttd) {}
Entry(pdns::ResolveTask task, time_t ttd) :
d_task(std::move(task)), d_ttd(ttd) {}
pdns::ResolveTask d_task;
time_t d_ttd;
};

typedef multi_index_container<Entry,
indexed_by<
ordered_unique<tag<pdns::ResolveTask>, member<Entry, pdns::ResolveTask, &Entry::d_task>>,
ordered_non_unique<tag<time_t>, member<Entry, time_t, &Entry::d_ttd>>>>
timed_set_t;
using timed_set_t = multi_index_container<
Entry,
indexed_by<ordered_unique<tag<pdns::ResolveTask>,
member<Entry, pdns::ResolveTask, &Entry::d_task>>,
ordered_non_unique<tag<time_t>,
member<Entry, time_t, &Entry::d_ttd>>>>;
timed_set_t d_set;
time_t d_expiry_seconds;
unsigned int d_count{0};
Expand All @@ -116,15 +118,15 @@ static void resolve(const struct timeval& now, bool logErrors, const pdns::Resol
{
auto log = g_slog->withName("taskq")->withValues("name", Logging::Loggable(task.d_qname), "qtype", Logging::Loggable(QType(task.d_qtype).toString()), "netmask", Logging::Loggable(task.d_netmask.empty() ? "" : task.d_netmask.toString()));
const string msg = "Exception while running a background ResolveTask";
SyncRes sr(now);
SyncRes resolver(now);
vector<DNSRecord> ret;
sr.setRefreshAlmostExpired(task.d_refreshMode);
sr.setQuerySource(task.d_netmask);
bool ex = true;
resolver.setRefreshAlmostExpired(task.d_refreshMode);
resolver.setQuerySource(task.d_netmask);
bool exceptionOccurred = true;
try {
log->info(Logr::Debug, "resolving", "refresh", Logging::Loggable(task.d_refreshMode));
int res = sr.beginResolve(task.d_qname, QType(task.d_qtype), QClass::IN, ret);
ex = false;
int res = resolver.beginResolve(task.d_qname, QType(task.d_qtype), QClass::IN, ret);
exceptionOccurred = false;
log->info(Logr::Debug, "done", "rcode", Logging::Loggable(res), "records", Logging::Loggable(ret.size()));
}
catch (const std::exception& e) {
Expand All @@ -146,7 +148,7 @@ static void resolve(const struct timeval& now, bool logErrors, const pdns::Resol
catch (...) {
log->error(Logr::Error, msg, "Unexpectec exception");
}
if (ex) {
if (exceptionOccurred) {
if (task.d_refreshMode) {
++s_almost_expired_tasks.exceptions;
}
Expand All @@ -168,15 +170,15 @@ static void tryDoT(const struct timeval& now, bool logErrors, const pdns::Resolv
{
auto log = g_slog->withName("taskq")->withValues("method", Logging::Loggable("tryDoT"), "name", Logging::Loggable(task.d_qname), "qtype", Logging::Loggable(QType(task.d_qtype).toString()), "ip", Logging::Loggable(task.d_ip));
const string msg = "Exception while running a background tryDoT task";
SyncRes sr(now);
SyncRes resolver(now);
vector<DNSRecord> ret;
sr.setRefreshAlmostExpired(false);
bool ex = true;
resolver.setRefreshAlmostExpired(false);
bool exceptionOccurred = true;
try {
log->info(Logr::Debug, "trying DoT");
bool ok = sr.tryDoT(task.d_qname, QType(task.d_qtype), task.d_nsname, task.d_ip, now.tv_sec);
ex = false;
log->info(Logr::Debug, "done", "ok", Logging::Loggable(ok));
bool tryOK = resolver.tryDoT(task.d_qname, QType(task.d_qtype), task.d_nsname, task.d_ip, now.tv_sec);
exceptionOccurred = false;
log->info(Logr::Debug, "done", "ok", Logging::Loggable(tryOK));
}
catch (const std::exception& e) {
log->error(Logr::Error, msg, e.what());
Expand All @@ -197,7 +199,7 @@ static void tryDoT(const struct timeval& now, bool logErrors, const pdns::Resolv
catch (...) {
log->error(Logr::Error, msg, "Unexpected exception");
}
if (ex) {
if (exceptionOccurred) {
++s_resolve_tasks.exceptions;
}
else {
Expand Down Expand Up @@ -262,15 +264,15 @@ void pushResolveTask(const DNSName& qname, uint16_t qtype, time_t now, time_t de
}
}

bool pushTryDoTTask(const DNSName& qname, uint16_t qtype, const ComboAddress& ip, time_t deadline, const DNSName& nsname)
bool pushTryDoTTask(const DNSName& qname, uint16_t qtype, const ComboAddress& ipAddress, time_t deadline, const DNSName& nsname)
{
if (SyncRes::isUnsupported(qtype)) {
auto log = g_slog->withName("taskq")->withValues("name", Logging::Loggable(qname), "qtype", Logging::Loggable(QType(qtype).toString()));
log->error(Logr::Error, "Cannot push task", "qtype unsupported");
return false;
}

pdns::ResolveTask task{qname, qtype, deadline, false, tryDoT, ip, nsname, {}};
pdns::ResolveTask task{qname, qtype, deadline, false, tryDoT, ipAddress, nsname, {}};
bool pushed = s_taskQueue.lock()->queue.push(std::move(task));
if (pushed) {
++s_almost_expired_tasks.pushed;
Expand Down
4 changes: 2 additions & 2 deletions pdns/recursordist/rec-taskqueue.hh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#pragma once

#include <cstdint>
#include <time.h>
#include <ctime>

class DNSName;
union ComboAddress;
Expand All @@ -36,7 +36,7 @@ void runTasks(size_t max, bool logErrors);
bool runTaskOnce(bool logErrors);
void pushAlmostExpiredTask(const DNSName& qname, uint16_t qtype, time_t deadline, const Netmask& netmask);
void pushResolveTask(const DNSName& qname, uint16_t qtype, time_t now, time_t deadline);
bool pushTryDoTTask(const DNSName& qname, uint16_t qtype, const ComboAddress& ip, time_t deadline, const DNSName& nsname);
bool pushTryDoTTask(const DNSName& qname, uint16_t qtype, const ComboAddress& ipAddress, time_t deadline, const DNSName& nsname);
void taskQueueClear();
pdns::ResolveTask taskQueuePop();

Expand Down
8 changes: 4 additions & 4 deletions pdns/recursordist/taskqueue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ ResolveTask TaskQueue::pop()
return ret;
}

bool ResolveTask::run(bool logErrors)
bool ResolveTask::run(bool logErrors) const
{
if (d_func == nullptr) {
auto log = g_slog->withName("taskq")->withValues("name", Logging::Loggable(d_qname), "qtype", Logging::Loggable(QType(d_qtype).toString()));
log->error(Logr::Debug, "null task");
return false;
}
struct timeval now;
struct timeval now{};
Utility::gettimeofday(&now);
if (d_deadline >= now.tv_sec) {
d_func(now, logErrors, *this);
Expand All @@ -70,8 +70,8 @@ bool ResolveTask::run(bool logErrors)

namespace boost
{
size_t hash_value(const ComboAddress& a)
size_t hash_value(const ComboAddress& address)
{
return ComboAddress::addressOnlyHash()(a);
return ComboAddress::addressOnlyHash()(address);
}
}
36 changes: 17 additions & 19 deletions pdns/recursordist/taskqueue.hh
Original file line number Diff line number Diff line change
Expand Up @@ -63,36 +63,36 @@ struct ResolveTask
DNSName d_nsname;
Netmask d_netmask;

bool operator<(const ResolveTask& a) const
bool operator<(const ResolveTask& task) const
{
return std::tie(d_qname, d_qtype, d_refreshMode, d_func, d_ip, d_netmask) < std::tie(a.d_qname, a.d_qtype, a.d_refreshMode, a.d_func, a.d_ip, a.d_netmask);
return std::tie(d_qname, d_qtype, d_refreshMode, d_func, d_ip, d_netmask) < std::tie(task.d_qname, task.d_qtype, task.d_refreshMode, task.d_func, task.d_ip, task.d_netmask);
}

bool run(bool logErrors);
[[nodiscard]] bool run(bool logErrors) const;
};

class TaskQueue
{
public:
bool empty() const
[[nodiscard]] bool empty() const
{
return d_queue.empty();
}

size_t size() const
[[nodiscard]] size_t size() const
{
return d_queue.size();
}

bool push(ResolveTask&& task);
ResolveTask pop();

uint64_t getPushes()
[[nodiscard]] uint64_t getPushes() const
{
return d_pushes;
}

uint64_t getExpired()
[[nodiscard]] uint64_t getExpired() const
{
return d_expired;
}
Expand All @@ -116,19 +116,17 @@ private:
{
};

typedef multi_index_container<
using queue_t = multi_index_container<
ResolveTask,
indexed_by<
ordered_unique<tag<HashTag>,
composite_key<ResolveTask,
member<ResolveTask, DNSName, &ResolveTask::d_qname>,
member<ResolveTask, uint16_t, &ResolveTask::d_qtype>,
member<ResolveTask, bool, &ResolveTask::d_refreshMode>,
member<ResolveTask, ResolveTask::TaskFunction, &ResolveTask::d_func>,
member<ResolveTask, ComboAddress, &ResolveTask::d_ip>,
member<ResolveTask, Netmask, &ResolveTask::d_netmask>>>,
sequenced<tag<SequencedTag>>>>
queue_t;
indexed_by<ordered_unique<tag<HashTag>,
composite_key<ResolveTask,
member<ResolveTask, DNSName, &ResolveTask::d_qname>,
member<ResolveTask, uint16_t, &ResolveTask::d_qtype>,
member<ResolveTask, bool, &ResolveTask::d_refreshMode>,
member<ResolveTask, ResolveTask::TaskFunction, &ResolveTask::d_func>,
member<ResolveTask, ComboAddress, &ResolveTask::d_ip>,
member<ResolveTask, Netmask, &ResolveTask::d_netmask>>>,
sequenced<tag<SequencedTag>>>>;

queue_t d_queue;
uint64_t d_pushes{0};
Expand Down
Loading

0 comments on commit 7dcdce8

Please sign in to comment.