diff --git a/include/libtorrent/bt_peer_connection.hpp b/include/libtorrent/bt_peer_connection.hpp index c002d95c5..ab09833a2 100644 --- a/include/libtorrent/bt_peer_connection.hpp +++ b/include/libtorrent/bt_peer_connection.hpp @@ -85,17 +85,8 @@ namespace libtorrent // this is the constructor where the we are the active part. // The peer_conenction should handshake and verify that the // other end has the correct id - bt_peer_connection( - aux::session_interface& ses - , aux::session_settings const& sett - , counters& stats_counters - , buffer_allocator_interface& allocator - , disk_interface& disk_thread - , boost::shared_ptr s - , tcp::endpoint const& remote - , torrent_peer* peerinfo - , peer_id const& pid - , boost::weak_ptr t = boost::weak_ptr()); + bt_peer_connection(peer_connection_args const& pack + , peer_id const& pid); void start(); diff --git a/include/libtorrent/http_seed_connection.hpp b/include/libtorrent/http_seed_connection.hpp index 83bfa8287..1aba8759e 100644 --- a/include/libtorrent/http_seed_connection.hpp +++ b/include/libtorrent/http_seed_connection.hpp @@ -81,14 +81,7 @@ namespace libtorrent // this is the constructor where the we are the active part. // The peer_conenction should handshake and verify that the // other end has the correct id - http_seed_connection( - aux::session_interface& ses - , aux::session_settings const& sett - , counters& stats_counters - , buffer_allocator_interface& allocator - , disk_interface& disk_thread - , boost::weak_ptr t - , boost::shared_ptr s + http_seed_connection(peer_connection_args const& pack , web_seed_entry& web); virtual int type() const { return peer_connection::http_seed_connection; } diff --git a/include/libtorrent/peer_connection.hpp b/include/libtorrent/peer_connection.hpp index edcefaccf..d4470202e 100644 --- a/include/libtorrent/peer_connection.hpp +++ b/include/libtorrent/peer_connection.hpp @@ -144,6 +144,21 @@ namespace libtorrent { return pb.block == block; } }; + // argument pack passed to peer_connection constructor + struct peer_connection_args + { + aux::session_interface* ses; + aux::session_settings const* sett; + counters* stats_counters; + buffer_allocator_interface* allocator; + disk_interface* disk_thread; + io_service* ios; + boost::weak_ptr tor; + boost::shared_ptr s; + tcp::endpoint const* endp; + torrent_peer* peerinfo; + }; + // internal inline void nop(char*, void*, block_cache_reference) {} @@ -280,17 +295,7 @@ namespace libtorrent num_channels }; - peer_connection( - aux::session_interface& ses - , aux::session_settings const& sett - , counters& stats_counters - , buffer_allocator_interface& allocator - , disk_interface& disk_thread - , io_service& ios - , boost::weak_ptr t - , boost::shared_ptr s - , tcp::endpoint const& remote - , torrent_peer* peerinfo); + peer_connection(peer_connection_args const& pack); // 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/include/libtorrent/web_connection_base.hpp b/include/libtorrent/web_connection_base.hpp index a68aec4cb..d53ab0405 100644 --- a/include/libtorrent/web_connection_base.hpp +++ b/include/libtorrent/web_connection_base.hpp @@ -85,14 +85,7 @@ namespace libtorrent // this is the constructor where the we are the active part. // The peer_conenction should handshake and verify that the // other end has the correct id - web_connection_base( - aux::session_interface& ses - , aux::session_settings const& sett - , counters& stats_counters - , buffer_allocator_interface& allocator - , disk_interface& disk_thread - , boost::weak_ptr t - , boost::shared_ptr s + web_connection_base(peer_connection_args const& pack , web_seed_entry& web); virtual int timeout() const; diff --git a/include/libtorrent/web_peer_connection.hpp b/include/libtorrent/web_peer_connection.hpp index f71133857..d59c91081 100644 --- a/include/libtorrent/web_peer_connection.hpp +++ b/include/libtorrent/web_peer_connection.hpp @@ -74,14 +74,7 @@ namespace libtorrent // this is the constructor where the we are the active part. // The peer_conenction should handshake and verify that the // other end has the correct id - web_peer_connection( - aux::session_interface& ses - , aux::session_settings const& sett - , counters& stats_counters - , buffer_allocator_interface& allocator - , disk_interface& disk_thread - , boost::weak_ptr t - , boost::shared_ptr s + web_peer_connection(peer_connection_args const& pack , web_seed_entry& web); virtual void on_connected(); diff --git a/src/bt_peer_connection.cpp b/src/bt_peer_connection.cpp index 5da656dd7..baf03c02d 100644 --- a/src/bt_peer_connection.cpp +++ b/src/bt_peer_connection.cpp @@ -95,20 +95,9 @@ namespace libtorrent }; - bt_peer_connection::bt_peer_connection( - aux::session_interface& ses - , aux::session_settings const& sett - , counters& stats_counters - , buffer_allocator_interface& allocator - , disk_interface& disk_thread - , shared_ptr s - , tcp::endpoint const& remote - , torrent_peer* peerinfo - , peer_id const& pid - , boost::weak_ptr tor) - : peer_connection(ses, sett, stats_counters, allocator, disk_thread - , ses.get_io_service() - , tor, s, remote, peerinfo) + bt_peer_connection::bt_peer_connection(peer_connection_args const& pack + , peer_id const& pid) + : peer_connection(pack) , m_state(read_protocol_identifier) , m_supports_extensions(false) , m_supports_dht_port(false) diff --git a/src/http_seed_connection.cpp b/src/http_seed_connection.cpp index d315c4805..222ef3aac 100644 --- a/src/http_seed_connection.cpp +++ b/src/http_seed_connection.cpp @@ -52,17 +52,9 @@ using libtorrent::aux::session_impl; namespace libtorrent { - http_seed_connection::http_seed_connection( - aux::session_interface& ses - , aux::session_settings const& sett - , counters& stats_counters - , buffer_allocator_interface& allocator - , disk_interface& disk_thread - , boost::weak_ptr t - , boost::shared_ptr s + http_seed_connection::http_seed_connection(peer_connection_args const& pack , web_seed_entry& web) - : web_connection_base(ses, sett, stats_counters, allocator, disk_thread - , t, s, web) + : web_connection_base(pack, web) , m_url(web.url) , m_response_left(0) , m_chunk_pos(0) @@ -73,7 +65,7 @@ namespace libtorrent if (!m_settings.get_bool(settings_pack::report_web_seed_downloads)) ignore_stats(true); - shared_ptr tor = t.lock(); + shared_ptr tor = pack.tor.lock(); TORRENT_ASSERT(tor); int blocks_per_piece = tor->torrent_file().piece_length() / tor->block_size(); diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index a295e2d7e..6f227a8b2 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -125,30 +125,20 @@ namespace libtorrent #endif // outbound connection - peer_connection::peer_connection( - aux::session_interface& ses - , aux::session_settings const& sett - , counters& stats_counters - , buffer_allocator_interface& allocator - , disk_interface& disk_thread - , io_service& ios - , boost::weak_ptr tor - , shared_ptr s - , tcp::endpoint const& endp - , torrent_peer* peerinfo) - : peer_connection_hot_members(tor, ses, sett) - , m_socket(s) - , m_peer_info(peerinfo) - , m_counters(stats_counters) + peer_connection::peer_connection(peer_connection_args const& pack) + : peer_connection_hot_members(pack.tor, *pack.ses, *pack.sett) + , m_socket(pack.s) + , m_peer_info(pack.peerinfo) + , m_counters(*pack.stats_counters) , m_num_pieces(0) , m_rtt(0) , m_recv_start(0) , m_desired_queue_size(2) , m_max_out_request_queue(m_settings.get_int(settings_pack::max_out_request_queue)) - , m_remote(endp) - , m_disk_thread(disk_thread) - , m_allocator(allocator) - , m_ios(ios) + , m_remote(*pack.endp) + , m_disk_thread(*pack.disk_thread) + , m_allocator(*pack.allocator) + , m_ios(*pack.ios) , m_work(m_ios) , m_last_piece(time_now()) , m_last_request(time_now()) @@ -168,7 +158,7 @@ namespace libtorrent , m_uploaded_at_last_unchoke(0) , m_soft_packet_size(0) , m_outstanding_bytes(0) - , m_disk_recv_buffer(allocator, 0) + , m_disk_recv_buffer(*pack.allocator, 0) , m_last_seen_complete(0) , m_receiving_block(piece_block::invalid) , m_timeout_extend(0) @@ -189,12 +179,12 @@ namespace libtorrent , m_prefer_whole_pieces(0) , m_disk_read_failures(0) , m_outstanding_piece_verification(0) - , m_outgoing(!tor.expired()) + , m_outgoing(!pack.tor.expired()) , m_received_listen_port(false) , m_fast_reconnect(false) , m_failed(false) - , m_connected(tor.expired()) - , m_queued(!tor.expired()) + , m_connected(pack.tor.expired()) + , m_queued(!pack.tor.expired()) , m_request_large_blocks(false) , m_share_mode(false) , m_upload_only(false) @@ -241,7 +231,7 @@ namespace libtorrent m_quota[0] = 0; m_quota[1] = 0; - TORRENT_ASSERT(peerinfo == 0 || peerinfo->banned == false); + TORRENT_ASSERT(pack.peerinfo == 0 || pack.peerinfo->banned == false); #ifndef TORRENT_DISABLE_RESOLVE_COUNTRIES std::fill(m_country, m_country + 2, 0); #ifndef TORRENT_DISABLE_GEO_IP diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 57ae0380d..360cf07df 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -3169,10 +3169,20 @@ retry: setup_socket_buffers(*s); + peer_connection_args pack; + pack.ses = this; + pack.sett = &m_settings; + pack.stats_counters = &m_stats_counters; + pack.allocator = this; + pack.disk_thread = &m_disk_thread; + pack.ios = &m_io_service; + pack.tor = boost::weak_ptr(); + pack.s = s; + pack.endp = &endp; + pack.peerinfo = 0; + boost::shared_ptr c - = boost::make_shared(boost::ref(*this), m_settings - , boost::ref(m_stats_counters), boost::ref(*this) - , boost::ref(m_disk_thread), s, endp, (torrent_peer*)0 + = boost::make_shared(boost::cref(pack) , get_peer_id()); #if TORRENT_USE_ASSERTS c->m_in_constructor = false; diff --git a/src/torrent.cpp b/src/torrent.cpp index 13634ee59..14d4eb633 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -6181,23 +6181,26 @@ namespace libtorrent } boost::shared_ptr c; + peer_connection_args pack; + pack.ses = &m_ses; + pack.sett = &m_ses.settings(); + pack.stats_counters = &m_ses.stats_counters(); + pack.allocator = &m_ses; + pack.disk_thread = &m_ses.disk_thread(); + pack.ios = &m_ses.get_io_service(); + pack.tor = shared_from_this(); + pack.s = s; + pack.endp = &web->endpoint; + pack.peerinfo = &web->peer_info; if (web->type == web_seed_entry::url_seed) { c = boost::make_shared( - boost::ref(m_ses), m_ses.settings() - , boost::ref(m_ses.stats_counters()) - , boost::ref(m_ses) - , boost::ref(m_ses.disk_thread()) - , shared_from_this(), s, boost::ref(*web)); + boost::cref(pack), boost::ref(*web)); } else if (web->type == web_seed_entry::http_seed) { c = boost::make_shared( - boost::ref(m_ses), m_ses.settings() - , boost::ref(m_ses.stats_counters()) - , boost::ref(m_ses) - , boost::ref(m_ses.disk_thread()) - , shared_from_this(), s, boost::ref(*web)); + boost::cref(pack), boost::ref(*web)); } if (!c) return; @@ -7197,12 +7200,20 @@ namespace libtorrent m_ses.setup_socket_buffers(*s); + peer_connection_args pack; + pack.ses = &m_ses; + pack.sett = &m_ses.settings(); + pack.stats_counters = &m_ses.stats_counters(); + pack.allocator = &m_ses; + pack.disk_thread = &m_ses.disk_thread(); + pack.ios = &m_ses.get_io_service(); + pack.tor = shared_from_this(); + pack.s = s; + pack.endp = &a; + pack.peerinfo = peerinfo; + boost::shared_ptr c = boost::make_shared( - boost::ref(m_ses), m_ses.settings() - , boost::ref(m_ses.stats_counters()) - , boost::ref(m_ses) - , boost::ref(m_ses.disk_thread()) - , s, a, peerinfo, m_ses.get_peer_id(), shared_from_this()); + boost::cref(pack), m_ses.get_peer_id()); #if TORRENT_USE_ASSERTS c->m_in_constructor = false; diff --git a/src/web_connection_base.cpp b/src/web_connection_base.cpp index 8509b3328..477d8a3ac 100644 --- a/src/web_connection_base.cpp +++ b/src/web_connection_base.cpp @@ -52,16 +52,9 @@ using boost::shared_ptr; namespace libtorrent { web_connection_base::web_connection_base( - aux::session_interface& ses - , aux::session_settings const& sett - , counters& stats_counters - , buffer_allocator_interface& allocator - , disk_interface& disk_thread - , boost::weak_ptr t - , boost::shared_ptr s + peer_connection_args const& pack , web_seed_entry& web) - : peer_connection(ses, sett, stats_counters, allocator, disk_thread - , ses.get_io_service(), t, s, web.endpoint, &web.peer_info) + : peer_connection(pack) , m_first_request(true) , m_ssl(false) , m_external_auth(web.auth) @@ -69,6 +62,9 @@ namespace libtorrent , m_parser(http_parser::dont_parse_chunks) , m_body_start(0) { + TORRENT_ASSERT(&web.peer_info == pack.peerinfo); + TORRENT_ASSERT(web.endpoint == *pack.endp); + INVARIANT_CHECK; // we only want left-over bandwidth diff --git a/src/web_peer_connection.cpp b/src/web_peer_connection.cpp index c35670672..81e7183b0 100644 --- a/src/web_peer_connection.cpp +++ b/src/web_peer_connection.cpp @@ -60,17 +60,9 @@ enum struct disk_interface; -web_peer_connection::web_peer_connection( - aux::session_interface& ses - , aux::session_settings const& sett - , counters& stats_counters - , buffer_allocator_interface& allocator - , disk_interface& disk_thread - , boost::weak_ptr t - , boost::shared_ptr s +web_peer_connection::web_peer_connection(peer_connection_args const& pack , web_seed_entry& web) - : web_connection_base(ses, sett, stats_counters, allocator, disk_thread - , t, s, web) + : web_connection_base(pack, web) , m_url(web.url) , m_web(&web) , m_received_body(0) @@ -85,7 +77,7 @@ web_peer_connection::web_peer_connection( if (!m_settings.get_bool(settings_pack::report_web_seed_downloads)) ignore_stats(true); - shared_ptr tor = t.lock(); + shared_ptr tor = pack.tor.lock(); TORRENT_ASSERT(tor); // we always prefer downloading 1 MiB chunks