forked from premiere/premiere-libtorrent
introduce a download_priority_t type, for uniform an type-safe piece- and file priorities
This commit is contained in:
parent
505b388a36
commit
6785046c2f
|
@ -283,7 +283,7 @@ void bind_converters()
|
|||
{
|
||||
// C++ -> python conversions
|
||||
to_python_converter<std::pair<int, int>, pair_to_tuple<int, int>>();
|
||||
to_python_converter<std::pair<lt::piece_index_t, int>, pair_to_tuple<lt::piece_index_t, int>>();
|
||||
to_python_converter<std::pair<lt::piece_index_t, lt::download_priority_t>, pair_to_tuple<lt::piece_index_t, lt::download_priority_t>>();
|
||||
to_python_converter<lt::tcp::endpoint, endpoint_to_tuple<lt::tcp::endpoint>>();
|
||||
to_python_converter<lt::udp::endpoint, endpoint_to_tuple<lt::udp::endpoint>>();
|
||||
to_python_converter<lt::address, address_to_tuple<lt::address>>();
|
||||
|
@ -294,13 +294,14 @@ void bind_converters()
|
|||
to_python_converter<std::vector<lt::sha1_hash>, vector_to_list<std::vector<lt::sha1_hash>>>();
|
||||
to_python_converter<std::vector<std::string>, vector_to_list<std::vector<std::string>>>();
|
||||
to_python_converter<std::vector<int>, vector_to_list<std::vector<int>>>();
|
||||
to_python_converter<std::vector<std::uint8_t>, vector_to_list<std::vector<std::uint8_t>>>();
|
||||
to_python_converter<std::vector<lt::download_priority_t>, vector_to_list<std::vector<lt::download_priority_t>>>();
|
||||
to_python_converter<std::vector<lt::tcp::endpoint>, vector_to_list<std::vector<lt::tcp::endpoint>>>();
|
||||
to_python_converter<std::vector<lt::udp::endpoint>, vector_to_list<std::vector<lt::udp::endpoint>>>();
|
||||
to_python_converter<std::vector<std::pair<std::string, int>>, vector_to_list<std::vector<std::pair<std::string, int>>>>();
|
||||
|
||||
to_python_converter<lt::queue_position_t, from_strong_typedef<lt::queue_position_t>>();
|
||||
to_python_converter<lt::piece_index_t, from_strong_typedef<lt::piece_index_t>>();
|
||||
to_python_converter<lt::download_priority_t, from_strong_typedef<lt::download_priority_t>>();
|
||||
to_python_converter<lt::file_index_t, from_strong_typedef<lt::file_index_t>>();
|
||||
to_python_converter<lt::port_mapping_t, from_strong_typedef<lt::port_mapping_t>>();
|
||||
to_python_converter<lt::peer_class_t, from_strong_typedef<lt::peer_class_t>>();
|
||||
|
@ -335,7 +336,7 @@ void bind_converters()
|
|||
to_python_converter<lt::aux::noexcept_movable<std::vector<lt::sha1_hash>>, vector_to_list<lt::aux::noexcept_movable<std::vector<lt::sha1_hash>>>>();
|
||||
to_python_converter<lt::aux::noexcept_movable<std::vector<std::string>>, vector_to_list<lt::aux::noexcept_movable<std::vector<std::string>>>>();
|
||||
to_python_converter<lt::aux::noexcept_movable<std::vector<int>>, vector_to_list<lt::aux::noexcept_movable<std::vector<int>>>>();
|
||||
to_python_converter<lt::aux::noexcept_movable<std::vector<std::uint8_t>>, vector_to_list<lt::aux::noexcept_movable<std::vector<std::uint8_t>>>>();
|
||||
to_python_converter<lt::aux::noexcept_movable<std::vector<lt::download_priority_t>>, vector_to_list<lt::aux::noexcept_movable<std::vector<lt::download_priority_t>>>>();
|
||||
to_python_converter<lt::aux::noexcept_movable<std::vector<lt::tcp::endpoint>>, vector_to_list<lt::aux::noexcept_movable<std::vector<lt::tcp::endpoint>>>>();
|
||||
to_python_converter<lt::aux::noexcept_movable<std::vector<lt::udp::endpoint>>, vector_to_list<lt::aux::noexcept_movable<std::vector<lt::udp::endpoint>>>>();
|
||||
to_python_converter<lt::aux::noexcept_movable<std::vector<std::pair<std::string, int>>>, vector_to_list<lt::aux::noexcept_movable<std::vector<std::pair<std::string, int>>>>>();
|
||||
|
@ -345,10 +346,10 @@ void bind_converters()
|
|||
tuple_to_pair<std::string, int>();
|
||||
tuple_to_endpoint<lt::tcp::endpoint>();
|
||||
tuple_to_endpoint<lt::udp::endpoint>();
|
||||
tuple_to_pair<lt::piece_index_t, int>();
|
||||
tuple_to_pair<lt::piece_index_t, lt::download_priority_t>();
|
||||
dict_to_map<lt::file_index_t, std::string>();
|
||||
list_to_vector<std::vector<int>>();
|
||||
list_to_vector<std::vector<std::uint8_t>>();
|
||||
list_to_vector<std::vector<lt::download_priority_t>>();
|
||||
list_to_vector<std::vector<std::string>>();
|
||||
list_to_vector<std::vector<lt::tcp::endpoint>>();
|
||||
list_to_vector<std::vector<lt::udp::endpoint>>();
|
||||
|
@ -356,7 +357,7 @@ void bind_converters()
|
|||
|
||||
// work-around types
|
||||
list_to_vector<lt::aux::noexcept_movable<std::vector<int>>>();
|
||||
list_to_vector<lt::aux::noexcept_movable<std::vector<std::uint8_t>>>();
|
||||
list_to_vector<lt::aux::noexcept_movable<std::vector<lt::download_priority_t>>>();
|
||||
list_to_vector<lt::aux::noexcept_movable<std::vector<std::string>>>();
|
||||
list_to_vector<lt::aux::noexcept_movable<std::vector<lt::tcp::endpoint>>>();
|
||||
list_to_vector<lt::aux::noexcept_movable<std::vector<lt::udp::endpoint>>>();
|
||||
|
@ -364,6 +365,7 @@ void bind_converters()
|
|||
|
||||
to_strong_typedef<lt::queue_position_t>();
|
||||
to_strong_typedef<lt::piece_index_t>();
|
||||
to_strong_typedef<lt::download_priority_t>();
|
||||
to_strong_typedef<lt::file_index_t>();
|
||||
to_strong_typedef<lt::port_mapping_t>();
|
||||
to_strong_typedef<lt::peer_class_t>();
|
||||
|
|
|
@ -335,7 +335,7 @@ namespace
|
|||
}
|
||||
else if(key == "file_priorities")
|
||||
{
|
||||
p.file_priorities = extract<std::vector<std::uint8_t>>(value);
|
||||
p.file_priorities = extract<std::vector<download_priority_t>>(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -67,24 +67,22 @@ namespace
|
|||
handle.piece_availability(avail);
|
||||
}
|
||||
|
||||
for (std::vector<int>::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<int> prio;
|
||||
std::vector<download_priority_t> prio;
|
||||
{
|
||||
allow_threading_guard guard;
|
||||
prio = handle.piece_priorities();
|
||||
}
|
||||
|
||||
for (std::vector<int>::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<std::pair<piece_index_t, int>>(*begin).check();
|
||||
bool const is_piece_list = extract<std::pair<piece_index_t, download_priority_t>>(*begin).check();
|
||||
|
||||
if (is_piece_list)
|
||||
{
|
||||
std::vector<std::pair<piece_index_t, int>> piece_list;
|
||||
std::vector<std::pair<piece_index_t, download_priority_t>> piece_list;
|
||||
std::transform(begin, end, std::back_inserter(piece_list)
|
||||
, &extract_fn<std::pair<piece_index_t, int>>);
|
||||
, &extract_fn<std::pair<piece_index_t, download_priority_t>>);
|
||||
info.prioritize_pieces(piece_list);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::vector<int> priority_vector;
|
||||
std::vector<download_priority_t> priority_vector;
|
||||
std::transform(begin, end, std::back_inserter(priority_vector)
|
||||
, &extract_fn<int>);
|
||||
, &extract_fn<download_priority_t>);
|
||||
info.prioritize_pieces(priority_vector);
|
||||
}
|
||||
}
|
||||
|
||||
void prioritize_files(torrent_handle& info, object o)
|
||||
{
|
||||
stl_input_iterator<int const> begin(o), end;
|
||||
info.prioritize_files(std::vector<int> (begin, end));
|
||||
stl_input_iterator<download_priority_t> begin(o), end;
|
||||
info.prioritize_files(std::vector<download_priority_t>(begin, end));
|
||||
}
|
||||
|
||||
list file_priorities(torrent_handle& handle)
|
||||
{
|
||||
list ret;
|
||||
std::vector<int> priorities = handle.file_priorities();
|
||||
std::vector<download_priority_t> priorities = handle.file_priorities();
|
||||
|
||||
for (std::vector<int>::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;
|
||||
|
|
|
@ -1797,7 +1797,7 @@ COLUMN OPTIONS
|
|||
std::vector<std::int64_t> file_progress;
|
||||
h.file_progress(file_progress);
|
||||
std::vector<lt::open_file_state> file_status = h.file_status();
|
||||
std::vector<int> file_prio = h.file_priorities();
|
||||
std::vector<lt::download_priority_t> file_prio = h.file_priorities();
|
||||
auto f = file_status.begin();
|
||||
std::shared_ptr<const lt::torrent_info> 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<std::uint8_t>(file_prio[idx]));
|
||||
|
||||
p += file_progress_width + 13;
|
||||
out += str;
|
||||
|
|
|
@ -846,7 +846,7 @@ void generate_data(char const* path, torrent_info const& ti)
|
|||
|
||||
file_pool fp;
|
||||
|
||||
aux::vector<std::uint8_t, file_index_t> priorities;
|
||||
aux::vector<download_priority_t, file_index_t> priorities;
|
||||
sha1_hash info_hash;
|
||||
storage_params params{
|
||||
fs,
|
||||
|
|
|
@ -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 \
|
||||
|
|
|
@ -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<std::vector<std::uint8_t>> file_priorities;
|
||||
aux::noexcept_movable<std::vector<download_priority_t>> 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<std::vector<std::uint8_t>> piece_priorities;
|
||||
aux::noexcept_movable<std::vector<download_priority_t>> 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
|
||||
|
|
|
@ -92,7 +92,7 @@ namespace aux {
|
|||
verify_resume_data(add_torrent_params const& rd
|
||||
, aux::vector<std::string, file_index_t> const& links
|
||||
, file_storage const& fs
|
||||
, aux::vector<std::uint8_t, file_index_t> const& file_priority
|
||||
, aux::vector<download_priority_t, file_index_t> const& file_priority
|
||||
, stat_cache& stat
|
||||
, std::string const& save_path
|
||||
, storage_error& ec);
|
||||
|
|
|
@ -178,7 +178,7 @@ namespace libtorrent {
|
|||
virtual void async_delete_files(storage_index_t storage, remove_flags_t options
|
||||
, std::function<void(storage_error const&)> handler) = 0;
|
||||
virtual void async_set_file_priority(storage_index_t storage
|
||||
, aux::vector<std::uint8_t, file_index_t> prio
|
||||
, aux::vector<download_priority_t, file_index_t> prio
|
||||
, std::function<void(storage_error const&)> handler) = 0;
|
||||
|
||||
virtual void async_clear_piece(storage_index_t storage, piece_index_t index
|
||||
|
|
|
@ -125,7 +125,7 @@ namespace libtorrent {
|
|||
boost::variant<disk_buffer_holder
|
||||
, std::string
|
||||
, add_torrent_params const*
|
||||
, aux::vector<std::uint8_t, file_index_t>
|
||||
, aux::vector<download_priority_t, file_index_t>
|
||||
, remove_flags_t
|
||||
> argument;
|
||||
|
||||
|
|
|
@ -324,7 +324,7 @@ namespace aux {
|
|||
void async_flush_piece(storage_index_t storage, piece_index_t piece
|
||||
, std::function<void()> handler = std::function<void()>()) override;
|
||||
void async_set_file_priority(storage_index_t storage
|
||||
, aux::vector<std::uint8_t, file_index_t> prio
|
||||
, aux::vector<download_priority_t, file_index_t> prio
|
||||
, std::function<void(storage_error const&)> handler) override;
|
||||
|
||||
void async_clear_piece(storage_index_t storage, piece_index_t index
|
||||
|
|
|
@ -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<std::uint8_t, download_priority_tag>;
|
||||
|
||||
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
|
||||
|
|
@ -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<int>& pieces) const;
|
||||
void piece_priorities(std::vector<download_priority_t>& 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<std::uint16_t>(peer_count_))
|
||||
, download_state(piece_pos::piece_open)
|
||||
, piece_priority(4)
|
||||
, piece_priority(static_cast<std::uint8_t>(default_priority))
|
||||
, index(index_)
|
||||
{
|
||||
TORRENT_ASSERT(peer_count_ >= 0);
|
||||
|
|
|
@ -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<std::uint8_t, file_index_t> const& prio
|
||||
virtual void set_file_priority(aux::vector<download_priority_t, file_index_t> 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<std::uint8_t, file_index_t> const& prio
|
||||
void set_file_priority(aux::vector<download_priority_t, file_index_t> 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<std::uint8_t, file_index_t> m_file_priority;
|
||||
aux::vector<download_priority_t, file_index_t> 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
|
||||
|
|
|
@ -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 <functional>
|
||||
#include <string>
|
||||
|
||||
|
@ -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<std::uint8_t, file_index_t> const& prio
|
||||
, aux::vector<download_priority_t, file_index_t> 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<std::uint8_t, file_index_t> const& priorities;
|
||||
aux::vector<download_priority_t, file_index_t> const& priorities;
|
||||
sha1_hash const& info_hash;
|
||||
};
|
||||
|
||||
|
|
|
@ -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<int, piece_index_t>& 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<int, piece_index_t> const& pieces);
|
||||
void prioritize_piece_list(std::vector<std::pair<piece_index_t, int>> const& pieces);
|
||||
void piece_priorities(aux::vector<int, piece_index_t>*) const;
|
||||
void prioritize_pieces(aux::vector<download_priority_t, piece_index_t> const& pieces);
|
||||
void prioritize_piece_list(std::vector<std::pair<piece_index_t, download_priority_t>> const& pieces);
|
||||
void piece_priorities(aux::vector<download_priority_t, piece_index_t>*) 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<int, file_index_t> const& files);
|
||||
void file_priorities(aux::vector<int, file_index_t>*) const;
|
||||
void prioritize_files(aux::vector<download_priority_t, file_index_t> const& files);
|
||||
void file_priorities(aux::vector<download_priority_t, file_index_t>*) 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<int, piece_index_t> const& priority);
|
||||
void remove_time_critical_pieces(aux::vector<download_priority_t, piece_index_t> 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<std::uint8_t, file_index_t> m_file_priority;
|
||||
aux::vector<download_priority_t, file_index_t> m_file_priority;
|
||||
|
||||
// this object is used to track download progress of individual files
|
||||
aux::file_progress m_file_progress;
|
||||
|
|
|
@ -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<download_priority_t> const& pieces) const;
|
||||
void prioritize_pieces(std::vector<std::pair<piece_index_t, download_priority_t>> const& pieces) const;
|
||||
std::vector<download_priority_t> piece_priorities() const;
|
||||
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
TORRENT_DEPRECATED
|
||||
void prioritize_pieces(std::vector<int> const& pieces) const;
|
||||
TORRENT_DEPRECATED
|
||||
void prioritize_pieces(std::vector<std::pair<piece_index_t, int>> const& pieces) const;
|
||||
std::vector<int> 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<download_priority_t> const& files) const;
|
||||
std::vector<download_priority_t> file_priorities() const;
|
||||
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
TORRENT_DEPRECATED
|
||||
void prioritize_files(std::vector<int> const& files) const;
|
||||
std::vector<int> file_priorities() const;
|
||||
#endif
|
||||
|
||||
// ``force_reannounce()`` will force this torrent to do another tracker
|
||||
// request, to receive new peers. The ``seconds`` argument specifies how
|
||||
|
|
|
@ -135,6 +135,10 @@ namespace libtorrent { namespace aux {
|
|||
|
||||
namespace std {
|
||||
|
||||
template<typename UnderlyingType, typename Tag>
|
||||
struct is_integral<libtorrent::aux::strong_typedef<UnderlyingType, Tag>>
|
||||
: std::is_integral<UnderlyingType> {};
|
||||
|
||||
template<typename UnderlyingType, typename Tag>
|
||||
class numeric_limits<libtorrent::aux::strong_typedef<UnderlyingType, Tag>> : public std::numeric_limits<UnderlyingType>
|
||||
{
|
||||
|
|
|
@ -274,7 +274,7 @@ namespace {
|
|||
counters cnt;
|
||||
disk_io_thread disk_thread(ios, cnt);
|
||||
|
||||
aux::vector<std::uint8_t, file_index_t> priorities;
|
||||
aux::vector<download_priority_t, file_index_t> priorities;
|
||||
sha1_hash info_hash;
|
||||
storage_params params{
|
||||
t.files(),
|
||||
|
|
|
@ -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<std::uint8_t, file_index_t> prios
|
||||
, aux::vector<download_priority_t, file_index_t> prios
|
||||
, std::function<void(storage_error const&)> 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<aux::vector<std::uint8_t, file_index_t>>(j->argument)
|
||||
boost::get<aux::vector<download_priority_t, file_index_t>>(j->argument)
|
||||
, j->error);
|
||||
return status_t::no_error;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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<std::uint16_t>(new_piece_priority);
|
||||
p.piece_priority = static_cast<std::uint8_t>(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<int>& pieces) const
|
||||
void piece_picker::piece_priorities(std::vector<download_priority_t>& 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<std::uint32_t>(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;
|
||||
|
|
|
@ -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<std::size_t>(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<std::uint8_t>(
|
||||
file_priority.list_int_value_at(i
|
||||
, static_cast<std::uint8_t>(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<std::size_t>(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<std::uint8_t>(prio_str[i])
|
||||
, static_cast<std::uint8_t>(dont_download)
|
||||
, static_cast<std::uint8_t>(top_priority)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<std::uint8_t, file_index_t> const& prio
|
||||
aux::vector<download_priority_t, file_index_t> 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<std::uint8_t, file_index_t> const&
|
||||
void set_file_priority(aux::vector<download_priority_t, file_index_t> 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<std::uint8_t, file_index_t> const& /* prio */
|
||||
void set_file_priority(aux::vector<download_priority_t, file_index_t> 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; }
|
||||
|
|
|
@ -462,7 +462,7 @@ namespace libtorrent { namespace aux {
|
|||
bool verify_resume_data(add_torrent_params const& rd
|
||||
, aux::vector<std::string, file_index_t> const& links
|
||||
, file_storage const& fs
|
||||
, aux::vector<std::uint8_t, file_index_t> const& file_priority
|
||||
, aux::vector<download_priority_t, file_index_t> 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;
|
||||
|
|
126
src/torrent.cpp
126
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<read_piece_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<read_piece_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<int, piece_index_t> const& priority)
|
||||
void torrent::remove_time_critical_pieces(aux::vector<download_priority_t, piece_index_t> 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<int>(index), priority);
|
||||
"no metadata yet ]", static_cast<int>(index)
|
||||
, static_cast<std::uint8_t>(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<std::pair<piece_index_t, int>> const& pieces)
|
||||
void torrent::prioritize_piece_list(std::vector<std::pair<piece_index_t
|
||||
, download_priority_t>> 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<int, piece_index_t> const& pieces)
|
||||
void torrent::prioritize_pieces(aux::vector<download_priority_t, piece_index_t> 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<int, piece_index_t>* pieces) const
|
||||
void torrent::piece_priorities(aux::vector<download_priority_t, piece_index_t>* 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<int, file_index_t> const& files)
|
||||
void torrent::prioritize_files(aux::vector<download_priority_t, file_index_t> 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<int>(limit), default_piece_priority);
|
||||
m_file_priority.resize(static_cast<int>(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<int>(index) + 1, default_piece_priority);
|
||||
if (prio == default_priority) return;
|
||||
m_file_priority.resize(static_cast<int>(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<int, file_index_t>* files) const
|
||||
void torrent::file_priorities(aux::vector<download_priority_t, file_index_t>* 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<int, piece_index_t> pieces(aux::numeric_cast<std::size_t>(m_torrent_file->num_pieces()), 0);
|
||||
aux::vector<download_priority_t, piece_index_t> pieces(aux::numeric_cast<std::size_t>(
|
||||
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<std::size_t>(m_torrent_file->num_pieces()));
|
||||
|
||||
for (piece_index_t i(0); i < fs.end_piece(); ++i)
|
||||
ret.piece_priorities.push_back(static_cast<std::uint8_t>(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<std::uint32_t>(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();
|
||||
|
|
|
@ -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<int>(0, &torrent::piece_priority, index);
|
||||
return sync_call_ret<download_priority_t>(dont_download, &torrent::piece_priority, index);
|
||||
}
|
||||
|
||||
void torrent_handle::prioritize_pieces(std::vector<int> const& pieces) const
|
||||
void torrent_handle::prioritize_pieces(std::vector<download_priority_t> const& pieces) const
|
||||
{
|
||||
async_call(&torrent::prioritize_pieces, static_cast<aux::vector<int, piece_index_t> const&>(pieces));
|
||||
async_call(&torrent::prioritize_pieces
|
||||
, static_cast<aux::vector<download_priority_t, piece_index_t> const&>(pieces));
|
||||
}
|
||||
|
||||
void torrent_handle::prioritize_pieces(std::vector<std::pair<piece_index_t, int>> const& pieces) const
|
||||
void torrent_handle::prioritize_pieces(std::vector<std::pair<piece_index_t
|
||||
, download_priority_t>> const& pieces) const
|
||||
{
|
||||
async_call(&torrent::prioritize_piece_list, pieces);
|
||||
}
|
||||
|
||||
std::vector<int> torrent_handle::piece_priorities() const
|
||||
std::vector<download_priority_t> torrent_handle::piece_priorities() const
|
||||
{
|
||||
aux::vector<int, piece_index_t> ret;
|
||||
aux::vector<download_priority_t, piece_index_t> 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<int> const& pieces) const
|
||||
{
|
||||
aux::vector<download_priority_t, piece_index_t> p;
|
||||
p.reserve(pieces.size());
|
||||
for (auto const prio : pieces) {
|
||||
p.push_back(download_priority_t(static_cast<std::uint8_t>(prio)));
|
||||
}
|
||||
async_call(&torrent::prioritize_pieces, p);
|
||||
}
|
||||
|
||||
void torrent_handle::prioritize_pieces(std::vector<std::pair<piece_index_t, int>> const& pieces) const
|
||||
{
|
||||
std::vector<std::pair<piece_index_t, download_priority_t>> 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<int>(0, &torrent::file_priority, index);
|
||||
return sync_call_ret<download_priority_t>(dont_download, &torrent::file_priority, index);
|
||||
}
|
||||
|
||||
void torrent_handle::prioritize_files(std::vector<int> const& files) const
|
||||
void torrent_handle::prioritize_files(std::vector<download_priority_t> const& files) const
|
||||
{
|
||||
async_call(&torrent::prioritize_files
|
||||
, static_cast<aux::vector<int, file_index_t> const&>(files));
|
||||
, static_cast<aux::vector<download_priority_t, file_index_t> const&>(files));
|
||||
}
|
||||
|
||||
std::vector<int> torrent_handle::file_priorities() const
|
||||
std::vector<download_priority_t> torrent_handle::file_priorities() const
|
||||
{
|
||||
aux::vector<int, file_index_t> ret;
|
||||
aux::vector<download_priority_t, file_index_t> 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<int> const& files) const
|
||||
{
|
||||
aux::vector<download_priority_t, file_index_t> file_prio;
|
||||
file_prio.reserve(files.size());
|
||||
for (auto const p : files) {
|
||||
file_prio.push_back(download_priority_t(static_cast<std::uint8_t>(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 {}
|
||||
|
|
|
@ -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<std::uint8_t>(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<char>(p));
|
||||
prio.push_back(static_cast<char>(static_cast<std::uint8_t>(p)));
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -169,7 +169,7 @@ void generate_files(lt::torrent_info const& ti, std::string const& path
|
|||
{
|
||||
file_pool fp;
|
||||
|
||||
aux::vector<std::uint8_t, file_index_t> priorities;
|
||||
aux::vector<download_priority_t, file_index_t> priorities;
|
||||
sha1_hash info_hash;
|
||||
storage_params params{
|
||||
ti.files(),
|
||||
|
|
|
@ -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<std::uint8_t, file_index_t> const& prio
|
||||
void set_file_priority(aux::vector<download_priority_t, file_index_t> 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; }
|
||||
|
|
|
@ -46,6 +46,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <iostream>
|
||||
|
||||
#include "test.hpp"
|
||||
#include "test_utils.hpp"
|
||||
|
||||
using namespace lt;
|
||||
using namespace std::placeholders;
|
||||
|
@ -179,8 +180,8 @@ std::shared_ptr<piece_picker> setup_picker(
|
|||
{
|
||||
int const idx = static_cast<int>(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<int> prios;
|
||||
std::vector<download_priority_t> 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
|
||||
|
|
|
@ -43,6 +43,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <functional>
|
||||
|
||||
#include "test.hpp"
|
||||
#include "test_utils.hpp"
|
||||
#include "setup_transfer.hpp"
|
||||
#include "settings.hpp"
|
||||
#include <fstream>
|
||||
|
@ -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<int, piece_index_t> priorities(num_pieces, 1);
|
||||
aux::vector<download_priority_t, piece_index_t> 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<int>(std::cout, ", "));
|
||||
std::copy(priorities.begin(), priorities.end(), std::ostream_iterator<download_priority_t>(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<int> priorities2 = tor2.piece_priorities();
|
||||
std::copy(priorities2.begin(), priorities2.end(), std::ostream_iterator<int>(std::cout, ", "));
|
||||
std::vector<download_priority_t> priorities2 = tor2.piece_priorities();
|
||||
std::copy(priorities2.begin(), priorities2.end()
|
||||
, std::ostream_iterator<download_priority_t>(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<int>(std::cout, ", "));
|
||||
std::copy(priorities2.begin(), priorities2.end()
|
||||
, std::ostream_iterator<download_priority_t>(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<int>(std::cout, ", "));
|
||||
std::copy(priorities2.begin(), priorities2.end(), std::ostream_iterator<download_priority_t>(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<int>(std::cout, ", "));
|
||||
std::copy(priorities.begin(), priorities.end()
|
||||
, std::ostream_iterator<download_priority_t>(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);
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
*/
|
||||
|
||||
#include "test.hpp"
|
||||
#include "test_utils.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
@ -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)
|
||||
|
|
|
@ -94,9 +94,9 @@ void test_remove_torrent(remove_flags_t const remove_options
|
|||
|
||||
if (test == partial_download)
|
||||
{
|
||||
std::vector<int> priorities(num_pieces, 1);
|
||||
std::vector<download_priority_t> 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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<std::uint8_t, file_index_t> priorities_vector;
|
||||
aux::vector<download_priority_t, file_index_t> 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<char> 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<int> file_priorities = test_resume_flags(ses
|
||||
std::vector<download_priority_t> 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<int> file_priorities = test_resume_flags(ses, {}, "", "123").file_priorities();
|
||||
std::vector<download_priority_t> 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<int> file_priorities = test_resume_flags(ses, {}, "456", "123").file_priorities();
|
||||
std::vector<download_priority_t> 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<int> file_priorities = test_resume_flags(ses
|
||||
std::vector<download_priority_t> 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<int> file_priorities = test_resume_flags(ses,
|
||||
std::vector<download_priority_t> 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<int> file_priorities = test_resume_flags(ses,
|
||||
std::vector<download_priority_t> 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<int> file_priorities = test_resume_flags(ses,
|
||||
std::vector<download_priority_t> 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<int> file_priorities = test_resume_flags(ses, {}, "", "123", true).file_priorities();
|
||||
std::vector<download_priority_t> 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<int> file_priorities = test_resume_flags(ses, {}, "010", "", true).file_priorities();
|
||||
std::vector<download_priority_t> 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<int> file_priorities = test_resume_flags(ses, {}, "123", "", true).file_priorities();
|
||||
std::vector<download_priority_t> 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<int> file_priorities = test_resume_flags(ses, {}, "4321", "", true).file_priorities();
|
||||
std::vector<download_priority_t> 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<int> file_priorities = test_resume_flags(ses, {}, "", "").file_priorities();
|
||||
std::vector<download_priority_t> 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<int> file_priorities = test_resume_flags(ses
|
||||
std::vector<download_priority_t> 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<int> file_priorities = test_resume_flags(ses
|
||||
std::vector<download_priority_t> 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<int> file_priorities = test_resume_flags(ses, {}, "", "123").file_priorities();
|
||||
std::vector<download_priority_t> 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<int> file_priorities = test_resume_flags(ses, {}, "010").file_priorities();
|
||||
std::vector<download_priority_t> 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<int> file_priorities = test_resume_flags(ses, {}, "123").file_priorities();
|
||||
std::vector<download_priority_t> 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<int> file_priorities = test_resume_flags(ses, {}, "4321").file_priorities();
|
||||
std::vector<download_priority_t> 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)
|
||||
|
|
|
@ -160,7 +160,7 @@ std::shared_ptr<default_storage> setup_torrent(file_storage& fs
|
|||
{
|
||||
std::shared_ptr<torrent_info> info = setup_torrent_info(fs, buf);
|
||||
|
||||
aux::vector<std::uint8_t, file_index_t> priorities;
|
||||
aux::vector<download_priority_t, file_index_t> priorities;
|
||||
sha1_hash info_hash;
|
||||
storage_params p{
|
||||
fs,
|
||||
|
@ -235,7 +235,7 @@ void run_storage_tests(std::shared_ptr<torrent_info> info
|
|||
boost::asio::io_service ios;
|
||||
disk_buffer_pool dp(16 * 1024, ios, std::bind(&nop));
|
||||
|
||||
aux::vector<std::uint8_t, file_index_t> priorities;
|
||||
aux::vector<download_priority_t, file_index_t> 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<std::uint8_t, file_index_t> priorities;
|
||||
aux::vector<download_priority_t, file_index_t> priorities;
|
||||
sha1_hash info_hash;
|
||||
storage_params p{
|
||||
fs,
|
||||
|
|
|
@ -46,6 +46,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <iostream>
|
||||
|
||||
#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<torrent_info> info, std::int64_t file_
|
|||
pack.set_int(settings_pack::max_retry_port_bind, 10);
|
||||
lt::session ses(pack);
|
||||
|
||||
aux::vector<std::uint8_t, file_index_t> zeroes;
|
||||
zeroes.resize(1000, 0);
|
||||
aux::vector<download_priority_t, file_index_t> 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<torrent_info> info, std::int64_t file_
|
|||
return;
|
||||
}
|
||||
|
||||
aux::vector<int, file_index_t> ones(info->num_files(), 1);
|
||||
aux::vector<download_priority_t, file_index_t> 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<torrent_info> 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<int, file_index_t> prio(info->num_files(), 1);
|
||||
prio[file_index_t(0)] = 0;
|
||||
aux::vector<download_priority_t, file_index_t> 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<torrent_info> 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<torrent_info> 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<char> 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<int> pieces(torrents[5].torrent_file()->num_pieces(), 0);
|
||||
std::vector<download_priority_t> pieces(torrents[5].torrent_file()->num_pieces(), 0_pri);
|
||||
torrents[5].prioritize_pieces(pieces);
|
||||
torrent_handle finished = torrents[5];
|
||||
|
||||
|
|
|
@ -77,7 +77,7 @@ struct test_storage : default_storage
|
|||
, m_limit(16 * 1024 * 2)
|
||||
{}
|
||||
|
||||
void set_file_priority(aux::vector<std::uint8_t, file_index_t> const& p
|
||||
void set_file_priority(aux::vector<download_priority_t, file_index_t> const& p
|
||||
, storage_error& ec) override {}
|
||||
|
||||
void set_limit(int lim)
|
||||
|
|
|
@ -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<std::uint8_t>(p));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue