From: Otto Moerbeek Date: Thu, 3 Jul 2025 07:07:49 +0000 (+0200) Subject: Expose getNSSPeedsTable() to Lua script X-Git-Tag: rec-5.4.0-alpha0~41^2~9 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=528c3a66607b80558580e0713a071fe8fb51e27c;p=thirdparty%2Fpdns.git Expose getNSSPeedsTable() to Lua script Signed-off-by: Otto Moerbeek --- diff --git a/pdns/recursordist/lua-recursor4.cc b/pdns/recursordist/lua-recursor4.cc index 906d5f2c71..a1e03ffcac 100644 --- a/pdns/recursordist/lua-recursor4.cc +++ b/pdns/recursordist/lua-recursor4.cc @@ -523,6 +523,11 @@ void RecursorLua4::postPrepareContext() // NOLINT(readability-function-cognitive return {dir, name}; }); + d_lw->writeFunction("getNSSpeedTable", []() { + std::string ret; + auto number = SyncRes::getNSSpeedTable(ret); + return std::tuple{ret, number}; + }); if (!d_include_path.empty()) { includePath(d_include_path); diff --git a/pdns/recursordist/syncres.cc b/pdns/recursordist/syncres.cc index 6a0c103e25..7669e75a64 100644 --- a/pdns/recursordist/syncres.cc +++ b/pdns/recursordist/syncres.cc @@ -240,9 +240,7 @@ public: float ret = std::numeric_limits::max(); const float factor = iter->getFactor(now); for (auto& entry : iter->d_collection) { - if (float tmp = entry.second.get(factor); tmp < ret) { - ret = tmp; - } + ret = std::min(ret, entry.second.get(factor)); } ind.modify(iter, [&](DecayingEwmaCollection& dec) { dec.d_lastget = now; }); return ret; @@ -274,7 +272,7 @@ public: }; template - void getEntry(T& message, U entry) + void getEntry(T& message, U entry) const { message.add_bytes(PBNSSpeedEntry::required_bytes_name, entry->d_name.toString()); message.add_int64(PBNSSpeedEntry::required_int64_lastgets, entry->d_lastget.tv_sec); @@ -287,7 +285,7 @@ public: } } - size_t getPB(std::string& ret) + size_t getPB(std::string& ret) const { protozero::pbf_builder full(ret); full.add_string(PBNSSpeedDump::required_string_version, getPDNSVersion()); @@ -309,6 +307,12 @@ public: static LockGuarded s_nsSpeeds; +size_t SyncRes::getNSSpeedTable(std::string& ret) +{ + const auto copy = *s_nsSpeeds.lock(); + return copy.getPB(ret); +} + class Throttle { public: diff --git a/pdns/recursordist/syncres.hh b/pdns/recursordist/syncres.hh index 09242aa09c..614741abe6 100644 --- a/pdns/recursordist/syncres.hh +++ b/pdns/recursordist/syncres.hh @@ -170,6 +170,8 @@ public: static uint64_t doDumpSavedParentNSSets(int fileDesc); static uint64_t doDumpDoTProbeMap(int fileDesc); + static size_t getNSSpeedTable(std::string& ret); + static int getRootNS(struct timeval now, asyncresolve_t asyncCallback, unsigned int depth, Logr::log_t); static void addDontQuery(const std::string& mask) {