0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2025-04-09 03:13:11 +02:00

ircd::net::dns: Improve/fix cache management related.

This commit is contained in:
Jason Volk 2018-04-14 17:31:28 -07:00
parent b9cf0c9796
commit de295777d0

View file

@ -2489,17 +2489,43 @@ ircd::net::dns::cache::put_error(const rfc1035::question &question,
{ {
case 1: // A case 1: // A
{ {
auto &map{A};
auto pit
{
map.equal_range(host)
};
auto it
{
pit.first != pit.second?
map.erase(pit.first, pit.second):
pit.first
};
rfc1035::record::A record; rfc1035::record::A record;
record.ttl = ircd::time() + seconds(cache::clear_nxdomain).count(); //TODO: code record.ttl = ircd::time() + seconds(cache::clear_nxdomain).count(); //TODO: code
A.emplace(host, record); map.emplace_hint(it, host, record);
return true; return true;
} }
case 33: // SRV case 33: // SRV
{ {
auto &map{SRV};
auto pit
{
map.equal_range(host)
};
auto it
{
pit.first != pit.second?
map.erase(pit.first, pit.second):
pit.first
};
rfc1035::record::SRV record; rfc1035::record::SRV record;
record.ttl = ircd::time() + seconds(cache::clear_nxdomain).count(); //TODO: code record.ttl = ircd::time() + seconds(cache::clear_nxdomain).count(); //TODO: code
SRV.emplace(host, record); map.emplace_hint(it, host, record);
return true; return true;
} }
} }
@ -2520,22 +2546,54 @@ ircd::net::dns::cache::put(const rfc1035::question &question,
{ {
case 1: // A case 1: // A
{ {
const auto &it auto &map{A};
auto pit
{ {
A.emplace(host, answer) map.equal_range(host)
}; };
return &it->second; auto it(pit.first);
while(it != pit.second)
{
const auto &rr{it->second};
if(rr == answer)
it = map.erase(it);
else
++it;
}
const auto &iit
{
map.emplace_hint(it, host, answer)
};
return &iit->second;
} }
case 33: // SRV case 33: // SRV
{ {
const auto &it auto &map{SRV};
auto pit
{ {
SRV.emplace(host, answer) map.equal_range(host)
}; };
return &it->second; auto it(pit.first);
while(it != pit.second)
{
const auto &rr{it->second};
if(rr == answer)
it = map.erase(it);
else
++it;
}
const auto &iit
{
map.emplace_hint(it, host, answer)
};
return &iit->second;
} }
default: default:
@ -2604,14 +2662,17 @@ ircd::net::dns::cache::get(const hostport &hp,
}); });
} }
record.at(count++) = &rr; if(count < record.size())
record.at(count++) = &rr;
++it; ++it;
} }
} }
else // Deduced A query (for now) else // Deduced A query (for now)
{ {
auto &map{A}; auto &map{A};
const auto pit{map.equal_range(host(hp))}; const auto &key{rstrip(host(hp), '.')};
const auto pit{map.equal_range(key)};
if(pit.first == pit.second) if(pit.first == pit.second)
return false; return false;
@ -2641,7 +2702,9 @@ ircd::net::dns::cache::get(const hostport &hp,
}); });
} }
record.at(count++) = &rr; if(count < record.size())
record.at(count++) = &rr;
++it; ++it;
} }
} }