.. include:: header.rst

`home`__

__ reference.html

.. contents:: Table of contents
  :depth: 2
  :backlinks: none

.. raw:: html

	<a name="block_info"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:class+block_info&labels=documentation&body=Documentation+under+heading+%22class+block_info%22+could+be+improved">report issue</a>]</span>



block_info
----------

Declared in "`libtorrent/torrent_handle.hpp`__"


__ include/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.




.. parsed-literal::
	

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

.. raw:: html

	<a name="peer()"></a>
	<a name="set_peer()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:block_info%3A%3A%5Bpeer%28%29+set_peer%28%29%5D&labels=documentation&body=Documentation+under+heading+%22block_info%3A%3A%5Bpeer%28%29+set_peer%28%29%5D%22+could+be+improved">report issue</a>]</span>



peer() set_peer()
.................

.. parsed-literal::
	
	tcp::endpoint **peer** () const;
	void **set_peer** (tcp\:\:endpoint const& ep);
	

The peer is the ip address of the peer this block was downloaded from.



.. raw:: html

	<a name="block_state_t"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:enum+block_state_t&labels=documentation&body=Documentation+under+heading+%22enum+block_state_t%22+could+be+improved">report issue</a>]</span>



enum block_state_t
..................

Declared in "`libtorrent/torrent_handle.hpp`__"


__ include/libtorrent/torrent_handle.hpp

+-----------+-------+------------------------------------------------------------------+
| name      | value | description                                                      |
+===========+=======+==================================================================+
| none      | 0     | This block has not been downloaded or requested form any peer.   |
|           |       |                                                                  |
+-----------+-------+------------------------------------------------------------------+
| requested | 1     | The block has been requested, but not completely downloaded yet. |
|           |       |                                                                  |
+-----------+-------+------------------------------------------------------------------+
| writing   | 2     | The block has been downloaded and is currently queued for being  |
|           |       | written to disk.                                                 |
|           |       |                                                                  |
+-----------+-------+------------------------------------------------------------------+
| finished  | 3     | The block has been written to disk.                              |
|           |       |                                                                  |
+-----------+-------+------------------------------------------------------------------+



.. raw:: html

	<a name="bytes_progress"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:block_info%3A%3A%5Bbytes_progress%5D&labels=documentation&body=Documentation+under+heading+%22block_info%3A%3A%5Bbytes_progress%5D%22+could+be+improved">report issue</a>]</span>


bytes_progress
	the number of bytes that have been received for this block
	


.. raw:: html

	<a name="block_size"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:block_info%3A%3A%5Bblock_size%5D&labels=documentation&body=Documentation+under+heading+%22block_info%3A%3A%5Bblock_size%5D%22+could+be+improved">report issue</a>]</span>


block_size
	the total number of bytes in this block.
	


.. raw:: html

	<a name="state"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:block_info%3A%3A%5Bstate%5D&labels=documentation&body=Documentation+under+heading+%22block_info%3A%3A%5Bstate%5D%22+could+be+improved">report issue</a>]</span>


state
	the state this block is in (see `block_state_t`__)
	

__ reference-Torrent_Handle.html#block_state_t

.. raw:: html

	<a name="num_peers"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:block_info%3A%3A%5Bnum_peers%5D&labels=documentation&body=Documentation+under+heading+%22block_info%3A%3A%5Bnum_peers%5D%22+could+be+improved">report issue</a>]</span>


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.
	


.. raw:: html

	<a name="partial_piece_info"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:class+partial_piece_info&labels=documentation&body=Documentation+under+heading+%22class+partial_piece_info%22+could+be+improved">report issue</a>]</span>



partial_piece_info
------------------

Declared in "`libtorrent/torrent_handle.hpp`__"


__ include/libtorrent/torrent_handle.hpp

This class holds information about pieces that have outstanding requests
or outstanding writes




.. parsed-literal::
	

	struct partial_piece_info
	{
	   piece_index_t piece_index;
	   int blocks_in_piece;
	   int finished;
	   int writing;
	   int requested;
	   block_info const* blocks;
	};

.. raw:: html

	<a name="piece_index"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:partial_piece_info%3A%3A%5Bpiece_index%5D&labels=documentation&body=Documentation+under+heading+%22partial_piece_info%3A%3A%5Bpiece_index%5D%22+could+be+improved">report issue</a>]</span>


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.
	


.. raw:: html

	<a name="blocks_in_piece"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:partial_piece_info%3A%3A%5Bblocks_in_piece%5D&labels=documentation&body=Documentation+under+heading+%22partial_piece_info%3A%3A%5Bblocks_in_piece%5D%22+could+be+improved">report issue</a>]</span>


blocks_in_piece
	the number of blocks in this piece
	


.. raw:: html

	<a name="finished"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:partial_piece_info%3A%3A%5Bfinished%5D&labels=documentation&body=Documentation+under+heading+%22partial_piece_info%3A%3A%5Bfinished%5D%22+could+be+improved">report issue</a>]</span>


finished
	the number of blocks that are in the finished state
	


.. raw:: html

	<a name="writing"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:partial_piece_info%3A%3A%5Bwriting%5D&labels=documentation&body=Documentation+under+heading+%22partial_piece_info%3A%3A%5Bwriting%5D%22+could+be+improved">report issue</a>]</span>


writing
	the number of blocks that are in the writing state
	


.. raw:: html

	<a name="requested"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:partial_piece_info%3A%3A%5Brequested%5D&labels=documentation&body=Documentation+under+heading+%22partial_piece_info%3A%3A%5Brequested%5D%22+could+be+improved">report issue</a>]</span>


requested
	the number of blocks that are in the requested state
	


.. raw:: html

	<a name="blocks"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:partial_piece_info%3A%3A%5Bblocks%5D&labels=documentation&body=Documentation+under+heading+%22partial_piece_info%3A%3A%5Bblocks%5D%22+could+be+improved">report issue</a>]</span>


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.
	

__ reference-Session.html#session
__ reference-Torrent_Handle.html#get_download_queue()

.. raw:: html

	<a name="torrent_handle"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:class+torrent_handle&labels=documentation&body=Documentation+under+heading+%22class+torrent_handle%22+could+be+improved">report issue</a>]</span>



torrent_handle
--------------

Declared in "`libtorrent/torrent_handle.hpp`__"


__ include/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 querying 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 system_error
	exception, in case the handle is no longer referring 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.



__ reference-Torrent_Handle.html#status()
__ reference-Torrent_Handle.html#torrent_handle
__ reference-Torrent_Info.html#is_valid()


