From 6c5bed63d369f284b69f349c8808686147637da8 Mon Sep 17 00:00:00 2001 From: Steven Siloti Date: Sun, 22 Nov 2015 09:31:10 -0800 Subject: [PATCH 1/3] whitespace cleanup --- src/kademlia/get_item.cpp | 2 +- src/kademlia/node.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/kademlia/get_item.cpp b/src/kademlia/get_item.cpp index 25ca0330b..317b9a151 100644 --- a/src/kademlia/get_item.cpp +++ b/src/kademlia/get_item.cpp @@ -119,7 +119,7 @@ get_item::get_item( , nodes_callback const& ncallback) : find_data(dht_node, item_target_id( std::make_pair(salt.c_str(), int(salt.size())), pk) - , ncallback) + , ncallback) , m_data_callback(dcallback) , m_data(pk, salt) , m_immutable(false) diff --git a/src/kademlia/node.cpp b/src/kademlia/node.cpp index cb06b59c6..8cf23628c 100644 --- a/src/kademlia/node.cpp +++ b/src/kademlia/node.cpp @@ -462,13 +462,13 @@ namespace { void put(std::vector > const& nodes , boost::intrusive_ptr ta) { - ta->set_targets(nodes); + ta->set_targets(nodes); ta->start(); } void put_data_cb(item& i, bool auth - , boost::intrusive_ptr ta - , boost::function f) + , boost::intrusive_ptr ta + , boost::function f) { // call data_callback only when we got authoritative data. if (auth) From 8a984effa7fcd05940adab0930db9c77e725a020 Mon Sep 17 00:00:00 2001 From: Steven Siloti Date: Sun, 22 Nov 2015 09:33:20 -0800 Subject: [PATCH 2/3] allow done() with a non-zero invoke count --- src/kademlia/put_data.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/kademlia/put_data.cpp b/src/kademlia/put_data.cpp index f23f09673..51e7b4556 100644 --- a/src/kademlia/put_data.cpp +++ b/src/kademlia/put_data.cpp @@ -67,7 +67,6 @@ void put_data::set_targets(std::vector > cons void put_data::done() { - if (m_invoke_count != 0) return; m_done = true; #ifndef TORRENT_DISABLE_LOGGING From 1f13343a70ae729aec4e804813674ecf6e929659 Mon Sep 17 00:00:00 2001 From: Steven Siloti Date: Sun, 22 Nov 2015 10:00:29 -0800 Subject: [PATCH 3/3] const correctness --- include/libtorrent/aux_/session_impl.hpp | 2 +- include/libtorrent/kademlia/dht_tracker.hpp | 4 ++-- include/libtorrent/kademlia/get_item.hpp | 2 +- include/libtorrent/kademlia/node.hpp | 8 ++++---- include/libtorrent/kademlia/put_data.hpp | 2 +- src/kademlia/dht_tracker.cpp | 4 ++-- src/kademlia/node.cpp | 10 +++++----- src/session_impl.cpp | 4 ++-- test/test_dht.cpp | 6 +++--- 9 files changed, 21 insertions(+), 21 deletions(-) diff --git a/include/libtorrent/aux_/session_impl.hpp b/include/libtorrent/aux_/session_impl.hpp index 3095dbd4b..510a0f857 100644 --- a/include/libtorrent/aux_/session_impl.hpp +++ b/include/libtorrent/aux_/session_impl.hpp @@ -313,7 +313,7 @@ namespace libtorrent void dht_get_mutable_item(boost::array key , std::string salt = std::string()); - void dht_put_immutable_item(entry data, sha1_hash target); + void dht_put_immutable_item(entry const& data, sha1_hash target); void dht_put_mutable_item(boost::array key , boost::function& diff --git a/include/libtorrent/kademlia/dht_tracker.hpp b/include/libtorrent/kademlia/dht_tracker.hpp index b32e82ccd..0f2749db3 100644 --- a/include/libtorrent/kademlia/dht_tracker.hpp +++ b/include/libtorrent/kademlia/dht_tracker.hpp @@ -104,14 +104,14 @@ namespace libtorrent { namespace dht // for immutable_item. // the callback function will be called when put operation is done. // the int parameter indicates the success numbers of put operation. - void put_item(entry data + void put_item(entry const& data , boost::function cb); // for mutable_item. // the data_cb will be called when we get authoritative mutable_item, // the cb is same as put immutable_item. void put_item(char const* key - , boost::function cb + , boost::function cb , boost::function data_cb, std::string salt = std::string()); // send an arbitrary DHT request directly to a node diff --git a/include/libtorrent/kademlia/get_item.hpp b/include/libtorrent/kademlia/get_item.hpp index 44ed3980d..00df641c9 100644 --- a/include/libtorrent/kademlia/get_item.hpp +++ b/include/libtorrent/kademlia/get_item.hpp @@ -43,7 +43,7 @@ namespace libtorrent { namespace dht class get_item : public find_data { public: - typedef boost::function data_callback; + typedef boost::function data_callback; void got_data(bdecode_node const& v, char const* pk, diff --git a/include/libtorrent/kademlia/node.hpp b/include/libtorrent/kademlia/node.hpp index 40e1b2cba..ae18994c1 100644 --- a/include/libtorrent/kademlia/node.hpp +++ b/include/libtorrent/kademlia/node.hpp @@ -177,12 +177,12 @@ public: void direct_request(udp::endpoint ep, entry& e , boost::function f); - void get_item(sha1_hash const& target, boost::function f); - void get_item(char const* pk, std::string const& salt, boost::function f); + void get_item(sha1_hash const& target, boost::function f); + void get_item(char const* pk, std::string const& salt, boost::function f); - void put_item(sha1_hash const& target, entry& data, boost::function f); + void put_item(sha1_hash const& target, entry const& data, boost::function f); void put_item(char const* pk, std::string const& salt - , boost::function f + , boost::function f , boost::function data_cb); bool verify_token(std::string const& token, char const* info_hash diff --git a/include/libtorrent/kademlia/put_data.hpp b/include/libtorrent/kademlia/put_data.hpp index 23f65b76b..5330581b5 100644 --- a/include/libtorrent/kademlia/put_data.hpp +++ b/include/libtorrent/kademlia/put_data.hpp @@ -53,7 +53,7 @@ class node; struct put_data: traversal_algorithm { - typedef boost::function put_callback; + typedef boost::function put_callback; put_data(node& node, put_callback const& callback); diff --git a/src/kademlia/dht_tracker.cpp b/src/kademlia/dht_tracker.cpp index b20cc3652..29a511835 100644 --- a/src/kademlia/dht_tracker.cpp +++ b/src/kademlia/dht_tracker.cpp @@ -254,7 +254,7 @@ namespace libtorrent { namespace dht m_dht.get_item(key, salt, cb); } - void dht_tracker::put_item(entry data + void dht_tracker::put_item(entry const& data , boost::function cb) { std::string flat_data; @@ -266,7 +266,7 @@ namespace libtorrent { namespace dht } void dht_tracker::put_item(char const* key - , boost::function cb + , boost::function cb , boost::function data_cb, std::string salt) { m_dht.put_item(key, salt, cb, data_cb); diff --git a/src/kademlia/node.cpp b/src/kademlia/node.cpp index 8cf23628c..e4491e058 100644 --- a/src/kademlia/node.cpp +++ b/src/kademlia/node.cpp @@ -423,7 +423,7 @@ void node::direct_request(udp::endpoint ep, entry& e } void node::get_item(sha1_hash const& target - , boost::function f) + , boost::function f) { #ifndef TORRENT_DISABLE_LOGGING if (m_observer) @@ -441,7 +441,7 @@ void node::get_item(sha1_hash const& target } void node::get_item(char const* pk, std::string const& salt - , boost::function f) + , boost::function f) { #ifndef TORRENT_DISABLE_LOGGING if (m_observer) @@ -466,7 +466,7 @@ void put(std::vector > const& nodes ta->start(); } -void put_data_cb(item& i, bool auth +void put_data_cb(item i, bool auth , boost::intrusive_ptr ta , boost::function f) { @@ -480,7 +480,7 @@ void put_data_cb(item& i, bool auth } // namespace -void node::put_item(sha1_hash const& target, entry& data, boost::function f) +void node::put_item(sha1_hash const& target, entry const& data, boost::function f) { #ifndef TORRENT_DISABLE_LOGGING if (m_observer) @@ -505,7 +505,7 @@ void node::put_item(sha1_hash const& target, entry& data, boost::function f + , boost::function f , boost::function data_cb) { #ifndef TORRENT_DISABLE_LOGGING diff --git a/src/session_impl.cpp b/src/session_impl.cpp index c970c131a..03fd963b5 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -5654,7 +5654,7 @@ retry: alerts.emplace_alert(target, num); } - void on_dht_put_mutable_item(alert_manager& alerts, dht::item& i, int num) + void on_dht_put_mutable_item(alert_manager& alerts, dht::item const& i, int num) { boost::array sig = i.sig(); boost::array pk = i.pk(); @@ -5694,7 +5694,7 @@ retry: } // anonymous namespace - void session_impl::dht_put_immutable_item(entry data, sha1_hash target) + void session_impl::dht_put_immutable_item(entry const& data, sha1_hash target) { if (!m_dht) return; m_dht->put_item(data, boost::bind(&on_dht_put_immutable_item, boost::ref(m_alerts) diff --git a/test/test_dht.cpp b/test/test_dht.cpp index 6a8ce602d..1d5d2d108 100644 --- a/test/test_dht.cpp +++ b/test/test_dht.cpp @@ -481,7 +481,7 @@ std::vector g_got_items; dht::item g_put_item; int g_put_count; -void get_mutable_item_cb(dht::item& i, bool a) +void get_mutable_item_cb(dht::item const& i, bool a) { if (!a) return; if (!i.empty()) @@ -498,12 +498,12 @@ void put_mutable_item_data_cb(dht::item& i) g_put_count++; } -void put_mutable_item_cb(dht::item&, int num, int expect) +void put_mutable_item_cb(dht::item const&, int num, int expect) { TEST_EQUAL(num, expect); } -void get_immutable_item_cb(dht::item& i) +void get_immutable_item_cb(dht::item const& i) { if (!i.empty()) g_got_items.push_back(i);