2013-10-10 19:00:32 +02:00
|
|
|
/*
|
|
|
|
|
|
|
|
Copyright (c) 2008-2013, 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"
|
2015-09-18 06:23:45 +02:00
|
|
|
#include "libtorrent/torrent_info.hpp"
|
2016-02-16 07:43:06 +01:00
|
|
|
#include "libtorrent/read_resume_data.hpp"
|
2017-03-09 00:01:59 +01:00
|
|
|
#include "libtorrent/write_resume_data.hpp"
|
2016-06-20 17:32:06 +02:00
|
|
|
#include <tuple>
|
2016-05-25 06:31:52 +02:00
|
|
|
#include <functional>
|
2013-10-10 19:00:32 +02:00
|
|
|
|
|
|
|
#include "test.hpp"
|
|
|
|
#include "setup_transfer.hpp"
|
2016-08-21 18:15:19 +02:00
|
|
|
#include "settings.hpp"
|
2013-10-10 19:00:32 +02:00
|
|
|
#include <fstream>
|
|
|
|
#include <iostream>
|
|
|
|
|
2017-04-12 20:05:53 +02:00
|
|
|
using namespace lt;
|
2016-06-20 17:32:06 +02:00
|
|
|
using std::ignore;
|
2013-10-10 19:00:32 +02:00
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
const int mask = alert::all_categories & ~(alert::performance_warning | alert::stats_notification);
|
2013-10-10 19:00:32 +02:00
|
|
|
|
|
|
|
int peer_disconnects = 0;
|
|
|
|
|
2015-04-03 22:15:48 +02:00
|
|
|
bool on_alert(alert const* a)
|
2013-10-10 19:00:32 +02:00
|
|
|
{
|
2015-06-06 18:10:43 +02:00
|
|
|
if (alert_cast<peer_disconnected_alert>(a))
|
2013-10-10 19:00:32 +02:00
|
|
|
++peer_disconnects;
|
|
|
|
else if (alert_cast<peer_error_alert>(a))
|
|
|
|
++peer_disconnects;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-06-06 18:10:43 +02:00
|
|
|
void cleanup()
|
2013-10-10 19:00:32 +02:00
|
|
|
{
|
|
|
|
error_code ec;
|
2016-02-16 07:43:06 +01:00
|
|
|
remove_all("tmp1_priority", ec);
|
|
|
|
remove_all("tmp2_priority", ec);
|
|
|
|
remove_all("tmp1_priority_moved", ec);
|
|
|
|
remove_all("tmp2_priority_moved", ec);
|
2015-06-06 18:10:43 +02:00
|
|
|
}
|
|
|
|
|
2016-02-16 07:43:06 +01:00
|
|
|
void test_transfer(settings_pack const& sett, bool test_deprecated = false)
|
2015-06-06 18:10:43 +02:00
|
|
|
{
|
2015-08-20 22:11:04 +02:00
|
|
|
// this allows shutting down the sessions in parallel
|
|
|
|
std::vector<session_proxy> sp;
|
|
|
|
|
2015-06-06 18:10:43 +02:00
|
|
|
cleanup();
|
2013-10-10 19:00:32 +02:00
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
settings_pack pack = sett;
|
2014-11-09 12:17:13 +01:00
|
|
|
|
2013-10-10 19:00:32 +02:00
|
|
|
// we need a short reconnect time since we
|
|
|
|
// finish the torrent and then restart it
|
|
|
|
// immediately to complete the second half.
|
|
|
|
// using a reconnect time > 0 will just add
|
|
|
|
// to the time it will take to complete the test
|
2014-07-06 21:18:00 +02:00
|
|
|
pack.set_int(settings_pack::min_reconnect_time, 0);
|
|
|
|
|
|
|
|
pack.set_bool(settings_pack::enable_outgoing_utp, false);
|
|
|
|
pack.set_bool(settings_pack::enable_incoming_utp, false);
|
|
|
|
pack.set_int(settings_pack::alert_mask, mask);
|
|
|
|
|
|
|
|
pack.set_int(settings_pack::out_enc_policy, settings_pack::pe_disabled);
|
|
|
|
pack.set_int(settings_pack::in_enc_policy, settings_pack::pe_disabled);
|
|
|
|
pack.set_bool(settings_pack::allow_multiple_connections_per_ip, false);
|
|
|
|
pack.set_int(settings_pack::unchoke_slots_limit, 8);
|
|
|
|
|
2015-06-07 23:54:08 +02:00
|
|
|
pack.set_bool(settings_pack::enable_upnp, false);
|
|
|
|
pack.set_bool(settings_pack::enable_natpmp, false);
|
|
|
|
pack.set_bool(settings_pack::enable_lsd, false);
|
|
|
|
pack.set_bool(settings_pack::enable_dht, false);
|
|
|
|
|
2015-06-27 22:16:14 +02:00
|
|
|
pack.set_str(settings_pack::listen_interfaces, "0.0.0.0:48075");
|
|
|
|
pack.set_int(settings_pack::alert_mask, mask);
|
|
|
|
|
|
|
|
lt::session ses1(pack);
|
|
|
|
|
|
|
|
pack.set_str(settings_pack::listen_interfaces, "0.0.0.0:49075");
|
|
|
|
pack.set_int(settings_pack::alert_mask, mask);
|
|
|
|
lt::session ses2(pack);
|
2013-10-10 19:00:32 +02:00
|
|
|
|
|
|
|
torrent_handle tor1;
|
|
|
|
torrent_handle tor2;
|
|
|
|
|
2015-06-06 18:10:43 +02:00
|
|
|
error_code ec;
|
2013-10-10 19:00:32 +02:00
|
|
|
create_directory("tmp1_priority", ec);
|
|
|
|
std::ofstream file("tmp1_priority/temporary");
|
2016-08-17 23:26:35 +02:00
|
|
|
std::shared_ptr<torrent_info> t = ::create_torrent(&file, "temporary", 16 * 1024, 13, false);
|
2013-10-10 19:00:32 +02:00
|
|
|
file.close();
|
|
|
|
|
|
|
|
wait_for_listen(ses1, "ses1");
|
|
|
|
wait_for_listen(ses2, "ses1");
|
|
|
|
|
|
|
|
peer_disconnects = 0;
|
|
|
|
|
|
|
|
// test using piece sizes smaller than 16kB
|
2016-07-09 22:26:26 +02:00
|
|
|
std::tie(tor1, tor2, ignore) = setup_transfer(&ses1, &ses2, nullptr
|
|
|
|
, true, false, true, "_priority", 8 * 1024, &t, false, nullptr);
|
2013-10-10 19:00:32 +02:00
|
|
|
|
2016-12-22 16:42:33 +01:00
|
|
|
int const num_pieces = tor2.torrent_file()->num_pieces();
|
|
|
|
aux::vector<int, piece_index_t> priorities(num_pieces, 1);
|
2013-10-10 19:00:32 +02:00
|
|
|
// set half of the pieces to priority 0
|
|
|
|
std::fill(priorities.begin(), priorities.begin() + (num_pieces / 2), 0);
|
|
|
|
tor2.prioritize_pieces(priorities);
|
2017-01-02 16:16:33 +01:00
|
|
|
std::cout << "setting priorities: ";
|
|
|
|
std::copy(priorities.begin(), priorities.end(), std::ostream_iterator<int>(std::cout, ", "));
|
|
|
|
std::cout << std::endl;
|
2013-10-10 19:00:32 +02:00
|
|
|
|
|
|
|
for (int i = 0; i < 200; ++i)
|
|
|
|
{
|
2017-04-02 20:22:17 +02:00
|
|
|
print_alerts(ses1, "ses1", true, true, &on_alert);
|
|
|
|
print_alerts(ses2, "ses2", true, true, &on_alert);
|
2013-10-10 19:00:32 +02:00
|
|
|
|
|
|
|
torrent_status st1 = tor1.status();
|
|
|
|
torrent_status st2 = tor2.status();
|
|
|
|
|
|
|
|
if (i % 10 == 0)
|
|
|
|
{
|
|
|
|
print_ses_rate(i / 10.f, &st1, &st2);
|
|
|
|
}
|
|
|
|
|
|
|
|
// st2 is finished when we have downloaded half of the pieces
|
|
|
|
if (st2.is_finished) break;
|
|
|
|
|
|
|
|
if (st2.state != torrent_status::downloading)
|
|
|
|
{
|
2015-08-20 22:11:04 +02:00
|
|
|
static char const* state_str[] =
|
2013-10-10 19:00:32 +02:00
|
|
|
{"checking (q)", "checking", "dl metadata"
|
|
|
|
, "downloading", "finished", "seeding", "allocating", "checking (r)"};
|
2017-01-02 16:16:33 +01:00
|
|
|
std::cout << "st2 state: " << state_str[st2.state] << std::endl;
|
2013-10-10 19:00:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CHECK(st1.state == torrent_status::seeding
|
|
|
|
|| st1.state == torrent_status::checking_files);
|
|
|
|
TEST_CHECK(st2.state == torrent_status::downloading
|
|
|
|
|| st2.state == torrent_status::checking_resume_data);
|
|
|
|
|
|
|
|
if (peer_disconnects >= 2) break;
|
|
|
|
|
|
|
|
// if nothing is being transferred after 2 seconds, we're failing the test
|
|
|
|
if (st1.upload_payload_rate == 0 && i > 20) break;
|
|
|
|
|
2016-06-26 15:24:06 +02:00
|
|
|
std::this_thread::sleep_for(lt::milliseconds(100));
|
2013-10-10 19:00:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CHECK(!tor2.status().is_seeding);
|
|
|
|
TEST_CHECK(tor2.status().is_finished);
|
|
|
|
|
|
|
|
if (tor2.status().is_finished)
|
2017-01-02 16:16:33 +01:00
|
|
|
std::cout << "torrent is finished (50% complete)" << std::endl;
|
2013-10-10 19:00:32 +02:00
|
|
|
else return;
|
|
|
|
|
2013-10-11 10:36:17 +02:00
|
|
|
std::vector<int> priorities2 = tor2.piece_priorities();
|
2017-01-02 16:16:33 +01:00
|
|
|
std::copy(priorities2.begin(), priorities2.end(), std::ostream_iterator<int>(std::cout, ", "));
|
|
|
|
std::cout << std::endl;
|
2013-10-11 10:36:17 +02:00
|
|
|
TEST_CHECK(std::equal(priorities.begin(), priorities.end(), priorities2.begin()));
|
|
|
|
|
2017-01-02 16:16:33 +01:00
|
|
|
std::cout << "force recheck" << std::endl;
|
2013-10-10 19:00:32 +02:00
|
|
|
tor2.force_recheck();
|
|
|
|
|
2013-10-11 10:36:17 +02:00
|
|
|
priorities2 = tor2.piece_priorities();
|
2017-01-02 16:16:33 +01:00
|
|
|
std::copy(priorities2.begin(), priorities2.end(), std::ostream_iterator<int>(std::cout, ", "));
|
|
|
|
std::cout << std::endl;
|
2013-10-11 10:36:17 +02:00
|
|
|
TEST_CHECK(std::equal(priorities.begin(), priorities.end(), priorities2.begin()));
|
|
|
|
|
2013-10-10 19:00:32 +02:00
|
|
|
peer_disconnects = 0;
|
|
|
|
|
2014-01-20 21:26:12 +01:00
|
|
|
// when we're done checking, we're likely to be put in downloading state
|
|
|
|
// for a split second before transitioning to finished. This loop waits
|
|
|
|
// for the finished state
|
|
|
|
torrent_status st2;
|
2013-10-10 19:00:32 +02:00
|
|
|
for (int i = 0; i < 50; ++i)
|
|
|
|
{
|
2017-04-02 20:22:17 +02:00
|
|
|
print_alerts(ses1, "ses1", true, true, &on_alert);
|
|
|
|
print_alerts(ses2, "ses2", true, true, &on_alert);
|
2013-10-10 19:00:32 +02:00
|
|
|
|
2014-01-20 21:26:12 +01:00
|
|
|
st2 = tor2.status();
|
2013-10-10 19:00:32 +02:00
|
|
|
if (i % 10 == 0)
|
|
|
|
{
|
2017-01-02 16:16:33 +01:00
|
|
|
std::cout << int(st2.progress * 100) << "% " << std::endl;
|
2013-10-10 19:00:32 +02:00
|
|
|
}
|
2014-01-20 21:26:12 +01:00
|
|
|
if (st2.state == torrent_status::finished) break;
|
2016-06-26 15:24:06 +02:00
|
|
|
std::this_thread::sleep_for(lt::milliseconds(100));
|
2013-10-10 19:00:32 +02:00
|
|
|
}
|
|
|
|
|
2014-07-21 05:03:59 +02:00
|
|
|
TEST_EQUAL(st2.state, torrent_status::finished);
|
|
|
|
|
|
|
|
if (st2.state != torrent_status::finished)
|
|
|
|
return;
|
|
|
|
|
2017-01-02 16:16:33 +01:00
|
|
|
std::cout << "recheck complete" << std::endl;
|
2014-01-20 21:26:12 +01:00
|
|
|
|
2013-10-11 10:36:17 +02:00
|
|
|
priorities2 = tor2.piece_priorities();
|
2017-01-02 16:16:33 +01:00
|
|
|
std::copy(priorities2.begin(), priorities2.end(), std::ostream_iterator<int>(std::cout, ", "));
|
|
|
|
std::cout << std::endl;
|
2013-10-10 19:00:32 +02:00
|
|
|
TEST_CHECK(std::equal(priorities.begin(), priorities.end(), priorities2.begin()));
|
|
|
|
|
|
|
|
tor2.pause();
|
2014-07-06 21:18:00 +02:00
|
|
|
wait_for_alert(ses2, torrent_paused_alert::alert_type, "ses2");
|
2013-10-10 19:00:32 +02:00
|
|
|
|
2016-10-10 02:23:45 +02:00
|
|
|
std::printf("save resume data\n");
|
2013-10-10 19:00:32 +02:00
|
|
|
tor2.save_resume_data();
|
|
|
|
|
|
|
|
std::vector<char> resume_data;
|
2014-07-06 21:18:00 +02:00
|
|
|
|
2015-03-12 05:34:54 +01:00
|
|
|
time_point start = clock_type::now();
|
2015-04-03 22:15:48 +02:00
|
|
|
while (true)
|
2013-10-10 19:00:32 +02:00
|
|
|
{
|
2015-04-06 01:16:01 +02:00
|
|
|
ses2.wait_for_alert(seconds(10));
|
2015-04-03 22:15:48 +02:00
|
|
|
std::vector<alert*> alerts;
|
|
|
|
ses2.pop_alerts(&alerts);
|
|
|
|
if (alerts.empty()) break;
|
|
|
|
for (std::vector<alert*>::iterator i = alerts.begin()
|
|
|
|
, end(alerts.end()); i != end; ++i)
|
2013-10-10 19:00:32 +02:00
|
|
|
{
|
2015-04-03 22:15:48 +02:00
|
|
|
alert* a = *i;
|
2017-01-02 16:16:33 +01:00
|
|
|
std::cout << "ses2: " << a->message() << std::endl;
|
2015-04-03 22:15:48 +02:00
|
|
|
if (alert_cast<save_resume_data_alert>(a))
|
|
|
|
{
|
2017-03-09 00:01:59 +01:00
|
|
|
resume_data = write_resume_data_buf(alert_cast<save_resume_data_alert>(a)->params);
|
2016-10-10 02:23:45 +02:00
|
|
|
std::printf("saved resume data\n");
|
2015-04-06 01:16:01 +02:00
|
|
|
goto done;
|
2015-04-03 22:15:48 +02:00
|
|
|
}
|
|
|
|
else if (alert_cast<save_resume_data_failed_alert>(a))
|
|
|
|
{
|
2016-10-10 02:23:45 +02:00
|
|
|
std::printf("save resume failed\n");
|
2015-04-06 01:16:01 +02:00
|
|
|
goto done;
|
2015-04-03 22:15:48 +02:00
|
|
|
}
|
|
|
|
if (total_seconds(clock_type::now() - start) > 10)
|
2015-04-06 01:16:01 +02:00
|
|
|
goto done;
|
2014-07-06 21:18:00 +02:00
|
|
|
}
|
2013-10-10 19:00:32 +02:00
|
|
|
}
|
2015-04-06 01:16:01 +02:00
|
|
|
done:
|
2015-06-06 18:10:43 +02:00
|
|
|
TEST_CHECK(resume_data.size());
|
2013-10-10 19:00:32 +02:00
|
|
|
|
2015-04-06 01:16:01 +02:00
|
|
|
if (resume_data.empty())
|
|
|
|
return;
|
|
|
|
|
2016-10-10 02:23:45 +02:00
|
|
|
std::printf("%s\n", &resume_data[0]);
|
2014-07-21 05:03:59 +02:00
|
|
|
|
2013-10-10 19:00:32 +02:00
|
|
|
ses2.remove_torrent(tor2);
|
|
|
|
|
2017-01-02 16:16:33 +01:00
|
|
|
std::cout << "removed" << std::endl;
|
2013-10-10 19:00:32 +02:00
|
|
|
|
2016-06-26 15:24:06 +02:00
|
|
|
std::this_thread::sleep_for(lt::milliseconds(100));
|
2013-10-10 19:00:32 +02:00
|
|
|
|
|
|
|
std::cout << "re-adding" << std::endl;
|
|
|
|
add_torrent_params p;
|
2016-02-16 07:43:06 +01:00
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
|
|
|
if (test_deprecated)
|
|
|
|
{
|
|
|
|
p.resume_data = resume_data;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
error_code ec;
|
2017-03-29 22:10:32 +02:00
|
|
|
p = read_resume_data(resume_data, ec);
|
2016-02-16 07:43:06 +01:00
|
|
|
TEST_CHECK(!ec);
|
|
|
|
}
|
2013-10-10 19:00:32 +02:00
|
|
|
p.flags &= ~add_torrent_params::flag_paused;
|
|
|
|
p.flags &= ~add_torrent_params::flag_auto_managed;
|
|
|
|
p.ti = t;
|
2013-10-11 10:36:17 +02:00
|
|
|
p.save_path = "tmp2_priority";
|
2016-02-16 07:43:06 +01:00
|
|
|
|
2013-10-10 19:00:32 +02:00
|
|
|
tor2 = ses2.add_torrent(p, ec);
|
|
|
|
tor2.prioritize_pieces(priorities);
|
|
|
|
std::cout << "resetting priorities" << std::endl;
|
|
|
|
tor2.resume();
|
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
// wait for torrent 2 to settle in back to finished state (it will
|
|
|
|
// start as checking)
|
|
|
|
torrent_status st1;
|
2013-10-10 19:00:32 +02:00
|
|
|
for (int i = 0; i < 5; ++i)
|
|
|
|
{
|
2017-04-02 20:22:17 +02:00
|
|
|
print_alerts(ses1, "ses1", true, true, &on_alert);
|
|
|
|
print_alerts(ses2, "ses2", true, true, &on_alert);
|
2013-10-10 19:00:32 +02:00
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
st1 = tor1.status();
|
|
|
|
st2 = tor2.status();
|
2013-10-10 19:00:32 +02:00
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
TEST_CHECK(st1.state == torrent_status::seeding);
|
2013-10-10 19:00:32 +02:00
|
|
|
|
|
|
|
if (st2.is_finished) break;
|
|
|
|
|
2016-06-26 15:24:06 +02:00
|
|
|
std::this_thread::sleep_for(lt::milliseconds(100));
|
2013-10-10 19:00:32 +02:00
|
|
|
}
|
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
// torrent 2 should not be seeding yet, it should
|
|
|
|
// just be 50% finished
|
|
|
|
TEST_CHECK(!st2.is_seeding);
|
|
|
|
TEST_CHECK(st2.is_finished);
|
2013-10-10 19:00:32 +02:00
|
|
|
|
|
|
|
std::fill(priorities.begin(), priorities.end(), 1);
|
|
|
|
tor2.prioritize_pieces(priorities);
|
|
|
|
std::cout << "setting priorities to 1" << std::endl;
|
|
|
|
TEST_EQUAL(tor2.status().is_finished, false);
|
|
|
|
|
2017-01-02 16:16:33 +01:00
|
|
|
std::copy(priorities.begin(), priorities.end(), std::ostream_iterator<int>(std::cout, ", "));
|
|
|
|
std::cout << std::endl;
|
2014-01-20 21:26:12 +01:00
|
|
|
|
2014-01-26 00:04:24 +01:00
|
|
|
// drain alerts
|
2017-04-02 20:22:17 +02:00
|
|
|
print_alerts(ses1, "ses1", true, true, &on_alert);
|
|
|
|
print_alerts(ses2, "ses2", true, true, &on_alert);
|
2014-01-26 00:04:24 +01:00
|
|
|
|
2013-10-10 19:00:32 +02:00
|
|
|
peer_disconnects = 0;
|
|
|
|
|
2014-01-20 21:26:12 +01:00
|
|
|
// this loop makes sure ses2 reconnects to the peer now that it's
|
|
|
|
// in download mode again. If this fails, the reconnect logic may
|
|
|
|
// not work or be inefficient
|
2014-07-06 21:18:00 +02:00
|
|
|
st1 = tor1.status();
|
2014-01-20 21:26:12 +01:00
|
|
|
st2 = tor2.status();
|
2013-10-10 19:00:32 +02:00
|
|
|
for (int i = 0; i < 130; ++i)
|
|
|
|
{
|
2017-04-02 20:22:17 +02:00
|
|
|
print_alerts(ses1, "ses1", true, true, &on_alert);
|
|
|
|
print_alerts(ses2, "ses2", true, true, &on_alert);
|
2013-10-10 19:00:32 +02:00
|
|
|
|
2013-10-14 06:37:40 +02:00
|
|
|
st1 = tor1.status();
|
|
|
|
st2 = tor2.status();
|
2013-10-10 19:00:32 +02:00
|
|
|
|
|
|
|
if (i % 10 == 0)
|
|
|
|
print_ses_rate(i / 10.f, &st1, &st2);
|
|
|
|
|
|
|
|
if (st2.is_seeding) break;
|
|
|
|
|
|
|
|
TEST_EQUAL(st1.state, torrent_status::seeding);
|
|
|
|
TEST_EQUAL(st2.state, torrent_status::downloading);
|
|
|
|
|
2013-10-14 06:37:40 +02:00
|
|
|
if (peer_disconnects >= 2)
|
|
|
|
{
|
2016-10-10 02:23:45 +02:00
|
|
|
std::printf("too many disconnects (%d), exiting\n", peer_disconnects);
|
2013-10-14 06:37:40 +02:00
|
|
|
break;
|
|
|
|
}
|
2013-10-10 19:00:32 +02:00
|
|
|
|
2016-06-26 15:24:06 +02:00
|
|
|
std::this_thread::sleep_for(lt::milliseconds(100));
|
2013-10-10 19:00:32 +02:00
|
|
|
}
|
|
|
|
|
2013-10-21 10:48:53 +02:00
|
|
|
st2 = tor2.status();
|
2014-01-20 21:26:12 +01:00
|
|
|
if (!st2.is_seeding)
|
2016-10-10 02:23:45 +02:00
|
|
|
std::printf("ses2 failed to reconnect to ses1!\n");
|
2013-10-14 06:37:40 +02:00
|
|
|
TEST_CHECK(st2.is_seeding);
|
2013-10-10 19:00:32 +02:00
|
|
|
|
2014-11-09 12:17:13 +01:00
|
|
|
sp.push_back(ses1.abort());
|
|
|
|
sp.push_back(ses2.abort());
|
2013-10-10 19:00:32 +02:00
|
|
|
}
|
|
|
|
|
2015-05-30 06:31:23 +02:00
|
|
|
TORRENT_TEST(priority)
|
2013-10-10 19:00:32 +02:00
|
|
|
{
|
2017-04-12 20:05:53 +02:00
|
|
|
using namespace lt;
|
2016-08-21 18:15:19 +02:00
|
|
|
settings_pack p = settings();
|
2014-11-09 12:17:13 +01:00
|
|
|
test_transfer(p);
|
2015-06-06 18:10:43 +02:00
|
|
|
cleanup();
|
2013-10-10 19:00:32 +02:00
|
|
|
}
|
|
|
|
|
2016-02-16 07:43:06 +01:00
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
|
|
|
TORRENT_TEST(priority_deprecated)
|
|
|
|
{
|
2017-04-12 20:05:53 +02:00
|
|
|
using namespace lt;
|
2016-02-16 07:43:06 +01:00
|
|
|
settings_pack p;
|
|
|
|
test_transfer(p, true);
|
|
|
|
cleanup();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-08-29 16:21:15 +02:00
|
|
|
// test to set piece and file priority on a torrent that doesn't have metadata
|
|
|
|
// yet
|
|
|
|
TORRENT_TEST(no_metadata_file_prio)
|
|
|
|
{
|
2016-08-21 18:15:19 +02:00
|
|
|
settings_pack pack = settings();
|
2015-08-29 16:21:15 +02:00
|
|
|
lt::session ses(pack);
|
|
|
|
|
|
|
|
add_torrent_params addp;
|
|
|
|
addp.flags &= ~add_torrent_params::flag_paused;
|
|
|
|
addp.flags &= ~add_torrent_params::flag_auto_managed;
|
|
|
|
addp.info_hash = sha1_hash("abababababababababab");
|
|
|
|
addp.save_path = ".";
|
|
|
|
torrent_handle h = ses.add_torrent(addp);
|
|
|
|
|
2016-12-22 16:42:33 +01:00
|
|
|
h.file_priority(file_index_t(0), 0);
|
|
|
|
TEST_EQUAL(h.file_priority(file_index_t(0)), 0);
|
|
|
|
h.file_priority(file_index_t(0), 1);
|
|
|
|
TEST_EQUAL(h.file_priority(file_index_t(0)), 1);
|
2015-08-29 16:21:15 +02:00
|
|
|
|
|
|
|
ses.remove_torrent(h);
|
|
|
|
}
|
2013-10-10 19:00:32 +02:00
|
|
|
|
2015-08-29 16:21:15 +02:00
|
|
|
TORRENT_TEST(no_metadata_piece_prio)
|
|
|
|
{
|
2016-08-21 18:15:19 +02:00
|
|
|
settings_pack pack = settings();
|
2015-08-29 16:21:15 +02:00
|
|
|
lt::session ses(pack);
|
|
|
|
|
|
|
|
add_torrent_params addp;
|
|
|
|
addp.flags &= ~add_torrent_params::flag_paused;
|
|
|
|
addp.flags &= ~add_torrent_params::flag_auto_managed;
|
|
|
|
addp.info_hash = sha1_hash("abababababababababab");
|
|
|
|
addp.save_path = ".";
|
|
|
|
torrent_handle h = ses.add_torrent(addp);
|
|
|
|
|
|
|
|
// you can't set piece priorities before the metadata has been downloaded
|
2016-12-22 16:42:33 +01:00
|
|
|
h.piece_priority(piece_index_t(2), 0);
|
|
|
|
TEST_EQUAL(h.piece_priority(piece_index_t(2)), 4);
|
|
|
|
h.piece_priority(piece_index_t(2), 1);
|
|
|
|
TEST_EQUAL(h.piece_priority(piece_index_t(2)), 4);
|
2015-08-29 16:21:15 +02:00
|
|
|
|
|
|
|
ses.remove_torrent(h);
|
|
|
|
}
|