extend DHT unit test and fix bug in routing_table bucket splitting
This commit is contained in:
@@ -62,6 +62,11 @@ address rand_v4()
|
||||
return address_v4((rand() << 16 | rand()) & 0xffffffff);
|
||||
}
|
||||
|
||||
udp::endpoint rand_ep()
|
||||
{
|
||||
return udp::endpoint(rand_v4(), rand());
|
||||
}
|
||||
|
||||
sha1_hash generate_next()
|
||||
{
|
||||
sha1_hash ret;
|
||||
@@ -69,6 +74,14 @@ sha1_hash generate_next()
|
||||
return ret;
|
||||
}
|
||||
|
||||
node_id random_id()
|
||||
{
|
||||
node_id ret;
|
||||
for (int i = 0; i < 20; ++i)
|
||||
ret[i] = rand();
|
||||
return ret;
|
||||
}
|
||||
|
||||
boost::array<char, 64> generate_key()
|
||||
{
|
||||
boost::array<char, 64> ret;
|
||||
@@ -591,6 +604,39 @@ int test_main()
|
||||
}
|
||||
#endif // TORRENT_USE_OPENSSL
|
||||
|
||||
// test routing table
|
||||
|
||||
{
|
||||
sett.extended_routing_table = false;
|
||||
routing_table tbl(random_id(), 8, sett);
|
||||
|
||||
// insert 256 nodes evenly distributed across the ID space.
|
||||
// we expect to fill the top 5 buckets
|
||||
for (int i = 0; i < 256; ++i)
|
||||
{
|
||||
node_id id = random_id();
|
||||
id[0] = i;
|
||||
tbl.node_seen(id, rand_ep(), 50);
|
||||
}
|
||||
TEST_EQUAL(tbl.num_active_buckets(), 6);
|
||||
|
||||
tbl.print_state(std::cerr);
|
||||
}
|
||||
|
||||
{
|
||||
sett.extended_routing_table = true;
|
||||
routing_table tbl(random_id(), 8, sett);
|
||||
for (int i = 0; i < 256; ++i)
|
||||
{
|
||||
node_id id = random_id();
|
||||
id[0] = i;
|
||||
tbl.node_seen(id, rand_ep(), 50);
|
||||
}
|
||||
TEST_EQUAL(tbl.num_active_buckets(), 6);
|
||||
|
||||
tbl.print_state(std::cerr);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user