make add_torrent_params::flags_t an enum class and move it out into its own header

This commit is contained in:
arvidn 2017-07-09 07:32:01 -07:00 committed by Arvid Norberg
parent 00655d562b
commit 4947602a2f
42 changed files with 903 additions and 886 deletions

View File

@ -237,8 +237,8 @@ def main():
atp = {}
atp["save_path"] = options.save_path
atp["storage_mode"] = lt.storage_mode_t.storage_mode_sparse
atp["flags"] = lt.add_torrent_params_flags_t.flag_duplicate_is_error \
| lt.add_torrent_params_flags_t.flag_auto_managed
atp["flags"] = lt.torrent_flags.duplicate_is_error \
| lt.torrent_flags.auto_managed
if f.startswith('magnet:') or f.startswith(
'http://') or f.startswith('https://'):
atp["url"] = f

View File

@ -8,6 +8,7 @@
#include "libtorrent/error_code.hpp"
#include "libtorrent/session_stats.hpp" // for stats_metric
#include "libtorrent/time.hpp"
#include "libtorrent/torrent_flags.hpp"
#include "libtorrent/units.hpp"
#include "libtorrent/sha1_hash.hpp"
#include "libtorrent/disk_interface.hpp" // for open_file_state
@ -229,6 +230,43 @@ struct to_strong_typedef
}
};
template<class T>
struct from_bitfield_flag
{
using underlying_type = typename T::underlying_type;
static PyObject* convert(T const v)
{
object o(static_cast<underlying_type>(v));
return incref(o.ptr());
}
};
template<typename T>
struct to_bitfield_flag
{
using underlying_type = typename T::underlying_type;
to_bitfield_flag()
{
converter::registry::push_back(
&convertible, &construct, type_id<T>()
);
}
static void* convertible(PyObject* x)
{
return PyNumber_Check(x) ? x : nullptr;
}
static void construct(PyObject* x, converter::rvalue_from_python_stage1_data* data)
{
void* storage = ((converter::rvalue_from_python_storage<T>*)data)->storage.bytes;
new (storage) T(extract<underlying_type>(object(borrowed(x))));
data->convertible = storage;
}
};
void bind_converters()
{
// C++ -> python conversions
@ -251,6 +289,7 @@ void bind_converters()
to_python_converter<lt::piece_index_t, from_strong_typedef<lt::piece_index_t>>();
to_python_converter<lt::file_index_t, from_strong_typedef<lt::file_index_t>>();
to_python_converter<lt::torrent_flags_t, from_bitfield_flag<lt::torrent_flags_t>>();
// work-around types
to_python_converter<lt::aux::noexcept_movable<lt::address>, address_to_tuple<
@ -293,4 +332,5 @@ void bind_converters()
to_strong_typedef<lt::piece_index_t>();
to_strong_typedef<lt::file_index_t>();
to_bitfield_flag<lt::torrent_flags_t>();
}

View File

@ -34,6 +34,7 @@ BOOST_PYTHON_MODULE(libtorrent)
Py_Initialize();
PyEval_InitThreads();
bind_converters();
bind_error_code();
bind_utility();
bind_fingerprint();
@ -51,6 +52,5 @@ BOOST_PYTHON_MODULE(libtorrent)
bind_peer_info();
bind_ip_filter();
bind_magnet_uri();
bind_converters();
bind_create_torrent();
}

View File

