From 894933e1f1b0e435a5987876752a19b6d587e2a2 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Thu, 3 May 2018 01:06:01 +0200 Subject: [PATCH 1/5] fix typo in comment --- include/libtorrent/alert_manager.hpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/include/libtorrent/alert_manager.hpp b/include/libtorrent/alert_manager.hpp index 6c7ead1c0..beac278fd 100644 --- a/include/libtorrent/alert_manager.hpp +++ b/include/libtorrent/alert_manager.hpp @@ -165,9 +165,7 @@ namespace libtorrent { // this mutex protects everything. Since it's held while executing user // callbacks (the notify function and extension on_alert()) it must be - // recursive to post new alerts. This is implemented by storing the - // current thread-id in m_mutex_holder, if it matches ours, we don't need - // to lock + // recursive to support recursively post new alerts. mutable recursive_mutex m_mutex; condition_variable m_condition; boost::uint32_t m_alert_mask; From dc28c965597d824a053527c3d8aaa76ece00e171 Mon Sep 17 00:00:00 2001 From: d-komarov Date: Sun, 6 May 2018 22:53:34 +0300 Subject: [PATCH 2/5] Fix unit tests build Export `recursive_mutex` because `emplace_alert` template injects dependency on that type during instatiation. --- include/libtorrent/thread.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/libtorrent/thread.hpp b/include/libtorrent/thread.hpp index 616a2cad6..fd7455a33 100644 --- a/include/libtorrent/thread.hpp +++ b/include/libtorrent/thread.hpp @@ -67,7 +67,7 @@ namespace libtorrent // internal void sleep(int milliseconds); - struct recursive_mutex; + struct TORRENT_EXTRA_EXPORT recursive_mutex; struct TORRENT_EXTRA_EXPORT condition_variable { @@ -108,7 +108,7 @@ namespace libtorrent #endif // internal - struct recursive_mutex + struct TORRENT_EXTRA_EXPORT recursive_mutex { typedef boost::asio::detail::scoped_lock scoped_lock; From fe25b50b1affc9b1e982e6ba7fb5d102e56eed6c Mon Sep 17 00:00:00 2001 From: arvidn Date: Thu, 10 May 2018 11:11:06 +0200 Subject: [PATCH 3/5] update libsimulator with a fix for boost-1.66 --- simulation/libsimulator | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simulation/libsimulator b/simulation/libsimulator index 5a5e25005..8209dcf79 160000 --- a/simulation/libsimulator +++ b/simulation/libsimulator @@ -1 +1 @@ -Subproject commit 5a5e25005fb449c8a90b7f2c642dce48a64a9f68 +Subproject commit 8209dcf79b7ca8769165c240d8a6962b8574dd27 From 299a54564859f5deb9b9822b9575563963aa48d6 Mon Sep 17 00:00:00 2001 From: arvidn Date: Thu, 10 May 2018 12:13:59 +0200 Subject: [PATCH 4/5] add test for suggests- and seed mode combined --- simulation/test_swarm.cpp | 23 ++++++++++++++++++++++- src/disk_io_thread.cpp | 2 -- src/peer_connection.cpp | 1 - 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/simulation/test_swarm.cpp b/simulation/test_swarm.cpp index 378061d29..8d85b6c38 100644 --- a/simulation/test_swarm.cpp +++ b/simulation/test_swarm.cpp @@ -58,6 +58,25 @@ TORRENT_TEST(seed_mode) { return true; }); } +TORRENT_TEST(seed_mode_suggest) +{ + setup_swarm(2, swarm_test::upload + // add session + , [](lt::settings_pack& pack) { + pack.set_int(settings_pack::suggest_mode, settings_pack::suggest_read_cache); + pack.set_int(settings_pack::cache_size, 2); + } + // add torrent + , [](lt::add_torrent_params& params) { + params.flags |= add_torrent_params::flag_seed_mode; + } + // on alert + , [](lt::alert const* a, lt::session& ses) {} + // terminate + , [](int ticks, lt::session& ses) -> bool + { return true; }); +} + TORRENT_TEST(plain) { setup_swarm(2, swarm_test::download @@ -129,6 +148,7 @@ TORRENT_TEST(suggest) // add session , [](lt::settings_pack& pack) { pack.set_int(settings_pack::suggest_mode, settings_pack::suggest_read_cache); + pack.set_int(settings_pack::cache_size, 2); } // add torrent , [](lt::add_torrent_params& params) {} @@ -311,10 +331,11 @@ TORRENT_TEST(stop_start_seed_graceful) #ifndef TORRENT_NO_DEPRECATE TORRENT_TEST(explicit_cache) { - setup_swarm(2, swarm_test::download + setup_swarm(4, swarm_test::download // add session , [](lt::settings_pack& pack) { pack.set_int(settings_pack::suggest_mode, settings_pack::suggest_read_cache); + pack.set_int(settings_pack::cache_size, 2); pack.set_bool(settings_pack::explicit_read_cache, true); pack.set_int(settings_pack::explicit_cache_interval, 5); } diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index a6189c26f..deb02a446 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -2685,8 +2685,6 @@ namespace libtorrent #if TORRENT_USE_ASSERTS pe->piece_log.push_back(piece_log_t(j->action)); #endif - TORRENT_PIECE_ASSERT(pe->cache_state <= cached_piece_entry::read_lru1 - || pe->cache_state == cached_piece_entry::read_lru2, pe); ++pe->piece_refcount; int block_size = m_disk_cache.block_size(); diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 8d6601278..14961345e 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -3832,7 +3832,6 @@ namespace libtorrent } #endif - if (m_sent_suggested_pieces.empty()) { boost::shared_ptr t = m_torrent.lock(); From a2c6136f4493d7b10320a85e9a40b5c57072e0ac Mon Sep 17 00:00:00 2001 From: arvidn Date: Thu, 10 May 2018 13:47:40 +0200 Subject: [PATCH 5/5] add round-trip test to create_torrent --- test/test_create_torrent.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/test_create_torrent.cpp b/test/test_create_torrent.cpp index 5f1e38d29..226294843 100644 --- a/test/test_create_torrent.cpp +++ b/test/test_create_torrent.cpp @@ -35,6 +35,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/torrent_info.hpp" #include "libtorrent/create_torrent.hpp" #include "libtorrent/bencode.hpp" +#include "libtorrent/announce_entry.hpp" #include "libtorrent/aux_/escape_string.hpp" // for convert_path_to_posix #include #include @@ -65,3 +66,23 @@ TORRENT_TEST(create_verbatim_torrent) TEST_CHECK(memcmp(dest_info, test_torrent + 1, sizeof(test_torrent)-3) == 0); } +TORRENT_TEST(create_torrent_round_trip) +{ + char const test_torrent[] = "d8:announce26:udp://testurl.com/announce7:comment22:this is a test comment13:creation datei1337e4:infod6:lengthi12345e4:name6:foobar12:piece lengthi65536e6:pieces20:ababababababababababee"; + lt::torrent_info info1(test_torrent, sizeof(test_torrent) - 1); + TEST_EQUAL(info1.comment(), "this is a test comment"); + TEST_EQUAL(info1.trackers().size(), 1); + TEST_EQUAL(info1.trackers().front().url, "udp://testurl.com/announce"); + + lt::create_torrent t(info1, true); + + std::vector buffer; + lt::bencode(std::back_inserter(buffer), t.generate()); + lt::torrent_info info2(&buffer[0], buffer.size()); + + TEST_EQUAL(info2.comment(), "this is a test comment"); + TEST_EQUAL(info2.trackers().size(), 1); + TEST_EQUAL(info2.trackers().front().url, "udp://testurl.com/announce"); + TEST_CHECK(info1.info_hash() == info2.info_hash()); +} +