diff --git a/docs/base.css b/docs/base.css new file mode 100644 index 000000000..3a4ca847e --- /dev/null +++ b/docs/base.css @@ -0,0 +1,136 @@ +/* Page template */ + +html>body { font-size: 13px; } +body { text-align: center; } + +#container { + text-align: left; + width: 700px; + margin: 0 auto; + position: relative; +} + +#headerNav { +} + +#headerNav ul { + margin: 2px; + list-style: none; + font-family: Tahoma; + text-align: right; + text-transform: uppercase; + line-height: 1em; +} + +#headerNav ul li { + display: inline; + border-left: solid 1px #ccc; + padding-left: 10px; + padding-right: 10px; + margin: 0; + font-size: 80%; +} + +#headerNav ul li.first { + border: 0; +} + +#headerNav ul li a { + border: none; + color: #666; +} + +#headerNav ul li a:hover { + background: #eee; +} + +#header { + height: 116px; + width: 695px; + background: url(../img/orange.png) #FDA72A no-repeat top left; +} + +#header h1 { + margin: 0; + padding: 0; + float: right; + width: 536px; + height: 116px; + background: url(../img/logo.png); +} + +#header h1 span, #header h2 { display: none; } + +#footer { + clear: both; + width: 695px; + height: 49px; + background: #D3D3D3 url(../img/footer.png) no-repeat left top; + text-align: center; + margin-bottom: 1em; +} + +#footer span { + line-height: 49px; + font-size: 88%; + text-align: center; + color: #777; + display: block; +} + +#main { + font-family: Verdana; + line-height: 1.25em; + text-align: left; + margin-top: 10px; +} + +/* Base elements */ + +* {margin: 0; padding: 0;} +body { font: 0.8125em Verdana, sans-serif;} + +h1, h2, h3 { + font: 1.5em Georgia "Times New Roman", serif; + letter-spacing: 1px; + padding-bottom: 0.5em; +} + +h1 { font-size: 180%; } +h2 { font-size: 130%; } +h3 { font-size: 100%; } + +p { + font-size: 92%; + line-height: 1.7em; +} + +a { + text-decoration: none; + color: #8D370A; + border-bottom: dotted 1px #8D370A; +} + +a:hover { + border-bottom: solid 1px #8D370A; + background: #eee; +} + +#librarySidebar { + float: left; + width: 150px; +} + +#libraryBody { + border-left: solid 1px #eee; + padding-left: 10px; + margin-left: 158px; + margin-right: 10px; +} + +ul, ol { line-height: 1.8em; } +ul { list-style: square; } +li { margin-left: 2.8em; font-size: 92%; } + +p, ul, ol, img {margin-bottom: 1em;} + diff --git a/docs/hacking.html b/docs/hacking.html new file mode 100644 index 000000000..6b5ac5943 --- /dev/null +++ b/docs/hacking.html @@ -0,0 +1,221 @@ + + + + + + +libtorrent hacking + + + + + + + + +
+
+
+ +
+ +
+

libtorrent hacking

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

This describe some of the internals of libtorrent. If you're looking for +something to contribute, please take a look at the todo list.

+
+

terminology

+

This section describes some of the terminology used throughout the +libtorrent source. Having a good understanding of some of these keywords +helps understanding what's going on.

+

A piece is a part of the data of a torrent that has a SHA-1 hash in +the .torrent file. Pieces are almost always a power of two in size, but not +necessarily. Each piece is plit up in blocks, which is a 16 kiB. A block +never spans two pieces. If a piece is smaller than 16 kiB or not divisible +by 16 kiB, there are blocks smaller than that.

+

16 kiB is a de-facto standard of the largest transfer unit in the bittorrent +protocol. Clients typically reject any request for larger pieces than this.

+

The piece picker is the part of a bittorrent client that is responsible for +the logic to determine which requests to send to peers. It doesn't actually +pick full pieces, but blocks (from pieces).

+

The file layout of a torrent is represented by file storage objects. This +class contains a list of all files in the torrent (in a well defined order), +the size of the pieces and implicitly the total size of the whole torrent and +number of pieces. The file storage determines the mapping from pieces +to files. This representation may be quite complex in order to keep it extremely +compact. This is useful to load very large torrents without exploding in memory +usage.

+

A torrent object represents all the state of swarm download. This includes +a piece picker, a list of peer connections, file storage (torrent file). One +important distiction is between a connected peer (peer_connection) and a peer +we just know about, and may have been connected to, and may connect to in the +future (policy::peer). The list of (not connected) peers may grow very large +if not limited (through tracker responses, DHT and peer exchange). This list +is typically limited to a few thousand peers.

+

The policy in libtorrent is somewhat poorly named. It was initially intended +to be a customization point where a client could define peer selection behavior +and unchoke logic. It didn't end up being though, and a more accurate name would +be peer_list. It really just maintains a potentially large list of known peers +for a swarm (not necessarily connected).

+
+
+

structure

+

This is the high level structure of libtorrent. Bold types are part of the public +interface:

+
++=========+  pimpl     +-------------------+
+| session | ---------> | aux::session_impl |
++=========+            +-------------------+
+                m_torrents[]  |  |
++================+            |  |
+| torrent_handle | ------+    |  |
++================+       |    |  |
+                         |    |  | m_connections[]
+                         |    |  |
+                         |    |  +---------------------+
+         m_picker        v    v                        |
+ +--------------+      +---------+---------+-- . .     |
+ | piece_picker | <--+-| torrent | torrent | to        |
+ +--------------+    | +---------+---------+-- . .     |
+      m_torrent_file |      | m_connections[]          |
+ +==============+    |      |                          |
+ | torrent_info | <--+      v                          v
+ +==============+    |     +-----------------+-----------------+-- . .
+            m_policy |     | peer_connection | peer_connection | pe
+ +--------+          |     +-----------------+-----------------+-- . .
+ | policy | <--------+      |             | m_socket
+ +--------+                 |             |
+   | m_peers[]              |             v
+   |                        |            +-----------------------+
+   |                        |            | socket_type (variant) |
+   v                        |            +-----------------------+
++--------------+            |
+| policy::peer |            |
++--------------+            |
+| policy::peer |            |
++--------------+ m_peer_info|
+| policy::peer | <----------+
++--------------+
+.              .
++ - - - - - - -+
+
+
+

session_impl

+

This is the session state object, containing all session global information, such as:

+
+
    +
  • the list of all torrents m_torrent.
  • +
  • the list of all peer connections m_connections.
  • +
  • the global rate limits m_settings.
  • +
  • the DHT state m_dht.
  • +
  • the port mapping state, m_upnp and m_natpmp.
  • +
+
+
+
+

session

+

This is the public interface to the session. It implements pimpl (pointer to implementation) +in order to hide the internal representation of the session_impl object from the user and +make binary compatibility simpler to maintain.

+
+
+

torrent_handle

+

This is the public interface to a torrent. It holds a weak reference to the internal +torrent object and manipulates it by sending messages to the network thread.

+
+
+

torrent

+
+
+

peer_connection

+
+
+

policy

+
+
+

piece_picker

+
+
+

torrent_info

+
+
+
+

threads

+

libtorrent starts 2 or 3 threads.

+
+
    +
  • The first thread is the main thread that will sit +idle in a kqueue() or epoll call most of the time. +This thread runs the main loop that will send and receive +data on all connections.
  • +
  • The second thread is the disk I/O thread. All disk read and write operations +are passed to this thread and messages are passed back to the main thread when +the operation completes. The disk thread also verifies the piece hashes.
  • +
  • The third and forth threads are spawned by asio on systems that don't support +non-blocking host name resolution to simulate non-blocking getaddrinfo().
  • +
+
+
+
+ +
+ + +
+ + diff --git a/docs/manual-ref.html b/docs/manual-ref.html new file mode 100644 index 000000000..da5e6f999 --- /dev/null +++ b/docs/manual-ref.html @@ -0,0 +1,959 @@ + + + + + + +libtorrent API Documentation + + + + + + + + +
+
+
+ +
+ +
+

libtorrent API Documentation

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

overview

+

The interface of libtorrent consists of a few classes. The main class is +the session, it contains the main loop that serves all torrents.

+

The basic usage is as follows:

+ +

Each class and function is described in this manual.

+

For a description on how to create torrent files, see create_torrent.

+
+
+

things to keep in mind

+

A common problem developers are facing is torrents stopping without explanation. +Here is a description on which conditions libtorrent will stop your torrents, +how to find out about it and what to do about it.

+

Make sure to keep track of the paused state, the error state and the upload +mode of your torrents. By default, torrents are auto-managed, which means +libtorrent will pause them, unpause them, scrape them and take them out +of upload-mode automatically.

+

Whenever a torrent encounters a fatal error, it will be stopped, and the +torrent_status::error will describe the error that caused it. If a torrent +is auto managed, it is scraped periodically and paused or resumed based on +the number of downloaders per seed. This will effectively seed torrents that +are in the greatest need of seeds.

+

If a torrent hits a disk write error, it will be put into upload mode. This +means it will not download anything, but only upload. The assumption is that +the write error is caused by a full disk or write permission errors. If the +torrent is auto-managed, it will periodically be taken out of the upload +mode, trying to write things to the disk again. This means torrent will recover +from certain disk errors if the problem is resolved. If the torrent is not +auto managed, you have to call set_upload_mode() to turn +downloading back on again.

+
+
+

network primitives

+

There are a few typedefs in the libtorrent namespace which pulls +in network types from the asio namespace. These are:

+
+typedef asio::ip::address address;
+typedef asio::ip::address_v4 address_v4;
+typedef asio::ip::address_v6 address_v6;
+using asio::ip::tcp;
+using asio::ip::udp;
+
+

These are declared in the <libtorrent/socket.hpp> header.

+

The using statements will give easy access to:

+
+tcp::endpoint
+udp::endpoint
+
+

Which are the endpoint types used in libtorrent. An endpoint is an address +with an associated port.

+

For documentation on these types, please refer to the asio documentation.

+
+
+

exceptions

+

Many functions in libtorrent have two versions, one that throws exceptions on +errors and one that takes an error_code reference which is filled with the +error code on errors.

+

There is one exception class that is used for errors in libtorrent, it is based +on boost.system's error_code class to carry the error code.

+

For more information, see libtorrent_exception and error_code_enum.

+
+

translating error codes

+

The error_code::message() function will typically return a localized error string, +for system errors. That is, errors that belong to the generic or system category.

+

Errors that belong to the libtorrent error category are not localized however, they +are only available in english. In order to translate libtorrent errors, compare the +error category of the error_code object against libtorrent::get_libtorrent_category(), +and if matches, you know the error code refers to the list above. You can provide +your own mapping from error code to string, which is localized. In this case, you +cannot rely on error_code::message() to generate your strings.

+

The numeric values of the errors are part of the API and will stay the same, although +new error codes may be appended at the end.

+

Here's a simple example of how to translate error codes:

+
+std::string error_code_to_string(boost::system::error_code const& ec)
+{
+        if (ec.category() != libtorrent::get_libtorrent_category())
+        {
+                return ec.message();
+        }
+        // the error is a libtorrent error
+
+        int code = ec.value();
+        static const char const* swedish[] =
+        {
+                "inget fel",
+                "en fil i torrenten kolliderar med en fil fran en annan torrent",
+                "hash check misslyckades",
+                "torrentfilen ar inte en dictionary",
+                "'info'-nyckeln saknas eller ar korrupt i torrentfilen",
+                "'info'-faltet ar inte en dictionary",
+                "'piece length' faltet saknas eller ar korrupt i torrentfilen",
+                "torrentfilen saknar namnfaltet",
+                "ogiltigt namn i torrentfilen (kan vara en attack)",
+                // ... more strings here
+        };
+
+        // use the default error string in case we don't have it
+        // in our translated list
+        if (code < 0 || code >= sizeof(swedish)/sizeof(swedish[0]))
+                return ec.message();
+
+        return swedish[code];
+}
+
+
+
+ +
+

queuing

+

libtorrent supports queuing. Which means it makes sure that a limited number of +torrents are being downloaded at any given time, and once a torrent is completely +downloaded, the next in line is started.

+

Torrents that are auto managed are subject to the queuing and the active torrents +limits. To make a torrent auto managed, set auto_managed to true when adding the +torrent (see async_add_torrent() and add_torrent()).

+

The limits of the number of downloading and seeding torrents are controlled via +active_downloads, active_seeds and active_limit in session_settings. +These limits takes non auto managed torrents into account as well. If there are +more non-auto managed torrents being downloaded than the active_downloads +setting, any auto managed torrents will be queued until torrents are removed so +that the number drops below the limit.

+

The default values are 8 active downloads and 5 active seeds.

+

At a regular interval, torrents are checked if there needs to be any re-ordering of +which torrents are active and which are queued. This interval can be controlled via +auto_manage_interval in session_settings. It defaults to every 30 seconds.

+

For queuing to work, resume data needs to be saved and restored for all torrents. +See save_resume_data().

+
+

downloading

+

Torrents that are currently being downloaded or incomplete (with bytes still to download) +are queued. The torrents in the front of the queue are started to be actively downloaded +and the rest are ordered with regards to their queue position. Any newly added torrent +is placed at the end of the queue. Once a torrent is removed or turns into a seed, its +queue position is -1 and all torrents that used to be after it in the queue, decreases their +position in order to fill the gap.

+

The queue positions are always in a sequence without any gaps.

+

Lower queue position means closer to the front of the queue, and will be started sooner than +torrents with higher queue positions.

+

To query a torrent for its position in the queue, or change its position, see: +queue_position(), queue_position_up(), queue_position_down(), queue_position_top() and queue_position_bottom().

+
+
+

seeding

+

Auto managed seeding torrents are rotated, so that all of them are allocated a fair +amount of seeding. Torrents with fewer completed seed cycles are prioritized for +seeding. A seed cycle is completed when a torrent meets either the share ratio limit +(uploaded bytes / downloaded bytes), the share time ratio (time seeding / time +downloaing) or seed time limit (time seeded).

+

The relevant settings to control these limits are share_ratio_limit, +seed_time_ratio_limit and seed_time_limit in session_settings.

+
+
+
+

fast resume

+

The fast resume mechanism is a way to remember which pieces are downloaded +and where they are put between sessions. You can generate fast resume data by +calling save_resume_data() on torrent_handle. You can +then save this data to disk and use it when resuming the torrent. libtorrent +will not check the piece hashes then, and rely on the information given in the +fast-resume data. The fast-resume data also contains information about which +blocks, in the unfinished pieces, were downloaded, so it will not have to +start from scratch on the partially downloaded pieces.

+

To use the fast-resume data you simply give it to async_add_torrent() and add_torrent(), and it +will skip the time consuming checks. It may have to do the checking anyway, if +the fast-resume data is corrupt or doesn't fit the storage for that torrent, +then it will not trust the fast-resume data and just do the checking.

+
+

file format

+

The file format is a bencoded dictionary containing the following fields:

+ ++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
file-formatstring: "libtorrent resume file"
file-versioninteger: 1
info-hashstring, the info hash of the torrent this data is saved for.
blocks per pieceinteger, the number of blocks per piece. Must be: piece_size +/ (16 * 1024). Clamped to be within the range [1, 256]. It +is the number of blocks per (normal sized) piece. Usually +each block is 16 * 1024 bytes in size. But if piece size is +greater than 4 megabytes, the block size will increase.
piecesA string with piece flags, one character per piece. +Bit 1 means we have that piece. +Bit 2 means we have verified that this piece is correct. +This only applies when the torrent is in seed_mode.
slots

list of integers. The list maps slots to piece indices. It +tells which piece is on which slot. If piece index is -2 it +means it is free, that there's no piece there. If it is -1, +means the slot isn't allocated on disk yet. The pieces have +to meet the following requirement:

+

If there's a slot at the position of the piece index, +the piece must be located in that slot.

+
total_uploadedinteger. The number of bytes that have been uploaded in +total for this torrent.
total_downloadedinteger. The number of bytes that have been downloaded in +total for this torrent.
active_timeinteger. The number of seconds this torrent has been active. +i.e. not paused.
seeding_timeinteger. The number of seconds this torrent has been active +and seeding.
num_seedsinteger. An estimate of the number of seeds on this torrent +when the resume data was saved. This is scrape data or based +on the peer list if scrape data is unavailable.
num_downloadersinteger. An estimate of the number of downloaders on this +torrent when the resume data was last saved. This is used as +an initial estimate until we acquire up-to-date scrape info.
upload_rate_limitinteger. In case this torrent has a per-torrent upload rate +limit, this is that limit. In bytes per second.
download_rate_limitinteger. The download rate limit for this torrent in case +one is set, in bytes per second.
max_connectionsinteger. The max number of peer connections this torrent +may have, if a limit is set.
max_uploadsinteger. The max number of unchoked peers this torrent may +have, if a limit is set.
seed_modeinteger. 1 if the torrent is in seed mode, 0 otherwise.
file_prioritylist of integers. One entry per file in the torrent. Each +entry is the priority of the file with the same index.
piece_prioritystring of bytes. Each byte is interpreted as an integer and +is the priority of that piece.
auto_managedinteger. 1 if the torrent is auto managed, otherwise 0.
sequential_downloadinteger. 1 if the torrent is in sequential download mode, +0 otherwise.
pausedinteger. 1 if the torrent is paused, 0 otherwise.
trackerslist of lists of strings. The top level list lists all +tracker tiers. Each second level list is one tier of +trackers.
mapped_fileslist of strings. If any file in the torrent has been +renamed, this entry contains a list of all the filenames. +In the same order as in the torrent file.
url-listlist of strings. List of url-seed URLs used by this torrent. +The urls are expected to be properly encoded and not contain +any illegal url characters.
httpseedslist of strings. List of httpseed URLs used by this torrent. +The urls are expected to be properly encoded and not contain +any illegal url characters.
merkle treestring. In case this torrent is a merkle torrent, this is a +string containing the entire merkle tree, all nodes, +including the root and all leaves. The tree is not +necessarily complete, but complete enough to be able to send +any piece that we have, indicated by the have bitmask.
peers

list of dictionaries. Each dictionary has the following +layout:

+ ++++ + + + + + + + + +
ipstring, the ip address of the peer. This is +not a binary representation of the ip +address, but the string representation. It +may be an IPv6 string or an IPv4 string.
portinteger, the listen port of the peer
+

These are the local peers we were connected to when this +fast-resume data was saved.

+
unfinished

list of dictionaries. Each dictionary represents an +piece, and has the following layout:

+ ++++ + + + + + + + + + + + +
pieceinteger, the index of the piece this entry +refers to.
bitmaskstring, a binary bitmask representing the +blocks that have been downloaded in this +piece.
adler32The adler32 checksum of the data in the +blocks specified by bitmask.
+
file sizeslist where each entry corresponds to a file in the file list +in the metadata. Each entry has a list of two values, the +first value is the size of the file in bytes, the second +is the time stamp when the last time someone wrote to it. +This information is used to compare with the files on disk. +All the files must match exactly this information in order +to consider the resume data as current. Otherwise a full +re-check is issued.
allocationThe allocation mode for the storage. Can be either full +or compact. If this is full, the file sizes and +timestamps are disregarded. Pieces are assumed not to have +moved around even if the files have been modified after the +last resume data checkpoint.
+
+
+
+

storage allocation

+

There are two modes in which storage (files on disk) are allocated in libtorrent.

+
    +
  1. The traditional full allocation mode, where the entire files are filled up with +zeros before anything is downloaded. libtorrent will look for sparse files support +in the filesystem that is used for storage, and use sparse files or file system +zero fill support if present. This means that on NTFS, full allocation mode will +only allocate storage for the downloaded pieces.
  2. +
  3. The sparse allocation, sparse files are used, and pieces are downloaded directly +to where they belong. This is the recommended (and default) mode.
  4. +
+

In previous versions of libtorrent, a 3rd mode was supported, compact allocation. +Support for this is deprecated and will be removed in future versions of libtorrent. +It's still described in here for completeness.

+

The allocation mode is selected when a torrent is started. It is passed as an +argument to session::add_torrent() or session::async_add_torrent().

+

The decision to use full allocation or compact allocation typically depends on whether +any files have priority 0 and if the filesystem supports sparse files.

+
+

sparse allocation

+

On filesystems that supports sparse files, this allocation mode will only use +as much space as has been downloaded.

+
+
    +
  • It does not require an allocation pass on startup.
  • +
  • It supports skipping files (setting prioirty to 0 to not download).
  • +
  • Fast resume data will remain valid even when file time stamps are out of date.
  • +
+
+
+
+

full allocation

+

When a torrent is started in full allocation mode, the disk-io thread +will make sure that the entire storage is allocated, and fill any gaps with zeros. +This will be skipped if the filesystem supports sparse files or automatic zero filling. +It will of course still check for existing pieces and fast resume data. The main +drawbacks of this mode are:

+
+
    +
  • It may take longer to start the torrent, since it will need to fill the files +with zeros on some systems. This delay is linearly dependent on the size of +the download.
  • +
  • The download may occupy unnecessary disk space between download sessions. In case +sparse files are not supported.
  • +
  • Disk caches usually perform extremely poorly with random access to large files +and may slow down a download considerably.
  • +
+
+

The benefits of this mode are:

+
+
    +
  • Downloaded pieces are written directly to their final place in the files and the +total number of disk operations will be fewer and may also play nicer to +filesystems' file allocation, and reduce fragmentation.
  • +
  • No risk of a download failing because of a full disk during download. Unless +sparse files are being used.
  • +
  • The fast resume data will be more likely to be usable, regardless of crashes or +out of date data, since pieces won't move around.
  • +
  • Can be used with prioritizing files to 0.
  • +
+
+
+
+

compact allocation

+
+

Note

+

Note that support for compact allocation is deprecated in libttorrent, and will +be removed in future versions.

+
+

The compact allocation will only allocate as much storage as it needs to keep the +pieces downloaded so far. This means that pieces will be moved around to be placed +at their final position in the files while downloading (to make sure the completed +download has all its pieces in the correct place). So, the main drawbacks are:

+
+
    +
  • More disk operations while downloading since pieces are moved around.
  • +
  • Potentially more fragmentation in the filesystem.
  • +
  • Cannot be used while having files with priority 0.
  • +
+
+

The benefits though, are:

+
+
    +
  • No startup delay, since the files don't need allocating.
  • +
  • The download will not use unnecessary disk space.
  • +
  • Disk caches perform much better than in full allocation and raises the download +speed limit imposed by the disk.
  • +
  • Works well on filesystems that don't support sparse files.
  • +
+
+

The algorithm that is used when allocating pieces and slots isn't very complicated. +For the interested, a description follows.

+

storing a piece:

+
    +
  1. let A be a newly downloaded piece, with index n.
  2. +
  3. let s be the number of slots allocated in the file we're +downloading to. (the number of pieces it has room for).
  4. +
  5. if n >= s then allocate a new slot and put the piece there.
  6. +
  7. if n < s then allocate a new slot, move the data at +slot n to the new slot and put A in slot n.
  8. +
+

allocating a new slot:

+
    +
  1. if there's an unassigned slot (a slot that doesn't +contain any piece), return that slot index.
  2. +
  3. append the new slot at the end of the file (or find an unused slot).
  4. +
  5. let i be the index of newly allocated slot
  6. +
  7. if we have downloaded piece index i already (to slot j) then
      +
    1. move the data at slot j to slot i.
    2. +
    3. return slot index j as the newly allocated free slot.
    4. +
    +
  8. +
  9. return i as the newly allocated slot.
  10. +
+
+
+
+

extensions

+

These extensions all operates within the extension protocol. The +name of the extension is the name used in the extension-list packets, +and the payload is the data in the extended message (not counting the +length-prefix, message-id nor extension-id).

+

Note that since this protocol relies on one of the reserved bits in the +handshake, it may be incompatible with future versions of the mainline +bittorrent client.

+

These are the extensions that are currently implemented.

+
+

metadata from peers

+

Extension name: "LT_metadata"

+

This extension is deprecated in favor of the more widely supported ut_metadata +extension, see BEP 9. +The point with this extension is that you don't have to distribute the +metadata (.torrent-file) separately. The metadata can be distributed +through the bittorrent swarm. The only thing you need to download such +a torrent is the tracker url and the info-hash of the torrent.

+

It works by assuming that the initial seeder has the metadata and that +the metadata will propagate through the network as more peers join.

+

There are three kinds of messages in the metadata extension. These packets +are put as payload to the extension message. The three packets are:

+
+
    +
  • request metadata
  • +
  • metadata
  • +
  • don't have metadata
  • +
+
+

request metadata:

+ +++++ + + + + + + + + + + + + + + + + + + + + +
sizenamedescription
uint8_tmsg_typeDetermines the kind of message this is +0 means 'request metadata'
uint8_tstartThe start of the metadata block that +is requested. It is given in 256:ths +of the total size of the metadata, +since the requesting client don't know +the size of the metadata.
uint8_tsizeThe size of the metadata block that is +requested. This is also given in +256:ths of the total size of the +metadata. The size is given as size-1. +That means that if this field is set +0, the request wants one 256:th of the +metadata.
+

metadata:

+ +++++ + + + + + + + + + + + + + + + + + + + + + + + + +
sizenamedescription
uint8_tmsg_type1 means 'metadata'
int32_ttotal_sizeThe total size of the metadata, given +in number of bytes.
int32_toffsetThe offset of where the metadata block +in this message belongs in the final +metadata. This is given in bytes.
uint8_t[]metadataThe actual metadata block. The size of +this part is given implicit by the +length prefix in the bittorrent +protocol packet.
+

Don't have metadata:

+ +++++ + + + + + + + + + + + + +
sizenamedescription
uint8_tmsg_type2 means 'I don't have metadata'. +This message is sent as a reply to a +metadata request if the the client +doesn't have any metadata.
+
+
+

dont_have

+

Extension name: "lt_dont_have"

+

The dont_have extension message is used to tell peers that the client no longer +has a specific piece. The extension message should be advertised in the m dictionary +as lt_dont_have. The message format mimics the regular HAVE bittorrent message.

+

Just like all extension messages, the first 2 bytes in the mssage itself are 20 (the +bittorrent extension message) and the message ID assigned to this extension in the m +dictionary in the handshake.

+ +++++ + + + + + + + + + + + + +
sizenamedescription
uint32_tpieceindex of the piece the peer no longer +has.
+

The length of this message (including the extension message prefix) is +6 bytes, i.e. one byte longer than the normal HAVE message, because +of the extension message wrapping.

+
+
+

HTTP seeding

+

There are two kinds of HTTP seeding. One with that assumes a smart +(and polite) client and one that assumes a smart server. These +are specified in BEP 19 and BEP 17 respectively.

+

libtorrent supports both. In the libtorrent source code and API, +BEP 19 urls are typically referred to as url seeds and BEP 17 +urls are typically referred to as HTTP seeds.

+

The libtorrent implementation of BEP 19 assumes that, if the URL ends with a slash +('/'), the filename should be appended to it in order to request pieces from +that file. The way this works is that if the torrent is a single-file torrent, +only that filename is appended. If the torrent is a multi-file torrent, the +torrent's name '/' the file name is appended. This is the same directory +structure that libtorrent will download torrents into.

+
+
+
+

piece picker

+

The piece picker in libtorrent has the following features:

+
    +
  • rarest first
  • +
  • sequential download
  • +
  • random pick
  • +
  • reverse order picking
  • +
  • parole mode
  • +
  • prioritize partial pieces
  • +
  • prefer whole pieces
  • +
  • piece affinity by speed category
  • +
  • piece priorities
  • +
+
+

internal representation

+

It is optimized by, at all times, keeping a list of pieces ordered +by rarity, randomly shuffled within each rarity class. This list +is organized as a single vector of contigous memory in RAM, for +optimal memory locality and to eliminate heap allocations and frees +when updating rarity of pieces.

+

Expensive events, like a peer joining or leaving, are evaluated +lazily, since it's cheaper to rebuild the whole list rather than +updating every single piece in it. This means as long as no blocks +are picked, peers joining and leaving is no more costly than a single +peer joining or leaving. Of course the special cases of peers that have +all or no pieces are optimized to not require rebuilding the list.

+
+
+

picker strategy

+

The normal mode of the picker is of course rarest first, meaning +pieces that few peers have are preferred to be downloaded over pieces +that more peers have. This is a fundamental algorithm that is the +basis of the performance of bittorrent. However, the user may set the +piece picker into sequential download mode. This mode simply picks +pieces sequentially, always preferring lower piece indices.

+

When a torrent starts out, picking the rarest pieces means increased +risk that pieces won't be completed early (since there are only a few +peers they can be downloaded from), leading to a delay of having any +piece to offer to other peers. This lack of pieces to trade, delays +the client from getting started into the normal tit-for-tat mode of +bittorrent, and will result in a long ramp-up time. The heuristic to +mitigate this problem is to, for the first few pieces, pick random pieces +rather than rare pieces. The threshold for when to leave this initial +picker mode is determined by session_settings::initial_picker_threshold.

+
+
+

reverse order

+

An orthogonal setting is reverse order, which is used for snubbed +peers. Snubbed peers are peers that appear very slow, and might have timed +out a piece request. The idea behind this is to make all snubbed peers +more likely to be able to do download blocks from the same piece, +concentrating slow peers on as few pieces as possible. The reverse order +means that the most common pieces are picked, instead of the rarest pieces +(or in the case of sequential download, the last pieces, intead of the first).

+
+
+

parole mode

+

Peers that have participated in a piece that failed the hash check, may be +put in parole mode. This means we prefer downloading a full piece from this +peer, in order to distinguish which peer is sending corrupt data. Whether to +do this is or not is controlled by session_settings::use_parole_mode.

+

In parole mode, the piece picker prefers picking one whole piece at a time for +a given peer, avoiding picking any blocks from a piece any other peer has +contributed to (since that would defeat the purpose of parole mode).

+
+
+

prioritize partial pieces

+

This setting determines if partially downloaded or requested pieces should always +be preferred over other pieces. The benefit of doing this is that the number of +partial pieces is minimized (and hence the turn-around time for downloading a block +until it can be uploaded to others is minimized). It also puts less stress on the +disk cache, since fewer partial pieces need to be kept in the cache. Whether or +not to enable this is controlled by session_settings::prioritize_partial_pieces.

+

The main benefit of not prioritizing partial pieces is that the rarest first +algorithm gets to have more influence on which pieces are picked. The picker is +more likely to truly pick the rarest piece, and hence improving the performance +of the swarm.

+

This setting is turned on automatically whenever the number of partial pieces +in the piece picker exceeds the number of peers we're connected to times 1.5. +This is in order to keep the waste of partial pieces to a minimum, but still +prefer rarest pieces.

+
+
+

prefer whole pieces

+

The prefer whole pieces setting makes the piece picker prefer picking entire +pieces at a time. This is used by web connections (both http seeding +standards), in order to be able to coalesce the small bittorrent requests +to larger HTTP requests. This significantly improves performance when +downloading over HTTP.

+

It is also used by peers that are downloading faster than a certain +threshold. The main advantage is that these peers will better utilize the +other peer's disk cache, by requesting all blocks in a single piece, from +the same peer.

+

This threshold is controlled by session_settings::whole_pieces_threshold.

+

TODO: piece affinity by speed category +TODO: piece priorities

+
+
+
+

SSL torrents

+

Torrents may have an SSL root (CA) certificate embedded in them. Such torrents +are called SSL torrents. An SSL torrent talks to all bittorrent peers over SSL. +The protocols are layered like this:

+
++-----------------------+
+| BitTorrent protocol   |
++-----------------------+
+| SSL                   |
++-----------+-----------+
+| TCP       | uTP       |
+|           +-----------+
+|           | UDP       |
++-----------+-----------+
+
+

During the SSL handshake, both peers need to authenticate by providing a certificate +that is signed by the CA certificate found in the .torrent file. These peer +certificates are expected to be privided to peers through some other means than +bittorrent. Typically by a peer generating a certificate request which is sent to +the publisher of the torrent, and the publisher returning a signed certificate.

+

In libtorrent, set_ssl_certificate() in torrent_handle is used to tell libtorrent where +to find the peer certificate and the private key for it. When an SSL torrent is loaded, +the torrent_need_cert_alert is posted to remind the user to provide a certificate.

+

A peer connecting to an SSL torrent MUST provide the SNI TLS extension (server name +indication). The server name is the hex encoded info-hash of the torrent to connect to. +This is required for the client accepting the connection to know which certificate to +present.

+

SSL connections are accepted on a separate socket from normal bittorrent connections. To +pick which port the SSL socket should bind to, set session_settings::ssl_listen to a +different port. It defaults to port 4433. This setting is only taken into account when the +normal listen socket is opened (i.e. just changing this setting won't necessarily close +and re-open the SSL socket). To not listen on an SSL socket at all, set ssl_listen to 0.

+

This feature is only available if libtorrent is build with openssl support (TORRENT_USE_OPENSSL) +and requires at least openSSL version 1.0, since it needs SNI support.

+

Peer certificates must have at least one SubjectAltName field of type dNSName. At least +one of the fields must exactly match the name of the torrent. This is a byte-by-byte comparison, +the UTF-8 encoding must be identical (i.e. there's no unicode normalization going on). This is +the recommended way of verifying certificates for HTTPS servers according to RFC 2818. Note +the difference that for torrents only dNSName fields are taken into account (not IP address fields). +The most specific (i.e. last) Common Name field is also taken into account if no SubjectAltName +did not match.

+

If any of these fields contain a single asterisk ("*"), the certificate is considered covering +any torrent, allowing it to be reused for any torrent.

+

The purpose of matching the torrent name with the fields in the peer certificate is to allow +a publisher to have a single root certificate for all torrents it distributes, and issue +separate peer certificates for each torrent. A peer receiving a certificate will not necessarily +be able to access all torrents published by this root certificate (only if it has a "star cert").

+
+

testing

+

To test incoming SSL connections to an SSL torrent, one can use the following openssl command:

+
+openssl s_client -cert <peer-certificate>.pem -key <peer-private-key>.pem -CAfile \
+   <torrent-cert>.pem -debug -connect 127.0.0.1:4433 -tls1 -servername <info-hash>
+
+

To create a root certificate, the Distinguished Name (DN) is not taken into account +by bittorrent peers. You still need to specify something, but from libtorrent's point of +view, it doesn't matter what it is. libtorrent only makes sure the peer certificates are +signed by the correct root certificate.

+

One way to create the certificates is to use the CA.sh script that comes with openssl, +like thisi (don't forget to enter a common Name for the certificate):

+
+CA.sh -newca
+CA.sh -newreq
+CA.sh -sign
+
+

The torrent certificate is located in ./demoCA/private/demoCA/cacert.pem, this is +the pem file to include in the .torrent file.

+

The peer's certificate is located in ./newcert.pem and the certificate's +private key in ./newkey.pem.

+
+
+
+ +
+ + +
+ + diff --git a/docs/manual.html b/docs/manual.html deleted file mode 100644 index 03c21cdbe..000000000 --- a/docs/manual.html +++ /dev/null @@ -1,8158 +0,0 @@ - - - - - - -libtorrent API Documentation - - - - - - - - -
-
-
- -
- -
-

libtorrent API Documentation

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

overview

-

The interface of libtorrent consists of a few classes. The main class is -the session, it contains the main loop that serves all torrents.

-

The basic usage is as follows:

- -

Each class and function is described in this manual.

-

For a description on how to create torrent files, see make_torrent.

-
-
-

things to keep in mind

-

A common problem developers are facing is torrents stopping without explanation. -Here is a description on which conditions libtorrent will stop your torrents, -how to find out about it and what to do about it.

-

Make sure to keep track of the paused state, the error state and the upload -mode of your torrents. By default, torrents are auto-managed, which means -libtorrent will pause them, unpause them, scrape them and take them out -of upload-mode automatically.

-

Whenever a torrent encounters a fatal error, it will be stopped, and the -torrent_status::error will describe the error that caused it. If a torrent -is auto managed, it is scraped periodically and paused or resumed based on -the number of downloaders per seed. This will effectively seed torrents that -are in the greatest need of seeds.

-

If a torrent hits a disk write error, it will be put into upload mode. This -means it will not download anything, but only upload. The assumption is that -the write error is caused by a full disk or write permission errors. If the -torrent is auto-managed, it will periodically be taken out of the upload -mode, trying to write things to the disk again. This means torrent will recover -from certain disk errors if the problem is resolved. If the torrent is not -auto managed, you have to call set_upload_mode() to turn -downloading back on again.

-
-
-

network primitives

-

There are a few typedefs in the libtorrent namespace which pulls -in network types from the asio namespace. These are:

-
-typedef asio::ip::address address;
-typedef asio::ip::address_v4 address_v4;
-typedef asio::ip::address_v6 address_v6;
-using asio::ip::tcp;
-using asio::ip::udp;
-
-

These are declared in the <libtorrent/socket.hpp> header.

-

The using statements will give easy access to:

-
-tcp::endpoint
-udp::endpoint
-
-

Which are the endpoint types used in libtorrent. An endpoint is an address -with an associated port.

-

For documentation on these types, please refer to the asio documentation.

-
-

is_listening() listen_port() listen_on()

-
-
-bool is_listening() const;
-unsigned short listen_port() const;
-
-enum {
-        listen_reuse_address = 1,
-        listen_no_system_port = 2
-};
-
-void listen_on(
-        std::pair<int, int> const& port_range
-        , error_code& ec
-        , char const* interface = 0
-        , int flags = 0);
-
-
-

is_listening() will tell you whether or not the session has successfully -opened a listening port. If it hasn't, this function will return false, and -then you can use listen_on() to make another attempt.

-

listen_port() returns the port we ended up listening on. Since you just pass -a port-range to the constructor and to listen_on(), to know which port it -ended up using, you have to ask the session using this function.

-

listen_on() will change the listen port and/or the listen interface. If the -session is already listening on a port, this socket will be closed and a new socket -will be opened with these new settings. The port range is the ports it will try -to listen on, if the first port fails, it will continue trying the next port within -the range and so on. The interface parameter can be left as 0, in that case the -os will decide which interface to listen on, otherwise it should be the ip-address -of the interface you want the listener socket bound to. listen_on() returns the -error code of the operation in ec. If this indicates success, the session is -listening on a port within the specified range. If it fails, it will also -generate an appropriate alert (listen_failed_alert).

-

If all ports in the specified range fails to be opened for listening, libtorrent will -try to use port 0 (which tells the operating system to pick a port that's free). If -that still fails you may see a listen_failed_alert with port 0 even if you didn't -ask to listen on it.

-

It is possible to prevent libtorrent from binding to port 0 by passing in the flag -session::no_system_port in the flags argument.

-

The interface parameter can also be a hostname that will resolve to the device you -want to listen on. If you don't specify an interface, libtorrent may attempt to -listen on multiple interfaces (typically 0.0.0.0 and ::). This means that if your -IPv6 interface doesn't work, you may still see a listen_failed_alert, even though -the IPv4 port succeeded.

-

The flags parameter can either be 0 or session::listen_reuse_address, which -will set the reuse address socket option on the listen socket(s). By default, the -listen socket does not use reuse address. If you're running a service that needs -to run on a specific port no matter if it's in use, set this flag.

-

If you're also starting the DHT, it is a good idea to do that after you've called -listen_on(), since the default listen port for the DHT is the same as the tcp -listen socket. If you start the DHT first, it will assume the tcp port is free and -open the udp socket on that port, then later, when listen_on() is called, it -may turn out that the tcp port is in use. That results in the DHT and the bittorrent -socket listening on different ports. If the DHT is active when listen_on is -called, the udp port will be rebound to the new port, if it was configured to use -the same port as the tcp socket, and if the listen_on call failed to bind to the -same port that the udp uses.

-

If you want the OS to pick a port for you, pass in 0 as both first and second.

-

The reason why it's a good idea to run the DHT and the bittorrent socket on the same -port is because that is an assumption that may be used to increase performance. One -way to accelerate the connecting of peers on windows may be to first ping all peers -with a DHT ping packet, and connect to those that responds first. On windows one -can only connect to a few peers at a time because of a built in limitation (in XP -Service pack 2).

-
-
-

add_feed()

-
-
-feed_handle add_feed(feed_settings const& feed);
-
-
-

This adds an RSS feed to the session. The feed will be refreshed -regularly and optionally add all torrents from the feed, as they -appear. The feed is defined by the feed_settings object:

-
-struct feed_settings
-{
-        feed_settings();
-
-std::string url;
-        bool auto_download;
-        bool auto_map_handles;
-        int default_ttl;
-        add_torrent_params add_args;
-};
-
-

By default auto_download is true, which means all torrents in -the feed will be downloaded. Set this to false in order to manually -add torrents to the session. You may react to the rss_alert when -a feed has been updated to poll it for the new items in the feed -when adding torrents manually. When torrents are added automatically, -an add_torrent_alert is posted which includes the torrent handle -as well as the error code if it failed to be added. You may also call -session::get_torrents() to get the handles to the new torrents.

-

Before adding the feed, you must set the url field to the -feed's url. It may point to an RSS or an atom feed.

-

auto_map_handles defaults to true and determines whether or -not to set the handle field in the feed_item, returned -as the feed status. If auto-download is enabled, this setting -is ignored. If auto-download is not set, setting this to false -will save one pass through all the feed items trying to find -corresponding torrents in the session.

-

The default_ttl is the default interval for refreshing a feed. -This may be overridden by the feed itself (by specifying the <ttl> -tag) and defaults to 30 minutes. The field specifies the number of -minutes between refreshes.

-

If torrents are added automatically, you may want to set the -add_args to appropriate values for download directory etc. -This object is used as a template for adding torrents from feeds, -but some torrent specific fields will be overridden by the -individual torrent being added. For more information on the -add_torrent_params, see `async_add_torrent() add_torrent()`_.

-

The returned feed_handle is a handle which is used to interact -with the feed, things like forcing a refresh or querying for -information about the items in the feed. For more information, -see feed_handle.

-
-
-

remove_feed()

-
-
-void remove_feed(feed_handle h);
-
-
-

Removes a feed from being watched by the session. When this -call returns, the feed handle is invalid and won't refer -to any feed.

-
-
-

get_feeds()

-
-
-void get_feeds(std::vector<feed_handle>& f) const;
-
-
-

Returns a list of all RSS feeds that are being watched by the session.

-
-
-

add_extension()

-
-
-void add_extension(boost::function<
-        boost::shared_ptr<torrent_plugin>(torrent*, void*)> ext);
-
-
-

This function adds an extension to this session. The argument is a function -object that is called with a torrent* and which should return a -boost::shared_ptr<torrent_plugin>. To write custom plugins, see -libtorrent plugins. For the typical bittorrent client all of these -extensions should be added. The main plugins implemented in libtorrent are:

-
-
metadata extension
-
Allows peers to download the metadata (.torren files) from the swarm -directly. Makes it possible to join a swarm with just a tracker and -info-hash.
-
-
-#include <libtorrent/extensions/metadata_transfer.hpp>
-ses.add_extension(&libtorrent::create_metadata_plugin);
-
-
-
uTorrent metadata
-
Same as metadata extension but compatible with uTorrent.
-
-
-#include <libtorrent/extensions/ut_metadata.hpp>
-ses.add_extension(&libtorrent::create_ut_metadata_plugin);
-
-
-
uTorrent peer exchange
-
Exchanges peers between clients.
-
-
-#include <libtorrent/extensions/ut_pex.hpp>
-ses.add_extension(&libtorrent::create_ut_pex_plugin);
-
-
-
smart ban plugin
-
A plugin that, with a small overhead, can ban peers -that sends bad data with very high accuracy. Should -eliminate most problems on poisoned torrents.
-
-
-#include <libtorrent/extensions/smart_ban.hpp>
-ses.add_extension(&libtorrent::create_smart_ban_plugin);
-
-
-
-

set_settings() set_pe_settings()

-
-
-void set_settings(session_settings const& settings);
-void set_pe_settings(pe_settings const& settings);
-
-
-

Sets the session settings and the packet encryption settings respectively. -See session_settings and pe_settings for more information on available -options.

-
-
-

set_proxy() proxy()

-
-
-void set_proxy(proxy_settings const& s);
-proxy_setting proxy() const;
-
-
-

These functions sets and queries the proxy settings to be used for the session.

-

For more information on what settings are available for proxies, see -proxy_settings.

-
-
-

set_i2p_proxy() i2p_proxy()

-
-
-void set_i2p_proxy(proxy_settings const&);
-proxy_settings const& i2p_proxy();
-
-
-

set_i2p_proxy sets the i2p proxy, and tries to open a persistant -connection to it. The only used fields in the proxy settings structs -are hostname and port.

-

i2p_proxy returns the current i2p proxy in use.

-
-
-

start_natpmp() stop_natpmp()

-
-
-natpmp* start_natpmp();
-void stop_natpmp();
-
-
-

Starts and stops the NAT-PMP service. When started, the listen port and the DHT -port are attempted to be forwarded on the router through NAT-PMP.

-

The natpmp object returned by start_natpmp() can be used to add and remove -arbitrary port mappings. Mapping status is returned through the -portmap_alert and the portmap_error_alert. The object will be valid until -stop_natpmp() is called. See UPnP and NAT-PMP.

-

It is off by default.

-
-
-
-

entry

-

The entry class represents one node in a bencoded hierarchy. It works as a -variant type, it can be either a list, a dictionary (std::map), an integer -or a string. This is its synopsis:

-
-class entry
-{
-public:
-
-        typedef std::map<std::string, entry> dictionary_type;
-        typedef std::string string_type;
-        typedef std::list<entry> list_type;
-        typedef size_type integer_type;
-
-        enum data_type
-        {
-                int_t,
-                string_t,
-                list_t,
-                dictionary_t,
-                undefined_t
-        };
-
-        data_type type() const;
-
-        entry(dictionary_type const&);
-        entry(string_type const&);
-        entry(list_type const&);
-        entry(integer_type const&);
-
-        entry();
-        entry(data_type t);
-        entry(entry const& e);
-        ~entry();
-
-        void operator=(entry const& e);
-        void operator=(dictionary_type const&);
-        void operator=(string_type const&);
-        void operator=(list_type const&);
-        void operator=(integer_type const&);
-
-        integer_type& integer();
-        integer_type const& integer() const;
-        string_type& string();
-        string_type const& string() const;
-        list_type& list();
-        list_type const& list() const;
-        dictionary_type& dict();
-        dictionary_type const& dict() const;
-
-        // these functions requires that the entry
-        // is a dictionary, otherwise they will throw
-        entry& operator[](char const* key);
-        entry& operator[](std::string const& key);
-        entry const& operator[](char const* key) const;
-        entry const& operator[](std::string const& key) const;
-        entry* find_key(char const* key);
-        entry const* find_key(char const* key) const;
-
-        void print(std::ostream& os, int indent = 0) const;
-};
-
-

TODO: finish documentation of entry.

-
-

integer() string() list() dict() type()

-
-
-integer_type& integer();
-integer_type const& integer() const;
-string_type& string();
-string_type const& string() const;
-list_type& list();
-list_type const& list() const;
-dictionary_type& dict();
-dictionary_type const& dict() const;
-
-
-

The integer(), string(), list() and dict() functions -are accessors that return the respective type. If the entry object isn't of the -type you request, the accessor will throw libtorrent_exception (which derives from -std::runtime_error). You can ask an entry for its type through the -type() function.

-

The print() function is there for debug purposes only.

-

If you want to create an entry you give it the type you want it to have in its -constructor, and then use one of the non-const accessors to get a reference which you then -can assign the value you want it to have.

-

The typical code to get info from a torrent file will then look like this:

-
-entry torrent_file;
-// ...
-
-// throws if this is not a dictionary
-entry::dictionary_type const& dict = torrent_file.dict();
-entry::dictionary_type::const_iterator i;
-i = dict.find("announce");
-if (i != dict.end())
-{
-        std::string tracker_url = i->second.string();
-        std::cout << tracker_url << "\n";
-}
-
-

The following code is equivalent, but a little bit shorter:

-
-entry torrent_file;
-// ...
-
-// throws if this is not a dictionary
-if (entry* i = torrent_file.find_key("announce"))
-{
-        std::string tracker_url = i->string();
-        std::cout << tracker_url << "\n";
-}
-
-

To make it easier to extract information from a torrent file, the class torrent_info -exists.

-
-
-

operator[]

-
-
-entry& operator[](char const* key);
-entry& operator[](std::string const& key);
-entry const& operator[](char const* key) const;
-entry const& operator[](std::string const& key) const;
-
-
-

All of these functions requires the entry to be a dictionary, if it isn't they -will throw libtorrent::type_error.

-

The non-const versions of the operator[] will return a reference to either -the existing element at the given key or, if there is no element with the -given key, a reference to a newly inserted element at that key.

-

The const version of operator[] will only return a reference to an -existing element at the given key. If the key is not found, it will throw -libtorrent::type_error.

-
-
-

find_key()

-
-
-entry* find_key(char const* key);
-entry const* find_key(char const* key) const;
-
-
-

These functions requires the entry to be a dictionary, if it isn't they -will throw libtorrent::type_error.

-

They will look for an element at the given key in the dictionary, if the -element cannot be found, they will return 0. If an element with the given -key is found, the return a pointer to it.

-
-
-
-

torrent_info

-

In previous versions of libtorrent, this class was also used for creating -torrent files. This functionality has been moved to create_torrent, see -make_torrent.

-

The torrent_info has the following synopsis:

-
-class torrent_info
-{
-public:
-
-        // these constructors throws exceptions on error
-        torrent_info(sha1_hash const& info_hash, int flags = 0);
-        torrent_info(lazy_entry const& torrent_file, int flags = 0);
-        torrent_info(char const* buffer, int size, int flags = 0);
-        torrent_info(std::string const& filename, int flags = 0);
-        torrent_info(std::wstring const& filename, int flags = 0);
-
-        // these constructors sets the error code on error
-        torrent_info(sha1_hash const& info_hash, error_code& ec, int flags = 0);
-        torrent_info(lazy_entry const& torrent_file, error_code& ec, int flags = 0);
-        torrent_info(char const* buffer, int size, error_code& ec, int flags = 0);
-        torrent_info(fs::path const& filename, error_code& ec, int flags = 0);
-        torrent_info(fs::wpath const& filename, error_code& ec, int flags = 0);
-
-        void add_tracker(std::string const& url, int tier = 0);
-        std::vector<announce_entry> const& trackers() const;
-
-        file_storage const& files() const;
-        file_storage const& orig_files() const;
-
-        void remap_files(file_storage const& f);
-
-        void rename_file(int index, std::string const& new_filename);
-        void rename_file(int index, std::wstring const& new_filename);
-
-        typedef file_storage::iterator file_iterator;
-        typedef file_storage::reverse_iterator reverse_file_iterator;
-
-        file_iterator begin_files() const;
-        file_iterator end_files() const;
-        reverse_file_iterator rbegin_files() const;
-        reverse_file_iterator rend_files() const;
-
-        int num_files() const;
-        file_entry const& file_at(int index) const;
-
-        std::vector<file_slice> map_block(int piece, size_type offset
-                , int size) const;
-        peer_request map_file(int file_index, size_type file_offset
-                , int size) const;
-
-        bool priv() const;
-
-        void add_url_seed(std::string const& url);
-        void add_http_seed(std::string const& url);
-        std::vector<web_seed_entry> const& web_seeds() const;
-
-        size_type total_size() const;
-        int piece_length() const;
-        int num_pieces() const;
-        sha1_hash const& info_hash() const;
-        std::string const& name() const;
-        std::string const& comment() const;
-        std::string const& creator() const;
-
-        std::vector<std::pair<std::string, int> > const& nodes() const;
-        void add_node(std::pair<std::string, int> const& node);
-
-        boost::optional<time_t> creation_date() const;
-
-        int piece_size(unsigned int index) const;
-        sha1_hash const& hash_for_piece(unsigned int index) const;
-        char const* hash_for_piece_ptr(unsigned int index) const;
-
-        std::vector<sha1_hash> const& merkle_tree() const;
-        void set_merkle_tree(std::vector<sha1_hash>& h);
-
-        boost::shared_array<char> metadata() const;
-        int metadata_size() const;
-};
-
-
-

torrent_info()

-
-
-torrent_info(sha1_hash const& info_hash, int flags = 0);
-torrent_info(lazy_entry const& torrent_file, int flags = 0);
-torrent_info(char const* buffer, int size, int flags = 0);
-torrent_info(std::string const& filename, int flags = 0);
-torrent_info(std::wstring const& filename, int flags = 0);
-
-torrent_info(sha1_hash const& info_hash, error_code& ec, int flags = 0);
-torrent_info(lazy_entry const& torrent_file, error_code& ec, int flags = 0);
-torrent_info(char const* buffer, int size, error_code& ec, int flags = 0);
-torrent_info(fs::path const& filename, error_code& ec, int flags = 0);
-torrent_info(fs::wpath const& filename, error_code& ec, int flags = 0);
-
-
-

The constructor that takes an info-hash will initialize the info-hash to the given value, -but leave all other fields empty. This is used internally when downloading torrents without -the metadata. The metadata will be created by libtorrent as soon as it has been downloaded -from the swarm.

-

The constructor that takes a lazy_entry will create a torrent_info object from the -information found in the given torrent_file. The lazy_entry represents a tree node in -an bencoded file. To load an ordinary .torrent file -into a lazy_entry, use lazy_bdecode().

-

The version that takes a buffer pointer and a size will decode it as a .torrent file and -initialize the torrent_info object for you.

-

The version that takes a filename will simply load the torrent file and decode it inside -the constructor, for convenience. This might not be the most suitable for applications that -want to be able to report detailed errors on what might go wrong.

-

The overloads that takes an error_code const& never throws if an error occur, they -will simply set the error code to describe what went wrong and not fully initialize the -torrent_info object. The overloads that do not take the extra error_code parameter will -always throw if an error occurs. These overloads are not available when building without -exception support.

-

The flags argument is currently unused.

-
-
-

add_tracker()

-
-
-void add_tracker(std::string const& url, int tier = 0);
-
-
-

add_tracker() adds a tracker to the announce-list. The tier determines the order in -which the trackers are to be tried. For more information see trackers().

-
-
-

files() orig_files()

-
-
-file_storage const& files() const;
-file_storage const& orig_files() const;
-
-
-

The file_storage object contains the information on how to map the pieces to -files. It is separated from the torrent_info object because when creating torrents -a storage object needs to be created without having a torrent file. When renaming files -in a storage, the storage needs to make its own copy of the file_storage in order -to make its mapping differ from the one in the torrent file.

-

orig_files() returns the original (unmodified) file storage for this torrent. This -is used by the web server connection, which needs to request files with the original -names. Filename may be chaged using torrent_info::rename_file().

-

For more information on the file_storage object, see the separate document on how -to create torrents.

-
-
-

remap_files()

-
-
-void remap_files(file_storage const& f);
-
-
-

Remaps the file storage to a new file layout. This can be used to, for instance, -download all data in a torrent to a single file, or to a number of fixed size -sector aligned files, regardless of the number and sizes of the files in the torrent.

-

The new specified file_storage must have the exact same size as the current one.

-
-
-

rename_file()

-
-
-void rename_file(int index, std::string const& new_filename);
-void rename_file(int index, std::wstring const& new_filename);
-
-
-

Renames a the file with the specified index to the new name. The new filename is -reflected by the file_storage returned by files() but not by the one -returned by orig_files().

-

If you want to rename the base name of the torrent (for a multifile torrent), you -can copy the file_storage (see files() orig_files()), change the name, and -then use remap_files().

-

The new_filename can both be a relative path, in which case the file name -is relative to the save_path of the torrent. If the new_filename is -an absolute path (i.e. is_complete(new_filename) == true), then the file -is detached from the save_path of the torrent. In this case the file is -not moved when move_storage_ is invoked.

-
-
-

begin_files() end_files() rbegin_files() rend_files()

-
-
-file_iterator begin_files() const;
-file_iterator end_files() const;
-reverse_file_iterator rbegin_files() const;
-reverse_file_iterator rend_files() const;
-
-
-

This class will need some explanation. First of all, to get a list of all files -in the torrent, you can use begin_files(), end_files(), -rbegin_files() and rend_files(). These will give you standard vector -iterators with the type internal_file_entry, which is an internal type.

-

You can resolve it into the public representation of a file (file_entry) -using the file_storage::at function, which takes an index and an iterator;

-
-struct file_entry
-{
-        std::string path;
-        size_type offset;
-        size_type size;
-        size_type file_base;
-        time_t mtime;
-        sha1_hash filehash;
-        bool pad_file:1;
-        bool hidden_attribute:1;
-        bool executable_attribute:1;
-        bool symlink_attribute:1;
-};
-
-

The path is the full path of this file. The paths are unicode strings -encoded in UTF-8.

-

size is the size of the file (in bytes) and offset is the byte offset -of the file within the torrent. i.e. the sum of all the sizes of the files -before it in the list.

-

file_base is the offset in the file where the storage should start. The normal -case is to have this set to 0, so that the storage starts saving data at the start -if the file. In cases where multiple files are mapped into the same file though, -the file_base should be set to an offset so that the different regions do -not overlap. This is used when mapping "unselected" files into a so-called part -file.

-

mtime is the modification time of this file specified in posix time.

-

symlink_path is the path which this is a symlink to, or empty if this is -not a symlink. This field is only used if the symlink_attribute is set.

-

filehash is a sha-1 hash of the content of the file, or zeroes, if no -file hash was present in the torrent file. It can be used to potentially -find alternative sources for the file.

-

pad_file is set to true for files that are not part of the data of the torrent. -They are just there to make sure the next file is aligned to a particular byte offset -or piece boundry. These files should typically be hidden from an end user. They are -not written to disk.

-

hidden_attribute is true if the file was marked as hidden (on windows).

-

executable_attribute is true if the file was marked as executable (posix)

-

symlink_attribute is true if the file was a symlink. If this is the case -the symlink_index refers to a string which specifies the original location -where the data for this file was found.

-
-
-

num_files() file_at()

-
-
-int num_files() const;
-file_entry const& file_at(int index) const;
-
-
-

If you need index-access to files you can use the num_files() and file_at() -to access files using indices.

-
-
-

map_block()

-
-
-std::vector<file_slice> map_block(int piece, size_type offset
-        , int size) const;
-
-
-

This function will map a piece index, a byte offset within that piece and -a size (in bytes) into the corresponding files with offsets where that data -for that piece is supposed to be stored.

-

The file slice struct looks like this:

-
-struct file_slice
-{
-        int file_index;
-        size_type offset;
-        size_type size;
-};
-
-

The file_index refers to the index of the file (in the torrent_info). -To get the path and filename, use file_at() and give the file_index -as argument. The offset is the byte offset in the file where the range -starts, and size is the number of bytes this range is. The size + offset -will never be greater than the file size.

-
-
-

map_file()

-
-
-peer_request map_file(int file_index, size_type file_offset
-        , int size) const;
-
-
-

This function will map a range in a specific file into a range in the torrent. -The file_offset parameter is the offset in the file, given in bytes, where -0 is the start of the file. -The peer_request structure looks like this:

-
-struct peer_request
-{
-        int piece;
-        int start;
-        int length;
-        bool operator==(peer_request const& r) const;
-};
-
-

piece is the index of the piece in which the range starts. -start is the offset within that piece where the range starts. -length is the size of the range, in bytes.

-

The input range is assumed to be valid within the torrent. file_offset -+ size is not allowed to be greater than the file size. file_index -must refer to a valid file, i.e. it cannot be >= num_files().

-
-
-

add_url_seed() add_http_seed()

-
-
-void add_url_seed(std::string const& url
-        , std::string const& extern_auth = std::string()
-        , web_seed_entry::headers_t const& extra_headers = web_seed_entry::headers_t());
-void add_http_seed(std::string const& url
-        , std::string const& extern_auth = std::string()
-        , web_seed_entry::headers_t const& extra_headers = web_seed_entry::headers_t());
-std::vector<web_seed_entry> const& web_seeds() const;
-
-
-

web_seeds() returns all url seeds and http seeds in the torrent. Each entry -is a web_seed_entry and may refer to either a url seed or http seed.

-

add_url_seed() and add_http_seed() adds one url to the list of -url/http seeds. Currently, the only transport protocol supported for the url -is http.

-

The extern_auth argument can be used for other athorization schemese than -basic HTTP authorization. If set, it will override any username and password -found in the URL itself. The string will be sent as the HTTP authorization header's -value (without specifying "Basic").

-

The extra_headers argument defaults to an empty list, but can be used to -insert custom HTTP headers in the requests to a specific web seed.

-

See HTTP seeding for more information.

-

The web_seed_entry has the following members:

-
-struct web_seed_entry
-{
-        enum type_t { url_seed, http_seed };
-
-        typedef std::vector<std::pair<std::string, std::string> > headers_t;
-
-        web_seed_entry(std::string const& url_, type_t type_
-                , std::string const& auth_ = std::string()
-                , headers_t const& extra_headers_ = headers_t());
-
-        bool operator==(web_seed_entry const& e) const;
-        bool operator<(web_seed_entry const& e) const;
-
-        std::string url;
-        type_t type;
-        std::string auth;
-        headers_t extra_headers;
-
-        // ...
-};
-
-
-
-

trackers()

-
-
-std::vector<announce_entry> const& trackers() const;
-
-
-

The trackers() function will return a sorted vector of announce_entry. -Each announce entry contains a string, which is the tracker url, and a tier index. The -tier index is the high-level priority. No matter which trackers that works or not, the -ones with lower tier will always be tried before the one with higher tier number.

-
-struct announce_entry
-{
-        announce_entry(std::string const& url);
-        std::string url;
-
-        int next_announce_in() const;
-        int min_announce_in() const;
-
-        int scrape_incomplete;
-        int scrape_complete;
-        int scrape_downloaded;
-
-        error_code last_error;
-
-        std::string message;
-
-        boost::uint8_t tier;
-        boost::uint8_t fail_limit;
-        boost::uint8_t fails;
-
-        enum tracker_source
-        {
-                source_torrent = 1,
-                source_client = 2,
-                source_magnet_link = 4,
-                source_tex = 8
-        };
-        boost::uint8_t source;
-
-        bool verified:1;
-        bool updating:1;
-        bool start_sent:1;
-        bool complete_sent:1;
-};
-
-

next_announce_in() returns the number of seconds to the next announce on -this tracker. min_announce_in() returns the number of seconds until we are -allowed to force another tracker update with this tracker.

-

If the last time this tracker was contacted failed, last_error is the error -code describing what error occurred.

-

scrape_incomplete, scrape_complete and scrape_downloaded are either --1 or the scrape information this tracker last responded with. incomplete is -the current number of downloaders in the swarm, complete is the current number -of seeds in the swarm and downloaded is the cumulative number of completed -downloads of this torrent, since the beginning of time (from this tracker's point -of view).

-

If the last time this tracker was contacted, the tracker returned a warning -or error message, message contains that message.

-

fail_limit is the max number of failures to announce to this tracker in -a row, before this tracker is not used anymore.

-

fails is the number of times in a row we have failed to announce to this -tracker.

-

source is a bitmask specifying which sources we got this tracker from.

-

verified is set to true the first time we receive a valid response -from this tracker.

-

updating is true while we're waiting for a response from the tracker.

-

start_sent is set to true when we get a valid response from an announce -with event=started. If it is set, we won't send start in the subsequent -announces.

-

complete_sent is set to true when we send a event=completed.

-
-
-

total_size() piece_length() piece_size() num_pieces()

-
-
-size_type total_size() const;
-int piece_length() const;
-int piece_size(unsigned int index) const;
-int num_pieces() const;
-
-
-

total_size(), piece_length() and num_pieces() returns the total -number of bytes the torrent-file represents (all the files in it), the number of byte for -each piece and the total number of pieces, respectively. The difference between -piece_size() and piece_length() is that piece_size() takes -the piece index as argument and gives you the exact size of that piece. It will always -be the same as piece_length() except in the case of the last piece, which may -be smaller.

-
-
-

hash_for_piece() hash_for_piece_ptr() info_hash()

-
-
-size_type piece_size(unsigned int index) const;
-sha1_hash const& hash_for_piece(unsigned int index) const;
-char const* hash_for_piece_ptr(unsigned int index) const;
-
-
-

hash_for_piece() takes a piece-index and returns the 20-bytes sha1-hash for that -piece and info_hash() returns the 20-bytes sha1-hash for the info-section of the -torrent file. For more information on the sha1_hash, see the big_number class. -hash_for_piece_ptr() returns a pointer to the 20 byte sha1 digest for the piece. -Note that the string is not null-terminated.

-
-
-

merkle_tree() set_merkle_tree()

-
-
-std::vector<sha1_hash> const& merkle_tree() const;
-void set_merkle_tree(std::vector<sha1_hash>& h);
-
-
-

merkle_tree() returns a reference to the merkle tree for this torrent, if any.

-

set_merkle_tree() moves the passed in merkle tree into the torrent_info object. -i.e. h will not be identical after the call. You need to set the merkle tree for -a torrent that you've just created (as a merkle torrent). The merkle tree is retrieved -from the create_torrent::merkle_tree() function, and need to be saved separately -from the torrent file itself. Once it's added to libtorrent, the merkle tree will be -persisted in the resume data.

-
-
-

name() comment() creation_date() creator()

-
-
-std::string const& name() const;
-std::string const& comment() const;
-std::string const& creator() const;
-boost::optional<time_t> creation_date() const;
-
-
-

name() returns the name of the torrent.

-

comment() returns the comment associated with the torrent. If there's no comment, -it will return an empty string. creation_date() returns the creation date of -the torrent as time_t (posix time). If there's no time stamp in the torrent file, -the optional object will be uninitialized.

-

Both the name and the comment is UTF-8 encoded strings.

-

creator() returns the creator string in the torrent. If there is no creator string -it will return an empty string.

-
-
-

priv()

-
-
-bool priv() const;
-
-
-

priv() returns true if this torrent is private. i.e., it should not be -distributed on the trackerless network (the kademlia DHT).

-
-
-

nodes()

-
-
-std::vector<std::pair<std::string, int> > const& nodes() const;
-
-
-

If this torrent contains any DHT nodes, they are put in this vector in their original -form (host name and port number).

-
-
-

add_node()

-
-
-void add_node(std::pair<std::string, int> const& node);
-
-
-

This is used when creating torrent. Use this to add a known DHT node. It may -be used, by the client, to bootstrap into the DHT network.

-
-
-

metadata() metadata_size()

-
-
-boost::shared_array<char> metadata() const;
-int metadata_size() const;
-
-
-

metadata() returns a the raw info section of the torrent file. The size -of the metadata is returned by metadata_size().

-
-
-
-

torrent_handle

-

You will usually have to store your torrent handles somewhere, since it's the -object through which you retrieve information about the torrent and aborts the torrent.

-
-

Warning

-

Any member function that returns a value or fills in a value has to -be made synchronously. This means it has to wait for the main thread -to complete the query before it can return. This might potentially be -expensive if done from within a GUI thread that needs to stay responsive. -Try to avoid quering for information you don't need, and try to do it -in as few calls as possible. You can get most of the interesting information -about a torrent from the torrent_handle::status() call.

-
-

Its declaration looks like this:

-
-struct torrent_handle
-{
-        torrent_handle();
-
-        enum status_flags_t
-        {
-                query_distributed_copies = 1,
-                query_accurate_download_counters = 2,
-                query_last_seen_complete = 4,
-                query_pieces = 8,
-                query_verified_pieces = 16,
-                query_torrent_file = 32,
-                query_name = 64,
-                query_save_path = 128,
-        };
-
-        torrent_status status(boost::uint32_t flags = 0xffffffff);
-        void file_progress(std::vector<size_type>& fp, int flags = 0);
-        void get_download_queue(std::vector<partial_piece_info>& queue) const;
-        void get_peer_info(std::vector<peer_info>& v) const;
-        boost::intrusive_ptr<torrent_info> torrent_file() const;
-        bool is_valid() const;
-
-        enum save_resume_flags_t { flush_disk_cache = 1, save_info_dict = 2 };
-        void save_resume_data(int flags = 0) const;
-        bool need_save_resume_data() const;
-        void force_reannounce() const;
-        void force_dht_announce() const;
-        void force_reannounce(boost::posix_time::time_duration) const;
-        void scrape_tracker() const;
-        void connect_peer(asio::ip::tcp::endpoint const& adr, int source = 0) const;
-
-        void set_tracker_login(std::string const& username
-                , std::string const& password) const;
-
-        std::vector<announce_entry> trackers() const;
-        void replace_trackers(std::vector<announce_entry> const&);
-        void add_tracker(announce_entry const& url);
-
-        void add_url_seed(std::string const& url);
-        void remove_url_seed(std::string const& url);
-        std::set<std::string> url_seeds() const;
-
-        void add_http_seed(std::string const& url);
-        void remove_http_seed(std::string const& url);
-        std::set<std::string> http_seeds() const;
-
-        int max_uploads() const;
-        void set_max_uploads(int max_uploads) const;
-        void set_max_connections(int max_connections) const;
-        int max_connections() const;
-        void set_upload_limit(int limit) const;
-        int upload_limit() const;
-        void set_download_limit(int limit) const;
-        int download_limit() const;
-        void set_sequential_download(bool sd) const;
-        bool is_sequential_download() const;
-
-        int queue_position() const;
-        void queue_position_up() const;
-        void queue_position_down() const;
-        void queue_position_top() const;
-        void queue_position_bottom() const;
-
-        void set_priority(int prio) const;
-
-        void use_interface(char const* net_interface) const;
-
-        enum pause_flags_t { graceful_pause = 1 };
-        void pause(int flags = 0) const;
-        void resume() const;
-        bool is_seed() const;
-        void force_recheck() const;
-        void clear_error() const;
-        void set_upload_mode(bool m) const;
-        void set_share_mode(bool m) const;
-
-        void apply_ip_filter(bool b) const;
-
-        void flush_cache() const;
-
-        void resolve_countries(bool r);
-        bool resolve_countries() const;
-
-        enum deadline_flags { alert_when_available = 1 };
-        void set_piece_deadline(int index, int deadline, int flags = 0) const;
-        void reset_piece_deadline(int index) const;
-
-        void piece_availability(std::vector<int>& avail) const;
-        void piece_priority(int index, int priority) const;
-        int piece_priority(int index) const;
-        void prioritize_pieces(std::vector<int> const& pieces) const;
-        std::vector<int> piece_priorities() const;
-
-        void file_priority(int index, int priority) const;
-        int file_priority(int index) const;
-        void prioritize_files(std::vector<int> const& files) const;
-        std::vector<int> file_priorities() const;
-
-        void auto_managed(bool m) const;
-
-        bool set_metadata(char const* buf, int size) const;
-
-        void move_storage(std::string const& save_path, int flags = 0) const;
-        void move_storage(std::wstring const& save_path, int flags = 0) const;
-        void rename_file(int index, std::string) const;
-        void rename_file(int index, std::wstring) const;
-        storage_interface* get_storage_impl() const;
-
-        void super_seeding(bool on) const;
-
-        enum flags_t { overwrite_existing = 1 };
-        void add_piece(int piece, char const* data, int flags = 0) const;
-        void read_piece(int piece) const;
-        bool have_piece(int piece) const;
-
-        sha1_hash info_hash() const;
-
-        void set_ssl_certificate(std::string const& cert
-                , std::string const& private_key
-                , std::string const& dh_params
-                , std::string const& passphrase = "");
-
-        bool operator==(torrent_handle const&) const;
-        bool operator!=(torrent_handle const&) const;
-        bool operator<(torrent_handle const&) const;
-
-        boost::shared_ptr<torrent> native_handle() const;
-};
-
-

The default constructor will initialize the handle to an invalid state. Which -means you cannot perform any operation on it, unless you first assign it a -valid handle. If you try to perform any operation on an uninitialized handle, -it will throw invalid_handle.

-
-

Warning

-

All operations on a torrent_handle may throw libtorrent_exception -exception, in case the handle is no longer refering to a torrent. There is -one exception is_valid() will never throw. -Since the torrents are processed by a background thread, there is no -guarantee that a handle will remain valid between two calls.

-
-
-

set_piece_deadline() reset_piece_deadline()

-
-
-enum deadline_flags { alert_when_available = 1 };
-void set_piece_deadline(int index, int deadline, int flags = 0) const;
-void reset_piece_deadline(int index) const;
-
-
-

This function sets or resets the deadline associated with a specific piece -index (index). libtorrent will attempt to download this entire piece before -the deadline expires. This is not necessarily possible, but pieces with a more -recent deadline will always be prioritized over pieces with a deadline further -ahead in time. The deadline (and flags) of a piece can be changed by calling this -function again.

-

The flags parameter can be used to ask libtorrent to send an alert once the -piece has been downloaded, by passing alert_when_available. When set, the -read_piece_alert alert will be delivered, with the piece data, when it's downloaded.

-

If the piece is already downloaded when this call is made, nothing happens, unless -the alert_when_available flag is set, in which case it will do the same thing -as calling read_piece() for index.

-

deadline is the number of milliseconds until this piece should be completed.

-

reset_piece_deadline removes the deadline from the piece. If it hasn't already -been downloaded, it will no longer be considered a priority.

-
-
-

piece_availability()

-
-
-void piece_availability(std::vector<int>& avail) const;
-
-
-

Fills the specified std::vector<int> with the availability for each -piece in this torrent. libtorrent does not keep track of availability for -seeds, so if the torrent is seeding the availability for all pieces is -reported as 0.

-

The piece availability is the number of peers that we are connected that has -advertized having a particular piece. This is the information that libtorrent -uses in order to prefer picking rare pieces.

-
-
-

piece_priority() prioritize_pieces() piece_priorities()

-
-
-void piece_priority(int index, int priority) const;
-int piece_priority(int index) const;
-void prioritize_pieces(std::vector<int> const& pieces) const;
-std::vector<int> piece_priorities() const;
-
-
-

These functions are used to set and get the prioritiy of individual pieces. -By default all pieces have priority 1. That means that the random rarest -first algorithm is effectively active for all pieces. You may however -change the priority of individual pieces. There are 8 different priority -levels:

-
-
    -
  1. piece is not downloaded at all
  2. -
  3. normal priority. Download order is dependent on availability
  4. -
  5. higher than normal priority. Pieces are preferred over pieces with -the same availability, but not over pieces with lower availability
  6. -
  7. pieces are as likely to be picked as partial pieces.
  8. -
  9. pieces are preferred over partial pieces, but not over pieces with -lower availability
  10. -
  11. currently the same as 4
  12. -
  13. piece is as likely to be picked as any piece with availability 1
  14. -
  15. maximum priority, availability is disregarded, the piece is preferred -over any other piece with lower priority
  16. -
-
-

The exact definitions of these priorities are implementation details, and -subject to change. The interface guarantees that higher number means higher -priority, and that 0 means do not download.

-

piece_priority sets or gets the priority for an individual piece, -specified by index.

-

prioritize_pieces takes a vector of integers, one integer per piece in -the torrent. All the piece priorities will be updated with the priorities -in the vector.

-

piece_priorities returns a vector with one element for each piece in the -torrent. Each element is the current priority of that piece.

-
-
-

file_priority() prioritize_files() file_priorities()

-
-
-void file_priority(int index, int priority) const;
-int file_priority(int index) const;
-void prioritize_files(std::vector<int> const& files) const;
-std::vector<int> file_priorities() const;
-
-
-

index must be in the range [0, number_of_files).

-

file_priority queries or sets the priority of file index.

-

prioritize_files takes a vector that has at as many elements as there are -files in the torrent. Each entry is the priority of that file. The function -sets the priorities of all the pieces in the torrent based on the vector.

-

file_priorities returns a vector with the priorities of all files.

-

The priority values are the same as for piece_priority.

-

Whenever a file priority is changed, all other piece priorities are reset -to match the file priorities. In order to maintain sepcial priorities for -particular pieces, piece_priority has to be called again for those pieces.

-

You cannot set the file priorities on a torrent that does not yet -have metadata or a torrent that is a seed. file_priority(int, int) and -prioritize_files() are both no-ops for such torrents.

-
-
-

file_progress()

-
-
-void file_progress(std::vector<size_type>& fp, int flags = 0);
-
-
-

This function fills in the supplied vector with the the number of bytes downloaded -of each file in this torrent. The progress values are ordered the same as the files -in the torrent_info. This operation is not very cheap. Its complexity is O(n + mj). -Where n is the number of files, m is the number of downloading pieces and j -is the number of blocks in a piece.

-

The flags parameter can be used to specify the granularity of the file progress. If -left at the default value of 0, the progress will be as accurate as possible, but also -more expensive to calculate. If torrent_handle::piece_granularity is specified, -the progress will be specified in piece granularity. i.e. only pieces that have been -fully downloaded and passed the hash check count. When specifying piece granularity, -the operation is a lot cheaper, since libtorrent already keeps track of this internally -and no calculation is required.

-
-
-

move_storage()

-
-
-void move_storage(std::string const& save_path, int flags = 0) const;
-void move_storage(std::wstring const& save_path, int flags = 0) const;
-
-
-

Moves the file(s) that this torrent are currently seeding from or downloading to. If -the given save_path is not located on the same drive as the original save path, -the files will be copied to the new drive and removed from their original location. -This will block all other disk IO, and other torrents download and upload rates may -drop while copying the file.

-

Since disk IO is performed in a separate thread, this operation is also asynchronous. -Once the operation completes, the storage_moved_alert is generated, with the new -path as the message. If the move fails for some reason, storage_moved_failed_alert -is generated instead, containing the error message.

-

The flags argument determines the behavior of the copying/moving of the files -in the torrent. They are defined in include/libtorrent/storage.hpp:

-
-
    -
  • always_replace_files = 0
  • -
  • fail_if_exist = 1
  • -
  • dont_replace = 2
  • -
-
-

always_replace_files is the default and replaces any file that exist in both the -source directory and the target directory.

-

fail_if_exist first check to see that none of the copy operations would cause an -overwrite. If it would, it will fail. Otherwise it will proceed as if it was in -always_replace_files mode. Note that there is an inherent race condition here. -If the files in the target directory appear after the check but before the copy -or move completes, they will be overwritten. When failing because of files already -existing in the target path, the error of move_storage_failed_alert is set -to boost::system::errc::file_exists.

-

The intention is that a client may use this as a probe, and if it fails, ask the user -which mode to use. The client may then re-issue the move_storage call with one -of the other modes.

-

dont_replace always takes the existing file in the target directory, if there is -one. The source files will still be removed in that case.

-

Files that have been renamed to have absolute pahts are not moved by this function. -Keep in mind that files that don't belong to the torrent but are stored in the torrent's -directory may be moved as well. This goes for files that have been renamed to -absolute paths that still end up inside the save path.

-
-
-

rename_file()

-
-
-void rename_file(int index, std::string) const;
-void rename_file(int index, std::wstring) const;
-
-
-

Renames the file with the given index asynchronously. The rename operation is complete -when either a file_renamed_alert or file_rename_failed_alert is posted.

-
-
-

get_storage_impl()

-
-
-storage_interface* get_storage_impl() const;
-
-
-

Returns the storage implementation for this torrent. This depends on the -storage contructor function that was passed to session::add_torrent.

-
-
-

super_seeding()

-
-
-void super_seeding(bool on) const;
-
-
-

Enables or disabled super seeding/initial seeding for this torrent. The torrent -needs to be a seed for this to take effect.

-
-
-

add_piece()

-
-
-enum flags_t { overwrite_existing = 1 };
-void add_piece(int piece, char const* data, int flags = 0) const;
-
-
-

This function will write data to the storage as piece piece, as if it had -been downloaded from a peer. data is expected to point to a buffer of as many -bytes as the size of the specified piece. The data in the buffer is copied and -passed on to the disk IO thread to be written at a later point.

-

By default, data that's already been downloaded is not overwritten by this buffer. If -you trust this data to be correct (and pass the piece hash check) you may pass the -overwrite_existing flag. This will instruct libtorrent to overwrite any data that -may already have been downloaded with this data.

-

Since the data is written asynchronously, you may know that is passed or failed the -hash check by waiting for piece_finished_alert or has_failed_alert.

-
-
-

read_piece()

-
-
-void read_piece(int piece) const;
-
-
-

This function starts an asynchronous read operation of the specified piece from -this torrent. You must have completed the download of the specified piece before -calling this function.

-

When the read operation is completed, it is passed back through an alert, -read_piece_alert. Since this alert is a reponse to an explicit call, it will -always be posted, regardless of the alert mask.

-

Note that if you read multiple pieces, the read operations are not guaranteed to -finish in the same order as you initiated them.

-
-
-

have_piece()

-
-
-bool have_piece(int piece) const;
-
-
-

Returns true if this piece has been completely downloaded, and false otherwise.

-
-
-

force_reannounce() force_dht_announce()

-
-
-void force_reannounce() const;
-void force_reannounce(boost::posix_time::time_duration) const;
-void force_dht_announce() const;
-
-
-

force_reannounce() will force this torrent to do another tracker request, to receive new -peers. The second overload of force_reannounce that takes a time_duration as -argument will schedule a reannounce in that amount of time from now.

-

If the tracker's min_interval has not passed since the last announce, the forced -announce will be scheduled to happen immediately as the min_interval expires. This is -to honor trackers minimum re-announce interval settings.

-

force_dht_announce will announce the torrent to the DHT immediately.

-
-
-

scrape_tracker()

-
-
-void scrape_tracker() const;
-
-
-

scrape_tracker() will send a scrape request to the tracker. A scrape request queries the -tracker for statistics such as total number of incomplete peers, complete peers, number of -downloads etc.

-

This request will specifically update the num_complete and num_incomplete fields in -the torrent_status struct once it completes. When it completes, it will generate a -scrape_reply_alert. If it fails, it will generate a scrape_failed_alert.

-
-
-

connect_peer()

-
-
-void connect_peer(asio::ip::tcp::endpoint const& adr, int source = 0) const;
-
-
-

connect_peer() is a way to manually connect to peers that one believe is a part of the -torrent. If the peer does not respond, or is not a member of this torrent, it will simply -be disconnected. No harm can be done by using this other than an unnecessary connection -attempt is made. If the torrent is uninitialized or in queued or checking mode, this -will throw libtorrent_exception. The second (optional) argument will be bitwised ORed into -the source mask of this peer. Typically this is one of the source flags in peer_info. -i.e. tracker, pex, dht etc.

-
-
-

set_upload_limit() set_download_limit() upload_limit() download_limit()

-
-
-void set_upload_limit(int limit) const;
-void set_download_limit(int limit) const;
-int upload_limit() const;
-int download_limit() const;
-
-
-

set_upload_limit will limit the upload bandwidth used by this particular torrent to the -limit you set. It is given as the number of bytes per second the torrent is allowed to upload. -set_download_limit works the same way but for download bandwidth instead of upload bandwidth. -Note that setting a higher limit on a torrent then the global limit (session_settings::upload_rate_limit) -will not override the global rate limit. The torrent can never upload more than the global rate -limit.

-

upload_limit and download_limit will return the current limit setting, for upload and -download, respectively.

-
-
-

set_sequential_download()

-
-
-void set_sequential_download(bool sd);
-
-
-

set_sequential_download() enables or disables sequential download. When enabled, the piece -picker will pick pieces in sequence instead of rarest first.

-

Enabling sequential download will affect the piece distribution negatively in the swarm. It should be -used sparingly.

-
-
-

pause() resume()

-
-
-enum pause_flags_t { graceful_pause = 1 };
-void pause(int flags) const;
-void resume() const;
-
-
-

pause(), and resume() will disconnect all peers and reconnect all peers respectively. -When a torrent is paused, it will however remember all share ratios to all peers and remember -all potential (not connected) peers. Torrents may be paused automatically if there is a file -error (e.g. disk full) or something similar. See file_error_alert.

-

To know if a torrent is paused or not, call torrent_handle::status() and inspect -torrent_status::paused.

-

The flags argument to pause can be set to torrent_handle::graceful_pause which will -delay the disconnect of peers that we're still downloading outstanding requests from. The torrent -will not accept any more requests and will disconnect all idle peers. As soon as a peer is -done transferring the blocks that were requested from it, it is disconnected. This is a graceful -shut down of the torrent in the sense that no downloaded bytes are wasted.

-

torrents that are auto-managed may be automatically resumed again. It does not make sense to -pause an auto-managed torrent without making it not automanaged first. Torrents are auto-managed -by default when added to the session. For more information, see queuing.

-
-
-

flush_cache()

-
-
-void flush_cache() const;
-
-
-

Instructs libtorrent to flush all the disk caches for this torrent and close all -file handles. This is done asynchronously and you will be notified that it's complete -through cache_flushed_alert.

-

Note that by the time you get the alert, libtorrent may have cached more data for the -torrent, but you are guaranteed that whatever cached data libtorrent had by the time -you called torrent_handle::flush_cache() has been written to disk.

-
-
-

force_recheck()

-
-
-void force_recheck() const;
-
-
-

force_recheck puts the torrent back in a state where it assumes to have no resume data. -All peers will be disconnected and the torrent will stop announcing to the tracker. The torrent -will be added to the checking queue, and will be checked (all the files will be read and -compared to the piece hashes). Once the check is complete, the torrent will start connecting -to peers again, as normal.

-
-
-

clear_error()

-
-
-void clear_error() const;
-
-
-

If the torrent is in an error state (i.e. torrent_status::error is non-empty), this -will clear the error and start the torrent again.

-
-
-

set_upload_mode()

-
-void set_upload_mode(bool m) const;
-
-

Explicitly sets the upload mode of the torrent. In upload mode, the torrent will not -request any pieces. If the torrent is auto managed, it will automatically be taken out -of upload mode periodically (see session_settings::optimistic_disk_retry). Torrents -are automatically put in upload mode whenever they encounter a disk write error.

-

m should be true to enter upload mode, and false to leave it.

-

To test if a torrent is in upload mode, call torrent_handle::status() and inspect -torrent_status::upload_mode.

-
-
-

set_share_mode()

-
-
-void set_share_mode(bool m) const;
-
-
-

Enable or disable share mode for this torrent. When in share mode, the torrent will -not necessarily be downloaded, especially not the whole of it. Only parts that are likely -to be distributed to more than 2 other peers are downloaded, and only if the previous -prediction was correct.

-
-
-

apply_ip_filter()

-
-void apply_ip_filter(bool b) const;
-
-

Set to true to apply the session global IP filter to this torrent (which is the -default). Set to false to make this torrent ignore the IP filter.

-
-
-

resolve_countries()

-
-
-void resolve_countries(bool r);
-bool resolve_countries() const;
-
-
-

Sets or gets the flag that derermines if countries should be resolved for the peers of this -torrent. It defaults to false. If it is set to true, the peer_info structure for the peers -in this torrent will have their country member set. See peer_info for more information -on how to interpret this field.

-
-
-

is_seed()

-
-
-bool is_seed() const;
-
-
-

Returns true if the torrent is in seed mode (i.e. if it has finished downloading).

-
-
-

auto_managed()

-
-
-void auto_managed(bool m) const;
-
-
-

auto_managed() changes whether the torrent is auto managed or not. For more info, -see queuing.

-
-
-

set_metadata()

-
-
-bool set_metadata(char const* buf, int size) const;
-
-
-

set_metadata expects the info section of metadata. i.e. The buffer passed in will be -hashed and verified against the info-hash. If it fails, a metadata_failed_alert will be -generated. If it passes, a metadata_received_alert is generated. The function returns -true if the metadata is successfully set on the torrent, and false otherwise. If the torrent -already has metadata, this function will not affect the torrent, and false will be returned.

-
-
-

set_tracker_login()

-
-
-void set_tracker_login(std::string const& username
-        , std::string const& password) const;
-
-
-

set_tracker_login() sets a username and password that will be sent along in the HTTP-request -of the tracker announce. Set this if the tracker requires authorization.

-
-
-

trackers() replace_trackers() add_tracker()

-
-
-std::vector<announce_entry> trackers() const;
-void replace_trackers(std::vector<announce_entry> const&) const;
-void add_tracker(announc_entry const& url);
-
-
-

trackers() will return the list of trackers for this torrent. The -announce entry contains both a string url which specify the announce url -for the tracker as well as an int tier, which is specifies the order in -which this tracker is tried. If you want libtorrent to use another list of -trackers for this torrent, you can use replace_trackers() which takes -a list of the same form as the one returned from trackers() and will -replace it. If you want an immediate effect, you have to call -force_reannounce() force_dht_announce(). See trackers() for the definition of announce_entry.

-

add_tracker() will look if the specified tracker is already in the set. -If it is, it doesn't do anything. If it's not in the current set of trackers, -it will insert it in the tier specified in the announce_entry.

-

The updated set of trackers will be saved in the resume data, and when a torrent -is started with resume data, the trackers from the resume data will replace the -original ones.

-
-
-

add_url_seed() remove_url_seed() url_seeds()

-
-
-void add_url_seed(std::string const& url);
-void remove_url_seed(std::string const& url);
-std::set<std::string> url_seeds() const;
-
-
-

add_url_seed() adds another url to the torrent's list of url seeds. If the -given url already exists in that list, the call has no effect. The torrent -will connect to the server and try to download pieces from it, unless it's -paused, queued, checking or seeding. remove_url_seed() removes the given -url if it exists already. url_seeds() return a set of the url seeds -currently in this torrent. Note that urls that fails may be removed -automatically from the list.

-

See HTTP seeding for more information.

-
-
-

add_http_seed() remove_http_seed() http_seeds()

-
-
-void add_http_seed(std::string const& url);
-void remove_http_seed(std::string const& url);
-std::set<std::string> http_seeds() const;
-
-
-

These functions are identical as the *_url_seed() variants, but they -operate on BEP 17 web seeds instead of BEP 19.

-

See HTTP seeding for more information.

-
-
-

queue_position() queue_position_up() queue_position_down() queue_position_top() queue_position_bottom()

-
-
-int queue_position() const;
-void queue_position_up() const;
-void queue_position_down() const;
-void queue_position_top() const;
-void queue_position_bottom() const;
-
-
-

Every torrent that is added is assigned a queue position exactly one greater than -the greatest queue position of all existing torrents. Torrents that are being -seeded have -1 as their queue position, since they're no longer in line to be downloaded.

-

When a torrent is removed or turns into a seed, all torrents with greater queue positions -have their positions decreased to fill in the space in the sequence.

-

queue_position() returns the torrent's position in the download queue. The torrents -with the smallest numbers are the ones that are being downloaded. The smaller number, -the closer the torrent is to the front of the line to be started.

-

The queue position is also available in the torrent_status.

-

The queue_position_*() functions adjust the torrents position in the queue. Up means -closer to the front and down means closer to the back of the queue. Top and bottom refers -to the front and the back of the queue respectively.

-
-
-

set_priority()

-
-
-void set_priority(int prio) const;
-
-
-

This sets the bandwidth priority of this torrent. The priority of a torrent determines -how much bandwidth its peers are assigned when distributing upload and download rate quotas. -A high number gives more bandwidth. The priority must be within the range [0, 255].

-

The default priority is 0, which is the lowest priority.

-

To query the priority of a torrent, use the torrent_handle::status() call.

-

Torrents with higher priority will not nececcarily get as much bandwidth as they can -consume, even if there's is more quota. Other peers will still be weighed in when -bandwidth is being distributed. With other words, bandwidth is not distributed strictly -in order of priority, but the priority is used as a weight.

-

Peers whose Torrent has a higher priority will take precedence when distributing unchoke slots. -This is a strict prioritization where every interested peer on a high priority torrent will -be unchoked before any other, lower priority, torrents have any peers unchoked.

-
-
-

use_interface()

-
-
-void use_interface(char const* net_interface) const;
-
-
-

use_interface() sets the network interface this torrent will use when it opens outgoing -connections. By default, it uses the same interface as the session_ uses to listen on. The -parameter must be a string containing one or more, comma separated, ip-address (either an -IPv4 or IPv6 address). When specifying multiple interfaces, the torrent will round-robin -which interface to use for each outgoing conneciton. This is useful for clients that are -multi-homed.

-
-
-

info_hash()

-
-
-sha1_hash info_hash() const;
-
-
-

info_hash() returns the info-hash for the torrent.

-
-
-

set_max_uploads() max_uploads()

-
-
-void set_max_uploads(int max_uploads) const;
-int max_uploads() const;
-
-
-

set_max_uploads() sets the maximum number of peers that's unchoked at the same time on this -torrent. If you set this to -1, there will be no limit. This defaults to infinite. The primary -setting controlling this is the global unchoke slots limit, set by unchoke_slots_limit -in session_settings.

-

max_uploads() returns the current settings.

-
-
-

set_max_connections() max_connections()

-
-
-void set_max_connections(int max_connections) const;
-int max_connections() const;
-
-
-

set_max_connections() sets the maximum number of connection this torrent will open. If all -connections are used up, incoming connections may be refused or poor connections may be closed. -This must be at least 2. The default is unlimited number of connections. If -1 is given to the -function, it means unlimited. There is also a global limit of the number of connections, set -by connections_limit in session_settings.

-

max_connections() returns the current settings.

-
-
-

save_resume_data()

-
-
-enum save_resume_flags_t { flush_disk_cache = 1, save_info_dict = 2 };
-void save_resume_data(int flags = 0) const;
-
-
-

save_resume_data() generates fast-resume data and returns it as an entry. This entry -is suitable for being bencoded. For more information about how fast-resume works, see fast resume.

-

The flags argument is a bitmask of flags ORed together. If the flag torrent_handle::flush_cache -is set, the disk cache will be flushed before creating the resume data. This avoids a problem with -file timestamps in the resume data in case the cache hasn't been flushed yet.

-

If the flag torrent_handle::save_info_dict is set, the resume data will contain the metadata -from the torrent file as well. This is default for any torrent that's added without a torrent -file (such as a magnet link or a URL).

-

This operation is asynchronous, save_resume_data will return immediately. The resume data -is delivered when it's done through an save_resume_data_alert.

-

The fast resume data will be empty in the following cases:

-
-
    -
  1. The torrent handle is invalid.
  2. -
  3. The torrent is checking (or is queued for checking) its storage, it will obviously -not be ready to write resume data.
  4. -
  5. The torrent hasn't received valid metadata and was started without metadata -(see libtorrent's metadata from peers extension)
  6. -
-
-

Note that by the time you receive the fast resume data, it may already be invalid if the torrent -is still downloading! The recommended practice is to first pause the session, then generate the -fast resume data, and then close it down. Make sure to not `remove_torrent()`_ before you receive -the save_resume_data_alert though. There's no need to pause when saving intermittent resume data.

-
-

Warning

-

If you pause every torrent individually instead of pausing the session, every torrent -will have its paused state saved in the resume data!

-
-
-

Warning

-

The resume data contains the modification timestamps for all files. If one file has -been modified when the torrent is added again, the will be rechecked. When shutting down, make -sure to flush the disk cache before saving the resume data. This will make sure that the file -timestamps are up to date and won't be modified after saving the resume data. The recommended way -to do this is to pause the torrent, which will flush the cache and disconnect all peers.

-
-
-

Note

-

It is typically a good idea to save resume data whenever a torrent is completed or paused. In those -cases you don't need to pause the torrent or the session, since the torrent will do no more writing -to its files. If you save resume data for torrents when they are paused, you can accelerate the -shutdown process by not saving resume data again for paused torrents. Completed torrents should -have their resume data saved when they complete and on exit, since their statistics might be updated.

-

In full allocation mode the reume data is never invalidated by subsequent -writes to the files, since pieces won't move around. This means that you don't need to -pause before writing resume data in full or sparse mode. If you don't, however, any data written to -disk after you saved resume data and before the session_ closed is lost.

-
-

It also means that if the resume data is out dated, libtorrent will not re-check the files, but assume -that it is fairly recent. The assumption is that it's better to loose a little bit than to re-check -the entire file.

-

It is still a good idea to save resume data periodically during download as well as when -closing down.

-

Example code to pause and save resume data for all torrents and wait for the alerts:

-
-extern int outstanding_resume_data; // global counter of outstanding resume data
-std::vector<torrent_handle> handles = ses.get_torrents();
-ses.pause();
-for (std::vector<torrent_handle>::iterator i = handles.begin();
-        i != handles.end(); ++i)
-{
-        torrent_handle& h = *i;
-        if (!h.is_valid()) continue;
-        torrent_status s = h.status();
-        if (!s.has_metadata) continue;
-        if (!s.need_save_resume_data()) continue;
-
-        h.save_resume_data();
-        ++outstanding_resume_data;
-}
-
-while (outstanding_resume_data > 0)
-{
-        alert const* a = ses.wait_for_alert(seconds(10));
-
-        // if we don't get an alert within 10 seconds, abort
-        if (a == 0) break;
-
-        std::auto_ptr<alert> holder = ses.pop_alert();
-
-        if (alert_cast<save_resume_data_failed_alert>(a))
-        {
-                process_alert(a);
-                --outstanding_resume_data;
-                continue;
-        }
-
-        save_resume_data_alert const* rd = alert_cast<save_resume_data_alert>(a);
-        if (rd == 0)
-        {
-                process_alert(a);
-                continue;
-        }
-
-        torrent_handle h = rd->handle;
-        torrent_status st = h.status(torrent_handle::query_save_path | torrent_handle::query_name);
-        std::ofstream out((st.save_path
-                + "/" + st.name + ".fastresume").c_str()
-                , std::ios_base::binary);
-        out.unsetf(std::ios_base::skipws);
-        bencode(std::ostream_iterator<char>(out), *rd->resume_data);
-        --outstanding_resume_data;
-}
-
-
-

Note

-

Note how outstanding_resume_data is a global counter in this example. -This is deliberate, otherwise there is a race condition for torrents that -was just asked to save their resume data, they posted the alert, but it has -not been received yet. Those torrents would report that they don't need to -save resume data again, and skipped by the initial loop, and thwart the counter -otherwise.

-
-
-
-

need_save_resume_data()

-
-
-bool need_save_resume_data() const;
-
-
-

This function returns true if any whole chunk has been downloaded since the -torrent was first loaded or since the last time the resume data was saved. When -saving resume data periodically, it makes sense to skip any torrent which hasn't -downloaded anything since the last time.

-
-

Note

-

A torrent's resume data is considered saved as soon as the alert -is posted. It is important to make sure this alert is received and handled -in order for this function to be meaningful.

-
-
-
-

status()

-
-
-torrent_status status(boost::uint32_t flags = 0xffffffff) const;
-
-
-

status() will return a structure with information about the status of this -torrent. If the torrent_handle is invalid, it will throw libtorrent_exception exception. -See torrent_status. The flags argument filters what information is returned -in the torrent_status. Some information in there is relatively expensive to calculate, and -if you're not interested in it (and see performance issues), you can filter them out.

-

By default everything is included. The flags you can use to decide what to include are:

-
    -
  • -
    query_distributed_copies
    -

    calculates distributed_copies, distributed_full_copies and distributed_fraction.

    -
    -
    -
  • -
  • -
    query_accurate_download_counters
    -

    includes partial downloaded blocks in total_done and total_wanted_done.

    -
    -
    -
  • -
  • -
    query_last_seen_complete
    -

    includes last_seen_complete.

    -
    -
    -
  • -
  • -
    query_pieces
    -

    includes pieces.

    -
    -
    -
  • -
  • -
    query_verified_pieces
    -

    includes verified_pieces (only applies to torrents in seed mode).

    -
    -
    -
  • -
  • -
    query_torrent_file
    -

    includes torrent_file, which is all the static information from the .torrent file.

    -
    -
    -
  • -
  • -
    query_name
    -

    includes name, the name of the torrent. This is either derived from the .torrent -file, or from the &dn= magnet link argument or possibly some other source. If the -name of the torrent is not known, this is an empty string.

    -
    -
    -
  • -
  • -
    query_save_path
    -

    includes save_path, the path to the directory the files of the torrent are saved to.

    -
    -
    -
  • -
-
-
-

get_download_queue()

-
-
-void get_download_queue(std::vector<partial_piece_info>& queue) const;
-
-
-

get_download_queue() takes a non-const reference to a vector which it will fill with -information about pieces that are partially downloaded or not downloaded at all but partially -requested. The entry in the vector (partial_piece_info) looks like this:

-
-struct partial_piece_info
-{
-        int piece_index;
-        int blocks_in_piece;
-        enum state_t { none, slow, medium, fast };
-        state_t piece_state;
-        block_info* blocks;
-};
-
-

piece_index is the index of the piece in question. blocks_in_piece is the -number of blocks in this particular piece. This number will be the same for most pieces, but -the last piece may have fewer blocks than the standard pieces.

-

piece_state is set to either fast, medium, slow or none. It tells which -download rate category the peers downloading this piece falls into. none means that no -peer is currently downloading any part of the piece. Peers prefer picking pieces from -the same category as themselves. The reason for this is to keep the number of partially -downloaded pieces down. Pieces set to none can be converted into any of fast, -medium or slow as soon as a peer want to download from it.

-
-struct block_info
-{
-        enum block_state_t
-        { none, requested, writing, finished };
-
-        void set_peer(tcp::endpoint const& ep);
-        tcp::endpoint peer() const;
-
-        unsigned bytes_progress:15;
-        unsigned block_size:15;
-        unsigned state:2;
-        unsigned num_peers:14;
-};
-
-

The blocks field points to an array of blocks_in_piece elements. This pointer is -only valid until the next call to get_download_queue() for any torrent in the same session. -They all share the storaga for the block arrays in their session object.

-

The block_info array contains data for each individual block in the piece. Each block has -a state (state) which is any of:

-
    -
  • none - This block has not been downloaded or requested form any peer.
  • -
  • requested - The block has been requested, but not completely downloaded yet.
  • -
  • writing - The block has been downloaded and is currently queued for being written to disk.
  • -
  • finished - The block has been written to disk.
  • -
-

The peer field is the ip address of the peer this block was downloaded from. -num_peers is the number of peers that is currently requesting this block. Typically this -is 0 or 1, but at the end of the torrent blocks may be requested by more peers in parallel to -speed things up. -bytes_progress is the number of bytes that have been received for this block, and -block_size is the total number of bytes in this block.

-
-
-

get_peer_info()

-
-
-void get_peer_info(std::vector<peer_info>&) const;
-
-
-

get_peer_info() takes a reference to a vector that will be cleared and filled -with one entry for each peer connected to this torrent, given the handle is valid. If the -torrent_handle is invalid, it will throw libtorrent_exception exception. Each entry in -the vector contains information about that particular peer. See peer_info.

-
-
-

torrent_file()

-
-
-boost::intrusive_ptr<torrent_info> torrent_file() const;
-
-
-

Returns a pointer to the torrent_info object associated with this torrent. The -torrent_info object is a copy of the internal object. If the torrent doesn't -have metadata, the object being returned will not be fully filled in. -The torrent may be in a state without metadata only if -it was started without a .torrent file, e.g. by using the libtorrent extension of -just supplying a tracker and info-hash.

-
-
-

is_valid()

-
-
-bool is_valid() const;
-
-
-

Returns true if this handle refers to a valid torrent and false if it hasn't been initialized -or if the torrent it refers to has been aborted. Note that a handle may become invalid after -it has been added to the session. Usually this is because the storage for the torrent is -somehow invalid or if the filenames are not allowed (and hence cannot be opened/created) on -your filesystem. If such an error occurs, a file_error_alert is generated and all handles -that refers to that torrent will become invalid.

-
-
-

set_ssl_certificate()

-
-
-void set_ssl_certificate(std::string const& cert, std::string const& private_key
-        , std::string const& dh_params, std::string const& passphrase = "");
-
-
-

For SSL torrents, use this to specify a path to a .pem file to use as this client's certificate. -The certificate must be signed by the certificate in the .torrent file to be valid.

-

cert is a path to the (signed) certificate in .pem format corresponding to this torrent.

-

private_key is a path to the private key for the specified certificate. This must be in .pem -format.

-

dh_params is a path to the Diffie-Hellman parameter file, which needs to be in .pem format. -You can generate this file using the openssl command like this: -openssl dhparam -outform PEM -out dhparams.pem 512.

-

passphrase may be specified if the private key is encrypted and requires a passphrase to -be decrypted.

-

Note that when a torrent first starts up, and it needs a certificate, it will suspend connecting -to any peers until it has one. It's typically desirable to resume the torrent after setting the -ssl certificate.

-

If you receive a torrent_need_cert_alert, you need to call this to provide a valid cert. If you -don't have a cert you won't be allowed to connect to any peers.

-
-
-

native_handle()

-
-
-boost::shared_ptr<torrent> native_handle() const;
-
-
-

This function is intended only for use by plugins and the alert dispatch function. Any code -that runs in libtorrent's network thread may not use the public API of torrent_handle. -Doing so results in a dead-lock. For such routines, the native_handle gives access to the -underlying type representing the torrent. This type does not have a stable API and should -be relied on as little as possible.

-
-
-
-

torrent_status

-

It contains the following fields:

-
-struct torrent_status
-{
-        enum state_t
-        {
-                queued_for_checking,
-                checking_files,
-                downloading_metadata,
-                downloading,
-                finished,
-                seeding,
-                allocating,
-                checking_resume_data
-        };
-
-        torrent_handle handle;
-
-        state_t state;
-        bool paused;
-        bool auto_managed;
-        bool sequential_download;
-        bool seeding;
-        bool finished;
-        float progress;
-        int progress_ppm;
-        std::string error;
-        std::string save_path;
-        std::string name;
-
-        boost::intrusive_ptr<const torrent_info> torrent_file;
-
-        boost::posix_time::time_duration next_announce;
-        boost::posix_time::time_duration announce_interval;
-
-        std::string current_tracker;
-
-        size_type total_download;
-        size_type total_upload;
-
-        size_type total_payload_download;
-        size_type total_payload_upload;
-
-        size_type total_failed_bytes;
-        size_type total_redundant_bytes;
-
-        int download_rate;
-        int upload_rate;
-
-        int download_payload_rate;
-        int upload_payload_rate;
-
-        int num_peers;
-
-        int num_complete;
-        int num_incomplete;
-
-        int list_seeds;
-        int list_peers;
-
-        int connect_candidates;
-
-        bitfield pieces;
-        bitfield verified_pieces;
-
-        int num_pieces;
-
-        size_type total_done;
-        size_type total_wanted_done;
-        size_type total_wanted;
-
-        int num_seeds;
-
-        int distributed_full_copies;
-        int distributed_fraction;
-
-        float distributed_copies;
-
-        int block_size;
-
-        int num_uploads;
-        int num_connections;
-        int uploads_limit;
-        int connections_limit;
-
-        storage_mode_t storage_mode;
-
-        int up_bandwidth_queue;
-        int down_bandwidth_queue;
-
-        size_type all_time_upload;
-        size_type all_time_download;
-
-        int active_time;
-        int finished_time;
-        int seeding_time;
-
-        int seed_rank;
-
-        int last_scrape;
-
-        bool has_incoming;
-
-        int sparse_regions;
-
-        bool seed_mode;
-        bool upload_mode;
-        bool share_mode;
-        bool super_seeding;
-
-        int priority;
-
-        time_t added_time;
-        time_t completed_time;
-        time_t last_seen_complete;
-
-        int time_since_upload;
-        int time_since_download;
-
-        int queue_position;
-        bool need_save_resume;
-        bool ip_filter_applies;
-
-        sha1_hash info_hash;
-
-        int listen_port;
-};
-
-

handle is a handle to the torrent whose status the object represents.

-

progress is a value in the range [0, 1], that represents the progress of the -torrent's current task. It may be checking files or downloading.

-

progress_ppm reflects the same value as progress, but instead in a range -[0, 1000000] (ppm = parts per million). When floating point operations are disabled, -this is the only alternative to the floating point value in progress.

-

The torrent's current task is in the state member, it will be one of the following:

- ---- - - - - - - - - - - - - - - - - - - - - - - - - - - -
checking_resume_dataThe torrent is currently checking the fastresume data and -comparing it to the files on disk. This is typically -completed in a fraction of a second, but if you add a -large number of torrents at once, they will queue up.
queued_for_checkingThe torrent is in the queue for being checked. But there -currently is another torrent that are being checked. -This torrent will wait for its turn.
checking_filesThe torrent has not started its download yet, and is -currently checking existing files.
downloading_metadataThe torrent is trying to download metadata from peers. -This assumes the metadata_transfer extension is in use.
downloadingThe torrent is being downloaded. This is the state -most torrents will be in most of the time. The progress -meter will tell how much of the files that has been -downloaded.
finishedIn this state the torrent has finished downloading but -still doesn't have the entire torrent. i.e. some pieces -are filtered and won't get downloaded.
seedingIn this state the torrent has finished downloading and -is a pure seeder.
allocatingIf the torrent was started in full allocation mode, this -indicates that the (disk) storage for the torrent is -allocated.
-

When downloading, the progress is total_wanted_done / total_wanted. This takes -into account files whose priority have been set to 0. They are not considered.

-

paused is set to true if the torrent is paused and false otherwise. It's only true -if the torrent itself is paused. If the torrent is not running because the session is -paused, this is still false. To know if a torrent is active or not, you need to inspect -both torrent_status::paused and session::is_paused().

-

auto_managed is set to true if the torrent is auto managed, i.e. libtorrent is -responsible for determining whether it should be started or queued. For more info -see queuing

-

sequential_download is true when the torrent is in sequential download mode. In -this mode pieces are downloaded in order rather than rarest first.

-

is_seeding is true if all pieces have been downloaded.

-

is_finished is true if all pieces that have a priority > 0 are downloaded. There is -only a distinction between finished and seeding if some pieces or files have been -set to priority 0, i.e. are not downloaded.

-

has_metadata is true if this torrent has metadata (either it was started from a -.torrent file or the metadata has been downloaded). The only scenario where this can be -false is when the torrent was started torrent-less (i.e. with just an info-hash and tracker -ip, a magnet link for instance).

-

error may be set to an error message describing why the torrent was paused, in -case it was paused by an error. If the torrent is not paused or if it's paused but -not because of an error, this string is empty.

-

save_path is the path to the directory where this torrent's files are stored. -It's typically the path as was given to `async_add_torrent() add_torrent()`_ when this torrent -was started. This field is only included if the torrent status is queried with -torrent_handle::query_save_path.

-

name is the name of the torrent. Typically this is derived from the .torrent file. -In case the torrent was started without metadata, and hasn't completely received it yet, -it returns the name given to it when added to the session. See session::add_torrent. -This field is only included if the torrent status is queried with torrent_handle::query_name.

-

torrent_file is set to point to the torrent_info object for this torrent. It's -only included if the torrent status is queried with torrent_handle::query_torrent_file.

-

next_announce is the time until the torrent will announce itself to the tracker. And -announce_interval is the time the tracker want us to wait until we announce ourself -again the next time.

-

current_tracker is the URL of the last working tracker. If no tracker request has -been successful yet, it's set to an empty string.

-

total_download and total_upload is the number of bytes downloaded and -uploaded to all peers, accumulated, this session only. The session is considered -to restart when a torrent is paused and restarted again. When a torrent is paused, -these counters are reset to 0. If you want complete, persistent, stats, see -all_time_upload and all_time_download.

-

total_payload_download and total_payload_upload counts the amount of bytes -send and received this session, but only the actual payload data (i.e the interesting -data), these counters ignore any protocol overhead.

-

total_failed_bytes is the number of bytes that has been downloaded and that -has failed the piece hash test. In other words, this is just how much crap that -has been downloaded.

-

total_redundant_bytes is the number of bytes that has been downloaded even -though that data already was downloaded. The reason for this is that in some -situations the same data can be downloaded by mistake. When libtorrent sends -requests to a peer, and the peer doesn't send a response within a certain -timeout, libtorrent will re-request that block. Another situation when -libtorrent may re-request blocks is when the requests it sends out are not -replied in FIFO-order (it will re-request blocks that are skipped by an out of -order block). This is supposed to be as low as possible.

-

pieces is the bitmask that represents which pieces we have (set to true) and -the pieces we don't have. It's a pointer and may be set to 0 if the torrent isn't -downloading or seeding.

-

verified_pieces is a bitmask representing which pieces has had their hash -checked. This only applies to torrents in seed mode. If the torrent is not -in seed mode, this bitmask may be empty.

-

num_pieces is the number of pieces that has been downloaded. It is equivalent -to: std::accumulate(pieces->begin(), pieces->end()). So you don't have to -count yourself. This can be used to see if anything has updated since last time -if you want to keep a graph of the pieces up to date.

-

download_rate and upload_rate are the total rates for all peers for this -torrent. These will usually have better precision than summing the rates from -all peers. The rates are given as the number of bytes per second. The -download_payload_rate and upload_payload_rate respectively is the -total transfer rate of payload only, not counting protocol chatter. This might -be slightly smaller than the other rates, but if projected over a long time -(e.g. when calculating ETA:s) the difference may be noticeable.

-

num_peers is the number of peers this torrent currently is connected to. -Peer connections that are in the half-open state (is attempting to connect) -or are queued for later connection attempt do not count. Although they are -visible in the peer list when you call get_peer_info().

-

num_complete and num_incomplete are set to -1 if the tracker did not -send any scrape data in its announce reply. This data is optional and may -not be available from all trackers. If these are not -1, they are the total -number of peers that are seeding (complete) and the total number of peers -that are still downloading (incomplete) this torrent.

-

list_seeds and list_peers are the number of seeds in our peer list -and the total number of peers (including seeds) respectively. We are not -necessarily connected to all the peers in our peer list. This is the number -of peers we know of in total, including banned peers and peers that we have -failed to connect to.

-

connect_candidates is the number of peers in this torrent's peer list -that is a candidate to be connected to. i.e. It has fewer connect attempts -than the max fail count, it is not a seed if we are a seed, it is not banned -etc. If this is 0, it means we don't know of any more peers that we can try.

-

total_done is the total number of bytes of the file(s) that we have. All -this does not necessarily has to be downloaded during this session (that's -total_payload_download).

-

total_wanted_done is the number of bytes we have downloaded, only counting the -pieces that we actually want to download. i.e. excluding any pieces that we have but -have priority 0 (i.e. not wanted).

-

total_wanted is the total number of bytes we want to download. This is also -excluding pieces whose priorities have been set to 0.

-

num_seeds is the number of peers that are seeding that this client is -currently connected to.

-

distributed_full_copies is the number of distributed copies of the torrent. -Note that one copy may be spread out among many peers. It tells how many copies -there are currently of the rarest piece(s) among the peers this client is -connected to.

-

distributed_fraction tells the share of pieces that have more copies than -the rarest piece(s). Divide this number by 1000 to get the fraction.

-

For example, if distributed_full_copies is 2 and distrbuted_fraction -is 500, it means that the rarest pieces have only 2 copies among the peers -this torrent is connected to, and that 50% of all the pieces have more than -two copies.

-

If we are a seed, the piece picker is deallocated as an optimization, and -piece availability is no longer tracked. In this case the distributed -copies members are set to -1.

-

distributed_copies is a floating point representation of the -distributed_full_copies as the integer part and distributed_fraction -/ 1000 as the fraction part. If floating point operations are disabled -this value is always -1.

-

block_size is the size of a block, in bytes. A block is a sub piece, it -is the number of bytes that each piece request asks for and the number of -bytes that each bit in the partial_piece_info's bitset represents -(see get_download_queue()). This is typically 16 kB, but it may be -larger if the pieces are larger.

-

num_uploads is the number of unchoked peers in this torrent.

-

num_connections is the number of peer connections this torrent has, including -half-open connections that hasn't completed the bittorrent handshake yet. This is -always >= num_peers.

-

uploads_limit is the set limit of upload slots (unchoked peers) for this torrent.

-

connections_limit is the set limit of number of connections for this torrent.

-

storage_mode is one of storage_mode_allocate, storage_mode_sparse or -storage_mode_compact. Identifies which storage mode this torrent is being saved -with. See Storage allocation.

-

up_bandwidth_queue and down_bandwidth_queue are the number of peers in this -torrent that are waiting for more bandwidth quota from the torrent rate limiter. -This can determine if the rate you get from this torrent is bound by the torrents -limit or not. If there is no limit set on this torrent, the peers might still be -waiting for bandwidth quota from the global limiter, but then they are counted in -the session_status object.

-

all_time_upload and all_time_download are accumulated upload and download -payload byte counters. They are saved in and restored from resume data to keep totals -across sessions.

-

active_time, finished_time and seeding_time are second counters. -They keep track of the number of seconds this torrent has been active (not -paused) and the number of seconds it has been active while being finished and -active while being a seed. seeding_time should be <= finished_time which -should be <= active_time. They are all saved in and restored from resume data, -to keep totals across sessions.

-

seed_rank is a rank of how important it is to seed the torrent, it is used -to determine which torrents to seed and which to queue. It is based on the peer -to seed ratio from the tracker scrape. For more information, see queuing.

-

last_scrape is the number of seconds since this torrent acquired scrape data. -If it has never done that, this value is -1.

-

has_incoming is true if there has ever been an incoming connection attempt -to this torrent.'

-

sparse_regions the number of regions of non-downloaded pieces in the -torrent. This is an interesting metric on windows vista, since there is -a limit on the number of sparse regions in a single file there.

-

seed_mode is true if the torrent is in seed_mode. If the torrent was -started in seed mode, it will leave seed mode once all pieces have been -checked or as soon as one piece fails the hash check.

-

upload_mode is true if the torrent is blocked from downloading. This -typically happens when a disk write operation fails. If the torrent is -auto-managed, it will periodically be taken out of this state, in the -hope that the disk condition (be it disk full or permission errors) has -been resolved. If the torrent is not auto-managed, you have to explicitly -take it out of the upload mode by calling set_upload_mode() on the -torrent_handle.

-

share_mode is true if the torrent is currently in share-mode, i.e. -not downloading the torrent, but just helping the swarm out.

-

super_seeding is true if the torrent is in super seeding mode.

-

added_time is the posix-time when this torrent was added. i.e. what -time(NULL) returned at the time.

-

completed_time is the posix-time when this torrent was finished. If -the torrent is not yet finished, this is 0.

-

last_seen_complete is the time when we, or one of our peers, last -saw a complete copy of this torrent.

-

time_since_upload and time_since_download are the number of -seconds since any peer last uploaded from this torrent and the last -time a downloaded piece passed the hash check, respectively.

-

queue_position is the position this torrent has in the download -queue. If the torrent is a seed or finished, this is -1.

-

need_save_resume is true if this torrent has unsaved changes -to its download state and statistics since the last resume data -was saved.

-

ip_filter_applies is true if the session global IP filter applies -to this torrent. This defaults to true.

-

info_hash is the info-hash of the torrent.

-

listen_port is the listen port this torrent is listening on for new -connections, if the torrent has its own listen socket. Only SSL torrents -have their own listen sockets. If the torrent doesn't have one, and is -accepting connections on the single listen socket, this is 0.

-
-
-

peer_info

-

It contains the following fields:

-
-struct peer_info
-{
-        enum
-        {
-                interesting = 0x1,
-                choked = 0x2,
-                remote_interested = 0x4,
-                remote_choked = 0x8,
-                supports_extensions = 0x10,
-                local_connection = 0x20,
-                handshake = 0x40,
-                connecting = 0x80,
-                queued = 0x100,
-                on_parole = 0x200,
-                seed = 0x400,
-                optimistic_unchoke = 0x800,
-                snubbed = 0x1000,
-                upload_only = 0x2000,
-                endgame_mode = 0x4000,
-                holepunched = 0x8000,
-                rc4_encrypted = 0x100000,
-                plaintext_encrypted = 0x200000
-        };
-
-        unsigned int flags;
-
-        enum peer_source_flags
-        {
-                tracker = 0x1,
-                dht = 0x2,
-                pex = 0x4,
-                lsd = 0x8
-        };
-
-        int source;
-
-        // bitmask representing socket state
-        enum bw_state { bw_idle = 0, bw_limit = 1, bw_network = 2, bw_disk = 4 };
-
-        char read_state;
-        char write_state;
-
-        asio::ip::tcp::endpoint ip;
-        int up_speed;
-        int down_speed;
-        int payload_up_speed;
-        int payload_down_speed;
-        size_type total_download;
-        size_type total_upload;
-        peer_id pid;
-        bitfield pieces;
-        int upload_limit;
-        int download_limit;
-
-        time_duration last_request;
-        time_duration last_active;
-        int request_timeout;
-
-        int send_buffer_size;
-        int used_send_buffer;
-
-        int receive_buffer_size;
-        int used_receive_buffer;
-
-        int num_hashfails;
-
-        char country[2];
-
-        std::string inet_as_name;
-        int inet_as;
-
-        size_type load_balancing;
-
-        int requests_in_buffer;
-        int download_queue_length;
-        int upload_queue_length;
-
-        int failcount;
-
-        int downloading_piece_index;
-        int downloading_block_index;
-        int downloading_progress;
-        int downloading_total;
-
-        std::string client;
-
-        enum
-        {
-                standard_bittorrent = 0,
-                web_seed = 1
-        };
-        int connection_type;
-
-        int remote_dl_rate;
-
-        int pending_disk_bytes;
-
-        int send_quota;
-        int receive_quota;
-
-        int rtt;
-
-        int num_pieces;
-
-        int download_rate_peak;
-        int upload_rate_peak;
-
-        float progress;
-        int progress_ppm;
-
-        tcp::endpoint local_endpoint;
-};
-
-

The flags attribute tells you in which state the peer is. It is set to -any combination of the enums above. The following table describes each flag:

- ---- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
interestingwe are interested in pieces from this peer.
chokedwe have choked this peer.
remote_interestedthe peer is interested in us
remote_chokedthe peer has choked us.
support_extensionsmeans that this peer supports the -extension protocol.
local_connectionThe connection was initiated by us, the peer has a -listen port open, and that port is the same as in the -address of this peer. If this flag is not set, this -peer connection was opened by this peer connecting to -us.
handshakeThe connection is opened, and waiting for the -handshake. Until the handshake is done, the peer -cannot be identified.
connectingThe connection is in a half-open state (i.e. it is -being connected).
queuedThe connection is currently queued for a connection -attempt. This may happen if there is a limit set on -the number of half-open TCP connections.
on_paroleThe peer has participated in a piece that failed the -hash check, and is now "on parole", which means we're -only requesting whole pieces from this peer until -it either fails that piece or proves that it doesn't -send bad data.
seedThis peer is a seed (it has all the pieces).
optimistic_unchokeThis peer is subject to an optimistic unchoke. It has -been unchoked for a while to see if it might unchoke -us in return an earn an upload/unchoke slot. If it -doesn't within some period of time, it will be choked -and another peer will be optimistically unchoked.
snubbedThis peer has recently failed to send a block within -the request timeout from when the request was sent. -We're currently picking one block at a time from this -peer.
upload_onlyThis peer has either explicitly (with an extension) -or implicitly (by becoming a seed) told us that it -will not downloading anything more, regardless of -which pieces we have.
endgame_modeThis means the last time this peer picket a piece, -it could not pick as many as it wanted because there -were not enough free ones. i.e. all pieces this peer -has were already requested from other peers.
holepunchedThis flag is set if the peer was in holepunch mode -when the connection succeeded. This typically only -happens if both peers are behind a NAT and the peers -connect via the NAT holepunch mechanism.
-

source is a combination of flags describing from which sources this peer -was received. The flags are:

- ---- - - - - - - - - - - - - - - - - - -
trackerThe peer was received from the tracker.
dhtThe peer was received from the kademlia DHT.
pexThe peer was received from the peer exchange -extension.
lsdThe peer was received from the local service -discovery (The peer is on the local network).
resume_dataThe peer was added from the fast resume data.
-

read_state and write_state are bitmasks indicating what state this peer -is in with regards to sending and receiving data. The states are declared in the -bw_state enum and defines as follows:

- ---- - - - - - - - - - - - - - - -
bw_idleThe peer is not waiting for any external events to -send or receive data.
bw_limitThe peer is waiting for the rate limiter.
bw_networkThe peer has quota and is currently waiting for a -network read or write operation to complete. This is -the state all peers are in if there are no bandwidth -limits.
bw_diskThe peer is waiting for the disk I/O thread to catch -up writing buffers to disk before downloading more.
-

Note that read_state and write_state are bitmasks. A peer may be waiting -on disk and on the network at the same time. bw_idle does not represent a bit, -but is simply a name for no bit being set in the bitmask.

-

The ip field is the IP-address to this peer. The type is an asio endpoint. For -more info, see the asio documentation.

-

up_speed and down_speed contains the current upload and download speed -we have to and from this peer (including any protocol messages). The transfer rates -of payload data only are found in payload_up_speed and payload_down_speed. -These figures are updated approximately once every second.

-

total_download and total_upload are the total number of bytes downloaded -from and uploaded to this peer. These numbers do not include the protocol chatter, but only -the payload data.

-

pid is the peer's id as used in the bit torrent protocol. This id can be used to -extract 'fingerprints' from the peer. Sometimes it can tell you which client the peer -is using. See identify_client()_

-

pieces is a bitfield, with one bit per piece in the torrent. -Each bit tells you if the peer has that piece (if it's set to 1) -or if the peer miss that piece (set to 0).

-

seed is true if this peer is a seed.

-

upload_limit is the number of bytes per second we are allowed to send to this -peer every second. It may be -1 if there's no local limit on the peer. The global -limit and the torrent limit is always enforced anyway.

-

download_limit is the number of bytes per second this peer is allowed to -receive. -1 means it's unlimited.

-

last_request and last_active is the time since we last sent a request -to this peer and since any transfer occurred with this peer, respectively.

-

request_timeout is the number of seconds until the current front piece request -will time out. This timeout can be adjusted through session_settings::request_timeout. --1 means that there is not outstanding request.

-

send_buffer_size and used_send_buffer is the number of bytes allocated -and used for the peer's send buffer, respectively.

-

receive_buffer_size and used_receive_buffer are the number of bytes -allocated and used as receive buffer, respectively.

-

num_hashfails is the number of pieces this peer has participated in -sending us that turned out to fail the hash check.

-

country is the two letter ISO 3166 country code for the country the peer -is connected from. If the country hasn't been resolved yet, both chars are set -to 0. If the resolution failed for some reason, the field is set to "--". If the -resolution service returns an invalid country code, it is set to "!!". -The countries.nerd.dk service is used to look up countries. This field will -remain set to 0 unless the torrent is set to resolve countries, see resolve_countries().

-

inet_as_name is the name of the AS this peer is located in. This might be -an empty string if there is no name in the geo ip database.

-

inet_as is the AS number the peer is located in.

-

load_balancing is a measurement of the balancing of free download (that we get) -and free upload that we give. Every peer gets a certain amount of free upload, but -this member says how much extra free upload this peer has got. If it is a negative -number it means that this was a peer from which we have got this amount of free -download.

-

requests_in_buffer is the number of requests messages that are currently in the -send buffer waiting to be sent.

-

download_queue_length is the number of piece-requests we have sent to this peer -that hasn't been answered with a piece yet.

-

upload_queue_length is the number of piece-requests we have received from this peer -that we haven't answered with a piece yet.

-

failcount is the number of times this peer has "failed". i.e. failed to connect -or disconnected us. The failcount is decremented when we see this peer in a tracker -response or peer exchange message.

-

You can know which piece, and which part of that piece, that is currently being -downloaded from a specific peer by looking at the next four members. -downloading_piece_index is the index of the piece that is currently being downloaded. -This may be set to -1 if there's currently no piece downloading from this peer. If it is ->= 0, the other three members are valid. downloading_block_index is the index of the -block (or sub-piece) that is being downloaded. downloading_progress is the number -of bytes of this block we have received from the peer, and downloading_total is -the total number of bytes in this block.

-

client is a string describing the software at the other end of the connection. -In some cases this information is not available, then it will contain a string -that may give away something about which software is running in the other end. -In the case of a web seed, the server type and version will be a part of this -string.

-

connection_type can currently be one of:

- ---- - - - - - - - - - - - - - - - - - - - -
typemeaning
peer_info::standard_bittorrentRegular bittorrent connection over TCP
peer_info::bittorrent_utpBittorrent connection over uTP
peer_info::web_sesedHTTP connection using the BEP 19 protocol
peer_info::http_seedHTTP connection using the BEP 17 protocol
-

remote_dl_rate is an estimate of the rate this peer is downloading at, in -bytes per second.

-

pending_disk_bytes is the number of bytes this peer has pending in the -disk-io thread. Downloaded and waiting to be written to disk. This is what -is capped by session_settings::max_queued_disk_bytes.

-

send_quota and receive_quota are the number of bytes this peer has been -assigned to be allowed to send and receive until it has to request more quota -from the bandwidth manager.

-

rtt is an estimated round trip time to this peer, in milliseconds. It is -estimated by timing the the tcp connect(). It may be 0 for incoming connections.

-

num_pieces is the number of pieces this peer has.

-

download_rate_peak and upload_rate_peak are the highest download and upload -rates seen on this connection. They are given in bytes per second. This number is -reset to 0 on reconnect.

-

progress is the progress of the peer in the range [0, 1]. This is always 0 when -floating point operations are diabled, instead use progress_ppm.

-

progress_ppm indicates the download progress of the peer in the range [0, 1000000] -(parts per million).

-

local_endpoint is the IP and port pair the socket is bound to locally. i.e. the IP -address of the interface it's going out over. This may be useful for multi-homed -clients with multiple interfaces to the internet.

-
-
-

feed_handle

-

The feed_handle refers to a specific RSS feed which is watched by the session. -The feed_item struct is defined in <libtorrent/rss.hpp>. It has the following -functions:

-
-struct feed_handle
-{
-        feed_handle();
-        void update_feed();
-        feed_status get_feed_status() const;
-        void set_settings(feed_settings const& s);
-        feed_settings settings() const;
-};
-
-
-

update_feed()

-
-
-void update_feed();
-
-
-

Forces an update/refresh of the feed. Regular updates of the feed is managed -by libtorrent, be careful to not call this too frequently since it may -overload the RSS server.

-
-
-

get_feed_status()

-
-
-feed_status get_feed_status() const;
-
-
-

Queries the RSS feed for information, including all the items in the feed. -The feed_status object has the following fields:

-
-struct feed_status
-{
-        std::string url;
-        std::string title;
-        std::string description;
-        time_t last_update;
-        int next_update;
-        bool updating;
-        std::vector<feed_item> items;
-        error_code error;
-        int ttl;
-};
-
-

url is the URL of the feed.

-

title is the name of the feed (as specified by the feed itself). This -may be empty if we have not recevied a response from the RSS server yet, -or if the feed does not specify a title.

-

description is the feed description (as specified by the feed itself). -This may be empty if we have not received a response from the RSS server -yet, or if the feed does not specify a description.

-

last_update is the posix time of the last successful response from the feed.

-

next_update is the number of seconds, from now, when the feed will be -updated again.

-

updating is true if the feed is currently being updated (i.e. waiting for -DNS resolution, connecting to the server or waiting for the response to the -HTTP request, or receiving the response).

-

items is a vector of all items that we have received from the feed. See -feed_item for more information.

-

error is set to the appropriate error code if the feed encountered an -error.

-

ttl is the current refresh time (in minutes). It's either the configured -default ttl, or the ttl specified by the feed.

-
-
-

set_settings() settings()

-
-
-void set_settings(feed_settings const& s);
-feed_settings settings() const;
-
-
-

Sets and gets settings for this feed. For more information on the -available settings, see add_feed().

-
-
-
-

feed_item

-

The feed_item struct is defined in <libtorrent/rss.hpp>.

-
-
-struct feed_item
-{
-        feed_item();
-        std::string url;
-        std::string uuid;
-        std::string title;
-        std::string description;
-        std::string comment;
-        std::string category;
-        size_type size;
-        torrent_handle handle;
-        sha1_hash info_hash;
-};
-
-
-

size is the total size of the content the torrent refers to, or -1 -if no size was specified by the feed.

-

handle is the handle to the torrent, if the session is already downloading -this torrent.

-

info_hash is the info-hash of the torrent, or cleared (i.e. all zeroes) if -the feed does not specify the info-hash.

-

All the strings are self explanatory and may be empty if the feed does not specify -those fields.

-
-
-

session customization

-

You have some control over session configuration through the session_settings object. You -create it and fill it with your settings and then use session::set_settings() -to apply them.

-

You have control over proxy and authorization settings and also the user-agent -that will be sent to the tracker. The user-agent will also be used to identify the -client with other peers.

-
-

presets

-

The default values of the session settings are set for a regular bittorrent client running -on a desktop system. There are functions that can set the session settings to pre set -settings for other environments. These can be used for the basis, and should be tweaked to -fit your needs better.

-
-session_settings min_memory_usage();
-session_settings high_performance_seed();
-
-

min_memory_usage returns settings that will use the minimal amount of RAM, at the -potential expense of upload and download performance. It adjusts the socket buffer sizes, -disables the disk cache, lowers the send buffer watermarks so that each connection only has -at most one block in use at any one time. It lowers the outstanding blocks send to the disk -I/O thread so that connections only have one block waiting to be flushed to disk at any given -time. It lowers the max number of peers in the peer list for torrents. It performs multiple -smaller reads when it hashes pieces, instead of reading it all into memory before hashing.

-

This configuration is inteded to be the starting point for embedded devices. It will -significantly reduce memory usage.

-

high_performance_seed returns settings optimized for a seed box, serving many peers -and that doesn't do any downloading. It has a 128 MB disk cache and has a limit of 400 files -in its file pool. It support fast upload rates by allowing large send buffers.

-
-
-

session_settings

-
-struct session_settings
-{
-        session_settings();
-        int version;
-        std::string user_agent;
-        int tracker_completion_timeout;
-        int tracker_receive_timeout;
-        int stop_tracker_timeout;
-        int tracker_maximum_response_length;
-
-        int piece_timeout;
-        float request_queue_time;
-        int max_allowed_in_request_queue;
-        int max_out_request_queue;
-        int whole_pieces_threshold;
-        int peer_timeout;
-        int urlseed_timeout;
-        int urlseed_pipeline_size;
-        int file_pool_size;
-        bool allow_multiple_connections_per_ip;
-        int max_failcount;
-        int min_reconnect_time;
-        int peer_connect_timeout;
-        bool ignore_limits_on_local_network;
-        int connection_speed;
-        bool send_redundant_have;
-        bool lazy_bitfields;
-        int inactivity_timeout;
-        int unchoke_interval;
-        int optimistic_unchoke_interval;
-        std::string announce_ip;
-        int num_want;
-        int initial_picker_threshold;
-        int allowed_fast_set_size;
-
-        enum { no_piece_suggestions = 0, suggest_read_cache = 1 };
-        int suggest_mode;
-        int max_queued_disk_bytes;
-        int handshake_timeout;
-        bool use_dht_as_fallback;
-        bool free_torrent_hashes;
-        bool upnp_ignore_nonrouters;
-        int send_buffer_watermark;
-        int send_buffer_watermark_factor;
-
-#ifndef TORRENT_NO_DEPRECATE
-        bool auto_upload_slots;
-        bool auto_upload_slots_rate_based;
-#endif
-
-        enum choking_algorithm_t
-        {
-                fixed_slots_choker,
-                auto_expand_choker,
-                rate_based_choker,
-                bittyrant_choker
-        };
-
-        int choking_algorithm;
-
-        enum seed_choking_algorithm_t
-        {
-                round_robin,
-                fastest_upload,
-                anti_leech
-        };
-
-        int seed_choking_algorithm;
-
-        bool use_parole_mode;
-        int cache_size;
-        int cache_buffer_chunk_size;
-        int cache_expiry;
-        bool use_read_cache;
-        bool explicit_read_cache;
-        int explicit_cache_interval;
-
-        enum io_buffer_mode_t
-        {
-                enable_os_cache = 0,
-                disable_os_cache_for_aligned_files = 1,
-                disable_os_cache = 2
-        };
-        int disk_io_write_mode;
-        int disk_io_read_mode;
-
-        std::pair<int, int> outgoing_ports;
-        char peer_tos;
-
-        int active_downloads;
-        int active_seeds;
-        int active_dht_limit;
-        int active_tracker_limit;
-        int active_limit;
-        bool auto_manage_prefer_seeds;
-        bool dont_count_slow_torrents;
-        int auto_manage_interval;
-        float share_ratio_limit;
-        float seed_time_ratio_limit;
-        int seed_time_limit;
-        int peer_turnover_interval;
-        float peer_turnover;
-        float peer_turnover_cutoff;
-        bool close_redundant_connections;
-
-        int auto_scrape_interval;
-        int auto_scrape_min_interval;
-
-        int max_peerlist_size;
-
-        int min_announce_interval;
-
-        bool prioritize_partial_pieces;
-        int auto_manage_startup;
-
-        bool rate_limit_ip_overhead;
-
-        bool announce_to_all_trackers;
-        bool announce_to_all_tiers;
-
-        bool prefer_udp_trackers;
-        bool strict_super_seeding;
-
-        int seeding_piece_quota;
-
-        int max_sparse_regions;
-
-        bool lock_disk_cache;
-
-        int max_rejects;
-
-        int recv_socket_buffer_size;
-        int send_socket_buffer_size;
-
-        bool optimize_hashing_for_speed;
-
-        int file_checks_delay_per_block;
-
-        enum disk_cache_algo_t
-        { lru, largest_contiguous, avoid_readback };
-
-        disk_cache_algo_t disk_cache_algorithm;
-
-        int read_cache_line_size;
-        int write_cache_line_size;
-
-        int optimistic_disk_retry;
-        bool disable_hash_checks;
-
-        int max_suggest_pieces;
-
-        bool drop_skipped_requests;
-
-        bool low_prio_disk;
-        int local_service_announce_interval;
-        int dht_announce_interval;
-
-        int udp_tracker_token_expiry;
-        bool volatile_read_cache;
-        bool guided_read_cache;
-        bool default_cache_min_age;
-
-        int num_optimistic_unchoke_slots;
-        bool no_atime_storage;
-        int default_est_reciprocation_rate;
-        int increase_est_reciprocation_rate;
-        int decrease_est_reciprocation_rate;
-        bool incoming_starts_queued_torrents;
-        bool report_true_downloaded;
-        bool strict_end_game_mode;
-
-        bool broadcast_lsd;
-
-        bool enable_outgoing_utp;
-        bool enable_incoming_utp;
-        bool enable_outgoing_tcp;
-        bool enable_incoming_tcp;
-        int max_pex_peers;
-        bool ignore_resume_timestamps;
-        bool no_recheck_incomplete_resume;
-        bool anonymous_mode;
-        bool force_proxy;
-        int tick_interval;
-        int share_mode_target;
-
-        int upload_rate_limit;
-        int download_rate_limit;
-        int local_upload_rate_limit;
-        int local_download_rate_limit;
-        int dht_upload_rate_limit;
-        int unchoke_slots_limit;
-        int half_open_limit;
-        int connections_limit;
-
-        int utp_target_delay;
-        int utp_gain_factor;
-        int utp_min_timeout;
-        int utp_syn_resends;
-        int utp_num_resends;
-        int utp_connect_timeout;
-        bool utp_dynamic_sock_buf;
-        int utp_loss_multiplier;
-
-        enum bandwidth_mixed_algo_t
-        {
-                prefer_tcp = 0,
-                peer_proportional = 1
-
-        };
-        int mixed_mode_algorithm;
-        bool rate_limit_utp;
-
-        int listen_queue_size;
-
-        bool announce_double_nat;
-
-        int torrent_connect_boost;
-        bool seeding_outgoing_connections;
-
-        bool no_connect_privileged_ports;
-        int alert_queue_size;
-        int max_metadata_size;
-        bool smooth_connects;
-        bool always_send_user_agent;
-        bool apply_ip_filter_to_trackers;
-        int read_job_every;
-        bool use_disk_read_ahead;
-        bool lock_files;
-
-        int ssl_listen;
-
-        int tracker_backoff;
-
-        bool ban_web_seeds;
-        int max_http_recv_buffer_size;
-
-        bool support_share_mode;
-        bool support_merkle_torrents;
-        bool report_redundant_bytes;
-        std::string handshake_client_version;
-        bool use_disk_cache_pool;
-};
-
-

version is automatically set to the libtorrent version you're using -in order to be forward binary compatible. This field should not be changed.

-

user_agent this is the client identification to the tracker. -The recommended format of this string is: -"ClientName/ClientVersion libtorrent/libtorrentVersion". -This name will not only be used when making HTTP requests, but also when -sending extended headers to peers that support that extension.

-

tracker_completion_timeout is the number of seconds the tracker -connection will wait from when it sent the request until it considers the -tracker to have timed-out. Default value is 60 seconds.

-

tracker_receive_timeout is the number of seconds to wait to receive -any data from the tracker. If no data is received for this number of -seconds, the tracker will be considered as having timed out. If a tracker -is down, this is the kind of timeout that will occur. The default value -is 20 seconds.

-

stop_tracker_timeout is the time to wait for tracker responses when -shutting down the session object. This is given in seconds. Default is -10 seconds.

-

tracker_maximum_response_length is the maximum number of bytes in a -tracker response. If a response size passes this number it will be rejected -and the connection will be closed. On gzipped responses this size is measured -on the uncompressed data. So, if you get 20 bytes of gzip response that'll -expand to 2 megs, it will be interrupted before the entire response has been -uncompressed (given your limit is lower than 2 megs). Default limit is -1 megabyte.

-

piece_timeout controls the number of seconds from a request is sent until -it times out if no piece response is returned.

-

request_queue_time is the length of the request queue given in the number -of seconds it should take for the other end to send all the pieces. i.e. the -actual number of requests depends on the download rate and this number.

-

max_allowed_in_request_queue is the number of outstanding block requests -a peer is allowed to queue up in the client. If a peer sends more requests -than this (before the first one has been handled) the last request will be -dropped. The higher this is, the faster upload speeds the client can get to a -single peer.

-

max_out_request_queue is the maximum number of outstanding requests to -send to a peer. This limit takes precedence over request_queue_time. i.e. -no matter the download speed, the number of outstanding requests will never -exceed this limit.

-

whole_pieces_threshold is a limit in seconds. if a whole piece can be -downloaded in at least this number of seconds from a specific peer, the -peer_connection will prefer requesting whole pieces at a time from this peer. -The benefit of this is to better utilize disk caches by doing localized -accesses and also to make it easier to identify bad peers if a piece fails -the hash check.

-

peer_timeout is the number of seconds the peer connection should -wait (for any activity on the peer connection) before closing it due -to time out. This defaults to 120 seconds, since that's what's specified -in the protocol specification. After half the time out, a keep alive message -is sent.

-

urlseed_timeout is the same as peer_timeout but applies only to -url seeds. This value defaults to 20 seconds.

-

urlseed_pipeline_size controls the pipelining with the web server. When -using persistent connections to HTTP 1.1 servers, the client is allowed to -send more requests before the first response is received. This number controls -the number of outstanding requests to use with url-seeds. Default is 5.

-

file_pool_size is the the upper limit on the total number of files this -session will keep open. The reason why files are left open at all is that -some anti virus software hooks on every file close, and scans the file for -viruses. deferring the closing of the files will be the difference between -a usable system and a completely hogged down system. Most operating systems -also has a limit on the total number of file descriptors a process may have -open. It is usually a good idea to find this limit and set the number of -connections and the number of files limits so their sum is slightly below it.

-

allow_multiple_connections_per_ip determines if connections from the -same IP address as existing connections should be rejected or not. Multiple -connections from the same IP address is not allowed by default, to prevent -abusive behavior by peers. It may be useful to allow such connections in -cases where simulations are run on the same machie, and all peers in a -swarm has the same IP address.

-

max_failcount is the maximum times we try to connect to a peer before -stop connecting again. If a peer succeeds, the failcounter is reset. If -a peer is retrieved from a peer source (other than DHT) the failcount is -decremented by one, allowing another try.

-

min_reconnect_time is the time to wait between connection attempts. If -the peer fails, the time is multiplied by fail counter.

-

peer_connect_timeout the number of seconds to wait after a connection -attempt is initiated to a peer until it is considered as having timed out. -The default is 10 seconds. This setting is especially important in case -the number of half-open connections are limited, since stale half-open -connection may delay the connection of other peers considerably.

-

ignore_limits_on_local_network, if set to true, upload, download and -unchoke limits are ignored for peers on the local network.

-

connection_speed is the number of connection attempts that -are made per second. If a number < 0 is specified, it will default to -200 connections per second. If 0 is specified, it means don't make -outgoing connections at all.

-

send_redundant_have controls if have messages will be sent -to peers that already have the piece. This is typically not necessary, -but it might be necessary for collecting statistics in some cases. -Default is false.

-

lazy_bitfields prevents outgoing bitfields from being full. If the -client is seed, a few bits will be set to 0, and later filled in with -have-messages. This is to prevent certain ISPs from stopping people -from seeding.

-

inactivity_timeout, if a peer is uninteresting and uninterested -for longer than this number of seconds, it will be disconnected. -Default is 10 minutes

-

unchoke_interval is the number of seconds between chokes/unchokes. -On this interval, peers are re-evaluated for being choked/unchoked. This -is defined as 30 seconds in the protocol, and it should be significantly -longer than what it takes for TCP to ramp up to it's max rate.

-

optimistic_unchoke_interval is the number of seconds between -each optimistic unchoke. On this timer, the currently optimistically -unchoked peer will change.

-

announce_ip is the ip address passed along to trackers as the &ip= parameter. -If left as the default (an empty string), that parameter is omitted.

-

num_want is the number of peers we want from each tracker request. It defines -what is sent as the &num_want= parameter to the tracker.

-

initial_picker_threshold specifies the number of pieces we need before we -switch to rarest first picking. This defaults to 4, which means the 4 first -pieces in any torrent are picked at random, the following pieces are picked -in rarest first order.

-

allowed_fast_set_size is the number of pieces we allow peers to download -from us without being unchoked.

-

suggest_mode controls whether or not libtorrent will send out suggest -messages to create a bias of its peers to request certain pieces. The modes -are:

-
    -
  • no_piece_suggestsions which is the default and will not send out suggest -messages.
  • -
  • suggest_read_cache which will send out suggest messages for the most -recent pieces that are in the read cache.
  • -
-

max_queued_disk_bytes is the number maximum number of bytes, to be -written to disk, that can wait in the disk I/O thread queue. This queue -is only for waiting for the disk I/O thread to receive the job and either -write it to disk or insert it in the write cache. When this limit is reached, -the peer connections will stop reading data from their sockets, until the disk -thread catches up. Setting this too low will severly limit your download rate.

-

handshake_timeout specifies the number of seconds we allow a peer to -delay responding to a protocol handshake. If no response is received within -this time, the connection is closed.

-

use_dht_as_fallback determines how the DHT is used. If this is true, -the DHT will only be used for torrents where all trackers in its tracker -list has failed. Either by an explicit error message or a time out. This -is false by default, which means the DHT is used by default regardless of -if the trackers fail or not.

-

free_torrent_hashes determines whether or not the torrent's piece hashes -are kept in memory after the torrent becomes a seed or not. If it is set to -true the hashes are freed once the torrent is a seed (they're not -needed anymore since the torrent won't download anything more). If it's set -to false they are not freed. If they are freed, the torrent_info returned -by get_torrent_info() will return an object that may be incomplete, that -cannot be passed back to `async_add_torrent() add_torrent()`_ for instance.

-

upnp_ignore_nonrouters indicates whether or not the UPnP implementation -should ignore any broadcast response from a device whose address is not the -configured router for this machine. i.e. it's a way to not talk to other -people's routers by mistake.

-

send_buffer_watermark is the upper limit of the send buffer low-watermark. -if the send buffer has fewer bytes than this, we'll read another 16kB block -onto it. If set too small, upload rate capacity will suffer. If set too high, -memory will be wasted. The actual watermark may be lower than this in case -the upload rate is low, this is the upper limit.

-

send_buffer_watermark_factor is multiplied to the peer's upload rate -to determine the low-watermark for the peer. It is specified as a percentage, -which means 100 represents a factor of 1. -The low-watermark is still clamped to not exceed the send_buffer_watermark -upper limit. This defaults to 50. For high capacity connections, setting this -higher can improve upload performance and disk throughput. Setting it too -high may waste RAM and create a bias towards read jobs over write jobs.

-

auto_upload_slots defaults to true. When true, if there is a global upload -limit set and the current upload rate is less than 90% of that, another upload -slot is opened. If the upload rate has been saturated for an extended period -of time, on upload slot is closed. The number of upload slots will never be -less than what has been set by session::set_max_uploads(). To query the -current number of upload slots, see session_status::allowed_upload_slots.

-

When auto_upload_slots_rate_based is set, and auto_upload_slots is set, -the max upload slots setting is used as a minimum number of unchoked slots. -This algorithm is designed to prevent the peer from spreading its upload -capacity too thin, but still open more slots in order to utilize the full capacity.

-

choking_algorithm specifies which algorithm to use to determine which peers -to unchoke. This setting replaces the deprecated settings auto_upload_slots -and auto_upload_slots_rate_based.

-

The options for choking algorithms are:

-
    -
  • fixed_slots_choker is the traditional choker with a fixed number of unchoke -slots (as specified by session::set_max_uploads()).
  • -
  • auto_expand_choker opens at least the number of slots as specified by -session::set_max_uploads() but opens up more slots if the upload capacity -is not saturated. This unchoker will work just like the fixed_slot_choker -if there's no global upload rate limit set.
  • -
  • rate_based_choker opens up unchoke slots based on the upload rate -achieved to peers. The more slots that are opened, the marginal upload -rate required to open up another slot increases.
  • -
  • bittyrant_choker attempts to optimize download rate by finding the -reciprocation rate of each peer individually and prefers peers that gives -the highest return on investment. It still allocates all upload capacity, -but shuffles it around to the best peers first. For this choker to be -efficient, you need to set a global upload rate limit -(session_settings::upload_rate_limit). For more information about this -choker, see the paper.
  • -
-

seed_choking_algorithm controls the seeding unchoke behavior. The available -options are:

-
    -
  • round_robin which round-robins the peers that are unchoked when seeding. This -distributes the upload bandwidht uniformly and fairly. It minimizes the ability -for a peer to download everything without redistributing it.
  • -
  • fastest_upload unchokes the peers we can send to the fastest. This might be -a bit more reliable in utilizing all available capacity.
  • -
  • anti_leech prioritizes peers who have just started or are just about to finish -the download. The intention is to force peers in the middle of the download to -trade with each other.
  • -
-

use_parole_mode specifies if parole mode should be used. Parole mode means -that peers that participate in pieces that fail the hash check are put in a mode -where they are only allowed to download whole pieces. If the whole piece a peer -in parole mode fails the hash check, it is banned. If a peer participates in a -piece that passes the hash check, it is taken out of parole mode.

-

cache_size is the disk write and read cache. It is specified in units of -16 KiB blocks. Buffers that are part of a peer's send or receive buffer also -count against this limit. Send and receive buffers will never be denied to be -allocated, but they will cause the actual cached blocks to be flushed or evicted. -If this is set to -1, the cache size is automatically set to the amount -of physical RAM available in the machine divided by 8. If the amount of physical -RAM cannot be determined, it's set to 1024 (= 16 MiB).

-

Disk buffers are allocated using a pool allocator, the number of blocks that -are allocated at a time when the pool needs to grow can be specified in -cache_buffer_chunk_size. This defaults to 16 blocks. Lower numbers -saves memory at the expense of more heap allocations. It must be at least 1.

-

cache_expiry is the number of seconds from the last cached write to a piece -in the write cache, to when it's forcefully flushed to disk. Default is 60 second.

-

use_read_cache, is set to true (default), the disk cache is also used to -cache pieces read from disk. Blocks for writing pieces takes presedence.

-

explicit_read_cache defaults to 0. If set to something greater than 0, the -disk read cache will not be evicted by cache misses and will explicitly be -controlled based on the rarity of pieces. Rare pieces are more likely to be -cached. This would typically be used together with suggest_mode set to -suggest_read_cache. The value is the number of pieces to keep in the read -cache. If the actual read cache can't fit as many, it will essentially be clamped.

-

explicit_cache_interval is the number of seconds in between each refresh of -a part of the explicit read cache. Torrents take turns in refreshing and this -is the time in between each torrent refresh. Refreshing a torrent's explicit -read cache means scanning all pieces and picking a random set of the rarest ones. -There is an affinity to pick pieces that are already in the cache, so that -subsequent refreshes only swaps in pieces that are rarer than whatever is in -the cache at the time.

-

disk_io_write_mode and disk_io_read_mode determines how files are -opened when they're in read only mode versus read and write mode. The options -are:

-
-
    -
  • -
    enable_os_cache
    -

    This is the default and files are opened normally, with the OS caching -reads and writes.

    -
    -
    -
  • -
  • -
    disable_os_cache_for_aligned_files
    -

    This will open files in unbuffered mode for files where every read and -write would be sector aligned. Using aligned disk offsets is a requirement -on some operating systems.

    -
    -
    -
  • -
  • -
    disable_os_cache
    -

    This opens all files in unbuffered mode (if allowed by the operating system). -Linux and Windows, for instance, require disk offsets to be sector aligned, -and in those cases, this option is the same as disable_os_caches_for_aligned_files.

    -
    -
    -
  • -
-
-

One reason to disable caching is that it may help the operating system from growing -its file cache indefinitely. Since some OSes only allow aligned files to be opened -in unbuffered mode, It is recommended to make the largest file in a torrent the first -file (with offset 0) or use pad files to align all files to piece boundries.

-

outgoing_ports, if set to something other than (0, 0) is a range of ports -used to bind outgoing sockets to. This may be useful for users whose router -allows them to assign QoS classes to traffic based on its local port. It is -a range instead of a single port because of the problems with failing to reconnect -to peers if a previous socket to that peer and port is in TIME_WAIT state.

-
-

Warning

-

setting outgoing ports will limit the ability to keep multiple -connections to the same client, even for different torrents. It is not -recommended to change this setting. Its main purpose is to use as an -escape hatch for cheap routers with QoS capability but can only classify -flows based on port numbers.

-
-

peer_tos determines the TOS byte set in the IP header of every packet -sent to peers (including web seeds). The default value for this is 0x0 -(no marking). One potentially useful TOS mark is 0x20, this represents -the QBone scavenger service. For more details, see QBSS.

-

active_downloads and active_seeds controls how many active seeding and -downloading torrents the queuing mechanism allows. The target number of active -torrents is min(active_downloads + active_seeds, active_limit). -active_downloads and active_seeds are upper limits on the number of -downloading torrents and seeding torrents respectively. Setting the value to --1 means unlimited.

-

For example if there are 10 seeding torrents and 10 downloading torrents, and -active_downloads is 4 and active_seeds is 4, there will be 4 seeds -active and 4 downloading torrents. If the settings are active_downloads = 2 -and active_seeds = 4, then there will be 2 downloading torrents and 4 seeding -torrents active. Torrents that are not auto managed are also counted against these -limits. If there are non-auto managed torrents that use up all the slots, no -auto managed torrent will be activated.

-

auto_manage_prefer_seeds specifies if libtorrent should prefer giving seeds -active slots or downloading torrents. The default is false.

-

if dont_count_slow_torrents is true, torrents without any payload transfers are -not subject to the active_seeds and active_downloads limits. This is intended -to make it more likely to utilize all available bandwidth, and avoid having torrents -that don't transfer anything block the active slots.

-

active_limit is a hard limit on the number of active torrents. This applies even to -slow torrents.

-

active_dht_limit is the max number of torrents to announce to the DHT. By default -this is set to 88, which is no more than one DHT announce every 10 seconds.

-

active_tracker_limit is the max number of torrents to announce to their trackers. -By default this is 360, which is no more than one announce every 5 seconds.

-

active_lsd_limit is the max number of torrents to announce to the local network -over the local service discovery protocol. By default this is 80, which is no more -than one announce every 5 seconds (assuming the default announce interval of 5 minutes).

-

You can have more torrents active, even though they are not announced to the DHT, -lsd or their tracker. If some peer knows about you for any reason and tries to connect, -it will still be accepted, unless the torrent is paused, which means it won't accept -any connections.

-

auto_manage_interval is the number of seconds between the torrent queue -is updated, and rotated.

-

share_ratio_limit is the upload / download ratio limit for considering a -seeding torrent have met the seed limit criteria. See queuing.

-

seed_time_ratio_limit is the seeding time / downloading time ratio limit -for considering a seeding torrent to have met the seed limit criteria. See queuing.

-

seed_time_limit is the limit on the time a torrent has been an active seed -(specified in seconds) before it is considered having met the seed limit criteria. -See queuing.

-

peer_turnover_interval controls a feature where libtorrent periodically can disconnect -the least useful peers in the hope of connecting to better ones. This settings controls -the interval of this optimistic disconnect. It defaults to every 5 minutes, and -is specified in seconds.

-

peer_turnover Is the fraction of the peers that are disconnected. This is -a float where 1.f represents all peers an 0 represents no peers. It defaults to -4% (i.e. 0.04f)

-

peer_turnover_cutoff is the cut off trigger for optimistic unchokes. If a torrent -has more than this fraction of its connection limit, the optimistic unchoke is -triggered. This defaults to 90% (i.e. 0.9f).

-

close_redundant_connections specifies whether libtorrent should close -connections where both ends have no utility in keeping the connection open. -For instance if both ends have completed their downloads, there's no point -in keeping it open. This defaults to true.

-

auto_scrape_interval is the number of seconds between scrapes of -queued torrents (auto managed and paused torrents). Auto managed -torrents that are paused, are scraped regularly in order to keep -track of their downloader/seed ratio. This ratio is used to determine -which torrents to seed and which to pause.

-

auto_scrape_min_interval is the minimum number of seconds between any -automatic scrape (regardless of torrent). In case there are a large number -of paused auto managed torrents, this puts a limit on how often a scrape -request is sent.

-

max_peerlist_size is the maximum number of peers in the list of -known peers. These peers are not necessarily connected, so this number -should be much greater than the maximum number of connected peers. -Peers are evicted from the cache when the list grows passed 90% of -this limit, and once the size hits the limit, peers are no longer -added to the list. If this limit is set to 0, there is no limit on -how many peers we'll keep in the peer list.

-

max_paused_peerlist_size is the max peer list size used for torrents -that are paused. This default to the same as max_peerlist_size, but -can be used to save memory for paused torrents, since it's not as -important for them to keep a large peer list.

-

min_announce_interval is the minimum allowed announce interval -for a tracker. This is specified in seconds, defaults to 5 minutes and -is used as a sanity check on what is returned from a tracker. It -mitigates hammering misconfigured trackers.

-

If prioritize_partial_pieces is true, partial pieces are picked -before pieces that are more rare. If false, rare pieces are always -prioritized, unless the number of partial pieces is growing out of -proportion.

-

auto_manage_startup is the number of seconds a torrent is considered -active after it was started, regardless of upload and download speed. This -is so that newly started torrents are not considered inactive until they -have a fair chance to start downloading.

-

If rate_limit_ip_overhead is set to true, the estimated TCP/IP overhead is -drained from the rate limiters, to avoid exceeding the limits with the total traffic

-

announce_to_all_trackers controls how multi tracker torrents are -treated. If this is set to true, all trackers in the same tier are -announced to in parallel. If all trackers in tier 0 fails, all trackers -in tier 1 are announced as well. If it's set to false, the behavior is as -defined by the multi tracker specification. It defaults to false, which -is the same behavior previous versions of libtorrent has had as well.

-

announce_to_all_tiers also controls how multi tracker torrents are -treated. When this is set to true, one tracker from each tier is announced -to. This is the uTorrent behavior. This is false by default in order -to comply with the multi-tracker specification.

-

prefer_udp_trackers is true by default. It means that trackers may -be rearranged in a way that udp trackers are always tried before http -trackers for the same hostname. Setting this to fails means that the -trackers' tier is respected and there's no preference of one protocol -over another.

-

strict_super_seeding when this is set to true, a piece has to -have been forwarded to a third peer before another one is handed out. -This is the traditional definition of super seeding.

-

seeding_piece_quota is the number of pieces to send to a peer, -when seeding, before rotating in another peer to the unchoke set. -It defaults to 3 pieces, which means that when seeding, any peer we've -sent more than this number of pieces to will be unchoked in favour of -a choked peer.

-

max_sparse_regions is a limit of the number of sparse regions in -a torrent. A sparse region is defined as a hole of pieces we have not -yet downloaded, in between pieces that have been downloaded. This is -used as a hack for windows vista which has a bug where you cannot -write files with more than a certain number of sparse regions. This -limit is not hard, it will be exceeded. Once it's exceeded, pieces -that will maintain or decrease the number of sparse regions are -prioritized. To disable this functionality, set this to 0. It defaults -to 0 on all platforms except windows.

-

lock_disk_cache if lock disk cache is set to true the disk cache -that's in use, will be locked in physical memory, preventing it from -being swapped out.

-

max_rejects is the number of piece requests we will reject in a row -while a peer is choked before the peer is considered abusive and is -disconnected.

-

recv_socket_buffer_size and send_socket_buffer_size specifies -the buffer sizes set on peer sockets. 0 (which is the default) means -the OS default (i.e. don't change the buffer sizes). The socket buffer -sizes are changed using setsockopt() with SOL_SOCKET/SO_RCVBUF and -SO_SNDBUFFER.

-

optimize_hashing_for_speed chooses between two ways of reading back -piece data from disk when its complete and needs to be verified against -the piece hash. This happens if some blocks were flushed to the disk -out of order. Everything that is flushed in order is hashed as it goes -along. Optimizing for speed will allocate space to fit all the the -remaingin, unhashed, part of the piece, reads the data into it in a single -call and hashes it. This is the default. If optimizing_hashing_for_speed -is false, a single block will be allocated (16 kB), and the unhashed parts -of the piece are read, one at a time, and hashed in this single block. This -is appropriate on systems that are memory constrained.

-

file_checks_delay_per_block is the number of milliseconds to sleep -in between disk read operations when checking torrents. This defaults -to 0, but can be set to higher numbers to slow down the rate at which -data is read from the disk while checking. This may be useful for -background tasks that doesn't matter if they take a bit longer, as long -as they leave disk I/O time for other processes.

-

disk_cache_algorithm tells the disk I/O thread which cache flush -algorithm to use. The default algorithm is largest_contiguous. This -flushes the entire piece, in the write cache, that was least recently -written to. This is specified by the session_settings::lru enum -value. session_settings::largest_contiguous will flush the largest -sequences of contiguous blocks from the write cache, regarless of the -piece's last use time. session_settings::avoid_readback will prioritize -flushing blocks that will avoid having to read them back in to verify -the hash of the piece once it's done. This is especially useful for high -throughput setups, where reading from the disk is especially expensive.

-

read_cache_line_size is the number of blocks to read into the read -cache when a read cache miss occurs. Setting this to 0 is essentially -the same thing as disabling read cache. The number of blocks read -into the read cache is always capped by the piece boundry.

-

When a piece in the write cache has write_cache_line_size contiguous -blocks in it, they will be flushed. Setting this to 1 effectively -disables the write cache.

-

optimistic_disk_retry is the number of seconds from a disk write -errors occur on a torrent until libtorrent will take it out of the -upload mode, to test if the error condition has been fixed.

-

libtorrent will only do this automatically for auto managed torrents.

-

You can explicitly take a torrent out of upload only mode using -set_upload_mode().

-

disable_hash_checks controls if downloaded pieces are verified against -the piece hashes in the torrent file or not. The default is false, i.e. -to verify all downloaded data. It may be useful to turn this off for performance -profiling and simulation scenarios. Do not disable the hash check for regular -bittorrent clients.

-

max_suggest_pieces is the max number of suggested piece indices received -from a peer that's remembered. If a peer floods suggest messages, this limit -prevents libtorrent from using too much RAM. It defaults to 10.

-

If drop_skipped_requests is set to true (it defaults to false), piece -requests that have been skipped enough times when piece messages -are received, will be considered lost. Requests are considered skipped -when the returned piece messages are re-ordered compared to the order -of the requests. This was an attempt to get out of dead-locks caused by -BitComet peers silently ignoring some requests. It may cause problems -at high rates, and high level of reordering in the uploading peer, that's -why it's disabled by default.

-

low_prio_disk determines if the disk I/O should use a normal -or low priority policy. This defaults to true, which means that -it's low priority by default. Other processes doing disk I/O will -normally take priority in this mode. This is meant to improve the -overall responsiveness of the system while downloading in the -background. For high-performance server setups, this might not -be desirable.

-

local_service_announce_interval is the time between local -network announces for a torrent. By default, when local service -discovery is enabled a torrent announces itself every 5 minutes. -This interval is specified in seconds.

-

dht_announce_interval is the number of seconds between announcing -torrents to the distributed hash table (DHT). This is specified to -be 15 minutes which is its default.

-

dht_max_torrents is the max number of torrents we will track -in the DHT.

-

udp_tracker_token_expiry is the number of seconds libtorrent -will keep UDP tracker connection tokens around for. This is specified -to be 60 seconds, and defaults to that. The higher this value is, the -fewer packets have to be sent to the UDP tracker. In order for higher -values to work, the tracker needs to be configured to match the -expiration time for tokens.

-

volatile_read_cache, if this is set to true, read cache blocks -that are hit by peer read requests are removed from the disk cache -to free up more space. This is useful if you don't expect the disk -cache to create any cache hits from other peers than the one who -triggered the cache line to be read into the cache in the first place.

-

guided_read_cache enables the disk cache to adjust the size -of a cache line generated by peers to depend on the upload rate -you are sending to that peer. The intention is to optimize the RAM -usage of the cache, to read ahead further for peers that you're -sending faster to.

-

default_cache_min_age is the minimum number of seconds any read -cache line is kept in the cache. This defaults to one second but -may be greater if guided_read_cache is enabled. Having a lower -bound on the time a cache line stays in the cache is an attempt -to avoid swapping the same pieces in and out of the cache in case -there is a shortage of spare cache space.

-

num_optimistic_unchoke_slots is the number of optimistic unchoke -slots to use. It defaults to 0, which means automatic. Having a higher -number of optimistic unchoke slots mean you will find the good peers -faster but with the trade-off to use up more bandwidth. When this is -set to 0, libtorrent opens up 20% of your allowed upload slots as -optimistic unchoke slots.

-

no_atime_storage this is a linux-only option and passes in the -O_NOATIME to open() when opening files. This may lead to -some disk performance improvements.

-

default_est_reciprocation_rate is the assumed reciprocation rate -from peers when using the BitTyrant choker. This defaults to 14 kiB/s. -If set too high, you will over-estimate your peers and be more altruistic -while finding the true reciprocation rate, if it's set too low, you'll -be too stingy and waste finding the true reciprocation rate.

-

increase_est_reciprocation_rate specifies how many percent the -extimated reciprocation rate should be increased by each unchoke -interval a peer is still choking us back. This defaults to 20%. -This only applies to the BitTyrant choker.

-

decrease_est_reciprocation_rate specifies how many percent the -estimated reciprocation rate should be decreased by each unchoke -interval a peer unchokes us. This default to 3%. -This only applies to the BitTyrant choker.

-

incoming_starts_queued_torrents defaults to false. If a torrent -has been paused by the auto managed feature in libtorrent, i.e. -the torrent is paused and auto managed, this feature affects whether -or not it is automatically started on an incoming connection. The -main reason to queue torrents, is not to make them unavailable, but -to save on the overhead of announcing to the trackers, the DHT and to -avoid spreading one's unchoke slots too thin. If a peer managed to -find us, even though we're no in the torrent anymore, this setting -can make us start the torrent and serve it.

-

When report_true_downloaded is true, the &downloaded= argument -sent to trackers will include redundant downloaded bytes. It defaults -to false, which means redundant bytes are not reported to the tracker.

-

strict_end_game_mode defaults to true, and controls when a block -may be requested twice. If this is true, a block may only be requested -twice when there's ay least one request to every piece that's left to -download in the torrent. This may slow down progress on some pieces -sometimes, but it may also avoid downloading a lot of redundant bytes. -If this is false, libtorrent attempts to use each peer connection -to its max, by always requesting something, even if it means requesting -something that has been requested from another peer already.

-

if broadcast_lsd is set to true, the local peer discovery -(or Local Service Discovery) will not only use IP multicast, but also -broadcast its messages. This can be useful when running on networks -that don't support multicast. Since broadcast messages might be -expensive and disruptive on networks, only every 8th announce uses -broadcast.

-

enable_outgoing_utp, enable_incoming_utp, enable_outgoing_tcp, -enable_incoming_tcp all determines if libtorrent should attempt to make -outgoing connections of the specific type, or allow incoming connection. By -default all of them are enabled.

-

ignore_resume_timestamps determines if the storage, when loading -resume data files, should verify that the file modification time -with the timestamps in the resume data. This defaults to false, which -means timestamps are taken into account, and resume data is less likely -to accepted (torrents are more likely to be fully checked when loaded). -It might be useful to set this to true if your network is faster than your -disk, and it would be faster to redownload potentially missed pieces than -to go through the whole storage to look for them.

-

no_recheck_incomplete_resume determines if the storage should check -the whole files when resume data is incomplete or missing or whether -it should simply assume we don't have any of the data. By default, this -is determined by the existance of any of the files. By setting this setting -to true, the files won't be checked, but will go straight to download -mode.

-

anonymous_mode defaults to false. When set to true, the client tries -to hide its identity to a certain degree. The peer-ID will no longer -include the client's fingerprint. The user-agent will be reset to an -empty string.

-

If you're using I2P, it might make sense to enable anonymous mode.

-

force_proxy disables any communication that's not going over a proxy. -Enabling this requires a proxy to be configured as well, see set_proxy_settings. -The listen sockets are closed, and incoming connections will -only be accepted through a SOCKS5 or I2P proxy (if a peer proxy is set up and -is run on the same machine as the tracker proxy). This setting also -disabled peer country lookups, since those are done via DNS lookups that -aren't supported by proxies.

-

tick_interval specifies the number of milliseconds between internal -ticks. This is the frequency with which bandwidth quota is distributed to -peers. It should not be more than one second (i.e. 1000 ms). Setting this -to a low value (around 100) means higher resolution bandwidth quota distribution, -setting it to a higher value saves CPU cycles.

-

share_mode_target specifies the target share ratio for share mode torrents. -This defaults to 3, meaning we'll try to upload 3 times as much as we download. -Setting this very high, will make it very conservative and you might end up -not downloading anything ever (and not affecting your share ratio). It does -not make any sense to set this any lower than 2. For instance, if only 3 peers -need to download the rarest piece, it's impossible to download a single piece -and upload it more than 3 times. If the share_mode_target is set to more than 3, -nothing is downloaded.

-

upload_rate_limit, download_rate_limit, local_upload_rate_limit -and local_download_rate_limit sets the session-global limits of upload -and download rate limits, in bytes per second. The local rates refer to peers -on the local network. By default peers on the local network are not rate limited.

-

These rate limits are only used for local peers (peers within the same subnet as -the client itself) and it is only used when session_settings::ignore_limits_on_local_network -is set to true (which it is by default). These rate limits default to unthrottled, -but can be useful in case you want to treat local peers preferentially, but not -quite unthrottled.

-

A value of 0 means unlimited.

-

dht_upload_rate_limit sets the rate limit on the DHT. This is specified in -bytes per second and defaults to 4000. For busy boxes with lots of torrents -that requires more DHT traffic, this should be raised.

-

unchoke_slots_limit is the max number of unchoked peers in the session. The -number of unchoke slots may be ignored depending on what choking_algorithm -is set to. A value of -1 means infinite.

-

half_open_limit sets the maximum number of half-open connections -libtorrent will have when connecting to peers. A half-open connection is one -where connect() has been called, but the connection still hasn't been established -(nor failed). Windows XP Service Pack 2 sets a default, system wide, limit of -the number of half-open connections to 10. So, this limit can be used to work -nicer together with other network applications on that system. The default is -to have no limit, and passing -1 as the limit, means to have no limit. When -limiting the number of simultaneous connection attempts, peers will be put in -a queue waiting for their turn to get connected.

-

connections_limit sets a global limit on the number of connections -opened. The number of connections is set to a hard minimum of at least two per -torrent, so if you set a too low connections limit, and open too many torrents, -the limit will not be met.

-

utp_target_delay is the target delay for uTP sockets in milliseconds. A high -value will make uTP connections more aggressive and cause longer queues in the upload -bottleneck. It cannot be too low, since the noise in the measurements would cause -it to send too slow. The default is 50 milliseconds.

-

utp_gain_factor is the number of bytes the uTP congestion window can increase -at the most in one RTT. This defaults to 300 bytes. If this is set too high, -the congestion controller reacts too hard to noise and will not be stable, if it's -set too low, it will react slow to congestion and not back off as fast.

-

utp_min_timeout is the shortest allowed uTP socket timeout, specified in milliseconds. -This defaults to 500 milliseconds. The timeout depends on the RTT of the connection, but -is never smaller than this value. A connection times out when every packet in a window -is lost, or when a packet is lost twice in a row (i.e. the resent packet is lost as well).

-

The shorter the timeout is, the faster the connection will recover from this situation, -assuming the RTT is low enough.

-

utp_syn_resends is the number of SYN packets that are sent (and timed out) before -giving up and closing the socket.

-

utp_num_resends is the number of times a packet is sent (and lossed or timed out) -before giving up and closing the connection.

-

utp_connect_timeout is the number of milliseconds of timeout for the initial SYN -packet for uTP connections. For each timed out packet (in a row), the timeout is doubled.

-

utp_dynamic_sock_buf controls if the uTP socket manager is allowed to increase -the socket buffer if a network interface with a large MTU is used (such as loopback -or ethernet jumbo frames). This defaults to true and might improve uTP throughput. -For RAM constrained systems, disabling this typically saves around 30kB in user space -and probably around 400kB in kernel socket buffers (it adjusts the send and receive -buffer size on the kernel socket, both for IPv4 and IPv6).

-

utp_loss_multiplier controls how the congestion window is changed when a packet -loss is experienced. It's specified as a percentage multiplier for cwnd. By default -it's set to 50 (i.e. cut in half). Do not change this value unless you know what -you're doing. Never set it higher than 100.

-

The mixed_mode_algorithm determines how to treat TCP connections when there are -uTP connections. Since uTP is designed to yield to TCP, there's an inherent problem -when using swarms that have both TCP and uTP connections. If nothing is done, uTP -connections would often be starved out for bandwidth by the TCP connections. This mode -is prefer_tcp. The peer_proportional mode simply looks at the current throughput -and rate limits all TCP connections to their proportional share based on how many of -the connections are TCP. This works best if uTP connections are not rate limited by -the global rate limiter (which they aren't by default).

-

rate_limit_utp determines if uTP connections should be throttled by the global rate -limiter or not. By default they are.

-

listen_queue_size is the value passed in to listen() for the listen socket. -It is the number of outstanding incoming connections to queue up while we're not -actively waiting for a connection to be accepted. The default is 5 which should -be sufficient for any normal client. If this is a high performance server which -expects to receive a lot of connections, or used in a simulator or test, it -might make sense to raise this number. It will not take affect until listen_on() -is called again (or for the first time).

-

if announce_double_nat is true, the &ip= argument in tracker requests -(unless otherwise specified) will be set to the intermediate IP address, if the -user is double NATed. If ther user is not double NATed, this option has no affect.

-

torrent_connect_boost is the number of peers to try to connect to immediately -when the first tracker response is received for a torrent. This is a boost to -given to new torrents to accelerate them starting up. The normal connect scheduler -is run once every second, this allows peers to be connected immediately instead -of waiting for the session tick to trigger connections.

-

seeding_outgoing_connections determines if seeding (and finished) torrents -should attempt to make outgoing connections or not. By default this is true. It -may be set to false in very specific applications where the cost of making -outgoing connections is high, and there are no or small benefits of doing so. -For instance, if no nodes are behind a firewall or a NAT, seeds don't need to -make outgoing connections.

-

if no_connect_privileged_ports is true (which is the default), libtorrent -will not connect to any peers on priviliged ports (<= 1023). This can mitigate -using bittorrent swarms for certain DDoS attacks.

-

alert_queue_size is the maximum number of alerts queued up internally. If -alerts are not popped, the queue will eventually fill up to this level. This -defaults to 1000.

-

max_metadata_size is the maximum allowed size (in bytes) to be received -by the metadata extension, i.e. magnet links. It defaults to 1 MiB.

-

smooth_connects is true by default, which means the number of connection -attempts per second may be limited to below the connection_speed, in case -we're close to bump up against the limit of number of connections. The intention -of this setting is to more evenly distribute our connection attempts over time, -instead of attempting to connectin in batches, and timing them out in batches.

-

always_send_user_agent defaults to false. When set to true, web connections -will include a user-agent with every request, as opposed to just the first -request in a connection.

-

apply_ip_filter_to_trackers defaults to true. It determines whether the -IP filter applies to trackers as well as peers. If this is set to false, -trackers are exempt from the IP filter (if there is one). If no IP filter -is set, this setting is irrelevant.

-

read_job_every is used to avoid starvation of read jobs in the disk I/O -thread. By default, read jobs are deferred, sorted by physical disk location -and serviced once all write jobs have been issued. In scenarios where the -download rate is enough to saturate the disk, there's a risk the read jobs will -never be serviced. With this setting, every x write job, issued in a row, will -instead pick one read job off of the sorted queue, where x is read_job_every.

-

use_disk_read_ahead defaults to true and will attempt to optimize disk reads -by giving the operating system heads up of disk read requests as they are queued -in the disk job queue. This gives a significant performance boost for seeding.

-

lock_files determines whether or not to lock files which libtorrent is downloading -to or seeding from. This is implemented using fcntl(F_SETLK) on unix systems and -by not passing in SHARE_READ and SHARE_WRITE on windows. This might prevent -3rd party processes from corrupting the files under libtorrent's feet.

-

ssl_listen sets the listen port for SSL connections. If this is set to 0, -no SSL listen port is opened. Otherwise a socket is opened on this port. This -setting is only taken into account when opening the regular listen port, and -won't re-open the listen socket simply by changing this setting.

-

It defaults to port 4433.

-

tracker_backoff determines how aggressively to back off from retrying -failing trackers. This value determines x in the following formula, determining -the number of seconds to wait until the next retry:

-
-delay = 5 + 5 * x / 100 * fails^2
-

It defaults to 250.

-

This setting may be useful to make libtorrent more or less aggressive in hitting -trackers.

-

ban_web_seeds enables banning web seeds. By default, web seeds that send -corrupt data are banned.

-

max_http_recv_buffer_size specifies the max number of bytes to receive into -RAM buffers when downloading stuff over HTTP. Specifically when specifying a -URL to a .torrent file when adding a torrent or when announcing to an HTTP -tracker. The default is 2 MiB.

-

support_share_mode enables or disables the share mode extension. This is -enabled by default.

-

support_merkle_torrents enables or disables the merkle tree torrent support. -This is enabled by default.

-

report_redundant_bytes enables or disables reporting redundant bytes to the tracker. -This is enabled by default.

-

handshake_client_version is the client name advertized in the peer handshake. If -set to an empty string, the user_agent string is used.

-

use_disk_cache_pool enables using a pool allocator for disk cache blocks. This is -disabled by default. Enabling it makes the cache perform better at high throughput. -It also makes the cache less likely and slower at returning memory back to the system -once allocated.

-
-
-
-

pe_settings

-

The pe_settings structure is used to control the settings related -to peer protocol encryption:

-
-struct pe_settings
-{
-        pe_settings();
-
-        enum enc_policy
-        {
-                forced,
-                enabled,
-                disabled
-        };
-
-        enum enc_level
-        {
-                plaintext,
-                rc4,
-                both
-        };
-
-        enc_policy out_enc_policy;
-        enc_policy in_enc_policy;
-        enc_level allowed_enc_level;
-        bool prefer_rc4;
-};
-
-

in_enc_policy and out_enc_policy control the settings for incoming -and outgoing connections respectively. The settings for these are:

-
-
    -
  • forced - Only encrypted connections are allowed. Incoming connections -that are not encrypted are closed and if the encrypted outgoing connection -fails, a non-encrypted retry will not be made.
  • -
  • enabled - encrypted connections are enabled, but non-encrypted -connections are allowed. An incoming non-encrypted connection will -be accepted, and if an outgoing encrypted connection fails, a non- -encrypted connection will be tried.
  • -
  • disabled - only non-encrypted connections are allowed.
  • -
-
-

allowed_enc_level determines the encryption level of the -connections. This setting will adjust which encryption scheme is -offered to the other peer, as well as which encryption scheme is -selected by the client. The settings are:

-
-
    -
  • plaintext - only the handshake is encrypted, the bulk of the traffic -remains unchanged.
  • -
  • rc4 - the entire stream is encrypted with RC4
  • -
  • both - both RC4 and plaintext connections are allowed.
  • -
-
-

prefer_rc4 can be set to true if you want to prefer the RC4 encrypted stream.

-
-
-

proxy_settings

-

The proxy_settings structs contains the information needed to -direct certain traffic to a proxy.

-
-
-struct proxy_settings
-{
-        proxy_settings();
-
-        std::string hostname;
-        int port;
-
-        std::string username;
-        std::string password;
-
-        enum proxy_type
-        {
-                none,
-                socks4,
-                socks5,
-                socks5_pw,
-                http,
-                http_pw
-        };
-
-        proxy_type type;
-        bool proxy_hostnames;
-        bool proxy_peer_connections;
-};
-
-
-

hostname is the name or IP of the proxy server. port is the -port number the proxy listens to. If required, username and password -can be set to authenticate with the proxy.

-

The type tells libtorrent what kind of proxy server it is. The following -options are available:

-
-
    -
  • none - This is the default, no proxy server is used, all other fields -are ignored.
  • -
  • socks4 - The server is assumed to be a SOCKS4 server that -requires a username.
  • -
  • socks5 - The server is assumed to be a SOCKS5 server (RFC 1928) that -does not require any authentication. The username and password are ignored.
  • -
  • socks5_pw - The server is assumed to be a SOCKS5 server that supports -plain text username and password authentication (RFC 1929). The username -and password specified may be sent to the proxy if it requires.
  • -
  • http - The server is assumed to be an HTTP proxy. If the transport used -for the connection is non-HTTP, the server is assumed to support the -CONNECT method. i.e. for web seeds and HTTP trackers, a plain proxy will -suffice. The proxy is assumed to not require authorization. The username -and password will not be used.
  • -
  • http_pw - The server is assumed to be an HTTP proxy that requires -user authorization. The username and password will be sent to the proxy.
  • -
-
-

proxy_hostnames defaults to true. It means that hostnames should be -attempted to be resolved through the proxy instead of using the local DNS -service. This is only supported by SOCKS5 and HTTP.

-

proxy_peer_connections determines whether or not to excempt peer and -web seed connections from using the proxy. This defaults to true, i.e. peer -connections are proxied by default.

-
-
-

ip_filter

-

The ip_filter class is a set of rules that uniquely categorizes all -ip addresses as allowed or disallowed. The default constructor creates -a single rule that allows all addresses (0.0.0.0 - 255.255.255.255 for -the IPv4 range, and the equivalent range covering all addresses for the -IPv6 range).

-
-
-template <class Addr>
-struct ip_range
-{
-        Addr first;
-        Addr last;
-        int flags;
-};
-
-class ip_filter
-{
-public:
-        enum access_flags { blocked = 1 };
-
-        ip_filter();
-        void add_rule(address first, address last, int flags);
-        int access(address const& addr) const;
-
-        typedef boost::tuple<std::vector<ip_range<address_v4> >
-                , std::vector<ip_range<address_v6> > > filter_tuple_t;
-
-        filter_tuple_t export_filter() const;
-};
-
-
-
-

ip_filter()

-
-
-ip_filter()
-
-
-

Creates a default filter that doesn't filter any address.

-

postcondition: -access(x) == 0 for every x

-
-
-

add_rule()

-
-
-void add_rule(address first, address last, int flags);
-
-
-

Adds a rule to the filter. first and last defines a range of -ip addresses that will be marked with the given flags. The flags -can currently be 0, which means allowed, or ip_filter::blocked, which -means disallowed.

-

precondition: -first.is_v4() == last.is_v4() && first.is_v6() == last.is_v6()

-

postcondition: -access(x) == flags for every x in the range [first, last]

-

This means that in a case of overlapping ranges, the last one applied takes -precedence.

-
-
-

access()

-
-
-int access(address const& addr) const;
-
-
-

Returns the access permissions for the given address (addr). The permission -can currently be 0 or ip_filter::blocked. The complexity of this operation -is O(log n), where n is the minimum number of non-overlapping ranges to describe -the current filter.

-
-
-

export_filter()

-
-
-boost::tuple<std::vector<ip_range<address_v4> >
-        , std::vector<ip_range<address_v6> > > export_filter() const;
-
-
-

This function will return the current state of the filter in the minimum number of -ranges possible. They are sorted from ranges in low addresses to high addresses. Each -entry in the returned vector is a range with the access control specified in its -flags field.

-

The return value is a tuple containing two range-lists. One for IPv4 addresses -and one for IPv6 addresses.

-
-
-
-

big_number

-

Both the peer_id and sha1_hash types are typedefs of the class -big_number. It represents 20 bytes of data. Its synopsis follows:

-
-class big_number
-{
-public:
-        bool operator==(const big_number& n) const;
-        bool operator!=(const big_number& n) const;
-        bool operator<(const big_number& n) const;
-
-        const unsigned char* begin() const;
-        const unsigned char* end() const;
-
-        unsigned char* begin();
-        unsigned char* end();
-};
-
-

The iterators gives you access to individual bytes.

-
-
-

bitfield

-

The bitfiled type stores any number of bits as a bitfield in an array.

-
-class bitfield
-{
-        bitfield();
-        bitfield(int bits);
-        bitfield(int bits, bool val);
-        bitfield(char const* bytes, int bits);
-        bitfield(bitfield const& rhs);
-
-        void borrow_bytes(char* bytes, int bits);
-        ~bitfield();
-
-        void assign(char const* bytes, int bits);
-
-        bool operator[](int index) const;
-
-        bool get_bit(int index) const;
-
-        void clear_bit(int index);
-        void set_bit(int index);
-
-        std::size_t size() const;
-        bool empty() const;
-
-        char const* bytes() const;
-
-        bitfield& operator=(bitfield const& rhs);
-
-        int count() const;
-
-        typedef const_iterator;
-        const_iterator begin() const;
-        const_iterator end() const;
-
-        void resize(int bits, bool val);
-        void set_all();
-        void clear_all();
-        void resize(int bits);
-};
-
-
-
-

hasher

-

This class creates sha1-hashes. Its declaration looks like this:

-
-class hasher
-{
-public:
-        hasher();
-        hasher(char const* data, unsigned int len);
-
-        void update(char const* data, unsigned int len);
-        sha1_hash final();
-        void reset();
-};
-
-

You use it by first instantiating it, then call update() to feed it -with data. i.e. you don't have to keep the entire buffer of which you want to -create the hash in memory. You can feed the hasher parts of it at a time. When -You have fed the hasher with all the data, you call final() and it -will return the sha1-hash of the data.

-

The constructor that takes a char const* and an integer will construct the -sha1 context and feed it the data passed in.

-

If you want to reuse the hasher object once you have created a hash, you have to -call reset() to reinitialize it.

-

The sha1-algorithm used was implemented by Steve Reid and released as public domain. -For more info, see src/sha1.cpp.

-
-
-

fingerprint

-

The fingerprint class represents information about a client and its version. It is used -to encode this information into the client's peer id.

-

This is the class declaration:

-
-struct fingerprint
-{
-        fingerprint(const char* id_string, int major, int minor
-                , int revision, int tag);
-
-        std::string to_string() const;
-
-        char name[2];
-        char major_version;
-        char minor_version;
-        char revision_version;
-        char tag_version;
-
-};
-
-

The constructor takes a char const* that should point to a string constant containing -exactly two characters. These are the characters that should be unique for your client. Make -sure not to clash with anybody else. Here are some taken id's:

- ---- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
id charsclient
'AZ'Azureus
'LT'libtorrent (default)
'BX'BittorrentX
'MT'Moonlight Torrent
'TS'Torrent Storm
'SS'Swarm Scope
'XT'Xan Torrent
-

There's currently an informal directory of client id's here.

-

The major, minor, revision and tag parameters are used to identify the -version of your client. All these numbers must be within the range [0, 9].

-

to_string() will generate the actual string put in the peer-id, and return it.

-
-
-

UPnP and NAT-PMP

-

The upnp and natpmp classes contains the state for all UPnP and NAT-PMP mappings, -by default 1 or two mappings are made by libtorrent, one for the listen port and one -for the DHT port (UDP).

-
-class upnp
-{
-public:
-
-        enum protocol_type { none = 0, udp = 1, tcp = 2 };
-        int add_mapping(protocol_type p, int external_port, int local_port);
-        void delete_mapping(int mapping_index);
-
-        void discover_device();
-        void close();
-
-        std::string router_model();
-};
-
-class natpmp
-{
-public:
-
-        enum protocol_type { none = 0, udp = 1, tcp = 2 };
-        int add_mapping(protocol_type p, int external_port, int local_port);
-        void delete_mapping(int mapping_index);
-
-        void close();
-        void rebind(address const& listen_interface);
-};
-
-

discover_device(), close() and rebind() are for internal uses and should -not be called directly by clients.

-
-

add_mapping()

-
-
-int add_mapping(protocol_type p, int external_port, int local_port);
-
-
-

Attempts to add a port mapping for the specified protocol. Valid protocols are -upnp::tcp and upnp::udp for the UPnP class and natpmp::tcp and -natpmp::udp for the NAT-PMP class.

-

external_port is the port on the external address that will be mapped. This -is a hint, you are not guaranteed that this port will be available, and it may -end up being something else. In the portmap_alert notification, the actual -external port is reported.

-

local_port is the port in the local machine that the mapping should forward -to.

-

The return value is an index that identifies this port mapping. This is used -to refer to mappings that fails or succeeds in the portmap_error_alert and -portmap_alert respectively. If The mapping fails immediately, the return value -is -1, which means failure. There will not be any error alert notification for -mappings that fail with a -1 return value.

-
-
-

delete_mapping()

-
-
-void delete_mapping(int mapping_index);
-
-
-

This function removes a port mapping. mapping_index is the index that refers -to the mapping you want to remove, which was returned from add_mapping().

-
-
-

router_model()

-
-
-std::string router_model();
-
-
-

This is only available for UPnP routers. If the model is advertized by -the router, it can be queried through this function.

-
-
-
-

free functions

-
-

identify_client()

-
-
-std::string identify_client(peer_id const& id);
-
-
-

This function is declared in the header <libtorrent/identify_client.hpp>. It can can be used -to extract a string describing a client version from its peer-id. It will recognize most clients -that have this kind of identification in the peer-id.

-
-
-

client_fingerprint()

-
-
-boost::optional<fingerprint> client_fingerprint(peer_id const& p);
-
-
-

Returns an optional fingerprint if any can be identified from the peer id. This can be used -to automate the identification of clients. It will not be able to identify peers with non- -standard encodings. Only Azureus style, Shadow's style and Mainline style. This function is -declared in the header <libtorrent/identify_client.hpp>.

-
-
-

lazy_bdecode()

-
-
-int lazy_bdecode(char const* start, char const* end, lazy_entry& ret
-        , error_code& ec, int* error_pos = 0, int depth_limit = 1000
-        , int item_limit = 1000000);
-
-
-

This function decodes bencoded data.

-

Whenever possible, lazy_bdecode() should be preferred over bdecode(). -It is more efficient and more secure. It supports having constraints on the -amount of memory is consumed by the parser.

-

lazy refers to the fact that it doesn't copy any actual data out of the -bencoded buffer. It builds a tree of lazy_entry which has pointers into -the bencoded buffer. This makes it very fast and efficient. On top of that, -it is not recursive, which saves a lot of stack space when parsing deeply -nested trees. However, in order to protect against potential attacks, the -depth_limit and item_limit control how many levels deep the tree is -allowed to get. With recursive parser, a few thousand levels would be enough -to exhaust the threads stack and terminate the process. The item_limit -protects against very large structures, not necessarily deep. Each bencoded -item in the structure causes the parser to allocate some amount of memory, -this memory is constant regardless of how much data actually is stored in -the item. One potential attack is to create a bencoded list of hundreds of -thousands empty strings, which would cause the parser to allocate a significant -amount of memory, perhaps more than is available on the machine, and effectively -provide a denial of service. The default item limit is set as a reasonable -upper limit for desktop computers. Very few torrents have more items in them. -The limit corresponds to about 25 MB, which might be a bit much for embedded -systems.

-

start and end defines the bencoded buffer to be decoded. ret is -the lazy_entry which is filled in with the whole decoded tree. ec -is a reference to an error_code which is set to describe the error encountered -in case the function fails. error_pos is an optional pointer to an int, -which will be set to the byte offset into the buffer where an error occurred, -in case the function fails.

-
-
-

bdecode() bencode()

-
-
-template<class InIt> entry bdecode(InIt start, InIt end);
-template<class OutIt> void bencode(OutIt out, const entry& e);
-
-
-

These functions will encode data to bencoded or decode bencoded data.

-

If possible, lazy_bdecode() should be preferred over bdecode().

-

The entry class is the internal representation of the bencoded data -and it can be used to retrieve information, an entry can also be build by -the program and given to bencode() to encode it into the OutIt -iterator.

-

The OutIt and InIt are iterators -(InputIterator and OutputIterator respectively). They -are templates and are usually instantiated as ostream_iterator, -back_insert_iterator or istream_iterator. These -functions will assume that the iterator refers to a character -(char). So, if you want to encode entry e into a buffer -in memory, you can do it like this:

-
-std::vector<char> buffer;
-bencode(std::back_inserter(buf), e);
-
-

If you want to decode a torrent file from a buffer in memory, you can do it like this:

-
-std::vector<char> buffer;
-// ...
-entry e = bdecode(buf.begin(), buf.end());
-
-

Or, if you have a raw char buffer:

-
-const char* buf;
-// ...
-entry e = bdecode(buf, buf + data_size);
-
-

Now we just need to know how to retrieve information from the entry.

-

If bdecode() encounters invalid encoded data in the range given to it -it will throw libtorrent_exception.

-
-
-

add_magnet_uri()

-

deprecated

-
-
-torrent_handle add_magnet_uri(session& ses, std::string const& uri
-        add_torrent_params p);
-torrent_handle add_magnet_uri(session& ses, std::string const& uri
-        add_torrent_params p, error_code& ec);
-
-
-

This function parses the magnet URI (uri) as a bittorrent magnet link, -and adds the torrent to the specified session (ses). It returns the -handle to the newly added torrent, or an invalid handle in case parsing -failed. To control some initial settings of the torrent, sepcify those in -the add_torrent_params, p. See `async_add_torrent() add_torrent()`_.

-

The overload that does not take an error_code throws an exception on -error and is not available when building without exception support.

-

A simpler way to add a magnet link to a session is to pass in the -link through add_torrent_params::url argument to session::add_torrent().

-

For more information about magnet links, see magnet links.

-
-
-

parse_magnet_uri()

-
-
-void parse_magnet_uri(std::string const& uri, add_torrent_params& p, error_code& ec);
-
-
-

This function parses out information from the magnet link and populates the -add_torrent_params object.

-
-
-

make_magnet_uri()

-
-
-std::string make_magnet_uri(torrent_handle const& handle);
-
-
-

Generates a magnet URI from the specified torrent. If the torrent -handle is invalid, an empty string is returned.

-

For more information about magnet links, see magnet links.

-
-
-
-

alerts

-

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 -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 a bitmask with the following bits:

- ---- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
error_notification

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_notificationEnables alerts when peers send invalid requests, get banned or -snubbed.
port_mapping_notificationEnables alerts for port mapping events. For NAT-PMP and UPnP.
storage_notificationEnables alerts for events related to the storage. File errors and -synchronization events for moving the storage, renaming files etc.
tracker_notificationEnables all tracker events. Includes announcing to trackers, -receiving responses, warnings and errors.
debug_notificationLow level alerts for when peers are connected and disconnected.
status_notificationEnables alerts for when a torrent or the session changes state.
progress_notificationAlerts for when blocks are requested and completed. Also when -pieces are completed.
ip_block_notificationAlerts when a peer is blocked by the ip blocker or port blocker.
performance_warningAlerts when some limit is reached that might limit the download -or upload rate.
stats_notificationIf 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.
dht_notificationAlerts on events in the DHT node. For incoming searches or -bootstrapping being done etc.
rss_notificationAlerts 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_categoriesThe full bitmask, representing all available categories.
-

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

-

When you get an alert, you can use alert_cast<> to attempt to cast the pointer to a -more specific alert type, to be queried for more information about the alert. alert_cast -has the followinf signature:

-
-template <T> T* alert_cast(alert* a);
-template <T> T const* alert_cast(alert const* a);
-
-

You can also use a alert dispatcher mechanism that's available in libtorrent.

-

All alert types are defined in the <libtorrent/alert_types.hpp> header file.

-

The alert class is the base class that specific messages are derived from. This -is its synopsis:

-
-class alert
-{
-public:
-
-        enum category_t
-        {
-                error_notification = implementation defined,
-                peer_notification = implementation defined,
-                port_mapping_notification = implementation defined,
-                storage_notification = implementation defined,
-                tracker_notification = implementation defined,
-                debug_notification = implementation defined,
-                status_notification = implementation defined,
-                progress_notification = implementation defined,
-                ip_block_notification = implementation defined,
-                performance_warning = implementation defined,
-                dht_notification = implementation defined,
-                stats_notification = implementation defined,
-                rss_notification = implementation defined,
-
-                all_categories = implementation defined
-        };
-
-        ptime timestamp() const;
-
-        virtual ~alert();
-
-        virtual int type() const = 0;
-        virtual std::string message() const = 0;
-        virtual char const* what() const = 0;
-        virtual int category() const = 0;
-        virtual bool discardable() const;
-        virtual std::auto_ptr<alert> clone() const = 0;
-};
-
-

type() 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() returns a string literal describing the type of the alert. It does -not include any information that might be bundled with the alert.

-

category() returns a bitmask specifying which categories this alert belong to.

-

clone() returns a pointer to a copy of the alert.

-

discardable() 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.

-

message() 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.

-

There's another alert base class that most alerts derives from, all the -alerts that are generated for a specific torrent are derived from:

-
-struct torrent_alert: alert
-{
-        // ...
-        torrent_handle handle;
-};
-
-

There's also a base class for all alerts referring to tracker events:

-
-struct tracker_alert: torrent_alert
-{
-        // ...
-        std::string url;
-};
-
-

The specific alerts are:

-
-

torrent_added_alert

-

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
-{
-        // ...
-};
-
-
-
-

add_torrent_alert

-

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
-{
-        // ...
-        add_torrent_params params;
-        error_code error;
-};
-
-

params is 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 is set to the error, if one occurred while adding the torrent.

-
-
-

torrent_removed_alert

-

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
-{
-        // ...
-        sha1_hash info_hash;
-};
-
-
-
-

read_piece_alert

-

This alert is posted when the asynchronous read operation initiated by -a call to 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
-{
-        // ...
-        error_code ec;
-        boost::shared_ptr<char> buffer;
-        int piece;
-        int size;
-};
-
-
-
-

external_ip_alert

-

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
-{
-        // ...
-        address external_address;
-};
-
-
-
-

listen_failed_alert

-

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
-{
-        // ...
-        tcp::endpoint endpoint;
-        error_code error;
-};
-
-
-
-

listen_succeeded_alert

-

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
-{
-        // ...
-        tcp::endpoint endpoint;
-};
-
-
-
-

portmap_error_alert

-

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.

-

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.

-
-struct portmap_error_alert: alert
-{
-        // ...
-        int mapping;
-        int type;
-        error_code error;
-};
-
-
-
-

portmap_alert

-

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.

-

mapping refers to the mapping index of the port map that failed, i.e. -the index returned from add_mapping().

-

external_port is the external port allocated for the mapping.

-

type is 0 for NAT-PMP and 1 for UPnP.

-
-struct portmap_alert: alert
-{
-        // ...
-        int mapping;
-        int external_port;
-        int map_type;
-};
-
-
-
-

portmap_log_alert

-

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
-{
-        //...
-        int map_type;
-        std::string msg;
-};
-
-
-
-

file_error_alert

-

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

-

file is the path to the file that was accessed when the error occurred.

-

error is the error code describing the error.

-
-struct file_error_alert: torrent_alert
-{
-        // ...
-        std::string file;
-        error_code error;
-};
-
-
-
-

torrent_error_alert

-

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

-
-struct torrent_error_alert: torrent_alert
-{
-        // ...
-        error_code error;
-};
-
-

The error specifies which error the torrent encountered.

-
-
-

file_renamed_alert

-

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

-
-struct file_renamed_alert: torrent_alert
-{
-        // ...
-        std::string name;
-        int index;
-};
-
-

The index member refers to the index of the file that was renamed, -name is the new name of the file.

-
-
-

file_rename_failed_alert

-

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
-{
-        // ...
-        int index;
-        error_code error;
-};
-
-

The index member refers to the index of the file that was supposed to be renamed, -error is the error code returned from the filesystem.

-
-
-

tracker_announce_alert

-

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
-{
-        // ...
-        int event;
-};
-
-

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

-
    -
  1. None
  2. -
  3. Completed
  4. -
  5. Started
  6. -
  7. Stopped
  8. -
-
-
-

tracker_error_alert

-

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
-{
-        // ...
-        int times_in_row;
-        int status_code;
-};
-
-
-
-

tracker_reply_alert

-

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
-{
-        // ...
-        int num_peers;
-};
-
-

The 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.

-
-
-

tracker_warning_alert

-

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. The msg string in the alert contains the warning message from -the tracker.

-
-struct tracker_warning_alert: tracker_alert
-{
-        // ...
-        std::string msg;
-};
-
-
-
-

scrape_reply_alert

-

This alert is generated when a scrape request succeeds. incomplete -and complete is the data returned in the scrape response. These numbers -may be -1 if the reponse was malformed.

-
-struct scrape_reply_alert: tracker_alert
-{
-        // ...
-        int incomplete;
-        int complete;
-};
-
-
-
-

scrape_failed_alert

-

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. msg contains a message describing the error.

-
-struct scrape_failed_alert: tracker_alert
-{
-        // ...
-        std::string msg;
-};
-
-
-
-

url_seed_alert

-

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

-

It contains url to the HTTP seed that failed along with an error message.

-
-struct url_seed_alert: torrent_alert
-{
-        // ...
-        std::string url;
-};
-
-
-
-

hash_failed_alert

-

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
-{
-        // ...
-        int piece_index;
-};
-
-
-
-

peer_alert

-

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
-{
-        // ...
-        tcp::endpoint ip;
-        peer_id pid;
-};
-
-
-
-

peer_connect_alert

-

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

-
-struct peer_connect_alert: peer_alert
-{
-        // ...
-};
-
-
-
-

peer_ban_alert

-

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
-{
-        // ...
-};
-
-
-
-

peer_snubbed_alert

-

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

-
-struct peer_snubbed_alert: peer_alert
-{
-        // ...
-};
-
-
-
-

peer_unsnubbed_alert

-

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
-{
-        // ...
-};
-
-
-
-

peer_error_alert

-

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.

-

The error_code tells you what error caused this alert.

-
-struct peer_error_alert: peer_alert
-{
-        // ...
-        error_code error;
-};
-
-
-
-

peer_connected_alert

-

This alert is generated when a peer is connected.

-
-struct peer_connected_alert: peer_alert
-{
-        // ...
-};
-
-
-
-

peer_disconnected_alert

-

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

-

The error_code tells you what error caused peer to disconnect.

-
-struct peer_disconnected_alert: peer_alert
-{
-        // ...
-        error_code error;
-};
-
-
-
-

invalid_request_alert

-

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.

-
-struct invalid_request_alert: peer_alert
-{
-        // ...
-        peer_request request;
-};
-
-
-struct peer_request
-{
-        int piece;
-        int start;
-        int length;
-        bool operator==(peer_request const& r) const;
-};
-
-

The peer_request contains the values the client sent in its request message. piece is -the index of the piece it want data from, start is the offset within the piece where the data -should be read, and length is the amount of data it wants.

-
-
-

request_dropped_alert

-

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

-
-struct request_dropped_alert: peer_alert
-{
-        // ...
-        int block_index;
-        int piece_index;
-};
-
-
-
-

block_timeout_alert

-

This alert is generated when a block request times out.

-
-struct block_timeout_alert: peer_alert
-{
-        // ...
-        int block_index;
-        int piece_index;
-};
-
-
-
-

block_finished_alert

-

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

-
-struct block_finished_alert: peer_alert
-{
-        // ...
-        int block_index;
-        int piece_index;
-};
-
-
-
-

lsd_peer_alert

-

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
-{
-        // ...
-};
-
-
-
-

file_completed_alert

-

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
-{
-        // ...
-        int index;
-};
-
-

The index member refers to the index of the file that completed.

-
-
-

block_downloading_alert

-

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

-
-struct block_downloading_alert: peer_alert
-{
-        // ...
-        int block_index;
-        int piece_index;
-};
-
-
-
-

unwanted_block_alert

-

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

-
-struct unwanted_block_alert: peer_alert
-{
-        // ...
-        int block_index;
-        int piece_index;
-};
-
-
-
-

torrent_delete_failed_alert

-

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

-

The error_code tells you why it failed.

-
-struct torrent_delete_failed_alert: torrent_alert
-{
-        // ...
-        error_code error;
-};
-
-
-
-

torrent_deleted_alert

-

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
-{
-        // ...
-        sha1_hash info_hash;
-};
-
-
-
-

torrent_finished_alert

-

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.

-

There are no additional data members in this alert.

-
-
-

performance_alert

-

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
-{
-        // ...
-
-        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,
-                too_few_outgoing_ports
-        };
-
-        performance_warning_t warning_code;
-};
-
-
-
outstanding_disk_buffer_limit_reached
-
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
-
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
-
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
-
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
-

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
-
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
-
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.
-
too_few_outgoing_ports
-
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.
-
-
-
-

state_changed_alert

-

Generated whenever a torrent changes its state.

-
-struct state_changed_alert: torrent_alert
-{
-        // ...
-
-        torrent_status::state_t state;
-        torrent_status::state_t prev_state;
-};
-
-

state is the new state of the torrent. prev_state is the previous state.

-
-
-

metadata_failed_alert

-

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.

-

There are no additional data members in this alert.

-
-
-

metadata_received_alert

-

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);
-        }
-}
-
-
-
-

fastresume_rejected_alert

-

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
-{
-        // ...
-        error_code error;
-};
-
-
-
-

peer_blocked_alert

-

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)
  • -
-

The ip member is the address that was blocked.

-
-struct peer_blocked_alert: torrent_alert
-{
-        // ...
-        address ip;
-};
-
-
-
-

storage_moved_alert

-

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
-{
-        // ...
-        std::string path;
-};
-
-
-
-

storage_moved_failed_alert

-

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
-{
-        // ...
-        error_code error;
-};
-
-
-
-

torrent_paused_alert

-

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.

-

There are no additional data members in this alert.

-
-
-

torrent_resumed_alert

-

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.

-

There are no additional data members in this alert.

-
-
-

save_resume_data_alert

-

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. -The resume_data member points to the resume data.

-
-struct save_resume_data_alert: torrent_alert
-{
-        // ...
-        boost::shared_ptr<entry> resume_data;
-};
-
-
-
-

save_resume_data_failed_alert

-

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
-{
-        // ...
-        error_code error;
-};
-
-
-
-

stats_alert

-

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
-{
-        // ...
-        enum stats_channel
-        {
-                upload_payload,
-                upload_protocol,
-                upload_ip_protocol,
-                upload_dht_protocol,
-                upload_tracker_protocol,
-                download_payload,
-                download_protocol,
-                download_ip_protocol,
-                download_dht_protocol,
-                download_tracker_protocol,
-                num_channels
-        };
-
-        int transferred[num_channels];
-        int interval;
-};
-
-

transferred this is 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

-

This alert is posted when the disk cache has been flushed for a specific torrent -as a result of a call to 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 flush_cached_alert: torrent_alert
-{
-        // ...
-};
-
-
-
-

torrent_need_cert_alert

-

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: tracker_alert
-{
-        // ...
-};
-
-
-
-

dht_announce_alert

-

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
-{
-        // ...
-        address ip;
-        int port;
-        sha1_hash info_hash;
-};
-
-
-
-

dht_get_peers_alert

-

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
-{
-        // ...
-        sha1_hash info_hash;
-};
-
-
-
-

dht_reply_alert

-

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
-{
-        // ...
-        int num_peers;
-};
-
-
-
-

dht_bootstrap_alert

-

This alert is posted when the initial DHT bootstrap is done. There's no any other -relevant information associated with this alert.

-
-struct dht_bootstrap_alert: alert
-{
-        // ...
-};
-
-
-
-

anonymous_mode_alert

-

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: tracker_alert
-{
-        // ...
-        enum kind_t
-        {
-                tracker_not_anonymous = 1
-        };
-        int kind;
-        std::string str;
-};
-
-

kind specifies what error this is, it's one of:

-

tracker_not_anonymous 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.

-
-
-

rss_alert

-

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
-        };
-
-        feed_handle handle;
-        std::string url;
-        int state;
-        error_code error;
-};
-
-

handle is the handle to the feed which generated this alert.

-

url is a short cut to access the url of the feed, without -having to call get_settings().

-

state is one of:

-
-
rss_alert::state_updating
-
An update of this feed was just initiated, it will either succeed -or fail soon.
-
rss_alert::state_updated
-
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.
-
rss_akert::state_error
-
An error just occurred. See the error field for information on -what went wrong.
-
-

error is an error code used for when an error occurs on the feed.

-
-
-

rss_item_alert

-

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_alert : alert
-{
-        // ...
-        virtual std::string message() const;
-
-        feed_handle handle;
-        feed_item item;
-};
-
-
-
-

incoming_connection_alert

-

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;
-
-        int socket_type;
-        tcp::endpoint ip;
-};
-
-

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

- ---- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
valuetype
0none (no socket instantiated)
1TCP
2Socks5
3HTTP
4uTP
5i2p
6SSL/TCP
7SSL/Socks5
8HTTPS (SSL/HTTP)
9SSL/uTP
-

ip is the IP address and port the connection came from.

-
-
-

state_update_alert

-

This alert is only posted when requested by the user, by calling `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
-{
-        // ...
-        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

-

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
-{
-        // ...
-        sha1_hash old_ih;
-        sha1_hash new_ih;
-};
-
-

old_ih and new_ih are the previous and new info-hash for the torrent, respectively.

-
-
-
-

alert dispatcher

-

The handle_alert class is defined in <libtorrent/alert.hpp>.

-

Examples usage:

-
-struct my_handler
-{
-        void operator()(portmap_error_alert const& a) const
-        {
-                std::cout << "Portmapper: " << a.msg << std::endl;
-        }
-
-        void operator()(tracker_warning_alert const& a) const
-        {
-                std::cout << "Tracker warning: " << a.msg << std::endl;
-        }
-
-        void operator()(torrent_finished_alert const& a) const
-        {
-                // write fast resume data
-                // ...
-
-                std::cout << a.handle.torrent_file()->name() << "completed"
-                        << std::endl;
-        }
-};
-
-
-std::auto_ptr<alert> a;
-a = ses.pop_alert();
-my_handler h;
-while (a.get())
-{
-        handle_alert<portmap_error_alert
-                , tracker_warning_alert
-                , torrent_finished_alert
-        >::handle_alert(h, a);
-        a = ses.pop_alert();
-}
-
-

In this example 3 alert types are used. You can use any number of template -parameters to select between more types. If the number of types are more than -15, you can define TORRENT_MAX_ALERT_TYPES to a greater number before -including <libtorrent/alert.hpp>.

-
-
-

exceptions

-

Many functions in libtorrent have two versions, one that throws exceptions on -errors and one that takes an error_code reference which is filled with the -error code on errors.

-

There is one exception class that is used for errors in libtorrent, it is based -on boost.system's error_code class to carry the error code.

-
-

libtorrent_exception

-
-struct libtorrent_exception: std::exception
-{
-        libtorrent_exception(error_code const& s);
-        virtual const char* what() const throw();
-        virtual ~libtorrent_exception() throw() {}
-        boost::system::error_code error() const;
-};
-
-
-
-
-

error_code

-

libtorrent uses boost.system's error_code class to represent errors. libtorrent has -its own error category (libtorrent::get_libtorrent_category()) whith the following error -codes:

- ----- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
codesymboldescription
0no_errorNot an error
1file_collisionTwo torrents has files which end up overwriting each other
2failed_hash_checkA piece did not match its piece hash
3torrent_is_no_dictThe .torrent file does not contain a bencoded dictionary at -its top level
4torrent_missing_infoThe .torrent file does not have an info dictionary
5torrent_info_no_dictThe .torrent file's info entry is not a dictionary
6torrent_missing_piece_lengthThe .torrent file does not have a piece length entry
7torrent_missing_nameThe .torrent file does not have a name entry
8torrent_invalid_nameThe .torrent file's name entry is invalid
9torrent_invalid_lengthThe length of a file, or of the whole .torrent file is invalid. -Either negative or not an integer
10torrent_file_parse_failedFailed to parse a file entry in the .torrent
11torrent_missing_piecesThe pieces field is missing or invalid in the .torrent file
12torrent_invalid_hashesThe pieces string has incorrect length
13too_many_pieces_in_torrentThe .torrent file has more pieces than is supported by libtorrent
14invalid_swarm_metadataThe metadata (.torrent file) that was received from the swarm -matched the info-hash, but failed to be parsed
15invalid_bencodingThe file or buffer is not correctly bencoded
16no_files_in_torrentThe .torrent file does not contain any files
17invalid_escaped_stringThe string was not properly url-encoded as expected
18session_is_closingOperation is not permitted since the session is shutting down
19duplicate_torrentThere's already a torrent with that info-hash added to the -session
20invalid_torrent_handleThe supplied torrent_handle is not referring to a valid torrent
21invalid_entry_typeThe type requested from the entry did not match its type
22missing_info_hash_in_uriThe specified URI does not contain a valid info-hash
23file_too_shortOne of the files in the torrent was unexpectadly small. This -might be caused by files being changed by an external process
24unsupported_url_protocolThe URL used an unknown protocol. Currently http and -https (if built with openssl support) are recognized. For -trackers udp is recognized as well.
25url_parse_errorThe URL did not conform to URL syntax and failed to be parsed
26peer_sent_empty_pieceThe peer sent a 'piece' message of length 0
27parse_failedA bencoded structure was currupt and failed to be parsed
28invalid_file_tagThe fast resume file was missing or had an invalid file version -tag
29missing_info_hashThe fast resume file was missing or had an invalid info-hash
30mismatching_info_hashThe info-hash in the resume file did not match the torrent
31invalid_hostnameThe URL contained an invalid hostname
32invalid_portThe URL had an invalid port
33port_blockedThe port is blocked by the port-filter, and prevented the -connection
34expected_close_bracket_in_addressThe IPv6 address was expected to end with ']'
35destructing_torrentThe torrent is being destructed, preventing the operation to -succeed
36timed_outThe connection timed out
37upload_upload_connectionThe peer is upload only, and we are upload only. There's no point -in keeping the connection
38uninteresting_upload_peerThe peer is upload only, and we're not interested in it. There's -no point in keeping the connection
39invalid_info_hashThe peer sent an unknown info-hash
40torrent_pausedThe torrent is paused, preventing the operation from succeeding
41invalid_haveThe peer sent an invalid have message, either wrong size or -referring to a piece that doesn't exist in the torrent
42invalid_bitfield_sizeThe bitfield message had the incorrect size
43too_many_requests_when_chokedThe peer kept requesting pieces after it was choked, possible -abuse attempt.
44invalid_pieceThe peer sent a piece message that does not correspond to a -piece request sent by the client
45no_memorymemory allocation failed
46torrent_abortedThe torrent is aborted, preventing the operation to succeed
47self_connectionThe peer is a connection to ourself, no point in keeping it
48invalid_piece_sizeThe peer sent a piece message with invalid size, either negative -or greater than one block
49timed_out_no_interestThe peer has not been interesting or interested in us for too -long, no point in keeping it around
50timed_out_inactivityThe peer has not said anything in a long time, possibly dead
51timed_out_no_handshakeThe peer did not send a handshake within a reasonable amount of -time, it might not be a bittorrent peer
52timed_out_no_requestThe peer has been unchoked for too long without requesting any -data. It might be lying about its interest in us
53invalid_chokeThe peer sent an invalid choke message
54invalid_unchokeThe peer send an invalid unchoke message
55invalid_interestedThe peer sent an invalid interested message
56invalid_not_interestedThe peer sent an invalid not-interested message
57invalid_requestThe peer sent an invalid piece request message
58invalid_hash_listThe peer sent an invalid hash-list message (this is part of the -merkle-torrent extension)
59invalid_hash_pieceThe peer sent an invalid hash-piece message (this is part of the -merkle-torrent extension)
60invalid_cancelThe peer sent an invalid cancel message
61invalid_dht_portThe peer sent an invalid DHT port-message
62invalid_suggestThe peer sent an invalid suggest piece-message
63invalid_have_allThe peer sent an invalid have all-message
64invalid_have_noneThe peer sent an invalid have none-message
65invalid_rejectThe peer sent an invalid reject message
66invalid_allow_fastThe peer sent an invalid allow fast-message
67invalid_extendedThe peer sent an invalid extesion message ID
68invalid_messageThe peer sent an invalid message ID
69sync_hash_not_foundThe synchronization hash was not found in the encrypted handshake
70invalid_encryption_constantThe encryption constant in the handshake is invalid
71no_plaintext_modeThe peer does not support plaintext, which is the selected mode
72no_rc4_modeThe peer does not support rc4, which is the selected mode
73unsupported_encryption_modeThe peer does not support any of the encryption modes that the -client supports
74unsupported_encryption_mode_selectedThe peer selected an encryption mode that the client did not -advertise and does not support
75invalid_pad_sizeThe pad size used in the encryption handshake is of invalid size
76invalid_encrypt_handshakeThe encryption handshake is invalid
77no_incoming_encryptedThe client is set to not support incoming encrypted connections -and this is an encrypted connection
78no_incoming_regularThe client is set to not support incoming regular bittorrent -connections, and this is a regular connection
79duplicate_peer_idThe client is already connected to this peer-ID
80torrent_removedTorrent was removed
81packet_too_largeThe packet size exceeded the upper sanity check-limit
82reserved 
83http_errorThe web server responded with an error
84missing_locationThe web server response is missing a location header
85invalid_redirectionThe web seed redirected to a path that no longer matches the -.torrent directory structure
86redirectingThe connection was closed becaused it redirected to a different -URL
87invalid_rangeThe HTTP range header is invalid
88no_content_lengthThe HTTP response did not have a content length
89banned_by_ip_filterThe IP is blocked by the IP filter
90too_many_connectionsAt the connection limit
91peer_bannedThe peer is marked as banned
92stopping_torrentThe torrent is stopping, causing the operation to fail
93too_many_corrupt_piecesThe peer has sent too many corrupt pieces and is banned
94torrent_not_readyThe torrent is not ready to receive peers
95peer_not_constructedThe peer is not completely constructed yet
96session_closingThe session is closing, causing the operation to fail
97optimistic_disconnectThe peer was disconnected in order to leave room for a -potentially better peer
98torrent_finishedThe torrent is finished
99no_routerNo UPnP router found
100metadata_too_largeThe metadata message says the metadata exceeds the limit
101invalid_metadata_requestThe peer sent an invalid metadata request message
102invalid_metadata_sizeThe peer advertised an invalid metadata size
103invalid_metadata_offsetThe peer sent a message with an invalid metadata offset
104invalid_metadata_messageThe peer sent an invalid metadata message
105pex_message_too_largeThe peer sent a peer exchange message that was too large
106invalid_pex_messageThe peer sent an invalid peer exchange message
107invalid_lt_tracker_messageThe peer sent an invalid tracker exchange message
108too_frequent_pexThe peer sent an pex messages too often. This is a possible -attempt of and attack
109no_metadataThe operation failed because it requires the torrent to have -the metadata (.torrent file) and it doesn't have it yet. -This happens for magnet links before they have downloaded the -metadata, and also torrents added by URL.
110invalid_dont_haveThe peer sent an invalid dont_have message. The dont have -message is an extension to allow peers to advertise that the -no longer has a piece they previously had.
111requires_ssl_connectionThe peer tried to connect to an SSL torrent without connecting -over SSL.
112invalid_ssl_certThe peer tried to connect to a torrent with a certificate -for a different torrent.
-

NAT-PMP errors:

- ----- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
codesymboldescription
120unsupported_protocol_versionThe NAT-PMP router responded with an unsupported protocol version
121natpmp_not_authorizedYou are not authorized to map ports on this NAT-PMP router
122network_failureThe NAT-PMP router failed because of a network failure
123no_resourcesThe NAT-PMP router failed because of lack of resources
124unsupported_opcodeThe NAT-PMP router failed because an unsupported opcode was sent
-

fastresume data errors:

- ----- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
codesymboldescription
130missing_file_sizesThe resume data file is missing the 'file sizes' entry
131no_files_in_resume_dataThe resume data file 'file sizes' entry is empty
132missing_piecesThe resume data file is missing the 'pieces' and 'slots' entry
133mismatching_number_of_filesThe number of files in the resume data does not match the number -of files in the torrent
134mismatching_files_sizeOne of the files on disk has a different size than in the fast -resume file
135mismatching_file_timestampOne of the files on disk has a different timestamp than in the -fast resume file
136not_a_dictionaryThe resume data file is not a dictionary
137invalid_blocks_per_pieceThe 'blocks per piece' entry is invalid in the resume data file
138missing_slotsThe resume file is missing the 'slots' entry, which is required -for torrents with compact allocation
139too_many_slotsThe resume file contains more slots than the torrent
140invalid_slot_listThe 'slot' entry is invalid in the resume data
141invalid_piece_indexOne index in the 'slot' list is invalid
142pieces_need_reorderThe pieces on disk needs to be re-ordered for the specified -allocation mode. This happens if you specify sparse allocation -and the files on disk are using compact storage. The pieces needs -to be moved to their right position
-

HTTP errors:

- ----- - - - - - - - - - - - - - - -
150http_parse_errorThe HTTP header was not correctly formatted
151http_missing_locationThe HTTP response was in the 300-399 range but lacked a location -header
152http_failed_decompressThe HTTP response was encoded with gzip or deflate but -decompressing it failed
-

I2P errors:

- ----- - - - - - - -
160no_i2p_routerThe URL specified an i2p address, but no i2p router is configured
-

tracker errors:

- ----- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
170scrape_not_availableThe tracker URL doesn't support transforming it into a scrape -URL. i.e. it doesn't contain "announce.
171invalid_tracker_responseinvalid tracker response
172invalid_peer_dictinvalid peer dictionary entry. Not a dictionary
173tracker_failuretracker sent a failure message
174invalid_files_entrymissing or invalid 'files' entry
175invalid_hash_entrymissing or invalid 'hash' entry
176invalid_peers_entrymissing or invalid 'peers' and 'peers6' entry
177invalid_tracker_response_lengthudp tracker response packet has invalid size
178invalid_tracker_transaction_idinvalid transaction id in udp tracker response
179invalid_tracker_actioninvalid action field in udp tracker response
190expected_stringexpected string in bencoded string
191expected_colonexpected colon in bencoded string
192unexpected_eofunexpected end of file in bencoded string
193expected_valueexpected value (list, dict, int or string) in bencoded string
194depth_exceededbencoded recursion depth limit exceeded
195item_limit_exceededbencoded item count limit exceeded
-

The names of these error codes are declared in then libtorrent::errors namespace.

-

There is also another error category, libtorrent::upnp_category, defining errors -retrned by UPnP routers. Here's a (possibly incomplete) list of UPnP error codes:

- ----- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
codesymboldescription
0no_errorNo error
402invalid_argumentOne of the arguments in the request is invalid
501action_failedThe request failed
714value_not_in_arrayThe specified value does not exist in the array
715source_ip_cannot_be_wildcardedThe source IP address cannot be wild-carded, but -must be fully specified
716external_port_cannot_be_wildcardedThe external port cannot be wildcarded, but must -be specified
718port_mapping_conflictThe port mapping entry specified conflicts with a -mapping assigned previously to another client
724internal_port_must_match_externalInternal and external port value must be the same
725only_permanent_leases_supportedThe NAT implementation only supports permanent -lease times on port mappings
726remote_host_must_be_wildcardRemoteHost must be a wildcard and cannot be a -specific IP addres or DNS name
727external_port_must_be_wildcardExternalPort must be a wildcard and cannot be a -specific port
-

The UPnP errors are declared in the libtorrent::upnp_errors namespace.

-

HTTP errors are reported in the libtorrent::http_category, with error code enums in -the libtorrent::errors namespace.

- ---- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
codesymbol
100cont
200ok
201created
202accepted
204no_content
300multiple_choices
301moved_permanently
302moved_temporarily
304not_modified
400bad_request
401unauthorized
403forbidden
404not_found
500internal_server_error
501not_implemented
502bad_gateway
503service_unavailable
-
-

translating error codes

-

The error_code::message() function will typically return a localized error string, -for system errors. That is, errors that belong to the generic or system category.

-

Errors that belong to the libtorrent error category are not localized however, they -are only available in english. In order to translate libtorrent errors, compare the -error category of the error_code object against libtorrent::get_libtorrent_category(), -and if matches, you know the error code refers to the list above. You can provide -your own mapping from error code to string, which is localized. In this case, you -cannot rely on error_code::message() to generate your strings.

-

The numeric values of the errors are part of the API and will stay the same, although -new error codes may be appended at the end.

-

Here's a simple example of how to translate error codes:

-
-std::string error_code_to_string(boost::system::error_code const& ec)
-{
-        if (ec.category() != libtorrent::get_libtorrent_category())
-        {
-                return ec.message();
-        }
-        // the error is a libtorrent error
-
-        int code = ec.value();
-        static const char const* swedish[] =
-        {
-                "inget fel",
-                "en fil i torrenten kolliderar med en fil fran en annan torrent",
-                "hash check misslyckades",
-                "torrent filen ar inte en dictionary",
-                "'info'-nyckeln saknas eller ar korrupt i torrentfilen",
-                "'info'-faltet ar inte en dictionary",
-                "'piece length' faltet saknas eller ar korrupt i torrentfilen",
-                "torrentfilen saknar namnfaltet",
-                "ogiltigt namn i torrentfilen (kan vara en attack)",
-                // ... more strings here
-        };
-
-        // use the default error string in case we don't have it
-        // in our translated list
-        if (code < 0 || code >= sizeof(swedish)/sizeof(swedish[0]))
-                return ec.message();
-
-        return swedish[code];
-}
-
-
-
-
-

storage_interface

-

The storage interface is a pure virtual class that can be implemented to -customize how and where data for a torrent is stored. The default storage -implementation uses regular files in the filesystem, mapping the files in the -torrent in the way one would assume a torrent is saved to disk. Implementing -your own storage interface makes it possible to store all data in RAM, or in -some optimized order on disk (the order the pieces are received for instance), -or saving multifile torrents in a single file in order to be able to take -advantage of optimized disk-I/O.

-

It is also possible to write a thin class that uses the default storage but -modifies some particular behavior, for instance encrypting the data before -it's written to disk, and decrypting it when it's read again.

-

The storage interface is based on slots, each slot is 'piece_size' number -of bytes. All access is done by writing and reading whole or partial -slots. One slot is one piece in the torrent, but the data in the slot -does not necessarily correspond to the piece with the same index (in -compact allocation mode it won't).

-

libtorrent comes with two built-in storage implementations; default_storage -and disabled_storage. Their constructor functions are called default_storage_constructor -and disabled_storage_constructor respectively. The disabled storage does -just what it sounds like. It throws away data that's written, and it -reads garbage. It's useful mostly for benchmarking and profiling purpose.

-

The interface looks like this:

-
-struct storage_interface
-{
-        virtual bool initialize(bool allocate_files) = 0;
-        virtual bool has_any_file() = 0;
-        virtual void hint_read(int slot, int offset, int len);
-        virtual int readv(file::iovec_t const* bufs, int slot, int offset, int num_bufs) = 0;
-        virtual int writev(file::iovec_t const* bufs, int slot, int offset, int num_bufs) = 0;
-        virtual int sparse_end(int start) const;
-        virtual bool move_storage(fs::path save_path) = 0;
-        virtual bool verify_resume_data(lazy_entry const& rd, error_code& error) = 0;
-        virtual bool write_resume_data(entry& rd) const = 0;
-        virtual bool move_slot(int src_slot, int dst_slot) = 0;
-        virtual bool swap_slots(int slot1, int slot2) = 0;
-        virtual bool swap_slots3(int slot1, int slot2, int slot3) = 0;
-        virtual bool rename_file(int file, std::string const& new_name) = 0;
-        virtual bool release_files() = 0;
-        virtual bool delete_files() = 0;
-        virtual void finalize_file(int index) {}
-        virtual ~storage_interface() {}
-
-        // non virtual functions
-
-        disk_buffer_pool* disk_pool();
-        void set_error(std::string const& file, error_code const& ec) const;
-        error_code const& error() const;
-        std::string const& error_file() const;
-        void clear_error();
-};
-
-
-

initialize()

-
-
-bool initialize(bool allocate_files) = 0;
-
-
-

This function is called when the storage is to be initialized. The default storage -will create directories and empty files at this point. If allocate_files is true, -it will also ftruncate all files to their target size.

-

Returning true indicates an error occurred.

-
-
-

has_any_file()

-
-
-virtual bool has_any_file() = 0;
-
-
-

This function is called when first checking (or re-checking) the storage for a torrent. -It should return true if any of the files that is used in this storage exists on disk. -If so, the storage will be checked for existing pieces before starting the download.

-
-
-

hint_read()

-
-
-void hint_read(int slot, int offset, int len);
-
-
-

This function is called when a read job is queued. It gives the storage wrapper an -opportunity to hint the operating system about this coming read. For instance, the -storage may call posix_fadvise(POSIX_FADV_WILLNEED) or fcntl(F_RDADVISE).

-
-
-

readv() writev()

-
-
-int readv(file::iovec_t const* buf, int slot, int offset, int num_bufs) = 0;
-int write(const char* buf, int slot, int offset, int size) = 0;
-
-
-

These functions should read or write the data in or to the given slot at the given offset. -It should read or write num_bufs buffers sequentially, where the size of each buffer -is specified in the buffer array bufs. The file::iovec_t type has the following members:

-
-struct iovec_t
-{
-        void* iov_base;
-        size_t iov_len;
-};
-
-

The return value is the number of bytes actually read or written, or -1 on failure. If -it returns -1, the error code is expected to be set to

-

Every buffer in bufs can be assumed to be page aligned and be of a page aligned size, -except for the last buffer of the torrent. The allocated buffer can be assumed to fit a -fully page aligned number of bytes though. This is useful when reading and writing the -last piece of a file in unbuffered mode.

-

The offset is aligned to 16 kiB boundries most of the time, but there are rare -exceptions when it's not. Specifically if the read cache is disabled/or full and a -client requests unaligned data, or the file itself is not aligned in the torrent. -Most clients request aligned data.

-
-
-

sparse_end()

-
-
-int sparse_end(int start) const;
-
-
-

This function is optional. It is supposed to return the first piece, starting at -start that is fully contained within a data-region on disk (i.e. non-sparse -region). The purpose of this is to skip parts of files that can be known to contain -zeros when checking files.

-
-
-

move_storage()

-
-
-bool move_storage(fs::path save_path) = 0;
-
-
-

This function should move all the files belonging to the storage to the new save_path. -The default storage moves the single file or the directory of the torrent.

-

Before moving the files, any open file handles may have to be closed, like -release_files().

-

Returning false indicates an error occurred.

-
-
-

verify_resume_data()

-
-
-bool verify_resume_data(lazy_entry const& rd, error_code& error) = 0;
-
-
-

This function should verify the resume data rd with the files -on disk. If the resume data seems to be up-to-date, return true. If -not, set error to a description of what mismatched and return false.

-

The default storage may compare file sizes and time stamps of the files.

-

Returning false indicates an error occurred.

-
-
-

write_resume_data()

-
-
-bool write_resume_data(entry& rd) const = 0;
-
-
-

This function should fill in resume data, the current state of the -storage, in rd. The default storage adds file timestamps and -sizes.

-

Returning true indicates an error occurred.

-
-
-

move_slot()

-
-
-bool move_slot(int src_slot, int dst_slot) = 0;
-
-
-

This function should copy or move the data in slot src_slot to -the slot dst_slot. This is only used in compact mode.

-

If the storage caches slots, this could be implemented more -efficient than reading and writing the data.

-

Returning true indicates an error occurred.

-
-
-

swap_slots()

-
-
-bool swap_slots(int slot1, int slot2) = 0;
-
-
-

This function should swap the data in slot1 and slot2. The default -storage uses a scratch buffer to read the data into, then moving the other -slot and finally writing back the temporary slot's data

-

This is only used in compact mode.

-

Returning true indicates an error occurred.

-
-
-

swap_slots3()

-
-
-bool swap_slots3(int slot1, int slot2, int slot3) = 0;
-
-
-

This function should do a 3-way swap, or shift of the slots. slot1 -should move to slot2, which should be moved to slot3 which in turn -should be moved to slot1.

-

This is only used in compact mode.

-

Returning true indicates an error occurred.

-
-
-

rename_file()

-
-
-bool rename_file(int file, std::string const& new_name) = 0;
-
-
-

Rename file with index file to the thame new_name. If there is an error, -true should be returned.

-
-
-

release_files()

-
-
-bool release_files() = 0;
-
-
-

This function should release all the file handles that it keeps open to files -belonging to this storage. The default implementation just calls -file_pool::release_files(this).

-

Returning true indicates an error occurred.

-
-
-

delete_files()

-
-
-bool delete_files() = 0;
-
-
-

This function should delete all files and directories belonging to this storage.

-

Returning true indicates an error occurred.

-

The disk_buffer_pool is used to allocate and free disk buffers. It has the -following members:

-
-struct disk_buffer_pool : boost::noncopyable
-{
-        char* allocate_buffer(char const* category);
-        void free_buffer(char* buf);
-
-        char* allocate_buffers(int blocks, char const* category);
-        void free_buffers(char* buf, int blocks);
-
-        int block_size() const { return m_block_size; }
-
-        void release_memory();
-};
-
-
-
-

finalize_file()

-
-
-virtual void finalize_file(int index);
-
-
-

This function is called each time a file is completely downloaded. The -storage implementation can perform last operations on a file. The file will -not be opened for writing after this.

-

index is the index of the file that completed.

-

On windows the default storage implementation clears the sparse file flag -on the specified file.

-
-
-

example

-

This is an example storage implementation that stores all pieces in a std::map, -i.e. in RAM. It's not necessarily very useful in practice, but illustrates the -basics of implementing a custom storage.

-
-struct temp_storage : storage_interface
-{
-        temp_storage(file_storage const& fs) : m_files(fs) {}
-        virtual bool initialize(bool allocate_files) { return false; }
-        virtual bool has_any_file() { return false; }
-        virtual int read(char* buf, int slot, int offset, int size)
-        {
-                std::map<int, std::vector<char> >::const_iterator i = m_file_data.find(slot);
-                if (i == m_file_data.end()) return 0;
-                int available = i->second.size() - offset;
-                if (available <= 0) return 0;
-                if (available > size) available = size;
-                memcpy(buf, &i->second[offset], available);
-                return available;
-        }
-        virtual int write(const char* buf, int slot, int offset, int size)
-        {
-                std::vector<char>& data = m_file_data[slot];
-                if (data.size() < offset + size) data.resize(offset + size);
-                std::memcpy(&data[offset], buf, size);
-                return size;
-        }
-        virtual bool rename_file(int file, std::string const& new_name)
-        { assert(false); return false; }
-        virtual bool move_storage(std::string const& save_path) { return false; }
-        virtual bool verify_resume_data(lazy_entry const& rd, error_code& error) { return false; }
-        virtual bool write_resume_data(entry& rd) const { return false; }
-        virtual bool move_slot(int src_slot, int dst_slot) { assert(false); return false; }
-        virtual bool swap_slots(int slot1, int slot2) { assert(false); return false; }
-        virtual bool swap_slots3(int slot1, int slot2, int slot3) { assert(false); return false; }
-        virtual size_type physical_offset(int slot, int offset)
-        { return slot * m_files.piece_length() + offset; };
-        virtual sha1_hash hash_for_slot(int slot, partial_hash& ph, int piece_size)
-        {
-                int left = piece_size - ph.offset;
-                assert(left >= 0);
-                if (left > 0)
-                {
-                        std::vector<char>& data = m_file_data[slot];
-                        // if there are padding files, those blocks will be considered
-                        // completed even though they haven't been written to the storage.
-                        // in this case, just extend the piece buffer to its full size
-                        // and fill it with zeroes.
-                        if (data.size() < piece_size) data.resize(piece_size, 0);
-                        ph.h.update(&data[ph.offset], left);
-                }
-                return ph.h.final();
-        }
-        virtual bool release_files() { return false; }
-        virtual bool delete_files() { return false; }
-
-        std::map<int, std::vector<char> > m_file_data;
-        file_storage m_files;
-};
-
-storage_interface* temp_storage_constructor(
-        file_storage const& fs, file_storage const* mapped
-        , std::string const& path, file_pool& fp
-        , std::vector<boost::uint8_t> const& prio)
-{
-        return new temp_storage(fs);
-}
-
-
-
- -
-

queuing

-

libtorrent supports queuing. Which means it makes sure that a limited number of -torrents are being downloaded at any given time, and once a torrent is completely -downloaded, the next in line is started.

-

Torrents that are auto managed are subject to the queuing and the active torrents -limits. To make a torrent auto managed, set auto_managed to true when adding the -torrent (see `async_add_torrent() add_torrent()`_).

-

The limits of the number of downloading and seeding torrents are controlled via -active_downloads, active_seeds and active_limit in session_settings. -These limits takes non auto managed torrents into account as well. If there are -more non-auto managed torrents being downloaded than the active_downloads -setting, any auto managed torrents will be queued until torrents are removed so -that the number drops below the limit.

-

The default values are 8 active downloads and 5 active seeds.

-

At a regular interval, torrents are checked if there needs to be any re-ordering of -which torrents are active and which are queued. This interval can be controlled via -auto_manage_interval in session_settings. It defaults to every 30 seconds.

-

For queuing to work, resume data needs to be saved and restored for all torrents. -See save_resume_data().

-
-

downloading

-

Torrents that are currently being downloaded or incomplete (with bytes still to download) -are queued. The torrents in the front of the queue are started to be actively downloaded -and the rest are ordered with regards to their queue position. Any newly added torrent -is placed at the end of the queue. Once a torrent is removed or turns into a seed, its -queue position is -1 and all torrents that used to be after it in the queue, decreases their -position in order to fill the gap.

-

The queue positions are always in a sequence without any gaps.

-

Lower queue position means closer to the front of the queue, and will be started sooner than -torrents with higher queue positions.

-

To query a torrent for its position in the queue, or change its position, see: -queue_position() queue_position_up() queue_position_down() queue_position_top() queue_position_bottom().

-
-
-

seeding

-

Auto managed seeding torrents are rotated, so that all of them are allocated a fair -amount of seeding. Torrents with fewer completed seed cycles are prioritized for -seeding. A seed cycle is completed when a torrent meets either the share ratio limit -(uploaded bytes / downloaded bytes), the share time ratio (time seeding / time -downloaing) or seed time limit (time seeded).

-

The relevant settings to control these limits are share_ratio_limit, -seed_time_ratio_limit and seed_time_limit in session_settings.

-
-
-
-

fast resume

-

The fast resume mechanism is a way to remember which pieces are downloaded -and where they are put between sessions. You can generate fast resume data by -calling save_resume_data() on torrent_handle. You can -then save this data to disk and use it when resuming the torrent. libtorrent -will not check the piece hashes then, and rely on the information given in the -fast-resume data. The fast-resume data also contains information about which -blocks, in the unfinished pieces, were downloaded, so it will not have to -start from scratch on the partially downloaded pieces.

-

To use the fast-resume data you simply give it to `async_add_torrent() add_torrent()`_, and it -will skip the time consuming checks. It may have to do the checking anyway, if -the fast-resume data is corrupt or doesn't fit the storage for that torrent, -then it will not trust the fast-resume data and just do the checking.

-
-

file format

-

The file format is a bencoded dictionary containing the following fields:

- ---- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
file-formatstring: "libtorrent resume file"
file-versioninteger: 1
info-hashstring, the info hash of the torrent this data is saved for.
blocks per pieceinteger, the number of blocks per piece. Must be: piece_size -/ (16 * 1024). Clamped to be within the range [1, 256]. It -is the number of blocks per (normal sized) piece. Usually -each block is 16 * 1024 bytes in size. But if piece size is -greater than 4 megabytes, the block size will increase.
piecesA string with piece flags, one character per piece. -Bit 1 means we have that piece. -Bit 2 means we have verified that this piece is correct. -This only applies when the torrent is in seed_mode.
slots

list of integers. The list maps slots to piece indices. It -tells which piece is on which slot. If piece index is -2 it -means it is free, that there's no piece there. If it is -1, -means the slot isn't allocated on disk yet. The pieces have -to meet the following requirement:

-

If there's a slot at the position of the piece index, -the piece must be located in that slot.

-
total_uploadedinteger. The number of bytes that have been uploaded in -total for this torrent.
total_downloadedinteger. The number of bytes that have been downloaded in -total for this torrent.
active_timeinteger. The number of seconds this torrent has been active. -i.e. not paused.
seeding_timeinteger. The number of seconds this torrent has been active -and seeding.
num_seedsinteger. An estimate of the number of seeds on this torrent -when the resume data was saved. This is scrape data or based -on the peer list if scrape data is unavailable.
num_downloadersinteger. An estimate of the number of downloaders on this -torrent when the resume data was last saved. This is used as -an initial estimate until we acquire up-to-date scrape info.
upload_rate_limitinteger. In case this torrent has a per-torrent upload rate -limit, this is that limit. In bytes per second.
download_rate_limitinteger. The download rate limit for this torrent in case -one is set, in bytes per second.
max_connectionsinteger. The max number of peer connections this torrent -may have, if a limit is set.
max_uploadsinteger. The max number of unchoked peers this torrent may -have, if a limit is set.
seed_modeinteger. 1 if the torrent is in seed mode, 0 otherwise.
file_prioritylist of integers. One entry per file in the torrent. Each -entry is the priority of the file with the same index.
piece_prioritystring of bytes. Each byte is interpreted as an integer and -is the priority of that piece.
auto_managedinteger. 1 if the torrent is auto managed, otherwise 0.
sequential_downloadinteger. 1 if the torrent is in sequential download mode, -0 otherwise.
pausedinteger. 1 if the torrent is paused, 0 otherwise.
trackerslist of lists of strings. The top level list lists all -tracker tiers. Each second level list is one tier of -trackers.
mapped_fileslist of strings. If any file in the torrent has been -renamed, this entry contains a list of all the filenames. -In the same order as in the torrent file.
url-listlist of strings. List of url-seed URLs used by this torrent. -The urls are expected to be properly encoded and not contain -any illegal url characters.
httpseedslist of strings. List of httpseed URLs used by this torrent. -The urls are expected to be properly encoded and not contain -any illegal url characters.
merkle treestring. In case this torrent is a merkle torrent, this is a -string containing the entire merkle tree, all nodes, -including the root and all leaves. The tree is not -necessarily complete, but complete enough to be able to send -any piece that we have, indicated by the have bitmask.
peers

list of dictionaries. Each dictionary has the following -layout:

- ---- - - - - - - - - -
ipstring, the ip address of the peer. This is -not a binary representation of the ip -address, but the string representation. It -may be an IPv6 string or an IPv4 string.
portinteger, the listen port of the peer
-

These are the local peers we were connected to when this -fast-resume data was saved.

-
unfinished

list of dictionaries. Each dictionary represents an -piece, and has the following layout:

- ---- - - - - - - - - - - - -
pieceinteger, the index of the piece this entry -refers to.
bitmaskstring, a binary bitmask representing the -blocks that have been downloaded in this -piece.
adler32The adler32 checksum of the data in the -blocks specified by bitmask.
-
file sizeslist where each entry corresponds to a file in the file list -in the metadata. Each entry has a list of two values, the -first value is the size of the file in bytes, the second -is the time stamp when the last time someone wrote to it. -This information is used to compare with the files on disk. -All the files must match exactly this information in order -to consider the resume data as current. Otherwise a full -re-check is issued.
allocationThe allocation mode for the storage. Can be either full -or compact. If this is full, the file sizes and -timestamps are disregarded. Pieces are assumed not to have -moved around even if the files have been modified after the -last resume data checkpoint.
-
-
-
-

storage allocation

-

There are two modes in which storage (files on disk) are allocated in libtorrent.

-
    -
  1. The traditional full allocation mode, where the entire files are filled up with -zeros before anything is downloaded. libtorrent will look for sparse files support -in the filesystem that is used for storage, and use sparse files or file system -zero fill support if present. This means that on NTFS, full allocation mode will -only allocate storage for the downloaded pieces.
  2. -
  3. The sparse allocation, sparse files are used, and pieces are downloaded directly -to where they belong. This is the recommended (and default) mode.
  4. -
-

In previous versions of libtorrent, a 3rd mode was supported, compact allocation. -Support for this is deprecated and will be removed in future versions of libtorrent. -It's still described in here for completeness.

-

The allocation mode is selected when a torrent is started. It is passed as an -argument to session::add_torrent() (see `async_add_torrent() add_torrent()`_).

-

The decision to use full allocation or compact allocation typically depends on whether -any files have priority 0 and if the filesystem supports sparse files.

-
-

sparse allocation

-

On filesystems that supports sparse files, this allocation mode will only use -as much space as has been downloaded.

-
-
    -
  • It does not require an allocation pass on startup.
  • -
  • It supports skipping files (setting prioirty to 0 to not download).
  • -
  • Fast resume data will remain valid even when file time stamps are out of date.
  • -
-
-
-
-

full allocation

-

When a torrent is started in full allocation mode, the disk-io thread -will make sure that the entire storage is allocated, and fill any gaps with zeros. -This will be skipped if the filesystem supports sparse files or automatic zero filling. -It will of course still check for existing pieces and fast resume data. The main -drawbacks of this mode are:

-
-
    -
  • It may take longer to start the torrent, since it will need to fill the files -with zeros on some systems. This delay is linearly dependent on the size of -the download.
  • -
  • The download may occupy unnecessary disk space between download sessions. In case -sparse files are not supported.
  • -
  • Disk caches usually perform extremely poorly with random access to large files -and may slow down a download considerably.
  • -
-
-

The benefits of this mode are:

-
-
    -
  • Downloaded pieces are written directly to their final place in the files and the -total number of disk operations will be fewer and may also play nicer to -filesystems' file allocation, and reduce fragmentation.
  • -
  • No risk of a download failing because of a full disk during download. Unless -sparse files are being used.
  • -
  • The fast resume data will be more likely to be usable, regardless of crashes or -out of date data, since pieces won't move around.
  • -
  • Can be used with prioritizing files to 0.
  • -
-
-
-
-

compact allocation

-

Note that support for compact allocation is deprecated in libttorrent, and will -be removed in future versions.

-

The compact allocation will only allocate as much storage as it needs to keep the -pieces downloaded so far. This means that pieces will be moved around to be placed -at their final position in the files while downloading (to make sure the completed -download has all its pieces in the correct place). So, the main drawbacks are:

-
-
    -
  • More disk operations while downloading since pieces are moved around.
  • -
  • Potentially more fragmentation in the filesystem.
  • -
  • Cannot be used while having files with priority 0.
  • -
-
-

The benefits though, are:

-
-
    -
  • No startup delay, since the files don't need allocating.
  • -
  • The download will not use unnecessary disk space.
  • -
  • Disk caches perform much better than in full allocation and raises the download -speed limit imposed by the disk.
  • -
  • Works well on filesystems that don't support sparse files.
  • -
-
-

The algorithm that is used when allocating pieces and slots isn't very complicated. -For the interested, a description follows.

-

storing a piece:

-
    -
  1. let A be a newly downloaded piece, with index n.
  2. -
  3. let s be the number of slots allocated in the file we're -downloading to. (the number of pieces it has room for).
  4. -
  5. if n >= s then allocate a new slot and put the piece there.
  6. -
  7. if n < s then allocate a new slot, move the data at -slot n to the new slot and put A in slot n.
  8. -
-

allocating a new slot:

-
    -
  1. if there's an unassigned slot (a slot that doesn't -contain any piece), return that slot index.
  2. -
  3. append the new slot at the end of the file (or find an unused slot).
  4. -
  5. let i be the index of newly allocated slot
  6. -
  7. if we have downloaded piece index i already (to slot j) then
      -
    1. move the data at slot j to slot i.
    2. -
    3. return slot index j as the newly allocated free slot.
    4. -
    -
  8. -
  9. return i as the newly allocated slot.
  10. -
-
-
-
-

extensions

-

These extensions all operates within the extension protocol. The -name of the extension is the name used in the extension-list packets, -and the payload is the data in the extended message (not counting the -length-prefix, message-id nor extension-id).

-

Note that since this protocol relies on one of the reserved bits in the -handshake, it may be incompatible with future versions of the mainline -bittorrent client.

-

These are the extensions that are currently implemented.

-
-

metadata from peers

-

Extension name: "LT_metadata"

-

This extension is deprecated in favor of the more widely supported ut_metadata -extension, see BEP 9. -The point with this extension is that you don't have to distribute the -metadata (.torrent-file) separately. The metadata can be distributed -through the bittorrent swarm. The only thing you need to download such -a torrent is the tracker url and the info-hash of the torrent.

-

It works by assuming that the initial seeder has the metadata and that -the metadata will propagate through the network as more peers join.

-

There are three kinds of messages in the metadata extension. These packets -are put as payload to the extension message. The three packets are:

-
-
    -
  • request metadata
  • -
  • metadata
  • -
  • don't have metadata
  • -
-
-

request metadata:

- ----- - - - - - - - - - - - - - - - - - - - - -
sizenamedescription
uint8_tmsg_typeDetermines the kind of message this is -0 means 'request metadata'
uint8_tstartThe start of the metadata block that -is requested. It is given in 256:ths -of the total size of the metadata, -since the requesting client don't know -the size of the metadata.
uint8_tsizeThe size of the metadata block that is -requested. This is also given in -256:ths of the total size of the -metadata. The size is given as size-1. -That means that if this field is set -0, the request wants one 256:th of the -metadata.
-

metadata:

- ----- - - - - - - - - - - - - - - - - - - - - - - - - -
sizenamedescription
uint8_tmsg_type1 means 'metadata'
int32_ttotal_sizeThe total size of the metadata, given -in number of bytes.
int32_toffsetThe offset of where the metadata block -in this message belongs in the final -metadata. This is given in bytes.
uint8_t[]metadataThe actual metadata block. The size of -this part is given implicit by the -length prefix in the bittorrent -protocol packet.
-

Don't have metadata:

- ----- - - - - - - - - - - - - -
sizenamedescription
uint8_tmsg_type2 means 'I don't have metadata'. -This message is sent as a reply to a -metadata request if the the client -doesn't have any metadata.
-
-
-

dont_have

-

Extension name: "lt_dont_have"

-

The dont_have extension message is used to tell peers that the client no longer -has a specific piece. The extension message should be advertised in the m dictionary -as lt_dont_have. The message format mimics the regular HAVE bittorrent message.

-

Just like all extension messages, the first 2 bytes in the mssage itself are 20 (the -bittorrent extension message) and the message ID assigned to this extension in the m -dictionary in the handshake.

- ----- - - - - - - - - - - - - -
sizenamedescription
uint32_tpieceindex of the piece the peer no longer -has.
-

The length of this message (including the extension message prefix) is -6 bytes, i.e. one byte longer than the normal HAVE message, because -of the extension message wrapping.

-
-
-

HTTP seeding

-

There are two kinds of HTTP seeding. One with that assumes a smart -(and polite) client and one that assumes a smart server. These -are specified in BEP 19 and BEP 17 respectively.

-

libtorrent supports both. In the libtorrent source code and API, -BEP 19 urls are typically referred to as url seeds and BEP 17 -urls are typically referred to as HTTP seeds.

-

The libtorrent implementation of BEP 19 assumes that, if the URL ends with a slash -('/'), the filename should be appended to it in order to request pieces from -that file. The way this works is that if the torrent is a single-file torrent, -only that filename is appended. If the torrent is a multi-file torrent, the -torrent's name '/' the file name is appended. This is the same directory -structure that libtorrent will download torrents into.

-
-
-
-

piece picker

-

The piece picker in libtorrent has the following features:

-
    -
  • rarest first
  • -
  • sequential download
  • -
  • random pick
  • -
  • reverse order picking
  • -
  • parole mode
  • -
  • prioritize partial pieces
  • -
  • prefer whole pieces
  • -
  • piece affinity by speed category
  • -
  • piece priorities
  • -
-
-

internal representation

-

It is optimized by, at all times, keeping a list of pieces ordered -by rarity, randomly shuffled within each rarity class. This list -is organized as a single vector of contigous memory in RAM, for -optimal memory locality and to eliminate heap allocations and frees -when updating rarity of pieces.

-

Expensive events, like a peer joining or leaving, are evaluated -lazily, since it's cheaper to rebuild the whole list rather than -updating every single piece in it. This means as long as no blocks -are picked, peers joining and leaving is no more costly than a single -peer joining or leaving. Of course the special cases of peers that have -all or no pieces are optimized to not require rebuilding the list.

-
-
-

picker strategy

-

The normal mode of the picker is of course rarest first, meaning -pieces that few peers have are preferred to be downloaded over pieces -that more peers have. This is a fundamental algorithm that is the -basis of the performance of bittorrent. However, the user may set the -piece picker into sequential download mode. This mode simply picks -pieces sequentially, always preferring lower piece indices.

-

When a torrent starts out, picking the rarest pieces means increased -risk that pieces won't be completed early (since there are only a few -peers they can be downloaded from), leading to a delay of having any -piece to offer to other peers. This lack of pieces to trade, delays -the client from getting started into the normal tit-for-tat mode of -bittorrent, and will result in a long ramp-up time. The heuristic to -mitigate this problem is to, for the first few pieces, pick random pieces -rather than rare pieces. The threshold for when to leave this initial -picker mode is determined by session_settings::initial_picker_threshold.

-
-
-

reverse order

-

An orthogonal setting is reverse order, which is used for snubbed -peers. Snubbed peers are peers that appear very slow, and might have timed -out a piece request. The idea behind this is to make all snubbed peers -more likely to be able to do download blocks from the same piece, -concentrating slow peers on as few pieces as possible. The reverse order -means that the most common pieces are picked, instead of the rarest pieces -(or in the case of sequential download, the last pieces, intead of the first).

-
-
-

parole mode

-

Peers that have participated in a piece that failed the hash check, may be -put in parole mode. This means we prefer downloading a full piece from this -peer, in order to distinguish which peer is sending corrupt data. Whether to -do this is or not is controlled by session_settings::use_parole_mode.

-

In parole mode, the piece picker prefers picking one whole piece at a time for -a given peer, avoiding picking any blocks from a piece any other peer has -contributed to (since that would defeat the purpose of parole mode).

-
-
-

prioritize partial pieces

-

This setting determines if partially downloaded or requested pieces should always -be preferred over other pieces. The benefit of doing this is that the number of -partial pieces is minimized (and hence the turn-around time for downloading a block -until it can be uploaded to others is minimized). It also puts less stress on the -disk cache, since fewer partial pieces need to be kept in the cache. Whether or -not to enable this is controlled by session_settings::prioritize_partial_pieces.

-

The main benefit of not prioritizing partial pieces is that the rarest first -algorithm gets to have more influence on which pieces are picked. The picker is -more likely to truly pick the rarest piece, and hence improving the performance -of the swarm.

-

This setting is turned on automatically whenever the number of partial pieces -in the piece picker exceeds the number of peers we're connected to times 1.5. -This is in order to keep the waste of partial pieces to a minimum, but still -prefer rarest pieces.

-
-
-

prefer whole pieces

-

The prefer whole pieces setting makes the piece picker prefer picking entire -pieces at a time. This is used by web connections (both http seeding -standards), in order to be able to coalesce the small bittorrent requests -to larger HTTP requests. This significantly improves performance when -downloading over HTTP.

-

It is also used by peers that are downloading faster than a certain -threshold. The main advantage is that these peers will better utilize the -other peer's disk cache, by requesting all blocks in a single piece, from -the same peer.

-

This threshold is controlled by session_settings::whole_pieces_threshold.

-

TODO: piece affinity by speed category -TODO: piece priorities

-
-
-
-

SSL torrents

-

Torrents may have an SSL root (CA) certificate embedded in them. Such torrents -are called SSL torrents. An SSL torrent talks to all bittorrent peers over SSL. -The protocols are layered like this:

-
-+-----------------------+
-| BitTorrent protocol   |
-+-----------------------+
-| SSL                   |
-+-----------+-----------+
-| TCP       | uTP       |
-|           +-----------+
-|           | UDP       |
-+-----------+-----------+
-
-

During the SSL handshake, both peers need to authenticate by providing a certificate -that is signed by the CA certificate found in the .torrent file. These peer -certificates are expected to be privided to peers through some other means than -bittorrent. Typically by a peer generating a certificate request which is sent to -the publisher of the torrent, and the publisher returning a signed certificate.

-

In libtorrent, set_ssl_certificate() in torrent_handle is used to tell libtorrent where -to find the peer certificate and the private key for it. When an SSL torrent is loaded, -the torrent_need_cert_alert is posted to remind the user to provide a certificate.

-

A peer connecting to an SSL torrent MUST provide the SNI TLS extension (server name -indication). The server name is the hex encoded info-hash of the torrent to connect to. -This is required for the client accepting the connection to know which certificate to -present.

-

SSL connections are accepted on a separate socket from normal bittorrent connections. To -pick which port the SSL socket should bind to, set session_settings::ssl_listen to a -different port. It defaults to port 4433. This setting is only taken into account when the -normal listen socket is opened (i.e. just changing this setting won't necessarily close -and re-open the SSL socket). To not listen on an SSL socket at all, set ssl_listen to 0.

-

This feature is only available if libtorrent is build with openssl support (TORRENT_USE_OPENSSL) -and requires at least openSSL version 1.0, since it needs SNI support.

-

Peer certificates must have at least one SubjectAltName field of type dNSName. At least -one of the fields must exactly match the name of the torrent. This is a byte-by-byte comparison, -the UTF-8 encoding must be identical (i.e. there's no unicode normalization going on). This is -the recommended way of verifying certificates for HTTPS servers according to RFC 2818. Note -the difference that for torrents only dNSName fields are taken into account (not IP address fields). -The most specific (i.e. last) Common Name field is also taken into account if no SubjectAltName -did not match.

-

If any of these fields contain a single asterisk ("*"), the certificate is considered covering -any torrent, allowing it to be reused for any torrent.

-

The purpose of matching the torrent name with the fields in the peer certificate is to allow -a publisher to have a single root certificate for all torrents it distributes, and issue -separate peer certificates for each torrent. A peer receiving a certificate will not necessarily -be able to access all torrents published by this root certificate (only if it has a "star cert").

-
-

testing

-

To test incoming SSL connections to an SSL torrent, one can use the following openssl command:

-
-openssl s_client -cert <peer-certificate>.pem -key <peer-private-key>.pem -CAfile <torrent-cert>.pem -debug -connect 127.0.0.1:4433 -tls1 -servername <info-hash>
-
-

To create a root certificate, the Distinguished Name (DN) is not taken into account -by bittorrent peers. You still need to specify something, but from libtorrent's point of -view, it doesn't matter what it is. libtorrent only makes sure the peer certificates are -signed by the correct root certificate.

-

One way to create the certificates is to use the CA.sh script that comes with openssl, like thisi (don't forget to enter a common Name for the certificate):

-
-CA.sh -newca
-CA.sh -newreq
-CA.sh -sign
-
-

The torrent certificate is located in ./demoCA/private/demoCA/cacert.pem, this is -the pem file to include in the .torrent file.

-

The peer's certificate is located in ./newcert.pem and the certificate's -private key in ./newkey.pem.

-
-
-
-

Docutils System Messages

-
-

System Message: ERROR/3 (manual.rst, line 21); backlink

-Unknown target name: "load_state() save_state()".
-
-

System Message: ERROR/3 (manual.rst, line 23); backlink

-Unknown target name: "start_dht() stop_dht() set_dht_settings() dht_state() is_dht_running()".
-
-

System Message: ERROR/3 (manual.rst, line 23); backlink

-Unknown target name: "start_lsd() stop_lsd()".
-
-

System Message: ERROR/3 (manual.rst, line 23); backlink

-Unknown target name: "start_upnp() stop_upnp()".
-
-

System Message: ERROR/3 (manual.rst, line 25); backlink

-Unknown target name: "async_add_torrent() add_torrent()".
-
-

System Message: ERROR/3 (manual.rst, line 26); backlink

-Unknown target name: "session".
-
-

System Message: ERROR/3 (manual.rst, line 34); backlink

-Unknown target name: "load_state() save_state()".
-
-

System Message: ERROR/3 (manual.rst, line 218); backlink

-Unknown target name: "async_add_torrent() add_torrent()".
-
-

System Message: ERROR/3 (manual.rst, line 718); backlink

-Unknown target name: "move_storage".
-
-

System Message: ERROR/3 (manual.rst, line 1920); backlink

-Unknown target name: "session".
-
-

System Message: ERROR/3 (manual.rst, line 2001); backlink

-Unknown target name: "remove_torrent()".
-
-

System Message: ERROR/3 (manual.rst, line 2021); backlink

-Unknown target name: "session".
-
-

System Message: ERROR/3 (manual.rst, line 2509); backlink

-Unknown target name: "async_add_torrent() add_torrent()".
-
-

System Message: ERROR/3 (manual.rst, line 3682); backlink

-Unknown target name: "async_add_torrent() add_torrent()".
-
-

System Message: ERROR/3 (manual.rst, line 5040); backlink

-Unknown target name: "async_add_torrent() add_torrent()".
-
-

System Message: ERROR/3 (manual.rst, line 5087); backlink

-Unknown target name: "set_alert_mask()".
-
-

System Message: ERROR/3 (manual.rst, line 5364); backlink

-Unknown target name: "session".
-
-

System Message: ERROR/3 (manual.rst, line 6527); backlink

-Unknown target name: "post_torrent_updates()".
-
-

System Message: ERROR/3 (manual.rst, line 7544); backlink

-Unknown target name: "async_add_torrent() add_torrent()".
-
-

System Message: ERROR/3 (manual.rst, line 7607); backlink

-Unknown target name: "async_add_torrent() add_torrent()".
-
-

System Message: ERROR/3 (manual.rst, line 7785); backlink

-Unknown target name: "async_add_torrent() add_torrent()".
-
-
- -
- - -
- - diff --git a/docs/reference-Alerts.html b/docs/reference-Alerts.html new file mode 100644 index 000000000..f3d7c0213 --- /dev/null +++ b/docs/reference-Alerts.html @@ -0,0 +1,2254 @@ + + + + + + +Alerts + + + + + + + + +
+
+
+ +
+ +
+

Alerts

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

Table of contents

+ +
+

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"

+ +++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
namevaluedescription
error_notification1

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_notification2Enables alerts when peers send invalid requests, get banned or +snubbed.
port_mapping_notification4Enables alerts for port mapping events. For NAT-PMP and UPnP.
storage_notification8Enables alerts for events related to the storage. File errors and +synchronization events for moving the storage, renaming files etc.
tracker_notification16Enables all tracker events. Includes announcing to trackers, +receiving responses, warnings and errors.
debug_notification32Low level alerts for when peers are connected and disconnected.
status_notification64Enables alerts for when a torrent or the session changes state.
progress_notification128Alerts for when blocks are requested and completed. Also when +pieces are completed.
ip_block_notification256Alerts when a peer is blocked by the ip blocker or port blocker.
performance_warning512Alerts when some limit is reached that might limit the download +or upload rate.
dht_notification1024Alerts on events in the DHT node. For incoming searches or +bootstrapping being done etc.
stats_notification2048If 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_notification4096Alerts 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_categories2147483647

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"

+ +++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
namevaluedescription
outstanding_disk_buffer_limit_reached0This 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_reached1This 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_low2This 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_low3This 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_low4

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_slots5If 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_limit6If 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_uplimit7 
too_few_outgoing_ports8This 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_descriptors9 
num_warnings10 
+
+
+
+

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. +
  3. Completed
  4. +
  5. Started
  6. +
  7. Stopped
  8. +
+
+
+
+
+

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"

+ +++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
namevaluedescription
tcp0 
tcp_ssl1 
udp2 
i2p3 
socks54 
+
+
+

enum op_t

+

Declared in "libtorrent/alert_types.hpp"

+ +++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
namevaluedescription
parse_addr0 
open1 
bind2 
listen3 
get_peer_name4 
accept5 
+
+
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"

+ +++++ + + + + + + + + + + + + + + + + + + + + +
namevaluedescription
tcp0 
tcp_ssl1 
udp2 
+
+
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"

+ +++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
namevaluedescription
upload_payload0 
upload_protocol1 
download_payload2 
download_protocol3 
upload_ip_protocol4 
upload_dht_protocol5 
upload_tracker_protocol6 
download_ip_protocol7 
download_dht_protocol8 
download_tracker_protocol9 
num_channels10 
+
+
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"

+ +++++ + + + + + + + + + + + + +
namevaluedescription
tracker_not_anonymous0means 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"

+ +++++ + + + + + + + + + + + + + + + + + + + + +
namevaluedescription
state_updating0An update of this feed was just initiated, it will either succeed +or fail soon.
state_updated1The 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_error2An 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. +
  3. TCP
  4. +
  5. Socks5
  6. +
  7. HTTP
  8. +
  9. uTP
  10. +
  11. i2p
  12. +
  13. SSL/TCP
  14. +
  15. SSL/Socks5
  16. +
  17. HTTPS (SSL/HTTP)
  18. +
  19. SSL/uTP
  20. +
+
+
+
+
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;
+};
+
+
+
+ +
+ + +
+ + diff --git a/docs/reference-Bencoding.html b/docs/reference-Bencoding.html new file mode 100644 index 000000000..bc0a5aa8f --- /dev/null +++ b/docs/reference-Bencoding.html @@ -0,0 +1,835 @@ + + + + + + +Bencoding + + + + + + + + +
+
+
+ +
+ +
+

Bencoding

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

Bencoding is a common representation in bittorrent used for +for dictionary, list, int and string hierarchies. It's used +to encode .torrent files and some messages in the network +protocol. libtorrent also uses it to store settings, resume +data and other state between sessions.

+

Strings in bencoded structures are not necessarily representing +text. Strings are raw byte buffers of a certain length. If a +string is meant to be interpreted as text, it is required to +be UTF-8 encoded. See BEP 3.

+

There are two mechanims to decode bencoded buffers in libtorrent.

+

The most flexible one is bdecode(), which returns a structure +represented by entry. When a buffer is decoded with this function, +it can be discarded. The entry does not contain any references back +to it. This means that bdecode() actually copies all the data out +of the buffer and into its own hierarchy. This makes this +function potentially expensive, if you're parsing large amounts +of data.

+

Another consideration is that bdecode() is a recursive parser. +For this reason, in order to avoid DoS attacks by triggering +a stack overflow, there is a recursion limit. This limit is +a sanity check to make sure it doesn't run the risk of +busting the stack.

+

The second mechanism is lazy_bdecode(), which returns a +bencoded structure represented by lazy_entry. This function +builds a tree that points back into the original buffer. +The returned lazy_entry will not be valid once the buffer +it was parsed out of is discarded.

+

Not only is this function more efficient because of less +memory allocation and data copy, the parser is also not +recursive, which means it probably performs a little bit +better and can have a higher recursion limit on the structures +it's parsing.

+
+

invalid_encoding

+

Declared in "libtorrent/bencode.hpp"

+

thrown by bdecode() if the provided bencoded buffer does not contain +valid encoding.

+
+struct invalid_encoding: std::exception
+{
+   virtual const char* what () const throw();
+};
+
+
+
+

type_error

+

Declared in "libtorrent/entry.hpp"

+

thrown by any accessor function of entry if the accessor +function requires a type different than the actual type +of the entry object.

+
+struct type_error: std::runtime_error
+{
+   type_error (const char* error);
+};
+
+
+
+

entry

+

Declared in "libtorrent/entry.hpp"

+

The entry class represents one node in a bencoded hierarchy. It works as a +variant type, it can be either a list, a dictionary (std::map), an integer +or a string.

+
+class entry
+{
+   data_type type () const;
+   entry (list_type const&);
+   entry (integer_type const&);
+   entry (dictionary_type const&);
+   entry (string_type const&);
+   entry (data_type t);
+   void operator= (string_type const&);
+   void operator= (entry const&);
+   void operator= (integer_type const&);
+   void operator= (lazy_entry const&);
+   void operator= (dictionary_type const&);
+   void operator= (list_type const&);
+   const integer_type& integer () const;
+   const string_type& string () const;
+   const dictionary_type& dict () const;
+   string_type& string ();
+   list_type& list ();
+   dictionary_type& dict ();
+   integer_type& integer ();
+   const list_type& list () const;
+   void swap (entry& e);
+   entry& operator[] (std::string const& key);
+   const entry& operator[] (std::string const& key) const;
+   entry& operator[] (char const* key);
+   const entry& operator[] (char const* key) const;
+   entry const* find_key (char const* key) const;
+   entry* find_key (char const* key);
+   entry* find_key (std::string const& key);
+   entry const* find_key (std::string const& key) const;
+   std::string to_string () const;
+
+   enum data_type
+   {
+      int_t,
+      string_t,
+      list_t,
+      dictionary_t,
+      undefined_t,
+   };
+
+   mutable boost::uint8_t m_type_queried:1;
+};
+
+
+

type()

+
+data_type type () const;
+
+

returns the concrete type of the entry

+
+
+

entry()

+
+entry (list_type const&);
+entry (integer_type const&);
+entry (dictionary_type const&);
+entry (string_type const&);
+
+

constructors directly from a specific type. +The content of the argument is copied into the +newly constructed entry

+
+
+

entry()

+
+entry (data_type t);
+
+

construct an empty entry of the specified type. +see data_type enum.

+
+
+

operator=()

+
+void operator= (string_type const&);
+void operator= (entry const&);
+void operator= (integer_type const&);
+void operator= (lazy_entry const&);
+void operator= (dictionary_type const&);
+void operator= (list_type const&);
+
+

copies the structure of the right hand side into this +entry.

+ + + +
+
+

string() dict() integer() list()

+
+const integer_type& integer () const;
+const string_type& string () const;
+const dictionary_type& dict () const;
+string_type& string ();
+list_type& list ();
+dictionary_type& dict ();
+integer_type& integer ();
+const list_type& list () const;
+
+

The integer(), string(), list() and dict() functions +are accessors that return the respective type. If the entry object isn't of the +type you request, the accessor will throw libtorrent_exception (which derives from +std::runtime_error). You can ask an entry for its type through the +type() function.

+

If you want to create an entry you give it the type you want it to have in its +constructor, and then use one of the non-const accessors to get a reference which you then +can assign the value you want it to have.

+

The typical code to get info from a torrent file will then look like this:

+
+entry torrent_file;
+// ...
+
+// throws if this is not a dictionary
+entry::dictionary_type const& dict = torrent_file.dict();
+entry::dictionary_type::const_iterator i;
+i = dict.find("announce");
+if (i != dict.end())
+{
+        std::string tracker_url = i->second.string();
+        std::cout << tracker_url << "\n";
+}
+
+

The following code is equivalent, but a little bit shorter:

+
+entry torrent_file;
+// ...
+
+// throws if this is not a dictionary
+if (entry* i = torrent_file.find_key("announce"))
+{
+        std::string tracker_url = i->string();
+        std::cout << tracker_url << "\n";
+}
+
+

To make it easier to extract information from a torrent file, the class torrent_info +exists.

+
+
+

swap()

+
+void swap (entry& e);
+
+

swaps the content of this with e.

+
+
+

operator[]()

+
+entry& operator[] (std::string const& key);
+const entry& operator[] (std::string const& key) const;
+entry& operator[] (char const* key);
+const entry& operator[] (char const* key) const;
+
+

All of these functions requires the entry to be a dictionary, if it isn't they +will throw libtorrent::type_error.

+

The non-const versions of the operator[] will return a reference to either +the existing element at the given key or, if there is no element with the +given key, a reference to a newly inserted element at that key.

+

The const version of operator[] will only return a reference to an +existing element at the given key. If the key is not found, it will throw +libtorrent::type_error.

+
+
+

find_key()

+
+entry const* find_key (char const* key) const;
+entry* find_key (char const* key);
+entry* find_key (std::string const& key);
+entry const* find_key (std::string const& key) const;
+
+

These functions requires the entry to be a dictionary, if it isn't they +will throw libtorrent::type_error.

+

They will look for an element at the given key in the dictionary, if the +element cannot be found, they will return 0. If an element with the given +key is found, the return a pointer to it.

+
+
+

enum data_type

+

Declared in "libtorrent/entry.hpp"

+ +++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
namevaluedescription
int_t0 
string_t1 
list_t2 
dictionary_t3 
undefined_t4 
+
+
m_type_queried
+
in debug mode this is set to false by bdecode +to indicate that the program has not yet queried +the type of this entry, and sould not assume +that it has a certain type. This is asserted in +the accessor functions. This does not apply if +exceptions are used.
+
+
+
+
+

pascal_string

+

Declared in "libtorrent/lazy_entry.hpp"

+

this is a string that is not NULL-terminated. Instead it +comes with a length, specified in bytes. This is particularly +useful when parsing bencoded structures, because strings are +not NULL-terminated internally, and requiring NULL termination +would require copying the string.

+

see lazy_entry::string_pstr().

+
+struct pascal_string
+{
+   pascal_string (char const* p, int l);
+   bool operator< (pascal_string const& rhs) const;
+
+   int len;
+   char const* ptr;
+};
+
+
+

pascal_string()

+
+pascal_string (char const* p, int l);
+
+

construct a string pointing to the characters at p +of length l characters. No NULL termination is required.

+
+
+

operator<()

+
+bool operator< (pascal_string const& rhs) const;
+
+

lexicographical comparison of strings. Order is consisten +with memcmp.

+
+
len
+
the number of characters in the string.
+
+
+
ptr
+
the pointer to the first character in the string. This is +not NULL terminated, but instead consult the len field +to know how many characters follow.
+
+
+
+
+

lazy_entry

+

Declared in "libtorrent/lazy_entry.hpp"

+

this object represent a node in a bencoded structure. It is a variant +type whose concrete type is one of:

+
    +
  1. dictionary (maps strings -> lazy_entry)
  2. +
  3. list (sequence of lazy_entry, i.e. heterogenous)
  4. +
  5. integer
  6. +
  7. string
  8. +
+

There is also a none type, which is used for uninitialized +lazy_entries.

+
+struct lazy_entry
+{
+   entry_type_t type () const;
+   void construct_int (char const* start, int length);
+   boost::int64_t int_value () const;
+   char const* string_ptr () const;
+   char const* string_cstr () const;
+   pascal_string string_pstr () const;
+   std::string string_value () const;
+   int string_length () const;
+   lazy_entry const* dict_find_string (char const* name) const;
+   lazy_entry* dict_find (char const* name);
+   lazy_entry const* dict_find (char const* name) const;
+   pascal_string dict_find_pstr (char const* name) const;
+   std::string dict_find_string_value (char const* name) const;
+   boost::int64_t dict_find_int_value (char const* name, boost::int64_t default_val = 0) const;
+   lazy_entry const* dict_find_int (char const* name) const;
+   lazy_entry const* dict_find_list (char const* name) const;
+   lazy_entry const* dict_find_dict (char const* name) const;
+   std::pair<std::string, lazy_entry const*> dict_at (int i) const;
+   int dict_size () const;
+   lazy_entry* list_at (int i);
+   lazy_entry const* list_at (int i) const;
+   std::string list_string_value_at (int i) const;
+   pascal_string list_pstr_at (int i) const;
+   boost::int64_t list_int_value_at (int i, boost::int64_t default_val = 0) const;
+   int list_size () const;
+   std::pair<char const*, int> data_section () const;
+   void swap (lazy_entry& e);
+
+   enum entry_type_t
+   {
+      none_t,
+      dict_t,
+      list_t,
+      string_t,
+      int_t,
+   };
+};
+
+
+

type()

+
+entry_type_t type () const;
+
+

tells you which specific type this lazy entry has. +See entry_type_t. The type determines which subset of +member functions are valid to use.

+
+
+

construct_int()

+
+void construct_int (char const* start, int length);
+
+

start points to the first decimal digit +length is the number of digits

+
+
+

int_value()

+
+boost::int64_t int_value () const;
+
+

requires the type to be an integer. return the integer value

+
+
+

string_ptr()

+
+char const* string_ptr () const;
+
+

the string is not null-terminated! +use string_length() to determine how many bytes +are part of the string.

+
+
+

string_cstr()

+
+char const* string_cstr () const;
+
+

this will return a null terminated string +it will write to the source buffer!

+
+
+

string_pstr()

+
+pascal_string string_pstr () const;
+
+

if this is a string, returns a pascal_string +representing the string value.

+
+
+

string_value()

+
+std::string string_value () const;
+
+

if this is a string, returns the string as a std::string. +(which requires a copy)

+
+
+

string_length()

+
+int string_length () const;
+
+

if the lazy_entry is a string, returns the +length of the string, in bytes.

+ +
+
+

dict_find() dict_find_string()

+
+lazy_entry const* dict_find_string (char const* name) const;
+lazy_entry* dict_find (char const* name);
+lazy_entry const* dict_find (char const* name) const;
+
+

if this is a dictionary, look for a key name, and return +a pointer to its value, or NULL if there is none.

+ +
+
+

dict_find_pstr() dict_find_string_value()

+
+pascal_string dict_find_pstr (char const* name) const;
+std::string dict_find_string_value (char const* name) const;
+
+

if this is a dictionary, look for a key name whose value +is a string. If such key exist, return a pointer to +its value, otherwise NULL.

+ +
+
+

dict_find_int_value() dict_find_int()

+
+boost::int64_t dict_find_int_value (char const* name, boost::int64_t default_val = 0) const;
+lazy_entry const* dict_find_int (char const* name) const;
+
+

if this is a dictionary, look for a key name whose value +is an int. If such key exist, return a pointer to its value, +otherwise NULL.

+ +
+
+

dict_find_list() dict_find_dict()

+
+lazy_entry const* dict_find_list (char const* name) const;
+lazy_entry const* dict_find_dict (char const* name) const;
+
+

these functions require that this is a dictionary. +(this->type() == dict_t). They look for an element with the +specified name in the dictionary. dict_find_dict only +finds dictionaries and dict_find_list only finds lists. +if no key with the corresponding value of the right type is +found, NULL is returned.

+
+
+

dict_at()

+
+std::pair<std::string, lazy_entry const*> dict_at (int i) const;
+
+

if this is a dictionary, return the key value pair at +position i from the dictionary.

+
+
+

dict_size()

+
+int dict_size () const;
+
+

requires that this is a dictionary. return the +number of items in it

+
+
+

list_at()

+
+lazy_entry* list_at (int i);
+lazy_entry const* list_at (int i) const;
+
+

requires that this is a list. return +the item at index i.

+ +
+
+

list_string_value_at() list_pstr_at()

+
+std::string list_string_value_at (int i) const;
+pascal_string list_pstr_at (int i) const;
+
+

these functions require this to have the type list. +(this->type() == list_t). list_string_value_at returns +the string at index i. list_pstr_at +returns a pascal_string of the string value at index i. +if the element at i is not a string, an empty string +is returned.

+
+
+

list_int_value_at()

+
+boost::int64_t list_int_value_at (int i, boost::int64_t default_val = 0) const;
+
+

this function require this to have the type list. +(this->type() == list_t). returns the integer value at +index i. If the element at i is not an integer +default_val is returned, which defaults to 0.

+
+
+

list_size()

+
+int list_size () const;
+
+

if this is a list, return the number of items in it.

+
+
+

data_section()

+
+std::pair<char const*, int> data_section () const;
+
+

returns pointers into the source buffer where +this entry has its bencoded data

+
+
+

swap()

+
+void swap (lazy_entry& e);
+
+

swap values of this and e.

+
+
+

enum entry_type_t

+

Declared in "libtorrent/lazy_entry.hpp"

+ +++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
namevaluedescription
none_t0 
dict_t1 
list_t2 
string_t3 
int_t4 
+ +
+
+

bdecode() bencode()

+

Declared in "libtorrent/bencode.hpp"

+
+template<class InIt> entry bdecode (InIt start, InIt end);
+template<class OutIt> int bencode (OutIt out, const entry& e);
+template<class InIt> entry bdecode (InIt start, InIt end, int& len);
+
+

These functions will encode data to bencoded or decode bencoded data.

+

If possible, lazy_bdecode() should be preferred over bdecode().

+

The entry class is the internal representation of the bencoded data +and it can be used to retrieve information, an entry can also be build by +the program and given to bencode() to encode it into the OutIt +iterator.

+

The OutIt and InIt are iterators +(InputIterator and OutputIterator respectively). They +are templates and are usually instantiated as ostream_iterator, +back_insert_iterator or istream_iterator. These +functions will assume that the iterator refers to a character +(char). So, if you want to encode entry e into a buffer +in memory, you can do it like this:

+
+std::vector<char> buffer;
+bencode(std::back_inserter(buf), e);
+
+

If you want to decode a torrent file from a buffer in memory, you can do it like this:

+
+std::vector<char> buffer;
+// ...
+entry e = bdecode(buf.begin(), buf.end());
+
+

Or, if you have a raw char buffer:

+
+const char* buf;
+// ...
+entry e = bdecode(buf, buf + data_size);
+
+

Now we just need to know how to retrieve information from the entry.

+

If bdecode() encounters invalid encoded data in the range given to it +it will throw libtorrent_exception.

+
+
+

operator<<()

+

Declared in "libtorrent/entry.hpp"

+
+inline std::ostream& operator<< (std::ostream& os, const entry& e);
+
+
+
+

lazy_bdecode()

+

Declared in "libtorrent/lazy_entry.hpp"

+
+int lazy_bdecode (char const* start, char const* end
+   , lazy_entry& ret, error_code& ec, int* error_pos = 0
+   , int depth_limit = 1000, int item_limit = 1000000);
+
+

This function decodes bencoded data.

+

Whenever possible, lazy_bdecode() should be preferred over bdecode(). +It is more efficient and more secure. It supports having constraints on the +amount of memory is consumed by the parser.

+

lazy refers to the fact that it doesn't copy any actual data out of the +bencoded buffer. It builds a tree of lazy_entry which has pointers into +the bencoded buffer. This makes it very fast and efficient. On top of that, +it is not recursive, which saves a lot of stack space when parsing deeply +nested trees. However, in order to protect against potential attacks, the +depth_limit and item_limit control how many levels deep the tree is +allowed to get. With recursive parser, a few thousand levels would be enough +to exhaust the threads stack and terminate the process. The item_limit +protects against very large structures, not necessarily deep. Each bencoded +item in the structure causes the parser to allocate some amount of memory, +this memory is constant regardless of how much data actually is stored in +the item. One potential attack is to create a bencoded list of hundreds of +thousands empty strings, which would cause the parser to allocate a significant +amount of memory, perhaps more than is available on the machine, and effectively +provide a denial of service. The default item limit is set as a reasonable +upper limit for desktop computers. Very few torrents have more items in them. +The limit corresponds to about 25 MB, which might be a bit much for embedded +systems.

+

start and end defines the bencoded buffer to be decoded. ret is +the lazy_entry which is filled in with the whole decoded tree. ec +is a reference to an error_code which is set to describe the error encountered +in case the function fails. error_pos is an optional pointer to an int, +which will be set to the byte offset into the buffer where an error occurred, +in case the function fails.

+
+
+

get_bdecode_category()

+

Declared in "libtorrent/lazy_entry.hpp"

+
+boost::system::error_category& get_bdecode_category ();
+
+

get the error_category for bdecode errors

+
+
+

enum error_code_enum

+

Declared in "libtorrent/lazy_entry.hpp"

+ +++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
namevaluedescription
no_error0Not an error
expected_string1expected string in bencoded string
expected_colon2expected colon in bencoded string
unexpected_eof3unexpected end of file in bencoded string
expected_value4expected value (list, dict, int or string) in bencoded string
depth_exceeded5bencoded recursion depth limit exceeded
limit_exceeded6bencoded item count limit exceeded
error_code_max7the number of error codes
+
+
+
+ +
+ + +
+ + diff --git a/docs/reference-Core.html b/docs/reference-Core.html new file mode 100644 index 000000000..5cb4141e1 --- /dev/null +++ b/docs/reference-Core.html @@ -0,0 +1,3408 @@ + + + + + + +Core + + + + + + + + +
+
+
+ +
+ +
+

Core

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

disk_buffer_holder

+

Declared in "libtorrent/disk_buffer_holder.hpp"

+

The disk buffer holder acts like a scoped_ptr that frees a disk buffer +when it's destructed, unless it's released. release returns the disk +buffer and transferres ownership and responsibility to free it to the caller.

+

A disk buffer is freed by passing it to session_impl::free_disk_buffer().

+

buffer() returns the pointer without transferring responsibility. If +this buffer has been released, buffer() will return 0.

+
+struct disk_buffer_holder
+{
+   disk_buffer_holder (disk_buffer_pool& disk_pool, char* buf);
+   ~disk_buffer_holder ();
+   char* release ();
+   char* get () const;
+   void reset (char* buf = 0);
+   void swap (disk_buffer_holder& h);
+};
+
+
+

disk_buffer_holder()

+
+disk_buffer_holder (disk_buffer_pool& disk_pool, char* buf);
+
+

construct a buffer holder that will free the held buffer +using a disk buffer pool directly (there's only one +disk_buffer_pool per session)

+
+
+

~disk_buffer_holder()

+
+~disk_buffer_holder ();
+
+

frees any unreleased disk buffer held by this object

+
+
+

release()

+
+char* release ();
+
+

return the held disk buffer and clear it from the +holder. The responsibility to free it is passed on +to the caller

+
+
+

get()

+
+char* get () const;
+
+

return a pointer to the held buffer

+
+
+

reset()

+
+void reset (char* buf = 0);
+
+

set the holder object to hold the specified buffer +(or NULL by default). If it's already holding a +disk buffer, it will first be freed.

+
+
+

swap()

+
+void swap (disk_buffer_holder& h);
+
+

swap pointers of two disk buffer holders.

+
+
+
+

peer_info

+

Declared in "libtorrent/peer_info.hpp"

+

holds information and statistics about one peer +that libtorrent is connected to

+
+struct peer_info
+{
+   enum peer_flags_t
+   {
+      interesting,
+      choked,
+      remote_interested,
+      remote_choked,
+      supports_extensions,
+      local_connection,
+      handshake,
+      connecting,
+      queued,
+      on_parole,
+      seed,
+      optimistic_unchoke,
+      snubbed,
+      upload_only,
+      endgame_mode,
+      holepunched,
+      i2p_socket,
+      utp_socket,
+      rc4_encrypted,
+      plaintext_encrypted,
+   };
+
+   enum peer_source_flags
+   {
+      tracker,
+      dht,
+      pex,
+      lsd,
+      resume_data,
+      incoming,
+   };
+
+   enum bw_state
+   {
+      bw_idle,
+      bw_limit,
+      bw_network,
+      bw_disk,
+   };
+
+   enum connection_type_t
+   {
+      standard_bittorrent,
+      web_seed,
+      http_seed,
+      bittorrent_utp,
+   };
+
+   unsigned int flags;
+   int source;
+   char read_state;
+   char write_state;
+   tcp::endpoint ip;
+   int up_speed;
+   int down_speed;
+   int payload_up_speed;
+   int payload_down_speed;
+   size_type total_download;
+   size_type total_upload;
+   peer_id pid;
+   bitfield pieces;
+   int upload_limit;
+   int download_limit;
+   time_duration last_request;
+   time_duration last_active;
+   time_duration download_queue_time;
+   int queue_bytes;
+   int request_timeout;
+   int send_buffer_size;
+   int used_send_buffer;
+   int receive_buffer_size;
+   int used_receive_buffer;
+   int num_hashfails;
+   char country[2];
+   std::string inet_as_name;
+   int inet_as;
+   size_type load_balancing;
+   int download_queue_length;
+   int timed_out_requests;
+   int busy_requests;
+   int requests_in_buffer;
+   int target_dl_queue_length;
+   int upload_queue_length;
+   int failcount;
+   int downloading_piece_index;
+   int downloading_block_index;
+   int downloading_progress;
+   int downloading_total;
+   std::string client;
+   int connection_type;
+   int remote_dl_rate;
+   int pending_disk_bytes;
+   int send_quota;
+   int receive_quota;
+   int rtt;
+   int num_pieces;
+   int download_rate_peak;
+   int upload_rate_peak;
+   int progress_ppm;
+   int estimated_reciprocation_rate;
+   tcp::endpoint local_endpoint;
+};
+
+
+

enum peer_flags_t

+

Declared in "libtorrent/peer_info.hpp"

+ +++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
namevaluedescription
interesting1we are interested in pieces from this peer.
choked2we have choked this peer.
remote_interested4the peer is interested in us
remote_choked8the peer has choked us.
supports_extensions16means that this peer supports the +extension protocol.
local_connection32The connection was initiated by us, the peer has a +listen port open, and that port is the same as in the +address of this peer. If this flag is not set, this +peer connection was opened by this peer connecting to +us.
handshake64The connection is opened, and waiting for the +handshake. Until the handshake is done, the peer +cannot be identified.
connecting128The connection is in a half-open state (i.e. it is +being connected).
queued256The connection is currently queued for a connection +attempt. This may happen if there is a limit set on +the number of half-open TCP connections.
on_parole512The peer has participated in a piece that failed the +hash check, and is now "on parole", which means we're +only requesting whole pieces from this peer until +it either fails that piece or proves that it doesn't +send bad data.
seed1024This peer is a seed (it has all the pieces).
optimistic_unchoke2048This peer is subject to an optimistic unchoke. It has +been unchoked for a while to see if it might unchoke +us in return an earn an upload/unchoke slot. If it +doesn't within some period of time, it will be choked +and another peer will be optimistically unchoked.
snubbed4096This peer has recently failed to send a block within +the request timeout from when the request was sent. +We're currently picking one block at a time from this +peer.
upload_only8192This peer has either explicitly (with an extension) +or implicitly (by becoming a seed) told us that it +will not downloading anything more, regardless of +which pieces we have.
endgame_mode16384This means the last time this peer picket a piece, +it could not pick as many as it wanted because there +were not enough free ones. i.e. all pieces this peer +has were already requested from other peers.
holepunched32768This flag is set if the peer was in holepunch mode +when the connection succeeded. This typically only +happens if both peers are behind a NAT and the peers +connect via the NAT holepunch mechanism.
i2p_socket65536indicates that this socket is runnin on top of the +I2P transport.
utp_socket131072indicates that this socket is a uTP socket
rc4_encrypted1048576this connection is obfuscated with RC4
plaintext_encrypted2097152the handshake of this connection was obfuscated +with a diffie-hellman exchange
+
+
+

enum peer_source_flags

+

Declared in "libtorrent/peer_info.hpp"

+ +++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
namevaluedescription
tracker1The peer was received from the tracker.
dht2The peer was received from the kademlia DHT.
pex4The peer was received from the peer exchange +extension.
lsd8The peer was received from the local service +discovery (The peer is on the local network).
resume_data16The peer was added from the fast resume data.
incoming32we received an incoming connection from this peer
+
+
+

enum bw_state

+

Declared in "libtorrent/peer_info.hpp"

+ +++++ + + + + + + + + + + + + + + + + + + + + + + + + +
namevaluedescription
bw_idle0The peer is not waiting for any external events to +send or receive data.
bw_limit1The peer is waiting for the rate limiter.
bw_network2The peer has quota and is currently waiting for a +network read or write operation to complete. This is +the state all peers are in if there are no bandwidth +limits.
bw_disk4The peer is waiting for the disk I/O thread to catch +up writing buffers to disk before downloading more.
+
+
+

enum connection_type_t

+

Declared in "libtorrent/peer_info.hpp"

+ +++++ + + + + + + + + + + + + + + + + + + + + + + + + +
namevaluedescription
standard_bittorrent0Regular bittorrent connection over TCP
web_seed1Bittorrent connection over uTP
http_seed2HTTP connection using the BEP 19 protocol
bittorrent_utp3HTTP connection using the BEP 17 protocol
+
+
flags
+
tells you in which state the peer is in. It is set to +any combination of the peer_flags_t enum.
+
+
+
source
+
a combination of flags describing from which sources this peer +was received.
+
+ +
+
read_state write_state
+
bitmasks indicating what state this peer +is in with regards to sending and receiving data. The states are declared in the +bw_state enum.
+
+
+
ip
+
the IP-address to this peer. The type is an asio endpoint. For +more info, see the asio documentation.
+
+ +
+
up_speed down_speed
+
the current upload and download speed +we have to and from this peer (including any protocol messages). +updated about once per second
+
+ +
+
payload_up_speed payload_down_speed
+
The transfer rates +of payload data only +updated about once per second
+
+ +
+
total_download total_upload
+
the total number of bytes downloaded +from and uploaded to this peer. These numbers do not include the protocol chatter, but only +the payload data.
+
+
+
pid
+
the peer's id as used in the bit torrent protocol. This id can be used to +extract 'fingerprints' from the peer. Sometimes it can tell you which client the peer +is using. See identify_client()_
+
+
+
pieces
+
a bitfield, with one bit per piece in the torrent. +Each bit tells you if the peer has that piece (if it's set to 1) +or if the peer miss that piece (set to 0).
+
+ +
+
upload_limit download_limit
+
the number of bytes per second we are allowed to send to or receive from this +peer. It may be -1 if there's no local limit on the peer. The global +limit and the torrent limit may also be enforced.
+
+ +
+
last_request last_active
+
the time since we last sent a request +to this peer and since any transfer occurred with this peer
+
+ +
+
download_queue_time queue_bytes
+
the time until all blocks in the request +queue will be d
+
+
+
request_timeout
+
the number of seconds until the current front piece request +will time out. This timeout can be adjusted through session_settings::request_timeout. +-1 means that there is not outstanding request.
+
+ +
+
send_buffer_size used_send_buffer
+
the number of bytes allocated +and used for the peer's send buffer, respectively.
+
+ +
+
receive_buffer_size used_receive_buffer
+
the number of bytes +allocated and used as receive buffer, respectively.
+
+
+
num_hashfails
+
the number of pieces this peer has participated in +sending us that turned out to fail the hash check.
+
+
+
country[2]
+
the two letter ISO 3166 country code for the country the peer +is connected from. If the country hasn't been resolved yet, both chars are set +to 0. If the resolution failed for some reason, the field is set to "--". If the +resolution service returns an invalid country code, it is set to "!!". +The countries.nerd.dk service is used to look up countries. This field will +remain set to 0 unless the torrent is set to resolve countries, see resolve_countries().
+
+
+
inet_as_name
+
the name of the AS this peer is located in. This might be +an empty string if there is no name in the geo ip database.
+
+
+
inet_as
+
the AS number the peer is located in.
+
+
+
load_balancing
+
a measurement of the balancing of free download (that we get) +and free upload that we give. Every peer gets a certain amount of free upload, but +this member says how much extra free upload this peer has got. If it is a negative +number it means that this was a peer from which we have got this amount of free +download.
+
+
+
download_queue_length
+
this is the number of requests +we have sent to this peer +that we haven't got a response +for yet
+
+
+
timed_out_requests
+
the number of block requests that have +timed out, and are still in the download +queue
+
+
+
busy_requests
+
the number of busy requests in the download +queue. A budy request is a request for a block +we've also requested from a different peer
+
+
+
requests_in_buffer
+
the number of requests messages that are currently in the +send buffer waiting to be sent.
+
+
+
target_dl_queue_length
+
the number of requests that is +tried to be maintained (this is +typically a function of download speed)
+
+
+
upload_queue_length
+
the number of piece-requests we have received from this peer +that we haven't answered with a piece yet.
+
+
+
failcount
+
the number of times this peer has "failed". i.e. failed to connect +or disconnected us. The failcount is decremented when we see this peer in a tracker +response or peer exchange message.
+
+ + + +
+
downloading_piece_index downloading_block_index downloading_progress downloading_total
+
You can know which piece, and which part of that piece, that is currently being +downloaded from a specific peer by looking at these four members. +downloading_piece_index is the index of the piece that is currently being downloaded. +This may be set to -1 if there's currently no piece downloading from this peer. If it is +>= 0, the other three members are valid. downloading_block_index is the index of the +block (or sub-piece) that is being downloaded. downloading_progress is the number +of bytes of this block we have received from the peer, and downloading_total is +the total number of bytes in this block.
+
+
+
client
+
a string describing the software at the other end of the connection. +In some cases this information is not available, then it will contain a string +that may give away something about which software is running in the other end. +In the case of a web seed, the server type and version will be a part of this +string.
+
+
+
connection_type
+
the kind of connection this peer uses. See connection_type_t.
+
+
+
remote_dl_rate
+
an estimate of the rate this peer is downloading at, in +bytes per second.
+
+
+
pending_disk_bytes
+
the number of bytes this peer has pending in the +disk-io thread. Downloaded and waiting to be written to disk. This is what +is capped by session_settings::max_queued_disk_bytes.
+
+ +
+
send_quota receive_quota
+
the number of bytes this peer has been +assigned to be allowed to send and receive until it has to request more quota +from the bandwidth manager.
+
+
+
rtt
+
an estimated round trip time to this peer, in milliseconds. It is +estimated by timing the the tcp connect(). It may be 0 for incoming connections.
+
+
+
num_pieces
+
the number of pieces this peer has.
+
+ +
+
download_rate_peak upload_rate_peak
+
the highest download and upload +rates seen on this connection. They are given in bytes per second. This number is +reset to 0 on reconnect.
+
+
+
progress_ppm
+
indicates the download progress of the peer in the range [0, 1000000] +(parts per million).
+
+
+
local_endpoint
+
the IP and port pair the socket is bound to locally. i.e. the IP +address of the interface it's going out over. This may be useful for multi-homed +clients with multiple interfaces to the internet.
+
+
+
+
+

peer_list_entry

+

Declared in "libtorrent/peer_info.hpp"

+
+struct peer_list_entry
+{
+   enum flags_t
+   {
+      banned,
+   };
+
+   tcp::endpoint ip;
+   int flags;
+   boost::uint8_t failcount;
+   boost::uint8_t source;
+};
+
+
+

enum flags_t

+

Declared in "libtorrent/peer_info.hpp"

+ +++++ + + + + + + + + + + + + +
namevaluedescription
banned1 
+
+
+
+

peer_request

+

Declared in "libtorrent/peer_request.hpp"

+

represents a byte range within a piece. Internally this is +is used for incoming piece requests.

+
+struct peer_request
+{
+   bool operator== (peer_request const& r) const;
+
+   int piece;
+   int start;
+   int length;
+};
+
+
+
piece
+
the index of the piece in which the range starts.
+
+
+
start
+
the offset within that piece where the range starts.
+
+
+
length
+
the size of the range, in bytes.
+
+
+
+

piece_block_progress

+

Declared in "libtorrent/piece_block_progress.hpp"

+
+struct piece_block_progress
+{
+   int piece_index;
+   int block_index;
+   int bytes_downloaded;
+   int full_block_bytes;
+};
+
+ +
+
piece_index block_index
+
the piece and block index +determines exactly which +part of the torrent that +is currently being downloaded
+
+
+
bytes_downloaded
+
the number of bytes we have received +of this block
+
+
+
full_block_bytes
+
the number of bytes in the block
+
+
+
+

block_info

+

Declared in "libtorrent/torrent_handle.hpp"

+

holds the state of a block in a piece. Who we requested +it from and how far along we are at downloading it.

+
+struct block_info
+{
+   void set_peer (tcp::endpoint const& ep);
+   tcp::endpoint peer () const;
+
+   enum block_state_t
+   {
+      none,
+      requested,
+      writing,
+      finished,
+   };
+
+   unsigned bytes_progress:15;
+   unsigned block_size:15;
+   unsigned state:2;
+   unsigned num_peers:14;
+};
+
+ +
+

set_peer() peer()

+
+void set_peer (tcp::endpoint const& ep);
+tcp::endpoint peer () const;
+
+

The peer is the ip address of the peer this block was downloaded from.

+
+
+

enum block_state_t

+

Declared in "libtorrent/torrent_handle.hpp"

+ +++++ + + + + + + + + + + + + + + + + + + + + + + + + +
namevaluedescription
none0This block has not been downloaded or requested form any peer.
requested1The block has been requested, but not completely downloaded yet.
writing2The block has been downloaded and is currently queued for being written to disk.
finished3The block has been written to disk.
+
+
bytes_progress
+
the number of bytes that have been received for this block
+
+
+
block_size
+
the total number of bytes in this block.
+
+
+
state
+
the state this block is in (see block_state_t)
+
+
+
num_peers
+
the number of peers that is currently requesting this block. Typically this +is 0 or 1, but at the end of the torrent blocks may be requested by more peers in parallel to +speed things up.
+
+
+
+
+

partial_piece_info

+

Declared in "libtorrent/torrent_handle.hpp"

+
+struct partial_piece_info
+{
+   enum state_t
+   {
+      none,
+      slow,
+      medium,
+      fast,
+   };
+
+   int piece_index;
+   int blocks_in_piece;
+   int finished;
+   int writing;
+   int requested;
+   block_info* blocks;
+   state_t piece_state;
+};
+
+
+

enum state_t

+

Declared in "libtorrent/torrent_handle.hpp"

+ +++++ + + + + + + + + + + + + + + + + + + + + + + + + +
namevaluedescription
none0 
slow1 
medium2 
fast3 
+
+
piece_index
+
the index of the piece in question. blocks_in_piece is the +number of blocks in this particular piece. This number will be the same for most pieces, but +the last piece may have fewer blocks than the standard pieces.
+
+
+
finished
+
the number of blocks in the finished state
+
+
+
writing
+
the number of blocks in the writing state
+
+
+
requested
+
the number of blocks in the requested state
+
+
+
blocks
+

this is an array of blocks_in_piece number of +items. One for each block in the piece.

+
+

Warning

+

This is a pointer that points to an array +that's owned by the session object. The next time +get_download_queue() is called, it will be invalidated.

+
+
+
+
+
piece_state
+

the download speed class this piece falls into. +this is used internally to cluster peers of the same +speed class together when requesting blocks.

+

set to either fast, medium, slow or none. It tells which +download rate category the peers downloading this piece falls into. none means that no +peer is currently downloading any part of the piece. Peers prefer picking pieces from +the same category as themselves. The reason for this is to keep the number of partially +downloaded pieces down. Pieces set to none can be converted into any of fast, +medium or slow as soon as a peer want to download from it.

+
+
+
+
+
+

torrent_handle

+

Declared in "libtorrent/torrent_handle.hpp"

+

You will usually have to store your torrent handles somewhere, since it's the +object through which you retrieve information about the torrent and aborts the torrent.

+
+

Warning

+

Any member function that returns a value or fills in a value has to +be made synchronously. This means it has to wait for the main thread +to complete the query before it can return. This might potentially be +expensive if done from within a GUI thread that needs to stay responsive. +Try to avoid quering for information you don't need, and try to do it +in as few calls as possible. You can get most of the interesting information +about a torrent from the torrent_handle::status() call.

+
+

The default constructor will initialize the handle to an invalid state. Which +means you cannot perform any operation on it, unless you first assign it a +valid handle. If you try to perform any operation on an uninitialized handle, +it will throw invalid_handle.

+
+

Warning

+

All operations on a torrent_handle may throw libtorrent_exception +exception, in case the handle is no longer refering to a torrent. There is +one exception is_valid() will never throw. +Since the torrents are processed by a background thread, there is no +guarantee that a handle will remain valid between two calls.

+
+
+struct torrent_handle
+{
+   torrent_handle ();
+   void add_piece (int piece, char const* data, int flags = 0) const;
+   void read_piece (int piece) const;
+   bool have_piece (int piece) const;
+   void get_full_peer_list (std::vector<peer_list_entry>& v) const;
+   void get_peer_info (std::vector<peer_info>& v) const;
+   torrent_status status (boost::uint32_t flags = 0xffffffff) const;
+   void get_download_queue (std::vector<partial_piece_info>& queue) const;
+   void reset_piece_deadline (int index) const;
+   void set_piece_deadline (int index, int deadline, int flags = 0) const;
+   void set_priority (int prio) const;
+   void file_progress (std::vector<size_type>& progress, int flags = 0) const;
+   void clear_error () const;
+   std::vector<announce_entry> trackers () const;
+   void replace_trackers (std::vector<announce_entry> const&) const;
+   void add_tracker (announce_entry const&) const;
+   void add_url_seed (std::string const& url) const;
+   void remove_url_seed (std::string const& url) const;
+   std::set<std::string> url_seeds () const;
+   void add_http_seed (std::string const& url) const;
+   void remove_http_seed (std::string const& url) const;
+   std::set<std::string> http_seeds () const;
+   void add_extension (boost::function<boost::shared_ptr<torrent_plugin>(torrent*, void*)> const& ext
+      , void* userdata = 0);
+   bool set_metadata (char const* metadata, int size) const;
+   bool is_valid () const;
+   void pause (int flags = 0) const;
+   void resume () const;
+   void set_upload_mode (bool b) const;
+   void set_share_mode (bool b) const;
+   void flush_cache () const;
+   void apply_ip_filter (bool b) const;
+   void force_recheck () const;
+   void save_resume_data (int flags = 0) const;
+   bool need_save_resume_data () const;
+   void auto_managed (bool m) const;
+   void queue_position_down () const;
+   void queue_position_top () const;
+   int queue_position () const;
+   void queue_position_bottom () const;
+   void queue_position_up () const;
+   void resolve_countries (bool r);
+   bool resolve_countries () const;
+   void set_ssl_certificate (std::string const& certificate
+      , std::string const& private_key
+      , std::string const& dh_params
+      , std::string const& passphrase = "");
+   storage_interface* get_storage_impl () const;
+   boost::intrusive_ptr<torrent_info> torrent_file () const;
+   void use_interface (const char* net_interface) const;
+   void piece_availability (std::vector<int>& avail) const;
+   int piece_priority (int index) const;
+   void piece_priority (int index, int priority) const;
+   void prioritize_pieces (std::vector<int> const& pieces) const;
+   std::vector<int> piece_priorities () const;
+   int file_priority (int index) const;
+   void prioritize_files (std::vector<int> const& files) const;
+   void file_priority (int index, int priority) const;
+   std::vector<int> file_priorities () const;
+   void force_reannounce () const;
+   void force_dht_announce () const;
+   void force_reannounce (boost::posix_time::time_duration) const;
+   void scrape_tracker () const;
+   int upload_limit () const;
+   int download_limit () const;
+   void set_upload_limit (int limit) const;
+   void set_download_limit (int limit) const;
+   void set_sequential_download (bool sd) const;
+   void connect_peer (tcp::endpoint const& adr, int source = 0) const;
+   int max_uploads () const;
+   void set_max_uploads (int max_uploads) const;
+   int max_connections () const;
+   void set_max_connections (int max_connections) const;
+   void set_tracker_login (std::string const& name
+      , std::string const& password) const;
+   void move_storage (std::string const& save_path, int flags = 0) const;
+   void rename_file (int index, std::string const& new_name) const;
+   void super_seeding (bool on) const;
+   sha1_hash info_hash () const;
+   bool operator!= (const torrent_handle& h) const;
+   bool operator< (const torrent_handle& h) const;
+   bool operator== (const torrent_handle& h) const;
+   boost::shared_ptr<torrent> native_handle () const;
+
+   enum flags_t
+   {
+      overwrite_existing,
+   };
+
+   enum status_flags_t
+   {
+      query_distributed_copies,
+      query_accurate_download_counters,
+      query_last_seen_complete,
+      query_pieces,
+      query_verified_pieces,
+      query_torrent_file,
+      query_name,
+      query_save_path,
+   };
+
+   enum deadline_flags
+   {
+      alert_when_available,
+   };
+
+   enum file_progress_flags_t
+   {
+      piece_granularity,
+   };
+
+   enum pause_flags_t
+   {
+      graceful_pause,
+   };
+
+   enum save_resume_flags_t
+   {
+      flush_disk_cache,
+      save_info_dict,
+   };
+};
+
+
+

torrent_handle()

+
+torrent_handle ();
+
+

constructs a torrent handle that does not refer to a torrent. +i.e. is_valid() will return false.

+
+
+

add_piece()

+
+void add_piece (int piece, char const* data, int flags = 0) const;
+
+

This function will write data to the storage as piece piece, as if it had +been downloaded from a peer. data is expected to point to a buffer of as many +bytes as the size of the specified piece. The data in the buffer is copied and +passed on to the disk IO thread to be written at a later point.

+

By default, data that's already been downloaded is not overwritten by this buffer. If +you trust this data to be correct (and pass the piece hash check) you may pass the +overwrite_existing flag. This will instruct libtorrent to overwrite any data that +may already have been downloaded with this data.

+

Since the data is written asynchronously, you may know that is passed or failed the +hash check by waiting for piece_finished_alert or hash_failed_alert.

+
+
+

read_piece()

+
+void read_piece (int piece) const;
+
+

This function starts an asynchronous read operation of the specified piece from +this torrent. You must have completed the download of the specified piece before +calling this function.

+

When the read operation is completed, it is passed back through an alert, +read_piece_alert. Since this alert is a reponse to an explicit call, it will +always be posted, regardless of the alert mask.

+

Note that if you read multiple pieces, the read operations are not guaranteed to +finish in the same order as you initiated them.

+
+
+

have_piece()

+
+bool have_piece (int piece) const;
+
+

Returns true if this piece has been completely downloaded, and false otherwise.

+
+
+

get_peer_info()

+
+void get_peer_info (std::vector<peer_info>& v) const;
+
+

takes a reference to a vector that will be cleared and filled +with one entry for each peer connected to this torrent, given the handle is valid. If the +torrent_handle is invalid, it will throw libtorrent_exception exception. Each entry in +the vector contains information about that particular peer. See peer_info.

+
+
+

status()

+
+torrent_status status (boost::uint32_t flags = 0xffffffff) const;
+
+

status() will return a structure with information about the status of this +torrent. If the torrent_handle is invalid, it will throw libtorrent_exception exception. +See torrent_status. The flags argument filters what information is returned +in the torrent_status. Some information in there is relatively expensive to calculate, and +if you're not interested in it (and see performance issues), you can filter them out.

+

By default everything is included. The flags you can use to decide what to include are +defined in the status_flags_t enum.

+
+
+

get_download_queue()

+
+void get_download_queue (std::vector<partial_piece_info>& queue) const;
+
+

get_download_queue() takes a non-const reference to a vector which it will fill with +information about pieces that are partially downloaded or not downloaded at all but partially +requested. See partial_piece_info for the fields in the returned vector.

+ +
+
+

reset_piece_deadline() set_piece_deadline()

+
+void reset_piece_deadline (int index) const;
+void set_piece_deadline (int index, int deadline, int flags = 0) const;
+
+

This function sets or resets the deadline associated with a specific piece +index (index). libtorrent will attempt to download this entire piece before +the deadline expires. This is not necessarily possible, but pieces with a more +recent deadline will always be prioritized over pieces with a deadline further +ahead in time. The deadline (and flags) of a piece can be changed by calling this +function again.

+

The flags parameter can be used to ask libtorrent to send an alert once the +piece has been downloaded, by passing alert_when_available. When set, the +read_piece_alert alert will be delivered, with the piece data, when it's downloaded.

+

If the piece is already downloaded when this call is made, nothing happens, unless +the alert_when_available flag is set, in which case it will do the same thing +as calling read_piece() for index.

+

deadline is the number of milliseconds until this piece should be completed.

+

reset_piece_deadline removes the deadline from the piece. If it hasn't already +been downloaded, it will no longer be considered a priority.

+
+
+

set_priority()

+
+void set_priority (int prio) const;
+
+

This sets the bandwidth priority of this torrent. The priority of a torrent determines +how much bandwidth its peers are assigned when distributing upload and download rate quotas. +A high number gives more bandwidth. The priority must be within the range [0, 255].

+

The default priority is 0, which is the lowest priority.

+

To query the priority of a torrent, use the torrent_handle::status() call.

+

Torrents with higher priority will not nececcarily get as much bandwidth as they can +consume, even if there's is more quota. Other peers will still be weighed in when +bandwidth is being distributed. With other words, bandwidth is not distributed strictly +in order of priority, but the priority is used as a weight.

+

Peers whose Torrent has a higher priority will take precedence when distributing unchoke slots. +This is a strict prioritization where every interested peer on a high priority torrent will +be unchoked before any other, lower priority, torrents have any peers unchoked.

+
+
+

file_progress()

+
+void file_progress (std::vector<size_type>& progress, int flags = 0) const;
+
+

This function fills in the supplied vector with the the number of bytes downloaded +of each file in this torrent. The progress values are ordered the same as the files +in the torrent_info. This operation is not very cheap. Its complexity is O(n + mj). +Where n is the number of files, m is the number of downloading pieces and j +is the number of blocks in a piece.

+

The flags parameter can be used to specify the granularity of the file progress. If +left at the default value of 0, the progress will be as accurate as possible, but also +more expensive to calculate. If torrent_handle::piece_granularity is specified, +the progress will be specified in piece granularity. i.e. only pieces that have been +fully downloaded and passed the hash check count. When specifying piece granularity, +the operation is a lot cheaper, since libtorrent already keeps track of this internally +and no calculation is required.

+
+
+

clear_error()

+
+void clear_error () const;
+
+

If the torrent is in an error state (i.e. torrent_status::error is non-empty), this +will clear the error and start the torrent again.

+ + +
+
+

add_tracker() replace_trackers() trackers()

+
+std::vector<announce_entry> trackers () const;
+void replace_trackers (std::vector<announce_entry> const&) const;
+void add_tracker (announce_entry const&) const;
+
+

trackers() will return the list of trackers for this torrent. The +announce entry contains both a string url which specify the announce url +for the tracker as well as an int tier, which is specifies the order in +which this tracker is tried. If you want libtorrent to use another list of +trackers for this torrent, you can use replace_trackers() which takes +a list of the same form as the one returned from trackers() and will +replace it. If you want an immediate effect, you have to call +force_reannounce(). See announce_entry.

+

add_tracker() will look if the specified tracker is already in the set. +If it is, it doesn't do anything. If it's not in the current set of trackers, +it will insert it in the tier specified in the announce_entry.

+

The updated set of trackers will be saved in the resume data, and when a torrent +is started with resume data, the trackers from the resume data will replace the +original ones.

+ + +
+
+

url_seeds() add_url_seed() remove_url_seed()

+
+void add_url_seed (std::string const& url) const;
+void remove_url_seed (std::string const& url) const;
+std::set<std::string> url_seeds () const;
+
+

add_url_seed() adds another url to the torrent's list of url seeds. If the +given url already exists in that list, the call has no effect. The torrent +will connect to the server and try to download pieces from it, unless it's +paused, queued, checking or seeding. remove_url_seed() removes the given +url if it exists already. url_seeds() return a set of the url seeds +currently in this torrent. Note that urls that fails may be removed +automatically from the list.

+

See http seeding for more information.

+ + +
+
+

http_seeds() remove_http_seed() add_http_seed()

+
+void add_http_seed (std::string const& url) const;
+void remove_http_seed (std::string const& url) const;
+std::set<std::string> http_seeds () const;
+
+

These functions are identical as the *_url_seed() variants, but they +operate on BEP 17 web seeds instead of BEP 19.

+

See http seeding for more information.

+
+
+

add_extension()

+
+void add_extension (boost::function<boost::shared_ptr<torrent_plugin>(torrent*, void*)> const& ext
+      , void* userdata = 0);
+
+

add the specified extension to this torrent. The ext argument is +a function that will be called from within libtorrent's context +passing in the internal torrent object and the specified userdata +pointer. The function is expected to return a shared pointer to +a torrent_plugin instance.

+
+
+

set_metadata()

+
+bool set_metadata (char const* metadata, int size) const;
+
+

set_metadata expects the info section of metadata. i.e. The buffer passed in will be +hashed and verified against the info-hash. If it fails, a metadata_failed_alert will be +generated. If it passes, a metadata_received_alert is generated. The function returns +true if the metadata is successfully set on the torrent, and false otherwise. If the torrent +already has metadata, this function will not affect the torrent, and false will be returned.

+
+
+

is_valid()

+
+bool is_valid () const;
+
+

Returns true if this handle refers to a valid torrent and false if it hasn't been initialized +or if the torrent it refers to has been aborted. Note that a handle may become invalid after +it has been added to the session. Usually this is because the storage for the torrent is +somehow invalid or if the filenames are not allowed (and hence cannot be opened/created) on +your filesystem. If such an error occurs, a file_error_alert is generated and all handles +that refers to that torrent will become invalid.

+ +
+
+

pause() resume()

+
+void pause (int flags = 0) const;
+void resume () const;
+
+

pause(), and resume() will disconnect all peers and reconnect all peers respectively. +When a torrent is paused, it will however remember all share ratios to all peers and remember +all potential (not connected) peers. Torrents may be paused automatically if there is a file +error (e.g. disk full) or something similar. See file_error_alert.

+

To know if a torrent is paused or not, call torrent_handle::status() and inspect +torrent_status::paused.

+

The flags argument to pause can be set to torrent_handle::graceful_pause which will +delay the disconnect of peers that we're still downloading outstanding requests from. The torrent +will not accept any more requests and will disconnect all idle peers. As soon as a peer is +done transferring the blocks that were requested from it, it is disconnected. This is a graceful +shut down of the torrent in the sense that no downloaded bytes are wasted.

+

torrents that are auto-managed may be automatically resumed again. It does not make sense to +pause an auto-managed torrent without making it not automanaged first. Torrents are auto-managed +by default when added to the session. For more information, see queuing.

+
+
+

set_upload_mode()

+
+void set_upload_mode (bool b) const;
+
+

Explicitly sets the upload mode of the torrent. In upload mode, the torrent will not +request any pieces. If the torrent is auto managed, it will automatically be taken out +of upload mode periodically (see session_settings::optimistic_disk_retry). Torrents +are automatically put in upload mode whenever they encounter a disk write error.

+

m should be true to enter upload mode, and false to leave it.

+

To test if a torrent is in upload mode, call torrent_handle::status() and inspect +torrent_status::upload_mode.

+
+
+

set_share_mode()

+
+void set_share_mode (bool b) const;
+
+

Enable or disable share mode for this torrent. When in share mode, the torrent will +not necessarily be downloaded, especially not the whole of it. Only parts that are likely +to be distributed to more than 2 other peers are downloaded, and only if the previous +prediction was correct.

+
+
+

flush_cache()

+
+void flush_cache () const;
+
+

Instructs libtorrent to flush all the disk caches for this torrent and close all +file handles. This is done asynchronously and you will be notified that it's complete +through cache_flushed_alert.

+

Note that by the time you get the alert, libtorrent may have cached more data for the +torrent, but you are guaranteed that whatever cached data libtorrent had by the time +you called torrent_handle::flush_cache() has been written to disk.

+
+
+

apply_ip_filter()

+
+void apply_ip_filter (bool b) const;
+
+

Set to true to apply the session global IP filter to this torrent (which is the +default). Set to false to make this torrent ignore the IP filter.

+
+
+

force_recheck()

+
+void force_recheck () const;
+
+

force_recheck puts the torrent back in a state where it assumes to have no resume data. +All peers will be disconnected and the torrent will stop announcing to the tracker. The torrent +will be added to the checking queue, and will be checked (all the files will be read and +compared to the piece hashes). Once the check is complete, the torrent will start connecting +to peers again, as normal.

+
+
+

save_resume_data()

+
+void save_resume_data (int flags = 0) const;
+
+

save_resume_data() generates fast-resume data and returns it as an entry. This entry +is suitable for being bencoded. For more information about how fast-resume works, see fast resume.

+

The flags argument is a bitmask of flags ORed together. see save_resume_flags_t

+

This operation is asynchronous, save_resume_data will return immediately. The resume data +is delivered when it's done through an save_resume_data_alert.

+

The fast resume data will be empty in the following cases:

+
+
    +
  1. The torrent handle is invalid.
  2. +
  3. The torrent is checking (or is queued for checking) its storage, it will obviously +not be ready to write resume data.
  4. +
  5. The torrent hasn't received valid metadata and was started without metadata +(see libtorrent's metadata from peers extension)
  6. +
+
+

Note that by the time you receive the fast resume data, it may already be invalid if the torrent +is still downloading! The recommended practice is to first pause the session, then generate the +fast resume data, and then close it down. Make sure to not remove_torrent() before you receive +the save_resume_data_alert though. There's no need to pause when saving intermittent resume data.

+
+

Warning

+

If you pause every torrent individually instead of pausing the session, every torrent +will have its paused state saved in the resume data!

+
+
+

Warning

+

The resume data contains the modification timestamps for all files. If one file has +been modified when the torrent is added again, the will be rechecked. When shutting down, make +sure to flush the disk cache before saving the resume data. This will make sure that the file +timestamps are up to date and won't be modified after saving the resume data. The recommended way +to do this is to pause the torrent, which will flush the cache and disconnect all peers.

+
+
+

Note

+

It is typically a good idea to save resume data whenever a torrent is completed or paused. In those +cases you don't need to pause the torrent or the session, since the torrent will do no more writing +to its files. If you save resume data for torrents when they are paused, you can accelerate the +shutdown process by not saving resume data again for paused torrents. Completed torrents should +have their resume data saved when they complete and on exit, since their statistics might be updated.

+

In full allocation mode the reume data is never invalidated by subsequent +writes to the files, since pieces won't move around. This means that you don't need to +pause before writing resume data in full or sparse mode. If you don't, however, any data written to +disk after you saved resume data and before the session closed is lost.

+
+

It also means that if the resume data is out dated, libtorrent will not re-check the files, but assume +that it is fairly recent. The assumption is that it's better to loose a little bit than to re-check +the entire file.

+

It is still a good idea to save resume data periodically during download as well as when +closing down.

+

Example code to pause and save resume data for all torrents and wait for the alerts:

+
+extern int outstanding_resume_data; // global counter of outstanding resume data
+std::vector<torrent_handle> handles = ses.get_torrents();
+ses.pause();
+for (std::vector<torrent_handle>::iterator i = handles.begin();
+        i != handles.end(); ++i)
+{
+        torrent_handle& h = *i;
+        if (!h.is_valid()) continue;
+        torrent_status s = h.status();
+        if (!s.has_metadata) continue;
+        if (!s.need_save_resume_data()) continue;
+
+        h.save_resume_data();
+        ++outstanding_resume_data;
+}
+
+while (outstanding_resume_data > 0)
+{
+        alert const* a = ses.wait_for_alert(seconds(10));
+
+        // if we don't get an alert within 10 seconds, abort
+        if (a == 0) break;
+
+        std::auto_ptr<alert> holder = ses.pop_alert();
+
+        if (alert_cast<save_resume_data_failed_alert>(a))
+        {
+                process_alert(a);
+                --outstanding_resume_data;
+                continue;
+        }
+
+        save_resume_data_alert const* rd = alert_cast<save_resume_data_alert>(a);
+        if (rd == 0)
+        {
+                process_alert(a);
+                continue;
+        }
+
+        torrent_handle h = rd->handle;
+        torrent_status st = h.status(torrent_handle::query_save_path | torrent_handle::query_name);
+        std::ofstream out((st.save_path
+                + "/" + st.name + ".fastresume").c_str()
+                , std::ios_base::binary);
+        out.unsetf(std::ios_base::skipws);
+        bencode(std::ostream_iterator<char>(out), *rd->resume_data);
+        --outstanding_resume_data;
+}
+
+
+

Note

+

Note how outstanding_resume_data is a global counter in this example. +This is deliberate, otherwise there is a race condition for torrents that +was just asked to save their resume data, they posted the alert, but it has +not been received yet. Those torrents would report that they don't need to +save resume data again, and skipped by the initial loop, and thwart the counter +otherwise.

+
+
+
+

need_save_resume_data()

+
+bool need_save_resume_data () const;
+
+

This function returns true if any whole chunk has been downloaded since the +torrent was first loaded or since the last time the resume data was saved. When +saving resume data periodically, it makes sense to skip any torrent which hasn't +downloaded anything since the last time.

+
+

Note

+

A torrent's resume data is considered saved as soon as the alert +is posted. It is important to make sure this alert is received and handled +in order for this function to be meaningful.

+
+
+
+

auto_managed()

+
+void auto_managed (bool m) const;
+
+

changes whether the torrent is auto managed or not. For more info, +see queuing.

+ + + + +
+
+

queue_position() queue_position_up() queue_position_bottom() queue_position_down() queue_position_top()

+
+void queue_position_down () const;
+void queue_position_top () const;
+int queue_position () const;
+void queue_position_bottom () const;
+void queue_position_up () const;
+
+

Every torrent that is added is assigned a queue position exactly one greater than +the greatest queue position of all existing torrents. Torrents that are being +seeded have -1 as their queue position, since they're no longer in line to be downloaded.

+

When a torrent is removed or turns into a seed, all torrents with greater queue positions +have their positions decreased to fill in the space in the sequence.

+

queue_position() returns the torrent's position in the download queue. The torrents +with the smallest numbers are the ones that are being downloaded. The smaller number, +the closer the torrent is to the front of the line to be started.

+

The queue position is also available in the torrent_status.

+

The queue_position_*() functions adjust the torrents position in the queue. Up means +closer to the front and down means closer to the back of the queue. Top and bottom refers +to the front and the back of the queue respectively.

+
+
+

resolve_countries()

+
+void resolve_countries (bool r);
+bool resolve_countries () const;
+
+

Sets or gets the flag that derermines if countries should be resolved for the peers of this +torrent. It defaults to false. If it is set to true, the peer_info structure for the peers +in this torrent will have their country member set. See peer_info for more information +on how to interpret this field.

+
+
+

set_ssl_certificate()

+
+void set_ssl_certificate (std::string const& certificate
+      , std::string const& private_key
+      , std::string const& dh_params
+      , std::string const& passphrase = "");
+
+

For SSL torrents, use this to specify a path to a .pem file to use as this client's certificate. +The certificate must be signed by the certificate in the .torrent file to be valid.

+

cert is a path to the (signed) certificate in .pem format corresponding to this torrent.

+

private_key is a path to the private key for the specified certificate. This must be in .pem +format.

+

dh_params is a path to the Diffie-Hellman parameter file, which needs to be in .pem format. +You can generate this file using the openssl command like this: +openssl dhparam -outform PEM -out dhparams.pem 512.

+

passphrase may be specified if the private key is encrypted and requires a passphrase to +be decrypted.

+

Note that when a torrent first starts up, and it needs a certificate, it will suspend connecting +to any peers until it has one. It's typically desirable to resume the torrent after setting the +ssl certificate.

+

If you receive a torrent_need_cert_alert, you need to call this to provide a valid cert. If you +don't have a cert you won't be allowed to connect to any peers.

+
+
+

get_storage_impl()

+
+storage_interface* get_storage_impl () const;
+
+

Returns the storage implementation for this torrent. This depends on the +storage contructor function that was passed to add_torrent.

+
+
+

torrent_file()

+
+boost::intrusive_ptr<torrent_info> torrent_file () const;
+
+

Returns a pointer to the torrent_info object associated with this torrent. The +torrent_info object is a copy of the internal object. If the torrent doesn't +have metadata, the object being returned will not be fully filled in. +The torrent may be in a state without metadata only if +it was started without a .torrent file, e.g. by using the libtorrent extension of +just supplying a tracker and info-hash.

+
+
+

use_interface()

+
+void use_interface (const char* net_interface) const;
+
+

use_interface() sets the network interface this torrent will use when it opens outgoing +connections. By default, it uses the same interface as the session uses to listen on. The +parameter must be a string containing one or more, comma separated, ip-address (either an +IPv4 or IPv6 address). When specifying multiple interfaces, the torrent will round-robin +which interface to use for each outgoing conneciton. This is useful for clients that are +multi-homed.

+
+
+

piece_availability()

+
+void piece_availability (std::vector<int>& avail) const;
+
+

Fills the specified std::vector<int> with the availability for each +piece in this torrent. libtorrent does not keep track of availability for +seeds, so if the torrent is seeding the availability for all pieces is +reported as 0.

+

The piece availability is the number of peers that we are connected that has +advertized having a particular piece. This is the information that libtorrent +uses in order to prefer picking rare pieces.

+ + +
+
+

piece_priority() prioritize_pieces() piece_priorities()

+
+int piece_priority (int index) const;
+void piece_priority (int index, int priority) const;
+void prioritize_pieces (std::vector<int> const& pieces) const;
+std::vector<int> piece_priorities () const;
+
+

These functions are used to set and get the prioritiy of individual pieces. +By default all pieces have priority 1. That means that the random rarest +first algorithm is effectively active for all pieces. You may however +change the priority of individual pieces. There are 8 different priority +levels:

+
+
    +
  1. piece is not downloaded at all
  2. +
  3. normal priority. Download order is dependent on availability
  4. +
  5. higher than normal priority. Pieces are preferred over pieces with +the same availability, but not over pieces with lower availability
  6. +
  7. pieces are as likely to be picked as partial pieces.
  8. +
  9. pieces are preferred over partial pieces, but not over pieces with +lower availability
  10. +
  11. currently the same as 4
  12. +
  13. piece is as likely to be picked as any piece with availability 1
  14. +
  15. maximum priority, availability is disregarded, the piece is preferred +over any other piece with lower priority
  16. +
+
+

The exact definitions of these priorities are implementation details, and +subject to change. The interface guarantees that higher number means higher +priority, and that 0 means do not download.

+

piece_priority sets or gets the priority for an individual piece, +specified by index.

+

prioritize_pieces takes a vector of integers, one integer per piece in +the torrent. All the piece priorities will be updated with the priorities +in the vector.

+

piece_priorities returns a vector with one element for each piece in the +torrent. Each element is the current priority of that piece.

+ + +
+
+

file_priorities() prioritize_files() file_priority()

+
+int file_priority (int index) const;
+void prioritize_files (std::vector<int> const& files) const;
+void file_priority (int index, int priority) const;
+std::vector<int> file_priorities () const;
+
+

index must be in the range [0, number_of_files).

+

file_priority() queries or sets the priority of file index.

+

prioritize_files() takes a vector that has at as many elements as there are +files in the torrent. Each entry is the priority of that file. The function +sets the priorities of all the pieces in the torrent based on the vector.

+

file_priorities() returns a vector with the priorities of all files.

+

The priority values are the same as for piece_priority().

+

Whenever a file priority is changed, all other piece priorities are reset +to match the file priorities. In order to maintain sepcial priorities for +particular pieces, piece_priority() has to be called again for those pieces.

+

You cannot set the file priorities on a torrent that does not yet +have metadata or a torrent that is a seed. file_priority(int, int) and +prioritize_files() are both no-ops for such torrents.

+ +
+
+

force_reannounce() force_dht_announce()

+
+void force_reannounce () const;
+void force_dht_announce () const;
+
+

force_reannounce() will force this torrent to do another tracker request, to receive new +peers. The second overload of force_reannounce that takes a time_duration as +argument will schedule a reannounce in that amount of time from now.

+

If the tracker's min_interval has not passed since the last announce, the forced +announce will be scheduled to happen immediately as the min_interval expires. This is +to honor trackers minimum re-announce interval settings.

+

force_dht_announce will announce the torrent to the DHT immediately.

+
+
+

force_reannounce()

+
+void force_reannounce (boost::posix_time::time_duration) const;
+
+

forces a reannounce in the specified amount of time. +This overrides the default announce interval, and no +announce will take place until the given time has +timed out.

+
+
+

scrape_tracker()

+
+void scrape_tracker () const;
+
+

scrape_tracker() will send a scrape request to the tracker. A scrape request queries the +tracker for statistics such as total number of incomplete peers, complete peers, number of +downloads etc.

+

This request will specifically update the num_complete and num_incomplete fields in +the torrent_status struct once it completes. When it completes, it will generate a +scrape_reply_alert. If it fails, it will generate a scrape_failed_alert.

+ + + +
+
+

set_upload_limit() upload_limit() download_limit() set_download_limit()

+
+int upload_limit () const;
+int download_limit () const;
+void set_upload_limit (int limit) const;
+void set_download_limit (int limit) const;
+
+

set_upload_limit will limit the upload bandwidth used by this particular torrent to the +limit you set. It is given as the number of bytes per second the torrent is allowed to upload. +set_download_limit works the same way but for download bandwidth instead of upload bandwidth. +Note that setting a higher limit on a torrent then the global limit (session_settings::upload_rate_limit) +will not override the global rate limit. The torrent can never upload more than the global rate +limit.

+

upload_limit and download_limit will return the current limit setting, for upload and +download, respectively.

+
+
+

set_sequential_download()

+
+void set_sequential_download (bool sd) const;
+
+

set_sequential_download() enables or disables sequential download. When enabled, the piece +picker will pick pieces in sequence instead of rarest first.

+

Enabling sequential download will affect the piece distribution negatively in the swarm. It should be +used sparingly.

+
+
+

connect_peer()

+
+void connect_peer (tcp::endpoint const& adr, int source = 0) const;
+
+

connect_peer() is a way to manually connect to peers that one believe is a part of the +torrent. If the peer does not respond, or is not a member of this torrent, it will simply +be disconnected. No harm can be done by using this other than an unnecessary connection +attempt is made. If the torrent is uninitialized or in queued or checking mode, this +will throw libtorrent_exception. The second (optional) argument will be bitwised ORed into +the source mask of this peer. Typically this is one of the source flags in peer_info. +i.e. tracker, pex, dht etc.

+ +
+
+

max_uploads() set_max_uploads()

+
+int max_uploads () const;
+void set_max_uploads (int max_uploads) const;
+
+

set_max_uploads() sets the maximum number of peers that's unchoked at the same time on this +torrent. If you set this to -1, there will be no limit. This defaults to infinite. The primary +setting controlling this is the global unchoke slots limit, set by unchoke_slots_limit +in session_settings.

+

max_uploads() returns the current settings.

+ +
+
+

max_connections() set_max_connections()

+
+int max_connections () const;
+void set_max_connections (int max_connections) const;
+
+

set_max_connections() sets the maximum number of connection this torrent will open. If all +connections are used up, incoming connections may be refused or poor connections may be closed. +This must be at least 2. The default is unlimited number of connections. If -1 is given to the +function, it means unlimited. There is also a global limit of the number of connections, set +by connections_limit in session_settings.

+

max_connections() returns the current settings.

+
+
+

set_tracker_login()

+
+void set_tracker_login (std::string const& name
+      , std::string const& password) const;
+
+

sets a username and password that will be sent along in the HTTP-request +of the tracker announce. Set this if the tracker requires authorization.

+
+
+

move_storage()

+
+void move_storage (std::string const& save_path, int flags = 0) const;
+
+

Moves the file(s) that this torrent are currently seeding from or downloading to. If +the given save_path is not located on the same drive as the original save path, +the files will be copied to the new drive and removed from their original location. +This will block all other disk IO, and other torrents download and upload rates may +drop while copying the file.

+

Since disk IO is performed in a separate thread, this operation is also asynchronous. +Once the operation completes, the storage_moved_alert is generated, with the new +path as the message. If the move fails for some reason, storage_moved_failed_alert +is generated instead, containing the error message.

+

The flags argument determines the behavior of the copying/moving of the files +in the torrent. see move_flags_t.

+
+
    +
  • always_replace_files = 0
  • +
  • fail_if_exist = 1
  • +
  • dont_replace = 2
  • +
+
+

always_replace_files is the default and replaces any file that exist in both the +source directory and the target directory.

+

fail_if_exist first check to see that none of the copy operations would cause an +overwrite. If it would, it will fail. Otherwise it will proceed as if it was in +always_replace_files mode. Note that there is an inherent race condition here. +If the files in the target directory appear after the check but before the copy +or move completes, they will be overwritten. When failing because of files already +existing in the target path, the error of move_storage_failed_alert is set +to boost::system::errc::file_exists.

+

The intention is that a client may use this as a probe, and if it fails, ask the user +which mode to use. The client may then re-issue the move_storage call with one +of the other modes.

+

dont_replace always takes the existing file in the target directory, if there is +one. The source files will still be removed in that case.

+

Files that have been renamed to have absolute pahts are not moved by this function. +Keep in mind that files that don't belong to the torrent but are stored in the torrent's +directory may be moved as well. This goes for files that have been renamed to +absolute paths that still end up inside the save path.

+
+
+

rename_file()

+
+void rename_file (int index, std::string const& new_name) const;
+
+

Renames the file with the given index asynchronously. The rename operation is complete +when either a file_renamed_alert or file_rename_failed_alert is posted.

+
+
+

super_seeding()

+
+void super_seeding (bool on) const;
+
+

Enables or disabled super seeding/initial seeding for this torrent. The torrent +needs to be a seed for this to take effect.

+
+
+

info_hash()

+
+sha1_hash info_hash () const;
+
+

info_hash() returns the info-hash for the torrent.

+ + +
+
+

operator!=() operator<() operator==()

+
+bool operator!= (const torrent_handle& h) const;
+bool operator< (const torrent_handle& h) const;
+bool operator== (const torrent_handle& h) const;
+
+

comparison operators. The order of the torrents is unspecified +but stable.

+
+
+

native_handle()

+
+boost::shared_ptr<torrent> native_handle () const;
+
+

This function is intended only for use by plugins and the alert dispatch function. Any code +that runs in libtorrent's network thread may not use the public API of torrent_handle. +Doing so results in a dead-lock. For such routines, the native_handle gives access to the +underlying type representing the torrent. This type does not have a stable API and should +be relied on as little as possible.

+
+
+

enum flags_t

+

Declared in "libtorrent/torrent_handle.hpp"

+ +++++ + + + + + + + + + + + + +
namevaluedescription
overwrite_existing1 
+
+
+

enum status_flags_t

+

Declared in "libtorrent/torrent_handle.hpp"

+ +++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
namevaluedescription
query_distributed_copies1calculates distributed_copies, distributed_full_copies and distributed_fraction.
query_accurate_download_counters2includes partial downloaded blocks in total_done and total_wanted_done.
query_last_seen_complete4includes last_seen_complete.
query_pieces8includes pieces.
query_verified_pieces16includes verified_pieces (only applies to torrents in seed mode).
query_torrent_file32includes torrent_file, which is all the static information from the .torrent file.
query_name64includes name, the name of the torrent. This is either derived from the .torrent +file, or from the &dn= magnet link argument or possibly some other source. If the +name of the torrent is not known, this is an empty string.
query_save_path128includes save_path, the path to the directory the files of the torrent are saved to.
+
+
+

enum deadline_flags

+

Declared in "libtorrent/torrent_handle.hpp"

+ +++++ + + + + + + + + + + + + +
namevaluedescription
alert_when_available1 
+
+
+

enum file_progress_flags_t

+

Declared in "libtorrent/torrent_handle.hpp"

+ +++++ + + + + + + + + + + + + +
namevaluedescription
piece_granularity1 
+
+
+

enum pause_flags_t

+

Declared in "libtorrent/torrent_handle.hpp"

+ +++++ + + + + + + + + + + + + +
namevaluedescription
graceful_pause1 
+
+
+

enum save_resume_flags_t

+

Declared in "libtorrent/torrent_handle.hpp"

+ +++++ + + + + + + + + + + + + + + + + +
namevaluedescription
flush_disk_cache1the disk cache will be flushed before creating the resume data. This avoids a problem with +file timestamps in the resume data in case the cache hasn't been flushed yet.
save_info_dict2the resume data will contain the metadata +from the torrent file as well. This is default for any torrent that's added without a torrent +file (such as a magnet link or a URL).
+
+
+
+

torrent_status

+

Declared in "libtorrent/torrent_handle.hpp"

+

holds a snapshot of the status of a torrent, as queried by torrent_handle::status().

+
+struct torrent_status
+{
+   bool operator== (torrent_status const& st) const;
+
+   enum state_t
+   {
+      queued_for_checking,
+      checking_files,
+      downloading_metadata,
+      downloading,
+      finished,
+      seeding,
+      allocating,
+      checking_resume_data,
+   };
+
+   torrent_handle handle;
+   std::string error;
+   std::string save_path;
+   std::string name;
+   boost::intrusive_ptr<const torrent_info> torrent_file;
+   boost::posix_time::time_duration next_announce;
+   boost::posix_time::time_duration announce_interval;
+   std::string current_tracker;
+   size_type total_download;
+   size_type total_upload;
+   size_type total_payload_download;
+   size_type total_payload_upload;
+   size_type total_failed_bytes;
+   size_type total_redundant_bytes;
+   bitfield pieces;
+   bitfield verified_pieces;
+   size_type total_done;
+   size_type total_wanted_done;
+   size_type total_wanted;
+   size_type all_time_upload;
+   size_type all_time_download;
+   time_t added_time;
+   time_t completed_time;
+   time_t last_seen_complete;
+   storage_mode_t storage_mode;
+   float progress;
+   int progress_ppm;
+   int queue_position;
+   int download_rate;
+   int upload_rate;
+   int download_payload_rate;
+   int upload_payload_rate;
+   int num_seeds;
+   int num_peers;
+   int num_complete;
+   int num_incomplete;
+   int list_seeds;
+   int list_peers;
+   int connect_candidates;
+   int num_pieces;
+   int distributed_full_copies;
+   int distributed_fraction;
+   float distributed_copies;
+   int block_size;
+   int num_uploads;
+   int num_connections;
+   int uploads_limit;
+   int connections_limit;
+   int up_bandwidth_queue;
+   int down_bandwidth_queue;
+   int time_since_upload;
+   int time_since_download;
+   int active_time;
+   int finished_time;
+   int seeding_time;
+   int seed_rank;
+   int last_scrape;
+   int sparse_regions;
+   int priority;
+   boost::uint8_t state;
+   bool need_save_resume;
+   bool ip_filter_applies;
+   bool upload_mode;
+   bool share_mode;
+   bool super_seeding;
+   bool paused;
+   bool auto_managed;
+   bool sequential_download;
+   bool is_seeding;
+   bool is_finished;
+   bool has_metadata;
+   bool has_incoming;
+   bool seed_mode;
+   sha1_hash info_hash;
+};
+
+
+

enum state_t

+

Declared in "libtorrent/torrent_handle.hpp"

+ +++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
namevaluedescription
queued_for_checking0The torrent is in the queue for being checked. But there +currently is another torrent that are being checked. +This torrent will wait for its turn.
checking_files1The torrent has not started its download yet, and is +currently checking existing files.
downloading_metadata2The torrent is trying to download metadata from peers. +This assumes the metadata_transfer extension is in use.
downloading3The torrent is being downloaded. This is the state +most torrents will be in most of the time. The progress +meter will tell how much of the files that has been +downloaded.
finished4In this state the torrent has finished downloading but +still doesn't have the entire torrent. i.e. some pieces +are filtered and won't get downloaded.
seeding5In this state the torrent has finished downloading and +is a pure seeder.
allocating6If the torrent was started in full allocation mode, this +indicates that the (disk) storage for the torrent is +allocated.
checking_resume_data7The torrent is currently checking the fastresume data and +comparing it to the files on disk. This is typically +completed in a fraction of a second, but if you add a +large number of torrents at once, they will queue up.
+
+
handle
+
a handle to the torrent whose status the object represents.
+
+
+
error
+
may be set to an error message describing why the torrent +was paused, in case it was paused by an error. If the torrent +is not paused or if it's paused but not because of an error, +this string is empty.
+
+
+
save_path
+
the path to the directory where this torrent's files are stored. +It's typically the path as was given to async_add_torrent() or +add_torrent() when this torrent was started. This field is only +included if the torrent status is queried with +torrent_handle::query_save_path.
+
+
+
name
+
the name of the torrent. Typically this is derived from the +.torrent file. In case the torrent was started without metadata, +and hasn't completely received it yet, it returns the name given +to it when added to the session. See session::add_torrent. +This field is only included if the torrent status is queried +with torrent_handle::query_name.
+
+
+
torrent_file
+
set to point to the torrent_info object for this torrent. It's +only included if the torrent status is queried with +torrent_handle::query_torrent_file.
+
+
+
next_announce
+
the time until the torrent will announce itself to the tracker.
+
+
+
announce_interval
+
the time the tracker want us to wait until we announce ourself +again the next time.
+
+
+
current_tracker
+
the URL of the last working tracker. If no tracker request has +been successful yet, it's set to an empty string.
+
+ +
+
total_download total_upload
+
the number of bytes downloaded and +uploaded to all peers, accumulated, this session only. The session is considered +to restart when a torrent is paused and restarted again. When a torrent is paused, +these counters are reset to 0. If you want complete, persistent, stats, see +all_time_upload and all_time_download.
+
+ +
+
total_payload_download total_payload_upload
+
counts the amount of bytes +send and received this session, but only the actual payload data (i.e the interesting +data), these counters ignore any protocol overhead.
+
+
+
total_failed_bytes
+
the number of bytes that has been downloaded and that +has failed the piece hash test. In other words, this is just how much crap that +has been downloaded.
+
+
+
total_redundant_bytes
+
the number of bytes that has been downloaded even +though that data already was downloaded. The reason for this is that in some +situations the same data can be downloaded by mistake. When libtorrent sends +requests to a peer, and the peer doesn't send a response within a certain +timeout, libtorrent will re-request that block. Another situation when +libtorrent may re-request blocks is when the requests it sends out are not +replied in FIFO-order (it will re-request blocks that are skipped by an out of +order block). This is supposed to be as low as possible.
+
+
+
pieces
+
a bitmask that represents which pieces we have (set to true) and +the pieces we don't have. It's a pointer and may be set to 0 if the torrent isn't +downloading or seeding.
+
+
+
verified_pieces
+
a bitmask representing which pieces has had their hash +checked. This only applies to torrents in seed mode. If the torrent is not +in seed mode, this bitmask may be empty.
+
+
+
total_done
+
the total number of bytes of the file(s) that we have. All +this does not necessarily has to be downloaded during this session (that's +total_payload_download).
+
+
+
total_wanted_done
+
the number of bytes we have downloaded, only counting the +pieces that we actually want to download. i.e. excluding any pieces that we have but +have priority 0 (i.e. not wanted).
+
+
+
total_wanted
+
The total number of bytes we want to download. +This may be smaller than the total torrent size +in case any pieces are prioritized to 0, i.e. not wanted
+
+ +
+
all_time_upload all_time_download
+
are accumulated upload and download +payload byte counters. They are saved in and restored from resume data to keep totals +across sessions.
+
+
+
added_time
+
the posix-time when this torrent was added. i.e. what +time(NULL) returned at the time.
+
+
+
completed_time
+
the posix-time when this torrent was finished. If +the torrent is not yet finished, this is 0.
+
+
+
last_seen_complete
+
the time when we, or one of our peers, last +saw a complete copy of this torrent.
+
+
+
storage_mode
+
The allocation mode for the torrent. See storage_mode_t for the options. +For more information, see storage allocation.
+
+
+
progress
+
a value in the range [0, 1], that represents the progress of the +torrent's current task. It may be checking files or downloading.
+
+
+
progress_ppm
+
reflects the same value as progress, but instead in a range +[0, 1000000] (ppm = parts per million). When floating point operations are disabled, +this is the only alternative to the floating point value in progress.
+
+
+
queue_position
+
the position this torrent has in the download +queue. If the torrent is a seed or finished, this is -1.
+
+ +
+
download_rate upload_rate
+
the total rates for all peers for this +torrent. These will usually have better precision than summing the rates from +all peers. The rates are given as the number of bytes per second.
+
+ +
+
download_payload_rate upload_payload_rate
+
the total transfer rate of payload only, not counting protocol chatter. This might +be slightly smaller than the other rates, but if projected over a long time +(e.g. when calculating ETA:s) the difference may be noticeable.
+
+
+
num_seeds
+
the number of peers that are seeding that this client is +currently connected to.
+
+
+
num_peers
+
the number of peers this torrent currently is connected to. +Peer connections that are in the half-open state (is attempting to connect) +or are queued for later connection attempt do not count. Although they are +visible in the peer list when you call get_peer_info().
+
+ +
+
num_complete num_incomplete
+
if the tracker sends scrape info in its +announce reply, these fields will be +set to the total number of peers that +have the whole file and the total number +of peers that are still downloading. +set to -1 if the tracker did not +send any scrape data in its announce reply.
+
+ +
+
list_seeds list_peers
+
the number of seeds in our peer list +and the total number of peers (including seeds). We are not +necessarily connected to all the peers in our peer list. This is the number +of peers we know of in total, including banned peers and peers that we have +failed to connect to.
+
+
+
connect_candidates
+
the number of peers in this torrent's peer list +that is a candidate to be connected to. i.e. It has fewer connect attempts +than the max fail count, it is not a seed if we are a seed, it is not banned +etc. If this is 0, it means we don't know of any more peers that we can try.
+
+
+
num_pieces
+
the number of pieces that has been downloaded. It is equivalent +to: std::accumulate(pieces->begin(), pieces->end()). So you don't have to +count yourself. This can be used to see if anything has updated since last time +if you want to keep a graph of the pieces up to date.
+
+
+
distributed_full_copies
+
the number of distributed copies of the torrent. +Note that one copy may be spread out among many peers. It tells how many copies +there are currently of the rarest piece(s) among the peers this client is +connected to.
+
+
+
distributed_fraction
+

tells the share of pieces that have more copies than +the rarest piece(s). Divide this number by 1000 to get the fraction.

+

For example, if distributed_full_copies is 2 and distrbuted_fraction +is 500, it means that the rarest pieces have only 2 copies among the peers +this torrent is connected to, and that 50% of all the pieces have more than +two copies.

+

If we are a seed, the piece picker is deallocated as an optimization, and +piece availability is no longer tracked. In this case the distributed +copies members are set to -1.

+
+
+
+
distributed_copies
+

the number of distributed copies of the file. +note that one copy may be spread out among many peers. +This is a floating point representation of the +distributed copies.

+
+
the integer part tells how many copies
+
there are of the rarest piece(s)
+
the fractional part tells the fraction of pieces that
+
have more copies than the rarest piece(s).
+
+
+
+
+
block_size
+
the size of a block, in bytes. A block is a sub piece, it +is the number of bytes that each piece request asks for and the number of +bytes that each bit in the partial_piece_info's bitset represents, +see get_download_queue(). This is typically 16 kB, but it may be +larger if the pieces are larger.
+
+
+
num_uploads
+
the number of unchoked peers in this torrent.
+
+
+
num_connections
+
the number of peer connections this torrent has, including +half-open connections that hasn't completed the bittorrent handshake yet. This is +always >= num_peers.
+
+
+
uploads_limit
+
the set limit of upload slots (unchoked peers) for this torrent.
+
+
+
connections_limit
+
the set limit of number of connections for this torrent.
+
+ +
+
up_bandwidth_queue down_bandwidth_queue
+
the number of peers in this +torrent that are waiting for more bandwidth quota from the torrent rate limiter. +This can determine if the rate you get from this torrent is bound by the torrents +limit or not. If there is no limit set on this torrent, the peers might still be +waiting for bandwidth quota from the global limiter, but then they are counted in +the session_status object.
+
+ +
+
time_since_upload time_since_download
+
the number of +seconds since any peer last uploaded from this torrent and the last +time a downloaded piece passed the hash check, respectively.
+
+ + +
+
active_time finished_time seeding_time
+
These keep track of the number of seconds this torrent has been active (not +paused) and the number of seconds it has been active while being finished and +active while being a seed. seeding_time should be <= finished_time which +should be <= active_time. They are all saved in and restored from resume data, +to keep totals across sessions.
+
+
+
seed_rank
+
A rank of how important it is to seed the torrent, it is used +to determine which torrents to seed and which to queue. It is based on the peer +to seed ratio from the tracker scrape. For more information, see queuing. +Higher value means more important to seed
+
+
+
last_scrape
+
the number of seconds since this torrent acquired scrape data. +If it has never done that, this value is -1.
+
+
+
sparse_regions
+
the number of regions of non-downloaded pieces in the +torrent. This is an interesting metric on windows vista, since there is +a limit on the number of sparse regions in a single file there.
+
+
+
priority
+
the priority of this torrent
+
+
+
state
+
the main state the torrent is in. See torrent_status::state_t.
+
+
+
need_save_resume
+
true if this torrent has unsaved changes +to its download state and statistics since the last resume data +was saved.
+
+
+
ip_filter_applies
+
true if the session global IP filter applies +to this torrent. This defaults to true.
+
+
+
upload_mode
+
true if the torrent is blocked from downloading. This +typically happens when a disk write operation fails. If the torrent is +auto-managed, it will periodically be taken out of this state, in the +hope that the disk condition (be it disk full or permission errors) has +been resolved. If the torrent is not auto-managed, you have to explicitly +take it out of the upload mode by calling set_upload_mode() on the +torrent_handle.
+
+
+
share_mode
+
true if the torrent is currently in share-mode, i.e. +not downloading the torrent, but just helping the swarm out.
+
+
+
super_seeding
+
true if the torrent is in super seeding mode
+
+
+
paused
+
set to true if the torrent is paused and false otherwise. It's only true +if the torrent itself is paused. If the torrent is not running because the session is +paused, this is still false. To know if a torrent is active or not, you need to inspect +both torrent_status::paused and session::is_paused().
+
+
+
auto_managed
+
set to true if the torrent is auto managed, i.e. libtorrent is +responsible for determining whether it should be started or queued. For more info +see queuing
+
+
+
sequential_download
+
true when the torrent is in sequential download mode. In +this mode pieces are downloaded in order rather than rarest first.
+
+
+
is_seeding
+
true if all pieces have been downloaded.
+
+
+
is_finished
+
true if all pieces that have a priority > 0 are downloaded. There is +only a distinction between finished and seeding if some pieces or files have been +set to priority 0, i.e. are not downloaded.
+
+
+
has_metadata
+
true if this torrent has metadata (either it was started from a +.torrent file or the metadata has been downloaded). The only scenario where this can be +false is when the torrent was started torrent-less (i.e. with just an info-hash and tracker +ip, a magnet link for instance).
+
+
+
has_incoming
+
true if there has ever been an incoming connection attempt +to this torrent.
+
+
+
seed_mode
+
true if the torrent is in seed_mode. If the torrent was +started in seed mode, it will leave seed mode once all pieces have been +checked or as soon as one piece fails the hash check.
+
+
+
info_hash
+
the info-hash for this torrent
+
+
+
+
+

announce_entry

+

Declared in "libtorrent/torrent_info.hpp"

+

this class holds information about one bittorrent tracker, as it +relates to a specific torrent.

+
+struct announce_entry
+{
+   announce_entry (std::string const& u);
+   ~announce_entry ();
+   announce_entry ();
+   int next_announce_in () const;
+   int min_announce_in () const;
+   void reset ();
+   void failed (session_settings const& sett, int retry_interval = 0);
+   bool can_announce (ptime now, bool is_seed) const;
+   bool is_working () const;
+   void trim ();
+
+   enum tracker_source
+   {
+      source_torrent,
+      source_client,
+      source_magnet_link,
+      source_tex,
+   };
+
+   std::string url;
+   std::string trackerid;
+   std::string message;
+   error_code last_error;
+   ptime next_announce;
+   ptime min_announce;
+   int scrape_incomplete;
+   int scrape_complete;
+   int scrape_downloaded;
+   boost::uint8_t tier;
+   boost::uint8_t fail_limit;
+   boost::uint8_t fails:7;
+   bool updating:1;
+   boost::uint8_t source:4;
+   bool verified:1;
+   bool start_sent:1;
+   bool complete_sent:1;
+   bool send_stats:1;
+};
+
+ +
+

announce_entry() ~announce_entry()

+
+announce_entry (std::string const& u);
+~announce_entry ();
+announce_entry ();
+
+

constructs a tracker announce entry with u as the URL.

+ +
+
+

min_announce_in() next_announce_in()

+
+int next_announce_in () const;
+int min_announce_in () const;
+
+

returns the number of seconds to the next announce on +this tracker. min_announce_in() returns the number of seconds until we are +allowed to force another tracker update with this tracker.

+

If the last time this tracker was contacted failed, last_error is the error +code describing what error occurred.

+
+
+

reset()

+
+void reset ();
+
+

reset announce counters and clears the started sent flag. +The announce_entry will look like we've never talked to +the tracker.

+
+
+

failed()

+
+void failed (session_settings const& sett, int retry_interval = 0);
+
+

updates the failure counter and time-outs for re-trying. +This is called when the tracker announce fails.

+
+
+

can_announce()

+
+bool can_announce (ptime now, bool is_seed) const;
+
+

returns true if we can announec to this tracker now. +The current time is passed in as now. The is_seed +argument is necessary because once we become a seed, we +need to announce right away, even if the re-announce timer +hasn't expired yet.

+
+
+

is_working()

+
+bool is_working () const;
+
+

returns true if the last time we tried to announce to this +tracker succeeded, or if we haven't tried yet.

+
+
+

trim()

+
+void trim ();
+
+

trims whitespace characters from the beginning of the URL.

+
+
+

enum tracker_source

+

Declared in "libtorrent/torrent_info.hpp"

+ +++++ + + + + + + + + + + + + + + + + + + + + + + + + +
namevaluedescription
source_torrent1the tracker was part of the .torrent file
source_client2the tracker was added programatically via the add_troacker()_ function
source_magnet_link4the tracker was part of a magnet link
source_tex8the tracker was received from the swarm via tracker exchange
+
+
url
+
tracker URL as it appeared in the torrent file
+
+
+
trackerid
+
the current &trackerid= argument passed to the tracker. +this is optional and is normally empty (in which case no +trackerid is sent).
+
+
+
message
+
if this tracker has returned an error or warning message +that message is stored here
+
+
+
last_error
+
if this tracker failed the last time it was contacted +this error code specifies what error occurred
+
+
+
next_announce
+
the time of next tracker announce
+
+
+
min_announce
+
no announces before this time
+
+ + +
+
scrape_incomplete scrape_complete scrape_downloaded
+
if this tracker has returned scrape data, these fields are filled +in with valid numbers. Otherwise they are set to -1. +the number of current downloaders
+
+
+
tier
+
the tier this tracker belongs to
+
+
+
fail_limit
+
the max number of failures to announce to this tracker in +a row, before this tracker is not used anymore. 0 means unlimited
+
+
+
fails
+
the number of times in a row we have failed to announce to this +tracker.
+
+
+
updating
+
true while we're waiting for a response from the tracker.
+
+
+
source
+
a bitmask specifying which sources we got this tracker from.
+
+
+
verified
+
set to true the first time we receive a valid response +from this tracker.
+
+
+
start_sent
+
set to true when we get a valid response from an announce +with event=started. If it is set, we won't send start in the subsequent +announces.
+
+
+
complete_sent
+
set to true when we send a event=completed.
+
+
+
send_stats
+
this is false the stats sent to this tracker will be 0
+
+
+
+
+

torrent_info

+

Declared in "libtorrent/torrent_info.hpp"

+

This class represents the information stored in a .torrent file

+
+class torrent_info : public intrusive_ptr_base<torrent_info>
+{
+   torrent_info (std::string const& filename, int flags = 0);
+   torrent_info (char const* buffer, int size, error_code& ec, int flags = 0);
+   torrent_info (sha1_hash const& info_hash, int flags = 0);
+   torrent_info (lazy_entry const& torrent_file, int flags = 0);
+   torrent_info (char const* buffer, int size, int flags = 0);
+   torrent_info (lazy_entry const& torrent_file, error_code& ec, int flags = 0);
+   torrent_info (torrent_info const& t, int flags = 0);
+   torrent_info (std::string const& filename, error_code& ec, int flags = 0);
+   ~torrent_info ();
+   file_storage const& files () const;
+   file_storage const& orig_files () const;
+   void rename_file (int index, std::string const& new_filename);
+   void remap_files (file_storage const& f);
+   std::vector<announce_entry> const& trackers () const;
+   void add_tracker (std::string const& url, int tier = 0);
+   void add_url_seed (std::string const& url
+      , std::string const& extern_auth = std::string()
+      , web_seed_entry::headers_t const& extra_headers = web_seed_entry::headers_t());
+   std::vector<web_seed_entry> const& web_seeds () const;
+   void add_http_seed (std::string const& url
+      , std::string const& extern_auth = std::string()
+      , web_seed_entry::headers_t const& extra_headers = web_seed_entry::headers_t());
+   int num_pieces () const;
+   size_type total_size () const;
+   int piece_length () const;
+   const sha1_hash& info_hash () const;
+   int num_files () const;
+   file_entry file_at (int index) const;
+   std::vector<file_slice> map_block (int piece, size_type offset, int size) const;
+   peer_request map_file (int file, size_type offset, int size) const;
+   std::string ssl_cert () const;
+   bool is_valid () const;
+   bool priv () const;
+   bool is_i2p () const;
+   sha1_hash hash_for_piece (int index) const;
+   char const* hash_for_piece_ptr (int index) const;
+   int piece_size (int index) const;
+   std::vector<sha1_hash> const& merkle_tree () const;
+   void set_merkle_tree (std::vector<sha1_hash>& h);
+   boost::optional<time_t> creation_date () const;
+   const std::string& name () const;
+   const std::string& comment () const;
+   const std::string& creator () const;
+   nodes_t const& nodes () const;
+   void add_node (std::pair<std::string, int> const& node);
+   bool parse_info_section (lazy_entry const& e, error_code& ec, int flags);
+   lazy_entry const* info (char const* key) const;
+   void swap (torrent_info& ti);
+   int metadata_size () const;
+   boost::shared_array<char> metadata () const;
+   bool is_merkle_torrent () const;
+};
+
+
+

torrent_info()

+
+torrent_info (std::string const& filename, int flags = 0);
+torrent_info (char const* buffer, int size, error_code& ec, int flags = 0);
+torrent_info (sha1_hash const& info_hash, int flags = 0);
+torrent_info (lazy_entry const& torrent_file, int flags = 0);
+torrent_info (char const* buffer, int size, int flags = 0);
+torrent_info (lazy_entry const& torrent_file, error_code& ec, int flags = 0);
+torrent_info (torrent_info const& t, int flags = 0);
+torrent_info (std::string const& filename, error_code& ec, int flags = 0);
+
+

The constructor that takes an info-hash will initialize the info-hash to the given value, +but leave all other fields empty. This is used internally when downloading torrents without +the metadata. The metadata will be created by libtorrent as soon as it has been downloaded +from the swarm.

+

The constructor that takes a lazy_entry will create a torrent_info object from the +information found in the given torrent_file. The lazy_entry represents a tree node in +an bencoded file. To load an ordinary .torrent file +into a lazy_entry, use lazy_bdecode().

+

The version that takes a buffer pointer and a size will decode it as a .torrent file and +initialize the torrent_info object for you.

+

The version that takes a filename will simply load the torrent file and decode it inside +the constructor, for convenience. This might not be the most suitable for applications that +want to be able to report detailed errors on what might go wrong.

+

The overloads that takes an error_code const& never throws if an error occur, they +will simply set the error code to describe what went wrong and not fully initialize the +torrent_info object. The overloads that do not take the extra error_code parameter will +always throw if an error occurs. These overloads are not available when building without +exception support.

+

The flags argument is currently unused.

+
+
+

~torrent_info()

+
+~torrent_info ();
+
+

frees all storage associated with this torrent_info object

+ +
+
+

orig_files() files()

+
+file_storage const& files () const;
+file_storage const& orig_files () const;
+
+

The file_storage object contains the information on how to map the pieces to +files. It is separated from the torrent_info object because when creating torrents +a storage object needs to be created without having a torrent file. When renaming files +in a storage, the storage needs to make its own copy of the file_storage in order +to make its mapping differ from the one in the torrent file.

+

orig_files() returns the original (unmodified) file storage for this torrent. This +is used by the web server connection, which needs to request files with the original +names. Filename may be chaged using torrent_info::rename_file().

+

For more information on the file_storage object, see the separate document on how +to create torrents.

+
+
+

rename_file()

+
+void rename_file (int index, std::string const& new_filename);
+
+

Renames a the file with the specified index to the new name. The new filename is +reflected by the file_storage returned by files() but not by the one +returned by orig_files().

+

If you want to rename the base name of the torrent (for a multifile torrent), you +can copy the file_storage (see files() and orig_files() ), change the name, and +then use remap_files().

+

The new_filename can both be a relative path, in which case the file name +is relative to the save_path of the torrent. If the new_filename is +an absolute path (i.e. is_complete(new_filename) == true), then the file +is detached from the save_path of the torrent. In this case the file is +not moved when move_storage() is invoked.

+
+
+

remap_files()

+
+void remap_files (file_storage const& f);
+
+

Remaps the file storage to a new file layout. This can be used to, for instance, +download all data in a torrent to a single file, or to a number of fixed size +sector aligned files, regardless of the number and sizes of the files in the torrent.

+

The new specified file_storage must have the exact same size as the current one.

+ +
+
+

trackers() add_tracker()

+
+std::vector<announce_entry> const& trackers () const;
+void add_tracker (std::string const& url, int tier = 0);
+
+

add_tracker() adds a tracker to the announce-list. The tier determines the order in +which the trackers are to be tried.

+

The trackers() function will return a sorted vector of announce_entry. +Each announce entry contains a string, which is the tracker url, and a tier index. The +tier index is the high-level priority. No matter which trackers that works or not, the +ones with lower tier will always be tried before the one with higher tier number. +For more information, see announce_entry.

+ + +
+
+

add_url_seed() add_http_seed() web_seeds()

+
+void add_url_seed (std::string const& url
+      , std::string const& extern_auth = std::string()
+      , web_seed_entry::headers_t const& extra_headers = web_seed_entry::headers_t());
+std::vector<web_seed_entry> const& web_seeds () const;
+void add_http_seed (std::string const& url
+      , std::string const& extern_auth = std::string()
+      , web_seed_entry::headers_t const& extra_headers = web_seed_entry::headers_t());
+
+

web_seeds() returns all url seeds and http seeds in the torrent. Each entry +is a web_seed_entry and may refer to either a url seed or http seed.

+

add_url_seed() and add_http_seed() adds one url to the list of +url/http seeds. Currently, the only transport protocol supported for the url +is http.

+

The extern_auth argument can be used for other athorization schemese than +basic HTTP authorization. If set, it will override any username and password +found in the URL itself. The string will be sent as the HTTP authorization header's +value (without specifying "Basic").

+

The extra_headers argument defaults to an empty list, but can be used to +insert custom HTTP headers in the requests to a specific web seed.

+

See http seeding for more information.

+ + +
+
+

piece_length() num_pieces() total_size()

+
+int num_pieces () const;
+size_type total_size () const;
+int piece_length () const;
+
+

total_size(), piece_length() and num_pieces() returns the total +number of bytes the torrent-file represents (all the files in it), the number of byte for +each piece and the total number of pieces, respectively. The difference between +piece_size() and piece_length() is that piece_size() takes +the piece index as argument and gives you the exact size of that piece. It will always +be the same as piece_length() except in the case of the last piece, which may +be smaller.

+
+
+

info_hash()

+
+const sha1_hash& info_hash () const;
+
+

returns the info-hash of the torrent

+ +
+
+

num_files() file_at()

+
+int num_files () const;
+file_entry file_at (int index) const;
+
+

If you need index-access to files you can use the num_files() and file_at() +to access files using indices.

+
+
+

map_block()

+
+std::vector<file_slice> map_block (int piece, size_type offset, int size) const;
+
+

This function will map a piece index, a byte offset within that piece and +a size (in bytes) into the corresponding files with offsets where that data +for that piece is supposed to be stored. See file_slice.

+
+
+

map_file()

+
+peer_request map_file (int file, size_type offset, int size) const;
+
+

This function will map a range in a specific file into a range in the torrent. +The file_offset parameter is the offset in the file, given in bytes, where +0 is the start of the file. See peer_request.

+

The input range is assumed to be valid within the torrent. file_offset ++ size is not allowed to be greater than the file size. file_index +must refer to a valid file, i.e. it cannot be >= num_files().

+
+
+

ssl_cert()

+
+std::string ssl_cert () const;
+
+

Returns the SSL root certificate for the torrent, if it is an SSL +torrent. Otherwise returns an empty string. The certificate is +the the public certificate in x509 format.

+
+
+

is_valid()

+
+bool is_valid () const;
+
+

returns true if this torrent_info object has a torrent loaded. +This is primarily used to determine if a magnet link has had its +metadata resolved yet or not.

+
+
+

priv()

+
+bool priv () const;
+
+

returns true if this torrent is private. i.e., it should not be +distributed on the trackerless network (the kademlia DHT).

+
+
+

is_i2p()

+
+bool is_i2p () const;
+
+

returns true if this is an i2p torrent. This is determined by whether +or not it has a tracker whose URL domain name ends with ".i2p". i2p +torrents disable the DHT and local peer discovery as well as talking +to peers over anything other than the i2p network.

+ + +
+
+

hash_for_piece_ptr() hash_for_piece() piece_size()

+
+sha1_hash hash_for_piece (int index) const;
+char const* hash_for_piece_ptr (int index) const;
+int piece_size (int index) const;
+
+

hash_for_piece() takes a piece-index and returns the 20-bytes sha1-hash for that +piece and info_hash() returns the 20-bytes sha1-hash for the info-section of the +torrent file. +hash_for_piece_ptr() returns a pointer to the 20 byte sha1 digest for the piece. +Note that the string is not null-terminated.

+ +
+
+

set_merkle_tree() merkle_tree()

+
+std::vector<sha1_hash> const& merkle_tree () const;
+void set_merkle_tree (std::vector<sha1_hash>& h);
+
+

merkle_tree() returns a reference to the merkle tree for this torrent, if any.

+

set_merkle_tree() moves the passed in merkle tree into the torrent_info object. +i.e. h will not be identical after the call. You need to set the merkle tree for +a torrent that you've just created (as a merkle torrent). The merkle tree is retrieved +from the create_torrent::merkle_tree() function, and need to be saved separately +from the torrent file itself. Once it's added to libtorrent, the merkle tree will be +persisted in the resume data.

+ + + +
+
+

creator() creation_date() name() comment()

+
+boost::optional<time_t> creation_date () const;
+const std::string& name () const;
+const std::string& comment () const;
+const std::string& creator () const;
+
+

name() returns the name of the torrent.

+

comment() returns the comment associated with the torrent. If there's no comment, +it will return an empty string. creation_date() returns the creation date of +the torrent as time_t (posix time). If there's no time stamp in the torrent file, +the optional object will be uninitialized.

+

Both the name and the comment is UTF-8 encoded strings.

+

creator() returns the creator string in the torrent. If there is no creator string +it will return an empty string.

+
+
+

nodes()

+
+nodes_t const& nodes () const;
+
+

If this torrent contains any DHT nodes, they are put in this vector in their original +form (host name and port number).

+
+
+

add_node()

+
+void add_node (std::pair<std::string, int> const& node);
+
+

This is used when creating torrent. Use this to add a known DHT node. It may +be used, by the client, to bootstrap into the DHT network.

+
+
+

parse_info_section()

+
+bool parse_info_section (lazy_entry const& e, error_code& ec, int flags);
+
+

populates the torrent_info by providing just the info-dict buffer. This is used when +loading a torrent from a magnet link for instance, where we only have the info-dict. +The lazy_entry e points to a parsed info-dictionary. ec returns an error code +if something fails (typically if the info dictionary is malformed). flags are currently +unused.

+
+
+

info()

+
+lazy_entry const* info (char const* key) const;
+
+

This function looks up keys from the info-dictionary of the loaded torrent file. +It can be used to access extension values put in the .torrent file. If the specified +key cannot be found, it returns NULL.

+
+
+

swap()

+
+void swap (torrent_info& ti);
+
+

swap the content of this and ti`.

+ +
+
+

metadata_size() metadata()

+
+int metadata_size () const;
+boost::shared_array<char> metadata () const;
+
+

metadata() returns a the raw info section of the torrent file. The size +of the metadata is returned by metadata_size().

+
+
+

is_merkle_torrent()

+
+bool is_merkle_torrent () const;
+
+

returns whether or not this is a merkle torrent. +see BEP30.

+
+
+

make_magnet_uri()

+

Declared in "libtorrent/magnet_uri.hpp"

+
+std::string make_magnet_uri (torrent_handle const& handle);
+std::string make_magnet_uri (torrent_info const& info);
+
+

Generates a magnet URI from the specified torrent. If the torrent +handle is invalid, an empty string is returned.

+

For more information about magnet links, see magnet links.

+
+
+

parse_magnet_uri()

+

Declared in "libtorrent/magnet_uri.hpp"

+
+void parse_magnet_uri (std::string const& uri, add_torrent_params& p, error_code& ec);
+
+

This function parses out information from the magnet link and populates the +add_torrent_params object.

+
+
+

hash_value()

+

Declared in "libtorrent/torrent_handle.hpp"

+
+std::size_t hash_value (torrent_status const& ts);
+
+

allows torrent_handle to be used in unordered_map and unordered_set.

+
+
+
+ +
+ + +
+ + diff --git a/docs/reference-Create_Torrents.html b/docs/reference-Create_Torrents.html new file mode 100644 index 000000000..5533b97b8 --- /dev/null +++ b/docs/reference-Create_Torrents.html @@ -0,0 +1,437 @@ + + + + + + +Create Torrents + + + + + + + + +
+
+
+ +
+ +
+

Create Torrents

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

Table of contents

+ +
+

This section describes the functions and classes that are used +to create torrent files. It is a layered API with low level classes +and higher level convenience functions. A torrent is created in 4 +steps:

+
    +
  1. first the files that will be part of the torrent are determined.
  2. +
  3. the torrent properties are set, such as tracker url, web seeds, +DHT nodes etc.
  4. +
  5. Read through all the files in the torrent, SHA-1 all the data +and set the piece hashes.
  6. +
  7. The torrent is bencoded into a file or buffer.
  8. +
+

If there are a lot of files and or deep directoy hierarchies to +traverse, step one can be time consuming.

+

Typically step 3 is by far the most time consuming step, since it +requires to read all the bytes from all the files in the torrent.

+

All of these classes and functions are declared by including +libtorrent/create_torrent.hpp.

+

example:

+
+file_storage fs;
+
+// recursively adds files in directories
+add_files(fs, "./my_torrent");
+
+create_torrent t(fs);
+t.add_tracker("http://my.tracker.com/announce");
+t.set_creator("libtorrent example");
+
+// reads the files and calculates the hashes
+set_piece_hashes(t, ".");
+
+ofstream out("my_torrent.torrent", std::ios_base::binary);
+bencode(std::ostream_iterator<char>(out), t.generate());
+
+
+

create_torrent

+

Declared in "libtorrent/create_torrent.hpp"

+

This class holds state for creating a torrent. After having added +all information to it, call create_torrent::generate() to generate +the torrent. The entry that's returned can then be bencoded into a +.torrent file using bencode().

+
+struct create_torrent
+{
+   create_torrent (torrent_info const& ti);
+   create_torrent (file_storage& fs, int piece_size = 0
+      , int pad_file_limit = -1, int flags = optimize, int alignment = 0x4000);
+   entry generate () const;
+   file_storage const& files () const;
+   void set_comment (char const* str);
+   void set_creator (char const* str);
+   void set_hash (int index, sha1_hash const& h);
+   void set_file_hash (int index, sha1_hash const& h);
+   void add_url_seed (std::string const& url);
+   void add_http_seed (std::string const& url);
+   void add_node (std::pair<std::string, int> const& node);
+   void add_tracker (std::string const& url, int tier = 0);
+   void set_root_cert (std::string const& pem);
+   bool priv () const;
+   void set_priv (bool p);
+   int num_pieces () const;
+   int piece_length () const;
+   int piece_size (int i) const;
+   std::vector<sha1_hash> const& merkle_tree () const;
+
+   enum flags_t
+   {
+      optimize,
+      merkle,
+      modification_time,
+      symlinks,
+      calculate_file_hashes,
+   };
+};
+
+
+

create_torrent()

+
+create_torrent (torrent_info const& ti);
+create_torrent (file_storage& fs, int piece_size = 0
+      , int pad_file_limit = -1, int flags = optimize, int alignment = 0x4000);
+
+

The piece_size is the size of each piece in bytes. It must +be a multiple of 16 kiB. If a piece size of 0 is specified, a +piece_size will be calculated such that the torrent file is roughly 40 kB.

+

If a pad_size_limit is specified (other than -1), any file larger than +the specified number of bytes will be preceeded by a pad file to align it +with the start of a piece. The pad_file_limit is ignored unless the +optimize flag is passed. Typically it doesn't make sense to set this +any lower than 4kiB.

+

The overload that takes a torrent_info object will make a verbatim +copy of its info dictionary (to preserve the info-hash). The copy of +the info dictionary will be used by create_torrent::generate(). This means +that none of the member functions of create_torrent that affects +the content of the info dictionary (such as set_hash()), will +have any affect.

+

The flags arguments specifies options for the torrent creation. It can +be any combination of the flags defined by create_torrent::flags_t.

+

alignment is used when pad files are enabled. This is the size eligible +files are aligned to. The default is the default bittorrent block size of +16 kiB. It is common to align to the piece size of the torrent.

+
+
+

generate()

+
+entry generate () const;
+
+

This function will generate the .torrent file as a bencode tree. In order to +generate the flat file, use the bencode() function.

+

It may be useful to add custom entries to the torrent file before bencoding it +and saving it to disk.

+

If anything goes wrong during torrent generation, this function will return +an empty entry structure. You can test for this condition by querying the +type of the entry:

+
+file_storage fs;
+// add file ...
+create_torrent t(fs);
+// add trackers and piece hashes ...
+e = t.generate();
+
+if (e.type() == entry::undefined_t)
+{
+        // something went wrong
+}
+
+

For instance, you cannot generate a torrent with 0 files in it. If you don't add +any files to the file_storage, torrent generation will fail.

+
+
+

files()

+
+file_storage const& files () const;
+
+

returns an immutable reference to the file_storage used to create +the torrent from.

+
+
+

set_comment()

+
+void set_comment (char const* str);
+
+

Sets the comment for the torrent. The string str should be utf-8 encoded. +The comment in a torrent file is optional.

+
+
+

set_creator()

+
+void set_creator (char const* str);
+
+

Sets the creator of the torrent. The string str should be utf-8 encoded. +This is optional.

+
+
+

set_hash()

+
+void set_hash (int index, sha1_hash const& h);
+
+

This sets the SHA-1 hash for the specified piece (index). You are required +to set the hash for every piece in the torrent before generating it. If you have +the files on disk, you can use the high level convenience function to do this. +See set_piece_hashes().

+
+
+

set_file_hash()

+
+void set_file_hash (int index, sha1_hash const& h);
+
+

This sets the sha1 hash for this file. This hash will end up under the key sha1 +associated with this file (for multi-file torrents) or in the root info dictionary +for single-file torrents.

+ +
+
+

add_url_seed() add_http_seed()

+
+void add_url_seed (std::string const& url);
+void add_http_seed (std::string const& url);
+
+

This adds a url seed to the torrent. You can have any number of url seeds. For a +single file torrent, this should be an HTTP url, pointing to a file with identical +content as the file of the torrent. For a multi-file torrent, it should point to +a directory containing a directory with the same name as this torrent, and all the +files of the torrent in it.

+

The second function, add_http_seed() adds an HTTP seed instead.

+
+
+

add_node()

+
+void add_node (std::pair<std::string, int> const& node);
+
+

This adds a DHT node to the torrent. This especially useful if you're creating a +tracker less torrent. It can be used by clients to bootstrap their DHT node from. +The node is a hostname and a port number where there is a DHT node running. +You can have any number of DHT nodes in a torrent.

+
+
+

add_tracker()

+
+void add_tracker (std::string const& url, int tier = 0);
+
+

Adds a tracker to the torrent. This is not strictly required, but most torrents +use a tracker as their main source of peers. The url should be an http:// or udp:// +url to a machine running a bittorrent tracker that accepts announces for this torrent's +info-hash. The tier is the fallback priority of the tracker. All trackers with tier 0 are +tried first (in any order). If all fail, trackers with tier 1 are tried. If all of those +fail, trackers with tier 2 are tried, and so on.

+
+
+

set_root_cert()

+
+void set_root_cert (std::string const& pem);
+
+

This function sets an X.509 certificate in PEM format to the torrent. This makes the +torrent an SSL torrent. An SSL torrent requires that each peer has a valid certificate +signed by this root certificate. For SSL torrents, all peers are connecting over SSL +connections. For more information, see the section on ssl torrents.

+

The string is not the path to the cert, it's the actual content of the certificate, +loaded into a std::string.

+ +
+
+

priv() set_priv()

+
+bool priv () const;
+void set_priv (bool p);
+
+

Sets and queries the private flag of the torrent. +Torrents with the private flag set ask clients to not use any other +sources than the tracker for peers, and to not advertize itself publicly, +apart from the tracker.

+
+
+

num_pieces()

+
+int num_pieces () const;
+
+

returns the number of pieces in the associated file_storage object.

+ +
+
+

piece_length() piece_size()

+
+int piece_length () const;
+int piece_size (int i) const;
+
+

piece_length() returns the piece size of all pieces but the +last one. piece_size() returns the size of the specified piece. +these functions are just forwarding to the associated file_storage.

+
+
+

merkle_tree()

+
+std::vector<sha1_hash> const& merkle_tree () const;
+
+

This function returns the merkle hash tree, if the torrent was created as a merkle +torrent. The tree is created by generate() and won't be valid until that function +has been called. When creating a merkle tree torrent, the actual tree itself has to +be saved off separately and fed into libtorrent the first time you start seeding it, +through the torrent_info::set_merkle_tree() function. From that point onwards, the +tree will be saved in the resume data.

+
+
+

enum flags_t

+

Declared in "libtorrent/create_torrent.hpp"

+ +++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
namevaluedescription
optimize1This will insert pad files to align the files to piece boundaries, for +optimized disk-I/O.
merkle2This will create a merkle hash tree torrent. A merkle torrent cannot +be opened in clients that don't specifically support merkle torrents. +The benefit is that the resulting torrent file will be much smaller and +not grow with more pieces. When this option is specified, it is +recommended to have a fairly small piece size, say 64 kiB. +When creating merkle torrents, the full hash tree is also generated +and should be saved off separately. It is accessed through the +create_torrent::merkle_tree() function.
modification_time4This will include the file modification time as part of the torrent. +This is not enabled by default, as it might cause problems when you +create a torrent from separate files with the same content, hoping to +yield the same info-hash. If the files have different modification times, +with this option enabled, you would get different info-hashes for the +files.
symlinks8If this flag is set, files that are symlinks get a symlink attribute +set on them and their data will not be included in the torrent. This +is useful if you need to reconstruct a file hierarchy which contains +symlinks.
calculate_file_hashes16If this is set, the set_piece_hashes() function will, as it calculates +the piece hashes, also calculate the file hashes and add those associated +with each file. Note that unless you use the set_piece_hashes() function, +this flag will have no effect.
+
+
+

add_files()

+

Declared in "libtorrent/create_torrent.hpp"

+
+template <class Pred> void add_files (file_storage& fs, std::string const& file, Pred p, boost::uint32_t flags = 0);
+inline void add_files (file_storage& fs, std::string const& file, boost::uint32_t flags = 0);
+
+

Adds the file specified by path to the file_storage object. In case path +refers to a diretory, files will be added recursively from the directory.

+

If specified, the predicate p is called once for every file and directory that +is encountered. files for which p returns true are added, and directories for +which p returns true are traversed. p must have the following signature:

+
+bool Pred(std::string const& p);
+
+

The path that is passed in to the predicate is the full path of the file or +directory. If no predicate is specified, all files are added, and all directories +are traveresed.

+

The ".." directory is never traversed.

+

The flags argument should be the same as the flags passed to the create_torrent +constructor.

+
+
+

set_piece_hashes()

+

Declared in "libtorrent/create_torrent.hpp"

+
+void set_piece_hashes (create_torrent& t, std::string const& p
+   , boost::function<void(int)> f, error_code& ec);
+inline void set_piece_hashes (create_torrent& t, std::string const& p);
+inline void set_piece_hashes (create_torrent& t, std::string const& p, error_code& ec);
+
+

This function will assume that the files added to the torrent file exists at path +p, read those files and hash the content and set the hashes in the create_torrent +object. The optional function f is called in between every hash that is set. f +must have the following signature:

+
+void Fun(int);
+
+

The overloads that don't take an error_code& may throw an exception in case of a +file error, the other overloads sets the error code to reflect the error, if any.

+
+
+
+ +
+ + +
+ + diff --git a/docs/reference-Custom_Storage.html b/docs/reference-Custom_Storage.html new file mode 100644 index 000000000..f266d2142 --- /dev/null +++ b/docs/reference-Custom_Storage.html @@ -0,0 +1,576 @@ + + + + + + +Custom Storage + + + + + + + + +
+
+
+ +
+ +
+

Custom Storage

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

Table of contents

+ +
+

This is an example storage implementation that stores all pieces in a std::map, +i.e. in RAM. It's not necessarily very useful in practice, but illustrates the +basics of implementing a custom storage.

+
+struct temp_storage : storage_interface
+{
+        temp_storage(file_storage const& fs) : m_files(fs) {}
+        virtual bool initialize(bool allocate_files) { return false; }
+        virtual bool has_any_file() { return false; }
+        virtual int read(char* buf, int slot, int offset, int size)
+        {
+                std::map<int, std::vector<char> >::const_iterator i = m_file_data.find(slot);
+                if (i == m_file_data.end()) return 0;
+                int available = i->second.size() - offset;
+                if (available <= 0) return 0;
+                if (available > size) available = size;
+                memcpy(buf, &i->second[offset], available);
+                return available;
+        }
+        virtual int write(const char* buf, int slot, int offset, int size)
+        {
+                std::vector<char>& data = m_file_data[slot];
+                if (data.size() < offset + size) data.resize(offset + size);
+                std::memcpy(&data[offset], buf, size);
+                return size;
+        }
+        virtual bool rename_file(int file, std::string const& new_name)
+        { assert(false); return false; }
+        virtual bool move_storage(std::string const& save_path) { return false; }
+        virtual bool verify_resume_data(lazy_entry const& rd, error_code& error) { return false; }
+        virtual bool write_resume_data(entry& rd) const { return false; }
+        virtual bool move_slot(int src_slot, int dst_slot) { assert(false); return false; }
+        virtual bool swap_slots(int slot1, int slot2) { assert(false); return false; }
+        virtual bool swap_slots3(int slot1, int slot2, int slot3) { assert(false); return false; }
+        virtual size_type physical_offset(int slot, int offset)
+        { return slot * m_files.piece_length() + offset; };
+        virtual sha1_hash hash_for_slot(int slot, partial_hash& ph, int piece_size)
+        {
+                int left = piece_size - ph.offset;
+                assert(left >= 0);
+                if (left > 0)
+                {
+                        std::vector<char>& data = m_file_data[slot];
+                        // if there are padding files, those blocks will be considered
+                        // completed even though they haven't been written to the storage.
+                        // in this case, just extend the piece buffer to its full size
+                        // and fill it with zeroes.
+                        if (data.size() < piece_size) data.resize(piece_size, 0);
+                        ph.h.update(&data[ph.offset], left);
+                }
+                return ph.h.final();
+        }
+        virtual bool release_files() { return false; }
+        virtual bool delete_files() { return false; }
+
+        std::map<int, std::vector<char> > m_file_data;
+        file_storage m_files;
+};
+
+storage_interface* temp_storage_constructor(
+        file_storage const& fs, file_storage const* mapped
+        , std::string const& path, file_pool& fp
+        , std::vector<boost::uint8_t> const& prio)
+{
+        return new temp_storage(fs);
+}
+
+
+

file_pool

+

Declared in "libtorrent/file_pool.hpp"

+

this is an internal cache of open file handles. It's primarily used by +storage_interface implementations. It provides semi weak guarantees of +not opening more file handles than specified. Given multiple threads, +each with the ability to lock a file handle (via smart pointer), there +may be windows where more file handles are open.

+
+struct file_pool : boost::noncopyable
+{
+   ~file_pool ();
+   file_pool (int size = 40);
+   boost::intrusive_ptr<file> open_file (void* st, std::string const& p
+      , int file_index, file_storage const& fs, int m, error_code& ec);
+   void release (void* st);
+   void release (void* st, int file_index);
+   void resize (int size);
+   int size_limit () const;
+};
+
+ +
+

~file_pool() file_pool()

+
+~file_pool ();
+file_pool (int size = 40);
+
+

size specifies the number of allowed files handles +to hold open at any given time.

+
+
+

open_file()

+
+boost::intrusive_ptr<file> open_file (void* st, std::string const& p
+      , int file_index, file_storage const& fs, int m, error_code& ec);
+
+

return an open file handle to file at file_index in the +file_storage fs opened at save path p. m is the +file open mode (see file::open_mode_t).

+
+
+

release()

+
+void release (void* st);
+void release (void* st, int file_index);
+
+

release all files belonging to the specified storage_interface (st) +the overload that takes file_index releases only the file with +that index in storage st.

+
+
+

resize()

+
+void resize (int size);
+
+

update the allowed number of open file handles to size.

+
+
+

size_limit()

+
+int size_limit () const;
+
+

returns the current limit of number of allowed open file handles held +by the file_pool.

+
+
+
+

storage_interface

+

Declared in "libtorrent/storage.hpp"

+

The storage interface is a pure virtual class that can be implemented to +customize how and where data for a torrent is stored. The default storage +implementation uses regular files in the filesystem, mapping the files in the +torrent in the way one would assume a torrent is saved to disk. Implementing +your own storage interface makes it possible to store all data in RAM, or in +some optimized order on disk (the order the pieces are received for instance), +or saving multifile torrents in a single file in order to be able to take +advantage of optimized disk-I/O.

+

It is also possible to write a thin class that uses the default storage but +modifies some particular behavior, for instance encrypting the data before +it's written to disk, and decrypting it when it's read again.

+

The storage interface is based on slots, each slot is 'piece_size' number +of bytes. All access is done by writing and reading whole or partial +slots. One slot is one piece in the torrent, but the data in the slot +does not necessarily correspond to the piece with the same index (in +compact allocation mode it won't).

+

libtorrent comes with two built-in storage implementations; default_storage +and disabled_storage. Their constructor functions are called default_storage_constructor() +and disabled_storage_constructor respectively. The disabled storage does +just what it sounds like. It throws away data that's written, and it +reads garbage. It's useful mostly for benchmarking and profiling purpose.

+
+struct storage_interface
+{
+   virtual bool initialize (bool allocate_files) = 0;
+   virtual bool has_any_file () = 0;
+   virtual int writev (file::iovec_t const* bufs, int slot, int offset, int num_bufs, int flags = file::random_access);
+   virtual int readv (file::iovec_t const* bufs, int slot, int offset, int num_bufs, int flags = file::random_access);
+   virtual void hint_read (int, int, int);
+   virtual int read (char* buf, int slot, int offset, int size) = 0;
+   virtual int write (const char* buf, int slot, int offset, int size) = 0;
+   virtual size_type physical_offset (int slot, int offset) = 0;
+   virtual int sparse_end (int start) const;
+   virtual int move_storage (std::string const& save_path, int flags) = 0;
+   virtual bool verify_resume_data (lazy_entry const& rd, error_code& error) = 0;
+   virtual bool write_resume_data (entry& rd) const = 0;
+   virtual bool move_slot (int src_slot, int dst_slot) = 0;
+   virtual bool swap_slots (int slot1, int slot2) = 0;
+   virtual bool swap_slots3 (int slot1, int slot2, int slot3) = 0;
+   virtual bool release_files () = 0;
+   virtual bool rename_file (int index, std::string const& new_filename) = 0;
+   virtual bool delete_files () = 0;
+   disk_buffer_pool* disk_pool ();
+   session_settings const& settings () const;
+   void set_error (std::string const& file, error_code const& ec) const;
+   error_code const& error () const;
+   std::string const& error_file () const;
+   virtual void clear_error ();
+};
+
+
+

initialize()

+
+virtual bool initialize (bool allocate_files) = 0;
+
+

This function is called when the storage is to be initialized. The default storage +will create directories and empty files at this point. If allocate_files is true, +it will also ftruncate all files to their target size.

+

Returning true indicates an error occurred.

+
+
+

has_any_file()

+
+virtual bool has_any_file () = 0;
+
+

This function is called when first checking (or re-checking) the storage for a torrent. +It should return true if any of the files that is used in this storage exists on disk. +If so, the storage will be checked for existing pieces before starting the download.

+ +
+
+

writev() readv()

+
+virtual int writev (file::iovec_t const* bufs, int slot, int offset, int num_bufs, int flags = file::random_access);
+virtual int readv (file::iovec_t const* bufs, int slot, int offset, int num_bufs, int flags = file::random_access);
+
+

These functions should read or write the data in or to the given slot at the given offset. +It should read or write num_bufs buffers sequentially, where the size of each buffer +is specified in the buffer array bufs. The file::iovec_t type has the following members:

+
+struct iovec_t
+{
+        void* iov_base;
+        size_t iov_len;
+};
+
+

The return value is the number of bytes actually read or written, or -1 on failure. If +it returns -1, the error code is expected to be set to

+

Every buffer in bufs can be assumed to be page aligned and be of a page aligned size, +except for the last buffer of the torrent. The allocated buffer can be assumed to fit a +fully page aligned number of bytes though. This is useful when reading and writing the +last piece of a file in unbuffered mode.

+

The offset is aligned to 16 kiB boundries most of the time, but there are rare +exceptions when it's not. Specifically if the read cache is disabled/or full and a +client requests unaligned data, or the file itself is not aligned in the torrent. +Most clients request aligned data.

+
+
+

hint_read()

+
+virtual void hint_read (int, int, int);
+
+

This function is called when a read job is queued. It gives the storage wrapper an +opportunity to hint the operating system about this coming read. For instance, the +storage may call posix_fadvise(POSIX_FADV_WILLNEED) or fcntl(F_RDADVISE).

+
+
+

read()

+
+virtual int read (char* buf, int slot, int offset, int size) = 0;
+
+

negative return value indicates an error

+
+
+

write()

+
+virtual int write (const char* buf, int slot, int offset, int size) = 0;
+
+

negative return value indicates an error

+
+
+

physical_offset()

+
+virtual size_type physical_offset (int slot, int offset) = 0;
+
+

returns the offset on the physical storage medium for the +byte at offset offset in slot slot.

+
+
+

sparse_end()

+
+virtual int sparse_end (int start) const;
+
+

This function is optional. It is supposed to return the first piece, starting at +start that is fully contained within a data-region on disk (i.e. non-sparse +region). The purpose of this is to skip parts of files that can be known to contain +zeros when checking files.

+
+
+

move_storage()

+
+virtual int move_storage (std::string const& save_path, int flags) = 0;
+
+

This function should move all the files belonging to the storage to the new save_path. +The default storage moves the single file or the directory of the torrent.

+

Before moving the files, any open file handles may have to be closed, like +release_files().

+

returns one of: +| no_error = 0 +| need_full_check = -1 +| fatal_disk_error = -2 +| file_exist = -4

+
+
+

verify_resume_data()

+
+virtual bool verify_resume_data (lazy_entry const& rd, error_code& error) = 0;
+
+

This function should verify the resume data rd with the files +on disk. If the resume data seems to be up-to-date, return true. If +not, set error to a description of what mismatched and return false.

+

The default storage may compare file sizes and time stamps of the files.

+

Returning false indicates an error occurred.

+
+
+

write_resume_data()

+
+virtual bool write_resume_data (entry& rd) const = 0;
+
+

This function should fill in resume data, the current state of the +storage, in rd. The default storage adds file timestamps and +sizes.

+

Returning true indicates an error occurred.

+
+
+

move_slot()

+
+virtual bool move_slot (int src_slot, int dst_slot) = 0;
+
+

This function should copy or move the data in slot src_slot to +the slot dst_slot. This is only used in compact mode.

+

If the storage caches slots, this could be implemented more +efficient than reading and writing the data.

+

Returning true indicates an error occurred.

+
+
+

swap_slots()

+
+virtual bool swap_slots (int slot1, int slot2) = 0;
+
+

This function should swap the data in slot1 and slot2. The default +storage uses a scratch buffer to read the data into, then moving the other +slot and finally writing back the temporary slot's data

+

This is only used in compact mode.

+

Returning true indicates an error occurred.

+
+
+

swap_slots3()

+
+virtual bool swap_slots3 (int slot1, int slot2, int slot3) = 0;
+
+

This function should do a 3-way swap, or shift of the slots. slot1 +should move to slot2, which should be moved to slot3 which in turn +should be moved to slot1.

+

This is only used in compact mode.

+

Returning true indicates an error occurred.

+
+
+

release_files()

+
+virtual bool release_files () = 0;
+
+

This function should release all the file handles that it keeps open to files +belonging to this storage. The default implementation just calls +file_pool::release_files(this).

+

Returning true indicates an error occurred.

+
+
+

rename_file()

+
+virtual bool rename_file (int index, std::string const& new_filename) = 0;
+
+

Rename file with index file to the thame new_name. If there is an error, +true should be returned.

+
+
+

delete_files()

+
+virtual bool delete_files () = 0;
+
+

This function should delete all files and directories belonging to this storage.

+

Returning true indicates an error occurred.

+

The disk_buffer_pool is used to allocate and free disk buffers. It has the +following members:

+
+struct disk_buffer_pool : boost::noncopyable
+{
+        char* allocate_buffer(char const* category);
+        void free_buffer(char* buf);
+
+        char* allocate_buffers(int blocks, char const* category);
+        void free_buffers(char* buf, int blocks);
+
+        int block_size() const { return m_block_size; }
+
+        void release_memory();
+};
+
+
+
+

disk_pool()

+
+disk_buffer_pool* disk_pool ();
+
+

access global disk_buffer_pool, for allocating and freeing disk buffers

+
+
+

settings()

+
+session_settings const& settings () const;
+
+

access global session_settings

+
+
+

set_error()

+
+void set_error (std::string const& file, error_code const& ec) const;
+
+

called by the storage implementation to set it into an +error state. Typically whenever a critical file operation +fails.

+ +
+
+

error_file() error()

+
+error_code const& error () const;
+std::string const& error_file () const;
+
+

returns the currently set error code and file path associated with it, +if set.

+
+
+

clear_error()

+
+virtual void clear_error ();
+
+

reset the error state to allow continuing reading and writing +to the storage

+
+
+
+

default_storage

+

Declared in "libtorrent/storage.hpp"

+

The default implementation of storage_interface. Behaves as a normal bittorrent client. +It is possible to derive from this class in order to override some of its behavior, when +implementing a custom storage.

+
+class default_storage : public storage_interface, boost::noncopyable
+{
+   default_storage (file_storage const& fs, file_storage const* mapped, std::string const& path
+      , file_pool& fp, std::vector<boost::uint8_t> const& file_prio);
+   bool move_slot (int src_slot, int dst_slot);
+   bool rename_file (int index, std::string const& new_filename);
+   int read (char* buf, int slot, int offset, int size);
+   bool has_any_file ();
+   int move_storage (std::string const& save_path, int flags);
+   bool write_resume_data (entry& rd) const;
+   int write (char const* buf, int slot, int offset, int size);
+   int writev (file::iovec_t const* buf, int slot, int offset, int num_bufs, int flags = file::random_access);
+   size_type physical_offset (int slot, int offset);
+   bool release_files ();
+   bool delete_files ();
+   bool verify_resume_data (lazy_entry const& rd, error_code& error);
+   int readv (file::iovec_t const* bufs, int slot, int offset, int num_bufs, int flags = file::random_access);
+   bool swap_slots3 (int slot1, int slot2, int slot3);
+   bool initialize (bool allocate_files);
+   void hint_read (int slot, int offset, int len);
+   bool swap_slots (int slot1, int slot2);
+   int sparse_end (int start) const;
+   file_storage const& files () const;
+};
+
+
+

enum move_flags_t

+

Declared in "libtorrent/storage.hpp"

+ +++++ + + + + + + + + + + + + + + + + + + + + +
namevaluedescription
always_replace_files0replace any files in the destination when copying +or moving the storage
fail_if_exist1if any files that we want to copy exist in the destination +exist, fail the whole operation and don't perform +any copy or move. There is an inherent race condition +in this mode. The files are checked for existence before +the operation starts. In between the check and performing +the copy, the destination files may be created, in which +case they are replaced.
dont_replace2if any file exist in the target, take those files instead +of the ones we may have in the source.
+
+
+
+ +
+ + +
+ + diff --git a/docs/reference-Error_Codes.html b/docs/reference-Error_Codes.html new file mode 100644 index 000000000..b6615601e --- /dev/null +++ b/docs/reference-Error_Codes.html @@ -0,0 +1,1070 @@ + + + + + + +Error Codes + + + + + + + + +
+
+
+ +
+ +
+

Error Codes

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

http_error_category

+

Declared in "libtorrent/error_code.hpp"

+
+struct http_error_category : boost::system::error_category
+{
+   virtual boost::system::error_condition default_error_condition (int ev) const BOOST_SYSTEM_NOEXCEPT;
+   virtual const char* name () const BOOST_SYSTEM_NOEXCEPT;
+   virtual std::string message (int ev) const BOOST_SYSTEM_NOEXCEPT;
+};
+
+
+
+

libtorrent_exception

+

Declared in "libtorrent/error_code.hpp"

+
+struct libtorrent_exception: std::exception
+{
+   error_code error () const;
+   virtual ~libtorrent_exception () throw();
+   libtorrent_exception (error_code const& s);
+   virtual const char* what () const throw();
+};
+
+
+
+

i2p_error_category

+

Declared in "libtorrent/i2p_stream.hpp"

+
+struct i2p_error_category : boost::system::error_category
+{
+   virtual boost::system::error_condition default_error_condition (int ev) const BOOST_SYSTEM_NOEXCEPT;
+   virtual const char* name () const BOOST_SYSTEM_NOEXCEPT;
+   virtual std::string message (int ev) const BOOST_SYSTEM_NOEXCEPT;
+};
+
+
+
+

upnp_error_category

+

Declared in "libtorrent/upnp.hpp"

+
+struct upnp_error_category : boost::system::error_category
+{
+   virtual boost::system::error_condition default_error_condition (int ev) const BOOST_SYSTEM_NOEXCEPT;
+   virtual const char* name () const BOOST_SYSTEM_NOEXCEPT;
+   virtual std::string message (int ev) const BOOST_SYSTEM_NOEXCEPT;
+};
+
+
+

get_libtorrent_category()

+

Declared in "libtorrent/error_code.hpp"

+
+boost::system::error_category& get_libtorrent_category ();
+
+

return the instance of the libtorrent_error_category which +maps libtorrent error codes to human readable error messages.

+
+
+

get_http_category()

+

Declared in "libtorrent/error_code.hpp"

+
+boost::system::error_category& get_http_category ();
+
+

returns the error_category for HTTP errors

+
+
+

enum error_code_enum

+

Declared in "libtorrent/error_code.hpp"

+ +++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
namevaluedescription
no_error0Not an error
file_collision1Two torrents has files which end up overwriting each other
failed_hash_check2A piece did not match its piece hash
torrent_is_no_dict3The .torrent file does not contain a bencoded dictionary at +its top level
torrent_missing_info4The .torrent file does not have an info dictionary
torrent_info_no_dict5The .torrent file's info entry is not a dictionary
torrent_missing_piece_length6The .torrent file does not have a piece length entry
torrent_missing_name7The .torrent file does not have a name entry
torrent_invalid_name8The .torrent file's name entry is invalid
torrent_invalid_length9The length of a file, or of the whole .torrent file is invalid. +Either negative or not an integer
torrent_file_parse_failed10Failed to parse a file entry in the .torrent
torrent_missing_pieces11The pieces field is missing or invalid in the .torrent file
torrent_invalid_hashes12The pieces string has incorrect length
too_many_pieces_in_torrent13The .torrent file has more pieces than is supported by libtorrent
invalid_swarm_metadata14The metadata (.torrent file) that was received from the swarm +matched the info-hash, but failed to be parsed
invalid_bencoding15The file or buffer is not correctly bencoded
no_files_in_torrent16The .torrent file does not contain any files
invalid_escaped_string17The string was not properly url-encoded as expected
session_is_closing18Operation is not permitted since the session is shutting down
duplicate_torrent19There's already a torrent with that info-hash added to the +session
invalid_torrent_handle20The supplied torrent_handle is not referring to a valid torrent
invalid_entry_type21The type requested from the entry did not match its type
missing_info_hash_in_uri22The specified URI does not contain a valid info-hash
file_too_short23One of the files in the torrent was unexpectadly small. This +might be caused by files being changed by an external process
unsupported_url_protocol24The URL used an unknown protocol. Currently http and +https (if built with openssl support) are recognized. For +trackers udp is recognized as well.
url_parse_error25The URL did not conform to URL syntax and failed to be parsed
peer_sent_empty_piece26The peer sent a 'piece' message of length 0
parse_failed27A bencoded structure was currupt and failed to be parsed
invalid_file_tag28The fast resume file was missing or had an invalid file version +tag
missing_info_hash29The fast resume file was missing or had an invalid info-hash
mismatching_info_hash30The info-hash did not match the torrent
invalid_hostname31The URL contained an invalid hostname
invalid_port32The URL had an invalid port
port_blocked33The port is blocked by the port-filter, and prevented the +connection
expected_close_bracket_in_address34The IPv6 address was expected to end with ']'
destructing_torrent35The torrent is being destructed, preventing the operation to +succeed
timed_out36The connection timed out
upload_upload_connection37The peer is upload only, and we are upload only. There's no point +in keeping the connection
uninteresting_upload_peer38The peer is upload only, and we're not interested in it. There's +no point in keeping the connection
invalid_info_hash39The peer sent an unknown info-hash
torrent_paused40The torrent is paused, preventing the operation from succeeding
invalid_have41The peer sent an invalid have message, either wrong size or +referring to a piece that doesn't exist in the torrent
invalid_bitfield_size42The bitfield message had the incorrect size
too_many_requests_when_choked43The peer kept requesting pieces after it was choked, possible +abuse attempt.
invalid_piece44The peer sent a piece message that does not correspond to a +piece request sent by the client
no_memory45memory allocation failed
torrent_aborted46The torrent is aborted, preventing the operation to succeed
self_connection47The peer is a connection to ourself, no point in keeping it
invalid_piece_size48The peer sent a piece message with invalid size, either negative +or greater than one block
timed_out_no_interest49The peer has not been interesting or interested in us for too +long, no point in keeping it around
timed_out_inactivity50The peer has not said anything in a long time, possibly dead
timed_out_no_handshake51The peer did not send a handshake within a reasonable amount of +time, it might not be a bittorrent peer
timed_out_no_request52The peer has been unchoked for too long without requesting any +data. It might be lying about its interest in us
invalid_choke53The peer sent an invalid choke message
invalid_unchoke54The peer send an invalid unchoke message
invalid_interested55The peer sent an invalid interested message
invalid_not_interested56The peer sent an invalid not-interested message
invalid_request57The peer sent an invalid piece request message
invalid_hash_list58The peer sent an invalid hash-list message (this is part of the +merkle-torrent extension)
invalid_hash_piece59The peer sent an invalid hash-piece message (this is part of the +merkle-torrent extension)
invalid_cancel60The peer sent an invalid cancel message
invalid_dht_port61The peer sent an invalid DHT port-message
invalid_suggest62The peer sent an invalid suggest piece-message
invalid_have_all63The peer sent an invalid have all-message
invalid_have_none64The peer sent an invalid have none-message
invalid_reject65The peer sent an invalid reject message
invalid_allow_fast66The peer sent an invalid allow fast-message
invalid_extended67The peer sent an invalid extesion message ID
invalid_message68The peer sent an invalid message ID
sync_hash_not_found69The synchronization hash was not found in the encrypted handshake
invalid_encryption_constant70The encryption constant in the handshake is invalid
no_plaintext_mode71The peer does not support plaintext, which is the selected mode
no_rc4_mode72The peer does not support rc4, which is the selected mode
unsupported_encryption_mode73The peer does not support any of the encryption modes that the +client supports
unsupported_encryption_mode_selected74The peer selected an encryption mode that the client did not +advertise and does not support
invalid_pad_size75The pad size used in the encryption handshake is of invalid size
invalid_encrypt_handshake76The encryption handshake is invalid
no_incoming_encrypted77The client is set to not support incoming encrypted connections +and this is an encrypted connection
no_incoming_regular78The client is set to not support incoming regular bittorrent +connections, and this is a regular connection
duplicate_peer_id79The client is already connected to this peer-ID
torrent_removed80Torrent was removed
packet_too_large81The packet size exceeded the upper sanity check-limit
reserved82 
http_error83The web server responded with an error
missing_location84The web server response is missing a location header
invalid_redirection85The web seed redirected to a path that no longer matches the +.torrent directory structure
redirecting86The connection was closed becaused it redirected to a different +URL
invalid_range87The HTTP range header is invalid
no_content_length88The HTTP response did not have a content length
banned_by_ip_filter89The IP is blocked by the IP filter
too_many_connections90At the connection limit
peer_banned91The peer is marked as banned
stopping_torrent92The torrent is stopping, causing the operation to fail
too_many_corrupt_pieces93The peer has sent too many corrupt pieces and is banned
torrent_not_ready94The torrent is not ready to receive peers
peer_not_constructed95The peer is not completely constructed yet
session_closing96The session is closing, causing the operation to fail
optimistic_disconnect97The peer was disconnected in order to leave room for a +potentially better peer
torrent_finished98The torrent is finished
no_router99No UPnP router found
metadata_too_large100The metadata message says the metadata exceeds the limit
invalid_metadata_request101The peer sent an invalid metadata request message
invalid_metadata_size102The peer advertised an invalid metadata size
invalid_metadata_offset103The peer sent a message with an invalid metadata offset
invalid_metadata_message104The peer sent an invalid metadata message
pex_message_too_large105The peer sent a peer exchange message that was too large
invalid_pex_message106The peer sent an invalid peer exchange message
invalid_lt_tracker_message107The peer sent an invalid tracker exchange message
too_frequent_pex108The peer sent an pex messages too often. This is a possible +attempt of and attack
no_metadata109The operation failed because it requires the torrent to have +the metadata (.torrent file) and it doesn't have it yet. +This happens for magnet links before they have downloaded the +metadata, and also torrents added by URL.
invalid_dont_have110The peer sent an invalid dont_have message. The dont have +message is an extension to allow peers to advertise that the +no longer has a piece they previously had.
requires_ssl_connection111The peer tried to connect to an SSL torrent without connecting +over SSL.
invalid_ssl_cert112The peer tried to connect to a torrent with a certificate +for a different torrent.
unsupported_protocol_version120The NAT-PMP router responded with an unsupported protocol version
natpmp_not_authorized121You are not authorized to map ports on this NAT-PMP router
network_failure122The NAT-PMP router failed because of a network failure
no_resources123The NAT-PMP router failed because of lack of resources
unsupported_opcode124The NAT-PMP router failed because an unsupported opcode was sent
missing_file_sizes130The resume data file is missing the 'file sizes' entry
no_files_in_resume_data131The resume data file 'file sizes' entry is empty
missing_pieces132The resume data file is missing the 'pieces' and 'slots' entry
mismatching_number_of_files133The number of files in the resume data does not match the number +of files in the torrent
mismatching_file_size134One of the files on disk has a different size than in the fast +resume file
mismatching_file_timestamp135One of the files on disk has a different timestamp than in the +fast resume file
not_a_dictionary136The resume data file is not a dictionary
invalid_blocks_per_piece137The 'blocks per piece' entry is invalid in the resume data file
missing_slots138The resume file is missing the 'slots' entry, which is required +for torrents with compact allocation
too_many_slots139The resume file contains more slots than the torrent
invalid_slot_list140The 'slot' entry is invalid in the resume data
invalid_piece_index141One index in the 'slot' list is invalid
pieces_need_reorder142The pieces on disk needs to be re-ordered for the specified +allocation mode. This happens if you specify sparse allocation +and the files on disk are using compact storage. The pieces needs +to be moved to their right position
http_parse_error150The HTTP header was not correctly formatted
http_missing_location151The HTTP response was in the 300-399 range but lacked a location +header
http_failed_decompress152The HTTP response was encoded with gzip or deflate but +decompressing it failed
no_i2p_router160The URL specified an i2p address, but no i2p router is configured
scrape_not_available170The tracker URL doesn't support transforming it into a scrape +URL. i.e. it doesn't contain "announce.
invalid_tracker_response171invalid tracker response
invalid_peer_dict172invalid peer dictionary entry. Not a dictionary
tracker_failure173tracker sent a failure message
invalid_files_entry174missing or invalid 'files' entry
invalid_hash_entry175missing or invalid 'hash' entry
invalid_peers_entry176missing or invalid 'peers' and 'peers6' entry
invalid_tracker_response_length177udp tracker response packet has invalid size
invalid_tracker_transaction_id178invalid transaction id in udp tracker response
invalid_tracker_action179invalid action field in udp tracker response
error_code_max180the number of error codes
+
+
+

enum http_errors

+

Declared in "libtorrent/error_code.hpp"

+ +++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
namevaluedescription
cont100 
ok200 
created201 
accepted202 
no_content204 
multiple_choices300 
moved_permanently301 
moved_temporarily302 
not_modified304 
bad_request400 
unauthorized401 
forbidden403 
not_found404 
internal_server_error500 
not_implemented501 
bad_gateway502 
service_unavailable503 
+
+
+

enum i2p_error_code

+

Declared in "libtorrent/i2p_stream.hpp"

+ +++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
namevaluedescription
no_error0 
parse_failed1 
cant_reach_peer2 
i2p_error3 
invalid_key4 
invalid_id5 
timeout6 
key_not_found7 
duplicated_id8 
num_errors9 
+
+
+

enum socks_error_code

+

Declared in "libtorrent/socks5_stream.hpp"

+ +++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
namevaluedescription
no_error0 
unsupported_version1 
unsupported_authentication_method2 
unsupported_authentication_version3 
authentication_error4 
username_required5 
general_failure6 
command_not_supported7 
no_identd8 
identd_error9 
num_errors10 
+
+
+

enum error_code_enum

+

Declared in "libtorrent/upnp.hpp"

+ +++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
namevaluedescription
no_error0No error
invalid_argument402One of the arguments in the request is invalid
action_failed501The request failed
value_not_in_array714The specified value does not exist in the array
source_ip_cannot_be_wildcarded715The source IP address cannot be wild-carded, but +must be fully specified
external_port_cannot_be_wildcarded716The external port cannot be wildcarded, but must +be specified
port_mapping_conflict718The port mapping entry specified conflicts with a +mapping assigned previously to another client
internal_port_must_match_external724Internal and external port value must be the same
only_permanent_leases_supported725The NAT implementation only supports permanent +lease times on port mappings
remote_host_must_be_wildcard726RemoteHost must be a wildcard and cannot be a +specific IP addres or DNS name
external_port_must_be_wildcard727ExternalPort must be a wildcard and cannot be a +specific port
+
+
+
+ +
+ + +
+ + diff --git a/docs/reference-Filter.html b/docs/reference-Filter.html new file mode 100644 index 000000000..12f8296f7 --- /dev/null +++ b/docs/reference-Filter.html @@ -0,0 +1,222 @@ + + + + + + +Filter + + + + + + + + +
+
+
+ +
+ +
+

Filter

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

Table of contents

+ +
+
+

ip_filter

+

Declared in "libtorrent/ip_filter.hpp"

+

The ip_filter class is a set of rules that uniquely categorizes all +ip addresses as allowed or disallowed. The default constructor creates +a single rule that allows all addresses (0.0.0.0 - 255.255.255.255 for +the IPv4 range, and the equivalent range covering all addresses for the +IPv6 range).

+

A default constructed ip_filter does not filter any address.

+
+struct ip_filter
+{
+   void add_rule (address first, address last, int flags);
+   int access (address const& addr) const;
+   filter_tuple_t export_filter () const;
+
+   enum access_flags
+   {
+      blocked,
+   };
+};
+
+
+

add_rule()

+
+void add_rule (address first, address last, int flags);
+
+

Adds a rule to the filter. first and last defines a range of +ip addresses that will be marked with the given flags. The flags +can currently be 0, which means allowed, or ip_filter::blocked, which +means disallowed.

+

precondition: +first.is_v4() == last.is_v4() && first.is_v6() == last.is_v6()

+

postcondition: +access(x) == flags for every x in the range [first, last]

+

This means that in a case of overlapping ranges, the last one applied takes +precedence.

+
+
+

access()

+
+int access (address const& addr) const;
+
+

Returns the access permissions for the given address (addr). The permission +can currently be 0 or ip_filter::blocked. The complexity of this operation +is O(log n), where n is the minimum number of non-overlapping ranges to describe +the current filter.

+
+
+

export_filter()

+
+filter_tuple_t export_filter () const;
+
+

This function will return the current state of the filter in the minimum number of +ranges possible. They are sorted from ranges in low addresses to high addresses. Each +entry in the returned vector is a range with the access control specified in its +flags field.

+

The return value is a tuple containing two range-lists. One for IPv4 addresses +and one for IPv6 addresses.

+
+
+

enum access_flags

+

Declared in "libtorrent/ip_filter.hpp"

+ +++++ + + + + + + + + + + + + +
namevaluedescription
blocked1indicates that IPs in this range should not be connected +to nor accepted as incoming connections
+
+
+
+

port_filter

+

Declared in "libtorrent/ip_filter.hpp"

+

the port filter maps non-overlapping port ranges to flags. This +is primarily used to indicate whether a range of ports should +be connected to or not. The default is to have the full port +range (0-65535) set to flag 0.

+
+class port_filter
+{
+   void add_rule (boost::uint16_t first, boost::uint16_t last, int flags);
+   int access (boost::uint16_t port) const;
+
+   enum access_flags
+   {
+      blocked,
+   };
+};
+
+
+

add_rule()

+
+void add_rule (boost::uint16_t first, boost::uint16_t last, int flags);
+
+

set the flags for the specified port range (first, last) to +flags overwriting any existing rule for those ports. The range +is inclusive, i.e. the port last also has the flag set on it.

+
+
+

access()

+
+int access (boost::uint16_t port) const;
+
+

test the specified port (port) for whether it is blocked +or not. The returned value is the flags set for this port. +see acces_flags.

+
+
+

enum access_flags

+

Declared in "libtorrent/ip_filter.hpp"

+ +++++ + + + + + + + + + + + + +
namevaluedescription
blocked1this flag indicates that destination ports in the +range should not be connected to
+
+
+
+ +
+ + +
+ + diff --git a/docs/reference-Plugins.html b/docs/reference-Plugins.html new file mode 100644 index 000000000..54815373a --- /dev/null +++ b/docs/reference-Plugins.html @@ -0,0 +1,603 @@ + + + + + + + + + + + + + + +
+
+
+ +
+ +
+ + +
+

Plugins

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

Table of contents

+ +
+

libtorrent has a plugin interface for implementing extensions to the protocol. +These can be general extensions for transferring metadata or peer exchange +extensions, or it could be used to provide a way to customize the protocol +to fit a particular (closed) network.

+

In short, the plugin interface makes it possible to:

+
    +
  • register extension messages (sent in the extension handshake), see +extensions.
  • +
  • add data and parse data from the extension handshake.
  • +
  • send extension messages and standard bittorrent messages.
  • +
  • override or block the handling of standard bittorrent messages.
  • +
  • save and restore state via the session state
  • +
  • see all alerts that are posted
  • +
+
+

a word of caution

+

Writing your own plugin is a very easy way to introduce serious bugs such as +dead locks and race conditions. Since a plugin has access to internal +structures it is also quite easy to sabotage libtorrent's operation.

+

All the callbacks in this interface are called with the main libtorrent thread +mutex locked. And they are always called from the libtorrent network thread. In +case portions of your plugin are called from other threads, typically the main +thread, you cannot use any of the member functions on the internal structures +in libtorrent, since those require the mutex to be locked. Futhermore, you would +also need to have a mutex on your own shared data within the plugin, to make +sure it is not accessed at the same time from the libtorrent thread (through a +callback). See boost thread's mutex. If you need to send out a message from +another thread, it is advised to use an internal queue, and do the actual +sending in tick().

+

Since the plugin interface gives you easy access to internal structures, it +is not supported as a stable API. Plugins should be considered spcific to a +specific version of libtorrent. Although, in practice the internals mostly +don't change that dramatically.

+
+
+
+

plugin-interface

+

The plugin interface consists of three base classes that the plugin may +implement. These are called plugin, torrent_plugin and peer_plugin. +They are found in the <libtorrent/extensions.hpp> header.

+

These plugins are instantiated for each session, torrent and possibly each peer, +respectively.

+

For plugins that only need per torrent state, it is enough to only implement +torrent_plugin and pass a constructor function or function object to +session::add_extension() or torrent_handle::add_extension() (if the +torrent has already been started and you want to hook in the extension at +run-time).

+

The signature of the function is:

+
+boost::shared_ptr<torrent_plugin> (*)(torrent*, void*);
+
+

The first argument is the internal torrent object, the second argument +is the userdata passed to session::add_torrent() or +torrent_handle::add_extension().

+

The function should return a boost::shared_ptr<torrent_plugin> which +may or may not be 0. If it is a null pointer, the extension is simply ignored +for this torrent. If it is a valid pointer (to a class inheriting +torrent_plugin), it will be associated with this torrent and callbacks +will be made on torrent events.

+

For more elaborate plugins which require session wide state, you would +implement plugin, construct an object (in a boost::shared_ptr) and pass +it in to session::add_extension().

+
+
+

custom alerts

+

Since plugins are running within internal libtorrent threads, one convenient +way to communicate with the client is to post custom alerts.

+

The expected interface of any alert, apart from deriving from the alert +base class, looks like this:

+
+const static int alert_type = <unique alert ID>;
+virtual int type() const { return alert_type; }
+
+virtual std::string message() const;
+
+virtual std::auto_ptr<alert> clone() const
+{ return std::auto_ptr<alert>(new name(*this)); }
+
+const static int static_category = <bitmask of alert::category_t flags>;
+virtual int category() const { return static_category; }
+
+virtual char const* what() const { return <string literal of the name of this alert>; }
+
+

The alert_type is used for the type-checking in alert_cast. It must +not collide with any other alert. The built-in alerts in libtorrent will +not use alert type IDs greater than user_alert_id. When defining your +own alert, make sure it's greater than this constant.

+

type() is the run-time equivalence of the alert_type.

+

The message() virtual function is expected to construct a useful +string representation of the alert and the event or data it represents. +Something convenient to put in a log file for instance.

+

clone() is used internally to copy alerts. The suggested implementation +of simply allocating a new instance as a copy of *this is all that's +expected.

+

The static category is required for checking wether or not the category +for a specific alert is enabled or not, without instantiating the alert. +The category virtual function is the run-time equivalence.

+

The what() virtual function may simply be a string literal of the class +name of your alert.

+

For more information, see the alert section.

+
+

plugin

+

Declared in "libtorrent/extensions.hpp"

+

this is the base class for a session plugin. One primary feature +is that it is notified of all torrents that are added to the session, +and can add its own torrent_plugins.

+
+struct plugin
+{
+   virtual boost::shared_ptr<torrent_plugin> new_torrent (torrent*, void*);
+   virtual void added (boost::weak_ptr<aux::session_impl>);
+   virtual void on_alert (alert const*);
+   virtual void on_tick ();
+   virtual void save_state (entry&) const;
+   virtual void load_state (lazy_entry const&);
+};
+
+
+

new_torrent()

+
+virtual boost::shared_ptr<torrent_plugin> new_torrent (torrent*, void*);
+
+

this is called by the session every time a new torrent is added. +The torrent* points to the internal torrent object created +for the new torrent. The void* is the userdata pointer as +passed in via add_torrent_params.

+

If the plugin returns a torrent_plugin instance, it will be added +to the new torrent. Otherwise, return an empty shared_ptr to a +torrent_plugin (the default).

+
+
+

added()

+
+virtual void added (boost::weak_ptr<aux::session_impl>);
+
+

called when plugin is added to a session

+
+
+

on_alert()

+
+virtual void on_alert (alert const*);
+
+

called when an alert is posted +alerts that are filtered are not +posted

+
+
+

on_tick()

+
+virtual void on_tick ();
+
+

called once per second

+
+
+

save_state()

+
+virtual void save_state (entry&) const;
+
+

called when saving settings state

+
+
+

load_state()

+
+virtual void load_state (lazy_entry const&);
+
+

called when loading settings state

+
+
+
+

torrent_plugin

+

Declared in "libtorrent/extensions.hpp"

+

Torrent plugins are associated with a single torrent and have a number +of functions called at certain events. Many of its functions have the +ability to change or override the default libtorrent behavior.

+
+struct torrent_plugin
+{
+   virtual boost::shared_ptr<peer_plugin> new_connection (peer_connection*);
+   virtual void on_piece_pass (int /index/);
+   virtual void on_piece_failed (int /index/);
+   virtual void tick ();
+   virtual bool on_resume ();
+   virtual bool on_pause ();
+   virtual void on_files_checked ();
+   virtual void on_state (int /s/);
+   virtual void on_add_peer (tcp::endpoint const&,
+      int /src/, int /flags/);
+};
+
+
+

new_connection()

+
+virtual boost::shared_ptr<peer_plugin> new_connection (peer_connection*);
+
+

This function is called each time a new peer is connected to the torrent. You +may choose to ignore this by just returning a default constructed +shared_ptr (in which case you don't need to override this member +function).

+

If you need an extension to the peer connection (which most plugins do) you +are supposed to return an instance of your peer_plugin class. Which in +turn will have its hook functions called on event specific to that peer.

+

The peer_connection will be valid as long as the shared_ptr is being +held by the torrent object. So, it is generally a good idea to not keep a +shared_ptr to your own peer_plugin. If you want to keep references to it, +use weak_ptr.

+

If this function throws an exception, the connection will be closed.

+ +
+
+

on_piece_failed() on_piece_pass()

+
+virtual void on_piece_pass (int /index/);
+virtual void on_piece_failed (int /index/);
+
+

These hooks are called when a piece passes the hash check or fails the hash +check, respectively. The index is the piece index that was downloaded. +It is possible to access the list of peers that participated in sending the +piece through the torrent and the piece_picker.

+
+
+

tick()

+
+virtual void tick ();
+
+

This hook is called approximately once per second. It is a way of making it +easy for plugins to do timed events, for sending messages or whatever.

+ +
+
+

on_resume() on_pause()

+
+virtual bool on_resume ();
+virtual bool on_pause ();
+
+

These hooks are called when the torrent is paused and unpaused respectively. +The return value indicates if the event was handled. A return value of +true indicates that it was handled, and no other plugin after this one +will have this hook function called, and the standard handler will also not be +invoked. So, returning true effectively overrides the standard behavior of +pause or unpause.

+

Note that if you call pause() or resume() on the torrent from your +handler it will recurse back into your handler, so in order to invoke the +standard handler, you have to keep your own state on whether you want standard +behavior or overridden behavior.

+
+
+

on_files_checked()

+
+virtual void on_files_checked ();
+
+

This function is called when the initial files of the torrent have been +checked. If there are no files to check, this function is called immediately.

+

i.e. This function is always called when the torrent is in a state where it +can start downloading.

+
+
+

on_state()

+
+virtual void on_state (int /s/);
+
+

called when the torrent changes state +the state is one of torrent_status::state_t +enum members

+
+
+

on_add_peer()

+
+virtual void on_add_peer (tcp::endpoint const&,
+      int /src/, int /flags/);
+
+

called every time a new peer is added to the peer list. +This is before the peer is connected to. For flags, see +torrent_plugin::flags_t. The source argument refers to +the source where we learned about this peer from. It's a +bitmask, because many sources may have told us about the same +peer. For peer source flags, see peer_info::peer_source_flags.

+
+
+
+

peer_plugin

+

Declared in "libtorrent/extensions.hpp"

+

peer plugins are associated with a specific peer. A peer could be +both a regular bittorrent peer (bt_peer_connection) or one of the +web seed connections (web_peer_connection or http_seed_connection). +In order to only attach to certain peers, make your +torrent_plugin::new_connection only return a plugin for certain peer +connection types

+
+struct peer_plugin
+{
+   virtual char const* type () const;
+   virtual void add_handshake (entry&);
+   virtual void on_disconnect (error_code const& ec);
+   virtual void on_connected ();
+   virtual bool on_handshake (char const* /reserved_bits/);
+   virtual bool on_extension_handshake (lazy_entry const&);
+   virtual bool on_have (int /index/);
+   virtual bool on_bitfield (bitfield const& /bitfield/);
+   virtual bool on_have_all ();
+   virtual bool on_reject (peer_request const&);
+   virtual bool on_request (peer_request const&);
+   virtual bool on_unchoke ();
+   virtual bool on_interested ();
+   virtual bool on_allowed_fast (int /index/);
+   virtual bool on_have_none ();
+   virtual bool on_choke ();
+   virtual bool on_not_interested ();
+   virtual bool on_piece (peer_request const& /piece/
+      , disk_buffer_holder& /data/);
+   virtual bool on_suggest (int /index/);
+   virtual bool on_cancel (peer_request const&);
+   virtual bool on_dont_have (int /index/);
+   virtual bool can_disconnect (error_code const& ec);
+   virtual bool on_extended (int /length/, int /msg/,
+      buffer::const_interval /body/);
+   virtual bool on_unknown_message (int /length/, int /msg/,
+      buffer::const_interval /body/);
+   virtual void on_piece_pass (int /index/);
+   virtual void on_piece_failed (int /index/);
+   virtual void tick ();
+   virtual bool write_request (peer_request const&);
+};
+
+
+

type()

+
+virtual char const* type () const;
+
+

This function is expected to return the name of +the plugin.

+
+
+

add_handshake()

+
+virtual void add_handshake (entry&);
+
+

can add entries to the extension handshake +this is not called for web seeds

+
+
+

on_disconnect()

+
+virtual void on_disconnect (error_code const& ec);
+
+

called when the peer is being disconnected.

+
+
+

on_connected()

+
+virtual void on_connected ();
+
+

called when the peer is successfully connected. Note that +incoming connections will have been connected by the time +the peer plugin is attached to it, and won't have this hook +called.

+
+
+

on_handshake()

+
+virtual bool on_handshake (char const* /reserved_bits/);
+
+

this is called when the initial BT handshake is received. Returning false +means that the other end doesn't support this extension and will remove +it from the list of plugins. +this is not called for web seeds

+
+
+

on_extension_handshake()

+
+virtual bool on_extension_handshake (lazy_entry const&);
+
+

called when the extension handshake from the other end is received +if this returns false, it means that this extension isn't +supported by this peer. It will result in this peer_plugin +being removed from the peer_connection and destructed. +this is not called for web seeds

+ + + + + + + + + + + + + + +
+
+

on_bitfield() on_have_none() on_suggest() on_unchoke() on_cancel() on_have() on_choke() on_piece() on_request() on_reject() on_not_interested() on_interested() on_allowed_fast() on_have_all() on_dont_have()

+
+virtual bool on_have (int /index/);
+virtual bool on_bitfield (bitfield const& /bitfield/);
+virtual bool on_have_all ();
+virtual bool on_reject (peer_request const&);
+virtual bool on_request (peer_request const&);
+virtual bool on_unchoke ();
+virtual bool on_interested ();
+virtual bool on_allowed_fast (int /index/);
+virtual bool on_have_none ();
+virtual bool on_choke ();
+virtual bool on_not_interested ();
+virtual bool on_piece (peer_request const& /piece/
+      , disk_buffer_holder& /data/);
+virtual bool on_suggest (int /index/);
+virtual bool on_cancel (peer_request const&);
+virtual bool on_dont_have (int /index/);
+
+

returning true from any of the message handlers +indicates that the plugin has handeled the message. +it will break the plugin chain traversing and not let +anyone else handle the message, including the default +handler.

+
+
+

can_disconnect()

+
+virtual bool can_disconnect (error_code const& ec);
+
+

called when libtorrent think this peer should be disconnected. +if the plugin returns false, the peer will not be disconnected.

+
+
+

on_extended()

+
+virtual bool on_extended (int /length/, int /msg/,
+      buffer::const_interval /body/);
+
+

called when an extended message is received. If returning true, +the message is not processed by any other plugin and if false +is returned the next plugin in the chain will receive it to +be able to handle it +this is not called for web seeds

+
+
+

on_unknown_message()

+
+virtual bool on_unknown_message (int /length/, int /msg/,
+      buffer::const_interval /body/);
+
+

this is not called for web seeds

+ +
+
+

on_piece_failed() on_piece_pass()

+
+virtual void on_piece_pass (int /index/);
+virtual void on_piece_failed (int /index/);
+
+

called when a piece that this peer participated in either +fails or passes the hash_check

+
+
+

tick()

+
+virtual void tick ();
+
+

called aproximately once every second

+
+
+

write_request()

+
+virtual bool write_request (peer_request const&);
+
+

called each time a request message is to be sent. If true +is returned, the original request message won't be sent and +no other plugin will have this function called.

+
+
+

create_lt_trackers_plugin()

+

Declared in "libtorrent/extensions/lt_trackers.hpp"

+
+boost::shared_ptr<torrent_plugin> create_lt_trackers_plugin (torrent*, void*);
+
+

constructor function for the trackers exchange extension. This can +either be passed in the add_torrent_params::extensions field, or +via torrent_handle::add_extension().

+
+
+

create_smart_ban_plugin()

+

Declared in "libtorrent/extensions/smart_ban.hpp"

+
+boost::shared_ptr<torrent_plugin> create_smart_ban_plugin (torrent*, void*);
+
+

constructor function for the smart ban extension. The extension keeps +track of the data peers have sent us for failing pieces and once the +piece completes and passes the hash check bans the peers that turned +out to have sent corrupt data. +This function can either be passed in the add_torrent_params::extensions +field, or via torrent_handle::add_extension().

+
+
+

create_ut_metadata_plugin()

+

Declared in "libtorrent/extensions/ut_metadata.hpp"

+
+boost::shared_ptr<torrent_plugin> create_ut_metadata_plugin (torrent*, void*);
+
+

constructor function for the ut_metadata extension. The ut_metadata +extension allows peers to request the .torrent file (or more +specifically the 'info'-dictionary of the .torrent file) from each +other. This is the main building block in making magnet links work. +This extension is enabled by default unless explicitly disabled in +the session constructor.

+

This can either be passed in the add_torrent_params::extensions field, or +via torrent_handle::add_extension().

+
+
+

create_ut_pex_plugin()

+

Declared in "libtorrent/extensions/ut_pex.hpp"

+
+boost::shared_ptr<torrent_plugin> create_ut_pex_plugin (torrent*, void*);
+
+

constructor function for the ut_pex extension. The ut_pex +extension allows peers to gossip about their connections, allowing +the swarm stay well connected and peers aware of more peers in the +swarm. This extension is enabled by default unless explicitly disabled in +the session constructor.

+

This can either be passed in the add_torrent_params::extensions field, or +via torrent_handle::add_extension().

+
+
+
+
+ +
+ + +
+ + diff --git a/docs/reference-RSS.html b/docs/reference-RSS.html new file mode 100644 index 000000000..d3d57f603 --- /dev/null +++ b/docs/reference-RSS.html @@ -0,0 +1,309 @@ + + + + + + +RSS + + + + + + + + +
+
+
+ +
+ +
+

RSS

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

Table of contents

+ +
+
+

feed_item

+

Declared in "libtorrent/rss.hpp"

+

represents one item from an RSS feed. Specifically +a feed of torrents.

+
+struct feed_item
+{
+   feed_item ();
+   ~feed_item ();
+
+   std::string url;
+   std::string uuid;
+   std::string title;
+   std::string description;
+   std::string comment;
+   std::string category;
+   size_type size;
+   torrent_handle handle;
+   sha1_hash info_hash;
+};
+
+ + + + + +
+
url uuid title description comment category
+
these are self explanatory and may be empty if the feed does not specify +those fields.
+
+
+
size
+
the total size of the content the torrent refers to, or -1 +if no size was specified by the feed.
+
+
+
handle
+
the handle to the torrent, if the session is already downloading +this torrent.
+
+
+
info_hash
+
the info-hash of the torrent, or cleared (i.e. all zeroes) if +the feed does not specify the info-hash.
+
+
+
+

feed_settings

+

Declared in "libtorrent/rss.hpp"

+

the feed_settings object is all the information +and configuration for a specific feed. All of +these settings can be changed by the user +after adding the feed

+
+struct feed_settings
+{
+   feed_settings ();
+
+   std::string url;
+   bool auto_download;
+   bool auto_map_handles;
+   int default_ttl;
+   add_torrent_params add_args;
+};
+
+
+
auto_download
+
By default auto_download is true, which means all torrents in +the feed will be downloaded. Set this to false in order to manually +add torrents to the session. You may react to the rss_alert when +a feed has been updated to poll it for the new items in the feed +when adding torrents manually. When torrents are added automatically, +an add_torrent_alert is posted which includes the torrent handle +as well as the error code if it failed to be added. You may also call +session::get_torrents() to get the handles to the new torrents.
+
+
+
auto_map_handles
+
auto_map_handles defaults to true and determines whether or +not to set the handle field in the feed_item, returned +as the feed status. If auto-download is enabled, this setting +is ignored. If auto-download is not set, setting this to false +will save one pass through all the feed items trying to find +corresponding torrents in the session.
+
+
+
default_ttl
+
The default_ttl is the default interval for refreshing a feed. +This may be overridden by the feed itself (by specifying the <ttl> +tag) and defaults to 30 minutes. The field specifies the number of +minutes between refreshes.
+
+
+
add_args
+
If torrents are added automatically, you may want to set the +add_args to appropriate values for download directory etc. +This object is used as a template for adding torrents from feeds, +but some torrent specific fields will be overridden by the +individual torrent being added. For more information on the +add_torrent_params, see async_add_torrent() and add_torrent().
+
+
+
+

feed_status

+

Declared in "libtorrent/rss.hpp"

+

holds information about the status of an RSS feed. Retrieved by +calling get_feed_status() on feed_handle.

+
+struct feed_status
+{
+   feed_status ();
+
+   std::string url;
+   std::string title;
+   std::string description;
+   time_t last_update;
+   int next_update;
+   bool updating;
+   std::vector<feed_item> items;
+   error_code error;
+   int ttl;
+};
+
+
+
url
+
the URL of the feed.
+
+
+
title
+
the name of the feed (as specified by the feed itself). This +may be empty if we have not recevied a response from the RSS server yet, +or if the feed does not specify a title.
+
+
+
description
+
the feed description (as specified by the feed itself). +This may be empty if we have not received a response from the RSS server +yet, or if the feed does not specify a description.
+
+
+
last_update
+
the posix time of the last successful response from the feed.
+
+
+
next_update
+
the number of seconds, from now, when the feed will be +updated again.
+
+
+
updating
+
true if the feed is currently being updated (i.e. waiting for +DNS resolution, connecting to the server or waiting for the response to the +HTTP request, or receiving the response).
+
+
+
items
+
a vector of all items that we have received from the feed. See +feed_item for more information.
+
+
+
error
+
set to the appropriate error code if the feed encountered an +error. See error_code for more info.
+
+
+
ttl
+
the current refresh time (in minutes). It's either the configured +default ttl, or the ttl specified by the feed.
+
+
+
+

feed_handle

+

Declared in "libtorrent/rss.hpp"

+

The feed_handle refers to a specific RSS feed that is watched by the session.

+
+struct feed_handle
+{
+   feed_handle ();
+   void update_feed ();
+   feed_status get_feed_status () const;
+   void set_settings (feed_settings const& s);
+   feed_settings settings () const;
+};
+
+
+

update_feed()

+
+void update_feed ();
+
+

Forces an update/refresh of the feed. Regular updates of the feed is managed +by libtorrent, be careful to not call this too frequently since it may +overload the RSS server.

+
+
+

get_feed_status()

+
+feed_status get_feed_status () const;
+
+

Queries the RSS feed for information, including all the items in the feed. +see feed_status.

+ +
+
+

settings() set_settings()

+
+void set_settings (feed_settings const& s);
+feed_settings settings () const;
+
+

Sets and gets settings for this feed. For more information on the +available settings, see add_feed().

+
+
+

add_feed_item()

+

Declared in "libtorrent/rss.hpp"

+
+torrent_handle add_feed_item (session& s, feed_item const& fi
+   , add_torrent_params const& p);
+torrent_handle add_feed_item (session& s, feed_item const& fi
+   , add_torrent_params const& p, error_code& ec);
+
+

given a feed_item f, add the torrent it refers to to session s.

+
+
+

new_feed()

+

Declared in "libtorrent/rss.hpp"

+
+boost::shared_ptr<feed> new_feed (aux::session_impl& ses, feed_settings const& sett);
+
+
+
+
+ +
+ + +
+ + diff --git a/docs/reference-Session.html b/docs/reference-Session.html index 4940049d1..32c2905f2 100644 --- a/docs/reference-Session.html +++ b/docs/reference-Session.html @@ -3,7 +3,7 @@ - + Session diff --git a/docs/reference-Settings.html b/docs/reference-Settings.html new file mode 100644 index 000000000..3ef8c3a76 --- /dev/null +++ b/docs/reference-Settings.html @@ -0,0 +1,1913 @@ + + + + + + +Settings + + + + + + + + +
+
+
+ +
+ +
+

Settings

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

Table of contents

+ +
+
+

proxy_settings

+

Declared in "libtorrent/session_settings.hpp"

+

The proxy_settings structs contains the information needed to +direct certain traffic to a proxy.

+
+struct proxy_settings
+{
+   proxy_settings ();
+
+   enum proxy_type
+   {
+      none,
+      socks4,
+      socks5,
+      socks5_pw,
+      http,
+      http_pw,
+      i2p_proxy,
+   };
+
+   std::string hostname;
+   std::string username;
+   std::string password;
+   boost::uint8_t type;
+   boost::uint16_t port;
+   bool proxy_hostnames;
+   bool proxy_peer_connections;
+};
+
+
+

enum proxy_type

+

Declared in "libtorrent/session_settings.hpp"

+ +++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
namevaluedescription
none0This is the default, no proxy server is used, all other fields +are ignored.
socks41The server is assumed to be a SOCKS4 server that +requires a username.
socks52The server is assumed to be a SOCKS5 server (RFC 1928) that +does not require any authentication. The username and password are ignored.
socks5_pw3The server is assumed to be a SOCKS5 server that supports +plain text username and password authentication (RFC 1929). The username +and password specified may be sent to the proxy if it requires.
http4The server is assumed to be an HTTP proxy. If the transport used +for the connection is non-HTTP, the server is assumed to support the +CONNECT method. i.e. for web seeds and HTTP trackers, a plain proxy will +suffice. The proxy is assumed to not require authorization. The username +and password will not be used.
http_pw5The server is assumed to be an HTTP proxy that requires +user authorization. The username and password will be sent to the proxy.
i2p_proxy6route through a i2p SAM proxy
+
+
hostname
+
the name or IP of the proxy server. port is the +port number the proxy listens to. If required, username and password +can be set to authenticate with the proxy.
+
+
+
type
+
tells libtorrent what kind of proxy server it is. See proxy_type +enum for options
+
+
+
port
+
the port the proxy server is running on
+
+
+
proxy_hostnames
+
defaults to true. It means that hostnames should be +attempted to be resolved through the proxy instead of using the local DNS +service. This is only supported by SOCKS5 and HTTP.
+
+
+
proxy_peer_connections
+
determines whether or not to excempt peer and +web seed connections from using the proxy. This defaults to true, i.e. peer +connections are proxied by default.
+
+
+
+
+

session_settings

+

Declared in "libtorrent/session_settings.hpp"

+

This holds most of the session-wide settings in libtorrent. Pass this +to session::set_settings() to change the settings, initialize it from +session::get_settings() to get the current settings.

+
+struct session_settings
+{
+   session_settings (std::string const& user_agent = "libtorrent/"
+      LIBTORRENT_VERSION);
+   ~session_settings ();
+
+   enum suggest_mode_t
+   {
+      no_piece_suggestions,
+      suggest_read_cache,
+   };
+
+   enum choking_algorithm_t
+   {
+      fixed_slots_choker,
+      auto_expand_choker,
+      rate_based_choker,
+      bittyrant_choker,
+   };
+
+   enum seed_choking_algorithm_t
+   {
+      round_robin,
+      fastest_upload,
+      anti_leech,
+   };
+
+   enum io_buffer_mode_t
+   {
+      enable_os_cache,
+      disable_os_cache_for_aligned_files,
+      disable_os_cache,
+   };
+
+   enum disk_cache_algo_t
+   {
+      lru,
+      largest_contiguous,
+      avoid_readback,
+   };
+
+   enum bandwidth_mixed_algo_t
+   {
+      prefer_tcp,
+      peer_proportional,
+   };
+
+   int version;
+   std::string user_agent;
+   int tracker_completion_timeout;
+   int tracker_receive_timeout;
+   int stop_tracker_timeout;
+   int tracker_maximum_response_length;
+   int piece_timeout;
+   int request_timeout;
+   int request_queue_time;
+   int max_allowed_in_request_queue;
+   int max_out_request_queue;
+   int whole_pieces_threshold;
+   int peer_timeout;
+   int urlseed_timeout;
+   int urlseed_pipeline_size;
+   int urlseed_wait_retry;
+   int file_pool_size;
+   bool allow_multiple_connections_per_ip;
+   int max_failcount;
+   int min_reconnect_time;
+   int peer_connect_timeout;
+   bool ignore_limits_on_local_network;
+   int connection_speed;
+   bool send_redundant_have;
+   bool lazy_bitfields;
+   int inactivity_timeout;
+   int unchoke_interval;
+   int optimistic_unchoke_interval;
+   std::string announce_ip;
+   int num_want;
+   int initial_picker_threshold;
+   int allowed_fast_set_size;
+   int suggest_mode;
+   int max_queued_disk_bytes;
+   int max_queued_disk_bytes_low_watermark;
+   int handshake_timeout;
+   bool use_dht_as_fallback;
+   bool free_torrent_hashes;
+   bool upnp_ignore_nonrouters;
+   int send_buffer_low_watermark;
+   int send_buffer_watermark;
+   int send_buffer_watermark_factor;
+   int choking_algorithm;
+   int seed_choking_algorithm;
+   bool use_parole_mode;
+   int cache_size;
+   int cache_buffer_chunk_size;
+   int cache_expiry;
+   bool use_read_cache;
+   bool explicit_read_cache;
+   int explicit_cache_interval;
+   int disk_io_write_mode;
+   int disk_io_read_mode;
+   bool coalesce_reads;
+   bool coalesce_writes;
+   std::pair<int, int> outgoing_ports;
+   char peer_tos;
+   int active_downloads;
+   int active_seeds;
+   int active_dht_limit;
+   int active_tracker_limit;
+   int active_lsd_limit;
+   int active_limit;
+   bool auto_manage_prefer_seeds;
+   bool dont_count_slow_torrents;
+   int auto_manage_interval;
+   float share_ratio_limit;
+   float seed_time_ratio_limit;
+   int seed_time_limit;
+   int peer_turnover_interval;
+   float peer_turnover;
+   float peer_turnover_cutoff;
+   bool close_redundant_connections;
+   int auto_scrape_interval;
+   int auto_scrape_min_interval;
+   int max_peerlist_size;
+   int max_paused_peerlist_size;
+   int min_announce_interval;
+   bool prioritize_partial_pieces;
+   int auto_manage_startup;
+   bool rate_limit_ip_overhead;
+   bool announce_to_all_trackers;
+   bool announce_to_all_tiers;
+   bool prefer_udp_trackers;
+   bool strict_super_seeding;
+   int seeding_piece_quota;
+   int max_sparse_regions;
+   bool lock_disk_cache;
+   int max_rejects;
+   int recv_socket_buffer_size;
+   int send_socket_buffer_size;
+   bool optimize_hashing_for_speed;
+   int file_checks_delay_per_block;
+   disk_cache_algo_t disk_cache_algorithm;
+   int read_cache_line_size;
+   int write_cache_line_size;
+   int optimistic_disk_retry;
+   bool disable_hash_checks;
+   bool allow_reordered_disk_operations;
+   bool allow_i2p_mixed;
+   int max_suggest_pieces;
+   bool drop_skipped_requests;
+   bool low_prio_disk;
+   int local_service_announce_interval;
+   int dht_announce_interval;
+   int udp_tracker_token_expiry;
+   bool volatile_read_cache;
+   bool guided_read_cache;
+   int default_cache_min_age;
+   int num_optimistic_unchoke_slots;
+   bool no_atime_storage;
+   int default_est_reciprocation_rate;
+   int increase_est_reciprocation_rate;
+   int decrease_est_reciprocation_rate;
+   bool incoming_starts_queued_torrents;
+   bool report_true_downloaded;
+   bool strict_end_game_mode;
+   bool broadcast_lsd;
+   bool enable_outgoing_utp;
+   bool enable_incoming_utp;
+   bool enable_outgoing_tcp;
+   bool enable_incoming_tcp;
+   int max_pex_peers;
+   bool ignore_resume_timestamps;
+   bool no_recheck_incomplete_resume;
+   bool anonymous_mode;
+   bool force_proxy;
+   int tick_interval;
+   bool report_web_seed_downloads;
+   int share_mode_target;
+   int upload_rate_limit;
+   int download_rate_limit;
+   int local_upload_rate_limit;
+   int local_download_rate_limit;
+   int dht_upload_rate_limit;
+   int unchoke_slots_limit;
+   int half_open_limit;
+   int connections_limit;
+   int connections_slack;
+   int utp_target_delay;
+   int utp_gain_factor;
+   int utp_min_timeout;
+   int utp_syn_resends;
+   int utp_fin_resends;
+   int utp_num_resends;
+   int utp_connect_timeout;
+   bool utp_dynamic_sock_buf;
+   int utp_loss_multiplier;
+   int mixed_mode_algorithm;
+   bool rate_limit_utp;
+   int listen_queue_size;
+   bool announce_double_nat;
+   int torrent_connect_boost;
+   bool seeding_outgoing_connections;
+   bool no_connect_privileged_ports;
+   int alert_queue_size;
+   int max_metadata_size;
+   bool smooth_connects;
+   bool always_send_user_agent;
+   bool apply_ip_filter_to_trackers;
+   int read_job_every;
+   bool use_disk_read_ahead;
+   bool lock_files;
+   int ssl_listen;
+   int tracker_backoff;
+   bool ban_web_seeds;
+   int max_http_recv_buffer_size;
+   bool support_share_mode;
+   bool support_merkle_torrents;
+   bool report_redundant_bytes;
+   std::string handshake_client_version;
+   bool use_disk_cache_pool;
+};
+
+
+

enum suggest_mode_t

+

Declared in "libtorrent/session_settings.hpp"

+ +++++ + + + + + + + + + + + + + + + + +
namevaluedescription
no_piece_suggestions0the default. will not send out suggest messages.
suggest_read_cache1send out suggest messages for the most +recent pieces that are in the read cache.
+
+
+

enum choking_algorithm_t

+

Declared in "libtorrent/session_settings.hpp"

+ +++++ + + + + + + + + + + + + + + + + + + + + + + + + +
namevaluedescription
fixed_slots_choker0the traditional choker with a fixed number of unchoke +slots, as specified by session::set_max_uploads()..
auto_expand_choker1opens at least the number of slots as specified by +session::set_max_uploads() but opens up more slots if the upload capacity +is not saturated. This unchoker will work just like the fixed_slot_choker +if there's no global upload rate limit set.
rate_based_choker2opens up unchoke slots based on the upload rate +achieved to peers. The more slots that are opened, the marginal upload +rate required to open up another slot increases.
bittyrant_choker3attempts to optimize download rate by finding the +reciprocation rate of each peer individually and prefers peers that gives +the highest return on investment. It still allocates all upload capacity, +but shuffles it around to the best peers first. For this choker to be +efficient, you need to set a global upload rate limit +session_settings::upload_rate_limit. For more information about this +choker, see the paper.
+
+
+

enum seed_choking_algorithm_t

+

Declared in "libtorrent/session_settings.hpp"

+ +++++ + + + + + + + + + + + + + + + + + + + + +
namevaluedescription
round_robin0round-robins the peers that are unchoked when seeding. This +distributes the upload bandwidht uniformly and fairly. It minimizes the ability +for a peer to download everything without redistributing it.
fastest_upload1unchokes the peers we can send to the fastest. This might be +a bit more reliable in utilizing all available capacity.
anti_leech2prioritizes peers who have just started or are just about to finish +the download. The intention is to force peers in the middle of the download to +trade with each other.
+
+
+

enum io_buffer_mode_t

+

Declared in "libtorrent/session_settings.hpp"

+ +++++ + + + + + + + + + + + + + + + + + + + + +
namevaluedescription
enable_os_cache0This is the default and files are opened normally, with the OS caching +reads and writes.
disable_os_cache_for_aligned_files1This will open files in unbuffered mode for files where every read and +write would be sector aligned. Using aligned disk offsets is a requirement +on some operating systems.
disable_os_cache2This opens all files in unbuffered mode (if allowed by the operating system). +Linux and Windows, for instance, require disk offsets to be sector aligned, +and in those cases, this option is the same as disable_os_caches_for_aligned_files.
+
+
+

enum disk_cache_algo_t

+

Declared in "libtorrent/session_settings.hpp"

+ +++++ + + + + + + + + + + + + + + + + + + + + +
namevaluedescription
lru0This +flushes the entire piece, in the write cache, that was least recently +written to.
largest_contiguous1will flush the largest +sequences of contiguous blocks from the write cache, regarless of the +piece's last use time.
avoid_readback2will prioritize +flushing blocks that will avoid having to read them back in to verify +the hash of the piece once it's done. This is especially useful for high +throughput setups, where reading from the disk is especially expensive.
+
+
+

enum bandwidth_mixed_algo_t

+

Declared in "libtorrent/session_settings.hpp"

+ +++++ + + + + + + + + + + + + + + + + +
namevaluedescription
prefer_tcp0disables the mixed mode bandwidth balancing
peer_proportional1does not throttle uTP, throttles TCP to the same proportion +of throughput as there are TCP connections
+
+
version
+
automatically set to the libtorrent version you're using +in order to be forward binary compatible. This field should not be changed.
+
+
+
user_agent
+
the client identification to the tracker. +The recommended format of this string is: +"ClientName/ClientVersion libtorrent/libtorrentVersion". +This name will not only be used when making HTTP requests, but also when +sending extended headers to peers that support that extension.
+
+
+
tracker_completion_timeout
+
the number of seconds the tracker +connection will wait from when it sent the request until it considers the +tracker to have timed-out. Default value is 60 seconds.
+
+
+
tracker_receive_timeout
+
the number of seconds to wait to receive +any data from the tracker. If no data is received for this number of +seconds, the tracker will be considered as having timed out. If a tracker +is down, this is the kind of timeout that will occur. The default value +is 20 seconds.
+
+
+
stop_tracker_timeout
+

the time to wait when sending a stopped message +before considering a tracker to have timed out. +this is usually shorter, to make the client quit +faster

+

This is given in seconds. Default is +10 seconds.

+
+
+
+
tracker_maximum_response_length
+
the maximum number of bytes in a +tracker response. If a response size passes this number it will be rejected +and the connection will be closed. On gzipped responses this size is measured +on the uncompressed data. So, if you get 20 bytes of gzip response that'll +expand to 2 megs, it will be interrupted before the entire response has been +uncompressed (given your limit is lower than 2 megs). Default limit is +1 megabyte.
+
+
+
piece_timeout
+
controls the number of seconds from a request is sent until +it times out if no piece response is returned.
+
+
+
request_timeout
+
the number of seconds one block (16kB) is expected +to be received within. If it's not, the block is +requested from a different peer
+
+
+
request_queue_time
+
the length of the request queue given in the number +of seconds it should take for the other end to send +all the pieces. i.e. the actual number of requests +depends on the download rate and this number.
+
+
+
max_allowed_in_request_queue
+
the number of outstanding block requests a peer is +allowed to queue up in the client. If a peer sends +more requests than this (before the first one has +been sent) the last request will be dropped. +the higher this is, the faster upload speeds the +client can get to a single peer.
+
+
+
max_out_request_queue
+
the maximum number of outstanding requests to +send to a peer. This limit takes precedence over +request_queue_time. +i.e. no matter the download speed, the number of outstanding requests will never +exceed this limit.
+
+
+
whole_pieces_threshold
+
if a whole piece can be downloaded in this number +of seconds, or less, the peer_connection will prefer +to request whole pieces at a time from this peer. +The benefit of this is to better utilize disk caches by +doing localized accesses and also to make it easier +to identify bad peers if a piece fails the hash check.
+
+
+
peer_timeout
+
the number of seconds to wait for any activity on +the peer wire before closing the connectiong due +to time out. +This defaults to 120 seconds, since that's what's specified +in the protocol specification. After half the time out, a keep alive message +is sent.
+
+
+
urlseed_timeout
+
same as peer_timeout, but only applies to url-seeds. +this is usually set lower, because web servers are +expected to be more reliable. +This value defaults to 20 seconds.
+
+
+
urlseed_pipeline_size
+
controls the pipelining with the web server. When +using persistent connections to HTTP 1.1 servers, the client is allowed to +send more requests before the first response is received. This number controls +the number of outstanding requests to use with url-seeds. Default is 5.
+
+
+
urlseed_wait_retry
+
time to wait until a new retry takes place
+
+
+
file_pool_size
+
sets the upper limit on the total number of files this +session will keep open. The reason why files are +left open at all is that some anti virus software +hooks on every file close, and scans the file for +viruses. deferring the closing of the files will +be the difference between a usable system and +a completely hogged down system. Most operating +systems also has a limit on the total number of +file descriptors a process may have open. It is +usually a good idea to find this limit and set the +number of connections and the number of files +limits so their sum is slightly below it.
+
+
+
allow_multiple_connections_per_ip
+
determines if connections from the +same IP address as existing connections should be rejected or not. Multiple +connections from the same IP address is not allowed by default, to prevent +abusive behavior by peers. It may be useful to allow such connections in +cases where simulations are run on the same machie, and all peers in a +swarm has the same IP address.
+
+
+
max_failcount
+
the maximum times we try to connect to a peer before +stop connecting again. If a peer succeeds, its failcounter is reset. If +a peer is retrieved from a peer source (other than DHT) the failcount is +decremented by one, allowing another try.
+
+
+
min_reconnect_time
+
the number of seconds to wait to reconnect to a peer. +this time is multiplied with the failcount.
+
+
+
peer_connect_timeout
+
the number of seconds to wait after a connection +attempt is initiated to a peer until it is considered as having timed out. +The default is 10 seconds. This setting is especially important in case +the number of half-open connections are limited, since stale half-open +connection may delay the connection of other peers considerably.
+
+
+
ignore_limits_on_local_network
+
if set to true, upload, download and unchoke limits +are ignored for peers on the local network.
+
+
+
connection_speed
+
the number of connection attempts that +are made per second. If a number < 0 is specified, it will default to +200 connections per second. If 0 is specified, it means don't make +outgoing connections at all.
+
+
+
send_redundant_have
+
if this is set to true, have messages will be sent +to peers that already have the piece. This is +typically not necessary, but it might be necessary +for collecting statistics in some cases. Default is false.
+
+
+
lazy_bitfields
+
prevents outgoing bitfields from being full. If the +client is seed, a few bits will be set to 0, and later filled in with +have-messages. This is an old attempt to prevent certain ISPs +from stopping people from seeding.
+
+
+
inactivity_timeout
+
if a peer is uninteresting and uninterested for longer +than this number of seconds, it will be disconnected. +default is 10 minutes
+
+
+
unchoke_interval
+
the number of seconds between chokes/unchokes. +On this interval, peers are re-evaluated for being choked/unchoked. This +is defined as 30 seconds in the protocol, and it should be significantly +longer than what it takes for TCP to ramp up to it's max rate.
+
+
+
optimistic_unchoke_interval
+
the number of seconds between +each optimistic unchoke. On this timer, the currently optimistically +unchoked peer will change.
+
+
+
announce_ip
+
the ip address passed along to trackers as the &ip= parameter. +If left as the default (an empty string), that parameter is omitted. +Most trackers ignore this argument. This is here for completeness +for edge-cases where it may be useful.
+
+
+
num_want
+
the number of peers we want from each tracker request. It defines +what is sent as the &num_want= parameter to the tracker. +Stopped messages always send num_want=0. This setting control what +to say in the case where we actually want peers.
+
+
+
initial_picker_threshold
+
specifies the number of pieces we need before we +switch to rarest first picking. This defaults to 4, which means the 4 first +pieces in any torrent are picked at random, the following pieces are picked +in rarest first order.
+
+
+
allowed_fast_set_size
+
the number of allowed pieces to send to choked peers +that supports the fast extensions
+
+
+
suggest_mode
+

this determines which pieces will be suggested to peers +suggest read cache will make libtorrent suggest pieces +that are fresh in the disk read cache, to potentially +lower disk access and increase the cache hit ratio

+

for options, see suggest_mode_t.

+
+
+
+
max_queued_disk_bytes
+

the maximum number of bytes a connection may have +pending in the disk write queue before its download +rate is being throttled. This prevents fast downloads +to slow medias to allocate more memory +indefinitely. This should be set to at least 16 kB +to not completely disrupt normal downloads. If it's +set to 0, you will be starving the disk thread and +nothing will be written to disk. +this is a per session setting.

+

When this limit is reached, +the peer connections will stop reading data from their sockets, until the disk +thread catches up. Setting this too low will severly limit your download rate.

+
+
+
+
max_queued_disk_bytes_low_watermark
+
this is the low watermark for the disk buffer queue. +whenever the number of queued bytes exceed the +max_queued_disk_bytes, libtorrent will wait for +it to drop below this value before issuing more +reads from the sockets. If set to 0, the +low watermark will be half of the max queued disk bytes
+
+
+
handshake_timeout
+
the number of seconds to wait for a handshake +response from a peer. If no response is received +within this time, the peer is disconnected.
+
+
+
use_dht_as_fallback
+
determines how the DHT is used. If this is true, +the DHT will only be used for torrents where all trackers in its tracker +list has failed. Either by an explicit error message or a time out. This +is false by default, which means the DHT is used by default regardless of +if the trackers fail or not.
+
+
+
free_torrent_hashes
+
determines whether or not the torrent's piece hashes +are kept in memory after the torrent becomes a seed or not. If it is set to +true the hashes are freed once the torrent is a seed (they're not +needed anymore since the torrent won't download anything more). If it's set +to false they are not freed. If they are freed, the torrent_info returned +by get_torrent_info() will return an object that may be incomplete, that +cannot be passed back to async_add_torrent() and add_torrent() for instance.
+
+
+
upnp_ignore_nonrouters
+
indicates whether or not the UPnP implementation +should ignore any broadcast response from a device whose address is not the +configured router for this machine. i.e. it's a way to not talk to other +people's routers by mistake.
+
+
+
send_buffer_low_watermark
+
This is the minimum send buffer target size (send buffer +includes bytes pending being read from disk). For good +and snappy seeding performance, set this fairly high, to +at least fit a few blocks. This is essentially the initial +window size which will determine how fast we can ramp up +the send rate
+
+
+
send_buffer_watermark
+

the upper limit of the send buffer low-watermark.

+

if the send buffer has fewer bytes than this, we'll +read another 16kB block onto it. If set too small, +upload rate capacity will suffer. If set too high, +memory will be wasted. +The actual watermark may be lower than this in case +the upload rate is low, this is the upper limit.

+
+
+
+
send_buffer_watermark_factor
+

the current upload rate to a peer is multiplied by +this factor to get the send buffer watermark. The +factor is specified as a percentage. i.e. 50 indicates +a factor of 0.5.

+

This product is clamped to the send_buffer_watermark +setting to not exceed the max. For high speed +upload, this should be set to a greater value than +100. The default is 50.

+

For high capacity connections, setting this +higher can improve upload performance and disk throughput. Setting it too +high may waste RAM and create a bias towards read jobs over write jobs.

+
+
+
+
choking_algorithm
+
specifies which algorithm to use to determine which peers +to unchoke. This setting replaces the deprecated settings auto_upload_slots +and auto_upload_slots_rate_based. For options, see choking_algorithm_t.
+
+
+
seed_choking_algorithm
+
controls the seeding unchoke behavior. For options, see seed_choking_algorithm_t.
+
+
+
use_parole_mode
+
specifies if parole mode should be used. Parole mode means +that peers that participate in pieces that fail the hash check are put in a mode +where they are only allowed to download whole pieces. If the whole piece a peer +in parole mode fails the hash check, it is banned. If a peer participates in a +piece that passes the hash check, it is taken out of parole mode.
+
+
+
cache_size
+

the disk write and read cache. It is specified in units of +16 KiB blocks. Buffers that are part of a peer's send or receive buffer also +count against this limit. Send and receive buffers will never be denied to be +allocated, but they will cause the actual cached blocks to be flushed or evicted. +If this is set to -1, the cache size is automatically set to the amount +of physical RAM available in the machine divided by 8. If the amount of physical +RAM cannot be determined, it's set to 1024 (= 16 MiB).

+

Disk buffers are allocated using a pool allocator, the number of blocks that +are allocated at a time when the pool needs to grow can be specified in +cache_buffer_chunk_size. This defaults to 16 blocks. Lower numbers +saves memory at the expense of more heap allocations. It must be at least 1.

+
+
+
+
cache_buffer_chunk_size
+
this is the number of disk buffer blocks (16 kiB) +that should be allocated at a time. It must be +at least 1. Lower number saves memory at the expense +of more heap allocations
+
+
+
cache_expiry
+
the number of seconds a write cache entry sits +idle in the cache before it's forcefully flushed +to disk.
+
+
+
use_read_cache
+
when set to true (default), the disk cache is also used to +cache pieces read from disk. Blocks for writing pieces takes presedence.
+
+
+
explicit_read_cache
+
defaults to 0. If set to something greater than 0, the +disk read cache will not be evicted by cache misses and will explicitly be +controlled based on the rarity of pieces. Rare pieces are more likely to be +cached. This would typically be used together with suggest_mode set to +suggest_read_cache. The value is the number of pieces to keep in the read +cache. If the actual read cache can't fit as many, it will essentially be clamped.
+
+
+
explicit_cache_interval
+
the number of seconds in between each refresh of +a part of the explicit read cache. Torrents take turns in refreshing and this +is the time in between each torrent refresh. Refreshing a torrent's explicit +read cache means scanning all pieces and picking a random set of the rarest ones. +There is an affinity to pick pieces that are already in the cache, so that +subsequent refreshes only swaps in pieces that are rarer than whatever is in +the cache at the time.
+
+ +
+
disk_io_write_mode disk_io_read_mode
+

determines how files are +opened when they're in read only mode versus read and write mode. For options, +see io_buffer_mode_t.

+

One reason to disable caching is that it may help the operating system from growing +its file cache indefinitely. Since some OSes only allow aligned files to be opened +in unbuffered mode, It is recommended to make the largest file in a torrent the first +file (with offset 0) or use pad files to align all files to piece boundries.

+
+
+
+
outgoing_ports
+

if set to something other than (0, 0) is a range of ports +used to bind outgoing sockets to. This may be useful for users whose router +allows them to assign QoS classes to traffic based on its local port. It is +a range instead of a single port because of the problems with failing to reconnect +to peers if a previous socket to that peer and port is in TIME_WAIT state.

+
+

Warning

+

setting outgoing ports will limit the ability to keep multiple +connections to the same client, even for different torrents. It is not +recommended to change this setting. Its main purpose is to use as an +escape hatch for cheap routers with QoS capability but can only classify +flows based on port numbers.

+
+
+
+
+
peer_tos
+
determines the TOS byte set in the IP header of every packet +sent to peers (including web seeds). The default value for this is 0x0 +(no marking). One potentially useful TOS mark is 0x20, this represents +the QBone scavenger service. For more details, see QBSS.
+
+ + + + + +
+
active_downloads active_seeds active_dht_limit active_tracker_limit active_lsd_limit active_limit
+

for auto managed torrents, these are the limits +they are subject to. If there are too many torrents +some of the auto managed ones will be paused until +some slots free up.

+

active_dht_limit and active_tracker_limit limits the +number of torrents that will be active on the DHT +and their tracker. If the active limit is set higher +than these numbers, some torrents will be "active" in +the sense that they will accept incoming connections, +but not announce on the DHT or their trackers.

+

active_lsd_limit is the max number of torrents to announce to the local network +over the local service discovery protocol. By default this is 80, which is no more +than one announce every 5 seconds (assuming the default announce interval of 5 minutes).

+

active_limit is a hard limit on the number of active torrents. This applies even to +slow torrents.

+

You can have more torrents active, even though they are not announced to the DHT, +lsd or their tracker. If some peer knows about you for any reason and tries to connect, +it will still be accepted, unless the torrent is paused, which means it won't accept +any connections.

+

active_downloads and active_seeds controls how many active seeding and +downloading torrents the queuing mechanism allows. The target number of active +torrents is min(active_downloads + active_seeds, active_limit). +active_downloads and active_seeds are upper limits on the number of +downloading torrents and seeding torrents respectively. Setting the value to +-1 means unlimited.

+

For example if there are 10 seeding torrents and 10 downloading torrents, and +active_downloads is 4 and active_seeds is 4, there will be 4 seeds +active and 4 downloading torrents. If the settings are active_downloads = 2 +and active_seeds = 4, then there will be 2 downloading torrents and 4 seeding +torrents active. Torrents that are not auto managed are also counted against these +limits. If there are non-auto managed torrents that use up all the slots, no +auto managed torrent will be activated.

+
+
+
+
auto_manage_prefer_seeds
+
prefer seeding torrents when determining which torrents to give +active slots to, the default is false which gives preference to +downloading torrents
+
+
+
dont_count_slow_torrents
+
if true, torrents without any payload transfers are +not subject to the active_seeds and active_downloads limits. This is intended +to make it more likely to utilize all available bandwidth, and avoid having torrents +that don't transfer anything block the active slots.
+
+
+
auto_manage_interval
+
the number of seconds in between recalculating which +torrents to activate and which ones to queue
+
+
+
share_ratio_limit
+

when a seeding torrent reaches either the share ratio +(bytes up / bytes down) or the seed time ratio +(seconds as seed / seconds as downloader) or the seed +time limit (seconds as seed) it is considered +done, and it will leave room for other torrents +the default value for share ratio is 2 +the default seed time ratio is 7, because that's a common +asymmetry ratio on connections

+
+

Note

+

This is an out-dated option that doesn't make much sense. +It will be removed in future versions of libtorrent

+
+
+
+
+
seed_time_ratio_limit
+
the seeding time / downloading time ratio limit +for considering a seeding torrent to have met the seed limit criteria. See queuing.
+
+
+
seed_time_limit
+
the limit on the time a torrent has been an active seed +(specified in seconds) before it is considered having met the seed limit criteria. +See queuing.
+
+ + +
+
peer_turnover_interval peer_turnover peer_turnover_cutoff
+

controls a feature where libtorrent periodically can disconnect +the least useful peers in the hope of connecting to better ones. peer_turnover_interval controls +the interval of this optimistic disconnect. It defaults to every 5 minutes, and +is specified in seconds.

+

peer_turnover Is the fraction of the peers that are disconnected. This is +a float where 1.f represents all peers an 0 represents no peers. It defaults to +4% (i.e. 0.04f)

+

peer_turnover_cutoff is the cut off trigger for optimistic unchokes. If a torrent +has more than this fraction of its connection limit, the optimistic unchoke is +triggered. This defaults to 90% (i.e. 0.9f).

+
+
+
+
close_redundant_connections
+
specifies whether libtorrent should close +connections where both ends have no utility in keeping the connection open. +For instance if both ends have completed their downloads, there's no point +in keeping it open. This defaults to true.
+
+
+
auto_scrape_interval
+
the number of seconds between scrapes of +queued torrents (auto managed and paused torrents). Auto managed +torrents that are paused, are scraped regularly in order to keep +track of their downloader/seed ratio. This ratio is used to determine +which torrents to seed and which to pause.
+
+
+
auto_scrape_min_interval
+
the minimum number of seconds between any +automatic scrape (regardless of torrent). In case there are a large number +of paused auto managed torrents, this puts a limit on how often a scrape +request is sent.
+
+
+
max_peerlist_size
+
the maximum number of peers in the list of +known peers. These peers are not necessarily connected, so this number +should be much greater than the maximum number of connected peers. +Peers are evicted from the cache when the list grows passed 90% of +this limit, and once the size hits the limit, peers are no longer +added to the list. If this limit is set to 0, there is no limit on +how many peers we'll keep in the peer list.
+
+
+
max_paused_peerlist_size
+
the max peer list size used for torrents +that are paused. This default to the same as max_peerlist_size, but +can be used to save memory for paused torrents, since it's not as +important for them to keep a large peer list.
+
+
+
min_announce_interval
+
the minimum allowed announce interval +for a tracker. This is specified in seconds, defaults to 5 minutes and +is used as a sanity check on what is returned from a tracker. It +mitigates hammering misconfigured trackers.
+
+
+
prioritize_partial_pieces
+
If true, partial pieces are picked +before pieces that are more rare. If false, rare pieces are always +prioritized, unless the number of partial pieces is growing out of +proportion.
+
+
+
auto_manage_startup
+
the number of seconds a torrent is considered +active after it was started, regardless of +upload and download speed. This is so that +newly started torrents are not considered +inactive until they have a fair chance to +start downloading.
+
+
+
rate_limit_ip_overhead
+
if set to true, the estimated TCP/IP overhead is +drained from the rate limiters, to avoid exceeding +the limits with the total traffic
+
+
+
announce_to_all_trackers
+
controls how multi tracker torrents are +treated. If this is set to true, all trackers in the same tier are +announced to in parallel. If all trackers in tier 0 fails, all trackers +in tier 1 are announced as well. If it's set to false, the behavior is as +defined by the multi tracker specification. It defaults to false, which +is the same behavior previous versions of libtorrent has had as well.
+
+
+
announce_to_all_tiers
+
controls how multi tracker torrents are +treated. When this is set to true, one tracker from each tier is announced +to. This is the uTorrent behavior. This is false by default in order +to comply with the multi-tracker specification.
+
+
+
prefer_udp_trackers
+
true by default. It means that trackers may +be rearranged in a way that udp trackers are always tried before http +trackers for the same hostname. Setting this to fails means that the +trackers' tier is respected and there's no preference of one protocol +over another.
+
+
+
strict_super_seeding
+
when this is set to true, a piece has to +have been forwarded to a third peer before another one is handed out. +This is the traditional definition of super seeding.
+
+
+
seeding_piece_quota
+
the number of pieces to send to a peer, +when seeding, before rotating in another peer to the unchoke set. +It defaults to 3 pieces, which means that when seeding, any peer we've +sent more than this number of pieces to will be unchoked in favour of +a choked peer.
+
+
+
max_sparse_regions
+
is a limit of the number of sparse regions in +a torrent. A sparse region is defined as a hole of pieces we have not +yet downloaded, in between pieces that have been downloaded. This is +used as a hack for windows vista which has a bug where you cannot +write files with more than a certain number of sparse regions. This +limit is not hard, it will be exceeded. Once it's exceeded, pieces +that will maintain or decrease the number of sparse regions are +prioritized. To disable this functionality, set this to 0. It defaults +to 0 on all platforms except windows.
+
+
+
lock_disk_cache
+
if lock disk cache is set to true the disk cache +that's in use, will be locked in physical memory, preventing it from +being swapped out.
+
+
+
max_rejects
+
the number of piece requests we will reject in a row +while a peer is choked before the peer is considered abusive and is +disconnected.
+
+ +
+
recv_socket_buffer_size send_socket_buffer_size
+
specifies +the buffer sizes set on peer sockets. 0 (which is the default) means +the OS default (i.e. don't change the buffer sizes). The socket buffer +sizes are changed using setsockopt() with SOL_SOCKET/SO_RCVBUF and +SO_SNDBUFFER.
+
+
+
optimize_hashing_for_speed
+
chooses between two ways of reading back +piece data from disk when its complete and needs to be verified against +the piece hash. This happens if some blocks were flushed to the disk +out of order. Everything that is flushed in order is hashed as it goes +along. Optimizing for speed will allocate space to fit all the the +remaingin, unhashed, part of the piece, reads the data into it in a single +call and hashes it. This is the default. If optimizing_hashing_for_speed +is false, a single block will be allocated (16 kB), and the unhashed parts +of the piece are read, one at a time, and hashed in this single block. This +is appropriate on systems that are memory constrained.
+
+
+
file_checks_delay_per_block
+
the number of milliseconds to sleep +in between disk read operations when checking torrents. This defaults +to 0, but can be set to higher numbers to slow down the rate at which +data is read from the disk while checking. This may be useful for +background tasks that doesn't matter if they take a bit longer, as long +as they leave disk I/O time for other processes.
+
+
+
disk_cache_algorithm
+
tells the disk I/O thread which cache flush +algorithm to use. The default algorithm is largest_contiguous. This is +specified by the disk_cache_algo_t enum.
+
+
+
read_cache_line_size
+

the number of blocks to read into the read +cache when a read cache miss occurs. Setting this to 0 is essentially +the same thing as disabling read cache. The number of blocks read +into the read cache is always capped by the piece boundry.

+

When a piece in the write cache has write_cache_line_size contiguous +blocks in it, they will be flushed. Setting this to 1 effectively +disables the write cache.

+
+
+
+
write_cache_line_size
+
whenever a contiguous range of this many +blocks is found in the write cache, it +is flushed immediately
+
+
+
optimistic_disk_retry
+

the number of seconds from a disk write +errors occur on a torrent until libtorrent will take it out of the +upload mode, to test if the error condition has been fixed.

+

libtorrent will only do this automatically for auto managed torrents.

+

You can explicitly take a torrent out of upload only mode using +set_upload_mode().

+
+
+
+
disable_hash_checks
+
controls if downloaded pieces are verified against +the piece hashes in the torrent file or not. The default is false, i.e. +to verify all downloaded data. It may be useful to turn this off for performance +profiling and simulation scenarios. Do not disable the hash check for regular +bittorrent clients.
+
+
+
allow_reordered_disk_operations
+
if this is true, disk read operations may +be re-ordered based on their physical disk +read offset. This greatly improves throughput +when uploading to many peers. This assumes +a traditional hard drive with a read head +and spinning platters. If your storage medium +is a solid state drive, this optimization +doesn't give you an benefits
+
+
+
allow_i2p_mixed
+
if this is true, i2p torrents are allowed +to also get peers from other sources than +the tracker, and connect to regular IPs, +not providing any anonymization. This may +be useful if the user is not interested in +the anonymization of i2p, but still wants to +be able to connect to i2p peers.
+
+
+
max_suggest_pieces
+
the max number of suggested piece indices received +from a peer that's remembered. If a peer floods suggest messages, this limit +prevents libtorrent from using too much RAM. It defaults to 10.
+
+
+
drop_skipped_requests
+
If set to true (it defaults to false), piece +requests that have been skipped enough times when piece messages +are received, will be considered lost. Requests are considered skipped +when the returned piece messages are re-ordered compared to the order +of the requests. This was an attempt to get out of dead-locks caused by +BitComet peers silently ignoring some requests. It may cause problems +at high rates, and high level of reordering in the uploading peer, that's +why it's disabled by default.
+
+
+
low_prio_disk
+
determines if the disk I/O should use a normal +or low priority policy. This defaults to true, which means that +it's low priority by default. Other processes doing disk I/O will +normally take priority in this mode. This is meant to improve the +overall responsiveness of the system while downloading in the +background. For high-performance server setups, this might not +be desirable.
+
+
+
local_service_announce_interval
+
the time between local +network announces for a torrent. By default, when local service +discovery is enabled a torrent announces itself every 5 minutes. +This interval is specified in seconds.
+
+
+
dht_announce_interval
+
the number of seconds between announcing +torrents to the distributed hash table (DHT). This is specified to +be 15 minutes which is its default.
+
+
+
udp_tracker_token_expiry
+
the number of seconds libtorrent +will keep UDP tracker connection tokens around for. This is specified +to be 60 seconds, and defaults to that. The higher this value is, the +fewer packets have to be sent to the UDP tracker. In order for higher +values to work, the tracker needs to be configured to match the +expiration time for tokens.
+
+
+
volatile_read_cache
+
if this is set to true, read cache blocks +that are hit by peer read requests are removed from the disk cache +to free up more space. This is useful if you don't expect the disk +cache to create any cache hits from other peers than the one who +triggered the cache line to be read into the cache in the first place.
+
+
+
guided_read_cache
+
enables the disk cache to adjust the size +of a cache line generated by peers to depend on the upload rate +you are sending to that peer. The intention is to optimize the RAM +usage of the cache, to read ahead further for peers that you're +sending faster to.
+
+
+
default_cache_min_age
+
the minimum number of seconds any read +cache line is kept in the cache. This defaults to one second but +may be greater if guided_read_cache is enabled. Having a lower +bound on the time a cache line stays in the cache is an attempt +to avoid swapping the same pieces in and out of the cache in case +there is a shortage of spare cache space.
+
+
+
num_optimistic_unchoke_slots
+
the number of optimistic unchoke +slots to use. It defaults to 0, which means automatic. Having a higher +number of optimistic unchoke slots mean you will find the good peers +faster but with the trade-off to use up more bandwidth. When this is +set to 0, libtorrent opens up 20% of your allowed upload slots as +optimistic unchoke slots.
+
+
+
no_atime_storage
+
this is a linux-only option and passes in the +O_NOATIME to open() when opening files. This may lead to +some disk performance improvements.
+
+
+
default_est_reciprocation_rate
+
the assumed reciprocation rate +from peers when using the BitTyrant choker. This defaults to 14 kiB/s. +If set too high, you will over-estimate your peers and be more altruistic +while finding the true reciprocation rate, if it's set too low, you'll +be too stingy and waste finding the true reciprocation rate.
+
+
+
increase_est_reciprocation_rate
+
specifies how many percent the +extimated reciprocation rate should be increased by each unchoke +interval a peer is still choking us back. This defaults to 20%. +This only applies to the BitTyrant choker.
+
+
+
decrease_est_reciprocation_rate
+
specifies how many percent the +estimated reciprocation rate should be decreased by each unchoke +interval a peer unchokes us. This default to 3%. +This only applies to the BitTyrant choker.
+
+
+
incoming_starts_queued_torrents
+
defaults to false. If a torrent +has been paused by the auto managed feature in libtorrent, i.e. +the torrent is paused and auto managed, this feature affects whether +or not it is automatically started on an incoming connection. The +main reason to queue torrents, is not to make them unavailable, but +to save on the overhead of announcing to the trackers, the DHT and to +avoid spreading one's unchoke slots too thin. If a peer managed to +find us, even though we're no in the torrent anymore, this setting +can make us start the torrent and serve it.
+
+
+
report_true_downloaded
+
when set to true, the downloaded counter sent to trackers +will include the actual number of payload bytes donwnloaded +including redundant bytes. If set to false, it will not include +any redundany bytes
+
+
+
strict_end_game_mode
+
defaults to true, and controls when a block +may be requested twice. If this is true, a block may only be requested +twice when there's ay least one request to every piece that's left to +download in the torrent. This may slow down progress on some pieces +sometimes, but it may also avoid downloading a lot of redundant bytes. +If this is false, libtorrent attempts to use each peer connection +to its max, by always requesting something, even if it means requesting +something that has been requested from another peer already.
+
+
+
broadcast_lsd
+
if set to true, the local peer discovery +(or Local Service Discovery) will not only use IP multicast, but also +broadcast its messages. This can be useful when running on networks +that don't support multicast. Since broadcast messages might be +expensive and disruptive on networks, only every 8th announce uses +broadcast.
+
+ + + +
+
enable_outgoing_utp enable_incoming_utp enable_outgoing_tcp enable_incoming_tcp
+
these all determines if libtorrent should attempt to make +outgoing connections of the specific type, or allow incoming connection. By +default all of them are enabled.
+
+
+
max_pex_peers
+
the max number of peers we accept from pex messages from a single peer. +this limits the number of concurrent peers any of our peers claims to +be connected to. If they clain to be connected to more than this, we'll +ignore any peer that exceeds this limit
+
+
+
ignore_resume_timestamps
+
determines if the storage, when loading +resume data files, should verify that the file modification time +with the timestamps in the resume data. This defaults to false, which +means timestamps are taken into account, and resume data is less likely +to accepted (torrents are more likely to be fully checked when loaded). +It might be useful to set this to true if your network is faster than your +disk, and it would be faster to redownload potentially missed pieces than +to go through the whole storage to look for them.
+
+
+
no_recheck_incomplete_resume
+
determines if the storage should check +the whole files when resume data is incomplete or missing or whether +it should simply assume we don't have any of the data. By default, this +is determined by the existance of any of the files. By setting this setting +to true, the files won't be checked, but will go straight to download +mode.
+
+
+
anonymous_mode
+

defaults to false. When set to true, the client tries +to hide its identity to a certain degree. The peer-ID will no longer +include the client's fingerprint. The user-agent will be reset to an +empty string. It will also try to not leak other identifying information, +such as your local listen port, your IP etc.

+

If you're using I2P, a VPN or a proxy, it might make sense to enable anonymous mode.

+
+
+
+
force_proxy
+
disables any communication that's not going over a proxy. +Enabling this requires a proxy to be configured as well, see set_proxy_settings. +The listen sockets are closed, and incoming connections will +only be accepted through a SOCKS5 or I2P proxy (if a peer proxy is set up and +is run on the same machine as the tracker proxy). This setting also +disabled peer country lookups, since those are done via DNS lookups that +aren't supported by proxies.
+
+
+
tick_interval
+
specifies the number of milliseconds between internal +ticks. This is the frequency with which bandwidth quota is distributed to +peers. It should not be more than one second (i.e. 1000 ms). Setting this +to a low value (around 100) means higher resolution bandwidth quota distribution, +setting it to a higher value saves CPU cycles.
+
+
+
report_web_seed_downloads
+
specifies whether downloads from web seeds is reported to the +tracker or not. Defaults to on
+
+
+
share_mode_target
+
specifies the target share ratio for share mode torrents. +This defaults to 3, meaning we'll try to upload 3 times as much as we download. +Setting this very high, will make it very conservative and you might end up +not downloading anything ever (and not affecting your share ratio). It does +not make any sense to set this any lower than 2. For instance, if only 3 peers +need to download the rarest piece, it's impossible to download a single piece +and upload it more than 3 times. If the share_mode_target is set to more than 3, +nothing is downloaded.
+
+ + + +
+
upload_rate_limit download_rate_limit local_upload_rate_limit local_download_rate_limit
+

sets the session-global limits of upload +and download rate limits, in bytes per second. The local rates refer to peers +on the local network. By default peers on the local network are not rate limited.

+

These rate limits are only used for local peers (peers within the same subnet as +the client itself) and it is only used when session_settings::ignore_limits_on_local_network +is set to true (which it is by default). These rate limits default to unthrottled, +but can be useful in case you want to treat local peers preferentially, but not +quite unthrottled.

+

A value of 0 means unlimited.

+
+
+
+
dht_upload_rate_limit
+
sets the rate limit on the DHT. This is specified in +bytes per second and defaults to 4000. For busy boxes with lots of torrents +that requires more DHT traffic, this should be raised.
+
+
+
unchoke_slots_limit
+
the max number of unchoked peers in the session. The +number of unchoke slots may be ignored depending on what choking_algorithm +is set to. A value of -1 means infinite.
+
+
+
half_open_limit
+
sets the maximum number of half-open connections +libtorrent will have when connecting to peers. A half-open connection is one +where connect() has been called, but the connection still hasn't been established +(nor failed). Windows XP Service Pack 2 sets a default, system wide, limit of +the number of half-open connections to 10. So, this limit can be used to work +nicer together with other network applications on that system. The default is +to have no limit, and passing -1 as the limit, means to have no limit. When +limiting the number of simultaneous connection attempts, peers will be put in +a queue waiting for their turn to get connected.
+
+
+
connections_limit
+
sets a global limit on the number of connections +opened. The number of connections is set to a hard minimum of at least two per +torrent, so if you set a too low connections limit, and open too many torrents, +the limit will not be met.
+
+
+
connections_slack
+
the number of extra incoming connections allowed +temporarily, in order to support replacing peers
+
+
+
utp_target_delay
+
the target delay for uTP sockets in milliseconds. A high +value will make uTP connections more aggressive and cause longer queues in the upload +bottleneck. It cannot be too low, since the noise in the measurements would cause +it to send too slow. The default is 50 milliseconds.
+
+
+
utp_gain_factor
+
the number of bytes the uTP congestion window can increase +at the most in one RTT. This defaults to 300 bytes. If this is set too high, +the congestion controller reacts too hard to noise and will not be stable, if it's +set too low, it will react slow to congestion and not back off as fast.
+
+
+
utp_min_timeout
+

the shortest allowed uTP socket timeout, specified in milliseconds. +This defaults to 500 milliseconds. The timeout depends on the RTT of the connection, but +is never smaller than this value. A connection times out when every packet in a window +is lost, or when a packet is lost twice in a row (i.e. the resent packet is lost as well).

+

The shorter the timeout is, the faster the connection will recover from this situation, +assuming the RTT is low enough.

+
+
+
+
utp_syn_resends
+
the number of SYN packets that are sent (and timed out) before +giving up and closing the socket.
+
+
+
utp_fin_resends
+
the number of resent packets sent on a closed socket before giving up
+
+
+
utp_num_resends
+
the number of times a packet is sent (and lossed or timed out) +before giving up and closing the connection.
+
+
+
utp_connect_timeout
+
the number of milliseconds of timeout for the initial SYN +packet for uTP connections. For each timed out packet (in a row), the timeout is doubled.
+
+
+
utp_dynamic_sock_buf
+
controls if the uTP socket manager is allowed to increase +the socket buffer if a network interface with a large MTU is used (such as loopback +or ethernet jumbo frames). This defaults to true and might improve uTP throughput. +For RAM constrained systems, disabling this typically saves around 30kB in user space +and probably around 400kB in kernel socket buffers (it adjusts the send and receive +buffer size on the kernel socket, both for IPv4 and IPv6).
+
+
+
utp_loss_multiplier
+
controls how the congestion window is changed when a packet +loss is experienced. It's specified as a percentage multiplier for cwnd. By default +it's set to 50 (i.e. cut in half). Do not change this value unless you know what +you're doing. Never set it higher than 100.
+
+
+
mixed_mode_algorithm
+

determines how to treat TCP connections when there are +uTP connections. Since uTP is designed to yield to TCP, there's an inherent problem +when using swarms that have both TCP and uTP connections. If nothing is done, uTP +connections would often be starved out for bandwidth by the TCP connections. This mode +is prefer_tcp. The peer_proportional mode simply looks at the current throughput +and rate limits all TCP connections to their proportional share based on how many of +the connections are TCP. This works best if uTP connections are not rate limited by +the global rate limiter (which they aren't by default).

+

see bandwidth_mixed_algo_t for options.

+
+
+
+
rate_limit_utp
+
determines if uTP connections should be throttled by the global rate +limiter or not. By default they are.
+
+
+
listen_queue_size
+
the value passed in to listen() for the listen socket. +It is the number of outstanding incoming connections to queue up while we're not +actively waiting for a connection to be accepted. The default is 5 which should +be sufficient for any normal client. If this is a high performance server which +expects to receive a lot of connections, or used in a simulator or test, it +might make sense to raise this number. It will not take affect until listen_on() +is called again (or for the first time).
+
+
+
announce_double_nat
+
if true, the &ip= argument in tracker requests +(unless otherwise specified) will be set to the intermediate IP address, if the +user is double NATed. If ther user is not double NATed, this option has no affect.
+
+
+
torrent_connect_boost
+
the number of peers to try to connect to immediately +when the first tracker response is received for a torrent. This is a boost to +given to new torrents to accelerate them starting up. The normal connect scheduler +is run once every second, this allows peers to be connected immediately instead +of waiting for the session tick to trigger connections.
+
+
+
seeding_outgoing_connections
+
determines if seeding (and finished) torrents +should attempt to make outgoing connections or not. By default this is true. It +may be set to false in very specific applications where the cost of making +outgoing connections is high, and there are no or small benefits of doing so. +For instance, if no nodes are behind a firewall or a NAT, seeds don't need to +make outgoing connections.
+
+
+
no_connect_privileged_ports
+
if true (which is the default), libtorrent +will not connect to any peers on priviliged ports (<= 1023). This can mitigate +using bittorrent swarms for certain DDoS attacks.
+
+
+
alert_queue_size
+
the maximum number of alerts queued up internally. If +alerts are not popped, the queue will eventually fill up to this level. This +defaults to 1000.
+
+
+
max_metadata_size
+
the maximum allowed size (in bytes) to be received +by the metadata extension, i.e. magnet links. It defaults to 1 MiB.
+
+
+
smooth_connects
+
true by default, which means the number of connection +attempts per second may be limited to below the connection_speed, in case +we're close to bump up against the limit of number of connections. The intention +of this setting is to more evenly distribute our connection attempts over time, +instead of attempting to connectin in batches, and timing them out in batches.
+
+
+
always_send_user_agent
+
defaults to false. When set to true, web connections +will include a user-agent with every request, as opposed to just the first +request in a connection.
+
+
+
apply_ip_filter_to_trackers
+
defaults to true. It determines whether the +IP filter applies to trackers as well as peers. If this is set to false, +trackers are exempt from the IP filter (if there is one). If no IP filter +is set, this setting is irrelevant.
+
+
+
read_job_every
+
used to avoid starvation of read jobs in the disk I/O +thread. By default, read jobs are deferred, sorted by physical disk location +and serviced once all write jobs have been issued. In scenarios where the +download rate is enough to saturate the disk, there's a risk the read jobs will +never be serviced. With this setting, every x write job, issued in a row, will +instead pick one read job off of the sorted queue, where x is read_job_every.
+
+
+
use_disk_read_ahead
+
defaults to true and will attempt to optimize disk reads +by giving the operating system heads up of disk read requests as they are queued +in the disk job queue. This gives a significant performance boost for seeding.
+
+
+
lock_files
+
determines whether or not to lock files which libtorrent is downloading +to or seeding from. This is implemented using fcntl(F_SETLK) on unix systems and +by not passing in SHARE_READ and SHARE_WRITE on windows. This might prevent +3rd party processes from corrupting the files under libtorrent's feet.
+
+
+
ssl_listen
+

sets the listen port for SSL connections. If this is set to 0, +no SSL listen port is opened. Otherwise a socket is opened on this port. This +setting is only taken into account when opening the regular listen port, and +won't re-open the listen socket simply by changing this setting.

+

if this is 0, outgoing SSL connections are disabled

+

It defaults to port 4433.

+
+
+
+
tracker_backoff
+

tracker_backoff determines how aggressively to back off from retrying +failing trackers. This value determines x in the following formula, determining +the number of seconds to wait until the next retry:

+
+delay = 5 + 5 * x / 100 * fails^2
+

It defaults to 250.

+

This setting may be useful to make libtorrent more or less aggressive in hitting +trackers.

+
+
+
+
ban_web_seeds
+
enables banning web seeds. By default, web seeds that send +corrupt data are banned.
+
+
+
max_http_recv_buffer_size
+
specifies the max number of bytes to receive into +RAM buffers when downloading stuff over HTTP. Specifically when specifying a +URL to a .torrent file when adding a torrent or when announcing to an HTTP +tracker. The default is 2 MiB.
+
+
+
support_share_mode
+
enables or disables the share mode extension. This is +enabled by default.
+
+
+
support_merkle_torrents
+
enables or disables the merkle tree torrent support. +This is enabled by default.
+
+
+
report_redundant_bytes
+
enables or disables reporting redundant bytes to the tracker. +This is enabled by default.
+
+
+
handshake_client_version
+
the version string to advertise for this client +in the peer protocol handshake. If this is empty +the user_agent is used
+
+
+
use_disk_cache_pool
+
if this is true, the disk cache uses a pool allocator +for disk cache blocks. Enabling this improves +performance of the disk cache with the side effect +that the disk cache is less likely and slower at +returning memory to the kernel when cache pressure +is low.
+
+
+
+
+ +
+ + +
+ + diff --git a/docs/reference-Storage.html b/docs/reference-Storage.html new file mode 100644 index 000000000..0affffe63 --- /dev/null +++ b/docs/reference-Storage.html @@ -0,0 +1,612 @@ + + + + + + +Storage + + + + + + + + +
+
+
+ +
+ +
+

Storage

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

Table of contents

+ +
+
+

file_entry

+

Declared in "libtorrent/file_storage.hpp"

+

information about a file in a file_storage

+
+struct file_entry
+{
+   std::string path;
+   std::string symlink_path;
+   size_type offset;
+   size_type size;
+   size_type file_base;
+   std::time_t mtime;
+   sha1_hash filehash;
+   bool pad_file:1;
+   bool hidden_attribute:1;
+   bool executable_attribute:1;
+   bool symlink_attribute:1;
+};
+
+
+
path
+
the full path of this file. The paths are unicode strings +encoded in UTF-8.
+
+
+
symlink_path
+
the path which this is a symlink to, or empty if this is +not a symlink. This field is only used if the symlink_attribute is set.
+
+
+
offset
+
the offset of this file inside the torrent
+
+
+
size
+
the size of the file (in bytes) and offset is the byte offset +of the file within the torrent. i.e. the sum of all the sizes of the files +before it in the list.
+
+
+
file_base
+
the offset in the file where the storage should start. The normal +case is to have this set to 0, so that the storage starts saving data at the start +if the file. In cases where multiple files are mapped into the same file though, +the file_base should be set to an offset so that the different regions do +not overlap. This is used when mapping "unselected" files into a so-called part +file.
+
+
+
mtime
+
the modification time of this file specified in posix time.
+
+
+
filehash
+
a sha-1 hash of the content of the file, or zeroes, if no +file hash was present in the torrent file. It can be used to potentially +find alternative sources for the file.
+
+
+
pad_file
+
set to true for files that are not part of the data of the torrent. +They are just there to make sure the next file is aligned to a particular byte offset +or piece boundry. These files should typically be hidden from an end user. They are +not written to disk.
+
+
+
hidden_attribute
+
true if the file was marked as hidden (on windows).
+
+
+
executable_attribute
+
true if the file was marked as executable (posix)
+
+
+
symlink_attribute
+
true if the file was a symlink. If this is the case +the symlink_index refers to a string which specifies the original location +where the data for this file was found.
+
+
+
+

file_slice

+

Declared in "libtorrent/file_storage.hpp"

+

represents a window of a file in a torrent.

+

The file_index refers to the index of the file (in the torrent_info). +To get the path and filename, use file_at() and give the file_index +as argument. The offset is the byte offset in the file where the range +starts, and size is the number of bytes this range is. The size + offset +will never be greater than the file size.

+
+struct file_slice
+{
+   int file_index;
+   size_type offset;
+   size_type size;
+};
+
+
+
file_index
+
the index of the file
+
+
+
offset
+
the offset from the start of the file, in bytes
+
+
+
size
+
the size of the window, in bytes
+
+
+
+

file_storage

+

Declared in "libtorrent/file_storage.hpp"

+

The file_storage class represents a file list and the piece +size. Everything necessary to interpret a regular bittorrent storage +file structure.

+
+class file_storage
+{
+   bool is_valid () const;
+   void reserve (int num_files);
+   void add_file (std::string const& p, size_type size, int flags = 0
+      , std::time_t mtime = 0, std::string const& s_p = "");
+   void add_file (file_entry const& e, char const* filehash = 0);
+   void rename_file (int index, std::string const& new_filename);
+   void rename_file_borrow (int index, char const* new_filename, int len);
+   std::vector<file_slice> map_block (int piece, size_type offset
+      , int size) const;
+   peer_request map_file (int file, size_type offset, int size) const;
+   int num_files () const;
+   file_entry at (int index) const;
+   size_type total_size () const;
+   void set_num_pieces (int n);
+   int num_pieces () const;
+   void set_piece_length (int l);
+   int piece_length () const;
+   int piece_size (int index) const;
+   void set_name (std::string const& n);
+   const std::string& name () const;
+   void swap (file_storage& ti);
+   void optimize (int pad_file_limit = -1, int alignment = 0x10000);
+   size_type file_size (int index) const;
+   sha1_hash hash (int index) const;
+   std::string file_name (int index) const;
+   size_type file_offset (int index) const;
+   time_t mtime (int index) const;
+   bool pad_file_at (int index) const;
+   std::string const& symlink (int index) const;
+   std::string file_path (int index, std::string const& save_path = "") const;
+   int file_flags (int index) const;
+   void set_file_base (int index, size_type off);
+   size_type file_base (int index) const;
+   int file_index_at_offset (size_type offset) const;
+   char const* file_name_ptr (int index) const;
+   int file_name_len (int index) const;
+
+   enum flags_t
+   {
+      pad_file,
+      attribute_hidden,
+      attribute_executable,
+      attribute_symlink,
+   };
+
+   enum file_flags_t
+   {
+      flag_pad_file,
+      flag_hidden,
+      flag_executable,
+      flag_symlink,
+   };
+};
+
+
+

is_valid()

+
+bool is_valid () const;
+
+

returns true if the piece length has been initialized +on the file_storage. This is typically taken as a proxy +of whether the file_storage as a whole is initialized or +not.

+
+
+

reserve()

+
+void reserve (int num_files);
+
+

allocates space for num_files in the internal file list. This can +be used to avoid reallocating the internal file list when the number +of files to be added is known up-front.

+
+
+

add_file()

+
+void add_file (std::string const& p, size_type size, int flags = 0
+      , std::time_t mtime = 0, std::string const& s_p = "");
+void add_file (file_entry const& e, char const* filehash = 0);
+
+

Adds a file to the file storage. The flags argument sets attributes on the file. +The file attributes is an extension and may not work in all bittorrent clients.

+

For possible file attributes, see file_storage::flags_t.

+

If more files than one are added, certain restrictions to their paths apply. +In a multi-file file storage (torrent), all files must share the same root directory.

+

That is, the first path element of all files must be the same. +This shared path element is also set to the name of the torrent. It +can be changed by calling set_name.

+

The built in functions to traverse a directory to add files will +make sure this requirement is fulfilled.

+
+
+

rename_file()

+
+void rename_file (int index, std::string const& new_filename);
+
+

renames the file at index to new_filename. Keep in mind +that filenames are expected to be UTF-8 encoded.

+
+
+

rename_file_borrow()

+
+void rename_file_borrow (int index, char const* new_filename, int len);
+
+

this is a low-level function that sets the name of a file +by making it reference a buffer that is not owned by the file_storage. +it's an optimization used when loading .torrent files, to not +duplicate names in memory.

+
+
+

map_block()

+
+std::vector<file_slice> map_block (int piece, size_type offset
+      , int size) const;
+
+

returns a list of file_slice objects representing the portions of +files the specified piece index, byte offset and size range overlaps. +this is the inverse mapping of map_file().

+
+
+

map_file()

+
+peer_request map_file (int file, size_type offset, int size) const;
+
+

returns a peer_request representing the piece index, byte offset +and size the specified file range overlaps. This is the inverse +mapping ove map_block().

+
+
+

num_files()

+
+int num_files () const;
+
+

returns the number of files in the file_storage

+
+
+

at()

+
+file_entry at (int index) const;
+
+

returns a file_entry with information about the file +at index. Index must be in the range [0, num_files() ).

+
+
+

total_size()

+
+size_type total_size () const;
+
+

returns the total number of bytes all the files in this torrent spans

+ +
+
+

num_pieces() set_num_pieces()

+
+void set_num_pieces (int n);
+int num_pieces () const;
+
+

set and get the number of pieces in the torrent

+ +
+
+

piece_length() set_piece_length()

+
+void set_piece_length (int l);
+int piece_length () const;
+
+

set and get the size of each piece in this torrent. This size is typically an even power +of 2. It doesn't have to be though. It should be divisible by 16kiB however.

+
+
+

piece_size()

+
+int piece_size (int index) const;
+
+

returns the piece size of index. This will be the same as piece_length(), except +for the last piece, which may be shorter.

+ +
+
+

set_name() name()

+
+void set_name (std::string const& n);
+const std::string& name () const;
+
+

set and get the name of this torrent. For multi-file torrents, this is also +the name of the root directory all the files are stored in.

+
+
+

swap()

+
+void swap (file_storage& ti);
+
+

swap all content of this with ti.

+
+
+

optimize()

+
+void optimize (int pad_file_limit = -1, int alignment = 0x10000);
+
+

if pad_file_limit >= 0, files larger than +that limit will be padded, default is to +not add any padding

+ + + + + + + +
+ +
+

file_flags()

+
+int file_flags (int index) const;
+
+

returns a bitmask of flags from file_flags_t that apply +to file at index.

+ +
+
+

file_base() set_file_base()

+
+void set_file_base (int index, size_type off);
+size_type file_base (int index) const;
+
+

The file base of a file is the offset within the file on the filsystem +where it starts to write. For the most part, this is always 0. It's +possible to map several files (in the torrent) into a single file on +the filesystem by making them all point to the same filename, but with +different file bases, so that they don't overlap. +torrent_info::remap_files() can be used to use a new file layout.

+
+
+

file_index_at_offset()

+
+int file_index_at_offset (size_type offset) const;
+
+

returns the index of the file at the given offset in the torrent

+ +
+
+

file_name_len() file_name_ptr()

+
+char const* file_name_ptr (int index) const;
+int file_name_len (int index) const;
+
+

low-level function. returns a pointer to the internal storage for +the filename. This string may not be null terinated! +the file_name_len() function returns the length of the filename.

+
+
+

enum flags_t

+

Declared in "libtorrent/file_storage.hpp"

+ +++++ + + + + + + + + + + + + + + + + + + + + + + + + +
namevaluedescription
pad_file1the file is a pad file. It's required to contain zeroes +at it will not be saved to disk. Its purpose is to make +the following file start on a piece boundary.
attribute_hidden2this file has the hidden attribute set. This is primarily +a windows attribute
attribute_executable4this file has the executable attribute set.
attribute_symlink8this file is a symbilic link. It should have a link +target string associated with it.
+
+
+

enum file_flags_t

+

Declared in "libtorrent/file_storage.hpp"

+ +++++ + + + + + + + + + + + + + + + + + + + + + + + + +
namevaluedescription
flag_pad_file1this file is a pad file. The creator of the +torrent promises the file is entirely filled with +zeroes and does not need to be downloaded. The +purpose is just to align the next file to either +a block or piece boundary.
flag_hidden2this file is hiddent (sets the hidden attribute +on windows)
flag_executable4this file is executable (sets the executable bit +on posix like systems)
flag_symlink8this file is a symlink. The symlink target is +specified in a separate field
+
+
+

default_storage_constructor()

+

Declared in "libtorrent/storage_defs.hpp"

+
+storage_interface* default_storage_constructor (
+   file_storage const&, file_storage const* mapped, std::string const&, file_pool&
+   , std::vector<boost::uint8_t> const&);
+
+

the constructor function for the regular file storage. This is the +default value for add_torrent_params::storage.

+
+
+

disabled_storage_constructor()

+

Declared in "libtorrent/storage_defs.hpp"

+
+storage_interface* disabled_storage_constructor (
+   file_storage const&, file_storage const* mapped, std::string const&, file_pool&
+   , std::vector<boost::uint8_t> const&);
+
+

the constructor function for the disabled storage. This can be used for +testing and benchmarking. It will throw away any data written to +it and return garbage for anything read from it.

+
+
+

enum storage_mode_t

+

Declared in "libtorrent/storage_defs.hpp"

+ +++++ + + + + + + + + + + + + + + + + +
namevaluedescription
storage_mode_allocate0All pieces will be written to their final position, all files will be +allocated in full when the torrent is first started. This is done with +fallocate() and similar calls. This mode minimizes fragmentation.
storage_mode_sparse1All pieces will be written to the place where they belong and sparse files +will be used. This is the recommended, and default mode.
+
+
+
+ +
+ + +
+ + diff --git a/docs/reference-String.html b/docs/reference-String.html new file mode 100644 index 000000000..815d46090 --- /dev/null +++ b/docs/reference-String.html @@ -0,0 +1,169 @@ + + + + + + +String + + + + + + + + +
+
+
+ +
+ +
+

String

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

to_hex()

+

Declared in "libtorrent/escape_string.hpp"

+
+std::string to_hex (std::string const& s);
+
+

converts (binary) the string s to hexadecimal representation and +returns it.

+
+
+

to_hex()

+

Declared in "libtorrent/escape_string.hpp"

+
+void to_hex (char const in, int len, char out);
+
+

converts the binary buffer [in, in + len) to hexadecimal +and prints it to the buffer out. The caller is responsible for +making sure the buffer pointed to by out is large enough, +i.e. has at least len * 2 bytes of space.

+
+
+

from_hex()

+

Declared in "libtorrent/escape_string.hpp"

+
+bool from_hex (char const in, int len, char out);
+
+

converts the buffer [in, in + len) from hexadecimal to +binary. The binary output is written to the buffer pointed to +by out. The caller is responsible for making sure the buffer +at out has enough space for the result to be written to, i.e. +(len + 1) / 2 bytes.

+
+
+

is_digit()

+

Declared in "libtorrent/string_util.hpp"

+
+bool is_digit (char c);
+
+

this is used by bdecode_recursive's header file

+ +
+
+

utf8_wchar() wchar_utf8()

+

Declared in "libtorrent/utf8.hpp"

+
+utf8_conv_result_t wchar_utf8 (
+   const std::wstring &wide, std::string &utf8);
+utf8_conv_result_t utf8_wchar (
+   const std::string &utf8, std::wstring &wide);
+
+

utf8_wchar converts a UTF-8 string (utf8) to a wide character +string (wide). wchar_utf8 converts a wide character string +(wide) to a UTF-8 string (utf8). The return value is one of +the enumeration values from utf8_conv_result_t.

+
+
+

enum utf8_conv_result_t

+

Declared in "libtorrent/utf8.hpp"

+ +++++ + + + + + + + + + + + + + + + + + + + + + + + + +
namevaluedescription
conversion_ok0conversion successful
source_exhausted1partial character in source, but hit end
target_exhausted2insuff. room in target for conversion
source_illegal3source sequence is illegal/malformed
+
+
+ +
+ + +
+ + diff --git a/docs/reference-Time.html b/docs/reference-Time.html new file mode 100644 index 000000000..ca62d9aa1 --- /dev/null +++ b/docs/reference-Time.html @@ -0,0 +1,197 @@ + + + + + + +Time + + + + + + + + +
+
+
+ +
+ +
+

Time

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

Table of contents

+ +
+

This section contains fundamental time types used internall by +libtorrent and exposed through various places in the API. The two +basic types are ptime and time_duration. The first represents +a point in time and the second the difference between two points +in time.

+

The internal representation of these types is implementation defined +and they can only be constructed via one of the construction functions +that take a well defined time unit (seconds, minutes, etc.). They can +only be turned into well defined time units by the accessor functions +(total_microseconds(), etc.).

+
+

Note

+

In a future version of libtorrent, these types will be replaced +by the standard timer types from std::chrono.

+
+
+

time_duration

+

Declared in "libtorrent/ptime.hpp"

+

libtorrent time_duration type

+
+struct time_duration
+{
+   time_duration& operator-= (time_duration const& c);
+   time_duration operator+ (time_duration const& c);
+   time_duration& operator+= (time_duration const& c);
+   time_duration operator/ (int rhs) const;
+   explicit time_duration (boost::int64_t d);
+   time_duration operator- (time_duration const& c);
+   time_duration& operator*= (int v);
+};
+
+
+
+

ptime

+

Declared in "libtorrent/ptime.hpp"

+

This type represents a point in time.

+
+struct ptime
+{
+   ptime& operator-= (time_duration rhs);
+   ptime& operator+= (time_duration rhs);
+};
+
+
+

is_negative()

+

Declared in "libtorrent/ptime.hpp"

+
+inline bool is_negative (time_duration dt);
+
+ +
+
+

operator+() operator-()

+

Declared in "libtorrent/ptime.hpp"

+
+inline ptime operator+ (time_duration lhs, ptime rhs);
+inline ptime operator+ (ptime lhs, time_duration rhs);
+inline time_duration operator- (ptime lhs, ptime rhs);
+inline ptime operator- (ptime lhs, time_duration rhs);
+
+
+
+

time_now()

+

Declared in "libtorrent/time.hpp"

+
+ptime const& time_now ();
+
+

returns the current time, as represented by ptime. The +resolution of this timer is about 100 ms.

+
+
+

time_now_hires()

+

Declared in "libtorrent/time.hpp"

+
+ptime time_now_hires ();
+
+

returns the current time as represented by ptime. This is +more expensive than time_now(), but provides as high resolution +as the operating system can provide.

+ +
+
+

min_time() max_time()

+

Declared in "libtorrent/time.hpp"

+
+ptime max_time ();
+ptime min_time ();
+
+

the earliest and latest possible time points +representable by ptime.

+ + + + +
+
+

microsec() minutes() hours() milliseconds() seconds()

+

Declared in "libtorrent/time.hpp"

+
+time_duration microsec (boost::int64_t s);
+time_duration seconds (boost::int64_t s);
+time_duration milliseconds (boost::int64_t s);
+time_duration minutes (boost::int64_t s);
+time_duration hours (boost::int64_t s);
+
+

returns a time_duration representing the specified number of seconds, milliseconds +microseconds, minutes and hours.

+ + +
+
+

total_seconds() total_microseconds() total_milliseconds()

+

Declared in "libtorrent/time.hpp"

+
+boost::int64_t total_seconds (time_duration td);
+boost::int64_t total_milliseconds (time_duration td);
+boost::int64_t total_microseconds (time_duration td);
+
+

returns the number of seconds, milliseconds and microseconds +a time_duration represents.

+
+
+
+ +
+ + +
+ + diff --git a/docs/reference-Utility.html b/docs/reference-Utility.html new file mode 100644 index 000000000..544251362 --- /dev/null +++ b/docs/reference-Utility.html @@ -0,0 +1,426 @@ + + + + + + +Utility + + + + + + + + +
+
+
+ +
+ +
+

Utility

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

Table of contents

+ +
+
+

bitfield

+

Declared in "libtorrent/bitfield.hpp"

+

The bitfiled type stores any number of bits as a bitfield +in a heap allocated or borrowed array.

+
+struct bitfield
+{
+   bitfield (int bits, bool val);
+   bitfield ();
+   bitfield (int bits);
+   bitfield (bitfield const& rhs);
+   bitfield (char const* b, int bits);
+   bitfield (bitfield&& rhs);
+   void borrow_bytes (char* b, int bits);
+   void assign (char const* b, int bits);
+   bool get_bit (int index) const;
+   bool operator[] (int index) const;
+   void clear_bit (int index);
+   void set_bit (int index);
+   bool all_set () const;
+   std::size_t size () const;
+   bool empty () const;
+   char const* bytes () const;
+   bitfield& operator= (bitfield const& rhs);
+   int count () const;
+};
+
+
+

bitfield()

+
+bitfield (int bits, bool val);
+bitfield ();
+bitfield (int bits);
+bitfield (bitfield const& rhs);
+bitfield (char const* b, int bits);
+
+

constructs a new bitfield. The default constructor creates an empty +bitfield. bits is the size of the bitfield (specified in bits). +`` val`` is the value to initialize the bits to. If not specified +all bits are initialized to 0.

+

The constructor taking a pointer b and bits copies a bitfield +from the specified buffer, and bits number of bits (rounded up to +the nearest byte boundry).

+
+
+

borrow_bytes()

+
+void borrow_bytes (char* b, int bits);
+
+

assigns a bitfield pointed to b of bits number of bits, without +taking ownership of the buffer. This is a way to avoid copying data and +yet provide a raw buffer to functions that may operate on the bitfield +type. It is the user's responsibility to make sure the passed-in buffer's +life time exceeds all uses of the bitfield.

+
+
+

assign()

+
+void assign (char const* b, int bits);
+
+

copy bitfield from buffer b of bits number of bits, rounded up to +the nearest byte boundary.

+ +
+
+

operator[]() get_bit()

+
+bool get_bit (int index) const;
+bool operator[] (int index) const;
+
+

query bit at index. Returns true if bit is 1, otherwise false.

+ +
+
+

set_bit() clear_bit()

+
+void clear_bit (int index);
+void set_bit (int index);
+
+

set bit at index to 0 (clear_bit) or 1 (set_bit).

+
+
+

all_set()

+
+bool all_set () const;
+
+

returns true if all bits in the bitfield are set

+
+
+

size()

+
+std::size_t size () const;
+
+

returns the size of the bitfield in bits.

+
+
+

empty()

+
+bool empty () const;
+
+

returns true if the bitfield has zero size.

+
+
+

bytes()

+
+char const* bytes () const;
+
+

returns a pointer to the internal buffer of the bitfield.

+
+
+

operator=()

+
+bitfield& operator= (bitfield const& rhs);
+
+

copy operator

+
+
+

count()

+
+int count () const;
+
+

count the number of bits in the bitfield that are set to 1.

+
+
+
+

sha1_hash

+

Declared in "libtorrent/sha1_hash.hpp"

+

This type holds a SHA-1 digest or any other kind of 20 byte +sequence. It implements a number of convenience functions, such +as bit operations, comparison operators etc.

+

In libtorrent it is primarily used to hold info-hashes, piece-hashes, +peer IDs, node IDs etc.

+
+class sha1_hash
+{
+   sha1_hash ();
+   static sha1_hash max ();
+   static sha1_hash min ();
+   explicit sha1_hash (char const* s);
+   void assign (char const* str);
+   explicit sha1_hash (std::string const& s);
+   void assign (std::string const& s);
+   void clear ();
+   bool is_all_zeros () const;
+   sha1_hash& operator<<= (int n);
+   sha1_hash& operator>>= (int n);
+   bool operator== (sha1_hash const& n) const;
+   bool operator!= (sha1_hash const& n) const;
+   bool operator< (sha1_hash const& n) const;
+   sha1_hash operator~ ();
+   sha1_hash operator^ (sha1_hash const& n) const;
+   sha1_hash& operator^= (sha1_hash const& n);
+   sha1_hash operator& (sha1_hash const& n) const;
+   sha1_hash& operator&= (sha1_hash const& n);
+   sha1_hash& operator|= (sha1_hash const& n);
+   unsigned char& operator[] (int i);
+   unsigned char const& operator[] (int i) const;
+   const_iterator begin () const;
+   iterator begin ();
+   iterator end ();
+   const_iterator end () const;
+   std::string to_string () const;
+
+   static const int size = number_size;
+};
+
+
+

sha1_hash()

+
+sha1_hash ();
+
+

constructs an all-sero sha1-hash

+
+
+

max()

+
+static sha1_hash max ();
+
+

returns an all-F sha1-hash. i.e. the maximum value +representable by a 160 bit number (20 bytes). This is +a static member function.

+
+
+

min()

+
+static sha1_hash min ();
+
+

returns an all-zero sha1-hash. i.e. the minimum value +representable by a 160 bit number (20 bytes). This is +a static member function.

+ +
+
+

assign() sha1_hash()

+
+explicit sha1_hash (char const* s);
+void assign (char const* str);
+explicit sha1_hash (std::string const& s);
+void assign (std::string const& s);
+
+

copies 20 bytes from the pointer provided, into the sha1-hash. +The passed in string MUST be at least 20 bytes. NULL terminators +are ignored, s is treated like a raw memory buffer.

+
+
+

clear()

+
+void clear ();
+
+

set the sha1-hash to all zeroes.

+
+
+

is_all_zeros()

+
+bool is_all_zeros () const;
+
+

return true if the sha1-hash is all zero.

+
+
+

operator<<=()

+
+sha1_hash& operator<<= (int n);
+
+

shift left n bits.

+
+
+

operator>>=()

+
+sha1_hash& operator>>= (int n);
+
+

shift r n bits.

+
+
+

operator==()

+
+bool operator== (sha1_hash const& n) const;
+
+

standard comparison operators

+
+
+

operator~()

+
+sha1_hash operator~ ();
+
+

negate every bit in the sha1-hash

+ +
+
+

operator^=() operator^()

+
+sha1_hash operator^ (sha1_hash const& n) const;
+sha1_hash& operator^= (sha1_hash const& n);
+
+

bit-wise XOR of the two sha1-hash.

+ +
+
+

operator&=() operator&()

+
+sha1_hash operator& (sha1_hash const& n) const;
+sha1_hash& operator&= (sha1_hash const& n);
+
+

bit-wise AND of the two sha1-hash.

+
+
+

operator|=()

+
+sha1_hash& operator|= (sha1_hash const& n);
+
+

bit-wise OR of the two sha1-hash.

+
+
+

operator[]()

+
+unsigned char& operator[] (int i);
+unsigned char const& operator[] (int i) const;
+
+

accessors for specific bytes

+ +
+
+

begin() end()

+
+const_iterator begin () const;
+iterator begin ();
+iterator end ();
+const_iterator end () const;
+
+

start and end iterators for the hash. The value type +of these iterators is unsigned char.

+
+
+

to_string()

+
+std::string to_string () const;
+
+

return a copy of the 20 bytes representing the sha1-hash as a std::string. +It's still a binary string with 20 binary characters.

+
+
number_size
+
the number of bytes of the number
+
+
+
+

identify_client()

+

Declared in "libtorrent/identify_client.hpp"

+
+std::string identify_client (const peer_id& p);
+
+

This function is declared in the header <libtorrent/identify_client.hpp>. It can can be used +to extract a string describing a client version from its peer-id. It will recognize most clients +that have this kind of identification in the peer-id.

+
+
+

client_fingerprint()

+

Declared in "libtorrent/identify_client.hpp"

+
+boost::optional<fingerprint> client_fingerprint (peer_id const& p);
+
+

Returns an optional fingerprint if any can be identified from the peer id. This can be used +to automate the identification of clients. It will not be able to identify peers with non- +standard encodings. Only Azureus style, Shadow's style and Mainline style. This function is +declared in the header <libtorrent/identify_client.hpp>.

+
+
+

operator<<()

+

Declared in "libtorrent/sha1_hash.hpp"

+
+inline std::ostream& operator<< (std::ostream& os, sha1_hash const& peer);
+
+

print a sha1_hash object to an ostream as 40 hexadecimal digits

+
+
+

operator>>()

+

Declared in "libtorrent/sha1_hash.hpp"

+
+inline std::istream& operator>> (std::istream& is, sha1_hash& peer);
+
+

read 40 hexadecimal digits from an istream into a sha1_hash

+
+
+

sleep()

+

Declared in "libtorrent/thread.hpp"

+
+void sleep (int milliseconds);
+
+

pauses the calling thread at least for the specified +number of milliseconds

+
+
+
+ +
+ + +
+ + diff --git a/docs/reference.html b/docs/reference.html new file mode 100644 index 000000000..3e3c2cee4 --- /dev/null +++ b/docs/reference.html @@ -0,0 +1,318 @@ + + + + + + +libtorrent reference documentation + + + + + + + +
+
+
+ +
+ +
+

libtorrent reference documentation

+ +
+ + + + +
+

Settings

+ +
+ +
+

Alerts

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+

Filter

+ +
+ + + + +
+
+ +
+ + +
+ + diff --git a/docs/rst.css b/docs/rst.css new file mode 100644 index 000000000..5e87b95d5 --- /dev/null +++ b/docs/rst.css @@ -0,0 +1,245 @@ +.document { + margin-left: 10px; + margin-right: 10px; +} + +.document a { + border: none; + color: black; +} + +.document a:hover { + background: none; +} + +.document a.reference { + color: #8D370A; + border-bottom: dotted 1px #8D370A; +} + +.document a.reference:hover { + border-bottom: solid 1px #8D370A; + background: #eee; +} + +div.section { + margin-bottom: 3em; +} + +div.section div.section div.section { + margin-bottom: 2em; +} + +h3 { text-transform: uppercase; } + +div.section p, div.section ul, div.section dl { +} + +table.docinfo { + text-align: left; + float: right; + width: 200px; + margin-right: 0px; + margin-left: 20px; + margin-bottom: 20px; +} + +table.docinfo th { + border-top: none; + font-size: 72%; + padding-left: 10px; +} + +table.docinfo td { + padding-left: 10px; + font-size: 88%; +} + +table.docinfo tr.field td, table.docinfo tr.field th {display: none;} + +h1.title { display: none; } + +dt { + font-size: 100%; + letter-spacing: 2px; + line-height: 1em; + color: #315586; + color: #000; + font-family: Tahoma; + font-weight: bold; +} + +dd { + line-height: 1.5em; + margin-left: 1em; + margin-bottom: 1em; + font-size: 92%; +} + +tt { + font: 1em "Courier New", "Courier"; + color: #315566; +} + +pre { + font-family: "Courier", monospace; + margin-right: 10px; + background: #C1E5F6; + border-left: solid 2px #6185A6; + border-right: solid 2px #6185A6; + padding: 5px 10px 5px 10px; + + background: #f6f6f6; + border: solid 1px #ddd; + margin: 1em 0; +} + +div.warning, div.note, div.important { + width: 80%; + margin: 1.5em auto; + background: #C1E5F6; + background: #F1FFF5; + border: solid 1px #D1DFD5; + padding: 5px 10px 5px 10px; +} + +p.admonition-title { + font-family: Georgia, "Lucida Grande"; + font-size: 128%; + letter-spacing: 2px; + text-transform: uppercase; + margin: 0 0 0.5em 0; + border-bottom: solid 1px #D1DFD5 +} + +div.sidebar { + background: #f8f8e8; + float: right; + width: 20em; + margin-right: 1em; + border: solid 1px #e5e5d5; + padding: 1.3em; +} + +div.sidebar p.sidebar-title { + font: 1.3em Georgia; + border-bottom: solid 1px #e5e5d5; + padding-bottom: 0.5em; + margin: 0 0 0.5em 0; +} + +h1 { font-size: 230%; } +h2 { font-size: 180%; } +h3 { font-size: 130%; } + +table { margin-bottom: 1em; border-collapse: collapse; } +table, th, td { border: none; } + +th, td { padding: 0.3em; } + +th { + text-align: left; + background: #f0f0e0; + border-right: solid 1px #f0f0e0; + border-top: solid 1px #e8e8d8; + border-bottom: solid 1px #e8e8d8; +} + +td { + background: #f8f8e8; + border-right: solid 1px #f8f8e8; + border-bottom: solid 1px #e8e8d8; +} + +td td { + background: #e8e8d8; + border-right: solid 1px #e8e8d8; + border-bottom: solid 1px #d8d8c8; +} + +div.topic { + border-left: solid 1px #eee; + padding-left: 1em; + margin: 0 0 1.5em; +} + +p.topic-title { + font: 1.3em Georgia, "Times New Roman", serif; +} + +/* TOC */ + +div.contents { + border: none; +} + +#table-of-contents { + margin-left: 20px; + padding: 0 0 1em; + width: 200px; + float: right; + clear: right; + background: url(../img/blue_bottom.png) no-repeat bottom left; + border-right: solid 1px #A1C5D6; +} + +#table-of-contents p { + font-family: Georgia, "Times New Roman", serif; + background: #A1C5D6 url(../img/blue_top.png) no-repeat top left; + color: #AD370A; + padding: 0.5em; + margin: 0; +} + +#table-of-contents li { + margin: 0 0.5em 0 0.5em; +} + +#table-of-contents ul { + margin: 0; + padding: 0 0 0 0.8em; + list-style: none; + text-align: left; + line-height: 1.5em; +} + +#table-of-contents ul ul { + background: url(../img/dotline.gif) repeat-y; +} + +#table-of-contents a.reference { + border: none; + font: 0.88em Tahoma; + font-weight: bold; + color: #000050; + margin-right: 1em; + background: url(../img/minus.gif) no-repeat left 50%; + padding-left: 15px; +} + +#table-of-contents li li a.reference { + font-weight: normal; + background: none; + padding: 0; +} + +#table-of-contents a.reference:hover {text-decoration: underline;} + +dd p { + font-size: 100%; +} + +dd pre { + font-size: 108.7%; +} + +li p, li li { font-size: 100%; } + +/* IE Hacks */ + +/* Hides from IE-mac \*/ +* html li pre { height: 1%; } +* html .topic pre { height: 1%; } +* html #table-of-contents ul ul { height: 1%; } +/* End hide from IE-mac */ + diff --git a/docs/todo.html b/docs/todo.html index 0d42460bc..ba3453c71 100644 --- a/docs/todo.html +++ b/docs/todo.html @@ -21,10 +21,10 @@

libtorrent todo-list

-3 important +4 important 5 relevant 15 feasible -41 notes +40 notes
relevance 4../src/session_impl.cpp:663in order to support SSL over uTP, the utp_socket manager either needs to be able to receive packets on multiple ports, or we need to peek into the first few bytes the payload stream of a socket to determine whether or not it's an SSL connection. (The former is simpler but won't do as well with NATs)
relevance 3../include/libtorrent/kademlia/find_data.hpp:60rename this class to get_peers, since that's what it does find_data is an unnecessarily generic name
relevance 3../src/kademlia/node.cpp:328if uTP is enabled, we should say "implied_port": 1
relevance 3../include/libtorrent/kademlia/find_data.hpp:60rename this class to get_peers, since that's what it does find_data is an unnecessarily generic name
relevance 2../src/torrent.cpp:8258will pick_pieces ever return an empty set?
relevance 2../src/torrent.cpp:8258will pick_pieces ever return an empty set?
relevance 2../src/utp_stream.cpp:1862we might want to do something else here as well, to resend the packet immediately without it being an MTU probe
relevance 2../src/utp_stream.cpp:1862we might want to do something else here as well, to resend the packet immediately without it being an MTU probe
relevance 2../src/utp_stream.cpp:2505sequence number, source IP and connection ID should be verified before accepting a reset packet
relevance 2../src/web_peer_connection.cpp:546create a mapping of file-index to redirection URLs. Use that to form URLs instead. Support to reconnect to a new server without destructing this peer_connection
relevance 2../src/web_peer_connection.cpp:546create a mapping of file-index to redirection URLs. Use that to form URLs instead. Support to reconnect to a new server without destructing this peer_connection
relevance 2../src/kademlia/node.cpp:69make this configurable in dht_settings
relevance 2../src/kademlia/node.cpp:69make this configurable in dht_settings
relevance 1../src/http_seed_connection.cpp:117in chunked encoding mode, this assert won't hold. the chunk headers should be subtracted from the receive_buffer_size
relevance 1../src/http_seed_connection.cpp:117in chunked encoding mode, this assert won't hold. the chunk headers should be subtracted from the receive_buffer_size
relevance 1../src/peer_connection.cpp:2570peers should really be corked/uncorked outside of all completed disk operations
relevance 1../src/peer_connection.cpp:2570peers should really be corked/uncorked outside of all completed disk operations
relevance 1../src/session_impl.cpp:5553report the proper address of the router as the source IP of this understanding of our external address, instead of the empty address
relevance 1../src/session_impl.cpp:5553report the proper address of the router as the source IP of this understanding of our external address, instead of the empty address
relevance 1../src/session_impl.cpp:5763report errors as alerts
relevance 1../src/session_impl.cpp:5763report errors as alerts
relevance 1../src/session_impl.cpp:6234we only need to do this if our global IPv4 address has changed since the DHT (currently) only supports IPv4. Since restarting the DHT is kind of expensive, it would be nice to not do it unnecessarily
relevance 1../src/session_impl.cpp:6234we only need to do this if our global IPv4 address has changed since the DHT (currently) only supports IPv4. Since restarting the DHT is kind of expensive, it would be nice to not do it unnecessarily
relevance 1../src/torrent.cpp:1043make this depend on the error and on the filesystem the files are being downloaded to. If the error is no_space_left_on_device and the filesystem doesn't support sparse files, only zero the priorities of the pieces that are at the tails of all files, leaving everything up to the highest written piece in each file
relevance 1../src/torrent.cpp:1043make this depend on the error and on the filesystem the files are being downloaded to. If the error is no_space_left_on_device and the filesystem doesn't support sparse files, only zero the priorities of the pieces that are at the tails of all files, leaving everything up to the highest written piece in each file
relevance 1../src/torrent.cpp:5330save the send_stats state instead of throwing them away it may pose an issue when downgrading though
relevance 1../src/torrent.cpp:5330save the send_stats state instead of throwing them away it may pose an issue when downgrading though
relevance 1../src/torrent.cpp:6236should disconnect all peers that have the pieces we have not just seeds. It would be pretty expensive to check all pieces for all peers though
relevance 1../src/torrent.cpp:6236should disconnect all peers that have the pieces we have not just seeds. It would be pretty expensive to check all pieces for all peers though
relevance 1../src/torrent_info.cpp:181we might save constructing a std::string if this would take a char const* instead
relevance 1../src/torrent_info.cpp:401this logic should be a separate step done once the torrent is loaded, and the original filenames should be preserved!
relevance 1../src/torrent_info.cpp:437once the filename renaming is removed from here this check can be removed as well
relevance 1../src/torrent_info.cpp:437once the filename renaming is removed from here this check can be removed as well
relevance 1../src/kademlia/node.cpp:772find_node should write directly to the response entry
relevance 1../src/kademlia/node.cpp:782find_node should write directly to the response entry
relevance 1../include/libtorrent/ip_voter.hpp:100instead, have one instance per possible subnet, global IPv4, global IPv6, loopback, 192.168.x.x, 10.x.x.x, etc.
relevance 1../include/libtorrent/ip_voter.hpp:100instead, have one instance per possible subnet, global IPv4, global IPv6, loopback, 192.168.x.x, 10.x.x.x, etc.
relevance 1../include/libtorrent/utp_stream.hpp:378implement blocking write. Low priority since it's not used (yet)
relevance 1../include/libtorrent/utp_stream.hpp:378implement blocking write. Low priority since it's not used (yet)
relevance 1../include/libtorrent/web_peer_connection.hpp:126if we make this be a disk_buffer_holder instead we would save a copy sometimes use allocate_disk_receive_buffer and release_disk_receive_buffer
relevance 1../include/libtorrent/web_peer_connection.hpp:126if we make this be a disk_buffer_holder instead we would save a copy sometimes use allocate_disk_receive_buffer and release_disk_receive_buffer
relevance 0../src/bt_peer_connection.cpp:615this could be optimized using knuth morris pratt
relevance 0../src/bt_peer_connection.cpp:621this could be optimized using knuth morris pratt
relevance 0../src/bt_peer_connection.cpp:2081if we're finished, send upload_only message
relevance 0../src/bt_peer_connection.cpp:2085if we're finished, send upload_only message
relevance 0../src/bt_peer_connection.cpp:3323move the erasing into the loop above remove all payload ranges that has been sent
relevance 0../src/bt_peer_connection.cpp:3325move the erasing into the loop above remove all payload ranges that has been sent
relevance 0../src/file.cpp:1370is there any way to pre-fetch data from a file on windows?
relevance 0../src/file.cpp:1370is there any way to pre-fetch data from a file on windows?
relevance 0../src/http_tracker_connection.cpp:99support authentication (i.e. user name and password) in the URL
relevance 0../src/http_tracker_connection.cpp:99support authentication (i.e. user name and password) in the URL
relevance 0../src/i2p_stream.cpp:204move this to proxy_base and use it in all proxies
relevance 0../src/i2p_stream.cpp:204move this to proxy_base and use it in all proxies
relevance 0../src/packet_buffer.cpp:176use compare_less_wrap for this comparison as well
relevance 0../src/packet_buffer.cpp:176use compare_less_wrap for this comparison as well
relevance 0../src/peer_connection.cpp:2733this might need something more so that once we have the metadata we can construct a full bitfield
relevance 0../src/peer_connection.cpp:2733this might need something more so that once we have the metadata we can construct a full bitfield
relevance 0../src/peer_connection.cpp:2864sort the allowed fast set in priority order
relevance 0../src/peer_connection.cpp:2864sort the allowed fast set in priority order
relevance 0../src/peer_connection.cpp:4584peers should really be corked/uncorked outside of all completed disk operations
relevance 0../src/peer_connection.cpp:4584peers should really be corked/uncorked outside of all completed disk operations
relevance 0../src/policy.cpp:857only allow _one_ connection to use this override at a time
relevance 0../src/policy.cpp:857only allow _one_ connection to use this override at a time
relevance 0../src/policy.cpp:1902how do we deal with our external address changing? Pass in a force-update maybe? and keep a version number in policy
relevance 0../src/session_impl.cpp:1764recalculate all connect candidates for all torrents
relevance 0../src/session_impl.cpp:3227have a separate list for these connections, instead of having to loop through all of them
relevance 0../src/session_impl.cpp:4317allow extensions to sort torrents for queuing
relevance 0../src/session_impl.cpp:4473use a lower limit than m_settings.connections_limit to allocate the to 10% or so of connection slots for incoming connections
relevance 0../src/session_impl.cpp:4508also take average_peers into account, to create a bias for downloading torrents with < average peers
relevance 0../src/session_impl.cpp:4507make this bias configurable
relevance 0../src/session_impl.cpp:4508also take average_peers into account, to create a bias for downloading torrents with < average peers
relevance 0../src/session_impl.cpp:4652make configurable
relevance 0../src/session_impl.cpp:4666make configurable
relevance 0../src/storage.cpp:324if the read fails, set error and exit immediately
relevance 0../src/storage.cpp:324if the read fails, set error and exit immediately
relevance 0../src/storage.cpp:358if the read fails, set error and exit immediately
relevance 0../src/storage.cpp:629make this more generic to not just work if files have been renamed, but also if they have been merged into a single file for instance maybe use the same format as .torrent files and reuse some code from torrent_info
relevance 0../src/storage.cpp:1246what if file_base is used to merge several virtual files into a single physical file? We should probably disable this if file_base is used. This is not a widely used feature though
relevance 0../src/storage.cpp:1246what if file_base is used to merge several virtual files into a single physical file? We should probably disable this if file_base is used. This is not a widely used feature though
relevance 0../src/torrent.cpp:1245is verify_peer_cert called once per certificate in the chain, and this function just tells us which depth we're at right now? If so, the comment makes sense. any certificate that isn't the leaf (i.e. the one presented by the peer) should be accepted automatically, given preverified is true. The leaf certificate need to be verified to make sure its DN matches the info-hash
relevance 0../src/torrent.cpp:1245is verify_peer_cert called once per certificate in the chain, and this function just tells us which depth we're at right now? If so, the comment makes sense. any certificate that isn't the leaf (i.e. the one presented by the peer) should be accepted automatically, given preverified is true. The leaf certificate need to be verified to make sure its DN matches the info-hash
relevance 0../src/torrent.cpp:5063make this more generic to not just work if files have been renamed, but also if they have been merged into a single file for instance maybe use the same format as .torrent files and reuse some code from torrent_info The mapped_files needs to be read both in the network thread and in the disk thread, since they both have their own mapped files structures which are kept in sync
relevance 0../src/torrent.cpp:5063make this more generic to not just work if files have been renamed, but also if they have been merged into a single file for instance maybe use the same format as .torrent files and reuse some code from torrent_info The mapped_files needs to be read both in the network thread and in the disk thread, since they both have their own mapped files structures which are kept in sync
relevance 0../src/torrent.cpp:5199if this is a merkle torrent and we can't restore the tree, we need to wipe all the bits in the have array, but not necessarily we might want to do a full check to see if we have all the pieces. This is low priority since almost no one uses merkle torrents
relevance 0../src/torrent.cpp:5387make this more generic to not just work if files have been renamed, but also if they have been merged into a single file for instance. using file_base
relevance 0../src/torrent.cpp:5387make this more generic to not just work if files have been renamed, but also if they have been merged into a single file for instance. using file_base
relevance 0../src/torrent.cpp:7937go through the pieces we have and count the total number of downloaders we have. Only count peers that are interested in us since some peers might not send have messages for pieces we have it num_interested == 0, we need to pick a new piece
relevance 0../src/udp_tracker_connection.cpp:550it would be more efficient to not use a string here. however, the problem is that some trackers will respond with actual strings. For example i2p trackers
relevance 0../src/udp_tracker_connection.cpp:550it would be more efficient to not use a string here. however, the problem is that some trackers will respond with actual strings. For example i2p trackers
relevance 0../src/utp_stream.cpp:1573this loop may not be very efficient
relevance 0../src/utp_stream.cpp:1573this loop may not be very efficient
relevance 0../src/kademlia/routing_table.cpp:291instad of refreshing a bucket by using find_nodes, ping each node periodically
relevance 0../src/kademlia/routing_table.cpp:293instad of refreshing a bucket by using find_nodes, ping each node periodically
relevance 0../include/libtorrent/config.hpp:326Make this count Unicode characters instead of bytes on windows
relevance 0../include/libtorrent/config.hpp:326Make this count Unicode characters instead of bytes on windows
relevance 0../include/libtorrent/entry.hpp:231could this be removed?
relevance 0../include/libtorrent/peer_connection.hpp:729make this private