]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/dns.cpp
m_dnsbl updates
[user/henk/code/inspircd.git] / src / dns.cpp
index 7be0f6874c16b9b43a1277ebaeea3e0c2e4f7cc3..8526d5be22bc4735db1a51c1220b49f77700403b 100644 (file)
@@ -2,7 +2,7 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
+ *  InspIRCd: (C) 2002-2010 InspIRCd Development Team
  * See: http://wiki.inspircd.org/Credits
  *
  * This program is free but copyrighted software; see
@@ -147,6 +147,17 @@ class RequestTimeout : public Timer
        }
 };
 
+CachedQuery::CachedQuery(const std::string &res, unsigned int ttl) : data(res)
+{
+       expires = ServerInstance->Time() + ttl;
+}
+
+int CachedQuery::CalcTTLRemaining()
+{
+       int n = expires - ServerInstance->Time();
+       return (n < 0 ? 0 : n);
+}
+
 /* Allocate the processing buffer */
 DNSRequest::DNSRequest(DNS* dns, int rid, const std::string &original) : dnsobj(dns)
 {
@@ -231,11 +242,9 @@ DNSRequest* DNS::AddQuery(DNSHeader *header, int &id, const char* original)
                return NULL;
 
        /* Create an id */
-       id = this->PRNG() & DNS::MAX_REQUEST_ID;
-
-       /* If this id is already 'in flight', pick another. */
-       while (requests[id])
-               id = this->PRNG() & DNS::MAX_REQUEST_ID;
+       do {
+               id = ServerInstance->GenRandomInt(DNS::MAX_REQUEST_ID);
+       } while (requests[id]);
 
        DNSRequest* req = new DNSRequest(this, id, original);
 
@@ -306,13 +315,14 @@ void DNS::Rehash()
        irc::sockets::aptosa(ServerInstance->Config->DNSServer, DNS::QUERY_PORT, myserver);
 
        /* Initialize mastersocket */
-       int s = irc::sockets::OpenTCPSocket(ServerInstance->Config->DNSServer, SOCK_DGRAM);
+       int s = socket(myserver.sa.sa_family, SOCK_DGRAM, 0);
        this->SetFd(s);
-       ServerInstance->SE->NonBlocking(this->GetFd());
 
        /* Have we got a socket and is it nonblocking? */
        if (this->GetFd() != -1)
        {
+               ServerInstance->SE->SetReuse(s);
+               ServerInstance->SE->NonBlocking(s);
                /* Bind the port - port 0 INADDR_ANY */
                if (!ServerInstance->BindSocket(this->GetFd(), portpass, "", false))
                {
@@ -1029,16 +1039,3 @@ void DNS::CleanResolvers(Module* module)
                }
        }
 }
-
-/** Generate pseudo-random number */
-unsigned long DNS::PRNG()
-{
-       unsigned long val = 0;
-       timeval n;
-       serverstats* s = ServerInstance->stats;
-       gettimeofday(&n,NULL);
-       val = (n.tv_usec ^ (getpid() ^ geteuid()) ^ ((this->currid++)) ^ s->statsAccept) + n.tv_sec;
-       val = val + (s->statsCollisions ^ s->statsDnsGood) - s->statsDnsBad;
-       val += (s->statsConnects ^ (unsigned long)s->statsSent ^ (unsigned long)s->statsRecv) - ServerInstance->ports.size();
-       return val;
-}