From 5275e75fa5b1317e2f96648b2c5170658be615be Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Mon, 14 May 2012 05:43:45 +0000 Subject: [PATCH] back-port deletion of the redundant peer_connection constructor from libtorrent_aio --- include/libtorrent/bt_peer_connection.hpp | 12 +- include/libtorrent/peer_connection.hpp | 8 -- src/bt_peer_connection.cpp | 53 +------- src/peer_connection.cpp | 151 +--------------------- src/torrent.cpp | 2 +- 5 files changed, 5 insertions(+), 221 deletions(-) diff --git a/include/libtorrent/bt_peer_connection.hpp b/include/libtorrent/bt_peer_connection.hpp index 86ba9f49d..e61c85edb 100644 --- a/include/libtorrent/bt_peer_connection.hpp +++ b/include/libtorrent/bt_peer_connection.hpp @@ -87,19 +87,11 @@ namespace libtorrent // other end has the correct id bt_peer_connection( aux::session_impl& ses - , boost::weak_ptr t , boost::shared_ptr s , tcp::endpoint const& remote , policy::peer* peerinfo - , bool outgoing = true); - - // with this constructor we have been contacted and we still don't - // know which torrent the connection belongs to - bt_peer_connection( - aux::session_impl& ses - , boost::shared_ptr s - , tcp::endpoint const& remote - , policy::peer* peerinfo); + , boost::weak_ptr t = boost::weak_ptr() + , bool outgoing = false); void start(); diff --git a/include/libtorrent/peer_connection.hpp b/include/libtorrent/peer_connection.hpp index b175b0df7..4b1c80046 100644 --- a/include/libtorrent/peer_connection.hpp +++ b/include/libtorrent/peer_connection.hpp @@ -174,14 +174,6 @@ namespace libtorrent , policy::peer* peerinfo , bool outgoing = true); - // with this constructor we have been contacted and we still don't - // know which torrent the connection belongs to - peer_connection( - aux::session_impl& ses - , boost::shared_ptr s - , tcp::endpoint const& remote - , 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 // and schedule events with references to itself (that is not safe to diff --git a/src/bt_peer_connection.cpp b/src/bt_peer_connection.cpp index 97f61dd38..9b458e0b0 100644 --- a/src/bt_peer_connection.cpp +++ b/src/bt_peer_connection.cpp @@ -96,10 +96,10 @@ namespace libtorrent bt_peer_connection::bt_peer_connection( session_impl& ses - , boost::weak_ptr tor , shared_ptr s , tcp::endpoint const& remote , policy::peer* peerinfo + , boost::weak_ptr tor , bool outgoing) : peer_connection(ses, tor, s, remote , peerinfo, outgoing) @@ -128,57 +128,6 @@ namespace libtorrent peer_log("*** bt_peer_connection"); #endif -#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS - m_in_constructor = false; -#endif - memset(m_reserved_bits, 0, sizeof(m_reserved_bits)); - } - - bt_peer_connection::bt_peer_connection( - session_impl& ses - , boost::shared_ptr s - , tcp::endpoint const& remote - , policy::peer* peerinfo) - : peer_connection(ses, s, remote, peerinfo) - , m_state(read_protocol_identifier) -#ifndef TORRENT_DISABLE_EXTENSIONS - , m_upload_only_id(0) - , m_holepunch_id(0) - , m_dont_have_id(0) - , m_share_mode_id(0) - , m_supports_extensions(false) -#endif - , m_supports_dht_port(false) - , m_supports_fast(false) -#ifndef TORRENT_DISABLE_ENCRYPTION - , m_encrypted(false) - , m_rc4_encrypted(false) - , m_sync_bytes_read(0) -#endif -#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS - , m_sent_bitfield(false) - , m_in_constructor(true) - , m_sent_handshake(false) -#endif - { - - // we are not attached to any torrent yet. - // we have to wait for the handshake to see - // which torrent the connector want's to connect to - - - // upload bandwidth will only be given to connections - // that are part of a torrent. Since this is an incoming - // connection, we have to give it some initial bandwidth - // to send the handshake. -#ifndef TORRENT_DISABLE_ENCRYPTION - m_quota[download_channel] = 2048; - m_quota[upload_channel] = 2048; -#else - m_quota[download_channel] = 80; - m_quota[upload_channel] = 80; -#endif - #if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS m_in_constructor = false; #endif diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index bfec1f4df..f9c8b1c2c 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -241,6 +241,7 @@ namespace libtorrent #endif #if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING error_code ec; + TORRENT_ASSERT(m_socket->remote_endpoint(ec) == m_remote || ec); 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]" @@ -250,156 +251,6 @@ namespace libtorrent , m_peer_info ? m_peer_info->seed : 0, m_peer_info , print_endpoint(m_socket->local_endpoint(ec)).c_str()); #endif -#ifdef TORRENT_DEBUG - piece_failed = false; -#endif -#ifndef TORRENT_DISABLE_GEO_IP - m_inet_as_name = m_ses.as_name_for_ip(m_remote.address()); -#endif - - std::fill(m_peer_id.begin(), m_peer_id.end(), 0); - } - - // incoming connection - peer_connection::peer_connection( - session_impl& ses - , shared_ptr s - , tcp::endpoint const& endp - , policy::peer* peerinfo) - : -#ifdef TORRENT_DEBUG - m_last_choke(time_now() - hours(1)) - , -#endif - m_ses(ses) - , m_max_out_request_queue(m_ses.settings().max_out_request_queue) - , m_work(ses.m_io_service) - , m_last_piece(time_now()) - , m_last_request(time_now()) - , m_last_incoming_request(min_time()) - , m_last_unchoke(time_now()) - , m_last_unchoked(time_now()) - , m_last_receive(time_now()) - , m_last_sent(time_now()) - , m_requested(min_time()) - , m_remote_dl_update(time_now()) - , m_connect(time_now()) - , m_became_uninterested(time_now()) - , m_became_uninteresting(time_now()) - , m_free_upload(0) - , m_downloaded_at_last_unchoke(0) - , m_uploaded_at_last_unchoke(0) - , m_disk_recv_buffer(ses, 0) - , m_socket(s) - , m_remote(endp) - , m_receiving_block(piece_block::invalid) - , m_last_seen_complete(0) - , m_timeout_extend(0) - , m_outstanding_bytes(0) - , m_extension_outstanding_bytes(0) - , m_queued_time_critical(0) - , m_num_pieces(0) - , m_timeout(m_ses.settings().peer_timeout) - , m_packet_size(0) - , m_soft_packet_size(0) - , m_recv_pos(0) - , m_disk_recv_buffer_size(0) - , m_reading_bytes(0) - , m_num_invalid_requests(0) - , m_priority(1) - , m_upload_limit(0) - , m_download_limit(0) - , m_peer_info(peerinfo) - , m_speed(slow) - , m_connection_ticket(-1) - , m_remote_bytes_dled(0) - , m_remote_dl_rate(0) - , m_outstanding_writing_bytes(0) - , m_download_rate_peak(0) - , m_upload_rate_peak(0) - , m_rtt(0) - , m_prefer_whole_pieces(0) - , m_desired_queue_size(2) - , m_choke_rejects(0) - , m_fast_reconnect(false) - , m_outgoing(false) - , m_received_listen_port(false) - , m_peer_interested(false) - , m_peer_choked(true) - , m_interesting(false) - , m_choked(true) - , m_failed(false) - , m_ignore_bandwidth_limits(false) - , m_ignore_unchoke_slots(false) - , m_have_all(false) - , m_disconnecting(false) - , m_connecting(false) - , m_queued(false) - , m_request_large_blocks(false) - , m_share_mode(false) - , m_upload_only(false) - , m_snubbed(false) - , m_bitfield_received(false) - , m_no_download(false) - , m_endgame_mode(false) - , m_sent_suggests(false) - , m_holepunch_mode(false) - , m_ignore_stats(false) - , m_corked(false) - , m_has_metadata(true) -#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS - , m_in_constructor(true) - , m_disconnect_started(false) - , m_initialized(false) - , m_in_use(1337) - , m_received_in_piece(0) -#endif - { - m_superseed_piece[0] = -1; - m_superseed_piece[1] = -1; - m_est_reciprocation_rate = m_ses.m_settings.default_est_reciprocation_rate; - -#if TORRENT_USE_I2P - if (peerinfo && peerinfo->is_i2p_addr) - { - // quadruple the timeout for i2p peers - m_timeout *= 4; - } -#endif - - m_channel_state[upload_channel] = peer_info::bw_idle; - m_channel_state[download_channel] = peer_info::bw_idle; - - m_quota[0] = 0; - m_quota[1] = 0; - -#ifndef TORRENT_DISABLE_RESOLVE_COUNTRIES - std::fill(m_country, m_country + 2, 0); -#ifndef TORRENT_DISABLE_GEO_IP - if (m_ses.has_country_db()) - { - char const *country = m_ses.country_for_ip(m_remote.address()); - if (country != 0) - { - m_country[0] = country[0]; - m_country[1] = country[1]; - } - } -#endif -#endif - -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING - error_code ec; - TORRENT_ASSERT(m_socket->remote_endpoint(ec) == m_remote || ec); - 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]" - , m_outgoing ? ">>> OUTGOING_CONNECTION" : "<<< INCOMING CONNECTION" - , print_endpoint(m_remote).c_str() - , m_socket->type_name() - , print_endpoint(m_socket->local_endpoint(ec)).c_str()); -#endif - #ifndef TORRENT_DISABLE_GEO_IP m_inet_as_name = m_ses.as_name_for_ip(m_remote.address()); #endif diff --git a/src/torrent.cpp b/src/torrent.cpp index 1cb096673..2cd6da5ad 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -5607,7 +5607,7 @@ namespace libtorrent m_ses.setup_socket_buffers(*s); boost::intrusive_ptr c(new bt_peer_connection( - m_ses, shared_from_this(), s, a, peerinfo)); + m_ses, s, a, peerinfo, shared_from_this(), true)); #if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS c->m_in_constructor = false;