Use ping instead of get_peers if current bucket is full.
This commit is contained in:
parent
50ccce6eed
commit
f9fa8ffdec
|
@ -187,6 +187,8 @@ public:
|
||||||
void check_invariant() const;
|
void check_invariant() const;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
bool is_full(int bucket) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
dht_logger* m_log;
|
dht_logger* m_log;
|
||||||
|
|
|
@ -564,14 +564,21 @@ void node::send_single_refresh(udp::endpoint const& ep, int bucket
|
||||||
e["y"] = "q";
|
e["y"] = "q";
|
||||||
entry& a = e["a"];
|
entry& a = e["a"];
|
||||||
|
|
||||||
// use get_peers instead of find_node. We'll get nodes in the response
|
if (m_table.is_full(bucket))
|
||||||
// either way.
|
{
|
||||||
e["q"] = "get_peers";
|
// current bucket is full, just ping it.
|
||||||
a["info_hash"] = target.to_string();
|
e["q"] = "ping";
|
||||||
m_counters.inc_stats_counter(counters::dht_get_peers_out);
|
m_counters.inc_stats_counter(counters::dht_ping_out);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// use get_peers instead of find_node. We'll get nodes in the response
|
||||||
|
// either way.
|
||||||
|
e["q"] = "get_peers";
|
||||||
|
a["info_hash"] = target.to_string();
|
||||||
|
m_counters.inc_stats_counter(counters::dht_get_peers_out);
|
||||||
|
}
|
||||||
|
|
||||||
// e["q"] = "find_node";
|
|
||||||
// a["target"] = target.to_string();
|
|
||||||
m_rpc.invoke(e, ep, o);
|
m_rpc.invoke(e, ep, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1235,5 +1235,17 @@ void routing_table::check_invariant() const
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
bool routing_table::is_full(int bucket) const
|
||||||
|
{
|
||||||
|
int num_buckets = m_buckets.size();
|
||||||
|
if (num_buckets == 0) return false;
|
||||||
|
if (bucket >= num_buckets) return false;
|
||||||
|
|
||||||
|
table_t::const_iterator i = m_buckets.begin();
|
||||||
|
std::advance(i, bucket);
|
||||||
|
return (i->live_nodes.size() >= bucket_limit(bucket)
|
||||||
|
&& i->replacements.size() >= m_bucket_size);
|
||||||
|
}
|
||||||
|
|
||||||
} } // namespace libtorrent::dht
|
} } // namespace libtorrent::dht
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue