]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1957] Moved Qid and random
authorFrancis Dupont <fdupont@isc.org>
Sat, 3 Jul 2021 15:12:54 +0000 (17:12 +0200)
committerFrancis Dupont <fdupont@isc.org>
Tue, 6 Jul 2021 12:21:57 +0000 (14:21 +0200)
15 files changed:
src/bin/d2/nc_trans.cc
src/bin/perfdhcp/Makefile.am
src/bin/perfdhcp/random_number_generator.h [moved from src/lib/util/random/random_number_generator.h with 98% similarity]
src/bin/perfdhcp/test_control.h
src/bin/perfdhcp/tests/Makefile.am
src/bin/perfdhcp/tests/random_number_generator_unittest.cc [moved from src/lib/util/tests/random_number_generator_unittest.cc with 97% similarity]
src/lib/asiodns/io_fetch.cc
src/lib/dns/Makefile.am
src/lib/dns/qid_gen.cc [moved from src/lib/util/random/qid_gen.cc with 57% similarity]
src/lib/dns/qid_gen.h [moved from src/lib/util/random/qid_gen.h with 56% similarity]
src/lib/dns/tests/Makefile.am
src/lib/dns/tests/qid_gen_unittest.cc [moved from src/lib/util/tests/qid_gen_unittest.cc with 88% similarity]
src/lib/util/Makefile.am
src/lib/util/random/.gitignore [deleted file]
src/lib/util/tests/Makefile.am

index d10b5c313c76018ff9a4d8a1cce0deef0192a296..86996859473971d719c1c04777c5d0e3ad258a71 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2013-2020 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2021 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -8,13 +8,12 @@
 
 #include <d2/d2_log.h>
 #include <d2/nc_trans.h>
+#include <dns/qid_gen.h>
 #include <dns/rdata.h>
-#include <util/random/qid_gen.h>
 
 #include <sstream>
 
 using namespace isc::util;
