mirror of
https://github.com/arvidn/libtorrent.git
synced 2026-05-07 16:30:54 -04:00
move session flags into the session_params object
This commit is contained in:
committed by
Arvid Norberg
parent
735c486c65
commit
d5b27eeacb
@@ -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
|
||||
|
||||
@@ -178,9 +178,10 @@ namespace
|
||||
std::shared_ptr<lt::session> make_session(boost::python::dict sett
|
||||
, session_flags_t const flags)
|
||||
{
|
||||
settings_pack p;
|
||||
make_settings_pack(p, sett);
|
||||
return std::make_shared<lt::session>(p, flags);
|
||||
session_params p;
|
||||
make_settings_pack(p.settings, sett);
|
||||
p.flags = flags;
|
||||
return std::make_shared<lt::session>(std::move(p));
|
||||
}
|
||||
|
||||
void session_apply_settings(lt::session& ses, dict const& sett_dict)
|
||||
|
||||
@@ -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&&);
|
||||
|
||||
@@ -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<std::shared_ptr<plugin>> 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
|
||||
|
||||
@@ -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<lt::session>(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();
|
||||
}
|
||||
|
||||
+10
-6
@@ -259,6 +259,7 @@ namespace {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// TODO: start() should just use flags out of the session_params object,
|
||||
m_impl = std::make_shared<aux::session_impl>(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)
|
||||
|
||||
Reference in New Issue
Block a user