Alerts

Author: Arvid Norberg, arvid@rasterbar.com
Version: 1.0.0

The pop_alert() function on session is the interface for retrieving alerts, warnings, messages and errors from libtorrent. If no alerts have been posted by libtorrent pop_alert() will return a default initialized std::auto_ptr object. If there is an alert in libtorrent's queue, the alert from the front of the queue is popped and returned. You can then use the alert object and query

By default, only errors are reported. set_alert_mask() can be used to specify which kinds of events should be reported. The alert mask is comprised by bits from the category_t enum.

Every alert belongs to one or more category. There is a small cost involved in posting alerts. Only alerts that belong to an enabled category are posted. Setting the alert bitmask to 0 will disable all alerts (except those that are non-discardable).

There are other alert base classes that some alerts derive from, all the alerts that are generated for a specific torrent are derived from torrent_alert, and tracker events derive from tracker_alert.

alert

Declared in "libtorrent/alert.hpp"

The alert class is the base class that specific messages are derived from.

class alert
{
   ptime timestamp () const;
   virtual int type () const = 0;
   virtual char const* what () const = 0;
   virtual std::string message () const = 0;
   virtual int category () const = 0;
   virtual bool discardable () const;
   virtual std::auto_ptr<alert> clone () const = 0;

   enum category_t
   {
      error_notification,
      peer_notification,
      port_mapping_notification,
      storage_notification,
      tracker_notification,
      debug_notification,
      status_notification,
      progress_notification,
      ip_block_notification,
      performance_warning,
      dht_notification,
      stats_notification,
      rss_notification,
      all_categories,
   };
};

timestamp()

ptime timestamp () const;

a timestamp is automatically created in the constructor

type()

virtual int type () const = 0;

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.

e.g:

std::auto_ptr<alert> a = ses.pop_alert();
switch (a->type())
{
        case read_piece_alert::alert_type:
        {
                read_piece_alert* p = (read_piece_alert*)a.get();
                if (p->ec) {
                        // read_piece failed
                        break;
                }
                // use p
                break;
        }
        case file_renamed_alert::alert_type:
        {
                // etc...
        }
}

what()

virtual char const* what () const = 0;

returns a string literal describing the type of the alert. It does not include any information that might be bundled with the alert.

message()

virtual std::string message () const = 0;

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.

category()

virtual int category () const = 0;

returns a bitmask specifying which categories this alert belong to.

discardable()

virtual bool discardable () const;

determines whether or not an alert is allowed to be discarded when the alert queue is full. There are a few alerts which may not be discared, since they would break the user contract, such as save_resume_data_alert.

clone()

virtual std::auto_ptr<alert> clone () const = 0;

returns a pointer to a copy of the alert.

enum category_t

Declared in "libtorrent/alert.hpp"

name value description
error_notification 1

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
peer_notification 2 Enables alerts when peers send invalid requests, get banned or snubbed.
port_mapping_notification 4 Enables alerts for port mapping events. For NAT-PMP and UPnP.
storage_notification 8 Enables alerts for events related to the storage. File errors and synchronization events for moving the storage, renaming files etc.
tracker_notification 16 Enables all tracker events. Includes announcing to trackers, receiving responses, warnings and errors.
debug_notification 32 Low level alerts for when peers are connected and disconnected.
status_notification 64 Enables alerts for when a torrent or the session changes state.
progress_notification 128 Alerts for when blocks are requested and completed. Also when pieces are completed.
ip_block_notification 256 Alerts when a peer is blocked by the ip blocker or port blocker.
performance_warning 512 Alerts when some limit is reached that might limit the download or upload rate.
dht_notification 1024 Alerts on events in the DHT node. For incoming searches or bootstrapping being done etc.
stats_notification 2048 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.
rss_notification 4096 Alerts on RSS related events, like feeds being updated, feed error conditions and successful RSS feed updates. Enabling this categoty will make you receive rss_alert alerts.
all_categories 2147483647

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.

torrent_alert

Declared in "libtorrent/alert_types.hpp"

This is a base class for alerts that are associated with a specific torrent. It contains a handle to the torrent.

struct torrent_alert: alert
{
   torrent_handle handle;
};
handle
The torrent_handle pointing to the torrent this alert is associated with.

peer_alert

Declared in "libtorrent/alert_types.hpp"

The peer alert is a base class for alerts that refer to a specific peer. It includes all the information to identify the peer. i.e. ip and peer-id.

struct peer_alert: torrent_alert
{
   virtual int category () const;
   virtual std::string message () const;

   const static int alert_type = 2;
   const static int static_category = alert::peer_notification;
   tcp::endpoint ip;
   peer_id pid;
};
ip
The peer's IP address and port.
pid
the peer ID, if known.

tracker_alert

Declared in "libtorrent/alert_types.hpp"

This is a base class used for alerts that are associated with a specific tracker. It derives from torrent_alert since a tracker is also associated with a specific torrent.

struct tracker_alert: torrent_alert
{
   virtual int category () const;
   virtual std::string message () const;

   const static int alert_type = 3;
   const static int static_category = alert::tracker_notification;
   std::string url;
};
url
The tracker URL

torrent_added_alert

Declared in "libtorrent/alert_types.hpp"

