added seed mode support (lazy hash checking)

This commit is contained in:
Arvid Norberg
2009-02-03 07:46:24 +00:00
parent a0333f82db
commit 1ac8f806fa
19 changed files with 481 additions and 230 deletions

View File

@@ -245,7 +245,8 @@ boost::tuple<torrent_handle, torrent_handle, torrent_handle>
setup_transfer(session* ses1, session* ses2, session* ses3
, bool clear_files, bool use_metadata_transfer, bool connect_peers
, std::string suffix, int piece_size
, boost::intrusive_ptr<torrent_info>* torrent, bool super_seeding)
, boost::intrusive_ptr<torrent_info>* torrent, bool super_seeding
, add_torrent_params const* p)
{
using namespace boost::filesystem;
@@ -289,22 +290,39 @@ setup_transfer(session* ses1, session* ses2, session* ses3
// file pool will complain if two torrents are trying to
// use the same files
sha1_hash info_hash = t->info_hash();
torrent_handle tor1 = ses1->add_torrent(clone_ptr(t), "./tmp1" + suffix);
add_torrent_params param;
if (p) param = *p;
param.ti = clone_ptr(t);
param.save_path = "./tmp1" + suffix;
torrent_handle tor1 = ses1->add_torrent(param);
tor1.super_seeding(super_seeding);
TEST_CHECK(!ses1->get_torrents().empty());
torrent_handle tor2;
torrent_handle tor3;
// the downloader cannot use seed_mode
param.seed_mode = false;
if (ses3)
{
tor3 = ses3->add_torrent(clone_ptr(t), "./tmp3" + suffix);
param.ti = clone_ptr(t);
param.save_path = "./tmp3" + suffix;
tor3 = ses3->add_torrent(param);
TEST_CHECK(!ses3->get_torrents().empty());
}
if (use_metadata_transfer)
tor2 = ses2->add_torrent("http://non-existent-name.com/announce"
, t->info_hash(), 0, "./tmp2" + suffix);
{
param.ti = 0;
param.info_hash = t->info_hash();
}
else
tor2 = ses2->add_torrent(clone_ptr(t), "./tmp2" + suffix);
{
param.ti = clone_ptr(t);
}
param.save_path = "./tmp2" + suffix;
tor2 = ses2->add_torrent(param);
TEST_CHECK(!ses2->get_torrents().empty());
assert(ses1->get_torrents().size() == 1);

View File

@@ -39,6 +39,7 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent
{
class alert;
class add_torrent_params;
}
bool print_alerts(libtorrent::session& ses, char const* name
@@ -51,12 +52,14 @@ void test_sleep(int millisec);
boost::intrusive_ptr<libtorrent::torrent_info> create_torrent(std::ostream* file = 0, int piece_size = 16 * 1024, int num_pieces = 1024 / 8);
boost::tuple<libtorrent::torrent_handle, libtorrent::torrent_handle
boost::tuple<libtorrent::torrent_handle
, libtorrent::torrent_handle
, libtorrent::torrent_handle>
setup_transfer(libtorrent::session* ses1, libtorrent::session* ses2
, libtorrent::session* ses3, bool clear_files, bool use_metadata_transfer = true
, bool connect = true, std::string suffix = "", int piece_size = 16 * 1024
, boost::intrusive_ptr<libtorrent::torrent_info>* torrent = 0, bool super_seeding = false);
, boost::intrusive_ptr<libtorrent::torrent_info>* torrent = 0, bool super_seeding = false
, libtorrent::add_torrent_params const* p = 0);
void start_web_server(int port, bool ssl = false);
void stop_web_server(int port);

View File

@@ -44,7 +44,7 @@ POSSIBILITY OF SUCH DAMAGE.
using boost::filesystem::remove_all;
using boost::filesystem::exists;
void test_swarm(bool super_seeding = false, bool strict = false)
void test_swarm(bool super_seeding = false, bool strict = false, bool seed_mode = false)
{
using namespace libtorrent;
@@ -92,9 +92,11 @@ void test_swarm(bool super_seeding = false, bool strict = false)
torrent_handle tor2;
torrent_handle tor3;
add_torrent_params p;
p.seed_mode = seed_mode;
// test using piece sizes smaller than 16kB
boost::tie(tor1, tor2, tor3) = setup_transfer(&ses1, &ses2, &ses3, true
, false, true, "_swarm", 8 * 1024, 0, super_seeding);
, false, true, "_swarm", 8 * 1024, 0, super_seeding, &p);
float sum_dl_rate2 = 0.f;
float sum_dl_rate3 = 0.f;
@@ -201,6 +203,9 @@ int test_main()
using namespace libtorrent;
using namespace boost::filesystem;
// with seed mode
test_swarm(false, false, true);
test_swarm();
// with super seeding