summaryrefslogtreecommitdiff
path: root/src/dns.cpp
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2007-01-08 18:42:13 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2007-01-08 18:42:13 +0000
commit2fe4636fa44ad48b801d0e38b892c0e47998327d (patch)
treeeceb91cda854b4fd8ab00e33c0d327ed88c33e01 /src/dns.cpp
parenta3bda51ef1095c92499b69a14273b4adf962ab1e (diff)
Add repeating timers, and make an hourly prune of the dns cache, otherwise a cache entry might not be cleared until a user with that ip comes back!
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@6264 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/dns.cpp')
-rw-r--r--src/dns.cpp47
1 files changed, 39 insertions, 8 deletions
diff --git a/src/dns.cpp b/src/dns.cpp
index cea1c4a43..625951ee5 100644
--- a/src/dns.cpp
+++ b/src/dns.cpp
@@ -103,6 +103,21 @@ class DNSRequest
int SendRequests(const DNSHeader *header, const int length, QueryType qt);
};
+class CacheTimer : public InspTimer
+{
+ private:
+ InspIRCd* ServerInstance;
+ DNS* dns;
+ public:
+ CacheTimer(InspIRCd* Instance, DNS* thisdns)
+ : InspTimer(3600, Instance->Time(), true), ServerInstance(Instance), dns(thisdns) { }
+
+ virtual void Tick(time_t TIME)
+ {
+ dns->PruneCache();
+ }
+};
+
class RequestTimeout : public InspTimer
{
InspIRCd* ServerInstance;
@@ -262,6 +277,23 @@ int DNS::ClearCache()
return rv;
}
+int DNS::PruneCache()
+{
+ int n = 0;
+ dnscache* newcache = new dnscache();
+ for (dnscache::iterator i = this->cache->begin(); i != this->cache->end(); i++)
+ /* Dont include expired items (theres no point) */
+ if (i->second.CalcTTLRemaining())
+ newcache->insert(*i);
+ else
+ n++;
+
+ delete this->cache;
+ this->cache = newcache;
+ ServerInstance->Log(DEBUG,"Prune %d expired cache items", n);
+ return n;
+}
+
void DNS::Rehash()
{
insp_inaddr addr;
@@ -276,14 +308,7 @@ void DNS::Rehash()
this->SetFd(-1);
/* Rehash the cache */
- dnscache* newcache = new dnscache();
- for (dnscache::iterator i = this->cache->begin(); i != this->cache->end(); i++)
- /* Dont include expired items (theres no point) */
- if (i->second.CalcTTLRemaining())
- newcache->insert(*i);
-
- delete this->cache;
- this->cache = newcache;
+ this->PruneCache();
}
else
{
@@ -397,6 +422,10 @@ DNS::DNS(InspIRCd* Instance) : ServerInstance(Instance)
/* Actually read the settings
*/
this->Rehash();
+
+ this->PruneTimer = new CacheTimer(ServerInstance, this);
+
+ ServerInstance->Timers->AddTimer(this->PruneTimer);
}
/** Build a payload to be placed after the header, based upon input data, a resource type, a class and a pointer to a buffer */
@@ -906,6 +935,8 @@ DNS::~DNS()
{
shutdown(this->GetFd(), 2);
close(this->GetFd());
+ ServerInstance->Timers->DelTimer(this->PruneTimer);
+ delete this->PruneTimer;
}
CachedQuery* DNS::GetCache(const std::string &source)