diff --git a/src/policy.cpp b/src/policy.cpp index 576b6a394..0892ad370 100755 --- a/src/policy.cpp +++ b/src/policy.cpp @@ -824,6 +824,8 @@ namespace libtorrent void policy::ban_peer(const peer_connection& c) { + INVARIANT_CHECK; + std::vector::iterator i = std::find_if( m_peers.begin() , m_peers.end() @@ -839,6 +841,7 @@ namespace libtorrent void policy::new_connection(peer_connection& c) { assert(!c.is_local()); + INVARIANT_CHECK; // if the connection comes from the tracker, // it's probably just a NAT-check. Ignore the @@ -895,6 +898,8 @@ namespace libtorrent void policy::peer_from_tracker(const address& remote, const peer_id& id) { + INVARIANT_CHECK; + // just ignore the obviously invalid entries from the tracker if(remote.ip() == 0 || remote.port == 0) return; @@ -980,6 +985,8 @@ namespace libtorrent void policy::piece_finished(int index, bool successfully_verified) { + INVARIANT_CHECK; + assert(index >= 0 && index < m_torrent->torrent_file().num_pieces()); if (successfully_verified) @@ -1017,6 +1024,8 @@ namespace libtorrent // this peer has. void policy::block_finished(peer_connection& c, piece_block) { + INVARIANT_CHECK; + // if the peer hasn't choked us, ask for another piece if (!c.has_peer_choked()) request_a_block(*m_torrent, c); @@ -1027,6 +1036,7 @@ namespace libtorrent // data from now on void policy::unchoked(peer_connection& c) { + INVARIANT_CHECK; if (c.is_interesting()) { request_a_block(*m_torrent, c); @@ -1036,6 +1046,8 @@ namespace libtorrent // called when a peer is interested in us void policy::interested(peer_connection& c) { + INVARIANT_CHECK; + // if the peer is choked and we have upload slots left, // then unchoke it. Another condition that has to be met // is that the torrent doesn't keep track of the individual @@ -1060,6 +1072,8 @@ namespace libtorrent // called when a peer is no longer interested in us void policy::not_interested(peer_connection& c) { + INVARIANT_CHECK; + if (m_torrent->ratio() != 0.f) { assert(c.share_diff() < std::numeric_limits::max()); @@ -1155,6 +1169,8 @@ namespace libtorrent // this is called whenever a peer connection is closed void policy::connection_closed(const peer_connection& c) { + INVARIANT_CHECK; + bool unchoked = false; std::vector::iterator i = std::find_if( @@ -1203,6 +1219,8 @@ namespace libtorrent void policy::peer_is_interesting(peer_connection& c) { + INVARIANT_CHECK; + c.send_interested(); if (c.has_peer_choked()) return; request_a_block(*m_torrent, c); diff --git a/src/torrent.cpp b/src/torrent.cpp index 4c70adcfa..0769b9c6e 100755 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -821,8 +821,7 @@ namespace libtorrent // if the peer_connection was downloading any pieces // abort them for (std::deque::const_iterator i = p->download_queue().begin(); - i != p->download_queue().end(); - ++i) + i != p->download_queue().end(); ++i) { m_picker->abort_download(*i); } @@ -833,8 +832,7 @@ namespace libtorrent const std::vector& pieces = p->get_bitfield(); for (std::vector::const_iterator i = pieces.begin(); - i != pieces.end(); - ++i) + i != pieces.end(); ++i) { if (*i) piece_list.push_back(static_cast(i - pieces.begin())); } @@ -842,8 +840,7 @@ namespace libtorrent std::random_shuffle(piece_list.begin(), piece_list.end()); for (std::vector::iterator i = piece_list.begin(); - i != piece_list.end(); - ++i) + i != piece_list.end(); ++i) { peer_lost(*i); }