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 // 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; } aux::session_interface& ses() { return m_ses; }
protected: protected:

View File

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

View File

@ -162,7 +162,7 @@ namespace libtorrent
size -= pr.length; 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 bool using_proxy = (proxy_type == settings_pack::http
|| proxy_type == settings_pack::http_pw) && !m_ssl; || proxy_type == settings_pack::http_pw) && !m_ssl;
@ -185,7 +185,7 @@ namespace libtorrent
} }
request += " HTTP/1.1\r\n"; 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"; request += "\r\n\r\n";
m_first_request = false; m_first_request = false;

View File

@ -3892,7 +3892,6 @@ namespace libtorrent
void peer_connection::on_connect_timeout() void peer_connection::on_connect_timeout()
{ {
m_queued_for_connection = false; m_queued_for_connection = false;
TORRENT_ASSERT(m_ses.is_single_thread());
#if defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING #if defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
boost::shared_ptr<torrent> t = m_torrent.lock(); boost::shared_ptr<torrent> t = m_torrent.lock();
@ -3977,8 +3976,6 @@ namespace libtorrent
// 2 protocol error (client sent something invalid) // 2 protocol error (client sent something invalid)
void peer_connection::disconnect(error_code const& ec, operation_t op, int error) void peer_connection::disconnect(error_code const& ec, operation_t op, int error)
{ {
TORRENT_ASSERT(m_ses.is_single_thread());
#if TORRENT_USE_ASSERTS #if TORRENT_USE_ASSERTS
m_disconnect_started = true; m_disconnect_started = true;
#endif #endif
@ -6668,7 +6665,7 @@ namespace libtorrent
} }
if (!m_disconnect_started && m_initialized 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 // none of this matters if we're disconnecting anyway
if (t->is_upload_only() && !m_need_interest_update) 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; 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 bool using_proxy = (proxy_type == settings_pack::http
|| proxy_type == settings_pack::http_pw) && !m_ssl; || 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 // assumed to be encoded in the torrent file
request += using_proxy ? m_url : m_path; request += using_proxy ? m_url : m_path;
request += " HTTP/1.1\r\n"; 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 += "\r\nRange: bytes=";
request += to_string(size_type(req.piece) * info.piece_length() request += to_string(size_type(req.piece) * info.piece_length()
+ req.start).elems; + 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 += escape_path(path.c_str(), path.length());
} }
request += " HTTP/1.1\r\n"; 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 += "\r\nRange: bytes=";
request += to_string(f.offset).elems; request += to_string(f.offset).elems;
request += "-"; request += "-";
@ -593,7 +593,7 @@ void web_peer_connection::on_receive(error_code const& error
// associated with the file we just requested. Only // associated with the file we just requested. Only
// when it doesn't have any of the file do the following // when it doesn't have any of the file do the following
int retry_time = atoi(m_parser.header("retry-after").c_str()); 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 // temporarily unavailable, retry later
t->retry_web_seed(this, retry_time); t->retry_web_seed(this, retry_time);
std::string error_msg = to_string(m_parser.status_code()).elems std::string error_msg = to_string(m_parser.status_code()).elems