From 56248845effbc5e2588e8d04695d02d5ba95050b Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Tue, 25 Sep 2012 18:47:04 +0000 Subject: [PATCH] some DHT fixes + cleanup --- src/kademlia/routing_table.cpp | 25 +++++++++++-------------- src/kademlia/rpc_manager.cpp | 4 ++-- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/kademlia/routing_table.cpp b/src/kademlia/routing_table.cpp index 4f4f8f5b9..4d347d011 100644 --- a/src/kademlia/routing_table.cpp +++ b/src/kademlia/routing_table.cpp @@ -625,7 +625,10 @@ bool routing_table::add_node(node_entry e) continue; } // this entry belongs in the new bucket - new_bucket.push_back(*j); + if (int(new_bucket.size()) < bucket_size_limit) + new_bucket.push_back(*j); + else if (int(new_replacement_bucket.size()) < m_bucket_size) + new_replacement_bucket.push_back(*j); j = b.erase(j); } @@ -648,7 +651,7 @@ bool routing_table::add_node(node_entry e) // this entry belongs in the new bucket if (int(new_bucket.size()) < new_bucket_size) new_bucket.push_back(*j); - else + else if (int(new_replacement_bucket.size()) < m_bucket_size) new_replacement_bucket.push_back(*j); } j = rb.erase(j); @@ -754,7 +757,12 @@ void routing_table::node_failed(node_id const& id, udp::endpoint const& ep) m_ips.erase(j->addr.to_v4().to_bytes()); b.erase(j); - j = std::find_if(rb.begin(), rb.end(), boost::bind(&node_entry::pinged, _1) == true); + // sort by RTT first, to find the node with the lowest + // RTT that is pinged + std::sort(rb.begin(), rb.end() + , boost::bind(&node_entry::rtt, _1) < boost::bind(&node_entry::rtt, _2)); + + j = std::find_if(rb.begin(), rb.end(), boost::bind(&node_entry::pinged, _1)); if (j == rb.end()) j = rb.begin(); b.push_back(*j); rb.erase(j); @@ -895,17 +903,6 @@ void routing_table::find_node(node_id const& target if (int(l.size()) >= count) l.resize(count); } -/* -routing_table::iterator routing_table::begin() const -{ - // +1 to avoid ourself - return iterator(m_buckets.begin() + 1, m_buckets.end()); -} -routing_table::iterator routing_table::end() const -{ - return iterator(m_buckets.end(), m_buckets.end()); -} -*/ } } // namespace libtorrent::dht diff --git a/src/kademlia/rpc_manager.cpp b/src/kademlia/rpc_manager.cpp index 04f1a857d..f337f90d7 100644 --- a/src/kademlia/rpc_manager.cpp +++ b/src/kademlia/rpc_manager.cpp @@ -379,8 +379,8 @@ time_duration rpc_manager::tick() { INVARIANT_CHECK; - const static int short_timeout = 3; - const static int timeout = 20; + const static int short_timeout = 2; + const static int timeout = 10; // look for observers that have timed out