2003-10-26 18:35:23 +01:00
|
|
|
/*
|
|
|
|
|
2012-10-02 05:16:33 +02:00
|
|
|
Copyright (c) 2003-2012, 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
|
|
|
|
|
|
|
|
#include <vector>
|
2007-08-17 18:40:55 +02:00
|
|
|
#include <set>
|
2004-01-25 19:18:36 +01:00
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma warning(push, 1)
|
|
|
|
#endif
|
|
|
|
|
2009-11-26 20:32:11 +01:00
|
|
|
#include <boost/assert.hpp>
|
2009-11-23 09:38:50 +01:00
|
|
|
#include <boost/date_time/posix_time/posix_time_duration.hpp>
|
2010-11-06 17:16:00 +01:00
|
|
|
#include <boost/shared_ptr.hpp>
|
|
|
|
#include <boost/weak_ptr.hpp>
|
2003-10-26 18:35:23 +01:00
|
|
|
|
2004-01-25 19:18:36 +01:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma warning(pop)
|
|
|
|
#endif
|
|
|
|
|
2003-10-26 18:35:23 +01:00
|
|
|
#include "libtorrent/peer_id.hpp"
|
2003-11-02 22:06:50 +01:00
|
|
|
#include "libtorrent/piece_picker.hpp"
|
2003-11-28 18:29:27 +01:00
|
|
|
#include "libtorrent/torrent_info.hpp"
|
2009-11-25 07:55:34 +01:00
|
|
|
#include "libtorrent/ptime.hpp"
|
2005-11-01 19:30:39 +01:00
|
|
|
#include "libtorrent/config.hpp"
|
2007-10-08 22:01:36 +02:00
|
|
|
#include "libtorrent/storage.hpp"
|
2009-11-23 09:38:50 +01:00
|
|
|
#include "libtorrent/address.hpp"
|
2009-11-26 06:45:43 +01:00
|
|
|
#include "libtorrent/bitfield.hpp"
|
|
|
|
#include "libtorrent/socket.hpp" // tcp::endpoint
|
2003-10-26 18:35:23 +01:00
|
|
|
|
|
|
|
namespace libtorrent
|
|
|
|
{
|
2006-10-11 16:02:21 +02:00
|
|
|
namespace aux
|
2003-10-26 18:35:23 +01:00
|
|
|
{
|
|
|
|
struct session_impl;
|
|
|
|
}
|
|
|
|
|
2007-11-08 02:45:35 +01:00
|
|
|
struct torrent_plugin;
|
2009-11-26 06:45:43 +01:00
|
|
|
struct peer_info;
|
|
|
|
struct peer_list_entry;
|
2011-02-01 10:48:28 +01:00
|
|
|
struct torrent_status;
|
2012-08-30 03:54:35 +02:00
|
|
|
class torrent;
|
2007-11-08 02:45:35 +01:00
|
|
|
|
2012-02-16 08:26:45 +01:00
|
|
|
TORRENT_EXPORT std::size_t hash_value(torrent_status const& ts);
|
2011-12-23 06:36:13 +01:00
|
|
|
|
2009-02-23 02:21:19 +01:00
|
|
|
#ifndef BOOST_NO_EXCEPTIONS
|
|
|
|
// for compatibility with 0.14
|
|
|
|
typedef libtorrent_exception duplicate_torrent;
|
|
|
|
typedef libtorrent_exception invalid_handle;
|
|
|
|
void throw_invalid_handle();
|
|
|
|
#endif
|
2003-11-28 18:29:27 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
struct TORRENT_EXPORT block_info
|
2003-10-26 18:35:23 +01:00
|
|
|
{
|
2011-02-01 10:48:28 +01:00
|
|
|
enum block_state_t
|
|
|
|
{ none, requested, writing, finished };
|
2003-12-22 08:14:35 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
private:
|
|
|
|
TORRENT_UNION addr_t
|
2003-10-26 18:35:23 +01:00
|
|
|
{
|
2011-02-01 10:48:28 +01:00
|
|
|
address_v4::bytes_type v4;
|
|
|
|
#if TORRENT_USE_IPV6
|
|
|
|
address_v6::bytes_type v6;
|
|
|
|
#endif
|
|
|
|
} addr;
|
2004-01-17 21:04:19 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
boost::uint16_t port;
|
|
|
|
public:
|
2003-11-20 20:58:29 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
void set_peer(tcp::endpoint const& ep)
|
|
|
|
{
|
|
|
|
#if TORRENT_USE_IPV6
|
|
|
|
is_v6_addr = ep.address().is_v6();
|
|
|
|
if (is_v6_addr)
|
|
|
|
addr.v6 = ep.address().to_v6().to_bytes();
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
addr.v4 = ep.address().to_v4().to_bytes();
|
|
|
|
port = ep.port();
|
|
|
|
}
|
2003-12-22 08:14:35 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
tcp::endpoint peer() const
|
|
|
|
{
|
|
|
|
#if TORRENT_USE_IPV6
|
|
|
|
if (is_v6_addr)
|
|
|
|
return tcp::endpoint(address_v6(addr.v6), port);
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
return tcp::endpoint(address_v4(addr.v4), port);
|
|
|
|
}
|
2003-12-22 08:14:35 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
// number of bytes downloaded in this block
|
|
|
|
unsigned bytes_progress:15;
|
|
|
|
// the total number of bytes in this block
|
|
|
|
unsigned block_size:15;
|
|
|
|
private:
|
|
|
|
// the type of the addr union
|
|
|
|
unsigned is_v6_addr:1;
|
2013-03-21 02:18:39 +01:00
|
|
|
// unsigned unused:1;
|
2011-02-01 10:48:28 +01:00
|
|
|
public:
|
|
|
|
// the state this block is in (see block_state_t)
|
|
|
|
unsigned state:2;
|
|
|
|
// the number of peers that has requested this block
|
|
|
|
// typically 0 or 1. If > 1, this block is in
|
|
|
|
// end game mode
|
|
|
|
unsigned num_peers:14;
|
|
|
|
};
|
2004-04-18 14:28:02 +02:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
struct TORRENT_EXPORT partial_piece_info
|
|
|
|
{
|
|
|
|
int piece_index;
|
|
|
|
int blocks_in_piece;
|
|
|
|
// the number of blocks in the finished state
|
|
|
|
int finished;
|
|
|
|
// the number of blocks in the writing state
|
|
|
|
int writing;
|
|
|
|
// the number of blocks in the requested state
|
|
|
|
int requested;
|
|
|
|
block_info* blocks;
|
|
|
|
enum state_t { none, slow, medium, fast };
|
|
|
|
state_t piece_state;
|
|
|
|
};
|
2006-04-25 23:04:48 +02:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
struct TORRENT_EXPORT torrent_handle
|
|
|
|
{
|
|
|
|
friend class invariant_access;
|
|
|
|
friend struct aux::session_impl;
|
|
|
|
friend struct feed;
|
|
|
|
friend class torrent;
|
2011-12-23 06:36:13 +01:00
|
|
|
friend std::size_t hash_value(torrent_handle const& th);
|
2003-12-22 08:14:35 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
torrent_handle() {}
|
2004-04-18 14:28:02 +02:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
enum flags_t { overwrite_existing = 1 };
|
|
|
|
void add_piece(int piece, char const* data, int flags = 0) const;
|
|
|
|
void read_piece(int piece) const;
|
2011-11-27 01:01:13 +01:00
|
|
|
bool have_piece(int piece) const;
|
2007-11-20 23:46:27 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
void get_full_peer_list(std::vector<peer_list_entry>& v) const;
|
|
|
|
void get_peer_info(std::vector<peer_info>& v) const;
|
2004-01-15 02:01:09 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
enum status_flags_t
|
|
|
|
{
|
|
|
|
query_distributed_copies = 1,
|
|
|
|
query_accurate_download_counters = 2,
|
2011-08-07 09:19:18 +02:00
|
|
|
query_last_seen_complete = 4,
|
|
|
|
query_pieces = 8,
|
2013-03-03 00:17:48 +01:00
|
|
|
query_verified_pieces = 16,
|
|
|
|
query_torrent_file = 32,
|
|
|
|
query_name = 64,
|
|
|
|
query_save_path = 128,
|
2011-02-01 10:48:28 +01:00
|
|
|
};
|
2005-02-23 21:38:29 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
// the flags specify which fields are calculated. By default everything
|
|
|
|
// is included, you may save CPU by not querying fields you don't need
|
|
|
|
torrent_status status(boost::uint32_t flags = 0xffffffff) const;
|
|
|
|
void get_download_queue(std::vector<partial_piece_info>& queue) const;
|
2007-11-20 23:46:27 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
enum deadline_flags { alert_when_available = 1 };
|
|
|
|
void set_piece_deadline(int index, int deadline, int flags = 0) const;
|
2011-08-05 08:31:46 +02:00
|
|
|
void reset_piece_deadline(int index) const;
|
2008-03-29 19:47:24 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
void set_priority(int prio) const;
|
2006-04-25 23:04:48 +02:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
|
|
|
#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.
|
|
|
|
TORRENT_DEPRECATED_PREFIX
|
|
|
|
void file_progress(std::vector<float>& progress) const TORRENT_DEPRECATED;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
enum file_progress_flags_t
|
|
|
|
{
|
|
|
|
piece_granularity = 1
|
|
|
|
};
|
2004-08-05 15:56:26 +02:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
void file_progress(std::vector<size_type>& progress, int flags = 0) const;
|
2005-05-30 19:43:03 +02:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
void clear_error() const;
|
2005-05-30 19:43:03 +02:00
|
|
|
|
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
|
|
|
|
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
|
|
|
|
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
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
void add_extension(boost::function<boost::shared_ptr<torrent_plugin>(torrent*, void*)> const& ext
|
|
|
|
, void* userdata = 0);
|
2004-08-11 19:22:58 +02:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
bool set_metadata(char const* metadata, int size) const;
|
2012-10-02 18:07:55 +02:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
bool is_valid() const;
|
2007-07-17 08:39:39 +02:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
enum pause_flags_t { graceful_pause = 1 };
|
|
|
|
void pause(int flags = 0) const;
|
|
|
|
void resume() const;
|
|
|
|
void set_upload_mode(bool b) const;
|
|
|
|
void set_share_mode(bool b) const;
|
|
|
|
void flush_cache() const;
|
2007-07-23 06:36:56 +02:00
|
|
|
|
2011-02-27 18:26:57 +01:00
|
|
|
void apply_ip_filter(bool b) const;
|
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
void force_recheck() const;
|
2008-01-17 18:40:46 +01:00
|
|
|
|
2011-02-26 08:48:05 +01:00
|
|
|
enum save_resume_flags_t { flush_disk_cache = 1, save_info_dict = 2 };
|
2011-02-01 10:48:28 +01:00
|
|
|
void save_resume_data(int flags = 0) const;
|
|
|
|
bool need_save_resume_data() const;
|
2008-04-16 08:31:05 +02:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
void auto_managed(bool m) const;
|
2008-04-16 08:31:05 +02:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
int queue_position() const;
|
|
|
|
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
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
void resolve_countries(bool r);
|
|
|
|
bool resolve_countries() const;
|
2008-05-19 06:06:25 +02:00
|
|
|
|
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 = "");
|
2011-09-10 07:52:07 +02:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
storage_interface* get_storage_impl() const;
|
2008-06-05 20:19:03 +02:00
|
|
|
|
2012-10-02 18:07:55 +02:00
|
|
|
boost::intrusive_ptr<torrent_info> torrent_file() const;
|
|
|
|
|
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
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
|
|
|
|
2013-03-03 00:17:48 +01:00
|
|
|
// deprecated in 1.0
|
|
|
|
// use status() instead (with query_save_path)
|
|
|
|
TORRENT_DEPRECATED_PREFIX
|
|
|
|
std::string save_path() const TORRENT_DEPRECATED;
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
TORRENT_DEPRECATED_PREFIX
|
|
|
|
std::string name() const TORRENT_DEPRECATED;
|
|
|
|
|
2012-10-02 18:07:55 +02:00
|
|
|
// use torrent_file() instead
|
|
|
|
TORRENT_DEPRECATED_PREFIX
|
|
|
|
const torrent_info& get_torrent_info() const TORRENT_DEPRECATED;
|
|
|
|
|
2011-12-18 13:52:09 +01:00
|
|
|
// deprecated in 0.16, feature will be removed
|
|
|
|
TORRENT_DEPRECATED_PREFIX
|
|
|
|
int get_peer_upload_limit(tcp::endpoint ip) const TORRENT_DEPRECATED;
|
|
|
|
TORRENT_DEPRECATED_PREFIX
|
|
|
|
int get_peer_download_limit(tcp::endpoint ip) const TORRENT_DEPRECATED;
|
|
|
|
TORRENT_DEPRECATED_PREFIX
|
|
|
|
void set_peer_upload_limit(tcp::endpoint ip, int limit) const TORRENT_DEPRECATED;
|
|
|
|
TORRENT_DEPRECATED_PREFIX
|
|
|
|
void set_peer_download_limit(tcp::endpoint ip, int limit) const TORRENT_DEPRECATED;
|
|
|
|
|
2011-12-18 08:18:42 +01:00
|
|
|
// deprecated in 0.16, feature will be removed
|
|
|
|
TORRENT_DEPRECATED_PREFIX
|
|
|
|
void set_ratio(float up_down_ratio) const TORRENT_DEPRECATED;
|
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
// deprecated in 0.16. use status() instead
|
|
|
|
TORRENT_DEPRECATED_PREFIX
|
|
|
|
bool is_seed() const TORRENT_DEPRECATED;
|
|
|
|
TORRENT_DEPRECATED_PREFIX
|
|
|
|
bool is_finished() const TORRENT_DEPRECATED;
|
|
|
|
TORRENT_DEPRECATED_PREFIX
|
|
|
|
bool is_paused() const TORRENT_DEPRECATED;
|
|
|
|
TORRENT_DEPRECATED_PREFIX
|
|
|
|
bool is_auto_managed() const TORRENT_DEPRECATED;
|
|
|
|
TORRENT_DEPRECATED_PREFIX
|
|
|
|
bool is_sequential_download() const TORRENT_DEPRECATED;
|
|
|
|
TORRENT_DEPRECATED_PREFIX
|
|
|
|
bool has_metadata() const TORRENT_DEPRECATED;
|
2012-03-01 10:01:48 +01:00
|
|
|
TORRENT_DEPRECATED_PREFIX
|
|
|
|
bool super_seeding() const TORRENT_DEPRECATED;
|
2009-06-19 00:32:55 +02:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
// deprecated in 0.13
|
2012-10-02 18:07:55 +02:00
|
|
|
// all these are deprecated, use piece
|
|
|
|
// priority functions instead
|
2011-02-01 10:48:28 +01:00
|
|
|
// marks the piece with the given index as filtered
|
|
|
|
// it will not be downloaded
|
|
|
|
TORRENT_DEPRECATED_PREFIX
|
|
|
|
void filter_piece(int index, bool filter) const TORRENT_DEPRECATED;
|
|
|
|
TORRENT_DEPRECATED_PREFIX
|
|
|
|
void filter_pieces(std::vector<bool> const& pieces) const TORRENT_DEPRECATED;
|
|
|
|
TORRENT_DEPRECATED_PREFIX
|
|
|
|
bool is_piece_filtered(int index) const TORRENT_DEPRECATED;
|
|
|
|
TORRENT_DEPRECATED_PREFIX
|
|
|
|
std::vector<bool> filtered_pieces() const TORRENT_DEPRECATED;
|
|
|
|
// marks the file with the given index as filtered
|
|
|
|
// it will not be downloaded
|
|
|
|
TORRENT_DEPRECATED_PREFIX
|
|
|
|
void filter_files(std::vector<bool> const& files) const TORRENT_DEPRECATED;
|
2009-09-13 04:24:25 +02:00
|
|
|
|
2012-10-02 18:07:55 +02:00
|
|
|
TORRENT_DEPRECATED_PREFIX
|
|
|
|
void use_interface(const char* net_interface) const TORRENT_DEPRECATED;
|
|
|
|
|
|
|
|
// deprecated in 0.14
|
|
|
|
// use save_resume_data() instead. It is async. and
|
|
|
|
// will return the resume data in an alert
|
|
|
|
TORRENT_DEPRECATED_PREFIX
|
|
|
|
entry write_resume_data() const TORRENT_DEPRECATED;
|
2011-02-01 10:48:28 +01:00
|
|
|
// ================ end deprecation ============
|
|
|
|
#endif
|
2010-09-05 18:01:36 +02:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
void piece_availability(std::vector<int>& avail) const;
|
|
|
|
|
|
|
|
// priority must be within the range [0, 7]
|
|
|
|
void piece_priority(int index, int priority) const;
|
|
|
|
int piece_priority(int index) const;
|
2010-03-09 04:21:35 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
void prioritize_pieces(std::vector<int> const& pieces) const;
|
|
|
|
std::vector<int> piece_priorities() const;
|
2010-07-08 21:29:38 +02:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
// priority must be within the range [0, 7]
|
|
|
|
void file_priority(int index, int priority) const;
|
|
|
|
int file_priority(int index) const;
|
2010-11-06 19:04:07 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
void prioritize_files(std::vector<int> const& files) const;
|
|
|
|
std::vector<int> file_priorities() const;
|
2010-11-06 19:04:07 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
// forces this torrent to reannounce
|
|
|
|
// (make a rerequest from the tracker)
|
|
|
|
void force_reannounce() const;
|
|
|
|
// announces this torrent to the DHT immediately
|
|
|
|
void force_dht_announce() const;
|
2009-05-03 11:45:07 +02:00
|
|
|
|
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.
|
|
|
|
void force_reannounce(boost::posix_time::time_duration) const;
|
2009-05-03 11:45:07 +02:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
// performs a scrape request
|
|
|
|
void scrape_tracker() const;
|
|
|
|
|
|
|
|
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
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
void set_sequential_download(bool sd) const;
|
2007-06-10 22:46:09 +02:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
// manually connect a peer
|
|
|
|
void connect_peer(tcp::endpoint const& adr, int source = 0) const;
|
2003-12-22 08:14:35 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
// -1 means unlimited unchokes
|
|
|
|
void set_max_uploads(int max_uploads) const;
|
|
|
|
int max_uploads() const;
|
2010-03-04 20:15:23 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
// -1 means unlimited connections
|
|
|
|
void set_max_connections(int max_connections) const;
|
|
|
|
int max_connections() const;
|
2010-03-19 19:39:51 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
void set_tracker_login(std::string const& name
|
|
|
|
, std::string const& password) const;
|
2009-03-17 10:34:44 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
// post condition: save_path() == save_path if true is returned
|
2013-05-09 04:50:16 +02:00
|
|
|
void move_storage(std::string const& save_path, int flags = 0) const;
|
2011-02-01 10:48:28 +01:00
|
|
|
void rename_file(int index, std::string const& new_name) const;
|
2009-09-13 04:24:25 +02:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
#if TORRENT_USE_WSTRING
|
2013-05-09 04:50:16 +02:00
|
|
|
void move_storage(std::wstring const& save_path, int flags = 0) const;
|
2011-02-01 10:48:28 +01:00
|
|
|
void rename_file(int index, std::wstring const& new_name) const;
|
2008-08-03 17:14:08 +02:00
|
|
|
#endif
|
2009-07-04 06:58:24 +02:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
void super_seeding(bool on) const;
|
2003-11-28 18:29:27 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
sha1_hash info_hash() const;
|
2008-07-12 19:00:52 +02:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
bool operator==(const torrent_handle& h) const
|
|
|
|
{ return m_torrent.lock() == h.m_torrent.lock(); }
|
2004-09-12 12:12:16 +02:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
bool operator!=(const torrent_handle& h) const
|
|
|
|
{ return m_torrent.lock() != h.m_torrent.lock(); }
|
2006-04-25 23:04:48 +02:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
bool operator<(const torrent_handle& h) const
|
|
|
|
{ return m_torrent.lock() < h.m_torrent.lock(); }
|
2008-12-30 04:54:07 +01:00
|
|
|
|
2012-08-30 03:54:35 +02:00
|
|
|
boost::shared_ptr<torrent> native_handle() const;
|
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
private:
|
|
|
|
|
|
|
|
torrent_handle(boost::weak_ptr<torrent> const& t)
|
|
|
|
: m_torrent(t)
|
|
|
|
{}
|
|
|
|
|
2013-02-25 05:13:46 +01:00
|
|
|
#if defined TORRENT_DEBUG && !defined TORRENT_DISABLE_INVARIANT_CHECKS
|
2011-02-01 10:48:28 +01:00
|
|
|
void check_invariant() const;
|
2007-11-08 02:45:35 +01:00
|
|
|
#endif
|
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
boost::weak_ptr<torrent> m_torrent;
|
2003-11-02 22:06:50 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
};
|
2009-06-19 00:32:55 +02:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
struct TORRENT_EXPORT torrent_status
|
|
|
|
{
|
2012-03-19 07:06:52 +01:00
|
|
|
torrent_status();
|
|
|
|
~torrent_status();
|
2010-10-29 04:21:43 +02:00
|
|
|
|
2011-12-23 06:36:13 +01:00
|
|
|
bool operator==(torrent_status const& st) const
|
|
|
|
{ return handle == st.handle; }
|
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
// handle to the torrent
|
|
|
|
torrent_handle handle;
|
2007-05-02 21:47:38 +02:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
enum state_t
|
|
|
|
{
|
|
|
|
queued_for_checking,
|
|
|
|
checking_files,
|
|
|
|
downloading_metadata,
|
|
|
|
downloading,
|
|
|
|
finished,
|
|
|
|
seeding,
|
|
|
|
allocating,
|
|
|
|
checking_resume_data
|
|
|
|
};
|
|
|
|
|
|
|
|
state_t state;
|
|
|
|
bool paused;
|
|
|
|
bool auto_managed;
|
|
|
|
bool sequential_download;
|
|
|
|
bool is_seeding;
|
|
|
|
bool is_finished;
|
|
|
|
bool has_metadata;
|
2008-04-24 05:28:48 +02:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
float progress;
|
|
|
|
// progress parts per million (progress * 1000000)
|
|
|
|
// when disabling floating point operations, this is
|
|
|
|
// the only option to query progress
|
|
|
|
int progress_ppm;
|
|
|
|
std::string error;
|
2008-05-29 05:37:19 +02:00
|
|
|
|
2013-03-03 00:17:48 +01:00
|
|
|
// save path of where the torrent's files are saved
|
|
|
|
// only set when status is queried with query_save_path
|
|
|
|
std::string save_path;
|
|
|
|
|
|
|
|
// name of the torrent, or empty if the torrent's name
|
|
|
|
// cannot be established yet
|
|
|
|
// only set when status is queried with query_name
|
|
|
|
std::string name;
|
|
|
|
|
|
|
|
// the torrent file for this torrent
|
|
|
|
// only set when status is queried with query_torrent_file
|
|
|
|
boost::intrusive_ptr<const torrent_info> torrent_file;
|
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
boost::posix_time::time_duration next_announce;
|
|
|
|
boost::posix_time::time_duration announce_interval;
|
2004-03-21 03:03:37 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
std::string current_tracker;
|
2008-09-04 18:20:19 +02:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
// transferred this session!
|
|
|
|
// total, payload plus protocol
|
|
|
|
size_type total_download;
|
|
|
|
size_type total_upload;
|
2007-03-20 02:59:00 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
// payload only
|
|
|
|
size_type total_payload_download;
|
|
|
|
size_type total_payload_upload;
|
2007-03-20 02:59:00 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
// the amount of payload bytes that
|
|
|
|
// has failed their hash test
|
|
|
|
size_type total_failed_bytes;
|
2010-10-30 19:23:30 +02:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
// the number of payload bytes that
|
|
|
|
// has been received redundantly.
|
|
|
|
size_type total_redundant_bytes;
|
2005-07-02 10:48:37 +02:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
// current transfer rate
|
|
|
|
// payload plus protocol
|
|
|
|
int download_rate;
|
|
|
|
int upload_rate;
|
2007-03-20 02:59:00 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
// the rate of payload that is
|
|
|
|
// sent and received
|
|
|
|
int download_payload_rate;
|
|
|
|
int upload_payload_rate;
|
2007-03-20 02:59:00 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
// the number of peers this torrent is connected to
|
|
|
|
// that are seeding.
|
|
|
|
int num_seeds;
|
2007-03-20 02:59:00 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
// the number of peers this torrent
|
|
|
|
// is connected to (including seeds).
|
|
|
|
int num_peers;
|
2007-03-20 02:59:00 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
// if the tracker sends scrape info in its
|
|
|
|
// announce reply, these fields will be
|
|
|
|
// set to the total number of peers that
|
|
|
|
// have the whole file and the total number
|
|
|
|
// of peers that are still downloading
|
|
|
|
int num_complete;
|
|
|
|
int num_incomplete;
|
2007-03-20 02:59:00 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
// this is the number of seeds whose IP we know
|
|
|
|
// but are not necessarily connected to
|
|
|
|
int list_seeds;
|
2004-02-26 01:27:06 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
// this is the number of peers whose IP we know
|
|
|
|
// (including seeds), but are not necessarily
|
|
|
|
// connected to
|
|
|
|
int list_peers;
|
2004-02-25 00:55:42 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
// the number of peers in our peerlist that
|
|
|
|
// we potentially could connect to
|
|
|
|
int connect_candidates;
|
|
|
|
|
|
|
|
bitfield pieces;
|
2011-08-07 09:19:18 +02:00
|
|
|
bitfield verified_pieces;
|
2011-02-01 10:48:28 +01:00
|
|
|
|
|
|
|
// this is the number of pieces the client has
|
|
|
|
// downloaded. it is equal to:
|
|
|
|
// std::accumulate(pieces->begin(), pieces->end());
|
|
|
|
int num_pieces;
|
2003-10-30 00:28:09 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
// the number of bytes of the file we have
|
|
|
|
// including pieces that may have been filtered
|
|
|
|
// after we downloaded them
|
|
|
|
size_type total_done;
|
2005-05-03 15:13:57 +02:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
// the number of bytes we have of those that we
|
|
|
|
// want. i.e. not counting bytes from pieces that
|
|
|
|
// are filtered as not wanted.
|
|
|
|
size_type total_wanted_done;
|
2007-11-20 23:46:27 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
// the total number of bytes we want to download
|
|
|
|
// this may be smaller than the total torrent size
|
|
|
|
// in case any pieces are filtered as not wanted
|
|
|
|
size_type total_wanted;
|
2006-11-14 01:08:16 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
// the number of distributed copies of the file.
|
|
|
|
// note that one copy may be spread out among many peers.
|
|
|
|
//
|
|
|
|
// the integer part tells how many copies
|
|
|
|
// there are of the rarest piece(s)
|
|
|
|
//
|
|
|
|
// the fractional part tells the fraction of pieces that
|
|
|
|
// have more copies than the rarest piece(s).
|
2003-10-26 18:35:23 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
// the number of full distributed copies (i.e. the number
|
|
|
|
// of peers that have the rarest piece)
|
|
|
|
int distributed_full_copies;
|
2007-04-10 11:25:17 +02:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
// the fraction of pieces that more peers has than the
|
|
|
|
// rarest pieces. This indicates how close the swarm is
|
|
|
|
// to have one more full distributed copy
|
|
|
|
int distributed_fraction;
|
2004-02-01 01:50:18 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
float distributed_copies;
|
2006-04-25 23:04:48 +02:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
// the block size that is used in this torrent. i.e.
|
|
|
|
// the number of bytes each piece request asks for
|
|
|
|
// and each bit in the download queue bitfield represents
|
|
|
|
int block_size;
|
2004-01-08 18:03:04 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
int num_uploads;
|
|
|
|
int num_connections;
|
|
|
|
int uploads_limit;
|
|
|
|
int connections_limit;
|
2004-01-12 04:05:10 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
// true if the torrent is saved in compact mode
|
|
|
|
// false if it is saved in full allocation mode
|
|
|
|
storage_mode_t storage_mode;
|
2003-12-07 06:53:04 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
int up_bandwidth_queue;
|
|
|
|
int down_bandwidth_queue;
|
2003-12-14 06:56:12 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
// number of bytes downloaded since torrent was started
|
|
|
|
// saved and restored from resume data
|
|
|
|
size_type all_time_upload;
|
|
|
|
size_type all_time_download;
|
2004-01-21 01:59:38 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
// the number of seconds of being active
|
|
|
|
// and as being a seed, saved and restored
|
|
|
|
// from resume data
|
|
|
|
int active_time;
|
|
|
|
int finished_time;
|
|
|
|
int seeding_time;
|
2004-02-22 23:40:45 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
// higher value means more important to seed
|
|
|
|
int seed_rank;
|
2009-03-31 10:12:35 +02:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
// number of seconds since last scrape, or -1 if
|
|
|
|
// there hasn't been a scrape
|
|
|
|
int last_scrape;
|
2004-07-18 02:39:58 +02:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
// true if there are incoming connections to this
|
|
|
|
// torrent
|
|
|
|
bool has_incoming;
|
2008-12-08 07:36:22 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
// the number of "holes" in the torrent
|
|
|
|
int sparse_regions;
|
2003-12-07 06:53:04 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
// is true if this torrent is (still) in seed_mode
|
|
|
|
bool seed_mode;
|
2003-12-07 06:53:04 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
// this is set to true when the torrent is blocked
|
|
|
|
// from downloading, typically caused by a file
|
|
|
|
// write operation failing
|
|
|
|
bool upload_mode;
|
2003-12-07 06:53:04 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
// this is true if the torrent is in share-mode
|
|
|
|
bool share_mode;
|
2003-12-07 06:53:04 +01:00
|
|
|
|
2012-03-01 10:01:48 +01:00
|
|
|
// true if the torrent is in super seeding mode
|
|
|
|
bool super_seeding;
|
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
// the priority of this torrent
|
|
|
|
int priority;
|
2003-11-08 03:16:26 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
// the time this torrent was added and completed
|
|
|
|
time_t added_time;
|
|
|
|
time_t completed_time;
|
|
|
|
time_t last_seen_complete;
|
2004-02-29 17:39:52 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
// number of seconds since last upload or download activity
|
|
|
|
int time_since_upload;
|
|
|
|
int time_since_download;
|
2003-10-26 18:35:23 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
// the position in the download queue where this torrent is
|
|
|
|
// this is -1 for seeds and finished torrents
|
|
|
|
int queue_position;
|
2003-10-26 18:35:23 +01:00
|
|
|
|
2011-02-01 10:48:28 +01:00
|
|
|
// true if this torrent has had changes since the last
|
|
|
|
// time resume data was saved
|
|
|
|
bool need_save_resume;
|
2011-02-27 18:26:57 +01:00
|
|
|
|
|
|
|
// defaults to true. Determines whether the session
|
|
|
|
// IP filter applies to this torrent or not
|
|
|
|
bool ip_filter_applies;
|
2011-04-19 10:21:09 +02:00
|
|
|
|
|
|
|
// the info-hash for this torrent
|
|
|
|
sha1_hash info_hash;
|
2011-09-12 05:51:49 +02:00
|
|
|
|
|
|
|
// if this torrent has its own listen socket, this is
|
|
|
|
// the port it's listening on. Otherwise it's 0
|
|
|
|
int listen_port;
|
2003-10-26 18:35:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // TORRENT_TORRENT_HANDLE_HPP_INCLUDED
|
2007-05-10 00:54:26 +02:00
|
|
|
|