fixed DHT bootstrapping issue
This commit is contained in:
@@ -116,6 +116,7 @@ release 0.14.9
|
|||||||
* fixed bug where torrents with incorrectly formatted web seed URLs would be
|
* fixed bug where torrents with incorrectly formatted web seed URLs would be
|
||||||
connected multiple times
|
connected multiple times
|
||||||
* fixed MinGW support
|
* fixed MinGW support
|
||||||
|
* fixed DHT bootstrapping issue
|
||||||
|
|
||||||
release 0.14.8
|
release 0.14.8
|
||||||
|
|
||||||
|
@@ -198,6 +198,8 @@ namespace libtorrent
|
|||||||
void maybe_update_udp_mapping(int nat, int local_port, int external_port);
|
void maybe_update_udp_mapping(int nat, int local_port, int external_port);
|
||||||
|
|
||||||
void on_dht_announce(error_code const& e);
|
void on_dht_announce(error_code const& e);
|
||||||
|
void on_dht_router_name_lookup(error_code const& e
|
||||||
|
, tcp::resolver::iterator host);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef TORRENT_DISABLE_ENCRYPTION
|
#ifndef TORRENT_DISABLE_ENCRYPTION
|
||||||
@@ -695,7 +697,7 @@ namespace libtorrent
|
|||||||
|
|
||||||
// these are used when starting the DHT
|
// these are used when starting the DHT
|
||||||
// (and bootstrapping it), and then erased
|
// (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
|
void on_receive_udp(error_code const& e
|
||||||
, udp::endpoint const& ep, char const* buf, int len);
|
, udp::endpoint const& ep, char const* buf, int len);
|
||||||
|
@@ -84,7 +84,7 @@ namespace libtorrent { namespace dht
|
|||||||
|
|
||||||
void add_node(udp::endpoint node);
|
void add_node(udp::endpoint node);
|
||||||
void add_node(std::pair<std::string, int> const& 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;
|
entry state() const;
|
||||||
|
|
||||||
|
@@ -599,21 +599,10 @@ namespace libtorrent { namespace dht
|
|||||||
add_node(host->endpoint());
|
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);
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
char port[7];
|
m_dht.add_router_node(node);
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void dht_tracker::on_bootstrap(std::vector<std::pair<node_entry, std::string> > const&)
|
void dht_tracker::on_bootstrap(std::vector<std::pair<node_entry, std::string> > const&)
|
||||||
|
@@ -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));
|
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()
|
for (std::vector<udp::endpoint>::const_iterator i = nodes.begin()
|
||||||
, end(nodes.end()); i != end; ++i)
|
, end(nodes.end()); i != end; ++i)
|
||||||
{
|
{
|
||||||
|
#ifdef TORRENT_DHT_VERBOSE_LOGGING
|
||||||
|
++count;
|
||||||
|
#endif
|
||||||
r->add_entry(node_id(0), *i, traversal_algorithm::result::initial);
|
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();
|
r->start();
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
@@ -238,6 +238,10 @@ void traversal_algorithm::add_requests()
|
|||||||
|
|
||||||
void traversal_algorithm::add_router_entries()
|
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()
|
for (routing_table::router_iterator i = m_node.m_table.router_begin()
|
||||||
, end(m_node.m_table.router_end()); i != end; ++i)
|
, end(m_node.m_table.router_end()); i != end; ++i)
|
||||||
{
|
{
|
||||||
|
@@ -3251,12 +3251,11 @@ namespace aux {
|
|||||||
m_dht_socket.bind(m_dht_settings.service_port);
|
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)
|
, end(m_dht_router_nodes.end()); i != end; ++i)
|
||||||
{
|
{
|
||||||
m_dht->add_router_node(*i);
|
m_dht->add_router_node(*i);
|
||||||
}
|
}
|
||||||
std::list<std::pair<std::string, int> >().swap(m_dht_router_nodes);
|
|
||||||
|
|
||||||
m_dht->start(startup_state);
|
m_dht->start(startup_state);
|
||||||
|
|
||||||
@@ -3367,11 +3366,22 @@ namespace aux {
|
|||||||
|
|
||||||
void session_impl::add_dht_router(std::pair<std::string, int> const& node)
|
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)
|
char port[7];
|
||||||
if (m_dht) m_dht->add_router_node(node);
|
snprintf(port, sizeof(port), "%d", node.second);
|
||||||
else m_dht_router_nodes.push_back(node);
|
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
|
#endif
|
||||||
|
|
||||||
#ifndef TORRENT_DISABLE_ENCRYPTION
|
#ifndef TORRENT_DISABLE_ENCRYPTION
|
||||||
|
Reference in New Issue
Block a user