make save_state_flags a strong type

This commit is contained in:
arvidn 2017-07-27 13:26:12 -07:00 committed by Arvid Norberg
parent 69bd2986de
commit 322007bb6a
28 changed files with 226 additions and 148 deletions

View File

@ -15,6 +15,7 @@
#include "libtorrent/aux_/noexcept_movable.hpp"
#include "libtorrent/peer_info.hpp"
#include "libtorrent/alert_types.hpp" // for picker_flags_t
#include "libtorrent/session_types.hpp" // for save_state_flags_t
#include "libtorrent/alert.hpp"
#include <vector>
@ -304,6 +305,9 @@ void bind_converters()
to_python_converter<lt::add_piece_flags_t, from_bitfield_flag<lt::add_piece_flags_t>>();
to_python_converter<lt::pause_flags_t, from_bitfield_flag<lt::pause_flags_t>>();
to_python_converter<lt::deadline_flags_t, from_bitfield_flag<lt::deadline_flags_t>>();
to_python_converter<lt::save_state_flags_t, from_bitfield_flag<lt::save_state_flags_t>>();
to_python_converter<lt::session_flags_t, from_bitfield_flag<lt::session_flags_t>>();
to_python_converter<lt::remove_flags_t, from_bitfield_flag<lt::remove_flags_t>>();
// work-around types
to_python_converter<lt::aux::noexcept_movable<lt::address>, address_to_tuple<
@ -358,4 +362,7 @@ void bind_converters()
to_bitfield_flag<lt::add_piece_flags_t>();
to_bitfield_flag<lt::pause_flags_t>();
to_bitfield_flag<lt::deadline_flags_t>();
to_bitfield_flag<lt::save_state_flags_t>();
to_bitfield_flag<lt::session_flags_t>();
to_bitfield_flag<lt::remove_flags_t>();
}

View File

