From 57eb57ac78f131104c4b27ae973ef30c5ce8269f Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Tue, 6 Mar 2012 07:35:56 +0000 Subject: [PATCH] move trust point and hashfailure counter logic to where they belong --- src/peer_connection.cpp | 26 +++++++------------------- src/torrent.cpp | 23 +++++++++++++++++++++-- 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 5fae18252..4dbe65b6c 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -1137,25 +1137,6 @@ namespace libtorrent } TORRENT_CATCH(std::exception&) {} } #endif - if (is_disconnecting()) return; - - if (peer_info_struct()) - { - if (m_ses.settings().use_parole_mode) - peer_info_struct()->on_parole = true; - - int hashfails = peer_info_struct()->hashfails; - int trust_points = peer_info_struct()->trust_points; - - // we decrease more than we increase, to keep the - // allowed failed/passed ratio low. - trust_points -= 2; - ++hashfails; - if (trust_points < -7) trust_points = -7; - peer_info_struct()->trust_points = trust_points; - if (hashfails > 255) hashfails = 255; - peer_info_struct()->hashfails = hashfails; - } } size_type peer_connection::total_free_upload() const @@ -3512,6 +3493,13 @@ namespace libtorrent } #endif + // for incoming connections, we get invalid argument errors + // when asking for the remote endpoint and the socket already + // closed, which is an edge case, but possible to happen when + // a peer makes a TCP and uTP connection in parallel. + // for outgoing connections however, why would we get this? + TORRENT_ASSERT(ec != error::invalid_argument || !m_outgoing); + #ifdef TORRENT_STATS ++m_ses.m_disconnected_peers; if (error == 2) ++m_ses.m_error_peers; diff --git a/src/torrent.cpp b/src/torrent.cpp index b80bb52f7..f77d8de7c 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -3112,7 +3112,6 @@ namespace libtorrent , index)); } - state_updated(); m_need_save_resume_data = true; state_updated(); @@ -3285,7 +3284,27 @@ namespace libtorrent { policy::peer* p = static_cast(*i); if (p == 0) continue; - if (p->connection) p->connection->received_invalid_data(index); + TORRENT_ASSERT(p->in_use); + if (p->connection) + { + TORRENT_ASSERT(p->connection->m_in_use == 1337); + p->connection->received_invalid_data(index); + } + + if (m_ses.settings().use_parole_mode) + p->on_parole = true; + + int hashfails = p->hashfails; + int trust_points = p->trust_points; + + // we decrease more than we increase, to keep the + // allowed failed/passed ratio low. + trust_points -= 2; + ++hashfails; + if (trust_points < -7) trust_points = -7; + p->trust_points = trust_points; + if (hashfails > 255) hashfails = 255; + p->hashfails = hashfails; // either, we have received too many failed hashes // or this was the only peer that sent us this piece.