@ -229,7 +229,7 @@ namespace
object const value = item[1];
// torrent_info objects are always held by a shared_ptr in the
// python binding, skip it if it is a object
if(key == "ti" && value != boost::python::object())
if (key == "ti" && value != boost::python::object())
{
// make a copy here. We don't want to end up holding a python-owned
// object inside libtorrent. If the last reference goes out of scope
@ -308,7 +308,7 @@ namespace
}
else if(key == "flags")
{
p.flags = extract<std::uint64_t>(value);
p.flags = extract<lt::torrent_flags_t>(value);
continue;
}
else if(key == "trackerid")
@ -560,6 +560,10 @@ namespace
} // namespace unnamed
struct dummy1 {};
#ifndef TORRENT_NO_DEPRECATE
struct dummy2 {};
#endif
void bind_session()
{
@ -706,28 +710,48 @@ void bind_session()
.value("start_default_features", lt::session::start_default_features)
;
enum_<add_torrent_params::flags_t>("add_torrent_params_flags_t")
.value("flag_seed_mode", add_torrent_params::flag_seed_mode)
.value("flag_upload_mode", add_torrent_params::flag_upload_mode)
.value("flag_share_mode", add_torrent_params::flag_share_mode)
.value("flag_apply_ip_filter", add_torrent_params::flag_apply_ip_filter)
.value("flag_paused", add_torrent_params::flag_paused)
.value("flag_auto_managed", add_torrent_params::flag_auto_managed)
.value("flag_duplicate_is_error", add_torrent_params::flag_duplicate_is_error)
.value("flag_update_subscribe", add_torrent_params::flag_update_subscribe)
.value("flag_super_seeding", add_torrent_params::flag_super_seeding)
.value("flag_sequential_download", add_torrent_params::flag_sequential_download)
.value("flag_stop_when_ready", add_torrent_params::flag_stop_when_ready)
.value("flag_override_trackers", add_torrent_params::flag_override_trackers)
.value("flag_override_web_seeds", add_torrent_params::flag_override_web_seeds)
{
scope s = class_<dummy1>("torrent_flags");
s.attr("seed_mode") = torrent_flags::seed_mode;
s.attr("upload_mode") = torrent_flags::upload_mode;
s.attr("share_mode") = torrent_flags::share_mode;
s.attr("apply_ip_filter") = torrent_flags::apply_ip_filter;
s.attr("paused") = torrent_flags::paused;
s.attr("auto_managed") = torrent_flags::auto_managed;
s.attr("duplicate_is_error") = torrent_flags::duplicate_is_error;
s.attr("update_subscribe") = torrent_flags::update_subscribe;
s.attr("super_seeding") = torrent_flags::super_seeding;
s.attr("sequential_download") = torrent_flags::sequential_download;
s.attr("stop_when_ready") = torrent_flags::stop_when_ready;
s.attr("override_trackers") = torrent_flags::override_trackers;
s.attr("override_web_seeds") = torrent_flags::override_web_seeds;
}
#ifndef TORRENT_NO_DEPRECATE
.value("flag_pinned", add_torrent_params::flag_pinned)
.value("flag_override_resume_data", add_torrent_params::flag_override_resume_data)
.value("flag_merge_resume_trackers", add_torrent_params::flag_merge_resume_trackers)
.value("flag_use_resume_save_path", add_torrent_params::flag_use_resume_save_path)
.value("flag_merge_resume_http_seeds", add_torrent_params::flag_merge_resume_http_seeds)
{
scope s = class_<dummy2>("add_torrent_params_flags_t");
s.attr("flag_seed_mode") = add_torrent_params::flag_seed_mode;
s.attr("flag_upload_mode") = add_torrent_params::flag_upload_mode;
s.attr("flag_share_mode") = add_torrent_params::flag_share_mode;
s.attr("flag_apply_ip_filter") = add_torrent_params::flag_apply_ip_filter;
s.attr("flag_paused") = add_torrent_params::flag_paused;
s.attr("flag_auto_managed") = add_torrent_params::flag_auto_managed;
s.attr("flag_duplicate_is_error") = add_torrent_params::flag_duplicate_is_error;
s.attr("flag_update_subscribe") = add_torrent_params::flag_update_subscribe;
s.attr("flag_super_seeding") = add_torrent_params::flag_super_seeding;
s.attr("flag_sequential_download") = add_torrent_params::flag_sequential_download;
s.attr("flag_stop_when_ready") = add_torrent_params::flag_stop_when_ready;
s.attr("flag_override_trackers") = add_torrent_params::flag_override_trackers;
s.attr("flag_override_web_seeds") = add_torrent_params::flag_override_web_seeds;
s.attr("flag_pinned") = add_torrent_params::flag_pinned;
s.attr("flag_override_resume_data") = add_torrent_params::flag_override_resume_data;
s.attr("flag_merge_resume_trackers") = add_torrent_params::flag_merge_resume_trackers;
s.attr("flag_use_resume_save_path") = add_torrent_params::flag_use_resume_save_path;
s.attr("flag_merge_resume_http_seeds") = add_torrent_params::flag_merge_resume_http_seeds;
}
#endif
;
class_<cache_status>("cache_status")
.add_property("pieces", cache_status_pieces)
#ifndef TORRENT_NO_DEPRECATE

View File

@ -437,8 +437,8 @@ void bind_torrent_handle()
bool (torrent_handle::*super_seeding0)() const = &torrent_handle::super_seeding;
void (torrent_handle::*super_seeding1)(bool) const = &torrent_handle::super_seeding;
#endif
void (torrent_handle::*set_flags0)(boost::uint64_t) const = &torrent_handle::set_flags;
void (torrent_handle::*set_flags1)(boost::uint64_t, boost::uint64_t) const = &torrent_handle::set_flags;
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;
@ -491,39 +491,13 @@ void bind_torrent_handle()
.def("is_valid", _(&torrent_handle::is_valid))
.def("pause", _(&torrent_handle::pause), arg("flags") = 0)
.def("resume", _(&torrent_handle::resume))
#ifndef TORRENT_NO_DEPRECATE
.def("stop_when_ready", _(&torrent_handle::stop_when_ready))
#endif
.def("clear_error", _(&torrent_handle::clear_error))
#ifndef TORRENT_NO_DEPRECATE
.def("super_seeding", super_seeding1)
.def("auto_managed", _(&torrent_handle::auto_managed))
#endif
.def("queue_position", _(&torrent_handle::queue_position))
.def("queue_position_up", _(&torrent_handle::queue_position_up))
.def("queue_position_down", _(&torrent_handle::queue_position_down))
.def("queue_position_top", _(&torrent_handle::queue_position_top))
.def("queue_position_bottom", _(&torrent_handle::queue_position_bottom))
// deprecated
#ifndef TORRENT_NO_DEPRECATE
.def("set_priority", _(&torrent_handle::set_priority))
.def("get_torrent_info", &get_torrent_info)
#ifndef TORRENT_NO_DEPRECATE
.def("super_seeding", super_seeding0)
#endif
.def("write_resume_data", _(&torrent_handle::write_resume_data))
.def("is_seed", _(&torrent_handle::is_seed))
.def("is_finished", _(&torrent_handle::is_finished))
#ifndef TORRENT_NO_DEPRECATE
.def("is_paused", _(&torrent_handle::is_paused))
.def("is_auto_managed", _(&torrent_handle::is_auto_managed))
#endif
.def("has_metadata", _(&torrent_handle::has_metadata))
.def("use_interface", &torrent_handle::use_interface)
.def("name", _(&torrent_handle::name))
#endif
.def("add_piece", add_piece)
.def("read_piece", _(&torrent_handle::read_piece))
.def("have_piece", _(&torrent_handle::have_piece))
@ -549,46 +523,53 @@ void bind_torrent_handle()
.def("force_dht_announce", _(&torrent_handle::force_dht_announce))
#endif
.def("scrape_tracker", _(&torrent_handle::scrape_tracker), arg("index") = -1)
#ifndef TORRENT_NO_DEPRECATE
.def("set_upload_mode", _(&torrent_handle::set_upload_mode))
.def("set_share_mode", _(&torrent_handle::set_share_mode))
#endif
.def("flush_cache", &torrent_handle::flush_cache)
#ifndef TORRENT_NO_DEPRECATE
.def("apply_ip_filter", &torrent_handle::apply_ip_filter)
#endif
.def("set_upload_limit", _(&torrent_handle::set_upload_limit))
.def("upload_limit", _(&torrent_handle::upload_limit))
.def("set_download_limit", _(&torrent_handle::set_download_limit))
.def("download_limit", _(&torrent_handle::download_limit))
#ifndef TORRENT_NO_DEPRECATE
.def("set_sequential_download", _(&torrent_handle::set_sequential_download))
.def("set_peer_upload_limit", &torrent_handle::set_peer_upload_limit)
.def("set_peer_download_limit", &torrent_handle::set_peer_download_limit)
.def("set_ratio", _(&torrent_handle::set_ratio))
.def("save_path", _(&torrent_handle::save_path))
#endif
.def("connect_peer", &torrent_handle::connect_peer, (arg("endpoint"), arg("source")=0, arg("flags")=0xd))
.def("set_max_uploads", &torrent_handle::set_max_uploads)
.def("max_uploads", _(&torrent_handle::max_uploads))
.def("set_max_connections", &torrent_handle::set_max_connections)
.def("max_connections", _(&torrent_handle::max_connections))
#ifndef TORRENT_NO_DEPRECATE
.def("set_tracker_login", &torrent_handle::set_tracker_login)
#endif
.def("move_storage", _(move_storage0), (arg("path"), arg("flags") = move_flags_t::always_replace_files))
.def("info_hash", _(&torrent_handle::info_hash))
.def("force_recheck", _(&torrent_handle::force_recheck))
.def("rename_file", _(rename_file0))
.def("set_ssl_certificate", &torrent_handle::set_ssl_certificate, (arg("cert"), arg("private_key"), arg("dh_params"), arg("passphrase")=""))
#if !defined TORRENT_NO_DEPRECATE
.def("move_storage", _(move_storage1), (arg("path"), arg("flags") = always_replace_files))
.def("rename_file", _(rename_file1))
#endif
.def("flags", _(&torrent_handle::flags))
.def("set_flags", _(set_flags0))
.def("set_flags", _(set_flags1))
.def("unset_flags", _(&torrent_handle::unset_flags))
// deprecated
#ifndef TORRENT_NO_DEPRECATE
.def("stop_when_ready", _(&torrent_handle::stop_when_ready))
.def("super_seeding", super_seeding1)
.def("auto_managed", _(&torrent_handle::auto_managed))
.def("set_priority", _(&torrent_handle::set_priority))
.def("get_torrent_info", &get_torrent_info)
.def("super_seeding", super_seeding0)
.def("write_resume_data", _(&torrent_handle::write_resume_data))
.def("is_seed", _(&torrent_handle::is_seed))
.def("is_finished", _(&torrent_handle::is_finished))
.def("has_metadata", _(&torrent_handle::has_metadata))
.def("use_interface", &torrent_handle::use_interface)
.def("name", _(&torrent_handle::name))
.def("is_paused", _(&torrent_handle::is_paused))
.def("is_auto_managed", _(&torrent_handle::is_auto_managed))
.def("set_upload_mode", _(&torrent_handle::set_upload_mode))
.def("set_share_mode", _(&torrent_handle::set_share_mode))
.def("apply_ip_filter", &torrent_handle::apply_ip_filter)
.def("set_sequential_download", _(&torrent_handle::set_sequential_download))
.def("set_peer_upload_limit", &torrent_handle::set_peer_upload_limit)
.def("set_peer_download_limit", &torrent_handle::set_peer_download_limit)
.def("set_ratio", _(&torrent_handle::set_ratio))
.def("save_path", _(&torrent_handle::save_path))
.def("set_tracker_login", &torrent_handle::set_tracker_login)
.def("move_storage", _(move_storage1), (arg("path"), arg("flags") = always_replace_files))
.def("rename_file", _(rename_file1))
#endif
;
class_<open_file_state>("open_file_state")

View File

@ -201,4 +201,3 @@ crypto
uri
infohashes
rw
0xffffffffffffffff

View File

@ -67,6 +67,21 @@ POSSIBILITY OF SUCH DAMAGE.
#include "print.hpp"
using lt::total_milliseconds;
using lt::alert;
using lt::piece_index_t;
using lt::file_index_t;
using lt::file_open_mode;
using lt::torrent_handle;
using lt::add_torrent_params;
using lt::cache_status;
using lt::total_seconds;
using lt::torrent_flags_t;
using lt::seconds;
using lt::operator""_sv;
using lt::address_v4;
#if TORRENT_USE_IPV6
using lt::address_v6;
#endif
#ifdef _WIN32
@ -308,7 +323,7 @@ std::string make_absolute_path(std::string const& p)
std::string print_endpoint(lt::tcp::endpoint const& ep)
{
using namespace lt;
error_code ec;
lt::error_code ec;
char buf[200];
address const& addr = ep.address();
#if TORRENT_USE_IPV6
@ -472,7 +487,7 @@ int print_peer_info(std::string& out
if (print_peer_rate)
{
bool unchoked = (i->flags & peer_info::choked) == 0;
bool const unchoked = (i->flags & lt::peer_info::choked) == 0;
std::snprintf(str, sizeof(str), " %s"
, unchoked ? add_suffix(i->estimated_reciprocation_rate, "/s").c_str() : " ");
@ -480,13 +495,13 @@ int print_peer_info(std::string& out
}
out += " ";
if (i->flags & peer_info::handshake)
if (i->flags & lt::peer_info::handshake)
{
out += esc("31");
out += " waiting for handshake";
out += esc("0");
}
else if (i->flags & peer_info::connecting)
else if (i->flags & lt::peer_info::connecting)
{
out += esc("31");
out += " connecting to peer";
@ -573,9 +588,9 @@ void add_magnet(lt::session& ses, lt::string_view uri)
p.upload_limit = torrent_upload_limit;
p.download_limit = torrent_download_limit;
if (seed_mode) p.flags |= lt::add_torrent_params::flag_seed_mode;
if (seed_mode) p.flags |= lt::torrent_flags::seed_mode;
if (disable_storage) p.storage = lt::disabled_storage_constructor;
if (share_mode) p.flags |= lt::add_torrent_params::flag_share_mode;
if (share_mode) p.flags |= lt::torrent_flags::share_mode;
p.save_path = save_path;
p.storage_mode = static_cast<lt::storage_mode_t>(allocation_mode);
@ -586,13 +601,15 @@ void add_magnet(lt::session& ses, lt::string_view uri)
// return false on failure
bool add_torrent(lt::session& ses, std::string torrent)
{
using namespace lt;
using lt::add_torrent_params;
using lt::storage_mode_t;
static int counter = 0;
std::printf("[%d] %s\n", counter++, torrent.c_str());
error_code ec;
auto ti = std::make_shared<torrent_info>(torrent, ec);
lt::error_code ec;
auto ti = std::make_shared<lt::torrent_info>(torrent, ec);
if (ec)
{
std::printf("failed to load torrent \"%s\": %s\n"
@ -611,9 +628,9 @@ bool add_torrent(lt::session& ses, std::string torrent)
}
ec.clear();
if (seed_mode) p.flags |= add_torrent_params::flag_seed_mode;
if (disable_storage) p.storage = disabled_storage_constructor;
if (share_mode) p.flags |= add_torrent_params::flag_share_mode;
if (seed_mode) p.flags |= lt::torrent_flags::seed_mode;
if (disable_storage) p.storage = lt::disabled_storage_constructor;
if (share_mode) p.flags |= lt::torrent_flags::share_mode;
p.max_connections = max_connections_per_torrent;
p.max_uploads = -1;
@ -622,7 +639,7 @@ bool add_torrent(lt::session& ses, std::string torrent)
p.ti = ti;
p.save_path = save_path;
p.storage_mode = (storage_mode_t)allocation_mode;
p.flags &= ~add_torrent_params::flag_duplicate_is_error;
p.flags &= ~lt::torrent_flags::duplicate_is_error;
p.userdata = static_cast<void*>(new std::string(torrent));
ses.async_add_torrent(std::move(p));
return true;
@ -967,7 +984,7 @@ void print_piece(lt::partial_piece_info const* pp
{
int const index = pp ? peer_index(pp->blocks[j].peer(), peers) % 36 : -1;
char const* chr = " ";
bool const snubbed = index >= 0 ? ((peers[index].flags & peer_info::snubbed) != 0) : false;
bool const snubbed = index >= 0 ? ((peers[index].flags & lt::peer_info::snubbed) != 0) : false;
char const* color = "";
@ -1078,14 +1095,15 @@ MAGNETURL is a magnet link
return 0;
}
using namespace lt;
using lt::settings_pack;
using lt::session_handle;
torrent_view view;
session_view ses_view;
session_params params;
lt::session_params params;
error_code ec;
lt::error_code ec;
#ifndef TORRENT_DISABLE_DHT
params.dht_settings.privacy_lookups = true;
@ -1094,7 +1112,7 @@ MAGNETURL is a magnet link
load_file(".ses_state", in, ec);
if (!ec)
{
bdecode_node e;
lt::bdecode_node e;
if (bdecode(&in[0], &in[0] + in.size(), e, ec) == 0)
params = read_session_params(e, session_handle::save_dht_state);
}
@ -1109,11 +1127,11 @@ MAGNETURL is a magnet link
std::deque<std::string> events;
time_point next_dir_scan = clock_type::now();
lt::time_point next_dir_scan = lt::clock_type::now();
// load the torrents given on the commandline
std::vector<lt::string_view> torrents;
ip_filter loaded_ip_filter;
lt::ip_filter loaded_ip_filter;
for (int i = 1; i < argc; ++i)
{
@ -1147,7 +1165,7 @@ MAGNETURL is a magnet link
std::string const key(start, equal - start);
char const* value = equal + 1;
int const sett_name = setting_by_name(key);
int const sett_name = lt::setting_by_name(key);
if (sett_name < 0)
{
std::fprintf(stderr, "unknown setting: \"%s\"\n", key.c_str());
@ -1186,7 +1204,7 @@ MAGNETURL is a magnet link
switch (argv[i][1])
{
case 'f': g_log_file = std::fopen(arg, "w+"); break;
case 'k': settings = high_performance_seed(); --i; break;
case 'k': settings = lt::high_performance_seed(); --i; break;
case 'G': seed_mode = true; --i; break;
case 's': save_path = make_absolute_path(arg); break;
case 'U': torrent_upload_limit = atoi(arg) * 1000; break;
@ -1210,7 +1228,7 @@ MAGNETURL is a magnet link
{
address_v4 start((a << 24) + (b << 16) + (c << 8) + d);
address_v4 last((e << 24) + (f << 16) + (g << 8) + h);
if (flags <= 127) flags = ip_filter::blocked;
if (flags <= 127) flags = lt::ip_filter::blocked;
else flags = 0;
loaded_ip_filter.add_rule(start, last, flags);
}
@ -1259,7 +1277,7 @@ MAGNETURL is a magnet link
if (rate_limit_locals)
{
ip_filter pcf;
lt::ip_filter pcf;
pcf.add_rule(address_v4::from_string("0.0.0.0")
, address_v4::from_string("255.255.255.255")
, 1 << static_cast<std::uint32_t>(lt::session::global_peer_class_id));
@ -1281,7 +1299,7 @@ MAGNETURL is a magnet link
std::thread resume_data_loader([&ses]
{
// load resume files
error_code ec;
lt::error_code ec;
std::string const resume_dir = path_append(save_path, ".resume");
std::vector<std::string> ents = list_dir(resume_dir
, [](lt::string_view p) { return p.size() > 7 && p.substr(p.size() - 7) == ".resume"; }, ec);
@ -1314,7 +1332,7 @@ MAGNETURL is a magnet link
// we're loading this torrent from resume data. There's no need to
// re-save the resume data immediately.
p.flags &= ~add_torrent_params::flag_need_save_resume;
p.flags &= ~lt::torrent_flags::need_save_resume;
ses.async_add_torrent(std::move(p));
}
@ -1322,8 +1340,8 @@ MAGNETURL is a magnet link
});
// main loop
std::vector<peer_info> peers;
std::vector<partial_piece_info> queue;
std::vector<lt::peer_info> peers;
std::vector<lt::partial_piece_info> queue;
#ifndef _WIN32
signal(SIGTERM, signal_handler);
@ -1495,14 +1513,7 @@ MAGNETURL is a magnet link
if (c == 's' && h.is_valid())
{
torrent_status const& ts = view.get_active_torrent();
if (ts.flags & add_torrent_params::flag_sequential_download)
{
h.set_flags(add_torrent_params::flag_sequential_download);
}
else
{
h.unset_flags(add_torrent_params::flag_sequential_download);
}
h.set_flags(~ts.flags, lt::torrent_flags::sequential_download);
}
if (c == 'R')
@ -1538,14 +1549,14 @@ MAGNETURL is a magnet link
if (c == 'p' && h.is_valid())
{
torrent_status const& ts = view.get_active_torrent();
if ((ts.flags & (add_torrent_params::flag_auto_managed |
add_torrent_params::flag_paused)) == add_torrent_params::flag_paused)
if ((ts.flags & (lt::torrent_flags::auto_managed
| lt::torrent_flags::paused)) == lt::torrent_flags::paused)
{
h.set_flags(add_torrent_params::flag_auto_managed);
h.set_flags(lt::torrent_flags::auto_managed);
}
else
{
h.unset_flags(add_torrent_params::flag_auto_managed);
h.unset_flags(lt::torrent_flags::auto_managed);
h.pause(torrent_handle::graceful_pause);
}
}
@ -1555,10 +1566,10 @@ MAGNETURL is a magnet link
{
torrent_status const& ts = view.get_active_torrent();
h.set_flags(
~(ts.flags & add_torrent_params::flag_auto_managed),
add_torrent_params::flag_auto_managed);
if ((ts.flags & add_torrent_params::flag_auto_managed) &&
(ts.flags & add_torrent_params::flag_paused))
~(ts.flags & lt::torrent_flags::auto_managed),
lt::torrent_flags::auto_managed);
if ((ts.flags & lt::torrent_flags::auto_managed)
&& (ts.flags & lt::torrent_flags::paused))
{
h.resume();
}
@ -1665,7 +1676,7 @@ COLUMN OPTIONS
*/
int bucket = 0;
for (dht_routing_bucket const& n : dht_routing_table)
for (lt::dht_routing_bucket const& n : dht_routing_table)
{
char const* progress_bar =
"################################"
@ -1682,7 +1693,7 @@ COLUMN OPTIONS
pos += 1;
}
for (dht_lookup const& l : dht_active_requests)
for (lt::dht_lookup const& l : dht_active_requests)
{
std::snprintf(str, sizeof(str)
, " %10s target: %s "
@ -1708,7 +1719,7 @@ COLUMN OPTIONS
}
}
#endif
time_point const now = clock_type::now();
lt::time_point const now = lt::clock_type::now();
if (h.is_valid())
{
torrent_status const& s = view.get_active_torrent();
@ -1725,10 +1736,10 @@ COLUMN OPTIONS
if (print_trackers)
{
for (announce_entry const& ae : h.trackers())
for (lt::announce_entry const& ae : h.trackers())
{
auto best_ae = std::min_element(ae.endpoints.begin(), ae.endpoints.end()
, [](announce_endpoint const& l, announce_endpoint const& r) { return l.fails < r.fails; } );
, [](lt::announce_endpoint const& l, lt::announce_endpoint const& r) { return l.fails < r.fails; } );
if (pos + 1 >= terminal_height) break;
std::snprintf(str, sizeof(str), "%2d %-55s fails: %-3d (%-3d) %s %s %5d \"%s\" %s\x1b[K\n"
@ -1755,24 +1766,24 @@ COLUMN OPTIONS
h.get_download_queue(queue);
std::sort(queue.begin(), queue.end()
, [] (partial_piece_info const& lhs, partial_piece_info const& rhs)
, [] (lt::partial_piece_info const& lhs, lt::partial_piece_info const& rhs)
{ return lhs.piece_index < rhs.piece_index; });
std::sort(cs.pieces.begin(), cs.pieces.end()
, [](cached_piece_info const& lhs, cached_piece_info const& rhs)
, [](lt::cached_piece_info const& lhs, lt::cached_piece_info const& rhs)
{ return lhs.piece < rhs.piece; });
int p = 0; // this is horizontal position
for (cached_piece_info const& i : cs.pieces)
for (lt::cached_piece_info const& i : cs.pieces)
{
if (pos + 3 >= terminal_height) break;
partial_piece_info* pp = nullptr;
partial_piece_info tmp;
lt::partial_piece_info* pp = nullptr;
lt::partial_piece_info tmp;
tmp.piece_index = i.piece;
std::vector<partial_piece_info>::iterator ppi
std::vector<lt::partial_piece_info>::iterator ppi
= std::lower_bound(queue.begin(), queue.end(), tmp
, [](partial_piece_info const& lhs, partial_piece_info const& rhs)
, [](lt::partial_piece_info const& lhs, lt::partial_piece_info const& rhs)
{ return lhs.piece_index < rhs.piece_index; });
if (ppi != queue.end() && ppi->piece_index == i.piece) pp = &*ppi;
@ -1800,7 +1811,7 @@ COLUMN OPTIONS
if (pp) queue.erase(ppi);
}
for (partial_piece_info const& i : queue)
for (lt::partial_piece_info const& i : queue)
{
if (pos + 3 >= terminal_height) break;
@ -1845,10 +1856,10 @@ COLUMN OPTIONS
{
std::vector<std::int64_t> file_progress;
h.file_progress(file_progress);
std::vector<open_file_state> file_status = h.file_status();
std::vector<lt::open_file_state> file_status = h.file_status();
std::vector<int> file_prio = h.file_priorities();
auto f = file_status.begin();
std::shared_ptr<const torrent_info> ti = h.torrent_file();
std::shared_ptr<const lt::torrent_info> ti = h.torrent_file();
int p = 0; // this is horizontal position
for (file_index_t i(0); i < file_index_t(ti->num_files()); ++i)
@ -1991,8 +2002,8 @@ COLUMN OPTIONS
#ifndef TORRENT_DISABLE_DHT
std::printf("\nsaving session state\n");
{
entry session_state;
ses.save_state(session_state, session::save_dht_state);
lt::entry session_state;
ses.save_state(session_state, lt::session::save_dht_state);
std::vector<char> out;
bencode(std::back_inserter(out), session_state);

View File

@ -46,20 +46,20 @@ std::string torrent_state(lt::torrent_status const& s)
if (s.errc) return s.errc.message();
std::string ret;
if ((s.flags & lt::add_torrent_params::flag_paused) &&
!(s.flags & lt::add_torrent_params::flag_auto_managed))
if ((s.flags & lt::torrent_flags::paused) &&
!(s.flags & lt::torrent_flags::auto_managed))
{
ret += "paused";
}
else if ((s.flags & lt::add_torrent_params::flag_paused) &&
(s.flags & lt::add_torrent_params::flag_auto_managed))
else if ((s.flags & lt::torrent_flags::paused) &&
(s.flags & lt::torrent_flags::auto_managed))
{
ret += "queued";
}
else if (s.flags & lt::add_torrent_params::flag_upload_mode) ret += "upload mode";
else if ((s.flags & lt::torrent_flags::upload_mode)) ret += "upload mode";
else ret += state_str[s.state];
if (!(s.flags & lt::add_torrent_params::flag_paused) &&
!(s.flags & lt::add_torrent_params::flag_auto_managed))
if (!(s.flags & lt::torrent_flags::paused) &&
!(s.flags & lt::torrent_flags::auto_managed))
{
ret += " [F]";
}
@ -351,7 +351,7 @@ void torrent_view::print_torrent(lt::torrent_status const& s, bool selected)
color_code progress_bar_color = col_yellow;
if (s.errc) progress_bar_color = col_red;
else if (s.flags & lt::add_torrent_params::flag_paused) progress_bar_color = col_blue;
else if (s.flags & lt::torrent_flags::paused) progress_bar_color = col_blue;
else if (s.state == lt::torrent_status::downloading_metadata)
progress_bar_color = col_magenta;
else if (s.current_tracker.empty())
@ -388,21 +388,21 @@ bool torrent_view::show_torrent(lt::torrent_status const& st)
{
case torrents_all: return true;
case torrents_downloading:
return !(st.flags & lt::add_torrent_params::flag_paused)
return !(st.flags & lt::torrent_flags::paused)
&& st.state != lt::torrent_status::seeding
&& st.state != lt::torrent_status::finished;
case torrents_not_paused:
return !(st.flags & lt::add_torrent_params::flag_paused);
return !(st.flags & lt::torrent_flags::paused);
case torrents_seeding:
return !(st.flags & lt::add_torrent_params::flag_paused)
return !(st.flags & lt::torrent_flags::paused)
&& (st.state == lt::torrent_status::seeding
|| st.state == lt::torrent_status::finished);
case torrents_queued:
return (st.flags & lt::add_torrent_params::flag_paused)
&& (st.flags & lt::add_torrent_params::flag_auto_managed);
return (st.flags & lt::torrent_flags::paused)
&& (st.flags & lt::torrent_flags::auto_managed);
case torrents_stopped:
return (st.flags & lt::add_torrent_params::flag_paused)
&& !(st.flags & lt::add_torrent_params::flag_auto_managed);
return (st.flags & lt::torrent_flags::paused)
&& !(st.flags & lt::torrent_flags::auto_managed);
case torrents_checking: return st.state == lt::torrent_status::checking_files;
}
return true;

View File

@ -46,6 +46,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/bitfield.hpp"
#include "libtorrent/error_code.hpp"
#include "libtorrent/units.hpp"
#include "libtorrent/torrent_flags.hpp"
#include "libtorrent/aux_/noexcept_movable.hpp"
namespace libtorrent {
@ -92,186 +93,37 @@ namespace libtorrent {
add_torrent_params(add_torrent_params const&);
add_torrent_params& operator=(add_torrent_params const&);
// values for the ``flags`` field
enum flags_t : std::uint64_t
{
// If ``flag_seed_mode`` is set, libtorrent will assume that all files
// are present for this torrent and that they all match the hashes in
// the torrent file. Each time a peer requests to download a block,
// the piece is verified against the hash, unless it has been verified
// already. If a hash fails, the torrent will automatically leave the
// seed mode and recheck all the files. The use case for this mode is
// if a torrent is created and seeded, or if the user already know
// that the files are complete, this is a way to avoid the initial
// file checks, and significantly reduce the startup time.
//
// Setting ``flag_seed_mode`` on a torrent without metadata (a
// .torrent file) is a no-op and will be ignored.
//
// If resume data is passed in with this torrent, the seed mode saved
// in there will override the seed mode you set here.
flag_seed_mode = 0x001,
// If ``flag_upload_mode`` is set, the torrent will be initialized in
// upload-mode, which means it will not make any piece requests. This
// state is typically entered on disk I/O errors, and if the torrent
// is also auto managed, it will be taken out of this state
// periodically. This mode can be used to avoid race conditions when
// adjusting priorities of pieces before allowing the torrent to start
// downloading.
//
// If the torrent is auto-managed (``flag_auto_managed``), the torrent
// will eventually be taken out of upload-mode, regardless of how it
// got there. If it's important to manually control when the torrent
// leaves upload mode, don't make it auto managed.
flag_upload_mode = 0x004,
// determines if the torrent should be added in *share mode* or not.
// Share mode indicates that we are not interested in downloading the
// torrent, but merely want to improve our share ratio (i.e. increase
// it). A torrent started in share mode will do its best to never
// download more than it uploads to the swarm. If the swarm does not
// have enough demand for upload capacity, the torrent will not
// download anything. This mode is intended to be safe to add any
// number of torrents to, without manual screening, without the risk
// of downloading more than is uploaded.
//
// A torrent in share mode sets the priority to all pieces to 0,
// except for the pieces that are downloaded, when pieces are decided
// to be downloaded. This affects the progress bar, which might be set
// to "100% finished" most of the time. Do not change file or piece
// priorities for torrents in share mode, it will make it not work.
//
// The share mode has one setting, the share ratio target, see
// ``settings_pack::share_mode_target`` for more info.
flag_share_mode = 0x008,
// determines if the IP filter should apply to this torrent or not. By
// default all torrents are subject to filtering by the IP filter
// (i.e. this flag is set by default). This is useful if certain
// torrents needs to be exempt for some reason, being an auto-update
// torrent for instance.
flag_apply_ip_filter = 0x010,
// specifies whether or not the torrent is to be started in a paused
// state. I.e. it won't connect to the tracker or any of the peers
// until it's resumed. This is typically a good way of avoiding race
// conditions when setting configuration options on torrents before
// starting them.
flag_paused = 0x020,
// If the torrent is auto-managed (``flag_auto_managed``), the torrent
// may be resumed at any point, regardless of how it paused. If it's
// important to manually control when the torrent is paused and
// resumed, don't make it auto managed.
//
// If ``flag_auto_managed`` is set, the torrent will be queued,
// started and seeded automatically by libtorrent. When this is set,
// the torrent should also be started as paused. The default queue
// order is the order the torrents were added. They are all downloaded
// in that order. For more details, see queuing_.
//
// If you pass in resume data, the auto_managed state of the torrent
// when the resume data was saved will override the auto_managed state
// you pass in here. You can override this by setting
// ``override_resume_data``.
flag_auto_managed = 0x040,
flag_duplicate_is_error = 0x080,
// on by default and means that this torrent will be part of state
// updates when calling post_torrent_updates().
flag_update_subscribe = 0x200,
// sets the torrent into super seeding mode. If the torrent is not a
// seed, this flag has no effect. It has the same effect as calling
// ``torrent_handle::super_seeding(true)`` on the torrent handle
// immediately after adding it.
flag_super_seeding = 0x400,
// sets the sequential download state for the torrent. It has the same
// effect as calling ``torrent_handle::sequential_download(true)`` on
// the torrent handle immediately after adding it.
flag_sequential_download = 0x800,
// These are all deprecated. use torrent_flags_t instead (in
// libtorrent/torrent_flags.hpp)
#ifndef TORRENT_NO_DEPRECATE
// indicates that this torrent should never be unloaded from RAM, even
// if unloading torrents are allowed in general. Setting this makes
// the torrent exempt from loading/unloading management.
flag_pinned TORRENT_DEPRECATED_ENUM = 0x1000,
#endif
// the stop when ready flag. Setting this flag is equivalent to calling
// torrent_handle::stop_when_ready() immediately after the torrent is
// added.
flag_stop_when_ready = 0x2000,
using flags_t = torrent_flags_t;
// when this flag is set, the tracker list in the add_torrent_params
// object override any trackers from the torrent file. If the flag is
// not set, the trackers from the add_torrent_params object will be
// added to the list of trackers used by the torrent.
flag_override_trackers = 0x4000,
#define DECL_FLAG(name) \
static constexpr torrent_flags_t TORRENT_DEPRECATED_MEMBER flag_##name = torrent_flags::name
// If this flag is set, the web seeds from the add_torrent_params
// object will override any web seeds in the torrent file. If it's not
// set, web seeds in the add_torrent_params object will be added to the
// list of web seeds used by the torrent.
flag_override_web_seeds = 0x8000,
// if this flag is set (which it is by default) the torrent will be
// considered needing to save its resume data immediately as it's
// added. New torrents that don't have any resume data should do that.
// This flag is cleared by a successful call to save_resume_data()
flag_need_save_resume = 0x10000,
#ifndef TORRENT_NO_DEPRECATE
// If ``flag_override_resume_data`` is set, flags set for this torrent
// in this ``add_torrent_params`` object will take precedence over
// whatever states are saved in the resume data. For instance, the
// ``paused``, ``auto_managed``, ``sequential_download``, ``seed_mode``,
// ``super_seeding``, ``max_uploads``, ``max_connections``,
// ``upload_limit`` and ``download_limit`` are all affected by this
// flag. The intention of this flag is to have any field in
// add_torrent_params configuring the torrent override the corresponding
// configuration from the resume file, with the one exception of save
// resume data, which has its own flag (for historic reasons).
// "file_priorities" and "save_path" are not affected by this flag.
flag_override_resume_data TORRENT_DEPRECATED_ENUM = 0x20000,
// defaults to on and specifies whether tracker URLs loaded from
// resume data should be added to the trackers in the torrent or
// replace the trackers. When replacing trackers (i.e. this flag is not
// set), any trackers passed in via add_torrent_params are also
// replaced by any trackers in the resume data. The default behavior is
// to have the resume data override the .torrent file _and_ the
// trackers added in add_torrent_params.
flag_merge_resume_trackers TORRENT_DEPRECATED_ENUM = 0x40000,
// if this flag is set, the save path from the resume data file, if
// present, is honored. This defaults to not being set, in which
// case the save_path specified in add_torrent_params is always used.
flag_use_resume_save_path TORRENT_DEPRECATED_ENUM = 0x80000,
// defaults to on and specifies whether web seed URLs loaded from
// resume data should be added to the ones in the torrent file or
// replace them. No distinction is made between the two different kinds
// of web seeds (`BEP 17`_ and `BEP 19`_). When replacing web seeds
// (i.e. when this flag is not set), any web seeds passed in via
// add_torrent_params are also replaced. The default behavior is to
// have any web seeds in the resume data take precedence over whatever
// is passed in here as well as the .torrent file.
flag_merge_resume_http_seeds TORRENT_DEPRECATED_ENUM = 0x100000,
#endif
// internal
default_flags = flag_update_subscribe
| flag_auto_managed | flag_paused | flag_apply_ip_filter
| flag_need_save_resume
#ifndef TORRENT_NO_DEPRECATE
| flag_pinned
| flag_merge_resume_http_seeds
| flag_merge_resume_trackers
#endif
};
DECL_FLAG(seed_mode);
DECL_FLAG(upload_mode);
DECL_FLAG(share_mode);
DECL_FLAG(apply_ip_filter);
DECL_FLAG(paused);
DECL_FLAG(auto_managed);
DECL_FLAG(duplicate_is_error);
DECL_FLAG(update_subscribe);
DECL_FLAG(super_seeding);
DECL_FLAG(sequential_download);
DECL_FLAG(pinned);
DECL_FLAG(stop_when_ready);
DECL_FLAG(override_trackers);
DECL_FLAG(override_web_seeds);
DECL_FLAG(need_save_resume);
DECL_FLAG(override_resume_data);
DECL_FLAG(merge_resume_trackers);
DECL_FLAG(use_resume_save_path);
DECL_FLAG(merge_resume_http_seeds);
DECL_FLAG(default_flags);
#undef DECL_FLAG
#endif // TORRENT_NO_DEPRECATE
#include "libtorrent/aux_/disable_warnings_pop.hpp"
@ -355,14 +207,14 @@ namespace libtorrent {
std::string trackerid;
// flags controlling aspects of this torrent and how it's added. See
// flags_t for details.
// torrent_flags_t for details.
//
// .. note::
// The ``flags`` field is initialized with default flags by the
// constructor. In order to preserve default behavior when clearing or
// setting other flags, make sure to bitwise OR or in a flag or bitwise
// AND the inverse of a flag to clear it.
std::uint64_t flags = default_flags;
torrent_flags_t flags = torrent_flags::default_flags;
// set this to the info hash of the torrent to add in case the info-hash
// is the only known property of the torrent. i.e. you don't have a

View File

@ -401,8 +401,8 @@ namespace libtorrent {
// before disconnecting
bool graceful_pause() const { return m_graceful_pause_mode; }
boost::uint64_t flags() const;
void set_flags(boost::uint64_t flags, boost::uint64_t mask);
torrent_flags_t flags() const;
void set_flags(torrent_flags_t flags, torrent_flags_t mask);
void set_upload_mode(bool b);
bool upload_mode() const { return m_upload_mode || m_graceful_pause_mode; }

View File

@ -0,0 +1,268 @@
/*
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_TORRENT_FLAGS_HPP
#define TORRENT_TORRENT_FLAGS_HPP
#include "libtorrent/flags.hpp"
namespace libtorrent {
struct torrent_flags_tag;
using torrent_flags_t = flags::bitfield_flag<std::uint64_t, torrent_flags_tag>;
namespace torrent_flags {
#ifndef TORRENT_NO_DEPRECATE
#include "libtorrent/aux_/disable_warnings_push.hpp"
#endif
// If ``seed_mode`` is set, libtorrent will assume that all files
// are present for this torrent and that they all match the hashes in
// the torrent file. Each time a peer requests to download a block,
// the piece is verified against the hash, unless it has been verified
// already. If a hash fails, the torrent will automatically leave the
// seed mode and recheck all the files. The use case for this mode is
// if a torrent is created and seeded, or if the user already know
// that the files are complete, this is a way to avoid the initial
// file checks, and significantly reduce the startup time.
//
// Setting ``seed_mode`` on a torrent without metadata (a
// .torrent file) is a no-op and will be ignored.
//
// If resume data is passed in with this torrent, the seed mode saved
// in there will override the seed mode you set here.
constexpr torrent_flags_t seed_mode{0x001};
// If ``upload_mode`` is set, the torrent will be initialized in
// upload-mode, which means it will not make any piece requests. This
// state is typically entered on disk I/O errors, and if the torrent
// is also auto managed, it will be taken out of this state
// periodically (see ``settings_pack::optimistic_disk_retry``).
//
// This mode can be used to avoid race conditions when
// adjusting priorities of pieces before allowing the torrent to start
// downloading.
//
// If the torrent is auto-managed (``auto_managed``), the torrent
// will eventually be taken out of upload-mode, regardless of how it
// got there. If it's important to manually control when the torrent
// leaves upload mode, don't make it auto managed.
constexpr torrent_flags_t upload_mode{0x004};
// determines if the torrent should be added in *share mode* or not.
// Share mode indicates that we are not interested in downloading the
// torrent, but merely want to improve our share ratio (i.e. increase
// it). A torrent started in share mode will do its best to never
// download more than it uploads to the swarm. If the swarm does not
// have enough demand for upload capacity, the torrent will not
// download anything. This mode is intended to be safe to add any
// number of torrents to, without manual screening, without the risk
// of downloading more than is uploaded.
//
// A torrent in share mode sets the priority to all pieces to 0,
// except for the pieces that are downloaded, when pieces are decided
// to be downloaded. This affects the progress bar, which might be set
// to "100% finished" most of the time. Do not change file or piece
// priorities for torrents in share mode, it will make it not work.
//
// The share mode has one setting, the share ratio target, see
// ``settings_pack::share_mode_target`` for more info.
constexpr torrent_flags_t share_mode{0x008};
// determines if the IP filter should apply to this torrent or not. By
// default all torrents are subject to filtering by the IP filter
// (i.e. this flag is set by default). This is useful if certain
// torrents needs to be exempt for some reason, being an auto-update
// torrent for instance.
constexpr torrent_flags_t apply_ip_filter{0x010};
// specifies whether or not the torrent is to be started in a paused
// state. I.e. it won't connect to the tracker or any of the peers
// until it's resumed. This is typically a good way of avoiding race
// conditions when setting configuration options on torrents before
// starting them.
constexpr torrent_flags_t paused{0x020};
// If the torrent is auto-managed (``auto_managed``), the torrent
// may be resumed at any point, regardless of how it paused. If it's
// important to manually control when the torrent is paused and
// resumed, don't make it auto managed.
//
// If ``auto_managed`` is set, the torrent will be queued,
// started and seeded automatically by libtorrent. When this is set,
// the torrent should also be started as paused. The default queue
// order is the order the torrents were added. They are all downloaded
// in that order. For more details, see queuing_.
//
// If you pass in resume data, the auto_managed state of the torrent
// when the resume data was saved will override the auto_managed state
// you pass in here. You can override this by setting
// ``override_resume_data``.
constexpr torrent_flags_t auto_managed{0x040};
constexpr torrent_flags_t duplicate_is_error{0x080};
// on by default and means that this torrent will be part of state
// updates when calling post_torrent_updates().
constexpr torrent_flags_t update_subscribe{0x200};
// sets the torrent into super seeding mode. If the torrent is not a
// seed, this flag has no effect. It has the same effect as calling
// ``torrent_handle::super_seeding(true)`` on the torrent handle
// immediately after adding it.
constexpr torrent_flags_t super_seeding{0x400};
// sets the sequential download state for the torrent. It has the same
// effect as calling ``torrent_handle::sequential_download(true)`` on
// the torrent handle immediately after adding it.
constexpr torrent_flags_t sequential_download{0x800};
#ifndef TORRENT_NO_DEPRECATE
// indicates that this torrent should never be unloaded from RAM, even
// if unloading torrents are allowed in general. Setting this makes
// the torrent exempt from loading/unloading management.
constexpr torrent_flags_t TORRENT_DEPRECATED_MEMBER pinned{0x1000};
#endif
// When this flag is set, the
// torrent will *force stop* whenever it transitions from a
// non-data-transferring state into a data-transferring state (referred to
// as being ready to download or seed). This is useful for torrents that
// should not start downloading or seeding yet, but want to be made ready
// to do so. A torrent may need to have its files checked for instance, so
// it needs to be started and possibly queued for checking (auto-managed
// and started) but as soon as it's done, it should be stopped.
//
// *Force stopped* means auto-managed is set to false and it's paused. As
// if auto_manage(false) and pause() were called on the torrent.
//
// Note that the torrent may transition into a downloading state while
// calling this function, and since the logic is edge triggered you may
// miss the edge. To avoid this race, if the torrent already is in a
// downloading state when this call is made, it will trigger the
// stop-when-ready immediately.
//
// When the stop-when-ready logic fires, the flag is cleared. Any
// subsequent transitions between downloading and non-downloading states
// will not be affected, until this function is used to set it again.
//
// The behavior is more robust when setting this flag as part of adding
// the torrent. See add_torrent_params.
//
// The stop-when-ready flag fixes the inherent race condition of waiting
// for the state_changed_alert and then call pause(). The download/seeding
// will most likely start in between posting the alert and receiving the
// call to pause.
constexpr torrent_flags_t stop_when_ready{0x2000};
// when this flag is set, the tracker list in the add_torrent_params
// object override any trackers from the torrent file. If the flag is
// not set, the trackers from the add_torrent_params object will be
// added to the list of trackers used by the torrent.
constexpr torrent_flags_t override_trackers{0x4000};
// If this flag is set, the web seeds from the add_torrent_params
// object will override any web seeds in the torrent file. If it's not
// set, web seeds in the add_torrent_params object will be added to the
// list of web seeds used by the torrent.
constexpr torrent_flags_t override_web_seeds{0x8000};
// if this flag is set (which it is by default) the torrent will be
// considered needing to save its resume data immediately as it's
// added. New torrents that don't have any resume data should do that.
// This flag is cleared by a successful call to save_resume_data()
constexpr torrent_flags_t need_save_resume{0x10000};
#ifndef TORRENT_NO_DEPRECATE
// If ``override_resume_data`` is set, flags set for this torrent
// in this ``add_torrent_params`` object will take precedence over
// whatever states are saved in the resume data. For instance, the
// ``paused``, ``auto_managed``, ``sequential_download``, ``seed_mode``,
// ``super_seeding``, ``max_uploads``, ``max_connections``,
// ``upload_limit`` and ``download_limit`` are all affected by this
// flag. The intention of this flag is to have any field in
// add_torrent_params configuring the torrent override the corresponding
// configuration from the resume file, with the one exception of save
// resume data, which has its own flag (for historic reasons).
// "file_priorities" and "save_path" are not affected by this flag.
constexpr torrent_flags_t TORRENT_DEPRECATED_MEMBER override_resume_data{0x20000};
// defaults to on and specifies whether tracker URLs loaded from
// resume data should be added to the trackers in the torrent or
// replace the trackers. When replacing trackers (i.e. this flag is not
// set), any trackers passed in via add_torrent_params are also
// replaced by any trackers in the resume data. The default behavior is
// to have the resume data override the .torrent file _and_ the
// trackers added in add_torrent_params.
constexpr torrent_flags_t TORRENT_DEPRECATED_MEMBER merge_resume_trackers{0x40000};
// if this flag is set, the save path from the resume data file, if
// present, is honored. This defaults to not being set, in which
// case the save_path specified in add_torrent_params is always used.
constexpr torrent_flags_t TORRENT_DEPRECATED_MEMBER use_resume_save_path{0x80000};
// defaults to on and specifies whether web seed URLs loaded from
// resume data should be added to the ones in the torrent file or
// replace them. No distinction is made between the two different kinds
// of web seeds (`BEP 17`_ and `BEP 19`_). When replacing web seeds
// (i.e. when this flag is not set), any web seeds passed in via
// add_torrent_params are also replaced. The default behavior is to
// have any web seeds in the resume data take precedence over whatever
// is passed in here as well as the .torrent file.
constexpr torrent_flags_t TORRENT_DEPRECATED_MEMBER merge_resume_http_seeds{0x100000};
#endif
constexpr torrent_flags_t all{0xffffffffffffffff};
// internal
constexpr torrent_flags_t default_flags =
torrent_flags::update_subscribe
| torrent_flags::auto_managed
| torrent_flags::paused
| torrent_flags::apply_ip_filter
| torrent_flags::need_save_resume
#ifndef TORRENT_NO_DEPRECATE
| torrent_flags::pinned
| torrent_flags::merge_resume_http_seeds
| torrent_flags::merge_resume_trackers
#endif
;
#ifndef TORRENT_NO_DEPRECATE
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#endif
} // torrent_flags
} // libtorrent
#endif

View File

@ -54,6 +54,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/units.hpp"
#include "libtorrent/aux_/vector.hpp"
#include "libtorrent/storage_defs.hpp"
#include "libtorrent/torrent_flags.hpp"
namespace libtorrent { namespace aux {
@ -577,85 +578,19 @@ namespace libtorrent { namespace aux {
void pause(int flags = 0) const;
void resume() const;
// reflects the torrent's flags. The bits in the return value
// correspond to the flags found in
// ``add_torrent_params::flags_t``. The currently supported
// flags are:
// ``seed_mode``, ``upload_mode``, ``share_mode``,
// ``apply_ip_filter``, ``paused``,
// ``auto_managed``, ``super_seeding``,
// ``sequential_download``, ``pinned``, and
// ``stop_when_ready``.
boost::uint64_t flags() const;
// sets the ``add_torrent_params::flags_t`` flags
// reflected by ``torrent_handle::flags()``. For each bit
// set in the ``mask`` argument, that flag will be set to the
// value of the corresponding bit in the ``flags`` argument.
// Note that ``seed_mode`` can only be set when adding a
// torrent, and cannot be set with ``set_flags()``. Any
// unsupported flags will be silently ignored.
void set_flags(boost::uint64_t flags, boost::uint64_t mask) const;
// an alias for ``set_flags(0xffffffffffffffff, flags)``
void set_flags(boost::uint64_t flags) const;
// an alias for ``set_flags(0, flags)``
void unset_flags(boost::uint64_t flags) const;
#ifndef TORRENT_NO_DEPRECATE
// set or clear the stop-when-ready flag. When this flag is set, the
// torrent will *force stop* whenever it transitions from a
// non-data-transferring state into a data-transferring state (referred to
// as being ready to download or seed). This is useful for torrents that
// should not start downloading or seeding yet, but want to be made ready
// to do so. A torrent may need to have its files checked for instance, so
// it needs to be started and possibly queued for checking (auto-managed
// and started) but as soon as it's done, it should be stopped.
//
// *Force stopped* means auto-managed is set to false and it's paused. As
// if auto_manage(false) and pause() were called on the torrent.
//
// Note that the torrent may transition into a downloading state while
// calling this function, and since the logic is edge triggered you may
// miss the edge. To avoid this race, if the torrent already is in a
// downloading state when this call is made, it will trigger the
// stop-when-ready immediately.
//
// When the stop-when-ready logic fires, the flag is cleared. Any
// subsequent transitions between downloading and non-downloading states
// will not be affected, until this function is used to set it again.
//
// The behavior is more robust when setting this flag as part of adding
// the torrent. See add_torrent_params.
//
// The stop-when-ready flag fixes the inherent race condition of waiting
// for the state_changed_alert and then call pause(). The download/seeding
// will most likely start in between posting the alert and receiving the
// call to pause.
TORRENT_DEPRECATED
void stop_when_ready(bool b) const;
// Explicitly sets the upload mode of the torrent. In upload mode, the
// torrent will not request any pieces. If the torrent is auto managed,
// it will automatically be taken out of upload mode periodically (see
// ``settings_pack::optimistic_disk_retry``). Torrents are
// automatically put in upload mode whenever they encounter a disk write
// error.
//
// ``m`` should be true to enter upload mode, and false to leave it.
//
// To test if a torrent is in upload mode, call
// ``torrent_handle::status()`` and inspect
// ``torrent_status::upload_mode``.
TORRENT_DEPRECATED
void set_upload_mode(bool b) const;
// Enable or disable share mode for this torrent. When in share mode, the
// torrent will not necessarily be downloaded, especially not the whole
// of it. Only parts that are likely to be distributed to more than 2
// other peers are downloaded, and only if the previous prediction was
// correct.
TORRENT_DEPRECATED
void set_share_mode(bool b) const;
#endif
// sets and gets the torrent state flags. See torrent_flags_t.
// The ``set_flags`` overload that take a mask will affect all
// flags part of the mask, and set their values to what the
// ``flags`` argument is set to. This allows clearing and
// setting flags in a single function call.
// The ``set_flags`` overload that just takes flags, sets all
// the specified flags and leave any other flags unchanged.
// ``unset_flags`` clears the specified flags, while leaving
// any other flags unchanged.
torrent_flags_t flags() const;
void set_flags(torrent_flags_t flags, torrent_flags_t mask) const;
void set_flags(torrent_flags_t flags) const;
void unset_flags(torrent_flags_t flags) const;
// Instructs libtorrent to flush all the disk caches for this torrent and
// close all file handles. This is done asynchronously and you will be
@ -667,14 +602,6 @@ namespace libtorrent { namespace aux {
// ``torrent_handle::flush_cache()`` has been written to disk.
void flush_cache() const;
#ifndef TORRENT_NO_DEPRECATE
// Set to true to apply the session global IP filter to this torrent
// (which is the default). Set to false to make this torrent ignore the
// IP filter.
TORRENT_DEPRECATED
void apply_ip_filter(bool b) const;
#endif
// ``force_recheck`` puts the torrent back in a state where it assumes to
// have no resume data. All peers will be disconnected and the torrent
// will stop announcing to the tracker. The torrent will be added to the
@ -846,13 +773,6 @@ namespace libtorrent { namespace aux {
// handled in order for this function to be meaningful.
bool need_save_resume_data() const;
#ifndef TORRENT_NO_DEPRECATE
// changes whether the torrent is auto managed or not. For more info,
// see queuing_.
TORRENT_DEPRECATED
void auto_managed(bool m) const;
#endif
// Every torrent that is added is assigned a queue position exactly one
// greater than the greatest queue position of all existing torrents.
// Torrents that are being seeded have -1 as their queue position, since
@ -940,6 +860,24 @@ namespace libtorrent { namespace aux {
// ================ start deprecation ============
// deprecated in 1.2
TORRENT_DEPRECATED
void stop_when_ready(bool b) const;
TORRENT_DEPRECATED
void set_upload_mode(bool b) const;
TORRENT_DEPRECATED
void set_share_mode(bool b) const;
TORRENT_DEPRECATED
void apply_ip_filter(bool b) const;
TORRENT_DEPRECATED
void auto_managed(bool m) const;
TORRENT_DEPRECATED
void set_pinned(bool p) const;
TORRENT_DEPRECATED
void set_sequential_download(bool sd) const;
// deprecated in 1.0
// use status() instead (with query_save_path)
TORRENT_DEPRECATED
@ -1137,36 +1075,6 @@ namespace libtorrent { namespace aux {
void set_download_limit(int limit) const;
int download_limit() const;
#ifndef TORRENT_NO_DEPRECATE
// A pinned torrent may not be unloaded by libtorrent. When the dynamic
// loading and unloading of torrents is enabled (by setting a load
// function on the session), this can be used to exempt certain torrents
// from the unloading logic.
//
// Magnet links, and other torrents that start out without having
// metadata are pinned automatically. This is to give the client a chance
// to get the metadata and save it before it's unloaded. In this case, it
// may be useful to unpin the torrent once its metadata has been saved
// to disk.
//
// For more information about dynamically loading and unloading torrents,
// see dynamic-loading-of-torrent-files_.
//
TORRENT_DEPRECATED
void set_pinned(bool p) const;
// ``set_sequential_download()`` enables or disables *sequential
// download*. When enabled, the piece picker will pick pieces in sequence
// instead of rarest first. In this mode, piece priorities are ignored,
// with the exception of priority 7, which are still preferred over the
// sequential piece order.
//
// Enabling sequential download will affect the piece distribution
// negatively in the swarm. It should be used sparingly.
TORRENT_DEPRECATED
void set_sequential_download(bool sd) const;
#endif
// ``connect_peer()`` is a way to manually connect to peers that one
// believe is a part of the torrent. If the peer does not respond, or is
// not a member of this torrent, it will simply be disconnected. No harm

View File

@ -583,7 +583,7 @@ namespace libtorrent {
// reflects several of the torrent's flags. For more
// information, see ``torrent_handle::flags()``.
boost::uint64_t flags = 0;
torrent_flags_t flags{};
};
}

View File

@ -41,6 +41,33 @@ namespace libtorrent {
add_torrent_params::add_torrent_params(add_torrent_params const&) = default;
add_torrent_params& add_torrent_params::operator=(add_torrent_params const&) = default;
#ifndef TORRENT_NO_DEPRECATE
#define DECL_FLAG(name) \
constexpr torrent_flags_t add_torrent_params::flag_##name
DECL_FLAG(seed_mode);
DECL_FLAG(upload_mode);
DECL_FLAG(share_mode);
DECL_FLAG(apply_ip_filter);
DECL_FLAG(paused);
DECL_FLAG(auto_managed);
DECL_FLAG(duplicate_is_error);
DECL_FLAG(update_subscribe);
DECL_FLAG(super_seeding);
DECL_FLAG(sequential_download);
DECL_FLAG(pinned);
DECL_FLAG(stop_when_ready);
DECL_FLAG(override_trackers);
DECL_FLAG(override_web_seeds);
DECL_FLAG(need_save_resume);
DECL_FLAG(override_resume_data);
DECL_FLAG(merge_resume_trackers);
DECL_FLAG(use_resume_save_path);
DECL_FLAG(merge_resume_http_seeds);
DECL_FLAG(default_flags);
#undef DECL_FLAG
#endif // TORRENT_NO_DEPRECATE
static_assert(std::is_nothrow_move_constructible<add_torrent_params>::value
, "should be nothrow move constructible");

View File

@ -45,10 +45,10 @@ namespace libtorrent {
namespace {
void apply_flag(std::uint64_t& current_flags
void apply_flag(torrent_flags_t& current_flags
, bdecode_node const& n
, char const* name
, std::uint64_t const flag)
, torrent_flags_t const flag)
{
if (n.dict_find_int_value(name, 0) == 0)
{
@ -133,11 +133,11 @@ namespace {
ret.download_limit = int(rd.dict_find_int_value("download_rate_limit", -1));
// torrent state
apply_flag(ret.flags, rd, "seed_mode", add_torrent_params::flag_seed_mode);
apply_flag(ret.flags, rd, "super_seeding", add_torrent_params::flag_super_seeding);
apply_flag(ret.flags, rd, "auto_managed", add_torrent_params::flag_auto_managed);
apply_flag(ret.flags, rd, "sequential_download", add_torrent_params::flag_sequential_download);
apply_flag(ret.flags, rd, "paused", add_torrent_params::flag_paused);
apply_flag(ret.flags, rd, "seed_mode", torrent_flags::seed_mode);
apply_flag(ret.flags, rd, "super_seeding", torrent_flags::super_seeding);
apply_flag(ret.flags, rd, "auto_managed", torrent_flags::auto_managed);
apply_flag(ret.flags, rd, "sequential_download", torrent_flags::sequential_download);
apply_flag(ret.flags, rd, "paused", torrent_flags::paused);
ret.save_path = rd.dict_find_string_value("save_path").to_string();
@ -177,7 +177,7 @@ namespace {
// this is suspicious, leave seed mode
if (ret.file_priorities[idx] == 0)
{
ret.flags &= ~add_torrent_params::flag_seed_mode;
ret.flags &= ~torrent_flags::seed_mode;
}
}
}
@ -189,7 +189,7 @@ namespace {
// resume data with an empty trackers list. Since we found a trackers
// list here, these should replace whatever we find in the .torrent
// file.
ret.flags |= add_torrent_params::flag_override_trackers;
ret.flags |= torrent_flags::override_trackers;
int tier = 0;
for (int i = 0; i < trackers.list_size(); ++i)
@ -217,7 +217,7 @@ namespace {
{
// since we found http seeds in the resume data, they should replace
// whatever web seeds are specified in the .torrent, by default
ret.flags |= add_torrent_params::flag_override_web_seeds;
ret.flags |= torrent_flags::override_web_seeds;
}
if (url_list)
@ -327,7 +327,7 @@ namespace {
}
}
ret.flags &= ~add_torrent_params::flag_need_save_resume;
ret.flags &= ~torrent_flags::need_save_resume;
return ret;
}

View File

@ -216,7 +216,7 @@ namespace {
if (ec) return;
// now, merge resume_data into atp according to the merge flags
if (atp.flags & add_torrent_params::flag_use_resume_save_path
if ((atp.flags & add_torrent_params::flag_use_resume_save_path)
&& !resume_data.save_path.empty())
{
atp.save_path = std::move(resume_data.save_path);
@ -236,31 +236,31 @@ namespace {
atp.tracker_tiers.insert(atp.tracker_tiers.end()
, resume_data.tracker_tiers.begin()
, resume_data.tracker_tiers.end());
if ((resume_data.flags & add_torrent_params::flag_merge_resume_trackers) == 0)
if (!(resume_data.flags & add_torrent_params::flag_merge_resume_trackers))
atp.flags |= add_torrent_params::flag_override_trackers;
}
if (!resume_data.url_seeds.empty())
{
if ((atp.flags & add_torrent_params::flag_merge_resume_http_seeds) == 0)
if (!(atp.flags & add_torrent_params::flag_merge_resume_http_seeds))
atp.url_seeds.clear();
atp.url_seeds.insert(atp.url_seeds.end()
, resume_data.url_seeds.begin()
, resume_data.url_seeds.end());
if ((atp.flags & add_torrent_params::flag_merge_resume_http_seeds) == 0)
if (!(atp.flags & add_torrent_params::flag_merge_resume_http_seeds))
atp.flags |= add_torrent_params::flag_override_web_seeds;
}
if (!resume_data.http_seeds.empty())
{
if ((atp.flags & add_torrent_params::flag_merge_resume_http_seeds) == 0)
if (!(atp.flags & add_torrent_params::flag_merge_resume_http_seeds))
atp.http_seeds.clear();
atp.http_seeds.insert(atp.http_seeds.end()
, resume_data.http_seeds.begin()
, resume_data.http_seeds.end());
if ((atp.flags & add_torrent_params::flag_merge_resume_http_seeds) == 0)
if (!(atp.flags & add_torrent_params::flag_merge_resume_http_seeds))
atp.flags |= add_torrent_params::flag_override_web_seeds;
}
@ -294,7 +294,7 @@ namespace {
atp.renamed_files = std::move(resume_data.renamed_files);
if ((atp.flags & add_torrent_params::flag_override_resume_data) == 0)
if (!(atp.flags & add_torrent_params::flag_override_resume_data))
{
atp.download_limit = resume_data.download_limit;
atp.upload_limit = resume_data.upload_limit;
@ -304,7 +304,7 @@ namespace {
if (!resume_data.file_priorities.empty())
atp.file_priorities = resume_data.file_priorities;
std::uint64_t const mask =
torrent_flags_t const mask =
add_torrent_params::flag_seed_mode
| add_torrent_params::flag_super_seeding
| add_torrent_params::flag_auto_managed

View File

@ -4866,7 +4866,7 @@ namespace {
// we want to put it off again anyway. So that while we're adding
// a boat load of torrents, we postpone the recalculation until
// we're done adding them all (since it's kind of an expensive operation)
if (params.flags & add_torrent_params::flag_auto_managed)
if (params.flags & torrent_flags::auto_managed)
{
const int max_downloading = settings().get_int(settings_pack::active_downloads);
const int max_seeds = settings().get_int(settings_pack::active_seeds);
@ -4984,7 +4984,7 @@ namespace {
if (torrent_ptr)
{
if ((params.flags & add_torrent_params::flag_duplicate_is_error) == 0)
if (!(params.flags & torrent_flags::duplicate_is_error))
{
#ifndef TORRENT_NO_DEPRECATE
//deprecated in 1.2

View File

@ -145,15 +145,15 @@ namespace libtorrent {
, bool const session_paused)
: m_ses(ses)
, m_complete(0xffffff)
, m_upload_mode((p.flags & add_torrent_params::flag_upload_mode) != 0)
, m_upload_mode(p.flags & torrent_flags::upload_mode)
, m_connections_initialized(false)
, m_abort(false)
, m_paused((p.flags & add_torrent_params::flag_paused) != 0)
, m_paused(p.flags & torrent_flags::paused)
, m_session_paused(session_paused)
, m_share_mode((p.flags & add_torrent_params::flag_share_mode) != 0)
, m_share_mode(p.flags & torrent_flags::share_mode)
, m_have_all(false)
, m_graceful_pause_mode(false)
, m_state_subscription((p.flags & add_torrent_params::flag_update_subscribe) != 0)
, m_state_subscription(p.flags & torrent_flags::update_subscribe)
, m_max_connections(0xffffff)
, m_block_size_shift(root2(block_size))
, m_state(torrent_status::checking_resume_data)
@ -180,8 +180,8 @@ namespace libtorrent {
, m_info_hash(info_hash)
, m_error_file(torrent_status::error_file_none)
, m_sequence_number(-1)
, m_announce_to_trackers((p.flags & add_torrent_params::flag_paused) == 0)
, m_announce_to_lsd((p.flags & add_torrent_params::flag_paused) == 0)
, m_announce_to_trackers(!(p.flags & torrent_flags::paused))
, m_announce_to_lsd(!(p.flags & torrent_flags::paused))
, m_has_incoming(false)
, m_files_checked(false)
, m_storage_mode(p.storage_mode)
@ -191,25 +191,25 @@ namespace libtorrent {
, m_auto_sequential(false)
, m_seed_mode(false)
, m_super_seeding(false)
, m_stop_when_ready((p.flags & add_torrent_params::flag_stop_when_ready) != 0)
, m_need_save_resume_data((p.flags & add_torrent_params::flag_need_save_resume) != 0)
, m_stop_when_ready(p.flags & torrent_flags::stop_when_ready)
, m_need_save_resume_data(p.flags & torrent_flags::need_save_resume)
, m_max_uploads((1 << 24) - 1)
, m_save_resume_flags(0)
, m_num_uploads(0)
, m_need_connect_boost(true)
, m_lsd_seq(0)
, m_magnet_link(false)
, m_apply_ip_filter((p.flags & add_torrent_params::flag_apply_ip_filter) != 0)
, m_apply_ip_filter(p.flags & torrent_flags::apply_ip_filter)
, m_pending_active_change(false)
, m_padding(0)
, m_incomplete(0xffffff)
, m_announce_to_dht((p.flags & add_torrent_params::flag_paused) == 0)
, m_announce_to_dht(!(p.flags & torrent_flags::paused))
, m_in_state_updates(false)
, m_is_active_download(false)
, m_is_active_finished(false)
, m_ssl_torrent(false)
, m_deleted(false)
, m_auto_managed((p.flags & add_torrent_params::flag_auto_managed) != 0)
, m_auto_managed(p.flags & torrent_flags::auto_managed)
, m_current_gauge_state(no_gauge_state)
, m_moving_storage(false)
, m_inactive(false)
@ -249,7 +249,7 @@ namespace libtorrent {
// if override web seed flag is set, don't load any web seeds from the
// torrent file.
std::vector<web_seed_t> ws;
if ((p.flags & add_torrent_params::flag_override_web_seeds) == 0)
if (!(p.flags & torrent_flags::override_web_seeds))
{
for (auto const& e : m_torrent_file->web_seeds())
ws.emplace_back(e);
@ -278,7 +278,7 @@ namespace libtorrent {
// --- TRACKERS ---
// if override trackers flag is set, don't load trackers from torrent file
if ((p.flags & add_torrent_params::flag_override_trackers) == 0)
if (!(p.flags & torrent_flags::override_trackers))
{
auto const& trackers = m_torrent_file->trackers();
m_trackers = {trackers.begin(), trackers.end()};
@ -338,7 +338,7 @@ namespace libtorrent {
// so assume the seed mode flag is not intended and don't enable it in
// 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 & add_torrent_params::flag_seed_mode) != 0
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.have_pieces.begin(), p.have_pieces.end(), false) == p.have_pieces.end();
@ -613,36 +613,36 @@ namespace libtorrent {
, p.max_connections
, p.upload_limit
, p.download_limit
, (p.flags & add_torrent_params::flag_seed_mode)
, (p.flags & torrent_flags::seed_mode)
? "seed-mode " : ""
, (p.flags & add_torrent_params::flag_upload_mode)
, (p.flags & torrent_flags::upload_mode)
? "upload-mode " : ""
, (p.flags & add_torrent_params::flag_share_mode)
, (p.flags & torrent_flags::share_mode)
? "share-mode " : ""
, (p.flags & add_torrent_params::flag_apply_ip_filter)
, (p.flags & torrent_flags::apply_ip_filter)
? "apply-ip-filter " : ""
, (p.flags & add_torrent_params::flag_paused)
, (p.flags & torrent_flags::paused)
? "paused " : ""
, (p.flags & add_torrent_params::flag_auto_managed)
, (p.flags & torrent_flags::auto_managed)
? "auto-managed " : ""
, (p.flags & add_torrent_params::flag_update_subscribe)
, (p.flags & torrent_flags::update_subscribe)
? "update-subscribe " : ""
, (p.flags & add_torrent_params::flag_super_seeding)
, (p.flags & torrent_flags::super_seeding)
? "super-seeding " : ""
, (p.flags & add_torrent_params::flag_sequential_download)
, (p.flags & torrent_flags::sequential_download)
? "sequential-download " : ""
, (p.flags & add_torrent_params::flag_override_trackers)
, (p.flags & torrent_flags::override_trackers)
? "override-trackers" : ""
, (p.flags & add_torrent_params::flag_override_web_seeds)
, (p.flags & torrent_flags::override_web_seeds)
? "override-web-seeds " : ""
, p.save_path.c_str()
);
}
#endif
if (p.flags & add_torrent_params::flag_sequential_download)
if (p.flags & torrent_flags::sequential_download)
m_sequential_download = true;
if (p.flags & add_torrent_params::flag_super_seeding)
if (p.flags & torrent_flags::super_seeding)
{
m_super_seeding = true;
set_need_save_resume();
@ -901,74 +901,59 @@ namespace libtorrent {
#endif
}
boost::uint64_t torrent::flags() const
torrent_flags_t torrent::flags() const
{
boost::uint64_t ret = 0;
if (m_seed_mode) {
ret |= add_torrent_params::flag_seed_mode;
}
if (m_upload_mode) {
ret |= add_torrent_params::flag_upload_mode;
}
if (m_share_mode) {
ret |= add_torrent_params::flag_share_mode;
}
if (m_apply_ip_filter) {
ret |= add_torrent_params::flag_apply_ip_filter;
}
if (is_torrent_paused()) {
ret |= add_torrent_params::flag_paused;
}
if (m_auto_managed) {
ret |= add_torrent_params::flag_auto_managed;
}
if (m_super_seeding) {
ret |= add_torrent_params::flag_super_seeding;
}
if (m_sequential_download) {
ret |= add_torrent_params::flag_sequential_download;
}
if (m_stop_when_ready) {
ret |= add_torrent_params::flag_stop_when_ready;
}
torrent_flags_t ret = torrent_flags_t{};
if (m_seed_mode)
ret |= torrent_flags::seed_mode;
if (m_upload_mode)
ret |= torrent_flags::upload_mode;
if (m_share_mode)
ret |= torrent_flags::share_mode;
if (m_apply_ip_filter)
ret |= torrent_flags::apply_ip_filter;
if (is_torrent_paused())
ret |= torrent_flags::paused;
if (m_auto_managed)
ret |= torrent_flags::auto_managed;
if (m_super_seeding)
ret |= torrent_flags::super_seeding;
if (m_sequential_download)
ret |= torrent_flags::sequential_download;
if (m_stop_when_ready)
ret |= torrent_flags::stop_when_ready;
return ret;
}
void torrent::set_flags(boost::uint64_t flags, boost::uint64_t mask)
void torrent::set_flags(torrent_flags_t const flags
, torrent_flags_t const mask)
{
if (mask & add_torrent_params::flag_seed_mode) {
if ((flags & add_torrent_params::flag_seed_mode) == 0) {
leave_seed_mode(false);
}
if ((mask & torrent_flags::seed_mode)
&& !(flags & torrent_flags::seed_mode))
{
leave_seed_mode(false);
}
if (mask & add_torrent_params::flag_upload_mode) {
set_upload_mode((flags & add_torrent_params::flag_upload_mode) != 0);
}
if (mask & add_torrent_params::flag_share_mode) {
set_share_mode((flags & add_torrent_params::flag_share_mode) != 0);
}
if (mask & add_torrent_params::flag_apply_ip_filter) {
set_apply_ip_filter((flags & add_torrent_params::flag_apply_ip_filter) != 0);
}
if (mask & add_torrent_params::flag_paused) {
if ((flags & add_torrent_params::flag_paused) != 0) {
if (mask & torrent_flags::upload_mode)
set_upload_mode(bool(flags & torrent_flags::upload_mode));
if (mask & torrent_flags::share_mode)
set_share_mode(bool(flags & torrent_flags::share_mode));
if (mask & torrent_flags::apply_ip_filter)
set_apply_ip_filter(bool(flags & torrent_flags::apply_ip_filter));
if (mask & torrent_flags::paused)
{
if (flags & torrent_flags::paused)
graceful_pause();
} else {
else
resume();
}
}
if (mask & add_torrent_params::flag_auto_managed) {
auto_managed((flags & add_torrent_params::flag_auto_managed) != 0);
}
if (mask & add_torrent_params::flag_super_seeding) {
set_super_seeding((flags & add_torrent_params::flag_super_seeding) != 0);
}
if (mask & add_torrent_params::flag_sequential_download) {
set_sequential_download((flags & add_torrent_params::flag_sequential_download) != 0);
}
if (mask & add_torrent_params::flag_stop_when_ready) {
stop_when_ready((flags & add_torrent_params::flag_stop_when_ready) != 0);
}
if (mask & torrent_flags::auto_managed)
auto_managed(bool(flags & torrent_flags::auto_managed));
if (mask & torrent_flags::super_seeding)
set_super_seeding(bool(flags & torrent_flags::super_seeding));
if (mask & torrent_flags::sequential_download)
set_sequential_download(bool(flags & torrent_flags::sequential_download));
if (mask & torrent_flags::stop_when_ready)
stop_when_ready(bool(flags & torrent_flags::stop_when_ready));
}
void torrent::set_share_mode(bool s)
@ -6075,12 +6060,12 @@ namespace libtorrent {
ret.num_incomplete = m_incomplete;
ret.num_downloaded = m_downloaded;
ret.flags = 0;
if (m_sequential_download) ret.flags |= add_torrent_params::flag_sequential_download;
if (m_seed_mode ) ret.flags |= add_torrent_params::flag_seed_mode;
if (m_super_seeding ) ret.flags |= add_torrent_params::flag_super_seeding;
if (is_torrent_paused()) ret.flags |= add_torrent_params::flag_paused;
if (m_auto_managed ) ret.flags |= add_torrent_params::flag_auto_managed;
ret.flags = torrent_flags_t{};
if (m_sequential_download) ret.flags |= torrent_flags::sequential_download;
if (m_seed_mode ) ret.flags |= torrent_flags::seed_mode;
if (m_super_seeding ) ret.flags |= torrent_flags::super_seeding;
if (is_torrent_paused()) ret.flags |= torrent_flags::paused;
if (m_auto_managed ) ret.flags |= torrent_flags::auto_managed;
ret.added_time = m_added_time;
ret.completed_time = m_completed_time;

View File

@ -48,6 +48,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/utf8.hpp"
#include "libtorrent/announce_entry.hpp"
#include "libtorrent/write_resume_data.hpp"
#include "libtorrent/torrent_flags.hpp"
#ifndef TORRENT_NO_DEPRECATE
#include "libtorrent/peer_info.hpp" // for peer_list_entry
@ -265,24 +266,25 @@ namespace libtorrent {
async_call(&torrent::pause, bool(flags & graceful_pause));
}
boost::uint64_t torrent_handle::flags() const
torrent_flags_t torrent_handle::flags() const
{
return sync_call_ret<boost::uint64_t>(0, &torrent::flags);
return sync_call_ret<torrent_flags_t>(torrent_flags_t{}, &torrent::flags);
}
void torrent_handle::set_flags(boost::uint64_t flags, boost::uint64_t mask) const
void torrent_handle::set_flags(torrent_flags_t const flags
, torrent_flags_t const mask) const
{
async_call(&torrent::set_flags, flags, mask);
}
void torrent_handle::set_flags(boost::uint64_t flags) const
void torrent_handle::set_flags(torrent_flags_t const flags) const
{
async_call(&torrent::set_flags, 0xffffffffffffffffull, flags);
async_call(&torrent::set_flags, torrent_flags::all, flags);
}
void torrent_handle::unset_flags(boost::uint64_t flags) const
void torrent_handle::unset_flags(torrent_flags_t const flags) const
{
async_call(&torrent::set_flags, 0ull, flags);
async_call(&torrent::set_flags, torrent_flags_t{}, flags);
}
#ifndef TORRENT_NO_DEPRECATE

View File

@ -68,10 +68,10 @@ namespace libtorrent {
ret["num_incomplete"] = atp.num_incomplete;
ret["num_downloaded"] = atp.num_downloaded;
ret["sequential_download"] = atp.flags & add_torrent_params::flag_sequential_download;
ret["sequential_download"] = bool(atp.flags & torrent_flags::sequential_download);
ret["seed_mode"] = atp.flags & add_torrent_params::flag_seed_mode;
ret["super_seeding"] = atp.flags & add_torrent_params::flag_super_seeding;
ret["seed_mode"] = bool(atp.flags & torrent_flags::seed_mode);
ret["super_seeding"] = bool(atp.flags & torrent_flags::super_seeding);
ret["added_time"] = atp.added_time;
ret["completed_time"] = atp.completed_time;
@ -224,8 +224,8 @@ namespace libtorrent {
ret["download_rate_limit"] = atp.download_limit;
ret["max_connections"] = atp.max_connections;
ret["max_uploads"] = atp.upload_limit;
ret["paused"] = atp.flags & add_torrent_params::flag_paused;
ret["auto_managed"] = atp.flags & add_torrent_params::flag_auto_managed;
ret["paused"] = bool(atp.flags & torrent_flags::paused);
ret["auto_managed"] = bool(atp.flags & torrent_flags::auto_managed);
if (!atp.file_priorities.empty())
{

View File

@ -823,12 +823,12 @@ setup_transfer(lt::session* ses1, lt::session* ses2, lt::session* ses3
// file pool will complain if two torrents are trying to
// use the same files
add_torrent_params param;
param.flags &= ~add_torrent_params::flag_paused;
param.flags &= ~add_torrent_params::flag_auto_managed;
param.flags &= ~torrent_flags::paused;
param.flags &= ~torrent_flags::auto_managed;
if (p) param = *p;
param.ti = clone_ptr(t);
param.save_path = "tmp1" + suffix;
param.flags |= add_torrent_params::flag_seed_mode;
param.flags |= torrent_flags::seed_mode;
error_code ec;
torrent_handle tor1 = ses1->add_torrent(param, ec);
if (ec)
@ -838,11 +838,11 @@ setup_transfer(lt::session* ses1, lt::session* ses2, lt::session* ses3
}
if (super_seeding)
{
tor1.set_flags(add_torrent_params::flag_super_seeding);
tor1.set_flags(torrent_flags::super_seeding);
}
// the downloader cannot use seed_mode
param.flags &= ~add_torrent_params::flag_seed_mode;
param.flags &= ~torrent_flags::seed_mode;
TEST_CHECK(!ses1->get_torrents().empty());

View File

@ -50,16 +50,16 @@ POSSIBILITY OF SUCH DAMAGE.
#pragma warning( disable : 4706 )
#endif
void test_swarm(int flags)
void test_swarm(test_flags_t const flags)
{
using namespace lt;
std::printf("\n\n ==== TEST SWARM === %s%s%s%s%s ===\n\n\n"
, (flags & super_seeding) ? "super-seeding ": ""
, (flags & strict_super_seeding) ? "strict-super-seeding ": ""
, (flags & seed_mode) ? "seed-mode ": ""
, (flags & time_critical) ? "time-critical ": ""
, (flags & suggest) ? "suggest ": ""
, (flags & test_flags::super_seeding) ? "super-seeding ": ""
, (flags & test_flags::strict_super_seeding) ? "strict-super-seeding ": ""
, (flags & test_flags::seed_mode) ? "seed-mode ": ""
, (flags & test_flags::time_critical) ? "time-critical ": ""
, (flags & test_flags::suggest) ? "suggest ": ""
);
// in case the previous run was terminated
@ -88,10 +88,10 @@ void test_swarm(int flags)
pack.set_int(settings_pack::alert_mask, mask);
pack.set_bool(settings_pack::allow_multiple_connections_per_ip, true);
if (flags & strict_super_seeding)
if (flags & test_flags::strict_super_seeding)
pack.set_bool(settings_pack::strict_super_seeding, true);
if (flags & suggest)
if (flags & test_flags::suggest)
pack.set_int(settings_pack::suggest_mode, settings_pack::suggest_read_cache);
// this is to avoid everything finish from a single peer
@ -126,14 +126,14 @@ void test_swarm(int flags)
torrent_handle tor3;
add_torrent_params p;
p.flags &= ~add_torrent_params::flag_paused;
p.flags &= ~add_torrent_params::flag_auto_managed;
if (flags & seed_mode) p.flags |= add_torrent_params::flag_seed_mode;
p.flags &= ~torrent_flags::paused;
p.flags &= ~torrent_flags::auto_managed;
if (flags & test_flags::seed_mode) p.flags |= torrent_flags::seed_mode;
// test using piece sizes smaller than 16kB
std::tie(tor1, tor2, tor3) = setup_transfer(&ses1, &ses2, &ses3, true
, false, true, "_swarm", 8 * 1024, nullptr, flags & super_seeding, &p);
, false, true, "_swarm", 8 * 1024, nullptr, bool(flags & test_flags::super_seeding), &p);
if (flags & time_critical)
if (flags & test_flags::time_critical)
{
tor2.set_piece_deadline(piece_index_t(2), 0);
tor2.set_piece_deadline(piece_index_t(5), 1000);
@ -155,10 +155,10 @@ void test_swarm(int flags)
torrent_status st2 = tor2.status();
torrent_status st3 = tor3.status();
if (flags & super_seeding)
if (flags & test_flags::super_seeding)
{
TEST_CHECK(st1.is_seeding);
TEST_CHECK(tor1.flags() & add_torrent_params::flag_super_seeding);
TEST_CHECK(tor1.flags() & torrent_flags::super_seeding);
}
if (st2.progress < 1.f && st2.progress > 0.5f)

View File

@ -31,15 +31,19 @@ POSSIBILITY OF SUCH DAMAGE.
*/
#include "test.hpp"
#include "libtorrent/flags.hpp"
enum test_flags_t
struct test_flags_tag;
using test_flags_t = libtorrent::flags::bitfield_flag<std::uint32_t, test_flags_tag>;
namespace test_flags
{
super_seeding = 1,
strict_super_seeding = 2,
seed_mode = 4,
time_critical = 8,
suggest = 16,
};
constexpr test_flags_t super_seeding{1};
constexpr test_flags_t strict_super_seeding{2};
constexpr test_flags_t seed_mode{4};
constexpr test_flags_t time_critical{8};
constexpr test_flags_t suggest{16};
}
void EXPORT test_swarm(int flags = 0);
void EXPORT test_swarm(test_flags_t flags = test_flags_t{});

View File

@ -408,7 +408,8 @@ entry read_ut_metadata_msg(tcp::socket& s, char* recv_buffer, int size)
std::shared_ptr<torrent_info> setup_peer(tcp::socket& s, sha1_hash& ih
, std::shared_ptr<lt::session>& ses, bool incoming = true
, int flags = 0, torrent_handle* th = nullptr)
, torrent_flags_t const flags = torrent_flags_t{}
, torrent_handle* th = nullptr)
{
std::shared_ptr<torrent_info> t = ::create_torrent();
ih = t->info_hash();
@ -427,8 +428,8 @@ std::shared_ptr<torrent_info> setup_peer(tcp::socket& s, sha1_hash& ih
error_code ec;
add_torrent_params p;
p.flags &= ~add_torrent_params::flag_paused;
p.flags &= ~add_torrent_params::flag_auto_managed;
p.flags &= ~torrent_flags::paused;
p.flags &= ~torrent_flags::auto_managed;
p.flags |= flags;
p.ti = t;
p.save_path = "./tmp1_fast";
@ -440,7 +441,7 @@ std::shared_ptr<torrent_info> setup_peer(tcp::socket& s, sha1_hash& ih
if (th) *th = ret;
// wait for the torrent to be ready
if ((flags & add_torrent_params::flag_seed_mode) == 0)
if (!(flags & torrent_flags::seed_mode))
{
wait_for_downloading(*ses, "ses");
}
@ -795,7 +796,8 @@ TORRENT_TEST(dont_have)
std::shared_ptr<lt::session> ses;
io_service ios;
tcp::socket s(ios);
std::shared_ptr<torrent_info> ti = setup_peer(s, ih, ses, true, 0, &th);
std::shared_ptr<torrent_info> ti = setup_peer(s, ih, ses, true
, torrent_flags_t{}, &th);
char recv_buffer[1000];
do_handshake(s, ih, recv_buffer);
@ -970,7 +972,7 @@ void have_all_test(bool const incoming)
std::shared_ptr<lt::session> ses;
io_service ios;
tcp::socket s(ios);
setup_peer(s, ih, ses, incoming, add_torrent_params::flag_seed_mode);
setup_peer(s, ih, ses, incoming, torrent_flags::seed_mode);
char recv_buffer[1000];
do_handshake(s, ih, recv_buffer);

View File

@ -40,7 +40,7 @@ POSSIBILITY OF SUCH DAMAGE.
using namespace libtorrent;
namespace lt = libtorrent;
void test_add_and_get_flags(boost::uint64_t flags)
void test_add_and_get_flags(torrent_flags_t const flags)
{
session ses(settings());
add_torrent_params p;
@ -55,7 +55,7 @@ void test_add_and_get_flags(boost::uint64_t flags)
TEST_EQUAL(h.flags() & flags, flags);
}
void test_set_after_add(boost::uint64_t flags)
void test_set_after_add(torrent_flags_t const flags)
{
session ses(settings());
add_torrent_params p;
@ -64,15 +64,15 @@ void test_set_after_add(boost::uint64_t flags)
p.ti = std::make_shared<torrent_info>("../test_torrents/base.torrent",
std::ref(ec));
TEST_CHECK(!ec);
p.flags = 0xffffffffffffffff & ~flags;
p.flags = torrent_flags::all & ~flags;
const torrent_handle h = ses.add_torrent(p);
TEST_CHECK(h.is_valid());
TEST_EQUAL(h.flags() & flags, 0);
TEST_EQUAL(h.flags() & flags, torrent_flags_t{});
h.set_flags(flags);
TEST_EQUAL(h.flags() & flags, flags);
}
void test_unset_after_add(boost::uint64_t flags)
void test_unset_after_add(torrent_flags_t const flags)
{
session ses(settings());
add_torrent_params p;
@ -86,79 +86,79 @@ void test_unset_after_add(boost::uint64_t flags)
TEST_CHECK(h.is_valid());
TEST_EQUAL(h.flags() & flags, flags);
h.unset_flags(flags);
TEST_EQUAL(h.flags() & flags, 0);
TEST_EQUAL(h.flags() & flags, torrent_flags_t{});
}
TORRENT_TEST(flag_seed_mode)
{
// seed-mode (can't be set after adding)
test_add_and_get_flags(add_torrent_params::flag_seed_mode);
test_unset_after_add(add_torrent_params::flag_seed_mode);
test_add_and_get_flags(torrent_flags::seed_mode);
test_unset_after_add(torrent_flags::seed_mode);
}
TORRENT_TEST(flag_upload_mode)
{
// upload-mode
test_add_and_get_flags(add_torrent_params::flag_upload_mode);
test_set_after_add(add_torrent_params::flag_upload_mode);
test_unset_after_add(add_torrent_params::flag_upload_mode);
test_add_and_get_flags(torrent_flags::upload_mode);
test_set_after_add(torrent_flags::upload_mode);
test_unset_after_add(torrent_flags::upload_mode);
}
TORRENT_TEST(flag_share_mode)
{
// share-mode
test_add_and_get_flags(add_torrent_params::flag_share_mode);
test_set_after_add(add_torrent_params::flag_share_mode);
test_unset_after_add(add_torrent_params::flag_share_mode);
test_add_and_get_flags(torrent_flags::share_mode);
test_set_after_add(torrent_flags::share_mode);
test_unset_after_add(torrent_flags::share_mode);
}
TORRENT_TEST(flag_apply_ip_filter)
{
// apply-ip-filter
test_add_and_get_flags(add_torrent_params::flag_apply_ip_filter);
test_set_after_add(add_torrent_params::flag_apply_ip_filter);
test_unset_after_add(add_torrent_params::flag_apply_ip_filter);
test_add_and_get_flags(torrent_flags::apply_ip_filter);
test_set_after_add(torrent_flags::apply_ip_filter);
test_unset_after_add(torrent_flags::apply_ip_filter);
}
TORRENT_TEST(flag_paused)
{
// paused
test_add_and_get_flags(add_torrent_params::flag_paused);
test_add_and_get_flags(torrent_flags::paused);
// TODO: change to a different test setup. currently always paused.
//test_set_after_add(add_torrent_params::flag_paused);
//test_unset_after_add(add_torrent_params::flag_paused);
//test_set_after_add(torrent_flags::paused);
//test_unset_after_add(torrent_flags::paused);
}
TORRENT_TEST(flag_auto_managed)
{
// auto-managed
test_add_and_get_flags(add_torrent_params::flag_auto_managed);
test_set_after_add(add_torrent_params::flag_auto_managed);
test_unset_after_add(add_torrent_params::flag_auto_managed);
test_add_and_get_flags(torrent_flags::auto_managed);
test_set_after_add(torrent_flags::auto_managed);
test_unset_after_add(torrent_flags::auto_managed);
}
TORRENT_TEST(flag_super_seeding)
{
// super-seeding
test_add_and_get_flags(add_torrent_params::flag_super_seeding);
test_set_after_add(add_torrent_params::flag_super_seeding);
test_unset_after_add(add_torrent_params::flag_super_seeding);
test_add_and_get_flags(torrent_flags::super_seeding);
test_set_after_add(torrent_flags::super_seeding);
test_unset_after_add(torrent_flags::super_seeding);
}
TORRENT_TEST(flag_sequential_download)
{
// sequential-download
test_add_and_get_flags(add_torrent_params::flag_sequential_download);
test_set_after_add(add_torrent_params::flag_sequential_download);
test_unset_after_add(add_torrent_params::flag_sequential_download);
test_add_and_get_flags(torrent_flags::sequential_download);
test_set_after_add(torrent_flags::sequential_download);
test_unset_after_add(torrent_flags::sequential_download);
}
TORRENT_TEST(flag_stop_when_ready)
{
// stop-when-ready
test_add_and_get_flags(add_torrent_params::flag_stop_when_ready);
test_add_and_get_flags(torrent_flags::stop_when_ready);
// setting stop-when-ready when already stopped has no effect.
// TODO: change to a different test setup. currently always paused.
//test_set_after_add(add_torrent_params::flag_stop_when_ready);
test_unset_after_add(add_torrent_params::flag_stop_when_ready);
//test_set_after_add(torrent_flags::stop_when_ready);
test_unset_after_add(torrent_flags::stop_when_ready);
}

View File

@ -48,8 +48,8 @@ void test_remove_url(std::string url)
{
lt::session s(settings());
add_torrent_params p;
p.flags &= ~add_torrent_params::flag_paused;
p.flags &= ~add_torrent_params::flag_auto_managed;
p.flags &= ~torrent_flags::paused;
p.flags &= ~torrent_flags::auto_managed;
p.url = url;
p.save_path = ".";
torrent_handle h = s.add_torrent(p);
@ -111,8 +111,8 @@ TORRENT_TEST(magnet)
// test magnet link parsing
add_torrent_params model;
model.flags &= ~add_torrent_params::flag_paused;
model.flags &= ~add_torrent_params::flag_auto_managed;
model.flags &= ~torrent_flags::paused;
model.flags &= ~torrent_flags::auto_managed;
model.save_path = ".";
error_code ec;
add_torrent_params p = model;

View File

@ -292,8 +292,8 @@ done:
p = read_resume_data(resume_data, ec);
TEST_CHECK(!ec);
}
p.flags &= ~add_torrent_params::flag_paused;
p.flags &= ~add_torrent_params::flag_auto_managed;
p.flags &= ~torrent_flags::paused;
p.flags &= ~torrent_flags::auto_managed;
p.ti = t;
p.save_path = "tmp2_priority";
@ -404,8 +404,8 @@ TORRENT_TEST(no_metadata_file_prio)
lt::session ses(pack);
add_torrent_params addp;
addp.flags &= ~add_torrent_params::flag_paused;
addp.flags &= ~add_torrent_params::flag_auto_managed;
addp.flags &= ~torrent_flags::paused;
addp.flags &= ~torrent_flags::auto_managed;
addp.info_hash = sha1_hash("abababababababababab");
addp.save_path = ".";
torrent_handle h = ses.add_torrent(addp);
@ -424,8 +424,8 @@ TORRENT_TEST(no_metadata_piece_prio)
lt::session ses(pack);
add_torrent_params addp;
addp.flags &= ~add_torrent_params::flag_paused;
addp.flags &= ~add_torrent_params::flag_auto_managed;
addp.flags &= ~torrent_flags::paused;
addp.flags &= ~torrent_flags::auto_managed;
addp.info_hash = sha1_hash("abababababababababab");
addp.save_path = ".";
torrent_handle h = ses.add_torrent(addp);

View File

@ -155,12 +155,12 @@ session_proxy test_proxy(settings_pack::proxy_type_t proxy_type, int flags)
t->add_tracker(udp_tracker_url, 1);
add_torrent_params addp;
addp.flags &= ~add_torrent_params::flag_paused;
addp.flags &= ~add_torrent_params::flag_auto_managed;
addp.flags &= ~torrent_flags::paused;
addp.flags &= ~torrent_flags::auto_managed;
// we don't want to waste time checking the torrent, just go straight into
// seeding it, announcing to trackers and connecting to peers
addp.flags |= add_torrent_params::flag_seed_mode;
addp.flags |= torrent_flags::seed_mode;
addp.ti = t;
addp.save_path = "tmp1_privacy";

View File

@ -105,12 +105,12 @@ void test_read_piece(int flags)
lt::session ses(sett);
add_torrent_params p;
p.flags &= ~add_torrent_params::flag_paused;
p.flags &= ~add_torrent_params::flag_auto_managed;
p.flags &= ~torrent_flags::paused;
p.flags &= ~torrent_flags::auto_managed;
p.save_path = "tmp1_read_piece";
p.ti = ti;
if (flags & seed_mode)
p.flags |= add_torrent_params::flag_seed_mode;
if (flags & flags_t::seed_mode)
p.flags |= torrent_flags::seed_mode;
torrent_handle tor1 = ses.add_torrent(p, ec);
if (ec) std::printf("ERROR: add_torrent: (%d) %s\n"
, ec.value(), ec.message().c_str());

View File

@ -92,11 +92,15 @@ TORRENT_TEST(read_resume)
TEST_EQUAL(atp.download_limit, 1344);
TEST_EQUAL(atp.max_connections, 1345);
TEST_EQUAL(atp.max_uploads, 1346);
TEST_CHECK((atp.flags & add_torrent_params::flag_seed_mode) == 0);
TEST_CHECK((atp.flags & add_torrent_params::flag_super_seeding) == 0);
TEST_CHECK((atp.flags & add_torrent_params::flag_auto_managed) == 0);
TEST_CHECK((atp.flags & add_torrent_params::flag_sequential_download) == 0);
TEST_CHECK((atp.flags & add_torrent_params::flag_paused) == 0);
torrent_flags_t const flags_mask
= torrent_flags::seed_mode
| torrent_flags::super_seeding
| torrent_flags::auto_managed
| torrent_flags::paused
| torrent_flags::sequential_download;
TEST_CHECK(!(atp.flags & flags_mask));
TEST_EQUAL(atp.added_time, 1347);
TEST_EQUAL(atp.completed_time, 1348);
TEST_EQUAL(atp.finished_time, 1352);

View File

@ -93,11 +93,11 @@ TORRENT_TEST(recheck)
file.close();
add_torrent_params param;
param.flags &= ~add_torrent_params::flag_paused;
param.flags &= ~add_torrent_params::flag_auto_managed;
param.flags &= ~torrent_flags::paused;
param.flags &= ~torrent_flags::auto_managed;
param.ti = t;
param.save_path = "tmp1_recheck";
param.flags |= add_torrent_params::flag_seed_mode;
param.flags |= torrent_flags::seed_mode;
torrent_handle tor1 = ses1.add_torrent(param, ec);
if (ec) std::printf("add_torrent: %s\n", ec.message().c_str());

View File

@ -86,8 +86,8 @@ void test_remap_files(storage_mode_t storage_mode = storage_mode_sparse)
add_torrent_params params;
params.save_path = ".";
params.storage_mode = storage_mode;
params.flags &= ~add_torrent_params::flag_paused;
params.flags &= ~add_torrent_params::flag_auto_managed;
params.flags &= ~torrent_flags::paused;
params.flags &= ~torrent_flags::auto_managed;
params.ti = t;
torrent_handle tor1 = ses.add_torrent(params);

View File

@ -48,6 +48,16 @@ POSSIBILITY OF SUCH DAMAGE.
using namespace lt;
torrent_flags_t const flags_mask
= torrent_flags::sequential_download
| torrent_flags::paused
| torrent_flags::auto_managed
| torrent_flags::seed_mode
| torrent_flags::super_seeding
| torrent_flags::share_mode
| torrent_flags::upload_mode
| torrent_flags::apply_ip_filter;
std::shared_ptr<torrent_info> generate_torrent()
{
file_storage fs;
@ -130,7 +140,8 @@ std::vector<char> generate_resume_data(torrent_info* ti
return ret;
}
torrent_handle test_resume_flags(lt::session& ses, int flags
torrent_handle test_resume_flags(lt::session& ses
, torrent_flags_t const flags = torrent_flags_t{}
, char const* file_priorities = "1111", char const* resume_file_prio = ""
, bool const test_deprecated = false)
{
@ -282,7 +293,8 @@ TORRENT_TEST(piece_priorities)
TORRENT_TEST(file_priorities_default_deprecated)
{
lt::session ses(settings());
std::vector<int> file_priorities = test_resume_flags(ses, 0, "", "", true).file_priorities();
std::vector<int> file_priorities = test_resume_flags(ses
, torrent_flags_t{}, "", "", true).file_priorities();
TEST_EQUAL(file_priorities.size(), 3);
TEST_EQUAL(file_priorities[0], 4);
@ -334,7 +346,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,
add_torrent_params::flag_share_mode, "", "123", true).file_priorities();
torrent_flags::share_mode, "", "123", true).file_priorities();
TEST_EQUAL(file_priorities.size(), 3);
TEST_EQUAL(file_priorities[0], 0);
@ -347,7 +359,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,
add_torrent_params::flag_share_mode, "123", "", true).file_priorities();
torrent_flags::share_mode, "123", "", true).file_priorities();
TEST_EQUAL(file_priorities.size(), 3);
TEST_EQUAL(file_priorities[0], 0);
@ -358,7 +370,7 @@ TORRENT_TEST(file_priorities_seed_mode_deprecated)
TORRENT_TEST(resume_save_load_deprecated)
{
lt::session ses(settings());
torrent_handle h = test_resume_flags(ses, 0, "123", "", true);
torrent_handle h = test_resume_flags(ses, torrent_flags_t{}, "123", "", true);
h.save_resume_data();
@ -380,7 +392,7 @@ TORRENT_TEST(resume_save_load_deprecated)
TORRENT_TEST(resume_save_load_resume_deprecated)
{
lt::session ses(settings());
torrent_handle h = test_resume_flags(ses, 0, "", "123", true);
torrent_handle h = test_resume_flags(ses, torrent_flags_t{}, "", "123", true);
h.save_resume_data();
@ -406,7 +418,7 @@ TORRENT_TEST(file_priorities_resume_override_deprecated)
// flag is set.
lt::session ses(settings());
std::vector<int> file_priorities = test_resume_flags(ses,
add_torrent_params::flag_override_resume_data, "", "123", true).file_priorities();
torrent_flags::override_resume_data, "", "123", true).file_priorities();
TEST_EQUAL(file_priorities.size(), 3);
TEST_EQUAL(file_priorities[0], 1);
@ -417,7 +429,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, 0, "", "123", true).file_priorities();
std::vector<int> file_priorities = test_resume_flags(ses, torrent_flags_t{}, "", "123", true).file_priorities();
TEST_EQUAL(file_priorities.size(), 3);
TEST_EQUAL(file_priorities[0], 1);
@ -428,7 +440,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, 0, "010", "", true).file_priorities();
std::vector<int> file_priorities = test_resume_flags(ses, torrent_flags_t{}, "010", "", true).file_priorities();
TEST_EQUAL(file_priorities.size(), 3);
TEST_EQUAL(file_priorities[0], 0);
@ -441,7 +453,7 @@ TORRENT_TEST(file_priorities1_deprecated)
TORRENT_TEST(file_priorities2_deprecated)
{
lt::session ses(settings());
std::vector<int> file_priorities = test_resume_flags(ses, 0, "123", "", true).file_priorities();
std::vector<int> file_priorities = test_resume_flags(ses, torrent_flags_t{}, "123", "", true).file_priorities();
TEST_EQUAL(file_priorities.size(), 3);
TEST_EQUAL(file_priorities[0], 1);
@ -452,7 +464,7 @@ TORRENT_TEST(file_priorities2_deprecated)
TORRENT_TEST(file_priorities3_deprecated)
{
lt::session ses(settings());
std::vector<int> file_priorities = test_resume_flags(ses, 0, "4321", "", true).file_priorities();
std::vector<int> file_priorities = test_resume_flags(ses, torrent_flags_t{}, "4321", "", true).file_priorities();
TEST_EQUAL(file_priorities.size(), 3);
TEST_EQUAL(file_priorities[0], 4);
@ -464,21 +476,14 @@ TORRENT_TEST(plain_deprecated)
{
lt::session ses(settings());
torrent_status s = test_resume_flags(ses, 0, "", "", true).status();
torrent_status s = test_resume_flags(ses, torrent_flags_t{}, "", "", true).status();
default_tests(s);
#ifdef TORRENT_WINDOWS
TEST_EQUAL(s.save_path, "c:\\add_torrent_params save_path");
#else
TEST_EQUAL(s.save_path, "/add_torrent_params save_path");
#endif
TEST_EQUAL(s.flags & add_torrent_params::flag_sequential_download, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_paused, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_auto_managed, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_seed_mode, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_super_seeding, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_share_mode, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_upload_mode, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_apply_ip_filter, 0);
TEST_EQUAL(s.flags & flags_mask, torrent_flags_t{});
TEST_EQUAL(s.connections_limit, 1345);
TEST_EQUAL(s.uploads_limit, 1346);
}
@ -487,21 +492,14 @@ TORRENT_TEST(use_resume_save_path_deprecated)
{
lt::session ses(settings());
torrent_status s = test_resume_flags(ses
, add_torrent_params::flag_use_resume_save_path, "", "", true).status();
, torrent_flags::use_resume_save_path, "", "", true).status();
default_tests(s);
#ifdef TORRENT_WINDOWS
TEST_EQUAL(s.save_path, "c:\\resume_data save_path");
#else
TEST_EQUAL(s.save_path, "/resume_data save_path");
#endif
TEST_EQUAL(s.flags & add_torrent_params::flag_sequential_download, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_paused, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_auto_managed, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_seed_mode, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_super_seeding, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_share_mode, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_upload_mode, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_apply_ip_filter, 0);
TEST_EQUAL(s.flags & flags_mask, torrent_flags_t{});
TEST_EQUAL(s.connections_limit, 1345);
TEST_EQUAL(s.uploads_limit, 1346);
}
@ -510,8 +508,8 @@ TORRENT_TEST(override_resume_data_deprecated)
{
lt::session ses(settings());
torrent_status s = test_resume_flags(ses
, add_torrent_params::flag_override_resume_data
| add_torrent_params::flag_paused, "", "", true).status();
, torrent_flags::override_resume_data
| torrent_flags::paused, "", "", true).status();
default_tests(s);
#ifdef TORRENT_WINDOWS
@ -519,15 +517,7 @@ TORRENT_TEST(override_resume_data_deprecated)
#else
TEST_EQUAL(s.save_path, "/add_torrent_params save_path");
#endif
TEST_EQUAL(s.flags & add_torrent_params::flag_sequential_download, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_paused,
add_torrent_params::flag_paused);
TEST_EQUAL(s.flags & add_torrent_params::flag_auto_managed, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_seed_mode, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_super_seeding, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_share_mode, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_upload_mode, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_apply_ip_filter, 0);
TEST_EQUAL(s.flags & flags_mask, torrent_flags::paused);
TEST_EQUAL(s.connections_limit, 2);
TEST_EQUAL(s.uploads_limit, 1);
}
@ -535,23 +525,15 @@ TORRENT_TEST(override_resume_data_deprecated)
TORRENT_TEST(seed_mode_deprecated)
{
lt::session ses(settings());
torrent_status s = test_resume_flags(ses, add_torrent_params::flag_override_resume_data
| add_torrent_params::flag_seed_mode, "", "", true).status();
torrent_status s = test_resume_flags(ses, torrent_flags::override_resume_data
| torrent_flags::seed_mode, "", "", true).status();
default_tests(s);
#ifdef TORRENT_WINDOWS
TEST_EQUAL(s.save_path, "c:\\add_torrent_params save_path");
#else
TEST_EQUAL(s.save_path, "/add_torrent_params save_path");
#endif
TEST_EQUAL(s.flags & add_torrent_params::flag_sequential_download, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_paused, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_auto_managed, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_seed_mode,
add_torrent_params::flag_seed_mode);
TEST_EQUAL(s.flags & add_torrent_params::flag_super_seeding, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_share_mode, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_upload_mode, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_apply_ip_filter, 0);
TEST_EQUAL(s.flags & flags_mask, torrent_flags::seed_mode);
TEST_EQUAL(s.connections_limit, 2);
TEST_EQUAL(s.uploads_limit, 1);
}
@ -560,22 +542,14 @@ TORRENT_TEST(upload_mode_deprecated)
{
lt::session ses(settings());
torrent_status s = test_resume_flags(ses
, add_torrent_params::flag_upload_mode, "", "", true).status();
, torrent_flags::upload_mode, "", "", true).status();
default_tests(s);
#ifdef TORRENT_WINDOWS
TEST_EQUAL(s.save_path, "c:\\add_torrent_params save_path");
#else
TEST_EQUAL(s.save_path, "/add_torrent_params save_path");
#endif
TEST_EQUAL(s.flags & add_torrent_params::flag_sequential_download, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_paused, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_auto_managed, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_seed_mode, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_super_seeding, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_share_mode, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_upload_mode,
add_torrent_params::flag_upload_mode);
TEST_EQUAL(s.flags & add_torrent_params::flag_apply_ip_filter, 0);
TEST_EQUAL(s.flags & flags_mask, torrent_flags::upload_mode);
TEST_EQUAL(s.connections_limit, 1345);
TEST_EQUAL(s.uploads_limit, 1346);
}
@ -584,23 +558,15 @@ TORRENT_TEST(share_mode_deprecated)
{
lt::session ses(settings());
torrent_status s = test_resume_flags(ses
, add_torrent_params::flag_override_resume_data
| add_torrent_params::flag_share_mode, "", "", true).status();
, torrent_flags::override_resume_data
| torrent_flags::share_mode, "", "", true).status();
default_tests(s);
#ifdef TORRENT_WINDOWS
TEST_EQUAL(s.save_path, "c:\\add_torrent_params save_path");
#else
TEST_EQUAL(s.save_path, "/add_torrent_params save_path");
#endif
TEST_EQUAL(s.flags & add_torrent_params::flag_sequential_download, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_paused, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_auto_managed, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_seed_mode, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_super_seeding, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_share_mode,
add_torrent_params::flag_share_mode);
TEST_EQUAL(s.flags & add_torrent_params::flag_upload_mode, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_apply_ip_filter, 0);
TEST_EQUAL(s.flags & flags_mask, torrent_flags::share_mode);
TEST_EQUAL(s.connections_limit, 2);
TEST_EQUAL(s.uploads_limit, 1);
}
@ -610,21 +576,14 @@ TORRENT_TEST(auto_managed_deprecated)
lt::session ses(settings());
// resume data overrides the auto-managed flag
torrent_status s = test_resume_flags(ses
, add_torrent_params::flag_auto_managed, "", "", true).status();
, torrent_flags::auto_managed, "", "", true).status();
default_tests(s);
#ifdef TORRENT_WINDOWS
TEST_EQUAL(s.save_path, "c:\\add_torrent_params save_path");
#else
TEST_EQUAL(s.save_path, "/add_torrent_params save_path");
#endif
TEST_EQUAL(s.flags & add_torrent_params::flag_sequential_download, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_paused, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_auto_managed, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_seed_mode, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_super_seeding, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_share_mode, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_upload_mode, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_apply_ip_filter, 0);
TEST_EQUAL(s.flags & flags_mask, torrent_flags_t{});
TEST_EQUAL(s.connections_limit, 1345);
TEST_EQUAL(s.uploads_limit, 1346);
}
@ -633,21 +592,14 @@ TORRENT_TEST(paused_deprecated)
{
lt::session ses(settings());
// resume data overrides the paused flag
torrent_status s = test_resume_flags(ses, add_torrent_params::flag_paused, "", "", true).status();
torrent_status s = test_resume_flags(ses, torrent_flags::paused, "", "", true).status();
default_tests(s);
#ifdef TORRENT_WINDOWS
TEST_EQUAL(s.save_path, "c:\\add_torrent_params save_path");
#else
TEST_EQUAL(s.save_path, "/add_torrent_params save_path");
#endif
TEST_EQUAL(s.flags & add_torrent_params::flag_sequential_download, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_paused, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_auto_managed, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_seed_mode, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_super_seeding, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_share_mode, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_upload_mode, 0);
TEST_EQUAL(s.flags & add_torrent_params::flag_apply_ip_filter, 0);
TEST_EQUAL(s.flags & flags_mask, torrent_flags_t{});
TEST_EQUAL(s.connections_limit, 1345);
TEST_EQUAL(s.uploads_limit, 1346);
@ -662,7 +614,7 @@ TORRENT_TEST(url_seed_resume_data_deprecated)
std::printf("flags: merge_resume_http_seeds\n");
lt::session ses(settings());
torrent_handle h = test_resume_flags(ses,
add_torrent_params::flag_merge_resume_http_seeds, "", "", true);
torrent_flags::merge_resume_http_seeds, "", "", true);
std::set<std::string> us = h.url_seeds();
std::set<std::string> ws = h.http_seeds();
@ -685,7 +637,7 @@ TORRENT_TEST(resume_override_torrent_deprecated)
std::printf("flags: no merge_resume_http_seed\n");
lt::session ses(settings());
torrent_handle h = test_resume_flags(ses,
add_torrent_params::flag_merge_resume_trackers, "", "", true);
torrent_flags::merge_resume_trackers, "", "", true);
std::set<std::string> us = h.url_seeds();
std::set<std::string> ws = h.http_seeds();
@ -702,7 +654,7 @@ TORRENT_TEST(resume_override_torrent_deprecated)
TORRENT_TEST(file_priorities_default)
{
lt::session ses(settings());
std::vector<int> file_priorities = test_resume_flags(ses, 0, "", "").file_priorities();
std::vector<int> file_priorities = test_resume_flags(ses, torrent_flags_t{}, "", "").file_priorities();
TEST_EQUAL(file_priorities.size(), 3);
TEST_EQUAL(file_priorities[0], 4);
@ -715,7 +667,7 @@ 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,
add_torrent_params::flag_share_mode, "", "123").file_priorities();
torrent_flags::share_mode, "", "123").file_priorities();
TEST_EQUAL(file_priorities.size(), 3);
TEST_EQUAL(file_priorities[0], 0);
@ -728,7 +680,7 @@ 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,
add_torrent_params::flag_share_mode, "123", "").file_priorities();
torrent_flags::share_mode, "123", "").file_priorities();
TEST_EQUAL(file_priorities.size(), 3);
TEST_EQUAL(file_priorities[0], 0);
@ -930,11 +882,11 @@ void test_seed_mode(test_mode_t const flags)
| test_mode::piece_prio
| test_mode::pieces_have))
{
TEST_CHECK(!(s.flags & add_torrent_params::flag_seed_mode));
TEST_CHECK(!(s.flags & torrent_flags::seed_mode));
}
else
{
TEST_CHECK(s.flags & add_torrent_params::flag_seed_mode);
TEST_CHECK(s.flags & torrent_flags::seed_mode);
}
}
#ifndef TORRENT_NO_DEPRECATE
@ -982,7 +934,7 @@ TORRENT_TEST(seed_mode_preserve)
TORRENT_TEST(resume_save_load)
{
lt::session ses(settings());
torrent_handle h = test_resume_flags(ses, 0, "123", "");
torrent_handle h = test_resume_flags(ses, torrent_flags_t{}, "123", "");
h.save_resume_data();
@ -1004,7 +956,7 @@ TORRENT_TEST(resume_save_load)
TORRENT_TEST(resume_save_load_resume)
{
lt::session ses(settings());
torrent_handle h = test_resume_flags(ses, 0, "", "123");
torrent_handle h = test_resume_flags(ses, torrent_flags_t{}, "", "123");
h.save_resume_data();
@ -1026,7 +978,7 @@ TORRENT_TEST(resume_save_load_resume)
TORRENT_TEST(file_priorities_resume)
{
lt::session ses(settings());
std::vector<int> file_priorities = test_resume_flags(ses, 0, "", "123").file_priorities();
std::vector<int> file_priorities = test_resume_flags(ses, torrent_flags_t{}, "", "123").file_priorities();
TEST_EQUAL(file_priorities.size(), 3);
TEST_EQUAL(file_priorities[0], 1);
@ -1037,7 +989,7 @@ TORRENT_TEST(file_priorities_resume)
TORRENT_TEST(file_priorities1)
{
lt::session ses(settings());
std::vector<int> file_priorities = test_resume_flags(ses, 0, "010").file_priorities();
std::vector<int> file_priorities = test_resume_flags(ses, torrent_flags_t{}, "010").file_priorities();
TEST_EQUAL(file_priorities.size(), 3);
TEST_EQUAL(file_priorities[0], 0);
@ -1050,7 +1002,7 @@ TORRENT_TEST(file_priorities1)
TORRENT_TEST(file_priorities2)
{
lt::session ses(settings());
std::vector<int> file_priorities = test_resume_flags(ses, 0, "123").file_priorities();
std::vector<int> file_priorities = test_resume_flags(ses, torrent_flags_t{}, "123").file_priorities();
TEST_EQUAL(file_priorities.size(), 3);
TEST_EQUAL(file_priorities[0], 1);
@ -1061,7 +1013,7 @@ TORRENT_TEST(file_priorities2)
TORRENT_TEST(file_priorities3)
{
lt::session ses(settings());
std::vector<int> file_priorities = test_resume_flags(ses, 0, "4321").file_priorities();
std::vector<int> file_priorities = test_resume_flags(ses, torrent_flags_t{}, "4321").file_priorities();
TEST_EQUAL(file_priorities.size(), 3);
TEST_EQUAL(file_priorities[0], 4);
@ -1073,21 +1025,14 @@ TORRENT_TEST(plain)
{
lt::session ses(settings());
torrent_status s = test_resume_flags(ses, 0).status();
torrent_status s = test_resume_flags(ses).status();
default_tests(s);
#ifdef TORRENT_WINDOWS
TEST_EQUAL(s.save_path, "c:\\add_torrent_params save_path");
#else
TEST_EQUAL(s.save_path, "/add_torrent_params save_path");
#endif
TEST_CHECK(!(s.flags & add_torrent_params::flag_sequential_download));
TEST_CHECK(!(s.flags & add_torrent_params::flag_paused));
TEST_CHECK(!(s.flags & add_torrent_params::flag_auto_managed));
TEST_CHECK(!(s.flags & add_torrent_params::flag_seed_mode));
TEST_CHECK(!(s.flags & add_torrent_params::flag_super_seeding));
TEST_CHECK(!(s.flags & add_torrent_params::flag_share_mode));
TEST_CHECK(!(s.flags & add_torrent_params::flag_upload_mode));
TEST_CHECK(!(s.flags & add_torrent_params::flag_apply_ip_filter));
TEST_EQUAL(s.flags & flags_mask, torrent_flags_t{});
TEST_EQUAL(s.connections_limit, 1345);
TEST_EQUAL(s.uploads_limit, 1346);
}
@ -1096,21 +1041,14 @@ TORRENT_TEST(seed_mode)
{
lt::session ses(settings());
torrent_status s = test_resume_flags(ses
, add_torrent_params::flag_seed_mode).status();
, torrent_flags::seed_mode).status();
default_tests(s);
#ifdef TORRENT_WINDOWS
TEST_EQUAL(s.save_path, "c:\\add_torrent_params save_path");
#else
TEST_EQUAL(s.save_path, "/add_torrent_params save_path");
#endif
TEST_CHECK(!(s.flags & add_torrent_params::flag_sequential_download));
TEST_CHECK(!(s.flags & add_torrent_params::flag_paused));
TEST_CHECK(!(s.flags & add_torrent_params::flag_auto_managed));
TEST_CHECK(s.flags & add_torrent_params::flag_seed_mode);
TEST_CHECK(!(s.flags & add_torrent_params::flag_super_seeding));
TEST_CHECK(!(s.flags & add_torrent_params::flag_share_mode));
TEST_CHECK(!(s.flags & add_torrent_params::flag_upload_mode));
TEST_CHECK(!(s.flags & add_torrent_params::flag_apply_ip_filter));
TEST_EQUAL(s.flags & flags_mask, torrent_flags::seed_mode);
TEST_EQUAL(s.connections_limit, 1345);
TEST_EQUAL(s.uploads_limit, 1346);
}
@ -1118,21 +1056,14 @@ TORRENT_TEST(seed_mode)
TORRENT_TEST(upload_mode)
{
lt::session ses(settings());
torrent_status s = test_resume_flags(ses, add_torrent_params::flag_upload_mode).status();
torrent_status s = test_resume_flags(ses, torrent_flags::upload_mode).status();
default_tests(s);
#ifdef TORRENT_WINDOWS
TEST_EQUAL(s.save_path, "c:\\add_torrent_params save_path");
#else
TEST_EQUAL(s.save_path, "/add_torrent_params save_path");
#endif
TEST_CHECK(!(s.flags & add_torrent_params::flag_sequential_download));
TEST_CHECK(!(s.flags & add_torrent_params::flag_paused));
TEST_CHECK(!(s.flags & add_torrent_params::flag_auto_managed));
TEST_CHECK(!(s.flags & add_torrent_params::flag_seed_mode));
TEST_CHECK(!(s.flags & add_torrent_params::flag_super_seeding));
TEST_CHECK(!(s.flags & add_torrent_params::flag_share_mode));
TEST_CHECK(s.flags & add_torrent_params::flag_upload_mode);
TEST_CHECK(!(s.flags & add_torrent_params::flag_apply_ip_filter));
TEST_EQUAL(s.flags & flags_mask, torrent_flags::upload_mode);
TEST_EQUAL(s.connections_limit, 1345);
TEST_EQUAL(s.uploads_limit, 1346);
}
@ -1141,21 +1072,14 @@ TORRENT_TEST(share_mode)
{
lt::session ses(settings());
torrent_status s = test_resume_flags(ses
, add_torrent_params::flag_share_mode).status();
, torrent_flags::share_mode).status();
default_tests(s);
#ifdef TORRENT_WINDOWS
TEST_EQUAL(s.save_path, "c:\\add_torrent_params save_path");
#else
TEST_EQUAL(s.save_path, "/add_torrent_params save_path");
#endif
TEST_CHECK(!(s.flags & add_torrent_params::flag_sequential_download));
TEST_CHECK(!(s.flags & add_torrent_params::flag_paused));
TEST_CHECK(!(s.flags & add_torrent_params::flag_auto_managed));
TEST_CHECK(!(s.flags & add_torrent_params::flag_seed_mode));
TEST_CHECK(!(s.flags & add_torrent_params::flag_super_seeding));
TEST_CHECK(s.flags & add_torrent_params::flag_share_mode);
TEST_CHECK(!(s.flags & add_torrent_params::flag_upload_mode));
TEST_CHECK(!(s.flags & add_torrent_params::flag_apply_ip_filter));
TEST_EQUAL(s.flags & flags_mask, torrent_flags::share_mode);
TEST_EQUAL(s.connections_limit, 1345);
TEST_EQUAL(s.uploads_limit, 1346);
}
@ -1164,21 +1088,14 @@ TORRENT_TEST(auto_managed)
{
lt::session ses(settings());
// resume data overrides the auto-managed flag
torrent_status s = test_resume_flags(ses, add_torrent_params::flag_auto_managed).status();
torrent_status s = test_resume_flags(ses, torrent_flags::auto_managed).status();
default_tests(s);
#ifdef TORRENT_WINDOWS
TEST_EQUAL(s.save_path, "c:\\add_torrent_params save_path");
#else
TEST_EQUAL(s.save_path, "/add_torrent_params save_path");
#endif
TEST_CHECK(!(s.flags & add_torrent_params::flag_sequential_download));
TEST_CHECK(!(s.flags & add_torrent_params::flag_paused));
TEST_CHECK(s.flags & add_torrent_params::flag_auto_managed);
TEST_CHECK(!(s.flags & add_torrent_params::flag_seed_mode));
TEST_CHECK(!(s.flags & add_torrent_params::flag_super_seeding));
TEST_CHECK(!(s.flags & add_torrent_params::flag_share_mode));
TEST_CHECK(!(s.flags & add_torrent_params::flag_upload_mode));
TEST_CHECK(!(s.flags & add_torrent_params::flag_apply_ip_filter));
TEST_EQUAL(s.flags & flags_mask, torrent_flags::auto_managed);
TEST_EQUAL(s.connections_limit, 1345);
TEST_EQUAL(s.uploads_limit, 1346);
}
@ -1187,21 +1104,14 @@ TORRENT_TEST(paused)
{
lt::session ses(settings());
// resume data overrides the paused flag
torrent_status s = test_resume_flags(ses, add_torrent_params::flag_paused).status();
torrent_status s = test_resume_flags(ses, torrent_flags::paused).status();
default_tests(s);
#ifdef TORRENT_WINDOWS
TEST_EQUAL(s.save_path, "c:\\add_torrent_params save_path");
#else
TEST_EQUAL(s.save_path, "/add_torrent_params save_path");
#endif
TEST_CHECK(!(s.flags & add_torrent_params::flag_sequential_download));
TEST_CHECK(s.flags & add_torrent_params::flag_paused);
TEST_CHECK(!(s.flags & add_torrent_params::flag_auto_managed));
TEST_CHECK(!(s.flags & add_torrent_params::flag_seed_mode));
TEST_CHECK(!(s.flags & add_torrent_params::flag_super_seeding));
TEST_CHECK(!(s.flags & add_torrent_params::flag_share_mode));
TEST_CHECK(!(s.flags & add_torrent_params::flag_upload_mode));
TEST_CHECK(!(s.flags & add_torrent_params::flag_apply_ip_filter));
TEST_EQUAL(s.flags & flags_mask, torrent_flags::paused);
TEST_EQUAL(s.connections_limit, 1345);
TEST_EQUAL(s.uploads_limit, 1346);

View File

@ -116,7 +116,7 @@ TORRENT_TEST(async_add_torrent_duplicate_error)
TEST_CHECK(a);
if (a == nullptr) return;
atp.flags |= add_torrent_params::flag_duplicate_is_error;
atp.flags |= torrent_flags::duplicate_is_error;
ses.async_add_torrent(atp);
a = alert_cast<add_torrent_alert>(wait_for_alert(ses, add_torrent_alert::alert_type, "ses"));
TEST_CHECK(a);
@ -142,7 +142,7 @@ TORRENT_TEST(async_add_torrent_duplicate)
torrent_handle h = a->handle;
TEST_CHECK(!a->error);
atp.flags &= ~add_torrent_params::flag_duplicate_is_error;
atp.flags &= ~torrent_flags::duplicate_is_error;
ses.async_add_torrent(atp);
a = alert_cast<add_torrent_alert>(wait_for_alert(ses, add_torrent_alert::alert_type, "ses"));
TEST_CHECK(a);
@ -160,12 +160,12 @@ TORRENT_TEST(async_add_torrent_duplicate_back_to_back)
add_torrent_params atp;
atp.info_hash.assign("abababababababababab");
atp.save_path = ".";
atp.flags |= add_torrent_params::flag_paused;
atp.flags &= ~add_torrent_params::flag_apply_ip_filter;
atp.flags &= ~add_torrent_params::flag_auto_managed;
atp.flags |= torrent_flags::paused;
atp.flags &= ~torrent_flags::apply_ip_filter;
atp.flags &= ~torrent_flags::auto_managed;
ses.async_add_torrent(atp);
atp.flags &= ~add_torrent_params::flag_duplicate_is_error;
atp.flags &= ~torrent_flags::duplicate_is_error;
ses.async_add_torrent(atp);
auto* a = alert_cast<add_torrent_alert>(wait_for_alert(ses
@ -183,9 +183,9 @@ TORRENT_TEST(async_add_torrent_duplicate_back_to_back)
TEST_CHECK(!a->error);
torrent_status st = h.status();
TEST_CHECK(st.flags & add_torrent_params::flag_paused);
TEST_CHECK(!(st.flags & add_torrent_params::flag_apply_ip_filter));
TEST_CHECK(!(st.flags & add_torrent_params::flag_auto_managed));
TEST_CHECK(st.flags & torrent_flags::paused);
TEST_CHECK(!(st.flags & torrent_flags::apply_ip_filter));
TEST_CHECK(!(st.flags & torrent_flags::auto_managed));
}
TORRENT_TEST(load_empty_file)
@ -228,7 +228,7 @@ TORRENT_TEST(paused_session)
lt::add_torrent_params ps;
std::ofstream file("temporary");
ps.ti = ::create_torrent(&file, "temporary", 16 * 1024, 13, false);
ps.flags = lt::add_torrent_params::flag_paused;
ps.flags = lt::torrent_flags::paused;
ps.save_path = ".";
torrent_handle h = s.add_torrent(std::move(ps));
@ -237,7 +237,7 @@ TORRENT_TEST(paused_session)
h.resume();
std::this_thread::sleep_for(lt::milliseconds(1000));
TEST_EQUAL(h.flags() & add_torrent_params::flag_paused, 0);
TEST_CHECK(!(h.flags() & torrent_flags::paused));
}
TORRENT_TEST(get_cache_info)

View File

@ -188,8 +188,8 @@ void test_ssl(int test_idx, bool use_utp)
add_torrent_params addp;
addp.save_path = "tmp1_ssl";
addp.flags &= ~add_torrent_params::flag_paused;
addp.flags &= ~add_torrent_params::flag_auto_managed;
addp.flags &= ~torrent_flags::paused;
addp.flags &= ~torrent_flags::auto_managed;
peer_disconnects = 0;
ssl_peer_disconnects = 0;
@ -573,8 +573,8 @@ void test_malicious_peer()
add_torrent_params addp;
addp.save_path = "tmp3_ssl";
addp.flags &= ~add_torrent_params::flag_paused;
addp.flags &= ~add_torrent_params::flag_auto_managed;
addp.flags &= ~torrent_flags::paused;
addp.flags &= ~torrent_flags::auto_managed;
addp.ti = t;
torrent_handle tor1 = ses1.add_torrent(addp, ec);

View File

@ -726,8 +726,8 @@ void test_fastresume(bool const test_deprecated)
TEST_CHECK(!ec);
}
p.flags &= ~add_torrent_params::flag_paused;
p.flags &= ~add_torrent_params::flag_auto_managed;
p.flags &= ~torrent_flags::paused;
p.flags &= ~torrent_flags::auto_managed;
p.ti = std::make_shared<torrent_info>(std::cref(*t));
p.save_path = combine_path(test_path, "tmp1");
p.storage_mode = storage_mode_sparse;

View File

@ -35,7 +35,7 @@ POSSIBILITY OF SUCH DAMAGE.
TORRENT_TEST(time_crititcal)
{
// with time critical pieces
test_swarm(time_critical);
test_swarm(test_flags::time_critical);
}

View File

@ -61,8 +61,8 @@ void test_running_torrent(std::shared_ptr<torrent_info> info, std::int64_t file_
aux::vector<std::uint8_t, file_index_t> zeroes;
zeroes.resize(1000, 0);
add_torrent_params p;
p.flags &= ~add_torrent_params::flag_paused;
p.flags &= ~add_torrent_params::flag_auto_managed;
p.flags &= ~torrent_flags::paused;
p.flags &= ~torrent_flags::auto_managed;
p.ti = info;
p.save_path = ".";
@ -357,9 +357,9 @@ TORRENT_TEST(duplicate_is_not_error)
add_torrent_params p;
p.ti = std::make_shared<torrent_info>(&tmp[0], int(tmp.size()), std::ref(ec), 0);
p.flags &= ~add_torrent_params::flag_paused;
p.flags &= ~add_torrent_params::flag_auto_managed;
p.flags &= ~add_torrent_params::flag_duplicate_is_error;
p.flags &= ~torrent_flags::paused;
p.flags &= ~torrent_flags::auto_managed;
p.flags &= ~torrent_flags::duplicate_is_error;
p.save_path = ".";
p.extensions.push_back(creator);
@ -427,8 +427,8 @@ TORRENT_TEST(async_load_deprecated)
lt::session ses(pack);
add_torrent_params p;
p.flags &= ~add_torrent_params::flag_paused;
p.flags &= ~add_torrent_params::flag_auto_managed;
p.flags &= ~torrent_flags::paused;
p.flags &= ~torrent_flags::auto_managed;
std::string dir = parent_path(current_working_directory());
p.url = "file://" + combine_path(combine_path(dir, "test_torrents"), "base.torrent");
@ -569,8 +569,8 @@ TORRENT_TEST(queue)
TORRENT_TEST(queue_paused)
{
add_torrent_params p;
p.flags |= add_torrent_params::flag_paused;
p.flags &= ~add_torrent_params::flag_auto_managed;
p.flags |= torrent_flags::paused;
p.flags &= ~torrent_flags::auto_managed;
test_queue(p);
}

View File

@ -354,9 +354,9 @@ void test_udp_tracker(std::string const& iface, address tracker, tcp::endpoint c
t->add_tracker(tracker_url, 0);
add_torrent_params addp;
addp.flags &= ~add_torrent_params::flag_paused;
addp.flags &= ~add_torrent_params::flag_auto_managed;
addp.flags |= add_torrent_params::flag_seed_mode;
addp.flags &= ~torrent_flags::paused;
addp.flags &= ~torrent_flags::auto_managed;
addp.flags |= torrent_flags::seed_mode;
addp.ti = t;
addp.save_path = "tmp1_tracker";
torrent_handle h = s->add_torrent(addp);
@ -448,9 +448,9 @@ TORRENT_TEST(http_peers)
t->add_tracker(tracker_url, 0);
add_torrent_params addp;
addp.flags &= ~add_torrent_params::flag_paused;
addp.flags &= ~add_torrent_params::flag_auto_managed;
addp.flags |= add_torrent_params::flag_seed_mode;
addp.flags &= ~torrent_flags::paused;
addp.flags &= ~torrent_flags::auto_managed;
addp.flags |= torrent_flags::seed_mode;
addp.ti = t;
addp.save_path = "tmp2_tracker";
torrent_handle h = s->add_torrent(addp);
@ -524,9 +524,9 @@ TORRENT_TEST(current_tracker)
t->add_tracker(tracker_url, 0);
add_torrent_params addp;
addp.flags &= ~add_torrent_params::flag_paused;
addp.flags &= ~add_torrent_params::flag_auto_managed;
addp.flags |= add_torrent_params::flag_seed_mode;
addp.flags &= ~torrent_flags::paused;
addp.flags &= ~torrent_flags::auto_managed;
addp.flags |= torrent_flags::seed_mode;
addp.ti = t;
addp.save_path = "tmp3_tracker";
torrent_handle h = s->add_torrent(addp);
@ -584,9 +584,9 @@ void test_proxy(bool proxy_trackers)
t->add_tracker(tracker_url, 0);
add_torrent_params addp;
addp.flags &= ~add_torrent_params::flag_paused;
addp.flags &= ~add_torrent_params::flag_auto_managed;
addp.flags |= add_torrent_params::flag_seed_mode;
addp.flags &= ~torrent_flags::paused;
addp.flags &= ~torrent_flags::auto_managed;
addp.flags |= torrent_flags::seed_mode;
addp.ti = t;
addp.save_path = "tmp2_tracker";
torrent_handle h = s->add_torrent(addp);
@ -674,9 +674,9 @@ void test_stop_tracker_timeout(bool nostop)
file.close();
add_torrent_params tp;
tp.flags &= ~add_torrent_params::flag_paused;
tp.flags &= ~add_torrent_params::flag_auto_managed;
tp.flags |= add_torrent_params::flag_seed_mode;
tp.flags &= ~torrent_flags::paused;
tp.flags &= ~torrent_flags::auto_managed;
tp.flags |= torrent_flags::seed_mode;
tp.ti = t;
tp.save_path = "tmp4_tracker";
torrent_handle h = s.add_torrent(tp);

View File

@ -230,13 +230,13 @@ void test_transfer(int proxy_type, settings_pack const& sett
TEST_CHECK(exists(combine_path("tmp1_transfer", "temporary")));
add_torrent_params addp(&test_storage_constructor);
addp.flags &= ~add_torrent_params::flag_paused;
addp.flags &= ~add_torrent_params::flag_auto_managed;
addp.flags &= ~torrent_flags::paused;
addp.flags &= ~torrent_flags::auto_managed;
add_torrent_params params;
params.storage_mode = storage_mode;
params.flags &= ~add_torrent_params::flag_paused;
params.flags &= ~add_torrent_params::flag_auto_managed;
params.flags &= ~torrent_flags::paused;
params.flags &= ~torrent_flags::auto_managed;
wait_for_listen(ses1, "ses1");
wait_for_listen(ses2, "ses2");
@ -284,9 +284,9 @@ void test_transfer(int proxy_type, settings_pack const& sett
// back into upload mode) before we restart it.
// TODO: factor out the disk-full test into its own unit test
if (test_disk_full &&
((tor2.flags() & add_torrent_params::flag_upload_mode) != 0) &&
++upload_mode_timer > 10)
if (test_disk_full
&& !(tor2.flags() & torrent_flags::upload_mode)
&& ++upload_mode_timer > 10)
{
test_disk_full = false;
((test_storage*)tor2.get_storage_impl())->set_limit(16 * 1024 * 1024);
@ -305,7 +305,7 @@ void test_transfer(int proxy_type, settings_pack const& sett
lt::error_code err = tor2.status().errc;
std::printf("error: \"%s\"\n", err.message().c_str());
TEST_CHECK(!err);
tor2.unset_flags(add_torrent_params::flag_upload_mode);
tor2.unset_flags(torrent_flags::upload_mode);
// at this point we probably disconnected the seed
// so we need to reconnect as well

View File

@ -95,8 +95,8 @@ void test_transfer()
// for performance testing
add_torrent_params atp;
atp.flags &= ~add_torrent_params::flag_paused;
atp.flags &= ~add_torrent_params::flag_auto_managed;
atp.flags &= ~torrent_flags::paused;
atp.flags &= ~torrent_flags::auto_managed;
// atp.storage = &disabled_storage_constructor;
// test using piece sizes smaller than 16kB

View File

@ -128,13 +128,13 @@ void test_transfer(lt::session& ses, std::shared_ptr<torrent_info> torrent_file
}
add_torrent_params p;
p.flags &= ~add_torrent_params::flag_paused;
p.flags &= ~add_torrent_params::flag_auto_managed;
p.flags &= ~torrent_flags::paused;
p.flags &= ~torrent_flags::auto_managed;
// the reason to set sequential download is to make sure that the order in
// which files are requested from the web server is consistent. Any specific
// scenario that needs testing should be an explicit test case
p.flags |= add_torrent_params::flag_sequential_download;
p.flags |= torrent_flags::sequential_download;
p.ti = torrent_file;
p.save_path = save_path;
torrent_handle th = ses.add_torrent(p, ec);