diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 00c96aa6f..3cc602bcc 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -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()) diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 8e2786554..b49b129b7 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -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;