The torrent_added_alert is posted once every time a torrent is successfully added. It doesn't contain any members of its own, but inherits the torrent handle from its base class. It's posted when the status_notification bit is set in the alert_mask.

struct torrent_added_alert: torrent_alert
{
   virtual std::string message () const;

   const static int static_category = alert::status_notification;
};

torrent_removed_alert

Declared in "libtorrent/alert_types.hpp"

The torrent_removed_alert is posted whenever a torrent is removed. Since the torrent handle in its baseclass will always be invalid (since the torrent is already removed) it has the info hash as a member, to identify it. It's posted when the status_notification bit is set in the alert_mask.

Even though the handle member doesn't point to an existing torrent anymore, it is still useful for comparing to other handles, which may also no longer point to existing torrents, but to the same non-existing torrents.

The torrent_handle acts as a weak_ptr, even though its object no longer exists, it can still compare equal to another weak pointer which points to the same non-existent object.

struct torrent_removed_alert: torrent_alert
{
   virtual std::string message () const;

   const static int static_category = alert::status_notification;
   sha1_hash info_hash;
};

read_piece_alert

Declared in "libtorrent/alert_types.hpp"

This alert is posted when the asynchronous read operation initiated by a call to torrent_handle::read_piece() is completed. If the read failed, the torrent is paused and an error state is set and the buffer member of the alert is 0. If successful, buffer points to a buffer containing all the data of the piece. piece is the piece index that was read. size is the number of bytes that was read.

If the operation fails, ec will indicat what went wrong.

struct read_piece_alert: torrent_alert
{
   virtual bool discardable () const;
   virtual std::string message () const;

   const static int static_category = alert::storage_notification;
   error_code ec;
   boost::shared_array<char> buffer;
   int piece;
   int size;
};

file_completed_alert

Declared in "libtorrent/alert_types.hpp"

This is posted whenever an individual file completes its download. i.e. All pieces overlapping this file have passed their hash check.

struct file_completed_alert: torrent_alert
{
   virtual std::string message () const;

   const static int static_category = alert::progress_notification;
   int index;
};
index
refers to the index of the file that completed.

file_renamed_alert

Declared in "libtorrent/alert_types.hpp"

This is posted as a response to a torrent_handle::rename_file() call, if the rename operation succeeds.

struct file_renamed_alert: torrent_alert
{
   virtual bool discardable () const;
   virtual std::string message () const;

   const static int static_category = alert::storage_notification;
   std::string name;
   int index;
};
index
refers to the index of the file that was renamed, name is the new name of the file.

file_rename_failed_alert

Declared in "libtorrent/alert_types.hpp"

This is posted as a response to a torrent_handle::rename_file() call, if the rename operation failed.

struct file_rename_failed_alert: torrent_alert
{
   virtual bool discardable () const;
   virtual std::string message () const;

   const static int static_category = alert::storage_notification;
   int index;
   error_code error;
};
index error
refers to the index of the file that was supposed to be renamed, error is the error code returned from the filesystem.

performance_alert

Declared in "libtorrent/alert_types.hpp"

This alert is generated when a limit is reached that might have a negative impact on upload or download rate performance.

struct performance_alert: torrent_alert
{
   virtual std::string message () const;

   enum performance_warning_t
   {
      outstanding_disk_buffer_limit_reached,
      outstanding_request_limit_reached,
      upload_limit_too_low,
      download_limit_too_low,
      send_buffer_watermark_too_low,
      too_many_optimistic_unchoke_slots,
      too_high_disk_queue_limit,
      bittyrant_with_no_uplimit,
      too_few_outgoing_ports,
      too_few_file_descriptors,
      num_warnings,
   };

   const static int static_category = alert::performance_warning;
   performance_warning_t warning_code;
};

enum performance_warning_t

Declared in "libtorrent/alert_types.hpp"

name value description
outstanding_disk_buffer_limit_reached 0 This warning means that the number of bytes queued to be written to disk exceeds the max disk byte queue setting (session_settings::max_queued_disk_bytes). This might restrict the download rate, by not queuing up enough write jobs to the disk I/O thread. When this alert is posted, peer connections are temporarily stopped from downloading, until the queued disk bytes have fallen below the limit again. Unless your max_queued_disk_bytes setting is already high, you might want to increase it to get better performance.
outstanding_request_limit_reached 1 This is posted when libtorrent would like to send more requests to a peer, but it's limited by session_settings::max_out_request_queue. The queue length libtorrent is trying to achieve is determined by the download rate and the assumed round-trip-time (session_settings::request_queue_time). The assumed rount-trip-time is not limited to just the network RTT, but also the remote disk access time and message handling time. It defaults to 3 seconds. The target number of outstanding requests is set to fill the bandwidth-delay product (assumed RTT times download rate divided by number of bytes per request). When this alert is posted, there is a risk that the number of outstanding requests is too low and limits the download rate. You might want to increase the max_out_request_queue setting.
upload_limit_too_low 2 This warning is posted when the amount of TCP/IP overhead is greater than the upload rate limit. When this happens, the TCP/IP overhead is caused by a much faster download rate, triggering TCP ACK packets. These packets eat into the rate limit specified to libtorrent. When the overhead traffic is greater than the rate limit, libtorrent will not be able to send any actual payload, such as piece requests. This means the download rate will suffer, and new requests can be sent again. There will be an equilibrium where the download rate, on average, is about 20 times the upload rate limit. If you want to maximize the download rate, increase the upload rate limit above 5% of your download capacity.
download_limit_too_low 3 This is the same warning as upload_limit_too_low but referring to the download limit instead of upload. This suggests that your download rate limit is mcuh lower than your upload capacity. Your upload rate will suffer. To maximize upload rate, make sure your download rate limit is above 5% of your upload capacity.
send_buffer_watermark_too_low 4

