transition merkle tree support over to the new read_resume_data()

This commit is contained in:
arvidn 2016-02-13 13:41:38 -08:00 committed by arvidn
parent 6223057b1e
commit 6e88771981
4 changed files with 34 additions and 27 deletions

View File

@ -468,6 +468,11 @@ namespace libtorrent
// precedence.
std::vector<boost::uint8_t> piece_priorities;
// if this is a merkle tree torrent, and you're seeding, this field must
// be set. It is all the hashes in the binary tree, with the root as the
// first entry. See torrent_info::set_merkle_tree() for more info.
std::vector<sha1_hash> merkle_tree;
#ifndef TORRENT_NO_DEPRECATE
// The optional parameter, ``resume_data`` can be given if up to date
// fast-resume data is available. The fast-resume data can be acquired

View File

@ -215,29 +215,9 @@ namespace libtorrent
bdecode_node mt = rd.dict_find_string("merkle tree");
if (mt)
{
#error add field for this
std::vector<sha1_hash> tree;
tree.resize(m_torrent_file->merkle_tree().size());
std::memcpy(&tree[0], mt.string_ptr()
, (std::min)(mt.string_length(), int(tree.size()) * 20));
if (mt.string_length() < int(tree.size()) * 20)
std::memset(&tree[0] + mt.string_length() / 20, 0
, tree.size() - mt.string_length() / 20);
m_torrent_file->set_merkle_tree(tree);
}
#error this is the case where the torrent is a merkle torrent but the resume \
data does not contain the merkle tree, we need some kind of check in the \
torrent constructor and error reporting
{
// TODO: 0 if this is a merkle torrent and we can't
// restore the tree, we need to wipe all the
// bits in the have array, but not necessarily
// we might want to do a full check to see if we have
// all the pieces. This is low priority since almost
// no one uses merkle torrents
TORRENT_ASSERT(false);
ret.merkle_tree.resize(mt.string_length() / 20);
std::memcpy(&ret.merkle_tree[0], mt.string_ptr()
, int(ret.merkle_tree.size()) * 20);
}
// some sanity checking. Maybe we shouldn't be in seed mode anymore

View File

@ -237,6 +237,8 @@ namespace libtorrent
atp.verified_pieces.swap(resume_data.verified_pieces);
atp.piece_priorities.swap(resume_data.piece_priorities);
atp.merkle_tree.swap(resume_data.merkle_tree);
if ((atp.flags & add_torrent_params::flag_override_resume_data) == 0)
{
atp.download_limit = resume_data.download_limit;

View File

@ -283,6 +283,7 @@ namespace libtorrent
// being initialized, which happens after the constructor returns.
// TODO: 3 we could probably get away with just saving a few fields here
// TODO: 2 p should probably be moved in here
m_add_torrent_params.reset(new add_torrent_params(p));
if (m_pinned)
@ -367,7 +368,6 @@ namespace libtorrent
e.source = announce_entry::source_magnet_link;
e.tier = tier;
m_trackers.push_back(e);
m_torrent_file->add_tracker(*i, tier);
}
std::sort(m_trackers.begin(), m_trackers.end(), boost::bind(&announce_entry::tier, _1)
@ -376,6 +376,29 @@ namespace libtorrent
if (settings().get_bool(settings_pack::prefer_udp_trackers))
prioritize_udp_trackers();
// --- MERKLE TREE ---
if (m_torrent_file->is_valid()
&& m_torrent_file->is_merkle_torrent())
{
if (p.merkle_tree.size() == m_torrent_file->merkle_tree().size())
{
// TODO: 2 set_merkle_tree should probably take the vector as &&
std::vector<sha1_hash> tree(p.merkle_tree);
m_torrent_file->set_merkle_tree(tree);
}
else
{
// TODO: 0 if this is a merkle torrent and we can't
// restore the tree, we need to wipe all the
// bits in the have array, but not necessarily
// we might want to do a full check to see if we have
// all the pieces. This is low priority since almost
// no one uses merkle torrents
TORRENT_ASSERT(false);
}
}
if (m_torrent_file->is_valid())
{
m_seed_mode = (p.flags & add_torrent_params::flag_seed_mode) != 0;
@ -398,9 +421,6 @@ namespace libtorrent
m_verifying.resize(m_torrent_file->num_pieces(), false);
}
if (settings().get_bool(settings_pack::prefer_udp_trackers))
prioritize_udp_trackers();
m_total_uploaded = p.total_uploaded;
m_total_downloaded = p.total_downloaded;