From 6785046c2fefe6a997f6061e306d45c4f5058e56 Mon Sep 17 00:00:00 2001 From: arvidn Date: Sun, 29 Oct 2017 00:44:40 +0200 Subject: [PATCH] introduce a download_priority_t type, for uniform an type-safe piece- and file priorities --- bindings/python/src/converters.cpp | 14 +-- bindings/python/src/session.cpp | 2 +- bindings/python/src/torrent_handle.cpp | 40 ++++--- examples/client_test.cpp | 4 +- examples/connection_tester.cpp | 2 +- include/libtorrent/Makefile.am | 1 + include/libtorrent/add_torrent_params.hpp | 5 +- include/libtorrent/aux_/storage_utils.hpp | 2 +- include/libtorrent/disk_interface.hpp | 2 +- include/libtorrent/disk_io_job.hpp | 2 +- include/libtorrent/disk_io_thread.hpp | 2 +- include/libtorrent/download_priority.hpp | 51 +++++++++ include/libtorrent/piece_picker.hpp | 9 +- include/libtorrent/storage.hpp | 6 +- include/libtorrent/storage_defs.hpp | 5 +- include/libtorrent/torrent.hpp | 24 ++--- include/libtorrent/torrent_handle.hpp | 25 +++-- include/libtorrent/units.hpp | 4 + src/create_torrent.cpp | 2 +- src/disk_io_thread.cpp | 4 +- src/peer_connection.cpp | 8 +- src/piece_picker.cpp | 52 ++++----- src/read_resume_data.cpp | 16 ++- src/request_blocks.cpp | 2 +- src/storage.cpp | 33 +++--- src/storage_utils.cpp | 4 +- src/torrent.cpp | 126 +++++++++++----------- src/torrent_handle.cpp | 62 ++++++++--- src/write_resume_data.cpp | 4 +- test/make_torrent.cpp | 2 +- test/test_block_cache.cpp | 2 +- test/test_piece_picker.cpp | 73 ++++++------- test/test_priority.cpp | 38 ++++--- test/test_read_resume.cpp | 13 +-- test/test_remove_torrent.cpp | 4 +- test/test_resume.cpp | 112 +++++++++---------- test/test_storage.cpp | 6 +- test/test_torrent.cpp | 33 +++--- test/test_transfer.cpp | 2 +- test/test_utils.hpp | 7 ++ 40 files changed, 470 insertions(+), 335 deletions(-) create mode 100644 include/libtorrent/download_priority.hpp diff --git a/bindings/python/src/converters.cpp b/bindings/python/src/converters.cpp index 3fef985c4..e222495ca 100644 --- a/bindings/python/src/converters.cpp +++ b/bindings/python/src/converters.cpp @@ -283,7 +283,7 @@ void bind_converters() { // C++ -> python conversions to_python_converter, pair_to_tuple>(); - to_python_converter, pair_to_tuple>(); + to_python_converter, pair_to_tuple>(); to_python_converter>(); to_python_converter>(); to_python_converter>(); @@ -294,13 +294,14 @@ void bind_converters() to_python_converter, vector_to_list>>(); to_python_converter, vector_to_list>>(); to_python_converter, vector_to_list>>(); - to_python_converter, vector_to_list>>(); + to_python_converter, vector_to_list>>(); to_python_converter, vector_to_list>>(); to_python_converter, vector_to_list>>(); to_python_converter>, vector_to_list>>>(); to_python_converter>(); to_python_converter>(); + to_python_converter>(); to_python_converter>(); to_python_converter>(); to_python_converter>(); @@ -335,7 +336,7 @@ void bind_converters() to_python_converter>, vector_to_list>>>(); to_python_converter>, vector_to_list>>>(); to_python_converter>, vector_to_list>>>(); - to_python_converter>, vector_to_list>>>(); + to_python_converter>, vector_to_list>>>(); to_python_converter>, vector_to_list>>>(); to_python_converter>, vector_to_list>>>(); to_python_converter>>, vector_to_list>>>>(); @@ -345,10 +346,10 @@ void bind_converters() tuple_to_pair(); tuple_to_endpoint(); tuple_to_endpoint(); - tuple_to_pair(); + tuple_to_pair(); dict_to_map(); list_to_vector>(); - list_to_vector>(); + list_to_vector>(); list_to_vector>(); list_to_vector>(); list_to_vector>(); @@ -356,7 +357,7 @@ void bind_converters() // work-around types list_to_vector>>(); - list_to_vector>>(); + list_to_vector>>(); list_to_vector>>(); list_to_vector>>(); list_to_vector>>(); @@ -364,6 +365,7 @@ void bind_converters() to_strong_typedef(); to_strong_typedef(); + to_strong_typedef(); to_strong_typedef(); to_strong_typedef(); to_strong_typedef(); diff --git a/bindings/python/src/session.cpp b/bindings/python/src/session.cpp index 721f5e1e1..0bd5b0776 100644 --- a/bindings/python/src/session.cpp +++ b/bindings/python/src/session.cpp @@ -335,7 +335,7 @@ namespace } else if(key == "file_priorities") { - p.file_priorities = extract>(value); + p.file_priorities = extract>(value); } else { diff --git a/bindings/python/src/torrent_handle.cpp b/bindings/python/src/torrent_handle.cpp index 1e599ddbc..3aee1b2e4 100644 --- a/bindings/python/src/torrent_handle.cpp +++ b/bindings/python/src/torrent_handle.cpp @@ -67,24 +67,22 @@ namespace handle.piece_availability(avail); } - for (std::vector::iterator i(avail.begin()) - , end(avail.end()); i != end; ++i) - ret.append(*i); + for (auto const a : avail) + ret.append(a); return ret; } list piece_priorities(torrent_handle& handle) { list ret; - std::vector prio; + std::vector prio; { allow_threading_guard guard; prio = handle.piece_priorities(); } - for (std::vector::iterator i(prio.begin()) - , end(prio.end()); i != end; ++i) - ret.append(*i); + for (auto const p : prio) + ret.append(p); return ret; } @@ -145,47 +143,47 @@ void prioritize_pieces(torrent_handle& info, object o) // determine which overload should be selected. the one taking a list of // priorities or the one taking a list of piece -> priority mappings - bool const is_piece_list = extract>(*begin).check(); + bool const is_piece_list = extract>(*begin).check(); if (is_piece_list) { - std::vector> piece_list; + std::vector> piece_list; std::transform(begin, end, std::back_inserter(piece_list) - , &extract_fn>); + , &extract_fn>); info.prioritize_pieces(piece_list); } else { - std::vector priority_vector; + std::vector priority_vector; std::transform(begin, end, std::back_inserter(priority_vector) - , &extract_fn); + , &extract_fn); info.prioritize_pieces(priority_vector); } } void prioritize_files(torrent_handle& info, object o) { - stl_input_iterator begin(o), end; - info.prioritize_files(std::vector (begin, end)); + stl_input_iterator begin(o), end; + info.prioritize_files(std::vector(begin, end)); } list file_priorities(torrent_handle& handle) { list ret; - std::vector priorities = handle.file_priorities(); + std::vector priorities = handle.file_priorities(); - for (std::vector::iterator i = priorities.begin(); i != priorities.end(); ++i) - ret.append(*i); + for (auto const p : priorities) + ret.append(p); return ret; } -int file_prioritity0(torrent_handle& h, file_index_t index) +download_priority_t file_prioritity0(torrent_handle& h, file_index_t index) { return h.file_priority(index); } -void file_prioritity1(torrent_handle& h, file_index_t index, int prio) +void file_prioritity1(torrent_handle& h, file_index_t index, download_priority_t prio) { return h.file_priority(index, prio); } @@ -448,8 +446,8 @@ void bind_torrent_handle() void (torrent_handle::*set_flags0)(torrent_flags_t) const = &torrent_handle::set_flags; void (torrent_handle::*set_flags1)(torrent_flags_t, torrent_flags_t) const = &torrent_handle::set_flags; - int (torrent_handle::*piece_priority0)(piece_index_t) const = &torrent_handle::piece_priority; - void (torrent_handle::*piece_priority1)(piece_index_t, int) const = &torrent_handle::piece_priority; + download_priority_t (torrent_handle::*piece_priority0)(piece_index_t) const = &torrent_handle::piece_priority; + void (torrent_handle::*piece_priority1)(piece_index_t, download_priority_t) const = &torrent_handle::piece_priority; void (torrent_handle::*move_storage0)(std::string const&, lt::move_flags_t) const = &torrent_handle::move_storage; void (torrent_handle::*rename_file0)(file_index_t, std::string const&) const = &torrent_handle::rename_file; diff --git a/examples/client_test.cpp b/examples/client_test.cpp index 1166b612c..f723d1e1c 100644 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -1797,7 +1797,7 @@ COLUMN OPTIONS std::vector file_progress; h.file_progress(file_progress); std::vector file_status = h.file_status(); - std::vector file_prio = h.file_priorities(); + std::vector file_prio = h.file_priorities(); auto f = file_status.begin(); std::shared_ptr ti = h.torrent_file(); @@ -1860,7 +1860,7 @@ COLUMN OPTIONS progress_bar(progress, file_progress_width, complete ? col_green : col_yellow, '-', '#' , title.c_str()).c_str() , add_suffix(file_progress[idx]).c_str() - , file_prio[idx]); + , static_cast(file_prio[idx])); p += file_progress_width + 13; out += str; diff --git a/examples/connection_tester.cpp b/examples/connection_tester.cpp index e9ebebb65..dace4a192 100644 --- a/examples/connection_tester.cpp +++ b/examples/connection_tester.cpp @@ -846,7 +846,7 @@ void generate_data(char const* path, torrent_info const& ti) file_pool fp; - aux::vector priorities; + aux::vector priorities; sha1_hash info_hash; storage_params params{ fs, diff --git a/include/libtorrent/Makefile.am b/include/libtorrent/Makefile.am index 90a3f7668..3e0aa0147 100644 --- a/include/libtorrent/Makefile.am +++ b/include/libtorrent/Makefile.am @@ -161,6 +161,7 @@ nobase_include_HEADERS = \ web_peer_connection.hpp \ xml_parse.hpp \ span.hpp \ + download_priority.hpp \ \ aux_/allocating_handler.hpp \ aux_/aligned_storage.hpp \ diff --git a/include/libtorrent/add_torrent_params.hpp b/include/libtorrent/add_torrent_params.hpp index 7e937da57..f878af864 100644 --- a/include/libtorrent/add_torrent_params.hpp +++ b/include/libtorrent/add_torrent_params.hpp @@ -47,6 +47,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/error_code.hpp" #include "libtorrent/units.hpp" #include "libtorrent/torrent_flags.hpp" +#include "libtorrent/download_priority.hpp" #include "libtorrent/aux_/noexcept_movable.hpp" namespace libtorrent { @@ -189,7 +190,7 @@ namespace libtorrent { // ``torrent_handle::prioritize_files()``. The file priorities specified // in here take precedence over those specified in the resume data, if // any. - aux::noexcept_movable> file_priorities; + aux::noexcept_movable> file_priorities; // torrent extension construction functions can be added to this vector // to have them be added immediately when the torrent is constructed. @@ -320,7 +321,7 @@ namespace libtorrent { // element in the vector represent the piece with the same index. If you // set both file- and piece priorities, file priorities will take // precedence. - aux::noexcept_movable> piece_priorities; + aux::noexcept_movable> piece_priorities; // if this is a merkle tree torrent, and you're seeding, this field must // be set. It is all the hashes in the binary tree, with the root as the diff --git a/include/libtorrent/aux_/storage_utils.hpp b/include/libtorrent/aux_/storage_utils.hpp index 25432e514..bb6c1279d 100644 --- a/include/libtorrent/aux_/storage_utils.hpp +++ b/include/libtorrent/aux_/storage_utils.hpp @@ -92,7 +92,7 @@ namespace aux { verify_resume_data(add_torrent_params const& rd , aux::vector const& links , file_storage const& fs - , aux::vector const& file_priority + , aux::vector const& file_priority , stat_cache& stat , std::string const& save_path , storage_error& ec); diff --git a/include/libtorrent/disk_interface.hpp b/include/libtorrent/disk_interface.hpp index 043ec2ad5..764816031 100644 --- a/include/libtorrent/disk_interface.hpp +++ b/include/libtorrent/disk_interface.hpp @@ -178,7 +178,7 @@ namespace libtorrent { virtual void async_delete_files(storage_index_t storage, remove_flags_t options , std::function handler) = 0; virtual void async_set_file_priority(storage_index_t storage - , aux::vector prio + , aux::vector prio , std::function handler) = 0; virtual void async_clear_piece(storage_index_t storage, piece_index_t index diff --git a/include/libtorrent/disk_io_job.hpp b/include/libtorrent/disk_io_job.hpp index 1b0751573..d4a28d82a 100644 --- a/include/libtorrent/disk_io_job.hpp +++ b/include/libtorrent/disk_io_job.hpp @@ -125,7 +125,7 @@ namespace libtorrent { boost::variant + , aux::vector , remove_flags_t > argument; diff --git a/include/libtorrent/disk_io_thread.hpp b/include/libtorrent/disk_io_thread.hpp index 7447106d3..b22ad9931 100644 --- a/include/libtorrent/disk_io_thread.hpp +++ b/include/libtorrent/disk_io_thread.hpp @@ -324,7 +324,7 @@ namespace aux { void async_flush_piece(storage_index_t storage, piece_index_t piece , std::function handler = std::function()) override; void async_set_file_priority(storage_index_t storage - , aux::vector prio + , aux::vector prio , std::function handler) override; void async_clear_piece(storage_index_t storage, piece_index_t index diff --git a/include/libtorrent/download_priority.hpp b/include/libtorrent/download_priority.hpp new file mode 100644 index 000000000..ad0cf1931 --- /dev/null +++ b/include/libtorrent/download_priority.hpp @@ -0,0 +1,51 @@ +/* + +Copyright (c) 2017, Arvid Norberg +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the distribution. + * Neither the name of the author nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +*/ + +#ifndef TORRENT_DOWNLOAD_PRIORITY_HPP_INCLUDED +#define TORRENT_DOWNLOAD_PRIORITY_HPP_INCLUDED + +#include "libtorrent/units.hpp" + +namespace libtorrent { + +struct download_priority_tag; +using download_priority_t = aux::strong_typedef; + +constexpr download_priority_t dont_download{0}; +constexpr download_priority_t default_priority{4}; +constexpr download_priority_t low_priority{1}; +constexpr download_priority_t top_priority{7}; + +} + +#endif + diff --git a/include/libtorrent/piece_picker.hpp b/include/libtorrent/piece_picker.hpp index 76772b469..f599f186d 100644 --- a/include/libtorrent/piece_picker.hpp +++ b/include/libtorrent/piece_picker.hpp @@ -58,6 +58,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/aux_/vector.hpp" #include "libtorrent/aux_/typed_span.hpp" #include "libtorrent/alert_types.hpp" // for picker_flags_t +#include "libtorrent/download_priority.hpp" namespace libtorrent { @@ -232,13 +233,13 @@ namespace libtorrent { // sets the priority of a piece. // returns true if the priority was changed from 0 to non-0 // or vice versa - bool set_piece_priority(piece_index_t index, int prio); + bool set_piece_priority(piece_index_t index, download_priority_t prio); // returns the priority for the piece at 'index' - int piece_priority(piece_index_t index) const; + download_priority_t piece_priority(piece_index_t index) const; // returns the current piece priorities for all pieces - void piece_priorities(std::vector& pieces) const; + void piece_priorities(std::vector& pieces) const; // pieces should be the vector that represents the pieces a // client has. It returns a list of all pieces that this client @@ -457,7 +458,7 @@ namespace libtorrent { piece_pos(int const peer_count_, int const index_) : peer_count(static_cast(peer_count_)) , download_state(piece_pos::piece_open) - , piece_priority(4) + , piece_priority(static_cast(default_priority)) , index(index_) { TORRENT_ASSERT(peer_count_ >= 0); diff --git a/include/libtorrent/storage.hpp b/include/libtorrent/storage.hpp index 8f2f34ea6..00376d3ce 100644 --- a/include/libtorrent/storage.hpp +++ b/include/libtorrent/storage.hpp @@ -223,7 +223,7 @@ namespace libtorrent { // change the priorities of files. This is a fenced job and is // guaranteed to be the only running function on this storage // when called - virtual void set_file_priority(aux::vector const& prio + virtual void set_file_priority(aux::vector const& prio , storage_error& ec) = 0; // This function should move all the files belonging to the storage to @@ -383,7 +383,7 @@ namespace libtorrent { ~default_storage() override; bool has_any_file(storage_error& ec) override; - void set_file_priority(aux::vector const& prio + void set_file_priority(aux::vector const& prio , storage_error& ec) override; void rename_file(file_index_t index, std::string const& new_filename , storage_error& ec) override; @@ -427,7 +427,7 @@ namespace libtorrent { file_handle open_file(file_index_t file, open_mode_t mode, storage_error& ec) const; file_handle open_file_impl(file_index_t file, open_mode_t mode, error_code& ec) const; - aux::vector m_file_priority; + aux::vector m_file_priority; std::string m_save_path; std::string m_part_file_name; // the file pool is a member of the disk_io_thread diff --git a/include/libtorrent/storage_defs.hpp b/include/libtorrent/storage_defs.hpp index a2863a216..9a79f3fd4 100644 --- a/include/libtorrent/storage_defs.hpp +++ b/include/libtorrent/storage_defs.hpp @@ -37,6 +37,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/units.hpp" #include "libtorrent/aux_/vector.hpp" #include "libtorrent/sha1_hash.hpp" +#include "libtorrent/download_priority.hpp" #include #include @@ -107,7 +108,7 @@ namespace libtorrent { { storage_params(file_storage const& f, file_storage const* mf , std::string const& sp, storage_mode_t const sm - , aux::vector const& prio + , aux::vector const& prio , sha1_hash const& ih) : files(f) , mapped_files(mf) @@ -120,7 +121,7 @@ namespace libtorrent { file_storage const* mapped_files = nullptr; // optional std::string const& path; storage_mode_t mode{storage_mode_sparse}; - aux::vector const& priorities; + aux::vector const& priorities; sha1_hash const& info_hash; }; diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index e47a35656..c907b843f 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -108,8 +108,6 @@ namespace libtorrent { class bt_peer_connection; struct listen_socket_t; - constexpr int default_piece_priority = 4; - enum class waste_reason { piece_timed_out, piece_cancelled, piece_unknown, piece_seed @@ -565,19 +563,19 @@ namespace libtorrent { void piece_availability(aux::vector& avail) const; - void set_piece_priority(piece_index_t index, int priority); - int piece_priority(piece_index_t index) const; + void set_piece_priority(piece_index_t index, download_priority_t priority); + download_priority_t piece_priority(piece_index_t index) const; - void prioritize_pieces(aux::vector const& pieces); - void prioritize_piece_list(std::vector> const& pieces); - void piece_priorities(aux::vector*) const; + void prioritize_pieces(aux::vector const& pieces); + void prioritize_piece_list(std::vector> const& pieces); + void piece_priorities(aux::vector*) const; - void set_file_priority(file_index_t index, int priority); - int file_priority(file_index_t index) const; + void set_file_priority(file_index_t index, download_priority_t priority); + download_priority_t file_priority(file_index_t index) const; void on_file_priority(storage_error const&); - void prioritize_files(aux::vector const& files); - void file_priorities(aux::vector*) const; + void prioritize_files(aux::vector const& files); + void file_priorities(aux::vector*) const; void cancel_non_critical(); void set_piece_deadline(piece_index_t piece, int t, deadline_flags_t flags); @@ -1203,7 +1201,7 @@ namespace libtorrent { #endif void remove_time_critical_piece(piece_index_t piece, bool finished = false); - void remove_time_critical_pieces(aux::vector const& priority); + void remove_time_critical_pieces(aux::vector const& priority); void request_time_critical_pieces(); void need_peer_list(); @@ -1258,7 +1256,7 @@ namespace libtorrent { // ever changed, this remains empty. Any unallocated slot // implicitly means the file has priority 4. // TODO: this wastes 5 bits per file - aux::vector m_file_priority; + aux::vector m_file_priority; // this object is used to track download progress of individual files aux::file_progress m_file_progress; diff --git a/include/libtorrent/torrent_handle.hpp b/include/libtorrent/torrent_handle.hpp index 03a606bd1..e9ebaad98 100644 --- a/include/libtorrent/torrent_handle.hpp +++ b/include/libtorrent/torrent_handle.hpp @@ -56,6 +56,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/storage_defs.hpp" #include "libtorrent/torrent_flags.hpp" #include "libtorrent/peer_info.hpp" // for peer_source_flags_t +#include "libtorrent/download_priority.hpp" namespace libtorrent { namespace aux { @@ -992,11 +993,18 @@ namespace aux { // // ``piece_priorities`` returns a vector with one element for each piece // in the torrent. Each element is the current priority of that piece. - void piece_priority(piece_index_t index, int priority) const; - int piece_priority(piece_index_t index) const; + void piece_priority(piece_index_t index, download_priority_t priority) const; + download_priority_t piece_priority(piece_index_t index) const; + void prioritize_pieces(std::vector const& pieces) const; + void prioritize_pieces(std::vector> const& pieces) const; + std::vector piece_priorities() const; + +#ifndef TORRENT_NO_DEPRECATE + TORRENT_DEPRECATED void prioritize_pieces(std::vector const& pieces) const; + TORRENT_DEPRECATED void prioritize_pieces(std::vector> const& pieces) const; - std::vector piece_priorities() const; +#endif // ``index`` must be in the range [0, number_of_files). // @@ -1020,10 +1028,15 @@ namespace aux { // You cannot set the file priorities on a torrent that does not yet have // metadata or a torrent that is a seed. ``file_priority(int, int)`` and // prioritize_files() are both no-ops for such torrents. - void file_priority(file_index_t index, int priority) const; - int file_priority(file_index_t index) const; + void file_priority(file_index_t index, download_priority_t priority) const; + download_priority_t file_priority(file_index_t index) const; + void prioritize_files(std::vector const& files) const; + std::vector file_priorities() const; + +#ifndef TORRENT_NO_DEPRECATE + TORRENT_DEPRECATED void prioritize_files(std::vector const& files) const; - std::vector file_priorities() const; +#endif // ``force_reannounce()`` will force this torrent to do another tracker // request, to receive new peers. The ``seconds`` argument specifies how diff --git a/include/libtorrent/units.hpp b/include/libtorrent/units.hpp index 594e44917..a46db6ef4 100644 --- a/include/libtorrent/units.hpp +++ b/include/libtorrent/units.hpp @@ -135,6 +135,10 @@ namespace libtorrent { namespace aux { namespace std { + template + struct is_integral> + : std::is_integral {}; + template class numeric_limits> : public std::numeric_limits { diff --git a/src/create_torrent.cpp b/src/create_torrent.cpp index e22131f52..67c63a42b 100644 --- a/src/create_torrent.cpp +++ b/src/create_torrent.cpp @@ -274,7 +274,7 @@ namespace { counters cnt; disk_io_thread disk_thread(ios, cnt); - aux::vector priorities; + aux::vector priorities; sha1_hash info_hash; storage_params params{ t.files(), diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index b1a3cab3a..baa1a06fd 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -1941,7 +1941,7 @@ constexpr disk_job_flags_t disk_interface::cache_hit; } void disk_io_thread::async_set_file_priority(storage_index_t const storage - , aux::vector prios + , aux::vector prios , std::function handler) { disk_io_job* j = allocate_job(job_action_t::file_priority); @@ -2767,7 +2767,7 @@ constexpr disk_job_flags_t disk_interface::cache_hit; status_t disk_io_thread::do_file_priority(disk_io_job* j, jobqueue_t& /* completed_jobs */ ) { j->storage->set_file_priority( - boost::get>(j->argument) + boost::get>(j->argument) , j->error); return status_t::no_error; } diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 5c5f5402e..6550cc6d5 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -454,7 +454,7 @@ namespace libtorrent { for (piece_index_t j(0); j != end_piece; ++j) { if (m_have_piece[j] - && t->piece_priority(j) > 0 + && t->piece_priority(j) > dont_download && !p.has_piece_passed(j)) { interested = true; @@ -728,7 +728,7 @@ namespace libtorrent { if (!m_have_piece[i]) continue; // if the peer has a piece and we don't, the peer is interesting if (!t->have_piece(i) - && t->picker().piece_priority(i) != 0) + && t->picker().piece_priority(i) != dont_download) interesting = true; } if (interesting) t->peer_is_interesting(*this); @@ -1909,7 +1909,7 @@ namespace libtorrent { if (!t->has_piece_passed(index) && !t->is_upload_only() && !is_interesting() - && (!t->has_picker() || t->picker().piece_priority(index) != 0)) + && (!t->has_picker() || t->picker().piece_priority(index) != dont_download)) t->peer_is_interesting(*this); disconnect_if_redundant(); @@ -3346,7 +3346,7 @@ namespace libtorrent { && !t->has_piece_passed(index) && t->valid_metadata() && t->has_picker() - && t->picker().piece_priority(index) > 0) + && t->picker().piece_priority(index) > dont_download) { t->peer_is_interesting(*this); } diff --git a/src/piece_picker.cpp b/src/piece_picker.cpp index d6fa44779..ccf44fba0 100644 --- a/src/piece_picker.cpp +++ b/src/piece_picker.cpp @@ -45,6 +45,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/aux_/range.hpp" #include "libtorrent/performance_counters.hpp" // for counters #include "libtorrent/alert_types.hpp" // for picker_log_alert +#include "libtorrent/download_priority.hpp" #if TORRENT_USE_ASSERTS #include "libtorrent/peer_connection.hpp" @@ -1657,7 +1658,8 @@ namespace libtorrent { TORRENT_ASSERT(p.priority(this) == -1); } - bool piece_picker::set_piece_priority(piece_index_t const index, int const new_piece_priority) + bool piece_picker::set_piece_priority(piece_index_t const index + , download_priority_t const new_piece_priority) { INVARIANT_CHECK; @@ -1666,19 +1668,19 @@ namespace libtorrent { << ", " << new_piece_priority << ")" << std::endl; #endif - TORRENT_ASSERT(new_piece_priority >= 0); - TORRENT_ASSERT(new_piece_priority < priority_levels); + TORRENT_ASSERT(new_piece_priority >= dont_download); + TORRENT_ASSERT(new_piece_priority <= top_priority); piece_pos& p = m_piece_map[index]; // if the priority isn't changed, don't do anything - if (new_piece_priority == int(p.piece_priority)) return false; + if (new_piece_priority == download_priority_t(p.piece_priority)) return false; - int prev_priority = p.priority(this); + int const prev_priority = p.priority(this); TORRENT_ASSERT(m_dirty || prev_priority < int(m_priority_boundaries.size())); bool ret = false; - if (new_piece_priority == piece_pos::filter_priority + if (new_piece_priority == dont_download && p.piece_priority != piece_pos::filter_priority) { // the piece just got filtered @@ -1715,7 +1717,7 @@ namespace libtorrent { } ret = true; } - else if (new_piece_priority != piece_pos::filter_priority + else if (new_piece_priority != dont_download && p.piece_priority == piece_pos::filter_priority) { // the piece just got unfiltered @@ -1740,7 +1742,7 @@ namespace libtorrent { TORRENT_ASSERT(m_num_filtered >= 0); TORRENT_ASSERT(m_num_have_filtered >= 0); - p.piece_priority = static_cast(new_piece_priority); + p.piece_priority = static_cast(new_piece_priority); int const new_priority = p.priority(this); if (prev_priority != new_priority && !m_dirty) @@ -1760,19 +1762,19 @@ namespace libtorrent { return ret; } - int piece_picker::piece_priority(piece_index_t const index) const + download_priority_t piece_picker::piece_priority(piece_index_t const index) const { - return m_piece_map[index].piece_priority; + return download_priority_t(m_piece_map[index].piece_priority); } - void piece_picker::piece_priorities(std::vector& pieces) const + void piece_picker::piece_priorities(std::vector& pieces) const { pieces.resize(m_piece_map.size()); auto j = pieces.begin(); for (auto i = m_piece_map.begin(), end(m_piece_map.end()); i != end; ++i, ++j) { - *j = i->piece_priority; + *j = download_priority_t(i->piece_priority); } } @@ -1922,7 +1924,7 @@ namespace { // in time critical mode, only pick high priority pieces if ((options & time_critical_mode) - && piece_priority(i->index) != priority_levels - 1) + && piece_priority(i->index) != top_priority) continue; if (!is_piece_free(i->index, pieces)) continue; @@ -1976,7 +1978,7 @@ namespace { { // in time critical mode, only pick high priority pieces if ((options & time_critical_mode) - && piece_priority(i) != priority_levels - 1) + && piece_priority(i) != top_priority) continue; pc.inc_stats_counter(counters::piece_picker_suggest_loops); @@ -1999,7 +2001,7 @@ namespace { TORRENT_ASSERT(!m_dirty); for (auto i = m_pieces.begin(); - i != m_pieces.end() && piece_priority(*i) == priority_levels - 1; ++i) + i != m_pieces.end() && piece_priority(*i) == top_priority; ++i) { if (!is_piece_free(*i, pieces)) continue; @@ -2022,7 +2024,7 @@ namespace { { if (!is_piece_free(i, pieces)) continue; // we've already added high priority pieces - if (piece_priority(i) == priority_levels - 1) continue; + if (piece_priority(i) == top_priority) continue; ret |= picker_log_alert::reverse_sequential; @@ -2040,7 +2042,7 @@ namespace { { if (!is_piece_free(i, pieces)) continue; // we've already added high priority pieces - if (piece_priority(i) == priority_levels - 1) continue; + if (piece_priority(i) == top_priority) continue; ret |= picker_log_alert::sequential_pieces; @@ -2097,7 +2099,7 @@ namespace { // pick pieces in priority order. Once we hit a lower priority // piece, we won't encounter any more high priority ones if ((options & time_critical_mode) - && piece_priority(i) != priority_levels - 1) + && piece_priority(i) != top_priority) break; if (!is_piece_free(i, pieces)) continue; @@ -2118,7 +2120,7 @@ namespace { // if we're in time-critical mode, we are only allowed to pick // high priority pieces. for (auto i = m_pieces.begin(); - i != m_pieces.end() && piece_priority(*i) == priority_levels - 1; ++i) + i != m_pieces.end() && piece_priority(*i) == top_priority; ++i) { if (!is_piece_free(*i, pieces)) continue; @@ -2258,7 +2260,7 @@ get_out: downloading_piece const& dp = *i; if ((options & time_critical_mode) - && piece_priority(dp.index) != priority_levels - 1) + && piece_priority(dp.index) != top_priority) continue; // we either don't have this piece, or we've already requested from it @@ -2298,10 +2300,10 @@ get_out: // this peer doesn't have this piece, try again if (!pieces[dp.index]) continue; // don't pick pieces with priority 0 - TORRENT_ASSERT(piece_priority(dp.index) > 0); + TORRENT_ASSERT(piece_priority(dp.index) > dont_download); if ((options & time_critical_mode) - && piece_priority(dp.index) != priority_levels - 1) + && piece_priority(dp.index) != top_priority) continue; partials[c++] = &dp; @@ -2314,7 +2316,7 @@ get_out: int piece = int(random(aux::numeric_cast(partials_size - 1))); downloading_piece const* dp = partials[piece]; TORRENT_ASSERT(pieces[dp->index]); - TORRENT_ASSERT(piece_priority(dp->index) > 0); + TORRENT_ASSERT(piece_priority(dp->index) > dont_download); // fill in with blocks requested from other peers // as backups TORRENT_ASSERT(dp->requested > 0); @@ -2350,11 +2352,11 @@ get_out: for (auto const& i : m_downloads[piece_pos::piece_downloading]) { if (!pieces[i.index]) continue; - if (piece_priority(i.index) == 0) continue; + if (piece_priority(i.index) == dont_download) continue; if (i.locked) continue; if ((options & time_critical_mode) - && piece_priority(i.index) != priority_levels - 1) + && piece_priority(i.index) != top_priority) continue; int idx = -1; diff --git a/src/read_resume_data.cpp b/src/read_resume_data.cpp index c25809d58..d80a229d3 100644 --- a/src/read_resume_data.cpp +++ b/src/read_resume_data.cpp @@ -39,7 +39,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/hasher.hpp" #include "libtorrent/torrent_info.hpp" #include "libtorrent/aux_/numeric_cast.hpp" -#include "libtorrent/torrent.hpp" // for default_piece_priority +#include "libtorrent/download_priority.hpp" // for default_priority namespace libtorrent { @@ -168,14 +168,17 @@ namespace { { int const num_files = file_priority.list_size(); ret.file_priorities.resize(aux::numeric_cast(num_files) - , default_piece_priority); + , default_priority); for (int i = 0; i < num_files; ++i) { std::size_t const idx = std::size_t(i); ret.file_priorities[idx] = aux::clamp( - file_priority.list_int_value_at(i, default_piece_priority), std::int64_t(0), std::int64_t(7)) & 0xff; + download_priority_t(static_cast( + file_priority.list_int_value_at(i + , static_cast(default_priority)))) + , dont_download, top_priority); // this is suspicious, leave seed mode - if (ret.file_priorities[idx] == 0) + if (ret.file_priorities[idx] == dont_download) { ret.flags &= ~torrent_flags::seed_mode; } @@ -273,7 +276,10 @@ namespace { ret.piece_priorities.resize(aux::numeric_cast(piece_priority.string_length())); for (std::size_t i = 0; i < ret.piece_priorities.size(); ++i) { - ret.piece_priorities[i] = aux::clamp(int(prio_str[i]), 0, 7) & 0xff; + ret.piece_priorities[i] = download_priority_t(aux::clamp( + static_cast(prio_str[i]) + , static_cast(dont_download) + , static_cast(top_priority))); } } diff --git a/src/request_blocks.cpp b/src/request_blocks.cpp index bbeac5b4b..1084d97c5 100644 --- a/src/request_blocks.cpp +++ b/src/request_blocks.cpp @@ -207,7 +207,7 @@ namespace libtorrent { { if (prefer_contiguous_blocks == 0 && num_requests <= 0) break; - if (time_critical_mode && p.piece_priority(i->piece_index) != 7) + if (time_critical_mode && p.piece_priority(i->piece_index) != top_priority) { // assume the subsequent pieces are not prio 7 and // be done diff --git a/src/storage.cpp b/src/storage.cpp index 8a94b28d0..08c4fb895 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -93,7 +93,7 @@ namespace libtorrent { file_storage const& fs = files(); for (file_index_t i(0); i < m_file_priority.end_index(); ++i) { - if (m_file_priority[i] == 0 && !fs.pad_file_at(i)) + if (m_file_priority[i] == dont_download && !fs.pad_file_at(i)) { need_partfile(); break; @@ -121,20 +121,20 @@ namespace libtorrent { } void default_storage::set_file_priority( - aux::vector const& prio + aux::vector const& prio , storage_error& ec) { // extend our file priorities in case it's truncated // the default assumed priority is 4 (the default) if (prio.size() > m_file_priority.size()) - m_file_priority.resize(prio.size(), default_piece_priority); + m_file_priority.resize(prio.size(), default_priority); file_storage const& fs = files(); for (file_index_t i(0); i < prio.end_index(); ++i) { - std::uint8_t const old_prio = m_file_priority[i]; - std::uint8_t new_prio = prio[i]; - if (old_prio == 0 && new_prio != 0) + download_priority_t const old_prio = m_file_priority[i]; + download_priority_t new_prio = prio[i]; + if (old_prio == dont_download && new_prio != dont_download) { // move stuff out of the part file file_handle f = open_file(i, open_mode::read_write, ec); @@ -157,7 +157,7 @@ namespace libtorrent { return; } } - else if (old_prio != 0 && new_prio == 0) + else if (old_prio != dont_download && new_prio == dont_download) { // move stuff into the part file // this is not implemented yet. @@ -165,7 +165,7 @@ namespace libtorrent { std::string fp = fs.file_path(i, m_save_path); if (exists(fp)) - new_prio = 1; + new_prio = low_priority; /* file_handle f = open_file(i, open_mode::read_only, ec); if (ec.ec != boost::system::errc::no_such_file_or_directory) @@ -195,7 +195,7 @@ namespace libtorrent { ec.ec.clear(); m_file_priority[i] = new_prio; - if (m_file_priority[i] == 0 && !fs.pad_file_at(i)) + if (m_file_priority[i] == dont_download && !fs.pad_file_at(i)) need_partfile(); } if (m_part_file) m_part_file->flush_metadata(ec.ec); @@ -231,7 +231,7 @@ namespace libtorrent { { // ignore files that have priority 0 if (m_file_priority.end_index() > file_index - && m_file_priority[file_index] == 0) + && m_file_priority[file_index] == dont_download) { continue; } @@ -469,7 +469,7 @@ namespace libtorrent { } if (file_index < m_file_priority.end_index() - && m_file_priority[file_index] == 0) + && m_file_priority[file_index] == dont_download) { TORRENT_ASSERT(m_part_file); @@ -532,7 +532,7 @@ namespace libtorrent { } if (file_index < m_file_priority.end_index() - && m_file_priority[file_index] == 0) + && m_file_priority[file_index] == dont_download) { TORRENT_ASSERT(m_part_file); @@ -652,8 +652,11 @@ namespace libtorrent { if (!m_allocate_files) mode |= open_mode::sparse; // files with priority 0 should always be sparse - if (m_file_priority.end_index() > file && m_file_priority[file] == 0) + if (m_file_priority.end_index() > file + && m_file_priority[file] == dont_download) + { mode |= open_mode::sparse; + } if (m_settings && settings().get_bool(settings_pack::no_atime_storage)) mode |= open_mode::no_atime; @@ -702,7 +705,7 @@ namespace { explicit disabled_storage(file_storage const& fs) : storage_interface(fs) {} bool has_any_file(storage_error&) override { return false; } - void set_file_priority(aux::vector const& + void set_file_priority(aux::vector const& , storage_error&) override {} void rename_file(file_index_t, std::string const&, storage_error&) override {} void release_files(storage_error&) override {} @@ -764,7 +767,7 @@ namespace { } bool has_any_file(storage_error&) override { return false; } - void set_file_priority(aux::vector const& /* prio */ + void set_file_priority(aux::vector const& /* prio */ , storage_error&) override {} status_t move_storage(std::string const& /* save_path */ , move_flags_t, storage_error&) override { return status_t::no_error; } diff --git a/src/storage_utils.cpp b/src/storage_utils.cpp index 5d205d544..a11784175 100644 --- a/src/storage_utils.cpp +++ b/src/storage_utils.cpp @@ -462,7 +462,7 @@ namespace libtorrent { namespace aux { bool verify_resume_data(add_torrent_params const& rd , aux::vector const& links , file_storage const& fs - , aux::vector const& file_priority + , aux::vector const& file_priority , stat_cache& stat , std::string const& save_path , storage_error& ec) @@ -522,7 +522,7 @@ namespace libtorrent { namespace aux { // expected location, but is likely to be in a partfile. Just exempt it // from checking if (file_index < file_priority.end_index() - && file_priority[file_index] == 0) + && file_priority[file_index] == dont_download) continue; error_code error; diff --git a/src/torrent.cpp b/src/torrent.cpp index 6b5c545ae..ac7575e7a 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -341,8 +341,8 @@ namespace libtorrent { // that case. Also, if the resume data says we're missing a piece, we // can't be in seed-mode. m_seed_mode = (p.flags & torrent_flags::seed_mode) - && std::find(p.file_priorities.begin(), p.file_priorities.end(), 0) == p.file_priorities.end() - && std::find(p.piece_priorities.begin(), p.piece_priorities.end(), 0) == p.piece_priorities.end() + && std::find(p.file_priorities.begin(), p.file_priorities.end(), dont_download) == p.file_priorities.end() + && std::find(p.piece_priorities.begin(), p.piece_priorities.end(), dont_download) == p.piece_priorities.end() && std::find(p.have_pieces.begin(), p.have_pieces.end(), false) == p.have_pieces.end(); m_connections_initialized = true; @@ -969,7 +969,7 @@ namespace libtorrent { if (m_share_mode && valid_metadata()) { m_file_priority.clear(); - m_file_priority.resize(m_torrent_file->num_files(), 0); + m_file_priority.resize(m_torrent_file->num_files(), dont_download); } update_piece_priorities(); @@ -1735,7 +1735,7 @@ namespace libtorrent { { // in share mode, all pieces have their priorities initialized to 0 m_file_priority.clear(); - m_file_priority.resize(m_torrent_file->num_files(), 0); + m_file_priority.resize(m_torrent_file->num_files(), dont_download); } // it's important to initialize the peers early, because this is what will @@ -1766,7 +1766,7 @@ namespace libtorrent { piece_index_t idx(0); for (auto prio : m_add_torrent_params->piece_priorities) { - if (has_picker() || prio != default_piece_priority) + if (has_picker() || prio != default_priority) { need_picker(); m_picker->set_piece_priority(idx, prio); @@ -1779,7 +1779,7 @@ 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()) + , m_file_priority.end(), dont_download) != m_file_priority.end()) { update_piece_priorities(); } @@ -3583,7 +3583,7 @@ namespace libtorrent { int num_filtered_pieces = m_picker->num_filtered() + m_picker->num_have_filtered(); piece_index_t const last_piece_index = m_torrent_file->last_piece(); - if (m_picker->piece_priority(last_piece_index) == 0) + if (m_picker->piece_priority(last_piece_index) == dont_download) { st.total_wanted -= m_torrent_file->piece_size(last_piece_index); TORRENT_ASSERT(st.total_wanted >= 0); @@ -3603,7 +3603,7 @@ namespace libtorrent { TORRENT_ASSERT(corr <= 0); TORRENT_ASSERT(corr > -piece_size); st.total_done += corr; - if (m_picker->piece_priority(last_piece) != 0) + if (m_picker->piece_priority(last_piece) != dont_download) { TORRENT_ASSERT(st.total_wanted_done >= piece_size); st.total_wanted_done += corr; @@ -3626,7 +3626,7 @@ namespace libtorrent { { int const deduction = std::min(p.length, piece_size - p.start); bool const done = m_picker->has_piece_passed(j); - bool const wanted = m_picker->piece_priority(j) > 0; + bool const wanted = m_picker->piece_priority(j) > dont_download; if (done) st.total_done -= deduction; if (wanted) st.total_wanted -= deduction; if (wanted && done) st.total_wanted_done -= deduction; @@ -3680,7 +3680,7 @@ namespace libtorrent { } st.total_done += corr; - if (m_picker->piece_priority(index) > 0) + if (m_picker->piece_priority(index) > dont_download) st.total_wanted_done += corr; } @@ -3722,7 +3722,7 @@ namespace libtorrent { { int const done = std::min(block_bytes_wanted(p.first), p.second); st.total_done += done; - if (m_picker->piece_priority(p.first.piece_index) != 0) + if (m_picker->piece_priority(p.first.piece_index) != dont_download) st.total_wanted_done += done; } @@ -4695,9 +4695,9 @@ namespace libtorrent { --i; } // just in case this piece had priority 0 - int prev_prio = m_picker->piece_priority(piece); - m_picker->set_piece_priority(piece, 7); - if (prev_prio == 0) update_gauge(); + download_priority_t prev_prio = m_picker->piece_priority(piece); + m_picker->set_piece_priority(piece, top_priority); + if (prev_prio == dont_download) update_gauge(); return; } @@ -4715,9 +4715,9 @@ namespace libtorrent { m_time_critical_pieces.insert(critical_piece_it, p); // just in case this piece had priority 0 - int prev_prio = m_picker->piece_priority(piece); - m_picker->set_piece_priority(piece, 7); - if (prev_prio == 0) update_gauge(); + download_priority_t prev_prio = m_picker->piece_priority(piece); + m_picker->set_piece_priority(piece, top_priority); + if (prev_prio == dont_download) update_gauge(); piece_picker::downloading_piece pi; m_picker->piece_info(piece, pi); @@ -4785,7 +4785,7 @@ namespace libtorrent { alerts().emplace_alert( get_handle(), piece, error_code(boost::system::errc::operation_canceled, generic_category())); } - if (has_picker()) m_picker->set_piece_priority(piece, 1); + if (has_picker()) m_picker->set_piece_priority(piece, low_priority); m_time_critical_pieces.erase(i); return; } @@ -4801,17 +4801,17 @@ namespace libtorrent { m_ses.alerts().emplace_alert( get_handle(), i->piece, error_code(boost::system::errc::operation_canceled, generic_category())); } - if (has_picker()) m_picker->set_piece_priority(i->piece, 1); + if (has_picker()) m_picker->set_piece_priority(i->piece, low_priority); i = m_time_critical_pieces.erase(i); } } // remove time critical pieces where priority is 0 - void torrent::remove_time_critical_pieces(aux::vector const& priority) + void torrent::remove_time_critical_pieces(aux::vector const& priority) { for (auto i = m_time_critical_pieces.begin(); i != m_time_critical_pieces.end();) { - if (priority[i->piece] == 0) + if (priority[i->piece] == dont_download) { if (i->flags & torrent_handle::alert_when_available) { @@ -4840,7 +4840,8 @@ namespace libtorrent { m_picker->get_availability(avail); } - void torrent::set_piece_priority(piece_index_t const index, int const priority) + void torrent::set_piece_priority(piece_index_t const index + , download_priority_t const priority) { // INVARIANT_CHECK; @@ -4848,7 +4849,8 @@ namespace libtorrent { if (!valid_metadata()) { debug_log("*** SET_PIECE_PRIORITY [ idx: %d prio: %d ignored. " - "no metadata yet ]", static_cast(index), priority); + "no metadata yet ]", static_cast(index) + , static_cast(priority)); } #endif if (!valid_metadata() || is_seed()) return; @@ -4870,29 +4872,30 @@ namespace libtorrent { if (filter_updated) { update_peer_interest(was_finished); - if (priority == 0) remove_time_critical_piece(index); + if (priority == dont_download) remove_time_critical_piece(index); } } - int torrent::piece_priority(piece_index_t const index) const + download_priority_t torrent::piece_priority(piece_index_t const index) const { // INVARIANT_CHECK; - if (!has_picker()) return default_piece_priority; + if (!has_picker()) return default_priority; // this call is only valid on torrents with metadata TORRENT_ASSERT(valid_metadata()); if (index < piece_index_t(0) || index >= m_torrent_file->end_piece()) { TORRENT_ASSERT_FAIL(); - return 0; + return dont_download; } return m_picker->piece_priority(index); } - void torrent::prioritize_piece_list(std::vector> const& pieces) + void torrent::prioritize_piece_list(std::vector> const& pieces) { INVARIANT_CHECK; @@ -4906,14 +4909,14 @@ namespace libtorrent { bool const was_finished = is_finished(); for (auto const& p : pieces) { - TORRENT_ASSERT(p.second >= 0); - TORRENT_ASSERT(p.second <= 7); + TORRENT_ASSERT(p.second >= dont_download); + TORRENT_ASSERT(p.second <= top_priority); TORRENT_ASSERT(p.first >= piece_index_t(0)); TORRENT_ASSERT(p.first < m_torrent_file->end_piece()); if (p.first < piece_index_t(0) || p.first >= m_torrent_file->end_piece() - || p.second < 0 || p.second > 7) + || p.second < dont_download || p.second > top_priority) { continue; } @@ -4933,7 +4936,7 @@ namespace libtorrent { state_updated(); } - void torrent::prioritize_pieces(aux::vector const& pieces) + void torrent::prioritize_pieces(aux::vector const& pieces) { INVARIANT_CHECK; @@ -4956,7 +4959,7 @@ namespace libtorrent { bool const was_finished = is_finished(); for (auto prio : pieces) { - TORRENT_ASSERT(prio >= 0 && prio <= 7); + TORRENT_ASSERT(prio >= dont_download && prio <= top_priority); filter_updated |= m_picker->set_piece_priority(index, prio); TORRENT_ASSERT(num_have() >= m_picker->num_have_filtered()); ++index; @@ -4977,7 +4980,7 @@ namespace libtorrent { update_state_list(); } - void torrent::piece_priorities(aux::vector* pieces) const + void torrent::piece_priorities(aux::vector* pieces) const { INVARIANT_CHECK; @@ -4986,7 +4989,7 @@ namespace libtorrent { if (!has_picker()) { pieces->clear(); - pieces->resize(m_torrent_file->num_pieces(), default_piece_priority); + pieces->resize(m_torrent_file->num_pieces(), default_priority); return; } @@ -4996,7 +4999,7 @@ namespace libtorrent { void torrent::on_file_priority(storage_error const&) {} - void torrent::prioritize_files(aux::vector const& files) + void torrent::prioritize_files(aux::vector const& files) { INVARIANT_CHECK; @@ -5007,13 +5010,15 @@ namespace libtorrent { file_index_t const limit = std::min(files.end_index(), fs.end_file()); if (m_file_priority.end_index() < limit) - m_file_priority.resize(static_cast(limit), default_piece_priority); + m_file_priority.resize(static_cast(limit), default_priority); auto si = files.begin(); for (file_index_t i(0); i < limit; ++i, ++si) { // initialize pad files to priority 0 - m_file_priority[i] = fs.pad_file_at(i) ? 0 : aux::clamp(*si, 0, 7) & 0xff; + m_file_priority[i] = fs.pad_file_at(i) + ? dont_download + : aux::clamp(*si, dont_download, top_priority); } // storage may be nullptr during construction and shutdown @@ -5026,7 +5031,8 @@ namespace libtorrent { update_piece_priorities(); } - void torrent::set_file_priority(file_index_t const index, int prio) + void torrent::set_file_priority(file_index_t const index + , download_priority_t prio) { INVARIANT_CHECK; @@ -5041,17 +5047,16 @@ namespace libtorrent { return; } - if (prio < 0) prio = 0; - else if (prio > 7) prio = 7; + prio = aux::clamp(prio, dont_download, top_priority); if (m_file_priority.end_index() <= index) { // any unallocated slot is assumed to have the default priority - if (prio == default_piece_priority) return; - m_file_priority.resize(static_cast(index) + 1, default_piece_priority); + if (prio == default_priority) return; + m_file_priority.resize(static_cast(index) + 1, default_priority); } if (m_file_priority[index] == prio) return; - m_file_priority[index] = std::uint8_t(prio); + m_file_priority[index] = prio; if (!valid_metadata()) return; @@ -5064,29 +5069,29 @@ namespace libtorrent { update_piece_priorities(); } - int torrent::file_priority(file_index_t const index) const + download_priority_t torrent::file_priority(file_index_t const index) const { TORRENT_ASSERT_PRECOND(index >= file_index_t(0)); - if (index < file_index_t(0)) return 0; + if (index < file_index_t(0)) return dont_download; // if we have metadata, perform additional checks if (valid_metadata()) { file_storage const& fs = m_torrent_file->files(); TORRENT_ASSERT_PRECOND(index < fs.end_file()); - if (index >= fs.end_file()) return 0; + if (index >= fs.end_file()) return dont_download; // pad files always have priority 0 - if (fs.pad_file_at(index)) return 0; + if (fs.pad_file_at(index)) return dont_download; } // any unallocated slot is assumed to have the default priority - if (m_file_priority.end_index() <= index) return default_piece_priority; + if (m_file_priority.end_index() <= index) return default_priority; return m_file_priority[index]; } - void torrent::file_priorities(aux::vector* files) const + void torrent::file_priorities(aux::vector* files) const { INVARIANT_CHECK; @@ -5098,7 +5103,7 @@ namespace libtorrent { } files->clear(); - files->resize(m_torrent_file->num_files(), default_piece_priority); + files->resize(m_torrent_file->num_files(), default_priority); TORRENT_ASSERT(int(m_file_priority.size()) <= m_torrent_file->num_files()); std::copy(m_file_priority.begin(), m_file_priority.end(), files->begin()); } @@ -5113,7 +5118,8 @@ namespace libtorrent { std::int64_t position = 0; // initialize the piece priorities to 0, then only allow // setting higher priorities - aux::vector pieces(aux::numeric_cast(m_torrent_file->num_pieces()), 0); + aux::vector pieces(aux::numeric_cast( + m_torrent_file->num_pieces()), dont_download); file_storage const& fs = m_torrent_file->files(); for (file_index_t i(0); i < fs.end_file(); ++i) { @@ -5122,12 +5128,12 @@ namespace libtorrent { position += size; // pad files always have priority 0 - int const file_prio - = fs.pad_file_at(i) ? 0 - : i >= m_file_priority.end_index() ? default_piece_priority + download_priority_t const file_prio + = fs.pad_file_at(i) ? dont_download + : i >= m_file_priority.end_index() ? default_priority : m_file_priority[i]; - if (file_prio == 0) + if (file_prio == dont_download) { // the pieces already start out as priority 0, no need to update // the pieces vector in this case @@ -6303,7 +6309,7 @@ namespace libtorrent { file_storage const& fs = m_torrent_file->files(); for (piece_index_t i(0); i < fs.end_piece(); ++i) { - if (m_picker->piece_priority(i) == default_piece_priority) continue; + if (m_picker->piece_priority(i) == default_priority) continue; default_prio = false; break; } @@ -6314,7 +6320,7 @@ namespace libtorrent { ret.piece_priorities.reserve(static_cast(m_torrent_file->num_pieces())); for (piece_index_t i(0); i < fs.end_piece(); ++i) - ret.piece_priorities.push_back(static_cast(m_picker->piece_priority(i))); + ret.piece_priorities.push_back(m_picker->piece_priority(i)); } } } @@ -9291,7 +9297,7 @@ namespace libtorrent { if (ps.peer_count == 0) continue; if (ps.priority == 0 && (ps.have || ps.downloading)) { - m_picker->set_piece_priority(i, default_piece_priority); + m_picker->set_piece_priority(i, default_priority); continue; } // don't count pieces we already have or are trying to download @@ -9324,7 +9330,7 @@ namespace libtorrent { // now, pick one of the rarest pieces to download int const pick = int(random(aux::numeric_cast(rarest_pieces.end_index() - 1))); bool const was_finished = is_finished(); - m_picker->set_piece_priority(rarest_pieces[pick], default_piece_priority); + m_picker->set_piece_priority(rarest_pieces[pick], default_priority); update_gauge(); update_peer_interest(was_finished); update_want_peers(); diff --git a/src/torrent_handle.cpp b/src/torrent_handle.cpp index ab20a23f1..81b6fa9f1 100644 --- a/src/torrent_handle.cpp +++ b/src/torrent_handle.cpp @@ -461,61 +461,93 @@ namespace libtorrent { sync_call(&torrent::piece_availability, availr); } - void torrent_handle::piece_priority(piece_index_t index, int priority) const + void torrent_handle::piece_priority(piece_index_t index, download_priority_t priority) const { async_call(&torrent::set_piece_priority, index, priority); } - int torrent_handle::piece_priority(piece_index_t index) const + download_priority_t torrent_handle::piece_priority(piece_index_t index) const { - return sync_call_ret(0, &torrent::piece_priority, index); + return sync_call_ret(dont_download, &torrent::piece_priority, index); } - void torrent_handle::prioritize_pieces(std::vector const& pieces) const + void torrent_handle::prioritize_pieces(std::vector const& pieces) const { - async_call(&torrent::prioritize_pieces, static_cast const&>(pieces)); + async_call(&torrent::prioritize_pieces + , static_cast const&>(pieces)); } - void torrent_handle::prioritize_pieces(std::vector> const& pieces) const + void torrent_handle::prioritize_pieces(std::vector> const& pieces) const { async_call(&torrent::prioritize_piece_list, pieces); } - std::vector torrent_handle::piece_priorities() const + std::vector torrent_handle::piece_priorities() const { - aux::vector ret; + aux::vector ret; auto retp = &ret; sync_call(&torrent::piece_priorities, retp); return ret; } - void torrent_handle::file_priority(file_index_t index, int priority) const +#ifndef TORRENT_NO_DEPRECATE + void torrent_handle::prioritize_pieces(std::vector const& pieces) const + { + aux::vector p; + p.reserve(pieces.size()); + for (auto const prio : pieces) { + p.push_back(download_priority_t(static_cast(prio))); + } + async_call(&torrent::prioritize_pieces, p); + } + + void torrent_handle::prioritize_pieces(std::vector> const& pieces) const + { + std::vector> p; + p.reserve(pieces.size()); + async_call(&torrent::prioritize_piece_list, std::move(p)); + } +#endif + + void torrent_handle::file_priority(file_index_t index, download_priority_t priority) const { async_call(&torrent::set_file_priority, index, priority); } - int torrent_handle::file_priority(file_index_t index) const + download_priority_t torrent_handle::file_priority(file_index_t index) const { - return sync_call_ret(0, &torrent::file_priority, index); + return sync_call_ret(dont_download, &torrent::file_priority, index); } - void torrent_handle::prioritize_files(std::vector const& files) const + void torrent_handle::prioritize_files(std::vector const& files) const { async_call(&torrent::prioritize_files - , static_cast const&>(files)); + , static_cast const&>(files)); } - std::vector torrent_handle::file_priorities() const + std::vector torrent_handle::file_priorities() const { - aux::vector ret; + aux::vector ret; auto retp = &ret; sync_call(&torrent::file_priorities, retp); return ret; } #ifndef TORRENT_NO_DEPRECATE + // ============ start deprecation =============== + void torrent_handle::prioritize_files(std::vector const& files) const + { + aux::vector file_prio; + file_prio.reserve(files.size()); + for (auto const p : files) { + file_prio.push_back(download_priority_t(static_cast(p))); + } + async_call(&torrent::prioritize_files, file_prio); + } + int torrent_handle::get_peer_upload_limit(tcp::endpoint) const { return -1; } int torrent_handle::get_peer_download_limit(tcp::endpoint) const { return -1; } void torrent_handle::set_peer_upload_limit(tcp::endpoint, int /* limit */) const {} diff --git a/src/write_resume_data.cpp b/src/write_resume_data.cpp index c5524c589..87a25ffbb 100644 --- a/src/write_resume_data.cpp +++ b/src/write_resume_data.cpp @@ -234,7 +234,7 @@ namespace libtorrent { entry::list_type& prio = ret["file_priority"].list(); prio.reserve(atp.file_priorities.size()); for (auto const p : atp.file_priorities) - prio.emplace_back(p); + prio.emplace_back(static_cast(p)); } if (!atp.piece_priorities.empty()) @@ -243,7 +243,7 @@ namespace libtorrent { entry::string_type& prio = ret["piece_priority"].string(); prio.reserve(atp.piece_priorities.size()); for (auto const p : atp.piece_priorities) - prio.push_back(static_cast(p)); + prio.push_back(static_cast(static_cast(p))); } return ret; diff --git a/test/make_torrent.cpp b/test/make_torrent.cpp index 7b75b52fb..9efd6e1bb 100644 --- a/test/make_torrent.cpp +++ b/test/make_torrent.cpp @@ -169,7 +169,7 @@ void generate_files(lt::torrent_info const& ti, std::string const& path { file_pool fp; - aux::vector priorities; + aux::vector priorities; sha1_hash info_hash; storage_params params{ ti.files(), diff --git a/test/test_block_cache.cpp b/test/test_block_cache.cpp index 5e0cd59c6..634253232 100644 --- a/test/test_block_cache.cpp +++ b/test/test_block_cache.cpp @@ -62,7 +62,7 @@ struct test_storage_impl : storage_interface } bool has_any_file(storage_error& ec) override { return false; } - void set_file_priority(aux::vector const& prio + void set_file_priority(aux::vector const& prio , storage_error& ec) override {} status_t move_storage(std::string const& save_path, move_flags_t flags , storage_error& ec) override { return status_t::no_error; } diff --git a/test/test_piece_picker.cpp b/test/test_piece_picker.cpp index 8195ac16d..af5a48ebf 100644 --- a/test/test_piece_picker.cpp +++ b/test/test_piece_picker.cpp @@ -46,6 +46,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include "test.hpp" +#include "test_utils.hpp" using namespace lt; using namespace std::placeholders; @@ -179,8 +180,8 @@ std::shared_ptr setup_picker( { int const idx = static_cast(i); if (priority[idx] == 0) break; - const int prio = priority[idx] - '0'; - assert(prio >= 0); + download_priority_t const prio(priority[idx] - '0'); + assert(prio >= dont_download); p->set_piece_priority(i, prio); TEST_CHECK(p->piece_priority(i) == prio); @@ -611,7 +612,7 @@ TORRENT_TEST(resize) TEST_CHECK(p->num_have_filtered() == 0); TEST_CHECK(p->num_have() == 0); - p->set_piece_priority(piece_index_t(0), 0); + p->set_piece_priority(piece_index_t(0), dont_download); TEST_CHECK(p->num_filtered() == 1); TEST_CHECK(p->num_have_filtered() == 0); TEST_CHECK(p->num_have() == 0); @@ -623,7 +624,7 @@ TORRENT_TEST(resize) TEST_CHECK(p->num_have() == 1); p->resize(blocks_per_piece, blocks_per_piece, blocks_per_piece * 7); - TEST_CHECK(p->piece_priority(piece_index_t(0)) == 0); + TEST_CHECK(p->piece_priority(piece_index_t(0)) == dont_download); TEST_CHECK(p->num_filtered() == 1); TEST_CHECK(p->num_have_filtered() == 0); TEST_CHECK(p->num_have() == 0); @@ -798,7 +799,7 @@ TORRENT_TEST(cursors_sweep_up_set_piece_priority) { TEST_EQUAL(p->cursor(), i); TEST_EQUAL(p->reverse_cursor(), piece_index_t(7)); - p->set_piece_priority(i, 0); + p->set_piece_priority(i, dont_download); } TEST_CHECK(p->is_finished()); TEST_CHECK(!p->is_seeding()); @@ -830,7 +831,7 @@ TORRENT_TEST(cursors_sweep_down_set_piece_priority) { TEST_EQUAL(p->cursor(), piece_index_t(0)); TEST_EQUAL(p->reverse_cursor(), next(i)); - p->set_piece_priority(i, 0); + p->set_piece_priority(i, dont_download); } TEST_CHECK(p->is_finished()); TEST_CHECK(!p->is_seeding()); @@ -847,8 +848,8 @@ TORRENT_TEST(cursors_sweep_in_set_priority) { TEST_EQUAL(p->cursor(), left); TEST_EQUAL(p->reverse_cursor(), next(right)); - p->set_piece_priority(left, 0); - p->set_piece_priority(right, 0); + p->set_piece_priority(left, dont_download); + p->set_piece_priority(right, dont_download); } TEST_CHECK(p->is_finished()); TEST_CHECK(!p->is_seeding()); @@ -961,24 +962,24 @@ TORRENT_TEST(cursors) p = setup_picker("7654321", " ", "", ""); TEST_EQUAL(p->cursor(), piece_index_t(0)); TEST_EQUAL(p->reverse_cursor(), piece_index_t(7)); - p->set_piece_priority(piece_index_t(1), 0); + p->set_piece_priority(piece_index_t(1), dont_download); TEST_EQUAL(p->cursor(), piece_index_t(0)); TEST_EQUAL(p->reverse_cursor(), piece_index_t(7)); - p->set_piece_priority(piece_index_t(0), 0); + p->set_piece_priority(piece_index_t(0), dont_download); TEST_EQUAL(p->cursor(), piece_index_t(2)); TEST_EQUAL(p->reverse_cursor(), piece_index_t(7)); - p->set_piece_priority(piece_index_t(5), 0); + p->set_piece_priority(piece_index_t(5), dont_download); TEST_EQUAL(p->cursor(), piece_index_t(2)); TEST_EQUAL(p->reverse_cursor(), piece_index_t(7)); - p->set_piece_priority(piece_index_t(6), 0); + p->set_piece_priority(piece_index_t(6), dont_download); TEST_EQUAL(p->cursor(), piece_index_t(2)); TEST_EQUAL(p->reverse_cursor(), piece_index_t(5)); - p->set_piece_priority(piece_index_t(4), 0); - p->set_piece_priority(piece_index_t(3), 0); - p->set_piece_priority(piece_index_t(2), 0); + p->set_piece_priority(piece_index_t(4), dont_download); + p->set_piece_priority(piece_index_t(3), dont_download); + p->set_piece_priority(piece_index_t(2), dont_download); TEST_EQUAL(p->cursor(), piece_index_t(7)); TEST_EQUAL(p->reverse_cursor(), piece_index_t(0)); - p->set_piece_priority(piece_index_t(3), 1); + p->set_piece_priority(piece_index_t(3), low_priority); TEST_EQUAL(p->cursor(), piece_index_t(3)); TEST_EQUAL(p->reverse_cursor(), piece_index_t(4)); } @@ -989,7 +990,7 @@ TORRENT_TEST(piece_priorities) auto p = setup_picker("5555555", " ", "7654321", ""); TEST_CHECK(p->num_filtered() == 0); TEST_CHECK(p->num_have_filtered() == 0); - p->set_piece_priority(piece_index_t(0), 0); + p->set_piece_priority(piece_index_t(0), dont_download); TEST_CHECK(p->num_filtered() == 1); TEST_CHECK(p->num_have_filtered() == 0); p->mark_as_finished({piece_index_t(0), 0}, nullptr); @@ -998,7 +999,7 @@ TORRENT_TEST(piece_priorities) TEST_CHECK(p->num_have_filtered() == 1); p->we_dont_have(piece_index_t(0)); - p->set_piece_priority(piece_index_t(0), 7); + p->set_piece_priority(piece_index_t(0), top_priority); auto picked = pick_pieces(p, "*******", 7 * blocks_per_piece, 0, nullptr , options, empty_vector); @@ -1009,14 +1010,14 @@ TORRENT_TEST(piece_priorities) // test changing priority on a piece we have p->we_have(piece_index_t(0)); - p->set_piece_priority(piece_index_t(0), 0); - p->set_piece_priority(piece_index_t(0), 1); - p->set_piece_priority(piece_index_t(0), 0); + p->set_piece_priority(piece_index_t(0), dont_download); + p->set_piece_priority(piece_index_t(0), low_priority); + p->set_piece_priority(piece_index_t(0), dont_download); - std::vector prios; + std::vector prios; p->piece_priorities(prios); TEST_CHECK(prios.size() == 7); - int prio_comp[] = {0, 6, 5, 4, 3, 2, 1}; + download_priority_t prio_comp[] = {0_pri, 6_pri, 5_pri, 4_pri, 3_pri, 2_pri, 1_pri}; TEST_CHECK(std::equal(prios.begin(), prios.end(), prio_comp)); } @@ -1042,7 +1043,7 @@ TORRENT_TEST(restore_piece) p->mark_as_finished({piece_index_t(0), 1}, nullptr); p->mark_as_finished({piece_index_t(0), 2}, nullptr); p->mark_as_finished({piece_index_t(0), 3}, nullptr); - p->set_piece_priority(piece_index_t(0), 0); + p->set_piece_priority(piece_index_t(0), dont_download); picked = pick_pieces(p, "*******", 1, 0, nullptr, options, empty_vector); TEST_CHECK(int(picked.size()) >= 1); @@ -1053,7 +1054,7 @@ TORRENT_TEST(restore_piece) TEST_CHECK(int(picked.size()) >= 1); TEST_CHECK(picked.front().piece_index == piece_index_t(1)); - p->set_piece_priority(piece_index_t(0), 7); + p->set_piece_priority(piece_index_t(0), top_priority); picked = pick_pieces(p, "*******", 1, 0, nullptr, options, empty_vector); TEST_CHECK(int(picked.size()) >= 1); TEST_CHECK(picked.front().piece_index == piece_index_t(0)); @@ -1412,10 +1413,10 @@ TORRENT_TEST(suggested_pieces) TEST_CHECK(int(picked.size()) >= blocks_per_piece); for (int i = 1; i < int(picked.size()); ++i) TEST_CHECK(picked[i] == piece_block(piece_index_t(1), i)); - p->set_piece_priority(piece_index_t(0), 0); - p->set_piece_priority(piece_index_t(1), 0); - p->set_piece_priority(piece_index_t(2), 0); - p->set_piece_priority(piece_index_t(3), 0); + p->set_piece_priority(piece_index_t(0), dont_download); + p->set_piece_priority(piece_index_t(1), dont_download); + p->set_piece_priority(piece_index_t(2), dont_download); + p->set_piece_priority(piece_index_t(3), dont_download); picked = pick_pieces(p, "****************", 1, blocks_per_piece , nullptr, options, suggested_pieces); @@ -1795,7 +1796,7 @@ TORRENT_TEST(get_download_queue_size) TEST_EQUAL(p->get_download_queue_size(), 5); - p->set_piece_priority(piece_index_t(1), 0); + p->set_piece_priority(piece_index_t(1), dont_download); int partial; int full; @@ -1884,7 +1885,7 @@ TORRENT_TEST(reprioritize_downloading) TEST_EQUAL(test_pick(p, piece_picker::rarest_first | piece_picker::prioritize_partials), piece_index_t(0)); // set the priority of the piece to 0 (while downloading it) - ret = p->set_piece_priority(piece_index_t(0), 0); + ret = p->set_piece_priority(piece_index_t(0), dont_download); TEST_EQUAL(ret, true); // make sure we _DON'T_ pick the partial piece, since it has priority zero @@ -1895,7 +1896,7 @@ TORRENT_TEST(reprioritize_downloading) // set the priority of the piece back to 1. It should now be the best pick // again (since it's partial) - ret = p->set_piece_priority(piece_index_t(0), 1); + ret = p->set_piece_priority(piece_index_t(0), low_priority); TEST_EQUAL(ret, true); // make sure we pick the partial piece @@ -1923,7 +1924,7 @@ TORRENT_TEST(reprioritize_fully_downloading) } // set the priority of the piece to 0 (while downloading it) - ret = p->set_piece_priority(piece_index_t(0), 0); + ret = p->set_piece_priority(piece_index_t(0), dont_download); TEST_EQUAL(ret, true); // make sure we still _DON'T_ pick the downloading piece @@ -1936,7 +1937,7 @@ TORRENT_TEST(reprioritize_fully_downloading) // set the priority of the piece back to 1. It should now be the best pick // again (since it's partial) - ret = p->set_piece_priority(piece_index_t(0), 1); + ret = p->set_piece_priority(piece_index_t(0), low_priority); TEST_EQUAL(ret, true); // make sure we still _DON'T_ pick the downloading piece @@ -1954,7 +1955,7 @@ TORRENT_TEST(download_filtered_piece) bool ret; // set the priority of the piece to 0 - ret = p->set_piece_priority(piece_index_t(0), 0); + ret = p->set_piece_priority(piece_index_t(0), dont_download); TEST_EQUAL(ret, true); // make sure we _DON'T_ pick piece 0 @@ -1982,7 +1983,7 @@ TORRENT_TEST(download_filtered_piece) // set the priority of the piece back to 1. It should now be the best pick // again (since it's partial) - ret = p->set_piece_priority(piece_index_t(0), 1); + ret = p->set_piece_priority(piece_index_t(0), low_priority); TEST_EQUAL(ret, true); // make sure we pick piece 0 diff --git a/test/test_priority.cpp b/test/test_priority.cpp index 15642b557..ebef68da1 100644 --- a/test/test_priority.cpp +++ b/test/test_priority.cpp @@ -43,6 +43,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include "test.hpp" +#include "test_utils.hpp" #include "setup_transfer.hpp" #include "settings.hpp" #include @@ -132,12 +133,12 @@ void test_transfer(settings_pack const& sett, bool test_deprecated = false) , true, false, true, "_priority", 8 * 1024, &t, false, nullptr); int const num_pieces = tor2.torrent_file()->num_pieces(); - aux::vector priorities(num_pieces, 1); + aux::vector priorities(num_pieces, 1_pri); // set half of the pieces to priority 0 - std::fill(priorities.begin(), priorities.begin() + (num_pieces / 2), 0); + std::fill(priorities.begin(), priorities.begin() + (num_pieces / 2), 0_pri); tor2.prioritize_pieces(priorities); std::cout << "setting priorities: "; - std::copy(priorities.begin(), priorities.end(), std::ostream_iterator(std::cout, ", ")); + std::copy(priorities.begin(), priorities.end(), std::ostream_iterator(std::cout, ", ")); std::cout << std::endl; for (int i = 0; i < 200; ++i) @@ -184,8 +185,9 @@ void test_transfer(settings_pack const& sett, bool test_deprecated = false) std::cout << "torrent is finished (50% complete)" << std::endl; else return; - std::vector priorities2 = tor2.piece_priorities(); - std::copy(priorities2.begin(), priorities2.end(), std::ostream_iterator(std::cout, ", ")); + std::vector priorities2 = tor2.piece_priorities(); + std::copy(priorities2.begin(), priorities2.end() + , std::ostream_iterator(std::cout, ", ")); std::cout << std::endl; TEST_CHECK(std::equal(priorities.begin(), priorities.end(), priorities2.begin())); @@ -193,7 +195,8 @@ void test_transfer(settings_pack const& sett, bool test_deprecated = false) tor2.force_recheck(); priorities2 = tor2.piece_priorities(); - std::copy(priorities2.begin(), priorities2.end(), std::ostream_iterator(std::cout, ", ")); + std::copy(priorities2.begin(), priorities2.end() + , std::ostream_iterator(std::cout, ", ")); std::cout << std::endl; TEST_CHECK(std::equal(priorities.begin(), priorities.end(), priorities2.begin())); @@ -225,7 +228,7 @@ void test_transfer(settings_pack const& sett, bool test_deprecated = false) std::cout << "recheck complete" << std::endl; priorities2 = tor2.piece_priorities(); - std::copy(priorities2.begin(), priorities2.end(), std::ostream_iterator(std::cout, ", ")); + std::copy(priorities2.begin(), priorities2.end(), std::ostream_iterator(std::cout, ", ")); std::cout << std::endl; TEST_CHECK(std::equal(priorities.begin(), priorities.end(), priorities2.begin())); @@ -325,12 +328,13 @@ done: TEST_CHECK(!st2.is_seeding); TEST_CHECK(st2.is_finished); - std::fill(priorities.begin(), priorities.end(), 1); + std::fill(priorities.begin(), priorities.end(), 1_pri); tor2.prioritize_pieces(priorities); std::cout << "setting priorities to 1" << std::endl; TEST_EQUAL(tor2.status().is_finished, false); - std::copy(priorities.begin(), priorities.end(), std::ostream_iterator(std::cout, ", ")); + std::copy(priorities.begin(), priorities.end() + , std::ostream_iterator(std::cout, ", ")); std::cout << std::endl; // drain alerts @@ -410,10 +414,10 @@ TORRENT_TEST(no_metadata_file_prio) addp.save_path = "."; torrent_handle h = ses.add_torrent(addp); - h.file_priority(file_index_t(0), 0); - TEST_EQUAL(h.file_priority(file_index_t(0)), 0); - h.file_priority(file_index_t(0), 1); - TEST_EQUAL(h.file_priority(file_index_t(0)), 1); + h.file_priority(file_index_t(0), 0_pri); + TEST_EQUAL(h.file_priority(file_index_t(0)), 0_pri); + h.file_priority(file_index_t(0), 1_pri); + TEST_EQUAL(h.file_priority(file_index_t(0)), 1_pri); ses.remove_torrent(h); } @@ -431,10 +435,10 @@ TORRENT_TEST(no_metadata_piece_prio) torrent_handle h = ses.add_torrent(addp); // you can't set piece priorities before the metadata has been downloaded - h.piece_priority(piece_index_t(2), 0); - TEST_EQUAL(h.piece_priority(piece_index_t(2)), 4); - h.piece_priority(piece_index_t(2), 1); - TEST_EQUAL(h.piece_priority(piece_index_t(2)), 4); + h.piece_priority(piece_index_t(2), 0_pri); + TEST_EQUAL(h.piece_priority(piece_index_t(2)), 4_pri); + h.piece_priority(piece_index_t(2), 1_pri); + TEST_EQUAL(h.piece_priority(piece_index_t(2)), 4_pri); ses.remove_torrent(h); } diff --git a/test/test_read_resume.cpp b/test/test_read_resume.cpp index 1a99c36df..c96f4d8cf 100644 --- a/test/test_read_resume.cpp +++ b/test/test_read_resume.cpp @@ -31,6 +31,7 @@ POSSIBILITY OF SUCH DAMAGE. */ #include "test.hpp" +#include "test_utils.hpp" #include @@ -106,12 +107,12 @@ TORRENT_TEST(read_resume) TEST_EQUAL(atp.finished_time, 1352); TEST_EQUAL(atp.piece_priorities.size(), 6); - TEST_EQUAL(atp.piece_priorities[0], 1); - TEST_EQUAL(atp.piece_priorities[1], 2); - TEST_EQUAL(atp.piece_priorities[2], 3); - TEST_EQUAL(atp.piece_priorities[3], 4); - TEST_EQUAL(atp.piece_priorities[4], 5); - TEST_EQUAL(atp.piece_priorities[5], 6); + TEST_EQUAL(atp.piece_priorities[0], 1_pri); + TEST_EQUAL(atp.piece_priorities[1], 2_pri); + TEST_EQUAL(atp.piece_priorities[2], 3_pri); + TEST_EQUAL(atp.piece_priorities[3], 4_pri); + TEST_EQUAL(atp.piece_priorities[4], 5_pri); + TEST_EQUAL(atp.piece_priorities[5], 6_pri); } TORRENT_TEST(read_resume_missing_info_hash) diff --git a/test/test_remove_torrent.cpp b/test/test_remove_torrent.cpp index 91973aae5..1a3d3e4e7 100644 --- a/test/test_remove_torrent.cpp +++ b/test/test_remove_torrent.cpp @@ -94,9 +94,9 @@ void test_remove_torrent(remove_flags_t const remove_options if (test == partial_download) { - std::vector priorities(num_pieces, 1); + std::vector priorities(num_pieces, low_priority); // set half of the pieces to priority 0 - std::fill(priorities.begin(), priorities.begin() + (num_pieces / 2), 0); + std::fill(priorities.begin(), priorities.begin() + (num_pieces / 2), dont_download); tor2.prioritize_pieces(priorities); } diff --git a/test/test_resume.cpp b/test/test_resume.cpp index eadf2a1cd..5bb5763f8 100644 --- a/test/test_resume.cpp +++ b/test/test_resume.cpp @@ -43,6 +43,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "setup_transfer.hpp" #include "test.hpp" +#include "test_utils.hpp" #include "settings.hpp" #include "setup_transfer.hpp" #include "settings.hpp" @@ -184,9 +185,9 @@ torrent_handle test_resume_flags(lt::session& ses if (file_priorities[0]) { - aux::vector priorities_vector; + aux::vector priorities_vector; for (int i = 0; file_priorities[i]; ++i) - priorities_vector.push_back(file_priorities[i] - '0'); + priorities_vector.push_back(download_priority_t(file_priorities[i] - '0')); p.file_priorities = priorities_vector; } @@ -226,8 +227,8 @@ void test_piece_priorities(bool test_deprecated = false) p.save_path = "."; torrent_handle h = ses.add_torrent(p); - h.piece_priority(piece_index_t(0), 0); - h.piece_priority(piece_index_t(ti->num_pieces()-1), 0); + h.piece_priority(piece_index_t(0), 0_pri); + h.piece_priority(piece_index_t(ti->num_pieces()-1), 0_pri); h.save_resume_data(); alert const* a = wait_for_alert(ses, save_resume_data_alert::alert_type); @@ -239,9 +240,9 @@ void test_piece_priorities(bool test_deprecated = false) { auto const prios = ra->params.piece_priorities; TEST_EQUAL(int(prios.size()), ti->num_pieces()); - TEST_EQUAL(prios[0], '\0'); - TEST_EQUAL(prios[1], '\x04'); - TEST_EQUAL(prios[ti->num_pieces()-1], '\0'); + TEST_EQUAL(prios[0], 0_pri); + TEST_EQUAL(prios[1], 4_pri); + TEST_EQUAL(prios[ti->num_pieces()-1], 0_pri); std::vector resume_data = write_resume_data_buf(ra->params); @@ -266,9 +267,9 @@ void test_piece_priorities(bool test_deprecated = false) // now, make sure the piece priorities are loaded correctly h = ses.add_torrent(p); - TEST_EQUAL(h.piece_priority(piece_index_t(0)), 0); - TEST_EQUAL(h.piece_priority(piece_index_t(1)), 4); - TEST_EQUAL(h.piece_priority(piece_index_t(ti->num_pieces()-1)), 0); + TEST_EQUAL(h.piece_priority(piece_index_t(0)), 0_pri); + TEST_EQUAL(h.piece_priority(piece_index_t(1)), 4_pri); + TEST_EQUAL(h.piece_priority(piece_index_t(ti->num_pieces()-1)), 0_pri); } #ifndef TORRENT_NO_DEPRECATE @@ -416,7 +417,7 @@ TORRENT_TEST(piece_slots_seed_suggest_cache) TORRENT_TEST(file_priorities_default_deprecated) { lt::session ses(settings()); - std::vector file_priorities = test_resume_flags(ses + std::vector file_priorities = test_resume_flags(ses , {}, "", "", true).file_priorities(); TEST_EQUAL(file_priorities.size(), 3); @@ -430,7 +431,7 @@ TORRENT_TEST(file_priorities_default_deprecated) TORRENT_TEST(file_priorities_in_resume_deprecated) { lt::session ses(settings()); - std::vector file_priorities = test_resume_flags(ses, {}, "", "123").file_priorities(); + std::vector file_priorities = test_resume_flags(ses, {}, "", "123").file_priorities(); TEST_EQUAL(file_priorities.size(), 3); TEST_EQUAL(file_priorities[0], 1); @@ -443,7 +444,7 @@ TORRENT_TEST(file_priorities_in_resume_deprecated) TORRENT_TEST(file_priorities_in_resume_and_params_deprecated) { lt::session ses(settings()); - std::vector file_priorities = test_resume_flags(ses, {}, "456", "123").file_priorities(); + std::vector file_priorities = test_resume_flags(ses, {}, "456", "123").file_priorities(); TEST_EQUAL(file_priorities.size(), 3); TEST_EQUAL(file_priorities[0], 4); @@ -455,7 +456,7 @@ TORRENT_TEST(file_priorities_in_resume_and_params_deprecated) TORRENT_TEST(file_priorities_override_resume_deprecated) { lt::session ses(settings()); - std::vector file_priorities = test_resume_flags(ses + std::vector file_priorities = test_resume_flags(ses , add_torrent_params::flag_override_resume_data, "", "123").file_priorities(); TEST_EQUAL(file_priorities.size(), 3); @@ -468,7 +469,7 @@ TORRENT_TEST(file_priorities_resume_seed_mode_deprecated) { // in share mode file priorities should always be 0 lt::session ses(settings()); - std::vector file_priorities = test_resume_flags(ses, + std::vector file_priorities = test_resume_flags(ses, torrent_flags::share_mode, "", "123", true).file_priorities(); TEST_EQUAL(file_priorities.size(), 3); @@ -481,7 +482,7 @@ TORRENT_TEST(file_priorities_seed_mode_deprecated) { // in share mode file priorities should always be 0 lt::session ses(settings()); - std::vector file_priorities = test_resume_flags(ses, + std::vector file_priorities = test_resume_flags(ses, torrent_flags::share_mode, "123", "", true).file_priorities(); TEST_EQUAL(file_priorities.size(), 3); @@ -540,7 +541,7 @@ TORRENT_TEST(file_priorities_resume_override_deprecated) // override the resume data file priorities, even when override resume data // flag is set. lt::session ses(settings()); - std::vector file_priorities = test_resume_flags(ses, + std::vector file_priorities = test_resume_flags(ses, torrent_flags::override_resume_data, "", "123", true).file_priorities(); TEST_EQUAL(file_priorities.size(), 3); @@ -552,7 +553,7 @@ TORRENT_TEST(file_priorities_resume_override_deprecated) TORRENT_TEST(file_priorities_resume_deprecated) { lt::session ses(settings()); - std::vector file_priorities = test_resume_flags(ses, {}, "", "123", true).file_priorities(); + std::vector file_priorities = test_resume_flags(ses, {}, "", "123", true).file_priorities(); TEST_EQUAL(file_priorities.size(), 3); TEST_EQUAL(file_priorities[0], 1); @@ -563,7 +564,7 @@ TORRENT_TEST(file_priorities_resume_deprecated) TORRENT_TEST(file_priorities1_deprecated) { lt::session ses(settings()); - std::vector file_priorities = test_resume_flags(ses, {}, "010", "", true).file_priorities(); + std::vector file_priorities = test_resume_flags(ses, {}, "010", "", true).file_priorities(); TEST_EQUAL(file_priorities.size(), 3); TEST_EQUAL(file_priorities[0], 0); @@ -576,7 +577,7 @@ TORRENT_TEST(file_priorities1_deprecated) TORRENT_TEST(file_priorities2_deprecated) { lt::session ses(settings()); - std::vector file_priorities = test_resume_flags(ses, {}, "123", "", true).file_priorities(); + std::vector file_priorities = test_resume_flags(ses, {}, "123", "", true).file_priorities(); TEST_EQUAL(file_priorities.size(), 3); TEST_EQUAL(file_priorities[0], 1); @@ -587,7 +588,7 @@ TORRENT_TEST(file_priorities2_deprecated) TORRENT_TEST(file_priorities3_deprecated) { lt::session ses(settings()); - std::vector file_priorities = test_resume_flags(ses, {}, "4321", "", true).file_priorities(); + std::vector file_priorities = test_resume_flags(ses, {}, "4321", "", true).file_priorities(); TEST_EQUAL(file_priorities.size(), 3); TEST_EQUAL(file_priorities[0], 4); @@ -777,38 +778,39 @@ TORRENT_TEST(resume_override_torrent_deprecated) TORRENT_TEST(file_priorities_default) { lt::session ses(settings()); - std::vector file_priorities = test_resume_flags(ses, {}, "", "").file_priorities(); + std::vector file_priorities + = test_resume_flags(ses, {}, "", "").file_priorities(); TEST_EQUAL(file_priorities.size(), 3); - TEST_EQUAL(file_priorities[0], 4); - TEST_EQUAL(file_priorities[1], 4); - TEST_EQUAL(file_priorities[2], 4); + TEST_EQUAL(file_priorities[0], 4_pri); + TEST_EQUAL(file_priorities[1], 4_pri); + TEST_EQUAL(file_priorities[2], 4_pri); } TORRENT_TEST(file_priorities_resume_seed_mode) { // in share mode file priorities should always be 0 lt::session ses(settings()); - std::vector file_priorities = test_resume_flags(ses + std::vector file_priorities = test_resume_flags(ses , torrent_flags::share_mode, "", "123").file_priorities(); TEST_EQUAL(file_priorities.size(), 3); - TEST_EQUAL(file_priorities[0], 0); - TEST_EQUAL(file_priorities[1], 0); - TEST_EQUAL(file_priorities[2], 0); + TEST_EQUAL(file_priorities[0], 0_pri); + TEST_EQUAL(file_priorities[1], 0_pri); + TEST_EQUAL(file_priorities[2], 0_pri); } TORRENT_TEST(file_priorities_seed_mode) { // in share mode file priorities should always be 0 lt::session ses(settings()); - std::vector file_priorities = test_resume_flags(ses + std::vector file_priorities = test_resume_flags(ses , torrent_flags::share_mode, "123", "").file_priorities(); TEST_EQUAL(file_priorities.size(), 3); - TEST_EQUAL(file_priorities[0], 0); - TEST_EQUAL(file_priorities[1], 0); - TEST_EQUAL(file_priorities[2], 0); + TEST_EQUAL(file_priorities[0], 0_pri); + TEST_EQUAL(file_priorities[1], 0_pri); + TEST_EQUAL(file_priorities[2], 0_pri); } void test_zero_file_prio(bool test_deprecated = false) @@ -1071,9 +1073,9 @@ TORRENT_TEST(resume_save_load) auto const l = a->params.file_priorities; TEST_EQUAL(l.size(), 3); - TEST_EQUAL(l[0], 1); - TEST_EQUAL(l[1], 2); - TEST_EQUAL(l[2], 3); + TEST_EQUAL(l[0], 1_pri); + TEST_EQUAL(l[1], 2_pri); + TEST_EQUAL(l[2], 3_pri); } TORRENT_TEST(resume_save_load_resume) @@ -1093,31 +1095,31 @@ TORRENT_TEST(resume_save_load_resume) auto const l = a->params.file_priorities; TEST_EQUAL(l.size(), 3); - TEST_EQUAL(l[0], 1); - TEST_EQUAL(l[1], 2); - TEST_EQUAL(l[2], 3); + TEST_EQUAL(l[0], 1_pri); + TEST_EQUAL(l[1], 2_pri); + TEST_EQUAL(l[2], 3_pri); } TORRENT_TEST(file_priorities_resume) { lt::session ses(settings()); - std::vector file_priorities = test_resume_flags(ses, {}, "", "123").file_priorities(); + std::vector file_priorities = test_resume_flags(ses, {}, "", "123").file_priorities(); TEST_EQUAL(file_priorities.size(), 3); - TEST_EQUAL(file_priorities[0], 1); - TEST_EQUAL(file_priorities[1], 2); - TEST_EQUAL(file_priorities[2], 3); + TEST_EQUAL(file_priorities[0], 1_pri); + TEST_EQUAL(file_priorities[1], 2_pri); + TEST_EQUAL(file_priorities[2], 3_pri); } TORRENT_TEST(file_priorities1) { lt::session ses(settings()); - std::vector file_priorities = test_resume_flags(ses, {}, "010").file_priorities(); + std::vector file_priorities = test_resume_flags(ses, {}, "010").file_priorities(); TEST_EQUAL(file_priorities.size(), 3); - TEST_EQUAL(file_priorities[0], 0); - TEST_EQUAL(file_priorities[1], 1); - TEST_EQUAL(file_priorities[2], 0); + TEST_EQUAL(file_priorities[0], 0_pri); + TEST_EQUAL(file_priorities[1], 1_pri); + TEST_EQUAL(file_priorities[2], 0_pri); //#error save resume data and assert the file priorities are preserved } @@ -1125,23 +1127,23 @@ TORRENT_TEST(file_priorities1) TORRENT_TEST(file_priorities2) { lt::session ses(settings()); - std::vector file_priorities = test_resume_flags(ses, {}, "123").file_priorities(); + std::vector file_priorities = test_resume_flags(ses, {}, "123").file_priorities(); TEST_EQUAL(file_priorities.size(), 3); - TEST_EQUAL(file_priorities[0], 1); - TEST_EQUAL(file_priorities[1], 2); - TEST_EQUAL(file_priorities[2], 3); + TEST_EQUAL(file_priorities[0], 1_pri); + TEST_EQUAL(file_priorities[1], 2_pri); + TEST_EQUAL(file_priorities[2], 3_pri); } TORRENT_TEST(file_priorities3) { lt::session ses(settings()); - std::vector file_priorities = test_resume_flags(ses, {}, "4321").file_priorities(); + std::vector file_priorities = test_resume_flags(ses, {}, "4321").file_priorities(); TEST_EQUAL(file_priorities.size(), 3); - TEST_EQUAL(file_priorities[0], 4); - TEST_EQUAL(file_priorities[1], 3); - TEST_EQUAL(file_priorities[2], 2); + TEST_EQUAL(file_priorities[0], 4_pri); + TEST_EQUAL(file_priorities[1], 3_pri); + TEST_EQUAL(file_priorities[2], 2_pri); } TORRENT_TEST(plain) diff --git a/test/test_storage.cpp b/test/test_storage.cpp index c74a275b9..fbc5398fa 100644 --- a/test/test_storage.cpp +++ b/test/test_storage.cpp @@ -160,7 +160,7 @@ std::shared_ptr setup_torrent(file_storage& fs { std::shared_ptr info = setup_torrent_info(fs, buf); - aux::vector priorities; + aux::vector priorities; sha1_hash info_hash; storage_params p{ fs, @@ -235,7 +235,7 @@ void run_storage_tests(std::shared_ptr info boost::asio::io_service ios; disk_buffer_pool dp(16 * 1024, ios, std::bind(&nop)); - aux::vector priorities; + aux::vector priorities; sha1_hash info_hash; storage_params p{ fs, @@ -478,7 +478,7 @@ void test_check_files(std::string const& test_path disk_buffer_pool dp(16 * 1024, ios, std::bind(&nop)); - aux::vector priorities; + aux::vector priorities; sha1_hash info_hash; storage_params p{ fs, diff --git a/test/test_torrent.cpp b/test/test_torrent.cpp index 9ef62b7eb..5ed71aeef 100644 --- a/test/test_torrent.cpp +++ b/test/test_torrent.cpp @@ -46,6 +46,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include "test.hpp" +#include "test_utils.hpp" #include "setup_transfer.hpp" using namespace lt; @@ -58,8 +59,8 @@ void test_running_torrent(std::shared_ptr info, std::int64_t file_ pack.set_int(settings_pack::max_retry_port_bind, 10); lt::session ses(pack); - aux::vector zeroes; - zeroes.resize(1000, 0); + aux::vector zeroes; + zeroes.resize(1000, 0_pri); add_torrent_params p; p.flags &= ~torrent_flags::paused; p.flags &= ~torrent_flags::auto_managed; @@ -78,7 +79,7 @@ void test_running_torrent(std::shared_ptr info, std::int64_t file_ return; } - aux::vector ones(info->num_files(), 1); + aux::vector ones(info->num_files(), 1_pri); h.prioritize_files(ones); torrent_status st = h.status(); @@ -86,8 +87,8 @@ void test_running_torrent(std::shared_ptr info, std::int64_t file_ TEST_EQUAL(st.total_wanted, file_size); // we want the single file TEST_EQUAL(st.total_wanted_done, 0); - aux::vector prio(info->num_files(), 1); - prio[file_index_t(0)] = 0; + aux::vector prio(info->num_files(), 1_pri); + prio[file_index_t(0)] = 0_pri; h.prioritize_files(prio); st = h.status(); @@ -96,16 +97,16 @@ void test_running_torrent(std::shared_ptr info, std::int64_t file_ TEST_EQUAL(int(h.file_priorities().size()), info->num_files()); if (!st.is_seeding) { - TEST_EQUAL(h.file_priorities()[0], 0); + TEST_EQUAL(h.file_priorities()[0], 0_pri); if (info->num_files() > 1) - TEST_EQUAL(h.file_priorities()[1], 1); + TEST_EQUAL(h.file_priorities()[1], 1_pri); if (info->num_files() > 2) - TEST_EQUAL(h.file_priorities()[2], 1); + TEST_EQUAL(h.file_priorities()[2], 1_pri); } if (info->num_files() > 1) { - prio[file_index_t(1)] = 0; + prio[file_index_t(1)] = 0_pri; h.prioritize_files(prio); st = h.status(); @@ -114,17 +115,17 @@ void test_running_torrent(std::shared_ptr info, std::int64_t file_ if (!st.is_seeding) { TEST_EQUAL(int(h.file_priorities().size()), info->num_files()); - TEST_EQUAL(h.file_priorities()[0], 0); + TEST_EQUAL(h.file_priorities()[0], 0_pri); if (info->num_files() > 1) - TEST_EQUAL(h.file_priorities()[1], 0); + TEST_EQUAL(h.file_priorities()[1], 0_pri); if (info->num_files() > 2) - TEST_EQUAL(h.file_priorities()[2], 1); + TEST_EQUAL(h.file_priorities()[2], 1_pri); } } if (info->num_pieces() > 0) { - h.piece_priority(piece_index_t(0), 1); + h.piece_priority(piece_index_t(0), 1_pri); st = h.status(); TEST_CHECK(st.pieces.size() > 0 && st.pieces[piece_index_t(0)] == false); std::vector piece(info->piece_length()); @@ -203,8 +204,8 @@ TORRENT_TEST(total_wanted) 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.file_priorities.resize(4, 0_pri); + p.file_priorities[1] = 1_pri; p.ti = info; @@ -480,7 +481,7 @@ void test_queue(add_torrent_params p) torrents.push_back(ses.add_torrent(std::move(p))); } - std::vector pieces(torrents[5].torrent_file()->num_pieces(), 0); + std::vector pieces(torrents[5].torrent_file()->num_pieces(), 0_pri); torrents[5].prioritize_pieces(pieces); torrent_handle finished = torrents[5]; diff --git a/test/test_transfer.cpp b/test/test_transfer.cpp index 76dcdf559..fee521035 100644 --- a/test/test_transfer.cpp +++ b/test/test_transfer.cpp @@ -77,7 +77,7 @@ struct test_storage : default_storage , m_limit(16 * 1024 * 2) {} - void set_file_priority(aux::vector const& p + void set_file_priority(aux::vector const& p , storage_error& ec) override {} void set_limit(int lim) diff --git a/test/test_utils.hpp b/test/test_utils.hpp index 3f2cdd7cb..37c25224f 100644 --- a/test/test_utils.hpp +++ b/test/test_utils.hpp @@ -34,10 +34,17 @@ POSSIBILITY OF SUCH DAMAGE. #define TEST_UTILS_HPP #include "test.hpp" +#include "libtorrent/download_priority.hpp" namespace libtorrent { EXPORT char const* time_now_string(); + +} + +inline lt::download_priority_t operator ""_pri(unsigned long long const p) +{ + return lt::download_priority_t(static_cast(p)); } #endif