summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrancis Dupont <fdupont@isc.org>2020-07-24 15:35:38 +0200
committerTomek Mrugalski <tomek@isc.org>2020-07-27 11:50:58 +0200
commit7b1b86a506c31a7bab0504d9d6423fc0f3d24da2 (patch)
treeace7a1188c851241248cced8edc851391fbaf0d6
parent[#1330] Moved closeSockets (diff)
downloadkea-7b1b86a506c31a7bab0504d9d6423fc0f3d24da2.tar.xz
kea-7b1b86a506c31a7bab0504d9d6423fc0f3d24da2.zip
[#1283] Restored (fixed) patch
-rw-r--r--m4macros/ax_boost_for_kea.m42
-rw-r--r--src/lib/asiolink/io_address.cc14
-rw-r--r--src/lib/asiolink/io_address.h11
3 files changed, 25 insertions, 2 deletions
diff --git a/m4macros/ax_boost_for_kea.m4 b/m4macros/ax_boost_for_kea.m4
index 3b2ac8bd1d..ebb6a61dbf 100644
--- a/m4macros/ax_boost_for_kea.m4
+++ b/m4macros/ax_boost_for_kea.m4
@@ -74,7 +74,7 @@ if test "${boost_include_path}" ; then
BOOST_INCLUDES="-isystem ${boost_include_path}"
CPPFLAGS="$CPPFLAGS $BOOST_INCLUDES"
fi
-AC_CHECK_HEADERS([boost/shared_ptr.hpp boost/foreach.hpp boost/interprocess/sync/interprocess_upgradable_mutex.hpp boost/date_time/posix_time/posix_time_types.hpp boost/bind.hpp boost/function.hpp boost/asio.hpp boost/asio/ip/address.hpp boost/asio/signal_set.hpp boost/system/error_code.hpp boost/atomic.hpp boost/circular_buffer.hpp],,
+AC_CHECK_HEADERS([boost/shared_ptr.hpp boost/foreach.hpp boost/interprocess/sync/interprocess_upgradable_mutex.hpp boost/date_time/posix_time/posix_time_types.hpp boost/bind.hpp boost/function.hpp boost/asio.hpp boost/asio/ip/address.hpp boost/asio/signal_set.hpp boost/system/error_code.hpp boost/atomic.hpp boost/circular_buffer.hpp boost/functional/hash.hpp],,
AC_MSG_ERROR([Missing required header files.]))
AC_CHECK_HEADERS(boost/asio/coroutine.hpp,,AC_MSG_RESULT(not found, using built-in header.))
diff --git a/src/lib/asiolink/io_address.cc b/src/lib/asiolink/io_address.cc
index dae8074066..97a73fd2dd 100644
--- a/src/lib/asiolink/io_address.cc
+++ b/src/lib/asiolink/io_address.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2010-2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2010-2020 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
@@ -11,6 +11,8 @@
#include <exceptions/exceptions.h>
#include <boost/static_assert.hpp>
+// moved to container_hash on recent boost versions
+#include <boost/functional/hash.hpp>
#include <unistd.h> // for some IPC/network system calls
#include <stdint.h>
@@ -172,6 +174,16 @@ IOAddress::increase(const IOAddress& addr) {
return (IOAddress::fromBytes(addr.getFamily(), &packed[0]));
}
+size_t
+hash_value(const IOAddress& address) {
+ if (address.isV4()) {
+ boost::hash<uint32_t> hasher;
+ return (hasher(address.toUint32()));
+ } else {
+ boost::hash<std::vector<uint8_t> > hasher;
+ return (hasher(address.toBytes()));
+ }
+}
} // namespace asiolink
} // namespace isc
diff --git a/src/lib/asiolink/io_address.h b/src/lib/asiolink/io_address.h
index bb2ce692d8..fb1d67b3ea 100644
--- a/src/lib/asiolink/io_address.h
+++ b/src/lib/asiolink/io_address.h
@@ -302,6 +302,17 @@ private:
std::ostream&
operator<<(std::ostream& os, const IOAddress& address);
+/// \brief Hash the IOAddress.
+///
+/// This method allows boost multi-index hashed indexes on IOAddresses.
+/// It follows the requirement with equality: if two addresses are equal
+/// their hashes are equal, if two addresses are not equal their hashes
+/// are almost surely not equal.
+///
+/// \param address A \c IOAddress to hash.
+/// \return The hash of the IOAddress.
+size_t hash_value(const IOAddress& address);
+
} // namespace asiolink
} // namespace isc
#endif // IO_ADDRESS_H