From 29c17c123e26942b2a151bc31f1c95d229aaffea Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Tue, 22 Jan 2013 02:04:58 +0000 Subject: [PATCH] fix traversal algorithm leak in DHT --- ChangeLog | 1 + src/kademlia/refresh.cpp | 3 +-- src/kademlia/rpc_manager.cpp | 13 ++++++++++++- src/kademlia/traversal_algorithm.cpp | 9 +++++++-- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9e3f38a87..b536c9d87 100644 --- a/ChangeLog +++ b/ChangeLog @@ -10,6 +10,7 @@ * fix uTP edge case where udp socket buffer fills up * fix nagle implementation in uTP + * fix traversal algorithm leak in DHT * fix string encoding conversions on windows * take torrent_handle::query_pieces into account in torrent_handle::statue() * honor trackers responding with 410 diff --git a/src/kademlia/refresh.cpp b/src/kademlia/refresh.cpp index 835e8ea0b..294c6b6f4 100644 --- a/src/kademlia/refresh.cpp +++ b/src/kademlia/refresh.cpp @@ -75,8 +75,7 @@ bool refresh::invoke(observer_ptr o) e["q"] = "find_node"; entry& a = e["a"]; a["target"] = target().to_string(); - m_node.m_rpc.invoke(e, o->target_ep(), o); - return true; + return m_node.m_rpc.invoke(e, o->target_ep(), o); } bootstrap::bootstrap( diff --git a/src/kademlia/rpc_manager.cpp b/src/kademlia/rpc_manager.cpp index 3cf1c3725..27048f542 100644 --- a/src/kademlia/rpc_manager.cpp +++ b/src/kademlia/rpc_manager.cpp @@ -393,6 +393,16 @@ time_duration rpc_manager::tick() time_duration ret = seconds(short_timeout); ptime now = time_now(); +#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS + ptime last = min_time(); + for (transactions_t::iterator i = m_transactions.begin(); + i != m_transactions.end(); ++i) + { + TORRENT_ASSERT((*i)->sent() > last); + last = (*i)->sent(); + } +#endif + for (transactions_t::iterator i = m_transactions.begin(); i != m_transactions.end();) { @@ -483,8 +493,9 @@ bool rpc_manager::invoke(entry& e, udp::endpoint target_addr #if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS o->m_was_sent = true; #endif + return true; } - return true; + return false; } observer::~observer() diff --git a/src/kademlia/traversal_algorithm.cpp b/src/kademlia/traversal_algorithm.cpp index 72cd5e02f..116e7718a 100644 --- a/src/kademlia/traversal_algorithm.cpp +++ b/src/kademlia/traversal_algorithm.cpp @@ -177,7 +177,8 @@ void traversal_algorithm::start() // router nodes in the table if (m_results.empty()) add_router_entries(); init(); - add_requests(); + bool is_done = add_requests(); + if (is_done) done(); } void* traversal_algorithm::allocate_observer() @@ -383,13 +384,17 @@ bool traversal_algorithm::add_requests() ; #endif + o->flags |= observer::flag_queried; if (invoke(*i)) { TORRENT_ASSERT(m_invoke_count >= 0); ++m_invoke_count; - o->flags |= observer::flag_queried; ++outstanding; } + else + { + o->flags |= observer::flag_failed; + } } // this is the completion condition. If we found m_num_target_nodes