fixed the cause of an inconsistency in the piece picker and the torrent
This commit is contained in:
parent
f83db0a423
commit
c69479a166
|
@ -940,7 +940,38 @@ namespace libtorrent
|
||||||
{
|
{
|
||||||
m_last_piece = second_clock::universal_time();
|
m_last_piece = second_clock::universal_time();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
struct check_postcondition
|
||||||
|
{
|
||||||
|
check_postcondition(boost::shared_ptr<torrent> const& t_
|
||||||
|
, bool init_check = true): t(t_) { if (init_check) check(); }
|
||||||
|
|
||||||
|
~check_postcondition() { check(); }
|
||||||
|
|
||||||
|
void check()
|
||||||
|
{
|
||||||
|
if (!t->is_seed())
|
||||||
|
{
|
||||||
|
const int blocks_per_piece = static_cast<int>(
|
||||||
|
t->torrent_file().piece_length() / t->block_size());
|
||||||
|
|
||||||
|
std::vector<piece_picker::downloading_piece> const& dl_queue
|
||||||
|
= t->picker().get_download_queue();
|
||||||
|
|
||||||
|
for (std::vector<piece_picker::downloading_piece>::const_iterator i =
|
||||||
|
dl_queue.begin(); i != dl_queue.end(); ++i)
|
||||||
|
{
|
||||||
|
assert(int(i->finished_blocks.count()) < blocks_per_piece);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
shared_ptr<torrent> t;
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// -----------------------------
|
// -----------------------------
|
||||||
// ----------- PIECE -----------
|
// ----------- PIECE -----------
|
||||||
// -----------------------------
|
// -----------------------------
|
||||||
|
@ -952,6 +983,7 @@ namespace libtorrent
|
||||||
boost::shared_ptr<torrent> t = m_torrent.lock();
|
boost::shared_ptr<torrent> t = m_torrent.lock();
|
||||||
assert(t);
|
assert(t);
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
|
check_postcondition post_checker_(t);
|
||||||
t->check_invariant();
|
t->check_invariant();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1073,9 +1105,18 @@ namespace libtorrent
|
||||||
fs.write(data, p.piece, p.start, p.length);
|
fs.write(data, p.piece, p.start, p.length);
|
||||||
|
|
||||||
picker.mark_as_finished(block_finished, m_remote);
|
picker.mark_as_finished(block_finished, m_remote);
|
||||||
t->get_policy().block_finished(*this, block_finished);
|
|
||||||
|
|
||||||
send_block_requests();
|
try
|
||||||
|
{
|
||||||
|
t->get_policy().block_finished(*this, block_finished);
|
||||||
|
send_block_requests();
|
||||||
|
}
|
||||||
|
catch (std::exception const&) {}
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
try
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
bool was_seed = t->is_seed();
|
bool was_seed = t->is_seed();
|
||||||
bool was_finished = picker.num_filtered() + t->num_pieces()
|
bool was_finished = picker.num_filtered() + t->num_pieces()
|
||||||
|
@ -1084,6 +1125,9 @@ namespace libtorrent
|
||||||
// did we just finish the piece?
|
// did we just finish the piece?
|
||||||
if (picker.is_piece_finished(p.piece))
|
if (picker.is_piece_finished(p.piece))
|
||||||
{
|
{
|
||||||
|
#ifndef NDEBUG
|
||||||
|
check_postcondition post_checker2_(t, false);
|
||||||
|
#endif
|
||||||
bool verified = t->verify_piece(p.piece);
|
bool verified = t->verify_piece(p.piece);
|
||||||
if (verified)
|
if (verified)
|
||||||
{
|
{
|
||||||
|
@ -1113,22 +1157,6 @@ namespace libtorrent
|
||||||
{
|
{
|
||||||
t->piece_failed(p.piece);
|
t->piece_failed(p.piece);
|
||||||
}
|
}
|
||||||
#ifndef NDEBUG
|
|
||||||
if (!t->is_seed())
|
|
||||||
{
|
|
||||||
const int blocks_per_piece = static_cast<int>(
|
|
||||||
t->torrent_file().piece_length() / t->block_size());
|
|
||||||
|
|
||||||
std::vector<piece_picker::downloading_piece> const& dl_queue
|
|
||||||
= t->picker().get_download_queue();
|
|
||||||
|
|
||||||
for (std::vector<piece_picker::downloading_piece>::const_iterator i =
|
|
||||||
dl_queue.begin(); i != dl_queue.end(); ++i)
|
|
||||||
{
|
|
||||||
assert(int(i->finished_blocks.count()) < blocks_per_piece);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
t->get_policy().piece_finished(p.piece, verified);
|
t->get_policy().piece_finished(p.piece, verified);
|
||||||
|
|
||||||
|
@ -1138,9 +1166,13 @@ namespace libtorrent
|
||||||
t->completed();
|
t->completed();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
t->check_invariant();
|
}
|
||||||
|
catch (std::exception const& e)
|
||||||
|
{
|
||||||
|
std::string err = e.what();
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -965,7 +965,12 @@ namespace libtorrent
|
||||||
assert(index < (int)m_piece_map.size());
|
assert(index < (int)m_piece_map.size());
|
||||||
assert(index >= 0);
|
assert(index >= 0);
|
||||||
|
|
||||||
if (m_piece_map[index].downloading == 0) return false;
|
if (m_piece_map[index].downloading == 0)
|
||||||
|
{
|
||||||
|
assert(std::find_if(m_downloads.begin(), m_downloads.end(), has_index(index))
|
||||||
|
== m_downloads.end());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
std::vector<downloading_piece>::const_iterator i
|
std::vector<downloading_piece>::const_iterator i
|
||||||
= std::find_if(m_downloads.begin(), m_downloads.end(), has_index(index));
|
= std::find_if(m_downloads.begin(), m_downloads.end(), has_index(index));
|
||||||
assert(i != m_downloads.end());
|
assert(i != m_downloads.end());
|
||||||
|
|
|
@ -734,7 +734,8 @@ namespace libtorrent
|
||||||
{
|
{
|
||||||
int corr = 0;
|
int corr = 0;
|
||||||
assert(!m_have_pieces[i->index]);
|
assert(!m_have_pieces[i->index]);
|
||||||
assert(int(i->finished_blocks.count()) < blocks_per_piece);
|
assert(int(i->finished_blocks.count())
|
||||||
|
< m_torrent_file.piece_size(i->index) / m_block_size);
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
for (std::vector<piece_picker::downloading_piece>::const_iterator j = boost::next(i);
|
for (std::vector<piece_picker::downloading_piece>::const_iterator j = boost::next(i);
|
||||||
|
|
Loading…
Reference in New Issue