summaryrefslogtreecommitdiff
path: root/src/dns.cpp
diff options
context:
space:
mode:
authordanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2010-02-09 02:22:27 +0000
committerdanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2010-02-09 02:22:27 +0000
commitaab7998583ca16590a32c7bdb80955a18b090700 (patch)
treea2b7f6d82a523e683347b7489ab77f0e940bdede /src/dns.cpp
parentdb790d9d1516c9c7cd48738340e5df1c8a2bebe3 (diff)
Add random number generation functions to InspIRCd class.
Default implementation uses libc random(), which can be better than rand(). If gnutls is loaded, gcrypt will be used to provide random numbers. git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@12404 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/dns.cpp')
-rw-r--r--src/dns.cpp19
1 files changed, 3 insertions, 16 deletions
diff --git a/src/dns.cpp b/src/dns.cpp
index dee83d3ac..8526d5be2 100644
--- a/src/dns.cpp
+++ b/src/dns.cpp
@@ -242,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);
@@ -1041,14 +1039,3 @@ void DNS::CleanResolvers(Module* module)
}
}
}
-
-/** Generate pseudo-random number */
-unsigned long DNS::PRNG()
-{
- unsigned long val = 0;
- serverstats* s = ServerInstance->stats;
- 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;
-}