diff --git a/libtorrent/include/libtorrent/policy.hpp b/libtorrent/include/libtorrent/policy.hpp index e95793826..0c9380b8a 100755 --- a/libtorrent/include/libtorrent/policy.hpp +++ b/libtorrent/include/libtorrent/policy.hpp @@ -99,11 +99,6 @@ namespace libtorrent // the peer has got at least one interesting piece void peer_is_interesting(peer_connection& c); - void piece_finished(int index, bool successfully_verified); - - // the peer choked us - void choked(peer_connection& c); - int count_choked() const; // the peer unchoked us diff --git a/libtorrent/src/peer_connection.cpp b/libtorrent/src/peer_connection.cpp index c355a6d23..ad0ce2a14 100755 --- a/libtorrent/src/peer_connection.cpp +++ b/libtorrent/src/peer_connection.cpp @@ -796,7 +796,6 @@ namespace libtorrent (*m_logger) << time_now_string() << " <== CHOKE\n"; #endif m_peer_choked = true; - t->get_policy().choked(*this); if (peer_info_struct() == 0 || !peer_info_struct()->on_parole) { diff --git a/libtorrent/src/piece_picker.cpp b/libtorrent/src/piece_picker.cpp index 5350f00f5..61064e65e 100755 --- a/libtorrent/src/piece_picker.cpp +++ b/libtorrent/src/piece_picker.cpp @@ -1775,7 +1775,13 @@ namespace libtorrent TORRENT_ASSERT(block.piece_index < (int)m_piece_map.size()); TORRENT_ASSERT(block.block_index < blocks_in_piece(block.piece_index)); - TORRENT_ASSERT(m_piece_map[block.piece_index].downloading); + // this might be the case if a piece fails, is restored, and then + // completed from a different peer (from which the piece was requested + // before it failed the hash check) + if (m_piece_map[block.piece_index].downloading == 0) + mark_as_downloading(block, peer, piece_picker::none); + + TORRENT_ASSERT(m_piece_map[block.piece_index].downloaing); std::vector::iterator i = std::find_if(m_downloads.begin(), m_downloads.end(), has_index(block.piece_index)); diff --git a/libtorrent/src/policy.cpp b/libtorrent/src/policy.cpp index d930ca6ff..07791adba 100755 --- a/libtorrent/src/policy.cpp +++ b/libtorrent/src/policy.cpp @@ -881,35 +881,6 @@ namespace libtorrent return &i->second; } - // this is called when we are choked by a peer - // i.e. a peer lets us know that we will not receive - // anything for a while - void policy::choked(peer_connection&) - { - } - - void policy::piece_finished(int index, bool successfully_verified) - { - INVARIANT_CHECK; - - TORRENT_ASSERT(index >= 0 && index < m_torrent->torrent_file().num_pieces()); - - if (successfully_verified) - { - // have all peers update their interested-flag - for (iterator i = m_peers.begin(); - i != m_peers.end(); ++i) - { - if (i->second.connection == 0) continue; - // if we're not interested, we will not become interested - if (!i->second.connection->is_interesting()) continue; - if (!i->second.connection->has_piece(index)) continue; - - i->second.connection->update_interest(); - } - } - } - // this is called when we are unchoked by a peer // i.e. a peer lets us know that we will receive // data from now on diff --git a/libtorrent/src/session_impl.cpp b/libtorrent/src/session_impl.cpp index 09da8857c..ba76445b3 100755 --- a/libtorrent/src/session_impl.cpp +++ b/libtorrent/src/session_impl.cpp @@ -527,7 +527,8 @@ namespace aux { // if queuing settings were changed, recalculate // queued torrents sooner if ((m_settings.active_downloads != s.active_downloads - || m_settings.active_seeds != s.active_seeds) + || m_settings.active_seeds != s.active_seeds + || m_settings.active_limit != s.active_limit) && m_auto_manage_time_scaler > 2) m_auto_manage_time_scaler = 2; m_settings = s; @@ -1323,6 +1324,8 @@ namespace aux { num_downloaders = (std::numeric_limits::max)(); if (num_seeds == -1) num_seeds = (std::numeric_limits::max)(); + if (hard_limit == -1) + hard_limit = (std::numeric_limits::max)(); for (torrent_map::iterator i = m_torrents.begin() , end(m_torrents.end()); i != end; ++i) diff --git a/libtorrent/src/smart_ban.cpp b/libtorrent/src/smart_ban.cpp index d0c753907..a3db95e2b 100644 --- a/libtorrent/src/smart_ban.cpp +++ b/libtorrent/src/smart_ban.cpp @@ -127,6 +127,10 @@ namespace libtorrent { namespace // The piece failed the hash check. Record // the CRC and origin peer of every block + // if the torrent is aborted, no point in starting + // a bunch of read operations on it + if (m_torrent.is_aborted()) return; + std::vector downloaders; m_torrent.picker().get_downloaders(downloaders, p); diff --git a/libtorrent/src/torrent.cpp b/libtorrent/src/torrent.cpp index 7ab14e12c..2a78a23d0 100755 --- a/libtorrent/src/torrent.cpp +++ b/libtorrent/src/torrent.cpp @@ -1254,9 +1254,35 @@ namespace libtorrent TORRENT_ASSERT(valid_metadata()); // if we just became a seed, picker is now invalid, since it // is deallocated by the torrent once it starts seeding + + // since this piece just passed, we might have + // become uninterested in some peers where this + // was the last piece we were interested in + for (peer_iterator i = m_connections.begin() + , end(m_connections.end()); i != end; ++i) + { + peer_connection* p = *i; + // if we're not interested already, no need to check + if (!p->is_interesting()) continue; + // if the peer doesn't have the piece we just got, it + // wouldn't affect our interest + if (!p->has_piece(index)) continue; + p->update_interest(); + } + + if (!was_finished&& is_finished()) + { + TORRENT_ASSERT(passed_hash_check == 0); + // torrent finished + // i.e. all the pieces we're interested in have + // been downloaded. Release the files (they will open + // in read only mode if needed) + finished(); + } } else if (passed_hash_check == -2) { + // piece_failed() will restore the piece piece_failed(index); } else @@ -1264,21 +1290,6 @@ namespace libtorrent TORRENT_ASSERT(passed_hash_check == -1); m_picker->restore_piece(index); } - - m_policy.piece_finished(index, passed_hash_check == 0); - - if (!was_finished - && (is_seed() - || m_picker->num_filtered() + num_have() - == torrent_file().num_pieces())) - { - TORRENT_ASSERT(passed_hash_check == 0); - // torrent finished - // i.e. all the pieces we're interested in have - // been downloaded. Release the files (they will open - // in read only mode if needed) - finished(); - } } void torrent::piece_failed(int index) @@ -3271,7 +3282,8 @@ namespace libtorrent piece_manager& torrent::filesystem() { TORRENT_ASSERT(m_owning_storage.get()); - return *m_owning_storage; + TORRENT_ASSERT(m_storage); + return *m_storage; }