From: Otto Moerbeek Date: Tue, 15 Sep 2020 11:21:09 +0000 (+0200) Subject: Include ; constify a few methods X-Git-Tag: rec-4.5.0-alpha0^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5246a6dc57c4bfb60eaf292a5432ed50725d84a2;p=thirdparty%2Fpdns.git Include ; constify a few methods --- diff --git a/pdns/recursordist/negcache.cc b/pdns/recursordist/negcache.cc index fd9b58e6f2..5897ffb725 100644 --- a/pdns/recursordist/negcache.cc +++ b/pdns/recursordist/negcache.cc @@ -43,10 +43,10 @@ NegCache::~NegCache() } } -size_t NegCache::size() +size_t NegCache::size() const { size_t count = 0; - for (auto& map : d_maps) { + for (const auto& map : d_maps) { count += map.d_entriesCount; } return count; @@ -168,9 +168,9 @@ void NegCache::updateValidationStatus(const DNSName& qname, const QType& qtype, * * \param qname The name of the entries to be counted */ -size_t NegCache::count(const DNSName& qname) +size_t NegCache::count(const DNSName& qname) const { - auto& map = getMap(qname); + const auto& map = getMap(qname); const lock l(map); return map.d_map.count(tie(qname)); } @@ -181,9 +181,9 @@ size_t NegCache::count(const DNSName& qname) * \param qname The name of the entries to be counted * \param qtype The type of the entries to be counted */ -size_t NegCache::count(const DNSName& qname, const QType qtype) +size_t NegCache::count(const DNSName& qname, const QType qtype) const { - auto& map = getMap(qname); + const auto& map = getMap(qname); const lock l(map); return map.d_map.count(tie(qname, qtype)); } @@ -252,29 +252,30 @@ void NegCache::prune(size_t maxEntries) * * \param fp A pointer to an open FILE object */ -size_t NegCache::dumpToFile(FILE* fp) +size_t NegCache::dumpToFile(FILE* fp) const { - size_t ret(0); + size_t ret = 0; struct timeval now; Utility::gettimeofday(&now, nullptr); - for (auto& m : d_maps) { + for (const auto& m : d_maps) { const lock l(m); auto& sidx = m.d_map.get(); for (const NegCacheEntry& ne : sidx) { ret++; - fprintf(fp, "%s %" PRId64 " IN %s VIA %s ; (%s)\n", ne.d_name.toString().c_str(), static_cast(ne.d_ttd - now.tv_sec), ne.d_qtype.getName().c_str(), ne.d_auth.toString().c_str(), vStateToString(ne.d_validationState).c_str()); + int64_t ttl = ne.d_ttd - now.tv_sec; + fprintf(fp, "%s %" PRId64 " IN %s VIA %s ; (%s)\n", ne.d_name.toString().c_str(), ttl, ne.d_qtype.getName().c_str(), ne.d_auth.toString().c_str(), vStateToString(ne.d_validationState).c_str()); for (const auto& rec : ne.authoritySOA.records) { - fprintf(fp, "%s %" PRId64 " IN %s %s ; (%s)\n", rec.d_name.toString().c_str(), static_cast(ne.d_ttd - now.tv_sec), DNSRecordContent::NumberToType(rec.d_type).c_str(), rec.d_content->getZoneRepresentation().c_str(), vStateToString(ne.d_validationState).c_str()); + fprintf(fp, "%s %" PRId64 " IN %s %s ; (%s)\n", rec.d_name.toString().c_str(), ttl, DNSRecordContent::NumberToType(rec.d_type).c_str(), rec.d_content->getZoneRepresentation().c_str(), vStateToString(ne.d_validationState).c_str()); } for (const auto& sig : ne.authoritySOA.signatures) { - fprintf(fp, "%s %" PRId64 " IN RRSIG %s ;\n", sig.d_name.toString().c_str(), static_cast(ne.d_ttd - now.tv_sec), sig.d_content->getZoneRepresentation().c_str()); + fprintf(fp, "%s %" PRId64 " IN RRSIG %s ;\n", sig.d_name.toString().c_str(), ttl, sig.d_content->getZoneRepresentation().c_str()); } for (const auto& rec : ne.DNSSECRecords.records) { - fprintf(fp, "%s %" PRId64 " IN %s %s ; (%s)\n", rec.d_name.toString().c_str(), static_cast(ne.d_ttd - now.tv_sec), DNSRecordContent::NumberToType(rec.d_type).c_str(), rec.d_content->getZoneRepresentation().c_str(), vStateToString(ne.d_validationState).c_str()); + fprintf(fp, "%s %" PRId64 " IN %s %s ; (%s)\n", rec.d_name.toString().c_str(), ttl, DNSRecordContent::NumberToType(rec.d_type).c_str(), rec.d_content->getZoneRepresentation().c_str(), vStateToString(ne.d_validationState).c_str()); } for (const auto& sig : ne.DNSSECRecords.signatures) { - fprintf(fp, "%s %" PRId64 " IN RRSIG %s ;\n", sig.d_name.toString().c_str(), static_cast(ne.d_ttd - now.tv_sec), sig.d_content->getZoneRepresentation().c_str()); + fprintf(fp, "%s %" PRId64 " IN RRSIG %s ;\n", sig.d_name.toString().c_str(), ttl, sig.d_content->getZoneRepresentation().c_str()); } } } diff --git a/pdns/recursordist/negcache.hh b/pdns/recursordist/negcache.hh index 91b37178ba..894d07501b 100644 --- a/pdns/recursordist/negcache.hh +++ b/pdns/recursordist/negcache.hh @@ -21,6 +21,8 @@ */ #pragma once +#include +#include #include #include #include "dnsparser.hh" @@ -70,13 +72,13 @@ public: void updateValidationStatus(const DNSName& qname, const QType& qtype, const vState newState, boost::optional capTTD); bool get(const DNSName& qname, const QType& qtype, const struct timeval& now, NegCacheEntry& ne, bool typeMustMatch = false); bool getRootNXTrust(const DNSName& qname, const struct timeval& now, NegCacheEntry& ne); - size_t count(const DNSName& qname); - size_t count(const DNSName& qname, const QType qtype); + size_t count(const DNSName& qname) const; + size_t count(const DNSName& qname, const QType qtype) const; void prune(size_t maxEntries); void clear(); - size_t dumpToFile(FILE* fd); + size_t dumpToFile(FILE* fd) const; size_t wipe(const DNSName& name, bool subtree = false); - size_t size(); + size_t size() const; void preRemoval(const NegCacheEntry& entry) { @@ -110,10 +112,10 @@ private: MapCombo(const MapCombo &) = delete; MapCombo & operator=(const MapCombo &) = delete; negcache_t d_map; - std::mutex mutex; + mutable std::mutex mutex; std::atomic d_entriesCount{0}; - uint64_t d_contended_count{0}; - uint64_t d_acquired_count{0}; + mutable uint64_t d_contended_count{0}; + mutable uint64_t d_acquired_count{0}; bool d_cachecachevalid{false}; // XXX }; @@ -123,9 +125,13 @@ private: { return d_maps[qname.hash() % d_maps.size()]; } + const MapCombo& getMap(const DNSName &qname) const + { + return d_maps[qname.hash() % d_maps.size()]; + } public: struct lock { - lock(MapCombo& map) : m(map.mutex) + lock(const MapCombo& map) : m(map.mutex) { if (!m.try_lock()) { m.lock();