don't use pointers to resume_data and file_priorities in add_torrent_params

This commit is contained in:
Arvid Norberg 2013-07-17 20:21:48 +00:00
parent f10bedf035
commit 9c9135bfc4
9 changed files with 17 additions and 29 deletions

View File

@ -1,3 +1,4 @@
* don't use pointers to resume_data and file_priorities in add_torrent_params
* allow moving files to absolute paths, out of the download directory
* make move_storage more generic to allow both overwriting files as well as taking existing ones
* fix choking issue at high upload rates

View File

@ -394,11 +394,11 @@ async_add_torrent() add_torrent()
sha1_hash info_hash;
std::string name;
std::string save_path;
std::vector<char>* resume_data;
std::vector<char> resume_data;
storage_mode_t storage_mode;
storage_constructor_type storage;
void* userdata;
std::vector<boost::uint8_t> const* file_priorities;
std::vector<boost::uint8_t> file_priorities;
std::string trackerid;
std::string url;
std::string uuid;

View File

@ -52,11 +52,9 @@ namespace libtorrent
#ifndef TORRENT_NO_DEPRECATE
, tracker_url(0)
#endif
, resume_data(0)
, storage_mode(storage_mode_sparse)
, storage(sc)
, userdata(0)
, file_priorities(0)
#ifndef TORRENT_NO_DEPRECATE
, flags(flag_ignore_flags | default_flags)
, seed_mode(false)
@ -129,11 +127,11 @@ namespace libtorrent
sha1_hash info_hash;
std::string name;
std::string save_path;
std::vector<char>* resume_data;
std::vector<char> resume_data;
storage_mode_t storage_mode;
storage_constructor_type storage;
void* userdata;
std::vector<boost::uint8_t> const* file_priorities;
std::vector<boost::uint8_t> file_priorities;
std::string trackerid;
std::string url;
std::string uuid;

View File

@ -647,7 +647,6 @@ namespace libtorrent
void session::async_add_torrent(add_torrent_params const& params)
{
add_torrent_params* p = new add_torrent_params(params);
if (params.resume_data) p->resume_data = new std::vector<char>(*params.resume_data);
TORRENT_ASYNC_CALL1(async_add_torrent, p);
}
@ -666,11 +665,9 @@ namespace libtorrent
add_torrent_params p(sc);
p.ti = tip;
p.save_path = save_path;
std::vector<char> buf;
if (resume_data.type() != entry::undefined_t)
{
bencode(std::back_inserter(buf), resume_data);
p.resume_data = &buf;
bencode(std::back_inserter(p.resume_data), resume_data);
}
p.storage_mode = storage_mode;
p.paused = paused;
@ -689,11 +686,9 @@ namespace libtorrent
add_torrent_params p(sc);
p.ti = ti;
p.save_path = save_path;
std::vector<char> buf;
if (resume_data.type() != entry::undefined_t)
{
bencode(std::back_inserter(buf), resume_data);
p.resume_data = &buf;
bencode(std::back_inserter(p.resume_data), resume_data);
}
p.storage_mode = storage_mode;
p.paused = paused;

View File

@ -5013,7 +5013,6 @@ retry:
{
error_code ec;
torrent_handle handle = add_torrent(*params, ec);
delete params->resume_data;
delete params;
}
@ -5085,7 +5084,7 @@ retry:
// we don't have a torrent file. If the user provided
// resume data, there may be some metadata in there
if ((!params.ti || !params.ti->is_valid())
&& params.resume_data)
&& !params.resume_data.empty())
{
int pos;
error_code ec;
@ -5094,8 +5093,8 @@ retry:
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING
session_log("adding magnet link with resume data");
#endif
if (lazy_bdecode(&(*params.resume_data)[0], &(*params.resume_data)[0]
+ params.resume_data->size(), tmp, ec, &pos) == 0
if (lazy_bdecode(&params.resume_data[0], &params.resume_data[0]
+ params.resume_data.size(), tmp, ec, &pos) == 0
&& tmp.type() == lazy_entry::dict_t
&& (info = tmp.dict_find_dict("info")))
{

View File

@ -430,7 +430,7 @@ namespace libtorrent
{
// if there is resume data already, we don't need to trigger the initial save
// resume data
if (p.resume_data && (p.flags & add_torrent_params::flag_override_resume_data) == 0)
if (!p.resume_data.empty() && (p.flags & add_torrent_params::flag_override_resume_data) == 0)
m_need_save_resume_data = false;
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
@ -476,13 +476,12 @@ namespace libtorrent
#endif
m_net_interfaces.push_back(tcp::endpoint(net_interface.address(), 0));
if (p.file_priorities)
m_file_priority = *p.file_priorities;
m_file_priority = p.file_priorities;
if (m_seed_mode)
m_verified.resize(m_torrent_file->num_pieces(), false);
if (p.resume_data) m_resume_data.swap(*p.resume_data);
m_resume_data = p.resume_data;
#ifndef TORRENT_DISABLE_ENCRYPTION
hasher h;

View File

@ -977,9 +977,7 @@ void test_fastresume(std::string const& test_path)
p.ti = new torrent_info(*t);
p.save_path = combine_path(test_path, "tmp1");
p.storage_mode = storage_mode_compact;
std::vector<char> resume_buf;
bencode(std::back_inserter(resume_buf), resume);
p.resume_data = &resume_buf;
bencode(std::back_inserter(p.resume_data), resume);
torrent_handle h = ses.add_torrent(p, ec);
std::auto_ptr<alert> a = ses.pop_alert();
@ -1071,9 +1069,7 @@ void test_rename_file_in_fastresume(std::string const& test_path)
p.ti = new torrent_info(*t);
p.save_path = combine_path(test_path, "tmp2");
p.storage_mode = storage_mode_compact;
std::vector<char> resume_buf;
bencode(std::back_inserter(resume_buf), resume);
p.resume_data = &resume_buf;
bencode(std::back_inserter(p.resume_data), resume);
torrent_handle h = ses.add_torrent(p, ec);
for (int i = 0; i < 5; ++i)

View File

@ -58,7 +58,7 @@ void test_running_torrent(boost::intrusive_ptr<torrent_info> info, size_type fil
// make sure we correctly handle the case where we pass in
// more values than there are files
p.file_priorities = &zeroes;
p.file_priorities = zeroes;
error_code ec;
torrent_handle h = ses.add_torrent(p, ec);

View File

@ -492,7 +492,7 @@ void test_transfer(int proxy_type, bool test_disk_full = false, bool test_allowe
p.flags &= ~add_torrent_params::flag_auto_managed;
p.ti = t;
p.save_path = "tmp2_transfer_moved";
p.resume_data = &resume_data;
p.resume_data = resume_data;
tor2 = ses2.add_torrent(p, ec);
ses2.set_alert_mask(alert::all_categories
& ~alert::progress_notification