Kea  1.9.9-git
qid_gen.cc
Go to the documentation of this file.
1 // Copyright (C) 2011-2015 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 // qid_gen defines a generator for query id's
8 //
9 // We probably want to merge this with the weighted random in the nsas
10 // (and other parts where we need randomness, perhaps another thing
11 // for a general libutil?)
12 
13 #include <config.h>
14 
15 #include <util/random/qid_gen.h>
16 
17 #include <sys/time.h>
18 
19 namespace isc {
20 namespace util {
21 namespace random {
22 
24 
27  return (qid_generator_instance);
28 }
29 
30 QidGenerator::QidGenerator() : dist_(0, 65535),
31  vgen_(generator_, dist_)
32 {
33  seed();
34 }
35 
36 void
38  struct timeval tv;
39  gettimeofday(&tv, 0);
40  generator_.seed((tv.tv_sec * 1000000) + tv.tv_usec);
41 }
42 
43 uint16_t
45  return (vgen_());
46 }
47 
48 
49 } // namespace random
50 } // namespace util
51 } // namespace isc
QidGenerator qid_generator_instance
Definition: qid_gen.cc:23
static QidGenerator & getInstance()
Returns the singleton instance of the QidGenerator.
Definition: qid_gen.cc:26
QidGenerator()
Default constructor.
Definition: qid_gen.cc:30
uint16_t generateQid()
Generate a Qid.
Definition: qid_gen.cc:44
void seed()
Seeds the QidGenerator (based on the current time)
Definition: qid_gen.cc:37
Defines the logger used by the top-level component of kea-dhcp-ddns.
This class generates Qids for outgoing queries.
Definition: qid_gen.h:33