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