From bb64887f30a96ec4116fe135c670ae09a9ca0527 Mon Sep 17 00:00:00 2001 From: arvidn Date: Sun, 2 Aug 2015 15:18:21 -0400 Subject: [PATCH] merge total wanted fix from RC_1_0 --- ChangeLog | 3 ++ include/libtorrent/create_torrent.hpp | 2 +- src/torrent.cpp | 8 ++++++ test/test_torrent.cpp | 41 ++++++++++++++++++++++++++- 4 files changed, 52 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index dd1f96240..16f1139f7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -72,6 +72,9 @@ * almost completely changed the storage interface (for custom storage) * added support for hashing pieces in multiple threads + + * fixed total_wanted bug (when setting file priorities in add_torrent_params) + 1.0.6 release * fixed uTP vulnerability diff --git a/include/libtorrent/create_torrent.hpp b/include/libtorrent/create_torrent.hpp index 15d7dee29..0c0829d8a 100644 --- a/include/libtorrent/create_torrent.hpp +++ b/include/libtorrent/create_torrent.hpp @@ -125,7 +125,7 @@ namespace libtorrent // not grow with more pieces. When this option is specified, it is // recommended to have a fairly small piece size, say 64 kiB. // When creating merkle torrents, the full hash tree is also generated - // and should be saved off separately. It is accessed through the + // and should be saved off separately. It is accessed through the // create_torrent::merkle_tree() function. merkle = 2, diff --git a/src/torrent.cpp b/src/torrent.cpp index 549ef905d..d6744bcea 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -1891,6 +1891,14 @@ namespace libtorrent } } + // in case file priorities were passed in via the add_torrent_params + // and also in the case of share mode, we need to update the priorities + if (!m_file_priority.empty() && std::find(m_file_priority.begin() + , m_file_priority.end(), 0) != m_file_priority.end()) + { + update_piece_priorities(); + } + if (!m_connections_initialized) { m_connections_initialized = true; diff --git a/test/test_torrent.cpp b/test/test_torrent.cpp index bcf7f6bb3..3576a4a89 100644 --- a/test/test_torrent.cpp +++ b/test/test_torrent.cpp @@ -154,6 +154,46 @@ void test_running_torrent(boost::shared_ptr info, boost::int64_t f } } +TORRENT_TEST(total_wanted) +{ + file_storage fs; + + fs.add_file("test_torrent_dir4/tmp1", 1024); + fs.add_file("test_torrent_dir4/tmp2", 1024); + fs.add_file("test_torrent_dir4/tmp3", 1024); + fs.add_file("test_torrent_dir4/tmp4", 1024); + + libtorrent::create_torrent t(fs, 1024); + std::vector tmp; + bencode(std::back_inserter(tmp), t.generate()); + error_code ec; + boost::shared_ptr info(boost::make_shared(&tmp[0], tmp.size(), ec)); + + settings_pack pack; + pack.set_int(settings_pack::alert_mask, alert::storage_notification); + pack.set_str(settings_pack::listen_interfaces, "0.0.0.0:48130"); + pack.set_int(settings_pack::max_retry_port_bind, 10); + lt::session ses(pack); + + add_torrent_params p; + p.ti = info; + p.save_path = "."; + + // we just want 1 out of 4 files, 1024 out of 4096 bytes + p.file_priorities.resize(4, 0); + p.file_priorities[1] = 1; + + p.ti = info; + + torrent_handle h = ses.add_torrent(p); + + torrent_status st = h.status(); + std::cout << "total_wanted: " << st.total_wanted << " : " << 1024 << std::endl; + TEST_EQUAL(st.total_wanted, 1024); + std::cout << "total_wanted_done: " << st.total_wanted_done << " : 0" << std::endl; + TEST_EQUAL(st.total_wanted_done, 0); +} + TORRENT_TEST(torrent) { /* { @@ -194,7 +234,6 @@ TORRENT_TEST(torrent) fs.add_file("test_torrent_dir2/tmp1", 0); libtorrent::create_torrent t(fs, 128 * 1024, 6); - t.add_tracker("http://non-existing.com/announce"); std::vector tmp; std::back_insert_iterator > out(tmp);