back-port aldenml's fix to not save replacement nodes twice to 1.1 (#1661)

back-port aldenml's fix to not save replacement nodes twice to 1.1
This commit is contained in:
Arvid Norberg 2017-02-04 19:58:32 -05:00 committed by GitHub
parent 0a26ed8d1e
commit c00a25a645
5 changed files with 44 additions and 25 deletions

View File

@ -174,9 +174,6 @@ public:
// bucket is not full.
void add_node(udp::endpoint node);
void replacement_cache(bucket_t& nodes) const
{ m_table.replacement_cache(nodes); }
int branch_factor() const { return m_settings.search_branching; }
void add_traversal_algorithm(traversal_algorithm* a)

View File

@ -196,8 +196,6 @@ public:
int num_active_buckets() const { return m_buckets.size(); }
void replacement_cache(bucket_t& nodes) const;
#if defined TORRENT_DEBUG
// used for debug and monitoring purposes. This will print out
// the state of the routing table to the given stream

View File

@ -376,16 +376,6 @@ namespace libtorrent { namespace dht
{
entry nodes(entry::list_t);
m_dht.m_table.for_each_node(&add_node_fun, &add_node_fun, &nodes);
bucket_t cache;
m_dht.replacement_cache(cache);
for (bucket_t::iterator i(cache.begin())
, end(cache.end()); i != end; ++i)
{
std::string node;
std::back_insert_iterator<std::string> out(node);
write_endpoint(i->ep(), out);
nodes.list().push_back(entry(node));
}
if (!nodes.list().empty())
ret["nodes"] = nodes;
}

View File

@ -431,16 +431,6 @@ out:
return candidate;
}
void routing_table::replacement_cache(bucket_t& nodes) const
{
for (table_t::const_iterator i = m_buckets.begin()
, end(m_buckets.end()); i != end; ++i)
{
std::copy(i->replacements.begin(), i->replacements.end()
, std::back_inserter(nodes));
}
}
routing_table::table_t::iterator routing_table::find_bucket(node_id const& id)
{
// TORRENT_ASSERT(id != m_id);

View File

@ -2647,5 +2647,49 @@ TORRENT_TEST(dht_verify_node_address)
TEST_EQUAL(table.size().get<0>(), 1);
TEST_EQUAL(nodes.size(), 1);
}
TORRENT_TEST(routing_table_for_each)
{
dht_settings sett = test_settings();
obs observer;
sett.extended_routing_table = false;
node_id id = to_hash("1234876923549721020394873245098347598635");
dht::routing_table tbl(id, 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;
boost::tie(nodes, replacements, boost::tuples::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);
#if defined TORRENT_DEBUG
tbl.print_state(std::cout);
#endif
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);
}
#endif