mirror of
https://github.com/inspircd/inspircd.git
synced 2025-03-10 02:59:01 -04:00
DNS caching stuff (almost done)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@6252 e03df62e-2008-0410-955e-edbf42e46eb7
This commit is contained in:
parent
8d948ff975
commit
f1ca6c6d71
@ -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
|
||||
|
@ -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
|
||||
|
10
src/dns.cpp
10
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;
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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(...)
|
||||
{
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user