<li>supports an <aclass="reference"href="extension_protocol.html">extension protocol</a>. See <aclass="reference"href="#extensions">extensions</a>.</li>
<p>To acquire the latest version of libtorrent, you'll have to grab it from CVS.
You'll find instructions on how to do this <aclass="reference"href="http://sourceforge.net/cvs/?group_id=79942">here</a> (see Anonymous CVS access).</p>
<p>The build systems supported "out of the box" in libtorrent are boost-build v2
(BBv2) and autotools (for unix-like systems). If you still can't build after
following these instructions, you can usually get help in the <ttclass="docutils literal"><spanclass="pre">#libtorrent</span></tt>
IRC channel on <ttclass="docutils literal"><spanclass="pre">irc.freenode.net</span></tt>.</p>
<divclass="section"id="building-with-bbv2">
<h2><aname="building-with-bbv2">building with BBv2</a></h2>
<p>The primary reason to use boost-build is that it will automatically build the
dependent boost libraries with the correct compiler settings, in order to
ensure that the build targets are link compatible (see <aclass="reference"href="http://boost.org/more/separate_compilation.html">boost guidelines</a>
for some details on this issue).</p>
<p>Since BBv2 will build the boost libraries for you, you need the full boost
source package. Having boost installed via some package system is usually not
enough (and even if it is enough, the necessary environment variables are
<p>First you need to build <ttclass="docutils literal"><spanclass="pre">bjam</span></tt>. You do this by opening a terminal (In
windows, run <ttclass="docutils literal"><spanclass="pre">cmd</span></tt>). Change directory to
<ttclass="docutils literal"><spanclass="pre">c:\boost_1_33_0\tools\build\jam_src</span></tt>. Then run the script called
<ttclass="docutils literal"><spanclass="pre">build.bat</span></tt> or <ttclass="docutils literal"><spanclass="pre">build.sh</span></tt> on a unix system. This will build <ttclass="docutils literal"><spanclass="pre">bjam</span></tt> and
place it in a directory starting with <ttclass="docutils literal"><spanclass="pre">bin.</span></tt> and then have the name of your
platform. Copy the <ttclass="docutils literal"><spanclass="pre">bjam.exe</span></tt> (or <ttclass="docutils literal"><spanclass="pre">bjam</span></tt> on a unix system) to a place
that's in you shell's <ttclass="docutils literal"><spanclass="pre">PATH</span></tt>. On linux systems a place commonly used may be
<ttclass="docutils literal"><spanclass="pre">/usr/local/bin</span></tt> or on windows <ttclass="docutils literal"><spanclass="pre">c:\windows</span></tt> (you can also add directories
to the search paths by modifying the environment variable called <ttclass="docutils literal"><spanclass="pre">PATH</span></tt>).</p>
<p>Now you have <ttclass="docutils literal"><spanclass="pre">bjam</span></tt> installed. <ttclass="docutils literal"><spanclass="pre">bjam</span></tt> can be considered an interpreter
that the boost-build system is implemented on. So boost-build uses <ttclass="docutils literal"><spanclass="pre">bjam</span></tt>.
So, to complete the installation you need to make two more things. You need to
set the environment variable <ttclass="docutils literal"><spanclass="pre">BOOST_BUILD_PATH</span></tt>. This is the path that tells
<ttclass="docutils literal"><spanclass="pre">bjam</span></tt> where it can find boost-build, your configuration file and all the
toolsets (descriptions used by boost-build to know how to use different
compilers on different platforms). Assuming the boost install path above, set
it to <ttclass="docutils literal"><spanclass="pre">c:\boost_1_33_0\tools\build\v2</span></tt>.</p>
<p>The last thing to do to complete the setup of BBv2 is to modify your
<ttclass="docutils literal"><spanclass="pre">user-config.jam</span></tt> file. It is located in <ttclass="docutils literal"><spanclass="pre">c:\boost_1_33\tools\build\v2</span></tt>.
Depending on your platform and which compiler you're using, you should add a
line for each compiler and compiler version you have installed on your system
that you want to be able to use with BBv2. For example, if you're using
Microsoft Visual Studio 7.1 (2003), just add a line:</p>
<preclass="literal-block">
using msvc : 7.1 ;
</pre>
<p>If you use GCC, add the line:</p>
<preclass="literal-block">
using gcc ;
</pre>
<p>If you have more than one version of GCC installed, you can add the
commandline used to invoke g++ after the version number, like this:</p>
<preclass="literal-block">
using gcc : 3.3 : g++-3.3 ;
using gcc : 4.0 : g++-4.0 ;
</pre>
<p>Another toolset worth mentioning is the <ttclass="docutils literal"><spanclass="pre">darwin</span></tt> toolset (For MacOS X).
From Tiger (10.4) MacOS X comes with both GCC 3.3 and GCC 4.0. Then you can
use the following toolsets:</p>
<preclass="literal-block">
using darwin : 3.3 : g++-3.3 ;
using darwin : 4.0 : g++-4.0 ;
</pre>
<p>Note that the spaces around the semi-colons and colons are important!</p>
<p>To build different versions you can also just add the name of the build
variant. Some default build variants in BBv2 are <ttclass="docutils literal"><spanclass="pre">release</span></tt>, <ttclass="docutils literal"><spanclass="pre">debug</span></tt>,
<p>You can build libtorrent as a dll too, by typing <ttclass="docutils literal"><spanclass="pre">link=shared</span></tt>, or
<ttclass="docutils literal"><spanclass="pre">link=static</span></tt> to build a static library. <ttclass="docutils literal"><spanclass="pre">link=shared</span></tt> is the default.</p>
<p>If you want to explicitly say how to link against the runtime library, you
can set the <ttclass="docutils literal"><spanclass="pre">runtime-link</span></tt> feature on the commandline, either to <ttclass="docutils literal"><spanclass="pre">shared</span></tt>
or <ttclass="docutils literal"><spanclass="pre">static</span></tt>. Most operating systems will only allow linking shared against
the runtime, but on windows you can do both. Example:</p>
Also, make sure the paths are correct in the different environments. In cygwin, the paths
(<ttclass="docutils literal"><spanclass="pre">BOOST_BUILD_PATH</span></tt> and <ttclass="docutils literal"><spanclass="pre">BOOST_ROOT</span></tt>) should be in the typical unix-format (e.g.
<ttclass="docutils literal"><spanclass="pre">/cygdrive/c/boost_1_33_0</span></tt>). In the windows environment, they should have the typical
windows format (<ttclass="docutils literal"><spanclass="pre">c:/boost_1_33_0</span></tt>).</p>
<p>The <ttclass="docutils literal"><spanclass="pre">Jamfile</span></tt> will define <ttclass="docutils literal"><spanclass="pre">NDEBUG</span></tt> when it's building a release build.
There are two other build variants available in the <ttclass="docutils literal"><spanclass="pre">Jamfile</span></tt>. debug_log
and release_log, these two variants inherits from the debug and release
For more build configuration flags see <aclass="reference"href="#build-configurations">Build configurations</a>.</p>
<p>The <ttclass="docutils literal"><spanclass="pre">Jamfile</span></tt> has the following build variants:</p>
<blockquote>
<ulclass="simple">
<li><ttclass="docutils literal"><spanclass="pre">release</span></tt> - release version without any logging</li>
<li><ttclass="docutils literal"><spanclass="pre">release_log</span></tt> - release version with standard logging</li>
<li><ttclass="docutils literal"><spanclass="pre">release_vlog</span></tt> - release version with verbose logging (all peer connections are logged)</li>
<li><ttclass="docutils literal"><spanclass="pre">debug</span></tt> - debug version without any logging</li>
<li><ttclass="docutils literal"><spanclass="pre">debug_log</span></tt> - debug version with standard logging</li>
<li><ttclass="docutils literal"><spanclass="pre">debug_vlog</span></tt> - debug version with verbose logging</li>
</ul>
</blockquote>
</div>
</div>
<divclass="section"id="building-with-autotools">
<h2><aname="building-with-autotools">building with autotools</a></h2>
<p>First of all, you need to install <ttclass="docutils literal"><spanclass="pre">automake</span></tt> and <ttclass="docutils literal"><spanclass="pre">autoconf</span></tt>. Many
may not be the case. For example when installing boost on darwin using
darwinports (the package system based on BSD ports) all libraries are
installed to <ttclass="docutils literal"><spanclass="pre">/opt/local/lib</span></tt> and headers are installed to
<ttclass="docutils literal"><spanclass="pre">/opt/local/include</span></tt>. By default the compiler will not look in these
directories. You have to set the enviornment variables <ttclass="docutils literal"><spanclass="pre">LDFLAGS</span></tt> and
<ttclass="docutils literal"><spanclass="pre">CXXFLAGS</span></tt> in order to make the compiler find those libs. In this example
you'd set them like this:</p>
<preclass="literal-block">
export LDFLAGS=-L/opt/local/lib
export CXXFLAGS=-I/opt/local/include
</pre>
<p>If you need to set these variables, it may be a good idea to add those lines
to your <ttclass="docutils literal"><spanclass="pre">~/.profile</span></tt> or <ttclass="docutils literal"><spanclass="pre">~/.tcshrc</span></tt> depending on your shell.</p>
<p>You know that the boost libraries were found if you see the following output
from the configure script:</p>
<preclass="literal-block">
checking whether the Boost::DateTime library is available... yes
checking for main in -lboost_date_time... yes
checking whether the Boost::Filesystem library is available... yes
checking for main in -lboost_filesystem... yes
checking whether the Boost::Thread library is available... yes
checking for main in -lboost_thread... yes
</pre>
<p>Another possible source of problems may be if the path to your libtorrent
directory contains spaces. Make sure you either rename the directories with
spaces in their names to remove the spaces or move the libtorrent directory.</p>
<p>If you're making your own project file, note that there are two versions of
the file abstraction. There's one <ttclass="docutils literal"><spanclass="pre">file_win.cpp</span></tt> which relies on windows
file API that supports files larger than 2 Gigabytes. This does not work in
vc6 for some reason, possibly because it may require windows NT and above.
The other file, <ttclass="docutils literal"><spanclass="pre">file.cpp</span></tt> is the default implementation that simply relies
on the standard low level io routines (<ttclass="docutils literal"><spanclass="pre">read()</span></tt>, <ttclass="docutils literal"><spanclass="pre">write()</span></tt>, <ttclass="docutils literal"><spanclass="pre">open()</span></tt>
etc.), this implementation doesn't do anything special to support unicode
filenames, so if your target is Windows 2000 and up, you may want to use
<ttclass="docutils literal"><spanclass="pre">file_win.cpp</span></tt> which supports unicode filenames.</p>
<p>If you're building in MS Visual Studio, you may have to set the compiler
options "force conformance in for loop scope", "treat wchar_t as built-in
type" and "Enable Run-Time Type Info" to Yes.</p>
<p>You add torrents through the <ttclass="docutils literal"><spanclass="pre">add_torrent()</span></tt> function where you give an
object representing the information found in the torrent file and the path where you
want to save the files. The <ttclass="docutils literal"><spanclass="pre">save_path</span></tt> will be prepended to the directory
structure in the torrent-file.</p>
<p>If the torrent you are trying to add already exists in the session (is either queued
for checking, being checked or downloading) <ttclass="docutils literal"><spanclass="pre">add_torrent()</span></tt> will throw
<aclass="reference"href="#duplicate-torrent">duplicate_torrent</a> which derives from <ttclass="docutils literal"><spanclass="pre">std::exception</span></tt>.</p>
is available. The fast-resume data can be acquired from a running torrent by calling
<ttclass="docutils literal"><spanclass="pre">torrent_handle::write_resume_data()</span></tt>. See <aclass="reference"href="#fast-resume">fast resume</a>.</p>
<p>The <aclass="reference"href="#torrent-handle">torrent_handle</a> returned by <ttclass="docutils literal"><spanclass="pre">add_torrent()</span></tt> can be used to retrieve information
about the torrent's progress, its peers etc. It is also used to abort a torrent.</p>
<p><ttclass="docutils literal"><spanclass="pre">status()</span></tt> returns session wide-statistics and status. The <ttclass="docutils literal"><spanclass="pre">session_status</span></tt>
struct has the following members:</p>
<preclass="literal-block">
struct session_status
{
bool has_incoming_connections;
float upload_rate;
float download_rate;
float payload_upload_rate;
float payload_download_rate;
size_type total_download;
size_type total_upload;
size_type total_payload_download;
size_type total_payload_upload;
int num_peers;
};
</pre>
<p><ttclass="docutils literal"><spanclass="pre">has_incoming_connections</span></tt> is false as long as no incoming connections have been
established on the listening socket. Every time you change the listen port, this will
be reset to false.</p>
<p><ttclass="docutils literal"><spanclass="pre">upload_rate</span></tt>, <ttclass="docutils literal"><spanclass="pre">download_rate</span></tt>, <ttclass="docutils literal"><spanclass="pre">payload_download_rate</span></tt> and <ttclass="docutils literal"><spanclass="pre">payload_upload_rate</span></tt>
are the total download and upload rates accumulated from all torrents. The payload
versions is the payload download only.</p>
<p><ttclass="docutils literal"><spanclass="pre">total_download</span></tt> and <ttclass="docutils literal"><spanclass="pre">total_upload</span></tt> are the total number of bytes downloaded and
uploaded to and from all torrents. <ttclass="docutils literal"><spanclass="pre">total_payload_download</span></tt> and <ttclass="docutils literal"><spanclass="pre">total_payload_upload</span></tt>
are the same thing but where only the payload is considered.</p>
<p><ttclass="docutils literal"><spanclass="pre">num_peers</span></tt> is the total number of peer connections this session have.</p>
<p><ttclass="docutils literal"><spanclass="pre">pop_alert()</span></tt> is used to ask the session if any errors or events has occured. With
<ttclass="docutils literal"><spanclass="pre">set_severity_level()</span></tt> you can filter how serious the event has to be for you to
receive it through <ttclass="docutils literal"><spanclass="pre">pop_alert()</span></tt>. For information, see <aclass="reference"href="#alerts">alerts</a>.</p>
</div>
</div>
<divclass="section"id="entry">
<h1><aname="entry">entry</a></h1>
<p>The <ttclass="docutils literal"><spanclass="pre">entry</span></tt> class represents one node in a bencoded hierarchy. It works as a
variant type, it can be either a list, a dictionary (<ttclass="docutils literal"><spanclass="pre">std::map</span></tt>), an integer
are accessors that return the respecive type. If the <ttclass="docutils literal"><spanclass="pre">entry</span></tt> object isn't of the
type you request, the accessor will throw <aclass="reference"href="#type-error">type_error</a> (which derives from
<ttclass="docutils literal"><spanclass="pre">std::runtime_error</span></tt>). You can ask an <ttclass="docutils literal"><spanclass="pre">entry</span></tt> for its type through the
<p>The default constructor of <ttclass="docutils literal"><spanclass="pre">torrent_info</span></tt> is used when creating torrent files. It will
initialize the object to an empty torrent, containing no files. The info hash will be set
to 0 when this constructor is used. To use the empty <ttclass="docutils literal"><spanclass="pre">torrent_info</span></tt> object, add files
and piece hashes, announce URLs and optionally a creator tag and comment. To do this you
use the members <ttclass="docutils literal"><spanclass="pre">set_comment()</span></tt>, <ttclass="docutils literal"><spanclass="pre">set_piece_size()</span></tt>, <ttclass="docutils literal"><spanclass="pre">set_creator()</span></tt>, <ttclass="docutils literal"><spanclass="pre">set_hash()</span></tt>
etc.</p>
<p>The contructor that takes an info-hash is identical to the default constructor with the
exception that it will initialize the info-hash to the given value. 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.</p>
<p>The last constructor is the one that is used in most cases. It will create a <ttclass="docutils literal"><spanclass="pre">torrent_info</span></tt>
object from the information found in the given torrent_file. The <ttclass="docutils literal"><spanclass="pre">entry</span></tt> represents a tree
node in an bencoded file. To load an ordinary .torrent file into an <ttclass="docutils literal"><spanclass="pre">entry</span></tt>, use bdecode(),
see <aclass="reference"href="#bdecode-bencode">bdecode() bencode()</a>.</p>
<p><ttclass="docutils literal"><spanclass="pre">set_hash()</span></tt> writes the hash for the piece with the given piece-index. You have to call
this function for every piece in the torrent. Usually the <aclass="reference"href="#hasher">hasher</a> is used to calculate
the sha1-hash for a piece.</p>
<p><ttclass="docutils literal"><spanclass="pre">add_tracker()</span></tt> adds a tracker to the announce-list. The <ttclass="docutils literal"><spanclass="pre">tier</span></tt> determines the order in
which the trackers are to be tried. For more iformation see <aclass="reference"href="#trackers">trackers()</a>.</p>
<p><ttclass="docutils literal"><spanclass="pre">add_file()</span></tt> adds a file to the torrent. The order in which you add files will determine
the order in which they are placed in the torrent file. You have to add at least one file
to the torrent. The <ttclass="docutils literal"><spanclass="pre">path</span></tt> you give has to be a relative path from the root directory
of the torrent. The <ttclass="docutils literal"><spanclass="pre">size</span></tt> is given in bytes.</p>
<p>When you have added all the files and hashes to your torrent, you can generate an <ttclass="docutils literal"><spanclass="pre">entry</span></tt>
which then can be encoded as a .torrent file. You do this by calling <aclass="reference"href="#create-torrent">create_torrent()</a>.</p>
<p>For a complete example of how to create a torrent from a file structure, see <aclass="reference"href="#make-torrent">make_torrent</a>.</p>
<p>This class will need some explanation. First of all, to get a list of all files
in the torrent, you can use <ttclass="docutils literal"><spanclass="pre">begin_files()</span></tt>, <ttclass="docutils literal"><spanclass="pre">end_files()</span></tt>,
<ttclass="docutils literal"><spanclass="pre">rbegin_files()</span></tt> and <ttclass="docutils literal"><spanclass="pre">rend_files()</span></tt>. These will give you standard vector
iterators with the type <ttclass="docutils literal"><spanclass="pre">file_entry</span></tt>.</p>
<p>If you need index-access to files you can use the <ttclass="docutils literal"><spanclass="pre">num_files()</span></tt> and <ttclass="docutils literal"><spanclass="pre">file_at()</span></tt>
to access files using indices.</p>
</div>
<divclass="section"id="print">
<h2><aname="print">print()</a></h2>
<blockquote>
<preclass="literal-block">
void print(std::ostream& os) const;
</pre>
</blockquote>
<p>The <ttclass="docutils literal"><spanclass="pre">print()</span></tt> function is there for debug purposes only. It will print the info from
<p>The <ttclass="docutils literal"><spanclass="pre">trackers()</span></tt> function will return a sorted vector of <ttclass="docutils literal"><spanclass="pre">announce_entry</span></tt>.
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.</p>
<p><ttclass="docutils literal"><spanclass="pre">total_size()</span></tt>, <ttclass="docutils literal"><spanclass="pre">piece_length()</span></tt> and <ttclass="docutils literal"><spanclass="pre">num_pieces()</span></tt> 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
<ttclass="docutils literal"><spanclass="pre">piece_size()</span></tt> and <ttclass="docutils literal"><spanclass="pre">piece_length()</span></tt> is that <ttclass="docutils literal"><spanclass="pre">piece_size()</span></tt> takes
the piece index as argument and gives you the exact size of that piece. It will always
be the same as <ttclass="docutils literal"><spanclass="pre">piece_length()</span></tt> except in the case of the last piece, which may
<p><ttclass="docutils literal"><spanclass="pre">hash_for_piece()</span></tt> takes a piece-index and returns the 20-bytes sha1-hash for that
piece and <ttclass="docutils literal"><spanclass="pre">info_hash()</span></tt> returns the 20-bytes sha1-hash for the info-section of the
torrent file. For more information on the <ttclass="docutils literal"><spanclass="pre">sha1_hash</span></tt>, see the <aclass="reference"href="#big-number">big_number</a> class.</p>
<p><ttclass="docutils literal"><spanclass="pre">name()</span></tt> returns the name of the torrent.</p>
<p><ttclass="docutils literal"><spanclass="pre">comment()</span></tt> returns the comment associated with the torrent. If there's no comment,
it will return an empty string. <ttclass="docutils literal"><spanclass="pre">creation_date()</span></tt> returns a <aclass="reference"href="http://www.boost.org/libs/date_time/doc/class_ptime.html">boost::posix_time::ptime</a>
object, representing the time when this torrent file was created. If there's no timestamp
in the torrent file, this will return a date of january 1:st 1970.</p>
<p><ttclass="docutils literal"><spanclass="pre">save_path()</span></tt> returns the path that was given to <aclass="reference"href="#add-torrent">add_torrent()</a> when this torrent
<p><ttclass="docutils literal"><spanclass="pre">set_upload_limit</span></tt> 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.
<ttclass="docutils literal"><spanclass="pre">set_download_limit</span></tt> 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 (<ttclass="docutils literal"><spanclass="pre">session::set_upload_rate_limit</span></tt>)
will not override the global rate limit. The torrent can never upload more than the global rate
<p><ttclass="docutils literal"><spanclass="pre">pause()</span></tt>, and <ttclass="docutils literal"><spanclass="pre">resume()</span></tt> 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. You can use <ttclass="docutils literal"><spanclass="pre">is_paused()</span></tt> to determine if a torrent
is currently paused. Torrents may be paused automatically if there is a file error (eg. disk full)
or something similar. See <aclass="reference"href="#file-error-alert">file_error_alert</a>.</p>
</div>
<divclass="section"id="is-seed">
<h2><aname="is-seed">is_seed()</a></h2>
<blockquote>
<preclass="literal-block">
bool is_seed() const;
</pre>
</blockquote>
<p>Returns true if the torrent is in seed mode (i.e. if it has finished downloading).</p>
</div>
<divclass="section"id="has-metadata">
<h2><aname="has-metadata">has_metadata()</a></h2>
<blockquote>
<preclass="literal-block">
bool has_metadata() const;
</pre>
</blockquote>
<p>Returns 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 return false is when the torrent
was started torrent-less (i.e. with just an info-hash and tracker ip). Note that if the torrent
doesn't have metadata, the member <aclass="reference"href="#get-torrent-info">get_torrent_info()</a> will throw.</p>
<p><ttclass="docutils literal"><spanclass="pre">set_tracker_login()</span></tt> 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.</p>
<p><ttclass="docutils literal"><spanclass="pre">set_max_uploads()</span></tt> 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.</p>
<p><ttclass="docutils literal"><spanclass="pre">set_max_connections()</span></tt> 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
<p><ttclass="docutils literal"><spanclass="pre">write_resume_data()</span></tt> generates fast-resume data and returns it as an <aclass="reference"href="#entry">entry</a>. This <aclass="reference"href="#entry">entry</a>
is suitable for being bencoded. For more information about how fast-resume works, see <aclass="reference"href="#fast-resume">fast resume</a>.</p>
<p>There are three cases where this function will just return an empty <ttclass="docutils literal"><spanclass="pre">entry</span></tt>:</p>
<blockquote>
<olclass="arabic simple">
<li>The torrent handle is invalid.</li>
<li>The torrent is checking (or is queued for checking) its storage, it will obviously
not be ready to write resume data.</li>
<li>The torrent hasn't received valid metadata and was started without metadata
(see libtorrent's <aclass="reference"href="#metadata-from-peers">metadata from peers</a> extension)</li>
</ol>
</blockquote>
<p>Note that by the time this function returns, the resume data may already be invalid if the torrent
is still downloading! The recommended practice is to first pause the torrent, then generate the
<p><ttclass="docutils literal"><spanclass="pre">status()</span></tt> will return a structure with information about the status of this
torrent. If the <aclass="reference"href="#torrent-handle">torrent_handle</a> is invalid, it will throw <aclass="reference"href="#invalid-handle">invalid_handle</a> exception.
See <aclass="reference"href="#torrent-status">torrent_status</a>.</p>
<p><ttclass="docutils literal"><spanclass="pre">piece_index</span></tt> is the index of the piece in question. <ttclass="docutils literal"><spanclass="pre">blocks_in_piece</span></tt> 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.</p>
<p><ttclass="docutils literal"><spanclass="pre">requested_blocks</span></tt> is a bitset with one bit per block in the piece. If a bit is set, it
means that that block has been requested, but not necessarily fully downloaded yet. To know
from whom the block has been requested, have a look in the <ttclass="docutils literal"><spanclass="pre">peer</span></tt> array. The bit-index
in the <ttclass="docutils literal"><spanclass="pre">requested_blocks</span></tt> and <ttclass="docutils literal"><spanclass="pre">finished_blocks</span></tt> correspons to the array-index into
<ttclass="docutils literal"><spanclass="pre">peers</span></tt> and <ttclass="docutils literal"><spanclass="pre">num_downloads</span></tt>. The array of peers is contains the address of the
<p><ttclass="docutils literal"><spanclass="pre">get_peer_info()</span></tt> 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
<aclass="reference"href="#torrent-handle">torrent_handle</a> is invalid, it will throw <aclass="reference"href="#invalid-handle">invalid_handle</a> exception. Each entry in
the vector contains information about that particular peer. See <aclass="reference"href="#peer-info">peer_info</a>.</p>
<p>Returns a const reference to the <aclass="reference"href="#torrent-info">torrent_info</a> object associated with this torrent.
This reference is valid as long as the <aclass="reference"href="#torrent-handle">torrent_handle</a> is valid, no longer. If the
<aclass="reference"href="#torrent-handle">torrent_handle</a> is invalid or if it doesn't have any metadata, <aclass="reference"href="#invalid-handle">invalid_handle</a>
exception will be thrown. The torrent may be in a state without metadata only if
it was started without a .torrent file, i.e. by using the libtorrent extension of
just supplying a tracker and info-hash.</p>
</div>
<divclass="section"id="is-valid">
<h2><aname="is-valid">is_valid()</a></h2>
<blockquote>
<preclass="literal-block">
bool is_valid() const;
</pre>
</blockquote>
<p>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 <aclass="reference"href="#file-error-alert">file_error_alert</a> is generated and all handles
that refers to that torrent will become invalid.</p>
<p>When downloading, the progress is <ttclass="docutils literal"><spanclass="pre">total_wanted_done</span></tt> / <ttclass="docutils literal"><spanclass="pre">total_wanted</span></tt>.</p>
<p><ttclass="docutils literal"><spanclass="pre">paused</span></tt> is set to true if the torrent is paused and false otherwise.</p>
<p><ttclass="docutils literal"><spanclass="pre">next_announce</span></tt> is the time until the torrent will announce itself to the tracker. And
<ttclass="docutils literal"><spanclass="pre">announce_interval</span></tt> is the time the tracker want us to wait until we announce ourself
again the next time.</p>
<p><ttclass="docutils literal"><spanclass="pre">current_tracker</span></tt> is the URL of the last working tracker. If no tracker request has
been successful yet, it's set to an empty string.</p>
<p><ttclass="docutils literal"><spanclass="pre">total_download</span></tt> and <ttclass="docutils literal"><spanclass="pre">total_upload</span></tt> is the number of bytes downloaded and
uploaded to all peers, accumulated, <em>this session</em> only.</p>
<p><ttclass="docutils literal"><spanclass="pre">total_payload_download</span></tt> and <ttclass="docutils literal"><spanclass="pre">total_payload_upload</span></tt> counts the amount of bytes
send and received this session, but only the actual oayload data (i.e the interesting
data), these counters ignore any protocol overhead.</p>
<p><ttclass="docutils literal"><spanclass="pre">total_failed_bytes</span></tt> 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.</p>
<p><ttclass="docutils literal"><spanclass="pre">pieces</span></tt> 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.</p>
<p><ttclass="docutils literal"><spanclass="pre">download_rate</span></tt> and <ttclass="docutils literal"><spanclass="pre">upload_rate</span></tt> 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
<ttclass="docutils literal"><spanclass="pre">download_payload_rate</span></tt> and <ttclass="docutils literal"><spanclass="pre">upload_payload_rate</span></tt> 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 noticable.</p>
<p><ttclass="docutils literal"><spanclass="pre">num_peers</span></tt> is the number of peers this torrent currently is connected to.</p>
<p><ttclass="docutils literal"><spanclass="pre">num_complete</span></tt> and <ttclass="docutils literal"><spanclass="pre">num_incomplete</span></tt> 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.</p>
<p><ttclass="docutils literal"><spanclass="pre">up_speed</span></tt> and <ttclass="docutils literal"><spanclass="pre">down_speed</span></tt> 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 <ttclass="docutils literal"><spanclass="pre">payload_up_speed</span></tt> and <ttclass="docutils literal"><spanclass="pre">payload_down_speed</span></tt>.
These figures are updated aproximately once every second.</p>
<p><ttclass="docutils literal"><spanclass="pre">total_download</span></tt> and <ttclass="docutils literal"><spanclass="pre">total_upload</span></tt> 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.</p>
<p><ttclass="docutils literal"><spanclass="pre">id</span></tt> 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()_</p>
<p><ttclass="docutils literal"><spanclass="pre">pieces</span></tt> is a vector of booleans that has as many entries as there are pieces
in the torrent. Each boolean tells you if the peer has that piece (if it's set to true)
or if the peer miss that piece (set to false).</p>
<p><ttclass="docutils literal"><spanclass="pre">seed</span></tt> is true if this peer is a seed.</p>
<p><ttclass="docutils literal"><spanclass="pre">upload_limit</span></tt> 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 limit. The upload limits of all peers
should sum up to the upload limit set by <ttclass="docutils literal"><spanclass="pre">session::set_upload_limit</span></tt>.</p>
<p><ttclass="docutils literal"><spanclass="pre">upload_ceiling</span></tt> is the current maximum allowed upload rate given the cownload
rate and share ratio. If the global upload rate is inlimited, the <ttclass="docutils literal"><spanclass="pre">upload_limit</span></tt>
for every peer will be the same as their <ttclass="docutils literal"><spanclass="pre">upload_ceiling</span></tt>.</p>
<p><ttclass="docutils literal"><spanclass="pre">load_balancing</span></tt> is a measurment 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 <em>extra</em> 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.</p>
<p><ttclass="docutils literal"><spanclass="pre">download_queue_length</span></tt> is the number of piece-requests we have sent to this peer
that hasn't been answered with a piece yet.</p>
<p><ttclass="docutils literal"><spanclass="pre">upload_queue_length</span></tt> is the number of piece-requests we have received from this peer
that we haven't answered with a piece yet.</p>
<p>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.
<ttclass="docutils literal"><spanclass="pre">downloading_piece_index</span></tt> 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. <ttclass="docutils literal"><spanclass="pre">downloading_block_index</span></tt> is the index of the
block (or sub-piece) that is being downloaded. <ttclass="docutils literal"><spanclass="pre">downloading_progress</span></tt> is the number
of bytes of this block we have received from the peer, and <ttclass="docutils literal"><spanclass="pre">downloading_total</span></tt> is
the total number of bytes in this block.</p>
</div>
<divclass="section"id="address">
<h1><aname="address">address</a></h1>
<p>The <ttclass="docutils literal"><spanclass="pre">address</span></tt> class represents a name of a network endpoint (usually referred to as
IP-address) and a port number. This is the same thing as a <ttclass="docutils literal"><spanclass="pre">sockaddr_in</span></tt> would contain.
Its declaration looks like this:</p>
<preclass="literal-block">
class address
{
public:
address();
address(unsigned char a
, unsigned char b
, unsigned char c
, unsigned char d
, unsigned short port);
address(unsigned int addr, unsigned short port);
address(const std::string& addr, unsigned short port);
address(const address& a);
~address();
std::string as_string() const;
unsigned int ip() const;
unsigned short port() const;
bool operator<(const address& a) const;
bool operator!=(const address& a) const;
bool operator==(const address& a) const;
};
</pre>
<p>It is less-than comparable to make it possible to use it as a key in a map. <ttclass="docutils literal"><spanclass="pre">as_string()</span></tt> may block
while it does the DNS lookup, it returns a string that points to the address represented by the object.</p>
<p><ttclass="docutils literal"><spanclass="pre">ip()</span></tt> will return the 32-bit ip-address as an integer. <ttclass="docutils literal"><spanclass="pre">port()</span></tt> returns the port number.</p>
<p><ttclass="docutils literal"><spanclass="pre">proxy_ip</span></tt> may be a hostname or ip to a http proxy to use. If this is
an empty string, no http proxy will be used.</p>
<p><ttclass="docutils literal"><spanclass="pre">proxy_port</span></tt> is the port on which the http proxy listens. If <ttclass="docutils literal"><spanclass="pre">proxy_ip</span></tt>
is empty, this will be ignored.</p>
<p><ttclass="docutils literal"><spanclass="pre">proxy_login</span></tt> should be the login username for the http proxy, if this
<p>Creates a default filter that doesn't filter any address.</p>
<p>postcondition:
<ttclass="docutils literal"><spanclass="pre">access(x)</span><spanclass="pre">==</span><spanclass="pre">0</span></tt> for every <ttclass="docutils literal"><spanclass="pre">x</span></tt></p>
</div>
<divclass="section"id="add-rule">
<h2><aname="add-rule">add_rule()</a></h2>
<blockquote>
<preclass="literal-block">
void add_rule(address first, address last, int flags);
</pre>
</blockquote>
<p>Adds a rule to the filter. <ttclass="docutils literal"><spanclass="pre">first</span></tt> and <ttclass="docutils literal"><spanclass="pre">last</span></tt> defines a range of
ip addresses that will be marked with the given flags. The <ttclass="docutils literal"><spanclass="pre">flags</span></tt>
can currenly be 0, which means allowed, or <ttclass="docutils literal"><spanclass="pre">ip_filter::blocked</span></tt>, which
means disallowed.</p>
<p>postcondition:
<ttclass="docutils literal"><spanclass="pre">access(x)</span><spanclass="pre">==</span><spanclass="pre">flags</span></tt> for every <ttclass="docutils literal"><spanclass="pre">x</span></tt> in the range [<ttclass="docutils literal"><spanclass="pre">first</span></tt>, <ttclass="docutils literal"><spanclass="pre">last</span></tt>]</p>
<p>This means that in a case of overlapping ranges, the last one applied takes
precedence.</p>
</div>
<divclass="section"id="access">
<h2><aname="access">access()</a></h2>
<blockquote>
<preclass="literal-block">
int access(address const& addr) const;
</pre>
</blockquote>
<p>Returns the access permissions for the given address (<ttclass="docutils literal"><spanclass="pre">addr</span></tt>). The permission
can currently be 0 or <ttclass="docutils literal"><spanclass="pre">ip_filter::blocked</span></tt>. The complexity of this operation
is O(<ttclass="docutils literal"><spanclass="pre">log</span></tt> n), where n is the minimum number of non-overlapping ranges to describe
<p>Both the <ttclass="docutils literal"><spanclass="pre">peer_id</span></tt> and <ttclass="docutils literal"><spanclass="pre">sha1_hash</span></tt> types are typedefs of the class
<ttclass="docutils literal"><spanclass="pre">big_number</span></tt>. It represents 20 bytes of data. Its synopsis follows:</p>
<preclass="literal-block">
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();
};
</pre>
<p>The iterators gives you access to individual bytes.</p>
</div>
<divclass="section"id="hasher">
<h1><aname="hasher">hasher</a></h1>
<p>This class creates sha1-hashes. Its declaration looks like this:</p>
<preclass="literal-block">
class hasher
{
public:
hasher();
void update(const char* data, unsigned int len);
sha1_hash final();
void reset();
};
</pre>
<p>You use it by first instantiating it, then call <ttclass="docutils literal"><spanclass="pre">update()</span></tt> 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 <ttclass="docutils literal"><spanclass="pre">final()</span></tt> and it
will return the sha1-hash of the data.</p>
<p>If you want to reuse the hasher object once you have created a hash, you have to
call <ttclass="docutils literal"><spanclass="pre">reset()</span></tt> to reinitialize it.</p>
<p>The sha1-algorithm used was implemented by Steve Reid and released as public domain.
For more info, see <ttclass="docutils literal"><spanclass="pre">src/sha1.cpp</span></tt>.</p>
</div>
<divclass="section"id="fingerprint">
<h1><aname="fingerprint">fingerprint</a></h1>
<p>The fingerprint class represents information about a client and its version. It is used
to encode this information into the client's peer id.</p>
<p>The constructor takes a <ttclass="docutils literal"><spanclass="pre">char</span><spanclass="pre">const*</span></tt> 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:</p>
<p>There's currently an informal directory of client id's <aclass="reference"href="http://wiki.theory.org/BitTorrentSpecification#peer_id">here</a>.</p>
<p>The <ttclass="docutils literal"><spanclass="pre">major</span></tt>, <ttclass="docutils literal"><spanclass="pre">minor</span></tt>, <ttclass="docutils literal"><spanclass="pre">revision</span></tt> and <ttclass="docutils literal"><spanclass="pre">tag</span></tt> parameters are used to identify the
version of your client. All these numbers must be within the range [0, 9].</p>
<p><ttclass="docutils literal"><spanclass="pre">to_string()</span></tt> will generate the actual string put in the peer-id, and return it.</p>
<p>This function is declared in the header <ttclass="docutils literal"><spanclass="pre"><libtorrent/identify_client.hpp></span></tt>. 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.</p>
<p>These functions will encode data to <aclass="reference"href="http://wiki.theory.org/index.php/BitTorrentSpecification">bencoded</a> or decode <aclass="reference"href="http://wiki.theory.org/index.php/BitTorrentSpecification">bencoded</a> data.</p>
<p>The <aclass="reference"href="#entry">entry</a> class is the internal representation of the bencoded data
and it can be used to retreive information, an <aclass="reference"href="#entry">entry</a> can also be build by
the program and given to <ttclass="docutils literal"><spanclass="pre">bencode()</span></tt> to encode it into the <ttclass="docutils literal"><spanclass="pre">OutIt</span></tt>
iterator.</p>
<p>The <ttclass="docutils literal"><spanclass="pre">OutIt</span></tt> and <ttclass="docutils literal"><spanclass="pre">InIt</span></tt> are iterators
(<aclass="reference"href="http://www.sgi.com/tech/stl/InputIterator.html">InputIterator</a> and <aclass="reference"href="http://www.sgi.com/tech/stl/OutputIterator.html">OutputIterator</a> respectively). They
are templates and are usually instantiated as <aclass="reference"href="http://www.sgi.com/tech/stl/ostream_iterator.html">ostream_iterator</a>,
<aclass="reference"href="http://www.sgi.com/tech/stl/back_insert_iterator.html">back_insert_iterator</a> or <aclass="reference"href="http://www.sgi.com/tech/stl/istream_iterator.html">istream_iterator</a>. These
functions will assume that the iterator refers to a character
(<ttclass="docutils literal"><spanclass="pre">char</span></tt>). So, if you want to encode entry <ttclass="docutils literal"><spanclass="pre">e</span></tt> into a buffer
<td>This will include alot of debug events that can be used
both for debugging libtorrent but also when debugging
other clients that are connected to libtorrent. It will
report strange behaviors among the connected peers.</td>
</tr>
</tbody>
</table>
<p>When setting a severity level, you will receive messages of that severity and all
messages that are more sever. If you set <ttclass="docutils literal"><spanclass="pre">alert::none</span></tt> (the default) you will not recieve
any events at all.</p>
<p>When you set a severuty level other than <ttclass="docutils literal"><spanclass="pre">none</span></tt>, you have the responsibility to call
<ttclass="docutils literal"><spanclass="pre">pop_alert()</span></tt> from time to time. If you don't do that, the alert queue will just grow.</p>
<p>When you get an alert, you can use <ttclass="docutils literal"><spanclass="pre">typeid()</span></tt> or <ttclass="docutils literal"><spanclass="pre">dynamic_cast<></span></tt> to get more detailed
information on exactly which type it is. i.e. what kind of error it is. You can also use a
<aclass="reference"href="#dispatcher">dispatcher</a> mechanism that's available in libtorrent.</p>
<p>All alert types are defined in the <ttclass="docutils literal"><spanclass="pre"><libtorrent/alert_types.hpp></span></tt> header file.</p>
<p>The <ttclass="docutils literal"><spanclass="pre">alert</span></tt> class is the base class that specific messages are derived from. This
<p>This alert is generated when a peer is banned because it has sent too many corrupt pieces
to us. It is generated at severity level <ttclass="docutils literal"><spanclass="pre">info</span></tt>. The <ttclass="docutils literal"><spanclass="pre">handle</span></tt> member is a <aclass="reference"href="#torrent-handle">torrent_handle</a>
to the torrent that this peer was a member of.</p>
<ttclass="docutils literal"><spanclass="pre">request</span></tt> is the actual incoming request from the peer. The alert is generated as severity level
<p>The <ttclass="docutils literal"><spanclass="pre">peer_request</span></tt> contains the values the client sent in its <ttclass="docutils literal"><spanclass="pre">request</span></tt> message. <ttclass="docutils literal"><spanclass="pre">piece</span></tt> is
the index of the piece it want data from, <ttclass="docutils literal"><spanclass="pre">start</span></tt> is the offset within the piece where the data
should be read, and <ttclass="docutils literal"><spanclass="pre">length</span></tt> is the amount of data it wants.</p>
<p>This is thrown by <ttclass="docutils literal"><spanclass="pre">bdecode()</span></tt> if the input data is not a valid bencoding.</p>
<preclass="literal-block">
struct invalid_encoding: std::exception
{
const char* what() const throw();
};
</pre>
</div>
<divclass="section"id="type-error">
<h2><aname="type-error">type_error</a></h2>
<p>This is thrown from the accessors of <ttclass="docutils literal"><spanclass="pre">entry</span></tt> if the data type of the <ttclass="docutils literal"><spanclass="pre">entry</span></tt> doesn't
<p>This exception is thrown from the constructor of <ttclass="docutils literal"><spanclass="pre">torrent_info</span></tt> if the given bencoded information
doesn't meet the requirements on what information has to be present in a torrent file.</p>
<p>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 <ttclass="docutils literal"><spanclass="pre">torrent_handle::write_resume_data()</span></tt> on <aclass="reference"href="#torrent-handle">torrent_handle</a>. 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.</p>
<p>There are two modes in which storage (files on disk) are allocated in libtorrent.</p>
<blockquote>
<ulclass="simple">
<li>The traditional <em>full allocation</em> mode, where the entire files are filled up with
zeroes before anything is downloaded.</li>
<li>And the <em>compact allocation</em> mode, where only files are allocated for actual
pieces that have been downloaded. This is the default allocation mode in libtorrent.</li>
</ul>
</blockquote>
<p>The allocation mode is selected when a torrent is started. It is passed as a boolean
argument to <ttclass="docutils literal"><spanclass="pre">session::add_torrent()</span></tt> (see <aclass="reference"href="#add-torrent">add_torrent()</a>). These two modes have
<p>for example. For more information, see the <aclass="reference"href="http://www.boost.org/libs/filesystem/doc/index.htm">Boost.Filesystem docs</a>.</p>