-// 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
#include <exceptions/exceptions.h>
#include <boost/static_assert.hpp>
+#include <boost/container_hash/hash.hpp>
#include <unistd.h> // for some IPC/network system calls
#include <stdint.h>
return (IOAddress::fromBytes(addr.getFamily(), &packed[0]));
}
+std::size_t
+hash_value(const IOAddress& address) {
+ boost::hash<std::vector<uint8_t> > hasher;
+ return (hasher(address.toBytes()));
+}
} // namespace asiolink
} // namespace isc
std::ostream&
operator<<(std::ostream& os, const IOAddress& address);
+/// \brief Hash the IOAddress.
+///
+/// This method allows boost multi-index hashed indexes on IOAddresses.
+///
+/// \param address A \c IOAddress to hash.
+/// \return The hash of the IOAddress.
+std::size_t hash_value(const IOAddress& address);
+
} // namespace asiolink
} // namespace isc
#endif // IO_ADDRESS_H
-// Copyright (C) 2011-2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2011-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
EXPECT_EQ(IOAddress("::1"), IOAddress::increase(any6));
EXPECT_EQ(IOAddress("::"), IOAddress::increase(the_last_one));
}
+
+// Test verifies the hash function is sane.
+TEST(IOAddressTest, hash) {
+ size_t hash1 = hash_value(IOAddress("192.0.2.1"));
+ size_t hash2 = hash_value(IOAddress("192.0.2.2"));
+ EXPECT_NE(hash1, hash2);
+
+ hash1 = hash_value(IOAddress("2001:db8::12"));
+ hash2 = hash_value(IOAddress("2001:db8::1234"));
+ EXPECT_NE(hash1, hash2);
+}
>,
// Fourth index allows for access by server identifier specified for the
// network.
- boost::multi_index::ordered_non_unique<
+ boost::multi_index::hashed_non_unique<
boost::multi_index::tag<SharedNetworkServerIdIndexTag>,
boost::multi_index::const_mem_fun<Network4, asiolink::IOAddress,
&Network4::getServerId>
#include <dhcpsrv/pool.h>
#include <dhcpsrv/subnet_id.h>
#include <dhcpsrv/triplet.h>
-#include <boost/multi_index/mem_fun.hpp>
+#include <boost/multi_index/hashed_index.hpp>
#include <boost/multi_index/indexed_by.hpp>
+#include <boost/multi_index/mem_fun.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/random_access_index.hpp>
#include <boost/multi_index_container.hpp>
>,
// Fourth index allows for searching using an output from getServerId.
- boost::multi_index::ordered_non_unique<
+ boost::multi_index::hashed_non_unique<
boost::multi_index::tag<SubnetServerIdIndexTag>,
boost::multi_index::const_mem_fun<Network4, asiolink::IOAddress,
&Network4::getServerId>