reverted bad check-in where files_checked was removed from piece_picker
This commit is contained in:
parent
8957b64c04
commit
7ff5893431
|
@ -112,15 +112,17 @@ namespace libtorrent
|
|||
block_info info[max_blocks_per_piece];
|
||||
};
|
||||
|
||||
// the vector tells which pieces we already have
|
||||
// and which we don't have.
|
||||
piece_picker(int blocks_per_piece
|
||||
, int total_num_blocks
|
||||
, std::vector<bool> const& pieces
|
||||
, std::vector<downloading_piece> const& unfinished);
|
||||
, int total_num_blocks);
|
||||
|
||||
void set_sequenced_download_threshold(int sequenced_download_threshold);
|
||||
|
||||
// the vector tells which pieces we already have
|
||||
// and which we don't have.
|
||||
void files_checked(
|
||||
const std::vector<bool>& pieces
|
||||
, const std::vector<downloading_piece>& unfinished);
|
||||
|
||||
// increases the peer count for the given piece
|
||||
// (is used when a HAVE or BITFIELD message is received)
|
||||
void inc_refcount(int index);
|
||||
|
@ -300,8 +302,8 @@ namespace libtorrent
|
|||
}
|
||||
|
||||
void add(int index);
|
||||
//TODO: should be renamed update()
|
||||
void move(int vec_index, int elem_index);
|
||||
// void remove(int vec_index, int elem_index);
|
||||
|
||||
int add_interesting_blocks(const std::vector<int>& piece_list
|
||||
, const std::vector<bool>& pieces
|
||||
|
@ -350,6 +352,9 @@ namespace libtorrent
|
|||
// the required popularity of a piece in order to download
|
||||
// it in sequence instead of random order.
|
||||
int m_sequenced_download_threshold;
|
||||
#ifndef NDEBUG
|
||||
bool m_files_checked_called;
|
||||
#endif
|
||||
};
|
||||
|
||||
inline int piece_picker::blocks_in_piece(int index) const
|
||||
|
|
|
@ -416,15 +416,13 @@ namespace libtorrent
|
|||
alert_manager& alerts() const;
|
||||
piece_picker& picker()
|
||||
{
|
||||
assert(m_files_checked_called);
|
||||
assert(!is_seed());
|
||||
assert(m_picker.get());
|
||||
return *m_picker;
|
||||
}
|
||||
bool has_picker() const
|
||||
{
|
||||
assert((m_files_checked_called && !is_seed())
|
||||
== bool(m_picker.get()));
|
||||
assert((valid_metadata() && !is_seed()) == bool(m_picker.get()));
|
||||
return m_picker.get();
|
||||
}
|
||||
policy& get_policy()
|
||||
|
@ -686,10 +684,6 @@ namespace libtorrent
|
|||
// is started. i.e.
|
||||
// total_done - m_initial_done <= total_payload_download
|
||||
size_type m_initial_done;
|
||||
|
||||
// set to true once files_checked has been called
|
||||
// and the piece picker is constructed
|
||||
bool m_files_checked_called;
|
||||
#endif
|
||||
|
||||
#ifdef TORRENT_LOGGING
|
||||
|
|
|
@ -54,9 +54,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
namespace libtorrent
|
||||
{
|
||||
|
||||
piece_picker::piece_picker(int blocks_per_piece, int total_num_blocks
|
||||
, std::vector<bool> const& pieces
|
||||
, std::vector<downloading_piece> const& unfinished)
|
||||
piece_picker::piece_picker(int blocks_per_piece, int total_num_blocks)
|
||||
: m_piece_info(2)
|
||||
, m_piece_map((total_num_blocks + blocks_per_piece-1) / blocks_per_piece)
|
||||
, m_num_filtered(0)
|
||||
|
@ -65,6 +63,9 @@ namespace libtorrent
|
|||
{
|
||||
assert(blocks_per_piece > 0);
|
||||
assert(total_num_blocks >= 0);
|
||||
#ifndef NDEBUG
|
||||
m_files_checked_called = false;
|
||||
#endif
|
||||
|
||||
// the piece index is stored in 20 bits, which limits the allowed
|
||||
// number of pieces somewhat
|
||||
|
@ -83,8 +84,16 @@ namespace libtorrent
|
|||
// and make them invalid (as if though we already had every piece)
|
||||
std::fill(m_piece_map.begin(), m_piece_map.end()
|
||||
, piece_pos(0, piece_pos::we_have_index));
|
||||
}
|
||||
|
||||
|
||||
// pieces is a bitmask with the pieces we have
|
||||
void piece_picker::files_checked(
|
||||
const std::vector<bool>& pieces
|
||||
, const std::vector<downloading_piece>& unfinished)
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
m_files_checked_called = true;
|
||||
#endif
|
||||
for (std::vector<bool>::const_iterator i = pieces.begin();
|
||||
i != pieces.end(); ++i)
|
||||
{
|
||||
|
@ -119,7 +128,6 @@ namespace libtorrent
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void piece_picker::set_sequenced_download_threshold(
|
||||
|
@ -370,6 +378,7 @@ namespace libtorrent
|
|||
{
|
||||
assert(priority > 0);
|
||||
assert(elem_index >= 0);
|
||||
assert(m_files_checked_called);
|
||||
|
||||
assert(int(m_piece_info.size()) > priority);
|
||||
assert(int(m_piece_info[priority].size()) > elem_index);
|
||||
|
@ -525,6 +534,7 @@ namespace libtorrent
|
|||
|
||||
assert(index >= 0);
|
||||
assert(index < (int)m_piece_map.size());
|
||||
assert(m_files_checked_called);
|
||||
|
||||
assert(m_piece_map[index].downloading == 1);
|
||||
|
||||
|
@ -546,6 +556,7 @@ namespace libtorrent
|
|||
// TORRENT_PIECE_PICKER_INVARIANT_CHECK;
|
||||
assert(i >= 0);
|
||||
assert(i < (int)m_piece_map.size());
|
||||
assert(m_files_checked_called);
|
||||
|
||||
piece_pos& p = m_piece_map[i];
|
||||
int index = p.index;
|
||||
|
@ -578,6 +589,7 @@ namespace libtorrent
|
|||
{
|
||||
// TORRENT_PIECE_PICKER_INVARIANT_CHECK;
|
||||
|
||||
assert(m_files_checked_called);
|
||||
assert(i >= 0);
|
||||
assert(i < (int)m_piece_map.size());
|
||||
|
||||
|
@ -744,6 +756,7 @@ namespace libtorrent
|
|||
TORRENT_PIECE_PICKER_INVARIANT_CHECK;
|
||||
assert(num_blocks > 0);
|
||||
assert(pieces.size() == m_piece_map.size());
|
||||
assert(m_files_checked_called);
|
||||
|
||||
// free refers to pieces that are free to download, no one else
|
||||
// is downloading them.
|
||||
|
|
|
@ -274,7 +274,6 @@ namespace libtorrent
|
|||
{
|
||||
#ifndef NDEBUG
|
||||
m_initial_done = 0;
|
||||
m_files_checked_called = false;
|
||||
#endif
|
||||
#ifdef TORRENT_LOGGING
|
||||
m_log = ses.create_log("torrent_"
|
||||
|
@ -366,7 +365,6 @@ namespace libtorrent
|
|||
{
|
||||
#ifndef NDEBUG
|
||||
m_initial_done = 0;
|
||||
m_files_checked_called = false;
|
||||
#endif
|
||||
|
||||
#ifdef TORRENT_LOGGING
|
||||
|
@ -466,6 +464,9 @@ namespace libtorrent
|
|||
m_storage.reset(new piece_manager(m_torrent_file, m_save_path
|
||||
, m_ses.m_files, m_storage_constructor));
|
||||
m_block_size = calculate_block_size(m_torrent_file, m_default_block_size);
|
||||
m_picker.reset(new piece_picker(
|
||||
static_cast<int>(m_torrent_file.piece_length() / m_block_size)
|
||||
, static_cast<int>((m_torrent_file.total_size()+m_block_size-1)/m_block_size)));
|
||||
|
||||
std::vector<std::string> const& url_seeds = m_torrent_file.url_seeds();
|
||||
std::copy(url_seeds.begin(), url_seeds.end(), std::inserter(m_web_seeds
|
||||
|
@ -705,7 +706,7 @@ namespace libtorrent
|
|||
{
|
||||
INVARIANT_CHECK;
|
||||
|
||||
if (!has_picker() || m_torrent_file.num_pieces() == 0)
|
||||
if (!valid_metadata() || m_torrent_file.num_pieces() == 0)
|
||||
return tuple<size_type, size_type>(0,0);
|
||||
|
||||
const int last_piece = m_torrent_file.num_pieces() - 1;
|
||||
|
@ -2136,18 +2137,15 @@ namespace libtorrent
|
|||
|
||||
if (!is_seed())
|
||||
{
|
||||
m_picker.reset(new piece_picker(
|
||||
static_cast<int>(m_torrent_file.piece_length() / m_block_size)
|
||||
, static_cast<int>((m_torrent_file.total_size()+m_block_size-1)/m_block_size)
|
||||
, m_have_pieces, unfinished_pieces));
|
||||
m_files_checked_called = true;
|
||||
m_picker->files_checked(m_have_pieces, unfinished_pieces);
|
||||
if (m_sequenced_download_threshold > 0)
|
||||
picker().set_sequenced_download_threshold(m_sequenced_download_threshold);
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(!m_picker);
|
||||
m_picker.reset();
|
||||
}
|
||||
|
||||
if (!m_connections_initialized)
|
||||
{
|
||||
m_connections_initialized = true;
|
||||
|
|
Loading…
Reference in New Issue