forked from premiere/premiere-libtorrent
use a python python dictionary for settings instead of session_settings object (in python bindings)
This commit is contained in:
parent
2ce418f344
commit
fc0bd8066b
|
@ -1,3 +1,4 @@
|
||||||
|
* use a python python dictionary for settings instead of session_settings object (in python bindings)
|
||||||
* optimized metadata transfer (magnet link) startup time (shaved off about 1 second)
|
* optimized metadata transfer (magnet link) startup time (shaved off about 1 second)
|
||||||
* optimized swarm startup time (shaved off about 1 second)
|
* optimized swarm startup time (shaved off about 1 second)
|
||||||
* support DHT name lookup
|
* support DHT name lookup
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include <boost/python.hpp>
|
#include <boost/python.hpp>
|
||||||
#include <libtorrent/session.hpp>
|
#include <libtorrent/session.hpp>
|
||||||
|
#include <libtorrent/settings.hpp> // for bencode_map_entry
|
||||||
#include <libtorrent/torrent.hpp>
|
#include <libtorrent/torrent.hpp>
|
||||||
#include <libtorrent/storage.hpp>
|
#include <libtorrent/storage.hpp>
|
||||||
#include <libtorrent/ip_filter.hpp>
|
#include <libtorrent/ip_filter.hpp>
|
||||||
|
@ -58,6 +59,75 @@ namespace
|
||||||
s.add_extension(invoke_extension_factory(e));
|
s.add_extension(invoke_extension_factory(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void session_set_settings(session& ses, dict const& sett_dict)
|
||||||
|
{
|
||||||
|
bencode_map_entry* map;
|
||||||
|
int len;
|
||||||
|
boost::tie(map, len) = aux::settings_map();
|
||||||
|
|
||||||
|
session_settings sett;
|
||||||
|
for (int i = 0; i < len; ++i)
|
||||||
|
{
|
||||||
|
if (!sett_dict.has_key(map[i].name)) continue;
|
||||||
|
|
||||||
|
void* dest = ((char*)&sett) + map[i].offset;
|
||||||
|
char const* name = map[i].name;
|
||||||
|
switch (map[i].type)
|
||||||
|
{
|
||||||
|
case std_string:
|
||||||
|
*((std::string*)dest) = extract<std::string>(sett_dict[name]);
|
||||||
|
break;
|
||||||
|
case character:
|
||||||
|
*((char*)dest) = extract<char>(sett_dict[name]);
|
||||||
|
break;
|
||||||
|
case boolean:
|
||||||
|
*((bool*)dest) = extract<bool>(sett_dict[name]);
|
||||||
|
break;
|
||||||
|
case integer:
|
||||||
|
*((int*)dest) = extract<int>(sett_dict[name]);
|
||||||
|
break;
|
||||||
|
case floating_point:
|
||||||
|
*((float*)dest) = extract<float>(sett_dict[name]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ses.set_settings(sett);
|
||||||
|
}
|
||||||
|
|
||||||
|
dict session_get_settings(session const& ses)
|
||||||
|
{
|
||||||
|
session_settings sett = ses.settings();
|
||||||
|
dict sett_dict;
|
||||||
|
bencode_map_entry* map;
|
||||||
|
int len;
|
||||||
|
boost::tie(map, len) = aux::settings_map();
|
||||||
|
for (int i = 0; i < len; ++i)
|
||||||
|
{
|
||||||
|
void const* dest = ((char const*)&sett) + map[i].offset;
|
||||||
|
char const* name = map[i].name;
|
||||||
|
switch (map[i].type)
|
||||||
|
{
|
||||||
|
case std_string:
|
||||||
|
sett_dict[name] = *((std::string const*)dest);
|
||||||
|
break;
|
||||||
|
case character:
|
||||||
|
sett_dict[name] = *((char const*)dest);
|
||||||
|
break;
|
||||||
|
case boolean:
|
||||||
|
sett_dict[name] = *((bool const*)dest);
|
||||||
|
break;
|
||||||
|
case integer:
|
||||||
|
sett_dict[name] = *((int const*)dest);
|
||||||
|
break;
|
||||||
|
case floating_point:
|
||||||
|
sett_dict[name] = *((float const*)dest);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sett_dict;
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef BOOST_NO_EXCEPTIONS
|
#ifndef BOOST_NO_EXCEPTIONS
|
||||||
#ifndef TORRENT_NO_DEPRECATE
|
#ifndef TORRENT_NO_DEPRECATE
|
||||||
torrent_handle add_torrent_depr(session& s, torrent_info const& ti
|
torrent_handle add_torrent_depr(session& s, torrent_info const& ti
|
||||||
|
@ -342,8 +412,14 @@ void bind_session()
|
||||||
.def("set_max_connections", allow_threads(&session::set_max_connections))
|
.def("set_max_connections", allow_threads(&session::set_max_connections))
|
||||||
.def("set_max_half_open_connections", allow_threads(&session::set_max_half_open_connections))
|
.def("set_max_half_open_connections", allow_threads(&session::set_max_half_open_connections))
|
||||||
.def("num_connections", allow_threads(&session::num_connections))
|
.def("num_connections", allow_threads(&session::num_connections))
|
||||||
.def("set_settings", allow_threads(&session::set_settings))
|
#ifndef TORRENT_NO_DEPRECATE
|
||||||
.def("settings", allow_threads(&session::settings))
|
.def("set_settings", &session::set_settings)
|
||||||
|
.def("settings", &session::settings)
|
||||||
|
.def("get_settings", &session_get_settings)
|
||||||
|
#else
|
||||||
|
.def("settings", &session_get_settings)
|
||||||
|
#endif
|
||||||
|
.def("set_settings", &session_set_settings)
|
||||||
#ifndef TORRENT_DISABLE_ENCRYPTION
|
#ifndef TORRENT_DISABLE_ENCRYPTION
|
||||||
.def("set_pe_settings", allow_threads(&session::set_pe_settings))
|
.def("set_pe_settings", allow_threads(&session::set_pe_settings))
|
||||||
.def("get_pe_settings", allow_threads(&session::get_pe_settings))
|
.def("get_pe_settings", allow_threads(&session::get_pe_settings))
|
||||||
|
|
|
@ -160,6 +160,7 @@ The ``session`` class has the following synopsis::
|
||||||
std::vector<torrent_handle> get_torrents() const;
|
std::vector<torrent_handle> get_torrents() const;
|
||||||
|
|
||||||
void set_settings(session_settings const& settings);
|
void set_settings(session_settings const& settings);
|
||||||
|
session_settings settings() const;
|
||||||
void set_pe_settings(pe_settings const& settings);
|
void set_pe_settings(pe_settings const& settings);
|
||||||
|
|
||||||
void set_upload_rate_limit(int bytes_per_second);
|
void set_upload_rate_limit(int bytes_per_second);
|
||||||
|
|
|
@ -98,6 +98,14 @@ a list of entries.
|
||||||
``create_torrent::add_node()`` takes two arguments, one string and one integer,
|
``create_torrent::add_node()`` takes two arguments, one string and one integer,
|
||||||
instead of a pair. The string is the address and the integer is the port.
|
instead of a pair. The string is the address and the integer is the port.
|
||||||
|
|
||||||
|
``session::set_settings()`` not only accepts a ``session_settings`` object, but also
|
||||||
|
a dictionary with keys matching the names of the members of the ``session_settings`` struct.
|
||||||
|
When calling ``set_settings``, the dictionary does not need to have every settings set,
|
||||||
|
keys that are not present, are set to their default value.
|
||||||
|
|
||||||
|
For backwards compatibility, ``session::settings()`` still returns a ``session_settings``
|
||||||
|
struct. To get a python dictionary of the settings, call ``session::get_settings``.
|
||||||
|
|
||||||
.. _`main library reference`: manual.html
|
.. _`main library reference`: manual.html
|
||||||
|
|
||||||
For an example python program, see ``client.py`` in the ``bindings/python``
|
For an example python program, see ``client.py`` in the ``bindings/python``
|
||||||
|
|
|
@ -112,6 +112,8 @@ namespace libtorrent
|
||||||
struct dht_tracker;
|
struct dht_tracker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct bencode_map_entry;
|
||||||
|
|
||||||
namespace aux
|
namespace aux
|
||||||
{
|
{
|
||||||
struct session_impl;
|
struct session_impl;
|
||||||
|
@ -127,6 +129,8 @@ namespace libtorrent
|
||||||
initialize_timer();
|
initialize_timer();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::pair<bencode_map_entry*, int> settings_map();
|
||||||
|
|
||||||
// this is the link between the main thread and the
|
// this is the link between the main thread and the
|
||||||
// thread started to run the main downloader loop
|
// thread started to run the main downloader loop
|
||||||
struct session_impl: boost::noncopyable, initialize_timer
|
struct session_impl: boost::noncopyable, initialize_timer
|
||||||
|
|
|
@ -328,7 +328,7 @@ namespace libtorrent
|
||||||
void remove_torrent(const torrent_handle& h, int options = none);
|
void remove_torrent(const torrent_handle& h, int options = none);
|
||||||
|
|
||||||
void set_settings(session_settings const& s);
|
void set_settings(session_settings const& s);
|
||||||
session_settings settings();
|
session_settings settings() const;
|
||||||
|
|
||||||
void set_proxy(proxy_settings const& s);
|
void set_proxy(proxy_settings const& s);
|
||||||
proxy_settings proxy() const;
|
proxy_settings proxy() const;
|
||||||
|
|
|
@ -691,7 +691,7 @@ namespace libtorrent
|
||||||
TORRENT_ASYNC_CALL1(set_settings, s);
|
TORRENT_ASYNC_CALL1(set_settings, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
session_settings session::settings()
|
session_settings session::settings() const
|
||||||
{
|
{
|
||||||
TORRENT_SYNC_CALL_RET(session_settings, settings);
|
TORRENT_SYNC_CALL_RET(session_settings, settings);
|
||||||
return r;
|
return r;
|
||||||
|
|
|
@ -435,6 +435,10 @@ namespace aux {
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::pair<bencode_map_entry*, int> settings_map()
|
||||||
|
{
|
||||||
|
std::make_pair(session_settings_map, lenof(session_settings_map));
|
||||||
|
}
|
||||||
#undef lenof
|
#undef lenof
|
||||||
|
|
||||||
#ifdef TORRENT_STATS
|
#ifdef TORRENT_STATS
|
||||||
|
|
Loading…
Reference in New Issue