@ -163,7 +163,7 @@ namespace
return ret;
}
std::shared_ptr<lt::session> make_session(boost::python::dict sett, int flags)
std::shared_ptr<lt::session> make_session(boost::python::dict sett, session_flags_t flags)
{
settings_pack p;
make_settings_pack(p, sett);
@ -471,11 +471,11 @@ namespace
}
#endif
entry save_state(lt::session const& s, std::uint32_t flags)
entry save_state(lt::session const& s, std::uint32_t const flags)
{
allow_threading_guard guard;
entry e;
s.save_state(e, flags);
s.save_state(e, save_state_flags_t(flags));
return e;
}
@ -495,7 +495,7 @@ namespace
return ret;
}
void load_state(lt::session& ses, entry const& st, std::uint32_t flags)
void load_state(lt::session& ses, entry const& st, std::uint32_t const flags)
{
allow_threading_guard guard;
@ -505,7 +505,7 @@ namespace
error_code ec;
bdecode(&buf[0], &buf[0] + buf.size(), e, ec);
TORRENT_ASSERT(!ec);
ses.load_state(e, flags);
ses.load_state(e, save_state_flags_t(flags));
}
#ifndef TORRENT_DISABLE_DHT
@ -564,6 +564,9 @@ struct dummy1 {};
#ifndef TORRENT_NO_DEPRECATE
struct dummy2 {};
#endif
struct dummy9 {};
struct dummy10 {};
struct dummy11 {};
void bind_session()
{
@ -695,21 +698,21 @@ void bind_session()
#endif
;
enum_<storage_mode_t>("storage_mode_t")
.value("storage_mode_allocate", storage_mode_allocate)
.value("storage_mode_sparse", storage_mode_sparse)
;
enum_<lt::session::options_t>("options_t")
.value("delete_files", lt::session::delete_files)
;
enum_<lt::session::session_flags_t>("session_flags_t")
.value("add_default_plugins", lt::session::add_default_plugins)
.value("start_default_features", lt::session::start_default_features)
;
{
scope s = class_<dummy11>("options_t");
s.attr("delete_files") = lt::session::delete_files;
}
{
scope s = class_<dummy10>("session_flags_t");
s.attr("add_default_plugins") = lt::session::add_default_plugins;
s.attr("start_default_features") = lt::session::start_default_features;
}
{
scope s = class_<dummy1>("torrent_flags");
@ -799,10 +802,10 @@ void bind_session()
)
#ifndef TORRENT_NO_DEPRECATE
.def(
init<fingerprint, int, std::uint32_t>((
init<fingerprint, session_flags_t, alert_category_t>((
arg("fingerprint")=fingerprint("LT",0,1,0,0)
, arg("flags")=lt::session::start_default_features | lt::session::add_default_plugins
, arg("alert_mask")=int(alert::error_notification)))
, arg("alert_mask")=alert::error_notification))
)
.def("outgoing_ports", &outgoing_ports)
#endif
@ -933,21 +936,22 @@ void bind_session()
.value("tcp", lt::session::tcp)
;
enum_<lt::session::save_state_flags_t>("save_state_flags_t")
.value("save_settings", lt::session::save_settings)
.value("save_dht_settings", lt::session::save_dht_settings)
.value("save_dht_state", lt::session::save_dht_state)
.value("save_encryption_settings", lt::session:: save_encryption_settings)
{
scope s = class_<dummy9>("save_state_flags_t");
s.attr("save_settings") = lt::session::save_settings;
s.attr("save_dht_settings") = lt::session::save_dht_settings;
s.attr("save_dht_state") = lt::session::save_dht_state;
s.attr("save_encryption_settings") = lt::session:: save_encryption_settings;
#ifndef TORRENT_NO_DEPRECATE
.value("save_as_map", lt::session::save_as_map)
.value("save_i2p_proxy", lt::session::save_i2p_proxy)
.value("save_proxy", lt::session::save_proxy)
.value("save_dht_proxy", lt::session::save_dht_proxy)
.value("save_peer_proxy", lt::session::save_peer_proxy)
.value("save_web_proxy", lt::session::save_web_proxy)
.value("save_tracker_proxy", lt::session::save_tracker_proxy)
s.attr("save_as_map") = lt::session::save_as_map;
s.attr("save_i2p_proxy") = lt::session::save_i2p_proxy;
s.attr("save_proxy") = lt::session::save_proxy;
s.attr("save_dht_proxy") = lt::session::save_dht_proxy;
s.attr("save_peer_proxy") = lt::session::save_peer_proxy;
s.attr("save_web_proxy") = lt::session::save_web_proxy;
s.attr("save_tracker_proxy") = lt::session::save_tracker_proxy;
#endif
;
}
#ifndef TORRENT_NO_DEPRECATE
enum_<lt::session::listen_on_flags_t>("listen_on_flags_t")

View File

@ -208,3 +208,6 @@ Hellman
html
namespace
dn
pe
lt
tex

View File

@ -116,6 +116,7 @@ nobase_include_HEADERS = \
session_settings.hpp \
session_stats.hpp \
session_status.hpp \
session_types.hpp \
settings_pack.hpp \
sha1.hpp \
sha512.hpp \

View File

@ -499,8 +499,8 @@ namespace aux {
void on_async_load_torrent(add_torrent_params* params, error_code ec);
#endif
void remove_torrent(torrent_handle const& h, int options) override;
void remove_torrent_impl(std::shared_ptr<torrent> tptr, int options) override;
void remove_torrent(torrent_handle const& h, remove_flags_t options) override;
void remove_torrent_impl(std::shared_ptr<torrent> tptr, remove_flags_t options) override;
void get_torrent_status(std::vector<torrent_status>* ret
, std::function<bool(torrent_status const&)> const& pred
@ -600,8 +600,8 @@ namespace aux {
void announce_lsd(sha1_hash const& ih, int port, bool broadcast = false) override;
void save_state(entry* e, std::uint32_t flags) const;
void load_state(bdecode_node const* e, std::uint32_t flags);
void save_state(entry* e, save_state_flags_t flags) const;
void load_state(bdecode_node const* e, save_state_flags_t flags);
bool has_connection(peer_connection* p) const override;
void insert_peer(std::shared_ptr<peer_connection> const& c) override;

View File

@ -43,6 +43,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/socket.hpp" // for tcp::endpoint
#include "libtorrent/aux_/vector.hpp"
#include "libtorrent/aux_/listen_socket_handle.hpp"
#include "libtorrent/session_types.hpp"
#include <functional>
#include <memory>
@ -155,8 +156,8 @@ namespace libtorrent { namespace aux {
virtual bool has_connection(peer_connection* p) const = 0;
virtual void insert_peer(std::shared_ptr<peer_connection> const& c) = 0;
virtual void remove_torrent(torrent_handle const& h, int options = 0) = 0;
virtual void remove_torrent_impl(std::shared_ptr<torrent> tptr, int options) = 0;
virtual void remove_torrent(torrent_handle const& h, remove_flags_t options = {}) = 0;
virtual void remove_torrent_impl(std::shared_ptr<torrent> tptr, remove_flags_t options) = 0;
// port filter
virtual port_filter const& get_port_filter() const = 0;

View File

@ -40,6 +40,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/aux_/typed_span.hpp"
#include "libtorrent/units.hpp"
#include "libtorrent/storage_defs.hpp" // for status_t
#include "libtorrent/session_types.hpp"
namespace libtorrent {
@ -85,7 +86,7 @@ namespace aux {
// opt to only delete the partfile
TORRENT_EXTRA_EXPORT void
delete_files(file_storage const& fs, std::string const& save_path
, std::string const& part_file_name, int const options, storage_error& ec);
, std::string const& part_file_name, remove_flags_t const options, storage_error& ec);
TORRENT_EXTRA_EXPORT bool
verify_resume_data(add_torrent_params const& rd

View File

@ -46,6 +46,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/time.hpp"
#include "libtorrent/sha1_hash.hpp"
#include "libtorrent/flags.hpp"
#include "libtorrent/session_types.hpp"
namespace libtorrent {
@ -164,7 +165,7 @@ namespace libtorrent {
virtual void async_rename_file(storage_index_t storage
, file_index_t index, std::string name
, std::function<void(std::string const&, file_index_t, storage_error const&)> handler) = 0;
virtual void async_delete_files(storage_index_t storage, int options
virtual void async_delete_files(storage_index_t storage, remove_flags_t options
, std::function<void(storage_error const&)> handler) = 0;
virtual void async_set_file_priority(storage_index_t storage
, aux::vector<std::uint8_t, file_index_t> prio

View File

@ -41,6 +41,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/disk_interface.hpp"
#include "libtorrent/aux_/vector.hpp"
#include "libtorrent/units.hpp"
#include "libtorrent/session_types.hpp"
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <boost/variant/variant.hpp>
@ -127,7 +128,8 @@ namespace libtorrent {
, std::string
, add_torrent_params const*
, aux::vector<std::uint8_t, file_index_t>
, int> argument;
, remove_flags_t
> argument;
// the disk storage this job applies to (if applicable)
std::shared_ptr<storage_interface> storage;

View File

@ -311,7 +311,7 @@ namespace aux {
, std::function<void(status_t, std::string const&, storage_error const&)> handler) override;
void async_release_files(storage_index_t storage
, std::function<void()> handler = std::function<void()>()) override;
void async_delete_files(storage_index_t storage, int options
void async_delete_files(storage_index_t storage, remove_flags_t options
, std::function<void(storage_error const&)> handler) override;
void async_check_files(storage_index_t storage
, add_torrent_params const* resume_data

View File

@ -163,7 +163,7 @@ namespace aux {
// This function helps to construct a ``session_params`` from a
// bencoded data generated by ``session_handle::save_state``
TORRENT_EXPORT session_params read_session_params(bdecode_node const& e
, std::uint32_t flags = 0xffffffff);
, save_state_flags_t flags = save_state_flags_t{0xffffffff});
// The session holds all state that spans multiple torrents. Among other
// things it runs the network loop and manages all torrents. Once it's
@ -222,7 +222,7 @@ namespace aux {
// default is to start those features. If you do not want them to start,
// pass 0 as the flags parameter.
session(settings_pack pack
, int flags = start_default_features | add_default_plugins)
, session_flags_t const flags = start_default_features | add_default_plugins)
{
TORRENT_CFG();
start(flags, std::move(pack), nullptr);
@ -251,7 +251,7 @@ namespace aux {
// destruct the session_proxy object.
session(settings_pack pack
, io_service& ios
, int flags = start_default_features | add_default_plugins)
, session_flags_t const flags = start_default_features | add_default_plugins)
{
TORRENT_CFG();
start(flags, std::move(pack), &ios);
@ -272,14 +272,14 @@ namespace aux {
#endif
TORRENT_DEPRECATED
session(fingerprint const& print
, int flags = start_default_features | add_default_plugins
, std::uint32_t alert_mask = alert::error_notification)
, session_flags_t const flags = start_default_features | add_default_plugins
, alert_category_t const alert_mask = alert::error_notification)
{
TORRENT_CFG();
settings_pack pack;
pack.set_int(settings_pack::alert_mask, int(alert_mask));
pack.set_str(settings_pack::peer_fingerprint, print.to_string());
if ((flags & start_default_features) == 0)
if (!(flags & start_default_features))
{
pack.set_bool(settings_pack::enable_upnp, false);
pack.set_bool(settings_pack::enable_natpmp, false);
@ -294,8 +294,8 @@ namespace aux {
session(fingerprint const& print
, std::pair<int, int> listen_port_range
, char const* listen_interface = "0.0.0.0"
, int flags = start_default_features | add_default_plugins
, int alert_mask = alert::error_notification)
, session_flags_t const flags = start_default_features | add_default_plugins
, alert_category_t const alert_mask = alert::error_notification)
{
TORRENT_CFG();
TORRENT_ASSERT(listen_port_range.first > 0);
@ -311,7 +311,7 @@ namespace aux {
std::snprintf(if_string, sizeof(if_string), "%s:%d", listen_interface, listen_port_range.first);
pack.set_str(settings_pack::listen_interfaces, if_string);
if ((flags & start_default_features) == 0)
if (!(flags & start_default_features))
{
pack.set_bool(settings_pack::enable_upnp, false);
pack.set_bool(settings_pack::enable_natpmp, false);
@ -362,7 +362,7 @@ namespace aux {
private:
void start(session_params params, io_service* ios);
void start(int flags, settings_pack sp, io_service* ios);
void start(session_flags_t flags, settings_pack sp, io_service* ios);
// data shared between the main thread
// and the working thread

View File

@ -43,6 +43,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/peer_class_type_filter.hpp"
#include "libtorrent/peer_id.hpp"
#include "libtorrent/io_service.hpp"
#include "libtorrent/session_types.hpp"
#include "libtorrent/kademlia/dht_storage.hpp"
@ -81,41 +82,30 @@ namespace libtorrent {
bool is_valid() const { return !m_impl.expired(); }
// TODO: 2 the ip filter should probably be saved here too
// saves settings (i.e. the settings_pack)
static constexpr save_state_flags_t save_settings{0x001};
#include "libtorrent/aux_/disable_warnings_push.hpp"
// saves dht_settings
static constexpr save_state_flags_t save_dht_settings{0x002};
// flags that determines which aspects of the session should be
// saved when calling save_state().
enum save_state_flags_t
{
// saves settings (i.e. the settings_pack)
save_settings = 0x001,
// saves dht state such as nodes and node-id, possibly accelerating
// joining the DHT if provided at next session startup.
static constexpr save_state_flags_t save_dht_state{0x004};
// saves dht_settings
save_dht_settings = 0x002,
// saves dht state such as nodes and node-id, possibly accelerating
// joining the DHT if provided at next session startup.
save_dht_state = 0x004,
// save pe_settings
save_encryption_settings = 0x020
// save pe_settings
static constexpr save_state_flags_t save_encryption_settings{0x020};
#ifndef TORRENT_NO_DEPRECATE
,
save_as_map TORRENT_DEPRECATED_ENUM = 0x040,
save_proxy TORRENT_DEPRECATED_ENUM = 0x008,
save_i2p_proxy TORRENT_DEPRECATED_ENUM = 0x010,
save_dht_proxy TORRENT_DEPRECATED_ENUM = 0x008, // save_proxy
save_peer_proxy TORRENT_DEPRECATED_ENUM = 0x008, // save_proxy
save_web_proxy TORRENT_DEPRECATED_ENUM = 0x008, // save_proxy
save_tracker_proxy TORRENT_DEPRECATED_ENUM = 0x008 // save_proxy
static constexpr save_state_flags_t TORRENT_DEPRECATED_MEMBER save_as_map{0x040};
static constexpr save_state_flags_t TORRENT_DEPRECATED_MEMBER save_proxy{0x008};
static constexpr save_state_flags_t TORRENT_DEPRECATED_MEMBER save_i2p_proxy{0x010};
static constexpr save_state_flags_t TORRENT_DEPRECATED_MEMBER save_dht_proxy{0x008};
static constexpr save_state_flags_t TORRENT_DEPRECATED_MEMBER save_peer_proxy{0x008};
static constexpr save_state_flags_t TORRENT_DEPRECATED_MEMBER save_web_proxy{0x008};
static constexpr save_state_flags_t TORRENT_DEPRECATED_MEMBER save_tracker_proxy{0x008};
#endif
};
#include "libtorrent/aux_/disable_warnings_pop.hpp"
// TODO: 2 the ip filter should probably be saved here too
// loads and saves all session settings, including dht_settings,
// encryption settings and proxy settings. ``save_state`` writes all keys
// to the ``entry`` that's passed in, which needs to either not be
@ -126,14 +116,14 @@ namespace libtorrent {
//
// The ``flags`` argument is used to filter which parts of the session
// state to save or load. By default, all state is saved/restored (except
// for the individual torrents). see save_state_flags_t
// for the individual torrents).
//
// When saving settings, there are two fields that are *not* loaded.
// ``peer_fingerprint`` and ``user_agent``. Those are left as configured
// by the ``session_settings`` passed to the session constructor or
// subsequently set via apply_settings().
void save_state(entry& e, std::uint32_t flags = 0xffffffff) const;
void load_state(bdecode_node const& e, std::uint32_t flags = 0xffffffff);
void save_state(entry& e, save_state_flags_t flags = save_state_flags_t{0xffffffff}) const;
void load_state(bdecode_node const& e, save_state_flags_t flags = save_state_flags_t{0xffffffff});
// .. note::
// these calls are potentially expensive and won't scale well with
@ -551,13 +541,13 @@ namespace libtorrent {
// use load_state and save_state instead
TORRENT_DEPRECATED
void load_state(entry const& ses_state
, std::uint32_t flags = 0xffffffff);
, save_state_flags_t flags = save_state_flags_t(0xffffffff));
TORRENT_DEPRECATED
entry state() const;
// deprecated in 1.1
TORRENT_DEPRECATED
void load_state(lazy_entry const& ses_state
, std::uint32_t flags = 0xffffffff);
, save_state_flags_t flags = save_state_flags_t{0xffffffff});
#endif // TORRENT_NO_DEPRECATE
// Sets a filter that will be used to reject and accept incoming as well
@ -741,28 +731,20 @@ namespace libtorrent {
, int flags = 0);
#endif
// flags to be passed in to remove_torrent().
enum options_t
{
// delete the files belonging to the torrent from disk.
// including the part-file, if there is one
delete_files = 1,
// delete the files belonging to the torrent from disk.
// including the part-file, if there is one
static constexpr remove_flags_t delete_files{1};
// delete just the part-file associated with this torrent
delete_partfile = 2
};
// delete just the part-file associated with this torrent
static constexpr remove_flags_t delete_partfile{2};
// flags to be passed in to the session constructor
enum session_flags_t
{
// this will add common extensions like ut_pex, ut_metadata, lt_tex
// smart_ban and possibly others.
add_default_plugins = 1,
// this will add common extensions like ut_pex, ut_metadata, lt_tex
// smart_ban and possibly others.
static constexpr session_flags_t add_default_plugins{1};
// this will start features like DHT, local service discovery, UPnP
// and NAT-PMP.
start_default_features = 2
};
// this will start features like DHT, local service discovery, UPnP
// and NAT-PMP.
static constexpr session_flags_t start_default_features{2};
// ``remove_torrent()`` will close all peer connections associated with
// the torrent and tell the tracker that we've stopped participating in
@ -782,7 +764,7 @@ namespace libtorrent {
// large state_update to be posted. When removing all torrents, it is
// advised to remove them from the back of the queue, to minimize the
// shifting.
void remove_torrent(const torrent_handle& h, int options = 0);
void remove_torrent(const torrent_handle& h, remove_flags_t options = {});
#ifndef TORRENT_NO_DEPRECATE
// deprecated in libtorrent 1.1. use settings_pack instead

View File

@ -0,0 +1,55 @@
/*
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_SESSION_TYPES_HPP_INCLUDED
#define TORRENT_SESSION_TYPES_HPP_INCLUDED
#include <cstdint>
#include "libtorrent/flags.hpp"
namespace libtorrent {
// hidden
struct save_state_flags_tag;
using save_state_flags_t = flags::bitfield_flag<std::uint32_t, save_state_flags_tag>;
// hidden
struct session_flags_tag;
using session_flags_t = flags::bitfield_flag<std::uint8_t, session_flags_tag>;
// hidden
struct remove_flags_tag;
using remove_flags_t = flags::bitfield_flag<std::uint8_t, remove_flags_tag>;
}
#endif

View File

@ -295,7 +295,7 @@ namespace libtorrent {
//
// void release_memory();
// };
virtual void delete_files(int options, storage_error& ec) = 0;
virtual void delete_files(remove_flags_t options, storage_error& ec) = 0;
// called periodically (useful for deferred flushing). When returning
// false, it means no more ticks are necessary. Any disk job submitted
@ -387,7 +387,7 @@ namespace libtorrent {
virtual void rename_file(file_index_t index, std::string const& new_filename
, storage_error& ec) override;
virtual void release_files(storage_error& ec) override;
virtual void delete_files(int options, storage_error& ec) override;
virtual void delete_files(remove_flags_t options, storage_error& ec) override;
virtual void initialize(storage_error& ec) override;
virtual status_t move_storage(std::string const& save_path
, move_flags_t flags, storage_error& ec) override;

View File

@ -542,7 +542,7 @@ namespace libtorrent {
bool should_check_files() const;
bool delete_files(int options);
bool delete_files(remove_flags_t options);
void peers_erased(std::vector<torrent_peer*> const& peers);
#ifndef TORRENT_NO_DEPRECATE

View File

@ -101,7 +101,7 @@ namespace libtorrent {
}
disk_io_job::disk_io_job()
: argument(0)
: argument(remove_flags_t{0})
, piece(0)
{
d.io.offset = 0;

View File

@ -1826,7 +1826,7 @@ namespace libtorrent {
}
void disk_io_thread::async_delete_files(storage_index_t const storage
, int const options
, remove_flags_t const options
, std::function<void(storage_error const&)> handler)
{
// remove cache blocks belonging to this torrent
@ -2465,7 +2465,7 @@ namespace libtorrent {
status_t disk_io_thread::do_delete_files(disk_io_job* j, jobqueue_t& completed_jobs)
{
TORRENT_ASSERT(boost::get<int>(j->argument) != 0);
TORRENT_ASSERT(boost::get<remove_flags_t>(j->argument));
// if this assert fails, something's wrong with the fence logic
TORRENT_ASSERT(j->storage->num_outstanding_jobs() == 1);
@ -2477,7 +2477,7 @@ namespace libtorrent {
, completed_jobs, l);
l.unlock();
j->storage->delete_files(boost::get<int>(j->argument), j->error);
j->storage->delete_files(boost::get<remove_flags_t>(j->argument), j->error);
return j->error ? status_t::fatal_disk_error : status_t::no_error;
}

View File

@ -255,7 +255,7 @@ namespace libtorrent {
// configurations this will give a link error
void TORRENT_CFG() {}
session_params read_session_params(bdecode_node const& e, std::uint32_t const flags)
session_params read_session_params(bdecode_node const& e, save_state_flags_t const flags)
{
session_params params;
@ -351,10 +351,10 @@ namespace {
}
}
void session::start(int flags, settings_pack sp, io_service* ios)
void session::start(session_flags_t const flags, settings_pack sp, io_service* ios)
{
start({std::move(sp),
default_plugins((flags & add_default_plugins) == 0)}, ios);
default_plugins(!(flags & add_default_plugins))}, ios);
}
session::~session()

View File

@ -47,9 +47,29 @@ using libtorrent::aux::session_impl;
namespace libtorrent {
peer_class_t constexpr session_handle::global_peer_class_id;
peer_class_t constexpr session_handle::tcp_peer_class_id;
peer_class_t constexpr session_handle::local_peer_class_id;
constexpr peer_class_t session_handle::global_peer_class_id;
constexpr peer_class_t session_handle::tcp_peer_class_id;
constexpr peer_class_t session_handle::local_peer_class_id;
constexpr save_state_flags_t session_handle::save_settings;
constexpr save_state_flags_t session_handle::save_dht_settings;
constexpr save_state_flags_t session_handle::save_dht_state;
constexpr save_state_flags_t session_handle::save_encryption_settings;
#ifndef TORRENT_NO_DEPRECATE
constexpr save_state_flags_t session_handle::save_as_map TORRENT_DEPRECATED_ENUM;
constexpr save_state_flags_t session_handle::save_proxy TORRENT_DEPRECATED_ENUM;
constexpr save_state_flags_t session_handle::save_i2p_proxy TORRENT_DEPRECATED_ENUM;
constexpr save_state_flags_t session_handle::save_dht_proxy TORRENT_DEPRECATED_ENUM;
constexpr save_state_flags_t session_handle::save_peer_proxy TORRENT_DEPRECATED_ENUM;
constexpr save_state_flags_t session_handle::save_web_proxy TORRENT_DEPRECATED_ENUM;
constexpr save_state_flags_t session_handle::save_tracker_proxy TORRENT_DEPRECATED_ENUM;
#endif
constexpr session_flags_t session_handle::add_default_plugins;
constexpr session_flags_t session_handle::start_default_features;
constexpr remove_flags_t session_handle::delete_files;
constexpr remove_flags_t session_handle::delete_partfile;
template <typename Fun, typename... Args>
void session_handle::async_call(Fun f, Args&&... a) const
@ -139,14 +159,14 @@ namespace libtorrent {
return r;
}
void session_handle::save_state(entry& e, std::uint32_t const flags) const
void session_handle::save_state(entry& e, save_state_flags_t const flags) const
{
entry* ep = &e;
sync_call(&session_impl::save_state, ep, flags);
}
void session_handle::load_state(bdecode_node const& e
, std::uint32_t const flags)
, save_state_flags_t const flags)
{
// this needs to be synchronized since the lifespan
// of e is tied to the caller
@ -701,7 +721,7 @@ namespace {
void session_handle::load_country_db(wchar_t const*) {}
void session_handle::load_state(entry const& ses_state
, std::uint32_t const flags)
, save_state_flags_t const flags)
{
if (ses_state.type() == entry::undefined_t) return;
std::vector<char> buf;
@ -724,12 +744,12 @@ namespace {
{
entry ret;
auto retp = &ret;
sync_call(&session_impl::save_state, retp, 0xffffffff);
sync_call(&session_impl::save_state, retp, save_state_flags_t{0xffffffff});
return ret;
}
void session_handle::load_state(lazy_entry const& ses_state
, std::uint32_t const flags)
, save_state_flags_t const flags)
{
if (ses_state.type() == lazy_entry::none_t) return;
std::pair<char const*, int> buf = ses_state.data_section();
@ -858,7 +878,7 @@ namespace {
}
#endif
void session_handle::remove_torrent(const torrent_handle& h, int options)
void session_handle::remove_torrent(const torrent_handle& h, remove_flags_t const options)
{
if (!h.is_valid())
#ifdef BOOST_NO_EXCEPTIONS

View File

@ -715,7 +715,7 @@ namespace aux {
#endif
}
void session_impl::save_state(entry* eptr, std::uint32_t const flags) const
void session_impl::save_state(entry* eptr, save_state_flags_t const flags) const
{
TORRENT_ASSERT(is_single_thread());
@ -755,7 +755,7 @@ namespace aux {
}
void session_impl::load_state(bdecode_node const* e
, std::uint32_t const flags)
, save_state_flags_t const flags)
{
TORRENT_ASSERT(is_single_thread());
@ -5111,7 +5111,8 @@ namespace {
return false;
}
void session_impl::remove_torrent(const torrent_handle& h, int options)
void session_impl::remove_torrent(const torrent_handle& h
, remove_flags_t const options)
{
INVARIANT_CHECK;
@ -5127,7 +5128,7 @@ namespace {
}
void session_impl::remove_torrent_impl(std::shared_ptr<torrent> tptr
, int options)
, remove_flags_t const options)
{
#ifndef TORRENT_NO_DEPRECATE
// deprecated in 1.2

View File

@ -390,7 +390,7 @@ namespace libtorrent {
m_stat_cache.clear();
}
void default_storage::delete_files(int const options, storage_error& ec)
void default_storage::delete_files(remove_flags_t const options, storage_error& ec)
{
#if TORRENT_USE_ASSERTS
// this is a fence job, we expect no other
@ -707,7 +707,7 @@ namespace {
, storage_error&) override {}
void rename_file(file_index_t, std::string const&, storage_error&) override {}
void release_files(storage_error&) override {}
void delete_files(int, storage_error&) override {}
void delete_files(remove_flags_t, storage_error&) override {}
void initialize(storage_error&) override {}
status_t move_storage(std::string const&, move_flags_t, storage_error&) override { return status_t::no_error; }
@ -776,7 +776,7 @@ namespace {
void release_files(storage_error&) override {}
void rename_file(file_index_t
, std::string const& /* new_filename */, storage_error&) override {}
void delete_files(int, storage_error&) override {}
void delete_files(remove_flags_t, storage_error&) override {}
};
}

View File

@ -401,7 +401,7 @@ namespace libtorrent { namespace aux {
}
void delete_files(file_storage const& fs, std::string const& save_path
, std::string const& part_file_name, int const options, storage_error& ec)
, std::string const& part_file_name, remove_flags_t const options, storage_error& ec)
{
if (options == session::delete_files)
{

View File

@ -420,7 +420,7 @@ namespace libtorrent {
// torrent, create another reference
auto me = shared_from_this();
m_ses.remove_torrent_impl(me, 0);
m_ses.remove_torrent_impl(me, {});
if (alerts().should_post<torrent_update_alert>())
alerts().emplace_alert<torrent_update_alert>(get_handle(), info_hash(), tf->info_hash());
@ -8096,7 +8096,7 @@ namespace libtorrent {
return limit_impl(peer_connection::download_channel);
}
bool torrent::delete_files(int const options)
bool torrent::delete_files(remove_flags_t const options)
{
TORRENT_ASSERT(is_single_thread());

View File

@ -72,7 +72,7 @@ struct test_storage_impl : storage_interface
void release_files(storage_error& ec) override {}
void rename_file(file_index_t index, std::string const& new_filename
, storage_error& ec) override {}
void delete_files(int, storage_error& ec) override {}
void delete_files(remove_flags_t, storage_error& ec) override {}
};
struct allocator : buffer_allocator_interface
@ -196,7 +196,7 @@ void test_write()
TEST_CHECK(ret >= 0);
// return the reference to the buffer we just read
rj.argument = 0;
rj.argument = remove_flags_t{};
TEST_EQUAL(bc.pinned_blocks(), 0);
bc.update_stats_counters(c);
@ -211,7 +211,7 @@ void test_write()
bc.update_stats_counters(c);
TEST_EQUAL(c[counters::pinned_blocks], 0);
rj.argument = 0;
rj.argument = remove_flags_t{};
tailqueue<disk_io_job> jobs;
bc.clear(jobs);
@ -334,7 +334,7 @@ void test_arc_promote()
// it's supposed to be a cache hit
TEST_CHECK(ret >= 0);
// return the reference to the buffer we just read
rj.argument = 0;
rj.argument = remove_flags_t{};
bc.update_stats_counters(c);
TEST_EQUAL(c[counters::write_cache_blocks], 0);
@ -355,7 +355,7 @@ void test_arc_promote()
// it's supposed to be a cache hit
TEST_CHECK(ret >= 0);
// return the reference to the buffer we just read
rj.argument = 0;
rj.argument = remove_flags_t{};
bc.update_stats_counters(c);
TEST_EQUAL(c[counters::write_cache_blocks], 0);
@ -457,7 +457,7 @@ void test_unaligned_read()
// it's supposed to be a cache hit
TEST_CHECK(ret >= 0);
// return the reference to the buffer we just read
rj.argument = 0;
rj.argument = remove_flags_t{};
tailqueue<disk_io_job> jobs;
bc.clear(jobs);
@ -497,7 +497,7 @@ TORRENT_TEST(delete_piece)
rj.d.io.buffer_size = 0x4000;
rj.piece = piece_index_t(0);
rj.storage = pm;
rj.argument = 0;
rj.argument = remove_flags_t{};
ret = bc.try_read(&rj, alloc);
cached_piece_entry* pe_ = bc.find_piece(pm.get(), piece_index_t(0));

View File

@ -98,9 +98,9 @@ TORRENT_TEST(direct_dht_request)
sp.set_str(settings_pack::dht_bootstrap_nodes, "");
sp.set_int(settings_pack::max_retry_port_bind, 800);
sp.set_str(settings_pack::listen_interfaces, "127.0.0.1:42434");
lt::session responder(sp, 0);
lt::session responder(sp, {});
sp.set_str(settings_pack::listen_interfaces, "127.0.0.1:45434");
lt::session requester(sp, 0);
lt::session requester(sp, {});
responder.add_extension(std::make_shared<test_plugin>());

View File

@ -55,7 +55,7 @@ enum test_case {
mid_download
};
void test_remove_torrent(int const remove_options
void test_remove_torrent(remove_flags_t const remove_options
, test_case const test = complete_download)
{
// this allows shutting down the sessions in parallel
@ -168,7 +168,7 @@ void test_remove_torrent(int const remove_options
TORRENT_TEST(remove_torrent)
{
test_remove_torrent(0);
test_remove_torrent({});
}
TORRENT_TEST(remove_torrent_and_files)
@ -178,7 +178,7 @@ TORRENT_TEST(remove_torrent_and_files)
TORRENT_TEST(remove_torrent_partial)
{
test_remove_torrent(0, partial_download);
test_remove_torrent({}, partial_download);
}
TORRENT_TEST(remove_torrent_and_files_partial)
@ -188,7 +188,7 @@ TORRENT_TEST(remove_torrent_and_files_partial)
TORRENT_TEST(remove_torrent_mid_download)
{
test_remove_torrent(0, mid_download);
test_remove_torrent({}, mid_download);
}
TORRENT_TEST(remove_torrent_and_files_mid_download)

View File

@ -159,7 +159,7 @@ void test_ssl(int test_idx, bool use_utp)
// if a peer fails once, don't try it again
sett.set_int(settings_pack::max_failcount, 1);
lt::session ses1(sett, 0);
lt::session ses1(sett, {});
// this +20 is here to use a different port as ses1
port += 20;
@ -172,7 +172,7 @@ void test_ssl(int test_idx, bool use_utp)
sett.set_str(settings_pack::listen_interfaces, listen_iface);
lt::session ses2(sett, 0);
lt::session ses2(sett, {});
wait_for_listen(ses1, "ses1");
wait_for_listen(ses2, "ses2");
@ -559,7 +559,7 @@ void test_malicious_peer()
sett.set_bool(settings_pack::enable_upnp, false);
sett.set_bool(settings_pack::enable_natpmp, false);
lt::session ses1(sett, 0);
lt::session ses1(sett, {});
wait_for_listen(ses1, "ses1");
// create torrent

View File

@ -407,7 +407,7 @@ int EXPORT run_http_suite(int proxy, char const* protocol, bool test_url_seed
pack.set_bool(settings_pack::enable_natpmp, false);
pack.set_bool(settings_pack::enable_upnp, false);
pack.set_bool(settings_pack::enable_dht, false);
lt::session ses(pack, 0);
lt::session ses(pack, {});
test_transfer(ses, torrent_file, proxy, protocol, test_url_seed
, chunked_encoding, test_ban, keepalive, proxy_peers);