-using namespace isc::util::random;
 
 namespace isc {
 namespace d2 {
@@ -324,7 +323,7 @@ NameChangeTransaction::prepNewRequest(DdnsDomainPtr domain) {
         D2UpdateMessagePtr request(new D2UpdateMessage(D2UpdateMessage::
                                                        OUTBOUND));
         // Set the query id
-        request->setId(QidGenerator::getInstance().generateQid());
+        request->setId(dns::QidGenerator::getInstance().generateQid());
         // Construct the Zone Section.
         dns::Name zone_name(domain->getName());
         request->setZone(zone_name, dns::RRClass::IN());
index 276f86b9b42e8176518ff26ba6d70b8ab7f1b443..f07e84b9de50a92c470e706a8c75c615196af35c 100644 (file)
@@ -25,6 +25,7 @@ libperfdhcp_la_SOURCES += pkt_transform.cc pkt_transform.h
 libperfdhcp_la_SOURCES += rate_control.cc rate_control.h
 libperfdhcp_la_SOURCES += stats_mgr.cc stats_mgr.h
 libperfdhcp_la_SOURCES += test_control.cc test_control.h
+libperfdhcp_la_SOURCES += random_number_generator.h
 libperfdhcp_la_SOURCES += receiver.cc receiver.h
 libperfdhcp_la_SOURCES += perf_socket.cc perf_socket.h
 libperfdhcp_la_SOURCES += abstract_scen.h
similarity index 98%
rename from src/lib/util/random/random_number_generator.h
rename to src/bin/perfdhcp/random_number_generator.h
index 5f50ee7ccffb28ebe8fb0def19709310c64158f7..ce5a3863640011b6142def61f4b8ddd6a4b3dff0 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2010-2020 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2010-2021 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -23,8 +23,7 @@
 /// PLEASE DO NOT USE THIS IN CRYPTOGRAPHICALLY SENSITIVE CODE.
 
 namespace isc {
-namespace util {
-namespace random {
+namespace perfdhcp {
 
 class InvalidLimits : public isc::BadValue {
 public:
@@ -197,8 +196,7 @@ private:
     size_t min_;                                ///< The minimum integer that will be generated
 };
 
-}   // namespace random
-}   // namespace util
+}   // namespace perfdhcp
 }   // namespace isc
 
 #endif//NSAS_RANDOM_NUMBER_GENERATOR_H
index a3401c8dbcc405ec9592c0576991de4955b93978..9524bc7e5fc5b7c6f06b19794512a8b94ec7e21a 100644 (file)
 #include <perfdhcp/receiver.h>
 #include <perfdhcp/command_options.h>
 #include <perfdhcp/perf_socket.h>
+#include <perfdhcp/random_number_generator.h>
 
 #include <dhcp/iface_mgr.h>
 #include <dhcp/dhcp4.h>
 #include <dhcp/dhcp6.h>
 #include <dhcp/pkt4.h>
 #include <dhcp/pkt6.h>
-#include <util/random/random_number_generator.h>
 
 #include <boost/noncopyable.hpp>
 #include <boost/shared_ptr.hpp>
@@ -348,7 +348,7 @@ public:
     // what's followed in other classes.
 protected:
     /// Generate uniformly distributed integers in range of [min, max]
-    isc::util::random::UniformRandomIntegerGenerator number_generator_;
+    UniformRandomIntegerGenerator number_generator_;
 
     /// \brief Creates DHCPREQUEST from a DHCPACK message.
     ///
index 5f79a9eb2c24f207bde3180502fe095b6d7fd63b..72202a8c4f80b1db47675487bce2be54bf6003c1 100644 (file)
@@ -36,6 +36,7 @@ run_unittests_SOURCES += perf_socket_unittest.cc
 run_unittests_SOURCES += basic_scen_unittest.cc
 run_unittests_SOURCES += avalanche_scen_unittest.cc
 run_unittests_SOURCES += command_options_helper.h
+run_unittests_SOURCES += random_number_generator_unittest.cc
 
 run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
 run_unittests_LDFLAGS  = $(AM_LDFLAGS) $(CRYPTO_LDFLAGS) $(GTEST_LDFLAGS)
similarity index 97%
rename from src/lib/util/tests/random_number_generator_unittest.cc
rename to src/bin/perfdhcp/tests/random_number_generator_unittest.cc
index 5710c95f05b595d9fbff03c362bcd9f5834219fc..7ac8b3863c9286771371c077d18ab62f00b71eb5 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2010-2015 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2010-2021 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -6,18 +6,15 @@
 
 #include <config.h>
 
-#include <util/random/random_number_generator.h>
+#include "../random_number_generator.h"
 
 #include <gtest/gtest.h>
 #include <boost/shared_ptr.hpp>
 
 #include <iostream>
 
-
-namespace isc {
-namespace util {
-namespace random {
-
+using namespace isc;
+using namespace isc::perfdhcp;  
 using namespace std;
 
 /// \brief Test Fixture Class for uniform random number generator
@@ -297,7 +294,3 @@ TEST_F(WeightedRandomIntegerGeneratorTest, ResetProbabilities) {
     ASSERT_TRUE(fabs(c1 - mu1) < 4*sigma1);
     ASSERT_TRUE(fabs(c2 - mu2) < 4*sigma2);
 }
-
-} // namespace random
-} // namespace util
-} // namespace isc
index 5ad10dfdb736e1e38284437d85593d2cd8db521c..7cad6b1ce12cd1e202fb136c6f421af5134bdd50 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2011-2020 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2011-2021 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -18,9 +18,9 @@
 #include <asiodns/logger.h>
 #include <dns/messagerenderer.h>
 #include <dns/opcode.h>
+#include <dns/qid_gen.h>
 #include <dns/rcode.h>
 #include <util/buffer.h>
-#include <util/random/qid_gen.h>
 
 #include <boost/scoped_ptr.hpp>
 #include <boost/date_time/posix_time/posix_time_types.hpp>
@@ -35,7 +35,6 @@ using namespace boost::asio;
 using namespace isc::asiolink;
 using namespace isc::dns;
 using namespace isc::util;
-using namespace isc::util::random;
 using namespace isc::log;
 using namespace std;
 
index b6dd3bbf755ceb60121d61a6dea89c8b61c8f520..0ce0ef53f07b8f9a249c1fd7388d03733e7794c5 100644 (file)
@@ -133,6 +133,7 @@ libkea_dns___la_SOURCES += rrset.h rrset.cc
 libkea_dns___la_SOURCES += rrttl.h rrttl.cc
 libkea_dns___la_SOURCES += rrtype.cc
 libkea_dns___la_SOURCES += rrcollator.h rrcollator.cc
+libkea_dns___la_SOURCES += qid_gen.h qid_gen.cc
 libkea_dns___la_SOURCES += question.h question.cc
 libkea_dns___la_SOURCES += serial.h serial.cc
 libkea_dns___la_SOURCES += tsig.h tsig.cc
@@ -197,6 +198,7 @@ libdns___include_HEADERS = \
        name.h \
        nsec3hash.h \
        opcode.h \
+       qid_gen.h \
        question.h \
        rcode.h \
        rdata.h \
similarity index 57%
rename from src/lib/util/random/qid_gen.cc
rename to src/lib/dns/qid_gen.cc
index a635c1818ae11d50ac5406d305df4e07f167624b..dad2b6ff5ade717797606969cf6b07381f11e4c3 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2011-2015 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2011-2021 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
 
 #include <config.h>
 
-#include <util/random/qid_gen.h>
-
-#include <sys/time.h>
+#include <cryptolink/crypto_rng.h>
+#include <dns/qid_gen.h>
+#include <cstring>
 
 namespace isc {
-namespace util {
-namespace random {
+namespace dns {
 
 QidGenerator qid_generator_instance;
 
@@ -27,25 +26,17 @@ QidGenerator::getInstance() {
     return (qid_generator_instance);
 }
 
-QidGenerator::QidGenerator() : dist_(0, 65535),
-                               vgen_(generator_, dist_)
+QidGenerator::QidGenerator()
 {
-    seed();
-}
-
-void
-QidGenerator::seed() {
-    struct timeval tv;
-    gettimeofday(&tv, 0);
-    generator_.seed((tv.tv_sec * 1000000) + tv.tv_usec);
 }
 
 uint16_t
 QidGenerator::generateQid() {
-    return (vgen_());
+    uint16_t val;
+    std::vector<uint8_t> rnd = isc::cryptolink::random(sizeof(uint16_t));
+    memmove(&val, &rnd[0], sizeof(uint16_t));
+    return (val);
 }
 
-
-} // namespace random
-} // namespace util
+} // namespace dns
 } // namespace isc
similarity index 56%
rename from src/lib/util/random/qid_gen.h
rename to src/lib/dns/qid_gen.h
index ad65b39a28f1435fa3e3601dda32d60da38d0a90..732dd9a3bc38623b8593015f8d34a96bc3def859 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2011-2015 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2011-2021 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
 #ifndef QID_GEN_H
 #define QID_GEN_H
 
-#include <boost/random/mersenne_twister.hpp>
-#include <boost/random/uniform_int.hpp>
-#include <boost/random/variate_generator.hpp>
-
+#include <cryptolink/crypto_rng.h>
 #include <stdint.h>
 
 namespace isc {
-namespace util {
-namespace random {
+namespace dns {
 
 /// This class generates Qids for outgoing queries
 ///
@@ -50,32 +46,9 @@ public:
     ///
     /// \return A random Qid
     uint16_t generateQid();
-
-    /// \brief Seeds the QidGenerator (based on the current time)
-    ///
-    /// This is automatically called by the constructor
-    void seed();
-
-private:
-    // "Mersenne Twister: A 623-dimensionally equidistributed
-    // uniform pseudo-random number generator", Makoto Matsumoto and
-    // Takuji Nishimura, ACM Transactions on Modeling and Computer
-    // Simulation: Special Issue on Uniform Random Number Generation,
-    // Vol. 8, No. 1, January 1998, pp. 3-30.
-    //
-    // mt19937 is an implementation of one of the pseudo random
-    // generators described in this paper.
-    boost::mt19937 generator_;
-
-    // For qid's we want a uniform distribution
-    boost::uniform_int<> dist_;
-
-    boost::variate_generator<boost::mt19937&, boost::uniform_int<> > vgen_;
 };
 
-
-} // namespace random
-} // namespace util
+} // namespace dns
 } // namespace isc
 
 #endif // QID_GEN_H
index 80ff1fb58231059c9848322a5c69db409e70e8a8..9b2e0fadc3656ec2d1904432f7e650127831cdb5 100644 (file)
@@ -68,6 +68,7 @@ run_unittests_SOURCES += rdata_hinfo_unittest.cc
 run_unittests_SOURCES += rdata_caa_unittest.cc
 run_unittests_SOURCES += rdata_tkey_unittest.cc
 run_unittests_SOURCES += rrset_unittest.cc
+run_unittests_SOURCES += qid_gen_unittest.cc
 run_unittests_SOURCES += question_unittest.cc
 run_unittests_SOURCES += rrparamregistry_unittest.cc
 run_unittests_SOURCES += masterload_unittest.cc
similarity index 88%
rename from src/lib/util/tests/qid_gen_unittest.cc
rename to src/lib/dns/tests/qid_gen_unittest.cc
index 889a98d9de0b9bbb2d34d1798b965c241b8edb18..20a2dfa13118ec7dfed6a8afe442582d17099667 100644 (file)
@@ -11,9 +11,9 @@
 
 #include <gtest/gtest.h>
 
-#include <util/random/qid_gen.h>
+#include <dns/qid_gen.h>
 
-using namespace isc::util::random;
+using namespace isc::dns;
 
 // Tests the operation of the Qid generator
 
@@ -26,7 +26,7 @@ TEST(QidGenerator, singleton) {
 }
 
 TEST(QidGenerator, generate) {
-    // We'll assume that boost's generator is 'good enough', and won't
+    // We'll assume that cryptolink's generator is 'good enough', and won't
     // do full statistical checking here. Let's just call it the xkcd
     // test (http://xkcd.com/221/), and check if three consecutive
     // generates are not all the same.
index e18089a4ad2b25f78ca7810ab639bc5ea9c2e66a..bf4c177a055af5d097470fbf39f1d05061610b14 100644 (file)
@@ -41,8 +41,6 @@ libkea_util_la_SOURCES += encode/base_n.cc encode/hex.h
 libkea_util_la_SOURCES += encode/binary_from_base32hex.h
 libkea_util_la_SOURCES += encode/binary_from_base16.h
 libkea_util_la_SOURCES += encode/utf8.cc encode/utf8.h
-libkea_util_la_SOURCES += random/qid_gen.h random/qid_gen.cc
-libkea_util_la_SOURCES += random/random_number_generator.h
 
 libkea_util_la_LIBADD = $(top_builddir)/src/lib/exceptions/libkea-exceptions.la
 
@@ -100,8 +98,3 @@ libkea_util_io_include_HEADERS = \
        io/fd_share.h \
        io/pktinfo_utilities.h \
        io/sockaddr_util.h
-
-libkea_util_random_includedir = $(pkgincludedir)/util/random
-libkea_util_random_include_HEADERS = \
-       random/qid_gen.h \
-       random/random_number_generator.h
diff --git a/src/lib/util/random/.gitignore b/src/lib/util/random/.gitignore
deleted file mode 100644 (file)
index c83c013..0000000
+++ /dev/null
@@ -1 +0,0 @@
-/.dirstamp
index d8354e967bb70f426eef03dfd2794606b91e8a57..3ddb57616df209f7da16da361d4b4f45f8ec7a8a 100644 (file)
@@ -44,8 +44,6 @@ run_unittests_SOURCES += memory_segment_common_unittest.cc
 run_unittests_SOURCES += multi_threading_mgr_unittest.cc
 run_unittests_SOURCES += optional_unittest.cc
 run_unittests_SOURCES += pid_file_unittest.cc
-run_unittests_SOURCES += qid_gen_unittest.cc
-run_unittests_SOURCES += random_number_generator_unittest.cc
 run_unittests_SOURCES += staged_value_unittest.cc
 run_unittests_SOURCES += state_model_unittest.cc
 run_unittests_SOURCES += strutil_unittest.cc