2003-10-26 18:35:23 +01:00
|
|
|
/*
|
|
|
|
|
2018-04-09 09:04:33 +02:00
|
|
|
Copyright (c) 2003-2018, Arvid Norberg
|
2003-10-26 18:35:23 +01:00
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions
|
|
|
|
are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
* Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in
|
|
|
|
the documentation and/or other materials provided with the distribution.
|
|
|
|
* Neither the name of the author nor the names of its
|
|
|
|
contributors may be used to endorse or promote products derived
|
|
|
|
from this software without specific prior written permission.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef TORRENT_TORRENT_HANDLE_HPP_INCLUDED
|
|
|
|
#define TORRENT_TORRENT_HANDLE_HPP_INCLUDED
|
|
|
|
|
2015-09-18 06:23:45 +02:00
|
|
|
#include "libtorrent/config.hpp"
|
|
|
|
|
2003-10-26 18:35:23 +01:00
|
|
|
#include <vector>
|
2007-08-17 18:40:55 +02:00
|
|
|
#include <set>
|
2016-08-13 03:31:55 +02:00
|
|
|
#include <functional>
|
2016-09-01 03:42:18 +02:00
|
|
|
#include <memory>
|
2004-01-25 19:18:36 +01:00
|
|
|
|
2016-06-20 17:32:06 +02:00
|
|
|
#include "libtorrent/aux_/disable_warnings_push.hpp"
|
2018-04-26 09:01:14 +02:00
|
|
|
#if TORRENT_ABI_VERSION == 1
|
2015-04-25 03:40:39 +02:00
|
|
|
// for deprecated force_reannounce
|
|
|
|
#include <boost/date_time/posix_time/posix_time_duration.hpp>
|
|
|
|
#endif
|
2015-04-21 03:16:28 +02:00
|
|
|
#include "libtorrent/aux_/disable_warnings_pop.hpp"
|
2004-01-25 19:18:36 +01:00
|
|
|
|
2018-04-26 09:01:14 +02:00
|
|
|
#include "libtorrent/fwd.hpp"
|
2009-11-23 09:38:50 +01:00
|
|
|
#include "libtorrent/address.hpp"
|
2009-11-26 06:45:43 +01:00
|
|
|
#include "libtorrent/socket.hpp" // tcp::endpoint
|
2016-08-22 17:02:51 +02:00
|
|
|
#include "libtorrent/span.hpp"
|
2016-08-26 01:07:16 +02:00
|
|
|
#include "libtorrent/sha1_hash.hpp"
|
2016-12-22 16:42:33 +01:00
|
|
|
#include "libtorrent/units.hpp"
|
|
|
|
#include "libtorrent/aux_/vector.hpp"
|
2017-06-01 10:15:15 +02:00
|
|
|
#include "libtorrent/storage_defs.hpp"
|
2017-07-09 16:32:01 +02:00
|
|
|
#include "libtorrent/torrent_flags.hpp"
|
2017-07-16 20:26:00 +02:00
|
|
|
#include "libtorrent/peer_info.hpp" // for peer_source_flags_t
|
2017-10-29 00:44:40 +02:00
|
|
|
#include "libtorrent/download_priority.hpp"
|
2017-12-17 14:15:38 +01:00
|
|
|
#include "libtorrent/pex_flags.hpp"
|
2018-04-01 13:48:17 +02:00
|
|
|
#include "libtorrent/broadcast_socket.hpp" // for is_v6
|
2003-10-26 18:35:23 +01:00
|
|
|
|
2017-07-27 01:16:29 +02:00
|
|
|
namespace libtorrent {
|
|
|
|
namespace aux {
|
|
|
|
struct session_impl;
|
|
|
|
}
|
2003-10-26 18:35:23 +01:00
|
|
|
|
2018-04-26 09:01:14 +02:00
|
|
|
#if TORRENT_ABI_VERSION == 1
|
2009-11-26 06:45:43 +01:00
|
|
|
struct peer_list_entry;
|
2017-07-16 21:25:07 +02:00
|
|
|
#endif
|
2012-08-30 03:54:35 +02:00
|
|
|
class torrent;
|
2007-11-08 02:45:35 +01:00
|
|
|
|
2009-02-23 02:21:19 +01:00
|
|
|
#ifndef BOOST_NO_EXCEPTIONS
|
2019-02-26 20:48:23 +01:00
|
|
|
[[noreturn]] void throw_invalid_handle();
|
2009-02-23 02:21:19 +01:00
|
|
|
#endif
|
2003-11-28 18:29:27 +01:00
|
|
|
|
2018-03-22 23:28:55 +01:00
|
|
|
using status_flags_t = flags::bitfield_flag<std::uint32_t, struct status_flags_tag>;
|
|
|
|
using add_piece_flags_t = flags::bitfield_flag<std::uint8_t, struct add_piece_flags_tag>;
|
|
|
|
using pause_flags_t = flags::bitfield_flag<std::uint8_t, struct pause_flags_tag>;
|
|
|
|
using deadline_flags_t = flags::bitfield_flag<std::uint8_t, struct deadline_flags_tag>;
|
|
|
|
using resume_data_flags_t = flags::bitfield_flag<std::uint8_t, struct resume_data_flags_tag>;
|
2018-09-04 14:31:05 +02:00
|
|
|
using reannounce_flags_t = flags::bitfield_flag<std::uint8_t, struct reannounce_flags_tag>;
|
2018-03-22 23:28:55 +01:00
|
|
|
using queue_position_t = aux::strong_typedef<int, struct queue_position_tag>;
|
2017-10-25 02:39:22 +02:00
|
|
|
|
2013-08-06 04:50:57 +02:00
|
|
|
// holds the state of a block in a piece. Who we requested
|
|
|
|
// it from and how far along we are at downloading it.
|
2011-02-01 10:48:28 +01:00
|
|
|
struct TORRENT_EXPORT block_info
|
2003-10-26 18:35:23 +01:00
|
|
|
{
|
2014-02-02 04:05:55 +01:00
|
|
|
// this is the enum used for the block_info::state field.
|
2011-02-01 10:48:28 +01:00
|
|
|
enum block_state_t
|
2013-08-06 04:50:57 +02:00
|
|
|
{
|
|
|
|
// This block has not been downloaded or requested form any peer.
|
|
|
|
none,
|
|
|
|
// The block has been requested, but not completely downloaded yet.
|
|
|
|
requested,
|
2014-02-02 04:05:55 +01:00
|
|
|
// The block has been downloaded and is currently queued for being
|
|
|
|
// written to disk.
|
2013-08-06 04:50:57 +02:00
|
|
|
writing,
|
|
|
|
// The block has been written to disk.
|
|
|
|
finished
|
|
|
|
};
|
2003-12-22 08:14:35 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
private:
|
2016-06-04 16:03:13 +02:00
|
|
|
union addr_t
|
2003-10-26 18:35:23 +01:00
|
|
|
{
|
2011-02-01 10:48:28 +01:00
|
|
|
address_v4::bytes_type v4;
|
|
|
|
address_v6::bytes_type v6;
|
2018-09-04 13:46:09 +02:00
|
|
|
};
|
|
|
|
addr_t addr;
|
2004-01-17 21:04:19 +01:00
|
|
|
|
2016-06-18 20:01:38 +02:00
|
|
|
std::uint16_t port;
|
2011-02-01 10:48:28 +01:00
|
|
|
public:
|
2003-11-20 20:58:29 +01:00
|
|
|
|
2013-08-06 04:50:57 +02:00
|
|
|
// The peer is the ip address of the peer this block was downloaded from.
|
2011-02-01 10:48:28 +01:00
|
|
|
void set_peer(tcp::endpoint const& ep)
|
|
|
|
{
|
2018-04-01 13:48:17 +02:00
|
|
|
is_v6_addr = is_v6(ep);
|
2011-02-01 10:48:28 +01:00
|
|
|
if (is_v6_addr)
|
|
|
|
addr.v6 = ep.address().to_v6().to_bytes();
|
|
|
|
else
|
|
|
|
addr.v4 = ep.address().to_v4().to_bytes();
|
|
|
|
port = ep.port();
|
|
|
|
}
|
|
|
|
tcp::endpoint peer() const
|
|
|
|
{
|
|
|
|
if (is_v6_addr)
|
|
|
|
return tcp::endpoint(address_v6(addr.v6), port);
|
|
|
|
else
|
|
|
|
return tcp::endpoint(address_v4(addr.v4), port);
|
|
|
|
}
|
2003-12-22 08:14:35 +01:00
|
|
|
|
2013-08-06 04:50:57 +02:00
|
|
|
// the number of bytes that have been received for this block
|
2011-02-01 10:48:28 +01:00
|
|
|
unsigned bytes_progress:15;
|
2013-07-22 17:50:19 +02:00
|
|
|
|
2013-08-06 04:50:57 +02:00
|
|
|
// the total number of bytes in this block.
|
2011-02-01 10:48:28 +01:00
|
|
|
unsigned block_size:15;
|
2013-07-22 17:50:19 +02:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
// the state this block is in (see block_state_t)
|
|
|
|
unsigned state:2;
|
2013-07-22 17:50:19 +02:00
|
|
|
|
2014-02-02 04:05:55 +01:00
|
|
|
// 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.
|
2011-02-01 10:48:28 +01:00
|
|
|
unsigned num_peers:14;
|
2013-07-22 17:50:19 +02:00
|
|
|
private:
|
|
|
|
// the type of the addr union
|
2016-11-20 03:14:16 +01:00
|
|
|
bool is_v6_addr:1;
|
2011-02-01 10:48:28 +01:00
|
|
|
};
|
2004-04-18 14:28:02 +02:00
|
|
|
|
2014-02-02 04:05:55 +01:00
|
|
|
// This class holds information about pieces that have outstanding requests
|
|
|
|
// or outstanding writes
|
2011-02-01 10:48:28 +01:00
|
|
|
struct TORRENT_EXPORT partial_piece_info
|
|
|
|
{
|
2018-04-26 09:01:14 +02:00
|
|
|
#if TORRENT_ABI_VERSION == 1
|
2017-05-15 23:49:03 +02:00
|
|
|
#include "libtorrent/aux_/disable_warnings_push.hpp"
|
|
|
|
partial_piece_info() = default;
|
2017-05-28 13:14:58 +02:00
|
|
|
partial_piece_info(partial_piece_info&&) noexcept = default;
|
2017-05-15 23:49:03 +02:00
|
|
|
partial_piece_info(partial_piece_info const&) = default;
|
|
|
|
partial_piece_info& operator=(partial_piece_info const&) = default;
|
2017-05-28 13:14:58 +02:00
|
|
|
partial_piece_info& operator=(partial_piece_info&&) noexcept = default;
|
2017-05-15 23:49:03 +02:00
|
|
|
#include "libtorrent/aux_/disable_warnings_pop.hpp"
|
|
|
|
#endif
|
2014-02-02 04:05:55 +01:00
|
|
|
// 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
|
2013-08-06 04:50:57 +02:00
|
|
|
// the last piece may have fewer blocks than the standard pieces.
|
2016-12-22 16:42:33 +01:00
|
|
|
piece_index_t piece_index;
|
2013-08-06 04:50:57 +02:00
|
|
|
|
2014-02-02 04:05:55 +01:00
|
|
|
// the number of blocks in this piece
|
2011-02-01 10:48:28 +01:00
|
|
|
int blocks_in_piece;
|
2014-02-02 04:05:55 +01:00
|
|
|
|
|
|
|
// the number of blocks that are in the finished state
|
2011-02-01 10:48:28 +01:00
|
|
|
int finished;
|
2014-02-02 04:05:55 +01:00
|
|
|
|
|
|
|
// the number of blocks that are in the writing state
|
2011-02-01 10:48:28 +01:00
|
|
|
int writing;
|
2014-02-02 04:05:55 +01:00
|
|
|
|
|
|
|
// the number of blocks that are in the requested state
|
2011-02-01 10:48:28 +01:00
|
|
|
int requested;
|
2013-08-06 04:50:57 +02:00
|
|
|
|
|
|
|
// 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.
|
2011-02-01 10:48:28 +01:00
|
|
|
block_info* blocks;
|
2013-08-06 04:50:57 +02:00
|
|
|
|
2018-04-26 09:01:14 +02:00
|
|
|
#if TORRENT_ABI_VERSION == 1
|
2014-02-02 04:05:55 +01:00
|
|
|
// the speed classes. These may be used by the piece picker to
|
|
|
|
// coalesce requests of similar download rates
|
2011-02-01 10:48:28 +01:00
|
|
|
enum state_t { none, slow, medium, fast };
|
2013-08-06 04:50:57 +02:00
|
|
|
|
|
|
|
// the download speed class this piece falls into.
|
|
|
|
// this is used internally to cluster peers of the same
|
|
|
|
// speed class together when requesting blocks.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-02-02 04:05:55 +01:00
|
|
|
// set to either ``fast``, ``medium``, ``slow`` or ``none``. It tells
|
|
|
|
// which download rate category the peers downloading this piece falls
|
|
|
|
// into. ``none`` means that no peer is currently downloading any part of
|
|
|
|
// the piece. Peers prefer picking pieces from the same category as
|
|
|
|
// themselves. The reason for this is to keep the number of partially
|
|
|
|
// downloaded pieces down. Pieces set to ``none`` can be converted into
|
|
|
|
// any of ``fast``, ``medium`` or ``slow`` as soon as a peer want to
|
|
|
|
// download from it.
|
2017-05-14 18:14:32 +02:00
|
|
|
state_t TORRENT_DEPRECATED_MEMBER piece_state;
|
|
|
|
#endif
|
2011-02-01 10:48:28 +01:00
|
|
|
};
|
2006-04-25 23:04:48 +02:00
|
|
|
|
2016-09-07 05:37:36 +02:00
|
|
|
// for std::hash (and to support using this type in unordered_map etc.)
|
|
|
|
TORRENT_EXPORT std::size_t hash_value(torrent_handle const& h);
|
2014-07-06 21:18:00 +02:00
|
|
|
|
2014-02-02 04:05:55 +01:00
|
|
|
// 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.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2013-08-06 04:50:57 +02:00
|
|
|
// .. warning::
|
2014-02-02 04:05:55 +01:00
|
|
|
// 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
|
2016-04-14 20:03:11 +02:00
|
|
|
// responsive. Try to avoid querying for information you don't need, and
|
2014-02-02 04:05:55 +01:00
|
|
|
// 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.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-02-02 04:05:55 +01:00
|
|
|
// 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``.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-02-02 04:05:55 +01:00
|
|
|
// .. warning::
|
2016-05-15 06:33:06 +02:00
|
|
|
// All operations on a torrent_handle may throw system_error
|
2016-04-14 20:03:11 +02:00
|
|
|
// exception, in case the handle is no longer referring to a torrent.
|
2014-02-02 04:05:55 +01:00
|
|
|
// 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.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2011-02-01 10:48:28 +01:00
|
|
|
struct TORRENT_EXPORT torrent_handle
|
|
|
|
{
|
|
|
|
friend struct aux::session_impl;
|
2015-06-28 23:12:27 +02:00
|
|
|
friend struct session_handle;
|
2011-02-01 10:48:28 +01:00
|
|
|
friend class torrent;
|
2016-09-07 05:37:36 +02:00
|
|
|
friend TORRENT_EXPORT std::size_t hash_value(torrent_handle const& th);
|
2003-12-22 08:14:35 +01:00
|
|
|
|
2013-11-19 18:57:16 +01:00
|
|
|
// constructs a torrent handle that does not refer to a torrent.
|
|
|
|
// i.e. is_valid() will return false.
|
2018-02-01 01:06:15 +01:00
|
|
|
torrent_handle() noexcept = default;
|
2004-04-18 14:28:02 +02:00
|
|
|
|
2019-09-07 11:20:24 +02:00
|
|
|
// hidden
|
2016-07-05 00:19:55 +02:00
|
|
|
torrent_handle(torrent_handle const& t) = default;
|
2017-05-28 13:14:58 +02:00
|
|
|
torrent_handle(torrent_handle&& t) noexcept = default;
|
2015-09-01 05:23:10 +02:00
|
|
|
torrent_handle& operator=(torrent_handle const&) = default;
|
2017-05-28 13:14:58 +02:00
|
|
|
torrent_handle& operator=(torrent_handle&&) noexcept = default;
|
2015-08-02 05:57:11 +02:00
|
|
|
|
2017-07-27 10:37:32 +02:00
|
|
|
// instruct libtorrent to overwrite any data that may already have been
|
|
|
|
// downloaded with the data of the new piece being added.
|
2017-07-30 18:13:22 +02:00
|
|
|
static constexpr add_piece_flags_t overwrite_existing = 0_bit;
|
2013-08-06 04:50:57 +02:00
|
|
|
|
2014-02-02 04:05:55 +01:00
|
|
|
// This function will write ``data`` to the storage as piece ``piece``,
|
|
|
|
// as if it had been downloaded from a peer. ``data`` is expected to
|
|
|
|
// point to a buffer of as many bytes as the size of the specified piece.
|
|
|
|
// The data in the buffer is copied and passed on to the disk IO thread
|
|
|
|
// to be written at a later point.
|
2013-08-06 04:50:57 +02:00
|
|
|
//
|
2014-02-02 04:05:55 +01:00
|
|
|
// 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.
|
2013-08-06 04:50:57 +02:00
|
|
|
//
|
2014-02-02 04:05:55 +01:00
|
|
|
// 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.
|
2017-07-27 10:37:32 +02:00
|
|
|
void add_piece(piece_index_t piece, char const* data, add_piece_flags_t flags = {}) const;
|
2013-08-06 04:50:57 +02:00
|
|
|
|
2014-02-02 04:05:55 +01:00
|
|
|
// 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.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-02-02 04:05:55 +01:00
|
|
|
// When the read operation is completed, it is passed back through an
|
2016-04-14 20:03:11 +02:00
|
|
|
// alert, read_piece_alert. Since this alert is a response to an explicit
|
2014-02-02 04:05:55 +01:00
|
|
|
// call, it will always be posted, regardless of the alert mask.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-02-02 04:05:55 +01:00
|
|
|
// Note that if you read multiple pieces, the read operations are not
|
|
|
|
// guaranteed to finish in the same order as you initiated them.
|
2016-12-22 16:42:33 +01:00
|
|
|
void read_piece(piece_index_t piece) const;
|
2013-08-06 04:50:57 +02:00
|
|
|
|
2019-11-28 14:52:40 +01:00
|
|
|
// Returns true if this piece has been completely downloaded and written
|
|
|
|
// to disk, and false otherwise.
|
2016-12-22 16:42:33 +01:00
|
|
|
bool have_piece(piece_index_t piece) const;
|
2007-11-20 23:46:27 +01:00
|
|
|
|
2018-04-26 09:01:14 +02:00
|
|
|
#if TORRENT_ABI_VERSION == 1
|
2014-02-02 05:07:36 +01:00
|
|
|
// internal
|
2016-06-17 22:07:28 +02:00
|
|
|
TORRENT_DEPRECATED
|
2011-02-01 10:48:28 +01:00
|
|
|
void get_full_peer_list(std::vector<peer_list_entry>& v) const;
|
2016-06-17 22:07:28 +02:00
|
|
|
#endif
|
2013-08-06 04:50:57 +02:00
|
|
|
|
2014-02-02 04:05:55 +01:00
|
|
|
// 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
|
2016-05-15 06:33:06 +02:00
|
|
|
// system_error exception. Each entry in the vector contains
|
2014-02-02 04:05:55 +01:00
|
|
|
// information about that particular peer. See peer_info.
|
2011-02-01 10:48:28 +01:00
|
|
|
void get_peer_info(std::vector<peer_info>& v) const;
|
2004-01-15 02:01:09 +01:00
|
|
|
|
2017-07-27 01:50:46 +02:00
|
|
|
// calculates ``distributed_copies``, ``distributed_full_copies`` and
|
|
|
|
// ``distributed_fraction``.
|
2017-07-30 18:13:22 +02:00
|
|
|
static constexpr status_flags_t query_distributed_copies = 0_bit;
|
2018-08-07 22:23:13 +02:00
|
|
|
|
2017-07-27 01:50:46 +02:00
|
|
|
// includes partial downloaded blocks in ``total_done`` and
|
|
|
|
// ``total_wanted_done``.
|
2017-07-30 18:13:22 +02:00
|
|
|
static constexpr status_flags_t query_accurate_download_counters = 1_bit;
|
2018-08-07 22:23:13 +02:00
|
|
|
|
2017-07-27 01:50:46 +02:00
|
|
|
// includes ``last_seen_complete``.
|
2017-07-30 18:13:22 +02:00
|
|
|
static constexpr status_flags_t query_last_seen_complete = 2_bit;
|
2017-07-27 01:50:46 +02:00
|
|
|
// populate the ``pieces`` field in torrent_status.
|
2017-07-30 18:13:22 +02:00
|
|
|
static constexpr status_flags_t query_pieces = 3_bit;
|
2017-07-27 01:50:46 +02:00
|
|
|
// includes ``verified_pieces`` (only applies to torrents in *seed
|
|
|
|
// mode*).
|
2017-07-30 18:13:22 +02:00
|
|
|
static constexpr status_flags_t query_verified_pieces = 4_bit;
|
2017-07-27 01:50:46 +02:00
|
|
|
// includes ``torrent_file``, which is all the static information from
|
|
|
|
// the .torrent file.
|
2017-07-30 18:13:22 +02:00
|
|
|
static constexpr status_flags_t query_torrent_file = 5_bit;
|
2017-07-27 01:50:46 +02:00
|
|
|
// 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.
|
2017-07-30 18:13:22 +02:00
|
|
|
static constexpr status_flags_t query_name = 6_bit;
|
2017-07-27 01:50:46 +02:00
|
|
|
// includes ``save_path``, the path to the directory the files of the
|
|
|
|
// torrent are saved to.
|
2017-07-30 18:13:22 +02:00
|
|
|
static constexpr status_flags_t query_save_path = 7_bit;
|
2005-02-23 21:38:29 +01:00
|
|
|
|
2014-02-02 04:05:55 +01:00
|
|
|
// ``status()`` will return a structure with information about the status
|
|
|
|
// of this torrent. If the torrent_handle is invalid, it will throw
|
2016-05-15 06:33:06 +02:00
|
|
|
// system_error exception. See torrent_status. The ``flags``
|
2014-02-02 04:05:55 +01:00
|
|
|
// 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.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-02-02 04:05:55 +01:00
|
|
|
// By default everything is included. The flags you can use to decide
|
|
|
|
// what to *include* are defined in the status_flags_t enum.
|
2017-07-30 18:13:22 +02:00
|
|
|
torrent_status status(status_flags_t flags = status_flags_t::all()) const;
|
2013-08-06 04:50:57 +02:00
|
|
|
|
2014-02-02 04:05:55 +01:00
|
|
|
// ``get_download_queue()`` takes a non-const reference to a vector which
|
|
|
|
// it will fill with information about pieces that are partially
|
|
|
|
// downloaded or not downloaded at all but partially requested. See
|
|
|
|
// partial_piece_info for the fields in the returned vector.
|
2011-02-01 10:48:28 +01:00
|
|
|
void get_download_queue(std::vector<partial_piece_info>& queue) const;
|
2007-11-20 23:46:27 +01:00
|
|
|
|
2017-07-27 10:37:32 +02:00
|
|
|
// 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.
|
2017-07-30 18:13:22 +02:00
|
|
|
static constexpr deadline_flags_t alert_when_available = 0_bit;
|
2013-08-06 04:50:57 +02:00
|
|
|
|
2014-02-02 04:05:55 +01:00
|
|
|
// 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
|
2013-08-06 04:50:57 +02:00
|
|
|
// function again.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-02-02 04:05:55 +01:00
|
|
|
// 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
|
2017-06-18 20:52:44 +02:00
|
|
|
// will have the same effect as calling read_piece() for ``index``.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-02-02 04:05:55 +01:00
|
|
|
// ``deadline`` is the number of milliseconds until this piece should be
|
|
|
|
// completed.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-02-02 04:05:55 +01:00
|
|
|
// ``reset_piece_deadline`` removes the deadline from the piece. If it
|
|
|
|
// hasn't already been downloaded, it will no longer be considered a
|
|
|
|
// priority.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-05-23 04:23:11 +02:00
|
|
|
// ``clear_piece_deadlines()`` removes deadlines on all pieces in
|
|
|
|
// the torrent. As if reset_piece_deadline() was called on all pieces.
|
2017-07-27 10:37:32 +02:00
|
|
|
void set_piece_deadline(piece_index_t index, int deadline, deadline_flags_t flags = {}) const;
|
2016-12-22 16:42:33 +01:00
|
|
|
void reset_piece_deadline(piece_index_t index) const;
|
2014-05-23 04:23:11 +02:00
|
|
|
void clear_piece_deadlines() const;
|
2008-03-29 19:47:24 +01:00
|
|
|
|
2018-04-26 09:01:14 +02:00
|
|
|
#if TORRENT_ABI_VERSION == 1
|
2014-02-02 04:05:55 +01:00
|
|
|
// This sets the bandwidth priority of this torrent. The priority of a
|
|
|
|
// torrent determines how much bandwidth its peers are assigned when
|
|
|
|
// distributing upload and download rate quotas. A high number gives more
|
|
|
|
// bandwidth. The priority must be within the range [0, 255].
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2013-08-06 04:50:57 +02:00
|
|
|
// The default priority is 0, which is the lowest priority.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-02-02 04:05:55 +01:00
|
|
|
// To query the priority of a torrent, use the
|
|
|
|
// ``torrent_handle::status()`` call.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2016-04-14 20:03:11 +02:00
|
|
|
// Torrents with higher priority will not necessarily get as much
|
2014-02-02 04:05:55 +01:00
|
|
|
// bandwidth as they can consume, even if there's is more quota. Other
|
|
|
|
// peers will still be weighed in when bandwidth is being distributed.
|
|
|
|
// With other words, bandwidth is not distributed strictly in order of
|
|
|
|
// priority, but the priority is used as a weight.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-02-02 04:05:55 +01:00
|
|
|
// Peers whose Torrent has a higher priority will take precedence when
|
2017-06-17 17:35:53 +02:00
|
|
|
// distributing unchoke slots. This is a strict prioritisation where
|
2014-02-02 04:05:55 +01:00
|
|
|
// every interested peer on a high priority torrent will be unchoked
|
|
|
|
// before any other, lower priority, torrents have any peers unchoked.
|
2016-08-26 18:37:23 +02:00
|
|
|
// deprecated in 1.2
|
|
|
|
TORRENT_DEPRECATED
|
2011-02-01 10:48:28 +01:00
|
|
|
void set_priority(int prio) const;
|
2016-08-14 19:11:59 +02:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
#if !TORRENT_NO_FPU
|
|
|
|
// fills the specified vector with the download progress [0, 1]
|
|
|
|
// of each file in the torrent. The files are ordered as in
|
|
|
|
// the torrent_info.
|
2015-04-17 03:49:49 +02:00
|
|
|
TORRENT_DEPRECATED
|
|
|
|
void file_progress(std::vector<float>& progress) const;
|
2011-02-01 10:48:28 +01:00
|
|
|
#endif
|
2016-08-14 19:11:59 +02:00
|
|
|
|
|
|
|
TORRENT_DEPRECATED
|
2017-04-09 00:24:50 +02:00
|
|
|
void file_status(std::vector<open_file_state>& status) const;
|
2011-02-01 10:48:28 +01:00
|
|
|
#endif
|
2014-02-02 05:07:36 +01:00
|
|
|
|
|
|
|
// flags to be passed in file_progress().
|
2011-02-01 10:48:28 +01:00
|
|
|
enum file_progress_flags_t
|
|
|
|
{
|
2014-02-02 05:07:36 +01:00
|
|
|
// 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.
|
2011-02-01 10:48:28 +01:00
|
|
|
piece_granularity = 1
|
|
|
|
};
|
2004-08-05 15:56:26 +02:00
|
|
|
|
2019-02-24 03:16:27 +01:00
|
|
|
// This function fills in the supplied vector with the number of
|
2014-02-02 04:05:55 +01:00
|
|
|
// bytes downloaded of each file in this torrent. The progress values are
|
|
|
|
// ordered the same as the files in the torrent_info. This operation is
|
|
|
|
// not very cheap. Its complexity is *O(n + mj)*. Where *n* is the number
|
|
|
|
// of files, *m* is the number of downloading pieces and *j* is the
|
|
|
|
// number of blocks in a piece.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-02-02 04:05:55 +01:00
|
|
|
// 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.
|
2016-06-18 20:01:38 +02:00
|
|
|
void file_progress(std::vector<std::int64_t>& progress, int flags = 0) const;
|
2005-05-30 19:43:03 +02:00
|
|
|
|
2016-08-14 19:11:59 +02:00
|
|
|
// 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
|
2014-07-06 21:18:00 +02:00
|
|
|
// the vector is empty when returning, if none of the files in the
|
|
|
|
// torrent are currently open.
|
|
|
|
//
|
2019-12-19 22:02:26 +01:00
|
|
|
// See open_file_state
|
2017-04-09 00:24:50 +02:00
|
|
|
std::vector<open_file_state> file_status() const;
|
2014-07-06 21:18:00 +02:00
|
|
|
|
2014-02-02 04:05:55 +01:00
|
|
|
// 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.
|
2011-02-01 10:48:28 +01:00
|
|
|
void clear_error() const;
|
2005-05-30 19:43:03 +02:00
|
|
|
|
2013-08-06 04:50:57 +02:00
|
|
|
// ``trackers()`` will return the list of trackers for this torrent. The
|
2014-02-02 04:05:55 +01:00
|
|
|
// 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.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-02-02 04:05:55 +01:00
|
|
|
// ``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.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-02-02 04:05:55 +01:00
|
|
|
// 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.
|
2011-02-01 10:48:28 +01:00
|
|
|
std::vector<announce_entry> trackers() const;
|
|
|
|
void replace_trackers(std::vector<announce_entry> const&) const;
|
|
|
|
void add_tracker(announce_entry const&) const;
|
2009-07-19 06:59:27 +02:00
|
|
|
|
2015-12-13 17:26:41 +01:00
|
|
|
// TODO: 3 unify url_seed and http_seed with just web_seed, using the
|
|
|
|
// web_seed_entry.
|
|
|
|
|
2014-02-02 04:05:55 +01:00
|
|
|
// ``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
|
2017-06-17 17:35:53 +02:00
|
|
|
// torrent. Note that URLs that fails may be removed automatically from
|
2014-02-02 04:05:55 +01:00
|
|
|
// the list.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2013-08-11 08:04:24 +02:00
|
|
|
// See http-seeding_ for more information.
|
2011-02-01 10:48:28 +01:00
|
|
|
void add_url_seed(std::string const& url) const;
|
|
|
|
void remove_url_seed(std::string const& url) const;
|
|
|
|
std::set<std::string> url_seeds() const;
|
2009-07-19 06:59:27 +02:00
|
|
|
|
2014-02-02 04:05:55 +01:00
|
|
|
// These functions are identical as the ``*_url_seed()`` variants, but
|
|
|
|
// they operate on `BEP 17`_ web seeds instead of `BEP 19`_.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2013-08-11 08:04:24 +02:00
|
|
|
// See http-seeding_ for more information.
|
2011-02-01 10:48:28 +01:00
|
|
|
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;
|
2009-07-19 06:59:27 +02:00
|
|
|
|
2013-11-29 06:29:39 +01:00
|
|
|
// 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.
|
2014-02-02 06:09:18 +01:00
|
|
|
void add_extension(
|
2016-08-17 20:30:24 +02:00
|
|
|
std::function<std::shared_ptr<torrent_plugin>(torrent_handle const&, void*)> const& ext
|
2017-09-28 10:11:20 +02:00
|
|
|
, void* userdata = nullptr);
|
2004-08-11 19:22:58 +02:00
|
|
|
|
2014-02-02 04:05:55 +01:00
|
|
|
// ``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.
|
2016-08-22 17:02:51 +02:00
|
|
|
bool set_metadata(span<char const> metadata) const;
|
|
|
|
|
2018-04-26 09:01:14 +02:00
|
|
|
#if TORRENT_ABI_VERSION == 1
|
2016-08-22 17:02:51 +02:00
|
|
|
TORRENT_DEPRECATED
|
|
|
|
bool set_metadata(char const* metadata, int size) const
|
2018-11-01 23:05:30 +01:00
|
|
|
{ return set_metadata({metadata, size}); }
|
2016-08-22 17:02:51 +02:00
|
|
|
#endif
|
2012-10-02 18:07:55 +02:00
|
|
|
|
2014-02-02 04:05:55 +01:00
|
|
|
// Returns true if this handle refers to a valid torrent and false if it
|
|
|
|
// hasn't been initialized or if the torrent it refers to has been
|
|
|
|
// aborted. Note that a handle may become invalid after it has been added
|
|
|
|
// to the session. Usually this is because the storage for the torrent is
|
|
|
|
// somehow invalid or if the filenames are not allowed (and hence cannot
|
|
|
|
// be opened/created) on your filesystem. If such an error occurs, a
|
|
|
|
// file_error_alert is generated and all handles that refers to that
|
|
|
|
// torrent will become invalid.
|
2011-02-01 10:48:28 +01:00
|
|
|
bool is_valid() const;
|
2007-07-17 08:39:39 +02:00
|
|
|
|
2017-07-27 10:37:32 +02:00
|
|
|
// 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.
|
2017-07-30 18:13:22 +02:00
|
|
|
static constexpr pause_flags_t graceful_pause = 0_bit;
|
2018-07-15 23:34:47 +02:00
|
|
|
static constexpr pause_flags_t clear_disk_cache = 1_bit;
|
2013-08-06 04:50:57 +02:00
|
|
|
|
2014-02-02 04:05:55 +01:00
|
|
|
// ``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.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-02-02 04:05:55 +01:00
|
|
|
// To know if a torrent is paused or not, call
|
|
|
|
// ``torrent_handle::status()`` and inspect ``torrent_status::paused``.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2015-09-19 23:49:01 +02:00
|
|
|
// .. 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
|
2017-06-17 17:35:53 +02:00
|
|
|
// not auto-managed first. Torrents are auto-managed by default when added
|
2015-09-19 23:49:01 +02:00
|
|
|
// to the session. For more information, see queuing_.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2017-07-27 10:37:32 +02:00
|
|
|
void pause(pause_flags_t flags = {}) const;
|
2011-02-01 10:48:28 +01:00
|
|
|
void resume() const;
|
2013-08-06 04:50:57 +02:00
|
|
|
|
2017-07-09 16:32:01 +02:00
|
|
|
// 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.
|
2019-02-15 14:09:20 +01:00
|
|
|
//
|
|
|
|
// The `seed_mode` flag is special, it can only be cleared by the
|
|
|
|
// `set_flags()` function, not set.
|
2017-07-09 16:32:01 +02:00
|
|
|
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;
|
|
|
|
void unset_flags(torrent_flags_t flags) const;
|
2015-09-18 06:23:45 +02:00
|
|
|
|
2014-02-02 04:05:55 +01:00
|
|
|
// 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.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-02-02 04:05:55 +01:00
|
|
|
// 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.
|
2011-02-01 10:48:28 +01:00
|
|
|
void flush_cache() const;
|
2007-07-23 06:36:56 +02:00
|
|
|
|
2014-02-02 04:05:55 +01:00
|
|
|
// ``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.
|
2011-02-01 10:48:28 +01:00
|
|
|
void force_recheck() const;
|
2008-01-17 18:40:46 +01:00
|
|
|
|
2017-07-27 01:16:29 +02:00
|
|
|
// 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.
|
2017-07-30 18:13:22 +02:00
|
|
|
static constexpr resume_data_flags_t flush_disk_cache = 0_bit;
|
2017-07-27 01:16:29 +02:00
|
|
|
|
|
|
|
// 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).
|
2017-07-30 18:13:22 +02:00
|
|
|
static constexpr resume_data_flags_t save_info_dict = 1_bit;
|
2017-07-27 01:16:29 +02:00
|
|
|
|
|
|
|
// 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.
|
2017-07-30 18:13:22 +02:00
|
|
|
static constexpr resume_data_flags_t only_if_modified = 2_bit;
|
2013-08-06 04:50:57 +02:00
|
|
|
|
2016-02-21 23:09:41 +01:00
|
|
|
// ``save_resume_data()`` asks libtorrent to generate fast-resume data for
|
|
|
|
// this torrent.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-02-02 04:05:55 +01:00
|
|
|
// This operation is asynchronous, ``save_resume_data`` will return
|
|
|
|
// immediately. The resume data is delivered when it's done through an
|
|
|
|
// save_resume_data_alert.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2013-08-06 04:50:57 +02:00
|
|
|
// The fast resume data will be empty in the following cases:
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2013-08-06 04:50:57 +02:00
|
|
|
// 1. The torrent handle is invalid.
|
2016-02-21 23:09:41 +01:00
|
|
|
// 2. The torrent hasn't received valid metadata and was started without
|
2014-02-02 04:05:55 +01:00
|
|
|
// metadata (see libtorrent's metadata-from-peers_ extension)
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-02-02 04:05:55 +01:00
|
|
|
// Note that by the time you receive the fast resume data, it may already
|
|
|
|
// be invalid if the torrent is still downloading! The recommended
|
|
|
|
// practice is to first pause the session, then generate the fast resume
|
|
|
|
// data, and then close it down. Make sure to not remove_torrent() before
|
|
|
|
// you receive the save_resume_data_alert though. There's no need to
|
|
|
|
// pause when saving intermittent resume data.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-02-02 04:05:55 +01:00
|
|
|
//.. warning::
|
|
|
|
// If you pause every torrent individually instead of pausing the
|
|
|
|
// session, every torrent will have its paused state saved in the
|
|
|
|
// resume data!
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-02-02 04:05:55 +01:00
|
|
|
//.. warning::
|
|
|
|
// The resume data contains the modification timestamps for all files.
|
|
|
|
// If one file has been modified when the torrent is added again, the
|
|
|
|
// will be rechecked. When shutting down, make sure to flush the disk
|
|
|
|
// cache before saving the resume data. This will make sure that the
|
|
|
|
// file timestamps are up to date and won't be modified after saving
|
|
|
|
// the resume data. The recommended way to do this is to pause the
|
|
|
|
// torrent, which will flush the cache and disconnect all peers.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-02-02 04:05:55 +01:00
|
|
|
//.. note::
|
|
|
|
// It is typically a good idea to save resume data whenever a torrent
|
|
|
|
// is completed or paused. In those cases you don't need to pause the
|
|
|
|
// torrent or the session, since the torrent will do no more writing to
|
|
|
|
// its files. If you save resume data for torrents when they are
|
|
|
|
// paused, you can accelerate the shutdown process by not saving resume
|
|
|
|
// data again for paused torrents. Completed torrents should have their
|
|
|
|
// resume data saved when they complete and on exit, since their
|
|
|
|
// statistics might be updated.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2016-04-14 20:03:11 +02:00
|
|
|
// In full allocation mode the resume data is never invalidated by
|
2014-02-02 04:05:55 +01:00
|
|
|
// subsequent writes to the files, since pieces won't move around. This
|
|
|
|
// means that you don't need to pause before writing resume data in full
|
|
|
|
// or sparse mode. If you don't, however, any data written to disk after
|
|
|
|
// you saved resume data and before the session closed is lost.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-02-02 04:05:55 +01:00
|
|
|
// It also means that if the resume data is out dated, libtorrent will
|
|
|
|
// not re-check the files, but assume that it is fairly recent. The
|
|
|
|
// assumption is that it's better to loose a little bit than to re-check
|
2013-08-06 04:50:57 +02:00
|
|
|
// the entire file.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-02-02 04:05:55 +01:00
|
|
|
// It is still a good idea to save resume data periodically during
|
|
|
|
// download as well as when closing down.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-02-02 04:05:55 +01:00
|
|
|
// Example code to pause and save resume data for all torrents and wait
|
2014-09-03 08:52:45 +02:00
|
|
|
// for the alerts:
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-09-03 08:52:45 +02:00
|
|
|
// .. code:: c++
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2013-08-06 04:50:57 +02:00
|
|
|
// extern int outstanding_resume_data; // global counter of outstanding resume data
|
|
|
|
// std::vector<torrent_handle> handles = ses.get_torrents();
|
|
|
|
// ses.pause();
|
2018-08-07 19:36:25 +02:00
|
|
|
// for (torrent_handle const& h : handles)
|
2013-08-06 04:50:57 +02:00
|
|
|
// {
|
|
|
|
// if (!h.is_valid()) continue;
|
|
|
|
// torrent_status s = h.status();
|
2018-07-11 12:44:25 +02:00
|
|
|
// if (!s.has_metadata || !s.need_save_resume_data()) continue;
|
2013-08-06 04:50:57 +02:00
|
|
|
//
|
|
|
|
// h.save_resume_data();
|
|
|
|
// ++outstanding_resume_data;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// while (outstanding_resume_data > 0)
|
|
|
|
// {
|
|
|
|
// alert const* a = ses.wait_for_alert(seconds(10));
|
|
|
|
//
|
|
|
|
// // if we don't get an alert within 10 seconds, abort
|
2018-08-07 19:36:25 +02:00
|
|
|
// if (a == nullptr) break;
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2015-11-20 07:00:39 +01:00
|
|
|
// std::vector<alert*> alerts;
|
2015-04-03 22:15:48 +02:00
|
|
|
// ses.pop_alerts(&alerts);
|
2013-08-06 04:50:57 +02:00
|
|
|
//
|
2015-11-20 07:00:39 +01:00
|
|
|
// for (alert* i : alerts)
|
|
|
|
// {
|
2015-04-03 22:15:48 +02:00
|
|
|
// if (alert_cast<save_resume_data_failed_alert>(a))
|
|
|
|
// {
|
|
|
|
// process_alert(a);
|
|
|
|
// --outstanding_resume_data;
|
|
|
|
// continue;
|
|
|
|
// }
|
2013-08-06 04:50:57 +02:00
|
|
|
//
|
2015-04-03 22:15:48 +02:00
|
|
|
// save_resume_data_alert const* rd = alert_cast<save_resume_data_alert>(a);
|
2018-08-07 19:36:25 +02:00
|
|
|
// if (rd == nullptr)
|
2015-04-03 22:15:48 +02:00
|
|
|
// {
|
|
|
|
// process_alert(a);
|
|
|
|
// continue;
|
|
|
|
// }
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2015-04-03 22:15:48 +02:00
|
|
|
// torrent_handle h = rd->handle;
|
|
|
|
// torrent_status st = h.status(torrent_handle::query_save_path
|
2015-11-20 07:00:39 +01:00
|
|
|
// | torrent_handle::query_name);
|
2015-04-03 22:15:48 +02:00
|
|
|
// std::ofstream out((st.save_path
|
|
|
|
// + "/" + st.name + ".fastresume").c_str()
|
|
|
|
// , std::ios_base::binary);
|
2019-12-18 14:08:01 +01:00
|
|
|
// std::vector<char> buf = write_resume_data_buf(rd->params);
|
|
|
|
// out.write(buf.data(), buf.size());
|
2015-04-03 22:15:48 +02:00
|
|
|
// --outstanding_resume_data;
|
2015-11-20 07:00:39 +01:00
|
|
|
// }
|
2013-08-06 04:50:57 +02:00
|
|
|
// }
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-02-02 04:05:55 +01:00
|
|
|
//.. 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.
|
2017-07-27 01:16:29 +02:00
|
|
|
void save_resume_data(resume_data_flags_t flags = {}) const;
|
2013-08-06 04:50:57 +02:00
|
|
|
|
2014-02-02 04:05:55 +01:00
|
|
|
// 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.
|
2013-08-06 04:50:57 +02:00
|
|
|
//
|
2014-02-02 04:05:55 +01:00
|
|
|
//.. note::
|
2018-08-07 19:36:25 +02:00
|
|
|
// 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.
|
2011-02-01 10:48:28 +01:00
|
|
|
bool need_save_resume_data() const;
|
2008-04-16 08:31:05 +02:00
|
|
|
|
2014-02-02 04:05:55 +01:00
|
|
|
// 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.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-02-02 04:05:55 +01:00
|
|
|
// 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.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-02-02 04:05:55 +01:00
|
|
|
// ``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.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2013-08-06 04:50:57 +02:00
|
|
|
// The queue position is also available in the torrent_status.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-02-02 04:05:55 +01:00
|
|
|
// 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.
|
2017-10-25 02:39:22 +02:00
|
|
|
queue_position_t queue_position() const;
|
2011-02-01 10:48:28 +01:00
|
|
|
void queue_position_up() const;
|
|
|
|
void queue_position_down() const;
|
|
|
|
void queue_position_top() const;
|
|
|
|
void queue_position_bottom() const;
|
2008-04-24 05:28:48 +02:00
|
|
|
|
2017-01-31 03:31:31 +01:00
|
|
|
// 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
|
2017-10-25 02:39:22 +02:00
|
|
|
void queue_position_set(queue_position_t p) const;
|
2017-01-31 03:31:31 +01:00
|
|
|
|
2014-02-02 04:05:55 +01:00
|
|
|
// 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.
|
2014-05-10 23:53:50 +02:00
|
|
|
//
|
|
|
|
// The set_ssl_certificate_buffer() overload takes the actual certificate,
|
2017-10-06 10:54:33 +02:00
|
|
|
// private key and DH params as strings, rather than paths to files.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-02-02 04:05:55 +01:00
|
|
|
// ``cert`` is a path to the (signed) certificate in .pem format
|
|
|
|
// corresponding to this torrent.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-02-02 04:05:55 +01:00
|
|
|
// ``private_key`` is a path to the private key for the specified
|
|
|
|
// certificate. This must be in .pem format.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-02-02 04:05:55 +01:00
|
|
|
// ``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``.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-02-02 04:05:55 +01:00
|
|
|
// ``passphrase`` may be specified if the private key is encrypted and
|
|
|
|
// requires a passphrase to be decrypted.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-02-02 04:05:55 +01:00
|
|
|
// 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
|
2017-06-17 17:35:53 +02:00
|
|
|
// typically desirable to resume the torrent after setting the SSL
|
2014-02-02 04:05:55 +01:00
|
|
|
// certificate.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-02-02 04:05:55 +01:00
|
|
|
// 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.
|
2011-09-12 05:51:49 +02:00
|
|
|
void set_ssl_certificate(std::string const& certificate
|
|
|
|
, std::string const& private_key
|
|
|
|
, std::string const& dh_params
|
|
|
|
, std::string const& passphrase = "");
|
2014-05-10 23:53:50 +02:00
|
|
|
void set_ssl_certificate_buffer(std::string const& certificate
|
|
|
|
, std::string const& private_key
|
|
|
|
, std::string const& dh_params);
|
2011-09-10 07:52:07 +02:00
|
|
|
|
2013-08-06 04:50:57 +02:00
|
|
|
// Returns the storage implementation for this torrent. This depends on the
|
2016-01-26 18:21:25 +01:00
|
|
|
// storage constructor function that was passed to add_torrent.
|
2011-02-01 10:48:28 +01:00
|
|
|
storage_interface* get_storage_impl() const;
|
2008-06-05 20:19:03 +02:00
|
|
|
|
2014-01-01 22:24:15 +01:00
|
|
|
// 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
|
2016-06-20 17:32:06 +02:00
|
|
|
// initialized (i.e. a nullptr). The torrent may be in a state
|
2014-01-01 22:24:15 +01:00
|
|
|
// without metadata only if it was started without a .torrent file, e.g.
|
2019-06-29 21:55:56 +02:00
|
|
|
// by being added by magnet link
|
2017-02-06 18:44:50 +01:00
|
|
|
std::shared_ptr<const torrent_info> torrent_file() const;
|
2012-10-02 18:07:55 +02:00
|
|
|
|
2018-04-26 09:01:14 +02:00
|
|
|
#if TORRENT_ABI_VERSION == 1
|
2009-01-05 02:08:09 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
// ================ start deprecation ============
|
2009-02-03 08:46:24 +01:00
|
|
|
|
2017-07-09 16:32:01 +02:00
|
|
|
// deprecated in 1.2
|
|
|
|
|
|
|
|
TORRENT_DEPRECATED
|
|
|
|
void stop_when_ready(bool b) const;
|
|
|
|
TORRENT_DEPRECATED
|
|
|
|
void set_upload_mode(bool b) const;
|
|
|
|
TORRENT_DEPRECATED
|
|
|
|
void set_share_mode(bool b) const;
|
|
|
|
TORRENT_DEPRECATED
|
|
|
|
void apply_ip_filter(bool b) const;
|
|
|
|
TORRENT_DEPRECATED
|
|
|
|
void auto_managed(bool m) const;
|
|
|
|
TORRENT_DEPRECATED
|
|
|
|
void set_pinned(bool p) const;
|
|
|
|
TORRENT_DEPRECATED
|
|
|
|
void set_sequential_download(bool sd) const;
|
|
|
|
|
|
|
|
|
2013-03-03 00:17:48 +01:00
|
|
|
// deprecated in 1.0
|
|
|
|
// use status() instead (with query_save_path)
|
2015-04-17 03:49:49 +02:00
|
|
|
TORRENT_DEPRECATED
|
|
|
|
std::string save_path() const;
|
2013-03-03 00:17:48 +01:00
|
|
|
|
|
|
|
// deprecated in 1.0
|
|
|
|
// use status() instead (with query_name)
|
|
|
|
// returns the name of this torrent, in case it doesn't
|
|
|
|
// have metadata it returns the name assigned to it
|
|
|
|
// when it was added.
|
2015-04-17 03:49:49 +02:00
|
|
|
TORRENT_DEPRECATED
|
|
|
|
std::string name() const;
|
2013-03-03 00:17:48 +01:00
|
|
|
|
2012-10-02 18:07:55 +02:00
|
|
|
// use torrent_file() instead
|
2015-04-17 03:49:49 +02:00
|
|
|
TORRENT_DEPRECATED
|
|
|
|
const torrent_info& get_torrent_info() const;
|
2012-10-02 18:07:55 +02:00
|
|
|
|
2011-12-18 13:52:09 +01:00
|
|
|
// deprecated in 0.16, feature will be removed
|
2015-04-17 03:49:49 +02:00
|
|
|
TORRENT_DEPRECATED
|
|
|
|
int get_peer_upload_limit(tcp::endpoint ip) const;
|
|
|
|
TORRENT_DEPRECATED
|
|
|
|
int get_peer_download_limit(tcp::endpoint ip) const;
|
|
|
|
TORRENT_DEPRECATED
|
|
|
|
void set_peer_upload_limit(tcp::endpoint ip, int limit) const;
|
|
|
|
TORRENT_DEPRECATED
|
|
|
|
void set_peer_download_limit(tcp::endpoint ip, int limit) const;
|
2011-12-18 13:52:09 +01:00
|
|
|
|
2011-12-18 08:18:42 +01:00
|
|
|
// deprecated in 0.16, feature will be removed
|
2015-04-17 03:49:49 +02:00
|
|
|
TORRENT_DEPRECATED
|
|
|
|
void set_ratio(float up_down_ratio) const;
|
2011-12-18 08:18:42 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
// deprecated in 0.16. use status() instead
|
2015-04-17 03:49:49 +02:00
|
|
|
TORRENT_DEPRECATED
|
|
|
|
bool is_seed() const;
|
|
|
|
TORRENT_DEPRECATED
|
|
|
|
bool is_finished() const;
|
|
|
|
TORRENT_DEPRECATED
|
|
|
|
bool is_paused() const;
|
|
|
|
TORRENT_DEPRECATED
|
|
|
|
bool is_auto_managed() const;
|
|
|
|
TORRENT_DEPRECATED
|
|
|
|
bool is_sequential_download() const;
|
|
|
|
TORRENT_DEPRECATED
|
|
|
|
bool has_metadata() const;
|
|
|
|
TORRENT_DEPRECATED
|
|
|
|
bool super_seeding() const;
|
2009-06-19 00:32:55 +02:00
|
|
|
|
2012-10-02 18:07:55 +02:00
|
|
|
// deprecated in 0.14
|
|
|
|
// use save_resume_data() instead. It is async. and
|
|
|
|
// will return the resume data in an alert
|
2015-04-17 03:49:49 +02:00
|
|
|
TORRENT_DEPRECATED
|
|
|
|
entry write_resume_data() const;
|
2010-09-05 18:01:36 +02:00
|
|
|
|
2014-02-02 06:09:18 +01:00
|
|
|
// ``use_interface()`` sets the network interface this torrent will use
|
|
|
|
// when it opens outgoing connections. By default, it uses the same
|
|
|
|
// interface as the session uses to listen on. The parameter must be a
|
|
|
|
// string containing one or more, comma separated, ip-address (either an
|
|
|
|
// IPv4 or IPv6 address). When specifying multiple interfaces, the
|
|
|
|
// torrent will round-robin which interface to use for each outgoing
|
2016-02-10 17:58:09 +01:00
|
|
|
// connection. This is useful for clients that are multi-homed.
|
2016-12-03 00:25:50 +01:00
|
|
|
TORRENT_DEPRECATED
|
2013-10-14 04:25:21 +02:00
|
|
|
void use_interface(const char* net_interface) const;
|
2016-12-03 00:25:50 +01:00
|
|
|
// ================ end deprecation ============
|
|
|
|
#endif
|
2013-10-14 04:25:21 +02:00
|
|
|
|
2014-02-02 06:09:18 +01:00
|
|
|
// 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.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-02-02 06:09:18 +01:00
|
|
|
// The piece availability is the number of peers that we are connected
|
2016-02-10 17:58:09 +01:00
|
|
|
// that has advertised having a particular piece. This is the information
|
2014-02-02 06:09:18 +01:00
|
|
|
// that libtorrent uses in order to prefer picking rare pieces.
|
2011-02-01 10:48:28 +01:00
|
|
|
void piece_availability(std::vector<int>& avail) const;
|
2015-08-29 16:21:15 +02:00
|
|
|
|
2016-02-10 17:58:09 +01:00
|
|
|
// These functions are used to set and get the priority of individual
|
2015-01-26 03:04:58 +01:00
|
|
|
// pieces. By default all pieces have priority 4. That means that the
|
2014-02-02 06:09:18 +01:00
|
|
|
// random rarest first algorithm is effectively active for all pieces.
|
|
|
|
// You may however change the priority of individual pieces. There are 8
|
2015-01-26 03:04:58 +01:00
|
|
|
// priority levels. 0 means not to download the piece at all. Otherwise,
|
|
|
|
// lower priority values means less likely to be picked. Piece priority
|
2016-11-19 20:33:04 +01:00
|
|
|
// takes precedence over piece availability. Every piece with priority 7
|
|
|
|
// will be attempted to be picked before a priority 6 piece and so on.
|
2016-11-20 17:18:16 +01:00
|
|
|
//
|
2016-11-19 20:33:04 +01:00
|
|
|
// The default priority of pieces is 4.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2015-08-29 16:21:15 +02:00
|
|
|
// Piece priorities can not be changed for torrents that have not
|
2018-07-29 10:33:09 +02:00
|
|
|
// downloaded the metadata yet. Magnet links won't have metadata
|
|
|
|
// immediately. see the metadata_received_alert.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2013-08-06 04:50:57 +02:00
|
|
|
// ``piece_priority`` sets or gets the priority for an individual piece,
|
|
|
|
// specified by ``index``.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-02-02 06:09:18 +01:00
|
|
|
// ``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.
|
2014-07-06 21:18:00 +02:00
|
|
|
// 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.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2017-11-05 16:27:34 +01:00
|
|
|
// ``get_piece_priorities`` returns a vector with one element for each piece
|
2014-02-02 06:09:18 +01:00
|
|
|
// in the torrent. Each element is the current priority of that piece.
|
2018-07-30 01:10:52 +02:00
|
|
|
//
|
2018-07-29 10:33:09 +02:00
|
|
|
// 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.
|
2017-10-29 00:44:40 +02:00
|
|
|
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_pieces(std::vector<std::pair<piece_index_t, download_priority_t>> const& pieces) const;
|
2017-11-05 16:27:34 +01:00
|
|
|
std::vector<download_priority_t> get_piece_priorities() const;
|
2017-10-29 00:44:40 +02:00
|
|
|
|
2018-04-26 09:01:14 +02:00
|
|
|
#if TORRENT_ABI_VERSION == 1
|
2017-10-29 00:44:40 +02:00
|
|
|
TORRENT_DEPRECATED
|
2011-02-01 10:48:28 +01:00
|
|
|
void prioritize_pieces(std::vector<int> const& pieces) const;
|
2017-10-29 00:44:40 +02:00
|
|
|
TORRENT_DEPRECATED
|
2016-12-22 16:42:33 +01:00
|
|
|
void prioritize_pieces(std::vector<std::pair<piece_index_t, int>> const& pieces) const;
|
2017-11-05 16:27:34 +01:00
|
|
|
TORRENT_DEPRECATED
|
|
|
|
std::vector<int> piece_priorities() const;
|
2017-10-29 00:44:40 +02:00
|
|
|
#endif
|
2010-07-08 21:29:38 +02:00
|
|
|
|
2013-08-06 04:50:57 +02:00
|
|
|
// ``index`` must be in the range [0, number_of_files).
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2013-08-06 04:50:57 +02:00
|
|
|
// ``file_priority()`` queries or sets the priority of file ``index``.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-02-02 06:09:18 +01:00
|
|
|
// ``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.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2017-11-05 16:27:34 +01:00
|
|
|
// ``get_file_priorities()`` returns a vector with the priorities of all
|
2014-02-02 06:09:18 +01:00
|
|
|
// files.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2019-12-18 14:08:01 +01:00
|
|
|
// The priority values are the same as for piece_priority(). See
|
|
|
|
// download_priority_t.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-02-02 06:09:18 +01:00
|
|
|
// Whenever a file priority is changed, all other piece priorities are
|
2014-12-25 12:24:02 +01:00
|
|
|
// reset to match the file priorities. In order to maintain special
|
2014-02-02 06:09:18 +01:00
|
|
|
// priorities for particular pieces, piece_priority() has to be called
|
|
|
|
// again for those pieces.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-02-02 06:09:18 +01:00
|
|
|
// 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
|
2013-08-06 04:50:57 +02:00
|
|
|
// prioritize_files() are both no-ops for such torrents.
|
2018-07-30 01:10:52 +02:00
|
|
|
//
|
2018-07-29 10:33:09 +02:00
|
|
|
// 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.
|
|
|
|
// However, the *piece* priorities are updated immediately.
|
2018-07-30 01:10:52 +02:00
|
|
|
//
|
2018-07-29 10:33:09 +02:00
|
|
|
// 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.
|
2017-10-29 00:44:40 +02:00
|
|
|
void file_priority(file_index_t index, download_priority_t priority) const;
|
|
|
|
download_priority_t file_priority(file_index_t index) const;
|
|
|
|
void prioritize_files(std::vector<download_priority_t> const& files) const;
|
2017-11-05 16:27:34 +01:00
|
|
|
std::vector<download_priority_t> get_file_priorities() const;
|
2017-10-29 00:44:40 +02:00
|
|
|
|
2018-04-26 09:01:14 +02:00
|
|
|
#if TORRENT_ABI_VERSION == 1
|
2017-10-29 00:44:40 +02:00
|
|
|
TORRENT_DEPRECATED
|
2011-02-01 10:48:28 +01:00
|
|
|
void prioritize_files(std::vector<int> const& files) const;
|
2017-11-05 16:27:34 +01:00
|
|
|
TORRENT_DEPRECATED
|
|
|
|
std::vector<int> file_priorities() const;
|
2017-10-29 00:44:40 +02:00
|
|
|
#endif
|
2010-11-06 19:04:07 +01:00
|
|
|
|
2018-09-04 14:31:05 +02:00
|
|
|
// 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.
|
|
|
|
static constexpr reannounce_flags_t ignore_min_interval = 0_bit;
|
2018-08-18 23:25:02 +02:00
|
|
|
|
2014-01-02 03:16:31 +01:00
|
|
|
// ``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.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-01-02 03:16:31 +01:00
|
|
|
// 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.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2018-08-18 23:25:02 +02:00
|
|
|
// The ``flags`` argument can be used to affect the re-announce. See
|
2018-09-04 14:31:05 +02:00
|
|
|
// ignore_min_interval.
|
|
|
|
//
|
2014-01-02 03:16:31 +01:00
|
|
|
// ``force_dht_announce`` will announce the torrent to the DHT
|
|
|
|
// immediately.
|
2018-09-04 14:31:05 +02:00
|
|
|
void force_reannounce(int seconds = 0, int tracker_index = -1, reannounce_flags_t = {}) const;
|
2011-02-01 10:48:28 +01:00
|
|
|
void force_dht_announce() const;
|
2009-05-03 11:45:07 +02:00
|
|
|
|
2018-04-26 09:01:14 +02:00
|
|
|
#if TORRENT_ABI_VERSION == 1
|
2011-02-01 10:48:28 +01:00
|
|
|
// forces a reannounce in the specified amount of time.
|
|
|
|
// This overrides the default announce interval, and no
|
|
|
|
// announce will take place until the given time has
|
|
|
|
// timed out.
|
2015-04-17 03:49:49 +02:00
|
|
|
TORRENT_DEPRECATED
|
|
|
|
void force_reannounce(boost::posix_time::time_duration) const;
|
2014-01-02 03:16:31 +01:00
|
|
|
#endif
|
2009-05-03 11:45:07 +02:00
|
|
|
|
2016-01-25 06:51:20 +01:00
|
|
|
// ``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.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2016-01-25 06:51:20 +01:00
|
|
|
// A scrape request queries the tracker for statistics such as total
|
|
|
|
// number of incomplete peers, complete peers, number of downloads etc.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-02-02 06:09:18 +01:00
|
|
|
// 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.
|
2016-01-25 06:51:20 +01:00
|
|
|
void scrape_tracker(int idx = -1) const;
|
2011-02-01 10:48:28 +01:00
|
|
|
|
2014-02-02 06:09:18 +01:00
|
|
|
// ``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
|
2016-03-18 18:43:11 +01:00
|
|
|
// (``settings_pack::upload_rate_limit``) will not override the global
|
2014-02-02 06:09:18 +01:00
|
|
|
// rate limit. The torrent can never upload more than the global rate
|
2013-08-06 04:50:57 +02:00
|
|
|
// limit.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-02-02 06:09:18 +01:00
|
|
|
// ``upload_limit`` and ``download_limit`` will return the current limit
|
|
|
|
// setting, for upload and download, respectively.
|
2017-03-31 00:07:24 +02:00
|
|
|
//
|
2017-03-28 02:47:12 +02:00
|
|
|
// Local peers are not rate limited by default. see peer-classes_.
|
2011-02-01 10:48:28 +01:00
|
|
|
void set_upload_limit(int limit) const;
|
|
|
|
int upload_limit() const;
|
|
|
|
void set_download_limit(int limit) const;
|
|
|
|
int download_limit() const;
|
2009-05-03 11:45:07 +02:00
|
|
|
|
2014-02-02 06:09:18 +01:00
|
|
|
// ``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
|
2016-05-15 06:33:06 +02:00
|
|
|
// mode, this will throw system_error. The second (optional)
|
2017-06-17 17:35:53 +02:00
|
|
|
// argument will be bitwise ORed into the source mask of this peer.
|
2014-02-02 06:09:18 +01:00
|
|
|
// Typically this is one of the source flags in peer_info. i.e.
|
|
|
|
// ``tracker``, ``pex``, ``dht`` etc.
|
2014-07-06 21:18:00 +02:00
|
|
|
//
|
2019-12-18 14:08:01 +01:00
|
|
|
// For possible values of ``flags``, see pex_flags_t.
|
2017-07-16 20:26:00 +02:00
|
|
|
void connect_peer(tcp::endpoint const& adr, peer_source_flags_t source = {}
|
2017-12-17 14:15:38 +01:00
|
|
|
, pex_flags_t flags = pex_encryption | pex_utp | pex_holepunch) const;
|
2003-12-22 08:14:35 +01:00
|
|
|
|
2014-02-02 06:09:18 +01:00
|
|
|
// ``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
|
2016-03-18 18:43:11 +01:00
|
|
|
// settings_pack.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2013-08-06 04:50:57 +02:00
|
|
|
// ``max_uploads()`` returns the current settings.
|
2011-02-01 10:48:28 +01:00
|
|
|
void set_max_uploads(int max_uploads) const;
|
|
|
|
int max_uploads() const;
|
2010-03-04 20:15:23 +01:00
|
|
|
|
2014-02-02 06:09:18 +01:00
|
|
|
// ``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
|
2016-03-18 18:43:11 +01:00
|
|
|
// ``connections_limit`` in settings_pack.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2013-08-06 04:50:57 +02:00
|
|
|
// ``max_connections()`` returns the current settings.
|
2011-02-01 10:48:28 +01:00
|
|
|
void set_max_connections(int max_connections) const;
|
|
|
|
int max_connections() const;
|
2010-03-19 19:39:51 +01:00
|
|
|
|
2018-04-26 09:01:14 +02:00
|
|
|
#if TORRENT_ABI_VERSION == 1
|
2013-08-06 04:50:57 +02:00
|
|
|
// 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.
|
2015-12-13 21:14:19 +01:00
|
|
|
TORRENT_DEPRECATED
|
2011-02-01 10:48:28 +01:00
|
|
|
void set_tracker_login(std::string const& name
|
|
|
|
, std::string const& password) const;
|
2015-12-13 21:14:19 +01:00
|
|
|
#endif
|
2009-03-17 10:34:44 +01:00
|
|
|
|
2014-02-02 06:09:18 +01:00
|
|
|
// 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.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-02-02 06:09:18 +01:00
|
|
|
// 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.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-02-02 06:09:18 +01:00
|
|
|
// The ``flags`` argument determines the behavior of the copying/moving
|
|
|
|
// of the files in the torrent. see move_flags_t.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-02-02 06:09:18 +01:00
|
|
|
// ``always_replace_files`` is the default and replaces any file that
|
|
|
|
// exist in both the source directory and the target directory.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-02-02 06:09:18 +01:00
|
|
|
// ``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``.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2014-02-02 06:09:18 +01:00
|
|
|
// 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.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2018-06-10 18:18:53 +02:00
|
|
|
// ``dont_replace`` always keeps the existing file in the target
|
2014-02-02 06:09:18 +01:00
|
|
|
// directory, if there is one. The source files will still be removed in
|
2018-06-10 18:18:53 +02:00
|
|
|
// 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.
|
2016-10-22 17:47:24 +02:00
|
|
|
//
|
2016-08-21 01:46:55 +02:00
|
|
|
// Files that have been renamed to have absolute paths are not moved by
|
2014-02-02 06:09:18 +01:00
|
|
|
// 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.
|
2017-06-01 10:15:15 +02:00
|
|
|
void move_storage(std::string const& save_path
|
2017-06-01 16:29:01 +02:00
|
|
|
, move_flags_t flags = move_flags_t::always_replace_files
|
2017-06-01 10:15:15 +02:00
|
|
|
) const;
|
|
|
|
|
2018-04-26 09:01:14 +02:00
|
|
|
#if TORRENT_ABI_VERSION == 1
|
2017-06-01 10:15:15 +02:00
|
|
|
// deprecated in 1.2
|
|
|
|
TORRENT_DEPRECATED
|
2017-06-01 16:29:01 +02:00
|
|
|
void move_storage(std::string const& save_path, int flags) const;
|
2017-06-01 10:15:15 +02:00
|
|
|
#endif
|
2013-08-06 04:50:57 +02:00
|
|
|
|
2014-02-02 06:09:18 +01:00
|
|
|
// 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.
|
2016-12-22 16:42:33 +01:00
|
|
|
void rename_file(file_index_t index, std::string const& new_name) const;
|
2009-09-13 04:24:25 +02:00
|
|
|
|
2018-04-26 09:01:14 +02:00
|
|
|
#if TORRENT_ABI_VERSION == 1
|
2013-08-02 07:03:22 +02:00
|
|
|
// all wstring APIs are deprecated since 0.16.11
|
|
|
|
// instead, use the wchar -> utf8 conversion functions
|
|
|
|
// and pass in utf8 strings
|
2015-04-17 03:49:49 +02:00
|
|
|
TORRENT_DEPRECATED
|
|
|
|
void move_storage(std::wstring const& save_path, int flags = 0) const;
|
|
|
|
TORRENT_DEPRECATED
|
2016-12-22 16:42:33 +01:00
|
|
|
void rename_file(file_index_t index, std::wstring const& new_name) const;
|
2009-07-04 06:58:24 +02:00
|
|
|
|
2014-11-12 17:57:59 +01:00
|
|
|
// Enables or disabled super seeding/initial seeding for this torrent.
|
|
|
|
// The torrent needs to be a seed for this to take effect.
|
2017-07-01 17:43:39 +02:00
|
|
|
TORRENT_DEPRECATED
|
2011-02-01 10:48:28 +01:00
|
|
|
void super_seeding(bool on) const;
|
2018-04-26 09:01:14 +02:00
|
|
|
#endif // TORRENT_ABI_VERSION
|
2003-11-28 18:29:27 +01:00
|
|
|
|
2014-11-12 17:57:59 +01:00
|
|
|
// ``info_hash()`` returns the info-hash 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.
|
2011-02-01 10:48:28 +01:00
|
|
|
sha1_hash info_hash() const;
|
2008-07-12 19:00:52 +02:00
|
|
|
|
2013-08-16 07:07:09 +02:00
|
|
|
// comparison operators. The order of the torrents is unspecified
|
|
|
|
// but stable.
|
2011-02-01 10:48:28 +01:00
|
|
|
bool operator==(const torrent_handle& h) const
|
2017-03-25 19:45:23 +01:00
|
|
|
{ return !m_torrent.owner_before(h.m_torrent) && !h.m_torrent.owner_before(m_torrent); }
|
2011-02-01 10:48:28 +01:00
|
|
|
bool operator!=(const torrent_handle& h) const
|
2017-03-25 19:45:23 +01:00
|
|
|
{ return m_torrent.owner_before(h.m_torrent) || h.m_torrent.owner_before(m_torrent); }
|
2011-02-01 10:48:28 +01:00
|
|
|
bool operator<(const torrent_handle& h) const
|
2017-03-25 19:45:23 +01:00
|
|
|
{ return m_torrent.owner_before(h.m_torrent); }
|
2008-12-30 04:54:07 +01:00
|
|
|
|
2019-09-07 11:20:24 +02:00
|
|
|
// returns a unique identifier for this torrent. It's not a dense index.
|
|
|
|
// It's not preserved across sessions.
|
2016-06-18 20:01:38 +02:00
|
|
|
std::uint32_t id() const
|
2014-07-06 21:18:00 +02:00
|
|
|
{
|
2015-04-18 04:33:39 +02:00
|
|
|
uintptr_t ret = reinterpret_cast<uintptr_t>(m_torrent.lock().get());
|
2018-07-28 08:42:33 +02:00
|
|
|
// a torrent object is about 1024 (2^10) bytes, so
|
|
|
|
// it's safe to shift 10 bits
|
2018-07-28 10:10:01 +02:00
|
|
|
return std::uint32_t(ret >> 10);
|
2014-07-06 21:18:00 +02:00
|
|
|
}
|
|
|
|
|
2014-02-02 06:09:18 +01:00
|
|
|
// This function is intended only for use by plugins and the alert
|
2015-06-27 20:22:13 +02:00
|
|
|
// dispatch function. This type does not have a stable API and should
|
2019-12-18 14:08:01 +01:00
|
|
|
// 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).
|
2016-08-31 14:27:36 +02:00
|
|
|
std::shared_ptr<torrent> native_handle() const;
|
2012-08-30 03:54:35 +02:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
private:
|
|
|
|
|
2016-05-22 01:05:42 +02:00
|
|
|
template<typename Fun, typename... Args>
|
|
|
|
void async_call(Fun f, Args&&... a) const;
|
|
|
|
|
|
|
|
template<typename Fun, typename... Args>
|
|
|
|
void sync_call(Fun f, Args&&... a) const;
|
|
|
|
|
|
|
|
template<typename Ret, typename Fun, typename... Args>
|
|
|
|
Ret sync_call_ret(Ret def, Fun f, Args&&... a) const;
|
|
|
|
|
2016-10-08 20:07:11 +02:00
|
|
|
explicit torrent_handle(std::weak_ptr<torrent> const& t)
|
2014-07-06 21:18:00 +02:00
|
|
|
{ if (!t.expired()) m_torrent = t; }
|
2011-02-01 10:48:28 +01:00
|
|
|
|
2016-08-31 14:27:36 +02:00
|
|
|
std::weak_ptr<torrent> m_torrent;
|
2011-02-01 10:48:28 +01:00
|
|
|
};
|
2003-10-26 18:35:23 +01:00
|
|
|
}
|
|
|
|
|
2016-09-07 05:37:36 +02:00
|
|
|
namespace std
|
|
|
|
{
|
|
|
|
template <>
|
|
|
|
struct hash<libtorrent::torrent_handle>
|
|
|
|
{
|
|
|
|
std::size_t operator()(libtorrent::torrent_handle const& th) const
|
|
|
|
{
|
|
|
|
return libtorrent::hash_value(th);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2003-10-26 18:35:23 +01:00
|
|
|
#endif // TORRENT_TORRENT_HANDLE_HPP_INCLUDED
|