.. parsed-literal::
	

	struct torrent_handle
	{
	   friend std::size_t **hash_value** (torrent\_handle const& th);
	   **torrent_handle** () noexcept = default;
	   void **add_piece** (piece\_index\_t piece, std\:\:vector<char> data, add\_piece\_flags\_t flags = {}) const;
	   void **add_piece** (piece\_index\_t piece, char const\* data, add\_piece\_flags\_t flags = {}) const;
	   void **read_piece** (piece\_index\_t piece) const;
	   bool **have_piece** (piece\_index\_t piece) const;
	   void **get_peer_info** (std\:\:vector<peer\_info>& v) const;
	   torrent_status **status** (status\_flags\_t flags = status\_flags\_t\:\:all()) const;
	   void **get_download_queue** (std\:\:vector<partial\_piece\_info>& queue) const;
	   std::vector<partial_piece_info> **get_download_queue** () const;
	   void **set_piece_deadline** (piece\_index\_t index, int deadline, deadline\_flags\_t flags = {}) const;
	   void **reset_piece_deadline** (piece\_index\_t index) const;
	   void **clear_piece_deadlines** () const;
	   std::vector<std::int64_t> **file_progress** (file\_progress\_flags\_t flags = {}) const;
	   void **file_progress** (std\:\:vector<std\:\:int64\_t>& progress, file\_progress\_flags\_t flags = {}) const;
	   std::vector<open_file_state> **file_status** () const;
	   void **clear_error** () const;
	   void **replace_trackers** (std\:\:vector<announce\_entry> const&) const;
	   void **add_tracker** (announce\_entry const&) const;
	   std::vector<announce_entry> **trackers** () const;
	   std::set<std::string> **url_seeds** () const;
	   void **add_url_seed** (std\:\:string const& url) const;
	   void **remove_url_seed** (std\:\:string const& url) 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** (
	      std\:\:function<std\:\:shared\_ptr<torrent\_plugin>(torrent\_handle const&, client\_data\_t)> const& ext
	      , client\_data\_t userdata = client\_data\_t{});
	   bool **set_metadata** (span<char const> metadata) const;
	   bool **is_valid** () const;
	   void **resume** () const;
	   void **pause** (pause\_flags\_t flags = {}) const;
	   void **unset_flags** (torrent\_flags\_t flags) const;
	   void **set_flags** (torrent\_flags\_t flags, torrent\_flags\_t mask) const;
	   void **set_flags** (torrent\_flags\_t flags) const;
	   torrent_flags_t **flags** () const;
	   void **flush_cache** () const;
	   void **force_recheck** () const;
	   void **save_resume_data** (resume\_data\_flags\_t flags = {}) const;
	   bool **need_save_resume_data** () const;
	   void **queue_position_down** () const;
	   void **queue_position_top** () const;
	   queue_position_t **queue_position** () const;
	   void **queue_position_bottom** () const;
	   void **queue_position_up** () const;
	   void **queue_position_set** (queue\_position\_t p) const;
	   void **set_ssl_certificate** (std\:\:string const& certificate
	      , std\:\:string const& private\_key
	      , std\:\:string const& dh\_params
	      , std\:\:string const& passphrase = "");
	   void **set_ssl_certificate_buffer** (std\:\:string const& certificate
	      , std\:\:string const& private\_key
	      , std\:\:string const& dh\_params);
	   std::shared_ptr<torrent_info> **torrent_file_with_hashes** () const;
	   std::shared_ptr<const torrent_info> **torrent_file** () const;
	   std::vector<std::vector<sha256_hash>> **piece_layers** () const;
	   void **piece_availability** (std\:\:vector<int>& avail) const;
	   void **prioritize_pieces** (std\:\:vector<std\:\:pair<piece\_index\_t, download\_priority\_t>> const& pieces) const;
	   std::vector<download_priority_t> **get_piece_priorities** () const;
	   void **piece_priority** (piece\_index\_t index, download\_priority\_t priority) const;
	   download_priority_t **piece_priority** (piece\_index\_t index) const;
	   void **prioritize_pieces** (std\:\:vector<download\_priority\_t> const& pieces) const;
	   void **prioritize_files** (std\:\:vector<download\_priority\_t> const& files) const;
	   download_priority_t **file_priority** (file\_index\_t index) const;
	   std::vector<download_priority_t> **get_file_priorities** () const;
	   void **file_priority** (file\_index\_t index, download\_priority\_t priority) const;
	   void **force_dht_announce** () const;
	   void **force_reannounce** (int seconds = 0, int idx = -1, reannounce\_flags\_t = {}) const;
	   void **force_lsd_announce** () const;
	   void **scrape_tracker** (int idx = -1) const;
	   void **set_upload_limit** (int limit) const;
	   int **download_limit** () const;
	   int **upload_limit** () const;
	   void **set_download_limit** (int limit) const;
	   void **connect_peer** (tcp\:\:endpoint const& adr, peer\_source\_flags\_t source = {}
	      , pex\_flags\_t flags = pex\_encryption | pex\_utp | pex\_holepunch) const;
	   void **clear_peers** ();
	   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 **move_storage** (std\:\:string const& save\_path
	      , move\_flags\_t flags = move\_flags\_t\:\:always\_replace\_files
	      ) const;
	   void **rename_file** (file\_index\_t index, std\:\:string const& new\_name) const;
	   info_hash_t **info_hashes** () 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;
	   std::uint32_t **id** () const;
	   std::shared_ptr<torrent> **native_handle** () const;
	   client_data_t **userdata** () const;
	   bool **in_session** () const;
	
	   static constexpr add_piece_flags_t **overwrite_existing**  = 0_bit;
	   static constexpr status_flags_t **query_distributed_copies**  = 0_bit;
	   static constexpr status_flags_t **query_accurate_download_counters**  = 1_bit;
	   static constexpr status_flags_t **query_last_seen_complete**  = 2_bit;
	   static constexpr status_flags_t **query_pieces**  = 3_bit;
	   static constexpr status_flags_t **query_verified_pieces**  = 4_bit;
	   static constexpr status_flags_t **query_torrent_file**  = 5_bit;
	   static constexpr status_flags_t **query_name**  = 6_bit;
	   static constexpr status_flags_t **query_save_path**  = 7_bit;
	   static constexpr deadline_flags_t **alert_when_available**  = 0_bit;
	   static constexpr file_progress_flags_t **piece_granularity**  = 0_bit;
	   static constexpr pause_flags_t **graceful_pause**  = 0_bit;
	   static constexpr resume_data_flags_t **flush_disk_cache**  = 0_bit;
	   static constexpr resume_data_flags_t **save_info_dict**  = 1_bit;
	   static constexpr resume_data_flags_t **only_if_modified**  = 2_bit;
	   static constexpr reannounce_flags_t **ignore_min_interval**  = 0_bit;
	};

.. raw:: html

	<a name="torrent_handle()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Btorrent_handle%28%29%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Btorrent_handle%28%29%5D%22+could+be+improved">report issue</a>]</span>



torrent_handle()
................

.. parsed-literal::
	
	**torrent_handle** () noexcept = default;
	

constructs a torrent handle that does not refer to a torrent.
i.e. `is_valid()`__ will return false.


__ reference-Torrent_Info.html#is_valid()

.. raw:: html

	<a name="add_piece()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Badd_piece%28%29%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Badd_piece%28%29%5D%22+could+be+improved">report issue</a>]</span>