We're stalled on the disk. We want to write to the socket, and we can write but our send buffer is empty, waiting to be refilled from the disk. This either means the disk is slower than the network connection or that our send buffer watermark is too small, because we can send it all before the disk gets back to us. The number of bytes that we keep outstanding, requested from the disk, is calculated as follows:

min(512, max(upload_rate * send_buffer_watermark_factor / 100, send_buffer_watermark))

If you receive this alert, you migth want to either increase your send_buffer_watermark or send_buffer_watermark_factor.

too_many_optimistic_unchoke_slots 5 If the half (or more) of all upload slots are set as optimistic unchoke slots, this warning is issued. You probably want more regular (rate based) unchoke slots.
too_high_disk_queue_limit 6 If the disk write queue ever grows larger than half of the cache size, this warning is posted. The disk write queue eats into the total disk cache and leaves very little left for the actual cache. This causes the disk cache to oscillate in evicting large portions of the cache before allowing peers to download any more, onto the disk write queue. Either lower max_queued_disk_bytes or increase cache_size.
bittyrant_with_no_uplimit 7  
too_few_outgoing_ports 8 This is generated if outgoing peer connections are failing because of address in use errors, indicating that session_settings::outgoing_ports is set and is too small of a range. Consider not using the outgoing_ports setting at all, or widen the range to include more ports.
too_few_file_descriptors 9  
num_warnings 10  

state_changed_alert

Declared in "libtorrent/alert_types.hpp"

Generated whenever a torrent changes its state.

struct state_changed_alert: torrent_alert
{
   virtual std::string message () const;

   const static int static_category = alert::status_notification;
   torrent_status::state_t state;
   torrent_status::state_t prev_state;
};
state
the new state of the torrent.
prev_state
the previous state.

tracker_error_alert

Declared in "libtorrent/alert_types.hpp"

This alert is generated on tracker time outs, premature disconnects, invalid response or a HTTP response other than "200 OK". From the alert you can get the handle to the torrent the tracker belongs to.

The times_in_row member says how many times in a row this tracker has failed. status_code is the code returned from the HTTP server. 401 means the tracker needs authentication, 404 means not found etc. If the tracker timed out, the code will be set to 0.

struct tracker_error_alert: tracker_alert
{
   virtual std::string message () const;

   const static int static_category = alert::tracker_notification | alert::error_notification;
   int times_in_row;
   int status_code;
   error_code error;
   std::string msg;
};

tracker_warning_alert

Declared in "libtorrent/alert_types.hpp"

This alert is triggered if the tracker reply contains a warning field. Usually this means that the tracker announce was successful, but the tracker has a message to the client.

struct tracker_warning_alert: tracker_alert
{
   virtual std::string message () const;

   const static int static_category = alert::tracker_notification | alert::error_notification;
   std::string msg;
};
msg
contains the warning message from the tracker.

scrape_reply_alert

Declared in "libtorrent/alert_types.hpp"

This alert is generated when a scrape request succeeds.

struct scrape_reply_alert: tracker_alert
{
   virtual std::string message () const;

   int incomplete;
   int complete;
};
incomplete complete
the data returned in the scrape response. These numbers may be -1 if the reponse was malformed.

scrape_failed_alert

Declared in "libtorrent/alert_types.hpp"

If a scrape request fails, this alert is generated. This might be due to the tracker timing out, refusing connection or returning an http response code indicating an error.

struct scrape_failed_alert: tracker_alert
{
   scrape_failed_alert (torrent_handle const& h
      , std::string const& u
      , std::string const& m);
   virtual std::string message () const;

   const static int static_category = alert::tracker_notification | alert::error_notification;
   std::string msg;
};
msg
contains a message describing the error.

tracker_reply_alert

Declared in "libtorrent/alert_types.hpp"

This alert is only for informational purpose. It is generated when a tracker announce succeeds. It is generated regardless what kind of tracker was used, be it UDP, HTTP or the DHT.

struct tracker_reply_alert: tracker_alert
{
   virtual std::string message () const;

   int num_peers;
};
num_peers
tells how many peers the tracker returned in this response. This is not expected to be more thant the num_want settings. These are not necessarily all new peers, some of them may already be connected.

dht_reply_alert

Declared in "libtorrent/alert_types.hpp"

This alert is generated each time the DHT receives peers from a node. num_peers is the number of peers we received in this packet. Typically these packets are received from multiple DHT nodes, and so the alerts are typically generated a few at a time.

struct dht_reply_alert: tracker_alert
{
   virtual std::string message () const;

   int num_peers;
};

tracker_announce_alert

Declared in "libtorrent/alert_types.hpp"

This alert is generated each time a tracker announce is sent (or attempted to be sent). There are no extra data members in this alert. The url can be found in the base class however.

struct tracker_announce_alert: tracker_alert
{
   virtual std::string message () const;

   int event;
};
event

