From 356db54dce450bff220f410bfea4670ccdf4440d Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Fri, 26 Jun 2009 05:58:24 +0000 Subject: [PATCH] connect candidate counter fix --- src/policy.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/policy.cpp b/src/policy.cpp index 83165ed88..50d081951 100644 --- a/src/policy.cpp +++ b/src/policy.cpp @@ -728,8 +728,6 @@ namespace libtorrent if (iter != m_peers.end() && (*iter)->address() == c.remote().address()) found = true; } - bool was_conn_cand = false; - if (found) { i = *iter; @@ -740,8 +738,6 @@ namespace libtorrent return false; } - was_conn_cand = is_connect_candidate(*i, m_finished); - if (i->connection != 0) { boost::shared_ptr other_socket @@ -790,6 +786,13 @@ namespace libtorrent i->connection->disconnect(error_code(errors::duplicate_peer_id, libtorrent_category)); } } + + if (is_connect_candidate(*i, m_finished)) + { + m_num_connect_candidates--; + TORRENT_ASSERT(m_num_connect_candidates >= 0); + if (m_num_connect_candidates < 0) m_num_connect_candidates = 0; + } } else { @@ -852,12 +855,8 @@ namespace libtorrent if (!c.fast_reconnect()) i->last_connected = session_time; - if (was_conn_cand != is_connect_candidate(*i, m_finished)) - { - m_num_connect_candidates += was_conn_cand ? -1 : 1; - TORRENT_ASSERT(m_num_connect_candidates >= 0); - if (m_num_connect_candidates < 0) m_num_connect_candidates = 0; - } + // this cannot be a connect candidate anymore, since i->connection is set + TORRENT_ASSERT(!is_connect_candidate(*i, m_finished)); return true; } @@ -1287,6 +1286,7 @@ namespace libtorrent if (p == 0) return; TORRENT_ASSERT(p->connection == &c); + TORRENT_ASSERT(!is_connect_candidate(*p, m_finished)); p->connection = 0; p->optimistically_unchoked = false;