From 0d2644802da12a8090e2b5a9beb29fefc6fd8725 Mon Sep 17 00:00:00 2001 From: Thomas Yuan Date: Wed, 23 Sep 2015 13:21:41 -0400 Subject: [PATCH] start 'find' from near nodes instead of all of nodes in routing table. --- src/kademlia/find_data.cpp | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/kademlia/find_data.cpp b/src/kademlia/find_data.cpp index 740ca29d2..237db52b6 100644 --- a/src/kademlia/find_data.cpp +++ b/src/kademlia/find_data.cpp @@ -81,16 +81,6 @@ void find_data_observer::reply(msg const& m) done(); } -namespace { - -void add_entry_fun(void* userdata, node_entry const& e) -{ - traversal_algorithm* f = static_cast(userdata); - f->add_entry(e.id, e.ep(), observer::flag_initial); -} - -} // anonymous namespace - find_data::find_data( node& dht_node , node_id target @@ -103,10 +93,19 @@ find_data::find_data( void find_data::start() { - // if the user didn't add seed-nodes manually, grab a bunch of nodes from the - // routing table + // if the user didn't add seed-nodes manually, grab k (bucket size) + // nodes from routing table. if (m_results.empty()) - m_node.m_table.for_each_node(&add_entry_fun, 0, this); + { + std::vector nodes; + m_node.m_table.find_node(m_target, nodes, routing_table::include_failed); + + for (std::vector::iterator i = nodes.begin() + , end(nodes.end()); i != end; ++i) + { + add_entry(i->id, i->ep(), observer::flag_initial); + } + } traversal_algorithm::start(); }