add_piece()
...........

.. parsed-literal::
	
	void **add_piece** (piece\_index\_t piece, std\:\:vector<char> data, add\_piece\_flags\_t flags = {}) const;
	void **add_piece** (piece\_index\_t piece, char const\* data, add\_piece\_flags\_t flags = {}) const;
	

This function will write ``data`` to the storage as piece ``piece``,
as if it had been downloaded from a peer.

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`__.

Adding pieces while the torrent is being checked (i.e. in
`torrent_status::checking_files`__ state) is not supported.

The overload taking a raw pointer to the data is a blocking call. It
won't return until the libtorrent thread has copied the data into its
disk write buffer. ``data`` is expected to point to a buffer of as
many bytes as the size of the specified piece. See
`file_storage::piece_size()`__.

The data in the buffer is copied and passed on to the disk IO thread
to be written at a later point.

The overload taking a ``std::vector<char>`` is not blocking, it will
send the buffer to the main thread and return immediately.


__ reference-Alerts.html#piece_finished_alert
__ reference-Alerts.html#hash_failed_alert
__ reference-Torrent_Status.html#checking_files
__ reference-Storage.html#piece_size()

.. raw:: html

	<a name="read_piece()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Bread_piece%28%29%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Bread_piece%28%29%5D%22+could+be+improved">report issue</a>]</span>



read_piece()
............

.. parsed-literal::
	
	void **read_piece** (piece\_index\_t 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 response 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.


__ reference-Alerts.html#alert
__ reference-Alerts.html#read_piece_alert
__ reference-Alerts.html#alert
__ reference-Alerts.html#alert

.. raw:: html

	<a name="have_piece()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Bhave_piece%28%29%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Bhave_piece%28%29%5D%22+could+be+improved">report issue</a>]</span>



have_piece()
............

.. parsed-literal::
	
	bool **have_piece** (piece\_index\_t piece) const;
	

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



.. raw:: html

	<a name="get_peer_info()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Bget_peer_info%28%29%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Bget_peer_info%28%29%5D%22+could+be+improved">report issue</a>]</span>



get_peer_info()
...............

.. parsed-literal::
	
	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
system_error exception. Each `entry`__ in the vector contains
information about that particular peer. See `peer_info`__.


__ reference-Bencoding.html#entry
__ reference-Torrent_Handle.html#torrent_handle
__ reference-Bencoding.html#entry
__ reference-Core.html#peer_info

.. raw:: html

	<a name="status()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Bstatus%28%29%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Bstatus%28%29%5D%22+could+be+improved">report issue</a>]</span>



status()
........

.. parsed-literal::
	
	torrent_status **status** (status\_flags\_t flags = status\_flags\_t\:\:all()) const;
	

``status()`` will return a structure with information about the status
of this torrent. If the `torrent_handle`__ is invalid, it will throw
system_error 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 this class.


__ reference-Torrent_Handle.html#torrent_handle
__ reference-Torrent_Status.html#torrent_status
__ reference-Torrent_Status.html#torrent_status

.. raw:: html

	<a name="get_download_queue()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Bget_download_queue%28%29%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Bget_download_queue%28%29%5D%22+could+be+improved">report issue</a>]</span>



get_download_queue()
....................

.. parsed-literal::
	
	void **get_download_queue** (std\:\:vector<partial\_piece\_info>& queue) const;
	std::vector<partial_piece_info> **get_download_queue** () const;
	

``get_download_queue()`` returns a vector with information about pieces
that are partially downloaded or not downloaded but partially
requested. See `partial_piece_info`__ for the fields in the returned
vector.


__ reference-Torrent_Handle.html#partial_piece_info

.. raw:: html

	<a name="clear_piece_deadlines()"></a>
	<a name="reset_piece_deadline()"></a>
	<a name="set_piece_deadline()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Bclear_piece_deadlines%28%29+reset_piece_deadline%28%29+set_piece_deadline%28%29%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Bclear_piece_deadlines%28%29+reset_piece_deadline%28%29+set_piece_deadline%28%29%5D%22+could+be+improved">report issue</a>]</span>



clear_piece_deadlines() reset_piece_deadline() set_piece_deadline()
...................................................................

.. parsed-literal::
	
	void **set_piece_deadline** (piece\_index\_t index, int deadline, deadline\_flags\_t flags = {}) const;
	void **reset_piece_deadline** (piece\_index\_t index) const;
	void **clear_piece_deadlines** () 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.

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 have the same effect 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.

``clear_piece_deadlines()`` removes deadlines on all pieces in
the torrent. As if `reset_piece_deadline()`__ was called on all pieces.


__ reference-Torrent_Handle.html#read_piece()
__ reference-Torrent_Handle.html#reset_piece_deadline()

.. raw:: html

	<a name="file_progress()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Bfile_progress%28%29%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Bfile_progress%28%29%5D%22+could+be+improved">report issue</a>]</span>



file_progress()
...............

.. parsed-literal::
	
	std::vector<std::int64_t> **file_progress** (file\_progress\_flags\_t flags = {}) const;
	void **file_progress** (std\:\:vector<std\:\:int64\_t>& progress, file\_progress\_flags\_t flags = {}) const;
	

This function fills in the supplied vector, or returns a vector, with
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 currently
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.


__ reference-Torrent_Info.html#torrent_info

.. raw:: html

	<a name="file_status()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Bfile_status%28%29%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Bfile_status%28%29%5D%22+could+be+improved">report issue</a>]</span>



file_status()
.............

.. parsed-literal::
	
	std::vector<open_file_state> **file_status** () const;
	

This function returns a vector with status about files
that are open for this torrent. Any file that is not open
will not be reported in the vector, i.e. it's possible that
the vector is empty when returning, if none of the files in the
torrent are currently open.

See `open_file_state`__


__ reference-Custom_Storage.html#open_file_state

.. raw:: html

	<a name="clear_error()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Bclear_error%28%29%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Bclear_error%28%29%5D%22+could+be+improved">report issue</a>]</span>



clear_error()
.............

.. parsed-literal::
	
	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.



.. raw:: html

	<a name="trackers()"></a>
	<a name="add_tracker()"></a>
	<a name="replace_trackers()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Btrackers%28%29+add_tracker%28%29+replace_trackers%28%29%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Btrackers%28%29+add_tracker%28%29+replace_trackers%28%29%5D%22+could+be+improved">report issue</a>]</span>



trackers() add_tracker() replace_trackers()
...........................................

.. parsed-literal::
	
	void **replace_trackers** (std\:\:vector<announce\_entry> const&) const;
	void **add_tracker** (announce\_entry const&) const;
	std::vector<announce_entry> **trackers** () 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.


__ reference-Bencoding.html#entry
__ reference-Alerts.html#int
__ reference-Torrent_Handle.html#force_reannounce()
__ reference-Trackers.html#announce_entry
__ reference-Trackers.html#announce_entry

.. raw:: html

	<a name="add_url_seed()"></a>
	<a name="url_seeds()"></a>
	<a name="remove_url_seed()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Badd_url_seed%28%29+url_seeds%28%29+remove_url_seed%28%29%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Badd_url_seed%28%29+url_seeds%28%29+remove_url_seed%28%29%5D%22+could+be+improved">report issue</a>]</span>



add_url_seed() url_seeds() remove_url_seed()
............................................

.. parsed-literal::
	
	std::set<std::string> **url_seeds** () const;
	void **add_url_seed** (std\:\:string const& url) const;
	void **remove_url_seed** (std\:\:string const& url) 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.


__ manual-ref.html#http-seeding

.. raw:: html

	<a name="add_http_seed()"></a>
	<a name="http_seeds()"></a>
	<a name="remove_http_seed()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Badd_http_seed%28%29+http_seeds%28%29+remove_http_seed%28%29%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Badd_http_seed%28%29+http_seeds%28%29+remove_http_seed%28%29%5D%22+could+be+improved">report issue</a>]</span>



add_http_seed() http_seeds() remove_http_seed()
...............................................

.. parsed-literal::
	
	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.


__ manual-ref.html#http-seeding

.. raw:: html

	<a name="add_extension()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Badd_extension%28%29%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Badd_extension%28%29%5D%22+could+be+improved">report issue</a>]</span>



add_extension()
...............

.. parsed-literal::
	
	void **add_extension** (
	      std\:\:function<std\:\:shared\_ptr<torrent\_plugin>(torrent\_handle const&, client\_data\_t)> const& ext
	      , client\_data\_t userdata = client\_data\_t{});
	

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.


__ reference-Plugins.html#torrent_plugin

.. raw:: html

	<a name="set_metadata()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Bset_metadata%28%29%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Bset_metadata%28%29%5D%22+could+be+improved">report issue</a>]</span>



set_metadata()
..............

.. parsed-literal::
	
	bool **set_metadata** (span<char const> metadata) 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.



.. raw:: html

	<a name="is_valid()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Bis_valid%28%29%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Bis_valid%28%29%5D%22+could+be+improved">report issue</a>]</span>



is_valid()
..........

.. parsed-literal::
	
	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
removed from the `session`__ AND destructed.

To tell if the `torrent_handle`__ is in the `session`__, use
`torrent_handle::in_session()`__. This will return true before
`session_handle::remove_torrent()`__ is called, and false
afterward.

Clients should only use `is_valid()`__ to determine if the result of
session::find_torrent() was successful.

Unlike other member functions which return a value, `is_valid()`__
completes immediately, without blocking on a result from the
network thread. Also unlike other functions, it never throws
the system_error exception.


__ reference-Session.html#session
__ reference-Torrent_Handle.html#torrent_handle
__ reference-Session.html#session
__ reference-Torrent_Handle.html#in_session()
__ reference-Session.html#remove_torrent()
__ reference-Torrent_Info.html#is_valid()
__ reference-Torrent_Info.html#is_valid()

.. raw:: html

	<a name="resume()"></a>
	<a name="pause()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Bresume%28%29+pause%28%29%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Bresume%28%29+pause%28%29%5D%22+could+be+improved">report issue</a>]</span>



resume() pause()
................

.. parsed-literal::
	
	void **resume** () const;
	void **pause** (pause\_flags\_t flags = {}) 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`__.