specifies what event was sent to the tracker. It is defined as:

  1. None
  2. Completed
  3. Started
  4. Stopped

hash_failed_alert

Declared in "libtorrent/alert_types.hpp"

This alert is generated when a finished piece fails its hash check. You can get the handle to the torrent which got the failed piece and the index of the piece itself from the alert.

struct hash_failed_alert: torrent_alert
{
   virtual std::string message () const;

   const static int static_category = alert::status_notification;
   int piece_index;
};

peer_ban_alert

Declared in "libtorrent/alert_types.hpp"

This alert is generated when a peer is banned because it has sent too many corrupt pieces to us. ip is the endpoint to the peer that was banned.

struct peer_ban_alert: peer_alert
{
   virtual std::string message () const;
};

peer_unsnubbed_alert

Declared in "libtorrent/alert_types.hpp"

This alert is generated when a peer is unsnubbed. Essentially when it was snubbed for stalling sending data, and now it started sending data again.

struct peer_unsnubbed_alert: peer_alert
{
   virtual std::string message () const;
};

peer_snubbed_alert

Declared in "libtorrent/alert_types.hpp"

This alert is generated when a peer is snubbed, when it stops sending data when we request it.

struct peer_snubbed_alert: peer_alert
{
   virtual std::string message () const;
};

peer_error_alert

Declared in "libtorrent/alert_types.hpp"

This alert is generated when a peer sends invalid data over the peer-peer protocol. The peer will be disconnected, but you get its ip address from the alert, to identify it.

struct peer_error_alert: peer_alert
{
   virtual std::string message () const;

   const static int static_category = alert::peer_notification;
   error_code error;
};
error
tells you what error caused this alert.

peer_connect_alert

Declared in "libtorrent/alert_types.hpp"

This alert is posted every time an outgoing peer connect attempts succeeds.

struct peer_connect_alert: peer_alert
{
   virtual std::string message () const;;

   const static int static_category = alert::debug_notification;
   int socket_type;
};

peer_disconnected_alert

Declared in "libtorrent/alert_types.hpp"

This alert is generated when a peer is disconnected for any reason (other than the ones covered by peer_error_alert ).

struct peer_disconnected_alert: peer_alert
{
   virtual std::string message () const;

   const static int static_category = alert::debug_notification;
   error_code error;
};
error
tells you what error caused peer to disconnect.

invalid_request_alert

Declared in "libtorrent/alert_types.hpp"

This is a debug alert that is generated by an incoming invalid piece request. ip is the address of the peer and the request is the actual incoming request from the peer. See peer_request for more info.

struct invalid_request_alert: peer_alert
{
   virtual std::string message () const;

   peer_request request;
};

torrent_finished_alert

Declared in "libtorrent/alert_types.hpp"

This alert is generated when a torrent switches from being a downloader to a seed. It will only be generated once per torrent. It contains a torrent_handle to the torrent in question.

struct torrent_finished_alert: torrent_alert
{
   virtual std::string message () const;

   const static int static_category = alert::status_notification;
};

piece_finished_alert

Declared in "libtorrent/alert_types.hpp"

this alert is posted every time a piece completes downloading and passes the hash check. This alert derives from torrent_alert which contains the torrent_handle to the torrent the piece belongs to.

struct piece_finished_alert: torrent_alert
{
   virtual std::string message () const;

   const static int static_category = alert::progress_notification;
   int piece_index;
};
piece_index
the index of the piece that finished

request_dropped_alert

Declared in "libtorrent/alert_types.hpp"

This alert is generated when a peer rejects or ignores a piece request.

struct request_dropped_alert: peer_alert
{
   virtual std::string message () const;

   | alert::peer_notification;
   int block_index;
   int piece_index;
};

block_timeout_alert

Declared in "libtorrent/alert_types.hpp"

This alert is generated when a block request times out.

struct block_timeout_alert: peer_alert
{
   virtual std::string message () const;

   | alert::peer_notification;
   int block_index;
   int piece_index;
};

block_finished_alert

Declared in "libtorrent/alert_types.hpp"

This alert is generated when a block request receives a response.

struct block_finished_alert: peer_alert
{
   virtual std::string message () const;

   const static int static_category = alert::progress_notification;
   int block_index;
   int piece_index;
};

block_downloading_alert

Declared in "libtorrent/alert_types.hpp"

This alert is generated when a block request is sent to a peer.

struct block_downloading_alert: peer_alert
{
   virtual std::string message () const;

   const static int static_category = alert::progress_notification;
   char const* peer_speedmsg;
   int block_index;
   int piece_index;
};

unwanted_block_alert

Declared in "libtorrent/alert_types.hpp"

This alert is generated when a block is received that was not requested or whose request timed out.

struct unwanted_block_alert: peer_alert
{
   virtual std::string message () const;

   int block_index;
   int piece_index;
};

storage_moved_alert

Declared in "libtorrent/alert_types.hpp"

The storage_moved_alert is generated when all the disk IO has completed and the files have been moved, as an effect of a call to torrent_handle::move_storage. This is useful to synchronize with the actual disk. The path member is the new path of the storage.

struct storage_moved_alert: torrent_alert
{
   virtual std::string message () const;

   const static int static_category = alert::storage_notification;
   std::string path;
};

storage_moved_failed_alert

