From c1b0c70c238bd821717b22470add6f74f9ae80c1 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 19 Aug 2018 16:35:10 +0200 Subject: [PATCH 1/7] fall back to copy+remove if rename_file fails --- ChangeLog | 1 + src/storage.cpp | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1d32f234d..9f0000cec 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + * fall back to copy+remove if rename_file fails * improve handling of filesystems not supporting fallocate() * force-proxy no longer disables DHT * improve connect-boost feature, to make new torrents quickly connect peers diff --git a/src/storage.cpp b/src/storage.cpp index 19108008c..7f6a7516a 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -778,9 +778,18 @@ namespace libtorrent if (ec) { - ec.file = index; - ec.operation = storage_error::rename; - return; + ec.ec.clear(); + copy_file(old_name, new_path, ec.ec); + + if (ec) + { + ec.file = index; + ec.operation = storage_error::rename; + return; + } + + error_code ignore; + remove(old_name, ignore); } } else if (ec.ec) From 269b71324eb55e18348a1e3f1c88f560abf7222d Mon Sep 17 00:00:00 2001 From: arvidn Date: Mon, 27 Aug 2018 10:43:32 +0200 Subject: [PATCH 2/7] improve log statement when not unchoking a peer --- src/peer_connection.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 3b8912bed..5962ae5de 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -1738,8 +1738,10 @@ namespace libtorrent else { peer_log(peer_log_alert::info, "UNCHOKE", "did not unchoke, the number of uploads (%d) " - "is more than or equal to the limit (%d)" - , m_ses.num_uploads(), m_settings.get_int(settings_pack::unchoke_slots_limit)); + "is more than or equal to the available slots (%d), limit (%d)" + , int(m_counters[counters::num_peers_up_unchoked]) + , int(m_counters[counters::num_unchoke_slots]) + , m_settings.get_int(settings_pack::unchoke_slots_limit)); } #endif } From 7c837be6511435a8415e05fffee501d5764d9e92 Mon Sep 17 00:00:00 2001 From: arvidn Date: Sun, 26 Aug 2018 22:15:05 +0200 Subject: [PATCH 3/7] make the print function for entry actually be json-like. when logging bencode entries, print it all on a single line. add test for entry print function --- include/libtorrent/entry.hpp | 3 +- src/bt_peer_connection.cpp | 4 +- src/entry.cpp | 96 +++++++++++++++++++----------------- test/test_bencoding.cpp | 81 ++++++++++++++++++++++++++++++ 4 files changed, 135 insertions(+), 49 deletions(-) diff --git a/include/libtorrent/entry.hpp b/include/libtorrent/entry.hpp index de09d9fbc..20bf88cda 100644 --- a/include/libtorrent/entry.hpp +++ b/include/libtorrent/entry.hpp @@ -256,6 +256,7 @@ namespace libtorrent // returns a pretty-printed string representation // of the bencoded structure, with JSON-style syntax std::string to_string() const; + std::string to_string(bool single_line) const; protected: @@ -265,7 +266,7 @@ namespace libtorrent private: - void to_string_impl(std::string& out, int indent) const; + void to_string_impl(std::string& out, int indent, bool single_line) const; #if (defined(_MSC_VER) && _MSC_VER < 1310) || TORRENT_COMPLETE_TYPES_REQUIRED // workaround for msvc-bug. diff --git a/src/bt_peer_connection.cpp b/src/bt_peer_connection.cpp index c29add0aa..fdf1900bc 100644 --- a/src/bt_peer_connection.cpp +++ b/src/bt_peer_connection.cpp @@ -1814,7 +1814,7 @@ namespace libtorrent #ifndef TORRENT_DISABLE_LOGGING peer_log(peer_log_alert::incoming_message, "EXTENDED_HANDSHAKE" - , "%s", print_entry(root).c_str()); + , "%s", print_entry(root, true).c_str()); #endif for (extension_list_t::iterator i = m_extensions.begin(); @@ -2355,7 +2355,7 @@ namespace libtorrent #ifndef TORRENT_DISABLE_LOGGING peer_log(peer_log_alert::outgoing_message, "EXTENDED_HANDSHAKE" - , "%s", handshake.to_string().c_str()); + , "%s", handshake.to_string(true).c_str()); #endif } #endif diff --git a/src/entry.cpp b/src/entry.cpp index c54bf305b..2e0991515 100644 --- a/src/entry.cpp +++ b/src/entry.cpp @@ -653,83 +653,87 @@ namespace libtorrent std::string entry::to_string() const { std::string ret; - to_string_impl(ret, 0); + to_string_impl(ret, 0, false); return ret; } - void entry::to_string_impl(std::string& out, int indent) const + std::string entry::to_string(bool single_line) const + { + std::string ret; + to_string_impl(ret, 0, single_line); + return ret; + } + +namespace { + bool is_binary(std::string const& str) + { + for (std::string::const_iterator i = str.begin(); i != str.end(); ++i) + { + if (!is_print(static_cast(*i))) + return true; + } + return false; + } + + void add_indent(std::string& out, int const indent) + { + out.resize(out.size() + indent, ' '); + } +} + + void entry::to_string_impl(std::string& out, int const indent + , bool const single_line) const { TORRENT_ASSERT(indent >= 0); - for (int i = 0; i < indent; ++i) out += " "; switch (m_type) { case int_t: out += libtorrent::to_string(integer()).elems; - out += "\n"; break; case string_t: { - bool binary_string = false; - for (std::string::const_iterator i = string().begin(); i != string().end(); ++i) - { - if (!is_print(static_cast(*i))) - { - binary_string = true; - break; - } - } - if (binary_string) - { - out += to_hex(string()); - out += "\n"; - } - else - { - out += string(); - out += "\n"; - } + out += "'"; + if (is_binary(string())) out += to_hex(string()); + else out += string(); + out += "'"; } break; case list_t: { - out += "list\n"; + out += single_line ? "[ " : "[\n"; + bool first = true; for (list_type::const_iterator i = list().begin(); i != list().end(); ++i) { - i->to_string_impl(out, indent+1); + if (!first) out += single_line ? ", " : ",\n"; + first = false; + if (!single_line) add_indent(out, indent+1); + i->to_string_impl(out, indent+1, single_line); } + out += " ]"; } break; case dictionary_t: { - out += "dictionary\n"; + out += single_line ? "{ " : "{\n"; + bool first = true; for (dictionary_type::const_iterator i = dict().begin(); i != dict().end(); ++i) { - bool binary_string = false; - for (std::string::const_iterator k = i->first.begin(); k != i->first.end(); ++k) - { - if (!is_print(static_cast(*k))) - { - binary_string = true; - break; - } - } - for (int j = 0; j < indent+1; ++j) out += " "; - out += "["; - if (binary_string) out += to_hex(i->first); + if (!first) out += single_line ? ", " : ",\n"; + first = false; + if (!single_line) add_indent(out, indent+1); + out += "'"; + if (is_binary(i->first)) out += to_hex(i->first); else out += i->first; - out += "]"; + out += "': "; - if (i->second.type() != entry::string_t - && i->second.type() != entry::int_t) - out += "\n"; - else out += " "; - i->second.to_string_impl(out, indent+2); + i->second.to_string_impl(out, indent+2, single_line); } + out += " }"; } break; case preformatted_t: - out += "\n"; + out += ""; break; case undefined_t: default: - out += "\n"; + out += ""; } } } diff --git a/test/test_bencoding.cpp b/test/test_bencoding.cpp index f94f953d0..c36321406 100644 --- a/test/test_bencoding.cpp +++ b/test/test_bencoding.cpp @@ -134,6 +134,87 @@ TORRENT_TEST(undefined_node2) TEST_EQUAL(encode(e), "d4:info0:e"); } +TORRENT_TEST(print_dict_single_line) +{ + entry e; + e["foo"] = "bar"; + e["bar"] = "foo"; + TEST_EQUAL(e.to_string(true), "{ 'bar': 'foo', 'foo': 'bar' }"); +} + +TORRENT_TEST(print_dict) +{ + entry e; + e["foo"] = "bar"; + e["bar"] = "foo"; + TEST_EQUAL(e.to_string(), "{\n 'bar': 'foo',\n 'foo': 'bar' }"); +} + +TORRENT_TEST(print_list_single_line) +{ + entry e; + e.list().push_back(entry("foo")); + e.list().push_back(entry("bar")); + TEST_EQUAL(e.to_string(true), "[ 'foo', 'bar' ]"); +} + + +TORRENT_TEST(print_list) +{ + entry e; + e.list().push_back(entry("foo")); + e.list().push_back(entry("bar")); + TEST_EQUAL(e.to_string(), "[\n 'foo',\n 'bar' ]"); +} + +TORRENT_TEST(print_int_single_line) +{ + entry e(1337); + TEST_EQUAL(e.to_string(true), "1337"); +} + +TORRENT_TEST(print_int) +{ + entry e(1337); + TEST_EQUAL(e.to_string(), "1337"); +} + +TORRENT_TEST(print_string_single_line) +{ + entry e("foobar"); + TEST_EQUAL(e.to_string(true), "'foobar'"); +} + +TORRENT_TEST(print_string) +{ + entry e("foobar"); + TEST_EQUAL(e.to_string(), "'foobar'"); +} + +TORRENT_TEST(print_deep_dict_single_line) +{ + entry e; + e["strings"].list().push_back(entry("foo")); + e["strings"].list().push_back(entry("bar")); + e["ints"].list().push_back(entry(1)); + e["ints"].list().push_back(entry(2)); + e["ints"].list().push_back(entry(3)); + e["a"] = "foobar"; + TEST_EQUAL(e.to_string(true), "{ 'a': 'foobar', 'ints': [ 1, 2, 3 ], 'strings': [ 'foo', 'bar' ] }"); +} + +TORRENT_TEST(print_deep_dict) +{ + entry e; + e["strings"].list().push_back(entry("foo")); + e["strings"].list().push_back(entry("bar")); + e["ints"].list().push_back(entry(1)); + e["ints"].list().push_back(entry(2)); + e["ints"].list().push_back(entry(3)); + e["a"] = "foobar"; + TEST_EQUAL(e.to_string(), "{\n 'a': 'foobar',\n 'ints': [\n 1,\n 2,\n 3 ],\n 'strings': [\n 'foo',\n 'bar' ] }"); +} + #ifndef TORRENT_NO_DEPRECATE TORRENT_TEST(lazy_entry) { From 2e313de898d278929eb3dba982cc519f2c4b2739 Mon Sep 17 00:00:00 2001 From: arvidn Date: Tue, 28 Aug 2018 10:20:40 +0200 Subject: [PATCH 4/7] remove unused member variables in torrent object --- include/libtorrent/torrent.hpp | 6 ------ src/torrent.cpp | 2 -- 2 files changed, 8 deletions(-) diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 1fdee65ec..6d22d798a 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -1622,12 +1622,6 @@ namespace libtorrent // the DHT bool m_announce_to_dht:1; - // these represent whether or not this torrent is counted - // in the total counters of active seeds and downloads - // in the session. - bool m_is_active_download:1; - bool m_is_active_finished:1; - // even if we're not built to support SSL torrents, // remember that this is an SSL torrent, so that we don't // accidentally start seeding it without any authentication. diff --git a/src/torrent.cpp b/src/torrent.cpp index 8c0f1f6d6..a657d943e 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -298,8 +298,6 @@ namespace libtorrent , m_connect_boost_counter(static_cast(settings().get_int(settings_pack::torrent_connect_boost))) , m_incomplete(0xffffff) , m_announce_to_dht((p.flags & add_torrent_params::flag_paused) == 0) - , m_is_active_download(false) - , m_is_active_finished(false) , m_ssl_torrent(false) , m_deleted(false) , m_pinned((p.flags & add_torrent_params::flag_pinned) != 0) From 214ace3efeb5bf90540064d59ec872200303eb5b Mon Sep 17 00:00:00 2001 From: arvidn Date: Mon, 27 Aug 2018 21:10:23 +0200 Subject: [PATCH 5/7] raise default value for active_limit to 500, since it's supposed to be an upper sanity check limit --- ChangeLog | 1 + src/session.cpp | 2 +- src/settings_pack.cpp | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9f0000cec..657cf238b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + * raise default setting for active_limit * fall back to copy+remove if rename_file fails * improve handling of filesystems not supporting fallocate() * force-proxy no longer disables DHT diff --git a/src/session.cpp b/src/session.cpp index 76000de52..8fb978233 100644 --- a/src/session.cpp +++ b/src/session.cpp @@ -270,7 +270,7 @@ namespace { set.set_int(settings_pack::peer_timeout, 20); set.set_int(settings_pack::inactivity_timeout, 20); - set.set_int(settings_pack::active_limit, 2000); + set.set_int(settings_pack::active_limit, 20000); set.set_int(settings_pack::active_tracker_limit, 2000); set.set_int(settings_pack::active_dht_limit, 600); set.set_int(settings_pack::active_seeds, 2000); diff --git a/src/settings_pack.cpp b/src/settings_pack.cpp index 4b31bab12..6fbe1aca6 100644 --- a/src/settings_pack.cpp +++ b/src/settings_pack.cpp @@ -284,7 +284,7 @@ namespace libtorrent SET(active_dht_limit, 88, 0), SET(active_tracker_limit, 1600, 0), SET(active_lsd_limit, 60, 0), - SET(active_limit, 15, &session_impl::trigger_auto_manage), + SET(active_limit, 500, &session_impl::trigger_auto_manage), SET_NOPREV(active_loaded_limit, 0, &session_impl::trigger_auto_manage), SET(auto_manage_interval, 30, 0), SET(seed_time_limit, 24 * 60 * 60, 0), From 2647ca2412277f989fcc6e4bb8d79cdd7dab9509 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sat, 18 Aug 2018 23:25:02 +0200 Subject: [PATCH 6/7] add option to ignore min-interval from tracker, when force-reannouncing a tracker --- ChangeLog | 1 + bindings/python/src/torrent_handle.cpp | 8 ++++++-- include/libtorrent/torrent.hpp | 2 +- include/libtorrent/torrent_handle.hpp | 13 +++++++++++++ include/libtorrent/tracker_manager.hpp | 2 +- src/torrent.cpp | 15 ++++++++++++--- src/torrent_handle.cpp | 12 +++++++++--- src/tracker_manager.cpp | 2 -- 8 files changed, 43 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 657cf238b..c9b54c16b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + * add option to ignore min-interval from trackers on force-reannounce * raise default setting for active_limit * fall back to copy+remove if rename_file fails * improve handling of filesystems not supporting fallocate() diff --git a/bindings/python/src/torrent_handle.cpp b/bindings/python/src/torrent_handle.cpp index c440aa46a..7673fedfd 100644 --- a/bindings/python/src/torrent_handle.cpp +++ b/bindings/python/src/torrent_handle.cpp @@ -393,7 +393,7 @@ void add_piece(torrent_handle& th, int piece, char const *data, int flags) void bind_torrent_handle() { // arguments are: number of seconds and tracker index - void (torrent_handle::*force_reannounce0)(int, int) const = &torrent_handle::force_reannounce; + void (torrent_handle::*force_reannounce0)(int, int, int) const = &torrent_handle::force_reannounce; #ifndef TORRENT_NO_DEPRECATE bool (torrent_handle::*super_seeding0)() const = &torrent_handle::super_seeding; @@ -496,7 +496,7 @@ void bind_torrent_handle() .def("save_resume_data", _(&torrent_handle::save_resume_data), arg("flags") = 0) .def("need_save_resume_data", _(&torrent_handle::need_save_resume_data)) .def("force_reannounce", _(force_reannounce0) - , (arg("seconds") = 0, arg("tracker_idx") = -1)) + , (arg("seconds") = 0, arg("tracker_idx") = -1, arg("flags") = 0)) #ifndef TORRENT_DISABLE_DHT .def("force_dht_announce", _(&torrent_handle::force_dht_announce)) #endif @@ -558,6 +558,10 @@ void bind_torrent_handle() .value("only_if_modified", torrent_handle::only_if_modified) ; + enum_("reannounce_flags_t") + .value("ignore_min_interval", torrent_handle::ignore_min_interval) + ; + enum_("deadline_flags") .value("alert_when_available", torrent_handle::alert_when_available) ; diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 6d22d798a..92b5d59cc 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -731,7 +731,7 @@ namespace libtorrent void do_connect_boost(); // forcefully sets next_announce to the current time - void force_tracker_request(time_point, int tracker_idx); + void force_tracker_request(time_point, int tracker_idx, int flags); void scrape_tracker(int idx, bool user_triggered); void announce_with_tracker(boost::uint8_t e = tracker_request::none); diff --git a/include/libtorrent/torrent_handle.hpp b/include/libtorrent/torrent_handle.hpp index a23e7c6ca..95be00d48 100644 --- a/include/libtorrent/torrent_handle.hpp +++ b/include/libtorrent/torrent_handle.hpp @@ -1092,6 +1092,15 @@ namespace libtorrent void prioritize_files(std::vector const& files) const; std::vector file_priorities() const; + // flags to be used with force_reannounce + enum reannounce_flags_t + { + // by default, force-reannounce will still honor the min-interval + // published by the tracker. If this flag is set, it will be ignored + // and the tracker is announced immediately. + ignore_min_interval = 1 + }; + // ``force_reannounce()`` will force this torrent to do another tracker // request, to receive new peers. The ``seconds`` argument specifies how // many seconds from now to issue the tracker announces. @@ -1104,9 +1113,13 @@ namespace libtorrent // The ``tracker_index`` argument specifies which tracker to re-announce. // If set to -1 (which is the default), all trackers are re-announce. // + // The ``flags`` argument can be used to affect the re-announce. See + // reannounce_flags_t. + // // ``force_dht_announce`` will announce the torrent to the DHT // immediately. void force_reannounce(int seconds = 0, int tracker_index = -1) const; + void force_reannounce(int seconds, int tracker_index, int flags) const; void force_dht_announce() const; #ifndef TORRENT_NO_DEPRECATE diff --git a/include/libtorrent/tracker_manager.hpp b/include/libtorrent/tracker_manager.hpp index 9d1414eeb..6e964f874 100644 --- a/include/libtorrent/tracker_manager.hpp +++ b/include/libtorrent/tracker_manager.hpp @@ -194,7 +194,7 @@ namespace libtorrent { tracker_response() : interval(1800) - , min_interval(120) + , min_interval(1) , complete(-1) , incomplete(-1) , downloaders(-1) diff --git a/src/torrent.cpp b/src/torrent.cpp index a657d943e..838c04061 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -3590,10 +3590,12 @@ namespace { } debug_log("TRACKER RESPONSE\n" "interval: %d\n" + "min-interval: %d\n" "external ip: %s\n" "resolved to: %s\n" "we connected to: %s\n" , interval + , resp.min_interval , print_address(resp.external_ip).c_str() , resolved_to.c_str() , print_address(tracker_ip).c_str()); @@ -3815,7 +3817,8 @@ namespace { // this is the entry point for the client to force a re-announce. It's // considered a client-initiated announce (as opposed to the regular ones, // issued by libtorrent) - void torrent::force_tracker_request(time_point t, int tracker_idx) + void torrent::force_tracker_request(time_point const t, int const tracker_idx + , int const flags) { if (is_paused()) return; if (tracker_idx == -1) @@ -3823,7 +3826,10 @@ namespace { for (std::vector::iterator i = m_trackers.begin() , end(m_trackers.end()); i != end; ++i) { - i->next_announce = (std::max)(t, i->min_announce) + seconds(1); + i->next_announce = (flags & torrent_handle::ignore_min_interval) + ? t + seconds(1) + : (std::max)(t, i->min_announce) + seconds(1); + i->min_announce = i->next_announce; i->triggered_manually = true; } } @@ -3833,7 +3839,10 @@ namespace { if (tracker_idx < 0 || tracker_idx >= int(m_trackers.size())) return; announce_entry& e = m_trackers[tracker_idx]; - e.next_announce = (std::max)(t, e.min_announce) + seconds(1); + e.next_announce = (flags & torrent_handle::ignore_min_interval) + ? t + seconds(1) + : (std::max)(t, e.min_announce) + seconds(1); + e.min_announce = e.next_announce; e.triggered_manually = true; } update_tracker_timer(clock_type::now()); diff --git a/src/torrent_handle.cpp b/src/torrent_handle.cpp index a152f164e..30c429724 100644 --- a/src/torrent_handle.cpp +++ b/src/torrent_handle.cpp @@ -709,8 +709,8 @@ namespace libtorrent void torrent_handle::force_reannounce( boost::posix_time::time_duration duration) const { - TORRENT_ASYNC_CALL2(force_tracker_request, aux::time_now() - + seconds(duration.total_seconds()), -1); + TORRENT_ASYNC_CALL3(force_tracker_request, aux::time_now() + + seconds(duration.total_seconds()), -1, 0); } #endif @@ -723,7 +723,13 @@ namespace libtorrent void torrent_handle::force_reannounce(int s, int idx) const { - TORRENT_ASYNC_CALL2(force_tracker_request, aux::time_now() + seconds(s), idx); + TORRENT_ASYNC_CALL3(force_tracker_request, aux::time_now() + seconds(s), idx, 0); + } + + void torrent_handle::force_reannounce(int s, int idx, int flags) const + { + TORRENT_ASYNC_CALL3(force_tracker_request, aux::time_now() + seconds(s) + , idx, flags); } void torrent_handle::file_status(std::vector& status) const diff --git a/src/tracker_manager.cpp b/src/tracker_manager.cpp index 604070032..06b850e56 100644 --- a/src/tracker_manager.cpp +++ b/src/tracker_manager.cpp @@ -279,8 +279,6 @@ namespace libtorrent TORRENT_ASSERT(req.num_want >= 0); TORRENT_ASSERT(!m_abort || req.event == tracker_request::stopped); if (m_abort && req.event != tracker_request::stopped) return; - if (req.event == tracker_request::stopped) - req.num_want = 0; #ifndef TORRENT_DISABLE_LOGGING boost::shared_ptr cb = c.lock(); From 51003d11cafc76970f60de65ac0997c9fda1d6c2 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Mon, 3 Sep 2018 09:54:03 +0200 Subject: [PATCH 7/7] add assert to storage --- src/disk_io_thread.cpp | 23 +++++++++++++++++++++++ src/storage.cpp | 1 + test/test_remove_torrent.cpp | 2 +- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index de7c8b0fd..2c1acacf1 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -1102,6 +1102,18 @@ namespace libtorrent boost::shared_ptr storage = j->storage; +#ifdef TORRENT_EXPENSIVE_INVARIANT_CHECKS + if (storage) + { + mutex::scoped_lock l(m_cache_mutex); + boost::unordered_set const& pieces = storage->cached_pieces(); + for (boost::unordered_set::const_iterator i = pieces.begin() + , end(pieces.end()); i != end; ++i) + { + TORRENT_ASSERT((*i)->storage == storage); + } + } +#endif // TODO: instead of doing this. pass in the settings to each storage_interface // call. Each disk thread could hold its most recent understanding of the settings // in a shared_ptr, and update it every time it wakes up from a job. That way @@ -1796,6 +1808,17 @@ namespace libtorrent j->storage = storage->shared_from_this(); j->callback = handler; +#ifdef TORRENT_EXPENSIVE_INVARIANT_CHECKS + { + mutex::scoped_lock l(m_cache_mutex); + boost::unordered_set const& pieces = storage->cached_pieces(); + for (boost::unordered_set::const_iterator i = pieces.begin() + , end(pieces.end()); i != end; ++i) + { + TORRENT_ASSERT((*i)->storage.get() == storage); + } + } +#endif add_fence_job(storage, j); } diff --git a/src/storage.cpp b/src/storage.cpp index 7f6a7516a..c65611e51 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -1765,6 +1765,7 @@ namespace libtorrent void storage_piece_set::remove_piece(cached_piece_entry* p) { + TORRENT_ASSERT(p->storage.get() == this); TORRENT_ASSERT(p->in_storage == true); TORRENT_ASSERT(m_cached_pieces.count(p) == 1); m_cached_pieces.erase(p); diff --git a/test/test_remove_torrent.cpp b/test/test_remove_torrent.cpp index b5e0e6154..8fe81a1a0 100644 --- a/test/test_remove_torrent.cpp +++ b/test/test_remove_torrent.cpp @@ -129,7 +129,7 @@ void test_remove_torrent(int const remove_options || st2.state == torrent_status::checking_resume_data); // if nothing is being transferred after 3 seconds, we're failing the test - if (st1.upload_payload_rate == 0 && i > 30) + if (st1.total_payload_upload == 0 && i > 30) { TEST_ERROR("no transfer"); return;