Skip to content

Commit

Permalink
allow execution of on_unknown_torrent method in the absence of active…
Browse files Browse the repository at this point in the history
… torrents
  • Loading branch information
joriscarrier committed Nov 17, 2023
1 parent 9c18976 commit 62c4c27
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
3 changes: 2 additions & 1 deletion include/libtorrent/aux_/session_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,8 @@ namespace aux {
plugins_all_idx = 0, // to store all plugins
plugins_optimistic_unchoke_idx = 1, // optimistic_unchoke_feature
plugins_tick_idx = 2, // tick_feature
plugins_dht_request_idx = 3 // dht_request_feature
plugins_dht_request_idx = 3, // dht_request_feature
plugins_unknown_torrent_idx = 4 // unknown_torrent_feature
};

template <typename Fun, typename... Args>
Expand Down
4 changes: 4 additions & 0 deletions include/libtorrent/extensions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ TORRENT_VERSION_NAMESPACE_3
// called
static constexpr feature_flags_t alert_feature = 4_bit;

// include this bit if your plugin needs to have on_unknown_torrent()
// called even if there is no active torrent in the session
static constexpr feature_flags_t unknown_torrent_feature = 5_bit;

// This function is expected to return a bitmask indicating which features
// this plugin implements. Some callbacks on this object may not be called
// unless the corresponding feature flag is returned here. Note that
Expand Down
6 changes: 4 additions & 2 deletions src/session_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,8 @@ bool ssl_server_name_callback(ssl::stream_handle_type stream_handle, std::string
m_ses_extensions[plugins_tick_idx].push_back(ext);
if (features & plugin::dht_request_feature)
m_ses_extensions[plugins_dht_request_idx].push_back(ext);
if (features & plugin::unknown_torrent_feature)
m_ses_extensions[plugins_unknown_torrent_idx].push_back(ext);
if (features & plugin::alert_feature)
m_alerts.add_extension(ext);
session_handle h(shared_from_this());
Expand Down Expand Up @@ -3086,7 +3088,7 @@ namespace {

// check if we have any active torrents
// if we don't reject the connection
if (m_torrents.empty())
if (m_torrents.empty() && m_ses_extensions[plugins_unknown_torrent_idx].empty())
{
#ifndef TORRENT_DISABLE_LOGGING
session_log("<== INCOMING CONNECTION [ rejected, there are no torrents ]");
Expand Down Expand Up @@ -3140,7 +3142,7 @@ namespace {
// the setting to start up queued torrents when they
// get an incoming connection is enabled, we cannot
// perform this check.
if (!m_settings.get_bool(settings_pack::incoming_starts_queued_torrents))
if (!m_settings.get_bool(settings_pack::incoming_starts_queued_torrents) || m_ses_extensions[plugins_unknown_torrent_idx].empty())
{
bool has_active_torrent = std::any_of(m_torrents.begin(), m_torrents.end()
, [](std::shared_ptr<torrent> const& i)
Expand Down

0 comments on commit 62c4c27

Please sign in to comment.