Merge pull request #183 from thomas-yuan/ta_init

start 'find' from near nodes instead of all of nodes in routing table.
This commit is contained in:
Arvid Norberg 2015-09-30 00:43:14 -04:00
commit d7cdcf9369
1 changed files with 12 additions and 13 deletions

View File

@ -81,16 +81,6 @@ void find_data_observer::reply(msg const& m)
done(); done();
} }
namespace {
void add_entry_fun(void* userdata, node_entry const& e)
{
traversal_algorithm* f = static_cast<traversal_algorithm*>(userdata);
f->add_entry(e.id, e.ep(), observer::flag_initial);
}
} // anonymous namespace
find_data::find_data( find_data::find_data(
node& dht_node node& dht_node
, node_id target , node_id target
@ -103,10 +93,19 @@ find_data::find_data(
void find_data::start() void find_data::start()
{ {
// if the user didn't add seed-nodes manually, grab a bunch of nodes from the // if the user didn't add seed-nodes manually, grab k (bucket size)
// routing table // nodes from routing table.
if (m_results.empty()) if (m_results.empty())
m_node.m_table.for_each_node(&add_entry_fun, 0, this); {
std::vector<node_entry> nodes;
m_node.m_table.find_node(m_target, nodes, routing_table::include_failed);
for (std::vector<node_entry>::iterator i = nodes.begin()
, end(nodes.end()); i != end; ++i)
{
add_entry(i->id, i->ep(), observer::flag_initial);
}
}
traversal_algorithm::start(); traversal_algorithm::start();
} }