restore find_plugin API (#2026)

This commit is contained in:
Steven Siloti 2017-05-24 20:29:21 -07:00 committed by Arvid Norberg
parent 392f284566
commit 40cfceb994
5 changed files with 26 additions and 0 deletions

View File

@ -370,6 +370,10 @@ namespace libtorrent {
// hidden // hidden
virtual ~peer_plugin() {} virtual ~peer_plugin() {}
// This function is expected to return the name of
// the plugin.
virtual string_view type() const { return {}; }
// can add entries to the extension handshake // can add entries to the extension handshake
// this is not called for web seeds // this is not called for web seeds
virtual void add_handshake(entry&) {} virtual void add_handshake(entry&) {}

View File

@ -303,6 +303,7 @@ namespace aux {
#ifndef TORRENT_DISABLE_EXTENSIONS #ifndef TORRENT_DISABLE_EXTENSIONS
void add_extension(std::shared_ptr<peer_plugin>); void add_extension(std::shared_ptr<peer_plugin>);
peer_plugin const* find_plugin(string_view type);
#endif #endif
// this function is called once the torrent associated // this function is called once the torrent associated

View File

@ -57,6 +57,7 @@ struct TORRENT_EXPORT peer_connection_handle
connection_type type() const; connection_type type() const;
void add_extension(std::shared_ptr<peer_plugin>); void add_extension(std::shared_ptr<peer_plugin>);
peer_plugin const* find_plugin(string_view type);
bool is_seed() const; bool is_seed() const;

View File

@ -518,6 +518,14 @@ namespace libtorrent {
TORRENT_ASSERT(is_single_thread()); TORRENT_ASSERT(is_single_thread());
m_extensions.push_back(ext); m_extensions.push_back(ext);
} }
peer_plugin const* peer_connection::find_plugin(string_view type)
{
TORRENT_ASSERT(is_single_thread());
auto p = std::find_if(m_extensions.begin(), m_extensions.end()
, [&](std::shared_ptr<peer_plugin> const& e) { return e->type() == type; });
return p != m_extensions.end() ? p->get() : nullptr;
}
#endif #endif
void peer_connection::send_allowed_set() void peer_connection::send_allowed_set()

View File

@ -57,6 +57,18 @@ void peer_connection_handle::add_extension(std::shared_ptr<peer_plugin> ext)
#endif #endif
} }
peer_plugin const* peer_connection_handle::find_plugin(string_view type)
{
#ifndef TORRENT_DISABLE_EXTENSIONS
std::shared_ptr<peer_connection> pc = native_handle();
TORRENT_ASSERT(pc);
return pc->find_plugin(type);
#else
TORRENT_UNUSED(type);
return nullptr;
#endif
}
bool peer_connection_handle::is_seed() const bool peer_connection_handle::is_seed() const
{ {
std::shared_ptr<peer_connection> pc = native_handle(); std::shared_ptr<peer_connection> pc = native_handle();