remove some peer connection dependencies on m_ses

This commit is contained in:
Arvid Norberg 2014-07-12 22:32:55 +00:00
parent d16fe60ca4
commit bf18e310e6
5 changed files with 17 additions and 21 deletions

View File

@ -762,7 +762,7 @@ namespace libtorrent
}
// TODO: 2 temporary hack until the stats counters are moved out
// from the session_interface.
// from the session_interface. This is used by ut_pex and ut_metadata.
aux::session_interface& ses() { return m_ses; }
protected:

View File

@ -159,7 +159,6 @@ namespace libtorrent
bt_peer_connection::~bt_peer_connection()
{
TORRENT_ASSERT(m_ses.is_single_thread());
}
void bt_peer_connection::on_connected()
@ -184,7 +183,7 @@ namespace libtorrent
#ifndef TORRENT_DISABLE_ENCRYPTION
boost::uint8_t out_enc_policy = m_ses.settings().get_int(settings_pack::out_enc_policy);
boost::uint8_t out_enc_policy = m_settings.get_int(settings_pack::out_enc_policy);
#ifdef TORRENT_USE_OPENSSL
// never try an encrypted connection when already using SSL
@ -521,7 +520,7 @@ namespace libtorrent
// write the verification constant and crypto field
int encrypt_size = sizeof(msg) - 512 + pad_size - 40;
boost::uint8_t crypto_provide = m_ses.settings().get_int(settings_pack::allowed_enc_level);
boost::uint8_t crypto_provide = m_settings.get_int(settings_pack::allowed_enc_level);
// this is an invalid setting, but let's just make the best of the situation
if ((crypto_provide & settings_pack::pe_both) == 0)
@ -2878,12 +2877,12 @@ namespace libtorrent
if (!is_outgoing())
{
// select a crypto method
int allowed_encryption = m_ses.settings().get_int(settings_pack::allowed_enc_level);
int allowed_encryption = m_settings.get_int(settings_pack::allowed_enc_level);
int crypto_select = crypto_field & allowed_encryption;
// when prefer_rc4 is set, keep the most significant bit
// otherwise keep the least significant one
if (m_ses.settings().get_bool(settings_pack::prefer_rc4))
if (m_settings.get_bool(settings_pack::prefer_rc4))
{
int mask = INT_MAX;
while (crypto_select & (mask << 1))
@ -2914,7 +2913,7 @@ namespace libtorrent
else // is_outgoing()
{
// check if crypto select is valid
int allowed_encryption = m_ses.settings().get_int(settings_pack::allowed_enc_level);
int allowed_encryption = m_settings.get_int(settings_pack::allowed_enc_level);
crypto_field &= allowed_encryption;
if (crypto_field == 0)
@ -3085,7 +3084,7 @@ namespace libtorrent
// encrypted portion of handshake completed, toggle
// peer_info pe_support flag back to true
if (is_outgoing() &&
m_ses.settings().get_int(settings_pack::out_enc_policy)
m_settings.get_int(settings_pack::out_enc_policy)
== settings_pack::pe_enabled)
{
torrent_peer* pi = peer_info_struct();
@ -3130,7 +3129,7 @@ namespace libtorrent
#endif // TORRENT_USE_OPENSSL
if (!is_outgoing()
&& m_ses.settings().get_int(settings_pack::in_enc_policy)
&& m_settings.get_int(settings_pack::in_enc_policy)
== settings_pack::pe_disabled)
{
disconnect(errors::no_incoming_encrypted, op_bittorrent);
@ -3165,7 +3164,7 @@ namespace libtorrent
TORRENT_ASSERT(m_state != read_pe_dhkey);
if (!is_outgoing()
&& m_ses.settings().get_int(settings_pack::in_enc_policy)
&& m_settings.get_int(settings_pack::in_enc_policy)
== settings_pack::pe_forced
&& !m_encrypted
&& !is_ssl(*get_socket()))
@ -3387,7 +3386,7 @@ namespace libtorrent
// Toggle pe_support back to false if this is a
// standard successful connection
if (is_outgoing() && !m_encrypted &&
m_ses.settings().get_int(settings_pack::out_enc_policy)
m_settings.get_int(settings_pack::out_enc_policy)
== settings_pack::pe_enabled)
{
torrent_peer* pi = peer_info_struct();

View File

@ -162,7 +162,7 @@ namespace libtorrent
size -= pr.length;
}
int proxy_type = m_ses.settings().get_int(settings_pack::proxy_type);
int proxy_type = m_settings.get_int(settings_pack::proxy_type);
bool using_proxy = (proxy_type == settings_pack::http
|| proxy_type == settings_pack::http_pw) && !m_ssl;
@ -185,7 +185,7 @@ namespace libtorrent
}
request += " HTTP/1.1\r\n";
add_headers(request, m_ses.settings(), using_proxy);
add_headers(request, m_settings, using_proxy);
request += "\r\n\r\n";
m_first_request = false;

View File

@ -3892,7 +3892,6 @@ namespace libtorrent
void peer_connection::on_connect_timeout()
{
m_queued_for_connection = false;
TORRENT_ASSERT(m_ses.is_single_thread());
#if defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
boost::shared_ptr<torrent> t = m_torrent.lock();
@ -3977,8 +3976,6 @@ namespace libtorrent
// 2 protocol error (client sent something invalid)
void peer_connection::disconnect(error_code const& ec, operation_t op, int error)
{
TORRENT_ASSERT(m_ses.is_single_thread());
#if TORRENT_USE_ASSERTS
m_disconnect_started = true;
#endif
@ -6668,7 +6665,7 @@ namespace libtorrent
}
if (!m_disconnect_started && m_initialized
&& m_ses.settings().get_bool(settings_pack::close_redundant_connections))
&& m_settings.get_bool(settings_pack::close_redundant_connections))
{
// none of this matters if we're disconnecting anyway
if (t->is_upload_only() && !m_need_interest_update)

View File

@ -279,7 +279,7 @@ void web_peer_connection::write_request(peer_request const& r)
size -= pr.length;
}
int proxy_type = m_ses.settings().get_int(settings_pack::proxy_type);
int proxy_type = m_settings.get_int(settings_pack::proxy_type);
bool using_proxy = (proxy_type == settings_pack::http
|| proxy_type == settings_pack::http_pw) && !m_ssl;
@ -290,7 +290,7 @@ void web_peer_connection::write_request(peer_request const& r)
// assumed to be encoded in the torrent file
request += using_proxy ? m_url : m_path;
request += " HTTP/1.1\r\n";
add_headers(request, m_ses.settings(), using_proxy);
add_headers(request, m_settings, using_proxy);
request += "\r\nRange: bytes=";
request += to_string(size_type(req.piece) * info.piece_length()
+ req.start).elems;
@ -347,7 +347,7 @@ void web_peer_connection::write_request(peer_request const& r)
request += escape_path(path.c_str(), path.length());
}
request += " HTTP/1.1\r\n";
add_headers(request, m_ses.settings(), using_proxy);
add_headers(request, m_settings, using_proxy);
request += "\r\nRange: bytes=";
request += to_string(f.offset).elems;
request += "-";
@ -593,7 +593,7 @@ void web_peer_connection::on_receive(error_code const& error
// associated with the file we just requested. Only
// when it doesn't have any of the file do the following
int retry_time = atoi(m_parser.header("retry-after").c_str());
if (retry_time <= 0) retry_time = m_ses.settings().get_int(settings_pack::urlseed_wait_retry);
if (retry_time <= 0) retry_time = m_settings.get_int(settings_pack::urlseed_wait_retry);
// temporarily unavailable, retry later
t->retry_web_seed(this, retry_time);
std::string error_msg = to_string(m_parser.status_code()).elems