For possible values of the ``flags`` parameter, see pause_flags_t.

To know if a torrent is paused or not, call
``torrent_handle::flags()`` and check for the
``torrent_status::paused`` flag.

.. note::
	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 auto-managed first. Torrents are auto-managed by default when added
	to the `session`__. For more information, see `queuing`__.



__ reference-Alerts.html#file_error_alert
__ reference-Session.html#session
__ manual-ref.html#queuing

.. raw:: html

	<a name="flags()"></a>
	<a name="unset_flags()"></a>
	<a name="set_flags()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Bflags%28%29+unset_flags%28%29+set_flags%28%29%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Bflags%28%29+unset_flags%28%29+set_flags%28%29%5D%22+could+be+improved">report issue</a>]</span>



flags() unset_flags() set_flags()
.................................

.. parsed-literal::
	
	void **unset_flags** (torrent\_flags\_t flags) const;
	void **set_flags** (torrent\_flags\_t flags, torrent\_flags\_t mask) const;
	void **set_flags** (torrent\_flags\_t flags) const;
	torrent_flags_t **flags** () const;
	

sets and gets the torrent state flags. See `torrent_flags_t`__.
The ``set_flags`` overload that take a mask will affect all
flags part of the mask, and set their values to what the
``flags`` argument is set to. This allows clearing and
setting flags in a single function call.
The ``set_flags`` overload that just takes flags, sets all
the specified flags and leave any other flags unchanged.
``unset_flags`` clears the specified flags, while leaving
any other flags unchanged.

The `seed_mode` flag is special, it can only be cleared once the
torrent has been added, and it can only be set as part of the
`add_torrent_params`__ flags, when adding the torrent.


__ reference-Core.html#torrent_flags_t
__ reference-Add_Torrent.html#add_torrent_params

.. raw:: html

	<a name="flush_cache()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Bflush_cache%28%29%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Bflush_cache%28%29%5D%22+could+be+improved">report issue</a>]</span>



flush_cache()
.............

.. parsed-literal::
	
	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.


__ reference-Alerts.html#cache_flushed_alert
__ reference-Alerts.html#alert

.. raw:: html

	<a name="force_recheck()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Bforce_recheck%28%29%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Bforce_recheck%28%29%5D%22+could+be+improved">report issue</a>]</span>



force_recheck()
...............

.. parsed-literal::
	
	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.
The torrent will be placed last in queue, i.e. its queue position
will be the highest of all torrents in the `session`__.


__ reference-Session.html#session

.. raw:: html

	<a name="save_resume_data()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Bsave_resume_data%28%29%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Bsave_resume_data%28%29%5D%22+could+be+improved">report issue</a>]</span>



save_resume_data()
..................

.. parsed-literal::
	
	void **save_resume_data** (resume\_data\_flags\_t flags = {}) const;
	

``save_resume_data()`` asks libtorrent to generate fast-resume data for
this torrent. The fast resume data (stored in an `add_torrent_params`__
object) can be used to resume a torrent in the next `session`__ without
having to check all files for which pieces have been downloaded. It
can also be used to save a .torrent file for a `torrent_handle`__.

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

