made torrent_info reference counted and held by a boost::intrusive_ptr
This commit is contained in:
@@ -23,7 +23,7 @@ void on_read_piece(int ret, disk_io_job const& j, char const* data, int size)
|
||||
TEST_CHECK(std::equal(j.buffer, j.buffer + ret, data));
|
||||
}
|
||||
|
||||
void run_storage_tests(torrent_info& info, bool compact_allocation = true)
|
||||
void run_storage_tests(boost::intrusive_ptr<torrent_info> info, bool compact_allocation = true)
|
||||
{
|
||||
const int half = piece_size / 2;
|
||||
|
||||
@@ -39,16 +39,16 @@ void run_storage_tests(torrent_info& info, bool compact_allocation = true)
|
||||
{ 0, 0, 1, 0, 0, 0, 0, 0
|
||||
, 1, 1, 1, 1, 1, 1, 1, 1};
|
||||
|
||||
info.set_hash(0, hasher(piece0, piece_size).final());
|
||||
info.set_hash(1, hasher(piece1, piece_size).final());
|
||||
info.set_hash(2, hasher(piece2, piece_size).final());
|
||||
info->set_hash(0, hasher(piece0, piece_size).final());
|
||||
info->set_hash(1, hasher(piece1, piece_size).final());
|
||||
info->set_hash(2, hasher(piece2, piece_size).final());
|
||||
|
||||
info.create_torrent();
|
||||
info->create_torrent();
|
||||
|
||||
create_directory(initial_path() / "temp_storage");
|
||||
|
||||
int num_pieces = (1 + 612 + 17 + piece_size - 1) / piece_size;
|
||||
TEST_CHECK(info.num_pieces() == num_pieces);
|
||||
TEST_CHECK(info->num_pieces() == num_pieces);
|
||||
|
||||
char piece[piece_size];
|
||||
|
||||
@@ -131,13 +131,13 @@ void run_storage_tests(torrent_info& info, bool compact_allocation = true)
|
||||
|
||||
int test_main()
|
||||
{
|
||||
torrent_info info;
|
||||
info.set_piece_size(piece_size);
|
||||
info.add_file("temp_storage/test1.tmp", 17);
|
||||
info.add_file("temp_storage/test2.tmp", 612);
|
||||
info.add_file("temp_storage/test3.tmp", 0);
|
||||
info.add_file("temp_storage/test4.tmp", 0);
|
||||
info.add_file("temp_storage/test5.tmp", 1);
|
||||
boost::intrusive_ptr<torrent_info> info(new torrent_info());
|
||||
info->set_piece_size(piece_size);
|
||||
info->add_file("temp_storage/test1.tmp", 17);
|
||||
info->add_file("temp_storage/test2.tmp", 612);
|
||||
info->add_file("temp_storage/test3.tmp", 0);
|
||||
info->add_file("temp_storage/test4.tmp", 0);
|
||||
info->add_file("temp_storage/test5.tmp", 1);
|
||||
|
||||
run_storage_tests(info);
|
||||
|
||||
@@ -155,7 +155,7 @@ int test_main()
|
||||
// make sure remap_files works
|
||||
std::vector<std::pair<std::string, libtorrent::size_type> > map;
|
||||
map.push_back(std::make_pair(std::string("temp_storage/test.tmp"), 17 + 612 + 1));
|
||||
bool ret = info.remap_files(map);
|
||||
bool ret = info->remap_files(map);
|
||||
TEST_CHECK(ret);
|
||||
|
||||
run_storage_tests(info, false);
|
||||
@@ -167,9 +167,9 @@ int test_main()
|
||||
|
||||
// ==============================================
|
||||
|
||||
info = torrent_info();
|
||||
info.set_piece_size(piece_size);
|
||||
info.add_file("temp_storage/test1.tmp", 17 + 612 + 1);
|
||||
info = new torrent_info();
|
||||
info->set_piece_size(piece_size);
|
||||
info->add_file("temp_storage/test1.tmp", 17 + 612 + 1);
|
||||
|
||||
run_storage_tests(info);
|
||||
|
||||
|
@@ -37,27 +37,27 @@ void test_transfer()
|
||||
{
|
||||
using namespace libtorrent;
|
||||
|
||||
torrent_info torrent_file;
|
||||
torrent_file.add_url_seed("http://127.0.0.1/bravia_paint_ad_70sec_1280x720.mov");
|
||||
boost::intrusive_ptr<torrent_info> torrent_file(new torrent_info);
|
||||
torrent_file->add_url_seed("http://127.0.0.1/bravia_paint_ad_70sec_1280x720.mov");
|
||||
|
||||
path full_path = "/Library/WebServer/Documents/bravia_paint_ad_70sec_1280x720.mov";
|
||||
add_files(torrent_file, full_path.branch_path(), full_path.leaf());
|
||||
add_files(*torrent_file, full_path.branch_path(), full_path.leaf());
|
||||
|
||||
file_pool fp;
|
||||
boost::scoped_ptr<storage_interface> s(default_storage_constructor(
|
||||
torrent_file, full_path.branch_path(), fp));
|
||||
// calculate the hash for all pieces
|
||||
int num = torrent_file.num_pieces();
|
||||
std::vector<char> buf(torrent_file.piece_length());
|
||||
int num = torrent_file->num_pieces();
|
||||
std::vector<char> buf(torrent_file->piece_length());
|
||||
for (int i = 0; i < num; ++i)
|
||||
{
|
||||
s->read(&buf[0], i, 0, torrent_file.piece_size(i));
|
||||
hasher h(&buf[0], torrent_file.piece_size(i));
|
||||
torrent_file.set_hash(i, h.final());
|
||||
s->read(&buf[0], i, 0, torrent_file->piece_size(i));
|
||||
hasher h(&buf[0], torrent_file->piece_size(i));
|
||||
torrent_file->set_hash(i, h.final());
|
||||
}
|
||||
|
||||
// to calculate the info_hash
|
||||
entry te = torrent_file.create_torrent();
|
||||
entry te = torrent_file->create_torrent();
|
||||
|
||||
te.print(std::cout);
|
||||
// std::ofstream torrent("web_seed.torrent", std::ios::binary | std::ios::trunc);
|
||||
|
Reference in New Issue
Block a user