fix test_dht to take into account the slightly more relaxed semantics of routing_table::find_node

This commit is contained in:
Arvid Norberg
2013-10-22 05:20:00 +00:00
parent a627a4e156
commit 1a2226b8f0
4 changed files with 68 additions and 49 deletions

View File

@@ -181,5 +181,14 @@ bool matching_prefix(node_entry const& n, int mask, int prefix, int bucket_index
return (id[0] & mask) == prefix;
}
node_id generate_prefix_mask(int bits)
{
node_id mask(0);
int b = 0;
for (; b < bits - 7; b += 8) mask[b/8] |= 0xff;
mask[b/8] |= 0xff << (8 - (bits&7));
return mask;
}
} } // namespace libtorrent::dht

View File

@@ -290,8 +290,7 @@ bool routing_table::need_refresh(node_id& target) const
// generate a random node_id within the given bucket
target = generate_random_id();
int num_bits = std::distance(m_buckets.begin(), i) + 1;
node_id mask(0);
for (int i = 0; i < num_bits; ++i) mask[i/8] |= 0x80 >> (i&7);
node_id mask = generate_prefix_mask(num_bits);
// target = (target & ~mask) | (root & mask)
node_id root = m_id;