The operation will fail, and post a `save_resume_data_failed_alert`__
instead, in the following cases:

	1. The torrent is in the process of being removed.
	2. No torrent state has changed since the last saving of resume
	   data, and the only_if_modified flag is set.
	   metadata (see libtorrent's `metadata from peers`__ extension)

Note that some `counters`__ may be outdated by the time you receive the fast resume data

When saving resume data because of shutting down, make sure not to
`remove_torrent()`__ before you receive the `save_resume_data_alert`__.
There's no need to pause the `session`__ or torrent when saving resume
data.

The paused state of a torrent is saved in the resume data, so pausing
all torrents before saving resume data will all torrents be restored
in a paused state.

.. note::
  It is typically a good idea to save resume data whenever a torrent
  is completed or paused. If you save resume data for torrents when they are
  paused, you can accelerate the shutdown process by not saving resume
  data again for those torrents. Completed torrents should have their
  resume data saved when they complete and on exit, since their
  statistics might be updated.

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

.. code:: c++

	extern int outstanding_resume_data; // global counter of outstanding resume data
	std::vector<torrent_handle> handles = ses.get_torrents();
	for (torrent_handle const& h : handles) try
	{
		h.save_resume_data(torrent_handle::only_if_modified);
		++outstanding_resume_data;
	}
	catch (lt::system_error const& e)
	{
		// the handle was invalid, ignore this one and move to the next
	}

	while (outstanding_resume_data > 0)
	{
		alert const* a = ses.wait_for_alert(seconds(30));

		// if we don't get an alert within 30 seconds, abort
		if (a == nullptr) break;

		std::vector<alert*> alerts;
		ses.pop_alerts(&alerts);

		for (alert* i : alerts)
		{
			if (alert_cast<save_resume_data_failed_alert>(i))
			{
				process_alert(i);
				--outstanding_resume_data;
				continue;
			}

			save_resume_data_alert const* rd = alert_cast<save_resume_data_alert>(i);
			if (rd == nullptr)
			{
				process_alert(i);
				continue;
			}

			std::ofstream out((rd->params.save_path
				+ "/" + rd->params.name + ".fastresume").c_str()
				, std::ios_base::binary);
			std::vector<char> buf = write_resume_data_buf(rd->params);
			out.write(buf.data(), buf.size());
			--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.


__ reference-Add_Torrent.html#add_torrent_params
__ reference-Session.html#session
__ reference-Torrent_Handle.html#torrent_handle
__ reference-Alerts.html#save_resume_data_alert
__ reference-Alerts.html#save_resume_data_failed_alert
__ manual-ref.html#metadata-from-peers
__ reference-Stats.html#counters
__ reference-Custom_Storage.html#remove_torrent()
__ reference-Alerts.html#save_resume_data_alert
__ reference-Session.html#session
__ reference-Alerts.html#alert

.. raw:: html

	<a name="need_save_resume_data()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Bneed_save_resume_data%28%29%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Bneed_save_resume_data%28%29%5D%22+could+be+improved">report issue</a>]</span>



need_save_resume_data()
.......................

.. parsed-literal::
	
	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
	`save_resume_data_alert`__ is posted. It is important to make sure this
	`alert`__ is received and handled in order for this function to be
	meaningful.


__ reference-Alerts.html#save_resume_data_alert
__ reference-Alerts.html#alert

.. raw:: html

	<a name="queue_position_bottom()"></a>
	<a name="queue_position()"></a>
	<a name="queue_position_down()"></a>
	<a name="queue_position_top()"></a>
	<a name="queue_position_up()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Bqueue_position_bottom%28%29+queue_position%28%29+queue_position_down%28%29+queue_position_top%28%29+queue_position_up%28%29%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Bqueue_position_bottom%28%29+queue_position%28%29+queue_position_down%28%29+queue_position_top%28%29+queue_position_up%28%29%5D%22+could+be+improved">report issue</a>]</span>



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

.. parsed-literal::
	
	void **queue_position_down** () const;
	void **queue_position_top** () const;
	queue_position_t **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.


__ reference-Torrent_Status.html#torrent_status

.. raw:: html

	<a name="queue_position_set()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Bqueue_position_set%28%29%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Bqueue_position_set%28%29%5D%22+could+be+improved">report issue</a>]</span>



queue_position_set()
....................

.. parsed-literal::
	
	void **queue_position_set** (queue\_position\_t p) const;
	

updates the position in the queue for this torrent. The relative order
of all other torrents remain intact but their numerical queue position
shifts to make space for this torrent's new position



.. raw:: html

	<a name="set_ssl_certificate_buffer()"></a>
	<a name="set_ssl_certificate()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Bset_ssl_certificate_buffer%28%29+set_ssl_certificate%28%29%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Bset_ssl_certificate_buffer%28%29+set_ssl_certificate%28%29%5D%22+could+be+improved">report issue</a>]</span>



set_ssl_certificate_buffer() set_ssl_certificate()
..................................................

.. parsed-literal::
	
	void **set_ssl_certificate** (std\:\:string const& certificate
	      , std\:\:string const& private\_key
	      , std\:\:string const& dh\_params
	      , std\:\:string const& passphrase = "");
	void **set_ssl_certificate_buffer** (std\:\:string const& certificate
	      , std\:\:string const& private\_key
	      , std\:\:string const& dh\_params);
	

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.

The `set_ssl_certificate_buffer()`__ overload takes the actual certificate,
private key and DH params as strings, rather than paths to files.

``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.


__ reference-Torrent_Handle.html#set_ssl_certificate_buffer()
__ reference-Alerts.html#torrent_need_cert_alert

.. raw:: html

	<a name="torrent_file_with_hashes()"></a>
	<a name="torrent_file()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Btorrent_file_with_hashes%28%29+torrent_file%28%29%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Btorrent_file_with_hashes%28%29+torrent_file%28%29%5D%22+could+be+improved">report issue</a>]</span>



torrent_file_with_hashes() torrent_file()
.........................................

.. parsed-literal::
	
	std::shared_ptr<torrent_info> **torrent_file_with_hashes** () const;
	std::shared_ptr<const torrent_info> **torrent_file** () const;
	

`torrent_file()`__ returns a pointer to the `torrent_info`__ object
associated with this torrent. The `torrent_info`__ object may be a copy
of the internal object. If the torrent doesn't have metadata, the
pointer will not be initialized (i.e. a nullptr). The torrent may be
in a state without metadata only if it was started without a .torrent
file, e.g. by being added by magnet link.

Note that the `torrent_info`__ object returned here may be a different
instance than the one added to the `session`__, with different attributes
like piece layers, dht nodes and trackers. A `torrent_info`__ object does
not round-trip cleanly when added to a `session`__.

If you want to save a .torrent file from the `torrent_handle`__, instead
call `save_resume_data()`__ and `write_torrent_file()`__ the
`add_torrent_params`__ object passed back in the `alert`__.

