diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2007-01-07 21:35:25 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2007-01-07 21:35:25 +0000 |
commit | f1ca6c6d71f3e31b333e0be45294bcb30fd89b4d (patch) | |
tree | 307b67ee46dc6b69b844626051c933711d1d1d0d /src | |
parent | 8d948ff975c815cb32300354244b1bab263af155 (diff) |
DNS caching stuff (almost done)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@6252 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r-- | src/dns.cpp | 10 | ||||
-rw-r--r-- | src/modules.cpp | 11 | ||||
-rw-r--r-- | src/modules/extra/m_pgsql.cpp | 5 | ||||
-rw-r--r-- | src/modules/m_cgiirc.cpp | 10 | ||||
-rw-r--r-- | src/modules/m_dnsbl.cpp | 5 | ||||
-rw-r--r-- | src/modules/m_http_client.cpp | 5 | ||||
-rw-r--r-- | src/modules/m_spanningtree.cpp | 10 | ||||
-rw-r--r-- | src/modules/m_testcommand.cpp | 23 | ||||
-rw-r--r-- | src/users.cpp | 10 |
9 files changed, 28 insertions, 61 deletions
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) |