fix multiple bitfields issue

This commit is contained in:
Arvid Norberg 2012-05-02 01:08:25 +00:00
parent 93b1a3478f
commit bf3751640a
2 changed files with 23 additions and 19 deletions

View File

@ -563,6 +563,20 @@ namespace libtorrent
#endif
}
void peer_lost(bitfield const& bits)
{
if (has_picker())
{
m_picker->dec_refcount(bits);
}
#ifdef TORRENT_DEBUG
else
{
TORRENT_ASSERT(is_seed());
}
#endif
}
void peer_lost(int index)
{
if (has_picker())

View File

@ -1864,6 +1864,14 @@ namespace libtorrent
return;
}
if (m_bitfield_received)
{
// if we've already received a bitfield message
// we first need to count down all the pieces
// we believe the peer has first
t->peer_lost(bits);
}
m_bitfield_received = true;
// if we don't have metadata yet
@ -1909,25 +1917,7 @@ namespace libtorrent
// peer has
// if we're a seed, we don't keep track of piece availability
bool interesting = false;
if (!t->is_upload_only())
{
t->peer_has(bits);
for (int i = 0; i < (int)m_have_piece.size(); ++i)
{
bool have = bits[i];
if (have && !m_have_piece[i])
{
if (!t->have_piece(i) && t->picker().piece_priority(i) != 0)
interesting = true;
}
else if (!have && m_have_piece[i])
{
// this should probably not be allowed
t->peer_lost(i);
}
}
}
t->peer_has(bits);
m_have_piece = bits;
m_num_pieces = num_pieces;