From 470680730043c35c0a92aa6668664722c3aa6311 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sat, 21 Jan 2012 21:29:22 +0000 Subject: [PATCH] fix issue with outgoing connections not being tied to a torrent --- include/libtorrent/bt_peer_connection.hpp | 3 +-- include/libtorrent/peer_connection.hpp | 3 +-- src/bt_peer_connection.cpp | 5 ++--- src/peer_connection.cpp | 25 ++++++++--------------- 4 files changed, 13 insertions(+), 23 deletions(-) diff --git a/include/libtorrent/bt_peer_connection.hpp b/include/libtorrent/bt_peer_connection.hpp index f9ba9b6ae..e1f41d626 100644 --- a/include/libtorrent/bt_peer_connection.hpp +++ b/include/libtorrent/bt_peer_connection.hpp @@ -99,8 +99,7 @@ namespace libtorrent aux::session_impl& ses , boost::shared_ptr s , tcp::endpoint const& remote - , policy::peer* peerinfo - , bool outgoing = false); + , policy::peer* peerinfo); void start(); diff --git a/include/libtorrent/peer_connection.hpp b/include/libtorrent/peer_connection.hpp index f73a081ac..1e7fa4668 100644 --- a/include/libtorrent/peer_connection.hpp +++ b/include/libtorrent/peer_connection.hpp @@ -180,8 +180,7 @@ namespace libtorrent aux::session_impl& ses , boost::shared_ptr s , tcp::endpoint const& remote - , policy::peer* peerinfo - , bool outgoing = false); + , policy::peer* peerinfo); // this function is called after it has been constructed and properly // reference counted. It is safe to call self() in this function diff --git a/src/bt_peer_connection.cpp b/src/bt_peer_connection.cpp index ecf1e0d36..14279c570 100644 --- a/src/bt_peer_connection.cpp +++ b/src/bt_peer_connection.cpp @@ -153,9 +153,8 @@ namespace libtorrent session_impl& ses , boost::shared_ptr s , tcp::endpoint const& remote - , policy::peer* peerinfo - , bool outgoing) - : peer_connection(ses, s, remote, peerinfo, outgoing) + , policy::peer* peerinfo) + : peer_connection(ses, s, remote, peerinfo) , m_state(read_protocol_identifier) #ifndef TORRENT_DISABLE_EXTENSIONS , m_upload_only_id(0) diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index d53ca628a..6ad751487 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -244,7 +244,7 @@ namespace libtorrent m_logger = m_ses.create_log(m_remote.address().to_string(ec) + "_" + to_string(m_remote.port()).elems, m_ses.listen_port()); peer_log("%s [ ep: %s type: %s seed: %d p: %p local: %s]" - , outgoing ? ">>> OUTGOING_CONNECTION" : "<<< INCOMING CONNECTION" + , m_active ? ">>> OUTGOING_CONNECTION" : "<<< INCOMING CONNECTION" , print_endpoint(m_remote).c_str() , m_socket->type_name() , m_peer_info ? m_peer_info->seed : 0, m_peer_info @@ -265,8 +265,7 @@ namespace libtorrent session_impl& ses , shared_ptr s , tcp::endpoint const& endp - , policy::peer* peerinfo - , bool outgoing) + , policy::peer* peerinfo) : #ifdef TORRENT_DEBUG m_last_choke(time_now() - hours(1)) @@ -324,7 +323,7 @@ namespace libtorrent , m_desired_queue_size(2) , m_choke_rejects(0) , m_fast_reconnect(false) - , m_active(outgoing) + , m_active(false) , m_received_listen_port(false) , m_peer_interested(false) , m_peer_choked(true) @@ -335,8 +334,8 @@ namespace libtorrent , m_ignore_unchoke_slots(false) , m_have_all(false) , m_disconnecting(false) - , m_connecting(outgoing) - , m_queued(outgoing) + , m_connecting(false) + , m_queued(false) , m_request_large_blocks(false) , m_share_mode(false) , m_upload_only(false) @@ -355,14 +354,6 @@ namespace libtorrent , m_received_in_piece(0) #endif { - boost::shared_ptr t = m_torrent.lock(); - // if t is NULL, we better not be connecting, since - // we can't decrement the connecting counter - TORRENT_ASSERT(t || !m_connecting); - if (m_connecting && t) - { - ++t->m_num_connecting; - } m_est_reciprocation_rate = m_ses.m_settings.default_est_reciprocation_rate; #if TORRENT_USE_I2P @@ -400,7 +391,7 @@ namespace libtorrent m_logger = m_ses.create_log(remote().address().to_string(ec) + "_" + to_string(remote().port()).elems, m_ses.listen_port()); peer_log("%s [ ep: %s type: %s local: %s]" - , outgoing ? ">>> OUTGOING_CONNECTION" : "<<< INCOMING CONNECTION" + , m_active ? ">>> OUTGOING_CONNECTION" : "<<< INCOMING CONNECTION" , print_endpoint(m_remote).c_str() , m_socket->type_name() , print_endpoint(m_socket->local_endpoint(ec)).c_str()); @@ -5368,14 +5359,16 @@ namespace libtorrent boost::shared_ptr t = m_torrent.lock(); m_queued = false; - TORRENT_ASSERT(m_connecting); if (!t) { + TORRENT_ASSERT(!m_connecting); disconnect(errors::torrent_aborted); return; } + TORRENT_ASSERT(m_connecting); + #if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING peer_log(">>> OPEN [ protocol: %s ]", (m_remote.address().is_v4()?"IPv4":"IPv6")); #endif