Kea 1.5.0
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
19namespace isc {
20namespace util {
21namespace random {
22
24
28}
29
30QidGenerator::QidGenerator() : dist_(0, 65535),
31 vgen_(generator_, dist_)
32{
33 seed();
34}
35
36void
38 struct timeval tv;
39 gettimeofday(&tv, 0);
40 generator_.seed((tv.tv_sec * 1000000) + tv.tv_usec);
41}
42
43uint16_t
45 return (vgen_());
46}
47
48
49} // namespace random
50} // namespace util
51} // namespace isc
This class generates Qids for outgoing queries.
Definition: qid_gen.h:33
static QidGenerator & getInstance()
Returns the singleton instance of the QidGenerator.
Definition: qid_gen.cc:26
uint16_t generateQid()
Generate a Qid.
Definition: qid_gen.cc:44
QidGenerator()
Default constructor.
Definition: qid_gen.cc:30
void seed()
Seeds the QidGenerator (based on the current time)
Definition: qid_gen.cc:37
QidGenerator qid_generator_instance
Definition: qid_gen.cc:23
Defines the logger used by the top-level component of kea-dhcp-ddns.