From d5b27eeacb573d5b6c7b30357c8d27ef1231b7eb Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Mon, 14 Dec 2020 17:23:16 +0100 Subject: [PATCH] move session flags into the session_params object --- ChangeLog | 1 + bindings/python/src/session.cpp | 7 +++--- include/libtorrent/session.hpp | 17 ++++++------- include/libtorrent/session_params.hpp | 27 ++++++++++++--------- simulation/test_session.cpp | 35 ++++++++++++++++++++++++++- src/session.cpp | 16 +++++++----- 6 files changed, 73 insertions(+), 30 deletions(-) diff --git a/ChangeLog b/ChangeLog index 214495057a8..21b15a4bbb9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + * move session_flags to session_params * the entry class is now a standard variant type * use std::string_view instead of boost counterpart * libtorrent now requires C++17 to build diff --git a/bindings/python/src/session.cpp b/bindings/python/src/session.cpp index 92f11e332f4..d1f869bdbc0 100644 --- a/bindings/python/src/session.cpp +++ b/bindings/python/src/session.cpp @@ -178,9 +178,10 @@ namespace std::shared_ptr make_session(boost::python::dict sett , session_flags_t const flags) { - settings_pack p; - make_settings_pack(p, sett); - return std::make_shared(p, flags); + session_params p; + make_settings_pack(p.settings, sett); + p.flags = flags; + return std::make_shared(std::move(p)); } void session_apply_settings(lt::session& ses, dict const& sett_dict) diff --git a/include/libtorrent/session.hpp b/include/libtorrent/session.hpp index 0fcc029f2b9..6cda79a6de8 100644 --- a/include/libtorrent/session.hpp +++ b/include/libtorrent/session.hpp @@ -129,15 +129,12 @@ namespace aux { // In order to avoid a race condition between starting the session and // configuring it, you can pass in a session_params object. Its settings // will take effect before the session starts up. - // - // The overloads taking ``flags`` can be used to start a session in - // paused mode (by passing in ``session::paused``). Note that - // ``add_default_plugins`` do not have an affect on constructors that - // take a session_params object. It already contains the plugins to use. explicit session(session_params const& params); explicit session(session_params&& params); - session(session_params const& params, session_flags_t flags); - session(session_params&& params, session_flags_t flags); +#if TORRENT_ABI_VERSION < 4 + TORRENT_DEPRECATED session(session_params const& params, session_flags_t flags); + TORRENT_DEPRECATED session(session_params&& params, session_flags_t flags); +#endif session(); // Overload of the constructor that takes an external io_context to run @@ -155,8 +152,10 @@ namespace aux { // destruct the session_proxy object. session(session_params&& params, io_context& ios); session(session_params const& params, io_context& ios); - session(session_params&& params, io_context& ios, session_flags_t); - session(session_params const& params, io_context& ios, session_flags_t); +#if TORRENT_ABI_VERSION < 4 + TORRENT_DEPRECATED session(session_params&& params, io_context& ios, session_flags_t); + TORRENT_DEPRECATED session(session_params const& params, io_context& ios, session_flags_t); +#endif // hidden session(session&&); diff --git a/include/libtorrent/session_params.hpp b/include/libtorrent/session_params.hpp index 9da88762e94..2d4544c72a0 100644 --- a/include/libtorrent/session_params.hpp +++ b/include/libtorrent/session_params.hpp @@ -24,6 +24,7 @@ see LICENSE file. #include "libtorrent/session_types.hpp" #include "libtorrent/kademlia/dht_storage.hpp" #include "libtorrent/ip_filter.hpp" +#include "libtorrent/session_types.hpp" // for session_flags_t #if TORRENT_ABI_VERSION <= 2 #include "libtorrent/kademlia/dht_settings.hpp" @@ -73,20 +74,13 @@ struct TORRENT_EXPORT session_params // The settings to configure the session with settings_pack settings; + // specifies flags affecting the session construction. E.g. they can be used + // to start a session in paused mode (by passing in ``session::paused``). + session_flags_t flags{}; + // the plugins to add to the session as it is constructed std::vector> extensions; -#if TORRENT_ABI_VERSION <= 2 - -#include "libtorrent/aux_/disable_deprecation_warnings_push.hpp" - - // this is deprecated. Use the dht_* settings instead. - dht::dht_settings dht_settings; - -#include "libtorrent/aux_/disable_warnings_pop.hpp" - -#endif - // DHT node ID and node addresses to bootstrap the DHT with. dht::dht_state dht_state; @@ -105,6 +99,17 @@ struct TORRENT_EXPORT session_params // the IP filter to use for the session. This restricts which peers are allowed // to connect. As if passed to set_ip_filter(). libtorrent::ip_filter ip_filter; + +#if TORRENT_ABI_VERSION <= 2 + +#include "libtorrent/aux_/disable_deprecation_warnings_push.hpp" + + // this is deprecated. Use the dht_* settings instead. + dht::dht_settings dht_settings; + +#include "libtorrent/aux_/disable_warnings_pop.hpp" + +#endif }; TORRENT_VERSION_NAMESPACE_3_END diff --git a/simulation/test_session.cpp b/simulation/test_session.cpp index 4ddcb652f82..16f3f9b32f5 100644 --- a/simulation/test_session.cpp +++ b/simulation/test_session.cpp @@ -224,7 +224,8 @@ TORRENT_TEST(tie_listen_ports) // make sure passing in the session::paused flag does indeed start the session // paused -TORRENT_TEST(construct_paused_session) +#if TORRENT_ABI_VERSION < 4 +TORRENT_TEST(construct_paused_session_deprecated) { using namespace libtorrent; @@ -252,3 +253,35 @@ TORRENT_TEST(construct_paused_session) sim.run(); } +#endif + +TORRENT_TEST(construct_paused_session) +{ + using namespace libtorrent; + + sim::default_config network_cfg; + sim::simulation sim{network_cfg}; + sim::asio::io_context ios { sim, addr("50.0.0.1")}; + + lt::session_proxy zombie; + + // create session + lt::session_params p; + p.settings = settings(); + p.settings.set_str(settings_pack::listen_interfaces, "0.0.0.0:0"); + p.settings.set_int(settings_pack::alert_mask, alert_category::error + | alert_category::status + | alert_category::torrent_log); + p.flags |= session::paused; + + auto ses = std::make_shared(p, ios); + + sim::timer t(sim, lt::seconds(30), [&](boost::system::error_code const&) + { + TEST_CHECK(ses->is_paused()); + zombie = ses->abort(); + ses.reset(); + }); + + sim.run(); +} diff --git a/src/session.cpp b/src/session.cpp index 73b0493ab4b..ae65f0a4c6b 100644 --- a/src/session.cpp +++ b/src/session.cpp @@ -259,6 +259,7 @@ namespace { #endif #endif + // TODO: start() should just use flags out of the session_params object, m_impl = std::make_shared(std::ref(*ios) , std::move(params.settings) , std::move(params.disk_io_constructor) @@ -317,14 +318,15 @@ namespace { session::session(session_params const& params) { - start({}, session_params(params), nullptr); + start(params.flags, session_params(params), nullptr); } session::session(session_params&& params) { - start({}, std::move(params), nullptr); + start(params.flags, std::move(params), nullptr); } +#if TORRENT_ABI_VERSION < 4 session::session(session_params const& params, session_flags_t const flags) { start(flags, session_params(params), nullptr); @@ -334,23 +336,25 @@ namespace { { start(flags, std::move(params), nullptr); } +#endif session::session() { session_params params; - start({}, std::move(params), nullptr); + start(params.flags, std::move(params), nullptr); } session::session(session_params&& params, io_context& ios) { - start({}, std::move(params), &ios); + start(params.flags, std::move(params), &ios); } session::session(session_params const& params, io_context& ios) { - start({}, session_params(params), &ios); + start(params.flags, session_params(params), &ios); } +#if TORRENT_ABI_VERSION < 4 session::session(session_params&& params, io_context& ios, session_flags_t const flags) { start(flags, std::move(params), &ios); @@ -360,7 +364,7 @@ namespace { { start(flags, session_params(params), &ios); } - +#endif #if TORRENT_ABI_VERSION <= 2 session::session(settings_pack&& pack, session_flags_t const flags)