fix seed_mode flag
This commit is contained in:
parent
3891f77253
commit
4473a8d0ce
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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<std::string, file_index_t>(), 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<std::string, file_index_t>(), 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()
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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<int>(status), error.ec.value(), error.ec.message().c_str());
|
||||
debug_log("fastresume data rejected: ret: %d (%d) op: %s file: %d %s"
|
||||
, static_cast<int>(status), error.ec.value()
|
||||
, operation_name(error.operation)
|
||||
, static_cast<int>(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
|
||||
|
|
|
@ -66,8 +66,18 @@ using namespace lt;
|
|||
#include <conio.h>
|
||||
#endif
|
||||
|
||||
std::shared_ptr<torrent_info> generate_torrent()
|
||||
std::shared_ptr<torrent_info> generate_torrent(bool const with_files)
|
||||
{
|
||||
if (with_files)
|
||||
{
|
||||
error_code ec;
|
||||
create_directories("test_resume", ec);
|
||||
std::vector<char> a(128 * 1024 * 8);
|
||||
std::vector<char> 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);
|
||||
|
|
|
@ -40,7 +40,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/units.hpp"
|
||||
#include "libtorrent/fwd.hpp"
|
||||
|
||||
EXPORT std::shared_ptr<lt::torrent_info> generate_torrent();
|
||||
EXPORT std::shared_ptr<lt::torrent_info> generate_torrent(bool with_files = false);
|
||||
|
||||
EXPORT int print_failures();
|
||||
|
||||
|
|
|
@ -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<torrent_info> ti = generate_torrent();
|
||||
std::shared_ptr<torrent_info> 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<alert*> 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<state_changed_alert>(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<alert*> 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<state_changed_alert>(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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue