2003-11-29 17:34:07 +01:00
|
|
|
/*
|
|
|
|
|
2016-01-18 00:57:46 +01:00
|
|
|
Copyright (c) 2003-2016, Arvid Norberg, Daniel Wallin
|
2003-11-29 17:34:07 +01:00
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions
|
|
|
|
are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
* Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in
|
|
|
|
the documentation and/or other materials provided with the distribution.
|
|
|
|
* Neither the name of the author nor the names of its
|
|
|
|
contributors may be used to endorse or promote products derived
|
|
|
|
from this software without specific prior written permission.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2004-01-25 19:18:36 +01:00
|
|
|
#ifndef TORRENT_ALERT_HPP_INCLUDED
|
|
|
|
#define TORRENT_ALERT_HPP_INCLUDED
|
2003-11-29 17:34:07 +01:00
|
|
|
|
|
|
|
#include <string>
|
2015-04-18 04:33:39 +02:00
|
|
|
|
2013-08-08 03:03:54 +02:00
|
|
|
// OVERVIEW
|
|
|
|
//
|
2014-04-28 06:46:33 +02:00
|
|
|
// The pop_alerts() function on session is the main interface for retrieving
|
|
|
|
// alerts (warnings, messages and errors from libtorrent). If no alerts have
|
2015-04-03 22:15:48 +02:00
|
|
|
// been posted by libtorrent pop_alerts() will return an empty list.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2016-03-18 18:43:11 +01:00
|
|
|
// By default, only errors are reported. settings_pack::alert_mask can be
|
2015-11-20 06:51:58 +01:00
|
|
|
// used to specify which kinds of events should be reported. The alert mask is
|
2017-07-26 06:33:10 +02:00
|
|
|
// a combination of the alert_category_t flags in the alert class.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2015-04-03 22:15:48 +02:00
|
|
|
// Every alert belongs to one or more category. There is a cost associated with
|
|
|
|
// posting alerts. Only alerts that belong to an enabled category are
|
2014-04-28 06:46:33 +02:00
|
|
|
// posted. Setting the alert bitmask to 0 will disable all alerts (except those
|
2015-04-03 22:15:48 +02:00
|
|
|
// that are non-discardable). Alerts that are responses to API calls such as
|
|
|
|
// save_resume_data() and post_session_stats() are non-discardable and will be
|
|
|
|
// posted even if their category is disabled.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2013-08-08 04:57:07 +02:00
|
|
|
// There are other alert base classes that some alerts derive from, all the
|
2014-04-28 06:46:33 +02:00
|
|
|
// alerts that are generated for a specific torrent are derived from
|
|
|
|
// torrent_alert, and tracker events derive from tracker_alert.
|
2013-08-08 03:03:54 +02:00
|
|
|
//
|
2015-04-03 22:15:48 +02:00
|
|
|
// Alerts returned by pop_alerts() are only valid until the next call to
|
|
|
|
// pop_alerts(). You may not copy an alert object to access it after the next
|
|
|
|
// call to pop_alerts(). Internal members of alerts also become invalid once
|
|
|
|
// pop_alerts() is called again.
|
2013-08-08 03:03:54 +02:00
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
#include "libtorrent/time.hpp"
|
2005-11-01 19:30:39 +01:00
|
|
|
#include "libtorrent/config.hpp"
|
2017-07-26 06:33:10 +02:00
|
|
|
#include "libtorrent/flags.hpp"
|
2004-01-25 19:18:36 +01:00
|
|
|
|
2017-04-12 19:00:57 +02:00
|
|
|
namespace libtorrent {
|
2003-11-29 17:34:07 +01:00
|
|
|
|
2017-07-26 06:33:10 +02:00
|
|
|
// hidden
|
|
|
|
struct alert_category_tag;
|
|
|
|
using alert_category_t = flags::bitfield_flag<std::uint32_t, alert_category_tag>;
|
|
|
|
|
2013-08-08 03:03:54 +02:00
|
|
|
// The ``alert`` class is the base class that specific messages are derived from.
|
2016-02-28 05:53:25 +01:00
|
|
|
// alert types are not copyable, and cannot be constructed by the client. The
|
|
|
|
// pointers returned by libtorrent are short lived (the details are described
|
|
|
|
// under session_handle::pop_alerts())
|
2005-11-01 19:30:39 +01:00
|
|
|
class TORRENT_EXPORT alert
|
2003-11-29 17:34:07 +01:00
|
|
|
{
|
|
|
|
public:
|
2008-07-06 14:22:56 +02:00
|
|
|
|
2016-05-13 14:19:44 +02:00
|
|
|
alert(alert const& rhs) = delete;
|
|
|
|
alert& operator=(alert const&) = delete;
|
2017-05-28 13:14:58 +02:00
|
|
|
alert(alert&& rhs) noexcept = default;
|
2016-05-13 14:19:44 +02:00
|
|
|
|
2009-10-30 04:21:25 +01:00
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
2008-07-06 14:22:56 +02:00
|
|
|
// only here for backwards compatibility
|
2017-03-18 01:41:47 +01:00
|
|
|
enum TORRENT_DEPRECATED severity_t { debug, info, warning, critical, fatal, none };
|
2009-10-30 04:21:25 +01:00
|
|
|
#endif
|
2003-11-29 17:34:07 +01:00
|
|
|
|
2017-07-26 06:33:10 +02:00
|
|
|
// Enables alerts that report an error. This includes:
|
|
|
|
//
|
|
|
|
// * tracker errors
|
|
|
|
// * tracker warnings
|
|
|
|
// * file errors
|
|
|
|
// * resume data failures
|
|
|
|
// * web seed errors
|
|
|
|
// * .torrent files errors
|
|
|
|
// * listen socket errors
|
|
|
|
// * port mapping errors
|
2017-07-30 18:13:22 +02:00
|
|
|
static constexpr alert_category_t error_notification = 0_bit;
|
2017-07-26 06:33:10 +02:00
|
|
|
|
|
|
|
// Enables alerts when peers send invalid requests, get banned or
|
|
|
|
// snubbed.
|
2017-07-30 18:13:22 +02:00
|
|
|
static constexpr alert_category_t peer_notification = 1_bit;
|
2017-07-26 06:33:10 +02:00
|
|
|
|
|
|
|
// Enables alerts for port mapping events. For NAT-PMP and UPnP.
|
2017-07-30 18:13:22 +02:00
|
|
|
static constexpr alert_category_t port_mapping_notification = 2_bit;
|
2017-07-26 06:33:10 +02:00
|
|
|
|
|
|
|
// Enables alerts for events related to the storage. File errors and
|
|
|
|
// synchronization events for moving the storage, renaming files etc.
|
2017-07-30 18:13:22 +02:00
|
|
|
static constexpr alert_category_t storage_notification = 3_bit;
|
2017-07-26 06:33:10 +02:00
|
|
|
|
|
|
|
// Enables all tracker events. Includes announcing to trackers,
|
|
|
|
// receiving responses, warnings and errors.
|
2017-07-30 18:13:22 +02:00
|
|
|
static constexpr alert_category_t tracker_notification = 4_bit;
|
2017-07-26 06:33:10 +02:00
|
|
|
|
|
|
|
// Low level alerts for when peers are connected and disconnected.
|
2017-07-30 18:13:22 +02:00
|
|
|
static constexpr alert_category_t debug_notification = 5_bit;
|
2017-07-26 06:33:10 +02:00
|
|
|
|
|
|
|
// Enables alerts for when a torrent or the session changes state.
|
2017-07-30 18:13:22 +02:00
|
|
|
static constexpr alert_category_t status_notification = 6_bit;
|
2017-07-26 06:33:10 +02:00
|
|
|
|
|
|
|
// Alerts for when blocks are requested and completed. Also when
|
|
|
|
// pieces are completed.
|
2017-07-30 18:13:22 +02:00
|
|
|
static constexpr alert_category_t progress_notification = 7_bit;
|
2017-07-26 06:33:10 +02:00
|
|
|
|
|
|
|
// Alerts when a peer is blocked by the ip blocker or port blocker.
|
2017-07-30 18:13:22 +02:00
|
|
|
static constexpr alert_category_t ip_block_notification = 8_bit;
|
2017-07-26 06:33:10 +02:00
|
|
|
|
|
|
|
// Alerts when some limit is reached that might limit the download
|
|
|
|
// or upload rate.
|
2017-07-30 18:13:22 +02:00
|
|
|
static constexpr alert_category_t performance_warning = 9_bit;
|
2017-07-26 06:33:10 +02:00
|
|
|
|
|
|
|
// Alerts on events in the DHT node. For incoming searches or
|
|
|
|
// bootstrapping being done etc.
|
2017-07-30 18:13:22 +02:00
|
|
|
static constexpr alert_category_t dht_notification = 10_bit;
|
2017-07-26 06:33:10 +02:00
|
|
|
|
|
|
|
// If you enable these alerts, you will receive a stats_alert
|
|
|
|
// approximately once every second, for every active torrent.
|
|
|
|
// These alerts contain all statistics counters for the interval since
|
|
|
|
// the lasts stats alert.
|
2017-07-30 18:13:22 +02:00
|
|
|
static constexpr alert_category_t stats_notification = 11_bit;
|
2013-08-08 04:57:07 +02:00
|
|
|
|
2015-04-04 21:24:26 +02:00
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
2017-07-26 06:33:10 +02:00
|
|
|
// Alerts on RSS related events, like feeds being updated, feed error
|
|
|
|
// conditions and successful RSS feed updates. Enabling this category
|
|
|
|
// will make you receive rss_alert alerts.
|
2017-07-30 18:13:22 +02:00
|
|
|
static constexpr alert_category_t TORRENT_DEPRECATED_MEMBER rss_notification = 12_bit;
|
2015-04-04 21:24:26 +02:00
|
|
|
#endif
|
2008-07-06 14:22:56 +02:00
|
|
|
|
2017-07-26 06:33:10 +02:00
|
|
|
// Enables debug logging alerts. These are available unless libtorrent
|
|
|
|
// was built with logging disabled (``TORRENT_DISABLE_LOGGING``). The
|
|
|
|
// alerts being posted are log_alert and are session wide.
|
2017-07-30 18:13:22 +02:00
|
|
|
static constexpr alert_category_t session_log_notification = 13_bit;
|
2014-12-09 10:08:26 +01:00
|
|
|
|
2017-07-26 06:33:10 +02:00
|
|
|
// Enables debug logging alerts for torrents. These are available
|
|
|
|
// unless libtorrent was built with logging disabled
|
|
|
|
// (``TORRENT_DISABLE_LOGGING``). The alerts being posted are
|
|
|
|
// torrent_log_alert and are torrent wide debug events.
|
2017-07-30 18:13:22 +02:00
|
|
|
static constexpr alert_category_t torrent_log_notification = 14_bit;
|
2014-12-09 10:08:26 +01:00
|
|
|
|
2017-07-26 06:33:10 +02:00
|
|
|
// Enables debug logging alerts for peers. These are available unless
|
|
|
|
// libtorrent was built with logging disabled
|
|
|
|
// (``TORRENT_DISABLE_LOGGING``). The alerts being posted are
|
|
|
|
// peer_log_alert and low-level peer events and messages.
|
2017-07-30 18:13:22 +02:00
|
|
|
static constexpr alert_category_t peer_log_notification = 15_bit;
|
2014-12-09 10:08:26 +01:00
|
|
|
|
2017-07-26 06:33:10 +02:00
|
|
|
// enables the incoming_request_alert.
|
2017-07-30 18:13:22 +02:00
|
|
|
static constexpr alert_category_t incoming_request_notification = 16_bit;
|
2015-05-09 05:04:08 +02:00
|
|
|
|
2017-07-26 06:33:10 +02:00
|
|
|
// enables dht_log_alert, debug logging for the DHT
|
2017-07-30 18:13:22 +02:00
|
|
|
static constexpr alert_category_t dht_log_notification = 17_bit;
|
2015-05-10 06:54:02 +02:00
|
|
|
|
2017-07-26 06:33:10 +02:00
|
|
|
// enable events from pure dht operations not related to torrents
|
2017-07-30 18:13:22 +02:00
|
|
|
static constexpr alert_category_t dht_operation_notification = 18_bit;
|
2015-06-30 03:02:16 +02:00
|
|
|
|
2017-07-26 06:33:10 +02:00
|
|
|
// enables port mapping log events. This log is useful
|
|
|
|
// for debugging the UPnP or NAT-PMP implementation
|
2017-07-30 18:13:22 +02:00
|
|
|
static constexpr alert_category_t port_mapping_log_notification = 19_bit;
|
2015-08-12 01:56:44 +02:00
|
|
|
|
2017-07-26 06:33:10 +02:00
|
|
|
// enables verbose logging from the piece picker.
|
2017-07-30 18:13:22 +02:00
|
|
|
static constexpr alert_category_t picker_log_notification = 20_bit;
|
2015-11-29 06:58:46 +01:00
|
|
|
|
2017-07-26 06:33:10 +02:00
|
|
|
// The full bitmask, representing all available categories.
|
|
|
|
//
|
|
|
|
// since the enum is signed, make sure this isn't
|
|
|
|
// interpreted as -1. For instance, boost.python
|
|
|
|
// does that and fails when assigning it to an
|
|
|
|
// unsigned parameter.
|
2017-07-30 18:13:22 +02:00
|
|
|
static constexpr alert_category_t all_categories = alert_category_t::all();
|
2008-07-06 14:22:56 +02:00
|
|
|
|
2013-09-01 19:34:05 +02:00
|
|
|
// hidden
|
2008-07-06 14:22:56 +02:00
|
|
|
alert();
|
2013-09-01 19:34:05 +02:00
|
|
|
// hidden
|
2004-01-23 01:39:05 +01:00
|
|
|
virtual ~alert();
|
2003-11-29 17:34:07 +01:00
|
|
|
|
2004-01-23 01:39:05 +01:00
|
|
|
// a timestamp is automatically created in the constructor
|
2015-03-12 05:34:54 +01:00
|
|
|
time_point timestamp() const;
|
2003-11-29 17:34:07 +01:00
|
|
|
|
2013-08-08 03:03:54 +02:00
|
|
|
// returns an integer that is unique to this alert type. It can be
|
|
|
|
// compared against a specific alert by querying a static constant called ``alert_type``
|
|
|
|
// in the alert. It can be used to determine the run-time type of an alert* in
|
|
|
|
// order to cast to that alert type and access specific members.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-09-03 08:52:45 +02:00
|
|
|
// e.g:
|
|
|
|
//
|
|
|
|
// .. code:: c++
|
2013-08-08 03:03:54 +02:00
|
|
|
//
|
2015-04-03 22:15:48 +02:00
|
|
|
// std::vector<alert*> alerts;
|
|
|
|
// ses.pop_alerts(&alerts);
|
|
|
|
// for (alert* i : alerts) {
|
|
|
|
// switch (a->type()) {
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2015-04-03 22:15:48 +02:00
|
|
|
// case read_piece_alert::alert_type:
|
|
|
|
// {
|
|
|
|
// read_piece_alert* p = (read_piece_alert*)a;
|
|
|
|
// if (p->ec) {
|
|
|
|
// // read_piece failed
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// // use p
|
2013-08-08 03:03:54 +02:00
|
|
|
// break;
|
|
|
|
// }
|
2015-04-03 22:15:48 +02:00
|
|
|
// case file_renamed_alert::alert_type:
|
|
|
|
// {
|
|
|
|
// // etc...
|
|
|
|
// }
|
2013-08-08 03:03:54 +02:00
|
|
|
// }
|
|
|
|
// }
|
2009-10-30 04:21:25 +01:00
|
|
|
virtual int type() const = 0;
|
2013-08-08 03:03:54 +02:00
|
|
|
|
|
|
|
// returns a string literal describing the type of the alert. It does
|
|
|
|
// not include any information that might be bundled with the alert.
|
2008-07-06 14:22:56 +02:00
|
|
|
virtual char const* what() const = 0;
|
2013-08-08 03:03:54 +02:00
|
|
|
|
|
|
|
// generate a string describing the alert and the information bundled
|
|
|
|
// with it. This is mainly intended for debug and development use. It is not suitable
|
|
|
|
// to use this for applications that may be localized. Instead, handle each alert
|
|
|
|
// type individually and extract and render the information from the alert depending
|
|
|
|
// on the locale.
|
2008-07-06 14:22:56 +02:00
|
|
|
virtual std::string message() const = 0;
|
2013-08-08 03:03:54 +02:00
|
|
|
|
|
|
|
// returns a bitmask specifying which categories this alert belong to.
|
2017-07-26 06:33:10 +02:00
|
|
|
virtual alert_category_t category() const = 0;
|
2013-08-08 03:03:54 +02:00
|
|
|
|
2015-04-03 22:15:48 +02:00
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
2015-08-20 01:33:20 +02:00
|
|
|
|
2017-03-18 01:41:47 +01:00
|
|
|
#include "libtorrent/aux_/disable_warnings_push.hpp"
|
2015-08-20 01:33:20 +02:00
|
|
|
|
2013-08-08 03:03:54 +02:00
|
|
|
// determines whether or not an alert is allowed to be discarded
|
2017-08-05 23:09:36 +02:00
|
|
|
// when the alert queue is full. There are a few alerts which may not be discarded,
|
2013-08-08 03:03:54 +02:00
|
|
|
// since they would break the user contract, such as save_resume_data_alert.
|
2015-04-17 03:49:49 +02:00
|
|
|
TORRENT_DEPRECATED
|
2015-05-18 03:30:32 +02:00
|
|
|
bool discardable() const { return discardable_impl(); }
|
2003-11-29 17:34:07 +01:00
|
|
|
|
2015-04-17 03:49:49 +02:00
|
|
|
TORRENT_DEPRECATED
|
2015-04-26 03:45:23 +02:00
|
|
|
severity_t severity() const { return warning; }
|
2003-11-29 17:34:07 +01:00
|
|
|
|
2015-05-18 03:30:32 +02:00
|
|
|
protected:
|
|
|
|
|
|
|
|
virtual bool discardable_impl() const { return true; }
|
|
|
|
|
2017-03-18 01:41:47 +01:00
|
|
|
#include "libtorrent/aux_/disable_warnings_pop.hpp"
|
2003-11-29 17:34:07 +01:00
|
|
|
|
2015-08-20 21:14:39 +02:00
|
|
|
#endif // TORRENT_NO_DEPRECATE
|
|
|
|
|
2003-11-29 17:34:07 +01:00
|
|
|
private:
|
2016-10-19 07:32:15 +02:00
|
|
|
time_point const m_timestamp;
|
2003-11-29 17:34:07 +01:00
|
|
|
};
|
|
|
|
|
2016-05-23 02:35:04 +02:00
|
|
|
// When you get an alert, you can use ``alert_cast<>`` to attempt to cast the
|
|
|
|
// pointer to a specific alert type, in order to query it for more
|
|
|
|
// information.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2016-05-23 02:35:04 +02:00
|
|
|
// .. note::
|
|
|
|
// ``alert_cast<>`` can only cast to an exact alert type, not a base class
|
2016-02-20 23:28:41 +01:00
|
|
|
template <class T> T* alert_cast(alert* a)
|
2009-11-02 04:34:16 +01:00
|
|
|
{
|
2016-07-03 21:07:20 +02:00
|
|
|
static_assert(std::is_base_of<alert, T>::value
|
|
|
|
, "alert_cast<> can only be used with alert types (deriving from libtorrent::alert)");
|
|
|
|
|
2016-05-13 14:19:44 +02:00
|
|
|
if (a == nullptr) return nullptr;
|
2009-11-02 04:34:16 +01:00
|
|
|
if (a->type() == T::alert_type) return static_cast<T*>(a);
|
2016-05-13 14:19:44 +02:00
|
|
|
return nullptr;
|
2009-11-02 04:34:16 +01:00
|
|
|
}
|
2016-02-20 23:28:41 +01:00
|
|
|
template <class T> T const* alert_cast(alert const* a)
|
2009-11-02 04:34:16 +01:00
|
|
|
{
|
2016-07-03 21:07:20 +02:00
|
|
|
static_assert(std::is_base_of<alert, T>::value
|
|
|
|
, "alert_cast<> can only be used with alert types (deriving from libtorrent::alert)");
|
2016-05-13 14:19:44 +02:00
|
|
|
if (a == nullptr) return nullptr;
|
2009-11-02 04:34:16 +01:00
|
|
|
if (a->type() == T::alert_type) return static_cast<T const*>(a);
|
2016-05-13 14:19:44 +02:00
|
|
|
return nullptr;
|
2009-11-02 04:34:16 +01:00
|
|
|
}
|
2009-10-30 04:21:25 +01:00
|
|
|
|
2003-11-29 17:34:07 +01:00
|
|
|
} // namespace libtorrent
|
|
|
|
|
2004-01-25 19:18:36 +01:00
|
|
|
#endif // TORRENT_ALERT_HPP_INCLUDED
|