int32_t MemRecursorCache::get(time_t now, const DNSName &qname, const QType& qt, bool requireAuth, vector<DNSRecord>* res, const ComboAddress& who, bool refresh, const OptTag& routingTag, vector<std::shared_ptr<RRSIGRecordContent>>* signatures, std::vector<std::shared_ptr<DNSRecord>>* authorityRecs, bool* variable, vState* state, bool* wasAuth, DNSName* fromAuthZone)
{
boost::optional<vState> cachedState{boost::none};
- time_t ttd=0;
uint32_t origTTL;
if(res) {
if (routingTag) {
auto entries = getEntries(map, qname, qt, routingTag);
+ bool found = false;
+ time_t ttd;
if (entries.first != entries.second) {
OrderedTagIterator_t firstIndexIterator;
for (auto i=entries.first; i != entries.second; ++i) {
-
firstIndexIterator = map.d_map.project<OrderedTag>(i);
- origTTL = firstIndexIterator->d_orig_ttl;
+
if (i->d_ttd <= now) {
moveCacheItemToFront<SequencedTag>(map.d_map, firstIndexIterator);
continue;
if (!entryMatches(firstIndexIterator, qtype, requireAuth, who)) {
continue;
}
-
+ found = true;
ttd = handleHit(map, firstIndexIterator, qname, origTTL, res, signatures, authorityRecs, variable, cachedState, wasAuth, fromAuthZone);
if (qt.getCode() != QType::ANY && qt.getCode() != QType::ADDR) { // normally if we have a hit, we are done
break;
}
}
- if (state && cachedState) {
- *state = *cachedState;
+ if (found) {
+ if (state && cachedState) {
+ *state = *cachedState;
+ }
+ return fakeTTD(firstIndexIterator, qname, qtype, ttd, now, origTTL, refresh);
}
- return fakeTTD(firstIndexIterator, qname, qtype, ttd, now, origTTL, refresh);
}
}
// Try (again) without tag
if (entries.first != entries.second) {
OrderedTagIterator_t firstIndexIterator;
- for (auto i=entries.first; i != entries.second; ++i) {
+ bool found = false;
+ time_t ttd;
+ for (auto i=entries.first; i != entries.second; ++i) {
firstIndexIterator = map.d_map.project<OrderedTag>(i);
- origTTL = firstIndexIterator->d_orig_ttl;
+
if (i->d_ttd <= now) {
moveCacheItemToFront<SequencedTag>(map.d_map, firstIndexIterator);
continue;
continue;
}
+ found = true;
ttd = handleHit(map, firstIndexIterator, qname, origTTL, res, signatures, authorityRecs, variable, cachedState, wasAuth, fromAuthZone);
if (qt.getCode() != QType::ANY && qt.getCode() != QType::ADDR) { // normally if we have a hit, we are done
break;
}
}
- if (state && cachedState) {
- *state = *cachedState;
+ if (found) {
+ if (state && cachedState) {
+ *state = *cachedState;
+ }
+ return fakeTTD(firstIndexIterator, qname, qtype, ttd, now, origTTL, refresh);
}
- return fakeTTD(firstIndexIterator, qname, qtype, ttd, now, origTTL, refresh);
}
return -1;
}
MRC.replace(now, power, QType(QType::A), records, signatures, authRecords, false, authZone, boost::none);
BOOST_CHECK_EQUAL(MRC.size(), 1U);
// let's first check that non-auth is not returned when we need authoritative data
- BOOST_CHECK_EQUAL(MRC.get(now, power, QType(QType::A), true, &retrieved, ComboAddress("127.0.0.1")), -now);
+ BOOST_CHECK_EQUAL(MRC.get(now, power, QType(QType::A), true, &retrieved, ComboAddress("127.0.0.1")), -1);
BOOST_CHECK_EQUAL(MRC.get(now, power, QType(QType::A), false, &retrieved, ComboAddress("127.0.0.1")), (ttd - now));
BOOST_REQUIRE_EQUAL(retrieved.size(), 1U);
BOOST_CHECK_EQUAL(getRR<ARecordContent>(retrieved.at(0))->getCA().toString(), dr2Content.toString());
BOOST_CHECK_EQUAL(MRC.size(), 2U);
/* trigger a miss (expired) for power2 */
- BOOST_CHECK_EQUAL(MRC.get(now, power2, QType(dr2.d_type), false, &retrieved, who, 0, boost::none, nullptr), -now);
+ BOOST_CHECK_EQUAL(MRC.get(now, power2, QType(dr2.d_type), false, &retrieved, who, 0, boost::none, nullptr), -1);
/* power2 should have been moved to the front of the expunge
queue, and should this time be removed first */