`torrent_file_with_hashes()`__ returns a *copy* of the internal
`torrent_info`__ and piece layer hashes (if it's a v2 torrent). The piece
layers will only be included if they are available. If this torrent
was added from a .torrent file with piece layers or if it's seeding,
the piece layers are available. This function is more expensive than
`torrent_file()`__ since it needs to make copies of this information.

The `torrent_file_with_hashes()`__ is here for backwards compatibility
when constructing a `create_torrent`__ object from a `torrent_info`__ that's
in a `session`__. Prefer `save_resume_data()`__ + `write_torrent_file()`__.

Note that a torrent added from a magnet link may not have the full
merkle trees for all files, and hence not have the complete piece
layers. In that state, you cannot create a .torrent file even from
the `torrent_info`__ returned from `torrent_file_with_hashes()`__. Once the
torrent completes downloading all files, becoming a seed, you can
make a .torrent file from it.


__ reference-Torrent_Handle.html#torrent_file()
__ reference-Torrent_Info.html#torrent_info
__ reference-Torrent_Info.html#torrent_info
__ reference-Torrent_Info.html#torrent_info
__ reference-Session.html#session
__ reference-Torrent_Info.html#torrent_info
__ reference-Session.html#session
__ reference-Torrent_Handle.html#torrent_handle
__ reference-Torrent_Handle.html#save_resume_data()
__ reference-Resume_Data.html#write_torrent_file()
__ reference-Add_Torrent.html#add_torrent_params
__ reference-Alerts.html#alert
__ reference-Torrent_Handle.html#torrent_file_with_hashes()
__ reference-Torrent_Info.html#torrent_info
__ reference-Torrent_Handle.html#torrent_file()
__ reference-Torrent_Handle.html#torrent_file_with_hashes()
__ reference-Create_Torrents.html#create_torrent
__ reference-Torrent_Info.html#torrent_info
__ reference-Session.html#session
__ reference-Torrent_Handle.html#save_resume_data()
__ reference-Resume_Data.html#write_torrent_file()
__ reference-Torrent_Info.html#torrent_info
__ reference-Torrent_Handle.html#torrent_file_with_hashes()

.. raw:: html

	<a name="piece_layers()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Bpiece_layers%28%29%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Bpiece_layers%28%29%5D%22+could+be+improved">report issue</a>]</span>



piece_layers()
..............

.. parsed-literal::
	
	std::vector<std::vector<sha256_hash>> **piece_layers** () const;
	

returns the piece layers for all files in the torrent. If this is a
v1 torrent (and doesn't have any piece layers) it returns an empty
vector. This is a blocking call that will synchronize with the
libtorrent network thread.



.. raw:: html

	<a name="piece_availability()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Bpiece_availability%28%29%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Bpiece_availability%28%29%5D%22+could+be+improved">report issue</a>]</span>



piece_availability()
....................

.. parsed-literal::
	
	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 advertised having a particular piece. This is the information
that libtorrent uses in order to prefer picking rare pieces.



.. raw:: html

	<a name="get_piece_priorities()"></a>
	<a name="piece_priority()"></a>
	<a name="prioritize_pieces()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Bget_piece_priorities%28%29+piece_priority%28%29+prioritize_pieces%28%29%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Bget_piece_priorities%28%29+piece_priority%28%29+prioritize_pieces%28%29%5D%22+could+be+improved">report issue</a>]</span>



get_piece_priorities() piece_priority() prioritize_pieces()
...........................................................

.. parsed-literal::
	
	void **prioritize_pieces** (std\:\:vector<std\:\:pair<piece\_index\_t, download\_priority\_t>> const& pieces) const;
	std::vector<download_priority_t> **get_piece_priorities** () const;
	void **piece_priority** (piece\_index\_t index, download\_priority\_t priority) const;
	download_priority_t **piece_priority** (piece\_index\_t index) const;
	void **prioritize_pieces** (std\:\:vector<download\_priority\_t> const& pieces) const;
	

These functions are used to set and get the priority of individual
pieces. By default all pieces have priority 4. 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
priority levels. 0 means not to download the piece at all. Otherwise,
lower priority values means less likely to be picked. Piece priority
takes precedence over piece availability. Every piece with priority 7
will be attempted to be picked before a priority 6 piece and so on.

The default priority of pieces is 4.

Piece priorities can not be changed for torrents that have not
downloaded the metadata yet. Magnet links won't have metadata
immediately. see the `metadata_received_alert`__.

``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.
The second overload of ``prioritize_pieces`` that takes a vector of pairs
will update the priorities of only select pieces, and leave all other
unaffected. Each pair is (piece, priority). That is, the first item is
the piece index and the second item is the priority of that piece.
Invalid entries, where the piece index or priority is out of range, are
not allowed.

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

It's possible to cancel the effect of *file* priorities by setting the
priorities for the affected pieces. Care has to be taken when mixing
usage of file- and piece priorities.


__ reference-Alerts.html#metadata_received_alert

.. raw:: html

	<a name="get_file_priorities()"></a>
	<a name="file_priority()"></a>
	<a name="prioritize_files()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Bget_file_priorities%28%29+file_priority%28%29+prioritize_files%28%29%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Bget_file_priorities%28%29+file_priority%28%29+prioritize_files%28%29%5D%22+could+be+improved">report issue</a>]</span>



get_file_priorities() file_priority() prioritize_files()
........................................................

.. parsed-literal::
	
	void **prioritize_files** (std\:\:vector<download\_priority\_t> const& files) const;
	download_priority_t **file_priority** (file\_index\_t index) const;
	std::vector<download_priority_t> **get_file_priorities** () const;
	void **file_priority** (file\_index\_t index, download\_priority\_t priority) 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.

``get_file_priorities()`` returns a vector with the priorities of all
files.

The priority values are the same as for `piece_priority()`__. See
`download_priority_t`__.

Whenever a file priority is changed, all other piece priorities are
reset to match the file priorities. In order to maintain special
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.

Since changing file priorities may involve disk operations (of moving
files in- and out of the part file), the internal accounting of file
priorities happen asynchronously. i.e. setting file priorities and then
immediately querying them may not yield the same priorities just set.
To synchronize with the priorities taking effect, wait for the
`file_prio_alert`__.

When combining file- and piece priorities, the resume file will record
both. When loading the resume data, the file priorities will be applied
first, then the piece priorities.

Moving data from a file into the part file is currently not
supported. If a file has its priority set to 0 *after* it has already
been created, it will not be moved into the partfile.


__ reference-Bencoding.html#entry
__ reference-Torrent_Handle.html#piece_priority()
__ reference-Core.html#download_priority_t
__ reference-Torrent_Handle.html#piece_priority()
__ reference-Torrent_Handle.html#prioritize_files()
__ reference-Alerts.html#file_prio_alert

.. raw:: html

	<a name="force_lsd_announce()"></a>
	<a name="force_dht_announce()"></a>
	<a name="force_reannounce()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Bforce_lsd_announce%28%29+force_dht_announce%28%29+force_reannounce%28%29%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Bforce_lsd_announce%28%29+force_dht_announce%28%29+force_reannounce%28%29%5D%22+could+be+improved">report issue</a>]</span>



force_lsd_announce() force_dht_announce() force_reannounce()
............................................................

.. parsed-literal::
	
	void **force_dht_announce** () const;
	void **force_reannounce** (int seconds = 0, int idx = -1, reannounce\_flags\_t = {}) const;
	void **force_lsd_announce** () const;
	

``force_reannounce()`` will force this torrent to do another tracker
request, to receive new peers. The ``seconds`` argument specifies how
many seconds from now to issue the tracker announces.

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.

The ``tracker_index`` argument specifies which tracker to re-announce.
If set to -1 (which is the default), all trackers are re-announce.

