exposed piece availability vector

This commit is contained in:
Arvid Norberg 2007-05-30 06:52:59 +00:00
parent 1d15a5040c
commit 14a15831ef
6 changed files with 37 additions and 0 deletions

View File

@ -125,6 +125,8 @@ namespace libtorrent
piece_picker(int blocks_per_piece
, int total_num_blocks);
void get_availability(std::vector<int>& avail) const;
void set_sequenced_download_threshold(int sequenced_download_threshold);
// the vector tells which pieces we already have

View File

@ -184,6 +184,8 @@ namespace libtorrent
void filter_files(std::vector<bool> const& files);
// ============ end deprecation =============
void piece_availability(std::vector<int>& avail) const;
void set_piece_priority(int index, int priority);
int piece_priority(int index) const;

View File

@ -269,6 +269,8 @@ namespace libtorrent
// ================ end deprecation ============
void piece_availability(std::vector<int>& avail) const;
// priority must be within the range [0, 7]
void piece_priority(int index, int priority) const;
int piece_priority(int index) const;

View File

@ -1292,6 +1292,17 @@ namespace libtorrent
}
}
void piece_picker::get_availability(std::vector<int>& avail) const
{
TORRENT_PIECE_PICKER_INVARIANT_CHECK;
avail.resize(m_piece_map.size());
std::vector<int>::iterator j = avail.begin();
for (std::vector<piece_pos>::const_iterator i = m_piece_map.begin()
, end(m_piece_map.end()); i != end; ++i, ++j)
*j = i->peer_count;
}
void piece_picker::mark_as_finished(piece_block block, const tcp::endpoint& peer)
{
TORRENT_PIECE_PICKER_INVARIANT_CHECK;

View File

@ -981,7 +981,19 @@ namespace libtorrent
return m_username + ":" + m_password;
}
void torrent::piece_availability(std::vector<int>& avail) const
{
INVARIANT_CHECK;
assert(valid_metadata());
if (is_seed())
{
avail.clear();
return;
}
m_picker->get_availability(avail);
}
void torrent::set_piece_priority(int index, int priority)
{

View File

@ -352,6 +352,14 @@ namespace libtorrent
}
void torrent_handle::piece_availability(std::vector<int>& avail) const
{
INVARIANT_CHECK;
call_member<void>(m_ses, m_chk, m_info_hash
, bind(&torrent::piece_availability, _1, boost::ref(avail)));
}
void torrent_handle::piece_priority(int index, int priority) const
{
INVARIANT_CHECK;