diff --git a/include/libtorrent/peer_connection.hpp b/include/libtorrent/peer_connection.hpp index 442a8b9ff..e5c418fd0 100644 --- a/include/libtorrent/peer_connection.hpp +++ b/include/libtorrent/peer_connection.hpp @@ -868,8 +868,7 @@ namespace libtorrent protected: #ifndef TORRENT_DISABLE_EXTENSIONS - typedef std::list> extension_list_t; - extension_list_t m_extensions; + std::list> m_extensions; #endif private: diff --git a/src/bt_peer_connection.cpp b/src/bt_peer_connection.cpp index e921dccd4..85ebee397 100644 --- a/src/bt_peer_connection.cpp +++ b/src/bt_peer_connection.cpp @@ -1771,7 +1771,7 @@ namespace libtorrent , "%s", print_entry(root).c_str()); #endif - for (extension_list_t::iterator i = m_extensions.begin(); + for (auto i = m_extensions.begin(); !m_extensions.empty() && i != m_extensions.end();) { // a false return value means that the extension @@ -1911,10 +1911,9 @@ namespace libtorrent default: { #ifndef TORRENT_DISABLE_EXTENSIONS - for (extension_list_t::iterator i = m_extensions.begin() - , end(m_extensions.end()); i != end; ++i) + for (auto const& e : m_extensions) { - if ((*i)->on_unknown_message(m_recv_buffer.packet_size(), packet_type + if (e->on_unknown_message(m_recv_buffer.packet_size(), packet_type , recv_buffer.subspan(1))) return m_recv_buffer.packet_finished(); } @@ -2238,10 +2237,9 @@ namespace libtorrent // loop backwards, to make the first extension be the last // to fill in the handshake (i.e. give the first extensions priority) - for (extension_list_t::reverse_iterator i = m_extensions.rbegin() - , end(m_extensions.rend()); i != end; ++i) + for (auto const& e : m_extensions) { - (*i)->add_handshake(handshake); + e->add_handshake(handshake); } #ifndef NDEBUG @@ -2307,10 +2305,9 @@ namespace libtorrent stats_counters().inc_stats_counter(counters::num_outgoing_unchoke); #ifndef TORRENT_DISABLE_EXTENSIONS - for (extension_list_t::iterator i = m_extensions.begin() - , end(m_extensions.end()); i != end; ++i) + for (auto const& e : m_extensions) { - (*i)->sent_unchoke(); + e->sent_unchoke(); } #endif } @@ -3339,7 +3336,7 @@ namespace libtorrent } #ifndef TORRENT_DISABLE_EXTENSIONS - for (extension_list_t::iterator i = m_extensions.begin() + for (auto i = m_extensions.begin() , end(m_extensions.end()); i != end;) { if (!(*i)->on_handshake(m_reserved_bits)) diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 053aea39a..aa5f0de73 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -1049,11 +1049,10 @@ namespace libtorrent // INVARIANT_CHECK; #ifndef TORRENT_DISABLE_EXTENSIONS - for (extension_list_t::iterator i = m_extensions.begin() - , end(m_extensions.end()); i != end; ++i) + for (auto const& e : m_extensions) { TORRENT_TRY { - (*i)->on_piece_pass(index); + e->on_piece_pass(index); } TORRENT_CATCH(std::exception&) {} } #else @@ -1070,11 +1069,10 @@ namespace libtorrent TORRENT_UNUSED(single_peer); #ifndef TORRENT_DISABLE_EXTENSIONS - for (extension_list_t::iterator i = m_extensions.begin() - , end(m_extensions.end()); i != end; ++i) + for (auto const& e : m_extensions) { TORRENT_TRY { - (*i)->on_piece_failed(index); + e->on_piece_failed(index); } TORRENT_CATCH(std::exception&) {} } #else @@ -1461,10 +1459,9 @@ namespace libtorrent if (!t) return; #ifndef TORRENT_DISABLE_EXTENSIONS - for (extension_list_t::iterator i = m_extensions.begin() - , end(m_extensions.end()); i != end; ++i) + for (auto const& e : m_extensions) { - if ((*i)->on_suggest(index)) return; + if (e->on_suggest(index)) return; } #endif @@ -1529,10 +1526,9 @@ namespace libtorrent #endif #ifndef TORRENT_DISABLE_EXTENSIONS - for (extension_list_t::iterator i = m_extensions.begin() - , end(m_extensions.end()); i != end; ++i) + for (auto const& e : m_extensions) { - if ((*i)->on_unchoke()) return; + if (e->on_unchoke()) return; } #endif @@ -1567,10 +1563,9 @@ namespace libtorrent TORRENT_ASSERT(t); #ifndef TORRENT_DISABLE_EXTENSIONS - for (extension_list_t::iterator i = m_extensions.begin() - , end(m_extensions.end()); i != end; ++i) + for (auto const& e : m_extensions) { - if ((*i)->on_interested()) return; + if (e->on_interested()) return; } #endif @@ -1660,10 +1655,9 @@ namespace libtorrent INVARIANT_CHECK; #ifndef TORRENT_DISABLE_EXTENSIONS - for (extension_list_t::iterator i = m_extensions.begin() - , end(m_extensions.end()); i != end; ++i) + for (auto const& e : m_extensions) { - if ((*i)->on_not_interested()) return; + if (e->on_not_interested()) return; } #endif @@ -1720,10 +1714,9 @@ namespace libtorrent TORRENT_ASSERT(t); #ifndef TORRENT_DISABLE_EXTENSIONS - for (extension_list_t::iterator i = m_extensions.begin() - , end(m_extensions.end()); i != end; ++i) + for (auto const& e : m_extensions) { - if ((*i)->on_have(index)) return; + if (e->on_have(index)) return; } #endif @@ -1952,10 +1945,9 @@ namespace libtorrent TORRENT_ASSERT(t); #ifndef TORRENT_DISABLE_EXTENSIONS - for (extension_list_t::iterator i = m_extensions.begin() - , end(m_extensions.end()); i != end; ++i) + for (auto const& e : m_extensions) { - if ((*i)->on_bitfield(bits)) return; + if (e->on_bitfield(bits)) return; } #endif @@ -2119,10 +2111,9 @@ namespace libtorrent { TORRENT_ASSERT(is_single_thread()); #ifndef TORRENT_DISABLE_EXTENSIONS - for (extension_list_t::const_iterator i = m_extensions.begin() - , end(m_extensions.end()); i != end; ++i) + for (auto const& e : m_extensions) { - if (!(*i)->can_disconnect(ec)) return false; + if (!e->can_disconnect(ec)) return false; } #else TORRENT_UNUSED(ec); @@ -2189,10 +2180,9 @@ namespace libtorrent if (is_disconnecting()) return; #ifndef TORRENT_DISABLE_EXTENSIONS - for (extension_list_t::iterator i = m_extensions.begin() - , end(m_extensions.end()); i != end; ++i) + for (auto const& e : m_extensions) { - if ((*i)->on_request(r)) return; + if (e->on_request(r)) return; } #endif if (is_disconnecting()) return; @@ -3094,10 +3084,9 @@ namespace libtorrent #endif #ifndef TORRENT_DISABLE_EXTENSIONS - for (extension_list_t::iterator i = m_extensions.begin() - , end(m_extensions.end()); i != end; ++i) + for (auto const& e : m_extensions) { - if ((*i)->on_have_all()) return; + if (e->on_have_all()) return; } #endif if (is_disconnecting()) return; @@ -3176,10 +3165,9 @@ namespace libtorrent TORRENT_ASSERT(t); #ifndef TORRENT_DISABLE_EXTENSIONS - for (extension_list_t::iterator i = m_extensions.begin() - , end(m_extensions.end()); i != end; ++i) + for (auto const& e : m_extensions) { - if ((*i)->on_have_none()) return; + if (e->on_have_none()) return; } #endif if (is_disconnecting()) return; @@ -3233,10 +3221,9 @@ namespace libtorrent #endif #ifndef TORRENT_DISABLE_EXTENSIONS - for (extension_list_t::iterator i = m_extensions.begin() - , end(m_extensions.end()); i != end; ++i) + for (auto const& e : m_extensions) { - if ((*i)->on_allowed_fast(index)) return; + if (e->on_allowed_fast(index)) return; } #endif if (is_disconnecting()) return; @@ -4151,10 +4138,9 @@ namespace libtorrent if (t) handle = t->get_handle(); #ifndef TORRENT_DISABLE_EXTENSIONS - for (extension_list_t::iterator i = m_extensions.begin() - , end(m_extensions.end()); i != end; ++i) + for (auto const& e : m_extensions) { - (*i)->on_disconnect(ec); + e->on_disconnect(ec); } #endif diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 46da70087..5c68f355d 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -2492,7 +2492,7 @@ namespace aux { // for SSL connections, incoming_connection() is called // after the handshake is done ADD_OUTSTANDING_ASYNC("session_impl::ssl_handshake"); - s->get >()->async_accept_handshake( + s->get>()->async_accept_handshake( std::bind(&session_impl::ssl_handshake, this, _1, s)); m_incoming_sockets.insert(s); } diff --git a/src/torrent.cpp b/src/torrent.cpp index 64e3a54ce..9b01d664d 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -2034,24 +2034,22 @@ namespace libtorrent } state_updated(); -/* + #ifndef TORRENT_DISABLE_EXTENSIONS // create the extensions again - // TOOD: should we store add_torrent_params::userdata + // TODO: should we store add_torrent_params::userdata // in torrent just to have it available here? - m_ses.add_extensions_to_torrent(shared_from_this(), nullptr); + //m_ses.add_extensions_to_torrent(shared_from_this(), nullptr); // and call on_load() on them - for (extension_list_t::iterator i = m_extensions.begin() - , end(m_extensions.end()); i != end; ++i) + for (auto const& e : m_extensions) { TORRENT_TRY { - (*i)->on_load(); + e->on_load(); } TORRENT_CATCH (std::exception&) {} } #endif -*/ inc_stats_counter(counters::num_loaded_torrents); @@ -2076,10 +2074,10 @@ namespace libtorrent // call on_unload() on extensions #ifndef TORRENT_DISABLE_EXTENSIONS - for (auto& ext : m_extensions) + for (auto const& e : m_extensions) { TORRENT_TRY { - ext->on_unload(); + e->on_unload(); } TORRENT_CATCH (std::exception&) {} } diff --git a/src/ut_metadata.cpp b/src/ut_metadata.cpp index 06e3ffcd8..0ddd11f92 100644 --- a/src/ut_metadata.cpp +++ b/src/ut_metadata.cpp @@ -279,7 +279,7 @@ namespace libtorrent { namespace if (!m_tp.need_loaded()) return; metadata = m_tp.metadata().data() + offset; metadata_piece_size = (std::min)( - int(m_tp.get_metadata_size() - offset), 16 * 1024); + m_tp.get_metadata_size() - offset, 16 * 1024); TORRENT_ASSERT(metadata_piece_size > 0); TORRENT_ASSERT(offset >= 0); TORRENT_ASSERT(offset + metadata_piece_size <= int(m_tp.get_metadata_size()));