merge loading of piece priorities from resume data fix from RC_1_0
This commit is contained in:
parent
bb705e9a52
commit
40c7596da9
|
@ -74,6 +74,7 @@
|
||||||
|
|
||||||
1.0.6 release
|
1.0.6 release
|
||||||
|
|
||||||
|
* fix loading of piece priorities from resume data
|
||||||
* improved seed-mode handling (seed-mode will now automatically be left when
|
* improved seed-mode handling (seed-mode will now automatically be left when
|
||||||
performing operations implying it's not a seed)
|
performing operations implying it's not a seed)
|
||||||
* fixed issue with file priorities and override resume data
|
* fixed issue with file priorities and override resume data
|
||||||
|
|
|
@ -1859,6 +1859,17 @@ namespace libtorrent
|
||||||
|
|
||||||
construct_storage();
|
construct_storage();
|
||||||
|
|
||||||
|
if (m_share_mode && valid_metadata())
|
||||||
|
{
|
||||||
|
// in share mode, all pieces have their priorities initialized to 0
|
||||||
|
m_file_priority.clear();
|
||||||
|
m_file_priority.resize(m_torrent_file->num_files(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// in case file priorities were passed in via the add_torrent_params
|
||||||
|
// and also in the case of share mode, we need to update the priorities
|
||||||
|
update_piece_priorities();
|
||||||
|
|
||||||
// if we've already loaded file priorities, don't load piece priorities,
|
// if we've already loaded file priorities, don't load piece priorities,
|
||||||
// they will interfere.
|
// they will interfere.
|
||||||
if (!m_seed_mode && m_resume_data && m_file_priority.empty())
|
if (!m_seed_mode && m_resume_data && m_file_priority.empty())
|
||||||
|
@ -1881,13 +1892,6 @@ namespace libtorrent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_share_mode && valid_metadata())
|
|
||||||
{
|
|
||||||
// in share mode, all pieces have their priorities initialized to 0
|
|
||||||
m_file_priority.clear();
|
|
||||||
m_file_priority.resize(m_torrent_file->num_files(), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!m_connections_initialized)
|
if (!m_connections_initialized)
|
||||||
{
|
{
|
||||||
m_connections_initialized = true;
|
m_connections_initialized = true;
|
||||||
|
@ -1907,10 +1911,6 @@ namespace libtorrent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// in case file priorities were passed in via the add_torrent_params
|
|
||||||
// and also in the case of share mode, we need to update the priorities
|
|
||||||
update_piece_priorities();
|
|
||||||
|
|
||||||
std::vector<web_seed_entry> const& web_seeds = m_torrent_file->web_seeds();
|
std::vector<web_seed_entry> const& web_seeds = m_torrent_file->web_seeds();
|
||||||
m_web_seeds.insert(m_web_seeds.end(), web_seeds.begin(), web_seeds.end());
|
m_web_seeds.insert(m_web_seeds.end(), web_seeds.begin(), web_seeds.end());
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include "libtorrent/create_torrent.hpp"
|
#include "libtorrent/create_torrent.hpp"
|
||||||
#include "libtorrent/alert_types.hpp"
|
#include "libtorrent/alert_types.hpp"
|
||||||
#include "libtorrent/entry.hpp"
|
#include "libtorrent/entry.hpp"
|
||||||
|
#include "libtorrent/bencode.hpp"
|
||||||
|
|
||||||
#include <boost/make_shared.hpp>
|
#include <boost/make_shared.hpp>
|
||||||
|
|
||||||
|
@ -188,6 +189,43 @@ void default_tests(torrent_status const& s)
|
||||||
TEST_EQUAL(s.completed_time, 1348);
|
TEST_EQUAL(s.completed_time, 1348);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TORRENT_TEST(piece_priorities)
|
||||||
|
{
|
||||||
|
session ses;
|
||||||
|
boost::shared_ptr<torrent_info> ti = generate_torrent();
|
||||||
|
add_torrent_params p;
|
||||||
|
p.ti = ti;
|
||||||
|
p.save_path = ".";
|
||||||
|
torrent_handle h = ses.add_torrent(p);
|
||||||
|
|
||||||
|
h.piece_priority(0, 0);
|
||||||
|
h.piece_priority(ti->num_pieces()-1, 0);
|
||||||
|
|
||||||
|
h.save_resume_data();
|
||||||
|
alert const* a = wait_for_alert(ses, save_resume_data_alert::alert_type);
|
||||||
|
|
||||||
|
TEST_CHECK(a);
|
||||||
|
if (save_resume_data_alert const* ra = alert_cast<save_resume_data_alert>(a))
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s\n", ra->resume_data->to_string().c_str());
|
||||||
|
entry::string_type prios = (*ra->resume_data)["piece_priority"].string();
|
||||||
|
TEST_EQUAL(prios.size(), ti->num_pieces());
|
||||||
|
TEST_EQUAL(prios[0], '\0');
|
||||||
|
TEST_EQUAL(prios[1], '\x04');
|
||||||
|
TEST_EQUAL(prios[ti->num_pieces()-1], '\0');
|
||||||
|
|
||||||
|
bencode(std::back_inserter(p.resume_data), *ra->resume_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
ses.remove_torrent(h);
|
||||||
|
|
||||||
|
// now, make sure the piece priorities are loaded correctly
|
||||||
|
h = ses.add_torrent(p);
|
||||||
|
TEST_EQUAL(h.piece_priority(0), 0);
|
||||||
|
TEST_EQUAL(h.piece_priority(1), 4);
|
||||||
|
TEST_EQUAL(h.piece_priority(ti->num_pieces()-1), 0);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: test what happens when loading a resume file with both piece priorities
|
// TODO: test what happens when loading a resume file with both piece priorities
|
||||||
// and file priorities (file prio should take presedence)
|
// and file priorities (file prio should take presedence)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue