diff --git a/include/libtorrent/kademlia/node.hpp b/include/libtorrent/kademlia/node.hpp index c55503e98..831d093aa 100644 --- a/include/libtorrent/kademlia/node.hpp +++ b/include/libtorrent/kademlia/node.hpp @@ -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) diff --git a/include/libtorrent/kademlia/routing_table.hpp b/include/libtorrent/kademlia/routing_table.hpp index 24d8b0271..03a6b962c 100644 --- a/include/libtorrent/kademlia/routing_table.hpp +++ b/include/libtorrent/kademlia/routing_table.hpp @@ -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 diff --git a/src/kademlia/dht_tracker.cpp b/src/kademlia/dht_tracker.cpp index 67beeb9c1..b535ccb62 100644 --- a/src/kademlia/dht_tracker.cpp +++ b/src/kademlia/dht_tracker.cpp @@ -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 out(node); - write_endpoint(i->ep(), out); - nodes.list().push_back(entry(node)); - } if (!nodes.list().empty()) ret["nodes"] = nodes; } diff --git a/src/kademlia/routing_table.cpp b/src/kademlia/routing_table.cpp index 0bafd4f3e..1ac00dedc 100644 --- a/src/kademlia/routing_table.cpp +++ b/src/kademlia/routing_table.cpp @@ -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); diff --git a/test/test_dht.cpp b/test/test_dht.cpp index 97eb147f4..2a541f695 100644 --- a/test/test_dht.cpp +++ b/test/test_dht.cpp @@ -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 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