merged RC_1_1 into master

This commit is contained in:
arvidn 2016-12-29 08:54:28 -08:00
commit 59b322bc79
8 changed files with 133 additions and 31 deletions

View File

@ -6,8 +6,11 @@
#include "libtorrent/socket.hpp"
#include "libtorrent/address.hpp"
#include "libtorrent/error_code.hpp"
#include "libtorrent/session_stats.hpp" // for stats_metric
#include "libtorrent/file_pool.hpp" // for pool_file_status
#include "libtorrent/time.hpp"
#include "libtorrent/units.hpp"
#include "libtorrent/sha1_hash.hpp"
#include <vector>
using namespace boost::python;
@ -201,6 +204,9 @@ void bind_converters()
to_python_converter<lt::udp::endpoint, endpoint_to_tuple<lt::udp::endpoint>>();
to_python_converter<lt::address, address_to_tuple>();
to_python_converter<std::vector<lt::stats_metric>, vector_to_list<lt::stats_metric>>();
to_python_converter<std::vector<lt::pool_file_status>, vector_to_list<lt::pool_file_status>>();
to_python_converter<std::vector<lt::sha1_hash>, vector_to_list<lt::sha1_hash>>();
to_python_converter<std::vector<std::string>, vector_to_list<std::string>>();
to_python_converter<std::vector<int>, vector_to_list<int>>();
to_python_converter<std::vector<std::uint8_t>, vector_to_list<std::uint8_t>>();

View File

@ -19,6 +19,7 @@
#include <libtorrent/kademlia/item.hpp> // for sign_mutable_item
#include <libtorrent/alert.hpp>
#include <libtorrent/time.hpp>
#include <libtorrent/session_stats.hpp>
#include <libtorrent/extensions/smart_ban.hpp>
#include <libtorrent/extensions/ut_metadata.hpp>
@ -868,6 +869,15 @@ void bind_session()
def("min_memory_usage", (mem_preset2)min_memory_usage);
def("read_resume_data", read_resume_data_wrapper);
class_<stats_metric>("stats_metric")
.def_readonly("name", &stats_metric::name)
.def_readonly("value_index", &stats_metric::value_index)
.def_readonly("type", &stats_metric::type)
;
def("session_stats_metrics", session_stats_metrics);
def("find_metric_idx", find_metric_idx);
scope().attr("create_ut_metadata_plugin") = "ut_metadata";
scope().attr("create_ut_pex_plugin") = "ut_pex";
scope().attr("create_smart_ban_plugin") = "smart_ban";

View File

@ -12,6 +12,7 @@
#include <libtorrent/peer_info.hpp>
#include "libtorrent/announce_entry.hpp"
#include <libtorrent/storage.hpp>
#include <libtorrent/file_pool.hpp>
#include <boost/lexical_cast.hpp>
#include "gil.hpp"
@ -416,6 +417,7 @@ void bind_torrent_handle()
.def("set_piece_deadline", _(&torrent_handle::set_piece_deadline)
, (arg("index"), arg("deadline"), arg("flags") = 0))
.def("reset_piece_deadline", _(&torrent_handle::reset_piece_deadline), (arg("index")))
.def("clear_piece_deadlines", _(&torrent_handle::clear_piece_deadlines), (arg("index")))
.def("piece_availability", &piece_availability)
.def("piece_priority", _(piece_priority0))
.def("piece_priority", _(piece_priority1))
@ -425,6 +427,7 @@ void bind_torrent_handle()
.def("file_priorities", &file_priorities)
.def("file_priority", &file_prioritity0)
.def("file_priority", &file_prioritity1)
.def("file_status", &torrent_handle::file_status)
.def("save_resume_data", _(&torrent_handle::save_resume_data), arg("flags") = 0)
.def("need_save_resume_data", _(&torrent_handle::need_save_resume_data))
.def("force_reannounce", _(force_reannounce0)
@ -467,16 +470,27 @@ void bind_torrent_handle()
#endif
;
class_<pool_file_status>("pool_file_status")
.def_readonly("file_index", &pool_file_status::file_index)
.def_readonly("last_use", &pool_file_status::last_use)
.def_readonly("open_mode", &pool_file_status::open_mode)
;
enum_<torrent_handle::file_progress_flags_t>("file_progress_flags")
.value("piece_granularity", torrent_handle::piece_granularity)
;
enum_<torrent_handle::flags_t>("add_piece_flags_t")
.value("overwrite_existing", torrent_handle::overwrite_existing)
;
enum_<torrent_handle::pause_flags_t>("pause_flags_t")
.value("graceful_pause", torrent_handle::graceful_pause)
;
enum_<torrent_handle::save_resume_flags_t>("save_resume_flags_t")
.value("flush_disk_cache", torrent_handle::flush_disk_cache)
.value("save_info_dict", torrent_handle::save_info_dict)
.value("only_if_modified", torrent_handle::only_if_modified)
;
enum_<torrent_handle::deadline_flags>("deadline_flags")

View File

@ -60,13 +60,28 @@ namespace
d["url"] = i->url;
d["type"] = i->type;
d["auth"] = i->auth;
d["extra_headers"] = i->extra_headers;
ret.append(d);
}
return ret;
}
void set_web_seeds(torrent_info& ti, list ws)
{
std::vector<web_seed_entry> web_seeds;
int const len = boost::python::len(ws);
for (int i = 0; i < len; i++)
{
dict e = extract<dict>(ws[i]);
int const type = extract<int>(e["type"]);
web_seeds.push_back(web_seed_entry(
extract<std::string>(e["url"])
, static_cast<web_seed_entry::type_t>(type)
, extract<std::string>(e["auth"])));
}
ti.set_web_seeds(web_seeds);
}
list get_merkle_tree(torrent_info const& ti)
{
std::vector<sha1_hash> const& mt = ti.merkle_tree();
@ -226,6 +241,7 @@ void bind_torrent_info()
.def("add_url_seed", &torrent_info::add_url_seed)
.def("add_http_seed", &torrent_info::add_http_seed)
.def("web_seeds", get_web_seeds)
.def("set_web_seeds", set_web_seeds)
.def("name", &torrent_info::name, copy)
.def("comment", &torrent_info::comment, copy)
@ -239,6 +255,9 @@ void bind_torrent_info()
.def("set_merkle_tree", set_merkle_tree)
.def("piece_size", &torrent_info::piece_size)
.def("similar_torrents", &torrent_info::similar_torrents)
.def("collections", &torrent_info::collections)
.def("ssl_cert", &torrent_info::ssl_cert)
.def("num_files", &torrent_info::num_files)
.def("rename_file", rename_file0)
.def("remap_files", &torrent_info::remap_files)
@ -252,7 +271,10 @@ void bind_torrent_info()
#endif // TORRENT_USE_WSTRING
#endif // TORRENT_NO_DEPRECATE
.def("is_valid", &torrent_info::is_valid)
.def("priv", &torrent_info::priv)
.def("is_i2p", &torrent_info::is_i2p)
.def("is_merkle_torrent", &torrent_info::is_merkle_torrent)
.def("trackers", range(begin_trackers, end_trackers))
.def("creation_date", &torrent_info::creation_date)

View File

@ -23,11 +23,18 @@ object pieces(torrent_status const& s) { return bitfield_to_list(s.pieces); }
object verified_pieces(torrent_status const& s) { return bitfield_to_list(s.verified_pieces); }
using by_value = return_value_policy<return_by_value>;
std::shared_ptr<const torrent_info> get_torrent_file(torrent_status const& st)
{
return st.torrent_file.lock();
}
void bind_torrent_status()
{
scope status = class_<torrent_status>("torrent_status")
.def(self == self)
.def_readonly("handle", &torrent_status::handle)
.def_readonly("info_hash", &torrent_status::info_hash)
.add_property("torrent_file", &get_torrent_file)
.def_readonly("state", &torrent_status::state)
.def_readonly("paused", &torrent_status::paused)
.def_readonly("stop_when_ready", &torrent_status::stop_when_ready)

View File

@ -22,25 +22,58 @@ class test_create_torrent(unittest.TestCase):
print(entry)
self.assertEqual(content, file_content)
class test_session_stats(unittest.TestCase):
def test_unique(self):
l = lt.session_stats_metrics()
self.assertTrue(len(l) > 40);
idx = set()
for m in l:
self.assertTrue(m.value_index not in idx)
idx.add(m.value_index)
def test_find_idx(self):
self.assertEqual(lt.find_metric_idx("peer.error_peers"), 0)
class test_torrent_handle(unittest.TestCase):
def setup(self):
self.ses = lt.session({'alert_mask': lt.alert.category_t.all_categories, 'enable_dht': False})
self.ti = lt.torrent_info('url_seed_multi.torrent');
self.h = self.ses.add_torrent({'ti': self.ti, 'save_path': os.getcwd()})
def test_torrent_handle(self):
ses = lt.session({'alert_mask': lt.alert.category_t.all_categories, 'enable_dht': False})
ti = lt.torrent_info('url_seed_multi.torrent');
h = ses.add_torrent({'ti': ti, 'save_path': os.getcwd()})
self.setup()
self.assertEqual(self.h.file_priorities(), [4,4])
self.assertEqual(self.h.piece_priorities(), [4])
self.assertEqual(h.file_priorities(), [4,4])
self.assertEqual(h.piece_priorities(), [4])
self.h.prioritize_files([0,1])
self.assertEqual(self.h.file_priorities(), [0,1])
h.prioritize_files([0,1])
self.assertEqual(h.file_priorities(), [0,1])
h.prioritize_pieces([0])
self.assertEqual(h.piece_priorities(), [0])
self.h.prioritize_pieces([0])
self.assertEqual(self.h.piece_priorities(), [0])
# also test the overload that takes a list of piece->priority mappings
h.prioritize_pieces([(0, 1)])
self.assertEqual(h.piece_priorities(), [1])
self.h.prioritize_pieces([(0, 1)])
self.assertEqual(self.h.piece_priorities(), [1])
def test_file_status(self):
self.setup()
l = self.h.file_status()
print(l)
def test_piece_deadlines(self):
self.setup()
self.h.clear_piece_deadlines()
def test_torrent_status(self):
self.setup()
st = self.h.status()
ti = st.handle;
self.assertEqual(ti.info_hash(), self.ti.info_hash())
# make sure we can compare torrent_status objects
st2 = self.h.status()
self.assertEqual(st2, st)
def test_read_resume_data(self):
@ -69,19 +102,14 @@ class test_torrent_handle(unittest.TestCase):
time.sleep(0.1)
def test_scrape(self):
ses = lt.session({'alert_mask': lt.alert.category_t.all_categories, 'enable_dht': False})
ti = lt.torrent_info('url_seed_multi.torrent');
h = ses.add_torrent({'ti': ti, 'save_path': os.getcwd()})
self.setup()
# this is just to make sure this function can be called like this
# from python
h.scrape_tracker()
self.h.scrape_tracker()
def test_cache_info(self):
ses = lt.session({'alert_mask': lt.alert.category_t.all_categories, 'enable_dht': False})
ti = lt.torrent_info('url_seed_multi.torrent');
h = ses.add_torrent({'ti': ti, 'save_path': os.getcwd()})
cs = ses.get_cache_info(h)
self.setup()
cs = self.ses.get_cache_info(self.h)
self.assertEqual(cs.pieces, [])
class test_torrent_info(unittest.TestCase):
@ -104,6 +132,19 @@ class test_torrent_info(unittest.TestCase):
self.assertTrue(len(ti.metadata()) != 0)
self.assertTrue(len(ti.hash_for_piece(0)) != 0)
def test_web_seeds(self):
ti = lt.torrent_info('base.torrent');
ws = [{'url': 'http://foo/test', 'auth': '', 'type': 0},
{'url': 'http://bar/test', 'auth': '', 'type': 1} ]
ti.set_web_seeds(ws)
web_seeds = ti.web_seeds()
self.assertEqual(len(ws), len(web_seeds))
for i in range(len(web_seeds)):
self.assertEqual(web_seeds[i]["url"], ws[i]["url"])
self.assertEqual(web_seeds[i]["auth"], ws[i]["auth"])
self.assertEqual(web_seeds[i]["type"], ws[i]["type"])
def test_iterable_files(self):
# this detects whether libtorrent was built with deprecated APIs

View File

@ -64,12 +64,6 @@ namespace libtorrent
TORRENT_EXPORT int setting_by_name(std::string const& name);
TORRENT_EXPORT char const* name_for_setting(int s);
#ifndef TORRENT_NO_DEPRECATE
struct session_settings;
std::shared_ptr<settings_pack> load_pack_from_struct(aux::session_settings const& current, session_settings const& s);
void load_struct_from_settings(aux::session_settings const& current, session_settings& ret);
#endif
// The ``settings_pack`` struct, contains the names of all settings as
// enum values. These values are passed in to the ``set_str()``,
// ``set_int()``, ``set_bool()`` functions, to specify the setting to

View File

@ -580,6 +580,7 @@ namespace aux {
void session_impl::init(std::shared_ptr<settings_pack> pack)
{
INVARIANT_CHECK;
// this is a debug facility
// see single_threaded in debug.hpp
thread_started();
@ -826,7 +827,9 @@ namespace aux {
void session_impl::add_ses_extension(std::shared_ptr<plugin> ext)
{
TORRENT_ASSERT(is_single_thread());
// this is called during startup of the session, from the thread creating
// it, not its own thread
// TORRENT_ASSERT(is_single_thread());
TORRENT_ASSERT_VAL(ext, ext);
std::uint32_t const features = ext->implemented_features();
@ -1313,6 +1316,7 @@ namespace aux {
// session_impl is responsible for deleting 'pack'
void session_impl::apply_settings_pack(std::shared_ptr<settings_pack> pack)
{
INVARIANT_CHECK;
apply_settings_pack_impl(*pack);
}
@ -3200,7 +3204,6 @@ namespace aux {
if (!m_paused) m_auto_manage_time_scaler--;
if (m_auto_manage_time_scaler < 0)
{
INVARIANT_CHECK;
m_auto_manage_time_scaler = settings().get_int(settings_pack::auto_manage_interval);
recalculate_auto_managed_torrents();
}
@ -4869,7 +4872,6 @@ namespace aux {
void session_impl::update_outgoing_interfaces()
{
INVARIANT_CHECK;
std::string net_interfaces = m_settings.get_str(settings_pack::outgoing_interfaces);
// declared in string_util.hpp
@ -5841,6 +5843,7 @@ namespace aux {
void session_impl::set_local_download_rate_limit(int bytes_per_second)
{
INVARIANT_CHECK;
settings_pack p;
p.set_int(settings_pack::local_download_rate_limit, bytes_per_second);
apply_settings_pack_impl(p);
@ -5848,6 +5851,7 @@ namespace aux {
void session_impl::set_local_upload_rate_limit(int bytes_per_second)
{
INVARIANT_CHECK;
settings_pack p;
p.set_int(settings_pack::local_upload_rate_limit, bytes_per_second);
apply_settings_pack_impl(p);
@ -5855,6 +5859,7 @@ namespace aux {
void session_impl::set_download_rate_limit_depr(int bytes_per_second)
{
INVARIANT_CHECK;
settings_pack p;
p.set_int(settings_pack::download_rate_limit, bytes_per_second);
apply_settings_pack_impl(p);
@ -5862,6 +5867,7 @@ namespace aux {
void session_impl::set_upload_rate_limit_depr(int bytes_per_second)
{
INVARIANT_CHECK;
settings_pack p;
p.set_int(settings_pack::upload_rate_limit, bytes_per_second);
apply_settings_pack_impl(p);
@ -5869,6 +5875,7 @@ namespace aux {
void session_impl::set_max_connections(int limit)
{
INVARIANT_CHECK;
settings_pack p;
p.set_int(settings_pack::connections_limit, limit);
apply_settings_pack_impl(p);
@ -5876,6 +5883,7 @@ namespace aux {
void session_impl::set_max_uploads(int limit)
{
INVARIANT_CHECK;
settings_pack p;
p.set_int(settings_pack::unchoke_slots_limit, limit);
apply_settings_pack_impl(p);