pass all the arguments to peer connections as an argument pack
This commit is contained in:
parent
fa613131c2
commit
65bb1d0006
|
@ -85,17 +85,8 @@ namespace libtorrent
|
||||||
// this is the constructor where the we are the active part.
|
// this is the constructor where the we are the active part.
|
||||||
// The peer_conenction should handshake and verify that the
|
// The peer_conenction should handshake and verify that the
|
||||||
// other end has the correct id
|
// other end has the correct id
|
||||||
bt_peer_connection(
|
bt_peer_connection(peer_connection_args const& pack
|
||||||
aux::session_interface& ses
|
, peer_id const& pid);
|
||||||
, 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>());
|
|
||||||
|
|
||||||
void start();
|
void start();
|
||||||
|
|
||||||
|
|
|
@ -81,14 +81,7 @@ namespace libtorrent
|
||||||
// this is the constructor where the we are the active part.
|
// this is the constructor where the we are the active part.
|
||||||
// The peer_conenction should handshake and verify that the
|
// The peer_conenction should handshake and verify that the
|
||||||
// other end has the correct id
|
// other end has the correct id
|
||||||
http_seed_connection(
|
http_seed_connection(peer_connection_args const& pack
|
||||||
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_seed_entry& web);
|
, web_seed_entry& web);
|
||||||
|
|
||||||
virtual int type() const { return peer_connection::http_seed_connection; }
|
virtual int type() const { return peer_connection::http_seed_connection; }
|
||||||
|
|
|
@ -144,6 +144,21 @@ namespace libtorrent
|
||||||
{ return pb.block == block; }
|
{ 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
|
// internal
|
||||||
inline void nop(char*, void*, block_cache_reference) {}
|
inline void nop(char*, void*, block_cache_reference) {}
|
||||||
|
|
||||||
|
@ -280,17 +295,7 @@ namespace libtorrent
|
||||||
num_channels
|
num_channels
|
||||||
};
|
};
|
||||||
|
|
||||||
peer_connection(
|
peer_connection(peer_connection_args const& pack);
|
||||||
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);
|
|
||||||
|
|
||||||
// this function is called after it has been constructed and properly
|
// this function is called after it has been constructed and properly
|
||||||
// reference counted. It is safe to call self() in this function
|
// reference counted. It is safe to call self() in this function
|
||||||
|
|
|
@ -85,14 +85,7 @@ namespace libtorrent
|
||||||
// this is the constructor where the we are the active part.
|
// this is the constructor where the we are the active part.
|
||||||
// The peer_conenction should handshake and verify that the
|
// The peer_conenction should handshake and verify that the
|
||||||
// other end has the correct id
|
// other end has the correct id
|
||||||
web_connection_base(
|
web_connection_base(peer_connection_args const& pack
|
||||||
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_seed_entry& web);
|
, web_seed_entry& web);
|
||||||
|
|
||||||
virtual int timeout() const;
|
virtual int timeout() const;
|
||||||
|
|
|
@ -74,14 +74,7 @@ namespace libtorrent
|
||||||
// this is the constructor where the we are the active part.
|
// this is the constructor where the we are the active part.
|
||||||
// The peer_conenction should handshake and verify that the
|
// The peer_conenction should handshake and verify that the
|
||||||
// other end has the correct id
|
// other end has the correct id
|
||||||
web_peer_connection(
|
web_peer_connection(peer_connection_args const& pack
|
||||||
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_seed_entry& web);
|
, web_seed_entry& web);
|
||||||
|
|
||||||
virtual void on_connected();
|
virtual void on_connected();
|
||||||
|
|
|
@ -95,20 +95,9 @@ namespace libtorrent
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
bt_peer_connection::bt_peer_connection(
|
bt_peer_connection::bt_peer_connection(peer_connection_args const& pack
|
||||||
aux::session_interface& ses
|
, peer_id const& pid)
|
||||||
, aux::session_settings const& sett
|
: peer_connection(pack)
|
||||||
, 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)
|
|
||||||
, m_state(read_protocol_identifier)
|
, m_state(read_protocol_identifier)
|
||||||
, m_supports_extensions(false)
|
, m_supports_extensions(false)
|
||||||
, m_supports_dht_port(false)
|
, m_supports_dht_port(false)
|
||||||
|
|
|
@ -52,17 +52,9 @@ using libtorrent::aux::session_impl;
|
||||||
|
|
||||||
namespace libtorrent
|
namespace libtorrent
|
||||||
{
|
{
|
||||||
http_seed_connection::http_seed_connection(
|
http_seed_connection::http_seed_connection(peer_connection_args const& pack
|
||||||
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_seed_entry& web)
|
, web_seed_entry& web)
|
||||||
: web_connection_base(ses, sett, stats_counters, allocator, disk_thread
|
: web_connection_base(pack, web)
|
||||||
, t, s, web)
|
|
||||||
, m_url(web.url)
|
, m_url(web.url)
|
||||||
, m_response_left(0)
|
, m_response_left(0)
|
||||||
, m_chunk_pos(0)
|
, m_chunk_pos(0)
|
||||||
|
@ -73,7 +65,7 @@ namespace libtorrent
|
||||||
if (!m_settings.get_bool(settings_pack::report_web_seed_downloads))
|
if (!m_settings.get_bool(settings_pack::report_web_seed_downloads))
|
||||||
ignore_stats(true);
|
ignore_stats(true);
|
||||||
|
|
||||||
shared_ptr<torrent> tor = t.lock();
|
shared_ptr<torrent> tor = pack.tor.lock();
|
||||||
TORRENT_ASSERT(tor);
|
TORRENT_ASSERT(tor);
|
||||||
int blocks_per_piece = tor->torrent_file().piece_length() / tor->block_size();
|
int blocks_per_piece = tor->torrent_file().piece_length() / tor->block_size();
|
||||||
|
|
||||||
|
|
|
@ -125,30 +125,20 @@ namespace libtorrent
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// outbound connection
|
// outbound connection
|
||||||
peer_connection::peer_connection(
|
peer_connection::peer_connection(peer_connection_args const& pack)
|
||||||
aux::session_interface& ses
|
: peer_connection_hot_members(pack.tor, *pack.ses, *pack.sett)
|
||||||
, aux::session_settings const& sett
|
, m_socket(pack.s)
|
||||||
, counters& stats_counters
|
, m_peer_info(pack.peerinfo)
|
||||||
, buffer_allocator_interface& allocator
|
, m_counters(*pack.stats_counters)
|
||||||
, 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)
|
|
||||||
, m_num_pieces(0)
|
, m_num_pieces(0)
|
||||||
, m_rtt(0)
|
, m_rtt(0)
|
||||||
, m_recv_start(0)
|
, m_recv_start(0)
|
||||||
, m_desired_queue_size(2)
|
, m_desired_queue_size(2)
|
||||||
, m_max_out_request_queue(m_settings.get_int(settings_pack::max_out_request_queue))
|
, m_max_out_request_queue(m_settings.get_int(settings_pack::max_out_request_queue))
|
||||||
, m_remote(endp)
|
, m_remote(*pack.endp)
|
||||||
, m_disk_thread(disk_thread)
|
, m_disk_thread(*pack.disk_thread)
|
||||||
, m_allocator(allocator)
|
, m_allocator(*pack.allocator)
|
||||||
, m_ios(ios)
|
, m_ios(*pack.ios)
|
||||||
, m_work(m_ios)
|
, m_work(m_ios)
|
||||||
, m_last_piece(time_now())
|
, m_last_piece(time_now())
|
||||||
, m_last_request(time_now())
|
, m_last_request(time_now())
|
||||||
|
@ -168,7 +158,7 @@ namespace libtorrent
|
||||||
, m_uploaded_at_last_unchoke(0)
|
, m_uploaded_at_last_unchoke(0)
|
||||||
, m_soft_packet_size(0)
|
, m_soft_packet_size(0)
|
||||||
, m_outstanding_bytes(0)
|
, m_outstanding_bytes(0)
|
||||||
, m_disk_recv_buffer(allocator, 0)
|
, m_disk_recv_buffer(*pack.allocator, 0)
|
||||||
, m_last_seen_complete(0)
|
, m_last_seen_complete(0)
|
||||||
, m_receiving_block(piece_block::invalid)
|
, m_receiving_block(piece_block::invalid)
|
||||||
, m_timeout_extend(0)
|
, m_timeout_extend(0)
|
||||||
|
@ -189,12 +179,12 @@ namespace libtorrent
|
||||||
, m_prefer_whole_pieces(0)
|
, m_prefer_whole_pieces(0)
|
||||||
, m_disk_read_failures(0)
|
, m_disk_read_failures(0)
|
||||||
, m_outstanding_piece_verification(0)
|
, m_outstanding_piece_verification(0)
|
||||||
, m_outgoing(!tor.expired())
|
, m_outgoing(!pack.tor.expired())
|
||||||
, m_received_listen_port(false)
|
, m_received_listen_port(false)
|
||||||
, m_fast_reconnect(false)
|
, m_fast_reconnect(false)
|
||||||
, m_failed(false)
|
, m_failed(false)
|
||||||
, m_connected(tor.expired())
|
, m_connected(pack.tor.expired())
|
||||||
, m_queued(!tor.expired())
|
, m_queued(!pack.tor.expired())
|
||||||
, m_request_large_blocks(false)
|
, m_request_large_blocks(false)
|
||||||
, m_share_mode(false)
|
, m_share_mode(false)
|
||||||
, m_upload_only(false)
|
, m_upload_only(false)
|
||||||
|
@ -241,7 +231,7 @@ namespace libtorrent
|
||||||
m_quota[0] = 0;
|
m_quota[0] = 0;
|
||||||
m_quota[1] = 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
|
#ifndef TORRENT_DISABLE_RESOLVE_COUNTRIES
|
||||||
std::fill(m_country, m_country + 2, 0);
|
std::fill(m_country, m_country + 2, 0);
|
||||||
#ifndef TORRENT_DISABLE_GEO_IP
|
#ifndef TORRENT_DISABLE_GEO_IP
|
||||||
|
|
|
@ -3169,10 +3169,20 @@ retry:
|
||||||
|
|
||||||
setup_socket_buffers(*s);
|
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::shared_ptr<peer_connection> c
|
||||||
= boost::make_shared<bt_peer_connection>(boost::ref(*this), m_settings
|
= boost::make_shared<bt_peer_connection>(boost::cref(pack)
|
||||||
, boost::ref(m_stats_counters), boost::ref(*this)
|
|
||||||
, boost::ref(m_disk_thread), s, endp, (torrent_peer*)0
|
|
||||||
, get_peer_id());
|
, get_peer_id());
|
||||||
#if TORRENT_USE_ASSERTS
|
#if TORRENT_USE_ASSERTS
|
||||||
c->m_in_constructor = false;
|
c->m_in_constructor = false;
|
||||||
|
|
|
@ -6181,23 +6181,26 @@ namespace libtorrent
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::shared_ptr<peer_connection> c;
|
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)
|
if (web->type == web_seed_entry::url_seed)
|
||||||
{
|
{
|
||||||
c = boost::make_shared<web_peer_connection>(
|
c = boost::make_shared<web_peer_connection>(
|
||||||
boost::ref(m_ses), m_ses.settings()
|
boost::cref(pack), boost::ref(*web));
|
||||||
, boost::ref(m_ses.stats_counters())
|
|
||||||
, boost::ref(m_ses)
|
|
||||||
, boost::ref(m_ses.disk_thread())
|
|
||||||
, shared_from_this(), s, boost::ref(*web));
|
|
||||||
}
|
}
|
||||||
else if (web->type == web_seed_entry::http_seed)
|
else if (web->type == web_seed_entry::http_seed)
|
||||||
{
|
{
|
||||||
c = boost::make_shared<http_seed_connection>(
|
c = boost::make_shared<http_seed_connection>(
|
||||||
boost::ref(m_ses), m_ses.settings()
|
boost::cref(pack), boost::ref(*web));
|
||||||
, boost::ref(m_ses.stats_counters())
|
|
||||||
, boost::ref(m_ses)
|
|
||||||
, boost::ref(m_ses.disk_thread())
|
|
||||||
, shared_from_this(), s, boost::ref(*web));
|
|
||||||
}
|
}
|
||||||
if (!c) return;
|
if (!c) return;
|
||||||
|
|
||||||
|
@ -7197,12 +7200,20 @@ namespace libtorrent
|
||||||
|
|
||||||
m_ses.setup_socket_buffers(*s);
|
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::shared_ptr<peer_connection> c = boost::make_shared<bt_peer_connection>(
|
||||||
boost::ref(m_ses), m_ses.settings()
|
boost::cref(pack), m_ses.get_peer_id());
|
||||||
, 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());
|
|
||||||
|
|
||||||
#if TORRENT_USE_ASSERTS
|
#if TORRENT_USE_ASSERTS
|
||||||
c->m_in_constructor = false;
|
c->m_in_constructor = false;
|
||||||
|
|
|
@ -52,16 +52,9 @@ using boost::shared_ptr;
|
||||||
namespace libtorrent
|
namespace libtorrent
|
||||||
{
|
{
|
||||||
web_connection_base::web_connection_base(
|
web_connection_base::web_connection_base(
|
||||||
aux::session_interface& ses
|
peer_connection_args const& pack
|
||||||
, 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_seed_entry& web)
|
, web_seed_entry& web)
|
||||||
: peer_connection(ses, sett, stats_counters, allocator, disk_thread
|
: peer_connection(pack)
|
||||||
, ses.get_io_service(), t, s, web.endpoint, &web.peer_info)
|
|
||||||
, m_first_request(true)
|
, m_first_request(true)
|
||||||
, m_ssl(false)
|
, m_ssl(false)
|
||||||
, m_external_auth(web.auth)
|
, m_external_auth(web.auth)
|
||||||
|
@ -69,6 +62,9 @@ namespace libtorrent
|
||||||
, m_parser(http_parser::dont_parse_chunks)
|
, m_parser(http_parser::dont_parse_chunks)
|
||||||
, m_body_start(0)
|
, m_body_start(0)
|
||||||
{
|
{
|
||||||
|
TORRENT_ASSERT(&web.peer_info == pack.peerinfo);
|
||||||
|
TORRENT_ASSERT(web.endpoint == *pack.endp);
|
||||||
|
|
||||||
INVARIANT_CHECK;
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
// we only want left-over bandwidth
|
// we only want left-over bandwidth
|
||||||
|
|
|
@ -60,17 +60,9 @@ enum
|
||||||
|
|
||||||
struct disk_interface;
|
struct disk_interface;
|
||||||
|
|
||||||
web_peer_connection::web_peer_connection(
|
web_peer_connection::web_peer_connection(peer_connection_args const& pack
|
||||||
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_seed_entry& web)
|
, web_seed_entry& web)
|
||||||
: web_connection_base(ses, sett, stats_counters, allocator, disk_thread
|
: web_connection_base(pack, web)
|
||||||
, t, s, web)
|
|
||||||
, m_url(web.url)
|
, m_url(web.url)
|
||||||
, m_web(&web)
|
, m_web(&web)
|
||||||
, m_received_body(0)
|
, 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))
|
if (!m_settings.get_bool(settings_pack::report_web_seed_downloads))
|
||||||
ignore_stats(true);
|
ignore_stats(true);
|
||||||
|
|
||||||
shared_ptr<torrent> tor = t.lock();
|
shared_ptr<torrent> tor = pack.tor.lock();
|
||||||
TORRENT_ASSERT(tor);
|
TORRENT_ASSERT(tor);
|
||||||
|
|
||||||
// we always prefer downloading 1 MiB chunks
|
// we always prefer downloading 1 MiB chunks
|
||||||
|
|
Loading…
Reference in New Issue