2003-10-23 01:00:57 +02:00
|
|
|
/*
|
|
|
|
|
2015-06-03 07:18:48 +02:00
|
|
|
Copyright (c) 2003-2015, Arvid Norberg
|
2003-10-23 01:00:57 +02: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.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2008-05-28 10:44:40 +02:00
|
|
|
#ifndef TORRENT_TORRENT_INFO_HPP_INCLUDED
|
|
|
|
#define TORRENT_TORRENT_INFO_HPP_INCLUDED
|
2003-10-23 01:00:57 +02:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2004-01-25 19:18:36 +01:00
|
|
|
|
2015-04-21 03:16:28 +02:00
|
|
|
#include "libtorrent/aux_/disable_warnings_push.hpp"
|
2004-01-25 19:18:36 +01:00
|
|
|
|
2004-03-05 13:04:47 +01:00
|
|
|
#include <boost/optional.hpp>
|
2008-05-14 07:29:42 +02:00
|
|
|
#include <boost/shared_array.hpp>
|
2003-10-23 01:00:57 +02:00
|
|
|
|
2015-04-21 03:16:28 +02:00
|
|
|
#include "libtorrent/aux_/disable_warnings_pop.hpp"
|
2004-01-25 19:18:36 +01:00
|
|
|
|
2009-11-23 09:38:50 +01:00
|
|
|
#include "libtorrent/config.hpp"
|
2003-10-23 01:00:57 +02:00
|
|
|
#include "libtorrent/entry.hpp"
|
2015-03-12 06:20:12 +01:00
|
|
|
#include "libtorrent/bdecode.hpp"
|
2003-10-23 01:00:57 +02:00
|
|
|
#include "libtorrent/peer_id.hpp"
|
2014-07-06 21:18:00 +02:00
|
|
|
#include "libtorrent/time.hpp"
|
2007-09-10 08:12:41 +02:00
|
|
|
#include "libtorrent/assert.hpp"
|
2008-05-28 10:44:40 +02:00
|
|
|
#include "libtorrent/file_storage.hpp"
|
2010-08-22 00:10:16 +02:00
|
|
|
#include "libtorrent/copy_ptr.hpp"
|
2010-10-10 20:43:58 +02:00
|
|
|
#include "libtorrent/socket.hpp"
|
2014-07-06 21:18:00 +02:00
|
|
|
#include "libtorrent/torrent_peer.hpp"
|
2003-11-20 20:58:29 +01:00
|
|
|
|
2003-10-23 01:00:57 +02:00
|
|
|
namespace libtorrent
|
|
|
|
{
|
2010-10-16 17:24:45 +02:00
|
|
|
class peer_connection;
|
2014-07-06 21:18:00 +02:00
|
|
|
|
|
|
|
namespace aux { struct session_settings; }
|
2015-05-16 20:35:47 +02:00
|
|
|
|
|
|
|
// internal, exposed for the unit test
|
2015-02-15 02:04:50 +01:00
|
|
|
TORRENT_EXTRA_EXPORT void sanitize_append_path_element(std::string& path
|
|
|
|
, char const* element, int element_len);
|
2015-05-16 20:35:47 +02:00
|
|
|
TORRENT_EXTRA_EXPORT bool verify_encoding(std::string& target
|
|
|
|
, bool fix_paths = false);
|
2010-10-10 20:43:58 +02:00
|
|
|
|
2008-11-29 09:38:40 +01:00
|
|
|
enum
|
|
|
|
{
|
2012-03-24 16:15:36 +01:00
|
|
|
// wait at least 5 seconds before retrying a failed tracker
|
|
|
|
tracker_retry_delay_min = 5
|
2008-11-29 09:38:40 +01:00
|
|
|
// when tracker_failed_max trackers
|
|
|
|
// has failed, wait 60 minutes instead
|
|
|
|
, tracker_retry_delay_max = 60 * 60
|
|
|
|
};
|
|
|
|
|
2013-07-26 08:11:10 +02:00
|
|
|
// this class holds information about one bittorrent tracker, as it
|
|
|
|
// relates to a specific torrent.
|
2005-11-01 19:30:39 +01:00
|
|
|
struct TORRENT_EXPORT announce_entry
|
2003-10-23 01:00:57 +02:00
|
|
|
{
|
2013-09-01 19:34:05 +02:00
|
|
|
// constructs a tracker announce entry with ``u`` as the URL.
|
2012-03-19 07:06:52 +01:00
|
|
|
announce_entry(std::string const& u);
|
2013-05-03 10:24:26 +02:00
|
|
|
announce_entry();
|
2012-03-19 07:06:52 +01:00
|
|
|
~announce_entry();
|
2015-08-02 21:55:05 +02:00
|
|
|
#if __cplusplus >= 201103L
|
|
|
|
announce_entry(announce_entry const& st) = default;
|
|
|
|
announce_entry& operator=(announce_entry const& st) = default;
|
|
|
|
#endif
|
2008-11-27 21:51:59 +01:00
|
|
|
|
2010-08-22 00:10:16 +02:00
|
|
|
// tracker URL as it appeared in the torrent file
|
2003-10-23 01:00:57 +02:00
|
|
|
std::string url;
|
2013-08-17 09:01:03 +02:00
|
|
|
|
|
|
|
// the current ``&trackerid=`` argument passed to the tracker.
|
|
|
|
// this is optional and is normally empty (in which case no
|
|
|
|
// trackerid is sent).
|
2010-11-18 06:51:52 +01:00
|
|
|
std::string trackerid;
|
2008-11-29 09:38:40 +01:00
|
|
|
|
2010-08-22 00:10:16 +02:00
|
|
|
// 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;
|
|
|
|
|
2014-12-17 03:48:22 +01:00
|
|
|
// returns the number of seconds to the next announce on this tracker.
|
|
|
|
// ``min_announce_in()`` returns the number of seconds until we are
|
2013-07-26 08:11:10 +02:00
|
|
|
// allowed to force another tracker update with this tracker.
|
|
|
|
//
|
2014-12-17 03:48:22 +01:00
|
|
|
// If the last time this tracker was contacted failed, ``last_error`` is
|
|
|
|
// the error code describing what error occurred.
|
2009-12-02 05:05:24 +01:00
|
|
|
int next_announce_in() const;
|
|
|
|
int min_announce_in() const;
|
|
|
|
|
2008-11-29 09:38:40 +01:00
|
|
|
// the time of next tracker announce
|
2015-03-12 05:34:54 +01:00
|
|
|
time_point next_announce;
|
2008-11-29 09:38:40 +01:00
|
|
|
|
2009-12-02 05:05:24 +01:00
|
|
|
// no announces before this time
|
2015-03-12 05:34:54 +01:00
|
|
|
time_point min_announce;
|
2009-12-02 05:05:24 +01:00
|
|
|
|
2014-12-17 03:48:22 +01:00
|
|
|
// TODO: include the number of peers received from this tracker, at last
|
|
|
|
// announce
|
2013-02-04 08:17:31 +01:00
|
|
|
|
2014-12-17 03:48:22 +01:00
|
|
|
// 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).
|
2013-07-26 08:11:10 +02:00
|
|
|
|
2014-12-17 03:48:22 +01:00
|
|
|
// 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
|
2013-02-04 08:17:31 +01:00
|
|
|
int scrape_incomplete;
|
|
|
|
int scrape_complete;
|
|
|
|
int scrape_downloaded;
|
|
|
|
|
2010-08-22 00:10:16 +02:00
|
|
|
// the tier this tracker belongs to
|
2008-11-27 21:51:59 +01:00
|
|
|
boost::uint8_t tier;
|
2010-08-22 00:10:16 +02:00
|
|
|
|
2013-07-26 08:11:10 +02:00
|
|
|
// the max number of failures to announce to this tracker in
|
|
|
|
// a row, before this tracker is not used anymore. 0 means unlimited
|
2008-11-27 21:51:59 +01:00
|
|
|
boost::uint8_t fail_limit;
|
|
|
|
|
2013-07-26 08:11:10 +02:00
|
|
|
// the number of times in a row we have failed to announce to this
|
|
|
|
// tracker.
|
2010-08-22 00:10:16 +02:00
|
|
|
boost::uint8_t fails:7;
|
|
|
|
|
2013-07-26 08:11:10 +02:00
|
|
|
// true while we're waiting for a response from the tracker.
|
2010-08-22 00:10:16 +02:00
|
|
|
bool updating:1;
|
2008-11-27 21:51:59 +01:00
|
|
|
|
2013-07-26 08:11:10 +02:00
|
|
|
// flags for the source bitmask, each indicating where
|
|
|
|
// we heard about this tracker
|
2008-11-29 09:38:40 +01:00
|
|
|
enum tracker_source
|
|
|
|
{
|
2013-07-26 08:11:10 +02:00
|
|
|
// the tracker was part of the .torrent file
|
2008-11-29 09:38:40 +01:00
|
|
|
source_torrent = 1,
|
2013-07-26 08:11:10 +02:00
|
|
|
// the tracker was added programatically via the add_troacker()_ function
|
2008-11-29 09:38:40 +01:00
|
|
|
source_client = 2,
|
2013-07-26 08:11:10 +02:00
|
|
|
// the tracker was part of a magnet link
|
2008-11-29 09:38:40 +01:00
|
|
|
source_magnet_link = 4,
|
2013-07-26 08:11:10 +02:00
|
|
|
// the tracker was received from the swarm via tracker exchange
|
2008-11-29 09:38:40 +01:00
|
|
|
source_tex = 8
|
|
|
|
};
|
2010-08-22 00:10:16 +02:00
|
|
|
|
2013-07-26 08:11:10 +02:00
|
|
|
// a bitmask specifying which sources we got this tracker from.
|
2010-08-22 00:10:16 +02:00
|
|
|
boost::uint8_t source:4;
|
2008-11-29 09:38:40 +01:00
|
|
|
|
2013-07-26 08:11:10 +02:00
|
|
|
// set to true the first time we receive a valid response
|
|
|
|
// from this tracker.
|
2008-11-27 21:51:59 +01:00
|
|
|
bool verified:1;
|
|
|
|
|
2013-07-26 08:11:10 +02:00
|
|
|
// 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.
|
2008-11-29 09:38:40 +01:00
|
|
|
bool start_sent:1;
|
|
|
|
|
2013-07-26 08:11:10 +02:00
|
|
|
// set to true when we send a event=completed.
|
2008-11-29 09:38:40 +01:00
|
|
|
bool complete_sent:1;
|
|
|
|
|
2009-09-25 20:17:59 +02:00
|
|
|
// this is false the stats sent to this tracker will be 0
|
|
|
|
bool send_stats:1;
|
|
|
|
|
2013-09-01 19:34:05 +02:00
|
|
|
// reset announce counters and clears the started sent flag.
|
|
|
|
// The announce_entry will look like we've never talked to
|
|
|
|
// the tracker.
|
2014-07-06 21:18:00 +02:00
|
|
|
void reset();
|
2008-11-29 09:38:40 +01:00
|
|
|
|
2013-09-01 19:34:05 +02:00
|
|
|
// updates the failure counter and time-outs for re-trying.
|
|
|
|
// This is called when the tracker announce fails.
|
2014-07-06 21:18:00 +02:00
|
|
|
void failed(aux::session_settings const& sett, int retry_interval = 0);
|
2008-11-29 09:38:40 +01:00
|
|
|
|
2013-11-28 09:44:31 +01:00
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
|
|
|
// deprecated in 1.0
|
2015-04-17 03:49:49 +02:00
|
|
|
TORRENT_DEPRECATED
|
2015-04-26 03:45:23 +02:00
|
|
|
bool will_announce(time_point now) const
|
2010-04-27 20:22:59 +02:00
|
|
|
{
|
|
|
|
return now <= next_announce
|
|
|
|
&& (fails < fail_limit || fail_limit == 0)
|
|
|
|
&& !updating;
|
|
|
|
}
|
2013-11-28 09:44:31 +01:00
|
|
|
#endif
|
2010-04-27 20:22:59 +02:00
|
|
|
|
2013-09-01 19:34:05 +02:00
|
|
|
// 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.
|
2015-03-12 05:34:54 +01:00
|
|
|
bool can_announce(time_point now, bool is_seed) const;
|
2008-11-29 09:38:40 +01:00
|
|
|
|
2013-09-01 19:34:05 +02:00
|
|
|
// returns true if the last time we tried to announce to this
|
|
|
|
// tracker succeeded, or if we haven't tried yet.
|
2008-11-29 09:38:40 +01:00
|
|
|
bool is_working() const
|
2009-11-26 19:31:27 +01:00
|
|
|
{ return fails == 0; }
|
2009-06-23 03:53:47 +02:00
|
|
|
|
2013-09-01 19:34:05 +02:00
|
|
|
// trims whitespace characters from the beginning of the URL.
|
2009-11-26 19:31:27 +01:00
|
|
|
void trim();
|
2003-10-23 01:00:57 +02:00
|
|
|
};
|
|
|
|
|
2013-09-01 19:34:05 +02:00
|
|
|
// 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`_.
|
2010-10-10 20:43:58 +02:00
|
|
|
struct web_seed_entry
|
|
|
|
{
|
|
|
|
// http seeds are different from url seeds in the
|
|
|
|
// protocol they use. http seeds follows the original
|
|
|
|
// http seed spec. by John Hoffman
|
|
|
|
enum type_t { url_seed, http_seed };
|
|
|
|
|
|
|
|
typedef std::vector<std::pair<std::string, std::string> > headers_t;
|
|
|
|
|
|
|
|
web_seed_entry(std::string const& url_, type_t type_
|
|
|
|
, std::string const& auth_ = std::string()
|
2012-03-24 02:29:31 +01:00
|
|
|
, headers_t const& extra_headers_ = headers_t());
|
2010-10-10 20:43:58 +02:00
|
|
|
|
2013-09-01 19:34:05 +02:00
|
|
|
// URL and type comparison
|
2010-10-10 20:43:58 +02:00
|
|
|
bool operator==(web_seed_entry const& e) const
|
|
|
|
{ return url == e.url && type == e.type; }
|
|
|
|
|
2013-09-01 19:34:05 +02:00
|
|
|
// URL and type less-than comparison
|
2010-10-10 20:43:58 +02:00
|
|
|
bool operator<(web_seed_entry const& e) const
|
|
|
|
{
|
|
|
|
if (url < e.url) return true;
|
|
|
|
if (url > e.url) return false;
|
2015-08-14 05:06:59 +02:00
|
|
|
return type < e.type;
|
2010-10-10 20:43:58 +02:00
|
|
|
}
|
|
|
|
|
2013-07-26 08:11:10 +02:00
|
|
|
// The URL of the web seed
|
2010-10-10 20:43:58 +02:00
|
|
|
std::string url;
|
2013-07-26 08:11:10 +02:00
|
|
|
|
|
|
|
// Optional authentication. If this is set, it's passed
|
|
|
|
// in as HTTP basic auth to the web seed. The format is:
|
|
|
|
// username:password.
|
2010-10-10 20:43:58 +02:00
|
|
|
std::string auth;
|
2013-07-26 08:11:10 +02:00
|
|
|
|
|
|
|
// Any extra HTTP headers that need to be passed to the web seed
|
2010-10-10 20:43:58 +02:00
|
|
|
headers_t extra_headers;
|
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
// The type of web seed (see type_t)
|
|
|
|
boost::uint8_t type;
|
2010-10-10 20:43:58 +02:00
|
|
|
};
|
|
|
|
|
2008-05-28 10:44:40 +02:00
|
|
|
#ifndef BOOST_NO_EXCEPTIONS
|
2009-02-23 02:21:19 +01:00
|
|
|
// for backwards compatibility with 0.14
|
|
|
|
typedef libtorrent_exception invalid_torrent_file;
|
2008-05-28 10:44:40 +02:00
|
|
|
#endif
|
2003-10-23 01:00:57 +02:00
|
|
|
|
2014-12-31 23:05:34 +01:00
|
|
|
// TODO: there may be some opportunities to optimize the size if torrent_info.
|
2014-07-06 21:18:00 +02:00
|
|
|
// specifically to turn some std::string and std::vector into pointers
|
|
|
|
class TORRENT_EXPORT torrent_info
|
2003-10-23 01:00:57 +02:00
|
|
|
{
|
|
|
|
public:
|
2010-11-15 06:10:36 +01:00
|
|
|
|
2014-10-22 09:05:10 +02:00
|
|
|
// The constructor that takes an info-hash will initialize the info-hash
|
|
|
|
// to the given value, but leave all other fields empty. This is used
|
|
|
|
// internally when downloading torrents without the metadata. The
|
|
|
|
// metadata will be created by libtorrent as soon as it has been
|
|
|
|
// downloaded from the swarm.
|
2013-07-26 08:11:10 +02:00
|
|
|
//
|
2015-03-12 06:20:12 +01:00
|
|
|
// The constructor that takes a bdecode_node will create a torrent_info
|
2014-10-22 09:05:10 +02:00
|
|
|
// object from the information found in the given torrent_file. The
|
2015-03-12 06:20:12 +01:00
|
|
|
// bdecode_node represents a tree node in an bencoded file. To load an
|
|
|
|
// ordinary .torrent file into a bdecode_node, use bdecode().
|
2013-07-26 08:11:10 +02:00
|
|
|
//
|
2014-10-22 09:05:10 +02:00
|
|
|
// The version that takes a buffer pointer and a size will decode it as a
|
|
|
|
// .torrent file and initialize the torrent_info object for you.
|
2013-07-26 08:11:10 +02:00
|
|
|
//
|
2014-10-22 09:05:10 +02:00
|
|
|
// The version that takes a filename will simply load the torrent file
|
|
|
|
// and decode it inside the constructor, for convenience. This might not
|
|
|
|
// be the most suitable for applications that want to be able to report
|
|
|
|
// detailed errors on what might go wrong.
|
|
|
|
//
|
|
|
|
// There is an upper limit on the size of the torrent file that will be
|
|
|
|
// loaded by the overload taking a filename. If it's important that even
|
|
|
|
// very large torrent files are loaded, use one of the other overloads.
|
2013-07-26 08:11:10 +02:00
|
|
|
//
|
2014-10-22 09:05:10 +02:00
|
|
|
// The overloads that takes an ``error_code const&`` never throws if an
|
|
|
|
// error occur, they will simply set the error code to describe what went
|
|
|
|
// wrong and not fully initialize the torrent_info object. The overloads
|
|
|
|
// that do not take the extra error_code parameter will always throw if
|
|
|
|
// an error occurs. These overloads are not available when building
|
|
|
|
// without exception support.
|
2013-07-26 08:11:10 +02:00
|
|
|
//
|
|
|
|
// The ``flags`` argument is currently unused.
|
2009-02-23 02:21:19 +01:00
|
|
|
#ifndef BOOST_NO_EXCEPTIONS
|
2015-03-12 06:20:12 +01:00
|
|
|
torrent_info(bdecode_node const& torrent_file, int flags = 0);
|
2010-11-15 06:10:36 +01:00
|
|
|
torrent_info(char const* buffer, int size, int flags = 0);
|
|
|
|
torrent_info(std::string const& filename, int flags = 0);
|
2015-03-12 06:20:12 +01:00
|
|
|
#endif // BOOST_NO_EXCEPTIONS
|
2014-07-06 21:18:00 +02:00
|
|
|
torrent_info(torrent_info const& t);
|
2010-11-15 06:10:36 +01:00
|
|
|
torrent_info(sha1_hash const& info_hash, int flags = 0);
|
2015-03-12 06:20:12 +01:00
|
|
|
torrent_info(bdecode_node const& torrent_file, error_code& ec, int flags = 0);
|
2010-11-15 06:10:36 +01:00
|
|
|
torrent_info(char const* buffer, int size, error_code& ec, int flags = 0);
|
|
|
|
torrent_info(std::string const& filename, error_code& ec, int flags = 0);
|
2013-11-29 06:29:39 +01:00
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
2015-04-17 03:49:49 +02:00
|
|
|
TORRENT_DEPRECATED
|
|
|
|
torrent_info(lazy_entry const& torrent_file, int flags = 0);
|
|
|
|
TORRENT_DEPRECATED
|
2015-03-12 06:20:12 +01:00
|
|
|
torrent_info(lazy_entry const& torrent_file, error_code& ec
|
2015-04-17 03:49:49 +02:00
|
|
|
, int flags = 0);
|
2009-10-26 02:29:39 +01:00
|
|
|
#if TORRENT_USE_WSTRING
|
2014-12-17 03:48:22 +01:00
|
|
|
// all wstring APIs are deprecated since 0.16.11 instead, use the wchar
|
|
|
|
// -> utf8 conversion functions and pass in utf8 strings
|
2015-04-17 03:49:49 +02:00
|
|
|
TORRENT_DEPRECATED
|
2015-03-12 06:20:12 +01:00
|
|
|
torrent_info(std::wstring const& filename, error_code& ec
|
2015-04-17 03:49:49 +02:00
|
|
|
, int flags = 0);
|
2015-07-26 01:40:07 +02:00
|
|
|
TORRENT_DEPRECATED
|
|
|
|
torrent_info(std::wstring const& filename, int flags = 0);
|
2009-10-26 02:29:39 +01:00
|
|
|
#endif // TORRENT_USE_WSTRING
|
2013-11-29 06:29:39 +01:00
|
|
|
#endif // TORRENT_NO_DEPRECATE
|
2009-02-23 02:21:19 +01:00
|
|
|
|
2013-11-19 18:57:16 +01:00
|
|
|
// frees all storage associated with this torrent_info object
|
2004-10-29 15:21:09 +02:00
|
|
|
~torrent_info();
|
2004-03-03 14:47:12 +01:00
|
|
|
|
2014-12-17 03:48:22 +01:00
|
|
|
// The file_storage object contains the information on how to map the
|
|
|
|
// pieces to files. It is separated from the torrent_info object because
|
|
|
|
// when creating torrents a storage object needs to be created without
|
|
|
|
// having a torrent file. When renaming files in a storage, the storage
|
|
|
|
// needs to make its own copy of the file_storage in order to make its
|
|
|
|
// mapping differ from the one in the torrent file.
|
2013-07-26 08:11:10 +02:00
|
|
|
//
|
2014-12-17 03:48:22 +01:00
|
|
|
// ``orig_files()`` returns the original (unmodified) file storage for
|
|
|
|
// this torrent. This is used by the web server connection, which needs
|
|
|
|
// to request files with the original names. Filename may be chaged using
|
|
|
|
// ``torrent_info::rename_file()``.
|
2013-07-26 08:11:10 +02:00
|
|
|
//
|
2014-12-17 03:48:22 +01:00
|
|
|
// For more information on the file_storage object, see the separate
|
|
|
|
// document on how to create torrents.
|
2008-05-28 10:44:40 +02:00
|
|
|
file_storage const& files() const { return m_files; }
|
2014-07-06 21:18:00 +02:00
|
|
|
file_storage const& orig_files() const
|
|
|
|
{
|
|
|
|
TORRENT_ASSERT(is_loaded());
|
|
|
|
return m_orig_files ? *m_orig_files : m_files;
|
|
|
|
}
|
2008-12-24 21:07:34 +01:00
|
|
|
|
2014-12-17 03:48:22 +01:00
|
|
|
// Renames a the file with the specified index to the new name. The new
|
|
|
|
// filename is reflected by the ``file_storage`` returned by ``files()``
|
|
|
|
// but not by the one returned by ``orig_files()``.
|
2013-07-26 08:11:10 +02:00
|
|
|
//
|
2014-12-17 03:48:22 +01:00
|
|
|
// If you want to rename the base name of the torrent (for a multifile
|
|
|
|
// torrent), you can copy the ``file_storage`` (see files() and
|
|
|
|
// orig_files() ), change the name, and then use `remap_files()`_.
|
2013-07-26 08:11:10 +02:00
|
|
|
//
|
2014-12-17 03:48:22 +01:00
|
|
|
// The ``new_filename`` can both be a relative path, in which case the
|
|
|
|
// file name is relative to the ``save_path`` of the torrent. If the
|
|
|
|
// ``new_filename`` is an absolute path (i.e. ``is_complete(new_filename)
|
|
|
|
// == true``), then the file is detached from the ``save_path`` of the
|
|
|
|
// torrent. In this case the file is not moved when move_storage() is
|
|
|
|
// invoked.
|
2008-12-24 21:07:34 +01:00
|
|
|
void rename_file(int index, std::string const& new_filename)
|
|
|
|
{
|
2014-07-06 21:18:00 +02:00
|
|
|
TORRENT_ASSERT(is_loaded());
|
2008-12-24 21:07:34 +01:00
|
|
|
copy_on_write();
|
|
|
|
m_files.rename_file(index, new_filename);
|
|
|
|
}
|
2013-11-29 06:29:39 +01:00
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
2009-10-26 02:29:39 +01:00
|
|
|
#if TORRENT_USE_WSTRING
|
2013-08-02 07:03:22 +02:00
|
|
|
// all wstring APIs are deprecated since 0.16.11
|
|
|
|
// instead, use the wchar -> utf8 conversion functions
|
|
|
|
// and pass in utf8 strings
|
2015-04-17 03:49:49 +02:00
|
|
|
TORRENT_DEPRECATED
|
|
|
|
void rename_file(int index, std::wstring const& new_filename);
|
2009-10-26 02:29:39 +01:00
|
|
|
#endif // TORRENT_USE_WSTRING
|
2013-11-29 06:29:39 +01:00
|
|
|
#endif // TORRENT_NO_DEPRECATE
|
2006-04-25 23:04:48 +02:00
|
|
|
|
2014-12-17 03:48:22 +01:00
|
|
|
// Remaps the file storage to a new file layout. This can be used to, for
|
|
|
|
// instance, download all data in a torrent to a single file, or to a
|
|
|
|
// number of fixed size sector aligned files, regardless of the number
|
|
|
|
// and sizes of the files in the torrent.
|
2013-07-26 08:11:10 +02:00
|
|
|
//
|
2014-12-17 03:48:22 +01:00
|
|
|
// The new specified ``file_storage`` must have the exact same size as
|
|
|
|
// the current one.
|
2009-11-27 23:15:34 +01:00
|
|
|
void remap_files(file_storage const& f);
|
|
|
|
|
2014-12-17 03:48:22 +01:00
|
|
|
// ``add_tracker()`` adds a tracker to the announce-list. The ``tier``
|
|
|
|
// determines the order in which the trackers are to be tried.
|
2013-07-26 08:11:10 +02:00
|
|
|
//
|
2014-12-17 03:48:22 +01:00
|
|
|
// The ``trackers()`` function will return a sorted vector of
|
|
|
|
// ``announce_entry``. Each announce entry contains a string, which is
|
|
|
|
// the tracker url, and a tier index. The tier index is the high-level
|
|
|
|
// priority. No matter which trackers that works or not, the ones with
|
|
|
|
// lower tier will always be tried before the one with higher tier
|
|
|
|
// number. For more information, see announce_entry_.
|
2008-05-28 10:44:40 +02:00
|
|
|
void add_tracker(std::string const& url, int tier = 0);
|
|
|
|
std::vector<announce_entry> const& trackers() const { return m_urls; }
|
2007-08-25 20:26:43 +02:00
|
|
|
|
2015-03-21 01:12:40 +01:00
|
|
|
// These two functions are related to BEP38_ (mutable torrents). The
|
|
|
|
// vectors returned from these correspond to the "similar" and
|
|
|
|
// "collections" keys in the .torrent file. Both info-hashes and
|
|
|
|
// collections from within the info-dict and from outside of it are
|
|
|
|
// included.
|
|
|
|
//
|
|
|
|
// .. _BEP38: http://www.bittorrent.org/beps/bep_0038.html
|
|
|
|
std::vector<sha1_hash> similar_torrents() const;
|
|
|
|
std::vector<std::string> collections() const;
|
|
|
|
|
2010-10-10 20:43:58 +02:00
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
|
|
|
// deprecated in 0.16. Use web_seeds() instead
|
2015-04-17 03:49:49 +02:00
|
|
|
TORRENT_DEPRECATED
|
|
|
|
std::vector<std::string> url_seeds() const;
|
|
|
|
TORRENT_DEPRECATED
|
|
|
|
std::vector<std::string> http_seeds() const;
|
2015-03-12 06:20:12 +01:00
|
|
|
|
|
|
|
// deprecated in 1.1
|
2015-04-17 03:49:49 +02:00
|
|
|
TORRENT_DEPRECATED
|
2015-03-12 06:20:12 +01:00
|
|
|
bool parse_info_section(lazy_entry const& e, error_code& ec
|
2015-04-17 03:49:49 +02:00
|
|
|
, int flags);
|
2010-10-10 20:43:58 +02:00
|
|
|
#endif // TORRENT_NO_DEPRECATE
|
|
|
|
|
2014-12-17 03:48:22 +01:00
|
|
|
// ``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.
|
2013-07-26 08:11:10 +02:00
|
|
|
//
|
|
|
|
// ``add_url_seed()`` and ``add_http_seed()`` adds one url to the list of
|
2014-12-17 03:48:22 +01:00
|
|
|
// url/http seeds. Currently, the only transport protocol supported for
|
|
|
|
// the url is http.
|
2013-07-26 08:11:10 +02:00
|
|
|
//
|
2014-12-17 03:48:22 +01:00
|
|
|
// The ``extern_auth`` argument can be used for other athorization
|
|
|
|
// schemese than basic HTTP authorization. If set, it will override any
|
|
|
|
// username and password found in the URL itself. The string will be sent
|
|
|
|
// as the HTTP authorization header's value (without specifying "Basic").
|
2013-07-26 08:11:10 +02:00
|
|
|
//
|
2014-12-17 03:48:22 +01:00
|
|
|
// The ``extra_headers`` argument defaults to an empty list, but can be
|
|
|
|
// used to insert custom HTTP headers in the requests to a specific web
|
|
|
|
// seed.
|
2013-07-26 08:11:10 +02:00
|
|
|
//
|
2013-08-11 08:04:24 +02:00
|
|
|
// See http-seeding_ for more information.
|
2013-07-26 08:11:10 +02:00
|
|
|
void add_url_seed(std::string const& url
|
2010-10-10 20:43:58 +02:00
|
|
|
, 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
|
|
|
|
, std::string const& extern_auth = std::string()
|
|
|
|
, web_seed_entry::headers_t const& extra_headers = web_seed_entry::headers_t());
|
|
|
|
std::vector<web_seed_entry> const& web_seeds() const
|
|
|
|
{ return m_web_seeds; }
|
2008-12-30 04:54:07 +01:00
|
|
|
|
2014-12-17 03:48:22 +01:00
|
|
|
// ``total_size()``, ``piece_length()`` and ``num_pieces()`` returns the
|
|
|
|
// total number of bytes the torrent-file represents (all the files in
|
|
|
|
// it), the number of byte for each piece and the total number of pieces,
|
|
|
|
// respectively. The difference between ``piece_size()`` and
|
|
|
|
// ``piece_length()`` is that ``piece_size()`` takes the piece index as
|
|
|
|
// argument and gives you the exact size of that piece. It will always be
|
|
|
|
// the same as ``piece_length()`` except in the case of the last piece,
|
|
|
|
// which may be smaller.
|
2014-12-03 05:32:50 +01:00
|
|
|
boost::int64_t total_size() const { return m_files.total_size(); }
|
2008-05-28 10:44:40 +02:00
|
|
|
int piece_length() const { return m_files.piece_length(); }
|
|
|
|
int num_pieces() const { return m_files.num_pieces(); }
|
2013-07-26 08:11:10 +02:00
|
|
|
|
2013-09-01 19:34:05 +02:00
|
|
|
// returns the info-hash of the torrent
|
2003-10-23 01:00:57 +02:00
|
|
|
const sha1_hash& info_hash() const { return m_info_hash; }
|
2008-05-28 10:44:40 +02:00
|
|
|
|
2013-08-12 09:30:57 +02:00
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
|
|
|
// deprecated in 1.0. Use the variants that take an index instead
|
|
|
|
// internal_file_entry is no longer exposed in the API
|
2008-05-28 10:44:40 +02:00
|
|
|
typedef file_storage::iterator file_iterator;
|
|
|
|
typedef file_storage::reverse_iterator reverse_file_iterator;
|
|
|
|
|
2014-12-17 03:48:22 +01:00
|
|
|
// This class will need some explanation. First of all, to get a list of
|
|
|
|
// all files in the torrent, you can use ``begin_files()``,
|
|
|
|
// ``end_files()``, ``rbegin_files()`` and ``rend_files()``. These will
|
|
|
|
// give you standard vector iterators with the type
|
|
|
|
// ``internal_file_entry``, which is an internal type.
|
2013-07-26 08:11:10 +02:00
|
|
|
//
|
2014-12-17 03:48:22 +01:00
|
|
|
// You can resolve it into the public representation of a file
|
|
|
|
// (``file_entry``) using the ``file_storage::at`` function, which takes
|
|
|
|
// an index and an iterator.
|
2015-04-17 03:49:49 +02:00
|
|
|
TORRENT_DEPRECATED
|
2015-04-25 06:22:51 +02:00
|
|
|
file_iterator begin_files() const { return m_files.begin_deprecated(); }
|
2015-04-17 03:49:49 +02:00
|
|
|
TORRENT_DEPRECATED
|
2015-04-25 06:22:51 +02:00
|
|
|
file_iterator end_files() const { return m_files.end_deprecated(); }
|
|
|
|
reverse_file_iterator rbegin_files() const { return m_files.rbegin_deprecated(); }
|
2015-04-17 03:49:49 +02:00
|
|
|
TORRENT_DEPRECATED
|
2015-04-25 06:22:51 +02:00
|
|
|
reverse_file_iterator rend_files() const { return m_files.rend_deprecated(); }
|
2013-08-12 09:30:57 +02:00
|
|
|
|
2015-04-17 03:49:49 +02:00
|
|
|
TORRENT_DEPRECATED
|
2015-04-25 06:22:51 +02:00
|
|
|
file_iterator file_at_offset(boost::int64_t offset) const
|
2013-10-07 09:45:36 +02:00
|
|
|
{ return m_files.file_at_offset_deprecated(offset); }
|
2013-08-12 09:30:57 +02:00
|
|
|
|
2015-04-17 03:49:49 +02:00
|
|
|
TORRENT_DEPRECATED
|
2015-04-25 06:22:51 +02:00
|
|
|
file_entry file_at(int index) const { return m_files.at_deprecated(index); }
|
2013-08-12 09:30:57 +02:00
|
|
|
#endif // TORRENT_NO_DEPRECATE
|
2013-07-26 08:11:10 +02:00
|
|
|
|
2014-12-17 03:48:22 +01:00
|
|
|
// If you need index-access to files you can use the ``num_files()`` and
|
2015-04-25 06:22:51 +02:00
|
|
|
// ``file_path()`` et.al. to access files using indices.
|
2008-05-28 10:44:40 +02:00
|
|
|
int num_files() const { return m_files.num_files(); }
|
|
|
|
|
2014-12-17 03:48:22 +01:00
|
|
|
// This function will map a piece index, a byte offset within that piece
|
|
|
|
// and a size (in bytes) into the corresponding files with offsets where
|
|
|
|
// that data for that piece is supposed to be stored. See file_slice.
|
2014-12-03 05:32:50 +01:00
|
|
|
std::vector<file_slice> map_block(int piece, boost::int64_t offset, int size) const
|
2014-07-06 21:18:00 +02:00
|
|
|
{
|
|
|
|
TORRENT_ASSERT(is_loaded());
|
|
|
|
return m_files.map_block(piece, offset, size);
|
|
|
|
}
|
2013-07-26 08:11:10 +02:00
|
|
|
|
2014-12-17 03:48:22 +01:00
|
|
|
// This function will map a range in a specific file into a range in the
|
|
|
|
// torrent. The ``file_offset`` parameter is the offset in the file,
|
|
|
|
// given in bytes, where 0 is the start of the file. See peer_request.
|
2013-07-26 08:11:10 +02:00
|
|
|
//
|
2014-12-17 03:48:22 +01:00
|
|
|
// The input range is assumed to be valid within the torrent.
|
|
|
|
// ``file_offset`` + ``size`` is not allowed to be greater than the file
|
|
|
|
// size. ``file_index`` must refer to a valid file, i.e. it cannot be >=
|
|
|
|
// ``num_files()``.
|
2014-12-03 05:32:50 +01:00
|
|
|
peer_request map_file(int file, boost::int64_t offset, int size) const
|
2014-07-06 21:18:00 +02:00
|
|
|
{
|
|
|
|
TORRENT_ASSERT(is_loaded());
|
|
|
|
return m_files.map_file(file, offset, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
// load and unload this torrent info
|
|
|
|
void load(char const* buffer, int size, error_code& ec);
|
|
|
|
void unload();
|
|
|
|
|
2008-08-03 17:14:08 +02:00
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
2007-04-10 11:11:32 +02:00
|
|
|
// ------- start deprecation -------
|
2008-05-14 07:29:42 +02:00
|
|
|
// these functions will be removed in a future version
|
2015-04-17 03:49:49 +02:00
|
|
|
TORRENT_DEPRECATED
|
|
|
|
torrent_info(entry const& torrent_file);
|
|
|
|
TORRENT_DEPRECATED
|
|
|
|
void print(std::ostream& os) const;
|
2007-04-10 11:11:32 +02:00
|
|
|
// ------- end deprecation -------
|
2008-08-03 17:14:08 +02:00
|
|
|
#endif
|
2007-04-10 11:11:32 +02:00
|
|
|
|
2013-09-01 19:34:05 +02:00
|
|
|
// Returns the SSL root certificate for the torrent, if it is an SSL
|
|
|
|
// torrent. Otherwise returns an empty string. The certificate is
|
|
|
|
// the the public certificate in x509 format.
|
2013-11-17 23:38:37 +01:00
|
|
|
std::string ssl_cert() const;
|
2011-09-05 07:50:41 +02:00
|
|
|
|
2013-09-01 19:34:05 +02:00
|
|
|
// returns true if this torrent_info object has a torrent loaded.
|
|
|
|
// This is primarily used to determine if a magnet link has had its
|
|
|
|
// metadata resolved yet or not.
|
2008-05-28 10:44:40 +02:00
|
|
|
bool is_valid() const { return m_files.is_valid(); }
|
2003-10-23 01:00:57 +02:00
|
|
|
|
2013-07-26 08:11:10 +02:00
|
|
|
// returns true if this torrent is private. i.e., it should not be
|
|
|
|
// distributed on the trackerless network (the kademlia DHT).
|
2006-08-01 17:27:08 +02:00
|
|
|
bool priv() const { return m_private; }
|
2004-03-07 21:50:56 +01:00
|
|
|
|
2013-09-01 19:34:05 +02:00
|
|
|
// returns true if this is an i2p torrent. This is determined by whether
|
|
|
|
// or not it has a tracker whose URL domain name ends with ".i2p". i2p
|
|
|
|
// torrents disable the DHT and local peer discovery as well as talking
|
|
|
|
// to peers over anything other than the i2p network.
|
2009-08-20 05:19:12 +02:00
|
|
|
bool is_i2p() const { return m_i2p; }
|
|
|
|
|
2014-12-17 03:48:22 +01:00
|
|
|
// ``hash_for_piece()`` takes a piece-index and returns the 20-bytes
|
|
|
|
// sha1-hash for that piece and ``info_hash()`` returns the 20-bytes
|
|
|
|
// sha1-hash for the info-section of the torrent file.
|
|
|
|
// ``hash_for_piece_ptr()`` returns a pointer to the 20 byte sha1 digest
|
|
|
|
// for the piece. Note that the string is not null-terminated.
|
2008-05-28 10:44:40 +02:00
|
|
|
int piece_size(int index) const { return m_files.piece_size(index); }
|
2008-05-14 07:29:42 +02:00
|
|
|
sha1_hash hash_for_piece(int index) const
|
2008-05-28 10:44:40 +02:00
|
|
|
{ return sha1_hash(hash_for_piece_ptr(index)); }
|
2008-05-14 07:29:42 +02:00
|
|
|
char const* hash_for_piece_ptr(int index) const
|
2003-10-23 01:00:57 +02:00
|
|
|
{
|
2007-10-05 02:30:00 +02:00
|
|
|
TORRENT_ASSERT(index >= 0);
|
2008-05-28 10:44:40 +02:00
|
|
|
TORRENT_ASSERT(index < m_files.num_pieces());
|
2014-07-06 21:18:00 +02:00
|
|
|
TORRENT_ASSERT(is_loaded());
|
2009-03-13 07:09:39 +01:00
|
|
|
if (is_merkle_torrent())
|
|
|
|
{
|
2010-10-16 17:24:45 +02:00
|
|
|
TORRENT_ASSERT(index < int(m_merkle_tree.size() - m_merkle_first_leaf));
|
2015-08-02 05:57:11 +02:00
|
|
|
return m_merkle_tree[m_merkle_first_leaf + index].data();
|
2009-03-13 07:09:39 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TORRENT_ASSERT(m_piece_hashes);
|
|
|
|
TORRENT_ASSERT(m_piece_hashes >= m_info_section.get());
|
|
|
|
TORRENT_ASSERT(m_piece_hashes < m_info_section.get() + m_info_section_size);
|
2010-10-16 17:24:45 +02:00
|
|
|
TORRENT_ASSERT(index < int(m_info_section_size / 20));
|
2009-03-13 07:09:39 +01:00
|
|
|
return &m_piece_hashes[index*20];
|
|
|
|
}
|
2003-10-23 01:00:57 +02:00
|
|
|
}
|
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
bool is_loaded() const { return m_piece_hashes || !m_merkle_tree.empty(); }
|
|
|
|
|
2014-12-17 03:48:22 +01:00
|
|
|
// ``merkle_tree()`` returns a reference to the merkle tree for this
|
|
|
|
// torrent, if any.
|
2013-07-26 08:11:10 +02:00
|
|
|
//
|
2014-12-17 03:48:22 +01:00
|
|
|
// ``set_merkle_tree()`` moves the passed in merkle tree into the
|
|
|
|
// torrent_info object. i.e. ``h`` will not be identical after the call.
|
|
|
|
// You need to set the merkle tree for a torrent that you've just created
|
|
|
|
// (as a merkle torrent). The merkle tree is retrieved from the
|
|
|
|
// ``create_torrent::merkle_tree()`` function, and need to be saved
|
|
|
|
// separately from the torrent file itself. Once it's added to
|
|
|
|
// libtorrent, the merkle tree will be persisted in the resume data.
|
2013-07-26 08:11:10 +02:00
|
|
|
std::vector<sha1_hash> const& merkle_tree() const { return m_merkle_tree; }
|
|
|
|
void set_merkle_tree(std::vector<sha1_hash>& h)
|
|
|
|
{ TORRENT_ASSERT(h.size() == m_merkle_tree.size() ); m_merkle_tree.swap(h); }
|
2003-11-20 20:58:29 +01:00
|
|
|
|
2013-07-26 08:11:10 +02:00
|
|
|
// ``name()`` returns the name of the torrent.
|
|
|
|
//
|
2014-12-17 03:48:22 +01:00
|
|
|
// ``comment()`` returns the comment associated with the torrent. If
|
|
|
|
// there's no comment, it will return an empty string.
|
|
|
|
// ``creation_date()`` returns the creation date of the torrent as time_t
|
|
|
|
// (`posix time`_). If there's no time stamp in the torrent file, the
|
|
|
|
// optional object will be uninitialized.
|
2013-07-26 08:11:10 +02:00
|
|
|
//
|
|
|
|
// Both the name and the comment is UTF-8 encoded strings.
|
|
|
|
//
|
2014-12-17 03:48:22 +01:00
|
|
|
// ``creator()`` returns the creator string in the torrent. If there is
|
|
|
|
// no creator string it will return an empty string.
|
2013-07-26 08:11:10 +02:00
|
|
|
//
|
2015-01-02 00:35:28 +01:00
|
|
|
// .. _`posix time`: http://www.opengroup.org/onlinepubs/009695399/functions/time.html
|
2013-07-26 08:11:10 +02:00
|
|
|
const std::string& name() const { return m_files.name(); }
|
|
|
|
boost::optional<time_t> creation_date() const;
|
2005-08-18 00:59:21 +02:00
|
|
|
const std::string& creator() const
|
|
|
|
{ return m_created_by; }
|
2003-11-20 20:58:29 +01:00
|
|
|
const std::string& comment() const
|
|
|
|
{ return m_comment; }
|
|
|
|
|
2006-08-01 17:27:08 +02:00
|
|
|
// dht nodes to add to the routing table/bootstrap from
|
|
|
|
typedef std::vector<std::pair<std::string, int> > nodes_t;
|
|
|
|
|
2014-12-17 03:48:22 +01:00
|
|
|
// If this torrent contains any DHT nodes, they are put in this vector in
|
|
|
|
// their original form (host name and port number).
|
2006-08-01 17:27:08 +02:00
|
|
|
nodes_t const& nodes() const
|
2008-05-15 09:37:34 +02:00
|
|
|
{ return m_nodes; }
|
2013-07-26 08:11:10 +02:00
|
|
|
|
2014-12-17 03:48:22 +01:00
|
|
|
// This is used when creating torrent. Use this to add a known DHT node.
|
|
|
|
// It may be used, by the client, to bootstrap into the DHT network.
|
2008-05-15 09:37:34 +02:00
|
|
|
void add_node(std::pair<std::string, int> const& node)
|
|
|
|
{ m_nodes.push_back(node); }
|
2006-08-01 17:27:08 +02:00
|
|
|
|
2014-12-17 03:48:22 +01:00
|
|
|
// populates the torrent_info by providing just the info-dict buffer.
|
|
|
|
// This is used when loading a torrent from a magnet link for instance,
|
2015-03-12 06:20:12 +01:00
|
|
|
// where we only have the info-dict. The bdecode_node ``e`` points to a
|
2014-12-17 03:48:22 +01:00
|
|
|
// parsed info-dictionary. ``ec`` returns an error code if something
|
|
|
|
// fails (typically if the info dictionary is malformed). ``flags`` are
|
|
|
|
// currently unused.
|
2015-03-12 06:20:12 +01:00
|
|
|
bool parse_info_section(bdecode_node const& e, error_code& ec, int flags);
|
2006-08-01 17:27:08 +02:00
|
|
|
|
2014-12-17 03:48:22 +01:00
|
|
|
// 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.
|
2015-03-12 06:20:12 +01:00
|
|
|
bdecode_node info(char const* key) const
|
2008-05-14 07:29:42 +02:00
|
|
|
{
|
2015-03-12 06:20:12 +01:00
|
|
|
if (m_info_dict.type() == bdecode_node::none_t)
|
2010-10-28 06:01:59 +02:00
|
|
|
{
|
|
|
|
error_code ec;
|
2015-03-12 06:20:12 +01:00
|
|
|
bdecode(m_info_section.get(), m_info_section.get()
|
2010-10-28 06:01:59 +02:00
|
|
|
+ m_info_section_size, m_info_dict, ec);
|
2015-03-12 06:20:12 +01:00
|
|
|
if (ec) return bdecode_node();
|
2010-10-28 06:01:59 +02:00
|
|
|
}
|
2008-05-14 07:29:42 +02:00
|
|
|
return m_info_dict.dict_find(key);
|
|
|
|
}
|
2004-06-14 01:30:42 +02:00
|
|
|
|
2013-09-01 19:34:05 +02:00
|
|
|
// swap the content of this and ``ti```.
|
2008-05-14 07:29:42 +02:00
|
|
|
void swap(torrent_info& ti);
|
2007-03-23 00:37:24 +01:00
|
|
|
|
2013-07-26 08:11:10 +02:00
|
|
|
// ``metadata()`` returns a the raw info section of the torrent file. The size
|
|
|
|
// of the metadata is returned by ``metadata_size()``.
|
|
|
|
int metadata_size() const { return m_info_section_size; }
|
2008-05-14 07:29:42 +02:00
|
|
|
boost::shared_array<char> metadata() const
|
|
|
|
{ return m_info_section; }
|
2007-05-10 00:54:26 +02:00
|
|
|
|
2013-11-09 03:01:26 +01:00
|
|
|
// internal
|
2009-03-13 07:09:39 +01:00
|
|
|
bool add_merkle_nodes(std::map<int, sha1_hash> const& subtree
|
|
|
|
, int piece);
|
|
|
|
std::map<int, sha1_hash> build_merkle_list(int piece) const;
|
2013-11-09 03:01:26 +01:00
|
|
|
|
|
|
|
// returns whether or not this is a merkle torrent.
|
|
|
|
// see BEP30__.
|
|
|
|
//
|
|
|
|
// __ http://bittorrent.org/beps/bep_0030.html
|
2009-03-13 07:09:39 +01:00
|
|
|
bool is_merkle_torrent() const { return !m_merkle_tree.empty(); }
|
|
|
|
|
2015-03-12 06:20:12 +01:00
|
|
|
bool parse_torrent_file(bdecode_node const& libtorrent, error_code& ec, int flags);
|
2014-07-06 21:18:00 +02:00
|
|
|
|
2010-08-22 00:10:16 +02:00
|
|
|
// if we're logging member offsets, we need access to them
|
2003-10-23 01:00:57 +02:00
|
|
|
private:
|
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
void resolve_duplicate_filenames();
|
|
|
|
|
2015-02-17 03:08:47 +01:00
|
|
|
// the slow path, in case we detect/suspect a name collision
|
|
|
|
void resolve_duplicate_filenames_slow();
|
|
|
|
|
2014-01-21 20:26:09 +01:00
|
|
|
#if TORRENT_USE_INVARIANT_CHECKS
|
2013-11-17 23:38:37 +01:00
|
|
|
friend class invariant_access;
|
|
|
|
void check_invariant() const;
|
|
|
|
#endif
|
|
|
|
|
2009-11-26 07:54:52 +01:00
|
|
|
// not assignable
|
|
|
|
torrent_info const& operator=(torrent_info const&);
|
|
|
|
|
2008-12-24 21:07:34 +01:00
|
|
|
void copy_on_write();
|
2011-09-21 11:27:07 +02:00
|
|
|
|
2008-05-28 10:44:40 +02:00
|
|
|
file_storage m_files;
|
|
|
|
|
2008-12-24 21:07:34 +01:00
|
|
|
// if m_files is modified, it is first copied into
|
|
|
|
// m_orig_files so that the original name and
|
|
|
|
// filenames are preserved.
|
2010-08-22 00:10:16 +02:00
|
|
|
copy_ptr<const file_storage> m_orig_files;
|
2008-12-24 21:07:34 +01:00
|
|
|
|
2003-10-23 01:00:57 +02:00
|
|
|
// the urls to the trackers
|
|
|
|
std::vector<announce_entry> m_urls;
|
2010-10-10 20:43:58 +02:00
|
|
|
std::vector<web_seed_entry> m_web_seeds;
|
2006-08-01 17:27:08 +02:00
|
|
|
nodes_t m_nodes;
|
|
|
|
|
2015-03-21 01:12:40 +01:00
|
|
|
// the info-hashes (20 bytes each) in the "similar" key. The pointers
|
|
|
|
// point directly into the info_section. When copied, these pointers must
|
|
|
|
// be corrected to point into the copied-to buffer
|
|
|
|
std::vector<char const*> m_similar_torrents;
|
|
|
|
|
|
|
|
// these are similar torrents from outside of the info-dict. We can't
|
|
|
|
// have non-owning pointers to those, as we only keep the info-dict
|
|
|
|
// around.
|
|
|
|
std::vector<sha1_hash> m_owned_similar_torrents;
|
|
|
|
|
|
|
|
// these or strings of the "collections" key from the torrent file. The
|
|
|
|
// pointers point directly into the info_section buffer and when copied,
|
|
|
|
// these pointers must be corrected to point into the new buffer. The
|
|
|
|
// int is the length of the string. Strings are not NULL-terminated.
|
|
|
|
std::vector<std::pair<char const*, int> > m_collections;
|
|
|
|
|
|
|
|
// these are the collections from outside of the info-dict. These are
|
|
|
|
// owning strings, since we only keep the info-section around, these
|
|
|
|
// cannot be pointers into that buffer.
|
|
|
|
std::vector<std::string> m_owned_collections;
|
|
|
|
|
2010-08-22 00:10:16 +02:00
|
|
|
// if this is a merkle torrent, this is the merkle
|
|
|
|
// tree. It has space for merkle_num_nodes(merkle_num_leafs(num_pieces))
|
|
|
|
// hashes
|
|
|
|
std::vector<sha1_hash> m_merkle_tree;
|
2003-10-28 02:20:50 +01:00
|
|
|
|
2010-08-22 00:10:16 +02:00
|
|
|
// this is a copy of the info section from the torrent.
|
|
|
|
// it use maintained in this flat format in order to
|
|
|
|
// make it available through the metadata extension
|
|
|
|
boost::shared_array<char> m_info_section;
|
|
|
|
|
|
|
|
// this is a pointer into the m_info_section buffer
|
|
|
|
// pointing to the first byte of the first sha-1 hash
|
|
|
|
char const* m_piece_hashes;
|
2003-11-20 20:58:29 +01:00
|
|
|
|
|
|
|
// if a comment is found in the torrent file
|
|
|
|
// this will be set to that comment
|
|
|
|
std::string m_comment;
|
2004-03-23 23:58:18 +01:00
|
|
|
|
|
|
|
// an optional string naming the software used
|
|
|
|
// to create the torrent file
|
|
|
|
std::string m_created_by;
|
2005-05-12 01:03:12 +02:00
|
|
|
|
2010-08-22 00:10:16 +02:00
|
|
|
// the info section parsed. points into m_info_section
|
|
|
|
// parsed lazily
|
2015-03-12 06:20:12 +01:00
|
|
|
mutable bdecode_node m_info_dict;
|
2010-08-22 00:10:16 +02:00
|
|
|
|
|
|
|
// if a creation date is found in the torrent file
|
|
|
|
// this will be set to that, otherwise it'll be
|
|
|
|
// 1970, Jan 1
|
|
|
|
time_t m_creation_date;
|
|
|
|
|
|
|
|
// the hash that identifies this torrent
|
|
|
|
sha1_hash m_info_hash;
|
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
// the index to the first leaf. This is where the hash for the
|
|
|
|
// first piece is stored
|
|
|
|
boost::uint32_t m_merkle_first_leaf;
|
|
|
|
|
2010-08-22 00:10:16 +02:00
|
|
|
// the number of bytes in m_info_section
|
|
|
|
boost::uint32_t m_info_section_size:24;
|
|
|
|
|
2005-05-12 01:03:12 +02:00
|
|
|
// this is used when creating a torrent. If there's
|
|
|
|
// only one file there are cases where it's impossible
|
|
|
|
// to know if it should be written as a multifile torrent
|
|
|
|
// or not. e.g. test/test there's one file and one directory
|
|
|
|
// and they have the same name.
|
2010-08-22 00:10:16 +02:00
|
|
|
bool m_multifile:1;
|
2006-08-01 17:27:08 +02:00
|
|
|
|
|
|
|
// this is true if the torrent is private. i.e., is should not
|
|
|
|
// be announced on the dht
|
2010-08-22 00:10:16 +02:00
|
|
|
bool m_private:1;
|
2005-10-16 18:58:41 +02:00
|
|
|
|
2009-08-20 05:19:12 +02:00
|
|
|
// this is true if one of the trackers has an .i2p top
|
|
|
|
// domain in its hostname. This means the DHT and LSD
|
|
|
|
// features are disabled for this torrent (unless the
|
|
|
|
// settings allows mixing i2p peers with regular peers)
|
2010-08-22 00:10:16 +02:00
|
|
|
bool m_i2p:1;
|
2003-10-23 01:00:57 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // TORRENT_TORRENT_INFO_HPP_INCLUDED
|
2003-10-24 13:11:28 +02:00
|
|
|
|