Declared in "libtorrent/alert_types.hpp"

The storage_moved_failed_alert is generated when an attempt to move the storage, via torrent_handle::move_storage(), fails.

struct storage_moved_failed_alert: torrent_alert
{
   virtual std::string message () const;

   const static int static_category = alert::storage_notification;
   error_code error;
};

torrent_deleted_alert

Declared in "libtorrent/alert_types.hpp"

This alert is generated when a request to delete the files of a torrent complete.

The info_hash is the info-hash of the torrent that was just deleted. Most of the time the torrent_handle in the torrent_alert will be invalid by the time this alert arrives, since the torrent is being deleted. The info_hash member is hence the main way of identifying which torrent just completed the delete.

This alert is posted in the storage_notification category, and that bit needs to be set in the alert_mask.

struct torrent_deleted_alert: torrent_alert
{
   virtual bool discardable () const;
   virtual std::string message () const;

   const static int static_category = alert::storage_notification;
   sha1_hash info_hash;
};

torrent_delete_failed_alert

Declared in "libtorrent/alert_types.hpp"

This alert is generated when a request to delete the files of a torrent fails. Just removing a torrent from the session cannot fail

struct torrent_delete_failed_alert: torrent_alert
{
   virtual bool discardable () const;
   virtual std::string message () const;

   | alert::error_notification;
   error_code error;
   sha1_hash info_hash;
};
error
tells you why it failed.
info_hash
the info hash of the torrent whose files failed to be deleted

save_resume_data_alert

Declared in "libtorrent/alert_types.hpp"

This alert is generated as a response to a torrent_handle::save_resume_data request. It is generated once the disk IO thread is done writing the state for this torrent.

struct save_resume_data_alert: torrent_alert
{
   virtual bool discardable () const;
   virtual std::string message () const;

   const static int static_category = alert::storage_notification;
   boost::shared_ptr<entry> resume_data;
};
resume_data
points to the resume data.

save_resume_data_failed_alert

Declared in "libtorrent/alert_types.hpp"

This alert is generated instead of save_resume_data_alert if there was an error generating the resume data. error describes what went wrong.

struct save_resume_data_failed_alert: torrent_alert
{
   virtual bool discardable () const;
   virtual std::string message () const;

   | alert::error_notification;
   error_code error;
};

torrent_paused_alert

Declared in "libtorrent/alert_types.hpp"

This alert is generated as a response to a torrent_handle::pause request. It is generated once all disk IO is complete and the files in the torrent have been closed. This is useful for synchronizing with the disk.

struct torrent_paused_alert: torrent_alert
{
   virtual std::string message () const;

   const static int static_category = alert::status_notification;
};

torrent_resumed_alert

Declared in "libtorrent/alert_types.hpp"

This alert is generated as a response to a torrent_handle::resume() request. It is generated when a torrent goes from a paused state to an active state.

struct torrent_resumed_alert: torrent_alert
{
   virtual std::string message () const;

   const static int static_category = alert::status_notification;
};

torrent_checked_alert

Declared in "libtorrent/alert_types.hpp"

This alert is posted when a torrent completes checking. i.e. when it transitions out of the checking files state into a state where it is ready to start downloading

struct torrent_checked_alert: torrent_alert
{
   virtual std::string message () const;

   const static int static_category = alert::status_notification;
};

url_seed_alert

Declared in "libtorrent/alert_types.hpp"

This alert is generated when a HTTP seed name lookup fails.

struct url_seed_alert: torrent_alert
{
   virtual std::string message () const;

   const static int static_category = alert::peer_notification | alert::error_notification;
   std::string url;
   std::string msg;
};
url
the HTTP seed that failed
msg
the error message, potentially from the server

file_error_alert

Declared in "libtorrent/alert_types.hpp"

If the storage fails to read or write files that it needs access to, this alert is generated and the torrent is paused.

struct file_error_alert: torrent_alert
{
   virtual std::string message () const;

   | alert::storage_notification;
   std::string file;
   error_code error;
};
file
the path to the file that was accessed when the error occurred.
error
the error code describing the error.

metadata_failed_alert

Declared in "libtorrent/alert_types.hpp"

This alert is generated when the metadata has been completely received and the info-hash failed to match it. i.e. the metadata that was received was corrupt. libtorrent will automatically retry to fetch it in this case. This is only relevant when running a torrent-less download, with the metadata extension provided by libtorrent.

struct metadata_failed_alert: torrent_alert
{
   virtual std::string message () const;

   const static int static_category = alert::error_notification;
   error_code error;
};
error
the error that occurred

metadata_received_alert

Declared in "libtorrent/alert_types.hpp"

This alert is generated when the metadata has been completely received and the torrent can start downloading. It is not generated on torrents that are started with metadata, but only those that needs to download it from peers (when utilizing the libtorrent extension).

There are no additional data members in this alert.

Typically, when receiving this alert, you would want to save the torrent file in order to load it back up again when the session is restarted. Here's an example snippet of code to do that:

torrent_handle h = alert->handle();
if (h.is_valid()) {
        boost::intrusive_ptr<torrent_info const> ti = h.torrent_file();
        create_torrent ct(*ti);
        entry te = ct.generate();
        std::vector<char> buffer;
        bencode(std::back_inserter(buffer), te);
        FILE* f = fopen((to_hex(ti->info_hash().to_string()) + ".torrent").c_str(), "wb+");
        if (f) {
                fwrite(&buffer[0], 1, buffer.size(), f);
                fclose(f);
        }
}
struct metadata_received_alert: torrent_alert
{
   virtual std::string message () const;

