Skip to content

Commit

Permalink
auth: improve changed catalog detection
Browse files Browse the repository at this point in the history
  • Loading branch information
mind04 committed Apr 12, 2024
1 parent e7bb966 commit a870ac5
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
9 changes: 4 additions & 5 deletions modules/lmdbbackend/lmdbbackend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1810,9 +1810,7 @@ void LMDBBackend::setFresh(uint32_t domain_id)

void LMDBBackend::getUpdatedPrimaries(vector<DomainInfo>& updatedDomains, std::unordered_set<DNSName>& catalogs, CatalogHashMap& catalogHashes)
{
CatalogInfo ci;

getAllDomainsFiltered(&(updatedDomains), [this, &catalogs, &catalogHashes, &ci](DomainInfo& di) {
getAllDomainsFiltered(&(updatedDomains), [this, &catalogs, &catalogHashes](DomainInfo& di) {

Check warning on line 1813 in modules/lmdbbackend/lmdbbackend.cc

View workflow job for this annotation

GitHub Actions / Analyze (cpp, auth)

parameter name 'di' is too short, expected at least 3 characters (readability-identifier-length - Level=Warning)
if (!di.isPrimaryType()) {
return false;
}
Expand All @@ -1824,12 +1822,13 @@ void LMDBBackend::getUpdatedPrimaries(vector<DomainInfo>& updatedDomains, std::u
}

if (!di.catalog.empty()) {
ci.fromJson(di.options, CatalogInfo::CatalogType::Producer);
ci.updateHash(catalogHashes, di);
CatalogInfo::updateCatalogHash(catalogHashes, di);
}

if (getSerial(di) && di.serial != di.notified_serial) {
di.backend = this;
di.catalog.clear();
di.options.clear();
return true;
}

Expand Down
26 changes: 17 additions & 9 deletions pdns/auth-catalogzone.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@
#include "dnsbackend.hh"
#include "json.hh"

void CatalogInfo::fromJson(const std::string& json, CatalogType type)
bool CatalogInfo::parseJson(const std::string& json, CatalogType type)
{
d_type = type;
if (d_type == CatalogType::None) {
if (type == CatalogType::None) {
throw std::runtime_error("CatalogType is set to None");
}

d_type = type;

if (json.empty()) {
return;
d_doc = nullptr;
return false;
}

std::string err;
Expand All @@ -44,7 +46,12 @@ void CatalogInfo::fromJson(const std::string& json, CatalogType type)
throw std::runtime_error("Parsing of JSON options failed: " + err);
}

if (!d_doc[getTypeString(d_type)].is_null()) {
return !d_doc[getTypeString(d_type)].is_null();
}

void CatalogInfo::fromJson(const std::string& json, CatalogType type)
{
if (parseJson(json, type)) {
auto items = d_doc[getTypeString(type)].object_items();

// coo property
Expand Down Expand Up @@ -107,11 +114,12 @@ std::string CatalogInfo::toJson() const
return ret.dump();
}

void CatalogInfo::updateHash(CatalogHashMap& hashes, const DomainInfo& di) const
void CatalogInfo::updateCatalogHash(CatalogHashMap& hashes, const DomainInfo& di)

Check warning on line 117 in pdns/auth-catalogzone.cc

View workflow job for this annotation

GitHub Actions / Analyze (cpp, auth)

parameter name 'di' is too short, expected at least 3 characters (readability-identifier-length - Level=Warning)
{
hashes[di.catalog].process(std::to_string(di.id) + di.zone.toLogString() + string("\0", 1) + d_coo.toLogString() + string("\0", 1) + d_unique.toLogString());
for (const auto& group : d_group) {
hashes[di.catalog].process(std::to_string(group.length()) + group);
CatalogInfo ci;

Check warning on line 119 in pdns/auth-catalogzone.cc

View workflow job for this annotation

GitHub Actions / Analyze (cpp, auth)

variable name 'ci' is too short, expected at least 3 characters (readability-identifier-length - Level=Warning)
hashes[di.catalog].process(std::to_string(di.id) + di.zone.toLogString());
if (ci.parseJson(di.options, CatalogType::Producer)) {
hashes[di.catalog].process(ci.d_doc["producer"].dump());
}
}

Expand Down
4 changes: 3 additions & 1 deletion pdns/auth-catalogzone.hh
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public:
std::string toJson() const;
void setType(CatalogType type) { d_type = type; }

void updateHash(CatalogHashMap& hashes, const DomainInfo& di) const;
static void updateCatalogHash(CatalogHashMap& hashes, const DomainInfo& di);
DNSName getUnique() const { return DNSName(toBase32Hex(hashQNameWithSalt(std::to_string(d_id), 0, d_zone))); } // salt with domain id to detect recreated zones
static DNSZoneRecord getCatalogVersionRecord(const DNSName& zone);
void toDNSZoneRecords(const DNSName& zone, vector<DNSZoneRecord>& dzrs) const;
Expand All @@ -77,4 +77,6 @@ public:
private:
CatalogType d_type;
json11::Json d_doc;

bool parseJson(const std::string& json, CatalogType type);
};
5 changes: 3 additions & 2 deletions pdns/backends/gsql/gsqlbackend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -593,8 +593,8 @@ void GSQLBackend::getUpdatedPrimaries(vector<DomainInfo>& updatedDomains, std::u

try {
if (!row[5].empty()) {
ci.fromJson(row[4], CatalogInfo::CatalogType::Producer);
ci.updateHash(catalogHashes, di);
di.options = row[4];
CatalogInfo::updateCatalogHash(catalogHashes, di);
}
}
catch (const std::exception& e) {
Expand Down Expand Up @@ -626,6 +626,7 @@ void GSQLBackend::getUpdatedPrimaries(vector<DomainInfo>& updatedDomains, std::u
di.kind = DomainInfo::Primary;
di.serial = sd.serial;
di.catalog.clear();
di.options.clear();

updatedDomains.emplace_back(di);
}
Expand Down

0 comments on commit a870ac5

Please sign in to comment.