The ``flags`` argument can be used to affect the re-announce. See
ignore_min_interval.

``force_dht_announce`` will announce the torrent to the DHT
immediately.

``force_lsd_announce`` will announce the torrent on LSD
immediately.



.. raw:: html

	<a name="scrape_tracker()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Bscrape_tracker%28%29%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Bscrape_tracker%28%29%5D%22+could+be+improved">report issue</a>]</span>



scrape_tracker()
................

.. parsed-literal::
	
	void **scrape_tracker** (int idx = -1) const;
	

``scrape_tracker()`` will send a scrape request to a tracker. By
default (``idx`` = -1) it will scrape the last working tracker. If
``idx`` is >= 0, the tracker with the specified index will scraped.

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`__.


__ reference-Torrent_Status.html#torrent_status
__ reference-Alerts.html#scrape_reply_alert
__ reference-Alerts.html#scrape_failed_alert

.. raw:: html

	<a name="set_download_limit()"></a>
	<a name="upload_limit()"></a>
	<a name="set_upload_limit()"></a>
	<a name="download_limit()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Bset_download_limit%28%29+upload_limit%28%29+set_upload_limit%28%29+download_limit%28%29%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Bset_download_limit%28%29+upload_limit%28%29+set_upload_limit%28%29+download_limit%28%29%5D%22+could+be+improved">report issue</a>]</span>



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

.. parsed-literal::
	
	void **set_upload_limit** (int limit) const;
	int **download_limit** () const;
	int **upload_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
(``settings_pack::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.

Local peers are not rate limited by default. see `peer classes`__.


__ manual-ref.html#peer-classes

.. raw:: html

	<a name="connect_peer()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Bconnect_peer%28%29%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Bconnect_peer%28%29%5D%22+could+be+improved">report issue</a>]</span>



connect_peer()
..............

.. parsed-literal::
	
	void **connect_peer** (tcp\:\:endpoint const& adr, peer\_source\_flags\_t source = {}
	      , pex\_flags\_t flags = pex\_encryption | pex\_utp | pex\_holepunch) 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 system_error. The second (optional)
argument will be bitwise 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.

For possible values of ``flags``, see `pex_flags_t`__.


__ reference-Core.html#peer_info
__ reference-Core.html#pex_flags_t

.. raw:: html

	<a name="clear_peers()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Bclear_peers%28%29%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Bclear_peers%28%29%5D%22+could+be+improved">report issue</a>]</span>



clear_peers()
.............

.. parsed-literal::
	
	void **clear_peers** ();
	

This will disconnect all peers and clear the peer list for this
torrent. New peers will have to be acquired before resuming, from
trackers, DHT or local service discovery, for example.



.. raw:: html

	<a name="set_max_uploads()"></a>
	<a name="max_uploads()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Bset_max_uploads%28%29+max_uploads%28%29%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Bset_max_uploads%28%29+max_uploads%28%29%5D%22+could+be+improved">report issue</a>]</span>



set_max_uploads() max_uploads()
...............................

.. parsed-literal::
	
	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
`settings_pack`__.

``max_uploads()`` returns the current settings.


__ reference-Settings.html#settings_pack

.. raw:: html

	<a name="set_max_connections()"></a>
	<a name="max_connections()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Bset_max_connections%28%29+max_connections%28%29%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Bset_max_connections%28%29+max_connections%28%29%5D%22+could+be+improved">report issue</a>]</span>



set_max_connections() max_connections()
.......................................

.. parsed-literal::
	
	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 `settings_pack`__.

``max_connections()`` returns the current settings.


__ reference-Settings.html#settings_pack

.. raw:: html

	<a name="move_storage()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Bmove_storage%28%29%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Bmove_storage%28%29%5D%22+could+be+improved">report issue</a>]</span>



move_storage()
..............

.. parsed-literal::
	
	void **move_storage** (std\:\:string const& save\_path
	      , move\_flags\_t flags = move\_flags\_t\:\:always\_replace\_files
	      ) 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`` 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 keeps the existing file in the target
directory, if there is one. The source files will still be removed in
that case. Note that it won't automatically re-check files. If an
incomplete torrent is moved into a directory with the complete files,
pause, move, force-recheck and resume. Without the re-checking, the
torrent will keep downloading and files in the new download directory
will be overwritten.

Files that have been renamed to have absolute paths 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.

When copying files, sparse regions are not likely to be preserved.
This makes it proportionally more expensive to move a large torrent
when only few pieces have been downloaded, since the files are then
allocated with zeros in the destination directory.


__ reference-Storage.html#move_flags_t

.. raw:: html

	<a name="rename_file()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Brename_file%28%29%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Brename_file%28%29%5D%22+could+be+improved">report issue</a>]</span>



rename_file()
.............

.. parsed-literal::
	
	void **rename_file** (file\_index\_t 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.


__ reference-Alerts.html#file_renamed_alert
__ reference-Alerts.html#file_rename_failed_alert

.. raw:: html

	<a name="info_hashes()"></a>
	<a name="info_hash()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Binfo_hashes%28%29+info_hash%28%29%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Binfo_hashes%28%29+info_hash%28%29%5D%22+could+be+improved">report issue</a>]</span>



info_hashes() info_hash()
.........................

.. parsed-literal::
	
	info_hash_t **info_hashes** () const;
	sha1_hash **info_hash** () const;
	

returns the info-hash(es) of the torrent. If this handle is to a
torrent that hasn't loaded yet (for instance by being added) by a
URL, the returned value is undefined.
The ``info_hash()`` returns the SHA-1 info-hash for v1 torrents and a
truncated hash for v2 torrents. For the full v2 info-hash, use
``info_hashes()`` instead.



.. raw:: html

	<a name="operator!=()"></a>
	<a name="operator<()"></a>
	<a name="operator==()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Boperator%21%3D%28%29+operator%3C%28%29+operator%3D%3D%28%29%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Boperator%21%3D%28%29+operator%3C%28%29+operator%3D%3D%28%29%5D%22+could+be+improved">report issue</a>]</span>



operator!=() operator<() operator==()
.....................................

.. parsed-literal::
	
	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.



.. raw:: html

	<a name="id()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Bid%28%29%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Bid%28%29%5D%22+could+be+improved">report issue</a>]</span>



id()
....

.. parsed-literal::
	
	std::uint32_t **id** () const;
	

returns a unique identifier for this torrent. It's not a dense index.
It's not preserved across sessions.



.. raw:: html

	<a name="native_handle()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Bnative_handle%28%29%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Bnative_handle%28%29%5D%22+could+be+improved">report issue</a>]</span>



native_handle()
...............

.. parsed-literal::
	
	std::shared_ptr<torrent> **native_handle** () const;
	

This function is intended only for use by plugins and the `alert`__
dispatch function. This type does not have a stable ABI and should
be relied on as little as possible. Accessing the handle returned by
this function is not thread safe outside of libtorrent's internal
thread (which is used to invoke `plugin`__ callbacks).
The ``torrent`` class is not only eligible for changing ABI across
minor versions of libtorrent, its layout is also dependent on build
configuration. This adds additional requirements on a client to be
built with the exact same build configuration as libtorrent itself.
i.e. the ``TORRENT_`` macros must match between libtorrent and the
client builds.


__ reference-Alerts.html#alert
__ reference-Plugins.html#plugin

.. raw:: html

	<a name="userdata()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Buserdata%28%29%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Buserdata%28%29%5D%22+could+be+improved">report issue</a>]</span>



userdata()
..........

.. parsed-literal::
	
	client_data_t **userdata** () const;
	

returns the userdata pointer as set in `add_torrent_params`__


__ reference-Add_Torrent.html#add_torrent_params

.. raw:: html

	<a name="in_session()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Bin_session%28%29%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Bin_session%28%29%5D%22+could+be+improved">report issue</a>]</span>



in_session()
............

.. parsed-literal::
	
	bool **in_session** () const;
	

Returns true if the torrent is in the `session`__. It returns true before
session::remove_torrent() is called, and false afterward.

Note that this is a blocking function, unlike `torrent_handle::is_valid()`__
which returns immediately.


__ reference-Session.html#session
__ reference-Torrent_Handle.html#is_valid()

.. raw:: html

	<a name="overwrite_existing"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Boverwrite_existing%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Boverwrite_existing%5D%22+could+be+improved">report issue</a>]</span>


overwrite_existing
	instruct libtorrent to overwrite any data that may already have been
	downloaded with the data of the new piece being added. Using this
	flag when adding a piece that is actively being downloaded from other
	peers may have some unexpected consequences, as blocks currently
	being downloaded from peers may not be replaced.
	


.. raw:: html

	<a name="query_distributed_copies"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Bquery_distributed_copies%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Bquery_distributed_copies%5D%22+could+be+improved">report issue</a>]</span>


query_distributed_copies
	calculates ``distributed_copies``, ``distributed_full_copies`` and
	``distributed_fraction``.
	


.. raw:: html

	<a name="query_accurate_download_counters"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Bquery_accurate_download_counters%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Bquery_accurate_download_counters%5D%22+could+be+improved">report issue</a>]</span>


query_accurate_download_counters
	includes partial downloaded blocks in ``total_done`` and
	``total_wanted_done``.
	


.. raw:: html

	<a name="query_last_seen_complete"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Bquery_last_seen_complete%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Bquery_last_seen_complete%5D%22+could+be+improved">report issue</a>]</span>


query_last_seen_complete
	includes ``last_seen_complete``.
	


.. raw:: html

	<a name="query_pieces"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Bquery_pieces%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Bquery_pieces%5D%22+could+be+improved">report issue</a>]</span>


query_pieces
	populate the ``pieces`` field in `torrent_status`__.
	

__ reference-Torrent_Status.html#torrent_status

.. raw:: html

	<a name="query_verified_pieces"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Bquery_verified_pieces%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Bquery_verified_pieces%5D%22+could+be+improved">report issue</a>]</span>


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


.. raw:: html

	<a name="query_torrent_file"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Bquery_torrent_file%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Bquery_torrent_file%5D%22+could+be+improved">report issue</a>]</span>


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


.. raw:: html

	<a name="query_name"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Bquery_name%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Bquery_name%5D%22+could+be+improved">report issue</a>]</span>


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.
	


.. raw:: html

	<a name="query_save_path"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Bquery_save_path%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Bquery_save_path%5D%22+could+be+improved">report issue</a>]</span>


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


.. raw:: html

	<a name="alert_when_available"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Balert_when_available%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Balert_when_available%5D%22+could+be+improved">report issue</a>]</span>


alert_when_available
	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.
	

__ reference-Alerts.html#alert
__ reference-Alerts.html#read_piece_alert
__ reference-Alerts.html#alert

.. raw:: html

	<a name="piece_granularity"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Bpiece_granularity%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Bpiece_granularity%5D%22+could+be+improved">report issue</a>]</span>


piece_granularity
	only calculate file progress at piece granularity. This makes
	the `file_progress()`__ call cheaper and also only takes bytes that
	have passed the hash check into account, so progress cannot
	regress in this mode.
	

__ reference-Torrent_Handle.html#file_progress()

.. raw:: html

	<a name="graceful_pause"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Bgraceful_pause%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Bgraceful_pause%5D%22+could+be+improved">report issue</a>]</span>


graceful_pause
	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.
	


.. raw:: html

	<a name="flush_disk_cache"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Bflush_disk_cache%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Bflush_disk_cache%5D%22+could+be+improved">report issue</a>]</span>


flush_disk_cache
	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.
	


.. raw:: html

	<a name="save_info_dict"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Bsave_info_dict%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Bsave_info_dict%5D%22+could+be+improved">report issue</a>]</span>


save_info_dict
	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).
	


.. raw:: html

	<a name="only_if_modified"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Bonly_if_modified%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Bonly_if_modified%5D%22+could+be+improved">report issue</a>]</span>


only_if_modified
	if nothing significant has changed in the torrent since the last
	time resume data was saved, fail this attempt. Significant changes
	primarily include more data having been downloaded, file or piece
	priorities having changed etc. If the resume data doesn't need
	saving, a `save_resume_data_failed_alert`__ is posted with the error
	resume_data_not_modified.
	

__ reference-Alerts.html#save_resume_data_failed_alert

.. raw:: html

	<a name="ignore_min_interval"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:torrent_handle%3A%3A%5Bignore_min_interval%5D&labels=documentation&body=Documentation+under+heading+%22torrent_handle%3A%3A%5Bignore_min_interval%5D%22+could+be+improved">report issue</a>]</span>


ignore_min_interval
	by default, force-reannounce will still honor the min-interval
	published by the tracker. If this flag is set, it will be ignored
	and the tracker is announced immediately.
	


.. raw:: html

	<a name="hash_value()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:hash_value%28%29&labels=documentation&body=Documentation+under+heading+%22hash_value%28%29%22+could+be+improved">report issue</a>]</span>



hash_value()
------------

Declared in "`libtorrent/torrent_handle.hpp`__"


__ include/libtorrent/torrent_handle.hpp

.. parsed-literal::
	
	std::size_t **hash_value** (torrent\_handle const& h);
	

for std::hash (and to support using this type in unordered_map etc.)





.. _`BEP 3`: https://www.bittorrent.org/beps/bep_0003.html
.. _`BEP 17`: https://www.bittorrent.org/beps/bep_0017.html
.. _extensions: manual-ref.html#extensions
.. _`BEP 52`: https://www.bittorrent.org/beps/bep_0052.html
.. _`BEP 19`: https://www.bittorrent.org/beps/bep_0019.html
.. _`BEP 38`: https://www.bittorrent.org/beps/bep_0038.html
.. _`rate based choking`: manual-ref.html#rate-based-choking
.. _`BEP 42`: https://www.bittorrent.org/beps/bep_0042.html
