Merge pull request #165 from arvidn/header-cleanup

separate out announce_entry and torrent_status into their own headers
This commit is contained in:
Arvid Norberg 2015-09-18 19:22:13 -04:00
commit 0f241a0816
51 changed files with 937 additions and 709 deletions

View File

@ -8,6 +8,7 @@ set(sources
alert
alert_manager
allocator
announce_entry
assert
bandwidth_limit
bandwidth_manager

View File

@ -590,6 +590,7 @@ SOURCES =
alert
alert_manager
allocator
announce_entry
assert
bandwidth_limit
bandwidth_manager

View File

@ -14,6 +14,7 @@
#include <libtorrent/bdecode.hpp>
#include <libtorrent/bencode.hpp>
#include <libtorrent/aux_/session_impl.hpp> // for settings_map()
#include <libtorrent/torrent_info.hpp>
#include <libtorrent/extensions/lt_trackers.hpp>
#include <libtorrent/extensions/metadata_transfer.hpp>

View File

@ -5,7 +5,11 @@
#include <boost/python.hpp>
#include <boost/python/tuple.hpp>
#include <libtorrent/torrent_handle.hpp>
#include <libtorrent/torrent_info.hpp>
#include <libtorrent/torrent_status.hpp>
#include <libtorrent/entry.hpp>
#include <libtorrent/peer_info.hpp>
#include "libtorrent/announce_entry.hpp"
#include <boost/lexical_cast.hpp>
#include "gil.hpp"

View File

@ -4,10 +4,11 @@
#include <boost/python.hpp>
#include <boost/shared_ptr.hpp>
#include <libtorrent/torrent_info.hpp>
#include "libtorrent/torrent_info.hpp"
#include "libtorrent/session_settings.hpp"
#include "libtorrent/time.hpp"
#include "libtorrent/socket_io.hpp"
#include "libtorrent/announce_entry.hpp"
#include "bytes.hpp"
using namespace boost::python;

View File

@ -3,7 +3,8 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <boost/python.hpp>
#include <libtorrent/torrent_handle.hpp>
#include <libtorrent/torrent_status.hpp>
#include <libtorrent/torrent_info.hpp>
#include <libtorrent/bitfield.hpp>
using namespace boost::python;

View File

@ -55,6 +55,8 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/extensions/ut_pex.hpp"
#include "libtorrent/extensions/smart_ban.hpp"
#include "libtorrent/torrent_info.hpp"
#include "libtorrent/announce_entry.hpp"
#include "libtorrent/entry.hpp"
#include "libtorrent/bencode.hpp"
#include "libtorrent/session.hpp"

View File

@ -33,6 +33,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/entry.hpp"
#include "libtorrent/bencode.hpp"
#include "libtorrent/torrent_info.hpp"
#include "libtorrent/announce_entry.hpp"
#include "libtorrent/bdecode.hpp"
#include "libtorrent/magnet_uri.hpp"

View File

@ -35,6 +35,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/entry.hpp"
#include "libtorrent/bencode.hpp"
#include "libtorrent/session.hpp"
#include "libtorrent/torrent_info.hpp"
int main(int argc, char* argv[])
{

View File

@ -1,5 +1,6 @@
#include "torrent_view.hpp"
#include "print.hpp"
#include "libtorrent/torrent_status.hpp"
const int header_size = 2;

View File

@ -2,6 +2,8 @@
#define TORRENT_VIEW_HPP_
#include <set>
#include <vector>
#include <boost/unordered_set.hpp>
#include "libtorrent/torrent_handle.hpp"

View File

@ -9,6 +9,7 @@ nobase_include_HEADERS = \
alert_types.hpp \
alloca.hpp \
allocator.hpp \
announce_entry.hpp \
assert.hpp \
bandwidth_limit.hpp \
bandwidth_manager.hpp \
@ -138,6 +139,7 @@ nobase_include_HEADERS = \
torrent_peer.hpp \
torrent_peer_allocator.hpp \
tracker_manager.hpp \
torrent_status.hpp \
udp_socket.hpp \
udp_tracker_connection.hpp \
uncork_interface.hpp \

View File

@ -33,15 +33,20 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef TORRENT_ALERT_TYPES_HPP_INCLUDED
#define TORRENT_ALERT_TYPES_HPP_INCLUDED
#include "libtorrent/config.hpp"
#include "libtorrent/alert.hpp"
#include "libtorrent/torrent_handle.hpp"
#include "libtorrent/socket.hpp"
#include "libtorrent/config.hpp"
#include "libtorrent/assert.hpp"
#include "libtorrent/identify_client.hpp"
#include "libtorrent/address.hpp"
#include "libtorrent/stat.hpp"
#include "libtorrent/add_torrent_params.hpp"
#include "libtorrent/torrent_status.hpp"
#include "libtorrent/entry.hpp"
#include "libtorrent/peer_request.hpp"
#include "libtorrent/performance_counters.hpp"
#ifndef TORRENT_NO_DEPRECATE
#include "libtorrent/rss.hpp" // for feed_handle
#endif
@ -49,6 +54,11 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/close_reason.hpp"
#include "libtorrent/aux_/escape_string.hpp" // for convert_from_native
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <boost/shared_array.hpp>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#ifdef __GNUC__
#pragma GCC diagnostic push

View File

@ -0,0 +1,199 @@
/*
Copyright (c) 2015, Arvid Norberg
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_ANNOUNCE_ENTRY_HPP_INCLUDED
#define TORRENT_ANNOUNCE_ENTRY_HPP_INCLUDED
#include "libtorrent/config.hpp"
#include "libtorrent/time.hpp" // for time_point
#include "libtorrent/error_code.hpp"
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <string>
#include <boost/cstdint.hpp>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
namespace libtorrent
{
namespace aux {
struct session_settings;
}
// this class holds information about one bittorrent tracker, as it
// relates to a specific torrent.
struct TORRENT_EXPORT announce_entry
{
// constructs a tracker announce entry with ``u`` as the URL.
announce_entry(std::string const& u);
announce_entry();
~announce_entry();
#if __cplusplus >= 201103L
announce_entry(announce_entry const&) = default;
announce_entry& operator=(announce_entry const&) = default;
#endif
// tracker URL as it appeared in the torrent file
std::string url;
// the current ``&trackerid=`` argument passed to the tracker.
// this is optional and is normally empty (in which case no
// trackerid is sent).
std::string trackerid;
// if this tracker has returned an error or warning message
// that message is stored here
std::string message;
// if this tracker failed the last time it was contacted
// this error code specifies what error occurred
error_code last_error;
// returns the number of seconds to the next announce on this tracker.
// ``min_announce_in()`` returns the number of seconds until we are
// allowed to force another tracker update with this tracker.
//
// If the last time this tracker was contacted failed, ``last_error`` is
// the error code describing what error occurred.
int next_announce_in() const;
int min_announce_in() const;
// the time of next tracker announce
time_point next_announce;
// no announces before this time
time_point min_announce;
// TODO: include the number of peers received from this tracker, at last
// announce
// these are either -1 or the scrape information this tracker last
// responded with. *incomplete* is the current number of downloaders in
// the swarm, *complete* is the current number of seeds in the swarm and
// *downloaded* is the cumulative number of completed downloads of this
// torrent, since the beginning of time (from this tracker's point of
// view).
// if this tracker has returned scrape data, these fields are filled in
// with valid numbers. Otherwise they are set to -1. the number of
// current downloaders
int scrape_incomplete;
int scrape_complete;
int scrape_downloaded;
// the tier this tracker belongs to
boost::uint8_t tier;
// the max number of failures to announce to this tracker in
// a row, before this tracker is not used anymore. 0 means unlimited
boost::uint8_t fail_limit;
// the number of times in a row we have failed to announce to this
// tracker.
boost::uint8_t fails:7;
// true while we're waiting for a response from the tracker.
bool updating:1;
// flags for the source bitmask, each indicating where
// we heard about this tracker
enum tracker_source
{
// the tracker was part of the .torrent file
source_torrent = 1,
// the tracker was added programatically via the add_troacker()_ function
source_client = 2,
// the tracker was part of a magnet link
source_magnet_link = 4,
// the tracker was received from the swarm via tracker exchange
source_tex = 8
};
// a bitmask specifying which sources we got this tracker from.
boost::uint8_t source:4;
// set to true the first time we receive a valid response
// from this tracker.
bool verified:1;
// set to true when we get a valid response from an announce
// with event=started. If it is set, we won't send start in the subsequent
// announces.
bool start_sent:1;
// set to true when we send a event=completed.
bool complete_sent:1;
// this is false the stats sent to this tracker will be 0
bool send_stats:1;
// reset announce counters and clears the started sent flag.
// The announce_entry will look like we've never talked to
// the tracker.
void reset();
// updates the failure counter and time-outs for re-trying.
// This is called when the tracker announce fails.
void failed(aux::session_settings const& sett, int retry_interval = 0);
#ifndef TORRENT_NO_DEPRECATE
// deprecated in 1.0
TORRENT_DEPRECATED
bool will_announce(time_point now) const
{
return now <= next_announce
&& (fails < fail_limit || fail_limit == 0)
&& !updating;
}
#endif
// returns true if we can announec to this tracker now.
// The current time is passed in as ``now``. The ``is_seed``
// argument is necessary because once we become a seed, we
// need to announce right away, even if the re-announce timer
// hasn't expired yet.
bool can_announce(time_point now, bool is_seed) const;
// returns true if the last time we tried to announce to this
// tracker succeeded, or if we haven't tried yet.
bool is_working() const
{ return fails == 0; }
// trims whitespace characters from the beginning of the URL.
void trim();
};
}
#endif

View File

@ -48,6 +48,7 @@ namespace libtorrent
struct disk_observer;
struct file_pool;
struct add_torrent_params;
struct cache_status;
struct disk_interface
{

View File

@ -45,6 +45,9 @@ namespace libtorrent
namespace aux
{ struct session_impl; }
class session;
struct bdecode_node;
// represents one item from an RSS feed. Specifically
// a feed of torrents.
//
@ -99,7 +102,7 @@ namespace libtorrent
, default_ttl(30)
{}
std::string url;
std::string url;
// By default ``auto_download`` is true, which means all torrents in
// the feed will be downloaded. Set this to false in order to manually

View File

@ -393,14 +393,8 @@ namespace libtorrent
void on_disk_read_complete(disk_io_job const* j, peer_request r
, boost::shared_ptr<read_piece_struct> rp);
storage_mode_t storage_mode() const
{ return storage_mode_t(m_storage_mode); }
storage_interface* get_storage()
{
if (!m_storage) return 0;
return m_storage->get_storage_impl();
}
storage_mode_t storage_mode() const;
storage_interface* get_storage();
// this will flag the torrent as aborted. The main
// loop in session_impl will check for this state

View File

@ -33,13 +33,15 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef TORRENT_TORRENT_HANDLE_HPP_INCLUDED
#define TORRENT_TORRENT_HANDLE_HPP_INCLUDED
#include "libtorrent/config.hpp"
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <vector>
#include <set>
#include <boost/assert.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/function.hpp>
#include <boost/weak_ptr.hpp>
#include <boost/cstdint.hpp>
@ -50,16 +52,8 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#include "libtorrent/peer_id.hpp"
#include "libtorrent/piece_picker.hpp"
#include "libtorrent/torrent_info.hpp"
#include "libtorrent/time.hpp"
#include "libtorrent/config.hpp"
#include "libtorrent/storage.hpp"
#include "libtorrent/address.hpp"
#include "libtorrent/bitfield.hpp"
#include "libtorrent/socket.hpp" // tcp::endpoint
#include "libtorrent/file_pool.hpp"
namespace libtorrent
{
@ -68,20 +62,23 @@ namespace libtorrent
struct session_impl;
}
class entry;
struct pool_file_status;
struct announce_entry;
class torrent_info;
struct torrent_plugin;
struct peer_info;
struct peer_list_entry;
struct torrent_status;
struct torrent_handle;
class sha1_hash;
struct storage_interface;
class torrent;
// allows torrent_handle to be used in unordered_map and unordered_set.
TORRENT_EXPORT std::size_t hash_value(torrent_status const& ts);
#ifndef BOOST_NO_EXCEPTIONS
// for compatibility with 0.14
typedef libtorrent_exception duplicate_torrent;
typedef libtorrent_exception invalid_handle;
void throw_invalid_handle() TORRENT_NO_RETURN;
#endif
@ -575,7 +572,7 @@ namespace libtorrent
// other peers are downloaded, and only if the previous prediction was
// correct.
void set_share_mode(bool b) const;
// Instructs libtorrent to flush all the disk caches for this torrent and
// close all file handles. This is done asynchronously and you will be
// notified that it's complete through cache_flushed_alert.
@ -1253,433 +1250,6 @@ namespace libtorrent
};
// holds a snapshot of the status of a torrent, as queried by
// torrent_handle::status().
struct TORRENT_EXPORT torrent_status
{
// hidden
torrent_status();
~torrent_status();
#if __cplusplus >= 201103L
torrent_status(torrent_status const&) = default;
torrent_status& operator=(torrent_status const&) = default;
#endif
// compres if the torrent status objects come from the same torrent. i.e.
// only the torrent_handle field is compared.
bool operator==(torrent_status const& st) const
{ return handle == st.handle; }
// a handle to the torrent whose status the object represents.
torrent_handle handle;
// the different overall states a torrent can be in
enum state_t
{
#ifndef TORRENT_NO_DEPRECATE
// The torrent is in the queue for being checked. But there
// currently is another torrent that are being checked.
// This torrent will wait for its turn.
queued_for_checking,
#else
unused_enum_for_backwards_compatibility,
#endif
// The torrent has not started its download yet, and is
// currently checking existing files.
checking_files,
// The torrent is trying to download metadata from peers.
// This assumes the metadata_transfer extension is in use.
downloading_metadata,
// The torrent is being downloaded. This is the state
// most torrents will be in most of the time. The progress
// meter will tell how much of the files that has been
// downloaded.
downloading,
// In this state the torrent has finished downloading but
// still doesn't have the entire torrent. i.e. some pieces
// are filtered and won't get downloaded.
finished,
// In this state the torrent has finished downloading and
// is a pure seeder.
seeding,
// If the torrent was started in full allocation mode, this
// indicates that the (disk) storage for the torrent is
// allocated.
allocating,
// The torrent is currently checking the fastresume data and
// comparing it to the files on disk. This is typically
// completed in a fraction of a second, but if you add a
// large number of torrents at once, they will queue up.
checking_resume_data
};
// may be set to an error message describing why the torrent
// was paused, in case it was paused by an error. If the torrent
// is not paused or if it's paused but not because of an error,
// this string is empty.
std::string error;
// the path to the directory where this torrent's files are stored.
// It's typically the path as was given to async_add_torrent() or
// add_torrent() when this torrent was started. This field is only
// included if the torrent status is queried with
// ``torrent_handle::query_save_path``.
std::string save_path;
// the name of the torrent. Typically this is derived from the
// .torrent file. In case the torrent was started without metadata,
// and hasn't completely received it yet, it returns the name given
// to it when added to the session. See ``session::add_torrent``.
// This field is only included if the torrent status is queried
// with ``torrent_handle::query_name``.
std::string name;
// set to point to the ``torrent_info`` object for this torrent. It's
// only included if the torrent status is queried with
// ``torrent_handle::query_torrent_file``.
boost::weak_ptr<const torrent_info> torrent_file;
// the time until the torrent will announce itself to the tracker.
time_duration next_announce;
#ifndef TORRENT_NO_DEPRECATE
// the time the tracker want us to wait until we announce ourself
// again the next time.
time_duration announce_interval;
#else
// hidden
time_duration deprecated_announce_interval_;
#endif
// the URL of the last working tracker. If no tracker request has
// been successful yet, it's set to an empty string.
std::string current_tracker;
// the number of bytes downloaded and uploaded to all peers, accumulated,
// *this session* only. The session is considered to restart when a
// torrent is paused and restarted again. When a torrent is paused, these
// counters are reset to 0. If you want complete, persistent, stats, see
// ``all_time_upload`` and ``all_time_download``.
boost::int64_t total_download;
boost::int64_t total_upload;
// counts the amount of bytes send and received this session, but only
// the actual payload data (i.e the interesting data), these counters
// ignore any protocol overhead. The session is considered to restart
// when a torrent is paused and restarted again. When a torrent is
// paused, these counters are reset to 0.
boost::int64_t total_payload_download;
boost::int64_t total_payload_upload;
// the number of bytes that has been downloaded and that has failed the
// piece hash test. In other words, this is just how much crap that has
// been downloaded since the torrent was last started. If a torrent is
// paused and then restarted again, this counter will be reset.
boost::int64_t total_failed_bytes;
// the number of bytes that has been downloaded even though that data
// already was downloaded. The reason for this is that in some situations
// the same data can be downloaded by mistake. When libtorrent sends
// requests to a peer, and the peer doesn't send a response within a
// certain timeout, libtorrent will re-request that block. Another
// situation when libtorrent may re-request blocks is when the requests
// it sends out are not replied in FIFO-order (it will re-request blocks
// that are skipped by an out of order block). This is supposed to be as
// low as possible. This only counts bytes since the torrent was last
// started. If a torrent is paused and then restarted again, this counter
// will be reset.
boost::int64_t total_redundant_bytes;
// a bitmask that represents which pieces we have (set to true) and the
// pieces we don't have. It's a pointer and may be set to 0 if the
// torrent isn't downloading or seeding.
bitfield pieces;
// a bitmask representing which pieces has had their hash checked. This
// only applies to torrents in *seed mode*. If the torrent is not in seed
// mode, this bitmask may be empty.
bitfield verified_pieces;
// the total number of bytes of the file(s) that we have. All this does
// not necessarily has to be downloaded during this session (that's
// ``total_payload_download``).
boost::int64_t total_done;
// the number of bytes we have downloaded, only counting the pieces that
// we actually want to download. i.e. excluding any pieces that we have
// but have priority 0 (i.e. not wanted).
boost::int64_t total_wanted_done;
// The total number of bytes we want to download. This may be smaller
// than the total torrent size in case any pieces are prioritized to 0,
// i.e. not wanted
boost::int64_t total_wanted;
// are accumulated upload and download payload byte counters. They are
// saved in and restored from resume data to keep totals across sessions.
boost::int64_t all_time_upload;
boost::int64_t all_time_download;
// the posix-time when this torrent was added. i.e. what ``time(NULL)``
// returned at the time.
time_t added_time;
// the posix-time when this torrent was finished. If the torrent is not
// yet finished, this is 0.
time_t completed_time;
// the time when we, or one of our peers, last saw a complete copy of
// this torrent.
time_t last_seen_complete;
// The allocation mode for the torrent. See storage_mode_t for the
// options. For more information, see storage-allocation_.
storage_mode_t storage_mode;
// a value in the range [0, 1], that represents the progress of the
// torrent's current task. It may be checking files or downloading.
float progress;
// progress parts per million (progress * 1000000) when disabling
// floating point operations, this is the only option to query progress
//
// reflects the same value as ``progress``, but instead in a range [0,
// 1000000] (ppm = parts per million). When floating point operations are
// disabled, this is the only alternative to the floating point value in
// progress.
int progress_ppm;
// the position this torrent has in the download
// queue. If the torrent is a seed or finished, this is -1.
int queue_position;
// the total rates for all peers for this torrent. These will usually
// have better precision than summing the rates from all peers. The rates
// are given as the number of bytes per second.
int download_rate;
int upload_rate;
// the total transfer rate of payload only, not counting protocol
// chatter. This might be slightly smaller than the other rates, but if
// projected over a long time (e.g. when calculating ETA:s) the
// difference may be noticeable.
int download_payload_rate;
int upload_payload_rate;
// the number of peers that are seeding that this client is
// currently connected to.
int num_seeds;
// the number of peers this torrent currently is connected to. Peer
// connections that are in the half-open state (is attempting to connect)
// or are queued for later connection attempt do not count. Although they
// are visible in the peer list when you call get_peer_info().
int num_peers;
// if the tracker sends scrape info in its announce reply, these fields
// will be set to the total number of peers that have the whole file and
// the total number of peers that are still downloading. set to -1 if the
// tracker did not send any scrape data in its announce reply.
int num_complete;
int num_incomplete;
// the number of seeds in our peer list and the total number of peers
// (including seeds). We are not necessarily connected to all the peers
// in our peer list. This is the number of peers we know of in total,
// including banned peers and peers that we have failed to connect to.
int list_seeds;
int list_peers;
// the number of peers in this torrent's peer list that is a candidate to
// be connected to. i.e. It has fewer connect attempts than the max fail
// count, it is not a seed if we are a seed, it is not banned etc. If
// this is 0, it means we don't know of any more peers that we can try.
int connect_candidates;
// the number of pieces that has been downloaded. It is equivalent to:
// ``std::accumulate(pieces->begin(), pieces->end())``. So you don't have
// to count yourself. This can be used to see if anything has updated
// since last time if you want to keep a graph of the pieces up to date.
int num_pieces;
// the number of distributed copies of the torrent. Note that one copy
// may be spread out among many peers. It tells how many copies there are
// currently of the rarest piece(s) among the peers this client is
// connected to.
int distributed_full_copies;
// tells the share of pieces that have more copies than the rarest
// piece(s). Divide this number by 1000 to get the fraction.
//
// For example, if ``distributed_full_copies`` is 2 and
// ``distrbuted_fraction`` is 500, it means that the rarest pieces have
// only 2 copies among the peers this torrent is connected to, and that
// 50% of all the pieces have more than two copies.
//
// If we are a seed, the piece picker is deallocated as an optimization,
// and piece availability is no longer tracked. In this case the
// distributed copies members are set to -1.
int distributed_fraction;
// the number of distributed copies of the file. note that one copy may
// be spread out among many peers. This is a floating point
// representation of the distributed copies.
//
// the integer part tells how many copies
// there are of the rarest piece(s)
//
// the fractional part tells the fraction of pieces that
// have more copies than the rarest piece(s).
float distributed_copies;
// the size of a block, in bytes. A block is a sub piece, it is the
// number of bytes that each piece request asks for and the number of
// bytes that each bit in the ``partial_piece_info``'s bitset represents,
// see get_download_queue(). This is typically 16 kB, but it may be
// larger if the pieces are larger.
int block_size;
// the number of unchoked peers in this torrent.
int num_uploads;
// the number of peer connections this torrent has, including half-open
// connections that hasn't completed the bittorrent handshake yet. This
// is always >= ``num_peers``.
int num_connections;
// the set limit of upload slots (unchoked peers) for this torrent.
int uploads_limit;
// the set limit of number of connections for this torrent.
int connections_limit;
// the number of peers in this torrent that are waiting for more
// bandwidth quota from the torrent rate limiter. This can determine if
// the rate you get from this torrent is bound by the torrents limit or
// not. If there is no limit set on this torrent, the peers might still
// be waiting for bandwidth quota from the global limiter, but then they
// are counted in the ``session_status`` object.
int up_bandwidth_queue;
int down_bandwidth_queue;
// the number of seconds since any peer last uploaded from this torrent
// and the last time a downloaded piece passed the hash check,
// respectively.
int time_since_upload;
int time_since_download;
// These keep track of the number of seconds this torrent has been active
// (not paused) and the number of seconds it has been active while being
// finished and active while being a seed. ``seeding_time`` should be <=
// ``finished_time`` which should be <= ``active_time``. They are all
// saved in and restored from resume data, to keep totals across
// sessions.
int active_time;
int finished_time;
int seeding_time;
// A rank of how important it is to seed the torrent, it is used to
// determine which torrents to seed and which to queue. It is based on
// the peer to seed ratio from the tracker scrape. For more information,
// see queuing_. Higher value means more important to seed
int seed_rank;
// the number of seconds since this torrent acquired scrape data.
// If it has never done that, this value is -1.
int last_scrape;
// the priority of this torrent
int priority;
// the main state the torrent is in. See torrent_status::state_t.
state_t state;
// true if this torrent has unsaved changes
// to its download state and statistics since the last resume data
// was saved.
bool need_save_resume;
// true if the session global IP filter applies
// to this torrent. This defaults to true.
bool ip_filter_applies;
// true if the torrent is blocked from downloading. This typically
// happens when a disk write operation fails. If the torrent is
// auto-managed, it will periodically be taken out of this state, in the
// hope that the disk condition (be it disk full or permission errors)
// has been resolved. If the torrent is not auto-managed, you have to
// explicitly take it out of the upload mode by calling set_upload_mode()
// on the torrent_handle.
bool upload_mode;
// true if the torrent is currently in share-mode, i.e. not downloading
// the torrent, but just helping the swarm out.
bool share_mode;
// true if the torrent is in super seeding mode
bool super_seeding;
// set to true if the torrent is paused and false otherwise. It's only
// true if the torrent itself is paused. If the torrent is not running
// because the session is paused, this is still false. To know if a
// torrent is active or not, you need to inspect both
// ``torrent_status::paused`` and ``session::is_paused()``.
bool paused;
// set to true if the torrent is auto managed, i.e. libtorrent is
// responsible for determining whether it should be started or queued.
// For more info see queuing_
bool auto_managed;
// true when the torrent is in sequential download mode. In this mode
// pieces are downloaded in order rather than rarest first.
bool sequential_download;
// true if all pieces have been downloaded.
bool is_seeding;
// true if all pieces that have a priority > 0 are downloaded. There is
// only a distinction between finished and seeding if some pieces or
// files have been set to priority 0, i.e. are not downloaded.
bool is_finished;
// true if this torrent has metadata (either it was started from a
// .torrent file or the metadata has been downloaded). The only scenario
// where this can be false is when the torrent was started torrent-less
// (i.e. with just an info-hash and tracker ip, a magnet link for
// instance).
bool has_metadata;
// true if there has ever been an incoming connection attempt to this
// torrent.
bool has_incoming;
// true if the torrent is in seed_mode. If the torrent was started in
// seed mode, it will leave seed mode once all pieces have been checked
// or as soon as one piece fails the hash check.
bool seed_mode;
// this is true if this torrent's storage is currently being moved from
// one location to another. This may potentially be a long operation
// if a large file ends up being copied from one drive to another.
bool moving_storage;
// true if this torrent is loaded into RAM. A torrent can be started
// and still not loaded into RAM, in case it has not had any peers interested in it
// yet. Torrents are loaded on demand.
bool is_loaded;
// the info-hash for this torrent
sha1_hash info_hash;
};
}
#endif // TORRENT_TORRENT_HANDLE_HPP_INCLUDED

View File

@ -44,19 +44,20 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#include "libtorrent/config.hpp"
#include "libtorrent/entry.hpp"
#include "libtorrent/bdecode.hpp"
#include "libtorrent/peer_id.hpp"
#include "libtorrent/time.hpp"
#include "libtorrent/assert.hpp"
#include "libtorrent/file_storage.hpp"
#include "libtorrent/copy_ptr.hpp"
#include "libtorrent/socket.hpp"
#include "libtorrent/torrent_peer.hpp"
#include "libtorrent/sha1_hash.hpp"
#include "libtorrent/file_storage.hpp"
namespace libtorrent
{
class peer_connection;
class entry;
struct announce_entry;
struct lazy_entry;
namespace aux { struct session_settings; }
@ -66,158 +67,6 @@ namespace libtorrent
TORRENT_EXTRA_EXPORT bool verify_encoding(std::string& target
, bool fix_paths = false);
enum
{
// wait at least 5 seconds before retrying a failed tracker
tracker_retry_delay_min = 5
// when tracker_failed_max trackers
// has failed, wait 60 minutes instead
, tracker_retry_delay_max = 60 * 60
};
// this class holds information about one bittorrent tracker, as it
// relates to a specific torrent.
struct TORRENT_EXPORT announce_entry
{
// constructs a tracker announce entry with ``u`` as the URL.
announce_entry(std::string const& u);
announce_entry();
~announce_entry();
#if __cplusplus >= 201103L
announce_entry(announce_entry const&) = default;
announce_entry& operator=(announce_entry const&) = default;
#endif
// tracker URL as it appeared in the torrent file
std::string url;
// the current ``&trackerid=`` argument passed to the tracker.
// this is optional and is normally empty (in which case no
// trackerid is sent).
std::string trackerid;
// if this tracker has returned an error or warning message
// that message is stored here
std::string message;
// if this tracker failed the last time it was contacted
// this error code specifies what error occurred
error_code last_error;
// returns the number of seconds to the next announce on this tracker.
// ``min_announce_in()`` returns the number of seconds until we are
// allowed to force another tracker update with this tracker.
//
// If the last time this tracker was contacted failed, ``last_error`` is
// the error code describing what error occurred.
int next_announce_in() const;
int min_announce_in() const;
// the time of next tracker announce
time_point next_announce;
// no announces before this time
time_point min_announce;
// TODO: include the number of peers received from this tracker, at last
// announce
// these are either -1 or the scrape information this tracker last
// responded with. *incomplete* is the current number of downloaders in
// the swarm, *complete* is the current number of seeds in the swarm and
// *downloaded* is the cumulative number of completed downloads of this
// torrent, since the beginning of time (from this tracker's point of
// view).
// if this tracker has returned scrape data, these fields are filled in
// with valid numbers. Otherwise they are set to -1. the number of
// current downloaders
int scrape_incomplete;
int scrape_complete;
int scrape_downloaded;
// the tier this tracker belongs to
boost::uint8_t tier;
// the max number of failures to announce to this tracker in
// a row, before this tracker is not used anymore. 0 means unlimited
boost::uint8_t fail_limit;
// the number of times in a row we have failed to announce to this
// tracker.
boost::uint8_t fails:7;
// true while we're waiting for a response from the tracker.
bool updating:1;
// flags for the source bitmask, each indicating where
// we heard about this tracker
enum tracker_source
{
// the tracker was part of the .torrent file
source_torrent = 1,
// the tracker was added programatically via the add_troacker()_ function
source_client = 2,
// the tracker was part of a magnet link
source_magnet_link = 4,
// the tracker was received from the swarm via tracker exchange
source_tex = 8
};
// a bitmask specifying which sources we got this tracker from.
boost::uint8_t source:4;
// set to true the first time we receive a valid response
// from this tracker.
bool verified:1;
// set to true when we get a valid response from an announce
// with event=started. If it is set, we won't send start in the subsequent
// announces.
bool start_sent:1;
// set to true when we send a event=completed.
bool complete_sent:1;
// this is false the stats sent to this tracker will be 0
bool send_stats:1;
// reset announce counters and clears the started sent flag.
// The announce_entry will look like we've never talked to
// the tracker.
void reset();
// updates the failure counter and time-outs for re-trying.
// This is called when the tracker announce fails.
void failed(aux::session_settings const& sett, int retry_interval = 0);
#ifndef TORRENT_NO_DEPRECATE
// deprecated in 1.0
TORRENT_DEPRECATED
bool will_announce(time_point now) const
{
return now <= next_announce
&& (fails < fail_limit || fail_limit == 0)
&& !updating;
}
#endif
// returns true if we can announec to this tracker now.
// The current time is passed in as ``now``. The ``is_seed``
// argument is necessary because once we become a seed, we
// need to announce right away, even if the re-announce timer
// hasn't expired yet.
bool can_announce(time_point now, bool is_seed) const;
// returns true if the last time we tried to announce to this
// tracker succeeded, or if we haven't tried yet.
bool is_working() const
{ return fails == 0; }
// trims whitespace characters from the beginning of the URL.
void trim();
};
// the web_seed_entry holds information about a web seed (also known
// as URL seed or HTTP seed). It is essentially a URL with some state
// associated with it. For more information, see `BEP 17`_ and `BEP 19`_.
@ -431,7 +280,7 @@ namespace libtorrent
// ``web_seeds()`` returns all url seeds and http seeds in the torrent.
// Each entry is a ``web_seed_entry`` and may refer to either a url seed
// or http seed.
//
//
// ``add_url_seed()`` and ``add_http_seed()`` adds one url to the list of
// url/http seeds. Currently, the only transport protocol supported for
// the url is http.
@ -446,7 +295,7 @@ namespace libtorrent
// seed.
//
// See http-seeding_ for more information.
void add_url_seed(std::string const& url
void add_url_seed(std::string const& url
, std::string const& extern_auth = std::string()
, web_seed_entry::headers_t const& extra_headers = web_seed_entry::headers_t());
void add_http_seed(std::string const& url
@ -568,8 +417,7 @@ namespace libtorrent
// ``hash_for_piece_ptr()`` returns a pointer to the 20 byte sha1 digest
// for the piece. Note that the string is not null-terminated.
int piece_size(int index) const { return m_files.piece_size(index); }
sha1_hash hash_for_piece(int index) const
{ return sha1_hash(hash_for_piece_ptr(index)); }
sha1_hash hash_for_piece(int index) const;
char const* hash_for_piece_ptr(int index) const
{
TORRENT_ASSERT(index >= 0);
@ -629,7 +477,7 @@ namespace libtorrent
// dht nodes to add to the routing table/bootstrap from
typedef std::vector<std::pair<std::string, int> > nodes_t;
// If this torrent contains any DHT nodes, they are put in this vector in
// their original form (host name and port number).
nodes_t const& nodes() const
@ -639,7 +487,7 @@ namespace libtorrent
// It may be used, by the client, to bootstrap into the DHT network.
void add_node(std::pair<std::string, int> const& node)
{ m_nodes.push_back(node); }
// populates the torrent_info by providing just the info-dict buffer.
// This is used when loading a torrent from a magnet link for instance,
// where we only have the info-dict. The bdecode_node ``e`` points to a
@ -651,17 +499,7 @@ namespace libtorrent
// This function looks up keys from the info-dictionary of the loaded
// torrent file. It can be used to access extension values put in the
// .torrent file. If the specified key cannot be found, it returns NULL.
bdecode_node info(char const* key) const
{
if (m_info_dict.type() == bdecode_node::none_t)
{
error_code ec;
bdecode(m_info_section.get(), m_info_section.get()
+ m_info_section_size, m_info_dict, ec);
if (ec) return bdecode_node();
}
return m_info_dict.dict_find(key);
}
bdecode_node info(char const* key) const;
// swap the content of this and ``ti```.
void swap(torrent_info& ti);
@ -783,7 +621,7 @@ namespace libtorrent
// or not. e.g. test/test there's one file and one directory
// and they have the same name.
bool m_multifile:1;
// this is true if the torrent is private. i.e., is should not
// be announced on the dht
bool m_private:1;

View File

@ -0,0 +1,483 @@
/*
Copyright (c) 2015, Arvid Norberg
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_STATUS_HPP_INCLUDED
#define TORRENT_TORRENT_STATUS_HPP_INCLUDED
#include "libtorrent/config.hpp"
#include "libtorrent/torrent_handle.hpp"
#include "libtorrent/bitfield.hpp"
#include "libtorrent/sha1_hash.hpp"
#include "libtorrent/time.hpp" // for time_duration
#include "libtorrent/storage_defs.hpp" // for storage_mode_t
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <boost/cstdint.hpp>
#include <string>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
namespace libtorrent
{
// holds a snapshot of the status of a torrent, as queried by
// torrent_handle::status().
struct TORRENT_EXPORT torrent_status
{
// hidden
torrent_status();
~torrent_status();
#if __cplusplus >= 201103L
torrent_status(torrent_status const&) = default;
torrent_status& operator=(torrent_status const&) = default;
#endif
// compres if the torrent status objects come from the same torrent. i.e.
// only the torrent_handle field is compared.
bool operator==(torrent_status const& st) const
{ return handle == st.handle; }
// a handle to the torrent whose status the object represents.
torrent_handle handle;
// the different overall states a torrent can be in
enum state_t
{
#ifndef TORRENT_NO_DEPRECATE
// The torrent is in the queue for being checked. But there
// currently is another torrent that are being checked.
// This torrent will wait for its turn.
queued_for_checking,
#else
unused_enum_for_backwards_compatibility,
#endif
// The torrent has not started its download yet, and is
// currently checking existing files.
checking_files,
// The torrent is trying to download metadata from peers.
// This assumes the metadata_transfer extension is in use.
downloading_metadata,
// The torrent is being downloaded. This is the state
// most torrents will be in most of the time. The progress
// meter will tell how much of the files that has been
// downloaded.
downloading,
// In this state the torrent has finished downloading but
// still doesn't have the entire torrent. i.e. some pieces
// are filtered and won't get downloaded.
finished,
// In this state the torrent has finished downloading and
// is a pure seeder.
seeding,
// If the torrent was started in full allocation mode, this
// indicates that the (disk) storage for the torrent is
// allocated.
allocating,
// The torrent is currently checking the fastresume data and
// comparing it to the files on disk. This is typically
// completed in a fraction of a second, but if you add a
// large number of torrents at once, they will queue up.
checking_resume_data
};
// may be set to an error message describing why the torrent
// was paused, in case it was paused by an error. If the torrent
// is not paused or if it's paused but not because of an error,
// this string is empty.
std::string error;
// the path to the directory where this torrent's files are stored.
// It's typically the path as was given to async_add_torrent() or
// add_torrent() when this torrent was started. This field is only
// included if the torrent status is queried with
// ``torrent_handle::query_save_path``.
std::string save_path;
// the name of the torrent. Typically this is derived from the
// .torrent file. In case the torrent was started without metadata,
// and hasn't completely received it yet, it returns the name given
// to it when added to the session. See ``session::add_torrent``.
// This field is only included if the torrent status is queried
// with ``torrent_handle::query_name``.
std::string name;
// set to point to the ``torrent_info`` object for this torrent. It's
// only included if the torrent status is queried with
// ``torrent_handle::query_torrent_file``.
boost::weak_ptr<const torrent_info> torrent_file;
// the time until the torrent will announce itself to the tracker.
time_duration next_announce;
#ifndef TORRENT_NO_DEPRECATE
// the time the tracker want us to wait until we announce ourself
// again the next time.
time_duration announce_interval;
#else
// hidden
time_duration deprecated_announce_interval_;
#endif
// the URL of the last working tracker. If no tracker request has
// been successful yet, it's set to an empty string.
std::string current_tracker;
// the number of bytes downloaded and uploaded to all peers, accumulated,
// *this session* only. The session is considered to restart when a
// torrent is paused and restarted again. When a torrent is paused, these
// counters are reset to 0. If you want complete, persistent, stats, see
// ``all_time_upload`` and ``all_time_download``.
boost::int64_t total_download;
boost::int64_t total_upload;
// counts the amount of bytes send and received this session, but only
// the actual payload data (i.e the interesting data), these counters
// ignore any protocol overhead. The session is considered to restart
// when a torrent is paused and restarted again. When a torrent is
// paused, these counters are reset to 0.
boost::int64_t total_payload_download;
boost::int64_t total_payload_upload;
// the number of bytes that has been downloaded and that has failed the
// piece hash test. In other words, this is just how much crap that has
// been downloaded since the torrent was last started. If a torrent is
// paused and then restarted again, this counter will be reset.
boost::int64_t total_failed_bytes;
// the number of bytes that has been downloaded even though that data
// already was downloaded. The reason for this is that in some situations
// the same data can be downloaded by mistake. When libtorrent sends
// requests to a peer, and the peer doesn't send a response within a
// certain timeout, libtorrent will re-request that block. Another
// situation when libtorrent may re-request blocks is when the requests
// it sends out are not replied in FIFO-order (it will re-request blocks
// that are skipped by an out of order block). This is supposed to be as
// low as possible. This only counts bytes since the torrent was last
// started. If a torrent is paused and then restarted again, this counter
// will be reset.
boost::int64_t total_redundant_bytes;
// a bitmask that represents which pieces we have (set to true) and the
// pieces we don't have. It's a pointer and may be set to 0 if the
// torrent isn't downloading or seeding.
bitfield pieces;
// a bitmask representing which pieces has had their hash checked. This
// only applies to torrents in *seed mode*. If the torrent is not in seed
// mode, this bitmask may be empty.
bitfield verified_pieces;
// the total number of bytes of the file(s) that we have. All this does
// not necessarily has to be downloaded during this session (that's
// ``total_payload_download``).
boost::int64_t total_done;
// the number of bytes we have downloaded, only counting the pieces that
// we actually want to download. i.e. excluding any pieces that we have
// but have priority 0 (i.e. not wanted).
boost::int64_t total_wanted_done;
// The total number of bytes we want to download. This may be smaller
// than the total torrent size in case any pieces are prioritized to 0,
// i.e. not wanted
boost::int64_t total_wanted;
// are accumulated upload and download payload byte counters. They are
// saved in and restored from resume data to keep totals across sessions.
boost::int64_t all_time_upload;
boost::int64_t all_time_download;
// the posix-time when this torrent was added. i.e. what ``time(NULL)``
// returned at the time.
time_t added_time;
// the posix-time when this torrent was finished. If the torrent is not
// yet finished, this is 0.
time_t completed_time;
// the time when we, or one of our peers, last saw a complete copy of
// this torrent.
time_t last_seen_complete;
// The allocation mode for the torrent. See storage_mode_t for the
// options. For more information, see storage-allocation_.
storage_mode_t storage_mode;
// a value in the range [0, 1], that represents the progress of the
// torrent's current task. It may be checking files or downloading.
float progress;
// progress parts per million (progress * 1000000) when disabling
// floating point operations, this is the only option to query progress
//
// reflects the same value as ``progress``, but instead in a range [0,
// 1000000] (ppm = parts per million). When floating point operations are
// disabled, this is the only alternative to the floating point value in
// progress.
int progress_ppm;
// the position this torrent has in the download
// queue. If the torrent is a seed or finished, this is -1.
int queue_position;
// the total rates for all peers for this torrent. These will usually
// have better precision than summing the rates from all peers. The rates
// are given as the number of bytes per second.
int download_rate;
int upload_rate;
// the total transfer rate of payload only, not counting protocol
// chatter. This might be slightly smaller than the other rates, but if
// projected over a long time (e.g. when calculating ETA:s) the
// difference may be noticeable.
int download_payload_rate;
int upload_payload_rate;
// the number of peers that are seeding that this client is
// currently connected to.
int num_seeds;
// the number of peers this torrent currently is connected to. Peer
// connections that are in the half-open state (is attempting to connect)
// or are queued for later connection attempt do not count. Although they
// are visible in the peer list when you call get_peer_info().
int num_peers;
// if the tracker sends scrape info in its announce reply, these fields
// will be set to the total number of peers that have the whole file and
// the total number of peers that are still downloading. set to -1 if the
// tracker did not send any scrape data in its announce reply.
int num_complete;
int num_incomplete;
// the number of seeds in our peer list and the total number of peers
// (including seeds). We are not necessarily connected to all the peers
// in our peer list. This is the number of peers we know of in total,
// including banned peers and peers that we have failed to connect to.
int list_seeds;
int list_peers;
// the number of peers in this torrent's peer list that is a candidate to
// be connected to. i.e. It has fewer connect attempts than the max fail
// count, it is not a seed if we are a seed, it is not banned etc. If
// this is 0, it means we don't know of any more peers that we can try.
int connect_candidates;
// the number of pieces that has been downloaded. It is equivalent to:
// ``std::accumulate(pieces->begin(), pieces->end())``. So you don't have
// to count yourself. This can be used to see if anything has updated
// since last time if you want to keep a graph of the pieces up to date.
int num_pieces;
// the number of distributed copies of the torrent. Note that one copy
// may be spread out among many peers. It tells how many copies there are
// currently of the rarest piece(s) among the peers this client is
// connected to.
int distributed_full_copies;
// tells the share of pieces that have more copies than the rarest
// piece(s). Divide this number by 1000 to get the fraction.
//
// For example, if ``distributed_full_copies`` is 2 and
// ``distrbuted_fraction`` is 500, it means that the rarest pieces have
// only 2 copies among the peers this torrent is connected to, and that
// 50% of all the pieces have more than two copies.
//
// If we are a seed, the piece picker is deallocated as an optimization,
// and piece availability is no longer tracked. In this case the
// distributed copies members are set to -1.
int distributed_fraction;
// the number of distributed copies of the file. note that one copy may
// be spread out among many peers. This is a floating point
// representation of the distributed copies.
//
// the integer part tells how many copies
// there are of the rarest piece(s)
//
// the fractional part tells the fraction of pieces that
// have more copies than the rarest piece(s).
float distributed_copies;
// the size of a block, in bytes. A block is a sub piece, it is the
// number of bytes that each piece request asks for and the number of
// bytes that each bit in the ``partial_piece_info``'s bitset represents,
// see get_download_queue(). This is typically 16 kB, but it may be
// larger if the pieces are larger.
int block_size;
// the number of unchoked peers in this torrent.
int num_uploads;
// the number of peer connections this torrent has, including half-open
// connections that hasn't completed the bittorrent handshake yet. This
// is always >= ``num_peers``.
int num_connections;
// the set limit of upload slots (unchoked peers) for this torrent.
int uploads_limit;
// the set limit of number of connections for this torrent.
int connections_limit;
// the number of peers in this torrent that are waiting for more
// bandwidth quota from the torrent rate limiter. This can determine if
// the rate you get from this torrent is bound by the torrents limit or
// not. If there is no limit set on this torrent, the peers might still
// be waiting for bandwidth quota from the global limiter, but then they
// are counted in the ``session_status`` object.
int up_bandwidth_queue;
int down_bandwidth_queue;
// the number of seconds since any peer last uploaded from this torrent
// and the last time a downloaded piece passed the hash check,
// respectively.
int time_since_upload;
int time_since_download;
// These keep track of the number of seconds this torrent has been active
// (not paused) and the number of seconds it has been active while being
// finished and active while being a seed. ``seeding_time`` should be <=
// ``finished_time`` which should be <= ``active_time``. They are all
// saved in and restored from resume data, to keep totals across
// sessions.
int active_time;
int finished_time;
int seeding_time;
// A rank of how important it is to seed the torrent, it is used to
// determine which torrents to seed and which to queue. It is based on
// the peer to seed ratio from the tracker scrape. For more information,
// see queuing_. Higher value means more important to seed
int seed_rank;
// the number of seconds since this torrent acquired scrape data.
// If it has never done that, this value is -1.
int last_scrape;
// the priority of this torrent
int priority;
// the main state the torrent is in. See torrent_status::state_t.
state_t state;
// true if this torrent has unsaved changes
// to its download state and statistics since the last resume data
// was saved.
bool need_save_resume;
// true if the session global IP filter applies
// to this torrent. This defaults to true.
bool ip_filter_applies;
// true if the torrent is blocked from downloading. This typically
// happens when a disk write operation fails. If the torrent is
// auto-managed, it will periodically be taken out of this state, in the
// hope that the disk condition (be it disk full or permission errors)
// has been resolved. If the torrent is not auto-managed, you have to
// explicitly take it out of the upload mode by calling set_upload_mode()
// on the torrent_handle.
bool upload_mode;
// true if the torrent is currently in share-mode, i.e. not downloading
// the torrent, but just helping the swarm out.
bool share_mode;
// true if the torrent is in super seeding mode
bool super_seeding;
// set to true if the torrent is paused and false otherwise. It's only
// true if the torrent itself is paused. If the torrent is not running
// because the session is paused, this is still false. To know if a
// torrent is active or not, you need to inspect both
// ``torrent_status::paused`` and ``session::is_paused()``.
bool paused;
// set to true if the torrent is auto managed, i.e. libtorrent is
// responsible for determining whether it should be started or queued.
// For more info see queuing_
bool auto_managed;
// true when the torrent is in sequential download mode. In this mode
// pieces are downloaded in order rather than rarest first.
bool sequential_download;
// true if all pieces have been downloaded.
bool is_seeding;
// true if all pieces that have a priority > 0 are downloaded. There is
// only a distinction between finished and seeding if some pieces or
// files have been set to priority 0, i.e. are not downloaded.
bool is_finished;
// true if this torrent has metadata (either it was started from a
// .torrent file or the metadata has been downloaded). The only scenario
// where this can be false is when the torrent was started torrent-less
// (i.e. with just an info-hash and tracker ip, a magnet link for
// instance).
bool has_metadata;
// true if there has ever been an incoming connection attempt to this
// torrent.
bool has_incoming;
// true if the torrent is in seed_mode. If the torrent was started in
// seed mode, it will leave seed mode once all pieces have been checked
// or as soon as one piece fails the hash check.
bool seed_mode;
// this is true if this torrent's storage is currently being moved from
// one location to another. This may potentially be a long operation
// if a large file ends up being copied from one drive to another.
bool moving_storage;
// true if this torrent is loaded into RAM. A torrent can be started
// and still not loaded into RAM, in case it has not had any peers interested in it
// yet. Torrents are loaded on demand.
bool is_loaded;
// the info-hash for this torrent
sha1_hash info_hash;
};
}
#endif

View File

@ -36,6 +36,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/torrent_handle.hpp"
#include "libtorrent/add_torrent_params.hpp"
#include "libtorrent/time.hpp"
#include "libtorrent/torrent_status.hpp"
#include "setup_swarm.hpp"
#include "settings.hpp"
#include "setup_transfer.hpp" // for create_torrent

View File

@ -37,6 +37,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/session.hpp"
#include "libtorrent/hasher.hpp"
#include "libtorrent/alert_types.hpp"
#include "libtorrent/torrent_info.hpp"
#include "libtorrent/thread.hpp"
#include "libtorrent/extensions/metadata_transfer.hpp"
#include "libtorrent/extensions/ut_metadata.hpp"

View File

@ -33,6 +33,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "setup_swarm.hpp"
#include "swarm_config.hpp"
#include "libtorrent/alert.hpp"
#include "libtorrent/announce_entry.hpp"
#include "libtorrent/extensions/lt_trackers.hpp"
#include "test.hpp"

View File

@ -35,6 +35,7 @@ libtorrent_rasterbar_la_SOURCES = \
alert.cpp \
alert_manager.cpp \
allocator.cpp \
announce_entry.cpp \
assert.cpp \
bandwidth_limit.cpp \
bandwidth_manager.cpp \

132
src/announce_entry.cpp Normal file
View File

@ -0,0 +1,132 @@
/*
Copyright (c) 2015, Arvid Norberg
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.
*/
#include "libtorrent/config.hpp"
#include "libtorrent/announce_entry.hpp"
#include "libtorrent/aux_/time.hpp"
#include "libtorrent/aux_/session_settings.hpp"
namespace libtorrent
{
enum
{
// wait at least 5 seconds before retrying a failed tracker
tracker_retry_delay_min = 5
// when tracker_failed_max trackers
// has failed, wait 60 minutes instead
, tracker_retry_delay_max = 60 * 60
};
announce_entry::announce_entry(std::string const& u)
: url(u)
, next_announce(min_time())
, min_announce(min_time())
, scrape_incomplete(-1)
, scrape_complete(-1)
, scrape_downloaded(-1)
, tier(0)
, fail_limit(0)
, fails(0)
, updating(false)
, source(0)
, verified(false)
, start_sent(false)
, complete_sent(false)
, send_stats(true)
{}
announce_entry::announce_entry()
: next_announce(min_time())
, min_announce(min_time())
, scrape_incomplete(-1)
, scrape_complete(-1)
, scrape_downloaded(-1)
, tier(0)
, fail_limit(0)
, fails(0)
, updating(false)
, source(0)
, verified(false)
, start_sent(false)
, complete_sent(false)
, send_stats(true)
{}
announce_entry::~announce_entry() {}
int announce_entry::next_announce_in() const
{ return total_seconds(next_announce - aux::time_now()); }
int announce_entry::min_announce_in() const
{ return total_seconds(min_announce - aux::time_now()); }
void announce_entry::reset()
{
start_sent = false;
next_announce = min_time();
min_announce = min_time();
}
void announce_entry::failed(aux::session_settings const& sett, int retry_interval)
{
++fails;
// the exponential back-off ends up being:
// 7, 15, 27, 45, 95, 127, 165, ... seconds
// with the default tracker_backoff of 250
int delay = (std::min)(tracker_retry_delay_min + int(fails) * int(fails)
* tracker_retry_delay_min * sett.get_int(settings_pack::tracker_backoff) / 100
, int(tracker_retry_delay_max));
delay = (std::max)(delay, retry_interval);
next_announce = aux::time_now() + seconds(delay);
updating = false;
}
bool announce_entry::can_announce(time_point now, bool is_seed) const
{
// if we're a seed and we haven't sent a completed
// event, we need to let this announce through
bool need_send_complete = is_seed && !complete_sent;
return now >= next_announce
&& (now >= min_announce || need_send_complete)
&& (fails < fail_limit || fail_limit == 0)
&& !updating;
}
void announce_entry::trim()
{
while (!url.empty() && is_space(url[0]))
url.erase(url.begin());
}
}

View File

@ -37,6 +37,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/disk_io_thread.hpp"
#include "libtorrent/aux_/merkle.hpp" // for merkle_*()
#include "libtorrent/torrent_info.hpp"
#include "libtorrent/announce_entry.hpp"
#include "libtorrent/performance_counters.hpp" // for counters
#include "libtorrent/alert_manager.hpp"

View File

@ -39,6 +39,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/error_code.hpp"
#include "libtorrent/error.hpp"
#include "libtorrent/file_pool.hpp"
#include "libtorrent/torrent_info.hpp"
#include <boost/scoped_array.hpp>
#include <boost/bind.hpp>
#include <boost/tuple/tuple.hpp>

View File

@ -43,7 +43,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/session_status.hpp"
#include "libtorrent/kademlia/node_id.hpp"
#include "libtorrent/kademlia/dht_observer.hpp"
#include "libtorrent/time.hpp"
#include "libtorrent/aux_/time.hpp"
#include "libtorrent/alert_types.hpp" // for dht_routing_bucket
#include "libtorrent/socket_io.hpp" // for print_endpoint
#include "libtorrent/invariant_check.hpp"

View File

@ -40,6 +40,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <libtorrent/session_status.hpp>
#include <libtorrent/socket_io.hpp> // for read_*_endpoint
#include <libtorrent/alert_types.hpp> // for dht_lookup
#include <libtorrent/aux_/time.hpp>
#include <boost/bind.hpp>

View File

@ -56,6 +56,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/io.hpp"
#include "libtorrent/parse_url.hpp"
#include "libtorrent/torrent_handle.hpp"
#include "libtorrent/announce_entry.hpp"
namespace libtorrent { namespace
{

View File

@ -35,6 +35,9 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/torrent_handle.hpp"
#include "libtorrent/aux_/escape_string.hpp"
#include "libtorrent/error_code.hpp"
#include "libtorrent/torrent_status.hpp"
#include "libtorrent/torrent_info.hpp"
#include "libtorrent/announce_entry.hpp"
#include <string>

View File

@ -62,6 +62,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#include "libtorrent/torrent_handle.hpp"
#include "libtorrent/announce_entry.hpp"
#include "libtorrent/torrent_info.hpp"
#include "libtorrent/tracker_manager.hpp"
#include "libtorrent/parse_url.hpp"
@ -1309,6 +1310,15 @@ namespace libtorrent
}
}
storage_mode_t torrent::storage_mode() const
{ return storage_mode_t(m_storage_mode); }
storage_interface* torrent::get_storage()
{
if (!m_storage) return 0;
return m_storage->get_storage_impl();
}
void torrent::need_picker()
{
if (m_picker) return;

View File

@ -57,6 +57,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/invariant_check.hpp"
#include "libtorrent/utf8.hpp"
#include "libtorrent/thread.hpp"
#include "libtorrent/announce_entry.hpp"
#ifdef __GNUC__
#pragma GCC diagnostic push

View File

@ -44,8 +44,10 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/aux_/session_settings.hpp"
#include "libtorrent/aux_/escape_string.hpp" // maybe_url_encode
#include "libtorrent/aux_/merkle.hpp" // for merkle_*
#include "libtorrent/aux_/time.hpp"
#include "libtorrent/add_torrent_params.hpp"
#include "libtorrent/magnet_uri.hpp"
#include "libtorrent/announce_entry.hpp"
#ifndef TORRENT_NO_DEPRECATE
#include "libtorrent/lazy_entry.hpp"
@ -599,88 +601,6 @@ namespace libtorrent
} // anonymous namespace
announce_entry::announce_entry(std::string const& u)
: url(u)
, next_announce(min_time())
, min_announce(min_time())
, scrape_incomplete(-1)
, scrape_complete(-1)
, scrape_downloaded(-1)
, tier(0)
, fail_limit(0)
, fails(0)
, updating(false)
, source(0)
, verified(false)
, start_sent(false)
, complete_sent(false)
, send_stats(true)
{}
announce_entry::announce_entry()
: next_announce(min_time())
, min_announce(min_time())
, scrape_incomplete(-1)
, scrape_complete(-1)
, scrape_downloaded(-1)
, tier(0)
, fail_limit(0)
, fails(0)
, updating(false)
, source(0)
, verified(false)
, start_sent(false)
, complete_sent(false)
, send_stats(true)
{}
announce_entry::~announce_entry() {}
int announce_entry::next_announce_in() const
{ return total_seconds(next_announce - aux::time_now()); }
int announce_entry::min_announce_in() const
{ return total_seconds(min_announce - aux::time_now()); }
void announce_entry::reset()
{
start_sent = false;
next_announce = min_time();
min_announce = min_time();
}
void announce_entry::failed(aux::session_settings const& sett, int retry_interval)
{
++fails;
// the exponential back-off ends up being:
// 7, 15, 27, 45, 95, 127, 165, ... seconds
// with the default tracker_backoff of 250
int delay = (std::min)(tracker_retry_delay_min + int(fails) * int(fails)
* tracker_retry_delay_min * sett.get_int(settings_pack::tracker_backoff) / 100
, int(tracker_retry_delay_max));
delay = (std::max)(delay, retry_interval);
next_announce = aux::time_now() + seconds(delay);
updating = false;
}
bool announce_entry::can_announce(time_point now, bool is_seed) const
{
// if we're a seed and we haven't sent a completed
// event, we need to let this announce through
bool need_send_complete = is_seed && !complete_sent;
return now >= next_announce
&& (now >= min_announce || need_send_complete)
&& (fails < fail_limit || fail_limit == 0)
&& !updating;
}
void announce_entry::trim()
{
while (!url.empty() && is_space(url[0]))
url.erase(url.begin());
}
web_seed_entry::web_seed_entry(std::string const& url_, type_t type_
, std::string const& auth_
, headers_t const& extra_headers_)
@ -1157,6 +1077,9 @@ namespace libtorrent
TORRENT_ASSERT(!is_loaded());
}
sha1_hash torrent_info::hash_for_piece(int index) const
{ return sha1_hash(hash_for_piece_ptr(index)); }
void torrent_info::copy_on_write()
{
TORRENT_ASSERT(is_loaded());
@ -1379,6 +1302,19 @@ namespace libtorrent
return true;
}
bdecode_node torrent_info::info(char const* key) const
{
if (m_info_dict.type() == bdecode_node::none_t)
{
error_code ec;
bdecode(m_info_section.get(), m_info_section.get()
+ m_info_section_size, m_info_dict, ec);
if (ec) return bdecode_node();
}
return m_info_dict.dict_find(key);
}
bool torrent_info::add_merkle_nodes(std::map<int, sha1_hash> const& subtree
, int piece)
{

View File

@ -48,6 +48,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/session_stats.hpp"
#include "libtorrent/thread.hpp"
#include "libtorrent/random.hpp"
#include "libtorrent/torrent_info.hpp"
#include <boost/tuple/tuple.hpp>
#include <boost/bind.hpp>

View File

@ -35,6 +35,9 @@ POSSIBILITY OF SUCH DAMAGE.
#include "setup_transfer.hpp"
#include "libtorrent/create_torrent.hpp"
#include <sys/stat.h> // for chmod
#include "libtorrent/torrent_info.hpp"
#include "libtorrent/torrent_status.hpp"
static const int file_sizes[] =
{ 5, 16 - 5, 16000, 17, 10, 8000, 8000, 1,1,1,1,1,100,1,1,1,1,100,1,1,1,1,1,1
,1,1,1,1,1,1,13,65000,34,75,2,30,400,500,23000,900,43000,400,4300,6, 4};

View File

@ -42,6 +42,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/bdecode.hpp"
#include "libtorrent/bencode.hpp"
#include "libtorrent/entry.hpp"
#include "libtorrent/torrent_info.hpp"
#include "libtorrent/aux_/disable_warnings_push.hpp"

View File

@ -35,6 +35,8 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/session.hpp"
#include "libtorrent/torrent_handle.hpp"
#include "libtorrent/bencode.hpp"
#include "libtorrent/torrent_info.hpp" // for announce_entry
#include "libtorrent/announce_entry.hpp"
using namespace libtorrent;
namespace lt = libtorrent;

View File

@ -40,6 +40,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/extensions/ut_pex.hpp"
#include "libtorrent/thread.hpp"
#include "libtorrent/ip_filter.hpp"
#include "libtorrent/torrent_status.hpp"
#include <boost/tuple/tuple.hpp>
#include "setup_transfer.hpp"

View File

@ -33,6 +33,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/entry.hpp"
#include "libtorrent/broadcast_socket.hpp"
#include "libtorrent/socket_io.hpp" // for print_endpoint
#include "libtorrent/announce_entry.hpp"
#include "test.hpp"
#include "setup_transfer.hpp"

View File

@ -38,6 +38,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/thread.hpp"
#include "libtorrent/time.hpp"
#include "libtorrent/file.hpp"
#include "libtorrent/torrent_info.hpp"
#include <boost/tuple/tuple.hpp>
#include <boost/bind.hpp>

View File

@ -40,6 +40,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/alert.hpp"
#include "libtorrent/random.hpp"
#include "libtorrent/alert_types.hpp"
#include "libtorrent/torrent_info.hpp"
#include <fstream>

View File

@ -35,6 +35,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "setup_transfer.hpp"
#include "libtorrent/create_torrent.hpp"
#include "libtorrent/alert_types.hpp"
#include "libtorrent/torrent_info.hpp"
enum flags_t
{

View File

@ -33,6 +33,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/session.hpp"
#include "libtorrent/alert_types.hpp"
#include "libtorrent/create_torrent.hpp"
#include "libtorrent/torrent_info.hpp"
#include "setup_transfer.hpp"
#include "test.hpp"

View File

@ -35,6 +35,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/thread.hpp"
#include "libtorrent/file.hpp"
#include "libtorrent/session_status.hpp"
#include "libtorrent/torrent_info.hpp"
#include <boost/bind.hpp>
#include <boost/tuple/tuple.hpp>

View File

@ -42,6 +42,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/aux_/session_impl.hpp"
#include "libtorrent/create_torrent.hpp"
#include "libtorrent/thread.hpp"
#include "libtorrent/torrent_info.hpp"
#include <boost/make_shared.hpp>
#include <boost/utility.hpp>

View File

@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/file_storage.hpp"
#include "libtorrent/torrent_info.hpp"
#include "libtorrent/create_torrent.hpp"
#include "libtorrent/announce_entry.hpp"
#include "libtorrent/aux_/escape_string.hpp" // for convert_path_to_posix
#include <boost/make_shared.hpp>

View File

@ -42,6 +42,8 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/error_code.hpp"
#include "libtorrent/tracker_manager.hpp"
#include "libtorrent/http_tracker_connection.hpp" // for parse_tracker_response
#include "libtorrent/torrent_info.hpp"
#include "libtorrent/announce_entry.hpp"
#include <fstream>

View File

@ -38,6 +38,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/thread.hpp"
#include "libtorrent/time.hpp"
#include "libtorrent/file.hpp"
#include "libtorrent/torrent_info.hpp"
#include "test.hpp"
#include "setup_transfer.hpp"

View File

@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "setup_transfer.hpp"
#include "web_seed_suite.hpp"
#include "libtorrent/create_torrent.hpp"
#include "libtorrent/torrent_info.hpp"
using namespace libtorrent;

View File

@ -39,6 +39,8 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/create_torrent.hpp"
#include "libtorrent/thread.hpp"
#include "libtorrent/alert_types.hpp"
#include "libtorrent/torrent_info.hpp"
#include "libtorrent/announce_entry.hpp"
#include "test.hpp"
#include "setup_transfer.hpp"