From fbdf76cf5b1cb72a9bb2dc6393a283e9421e59f2 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Mon, 13 Dec 2010 09:24:19 +0000 Subject: [PATCH] fix DHT size estimation --- src/kademlia/routing_table.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/kademlia/routing_table.cpp b/src/kademlia/routing_table.cpp index 76e68e901..b71402dea 100644 --- a/src/kademlia/routing_table.cpp +++ b/src/kademlia/routing_table.cpp @@ -99,14 +99,21 @@ boost::tuple routing_table::size() const size_type routing_table::num_global_nodes() const { - int num_nodes = 1; // we are one of the nodes + int deepest_bucket = 0; + int deepest_size = 0; for (table_t::const_iterator i = m_buckets.begin() , end(m_buckets.end()); i != end; ++i) { - num_nodes += i->live_nodes.size(); + deepest_size = i->live_nodes.size(); // + i->replacements.size(); + if (deepest_size < m_bucket_size) break; + // this bucket is full + ++deepest_bucket; } - return (2 << m_buckets.size()) * num_nodes; + if (deepest_bucket == 0) return 1 + deepest_size; + + if (deepest_size < m_bucket_size / 2) return (1 << deepest_bucket) * m_bucket_size; + else return (2 << deepest_bucket) * deepest_size; } #if (defined TORRENT_DHT_VERBOSE_LOGGING || defined TORRENT_DEBUG) && TORRENT_USE_IOSTREAM