fix off-by-one bug in DHT node-ID calculation
This commit is contained in:
parent
47781bf2c5
commit
35ea214124
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue