From 692759ba811c6fc94df34e4fe32fb52f11b9ea6d Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Mon, 6 Feb 2017 00:01:04 -0500 Subject: [PATCH 1/9] slightly improve proxy settings backwards compatibility-1.1 (#1664) slightly improve proxy settings backwards compatibility --- ChangeLog | 1 + src/session_handle.cpp | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index ee687039f..e78c8988a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + * slightly improve proxy settings backwards compatibility * add function to get default settings * updating super seeding would include the torrent in state_update_alert * fix issue where num_seeds could be greater than num_peers in torrent_status diff --git a/src/session_handle.cpp b/src/session_handle.cpp index 0930ab732..563d8ad77 100644 --- a/src/session_handle.cpp +++ b/src/session_handle.cpp @@ -785,14 +785,19 @@ namespace libtorrent set_proxy(s); } - void session_handle::set_web_seed_proxy(proxy_settings const& s) + void session_handle::set_web_seed_proxy(proxy_settings const&) { - set_proxy(s); + // NO-OP } void session_handle::set_tracker_proxy(proxy_settings const& s) { - set_proxy(s); + // if the tracker proxy is enabled, set the "proxy_tracker_connections" + // setting + settings_pack pack; + pack.set_bool(settings_pack::proxy_tracker_connections + , s.type != aux::proxy_settings::none); + apply_settings(pack); } proxy_settings session_handle::peer_proxy() const @@ -807,12 +812,14 @@ namespace libtorrent proxy_settings session_handle::tracker_proxy() const { - return proxy(); + settings_pack const sett = get_settings(); + return sett.get_bool(settings_pack::proxy_tracker_connections) + ? proxy_settings(sett) : proxy_settings(); } - void session_handle::set_dht_proxy(proxy_settings const& s) + void session_handle::set_dht_proxy(proxy_settings const&) { - set_proxy(s); + // NO-OP } proxy_settings session_handle::dht_proxy() const From c4d96c7aa9434261032d9ae92d57548d1bff0c18 Mon Sep 17 00:00:00 2001 From: ximply <527087538@qq.com> Date: Tue, 7 Feb 2017 14:34:52 +0800 Subject: [PATCH 2/9] add web_seed_name_lookup_retry to session_settings (#1674) add web_seed_name_lookup_retry to session_settings to control web seed name lookup retry in seconds, default is 1800 seconds --- ChangeLog | 1 + include/libtorrent/settings_pack.hpp | 5 ++++- src/settings_pack.cpp | 1 + src/torrent.cpp | 4 ++-- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index e78c8988a..8d2857cf8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + * add web_seed_name_lookup_retry to session_settings * slightly improve proxy settings backwards compatibility * add function to get default settings * updating super seeding would include the torrent in state_update_alert diff --git a/include/libtorrent/settings_pack.hpp b/include/libtorrent/settings_pack.hpp index 47aeaa4e7..90db63ed7 100644 --- a/include/libtorrent/settings_pack.hpp +++ b/include/libtorrent/settings_pack.hpp @@ -794,7 +794,10 @@ namespace libtorrent // time to wait until a new retry of a web seed takes place urlseed_wait_retry, - + + // time to wait until a new retry of a web seed name lookup + web_seed_name_lookup_retry, + // sets the upper limit on the total number of files this session will // keep open. The reason why files are left open at all is that some // anti virus software hooks on every file close, and scans the file diff --git a/src/settings_pack.cpp b/src/settings_pack.cpp index 75551e05e..bc439b1e9 100644 --- a/src/settings_pack.cpp +++ b/src/settings_pack.cpp @@ -236,6 +236,7 @@ namespace libtorrent SET(urlseed_pipeline_size, 5, 0), SET_NOPREV(urlseed_max_request_bytes, 16 * 1024 * 1024, 0), SET(urlseed_wait_retry, 30, 0), + SET_NOPREV(web_seed_name_lookup_retry, 1800, 0), SET(file_pool_size, 40, 0), SET(max_failcount, 3, &session_impl::update_max_failcount), SET(min_reconnect_time, 60, 0), diff --git a/src/torrent.cpp b/src/torrent.cpp index 184c7359d..94f852afc 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -6511,8 +6511,8 @@ namespace libtorrent , web->url.c_str(), e.value(), e.message().c_str()); #endif - // unavailable, retry in 30 minutes - web->retry = aux::time_now() + minutes(30); + // unavailable, retry in `settings_pack::web_seed_name_lookup_retry` seconds + web->retry = aux::time_now() + seconds(settings().get_int(settings_pack::web_seed_name_lookup_retry)); return; } From 61f9f6bb7fc35a451dde61575365e0a259990c00 Mon Sep 17 00:00:00 2001 From: arvidn Date: Tue, 7 Feb 2017 17:26:34 -0500 Subject: [PATCH 3/9] fix travis script for running python tests --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index bc26d4222..2d6cdff96 100644 --- a/.travis.yml +++ b/.travis.yml @@ -120,12 +120,12 @@ script: # here we specify the temporary lib dir as a path to look for the main library # a binary built with sanitizer does not interact well with python + - cd bindings/python - 'if [[ $lang != "sanitizer" ]]; then - cd bindings/python; bjam --hash -j3 warnings-as-errors=on debug-iterators=on picker-debugging=on invariant-checks=full variant=$variant $coverage_toolset stage_module libtorrent-link=shared install-type=LIB dll-path=../../lib; LD_LIBRARY_PATH=../../lib DYLD_LIBRARY_PATH=../../lib python test.py; - cd ../..; fi' + - cd ../.. - cd simulation - if [ $sim = "1" ]; then From 964542e53bba4696625a9c246665c12e4f47571d Mon Sep 17 00:00:00 2001 From: arvidn Date: Wed, 8 Feb 2017 07:56:20 -0500 Subject: [PATCH 4/9] back-port ajax16384's fix to enum_net_interfaces on windows --- src/enum_net.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/enum_net.cpp b/src/enum_net.cpp index 796763776..66f5588aa 100644 --- a/src/enum_net.cpp +++ b/src/enum_net.cpp @@ -630,6 +630,13 @@ namespace libtorrent IP_ADAPTER_UNICAST_ADDRESS* unicast = adapter->FirstUnicastAddress; while (unicast) { + if (unicast->Address.lpSockaddr->sa_family != AF_INET +#if TORRENT_USE_IPV6 + && unicast->Address.lpSockaddr->sa_family != AF_INET6 +#endif + ) + continue; + r.interface_address = sockaddr_to_address(unicast->Address.lpSockaddr); ret.push_back(r); From de30f357b346c2022f26f6901423888ba4077b41 Mon Sep 17 00:00:00 2001 From: Calum Lind Date: Mon, 30 Jan 2017 16:13:57 +0000 Subject: [PATCH 5/9] Add missing announce_entry properties to python bindings Fix and refactor the announce_entry class - Removed verified from torrent_handle dict to announce_entry as it's read-only. - Changed source and send_stats to read_write properties. - Switched trivial type properties to using read_only or read_write. --- .gitignore | 6 ++++++ bindings/python/compile_flags.in | 2 +- bindings/python/src/torrent_handle.cpp | 14 ++++++------ bindings/python/src/torrent_info.cpp | 30 ++++++++++++++++++++------ bindings/python/test.py | 20 +++++++++++++++++ configure.ac | 3 +++ 6 files changed, 61 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index 810f03485..bf75a8a17 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,7 @@ *.exe *.out *.app +libtool *.m4 *.in @@ -50,3 +51,8 @@ bindings/python/*flags # Logs libtorrent_logs* *.log + +# Python related files and dirs +*.pyc +dist +*.egg-info diff --git a/bindings/python/compile_flags.in b/bindings/python/compile_flags.in index 701d89862..d51261c10 100644 --- a/bindings/python/compile_flags.in +++ b/bindings/python/compile_flags.in @@ -1 +1 @@ --I@top_srcdir@/include @COMPILETIME_OPTIONS@ @CPPFLAGS@ @BOOST_CPPFLAGS@ @OPENSSL_INCLUDES@ +-I@top_srcdir@/include @COMPILETIME_OPTIONS@ @CPPFLAGS@ @BOOST_CPPFLAGS@ @PYTHON_CXXFLAGS@ @OPENSSL_INCLUDES@ diff --git a/bindings/python/src/torrent_handle.cpp b/bindings/python/src/torrent_handle.cpp index 5a8ff4c44..66b6bd3ae 100644 --- a/bindings/python/src/torrent_handle.cpp +++ b/bindings/python/src/torrent_handle.cpp @@ -191,12 +191,6 @@ void dict_to_announce_entry(dict d, announce_entry& ae) ae.tier = extract(d["tier"]); if (d.has_key("fail_limit")) ae.fail_limit = extract(d["fail_limit"]); - if (d.has_key("source")) - ae.source = extract(d["source"]); - if (d.has_key("verified")) - ae.verified = extract(d["verified"]); - if (d.has_key("send_stats")) - ae.send_stats = extract(d["send_stats"]); } void replace_trackers(torrent_handle& h, object trackers) @@ -245,6 +239,14 @@ list trackers(torrent_handle& h) { dict d; d["url"] = i->url; + d["trackerid"] = i->trackerid; + d["message"] = i->message; + d["last_error"] = i->last_error; + d["next_announce"] = i->next_announce; + d["min_announce"] = i->min_announce; + d["scrape_incomplete"] = i->scrape_incomplete; + d["scrape_complete"] = i->scrape_complete; + d["scrape_downloaded"] = i->scrape_downloaded; d["tier"] = i->tier; d["fail_limit"] = i->fail_limit; d["fails"] = i->fails; diff --git a/bindings/python/src/torrent_info.cpp b/bindings/python/src/torrent_info.cpp index 97afbb447..a5a01ef2c 100644 --- a/bindings/python/src/torrent_info.cpp +++ b/bindings/python/src/torrent_info.cpp @@ -18,6 +18,7 @@ using namespace boost::python; using namespace libtorrent; +namespace lt = libtorrent; namespace { @@ -126,10 +127,10 @@ namespace return result; } - int get_tier(announce_entry const& ae) { return ae.tier; } - void set_tier(announce_entry& ae, int v) { ae.tier = v; } - int get_fail_limit(announce_entry const& ae) { return ae.fail_limit; } - void set_fail_limit(announce_entry& ae, int l) { ae.fail_limit = l; } + // Create getters for announce_entry data members with non-trivial types which need converting. + lt::time_point get_next_announce(announce_entry const& ae) { return ae.next_announce; } + lt::time_point get_min_announce(announce_entry const& ae) { return ae.min_announce; } + // announce_entry data member bit-fields. int get_fails(announce_entry const& ae) { return ae.fails; } int get_source(announce_entry const& ae) { return ae.source; } bool get_verified(announce_entry const& ae) { return ae.verified; } @@ -137,6 +138,11 @@ namespace bool get_start_sent(announce_entry const& ae) { return ae.start_sent; } bool get_complete_sent(announce_entry const& ae) { return ae.complete_sent; } bool get_send_stats(announce_entry const& ae) { return ae.send_stats; } + // announce_entry method requires lt::time_point. + bool can_announce(announce_entry const& ae, bool is_seed) { + lt::time_point now = lt::clock_type::now(); + return ae.can_announce(now, is_seed); + } #ifndef TORRENT_NO_DEPRECATE boost::int64_t get_size(file_entry const& fe) { return fe.size; } @@ -307,8 +313,16 @@ void bind_torrent_info() class_("announce_entry", init()) .def_readwrite("url", &announce_entry::url) - .add_property("tier", &get_tier, &set_tier) - .add_property("fail_limit", &get_fail_limit, &set_fail_limit) + .def_readonly("trackerid", &announce_entry::trackerid) + .def_readonly("message", &announce_entry::message) + .def_readonly("last_error", &announce_entry::last_error) + .add_property("next_announce", &get_next_announce) + .add_property("min_announce", &get_min_announce) + .def_readonly("scrape_incomplete", &announce_entry::scrape_incomplete) + .def_readonly("scrape_complete", &announce_entry::scrape_complete) + .def_readonly("scrape_downloaded", &announce_entry::scrape_downloaded) + .def_readwrite("tier", &announce_entry::tier) + .def_readwrite("fail_limit", &announce_entry::fail_limit) .add_property("fails", &get_fails) .add_property("source", &get_source) .add_property("verified", &get_verified) @@ -317,8 +331,10 @@ void bind_torrent_info() .add_property("complete_sent", &get_complete_sent) .add_property("send_stats", &get_send_stats) + .def("next_announce_in", &announce_entry::next_announce_in) + .def("min_announce_in", &announce_entry::min_announce_in) .def("reset", &announce_entry::reset) - .def("can_announce", &announce_entry::can_announce) + .def("can_announce", can_announce) .def("is_working", &announce_entry::is_working) .def("trim", &announce_entry::trim) ; diff --git a/bindings/python/test.py b/bindings/python/test.py index 51fa5260e..3ffa8c9ed 100644 --- a/bindings/python/test.py +++ b/bindings/python/test.py @@ -57,6 +57,20 @@ class test_torrent_handle(unittest.TestCase): self.h.prioritize_pieces([(0, 1)]) self.assertEqual(self.h.piece_priorities(), [1]) + def test_replace_trackers(self): + self.setup() + trackers = [] + for idx, tracker_url in enumerate(('udp://tracker1.com', 'udp://tracker2.com')): + tracker = lt.announce_entry(tracker_url) + tracker.tier = idx + tracker.fail_limit = 2 + trackers.append(tracker) + self.h.replace_trackers(trackers) + new_trackers = self.h.trackers() + self.assertEqual(new_trackers[0]['url'], 'udp://tracker1.com') + self.assertEqual(new_trackers[1]['tier'], 1) + self.assertEqual(new_trackers[1]['fail_limit'], 2) + def test_file_status(self): self.setup() l = self.h.file_status() @@ -138,6 +152,12 @@ class test_torrent_info(unittest.TestCase): self.assertEqual(os.path.split(os.path.split(f.path)[0]), ('temp', 'foo')) idx += 1 + def test_announce_entry(self): + ae = lt.announce_entry('test') + self.assertEquals(ae.can_announce(False), True) + self.assertEquals(ae.scrape_incomplete, -1) + self.assertEquals(ae.next_announce, None) + class test_alerts(unittest.TestCase): def test_alert(self): diff --git a/configure.ac b/configure.ac index 4aba9b2e2..c08e19dfc 100644 --- a/configure.ac +++ b/configure.ac @@ -556,6 +556,9 @@ AC_SUBST(DEBUGFLAGS) AC_SUBST(PYTHON_INSTALL_PARAMS) AC_SUBST(COMPILETIME_OPTIONS) +# Disable deprecated warnings for the Python binding builds. +PYTHON_CXXFLAGS="${PYTHON_CXXFLAGS} -Wno-deprecated-declarations" +AC_SUBST(PYTHON_CXXFLAGS) # Try to guess real git revision if any, fallback to hardcoded otherwise GIT_REVISION=`git log -1 --format=format:%h 2>/dev/null` From 4492cada4af1d30ade75e6b03b5f69c58439839c Mon Sep 17 00:00:00 2001 From: Calum Lind Date: Sun, 5 Feb 2017 22:58:02 +0000 Subject: [PATCH 6/9] Backport time_point to python convertor. Fix bindings returning invalid date from time_point convertor --- bindings/python/src/datetime.cpp | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/bindings/python/src/datetime.cpp b/bindings/python/src/datetime.cpp index f1e91d702..79ece6add 100644 --- a/bindings/python/src/datetime.cpp +++ b/bindings/python/src/datetime.cpp @@ -5,6 +5,7 @@ #include "boost_python.hpp" #include #include "optional.hpp" +#include #include #include "libtorrent/time.hpp" @@ -55,6 +56,33 @@ struct time_duration_to_python } }; +struct time_point_to_python +{ + static PyObject* convert(lt::time_point tpt) + { + object result; + if (tpt > lt::min_time()) { + time_t const tm = boost::chrono::system_clock::to_time_t(boost::chrono::system_clock::now() + + boost::chrono::duration_cast(tpt - lt::clock_type::now())); + + std::tm* date = std::localtime(&tm); + result = datetime_datetime( + (int)1900 + date->tm_year + // tm use 0-11 and we need 1-12 + , (int)date->tm_mon + 1 + , (int)date->tm_mday + , date->tm_hour + , date->tm_min + , date->tm_sec + ); + } + else { + result = object(); + } + return incref(result.ptr()); + } +}; + struct ptime_to_python { static PyObject* convert(boost::posix_time::ptime const& pt) @@ -87,6 +115,11 @@ void bind_datetime() , time_duration_to_python >(); + to_python_converter< + lt::time_point + , time_point_to_python + >(); + to_python_converter< boost::posix_time::ptime , ptime_to_python From db32618c399519be85ad2d44dcf2bd601593e613 Mon Sep 17 00:00:00 2001 From: arvidn Date: Fri, 10 Feb 2017 14:47:37 -0500 Subject: [PATCH 7/9] system_clock fix --- bindings/python/src/datetime.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bindings/python/src/datetime.cpp b/bindings/python/src/datetime.cpp index 79ece6add..3f1dc5e3a 100644 --- a/bindings/python/src/datetime.cpp +++ b/bindings/python/src/datetime.cpp @@ -56,14 +56,20 @@ struct time_duration_to_python } }; +#if defined BOOST_ASIO_HAS_STD_CHRONO +using std::chrono::system_clock; +#else +using boost::chrono::system_clock; +#endif + struct time_point_to_python { static PyObject* convert(lt::time_point tpt) { object result; if (tpt > lt::min_time()) { - time_t const tm = boost::chrono::system_clock::to_time_t(boost::chrono::system_clock::now() - + boost::chrono::duration_cast(tpt - lt::clock_type::now())); + time_t const tm = system_clock::to_time_t(system_clock::now() + + lt::duration_cast(tpt - lt::clock_type::now())); std::tm* date = std::localtime(&tm); result = datetime_datetime( From 85f6febfff29a92953c7626f658c7e76ae5d3637 Mon Sep 17 00:00:00 2001 From: arvidn Date: Sat, 11 Feb 2017 09:33:01 -0500 Subject: [PATCH 8/9] fix some left-over incorrect default piece priorities (1 -> 4) --- src/storage.cpp | 4 ++-- src/torrent.cpp | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/storage.cpp b/src/storage.cpp index 89235be22..a22c70e5f 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -436,9 +436,9 @@ namespace libtorrent void default_storage::set_file_priority(std::vector const& prio, storage_error& ec) { // extend our file priorities in case it's truncated - // the default assumed priority is 1 + // the default assumed priority is 4 (the default) if (prio.size() > m_file_priority.size()) - m_file_priority.resize(prio.size(), 1); + m_file_priority.resize(prio.size(), 4); file_storage const& fs = files(); for (int i = 0; i < int(prio.size()); ++i) diff --git a/src/torrent.cpp b/src/torrent.cpp index 94f852afc..521644b4c 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -5589,7 +5589,7 @@ namespace libtorrent std::copy(files.begin(), files.begin() + limit, m_file_priority.begin()); if (valid_metadata() && m_torrent_file->num_files() > int(m_file_priority.size())) - m_file_priority.resize(m_torrent_file->num_files(), 1); + m_file_priority.resize(m_torrent_file->num_files(), 4); // initialize pad files to priority 0 file_storage const& fs = m_torrent_file->files(); @@ -10604,7 +10604,7 @@ namespace libtorrent if (ps.peer_count == 0) continue; if (ps.priority == 0 && (ps.have || ps.downloading)) { - m_picker->set_piece_priority(i, 1); + m_picker->set_piece_priority(i, 4); continue; } // don't count pieces we already have or are trying to download @@ -10637,7 +10637,7 @@ namespace libtorrent // now, pick one of the rarest pieces to download int pick = random() % rarest_pieces.size(); bool was_finished = is_finished(); - m_picker->set_piece_priority(rarest_pieces[pick], 1); + m_picker->set_piece_priority(rarest_pieces[pick], 4); update_gauge(); update_peer_interest(was_finished); update_want_peers(); From 949d4cd12a10367f96ce417e3676e7209efd9588 Mon Sep 17 00:00:00 2001 From: arvidn Date: Sat, 11 Feb 2017 15:47:22 -0500 Subject: [PATCH 9/9] fix regression in windows implementation of enum_net causing infinite loop --- src/enum_net.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/enum_net.cpp b/src/enum_net.cpp index 66f5588aa..5faeee9e0 100644 --- a/src/enum_net.cpp +++ b/src/enum_net.cpp @@ -627,8 +627,8 @@ namespace libtorrent strncpy(r.name, adapter->AdapterName, sizeof(r.name)); r.name[sizeof(r.name)-1] = 0; r.mtu = adapter->Mtu; - IP_ADAPTER_UNICAST_ADDRESS* unicast = adapter->FirstUnicastAddress; - while (unicast) + for (IP_ADAPTER_UNICAST_ADDRESS* unicast = adapter->FirstUnicastAddress; + unicast; unicast = unicast->Next) { if (unicast->Address.lpSockaddr->sa_family != AF_INET #if TORRENT_USE_IPV6 @@ -640,8 +640,6 @@ namespace libtorrent r.interface_address = sockaddr_to_address(unicast->Address.lpSockaddr); ret.push_back(r); - - unicast = unicast->Next; } }