DHT bootstrapping and refresh fix

This commit is contained in:
Arvid Norberg 2010-02-20 16:37:50 +00:00
parent 421e841b81
commit 47f3a18d65
4 changed files with 18 additions and 18 deletions

View File

@ -158,6 +158,8 @@ public:
void print_state(std::ostream& os) const;
#endif
void touch_bucket(node_id const& target);
private:
typedef std::list<routing_table_node> table_t;
@ -178,6 +180,9 @@ private:
table_t m_buckets;
node_id m_id; // our own node id
// the last time need_bootstrap() returned true
mutable ptime m_last_bootstrap;
// this is a set of all the endpoints that have
// been identified as router nodes. They will

View File

@ -141,7 +141,7 @@ struct traversal_algorithm : boost::noncopyable
, m_timeouts(0)
{
#ifdef TORRENT_DHT_VERBOSE_LOGGING
TORRENT_LOG(traversal) << " [" << this << "] new traversal process";
TORRENT_LOG(traversal) << " [" << this << "] new traversal process. Target: " << target;
#endif
}

View File

@ -60,6 +60,7 @@ routing_table::routing_table(node_id const& id, int bucket_size
: m_bucket_size(bucket_size)
, m_settings(settings)
, m_id(id)
, m_last_bootstrap(min_time())
{
}
@ -157,12 +158,12 @@ void routing_table::print_state(std::ostream& os) const
}
#endif
/*
void routing_table::touch_bucket(int bucket)
void routing_table::touch_bucket(node_id const& target)
{
m_bucket_activity[bucket] = time_now();
table_t::iterator i = find_bucket(target);
i->last_active = time_now();
}
*/
bool routing_table::need_refresh(node_id& target) const
{
@ -172,7 +173,7 @@ bool routing_table::need_refresh(node_id& target) const
, boost::bind(&routing_table_node::last_active, _1)
< boost::bind(&routing_table_node::last_active, _2));
if (i->last_active > time_now() - minutes(15)) return false;
if (time_now() - i->last_active < minutes(15)) return false;
// generate a random node_id within the given bucket
target = generate_id();
@ -196,18 +197,6 @@ bool routing_table::need_refresh(node_id& target) const
TORRENT_ASSERT(distance_exp(m_id, target) == 160 - num_bits);
return true;
}
/*
ptime routing_table::next_refresh(int bucket)
{
TORRENT_ASSERT(bucket < 160);
TORRENT_ASSERT(bucket >= 0);
// lower than or equal to since a refresh of bucket 0 will
// effectively refresh the lowest active bucket as well
if (bucket < m_lowest_active_bucket && bucket > 0)
return time_now() + minutes(15);
return m_bucket_activity[bucket] + minutes(15);
}
*/
void routing_table::replacement_cache(bucket_t& nodes) const
{
@ -517,6 +506,9 @@ bool routing_table::node_seen(node_id const& id, udp::endpoint ep)
bool routing_table::need_bootstrap() const
{
ptime now = time_now();
if (now - m_last_bootstrap < seconds(30)) return false;
for (table_t::const_iterator i = m_buckets.begin()
, end(m_buckets.end()); i != end; ++i)
{
@ -526,6 +518,7 @@ bool routing_table::need_bootstrap() const
if (j->confirmed()) return false;
}
}
m_last_bootstrap = now;
return true;
}

View File

@ -251,6 +251,8 @@ void traversal_algorithm::add_router_entries()
void traversal_algorithm::init()
{
// update the last activity of this bucket
m_node.m_table.touch_bucket(m_target);
m_branch_factor = m_node.branch_factor();
m_node.add_traversal_algorithm(this);
}