diff --git a/ChangeLog b/ChangeLog index 6b1841658..cfde3cc00 100644 --- a/ChangeLog +++ b/ChangeLog @@ -50,6 +50,7 @@ * resume data no longer has timestamps of files * require C++11 to build libtorrent + * 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/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() diff --git a/bindings/python/src/create_torrent.cpp b/bindings/python/src/create_torrent.cpp index 17d79e71f..3118e5f71 100644 --- a/bindings/python/src/create_torrent.cpp +++ b/bindings/python/src/create_torrent.cpp @@ -184,7 +184,7 @@ void bind_create_torrent() .value("flag_hidden", file_storage::flag_hidden) .value("flag_executable", file_storage::flag_executable) .value("flag_symlink", file_storage::flag_symlink) - ; + ; class_("create_torrent", no_init) .def(init()) diff --git a/bindings/python/src/string.cpp b/bindings/python/src/string.cpp index 03406b3da..c5674b653 100644 --- a/bindings/python/src/string.cpp +++ b/bindings/python/src/string.cpp @@ -19,7 +19,7 @@ struct unicode_from_python static void* convertible(PyObject* x) { #if PY_VERSION_HEX >= 0x03020000 - return PyBytes_Check(x) ? x : PyUnicode_Check(x) ? x : 0; + return PyBytes_Check(x) ? x : PyUnicode_Check(x) ? x : nullptr; #else return PyString_Check(x) ? x : PyUnicode_Check(x) ? x : nullptr; #endif @@ -44,7 +44,7 @@ struct unicode_from_python , PyBytes_Size(utf8)); #else new (storage) std::string(PyString_AsString(utf8) - , PyString_Size(utf8)); + , PyString_Size(utf8)); #endif Py_DECREF(utf8); } @@ -52,7 +52,8 @@ struct unicode_from_python else { #if PY_VERSION_HEX >= 0x03000000 - new (storage) std::string(PyBytes_AsString(x), PyBytes_Size(x)); + new (storage) std::string(PyBytes_AsString(x) + , PyBytes_Size(x)); #else new (storage) std::string(PyString_AsString(x) , PyString_Size(x)); diff --git a/configure.ac b/configure.ac index f5275dcf3..5d12384da 100644 --- a/configure.ac +++ b/configure.ac @@ -527,8 +527,8 @@ AC_SUBST(COMPILETIME_OPTIONS) # 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' include/libtorrent/version.hpp`]) +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`]) ############################################################################### diff --git a/docs/gen_stats_doc.py b/docs/gen_stats_doc.py index 16093a476..0925c0b61 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 diff --git a/include/libtorrent/disk_io_thread.hpp b/include/libtorrent/disk_io_thread.hpp index b27cf9e23..2d9546a99 100644 --- a/include/libtorrent/disk_io_thread.hpp +++ b/include/libtorrent/disk_io_thread.hpp @@ -195,6 +195,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 @@ -237,6 +238,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_stats.hpp b/include/libtorrent/session_stats.hpp index c2e8a91a8..dc03737a6 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 diff --git a/include/libtorrent/session_status.hpp b/include/libtorrent/session_status.hpp index ef61c269f..1d708762a 100644 --- a/include/libtorrent/session_status.hpp +++ b/include/libtorrent/session_status.hpp @@ -87,22 +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" + "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" + "net.recv_ip_overhead_bytes" + // they does include payload + protocol + ip overhead bytes std::int64_t total_download; std::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. + // ``total_payload_download`` is deprecated, use session_stats_metrics + // "net.recv_payload_bytes" ``total_payload_upload`` is deprecated, use + // session_stats_metrics "net.sent_payload_bytes" std::int64_t total_payload_download; std::int64_t total_payload_upload; @@ -181,6 +190,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; diff --git a/include/libtorrent/stat.hpp b/include/libtorrent/stat.hpp index e20cbf1fb..5657657d3 100644 --- a/include/libtorrent/stat.hpp +++ b/include/libtorrent/stat.hpp @@ -252,6 +252,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/file_storage.cpp b/src/file_storage.cpp index 8c679586b..d68e70f13 100644 --- a/src/file_storage.cpp +++ b/src/file_storage.cpp @@ -138,9 +138,9 @@ namespace libtorrent } if (branch_len >= int(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 = int(m_name.size()) + (int(m_name.size()) == branch_len ? 0 : 1); branch_path += offset; diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 2ce0322dc..efb403801 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -3007,16 +3007,39 @@ namespace aux { 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); } @@ -4524,12 +4547,6 @@ namespace aux { 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 @@ -5433,9 +5450,9 @@ namespace aux { // 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]; diff --git a/test/test.cpp b/test/test.cpp index e3f14ccd7..ba224b21a 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]; std::snprintf(buf, sizeof(buf), "\x1b[41m***** %s:%d \"%s\" *****\x1b[0m\n", file, line, err); - std::printf("\n%s\n", buf); + std::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 0b8f94455..231e3488c 100644 --- a/test/test_file_storage.cpp +++ b/test/test_file_storage.cpp @@ -96,6 +96,10 @@ TORRENT_TEST(rename_file) st.rename_file(file_index_t{0}, "/tmp/a"); TEST_EQUAL(st.file_path(file_index_t{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) diff --git a/test/test_storage.cpp b/test/test_storage.cpp index acdb4003f..6eec54b30 100644 --- a/test/test_storage.cpp +++ b/test/test_storage.cpp @@ -761,11 +761,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); @@ -789,14 +785,14 @@ TORRENT_TEST(rename_file) for (file_index_t i(0); i < fs.end_file(); ++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); @@ -809,7 +805,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__"); } }