   const static int static_category = alert::status_notification;
};

udp_error_alert

Declared in "libtorrent/alert_types.hpp"

This alert is posted when there is an error on the UDP socket. The UDP socket is used for all uTP, DHT and UDP tracker traffic. It's global to the session.

struct udp_error_alert: alert
{
   virtual std::string message () const;

   const static int static_category = alert::error_notification;
   udp::endpoint endpoint;
   error_code error;
};
endpoint
the source address associated with the error (if any)
error
the error code describing the error

external_ip_alert

Declared in "libtorrent/alert_types.hpp"

Whenever libtorrent learns about the machines external IP, this alert is generated. The external IP address can be acquired from the tracker (if it supports that) or from peers that supports the extension protocol. The address can be accessed through the external_address member.

struct external_ip_alert: alert
{
   virtual std::string message () const;

   const static int static_category = alert::status_notification;
   address external_address;
};
external_address
the IP address that is believed to be our external IP

listen_failed_alert

Declared in "libtorrent/alert_types.hpp"

This alert is generated when none of the ports, given in the port range, to session can be opened for listening. The endpoint member is the interface and port that failed, error is the error code describing the failure.

libtorrent may sometimes try to listen on port 0, if all other ports failed. Port 0 asks the operating system to pick a port that's free). If that fails you may see a listen_failed_alert with port 0 even if you didn't ask to listen on it.

struct listen_failed_alert: alert
{
   virtual bool discardable () const;
   virtual std::string message () const;

   enum socket_type_t
   {
      tcp,
      tcp_ssl,
      udp,
      i2p,
      socks5,
   };

   enum op_t
   {
      parse_addr,
      open,
      bind,
      listen,
      get_peer_name,
      accept,
   };

   const static int static_category = alert::status_notification | alert::error_notification;
   tcp::endpoint endpoint;
   error_code error;
   int operation;
   socket_type_t sock_type;
};

enum socket_type_t

Declared in "libtorrent/alert_types.hpp"

name value description
tcp 0  
tcp_ssl 1  
udp 2  
i2p 3  
socks5 4  

enum op_t

Declared in "libtorrent/alert_types.hpp"

name value description
parse_addr 0  
open 1  
bind 2  
listen 3  
get_peer_name 4  
accept 5  
endpoint
the endpoint libtorrent attempted to listen on
error
the error the system returned
operation
the specific low level operation that failed. See op_t.
sock_type
the type of listen socket this alert refers to.

listen_succeeded_alert

Declared in "libtorrent/alert_types.hpp"

This alert is posted when the listen port succeeds to be opened on a particular interface. endpoint is the endpoint that successfully was opened for listening.

struct listen_succeeded_alert: alert
{
   virtual bool discardable () const;
   virtual std::string message () const;

   enum socket_type_t
   {
      tcp,
      tcp_ssl,
      udp,
   };

   const static int static_category = alert::status_notification;
   tcp::endpoint endpoint;
   socket_type_t sock_type;
};

enum socket_type_t

Declared in "libtorrent/alert_types.hpp"

name value description
tcp 0  
tcp_ssl 1  
udp 2  
endpoint
the endpoint libtorrent ended up listening on. The address refers to the local interface and the port is the listen port.
sock_type
the type of listen socket this alert refers to.

portmap_error_alert

Declared in "libtorrent/alert_types.hpp"

This alert is generated when a NAT router was successfully found but some part of the port mapping request failed. It contains a text message that may help the user figure out what is wrong. This alert is not generated in case it appears the client is not running on a NAT:ed network or if it appears there is no NAT router that can be remote controlled to add port mappings.

struct portmap_error_alert: alert
{
   virtual std::string message () const;

   | alert::error_notification;
   int mapping;
   int map_type;
   error_code error;
};
mapping
refers to the mapping index of the port map that failed, i.e. the index returned from add_mapping().
map_type
is 0 for NAT-PMP and 1 for UPnP.
error
tells you what failed.

portmap_alert

Declared in "libtorrent/alert_types.hpp"

This alert is generated when a NAT router was successfully found and a port was successfully mapped on it. On a NAT:ed network with a NAT-PMP capable router, this is typically generated once when mapping the TCP port and, if DHT is enabled, when the UDP port is mapped.

struct portmap_alert: alert
{
   virtual std::string message () const;

   const static int static_category = alert::port_mapping_notification;
   int mapping;
   int external_port;
   int map_type;
};
mapping
refers to the mapping index of the port map that failed, i.e. the index returned from add_mapping().
external_port
the external port allocated for the mapping.
map_type
0 for NAT-PMP and 1 for UPnP.

portmap_log_alert

Declared in "libtorrent/alert_types.hpp"

This alert is generated to log informational events related to either UPnP or NAT-PMP. They contain a log line and the type (0 = NAT-PMP and 1 = UPnP). Displaying these messages to an end user is only useful for debugging the UPnP or NAT-PMP implementation.

struct portmap_log_alert: alert
{
   virtual std::string message () const;

   const static int static_category = alert::port_mapping_notification;
   int map_type;
   std::string msg;
};

