From 5ee6266e93562b828bb69c474f795876388a89ca Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 12 Dec 2010 09:15:54 +0000 Subject: [PATCH] more DHT fixes --- src/kademlia/routing_table.cpp | 7 +------ src/session_impl.cpp | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/kademlia/routing_table.cpp b/src/kademlia/routing_table.cpp index 11408864d..c072cbd92 100644 --- a/src/kademlia/routing_table.cpp +++ b/src/kademlia/routing_table.cpp @@ -184,7 +184,7 @@ bool routing_table::need_refresh(node_id& target) const ptime now = time_now(); // refresh our own bucket once every 15 minutes - if (now - m_last_self_refresh < minutes(15)) + if (now - m_last_self_refresh > minutes(15)) { m_last_self_refresh = now; target = m_id; @@ -272,11 +272,6 @@ bool routing_table::add_node(node_entry const& e) bucket_t& b = i->live_nodes; bucket_t& rb = i->replacements; - // if the replacement cache is full, we don't - // need another node. The table is fine the - // way it is. - if ((int)rb.size() >= m_bucket_size) return ret; - // if the node already exists, we don't need it bucket_t::iterator j = std::find_if(b.begin(), b.end() , boost::bind(&node_entry::id, _1) == e.id); diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 9c290f41a..e5eb8fb0a 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -973,7 +973,6 @@ namespace aux { { m_dht_state = *settings; } - #endif #if TORRENT_USE_I2P @@ -4350,6 +4349,9 @@ namespace aux { if (is_loopback(ip)) return; if (m_external_address == ip) return; + // for now, just trust whoever tells us our external address first + if (m_external_address != address()) return; + m_external_address = ip; if (m_alerts.should_post()) m_alerts.post_alert(external_ip_alert(ip)); @@ -4357,7 +4359,18 @@ namespace aux { // since we have a new external IP now, we need to // restart the DHT with a new node ID #ifndef TORRENT_DISABLE_DHT - start_dht(m_dht_state); + if (m_dht) + { + entry s = m_dht->state(); + int cur_state = 0; + int prev_state = 0; + entry* nodes1 = s.find_key("nodes"); + if (nodes1 && nodes1->type() == entry::list_t) cur_state = nodes1->list().size(); + entry* nodes2 = m_dht_state.find_key("nodes"); + if (nodes2 && nodes2->type() == entry::list_t) prev_state = nodes2->list().size(); + if (cur_state > prev_state) m_dht_state = s; + start_dht(m_dht_state); + } #endif }