string value;
bool haveSomething;
{
- MapCombo& mc=getMap(pcReverse(p->qdomain));
+ MapCombo& mc=getMap(p->qdomain);
TryReadLock l(&mc.d_mut); // take a readlock here
if(!l.gotIt()) {
S.inc("deferred-cache-lookup");
CacheEntry val;
val.created=time(0);
val.ttd=val.created+ttl;
- val.qname=pcReverse(qname);
+ val.qname=qname;
val.qtype=qtype.getCode();
val.value=value;
val.ctype=cet;
int PacketCache::purge(const string &match)
{
int delcount=0;
-
- BOOST_FOREACH(MapCombo& mc, d_maps) {
- WriteLock l(&mc.d_mut);
-
- if(ends_with(match, "$")) {
- string prefix(match);
- prefix.resize(prefix.size()-1);
-
- string zone = pcReverse(DNSName(prefix));
-
- cmap_t::const_iterator iter = mc.d_map.lower_bound(tie(zone));
- cmap_t::const_iterator start=iter;
+ if(ends_with(match, "$")) {
+ string prefix(match);
+ prefix.resize(prefix.size()-1);
+ DNSName dprefix(prefix);
+ for(MapCombo& mc : d_maps) {
+ WriteLock l(&mc.d_mut);
+ cmap_t::const_iterator iter = mc.d_map.lower_bound(tie(dprefix));
+ auto start=iter;
for(; iter != mc.d_map.end(); ++iter) {
- if(iter->qname.compare(0, zone.size(), zone) != 0) {
+ if(!iter->qname.isPartOf(dprefix)) {
break;
}
delcount++;
}
mc.d_map.erase(start, iter);
}
-
- else {
- string qname = pcReverse(DNSName(match));
-
- delcount+=mc.d_map.count(tie(qname));
- pair<cmap_t::iterator, cmap_t::iterator> range = mc.d_map.equal_range(tie(qname));
+ }
+ else {
+ DNSName dn(match);
+ auto mc = getMap(dn);
+ WriteLock l(&mc.d_mut);
+ auto range = mc.d_map.equal_range(tie(dn));
+ if(range.first != range.second) {
+ delcount+=distance(range.first, range.second) - 1;
mc.d_map.erase(range.first, range.second);
}
}
+
*d_statnumentries-=delcount; // XXX FIXME NEEDS TO BE ADJUSTED
return delcount;
}
cleanup();
}
- MapCombo& mc=getMap(pcReverse(qname));
+ MapCombo& mc=getMap(qname);
TryReadLock l(&mc.d_mut); // take a readlock here
if(!l.gotIt()) {
{
uint16_t qt = qtype.getCode();
//cerr<<"Lookup for maxReplyLen: "<<maxReplyLen<<endl;
- string pcqname = pcReverse(qname);
- MapCombo& mc=getMap(pcqname);
- cmap_t::const_iterator i=mc.d_map.find(tie(pcqname, qt, cet, zoneID, meritsRecursion, maxReplyLen, dnssecOK, hasEDNS, *age));
+ MapCombo& mc=getMap(qname);
+ cmap_t::const_iterator i=mc.d_map.find(tie(qname, qt, cet, zoneID, meritsRecursion, maxReplyLen, dnssecOK, hasEDNS, *age));
time_t now=time(0);
bool ret=(i!=mc.d_map.end() && i->ttd > now);
if(ret) {
}
-string PacketCache::pcReverse(DNSName content)
-{
- string ret=content.labelReverse().toDNSString();
- return ret.substr(0, ret.size()-1);
-}
-
map<char,int> PacketCache::getCounts()
{
int recursivePackets=0, nonRecursivePackets=0, queryCacheEntries=0, negQueryCacheEntries=0;
private:
bool getEntryLocked(const DNSName &content, const QType& qtype, CacheEntryType cet, string& entry, int zoneID=-1,
bool meritsRecursion=false, unsigned int maxReplyLen=512, bool dnssecOk=false, bool hasEDNS=false, unsigned int *age=0);
- string pcReverse(DNSName content);
+
struct CacheEntry
{
CacheEntry() { qtype = ctype = 0; zoneID = -1; meritsRecursion=false; dnssecOk=false; hasEDNS=false; created=0; ttd=0; maxReplyLen=512;}
- string qname;
+ DNSName qname;
string value;
time_t created;
time_t ttd;
ordered_unique<
composite_key<
CacheEntry,
- member<CacheEntry,string,&CacheEntry::qname>,
+ member<CacheEntry,DNSName,&CacheEntry::qname>,
member<CacheEntry,uint16_t,&CacheEntry::qtype>,
member<CacheEntry,uint16_t, &CacheEntry::ctype>,
member<CacheEntry,int, &CacheEntry::zoneID>,
member<CacheEntry,bool, &CacheEntry::dnssecOk>,
member<CacheEntry,bool, &CacheEntry::hasEDNS>
>,
- composite_key_compare<std::less<string>, std::less<uint16_t>, std::less<uint16_t>, std::less<int>, std::less<bool>,
+ composite_key_compare<CanonDNSNameCompare, std::less<uint16_t>, std::less<uint16_t>, std::less<int>, std::less<bool>,
std::less<unsigned int>, std::less<bool>, std::less<bool> >
>,
sequenced<>
};
vector<MapCombo> d_maps;
- MapCombo& getMap(const std::string& qname)
+ MapCombo& getMap(const DNSName& qname)
{
- return d_maps[burtle((const unsigned char*)qname.c_str(), qname.length(), 0) % d_maps.size()];
+ return d_maps[hash_value(qname) % d_maps.size()];
}
AtomicCounter d_ops;