mirror of
https://github.com/twisterarmy/twister-core.git
synced 2025-01-10 23:07:52 +00:00
keep track of last "have" for each torrent
This commit is contained in:
parent
f631bdf98d
commit
98903d5a73
@ -212,8 +212,8 @@ namespace libtorrent
|
||||
|
||||
// sets all pieces to dont-have
|
||||
void init(int blocks_per_piece, int blocks_in_last_piece, int total_num_pieces);
|
||||
void increase_num_pieces(int total_num_pieces);
|
||||
int num_pieces() const { return int(m_piece_map.size()); }
|
||||
void increase_num_pieces(int total_num_pieces);
|
||||
int num_pieces() const { return int(m_piece_map.size()); }
|
||||
|
||||
bool have_piece(int index) const
|
||||
{
|
||||
@ -357,6 +357,8 @@ namespace libtorrent
|
||||
|
||||
int num_have() const { return m_num_have; }
|
||||
|
||||
int last_have() const { return m_last_have; }
|
||||
|
||||
// the number of pieces we want and don't have
|
||||
int num_want_left() const { return num_pieces() - m_num_have - m_num_filtered; }
|
||||
|
||||
@ -611,6 +613,9 @@ namespace libtorrent
|
||||
// the number of pieces we have
|
||||
int m_num_have;
|
||||
|
||||
// the index of last have
|
||||
int m_last_have;
|
||||
|
||||
// we have all pieces in the range [0, m_cursor)
|
||||
// m_cursor is the first piece we don't have
|
||||
int m_cursor;
|
||||
|
@ -529,6 +529,13 @@ namespace libtorrent
|
||||
: m_torrent_file->num_pieces();
|
||||
}
|
||||
|
||||
int last_have() const
|
||||
{
|
||||
return has_picker()
|
||||
? m_picker->last_have()
|
||||
: -1;
|
||||
}
|
||||
|
||||
// when we get a have message, this is called for that piece
|
||||
void peer_has(int index, peer_connection const* peer)
|
||||
{
|
||||
|
@ -558,6 +558,9 @@ namespace libtorrent
|
||||
// std::accumulate(pieces->begin(), pieces->end());
|
||||
int num_pieces;
|
||||
|
||||
// index of last piece we have
|
||||
int last_have;
|
||||
|
||||
// the number of bytes of the file we have
|
||||
// including pieces that may have been filtered
|
||||
// after we downloaded them
|
||||
|
@ -71,6 +71,7 @@ namespace libtorrent
|
||||
, m_num_filtered(0)
|
||||
, m_num_have_filtered(0)
|
||||
, m_num_have(0)
|
||||
, m_last_have(-1)
|
||||
, m_cursor(0)
|
||||
, m_reverse_cursor(0)
|
||||
, m_sparse_regions(1)
|
||||
@ -104,6 +105,7 @@ namespace libtorrent
|
||||
m_num_filtered += m_num_have_filtered;
|
||||
m_num_have_filtered = 0;
|
||||
m_num_have = 0;
|
||||
m_last_have = -1;
|
||||
m_dirty = true;
|
||||
for (std::vector<piece_pos>::iterator i = m_piece_map.begin()
|
||||
, end(m_piece_map.end()); i != end; ++i)
|
||||
@ -1224,6 +1226,11 @@ namespace libtorrent
|
||||
--m_num_have;
|
||||
p.set_not_have();
|
||||
|
||||
if (index == m_last_have) {
|
||||
while( !m_piece_map[m_last_have].have() && m_last_have >= 0 )
|
||||
m_last_have--;
|
||||
}
|
||||
|
||||
if (m_dirty) return;
|
||||
if (p.priority(this) >= 0) add(index);
|
||||
}
|
||||
@ -1288,6 +1295,8 @@ namespace libtorrent
|
||||
}
|
||||
++m_num_have;
|
||||
p.set_have();
|
||||
if (index > m_last_have)
|
||||
m_last_have = index;
|
||||
if (m_cursor == m_reverse_cursor - 1 &&
|
||||
m_cursor == index)
|
||||
{
|
||||
|
@ -8537,6 +8537,7 @@ namespace libtorrent
|
||||
st->pieces.resize(num_pieces, true);
|
||||
}
|
||||
st->num_pieces = num_have();
|
||||
st->last_have = last_have();
|
||||
st->num_seeds = num_seeds();
|
||||
if ((flags & torrent_handle::query_distributed_copies) && m_picker.get())
|
||||
{
|
||||
|
@ -104,6 +104,7 @@ namespace libtorrent
|
||||
, list_peers(0)
|
||||
, connect_candidates(0)
|
||||
, num_pieces(0)
|
||||
, last_have(-1)
|
||||
, total_done(0)
|
||||
, total_wanted_done(0)
|
||||
, total_wanted(0)
|
||||
|
@ -147,10 +147,20 @@ torrent_handle startTorrentUser(std::string const &username)
|
||||
|
||||
m_userTorrent[username] = ses->add_torrent(tparams);
|
||||
m_userTorrent[username].force_dht_announce();
|
||||
torrent_status status = m_userTorrent[username].status();
|
||||
}
|
||||
return m_userTorrent[username];
|
||||
}
|
||||
|
||||
int lastPostKfromTorrent(std::string const &username)
|
||||
{
|
||||
if( !m_userTorrent.count(username) )
|
||||
return -1;
|
||||
|
||||
torrent_status status = m_userTorrent[username].status();
|
||||
return status.last_have;
|
||||
}
|
||||
|
||||
void ThreadWaitExtIP()
|
||||
{
|
||||
RenameThread("wait-extip");
|
||||
|
Loading…
Reference in New Issue
Block a user