fix off-by-one bug in DHT node-ID calculation

This commit is contained in:
Arvid Norberg 2012-02-16 03:51:39 +00:00
parent 47781bf2c5
commit 35ea214124
2 changed files with 3 additions and 3 deletions

View File

@ -95,7 +95,7 @@ Example code code for calculating a valid node ID::
int mod_shift = 6 * 4 / num_octets; // 6 or 3, depending on IPv4 and IPv6
while (num_octets)
{
seed = (uint64_t(seed) * ip[num_octets]) & (modulus-1);
seed = (uint64_t(seed) * ip[num_octets-1]) & (modulus-1);
modulus <<= mod_shift;
--num_octets;
}
@ -119,7 +119,7 @@ Example code to verify a node ID::
int mod_shift = 6 * 4 / num_octets; // 6 or 3, depending on IPv4 and IPv6
while (num_octets)
{
seed = (uint64_t(seed) * ip[num_octets]) & (modulus-1);
seed = (uint64_t(seed) * ip[num_octets-1]) & (modulus-1);
modulus <<= mod_shift;
--num_octets;
}

View File

@ -127,7 +127,7 @@ node_id generate_id_impl(address const& ip, boost::uint32_t r)
while (num_octets)
{
seed *= p[num_octets];
seed *= p[num_octets-1];
seed &= (modulus-1);
modulus <<= mod_shift;
--num_octets;