]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/dns.cpp
Register channel mode Z when enabled
[user/henk/code/inspircd.git] / src / dns.cpp
index 80909c0bb4b8ef5eee6e97d424275174e3d69624..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);
 
@@ -1030,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;
-}