Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented automatic torrent notification on torrent alerts
Browse files Browse the repository at this point in the history
joriscarrier committed Jan 3, 2024

Verified

This commit was signed with the committer’s verified signature. The key has expired.
o01eg O01eg
1 parent 96a8174 commit 387b193
Showing 4 changed files with 41 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -710,6 +710,8 @@ feature_option(exceptions "build with exception support" ON)
feature_option(gnutls "build using GnuTLS instead of OpenSSL" OFF)
target_optional_compile_definitions(torrent-rasterbar PUBLIC FEATURE NAME extensions DEFAULT ON
DESCRIPTION "Enables protocol extensions" DISABLED TORRENT_DISABLE_EXTENSIONS)
target_optional_compile_definitions(torrent-rasterbar PUBLIC FEATURE NAME torrent_auto_notify DEFAULT OFF
DESCRIPTION "Enables torrent notify on torrent_alert" DISABLED TORRENT_DISABLE_TORRENT_AUTO_NOTIFY)
target_optional_compile_definitions(torrent-rasterbar PUBLIC FEATURE NAME i2p DEFAULT ON
DESCRIPTION "build with I2P support" DISABLED TORRENT_USE_I2P=0)
target_optional_compile_definitions(torrent-rasterbar PUBLIC FEATURE NAME logging DEFAULT ON
3 changes: 3 additions & 0 deletions Jamfile
Original file line number Diff line number Diff line change
@@ -573,6 +573,9 @@ feature.compose <windows-version>xp : <define>_WIN32_WINNT=0x0501 ;
feature extensions : on off : composite propagated link-incompatible ;
feature.compose <extensions>off : <define>TORRENT_DISABLE_EXTENSIONS ;

feature torrent_auto_notify : off on : composite propagated link-incompatible ;
feature.compose <torrent_auto_notify>off : <define>TORRENT_DISABLE_TORRENT_AUTO_NOTIFY ;

feature asio-debugging : off on : composite propagated link-incompatible ;
feature.compose <asio-debugging>on : <define>TORRENT_ASIO_DEBUGGING ;

13 changes: 13 additions & 0 deletions docs/building.rst
Original file line number Diff line number Diff line change
@@ -450,6 +450,11 @@ Build features
| | * ``off`` - disable mmap storage, and fall back to |
| | single-threaded, portable file operations. |
+--------------------------+----------------------------------------------------+
| ``torrent_auto_notify`` | * ``off`` - default. disable automatic |
| | notification on torrent alerts |
| | * ``on`` - enable automatic notification on |
| | torrent alerts |
+--------------------------+----------------------------------------------------+

The ``variant`` feature is *implicit*, which means you don't need to specify
the name of the feature, just the value.
@@ -699,6 +704,14 @@ own code that compiles and links with libtorrent.
| | disabled along with support for the extension |
| | handshake (BEP 10). |
+----------------------------------------+-------------------------------------------------+
| ``TORRENT_DISABLE_TORRENT_AUTO_NOTIFY``| If this is defined, libtorrent will not notify |
| | the torrent on a torrent alert. you can |
| | manually notify the torrent via plugins |
| | by calling ``torrent::notify()`` |
| | (This is set by the Jamfile when |
| | ``torrent_auto_notify=off`` is set |
| | (default is off)). |
+----------------------------------------+-------------------------------------------------+
| ``TORRENT_USE_INVARIANT_CHECKS`` | If defined to non-zero, this will enable |
| | internal invariant checks in libtorrent. |
| | The invariant checks can sometimes |
24 changes: 23 additions & 1 deletion include/libtorrent/aux_/alert_manager.hpp
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
Copyright (c) 2003-2013, Daniel Wallin
Copyright (c) 2013, 2015-2020, Arvid Norberg
Copyright (c) 2016, 2018, 2020, Alden Torres
Copyright (c) 2024, Joris Carrier
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -48,6 +49,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <condition_variable>
#include <atomic>
#include <bitset>
#include <type_traits> // for std::is_base_of

#ifndef TORRENT_DISABLE_EXTENSIONS
#include "libtorrent/extensions.hpp"
@@ -58,6 +60,20 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent {
namespace aux {

template<typename T>
void handle_alert_on_torrent_impl(const T& a, std::true_type) {
static_cast<void>(a); // avoid the warning unused (-Wunused-parameter)
#ifndef TORRENT_DISABLE_TORRENT_AUTO_NOTIFY
auto t = a.handle.native_handle();
if (t) t->notify();
#endif
}

template<typename T>
void handle_alert_on_torrent_impl(const T&, std::false_type) {
// Do nothing if alert is not derivied from torrent_alert
}

struct TORRENT_EXTRA_EXPORT alert_manager
{
explicit alert_manager(int queue_limit
@@ -68,6 +84,12 @@ namespace aux {

~alert_manager();

template<class T>
void handle_alert(T& a) {
handle_alert_on_torrent_impl(a, std::is_base_of<torrent_alert, T>());
maybe_notify(&a);
}

template <class T, typename... Args>
void emplace_alert(Args&&... args) try
{
@@ -88,7 +110,7 @@ namespace aux {
T& alert = queue.emplace_back<T>(
m_allocations[m_generation], std::forward<Args>(args)...);

maybe_notify(&alert);
handle_alert(alert);
}
catch (std::bad_alloc const&)
{

0 comments on commit 387b193

Please sign in to comment.