summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2007-01-07 22:01:00 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2007-01-07 22:01:00 +0000
commitfe46f3c228ae993b59fbf5eca423c3171d90e1b3 (patch)
tree00e891232399b60adfe3a815b1a00ee2273da99d
parent2a5e6d416ff00d25230cee662b6e56e9a3d59f75 (diff)
Document dns caching, add a "bool cached" to OnLookupComplete method in Resolver, and and add " -- cached" to end of 'looking up your host' string if their result is a cached result
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@6254 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--include/dns.h14
-rw-r--r--include/inspircd.h10
-rw-r--r--include/users.h2
-rw-r--r--src/dns.cpp4
-rw-r--r--src/modules/extra/m_pgsql.cpp4
-rw-r--r--src/modules/m_cgiirc.cpp2
-rw-r--r--src/modules/m_dnsbl.cpp2
-rw-r--r--src/modules/m_http_client.cpp2
-rw-r--r--src/modules/m_spanningtree.cpp4
-rw-r--r--src/modules/m_testcommand.cpp4
-rw-r--r--src/users.cpp4
11 files changed, 36 insertions, 16 deletions
diff --git a/include/dns.h b/include/dns.h
index bfced4184..c7283f6b8 100644
--- a/include/dns.h
+++ b/include/dns.h
@@ -228,6 +228,14 @@ class Resolver : public Extensible
* To get around this automatic behaviour, you must use one of the values
* DNS_QUERY_PTR4 or DNS_QUERY_PTR6 to force ipv4 or ipv6 behaviour on the lookup,
* irrespective of what protocol InspIRCd has been built for.
+ * @param cached The constructor will set this boolean to true or false depending
+ * on whether the DNS lookup you are attempting is cached (and not expired) or not.
+ * If the value is cached, upon return this will be set to true, otherwise it will
+ * be set to false. You should pass this value to InspIRCd::AddResolver(), which
+ * will then influence the behaviour of the method and determine whether a cached
+ * or non-cached result is obtained. The value in this variable is always correct
+ * for the given request when the constructor exits.
+ * @param creator See the note below.
* @throw ModuleException This class may throw an instance of ModuleException, in the
* event a lookup could not be allocated, or a similar hard error occurs such as
* the network being down. This will also be thrown if an invalid IP address is
@@ -247,8 +255,12 @@ 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.
+ * @param ttl The time-to-live value of the result, in the instance of a cached
+ * result, this is the number of seconds remaining before refresh/expiry.
+ * @param cached True if the result is a cached result, false if it was requested
+ * from the DNS server.
*/
- virtual void OnLookupComplete(const std::string &result, unsigned int ttl) = 0;
+ virtual void OnLookupComplete(const std::string &result, unsigned int ttl, bool cached) = 0;
/**
* If an error occurs (such as NXDOMAIN, no domain name found) then this method
* will be called.
diff --git a/include/inspircd.h b/include/inspircd.h
index 136914276..2224dca63 100644
--- a/include/inspircd.h
+++ b/include/inspircd.h
@@ -885,7 +885,15 @@ 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.
+ * @param cached If this value is true, then the cache will
+ * be searched for the DNS result, immediately. If the value is
+ * false, then a request will be sent to the nameserver, and the
+ * result will not be immediately available. You should usually
+ * use the boolean value which you passed to the Resolver
+ * constructor, which Resolver will set appropriately depending
+ * on if cached results are available and haven't expired. It is
+ * however safe to force this value to false, forcing a remote DNS
+ * lookup, but not an update of the cache.
* @return True if the resolver was added
*/
bool AddResolver(Resolver* r, bool cached);
diff --git a/include/users.h b/include/users.h
index c26d791fa..d69781f80 100644
--- a/include/users.h
+++ b/include/users.h
@@ -69,7 +69,7 @@ class UserResolver : public Resolver
public:
UserResolver(InspIRCd* Instance, userrec* user, std::string to_resolve, QueryType qt, bool &cache);
- void OnLookupComplete(const std::string &result, unsigned int ttl);
+ void OnLookupComplete(const std::string &result, unsigned int ttl, bool cached);
void OnError(ResolverError e, const std::string &errormessage);
};
diff --git a/src/dns.cpp b/src/dns.cpp
index a8aaa3fde..b7bdbca4e 100644
--- a/src/dns.cpp
+++ b/src/dns.cpp
@@ -914,7 +914,7 @@ void DNS::DelCache(const std::string &source)
void Resolver::TriggerCachedResult()
{
if (CQ)
- OnLookupComplete(CQ->data, time_left);
+ OnLookupComplete(CQ->data, time_left, true);
}
/** High level abstraction of dns used by application at large */
@@ -1060,7 +1060,7 @@ void DNS::HandleEvent(EventType et, int errornum)
this->cache->insert(std::make_pair(res.original.c_str(), CachedQuery(res.result, res.ttl)));
}
- Classes[res.id]->OnLookupComplete(res.result, res.ttl);
+ Classes[res.id]->OnLookupComplete(res.result, res.ttl, false);
delete Classes[res.id];
Classes[res.id] = NULL;
}
diff --git a/src/modules/extra/m_pgsql.cpp b/src/modules/extra/m_pgsql.cpp
index d5041f6f7..72c107725 100644
--- a/src/modules/extra/m_pgsql.cpp
+++ b/src/modules/extra/m_pgsql.cpp
@@ -95,7 +95,7 @@ class SQLresolver : public Resolver
{
}
- virtual void OnLookupComplete(const std::string &result, unsigned int ttl);
+ virtual void OnLookupComplete(const std::string &result, unsigned int ttl, bool cached);
virtual void OnError(ResolverError e, const std::string &errormessage)
{
@@ -1240,7 +1240,7 @@ public:
/* move this here to use AddConn, rather that than having the whole
* module above SQLConn, since this is buggin me right now :/
*/
-void SQLresolver::OnLookupComplete(const std::string &result, unsigned int ttl)
+void SQLresolver::OnLookupComplete(const std::string &result, unsigned int ttl, bool cached)
{
host.ip = result;
((ModulePgSQL*)mod)->AddConn(host);
diff --git a/src/modules/m_cgiirc.cpp b/src/modules/m_cgiirc.cpp
index a5f0bca3e..437ce3190 100644
--- a/src/modules/m_cgiirc.cpp
+++ b/src/modules/m_cgiirc.cpp
@@ -54,7 +54,7 @@ class CGIResolver : public Resolver
CGIResolver(Module* me, InspIRCd* ServerInstance, bool NotifyOpers, const std::string &source, bool forward, userrec* u, int userfd, const std::string &type, bool &cached)
: Resolver(ServerInstance, source, forward ? DNS_QUERY_FORWARD : DNS_QUERY_REVERSE, cached, me), typ(type), theirfd(userfd), them(u), notify(NotifyOpers) { }
- virtual void OnLookupComplete(const std::string &result, unsigned int ttl)
+ virtual void OnLookupComplete(const std::string &result, unsigned int ttl, bool cached)
{
/* Check the user still exists */
if ((them) && (them == ServerInstance->SE->GetRef(theirfd)))
diff --git a/src/modules/m_dnsbl.cpp b/src/modules/m_dnsbl.cpp
index a60c2eb0c..713924110 100644
--- a/src/modules/m_dnsbl.cpp
+++ b/src/modules/m_dnsbl.cpp
@@ -54,7 +54,7 @@ class DNSBLResolver : public Resolver
ConfEntry = conf;
}
- virtual void OnLookupComplete(const std::string &result, unsigned int ttl)
+ virtual void OnLookupComplete(const std::string &result, unsigned int ttl, bool cached)
{
/* Check the user still exists */
if ((them) && (them == ServerInstance->SE->GetRef(theirfd)))
diff --git a/src/modules/m_http_client.cpp b/src/modules/m_http_client.cpp
index 6891aa972..d015661c0 100644
--- a/src/modules/m_http_client.cpp
+++ b/src/modules/m_http_client.cpp
@@ -60,7 +60,7 @@ class HTTPResolver : public Resolver
{
}
- void OnLookupComplete(const string &result, unsigned int ttl)
+ void OnLookupComplete(const string &result, unsigned int ttl, bool cached)
{
socket->Connect(result);
}
diff --git a/src/modules/m_spanningtree.cpp b/src/modules/m_spanningtree.cpp
index 6cc46f119..8fee962fa 100644
--- a/src/modules/m_spanningtree.cpp
+++ b/src/modules/m_spanningtree.cpp
@@ -3719,7 +3719,7 @@ class ServernameResolver : public Resolver
/* Nothing in here, folks */
}
- void OnLookupComplete(const std::string &result, unsigned int ttl)
+ void OnLookupComplete(const std::string &result, unsigned int ttl, bool cached)
{
/* Initiate the connection, now that we have an IP to use.
* Passing a hostname directly to InspSocket causes it to
@@ -3768,7 +3768,7 @@ class SecurityIPResolver : public Resolver
{
}
- void OnLookupComplete(const std::string &result, unsigned int ttl)
+ void OnLookupComplete(const std::string &result, unsigned int ttl, bool cached)
{
ServerInstance->Log(DEBUG,"Security IP cache: Adding IP address '%s' for Link '%s'",result.c_str(),MyLink.Name.c_str());
Utils->ValidIPs.push_back(result);
diff --git a/src/modules/m_testcommand.cpp b/src/modules/m_testcommand.cpp
index 761196978..a3ae7aedf 100644
--- a/src/modules/m_testcommand.cpp
+++ b/src/modules/m_testcommand.cpp
@@ -31,9 +31,9 @@ class MyV6Resolver : public Resolver
fw = forward;
}
- virtual void OnLookupComplete(const std::string &result, unsigned int ttl)
+ virtual void OnLookupComplete(const std::string &result, unsigned int ttl, bool cached)
{
- ServerInstance->Log(DEBUG,"*** RESOLVER COMPLETED %s LOOKUP, IP IS: '%s' TTL=%lu",fw ? "FORWARD" : "REVERSE", result.c_str(), ttl);
+ ServerInstance->Log(DEBUG,"*** RESOLVER COMPLETED %s LOOKUP, IP IS: '%s' TTL=%lu CACHED=%d",fw ? "FORWARD" : "REVERSE", result.c_str(), ttl, cached);
}
virtual void OnError(ResolverError e, const std::string &errormessage)
diff --git a/src/users.cpp b/src/users.cpp
index a42e86210..0e88c3de4 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -168,7 +168,7 @@ UserResolver::UserResolver(InspIRCd* Instance, userrec* user, std::string to_res
this->bound_fd = user->GetFd();
}
-void UserResolver::OnLookupComplete(const std::string &result, unsigned int ttl)
+void UserResolver::OnLookupComplete(const std::string &result, unsigned int ttl, bool cached)
{
if ((!this->fwd) && (ServerInstance->SE->GetRef(this->bound_fd) == this->bound_user))
{
@@ -211,7 +211,7 @@ void UserResolver::OnLookupComplete(const std::string &result, unsigned int ttl)
if (*(hostname.c_str()) == ':')
hostname = "0" + hostname;
- this->bound_user->WriteServ("NOTICE Auth :*** Found your hostname (%s)", hostname.c_str());
+ this->bound_user->WriteServ("NOTICE Auth :*** Found your hostname (%s)%s", hostname.c_str(), (cached ? " -- cached" : ""));
this->bound_user->dns_done = true;
strlcpy(this->bound_user->dhost, hostname.c_str(),64);
strlcpy(this->bound_user->host, hostname.c_str(),64);