summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2007-01-07 21:35:25 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2007-01-07 21:35:25 +0000
commitf1ca6c6d71f3e31b333e0be45294bcb30fd89b4d (patch)
tree307b67ee46dc6b69b844626051c933711d1d1d0d
parent8d948ff975c815cb32300354244b1bab263af155 (diff)
DNS caching stuff (almost done)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@6252 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--include/dns.h14
-rw-r--r--include/inspircd.h3
-rw-r--r--src/dns.cpp10
-rw-r--r--src/modules.cpp11
-rw-r--r--src/modules/extra/m_pgsql.cpp5
-rw-r--r--src/modules/m_cgiirc.cpp10
-rw-r--r--src/modules/m_dnsbl.cpp5
-rw-r--r--src/modules/m_http_client.cpp5
-rw-r--r--src/modules/m_spanningtree.cpp10
-rw-r--r--src/modules/m_testcommand.cpp23
-rw-r--r--src/users.cpp10
11 files changed, 43 insertions, 63 deletions
diff --git a/include/dns.h b/include/dns.h
index 83e4ab902..bfced4184 100644
--- a/include/dns.h
+++ b/include/dns.h
@@ -194,6 +194,16 @@ class Resolver : public Extensible
* The core uses this to route results to the correct objects.
*/
int myid;
+
+ /**
+ * Cached result, if there is one
+ */
+ CachedQuery *CQ;
+
+ /**
+ * Time left before cache expiry
+ */
+ int time_left;
public:
/**
* Initiate DNS lookup. Your class should not attempt to delete or free these
@@ -238,7 +248,7 @@ class Resolver : public Extensible
* When your lookup completes, this method will be called.
* @param result The resulting DNS lookup, either an IP address or a hostname.
*/
- virtual void OnLookupComplete(const std::string &result, unsigned int ttl);
+ virtual void OnLookupComplete(const std::string &result, unsigned int ttl) = 0;
/**
* If an error occurs (such as NXDOMAIN, no domain name found) then this method
* will be called.
@@ -260,6 +270,8 @@ class Resolver : public Extensible
* Returns the creator module, or NULL
*/
Module* GetCreator();
+
+ void TriggerCachedResult();
};
/** DNS is a singleton class used by the core to dispatch dns
diff --git a/include/inspircd.h b/include/inspircd.h
index 3f6b702f1..136914276 100644
--- a/include/inspircd.h
+++ b/include/inspircd.h
@@ -885,9 +885,10 @@ class InspIRCd : public classbase
/** Add a dns Resolver class to this server's active set
* @param r The resolver to add
+ * @param cached The value of 'cached' which you passed to the Resolver constructor before this function.
* @return True if the resolver was added
*/
- bool AddResolver(Resolver* r);
+ bool AddResolver(Resolver* r, bool cached);
/** Add a command to this server's command parser
* @param f A command_t command handler object to add
diff --git a/src/dns.cpp b/src/dns.cpp
index 385f8639e..a8aaa3fde 100644
--- a/src/dns.cpp
+++ b/src/dns.cpp
@@ -911,9 +911,10 @@ void DNS::DelCache(const std::string &source)
cache->erase(source.c_str());
}
-void Resolver::OnLookupComplete(const std::string &result, unsigned int ttl)
+void Resolver::TriggerCachedResult()
{
- throw CoreException("Someone didnt define an OnLookupComplete method for their Resolver class!");
+ if (CQ)
+ OnLookupComplete(CQ->data, time_left);
}
/** High level abstraction of dns used by application at large */
@@ -923,10 +924,10 @@ Resolver::Resolver(InspIRCd* Instance, const std::string &source, QueryType qt,
cached = false;
- CachedQuery* CQ = ServerInstance->Res->GetCache(source);
+ CQ = ServerInstance->Res->GetCache(source);
if (CQ)
{
- int time_left = CQ->CalcTTLRemaining();
+ time_left = CQ->CalcTTLRemaining();
if (!time_left)
{
ServerInstance->Log(DEBUG,"Cached but EXPIRED result: %s", CQ->data.c_str());
@@ -936,7 +937,6 @@ Resolver::Resolver(InspIRCd* Instance, const std::string &source, QueryType qt,
{
cached = true;
ServerInstance->Log(DEBUG,"Cached result: %s", CQ->data.c_str());
- OnLookupComplete(CQ->data, time_left);
return;
}
}
diff --git a/src/modules.cpp b/src/modules.cpp
index 959092641..8d5ca846f 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -434,9 +434,16 @@ bool InspIRCd::DelModeWatcher(ModeWatcher* mw)
return this->Modes->DelModeWatcher(mw);
}
-bool InspIRCd::AddResolver(Resolver* r)
+bool InspIRCd::AddResolver(Resolver* r, bool cached)
{
- return this->Res->AddResolverClass(r);
+ if (!cached)
+ return this->Res->AddResolverClass(r);
+ else
+ {
+ r->TriggerCachedResult();
+ delete r;
+ return true;
+ }
}
bool InspIRCd::UserToPseudo(userrec* user, const std::string &message)
diff --git a/src/modules/extra/m_pgsql.cpp b/src/modules/extra/m_pgsql.cpp
index d72256a5f..d5041f6f7 100644
--- a/src/modules/extra/m_pgsql.cpp
+++ b/src/modules/extra/m_pgsql.cpp
@@ -1101,10 +1101,7 @@ public:
{
bool cached;
resolver = new SQLresolver(this, ServerInstance, host, cached);
- if (!cached)
- ServerInstance->AddResolver(resolver);
- else
- delete resolver;
+ ServerInstance->AddResolver(resolver, cached);
}
catch(...)
{
diff --git a/src/modules/m_cgiirc.cpp b/src/modules/m_cgiirc.cpp
index 6df039dce..a5f0bca3e 100644
--- a/src/modules/m_cgiirc.cpp
+++ b/src/modules/m_cgiirc.cpp
@@ -261,10 +261,7 @@ public:
{
bool cached;
CGIResolver* r = new CGIResolver(this, ServerInstance, NotifyOpers, user->password, false, user, user->GetFd(), "PASS", cached);
- if (!cached)
- ServerInstance->AddResolver(r);
- else
- delete r;
+ ServerInstance->AddResolver(r, cached);
}
catch (ModuleException& e)
{
@@ -321,10 +318,7 @@ public:
ServerInstance->Log(DEBUG,"MAKE RESOLVER: %s %d %s",newip, user->GetFd(), "IDENT");
bool cached;
CGIResolver* r = new CGIResolver(this, ServerInstance, NotifyOpers, newip, false, user, user->GetFd(), "IDENT", cached);
- if (!cached)
- ServerInstance->AddResolver(r);
- else
- delete r;
+ ServerInstance->AddResolver(r, cached);
}
catch (ModuleException& e)
{
diff --git a/src/modules/m_dnsbl.cpp b/src/modules/m_dnsbl.cpp
index d6581a7d1..a60c2eb0c 100644
--- a/src/modules/m_dnsbl.cpp
+++ b/src/modules/m_dnsbl.cpp
@@ -309,10 +309,7 @@ class ModuleDNSBL : public Module
/* now we'd need to fire off lookups for `hostname'. */
bool cached;
DNSBLResolver *r = new DNSBLResolver(this, ServerInstance, hostname, user, user->GetFd(), *i, cached);
- if (!cached)
- ServerInstance->AddResolver(r);
- else
- delete r;
+ ServerInstance->AddResolver(r, cached);
}
}
diff --git a/src/modules/m_http_client.cpp b/src/modules/m_http_client.cpp
index 92a9aa348..6891aa972 100644
--- a/src/modules/m_http_client.cpp
+++ b/src/modules/m_http_client.cpp
@@ -151,10 +151,7 @@ bool HTTPSocket::DoRequest(HTTPClientRequest *req)
{
bool cached;
HTTPResolver* r = new HTTPResolver(this, Server, url.domain, cached, (Module*)Mod);
- if (!cached)
- Instance->AddResolver(r);
- else
- delete r;
+ Instance->AddResolver(r, cached);
return true;
}
else
diff --git a/src/modules/m_spanningtree.cpp b/src/modules/m_spanningtree.cpp
index cbecfa24f..6cc46f119 100644
--- a/src/modules/m_spanningtree.cpp
+++ b/src/modules/m_spanningtree.cpp
@@ -4124,10 +4124,7 @@ void SpanningTreeUtilities::ReadConfiguration(bool rebind)
{
bool cached;
SecurityIPResolver* sr = new SecurityIPResolver((Module*)this->Creator, this, ServerInstance, L.IPAddr, L, cached);
- if (!cached)
- ServerInstance->AddResolver(sr);
- else
- delete sr;
+ ServerInstance->AddResolver(sr, cached);
}
catch (ModuleException& e)
{
@@ -4659,10 +4656,7 @@ class ModuleSpanningTree : public Module
{
bool cached;
ServernameResolver* snr = new ServernameResolver((Module*)this, Utils, ServerInstance,x->IPAddr, *x, cached);
- if (!cached)
- ServerInstance->AddResolver(snr);
- else
- delete snr;
+ ServerInstance->AddResolver(snr, cached);
}
catch (ModuleException& e)
{
diff --git a/src/modules/m_testcommand.cpp b/src/modules/m_testcommand.cpp
index 55632c98e..761196978 100644
--- a/src/modules/m_testcommand.cpp
+++ b/src/modules/m_testcommand.cpp
@@ -60,24 +60,11 @@ class cmd_woot : public command_t
* do it for us as required.*/
try
{
- bool cached1, cached2;
- MyV6Resolver* r = new MyV6Resolver(ServerInstance, Creator, "shake.stacken.kth.se", true, cached1);
- if (!cached1)
- ServerInstance->AddResolver(r);
- else
- {
- ServerInstance->Log(DEBUG,"Result was cached, delete object");
- delete r;
- }
-
- r = new MyV6Resolver(ServerInstance, Creator, "2001:6b0:1:ea:202:a5ff:fecd:13a6", false, cached2);
- if (!cached2)
- ServerInstance->AddResolver(r);
- else
- {
- ServerInstance->Log(DEBUG,"Result was cached, delete object");
- delete r;
- }
+ bool cached;
+ MyV6Resolver* r = new MyV6Resolver(ServerInstance, Creator, "shake.stacken.kth.se", true, cached);
+ ServerInstance->AddResolver(r, cached);
+ r = new MyV6Resolver(ServerInstance, Creator, "2001:6b0:1:ea:202:a5ff:fecd:13a6", false, cached);
+ ServerInstance->AddResolver(r, cached);
}
catch (ModuleException& e)
{
diff --git a/src/users.cpp b/src/users.cpp
index 37664a629..a42e86210 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -153,10 +153,7 @@ void userrec::StartDNSLookup()
ServerInstance->Log(DEBUG,"Passing instance: %08x",this->ServerInstance);
bool cached;
res_reverse = new UserResolver(this->ServerInstance, this, this->GetIPString(), DNS_QUERY_REVERSE, cached);
- if (!cached)
- this->ServerInstance->AddResolver(res_reverse);
- else
- delete res_reverse;
+ this->ServerInstance->AddResolver(res_reverse, cached);
}
catch (CoreException& e)
{
@@ -189,10 +186,7 @@ void UserResolver::OnLookupComplete(const std::string &result, unsigned int ttl)
#else
bound_user->res_forward = new UserResolver(this->ServerInstance, this->bound_user, result, DNS_QUERY_A, cached);
#endif
- if (!cached)
- this->ServerInstance->AddResolver(bound_user->res_forward);
- else
- delete bound_user->res_forward;
+ this->ServerInstance->AddResolver(bound_user->res_forward, cached);
}
}
catch (CoreException& e)