fixed DHT bootstrapping issue

This commit is contained in:
Arvid Norberg 2010-02-14 07:46:57 +00:00
parent 0acfe4a480
commit 5c02f3df59
7 changed files with 36 additions and 20 deletions

View File

@ -116,6 +116,7 @@ release 0.14.9
* fixed bug where torrents with incorrectly formatted web seed URLs would be
connected multiple times
* fixed MinGW support
* fixed DHT bootstrapping issue
release 0.14.8

View File

@ -198,6 +198,8 @@ namespace libtorrent
void maybe_update_udp_mapping(int nat, int local_port, int external_port);
void on_dht_announce(error_code const& e);
void on_dht_router_name_lookup(error_code const& e
, tcp::resolver::iterator host);
#endif
#ifndef TORRENT_DISABLE_ENCRYPTION
@ -695,7 +697,7 @@ namespace libtorrent
// these are used when starting the DHT
// (and bootstrapping it), and then erased
std::list<std::pair<std::string, int> > m_dht_router_nodes;
std::list<udp::endpoint> m_dht_router_nodes;
void on_receive_udp(error_code const& e
, udp::endpoint const& ep, char const* buf, int len);

View File

@ -84,7 +84,7 @@ namespace libtorrent { namespace dht
void add_node(udp::endpoint node);
void add_node(std::pair<std::string, int> const& node);
void add_router_node(std::pair<std::string, int> const& node);
void add_router_node(udp::endpoint const& node);
entry state() const;

View File

@ -599,21 +599,10 @@ namespace libtorrent { namespace dht
add_node(host->endpoint());
}
void dht_tracker::add_router_node(std::pair<std::string, int> const& node)
void dht_tracker::add_router_node(udp::endpoint const& node)
{
mutex_t::scoped_lock l(m_mutex);
char port[7];
snprintf(port, sizeof(port), "%d", node.second);
udp::resolver::query q(node.first, port);
m_host_resolver.async_resolve(q,
bind(&dht_tracker::on_router_name_lookup, self(), _1, _2));
}
void dht_tracker::on_router_name_lookup(error_code const& e
, udp::resolver::iterator host)
{
if (e || host == udp::resolver::iterator()) return;
m_dht.add_router_node(host->endpoint());
m_dht.add_router_node(node);
}
void dht_tracker::on_bootstrap(std::vector<std::pair<node_entry, std::string> > const&)

View File

@ -259,12 +259,22 @@ void node_impl::bootstrap(std::vector<udp::endpoint> const& nodes
{
boost::intrusive_ptr<dht::refresh> r(new dht::refresh(*this, m_id, f));
#ifdef TORRENT_DHT_VERBOSE_LOGGING
int count = 0;
#endif
for (std::vector<udp::endpoint>::const_iterator i = nodes.begin()
, end(nodes.end()); i != end; ++i)
{
#ifdef TORRENT_DHT_VERBOSE_LOGGING
++count;
#endif
r->add_entry(node_id(0), *i, traversal_algorithm::result::initial);
}
#ifdef TORRENT_DHT_VERBOSE_LOGGING
TORRENT_LOG(node) << "bootstrapping with " << count << " nodes";
#endif
r->start();
}
/*

View File

@ -238,6 +238,10 @@ void traversal_algorithm::add_requests()
void traversal_algorithm::add_router_entries()
{
#ifdef TORRENT_DHT_VERBOSE_LOGGING
TORRENT_LOG(traversal) << " using router nodes to initiate traversal algorithm. "
<< std::distance(m_node.m_table.router_begin(), m_node.m_table.router_end()) << " routers";
#endif
for (routing_table::router_iterator i = m_node.m_table.router_begin()
, end(m_node.m_table.router_end()); i != end; ++i)
{

View File

@ -3251,12 +3251,11 @@ namespace aux {
m_dht_socket.bind(m_dht_settings.service_port);
}
for (std::list<std::pair<std::string, int> >::iterator i = m_dht_router_nodes.begin()
for (std::list<udp::endpoint>::iterator i = m_dht_router_nodes.begin()
, end(m_dht_router_nodes.end()); i != end; ++i)
{
m_dht->add_router_node(*i);
}
std::list<std::pair<std::string, int> >().swap(m_dht_router_nodes);
m_dht->start(startup_state);
@ -3367,11 +3366,22 @@ namespace aux {
void session_impl::add_dht_router(std::pair<std::string, int> const& node)
{
// router nodes should be added before the DHT is started (and bootstrapped)
if (m_dht) m_dht->add_router_node(node);
else m_dht_router_nodes.push_back(node);
char port[7];
snprintf(port, sizeof(port), "%d", node.second);
tcp::resolver::query q(node.first, port);
m_host_resolver.async_resolve(q,
bind(&session_impl::on_dht_router_name_lookup, this, _1, _2));
}
void session_impl::on_dht_router_name_lookup(error_code const& e
, tcp::resolver::iterator host)
{
if (e || host == tcp::resolver::iterator()) return;
// router nodes should be added before the DHT is started (and bootstrapped)
udp::endpoint ep(host->endpoint().address(), host->endpoint().port());
if (m_dht) m_dht->add_router_node(ep);
m_dht_router_nodes.push_back(ep);
}
#endif
#ifndef TORRENT_DISABLE_ENCRYPTION