diff --git a/ChangeLog b/ChangeLog index 8ded4d976..2750c7961 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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 diff --git a/include/libtorrent/aux_/session_impl.hpp b/include/libtorrent/aux_/session_impl.hpp index 005449760..73feceb89 100644 --- a/include/libtorrent/aux_/session_impl.hpp +++ b/include/libtorrent/aux_/session_impl.hpp @@ -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 > m_dht_router_nodes; + std::list m_dht_router_nodes; void on_receive_udp(error_code const& e , udp::endpoint const& ep, char const* buf, int len); diff --git a/include/libtorrent/kademlia/dht_tracker.hpp b/include/libtorrent/kademlia/dht_tracker.hpp index ee417dcf8..a448c2cdd 100644 --- a/include/libtorrent/kademlia/dht_tracker.hpp +++ b/include/libtorrent/kademlia/dht_tracker.hpp @@ -84,7 +84,7 @@ namespace libtorrent { namespace dht void add_node(udp::endpoint node); void add_node(std::pair const& node); - void add_router_node(std::pair const& node); + void add_router_node(udp::endpoint const& node); entry state() const; diff --git a/src/kademlia/dht_tracker.cpp b/src/kademlia/dht_tracker.cpp index 34e1064eb..2a7b64efa 100644 --- a/src/kademlia/dht_tracker.cpp +++ b/src/kademlia/dht_tracker.cpp @@ -599,21 +599,10 @@ namespace libtorrent { namespace dht add_node(host->endpoint()); } - void dht_tracker::add_router_node(std::pair 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 > const&) diff --git a/src/kademlia/node.cpp b/src/kademlia/node.cpp index fce084b66..06bf032d5 100644 --- a/src/kademlia/node.cpp +++ b/src/kademlia/node.cpp @@ -259,12 +259,22 @@ void node_impl::bootstrap(std::vector const& nodes { boost::intrusive_ptr r(new dht::refresh(*this, m_id, f)); +#ifdef TORRENT_DHT_VERBOSE_LOGGING + int count = 0; +#endif + for (std::vector::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(); } /* diff --git a/src/kademlia/traversal_algorithm.cpp b/src/kademlia/traversal_algorithm.cpp index 7861428b8..940da259e 100644 --- a/src/kademlia/traversal_algorithm.cpp +++ b/src/kademlia/traversal_algorithm.cpp @@ -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) { diff --git a/src/session_impl.cpp b/src/session_impl.cpp index cbe41100c..b975e0583 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -3251,12 +3251,11 @@ namespace aux { m_dht_socket.bind(m_dht_settings.service_port); } - for (std::list >::iterator i = m_dht_router_nodes.begin() + for (std::list::iterator i = m_dht_router_nodes.begin() , end(m_dht_router_nodes.end()); i != end; ++i) { m_dht->add_router_node(*i); } - std::list >().swap(m_dht_router_nodes); m_dht->start(startup_state); @@ -3367,11 +3366,22 @@ namespace aux { void session_impl::add_dht_router(std::pair 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