]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/dns.cpp
rename channel modes +it to distinguish them from commands
[user/henk/code/inspircd.git] / src / dns.cpp
index 7be0f6874c16b9b43a1277ebaeea3e0c2e4f7cc3..dee83d3acc3e8e44a7e984bd4b771b764de37b0b 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)
 {
@@ -306,13 +317,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))
                {
@@ -1034,11 +1046,9 @@ void DNS::CleanResolvers(Module* module)
 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();
+       val = (rand() ^ this->currid++ ^ s->statsAccept) + ServerInstance->Time_ns();
+       val += (s->statsCollisions ^ s->statsDnsGood) * s->statsDnsBad;
+       val += (s->statsConnects ^ (unsigned long)s->statsSent ^ (unsigned long)s->statsRecv);
        return val;
 }