fastresume_rejected_alert

Declared in "libtorrent/alert_types.hpp"

This alert is generated when a fastresume file has been passed to add_torrent() but the files on disk did not match the fastresume file. The error_code explains the reason why the resume file was rejected.

struct fastresume_rejected_alert: torrent_alert
{
   virtual std::string message () const;

   | alert::error_notification;
   error_code error;
};

peer_blocked_alert

Declared in "libtorrent/alert_types.hpp"

This alert is posted when an incoming peer connection, or a peer that's about to be added to our peer list, is blocked for some reason. This could be any of:

  • the IP filter
  • i2p mixed mode restrictions (a normal peer is not allowed on an i2p swarm)
  • the port filter
  • the peer has a low port and no_connect_privileged_ports is enabled
  • the protocol of the peer is blocked (uTP/TCP blocking)
struct peer_blocked_alert: torrent_alert
{
   virtual std::string message () const;

   const static int static_category = alert::ip_block_notification;
   address ip;
};
ip
the address that was blocked.

dht_announce_alert

Declared in "libtorrent/alert_types.hpp"

This alert is generated when a DHT node announces to an info-hash on our DHT node. It belongs to the dht_notification category.

struct dht_announce_alert: alert
{
   virtual std::string message () const;

   const static int static_category = alert::dht_notification;
   address ip;
   int port;
   sha1_hash info_hash;
};

dht_get_peers_alert

Declared in "libtorrent/alert_types.hpp"

This alert is generated when a DHT node sends a get_peers message to our DHT node. It belongs to the dht_notification category.

struct dht_get_peers_alert: alert
{
   virtual std::string message () const;

   const static int static_category = alert::dht_notification;
   sha1_hash info_hash;
};

stats_alert

Declared in "libtorrent/alert_types.hpp"

This alert is posted approximately once every second, and it contains byte counters of most statistics that's tracked for torrents. Each active torrent posts these alerts regularly.

struct stats_alert: torrent_alert
{
   virtual std::string message () const;

   enum stats_channel
   {
      upload_payload,
      upload_protocol,
      download_payload,
      download_protocol,
      upload_ip_protocol,
      upload_dht_protocol,
      upload_tracker_protocol,
      download_ip_protocol,
      download_dht_protocol,
      download_tracker_protocol,
      num_channels,
   };

   const static int static_category = alert::stats_notification;
   int transferred[num_channels];
   int interval;
};

enum stats_channel

Declared in "libtorrent/alert_types.hpp"

name value description
upload_payload 0  
upload_protocol 1  
download_payload 2  
download_protocol 3  
upload_ip_protocol 4  
upload_dht_protocol 5  
upload_tracker_protocol 6  
download_ip_protocol 7  
download_dht_protocol 8  
download_tracker_protocol 9  
num_channels 10  
transferred[num_channels]
an array of samples. The enum describes what each sample is a measurement of. All of these are raw, and not smoothing is performed.
interval
the number of milliseconds during which these stats were collected. This is typically just above 1000, but if CPU is limited, it may be higher than that.

cache_flushed_alert

Declared in "libtorrent/alert_types.hpp"

This alert is posted when the disk cache has been flushed for a specific torrent as a result of a call to torrent_handle::flush_cache(). This alert belongs to the storage_notification category, which must be enabled to let this alert through. The alert is also posted when removing a torrent from the session, once the outstanding cache flush is complete and the torrent does no longer have any files open.

struct cache_flushed_alert: torrent_alert
{
   const static int static_category = alert::storage_notification;
};

anonymous_mode_alert

Declared in "libtorrent/alert_types.hpp"

This alert is posted when a bittorrent feature is blocked because of the anonymous mode. For instance, if the tracker proxy is not set up, no trackers will be used, because trackers can only be used through proxies when in anonymous mode.

struct anonymous_mode_alert: torrent_alert
{
   virtual std::string message () const;

   enum kind_t
   {
      tracker_not_anonymous,
   };

   const static int static_category = alert::error_notification;
   int kind;
   std::string str;
};

enum kind_t

Declared in "libtorrent/alert_types.hpp"

name value description
tracker_not_anonymous 0 means that there's no proxy set up for tracker communication and the tracker will not be contacted. The tracker which this failed for is specified in the str member.
kind str
specifies what error this is, see kind_t.

lsd_peer_alert

Declared in "libtorrent/alert_types.hpp"

This alert is generated when we receive a local service discovery message from a peer for a torrent we're currently participating in.

struct lsd_peer_alert: peer_alert
{
   virtual std::string message () const;

   const static int static_category = alert::peer_notification;
};

trackerid_alert

Declared in "libtorrent/alert_types.hpp"

This alert is posted whenever a tracker responds with a trackerid. The tracker ID is like a cookie. The libtorrent will store the tracker ID for this tracker and repeat it in subsequent announces.

struct trackerid_alert: tracker_alert
{
   virtual std::string message () const;

   const static int static_category = alert::status_notification;
   std::string trackerid;
};
trackerid
The tracker ID returned by the tracker

dht_bootstrap_alert

Declared in "libtorrent/alert_types.hpp"

This alert is posted when the initial DHT bootstrap is done.

struct dht_bootstrap_alert: alert
{
   virtual std::string message () const;

