pass all the arguments to peer connections as an argument pack

This commit is contained in:
Arvid Norberg 2014-07-14 04:32:41 +00:00
parent fa613131c2
commit 65bb1d0006
12 changed files with 88 additions and 133 deletions

View File

@ -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<socket_type> s
, tcp::endpoint const& remote
, torrent_peer* peerinfo
, peer_id const& pid
, boost::weak_ptr<torrent> t = boost::weak_ptr<torrent>());
bt_peer_connection(peer_connection_args const& pack
, peer_id const& pid);
void start();

View File

@ -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<torrent> t
, boost::shared_ptr<socket_type> s
http_seed_connection(peer_connection_args const& pack
, web_seed_entry& web);
virtual int type() const { return peer_connection::http_seed_connection; }

View File

@ -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<torrent> tor;
boost::shared_ptr<socket_type> 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<torrent> t
, boost::shared_ptr<socket_type> 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

View File

@ -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<torrent> t
, boost::shared_ptr<socket_type> s
web_connection_base(peer_connection_args const& pack
, web_seed_entry& web);
virtual int timeout() const;

View File

@ -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<torrent> t
, boost::shared_ptr<socket_type> s
web_peer_connection(peer_connection_args const& pack
, web_seed_entry& web);
virtual void on_connected();

View File

@ -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<socket_type> s
, tcp::endpoint const& remote
, torrent_peer* peerinfo
, peer_id const& pid
, boost::weak_ptr<torrent> 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)

View File

@ -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<torrent> t
, boost::shared_ptr<socket_type> 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<torrent> tor = t.lock();
shared_ptr<torrent> tor = pack.tor.lock();
TORRENT_ASSERT(tor);
int blocks_per_piece = tor->torrent_file().piece_length() / tor->block_size();

View File

@ -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<torrent> tor
, shared_ptr<socket_type> 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

View File

@ -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<torrent>();
pack.s = s;
pack.endp = &endp;
pack.peerinfo = 0;
boost::shared_ptr<peer_connection> c
= boost::make_shared<bt_peer_connection>(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<bt_peer_connection>(boost::cref(pack)
, get_peer_id());
#if TORRENT_USE_ASSERTS
c->m_in_constructor = false;

View File

@ -6181,23 +6181,26 @@ namespace libtorrent
}
boost::shared_ptr<peer_connection> 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<web_peer_connection>(
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<http_seed_connection>(
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<peer_connection> c = boost::make_shared<bt_peer_connection>(
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;

View File

@ -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<torrent> t
, boost::shared_ptr<socket_type> 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

View File

@ -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<torrent> t
, boost::shared_ptr<socket_type> 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<torrent> tor = t.lock();
shared_ptr<torrent> tor = pack.tor.lock();
TORRENT_ASSERT(tor);
// we always prefer downloading 1 MiB chunks