X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fdnsqueue.cpp;h=71f227567540f33b8c0389ce318f7334d5217665;hb=5a17e1b8bd690a573c91e5c69f2c150fe0516f7a;hp=2d123a4198b7f5034a353f21273c3c4becf17bbf;hpb=d7522cd852f6d1821b00774441762f73403341fe;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/dnsqueue.cpp b/src/dnsqueue.cpp index 2d123a419..71f227567 100644 --- a/src/dnsqueue.cpp +++ b/src/dnsqueue.cpp @@ -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: * * @@ -19,7 +19,6 @@ using namespace std; #include "inspircd_config.h" #include "inspircd.h" #include "inspircd_io.h" -#include "inspircd_util.h" #include #include #include @@ -43,7 +42,6 @@ using namespace std; #include #include #include -#include #include #include #include @@ -52,14 +50,14 @@ using namespace std; #include "hashcomp.h" #include "socketengine.h" -extern SocketEngine* SE; -typedef nspace::hash_map, irc::StrHashComp> user_hash; -extern user_hash clientlist; -extern char DNSServer[MAXBUF]; +extern ServerConfig* Config; +extern InspIRCd* ServerInstance; + +address_cache addrcache; class Lookup; -Lookup* dnslist[65535]; +Lookup* dnslist[MAX_DESCRIPTORS]; //enum LookupState { reverse, forward }; @@ -72,12 +70,12 @@ private: public: Lookup() { - strcpy(u,""); + *u = 0; } void Reset() { - strcpy(u,""); + *u = 0; } ~Lookup() @@ -90,7 +88,7 @@ public: userrec* usr = Find(nick); if (usr) { - resolver1.SetNS(std::string(DNSServer)); + resolver1.SetNS(std::string(Config->DNSServer)); if (!resolver1.ReverseLookup(std::string(usr->host))) { return false; @@ -98,9 +96,11 @@ public: strlcpy(u,nick.c_str(),NICKMAX); /* ASSOCIATE WITH DNS LOOKUP LIST */ - dnslist[resolver1.GetFD()] = this; - - return true; + if (resolver1.GetFD() != -1) + { + dnslist[resolver1.GetFD()] = this; + return true; + } } return false; } @@ -127,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; @@ -157,7 +163,11 @@ public: { usr = Find(u); if ((usr) && (usr->dns_done)) + { + if (resolver1.GetFD() != -1) + dnslist[resolver1.GetFD()] = NULL; return true; + } if (resolver1.GetFD() != -1) { dnslist[resolver1.GetFD()] = NULL; @@ -173,7 +183,7 @@ public: if (hostname != "") { resolver2.ForwardLookup(hostname); - if (resolver2.GetFD()) + if (resolver2.GetFD() != -1) dnslist[resolver2.GetFD()] = this; } } @@ -199,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 @@ -223,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 @@ -258,6 +280,11 @@ void dns_poll(int fdcheck) */ return; } - log(DEBUG,"DNS: Received an event for an invalid descriptor!"); + /* This FD doesnt belong here, lets be rid of it, + * just to be safe so we dont get any more events + * about it. + */ + if (ServerInstance && ServerInstance->SE) + ServerInstance->SE->DelFd(fdcheck); }