From f95f5b05c268b31c691e31b46b3f86e55f88f7cc Mon Sep 17 00:00:00 2001 From: arvidn Date: Mon, 20 Mar 2017 23:58:08 -0400 Subject: [PATCH 1/5] fix issue where torrent_status::num_seeds could be negative --- ChangeLog | 1 + src/torrent.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 6084d1a4d..14499ed79 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + * fix issue where torrent_status::num_seeds could be negative * document deprecation of dynamic loading/unloading of torrents * include user-agent in tracker announces in anonymous_mode for private torrents * add support for IPv6 peers from udp trackers diff --git a/src/torrent.cpp b/src/torrent.cpp index eca8110d5..ded965319 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -12235,7 +12235,7 @@ namespace libtorrent st->pieces.resize(num_pieces, false); } st->num_pieces = num_have(); - st->num_seeds = num_seeds() - int(m_num_connecting_seeds); + st->num_seeds = num_seeds(); if ((flags & torrent_handle::query_distributed_copies) && m_picker.get()) { boost::tie(st->distributed_full_copies, st->distributed_fraction) = From 4d397f5ebfa09c6840475de6be9606f9750f0846 Mon Sep 17 00:00:00 2001 From: arvidn Date: Tue, 21 Mar 2017 08:17:28 -0400 Subject: [PATCH 2/5] fix minor robustness issue in DHT bootstrap logic --- ChangeLog | 1 + include/libtorrent/kademlia/refresh.hpp | 2 -- src/kademlia/node.cpp | 3 --- src/kademlia/refresh.cpp | 9 --------- 4 files changed, 1 insertion(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 14499ed79..f87feb3e6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + * fix minor robustness issue in DHT bootstrap logic * fix issue where torrent_status::num_seeds could be negative * document deprecation of dynamic loading/unloading of torrents * include user-agent in tracker announces in anonymous_mode for private torrents diff --git a/include/libtorrent/kademlia/refresh.hpp b/include/libtorrent/kademlia/refresh.hpp index e0d9a46e2..e6b58bdac 100644 --- a/include/libtorrent/kademlia/refresh.hpp +++ b/include/libtorrent/kademlia/refresh.hpp @@ -55,8 +55,6 @@ public: observer_ptr new_observer(void* ptr, udp::endpoint const& ep , node_id const& id); - void trim_seed_nodes(); - protected: virtual bool invoke(observer_ptr o); diff --git a/src/kademlia/node.cpp b/src/kademlia/node.cpp index a268efd94..059d7490b 100644 --- a/src/kademlia/node.cpp +++ b/src/kademlia/node.cpp @@ -218,9 +218,6 @@ void node::bootstrap(std::vector const& nodes r->add_entry(node_id(0), *i, observer::flag_initial); } - // make us start as far away from our node ID as possible - r->trim_seed_nodes(); - #ifndef TORRENT_DISABLE_LOGGING if (m_observer) m_observer->log(dht_logger::node, "bootstrapping with %d nodes", count); diff --git a/src/kademlia/refresh.cpp b/src/kademlia/refresh.cpp index e6aa5c70f..a41648551 100644 --- a/src/kademlia/refresh.cpp +++ b/src/kademlia/refresh.cpp @@ -89,15 +89,6 @@ bootstrap::bootstrap( char const* bootstrap::name() const { return "bootstrap"; } -void bootstrap::trim_seed_nodes() -{ - // when we're bootstrapping, we want to start as far away from our ID as - // possible, to cover as much as possible of the ID space. So, remove all - // nodes except for the 32 that are farthest away from us - if (m_results.size() > 32) - m_results.erase(m_results.begin(), m_results.end() - 32); -} - void bootstrap::done() { #ifndef TORRENT_DISABLE_LOGGING From 2e367ea53b1ce36d42eec73d12056ca4cd8029a4 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Thu, 23 Mar 2017 08:31:10 -0400 Subject: [PATCH 3/5] fix python binding for parse_magnet_uri (#1838) fix python binding for parse_magnet_uri --- ChangeLog | 1 + bindings/python/src/magnet_uri.cpp | 2 +- bindings/python/test.py | 9 +++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index f87feb3e6..19c4acb5e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + * fix python binding for parse_magnet_uri * fix minor robustness issue in DHT bootstrap logic * fix issue where torrent_status::num_seeds could be negative * document deprecation of dynamic loading/unloading of torrents diff --git a/bindings/python/src/magnet_uri.cpp b/bindings/python/src/magnet_uri.cpp index f3f087fc3..52e763b17 100644 --- a/bindings/python/src/magnet_uri.cpp +++ b/bindings/python/src/magnet_uri.cpp @@ -58,7 +58,7 @@ namespace { , end(p.dht_nodes.end()); i != end; ++i) tracker_list.append(boost::python::make_tuple(i->first, i->second)); ret["dht_nodes"] = nodes_list; - ret["info_hash"] = p.info_hash; + ret["info_hash"] = p.info_hash.to_string(); ret["name"] = p.name; ret["save_path"] = p.save_path; ret["storage_mode"] = p.storage_mode; diff --git a/bindings/python/test.py b/bindings/python/test.py index da4f8932c..5abc13355 100644 --- a/bindings/python/test.py +++ b/bindings/python/test.py @@ -256,6 +256,15 @@ class test_sha1hash(unittest.TestCase): s = lt.sha1_hash(binascii.unhexlify(h)) self.assertEqual(h, str(s)) +class test_magnet_link(unittest.TestCase): + + def test_parse_magnet_uri(self): + ses = lt.session({}) + magnet = 'magnet:?xt=urn:btih:C6EIF4CCYDBTIJVG3APAGM7M4NDONCTI' + p = lt.parse_magnet_uri(magnet) + p['save_path'] = '.' + h = ses.add_torrent(p) + self.assertEqual(str(h.info_hash()), '178882f042c0c33426a6d81e0333ece346e68a68') class test_session(unittest.TestCase): From 9ea9075b2afb516f82bbee9c4914a8ca905cf259 Mon Sep 17 00:00:00 2001 From: arvidn Date: Sun, 26 Mar 2017 09:29:41 -0400 Subject: [PATCH 4/5] remove support for adding torrents by http URLs in client_test (since that's deprecated) --- examples/client_test.cpp | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/examples/client_test.cpp b/examples/client_test.cpp index 92ce9583f..5ae070191 100644 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -1213,7 +1213,7 @@ int main(int argc, char* argv[]) if (argc == 1) { - fprintf(stderr, "usage: client_test [OPTIONS] [TORRENT|MAGNETURL|URL]\n\n" + fprintf(stderr, "usage: client_test [OPTIONS] [TORRENT|MAGNETURL]\n\n" "OPTIONS:\n" "\n CLIENT OPTIONS\n" " -f logs all events to the given file\n" @@ -1590,9 +1590,7 @@ int main(int argc, char* argv[]) for (std::vector::iterator i = torrents.begin() , end(torrents.end()); i != end; ++i) { - if (std::strstr(i->c_str(), "http://") == i->c_str() - || std::strstr(i->c_str(), "https://") == i->c_str() - || std::strstr(i->c_str(), "magnet:") == i->c_str()) + if (std::strstr(i->c_str(), "magnet:") == i->c_str()) { add_torrent_params p; if (seed_mode) p.flags |= add_torrent_params::flag_seed_mode; @@ -1603,19 +1601,16 @@ int main(int argc, char* argv[]) p.url = *i; std::vector buf; - if (std::strstr(i->c_str(), "magnet:") == i->c_str()) - { - add_torrent_params tmp; - ec.clear(); - parse_magnet_uri(*i, tmp, ec); + add_torrent_params tmp; + ec.clear(); + parse_magnet_uri(*i, tmp, ec); - if (ec) continue; + if (ec) continue; - std::string filename = path_append(save_path, path_append(".resume" - , to_hex(tmp.info_hash.to_string()) + ".resume")); + std::string filename = path_append(save_path, path_append(".resume" + , to_hex(tmp.info_hash.to_string()) + ".resume")); - load_file(filename, p.resume_data, ec); - } + load_file(filename, p.resume_data, ec); printf("adding URL: %s\n", i->c_str()); ses.async_add_torrent(p); From 910ccc528f20cd735cec1407b4f3ef361625a3df Mon Sep 17 00:00:00 2001 From: arvidn Date: Sun, 26 Mar 2017 19:19:20 -0400 Subject: [PATCH 5/5] deprecate torrent_added_alert in favor of add_torrent_alert --- ChangeLog | 1 + bindings/python/src/alert.cpp | 2 ++ include/libtorrent/alert_types.hpp | 6 +++++- simulation/test_swarm.cpp | 2 +- simulation/test_torrent_status.cpp | 2 +- simulation/test_transfer.cpp | 2 +- src/alert.cpp | 2 ++ src/session_impl.cpp | 2 ++ test/test_alert_manager.cpp | 34 +++++++++++++++--------------- 9 files changed, 32 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index 19c4acb5e..84217751a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + * deprecate torrent_added_alert (in favor of add_torrent_alert) * fix python binding for parse_magnet_uri * fix minor robustness issue in DHT bootstrap logic * fix issue where torrent_status::num_seeds could be negative diff --git a/bindings/python/src/alert.cpp b/bindings/python/src/alert.cpp index 9dc16fc9e..8572c7e63 100644 --- a/bindings/python/src/alert.cpp +++ b/bindings/python/src/alert.cpp @@ -243,9 +243,11 @@ void bind_alert() .def("tracker_url", &tracker_alert::tracker_url) ; +#ifndef TORRENT_NO_DEPRECATE class_, noncopyable>( "torrent_added_alert", no_init) ; +#endif class_, noncopyable>( "torrent_removed_alert", no_init) diff --git a/include/libtorrent/alert_types.hpp b/include/libtorrent/alert_types.hpp index 027b2c8ce..93af05996 100644 --- a/include/libtorrent/alert_types.hpp +++ b/include/libtorrent/alert_types.hpp @@ -195,11 +195,14 @@ namespace libtorrent #define TORRENT_DEFINE_ALERT_PRIO(name, seq) \ TORRENT_DEFINE_ALERT_IMPL(name, seq, 1) +#ifndef TORRENT_NO_DEPRECATE // The ``torrent_added_alert`` is posted once every time a torrent is successfully // added. It doesn't contain any members of its own, but inherits the torrent handle // from its base class. // It's posted when the ``status_notification`` bit is set in the alert_mask. - struct TORRENT_EXPORT torrent_added_alert TORRENT_FINAL : torrent_alert + // deprecated in 1.1.3 + // use add_torrent_alert instead + struct TORRENT_DEPRECATED_EXPORT torrent_added_alert TORRENT_FINAL : torrent_alert { // internal torrent_added_alert(aux::stack_allocator& alloc, torrent_handle const& h); @@ -208,6 +211,7 @@ namespace libtorrent static const int static_category = alert::status_notification; virtual std::string message() const TORRENT_OVERRIDE; }; +#endif // The ``torrent_removed_alert`` is posted whenever a torrent is removed. Since // the torrent handle in its base class will always be invalid (since the torrent diff --git a/simulation/test_swarm.cpp b/simulation/test_swarm.cpp index c2e94cb4e..378061d29 100644 --- a/simulation/test_swarm.cpp +++ b/simulation/test_swarm.cpp @@ -195,7 +195,7 @@ void test_stop_start_download(swarm_test type, bool graceful) // on alert , [&](lt::alert const* a, lt::session& ses) { - if (lt::alert_cast(a)) + if (lt::alert_cast(a)) add_extra_peers(ses); if (auto tp = lt::alert_cast(a)) diff --git a/simulation/test_torrent_status.cpp b/simulation/test_torrent_status.cpp index c5e979d51..763404b36 100644 --- a/simulation/test_torrent_status.cpp +++ b/simulation/test_torrent_status.cpp @@ -54,7 +54,7 @@ TORRENT_TEST(status_timers) , [](lt::add_torrent_params& params) {} // on alert , [&](lt::alert const* a, lt::session& ses) { - if (auto ta = alert_cast(a)) + if (auto ta = alert_cast(a)) { TEST_CHECK(!handle.is_valid()); start_time = lt::clock_type::now(); diff --git a/simulation/test_transfer.cpp b/simulation/test_transfer.cpp index 5b732e170..3752faedc 100644 --- a/simulation/test_transfer.cpp +++ b/simulation/test_transfer.cpp @@ -110,7 +110,7 @@ void run_test( // only monitor alerts for session 0 (the downloader) print_alerts(*ses[0], [=](lt::session& ses, lt::alert const* a) { - if (auto ta = alert_cast(a)) + if (auto ta = alert_cast(a)) { ta->handle.connect_peer(lt::tcp::endpoint( (flags & connect_socks) ? proxy : peer1, 6881)); diff --git a/src/alert.cpp b/src/alert.cpp index 5d9129da4..e7b7a2521 100644 --- a/src/alert.cpp +++ b/src/alert.cpp @@ -1202,6 +1202,7 @@ namespace libtorrent { return m_alloc.ptr(m_file_idx); } +#ifndef TORRENT_NO_DEPRECATE torrent_added_alert::torrent_added_alert(aux::stack_allocator& alloc , torrent_handle const& h) : torrent_alert(alloc, h) @@ -1211,6 +1212,7 @@ namespace libtorrent { { return torrent_alert::message() + " added"; } +#endif torrent_removed_alert::torrent_removed_alert(aux::stack_allocator& alloc , torrent_handle const& h, sha1_hash const& ih) diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 077c8a218..f74867ce6 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -4856,8 +4856,10 @@ retry: } #endif +#ifndef TORRENT_NO_DEPRECATE if (m_alerts.should_post()) m_alerts.emplace_alert(handle); +#endif // if this was an existing torrent, we can't start it again, or add // another set of plugins etc. we're done diff --git a/test/test_alert_manager.cpp b/test/test_alert_manager.cpp index bf0c28f4d..32a6532a5 100644 --- a/test/test_alert_manager.cpp +++ b/test/test_alert_manager.cpp @@ -54,7 +54,7 @@ TORRENT_TEST(limit) // try add 600 torrent_add_alert to make sure we honor the limit of 500 // alerts. for (int i = 0; i < 600; ++i) - mgr.emplace_alert(torrent_handle()); + mgr.emplace_alert(torrent_handle()); TEST_EQUAL(mgr.pending(), true); @@ -71,7 +71,7 @@ TORRENT_TEST(limit) mgr.set_alert_queue_size_limit(200); for (int i = 0; i < 600; ++i) - mgr.emplace_alert(torrent_handle()); + mgr.emplace_alert(torrent_handle()); TEST_EQUAL(mgr.pending(), true); @@ -89,7 +89,7 @@ TORRENT_TEST(priority_limit) // this should only add 100 because of the limit for (int i = 0; i < 200; ++i) - mgr.emplace_alert(torrent_handle()); + mgr.emplace_alert(torrent_handle(), add_torrent_params(), error_code()); // the limit is twice as high for priority alerts for (int i = 0; i < 200; ++i) @@ -119,7 +119,7 @@ TORRENT_TEST(dispatch_function) TEST_EQUAL(mgr.pending(), false); for (int i = 0; i < 20; ++i) - mgr.emplace_alert(torrent_handle()); + mgr.emplace_alert(torrent_handle(), add_torrent_params(), error_code()); TEST_EQUAL(mgr.pending(), true); @@ -130,7 +130,7 @@ TORRENT_TEST(dispatch_function) TEST_EQUAL(cnt, 20); for (int i = 0; i < 200; ++i) - mgr.emplace_alert(torrent_handle()); + mgr.emplace_alert(torrent_handle(), add_torrent_params(), error_code()); TEST_EQUAL(mgr.pending(), false); TEST_EQUAL(cnt, 220); @@ -151,7 +151,7 @@ TORRENT_TEST(notify_function) TEST_EQUAL(mgr.pending(), false); for (int i = 0; i < 20; ++i) - mgr.emplace_alert(torrent_handle()); + mgr.emplace_alert(torrent_handle(), add_torrent_params(), error_code()); TEST_EQUAL(mgr.pending(), true); @@ -165,7 +165,7 @@ TORRENT_TEST(notify_function) // subsequent posted alerts will not cause an edge (because there are // already alerts queued) for (int i = 0; i < 20; ++i) - mgr.emplace_alert(torrent_handle()); + mgr.emplace_alert(torrent_handle(), add_torrent_params(), error_code()); TEST_EQUAL(mgr.pending(), true); TEST_EQUAL(cnt, 1); @@ -179,7 +179,7 @@ TORRENT_TEST(notify_function) TEST_EQUAL(mgr.pending(), false); for (int i = 0; i < 20; ++i) - mgr.emplace_alert(torrent_handle()); + mgr.emplace_alert(torrent_handle(), add_torrent_params(), error_code()); TEST_EQUAL(mgr.pending(), true); TEST_EQUAL(cnt, 2); @@ -211,14 +211,14 @@ TORRENT_TEST(extensions) mgr.add_extension(boost::make_shared(2)); for (int i = 0; i < 53; ++i) - mgr.emplace_alert(torrent_handle()); + mgr.emplace_alert(torrent_handle(), add_torrent_params(), error_code()); TEST_EQUAL(plugin_alerts[0], 53); TEST_EQUAL(plugin_alerts[1], 53); TEST_EQUAL(plugin_alerts[2], 53); for (int i = 0; i < 17; ++i) - mgr.emplace_alert(torrent_handle()); + mgr.emplace_alert(torrent_handle(), add_torrent_params(), error_code()); TEST_EQUAL(plugin_alerts[0], 70); TEST_EQUAL(plugin_alerts[1], 70); @@ -229,7 +229,7 @@ TORRENT_TEST(extensions) void post_torrent_added(alert_manager* mgr) { test_sleep(10); - mgr->emplace_alert(torrent_handle()); + mgr->emplace_alert(torrent_handle(), add_torrent_params(), error_code()); } TORRENT_TEST(wait_for_alert) @@ -247,7 +247,7 @@ TORRENT_TEST(wait_for_alert) TEST_CHECK(end - start > milliseconds(900)); TEST_CHECK(end - start < milliseconds(1100)); - mgr.emplace_alert(torrent_handle()); + mgr.emplace_alert(torrent_handle(), add_torrent_params(), error_code()); start = clock_type::now(); a = mgr.wait_for_alert(seconds(1)); @@ -255,7 +255,7 @@ TORRENT_TEST(wait_for_alert) fprintf(stderr, "delay: %d ms\n", int(total_milliseconds(end - start))); TEST_CHECK(end - start < milliseconds(1)); - TEST_CHECK(a->type() == torrent_added_alert::alert_type); + TEST_CHECK(a->type() == add_torrent_alert::alert_type); std::vector alerts; int num_resume = 0; @@ -269,7 +269,7 @@ TORRENT_TEST(wait_for_alert) fprintf(stderr, "delay: %d ms\n", int(total_milliseconds(end - start))); TEST_CHECK(end - start < milliseconds(500)); - TEST_CHECK(a->type() == torrent_added_alert::alert_type); + TEST_CHECK(a->type() == add_torrent_alert::alert_type); posting_thread.join(); } @@ -281,7 +281,7 @@ TORRENT_TEST(queued_resume) TEST_EQUAL(mgr.num_queued_resume(), 0); for (int i = 0; i < 17; ++i) - mgr.emplace_alert(torrent_handle()); + mgr.emplace_alert(torrent_handle(), add_torrent_params(), error_code()); TEST_EQUAL(mgr.num_queued_resume(), 0); @@ -312,12 +312,12 @@ TORRENT_TEST(alert_mask) { alert_manager mgr(100, 0xffffffff); - TEST_CHECK(mgr.should_post()); + TEST_CHECK(mgr.should_post()); TEST_CHECK(mgr.should_post()); mgr.set_alert_mask(0); - TEST_CHECK(!mgr.should_post()); + TEST_CHECK(!mgr.should_post()); TEST_CHECK(!mgr.should_post()); }