]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/dnsqueue.cpp
Typoes
[user/henk/code/inspircd.git] / src / dnsqueue.cpp
index 8ea0f3ec38f35ae2dc208260e13084500b71d646..71f227567540f33b8c0389ce318f7334d5217665 100644 (file)
@@ -2,7 +2,7 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
+ *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
  *                       E-mail:
  *                <brain@chatspike.net>
  *               <Craig@chatspike.net>
@@ -53,9 +53,11 @@ using namespace std;
 extern ServerConfig* Config;
 extern InspIRCd* ServerInstance;
 
+address_cache addrcache;
+
 class Lookup;
 
-Lookup* dnslist[65535];
+Lookup* dnslist[MAX_DESCRIPTORS];
 
 //enum LookupState { reverse, forward };
 
@@ -125,10 +127,16 @@ public:
                                                }
                                                if ((hostname != "") && (usr->registered != 7))
                                                {
-                                                       if (std::string(usr->ip) == ip)
+                                                       if (std::string((char*)inet_ntoa(usr->ip4)) == ip)
                                                        {
                                                                strlcpy(usr->host,hostname.c_str(),MAXBUF);
                                                                strlcpy(usr->dhost,hostname.c_str(),MAXBUF);
+                                                               address_cache::iterator address = addrcache.find(usr->ip4);
+                                                               if (address == addrcache.end())
+                                                               {
+                                                                       log(DEBUG,"Caching hostname %s -> %s",(char*)inet_ntoa(usr->ip4),hostname.c_str());
+                                                                       addrcache[usr->ip4] = new std::string(hostname);
+                                                               }
                                                        }
                                                        usr->dns_done = true;
                                                        return true;
@@ -201,6 +209,18 @@ bool lookup_dns(std::string nick)
        userrec* u = Find(nick);
        if (u)
        {
+               /* Check the cache */
+               address_cache::iterator address = addrcache.find(u->ip4);
+               if (address != addrcache.end())
+               {
+                       /* Theyre in the cache, dont waste a lookup */
+                       WriteServ(u->fd,"NOTICE Auth :*** Found your hostname (cached)");
+                       log(DEBUG,"Found cached host");
+                       strlcpy(u->host,address->second->c_str(),MAXBUF);
+                       strlcpy(u->dhost,address->second->c_str(),MAXBUF);
+                       u->dns_done = true;
+                       return true;
+               }
                /* If the user exists, create a new
                 * lookup object, and associate it
                 * with the user. The lookup object
@@ -225,7 +245,7 @@ bool lookup_dns(std::string nick)
 void dns_poll(int fdcheck)
 {
        /* Check the given file descriptor is in valid range */
-       if ((fdcheck < 0) || (fdcheck > 65535))
+       if ((fdcheck < 0) || (fdcheck > MAX_DESCRIPTORS))
                return;
 
        /* Try and find the file descriptor in our list of