2003-10-23 01:00:57 +02:00
|
|
|
/*
|
|
|
|
|
|
|
|
Copyright (c) 2003, Arvid Norberg
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions
|
|
|
|
are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
* Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in
|
|
|
|
the documentation and/or other materials provided with the distribution.
|
|
|
|
* Neither the name of the author nor the names of its
|
|
|
|
contributors may be used to endorse or promote products derived
|
|
|
|
from this software without specific prior written permission.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifndef TORRENT_PIECE_PICKER_HPP_INCLUDED
|
|
|
|
#define TORRENT_PIECE_PICKER_HPP_INCLUDED
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <vector>
|
|
|
|
#include <bitset>
|
|
|
|
#include <cassert>
|
2007-03-15 23:03:56 +01:00
|
|
|
#include <utility>
|
2003-10-23 01:00:57 +02:00
|
|
|
|
2004-01-25 19:18:36 +01:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma warning(push, 1)
|
|
|
|
#endif
|
|
|
|
|
2007-03-15 23:03:56 +01:00
|
|
|
#include <boost/static_assert.hpp>
|
2004-01-13 04:08:59 +01:00
|
|
|
|
2004-01-25 19:18:36 +01:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma warning(pop)
|
|
|
|
#endif
|
|
|
|
|
2003-11-02 22:06:50 +01:00
|
|
|
#include "libtorrent/peer_id.hpp"
|
2004-01-12 21:31:27 +01:00
|
|
|
#include "libtorrent/socket.hpp"
|
2006-04-25 23:04:48 +02:00
|
|
|
#include "libtorrent/session_settings.hpp"
|
2005-11-01 19:30:39 +01:00
|
|
|
#include "libtorrent/config.hpp"
|
2003-11-02 22:06:50 +01:00
|
|
|
|
2003-10-23 01:00:57 +02:00
|
|
|
namespace libtorrent
|
|
|
|
{
|
|
|
|
|
|
|
|
class torrent;
|
|
|
|
class peer_connection;
|
|
|
|
|
2005-11-01 19:30:39 +01:00
|
|
|
struct TORRENT_EXPORT piece_block
|
2003-10-23 01:00:57 +02:00
|
|
|
{
|
|
|
|
piece_block(int p_index, int b_index)
|
|
|
|
: piece_index(p_index)
|
|
|
|
, block_index(b_index)
|
2004-02-01 10:47:58 +01:00
|
|
|
{}
|
2003-10-23 01:00:57 +02:00
|
|
|
int piece_index;
|
|
|
|
int block_index;
|
2004-09-16 03:14:16 +02:00
|
|
|
|
|
|
|
bool operator<(piece_block const& b) const
|
|
|
|
{
|
|
|
|
if (piece_index < b.piece_index) return true;
|
|
|
|
if (piece_index == b.piece_index) return block_index < b.block_index;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(piece_block const& b) const
|
2003-11-05 00:27:06 +01:00
|
|
|
{ return piece_index == b.piece_index && block_index == b.block_index; }
|
|
|
|
|
2004-09-16 03:14:16 +02:00
|
|
|
bool operator!=(piece_block const& b) const
|
2003-11-05 00:27:06 +01:00
|
|
|
{ return piece_index != b.piece_index || block_index != b.block_index; }
|
|
|
|
|
2003-10-23 01:00:57 +02:00
|
|
|
};
|
|
|
|
|
2005-11-01 19:30:39 +01:00
|
|
|
class TORRENT_EXPORT piece_picker
|
2003-10-23 01:00:57 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2003-11-02 22:06:50 +01:00
|
|
|
struct block_info
|
|
|
|
{
|
2007-07-04 04:16:49 +02:00
|
|
|
block_info(): peer(0), num_downloads(0), state(state_none) {}
|
2003-11-02 22:06:50 +01:00
|
|
|
// the peer this block was requested or
|
2007-07-04 04:16:49 +02:00
|
|
|
// downloaded from. This is a pointer to
|
|
|
|
// a policy::peer object
|
|
|
|
void* peer;
|
2003-11-02 22:06:50 +01:00
|
|
|
// the number of times this block has been downloaded
|
2007-05-08 13:13:13 +02:00
|
|
|
unsigned num_downloads:14;
|
2007-06-10 22:46:09 +02:00
|
|
|
enum { state_none, state_requested, state_writing, state_finished };
|
|
|
|
unsigned state:2;
|
2003-11-02 22:06:50 +01:00
|
|
|
};
|
|
|
|
|
2007-04-27 02:27:37 +02:00
|
|
|
// the peers that are downloading this piece
|
|
|
|
// are considered fast peers or slow peers.
|
|
|
|
// none is set if the blocks were downloaded
|
|
|
|
// in a previous session
|
|
|
|
enum piece_state_t
|
|
|
|
{ none, slow, medium, fast };
|
|
|
|
|
2003-11-02 22:06:50 +01:00
|
|
|
struct downloading_piece
|
|
|
|
{
|
2007-06-10 22:46:09 +02:00
|
|
|
downloading_piece(): finished(0), writing(0), requested(0) {}
|
2007-04-27 02:27:37 +02:00
|
|
|
piece_state_t state;
|
|
|
|
|
|
|
|
// the index of the piece
|
2003-11-02 22:06:50 +01:00
|
|
|
int index;
|
|
|
|
// info about each block
|
2007-05-09 02:49:13 +02:00
|
|
|
// this is a pointer into the m_block_info
|
|
|
|
// vector owned by the piece_picker
|
|
|
|
block_info* info;
|
2007-06-10 22:46:09 +02:00
|
|
|
// the number of blocks in the finished state
|
|
|
|
boost::int16_t finished;
|
|
|
|
// the number of blocks in the writing state
|
|
|
|
boost::int16_t writing;
|
|
|
|
// the number of blocks in the requested state
|
|
|
|
boost::int16_t requested;
|
2003-11-02 22:06:50 +01:00
|
|
|
};
|
|
|
|
|
2006-04-25 23:04:48 +02:00
|
|
|
piece_picker(int blocks_per_piece
|
2007-03-17 18:28:59 +01:00
|
|
|
, int total_num_blocks);
|
2006-04-25 23:04:48 +02:00
|
|
|
|
2007-05-30 08:52:59 +02:00
|
|
|
void get_availability(std::vector<int>& avail) const;
|
|
|
|
|
2006-04-25 23:04:48 +02:00
|
|
|
void set_sequenced_download_threshold(int sequenced_download_threshold);
|
2003-10-23 01:00:57 +02:00
|
|
|
|
2007-03-17 18:28:59 +01:00
|
|
|
// the vector tells which pieces we already have
|
|
|
|
// and which we don't have.
|
|
|
|
void files_checked(
|
2007-06-10 22:46:09 +02:00
|
|
|
std::vector<bool> const& pieces
|
|
|
|
, std::vector<downloading_piece> const& unfinished
|
|
|
|
, std::vector<int>& verify_pieces);
|
2007-03-17 18:28:59 +01:00
|
|
|
|
2003-10-23 01:00:57 +02:00
|
|
|
// increases the peer count for the given piece
|
|
|
|
// (is used when a HAVE or BITFIELD message is received)
|
2003-12-18 04:30:41 +01:00
|
|
|
void inc_refcount(int index);
|
2003-10-23 01:00:57 +02:00
|
|
|
|
2003-12-18 04:30:41 +01:00
|
|
|
// decreases the peer count for the given piece
|
|
|
|
// (used when a peer disconnects)
|
2003-10-23 01:00:57 +02:00
|
|
|
void dec_refcount(int index);
|
2007-04-15 04:14:02 +02:00
|
|
|
|
|
|
|
// these will increase and decrease the peer count
|
|
|
|
// of all pieces. They are used when seeds join
|
|
|
|
// or leave the swarm.
|
|
|
|
void inc_refcount_all();
|
|
|
|
void dec_refcount_all();
|
2003-10-23 01:00:57 +02:00
|
|
|
|
|
|
|
// This indicates that we just received this piece
|
|
|
|
// it means that the refcounter will indicate that
|
|
|
|
// we are not interested in this piece anymore
|
|
|
|
// (i.e. we don't have to maintain a refcount)
|
|
|
|
void we_have(int index);
|
|
|
|
|
2007-03-15 23:03:56 +01:00
|
|
|
// sets the priority of a piece.
|
|
|
|
void set_piece_priority(int index, int prio);
|
2005-05-25 12:01:01 +02:00
|
|
|
|
2007-03-15 23:03:56 +01:00
|
|
|
// returns the priority for the piece at 'index'
|
|
|
|
int piece_priority(int index) const;
|
2005-05-25 12:01:01 +02:00
|
|
|
|
2007-03-20 02:59:00 +01:00
|
|
|
// returns the current piece priorities for all pieces
|
|
|
|
void piece_priorities(std::vector<int>& pieces) const;
|
|
|
|
|
|
|
|
// ========== start deprecation ==============
|
|
|
|
|
2005-05-25 12:01:01 +02:00
|
|
|
// fills the bitmask with 1's for pieces that are filtered
|
|
|
|
void filtered_pieces(std::vector<bool>& mask) const;
|
|
|
|
|
2007-03-20 02:59:00 +01:00
|
|
|
// ========== end deprecation ==============
|
|
|
|
|
2003-10-23 01:00:57 +02:00
|
|
|
// pieces should be the vector that represents the pieces a
|
|
|
|
// client has. It returns a list of all pieces that this client
|
|
|
|
// has and that are interesting to download. It returns them in
|
|
|
|
// priority order. It doesn't care about the download flag.
|
|
|
|
// The user of this function must lookup if any piece is
|
|
|
|
// marked as being downloaded. If the user of this function
|
|
|
|
// decides to download a piece, it must mark it as being downloaded
|
|
|
|
// itself, by using the mark_as_downloading() member function.
|
2004-11-30 12:17:32 +01:00
|
|
|
// THIS IS DONE BY THE peer_connection::send_request() MEMBER FUNCTION!
|
2007-07-04 04:16:49 +02:00
|
|
|
// The last argument is the policy::peer pointer for the peer that
|
|
|
|
// we'll download from.
|
2005-08-15 00:04:58 +02:00
|
|
|
void pick_pieces(const std::vector<bool>& pieces
|
|
|
|
, std::vector<piece_block>& interesting_blocks
|
|
|
|
, int num_pieces, bool prefer_whole_pieces
|
2007-07-04 04:16:49 +02:00
|
|
|
, void* peer, piece_state_t speed) const;
|
|
|
|
|
|
|
|
// clears the peer pointer in all downloading pieces with this
|
|
|
|
// peer pointer
|
|
|
|
void clear_peer(void* peer);
|
2003-10-23 01:00:57 +02:00
|
|
|
|
|
|
|
// returns true if any client is currently downloading this
|
|
|
|
// piece-block, or if it's queued for downloading by some client
|
2005-08-15 00:04:58 +02:00
|
|
|
// or if it already has been successfully downloaded
|
2007-06-10 22:46:09 +02:00
|
|
|
bool is_requested(piece_block block) const;
|
|
|
|
// returns true if the block has been downloaded
|
|
|
|
bool is_downloaded(piece_block block) const;
|
|
|
|
// returns true if the block has been downloaded and written to disk
|
2003-11-05 00:27:06 +01:00
|
|
|
bool is_finished(piece_block block) const;
|
|
|
|
|
2003-10-23 01:00:57 +02:00
|
|
|
// marks this piece-block as queued for downloading
|
2007-07-04 04:16:49 +02:00
|
|
|
void mark_as_downloading(piece_block block, void* peer
|
2007-04-27 02:27:37 +02:00
|
|
|
, piece_state_t s);
|
2007-07-04 04:16:49 +02:00
|
|
|
void mark_as_writing(piece_block block, void* peer);
|
|
|
|
void mark_as_finished(piece_block block, void* peer);
|
2003-10-23 01:00:57 +02:00
|
|
|
|
2005-02-23 17:56:32 +01:00
|
|
|
// if a piece had a hash-failure, it must be restored and
|
2003-11-02 22:06:50 +01:00
|
|
|
// made available for redownloading
|
2003-10-23 01:00:57 +02:00
|
|
|
void restore_piece(int index);
|
|
|
|
|
|
|
|
// clears the given piece's download flag
|
|
|
|
// this means that this piece-block can be picked again
|
|
|
|
void abort_download(piece_block block);
|
|
|
|
|
|
|
|
bool is_piece_finished(int index) const;
|
|
|
|
|
2005-02-23 17:56:32 +01:00
|
|
|
// returns the number of blocks there is in the given piece
|
2003-10-30 00:28:09 +01:00
|
|
|
int blocks_in_piece(int index) const;
|
2003-11-02 22:06:50 +01:00
|
|
|
|
|
|
|
// the number of downloaded blocks that hasn't passed
|
|
|
|
// the hash-check yet
|
2003-10-30 00:28:09 +01:00
|
|
|
int unverified_blocks() const;
|
2003-10-23 01:00:57 +02:00
|
|
|
|
2007-07-04 04:16:49 +02:00
|
|
|
void get_downloaders(std::vector<void*>& d, int index) const;
|
2004-01-13 04:08:59 +01:00
|
|
|
|
2006-12-21 03:44:00 +01:00
|
|
|
std::vector<downloading_piece> const& get_download_queue() const
|
2003-11-02 22:06:50 +01:00
|
|
|
{ return m_downloads; }
|
|
|
|
|
2007-07-04 04:16:49 +02:00
|
|
|
void* get_downloader(piece_block block) const;
|
2004-01-13 04:08:59 +01:00
|
|
|
|
2005-05-30 19:43:03 +02:00
|
|
|
// the number of filtered pieces we don't have
|
|
|
|
int num_filtered() const { return m_num_filtered; }
|
|
|
|
|
|
|
|
// the number of filtered pieces we already have
|
|
|
|
int num_have_filtered() const { return m_num_have_filtered; }
|
2007-04-12 00:27:58 +02:00
|
|
|
|
2003-10-23 01:00:57 +02:00
|
|
|
#ifndef NDEBUG
|
|
|
|
// used in debug mode
|
2006-07-16 02:08:50 +02:00
|
|
|
void check_invariant(const torrent* t = 0) const;
|
2003-10-23 01:00:57 +02:00
|
|
|
#endif
|
|
|
|
|
2004-01-03 03:10:11 +01:00
|
|
|
// functor that compares indices on downloading_pieces
|
|
|
|
struct has_index
|
|
|
|
{
|
2004-01-26 01:21:12 +01:00
|
|
|
has_index(int i): index(i) { assert(i >= 0); }
|
2004-01-03 03:10:11 +01:00
|
|
|
bool operator()(const downloading_piece& p) const
|
|
|
|
{ return p.index == index; }
|
|
|
|
int index;
|
|
|
|
};
|
|
|
|
|
2004-01-15 17:45:34 +01:00
|
|
|
int blocks_in_last_piece() const
|
|
|
|
{ return m_blocks_in_last_piece; }
|
|
|
|
|
2004-08-05 15:56:26 +02:00
|
|
|
float distributed_copies() const;
|
|
|
|
|
2003-10-23 01:00:57 +02:00
|
|
|
private:
|
|
|
|
|
|
|
|
struct piece_pos
|
|
|
|
{
|
|
|
|
piece_pos() {}
|
|
|
|
piece_pos(int peer_count_, int index_)
|
|
|
|
: peer_count(peer_count_)
|
|
|
|
, downloading(0)
|
2007-03-15 23:03:56 +01:00
|
|
|
, piece_priority(1)
|
2003-10-23 01:00:57 +02:00
|
|
|
, index(index_)
|
2004-01-26 01:21:12 +01:00
|
|
|
{
|
|
|
|
assert(peer_count_ >= 0);
|
|
|
|
assert(index_ >= 0);
|
|
|
|
}
|
2003-10-23 01:00:57 +02:00
|
|
|
|
|
|
|
// selects which vector to look in
|
2007-03-15 23:03:56 +01:00
|
|
|
unsigned peer_count : 10;
|
2003-10-23 01:00:57 +02:00
|
|
|
// is 1 if the piece is marked as being downloaded
|
|
|
|
unsigned downloading : 1;
|
2007-03-15 23:03:56 +01:00
|
|
|
// is 0 if the piece is filtered (not to be downloaded)
|
|
|
|
// 1 is normal priority (default)
|
2007-03-20 02:59:00 +01:00
|
|
|
// 2 is higher priority than pieces at the same availability level
|
|
|
|
// 3 is same priority as partial pieces
|
|
|
|
// 4 is higher priority than partial pieces
|
|
|
|
// 5 and 6 same priority as availability 1 (ignores availability)
|
|
|
|
// 7 is maximum priority (ignores availability)
|
|
|
|
unsigned piece_priority : 3;
|
2003-10-23 01:00:57 +02:00
|
|
|
// index in to the piece_info vector
|
2007-03-20 02:59:00 +01:00
|
|
|
unsigned index : 18;
|
2003-10-23 01:00:57 +02:00
|
|
|
|
2007-03-15 23:03:56 +01:00
|
|
|
enum
|
2006-04-25 23:04:48 +02:00
|
|
|
{
|
2007-03-15 23:03:56 +01:00
|
|
|
// index is set to this to indicate that we have the
|
|
|
|
// piece. There is no entry for the piece in the
|
|
|
|
// buckets if this is the case.
|
2007-03-20 02:59:00 +01:00
|
|
|
we_have_index = 0x3ffff,
|
2007-03-15 23:03:56 +01:00
|
|
|
// the priority value that means the piece is filtered
|
|
|
|
filter_priority = 0,
|
|
|
|
// the max number the peer count can hold
|
|
|
|
max_peer_count = 0x3ff
|
|
|
|
};
|
|
|
|
|
|
|
|
bool have() const { return index == we_have_index; }
|
|
|
|
void set_have() { index = we_have_index; assert(have()); }
|
2006-04-25 23:04:48 +02:00
|
|
|
|
2007-03-15 23:03:56 +01:00
|
|
|
bool filtered() const { return piece_priority == filter_priority; }
|
|
|
|
void filtered(bool f) { piece_priority = f ? filter_priority : 0; }
|
|
|
|
|
|
|
|
int priority(int limit) const
|
2006-04-25 23:04:48 +02:00
|
|
|
{
|
2007-03-15 23:03:56 +01:00
|
|
|
if (filtered() || have()) return 0;
|
2007-04-17 11:21:53 +02:00
|
|
|
// pieces we are currently downloading have high priority
|
2007-04-18 22:40:41 +02:00
|
|
|
int prio = downloading ? (std::min)(1, int(peer_count)) : peer_count * 2;
|
2007-03-15 23:03:56 +01:00
|
|
|
// if the peer_count is 0 or 1, the priority cannot be higher
|
|
|
|
if (prio <= 1) return prio;
|
|
|
|
if (prio >= limit * 2) prio = limit * 2;
|
|
|
|
// the different priority levels
|
|
|
|
switch (piece_priority)
|
|
|
|
{
|
|
|
|
case 2: return prio - 1;
|
2007-03-20 02:59:00 +01:00
|
|
|
case 3: return (std::max)(prio / 2, 1);
|
|
|
|
case 4: return (std::max)(prio / 2 - 1, 1);
|
|
|
|
case 5:
|
|
|
|
case 6: return (std::min)(prio / 2 - 1, 2);
|
|
|
|
case 7: return 1;
|
2007-03-15 23:03:56 +01:00
|
|
|
}
|
|
|
|
return prio;
|
2006-04-25 23:04:48 +02:00
|
|
|
}
|
2007-03-15 23:03:56 +01:00
|
|
|
|
2006-04-25 23:04:48 +02:00
|
|
|
bool operator!=(piece_pos p) const
|
2003-10-23 01:00:57 +02:00
|
|
|
{ return index != p.index || peer_count != p.peer_count; }
|
|
|
|
|
2006-04-25 23:04:48 +02:00
|
|
|
bool operator==(piece_pos p) const
|
2003-10-23 01:00:57 +02:00
|
|
|
{ return index == p.index && peer_count == p.peer_count; }
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2007-03-15 23:03:56 +01:00
|
|
|
BOOST_STATIC_ASSERT(sizeof(piece_pos) == sizeof(char) * 4);
|
2003-11-02 22:06:50 +01:00
|
|
|
|
2007-03-15 23:03:56 +01:00
|
|
|
bool is_ordered(int priority) const
|
|
|
|
{
|
|
|
|
return priority >= m_sequenced_download_threshold * 2;
|
|
|
|
}
|
2003-10-23 01:00:57 +02:00
|
|
|
|
2007-03-15 23:03:56 +01:00
|
|
|
void add(int index);
|
|
|
|
void move(int vec_index, int elem_index);
|
2005-08-15 00:04:58 +02:00
|
|
|
|
2007-03-15 23:03:56 +01:00
|
|
|
int add_interesting_blocks(const std::vector<int>& piece_list
|
|
|
|
, const std::vector<bool>& pieces
|
|
|
|
, std::vector<piece_block>& interesting_blocks
|
|
|
|
, std::vector<piece_block>& backup_blocks
|
|
|
|
, int num_blocks, bool prefer_whole_pieces
|
2007-07-04 04:16:49 +02:00
|
|
|
, void* peer, piece_state_t speed) const;
|
2003-10-23 01:00:57 +02:00
|
|
|
|
2007-05-09 02:49:13 +02:00
|
|
|
downloading_piece& add_download_piece();
|
|
|
|
void erase_download_piece(std::vector<downloading_piece>::iterator i);
|
|
|
|
|
2003-10-23 01:00:57 +02:00
|
|
|
// this vector contains all pieces we don't have.
|
|
|
|
// in the first entry (index 0) is a vector of all pieces
|
|
|
|
// that no peer have, the vector at index 1 contains
|
|
|
|
// all pieces that exactly one peer have, index 2 contains
|
|
|
|
// all pieces exactly two peers have and so on.
|
2007-03-15 23:03:56 +01:00
|
|
|
// this is not entirely true. The availibility of a piece
|
|
|
|
// is adjusted depending on its priority. But the principle
|
|
|
|
// is that the higher index, the lower priority a piece has.
|
2003-10-23 01:00:57 +02:00
|
|
|
std::vector<std::vector<int> > m_piece_info;
|
2003-10-23 18:55:52 +02:00
|
|
|
|
2003-10-23 01:00:57 +02:00
|
|
|
// this maps indices to number of peers that has this piece and
|
|
|
|
// index into the m_piece_info vectors.
|
2005-05-25 12:01:01 +02:00
|
|
|
// piece_pos::we_have_index means that we have the piece, so it
|
|
|
|
// doesn't exist in the piece_info buckets
|
2005-09-01 23:04:21 +02:00
|
|
|
// pieces with the filtered flag set doesn't have entries in
|
|
|
|
// the m_piece_info buckets either
|
2003-10-23 01:00:57 +02:00
|
|
|
std::vector<piece_pos> m_piece_map;
|
|
|
|
|
|
|
|
// each piece that's currently being downloaded
|
|
|
|
// has an entry in this list with block allocations.
|
|
|
|
// i.e. it says wich parts of the piece that
|
|
|
|
// is being downloaded
|
|
|
|
std::vector<downloading_piece> m_downloads;
|
|
|
|
|
2007-05-09 02:49:13 +02:00
|
|
|
// this holds the information of the
|
|
|
|
// blocks in partially downloaded pieces.
|
|
|
|
// the first m_blocks_per_piece entries
|
|
|
|
// in the vector belongs to the first
|
|
|
|
// entry in m_downloads, the second
|
|
|
|
// m_blocks_per_piece entries to the
|
|
|
|
// second entry in m_downloads and so on.
|
|
|
|
std::vector<block_info> m_block_info;
|
|
|
|
|
2003-10-23 01:00:57 +02:00
|
|
|
int m_blocks_per_piece;
|
|
|
|
int m_blocks_in_last_piece;
|
|
|
|
|
2005-05-30 19:43:03 +02:00
|
|
|
// the number of filtered pieces that we don't already
|
|
|
|
// have. total_number_of_pieces - number_of_pieces_we_have
|
|
|
|
// - num_filtered is supposed to the number of pieces
|
|
|
|
// we still want to download
|
|
|
|
int m_num_filtered;
|
|
|
|
|
|
|
|
// the number of pieces we have that also are filtered
|
|
|
|
int m_num_have_filtered;
|
2007-05-14 12:54:18 +02:00
|
|
|
|
|
|
|
// the number of pieces we have
|
|
|
|
int m_num_have;
|
2006-04-25 23:04:48 +02:00
|
|
|
|
|
|
|
// the required popularity of a piece in order to download
|
|
|
|
// it in sequence instead of random order.
|
|
|
|
int m_sequenced_download_threshold;
|
2007-03-17 18:28:59 +01:00
|
|
|
#ifndef NDEBUG
|
|
|
|
bool m_files_checked_called;
|
|
|
|
#endif
|
2003-10-23 01:00:57 +02:00
|
|
|
};
|
|
|
|
|
2003-10-30 00:28:09 +01:00
|
|
|
inline int piece_picker::blocks_in_piece(int index) const
|
|
|
|
{
|
2004-01-26 01:21:12 +01:00
|
|
|
assert(index >= 0);
|
|
|
|
assert(index < (int)m_piece_map.size());
|
2004-01-26 11:29:00 +01:00
|
|
|
if (index+1 == (int)m_piece_map.size())
|
2003-10-30 00:28:09 +01:00
|
|
|
return m_blocks_in_last_piece;
|
|
|
|
else
|
|
|
|
return m_blocks_per_piece;
|
|
|
|
}
|
|
|
|
|
2003-10-23 01:00:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // TORRENT_PIECE_PICKER_HPP_INCLUDED
|
2005-11-01 19:30:39 +01:00
|
|
|
|