From d6a7c7d991f8b653864fd09441acca920dc29274 Mon Sep 17 00:00:00 2001 From: arvidn Date: Tue, 10 Jan 2017 19:53:56 -0500 Subject: [PATCH 01/10] fix error in accounting of IP overhead --- include/libtorrent/stat.hpp | 2 ++ src/session_impl.cpp | 33 +++++++++++++++++++++++++-------- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/include/libtorrent/stat.hpp b/include/libtorrent/stat.hpp index 18e14e617..e844c60dc 100644 --- a/include/libtorrent/stat.hpp +++ b/include/libtorrent/stat.hpp @@ -260,6 +260,8 @@ namespace libtorrent // these are the channels we keep stats for enum { + // TODO: 3 everything but payload counters and rates could probably be + // removed from here upload_payload, upload_protocol, download_payload, diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 7e7d60e5b..d523baeb8 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -3070,16 +3070,39 @@ retry: void session_impl::trancieve_ip_packet(int bytes, bool ipv6) { + // one TCP/IP packet header for the packet + // sent or received, and one for the ACK + // The IPv4 header is 20 bytes + // and IPv6 header is 40 bytes + int const header = (ipv6 ? 40 : 20) + 20; + int const mtu = 1500; + int const packet_size = mtu - header; + int const overhead = std::max(1, (bytes + packet_size - 1) / packet_size) * header; + m_stats_counters.inc_stats_counter(counters::sent_ip_overhead_bytes + , overhead); + m_stats_counters.inc_stats_counter(counters::recv_ip_overhead_bytes + , overhead); + m_stat.trancieve_ip_packet(bytes, ipv6); } void session_impl::sent_syn(bool ipv6) { + int const overhead = ipv6 ? 60 : 40; + m_stats_counters.inc_stats_counter(counters::sent_ip_overhead_bytes + , overhead); + m_stat.sent_syn(ipv6); } void session_impl::received_synack(bool ipv6) { + int const overhead = ipv6 ? 60 : 40; + m_stats_counters.inc_stats_counter(counters::sent_ip_overhead_bytes + , overhead); + m_stats_counters.inc_stats_counter(counters::recv_ip_overhead_bytes + , overhead); + m_stat.received_synack(ipv6); } @@ -4692,12 +4715,6 @@ retry: m_dht->update_stats_counters(m_stats_counters); #endif - m_stats_counters.set_value(counters::sent_ip_overhead_bytes - , m_stat.total_transfer(stat::upload_ip_protocol)); - - m_stats_counters.set_value(counters::recv_ip_overhead_bytes - , m_stat.total_transfer(stat::download_ip_protocol)); - m_stats_counters.set_value(counters::limiter_up_queue , m_upload_rate.queue_size()); m_stats_counters.set_value(counters::limiter_down_queue @@ -5718,9 +5735,9 @@ retry: // IP-overhead s.ip_overhead_download_rate = m_stat.transfer_rate(stat::download_ip_protocol); - s.total_ip_overhead_download = m_stat.total_transfer(stat::download_ip_protocol); + s.total_ip_overhead_download = m_stats_counters[counters::recv_ip_overhead_bytes]; s.ip_overhead_upload_rate = m_stat.transfer_rate(stat::upload_ip_protocol); - s.total_ip_overhead_upload = m_stat.total_transfer(stat::upload_ip_protocol); + s.total_ip_overhead_upload = m_stats_counters[counters::sent_ip_overhead_bytes]; // tracker s.total_tracker_download = m_stats_counters[counters::recv_tracker_bytes]; From 70a650fc940f1b1b19dc7c3051204e19c07a4b4c Mon Sep 17 00:00:00 2001 From: arvidn Date: Thu, 12 Jan 2017 18:02:54 -0500 Subject: [PATCH 02/10] fix typo in session stats documentation generation script --- docs/gen_stats_doc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/gen_stats_doc.py b/docs/gen_stats_doc.py index 3c7e8987a..4cbf695d1 100755 --- a/docs/gen_stats_doc.py +++ b/docs/gen_stats_doc.py @@ -20,7 +20,7 @@ for l in f: counter_type = 'counter' continue - if 'enum stats_gauges_t' in l: + if 'enum stats_gauge_t' in l: counter_type = 'gauge' continue From 2120a138695b068ea0c7eb80327791900cd2b274 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Fri, 13 Jan 2017 00:39:49 -0500 Subject: [PATCH 03/10] fix file rename issue with name prefix matching torrent name (#1524) fix file rename issue with name prefix matching torrent name --- ChangeLog | 1 + src/file_storage.cpp | 4 ++-- test/test.cpp | 2 +- test/test_file_storage.cpp | 6 +++++- test/test_storage.cpp | 13 +++++-------- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index d5db6a694..bb8842beb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + * fix file rename issue with name prefix matching torrent name * fix division by zero when setting tick_interval > 1000 * fix move_storage() to its own directory (would delete the files) * fix socks5 support for UDP diff --git a/src/file_storage.cpp b/src/file_storage.cpp index e08eb9cea..d904da436 100644 --- a/src/file_storage.cpp +++ b/src/file_storage.cpp @@ -179,9 +179,9 @@ namespace libtorrent } if (branch_len >= m_name.size() - && std::memcmp(branch_path, m_name.c_str(), m_name.size()) == 0) + && std::memcmp(branch_path, m_name.c_str(), m_name.size()) == 0 + && branch_path[m_name.size()] == TORRENT_SEPARATOR) { - // the +1 is to skip the trailing '/' (or '\') int const offset = m_name.size() + (m_name.size() == branch_len?0:1); branch_path += offset; diff --git a/test/test.cpp b/test/test.cpp index 9e5e290b7..93cacd099 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -50,7 +50,7 @@ void report_failure(char const* err, char const* file, int line) { char buf[500]; snprintf(buf, sizeof(buf), "\x1b[41m***** %s:%d \"%s\" *****\x1b[0m\n", file, line, err); - printf("\n%s\n", buf); + fprintf(stderr, "\n%s\n", buf); failure_strings.push_back(buf); ++_g_test_failures; } diff --git a/test/test_file_storage.cpp b/test/test_file_storage.cpp index dd4b3fa55..ac8f769d1 100644 --- a/test/test_file_storage.cpp +++ b/test/test_file_storage.cpp @@ -96,6 +96,10 @@ TORRENT_TEST(rename_file) st.rename_file(0, "/tmp/a"); TEST_EQUAL(st.file_path(0, "."), "/tmp/a"); #endif + + st.rename_file(0, combine_path("test__", "a")); + TEST_EQUAL(st.file_path(0, "."), combine_path(".", combine_path("test__" + , "a"))); } TORRENT_TEST(set_name) @@ -105,7 +109,7 @@ TORRENT_TEST(set_name) // torrent, the path of the files should change too file_storage st; setup_test_storage(st); - + st.set_name("test_2"); TEST_EQUAL(st.file_path(0, "."), combine_path(".", combine_path("test_2" , "a"))); diff --git a/test/test_storage.cpp b/test/test_storage.cpp index 73a14020e..8e9cac56d 100644 --- a/test/test_storage.cpp +++ b/test/test_storage.cpp @@ -33,6 +33,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "test.hpp" #include "setup_transfer.hpp" #include "test_utils.hpp" +#include "settings.hpp" #include "libtorrent/storage.hpp" #include "libtorrent/file_pool.hpp" @@ -749,11 +750,7 @@ TORRENT_TEST(rename_file) & ~(alert::performance_warning | alert::stats_notification); - settings_pack pack; - pack.set_bool(settings_pack::enable_lsd, false); - pack.set_bool(settings_pack::enable_natpmp, false); - pack.set_bool(settings_pack::enable_upnp, false); - pack.set_bool(settings_pack::enable_dht, false); + settings_pack pack = settings(); pack.set_int(settings_pack::alert_mask, mask); pack.set_bool(settings_pack::disable_hash_checks, true); lt::session ses(pack); @@ -777,14 +774,14 @@ TORRENT_TEST(rename_file) for (int i = 0; i < info->num_files(); ++i) { std::string name = fs.file_path(i); - h.rename_file(i, "__" + name); + h.rename_file(i, "temp_storage__" + name.substr(12)); } // wait fir the files to have been renamed alert const* fra = wait_for_alert(ses, file_renamed_alert::alert_type, "ses", info->num_files()); TEST_CHECK(fra); - TEST_CHECK(exists("__" + info->name())); + TEST_CHECK(exists(info->name() + "__")); h.save_resume_data(); alert const* ra = wait_for_alert(ses, save_resume_data_alert::alert_type); @@ -797,7 +794,7 @@ TORRENT_TEST(rename_file) entry::list_type files = resume.dict().find("mapped_files")->second.list(); for (entry::list_type::iterator i = files.begin(); i != files.end(); ++i) { - TEST_CHECK(i->string().substr(0, 2) == "__"); + TEST_EQUAL(i->string().substr(0, 14), "temp_storage__"); } } From 3f7bc23c6cd92c1f71d814c1ecc9d52db6bba3e6 Mon Sep 17 00:00:00 2001 From: Falco Date: Thu, 12 Jan 2017 21:43:58 +0100 Subject: [PATCH 04/10] use git for configure revision --- configure.ac | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/configure.ac b/configure.ac index 6ccc15ab4..e5ed84339 100644 --- a/configure.ac +++ b/configure.ac @@ -557,10 +557,10 @@ AC_SUBST(PYTHON_INSTALL_PARAMS) AC_SUBST(COMPILETIME_OPTIONS) -# Try to guess real svn revision if any, fallback to hardcoded otherwise -SVN_REVISION=`svn info 2>/dev/null | sed -n -e '/^URL\:.*libtorrent.svn.sourceforge.net/,$!d;s,^Revision\: \([[0-9]]*\)$,\1,p'` -AS_IF([test -z "$SVN_REVISION"], - [SVN_REVISION=`sed -n -e 's/^#define LIBTORRENT_REVISION \"\$Rev\: \([0-9]*\) \$\" $/\1/p' include/libtorrent/version.hpp`]) +# Try to guess real git revision if any, fallback to hardcoded otherwise +GIT_REVISION=`git log -1 --format=format:%h 2>/dev/null` +AS_IF([test -z "$GIT_REVISION"], + [GIT_REVISION=`sed -n -e "s/^#define LIBTORRENT_REVISION \"\([0-9a-z]*\)\"$/\1/p" $(dirname $0)/include/libtorrent/version.hpp`]) ############################################################################### @@ -603,7 +603,7 @@ cat > config.report << END Package: name: ${PACKAGE_NAME} version: ${PACKAGE_VERSION} - svn revision: ${SVN_REVISION} + git revision: ${GIT_REVISION} Build environment: build system: ${build} From 219846fc3d47fc3a6c10eab8079bc90f6a93f86d Mon Sep 17 00:00:00 2001 From: arvidn Date: Fri, 13 Jan 2017 00:54:52 -0500 Subject: [PATCH 05/10] back-ported AM_MAINTAINER_MODE patch to RC_1_1 --- configure.ac | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index e5ed84339..4aba9b2e2 100644 --- a/configure.ac +++ b/configure.ac @@ -79,7 +79,7 @@ AC_CANONICAL_TARGET AS_ECHO AS_ECHO "Initializing Automake:" AM_INIT_AUTOMAKE([1.11 foreign]) - +AM_MAINTAINER_MODE([enable]) AS_ECHO AS_ECHO "Initializing Libtool:" @@ -693,7 +693,7 @@ OpenSSL library: OpenSSL Libs: ${OPENSSL_LIBS} OpenSSL LDFlags: ${OPENSSL_LDFLAGS} OpenSSL Includes: ${OPENSSL_INCLUDES} -END +END ]) cat config.report From 07d45329ea625a8e28ce66897f03352706ca6a50 Mon Sep 17 00:00:00 2001 From: arvidn Date: Fri, 13 Jan 2017 17:37:37 -0500 Subject: [PATCH 06/10] fix stats_metric enum to end up in documentation --- include/libtorrent/session_stats.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/libtorrent/session_stats.hpp b/include/libtorrent/session_stats.hpp index e3921edf4..43168f6a9 100644 --- a/include/libtorrent/session_stats.hpp +++ b/include/libtorrent/session_stats.hpp @@ -46,8 +46,8 @@ namespace libtorrent { char const* name; int value_index; - enum { type_counter, type_gauge }; - int type; + enum metric_type_t { type_counter, type_gauge }; + metric_type_t type; }; // This free function returns the list of available metrics exposed by From 51aa8e6928f848c37e389ac5121da0425d08591c Mon Sep 17 00:00:00 2001 From: Falco Date: Fri, 13 Jan 2017 12:52:57 +0000 Subject: [PATCH 07/10] documentation for deprecated members --- include/libtorrent/disk_io_thread.hpp | 2 ++ include/libtorrent/session_status.hpp | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/include/libtorrent/disk_io_thread.hpp b/include/libtorrent/disk_io_thread.hpp index 8fe8a3067..6cbfd0ccc 100644 --- a/include/libtorrent/disk_io_thread.hpp +++ b/include/libtorrent/disk_io_thread.hpp @@ -199,6 +199,7 @@ namespace libtorrent // the total number of buffers currently in use. // This includes the read/write disk cache as well as send and receive buffers // used in peer connections. + // deprecated, use session_stats_metrics "disk.disk_blocks_in_use" mutable int total_used_buffers; // the number of microseconds an average disk I/O job @@ -241,6 +242,7 @@ namespace libtorrent // number of jobs waiting to be issued (m_to_issue) // average over 30 seconds + // deprecated, use session_stats_metrics "disk.queued_disk_jobs" int queued_jobs; // largest ever seen number of queued jobs diff --git a/include/libtorrent/session_status.hpp b/include/libtorrent/session_status.hpp index f6aa24760..f4e28d235 100644 --- a/include/libtorrent/session_status.hpp +++ b/include/libtorrent/session_status.hpp @@ -87,23 +87,31 @@ namespace libtorrent // the total download and upload rates accumulated // from all torrents. This includes bittorrent protocol, DHT and an estimated TCP/IP // protocol overhead. + // deprecated, use session_stats_metrics "net.recv_bytes" and "net.send_bytes" + // they does include payload + protocol bytes but does not include ip protocol bytes int upload_rate; int download_rate; // the total number of bytes downloaded and // uploaded to and from all torrents. This also includes all the protocol overhead. + // deprecated, use session_stats_metrics "net.recv_bytes" and "net.send_bytes" + // they does include payload + protocol bytes but does not include ip protocol bytes boost::int64_t total_download; boost::int64_t total_upload; // the rate of the payload // down- and upload only. + // deprecated, use session_stats_metrics "net.recv_payload_bytes" int payload_upload_rate; + // deprecated, use session_stats_metrics "net.sent_payload_bytes" int payload_download_rate; // the total transfers of payload // only. The payload does not include the bittorrent protocol overhead, but only parts of the // actual files to be downloaded. + // deprecated, use session_stats_metrics "net.recv_payload_bytes" boost::int64_t total_payload_download; + // deprecated, use session_stats_metrics "net.sent_payload_bytes" boost::int64_t total_payload_upload; // the estimated TCP/IP overhead in each direction. @@ -181,6 +189,7 @@ namespace libtorrent // ``dht_node_cache`` is set to the number of nodes in the node cache. These nodes // are used to replace the regular nodes in the routing table in case any of them // becomes unresponsive. + // deprecated, use session_stats_metrics "dht.dht_nodes" and "dht.dht_nodes_cache" int dht_nodes; int dht_node_cache; From 564fbea0654b27a41a9c7486f4eaa4e0bc53789f Mon Sep 17 00:00:00 2001 From: Falcosc Date: Sat, 14 Jan 2017 18:58:44 +0100 Subject: [PATCH 08/10] Docu for deprecated (#1551) documentation for deprecated members --- include/libtorrent/session_status.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/libtorrent/session_status.hpp b/include/libtorrent/session_status.hpp index f4e28d235..abf1b9326 100644 --- a/include/libtorrent/session_status.hpp +++ b/include/libtorrent/session_status.hpp @@ -87,15 +87,15 @@ namespace libtorrent // the total download and upload rates accumulated // from all torrents. This includes bittorrent protocol, DHT and an estimated TCP/IP // protocol overhead. - // deprecated, use session_stats_metrics "net.recv_bytes" and "net.send_bytes" - // they does include payload + protocol bytes but does not include ip protocol bytes + // deprecated, use session_stats_metrics "net.recv_bytes" + "net.recv_ip_overhead_bytes" + // they does include payload + protocol + ip overhead bytes int upload_rate; int download_rate; // the total number of bytes downloaded and // uploaded to and from all torrents. This also includes all the protocol overhead. - // deprecated, use session_stats_metrics "net.recv_bytes" and "net.send_bytes" - // they does include payload + protocol bytes but does not include ip protocol bytes + // deprecated, use session_stats_metrics "net.recv_bytes" + "net.recv_ip_overhead_bytes" + // they does include payload + protocol + ip overhead bytes boost::int64_t total_download; boost::int64_t total_upload; From febcbbf17cdc6b2552df2aa9b17d91c4108c3989 Mon Sep 17 00:00:00 2001 From: arvidn Date: Sat, 14 Jan 2017 12:57:49 -0500 Subject: [PATCH 09/10] fix make_torrent.py to not use deprecated functions --- bindings/python/make_torrent.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bindings/python/make_torrent.py b/bindings/python/make_torrent.py index 0bf96b241..030175454 100755 --- a/bindings/python/make_torrent.py +++ b/bindings/python/make_torrent.py @@ -5,7 +5,7 @@ import os import libtorrent if len(sys.argv) < 3: - print 'usage make_torrent.py file tracker-url' + print('usage make_torrent.py file tracker-url') sys.exit(1) input = os.path.abspath(sys.argv[1]) @@ -32,22 +32,22 @@ for root, dirs, files in os.walk(input): fname = os.path.join(root[len(parent_input)+1:], f) size = os.path.getsize(os.path.join(parent_input, fname)) - print '%10d kiB %s' % (size / 1024, fname) + print('%10d kiB %s' % (size / 1024, fname)) fs.add_file(fname, size); if fs.num_files() == 0: - print 'no files added' + print('no files added') sys.exit(1) t = libtorrent.create_torrent(fs, 0, 4 * 1024 * 1024) t.add_tracker(sys.argv[2]) -t.set_creator('libtorrent %s' % libtorrent.version) +t.set_creator('libtorrent %s' % libtorrent.__version__) libtorrent.set_piece_hashes(t, parent_input, lambda x: sys.stderr.write('.')) sys.stderr.write('\n') f = open('out.torrent', 'wb+') -print >>f, libtorrent.bencode(t.generate()) +f.write(libtorrent.bencode(t.generate())) f.close() From de499310f515cdfc8b0d722b6cecd2a79c1f8944 Mon Sep 17 00:00:00 2001 From: Calum Lind Date: Sat, 14 Jan 2017 18:58:57 +0000 Subject: [PATCH 10/10] [#1217] Fix RuntimeWarning registering pointer with Python This fix checks for existing registered pointers for alert so that Boost does not output the following warning when importing libtorrent in Python: > RuntimeWarning: to-Python converter for boost::shared_ptrlibtorrent::alert already registered; second conversion method ignored. --- bindings/python/src/alert.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bindings/python/src/alert.cpp b/bindings/python/src/alert.cpp index 7f4541775..9dc16fc9e 100644 --- a/bindings/python/src/alert.cpp +++ b/bindings/python/src/alert.cpp @@ -170,9 +170,11 @@ void bind_alert() using boost::noncopyable; #ifndef TORRENT_NO_DEPRECATE typedef boost::shared_ptr alert_holder; -#if BOOST_VERSION >= 106000 - register_ptr_to_python >(); -#endif + + if (boost::python::converter::registry::query( + boost::python::type_id >()) == NULL) { + register_ptr_to_python >(); + } #else typedef alert alert_holder; #endif @@ -663,7 +665,7 @@ void bind_alert() ; class_, noncopyable>( "torrent_need_cert_alert", no_init) - .def_readonly("error", &torrent_need_cert_alert::error) + .def_readonly("error", &torrent_need_cert_alert::error) ; class_, noncopyable>(