diff --git a/ChangeLog b/ChangeLog index 50865add9..a9b5292af 100644 --- a/ChangeLog +++ b/ChangeLog @@ -62,6 +62,10 @@ * resume data no longer has timestamps of files * require C++11 to build libtorrent + * 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 * 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/bindings/python/src/alert.cpp b/bindings/python/src/alert.cpp index 671980916..fcffe26b4 100644 --- a/bindings/python/src/alert.cpp +++ b/bindings/python/src/alert.cpp @@ -302,9 +302,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/bindings/python/src/magnet_uri.cpp b/bindings/python/src/magnet_uri.cpp index 509deba0a..c6fba72d0 100644 --- a/bindings/python/src/magnet_uri.cpp +++ b/bindings/python/src/magnet_uri.cpp @@ -46,7 +46,7 @@ namespace { dict ret; - ret["ti"] = p.ti; + if (p.ti) ret["ti"] = p.ti; list tracker_list; for (std::vector::const_iterator i = p.trackers.begin() , end(p.trackers.end()); i != end; ++i) @@ -57,7 +57,7 @@ namespace { for (auto const& i : p.dht_nodes) 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 acd335c5c..4cf876d35 100644 --- a/bindings/python/test.py +++ b/bindings/python/test.py @@ -365,6 +365,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): diff --git a/include/libtorrent/alert_types.hpp b/include/libtorrent/alert_types.hpp index ec6554162..d30355a25 100644 --- a/include/libtorrent/alert_types.hpp +++ b/include/libtorrent/alert_types.hpp @@ -161,11 +161,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 final : torrent_alert + // deprecated in 1.1.3 + // use add_torrent_alert instead + struct TORRENT_DEPRECATED_EXPORT torrent_added_alert final : torrent_alert { // internal torrent_added_alert(aux::stack_allocator& alloc, torrent_handle const& h); @@ -174,6 +177,7 @@ namespace libtorrent static const int static_category = alert::status_notification; virtual std::string message() const 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/include/libtorrent/kademlia/refresh.hpp b/include/libtorrent/kademlia/refresh.hpp index 97390e4d3..be7b09c74 100644 --- a/include/libtorrent/kademlia/refresh.hpp +++ b/include/libtorrent/kademlia/refresh.hpp @@ -51,8 +51,6 @@ public: observer_ptr new_observer(udp::endpoint const& ep , node_id const& id); - void trim_seed_nodes(); - protected: virtual bool invoke(observer_ptr o); diff --git a/simulation/test_pause.cpp b/simulation/test_pause.cpp index 6d91038d1..37dc65071 100644 --- a/simulation/test_pause.cpp +++ b/simulation/test_pause.cpp @@ -84,7 +84,7 @@ void run_test(Setup const& setup, Torrent const& torrent lt::torrent_handle h; print_alerts(*ses, [&](lt::session& ses, lt::alert const* a) { - auto at = lt::alert_cast(a); + auto at = lt::alert_cast(a); if (at == nullptr) return; h = at->handle; diff --git a/simulation/test_swarm.cpp b/simulation/test_swarm.cpp index 15093e19b..11ae295e7 100644 --- a/simulation/test_swarm.cpp +++ b/simulation/test_swarm.cpp @@ -239,7 +239,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 40fa39f02..2448166e1 100644 --- a/simulation/test_torrent_status.cpp +++ b/simulation/test_torrent_status.cpp @@ -65,7 +65,7 @@ TORRENT_TEST(status_timers) , [](lt::add_torrent_params&) {} // on alert , [&](lt::alert const* a, lt::session&) { - if (auto ta = alert_cast(a)) + if (auto ta = alert_cast(a)) { TEST_CHECK(!handle.is_valid()); start_time = time_now(); @@ -121,7 +121,7 @@ TORRENT_TEST(status_timers_last_upload) , [](lt::add_torrent_params&) {} // on alert , [&](lt::alert const* a, lt::session&) { - if (auto ta = alert_cast(a)) + if (auto ta = alert_cast(a)) { TEST_CHECK(!handle.is_valid()); start_time = time_now(); @@ -169,7 +169,7 @@ TORRENT_TEST(status_timers_time_shift_with_active_torrent) , [](lt::add_torrent_params&) {} // on alert , [&](lt::alert const* a, lt::session&) { - if (auto ta = alert_cast(a)) + if (auto ta = alert_cast(a)) { TEST_CHECK(!handle.is_valid()); start_time = time_now(); @@ -250,7 +250,7 @@ TORRENT_TEST(finish_time_shift_active) , [](lt::add_torrent_params&) {} // on alert , [&](lt::alert const* a, lt::session&) { - if (auto ta = alert_cast(a)) + if (auto ta = alert_cast(a)) { TEST_CHECK(!handle.is_valid()); start_time = time_now(); @@ -324,7 +324,7 @@ TORRENT_TEST(finish_time_shift_paused) , [](lt::add_torrent_params&) {} // on alert , [&](lt::alert const* a, lt::session&) { - if (auto ta = alert_cast(a)) + if (auto ta = alert_cast(a)) { TEST_CHECK(!handle.is_valid()); start_time = time_now(); diff --git a/simulation/test_transfer.cpp b/simulation/test_transfer.cpp index fa8f8d40b..831ffefa2 100644 --- a/simulation/test_transfer.cpp +++ b/simulation/test_transfer.cpp @@ -123,7 +123,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 9999d03f8..84f4bdef2 100644 --- a/src/alert.cpp +++ b/src/alert.cpp @@ -1273,6 +1273,7 @@ namespace libtorrent return m_alloc.get().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) @@ -1282,6 +1283,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/kademlia/node.cpp b/src/kademlia/node.cpp index de96115d8..f429b8e08 100644 --- a/src/kademlia/node.cpp +++ b/src/kademlia/node.cpp @@ -230,9 +230,6 @@ void node::bootstrap(std::vector const& nodes r->add_entry(node_id(), n, 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 != nullptr) m_observer->log(dht_logger::node, "bootstrapping with %d nodes", count); diff --git a/src/kademlia/refresh.cpp b/src/kademlia/refresh.cpp index 7f070218a..b364d1fa8 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 diff --git a/src/session_impl.cpp b/src/session_impl.cpp index f823ddd1c..225745398 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -4684,8 +4684,10 @@ namespace aux { } #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/src/torrent.cpp b/src/torrent.cpp index ca7e3992f..7c05ba184 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -10553,7 +10553,7 @@ namespace libtorrent } } 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()) { std::tie(st->distributed_full_copies, st->distributed_fraction) = diff --git a/test/test_alert_manager.cpp b/test/test_alert_manager.cpp index d138e0a60..797fcd9c3 100644 --- a/test/test_alert_manager.cpp +++ b/test/test_alert_manager.cpp @@ -53,7 +53,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); @@ -69,7 +69,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); @@ -87,7 +87,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 (file_index_t i(0); i < file_index_t(200); ++i) @@ -115,7 +115,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); @@ -129,7 +129,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); @@ -142,7 +142,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); @@ -174,14 +174,14 @@ TORRENT_TEST(extensions) mgr.add_extension(std::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); @@ -192,7 +192,7 @@ TORRENT_TEST(extensions) void post_torrent_added(alert_manager* mgr) { std::this_thread::sleep_for(lt::milliseconds(10)); - mgr->emplace_alert(torrent_handle()); + mgr->emplace_alert(torrent_handle(), add_torrent_params(), error_code()); } TORRENT_TEST(wait_for_alert) @@ -210,7 +210,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)); @@ -218,7 +218,7 @@ TORRENT_TEST(wait_for_alert) std::printf("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; mgr.get_all(alerts); @@ -231,7 +231,7 @@ TORRENT_TEST(wait_for_alert) std::printf("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(); } @@ -240,12 +240,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()); } diff --git a/test/test_alert_types.cpp b/test/test_alert_types.cpp index 90efdabca..a23f3da42 100644 --- a/test/test_alert_types.cpp +++ b/test/test_alert_types.cpp @@ -58,7 +58,11 @@ TORRENT_TEST(alerts_types) TEST_EQUAL(count_alert_types, seq); \ count_alert_types++; +#ifndef TORRENT_NO_DEPRECATE TEST_ALERT_TYPE(torrent_added_alert, 3, 0, alert::status_notification); +#else + ++count_alert_types; +#endif TEST_ALERT_TYPE(torrent_removed_alert, 4, 1, alert::status_notification); TEST_ALERT_TYPE(read_piece_alert, 5, 1, alert::storage_notification); TEST_ALERT_TYPE(file_completed_alert, 6, 0, alert::progress_notification);