avoid double saving of replacements nodes, removed replacement_cache, test (#1656)
avoid double saving of replacements nodes, deprecated replacement_cache, test
This commit is contained in:
parent
34ecb60c09
commit
3ef4109bf3
|
@ -162,9 +162,6 @@ public:
|
||||||
// bucket is not full.
|
// bucket is not full.
|
||||||
void add_node(udp::endpoint const& node);
|
void add_node(udp::endpoint const& node);
|
||||||
|
|
||||||
void replacement_cache(bucket_t& nodes) const
|
|
||||||
{ m_table.replacement_cache(nodes); }
|
|
||||||
|
|
||||||
int branch_factor() const { return m_settings.search_branching; }
|
int branch_factor() const { return m_settings.search_branching; }
|
||||||
|
|
||||||
void add_traversal_algorithm(traversal_algorithm* a)
|
void add_traversal_algorithm(traversal_algorithm* a)
|
||||||
|
|
|
@ -249,8 +249,6 @@ public:
|
||||||
|
|
||||||
int num_active_buckets() const { return int(m_buckets.size()); }
|
int num_active_buckets() const { return int(m_buckets.size()); }
|
||||||
|
|
||||||
void replacement_cache(bucket_t& nodes) const;
|
|
||||||
|
|
||||||
int bucket_limit(int bucket) const;
|
int bucket_limit(int bucket) const;
|
||||||
|
|
||||||
#if TORRENT_USE_INVARIANT_CHECKS
|
#if TORRENT_USE_INVARIANT_CHECKS
|
||||||
|
|
|
@ -547,13 +547,8 @@ namespace libtorrent { namespace dht
|
||||||
std::vector<udp::endpoint> save_nodes(node const& dht)
|
std::vector<udp::endpoint> save_nodes(node const& dht)
|
||||||
{
|
{
|
||||||
std::vector<udp::endpoint> ret;
|
std::vector<udp::endpoint> ret;
|
||||||
|
// TODO: refactor for more use of lambda
|
||||||
dht.m_table.for_each_node(&add_node_fun, &add_node_fun, &ret);
|
dht.m_table.for_each_node(&add_node_fun, &add_node_fun, &ret);
|
||||||
bucket_t cache;
|
|
||||||
dht.replacement_cache(cache);
|
|
||||||
for (auto const& b : cache)
|
|
||||||
{
|
|
||||||
ret.push_back(b.ep());
|
|
||||||
}
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -276,15 +276,6 @@ out:
|
||||||
return candidate;
|
return candidate;
|
||||||
}
|
}
|
||||||
|
|
||||||
void routing_table::replacement_cache(bucket_t& nodes) const
|
|
||||||
{
|
|
||||||
for (auto const& b : m_buckets)
|
|
||||||
{
|
|
||||||
std::copy(b.replacements.begin(), b.replacements.end()
|
|
||||||
, std::back_inserter(nodes));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
routing_table::table_t::iterator routing_table::find_bucket(node_id const& id)
|
routing_table::table_t::iterator routing_table::find_bucket(node_id const& id)
|
||||||
{
|
{
|
||||||
// TORRENT_ASSERT(id != m_id);
|
// TORRENT_ASSERT(id != m_id);
|
||||||
|
|
|
@ -2938,6 +2938,47 @@ TORRENT_TEST(routing_table_set_id)
|
||||||
print_state(std::cout, tbl);
|
print_state(std::cout, tbl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TORRENT_TEST(routing_table_for_each)
|
||||||
|
{
|
||||||
|
dht_settings sett = test_settings();
|
||||||
|
obs observer;
|
||||||
|
|
||||||
|
sett.extended_routing_table = false;
|
||||||
|
node_id id = to_hash("1234876923549721020394873245098347598635");
|
||||||
|
|
||||||
|
routing_table tbl(id, udp::v4(), 2, sett, &observer);
|
||||||
|
|
||||||
|
for (int i = 0; i < 32; ++i)
|
||||||
|
{
|
||||||
|
id[4] = i;
|
||||||
|
tbl.node_seen(id, rand_udp_ep(), 20 + (id[19] & 0xff));
|
||||||
|
}
|
||||||
|
|
||||||
|
int nodes;
|
||||||
|
int replacements;
|
||||||
|
std::tie(nodes, replacements, std::ignore) = tbl.size();
|
||||||
|
|
||||||
|
std::printf("num_active_buckets: %d\n", tbl.num_active_buckets());
|
||||||
|
std::printf("live nodes: %d\n", nodes);
|
||||||
|
std::printf("replacements: %d\n", replacements);
|
||||||
|
|
||||||
|
TEST_EQUAL(tbl.num_active_buckets(), 2);
|
||||||
|
TEST_EQUAL(nodes, 2);
|
||||||
|
TEST_EQUAL(replacements, 2);
|
||||||
|
|
||||||
|
print_state(std::cout, tbl);
|
||||||
|
|
||||||
|
std::vector<node_entry> v;
|
||||||
|
tbl.for_each_node(node_push_back, nop, &v);
|
||||||
|
TEST_EQUAL(v.size(), 2);
|
||||||
|
v.clear();
|
||||||
|
tbl.for_each_node(nop, node_push_back, &v);
|
||||||
|
TEST_EQUAL(v.size(), 2);
|
||||||
|
v.clear();
|
||||||
|
tbl.for_each_node(node_push_back, node_push_back, &v);
|
||||||
|
TEST_EQUAL(v.size(), 4);
|
||||||
|
}
|
||||||
|
|
||||||
TORRENT_TEST(node_set_id)
|
TORRENT_TEST(node_set_id)
|
||||||
{
|
{
|
||||||
dht_test_setup t(udp::endpoint(rand_v4(), 20));
|
dht_test_setup t(udp::endpoint(rand_v4(), 20));
|
||||||
|
|
Loading…
Reference in New Issue