2014-07-06 21:18:00 +02:00
|
|
|
/*
|
|
|
|
|
|
|
|
Copyright (c) 2012, Arvid Norberg
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions
|
|
|
|
are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
* Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in
|
|
|
|
the documentation and/or other materials provided with the distribution.
|
|
|
|
* Neither the name of the author nor the names of its
|
|
|
|
contributors may be used to endorse or promote products derived
|
|
|
|
from this software without specific prior written permission.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "libtorrent/session.hpp"
|
|
|
|
#include "libtorrent/session_settings.hpp"
|
|
|
|
#include "libtorrent/alert_types.hpp"
|
|
|
|
#include "libtorrent/bencode.hpp"
|
|
|
|
#include "libtorrent/time.hpp"
|
2017-04-11 06:52:46 +02:00
|
|
|
#include "libtorrent/aux_/path.hpp"
|
2014-07-06 21:18:00 +02:00
|
|
|
#include "libtorrent/error_code.hpp"
|
2016-06-20 17:32:06 +02:00
|
|
|
#include <tuple>
|
2016-05-25 06:31:52 +02:00
|
|
|
#include <functional>
|
2014-07-06 21:18:00 +02:00
|
|
|
|
|
|
|
#include "test.hpp"
|
|
|
|
#include "setup_transfer.hpp"
|
2018-09-22 02:25:56 +02:00
|
|
|
#include "settings.hpp"
|
2014-07-06 21:18:00 +02:00
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
#include <iostream>
|
|
|
|
|
2017-04-12 20:05:53 +02:00
|
|
|
using namespace lt;
|
2014-07-06 21:18:00 +02:00
|
|
|
|
2018-01-23 20:56:03 +01:00
|
|
|
namespace {
|
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
void wait_for_complete(lt::session& ses, torrent_handle h)
|
|
|
|
{
|
2016-03-03 03:35:08 +01:00
|
|
|
int last_progress = 0;
|
|
|
|
clock_type::time_point last_change = clock_type::now();
|
2016-07-03 04:32:35 +02:00
|
|
|
for (int i = 0; i < 200; ++i)
|
2014-07-06 21:18:00 +02:00
|
|
|
{
|
|
|
|
print_alerts(ses, "ses1");
|
|
|
|
torrent_status st = h.status();
|
2016-10-10 02:23:45 +02:00
|
|
|
std::printf("%f s - %f %%\n"
|
2018-01-29 12:40:44 +01:00
|
|
|
, total_milliseconds(clock_type::now() - last_change) / 1000.0
|
|
|
|
, st.progress_ppm / 10000.0);
|
2014-07-06 21:18:00 +02:00
|
|
|
if (st.progress_ppm == 1000000) return;
|
2016-03-03 03:35:08 +01:00
|
|
|
if (st.progress_ppm != last_progress)
|
|
|
|
{
|
|
|
|
last_progress = st.progress_ppm;
|
|
|
|
last_change = clock_type::now();
|
|
|
|
}
|
2016-07-03 04:32:35 +02:00
|
|
|
if (clock_type::now() - last_change > seconds(20)) break;
|
|
|
|
std::this_thread::sleep_for(lt::seconds(1));
|
2014-07-06 21:18:00 +02:00
|
|
|
}
|
2015-05-30 23:46:59 +02:00
|
|
|
TEST_ERROR("torrent did not finish");
|
2014-07-06 21:18:00 +02:00
|
|
|
}
|
|
|
|
|
2018-01-23 20:56:03 +01:00
|
|
|
} // anonymous namespace
|
|
|
|
|
2015-05-30 06:31:23 +02:00
|
|
|
TORRENT_TEST(recheck)
|
2014-07-06 21:18:00 +02:00
|
|
|
{
|
|
|
|
error_code ec;
|
2018-09-22 02:25:56 +02:00
|
|
|
settings_pack sett = settings();
|
2015-06-05 08:31:52 +02:00
|
|
|
sett.set_str(settings_pack::listen_interfaces, "0.0.0.0:48675");
|
2015-07-28 14:04:51 +02:00
|
|
|
sett.set_bool(settings_pack::enable_upnp, false);
|
|
|
|
sett.set_bool(settings_pack::enable_natpmp, false);
|
|
|
|
sett.set_bool(settings_pack::enable_lsd, false);
|
|
|
|
sett.set_bool(settings_pack::enable_dht, false);
|
2015-06-05 08:31:52 +02:00
|
|
|
lt::session ses1(sett);
|
2014-07-06 21:18:00 +02:00
|
|
|
create_directory("tmp1_recheck", ec);
|
2016-10-10 02:23:45 +02:00
|
|
|
if (ec) std::printf("create_directory: %s\n", ec.message().c_str());
|
2014-07-06 21:18:00 +02:00
|
|
|
std::ofstream file("tmp1_recheck/temporary");
|
2016-08-17 23:26:35 +02:00
|
|
|
std::shared_ptr<torrent_info> t = ::create_torrent(&file, "temporary", 4 * 1024 * 1024
|
2015-07-29 01:18:15 +02:00
|
|
|
, 7, false);
|
2014-07-06 21:18:00 +02:00
|
|
|
file.close();
|
|
|
|
|
|
|
|
add_torrent_params param;
|
2017-07-09 16:32:01 +02:00
|
|
|
param.flags &= ~torrent_flags::paused;
|
|
|
|
param.flags &= ~torrent_flags::auto_managed;
|
2014-07-06 21:18:00 +02:00
|
|
|
param.ti = t;
|
|
|
|
param.save_path = "tmp1_recheck";
|
2017-07-09 16:32:01 +02:00
|
|
|
param.flags |= torrent_flags::seed_mode;
|
2014-07-06 21:18:00 +02:00
|
|
|
torrent_handle tor1 = ses1.add_torrent(param, ec);
|
2016-10-10 02:23:45 +02:00
|
|
|
if (ec) std::printf("add_torrent: %s\n", ec.message().c_str());
|
2014-07-06 21:18:00 +02:00
|
|
|
|
|
|
|
wait_for_listen(ses1, "ses1");
|
|
|
|
|
|
|
|
tor1.force_recheck();
|
|
|
|
|
|
|
|
torrent_status st1 = tor1.status();
|
|
|
|
TEST_CHECK(st1.progress_ppm <= 1000000);
|
|
|
|
wait_for_complete(ses1, tor1);
|
|
|
|
|
|
|
|
tor1.force_recheck();
|
|
|
|
|
|
|
|
st1 = tor1.status();
|
|
|
|
TEST_CHECK(st1.progress_ppm <= 1000000);
|
|
|
|
wait_for_complete(ses1, tor1);
|
|
|
|
}
|