diff --git a/ChangeLog b/ChangeLog index b4d715ed0..40b689895 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + * fix error in seed_mode flag * support magnet link parameters with number siffixes * consistently use "lt" namespace in examples and documentation * fix Mingw build to use native cryptoAPI diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index d321a6d3d..01eb315e8 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -67,7 +67,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/linked_list.hpp" #include "libtorrent/debug.hpp" #include "libtorrent/piece_block.hpp" -#include "libtorrent/disk_interface.hpp" // for status_t +#include "libtorrent/disk_interface.hpp" #include "libtorrent/aux_/file_progress.hpp" #include "libtorrent/aux_/suggest_piece.hpp" #include "libtorrent/units.hpp" diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index 32dfdd915..2a5d42a82 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -2530,14 +2530,15 @@ constexpr disk_job_flags_t disk_interface::cache_hit; TORRENT_ASSERT(j->storage->files().piece_length() > 0); + bool const verify_success = j->storage->verify_resume_data(*rd + , links ? *links : aux::vector(), j->error); + // if we don't have any resume data, return // or if error is set and return value is 'no_error' or 'need_full_check' // the error message indicates that the fast resume data was rejected // if 'fatal_disk_error' is returned, the error message indicates what // when wrong in the disk access - if ((rd->have_pieces.empty() - || !j->storage->verify_resume_data(*rd - , links ? *links : aux::vector(), j->error)) + if ((rd->have_pieces.empty() || !verify_success) && !m_settings.get_bool(settings_pack::no_recheck_incomplete_resume)) { // j->error may have been set at this point, by verify_resume_data() diff --git a/src/storage_utils.cpp b/src/storage_utils.cpp index a7bfa469b..132b2af33 100644 --- a/src/storage_utils.cpp +++ b/src/storage_utils.cpp @@ -472,6 +472,7 @@ namespace libtorrent { namespace aux { #ifdef TORRENT_DISABLE_MUTABLE_TORRENTS TORRENT_UNUSED(links); #else + // TODO: this should probably be moved to default_storage::initialize if (!links.empty()) { TORRENT_ASSERT(int(links.size()) == fs.num_files()); diff --git a/src/torrent.cpp b/src/torrent.cpp index 97a7a3f44..ee9c6b18f 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -2075,8 +2075,11 @@ bool is_downloading_state(int const st) { if (status != status_t::no_error || error) { - debug_log("fastresume data rejected: ret: %d (%d) %s" - , static_cast(status), error.ec.value(), error.ec.message().c_str()); + debug_log("fastresume data rejected: ret: %d (%d) op: %s file: %d %s" + , static_cast(status), error.ec.value() + , operation_name(error.operation) + , static_cast(error.file()) + , error.ec.message().c_str()); } else { @@ -2085,7 +2088,8 @@ bool is_downloading_state(int const st) } #endif - bool should_start_full_check = status != status_t::no_error; + bool should_start_full_check = (status != status_t::no_error) + && !m_seed_mode; // if we got a partial pieces bitfield, it means we were in the middle of // checking this torrent. pick it up where we left off diff --git a/test/setup_transfer.cpp b/test/setup_transfer.cpp index 8714e2eb8..c892083b0 100644 --- a/test/setup_transfer.cpp +++ b/test/setup_transfer.cpp @@ -66,8 +66,18 @@ using namespace lt; #include #endif -std::shared_ptr generate_torrent() +std::shared_ptr generate_torrent(bool const with_files) { + if (with_files) + { + error_code ec; + create_directories("test_resume", ec); + std::vector a(128 * 1024 * 8); + std::vector b(128 * 1024); + std::ofstream("test_resume/tmp1").write(a.data(), std::streamsize(a.size())); + std::ofstream("test_resume/tmp2").write(b.data(), std::streamsize(b.size())); + std::ofstream("test_resume/tmp3").write(b.data(), std::streamsize(b.size())); + } file_storage fs; fs.add_file("test_resume/tmp1", 128 * 1024 * 8); fs.add_file("test_resume/tmp2", 128 * 1024); diff --git a/test/setup_transfer.hpp b/test/setup_transfer.hpp index dc8f2b0ae..6aebb4aa8 100644 --- a/test/setup_transfer.hpp +++ b/test/setup_transfer.hpp @@ -40,7 +40,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/units.hpp" #include "libtorrent/fwd.hpp" -EXPORT std::shared_ptr generate_torrent(); +EXPORT std::shared_ptr generate_torrent(bool with_files = false); EXPORT int print_failures(); diff --git a/test/test_resume.cpp b/test/test_resume.cpp index dbcd7e32d..153045397 100644 --- a/test/test_resume.cpp +++ b/test/test_resume.cpp @@ -460,7 +460,7 @@ TORRENT_TEST(file_priorities_override_resume_deprecated) TEST_EQUAL(file_priorities[2], 3); } -TORRENT_TEST(file_priorities_resume_seed_mode_deprecated) +TORRENT_TEST(file_priorities_resume_share_mode_deprecated) { // in share mode file priorities should always be 0 lt::session ses(settings()); @@ -473,7 +473,7 @@ TORRENT_TEST(file_priorities_resume_seed_mode_deprecated) TEST_EQUAL(file_priorities[2], 0); } -TORRENT_TEST(file_priorities_seed_mode_deprecated) +TORRENT_TEST(file_priorities_share_mode_deprecated) { // in share mode file priorities should always be 0 lt::session ses(settings()); @@ -782,7 +782,7 @@ TORRENT_TEST(file_priorities_default) TEST_EQUAL(file_priorities[2], 4_pri); } -TORRENT_TEST(file_priorities_resume_seed_mode) +TORRENT_TEST(file_priorities_resume_share_mode) { // in share mode file priorities should always be 0 lt::session ses(settings()); @@ -795,7 +795,7 @@ TORRENT_TEST(file_priorities_resume_seed_mode) TEST_EQUAL(file_priorities[2], 0_pri); } -TORRENT_TEST(file_priorities_seed_mode) +TORRENT_TEST(file_priorities_share_mode) { // in share mode file priorities should always be 0 lt::session ses(settings()); @@ -953,7 +953,7 @@ namespace { void test_seed_mode(test_mode_t const flags) { lt::session ses(settings()); - std::shared_ptr ti = generate_torrent(); + std::shared_ptr ti = generate_torrent(true); add_torrent_params p; p.ti = ti; p.save_path = "."; @@ -979,19 +979,19 @@ void test_seed_mode(test_mode_t const flags) } } - std::string pieces(std::size_t(ti->num_pieces()), '\x01'); if (flags & test_mode::pieces_have) { + std::string pieces(std::size_t(ti->num_pieces()), '\x01'); pieces[0] = '\0'; + rd["pieces"] = pieces; } - rd["pieces"] = pieces; - std::string pieces_prio(std::size_t(ti->num_pieces()), '\x01'); if (flags & test_mode::piece_prio) { + std::string pieces_prio(std::size_t(ti->num_pieces()), '\x01'); pieces_prio[0] = '\0'; + rd["piece_priority"] = pieces_prio; } - rd["piece_priority"] = pieces_prio; rd["seed_mode"] = 1; @@ -1015,15 +1015,54 @@ void test_seed_mode(test_mode_t const flags) torrent_handle h = ses.add_torrent(p); - torrent_status s = h.status(); if (flags & (test_mode::file_prio | test_mode::piece_prio | test_mode::pieces_have)) { + std::vector alerts; + bool done = false; + auto const start_time = lt::clock_type::now(); + while (!done) + { + ses.wait_for_alert(seconds(1)); + ses.pop_alerts(&alerts); + for (auto a : alerts) + { + std::printf("%s\n", a->message().c_str()); + if (auto const* sca = alert_cast(a)) + { + TEST_CHECK(sca->state != torrent_status::seeding); + if (sca->state == torrent_status::downloading) done = true; + } + } + if (lt::clock_type::now() - start_time > seconds(5)) break; + } + TEST_CHECK(done); + torrent_status const s = h.status(); TEST_CHECK(!(s.flags & torrent_flags::seed_mode)); } else { + std::vector alerts; + bool done = false; + auto const start_time = lt::clock_type::now(); + while (!done) + { + ses.wait_for_alert(seconds(1)); + ses.pop_alerts(&alerts); + for (auto a : alerts) + { + std::printf("%s\n", a->message().c_str()); + if (auto const* sca = alert_cast(a)) + { + TEST_CHECK(sca->state != torrent_status::checking_files); + if (sca->state == torrent_status::seeding) done = true; + } + } + if (lt::clock_type::now() - start_time > seconds(5)) break; + } + TEST_CHECK(done); + torrent_status const s = h.status(); TEST_CHECK(s.flags & torrent_flags::seed_mode); } }