From fd4c09d7b29add5fcb22709a3cdefab5fd01cd4a Mon Sep 17 00:00:00 2001 From: Alden Torres Date: Fri, 2 Sep 2016 16:42:55 -0400 Subject: [PATCH] refactor to use std::shared_ptr with traversal_algorithm (#1056) refactor to use std::shared_ptr with traversal_algorithm. use a more stable linaro gcc link --- .travis.yml | 6 +- .../libtorrent/kademlia/direct_request.hpp | 2 +- include/libtorrent/kademlia/find_data.hpp | 6 +- include/libtorrent/kademlia/get_item.hpp | 2 +- include/libtorrent/kademlia/get_peers.hpp | 4 +- include/libtorrent/kademlia/node.hpp | 2 +- include/libtorrent/kademlia/observer.hpp | 4 +- include/libtorrent/kademlia/put_data.hpp | 2 +- include/libtorrent/kademlia/routing_table.hpp | 4 +- include/libtorrent/kademlia/rpc_manager.hpp | 2 +- .../kademlia/traversal_algorithm.hpp | 20 ++---- include/libtorrent/peer_class_set.hpp | 1 - include/libtorrent/string_util.hpp | 2 +- src/kademlia/find_data.cpp | 2 +- src/kademlia/get_item.cpp | 2 +- src/kademlia/get_peers.cpp | 16 ++--- src/kademlia/node.cpp | 68 ++++++++----------- src/kademlia/put_data.cpp | 2 +- src/kademlia/refresh.cpp | 10 ++- src/kademlia/rpc_manager.cpp | 2 +- src/kademlia/traversal_algorithm.cpp | 17 ++--- src/pe_crypto.cpp | 2 - src/peer_class_set.cpp | 4 +- src/session_impl.cpp | 2 +- src/string_util.cpp | 2 +- test/test_dht.cpp | 3 +- 26 files changed, 73 insertions(+), 116 deletions(-) diff --git a/.travis.yml b/.travis.yml index 121f71a67..751c809a7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -90,9 +90,9 @@ install: - 'if [ $arch == "arm" ]; then cd test; - wget https://releases.linaro.org/components/toolchain/binaries/latest-5/armv8l-linux-gnueabihf/gcc-linaro-5.3-2016.02-x86_64_armv8l-linux-gnueabihf.tar.xz; - tar xf gcc-linaro-5.3-2016.02-x86_64_armv8l-linux-gnueabihf.tar.xz; - export PATH=${PWD}/gcc-linaro-5.3-2016.02-x86_64_armv8l-linux-gnueabihf/bin:${PATH}; + wget -O gcc-linaro.tar.xz https://releases.linaro.org/components/toolchain/binaries/5.3-2016.05/armv8l-linux-gnueabihf/gcc-linaro-5.3.1-2016.05-x86_64_armv8l-linux-gnueabihf.tar.xz; + tar xf gcc-linaro.tar.xz; + export PATH=${PWD}/gcc-linaro-5.3.1-2016.05-x86_64_armv8l-linux-gnueabihf/bin:${PATH}; armv8l-linux-gnueabihf-g++ --version; wget -O boost.zip http://pilotfiber.dl.sourceforge.net/project/boost/boost/1.55.0/boost_1_55_0.zip; unzip -qq boost.zip; diff --git a/include/libtorrent/kademlia/direct_request.hpp b/include/libtorrent/kademlia/direct_request.hpp index 2ed1ea979..a9f483b67 100644 --- a/include/libtorrent/kademlia/direct_request.hpp +++ b/include/libtorrent/kademlia/direct_request.hpp @@ -68,7 +68,7 @@ protected: struct direct_observer : observer { - direct_observer(boost::intrusive_ptr const& algo + direct_observer(std::shared_ptr const& algo , udp::endpoint const& ep, node_id const& id) : observer(algo, ep, id) {} diff --git a/include/libtorrent/kademlia/find_data.hpp b/include/libtorrent/kademlia/find_data.hpp index e095bda3b..8f8ec20b2 100644 --- a/include/libtorrent/kademlia/find_data.hpp +++ b/include/libtorrent/kademlia/find_data.hpp @@ -43,10 +43,6 @@ POSSIBILITY OF SUCH DAMAGE. #include #include -#include "libtorrent/aux_/disable_warnings_push.hpp" -#include -#include "libtorrent/aux_/disable_warnings_pop.hpp" - namespace libtorrent { namespace dht { @@ -86,7 +82,7 @@ protected: struct find_data_observer : traversal_observer { find_data_observer( - boost::intrusive_ptr const& algorithm + std::shared_ptr const& algorithm , udp::endpoint const& ep, node_id const& id) : traversal_observer(algorithm, ep, id) {} diff --git a/include/libtorrent/kademlia/get_item.hpp b/include/libtorrent/kademlia/get_item.hpp index 2c92b915d..a6036b0d1 100644 --- a/include/libtorrent/kademlia/get_item.hpp +++ b/include/libtorrent/kademlia/get_item.hpp @@ -79,7 +79,7 @@ class get_item_observer : public find_data_observer { public: get_item_observer( - boost::intrusive_ptr const& algorithm + std::shared_ptr const& algorithm , udp::endpoint const& ep, node_id const& id) : find_data_observer(algorithm, ep, id) {} diff --git a/include/libtorrent/kademlia/get_peers.hpp b/include/libtorrent/kademlia/get_peers.hpp index 787b6389b..75bc62100 100644 --- a/include/libtorrent/kademlia/get_peers.hpp +++ b/include/libtorrent/kademlia/get_peers.hpp @@ -85,7 +85,7 @@ private: struct get_peers_observer : find_data_observer { get_peers_observer( - boost::intrusive_ptr const& algorithm + std::shared_ptr const& algorithm , udp::endpoint const& ep, node_id const& id) : find_data_observer(algorithm, ep, id) {} @@ -96,7 +96,7 @@ struct get_peers_observer : find_data_observer struct obfuscated_get_peers_observer : traversal_observer { obfuscated_get_peers_observer( - boost::intrusive_ptr const& algorithm + std::shared_ptr const& algorithm , udp::endpoint const& ep, node_id const& id) : traversal_observer(algorithm, ep, id) {} diff --git a/include/libtorrent/kademlia/node.hpp b/include/libtorrent/kademlia/node.hpp index dfa69ae93..a8f273062 100644 --- a/include/libtorrent/kademlia/node.hpp +++ b/include/libtorrent/kademlia/node.hpp @@ -79,7 +79,7 @@ struct null_type {}; class announce_observer : public observer { public: - announce_observer(boost::intrusive_ptr const& algo + announce_observer(std::shared_ptr const& algo , udp::endpoint const& ep, node_id const& id) : observer(algo, ep, id) {} diff --git a/include/libtorrent/kademlia/observer.hpp b/include/libtorrent/kademlia/observer.hpp index 4e2026101..5b2836e08 100644 --- a/include/libtorrent/kademlia/observer.hpp +++ b/include/libtorrent/kademlia/observer.hpp @@ -59,7 +59,7 @@ struct TORRENT_EXTRA_EXPORT observer : boost::noncopyable friend TORRENT_EXTRA_EXPORT void intrusive_ptr_add_ref(observer const*); friend TORRENT_EXTRA_EXPORT void intrusive_ptr_release(observer const*); - observer(boost::intrusive_ptr const& a + observer(std::shared_ptr const& a , udp::endpoint const& ep, node_id const& id) : m_sent() , m_algorithm(a) @@ -139,7 +139,7 @@ private: time_point m_sent; - const boost::intrusive_ptr m_algorithm; + const std::shared_ptr m_algorithm; node_id m_id; diff --git a/include/libtorrent/kademlia/put_data.hpp b/include/libtorrent/kademlia/put_data.hpp index 40703b666..bb9208835 100644 --- a/include/libtorrent/kademlia/put_data.hpp +++ b/include/libtorrent/kademlia/put_data.hpp @@ -71,7 +71,7 @@ protected: struct put_data_observer : traversal_observer { put_data_observer( - boost::intrusive_ptr const& algorithm + std::shared_ptr const& algorithm , udp::endpoint const& ep, node_id const& id, std::string const& token) : traversal_observer(algorithm, ep, id) , m_token(token) diff --git a/include/libtorrent/kademlia/routing_table.hpp b/include/libtorrent/kademlia/routing_table.hpp index 5df4137a0..7d7f5791f 100644 --- a/include/libtorrent/kademlia/routing_table.hpp +++ b/include/libtorrent/kademlia/routing_table.hpp @@ -171,8 +171,8 @@ public: // iterates over the router nodes added typedef std::set::const_iterator router_iterator; - router_iterator router_begin() const { return m_router_nodes.begin(); } - router_iterator router_end() const { return m_router_nodes.end(); } + router_iterator begin() const { return m_router_nodes.begin(); } + router_iterator end() const { return m_router_nodes.end(); } enum add_node_status_t { failed_to_add = 0, diff --git a/include/libtorrent/kademlia/rpc_manager.hpp b/include/libtorrent/kademlia/rpc_manager.hpp index 12f222e7c..273e37b26 100644 --- a/include/libtorrent/kademlia/rpc_manager.hpp +++ b/include/libtorrent/kademlia/rpc_manager.hpp @@ -57,7 +57,7 @@ struct udp_socket_interface; struct TORRENT_EXTRA_EXPORT null_observer : public observer { - null_observer(boost::intrusive_ptr const& a + null_observer(std::shared_ptr const& a , udp::endpoint const& ep, node_id const& id): observer(a, ep, id) {} virtual void reply(msg const&) { flags |= flag_done; } }; diff --git a/include/libtorrent/kademlia/traversal_algorithm.hpp b/include/libtorrent/kademlia/traversal_algorithm.hpp index 73734c37a..8f80acc8f 100644 --- a/include/libtorrent/kademlia/traversal_algorithm.hpp +++ b/include/libtorrent/kademlia/traversal_algorithm.hpp @@ -43,7 +43,6 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/aux_/disable_warnings_push.hpp" #include -#include #include "libtorrent/aux_/disable_warnings_pop.hpp" namespace libtorrent { struct dht_lookup; } @@ -55,6 +54,7 @@ class node; // this class may not be instantiated as a stack object struct TORRENT_EXTRA_EXPORT traversal_algorithm : boost::noncopyable + , std::enable_shared_from_this { void traverse(node_id const& id, udp::endpoint addr); void finished(observer_ptr o); @@ -83,6 +83,9 @@ struct TORRENT_EXTRA_EXPORT traversal_algorithm : boost::noncopyable protected: + std::shared_ptr self() + { return shared_from_this(); } + // returns true if we're done bool add_requests(); @@ -97,22 +100,9 @@ protected: virtual bool invoke(observer_ptr) { return false; } - friend void intrusive_ptr_add_ref(traversal_algorithm* p) - { - TORRENT_ASSERT(p->m_ref_count < 0xffff); - p->m_ref_count++; - } - - friend void intrusive_ptr_release(traversal_algorithm* p) - { - if (--p->m_ref_count == 0) - delete p; - } - node& m_node; std::vector m_results; node_id const m_target; - std::uint16_t m_ref_count; std::uint16_t m_invoke_count; std::uint16_t m_branch_factor; std::uint16_t m_responses; @@ -128,7 +118,7 @@ protected: struct traversal_observer : observer { traversal_observer( - boost::intrusive_ptr const& algorithm + std::shared_ptr const& algorithm , udp::endpoint const& ep, node_id const& id) : observer(algorithm, ep, id) {} diff --git a/include/libtorrent/peer_class_set.hpp b/include/libtorrent/peer_class_set.hpp index 98acc2bba..54fc42334 100644 --- a/include/libtorrent/peer_class_set.hpp +++ b/include/libtorrent/peer_class_set.hpp @@ -67,4 +67,3 @@ namespace libtorrent { } #endif // TORRENT_PEER_CLASS_SET_HPP_INCLUDED - diff --git a/include/libtorrent/string_util.hpp b/include/libtorrent/string_util.hpp index 58261d8f6..51fa3da87 100644 --- a/include/libtorrent/string_util.hpp +++ b/include/libtorrent/string_util.hpp @@ -86,7 +86,7 @@ namespace libtorrent // it is a comma-separated list of IP or device names with ports. For // example: "eth0:6881,eth1:6881" or "127.0.0.1:6881" TORRENT_EXTRA_EXPORT void parse_comma_separated_string_port( - std::string const& in, std::vector >& out); + std::string const& in, std::vector>& out); // this parses the string that's used as the outgoing_interfaces setting. // it is a comma separated list of IPs and device names. For example: diff --git a/src/kademlia/find_data.cpp b/src/kademlia/find_data.cpp index 2da5969dd..9219d960a 100644 --- a/src/kademlia/find_data.cpp +++ b/src/kademlia/find_data.cpp @@ -121,7 +121,7 @@ void find_data::got_write_token(node_id const& n, std::string write_token) observer_ptr find_data::new_observer(void* ptr , udp::endpoint const& ep, node_id const& id) { - observer_ptr o(new (ptr) find_data_observer(this, ep, id)); + observer_ptr o(new (ptr) find_data_observer(self(), ep, id)); #if TORRENT_USE_ASSERTS o->m_in_constructor = false; #endif diff --git a/src/kademlia/get_item.cpp b/src/kademlia/get_item.cpp index bf5488545..923bbd3a3 100644 --- a/src/kademlia/get_item.cpp +++ b/src/kademlia/get_item.cpp @@ -128,7 +128,7 @@ char const* get_item::name() const { return "get"; } observer_ptr get_item::new_observer(void* ptr , udp::endpoint const& ep, node_id const& id) { - observer_ptr o(new (ptr) get_item_observer(this, ep, id)); + observer_ptr o(new (ptr) get_item_observer(self(), ep, id)); #if TORRENT_USE_ASSERTS o->m_in_constructor = false; #endif diff --git a/src/kademlia/get_peers.cpp b/src/kademlia/get_peers.cpp index 4d748e674..214d73765 100644 --- a/src/kademlia/get_peers.cpp +++ b/src/kademlia/get_peers.cpp @@ -163,7 +163,7 @@ bool get_peers::invoke(observer_ptr o) observer_ptr get_peers::new_observer(void* ptr , udp::endpoint const& ep, node_id const& id) { - observer_ptr o(new (ptr) get_peers_observer(this, ep, id)); + observer_ptr o(new (ptr) get_peers_observer(self(), ep, id)); #if TORRENT_USE_ASSERTS o->m_in_constructor = false; #endif @@ -189,7 +189,7 @@ observer_ptr obfuscated_get_peers::new_observer(void* ptr { if (m_obfuscated) { - observer_ptr o(new (ptr) obfuscated_get_peers_observer(this, ep, id)); + observer_ptr o(new (ptr) obfuscated_get_peers_observer(self(), ep, id)); #if TORRENT_USE_ASSERTS o->m_in_constructor = false; #endif @@ -197,7 +197,7 @@ observer_ptr obfuscated_get_peers::new_observer(void* ptr } else { - observer_ptr o(new (ptr) get_peers_observer(this, ep, id)); + observer_ptr o(new (ptr) get_peers_observer(self(), ep, id)); #if TORRENT_USE_ASSERTS o->m_in_constructor = false; #endif @@ -222,10 +222,8 @@ bool obfuscated_get_peers::invoke(observer_ptr o) // our node-list for this traversal algorithm, to // allow the get_peers traversal to regress in case // nodes further down end up being dead - for (std::vector::iterator i = m_results.begin() - , end(m_results.end()); i != end; ++i) + for (auto const& node : m_results) { - observer* const node = i->get(); // don't re-request from nodes that didn't respond if (node->flags & observer::flag_failed) continue; // don't interrupt with queries that are already in-flight @@ -270,10 +268,8 @@ void obfuscated_get_peers::done() // oops, we failed to switch over to the non-obfuscated // mode early enough. do it now - boost::intrusive_ptr ta(new get_peers(m_node, m_target - , m_data_callback - , m_nodes_callback - , m_noseeds)); + auto ta = std::make_shared(m_node, m_target + , m_data_callback, m_nodes_callback, m_noseeds); // don't call these when the obfuscated_get_peers // is done, we're passing them on to be called when diff --git a/src/kademlia/node.cpp b/src/kademlia/node.cpp index 14614c747..746a01061 100644 --- a/src/kademlia/node.cpp +++ b/src/kademlia/node.cpp @@ -202,20 +202,19 @@ void node::bootstrap(std::vector const& nodes node_id target = m_id; make_id_secret(target); - boost::intrusive_ptr r(new dht::bootstrap(*this, target, f)); + auto r = std::make_shared(*this, target, f); m_last_self_refresh = aux::time_now(); #ifndef TORRENT_DISABLE_LOGGING int count = 0; #endif - for (std::vector::const_iterator i = nodes.begin() - , end(nodes.end()); i != end; ++i) + for (auto const& n : nodes) { #ifndef TORRENT_DISABLE_LOGGING ++count; #endif - r->add_entry(node_id(nullptr), *i, observer::flag_initial); + r->add_entry(node_id(nullptr), n, observer::flag_initial); } // make us start as far away from our node ID as possible @@ -348,7 +347,7 @@ void node::incoming(msg const& m) namespace { - void announce_fun(std::vector > const& v + void announce_fun(std::vector> const& v , node& node, int listen_port, sha1_hash const& ih, int flags) { #ifndef TORRENT_DISABLE_LOGGING @@ -362,23 +361,21 @@ namespace #endif // create a dummy traversal_algorithm - boost::intrusive_ptr algo( - new traversal_algorithm(node, (node_id::min)())); + auto algo = std::make_shared(node, node_id()); // store on the first k nodes - for (std::vector >::const_iterator i = v.begin() - , end(v.end()); i != end; ++i) + for (auto const& p : v) { #ifndef TORRENT_DISABLE_LOGGING if (node.observer()) { node.observer()->log(dht_logger::node, "announce-distance: %d" - , (160 - distance_exp(ih, i->first.id))); + , (160 - distance_exp(ih, p.first.id))); } #endif void* ptr = node.m_rpc.allocate_observer(); if (ptr == nullptr) return; - observer_ptr o(new (ptr) announce_observer(algo, i->first.ep(), i->first.id)); + observer_ptr o(new (ptr) announce_observer(algo, p.first.ep(), p.first.id)); #if TORRENT_USE_ASSERTS o->m_in_constructor = false; #endif @@ -388,11 +385,11 @@ namespace entry& a = e["a"]; a["info_hash"] = ih; a["port"] = listen_port; - a["token"] = i->second; + a["token"] = p.second; a["seed"] = (flags & node::flag_seed) ? 1 : 0; if (flags & node::flag_implied_port) a["implied_port"] = 1; node.stats_counters().inc_stats_counter(counters::dht_announce_peer_out); - node.m_rpc.invoke(e, i->first.ep(), o); + node.m_rpc.invoke(e, p.first.ep(), o); } } } @@ -425,7 +422,7 @@ void node::get_peers(sha1_hash const& info_hash // search for nodes with ids close to id or with peers // for info-hash id. then send announce_peer to them. - boost::intrusive_ptr ta; + std::shared_ptr ta; if (m_settings.privacy_lookups) { ta.reset(new dht::obfuscated_get_peers(*this, info_hash, dcallback, ncallback, noseeds)); @@ -460,12 +457,11 @@ void node::direct_request(udp::endpoint ep, entry& e , std::function f) { // not really a traversal - boost::intrusive_ptr algo( - new direct_traversal(*this, (node_id::min)(), f)); + auto algo = std::make_shared(*this, node_id(), f); void* ptr = m_rpc.allocate_observer(); if (ptr == nullptr) return; - observer_ptr o(new (ptr) direct_observer(algo, ep, (node_id::min)())); + observer_ptr o(new (ptr) direct_observer(algo, ep, node_id())); #if TORRENT_USE_ASSERTS o->m_in_constructor = false; #endif @@ -485,8 +481,8 @@ void node::get_item(sha1_hash const& target } #endif - boost::intrusive_ptr ta; - ta.reset(new dht::get_item(*this, target, std::bind(f, _1), find_data::nodes_callback())); + auto ta = std::make_shared(*this, target + , std::bind(f, _1), find_data::nodes_callback()); ta->start(); } @@ -502,22 +498,22 @@ void node::get_item(public_key const& pk, std::string const& salt } #endif - boost::intrusive_ptr ta; - ta.reset(new dht::get_item(*this, pk, salt, f, find_data::nodes_callback())); + auto ta = std::make_shared(*this, pk, salt, f + , find_data::nodes_callback()); ta->start(); } namespace { -void put(std::vector > const& nodes - , boost::intrusive_ptr ta) +void put(std::vector> const& nodes + , std::shared_ptr ta) { ta->set_targets(nodes); ta->start(); } void put_data_cb(item i, bool auth - , boost::intrusive_ptr ta + , std::shared_ptr ta , std::function f) { // call data_callback only when we got authoritative data. @@ -544,13 +540,11 @@ void node::put_item(sha1_hash const& target, entry const& data, std::function put_ta; - put_ta.reset(new dht::put_data(*this, std::bind(f, _2))); + auto put_ta = std::make_shared(*this, std::bind(f, _2)); put_ta->set_data(i); - boost::intrusive_ptr ta; - ta.reset(new dht::get_item(*this, target, get_item::data_callback(), - std::bind(&put, _1, put_ta))); + auto ta = std::make_shared(*this, target + , get_item::data_callback(), std::bind(&put, _1, put_ta)); ta->start(); } @@ -567,20 +561,18 @@ void node::put_item(public_key const& pk, std::string const& salt } #endif - boost::intrusive_ptr put_ta; - put_ta.reset(new dht::put_data(*this, f)); + auto put_ta = std::make_shared(*this, f); - boost::intrusive_ptr ta; - ta.reset(new dht::get_item(*this, pk, salt + auto ta = std::make_shared(*this, pk, salt , std::bind(&put_data_cb, _1, _2, put_ta, data_cb) - , std::bind(&put, _1, put_ta))); + , std::bind(&put, _1, put_ta)); ta->start(); } struct ping_observer : observer { ping_observer( - boost::intrusive_ptr const& algorithm + std::shared_ptr const& algorithm , udp::endpoint const& ep, node_id const& id) : observer(algorithm, ep, id) {} @@ -644,8 +636,7 @@ void node::tick() { node_id target = m_id; make_id_secret(target); - boost::intrusive_ptr r(new dht::bootstrap(*this, target - , std::bind(&nop))); + auto r = std::make_shared(*this, target, std::bind(&nop)); r->start(); m_last_self_refresh = now; return; @@ -683,8 +674,7 @@ void node::send_single_refresh(udp::endpoint const& ep, int bucket // create a dummy traversal_algorithm // this is unfortunately necessary for the observer // to free itself from the pool when it's being released - boost::intrusive_ptr algo( - new traversal_algorithm(*this, (node_id::min)())); + auto algo = std::make_shared(*this, node_id()); observer_ptr o(new (ptr) ping_observer(algo, ep, id)); #if TORRENT_USE_ASSERTS o->m_in_constructor = false; diff --git a/src/kademlia/put_data.cpp b/src/kademlia/put_data.cpp index 06306e00c..4b2d17d12 100644 --- a/src/kademlia/put_data.cpp +++ b/src/kademlia/put_data.cpp @@ -63,7 +63,7 @@ void put_data::set_targets(std::vector > cons void* ptr = m_node.m_rpc.allocate_observer(); if (ptr == nullptr) return; - observer_ptr o(new (ptr) put_data_observer(this, i->first.ep() + observer_ptr o(new (ptr) put_data_observer(self(), i->first.ep() , i->first.id, i->second)); #if TORRENT_USE_ASSERTS diff --git a/src/kademlia/refresh.cpp b/src/kademlia/refresh.cpp index 7a04ffba3..d30e0a133 100644 --- a/src/kademlia/refresh.cpp +++ b/src/kademlia/refresh.cpp @@ -44,7 +44,7 @@ namespace libtorrent { namespace dht observer_ptr bootstrap::new_observer(void* ptr , udp::endpoint const& ep, node_id const& id) { - observer_ptr o(new (ptr) get_peers_observer(this, ep, id)); + observer_ptr o(new (ptr) get_peers_observer(self(), ep, id)); #if TORRENT_USE_ASSERTS o->m_in_constructor = false; #endif @@ -97,15 +97,13 @@ void bootstrap::done() , static_cast(this)); #endif - for (std::vector::iterator i = m_results.begin() - , end(m_results.end()); i != end; ++i) + for (auto const& o : m_results) { - if ((*i)->flags & observer::flag_queried) continue; + if (o->flags & observer::flag_queried) continue; // this will send a ping - m_node.add_node((*i)->target_ep()); + m_node.add_node(o->target_ep()); } get_peers::done(); } } } // namespace libtorrent::dht - diff --git a/src/kademlia/rpc_manager.cpp b/src/kademlia/rpc_manager.cpp index a58463a0f..ddb14d1b3 100644 --- a/src/kademlia/rpc_manager.cpp +++ b/src/kademlia/rpc_manager.cpp @@ -82,7 +82,7 @@ void intrusive_ptr_release(observer const* o) TORRENT_ASSERT(o->m_refs > 0); if (--o->m_refs == 0) { - boost::intrusive_ptr ta = o->algorithm(); + auto ta = o->algorithm()->shared_from_this(); (const_cast(o))->~observer(); ta->free_observer(const_cast(o)); } diff --git a/src/kademlia/traversal_algorithm.cpp b/src/kademlia/traversal_algorithm.cpp index 79021930f..52d3e03b9 100644 --- a/src/kademlia/traversal_algorithm.cpp +++ b/src/kademlia/traversal_algorithm.cpp @@ -79,7 +79,7 @@ bool is_sorted(It b, It e, Cmp cmp) observer_ptr traversal_algorithm::new_observer(void* ptr , udp::endpoint const& ep, node_id const& id) { - observer_ptr o(new (ptr) null_observer(boost::intrusive_ptr(this), ep, id)); + observer_ptr o(new (ptr) null_observer(self(), ep, id)); #if TORRENT_USE_ASSERTS o->m_in_constructor = false; #endif @@ -91,7 +91,6 @@ traversal_algorithm::traversal_algorithm( , node_id target) : m_node(dht_node) , m_target(target) - , m_ref_count(0) , m_invoke_count(0) , m_branch_factor(3) , m_responses(0) @@ -385,10 +384,8 @@ void traversal_algorithm::done() int closest_target = 160; #endif - for (std::vector::iterator i = m_results.begin() - , end(m_results.end()); i != end; ++i) + for (auto const& o : m_results) { - boost::intrusive_ptr o = *i; if ((o->flags & (observer::flag_queried | observer::flag_failed)) == observer::flag_queried) { // set the done flag on any outstanding queries to prevent them from @@ -521,14 +518,11 @@ void traversal_algorithm::add_router_entries() { get_node().observer()->log(dht_logger::traversal , "[%p] using router nodes to initiate traversal algorithm %d routers" - , static_cast(this), int(std::distance(m_node.m_table.router_begin(), m_node.m_table.router_end()))); + , static_cast(this), int(std::distance(m_node.m_table.begin(), m_node.m_table.end()))); } #endif - for (routing_table::router_iterator i = m_node.m_table.router_begin() - , end(m_node.m_table.router_end()); i != end; ++i) - { - add_entry(node_id(nullptr), *i, observer::flag_initial); - } + for (auto const& n : m_node.m_table) + add_entry(node_id(), n, observer::flag_initial); } void traversal_algorithm::init() @@ -644,4 +638,3 @@ void traversal_observer::reply(msg const& m) } } } // namespace libtorrent::dht - diff --git a/src/pe_crypto.cpp b/src/pe_crypto.cpp index c6fa0a07b..6689546c6 100644 --- a/src/pe_crypto.cpp +++ b/src/pe_crypto.cpp @@ -53,8 +53,6 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/alloca.hpp" #include "libtorrent/pe_crypto.hpp" #include "libtorrent/hasher.hpp" -#include "libtorrent/assert.hpp" -#include "libtorrent/span.hpp" namespace libtorrent { diff --git a/src/peer_class_set.cpp b/src/peer_class_set.cpp index f2f7e482a..423b309d7 100644 --- a/src/peer_class_set.cpp +++ b/src/peer_class_set.cpp @@ -31,8 +31,7 @@ POSSIBILITY OF SUCH DAMAGE. */ #include "libtorrent/peer_class_set.hpp" -#include "libtorrent/peer_class.hpp" -#include + #include // for find namespace libtorrent @@ -72,4 +71,3 @@ namespace libtorrent pool.decref(c); } } - diff --git a/src/session_impl.cpp b/src/session_impl.cpp index ea70c71fe..062133619 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -5194,7 +5194,7 @@ namespace aux { { #ifndef TORRENT_DISABLE_DHT std::string const& node_list = m_settings.get_str(settings_pack::dht_bootstrap_nodes); - std::vector > nodes; + std::vector> nodes; parse_comma_separated_string_port(node_list, nodes); for (int i = 0; i < nodes.size(); ++i) diff --git a/src/string_util.cpp b/src/string_util.cpp index 42337201e..b2984aaba 100644 --- a/src/string_util.cpp +++ b/src/string_util.cpp @@ -310,7 +310,7 @@ namespace libtorrent // it is a comma-separated list of IP or device names with ports. For // example: "eth0:6881,eth1:6881" or "127.0.0.1:6881" void parse_comma_separated_string_port(std::string const& in - , std::vector >& out) + , std::vector>& out) { out.clear(); diff --git a/test/test_dht.cpp b/test/test_dht.cpp index 06284dac4..5a89d16ad 100644 --- a/test/test_dht.cpp +++ b/test/test_dht.cpp @@ -2966,8 +2966,7 @@ TORRENT_TEST(rpc_invalid_error_msg) req["t"] = "\0\0\0\0"; g_sent_packets.clear(); - boost::intrusive_ptr algo(new dht::traversal_algorithm( - node, node_id())); + auto algo = std::make_shared(node, node_id()); observer_ptr o(new (rpc.allocate_observer()) null_observer(algo, source, node_id())); #if TORRENT_USE_ASSERTS