remove m_resume_data and m_resume_data_loaded members from torrent

This commit is contained in:
arvidn 2016-02-08 17:45:56 -05:00 committed by arvidn
parent 59da9f35a8
commit e0ee12d4f3
3 changed files with 23 additions and 91 deletions

View File

@ -105,12 +105,6 @@ namespace libtorrent
struct piece_checker_data;
}
struct resume_data_t
{
std::vector<char> buf;
bdecode_node node;
};
struct time_critical_piece
{
// when this piece was first requested
@ -1304,10 +1298,6 @@ namespace libtorrent
// set if there's an error on this torrent
error_code m_error;
// used if there is any resume data
#error do we still need this?
boost::scoped_ptr<resume_data_t> m_resume_data;
// if the torrent is started without metadata, it may
// still be given a name until the metadata is received
// once the metadata is received this field will no
@ -1494,7 +1484,9 @@ namespace libtorrent
// torrent.
bool m_super_seeding:1;
#error a 1 bit hole here
// if this is set, whenever transitioning into a downloading/seeding state
// from a non-downloading/seeding state, the torrent is paused.
bool m_stop_when_ready:1;
#ifndef TORRENT_NO_DEPRECATE
#ifndef TORRENT_DISABLE_RESOLVE_COUNTRIES
@ -1686,18 +1678,6 @@ namespace libtorrent
// flapping. If the state changes back during this period, we cancel the
// quarantine
bool m_pending_active_change:1;
#error 2 missing bit here
// if this is set, whenever transitioning into a downloading/seeding state
// from a non-downloading/seeding state, the torrent is paused.
bool m_stop_when_ready:1;
#if TORRENT_USE_ASSERTS
public:
// set to false until we've loaded resume data
bool m_resume_data_loaded;
#endif
};
struct torrent_ref_holder

View File

@ -66,6 +66,25 @@ namespace libtorrent
{
add_torrent_params ret;
if (rd.dict_find_string_value("file-format")
!= "libtorrent resume file")
{
ec = error_code(errors::invalid_file_tag, get_libtorrent_category());
return ret;
}
std::string info_hash = rd.dict_find_string_value("info-hash");
if (info_hash.empty())
{
ec = error_code(errors::missing_info_hash, get_libtorrent_category());
return ret;
}
#error we need to verify the info-hash from the resume data \
matches the torrent_info object or the magnet link in the URL field. This \
can only be done reliably on the libtorrent side as the torrent is being \
added. i.e. the info_hash needs to be saved
ret.total_uploaded = rd.dict_find_int_value("total_uploaded");
ret.total_downloaded = rd.dict_find_int_value("total_downloaded");
ret.active_time = rd.dict_find_int_value("active_time");

View File

@ -237,6 +237,7 @@ namespace libtorrent
, m_auto_sequential(false)
, m_seed_mode(false)
, m_super_seeding(false)
, m_stop_when_ready((p.flags & add_torrent_params::flag_stop_when_ready) != 0)
#ifndef TORRENT_NO_DEPRECATE
#ifndef TORRENT_DISABLE_RESOLVE_COUNTRIES
, m_resolving_country(false)
@ -277,7 +278,6 @@ namespace libtorrent
, m_last_scrape((std::numeric_limits<boost::int16_t>::min)())
, m_progress_ppm(0)
, m_pending_active_change(false)
, m_stop_when_ready((p.flags & add_torrent_params::flag_stop_when_ready) != 0)
{
// we cannot log in the constructor, because it relies on shared_from_this
// being initialized, which happens after the constructor returns.
@ -292,9 +292,6 @@ namespace libtorrent
if (!p.resume_data.empty() && (p.flags & add_torrent_params::flag_override_resume_data) == 0)
m_need_save_resume_data = false;
#if TORRENT_USE_ASSERTS
m_resume_data_loaded = false;
#endif
#if TORRENT_USE_UNC_PATHS
m_save_path = canonicalize_path(m_save_path);
#endif
@ -349,12 +346,6 @@ namespace libtorrent
m_verifying.resize(m_torrent_file->num_pieces(), false);
}
if (!p.resume_data.empty())
{
m_resume_data.reset(new resume_data_t);
m_resume_data->buf = p.resume_data;
}
int tier = 0;
std::vector<int>::const_iterator tier_iter = p.tracker_tiers.begin();
for (std::vector<std::string>::const_iterator i = p.trackers.begin()
@ -823,23 +814,6 @@ namespace libtorrent
m_file_progress.clear();
if (m_resume_data)
{
int pos;
error_code ec;
if (bdecode(&m_resume_data->buf[0], &m_resume_data->buf[0]
+ m_resume_data->buf.size(), m_resume_data->node, ec, &pos) != 0)
{
m_resume_data.reset();
#ifndef TORRENT_DISABLE_LOGGING
debug_log("resume data rejected: %s pos: %d", ec.message().c_str(), pos);
#endif
if (m_ses.alerts().should_post<fastresume_rejected_alert>())
m_ses.alerts().emplace_alert<fastresume_rejected_alert>(get_handle()
, ec, "", static_cast<char const*>(0));
}
}
update_want_peers();
update_want_scrape();
update_want_tick();
@ -1864,43 +1838,6 @@ namespace libtorrent
return;
}
if (m_resume_data && m_resume_data->node.type() == bdecode_node::dict_t)
{
int ev = 0;
if (m_resume_data->node.dict_find_string_value("file-format")
!= "libtorrent resume file")
{
ev = errors::invalid_file_tag;
}
std::string info_hash = m_resume_data->node.dict_find_string_value("info-hash");
if (!ev && info_hash.empty())
ev = errors::missing_info_hash;
if (!ev && sha1_hash(info_hash) != m_torrent_file->info_hash())
ev = errors::mismatching_info_hash;
if (ev && m_ses.alerts().should_post<fastresume_rejected_alert>())
{
error_code ec = error_code(ev, get_libtorrent_category());
m_ses.alerts().emplace_alert<fastresume_rejected_alert>(get_handle()
, ec, "", static_cast<char const*>(0));
}
if (ev)
{
#ifndef TORRENT_DISABLE_LOGGING
debug_log("fastresume data rejected: %s"
, error_code(ev, get_libtorrent_category()).message().c_str());
#endif
m_resume_data.reset();
}
}
#if TORRENT_USE_ASSERTS
m_resume_data_loaded = true;
#endif
construct_storage();
if (m_share_mode && valid_metadata())
@ -1964,10 +1901,6 @@ namespace libtorrent
update_piece_priorities();
}
#if TORRENT_USE_ASSERTS
m_resume_data_loaded = true;
#endif
if (m_seed_mode)
{
m_have_all = true;