   const static int static_category = alert::dht_notification;
};

rss_alert

Declared in "libtorrent/alert_types.hpp"

This alert is posted on RSS feed events such as start of RSS feed updates, successful completed updates and errors during updates.

This alert is only posted if the rss_notifications category is enabled in the alert_mask.

struct rss_alert: alert
{
   virtual std::string message () const;

   enum state_t
   {
      state_updating,
      state_updated,
      state_error,
   };

   const static int static_category = alert::rss_notification;
   feed_handle handle;
   std::string url;
   int state;
   error_code error;
};

enum state_t

Declared in "libtorrent/alert_types.hpp"

name value description
state_updating 0 An update of this feed was just initiated, it will either succeed or fail soon.
state_updated 1 The feed just completed a successful update, there may be new items in it. If you're adding torrents manually, you may want to request the feed status of the feed and look through the items vector.
state_error 2 An error just occurred. See the error field for information on what went wrong.
handle
the handle to the feed which generated this alert.
url
a short cut to access the url of the feed, without having to call feed_handle::get_settings().
state
one of the values from rss_alert::state_t.
error
an error code used for when an error occurs on the feed.

torrent_error_alert

Declared in "libtorrent/alert_types.hpp"

This is posted whenever a torrent is transitioned into the error state.

struct torrent_error_alert: torrent_alert
{
   virtual std::string message () const;

   const static int static_category = alert::error_notification | alert::status_notification;
   error_code error;
};
error
specifies which error the torrent encountered.

torrent_need_cert_alert

Declared in "libtorrent/alert_types.hpp"

This is always posted for SSL torrents. This is a reminder to the client that the torrent won't work unless torrent_handle::set_ssl_certificate() is called with a valid certificate. Valid certificates MUST be signed by the SSL certificate in the .torrent file.

struct torrent_need_cert_alert: torrent_alert
{
   virtual bool discardable () const;
   virtual std::string message () const;

   const static int static_category = alert::status_notification;
   error_code error;
};

incoming_connection_alert

Declared in "libtorrent/alert_types.hpp"

The incoming connection alert is posted every time we successfully accept an incoming connection, through any mean. The most straigh-forward ways of accepting incoming connections are through the TCP listen socket and the UDP listen socket for uTP sockets. However, connections may also be accepted ofer a Socks5 or i2p listen socket, or via a torrent specific listen socket for SSL torrents.

struct incoming_connection_alert: alert
{
   virtual std::string message () const;

   const static int static_category = alert::peer_notification;
   int socket_type;
   tcp::endpoint ip;
};
socket_type

tells you what kind of socket the connection was accepted as:

  1. none (no socket instantiated)
  2. TCP
  3. Socks5
  4. HTTP
  5. uTP
  6. i2p
  7. SSL/TCP
  8. SSL/Socks5
  9. HTTPS (SSL/HTTP)
  10. SSL/uTP
ip
is the IP address and port the connection came from.

add_torrent_alert

Declared in "libtorrent/alert_types.hpp"

This alert is always posted when a torrent was attempted to be added and contains the return status of the add operation. The torrent handle of the new torrent can be found in the base class' handle member. If adding the torrent failed, error contains the error code.

struct add_torrent_alert : torrent_alert
{
   virtual bool discardable () const;
   virtual std::string message () const;

   const static int static_category = alert::status_notification;
   add_torrent_params params;
   error_code error;
};
params
a copy of the parameters used when adding the torrent, it can be used to identify which invocation to async_add_torrent() caused this alert.
error
set to the error, if one occurred while adding the torrent.

state_update_alert

Declared in "libtorrent/alert_types.hpp"

This alert is only posted when requested by the user, by calling session::post_torrent_updates() on the session. It contains the torrent status of all torrents that changed since last time this message was posted. Its category is status_notification, but it's not subject to filtering, since it's only manually posted anyway.

struct state_update_alert : alert
{
   virtual bool discardable () const;
   virtual std::string message () const;

   const static int static_category = alert::status_notification;
   std::vector<torrent_status> status;
};
status
contains the torrent status of all torrents that changed since last time this message was posted. Note that you can map a torrent status to a specific torrent via its handle member. The receiving end is suggested to have all torrents sorted by the torrent_handle or hashed by it, for efficient updates.

torrent_update_alert

Declared in "libtorrent/alert_types.hpp"

When a torrent changes its info-hash, this alert is posted. This only happens in very specific cases. For instance, when a torrent is downloaded from a URL, the true info hash is not known immediately. First the .torrent file must be downloaded and parsed.

Once this download completes, the torrent_update_alert is posted to notify the client of the info-hash changing.

struct torrent_update_alert : torrent_alert
{
   virtual bool discardable () const;
   virtual std::string message () const;

   const static int static_category = alert::status_notification;
   sha1_hash old_ih;
   sha1_hash new_ih;
};
old_ih new_ih
old_ih and new_ih are the previous and new info-hash for the torrent, respectively.

rss_item_alert

Declared in "libtorrent/alert_types.hpp"

This alert is posted every time a new RSS item (i.e. torrent) is received from an RSS feed.

It is only posted if the rss_notifications category is enabled in the alert_mask.

struct rss_item_alert : alert
{
   virtual std::string message () const;

   const static int static_category = alert::rss_notification;
   feed_handle handle;
   feed_item item;
};