no more extension_list_t type and uncommented call to torrent_plugin::on_load (#1042)

This commit is contained in:
Alden Torres 2016-08-30 17:36:44 -04:00 committed by Arvid Norberg
parent 2ac45d17ef
commit cfd2caeb74
6 changed files with 46 additions and 66 deletions

View File

@ -868,8 +868,7 @@ namespace libtorrent
protected:
#ifndef TORRENT_DISABLE_EXTENSIONS
typedef std::list<std::shared_ptr<peer_plugin>> extension_list_t;
extension_list_t m_extensions;
std::list<std::shared_ptr<peer_plugin>> m_extensions;
#endif
private:

View File

@ -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))

View File

@ -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

View File

@ -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&) {}
}

View File

@ -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()));