From af25f2653841e80885bc49dd479559328b075ae5 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Fri, 12 Jun 2009 16:12:19 +0000 Subject: [PATCH] correction of previous 'assert fix' --- src/peer_connection.cpp | 19 +++++++++++-------- src/piece_picker.cpp | 2 -- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 660849be1..a41722ccb 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -1329,14 +1329,6 @@ namespace libtorrent m_have_piece.set_bit(index); ++m_num_pieces; - if (is_seed()) - { - m_peer_info->seed = true; - m_upload_only = true; - disconnect_if_redundant(); - if (is_disconnecting()) return; - } - // only update the piece_picker if // we have the metadata and if // we're not a seed (in which case @@ -1363,6 +1355,17 @@ namespace libtorrent } } + // it's important to not disconnect before we have + // updated the piece picker, otherwise we will incorrectly + // decrement the piece count without first incrementing it + if (is_seed()) + { + m_peer_info->seed = true; + m_upload_only = true; + disconnect_if_redundant(); + if (is_disconnecting()) return; + } + // if we're super seeding, this might mean that somebody // forwarded this piece. In which case we need to give // a new piece to that peer diff --git a/src/piece_picker.cpp b/src/piece_picker.cpp index abee2a07f..4e5e89787 100644 --- a/src/piece_picker.cpp +++ b/src/piece_picker.cpp @@ -852,8 +852,6 @@ namespace libtorrent for (std::vector::iterator i = m_piece_map.begin() , end(m_piece_map.end()); i != end; ++i) { - // we don't maintain peer count for pieces we have - if (i->index == piece_pos::we_have_index) continue; TORRENT_ASSERT(i->peer_count > 0); --i->peer_count; }