if priorities are changed so that the torrent changes state to be finished, a torrent_finished_alert is generated now. Fixes #305

This commit is contained in:
Arvid Norberg 2008-04-13 07:39:37 +00:00
parent 17c4257cce
commit 6639f72804
2 changed files with 19 additions and 8 deletions

View File

@ -573,7 +573,7 @@ namespace libtorrent
, boost::intrusive_ptr<peer_connection> p) const;
bool request_bandwidth_from_session(int channel) const;
void update_peer_interest();
void update_peer_interest(bool was_finished);
boost::intrusive_ptr<torrent_info> m_torrent_file;

View File

@ -1488,9 +1488,10 @@ namespace libtorrent
TORRENT_ASSERT(index >= 0);
TORRENT_ASSERT(index < m_torrent_file->num_pieces());
bool was_finished = is_finished();
bool filter_updated = m_picker->set_piece_priority(index, priority);
TORRENT_ASSERT(m_num_pieces >= m_picker->num_have_filtered());
if (filter_updated) update_peer_interest();
if (filter_updated) update_peer_interest(was_finished);
}
int torrent::piece_priority(int index) const
@ -1520,6 +1521,7 @@ namespace libtorrent
int index = 0;
bool filter_updated = false;
bool was_finished = is_finished();
for (std::vector<int>::const_iterator i = pieces.begin()
, end(pieces.end()); i != end; ++i, ++index)
{
@ -1528,7 +1530,7 @@ namespace libtorrent
filter_updated |= m_picker->set_piece_priority(index, *i);
TORRENT_ASSERT(m_num_pieces >= m_picker->num_have_filtered());
}
if (filter_updated) update_peer_interest();
if (filter_updated) update_peer_interest(was_finished);
}
void torrent::piece_priorities(std::vector<int>& pieces) const
@ -1571,6 +1573,8 @@ namespace libtorrent
if (m_torrent_file->num_pieces() == 0) return;
bool was_finished = is_finished();
int piece_length = m_torrent_file->piece_length();
// initialize the piece priorities to 0, then only allow
// setting higher priorities
@ -1594,19 +1598,24 @@ namespace libtorrent
, bind(&set_if_greater, _1, files[i]));
}
prioritize_pieces(pieces);
update_peer_interest();
update_peer_interest(was_finished);
}
// this is called when piece priorities have been updated
// updates the interested flag in peers
void torrent::update_peer_interest()
void torrent::update_peer_interest(bool was_finished)
{
for (peer_iterator i = begin(); i != end(); ++i)
(*i)->update_interest();
// if we used to be finished, but we aren't anymore
// we may need to connect to peers again
if (!is_finished())
if (!is_finished() && was_finished)
m_policy.recalculate_connect_candidates();
// the torrent just became finished
if (is_finished() && !was_finished)
finished();
}
void torrent::filter_piece(int index, bool filter)
@ -1621,8 +1630,9 @@ namespace libtorrent
TORRENT_ASSERT(index >= 0);
TORRENT_ASSERT(index < m_torrent_file->num_pieces());
bool was_finished = is_finished();
m_picker->set_piece_priority(index, filter ? 1 : 0);
update_peer_interest();
update_peer_interest(was_finished);
}
void torrent::filter_pieces(std::vector<bool> const& bitmask)
@ -1635,6 +1645,7 @@ namespace libtorrent
TORRENT_ASSERT(m_picker.get());
bool was_finished = is_finished();
int index = 0;
for (std::vector<bool>::const_iterator i = bitmask.begin()
, end(bitmask.end()); i != end; ++i, ++index)
@ -1645,7 +1656,7 @@ namespace libtorrent
else
m_picker->set_piece_priority(index, 1);
}
update_peer_interest();
update_peer_interest(was_finished);
}
bool torrent::is_piece_filtered(int index) const