torrent_info fixes. make_torrent now builds
This commit is contained in:
parent
31ab7f9773
commit
dbb625a910
|
@ -1210,9 +1210,9 @@ class torrent_info
|
|||
{
|
||||
public:
|
||||
|
||||
torrent_info();
|
||||
torrent_info(sha1_hash const& info_hash);
|
||||
torrent_info(entry const& torrent_file);
|
||||
torrent_info(lazy_entry const& torrent_file);
|
||||
torrent_info(char const* buffer, int size);
|
||||
torrent_info(char const* filename);
|
||||
|
||||
void add_tracker(std::string const& url, int tier = 0);
|
||||
|
@ -1256,8 +1256,6 @@ public:
|
|||
boost::optional<boost::posix_time::ptime>
|
||||
creation_date() const;
|
||||
|
||||
void print(std::ostream& os) const;
|
||||
|
||||
int piece_size(unsigned int index) const;
|
||||
sha1_hash const& hash_for_piece(unsigned int index) const;
|
||||
char const* hash_for_piece_ptr(unsigned int index) const;
|
||||
|
@ -1270,26 +1268,22 @@ public:
|
|||
<h2>torrent_info()</h2>
|
||||
<blockquote>
|
||||
<pre class="literal-block">
|
||||
torrent_info();
|
||||
torrent_info(sha1_hash const& info_hash);
|
||||
torrent_info(entry const& torrent_file);
|
||||
torrent_info(lazy_entry const& torrent_file);
|
||||
torrent_info(char const* buffer, int size);
|
||||
torrent_info(char const* filename);
|
||||
</pre>
|
||||
</blockquote>
|
||||
<p>The default constructor of <tt class="docutils literal"><span class="pre">torrent_info</span></tt> is used when creating torrent files. It will
|
||||
initialize the object to an empty torrent, containing no files. The info hash will be set
|
||||
to 0 when this constructor is used. To use the empty <tt class="docutils literal"><span class="pre">torrent_info</span></tt> object, add files
|
||||
and piece hashes, announce URLs and optionally a creator tag and comment. To do this you
|
||||
use the members <tt class="docutils literal"><span class="pre">set_comment()</span></tt>, <tt class="docutils literal"><span class="pre">set_piece_size()</span></tt>, <tt class="docutils literal"><span class="pre">set_creator()</span></tt>, <tt class="docutils literal"><span class="pre">set_hash()</span></tt>
|
||||
etc.</p>
|
||||
<p>The constructor that takes an info-hash is identical to the default constructor with the
|
||||
exception that it will initialize the info-hash to the given value. 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.</p>
|
||||
<p>The constructor that takes an entry, is the one that is used in most cases. It will create
|
||||
a <tt class="docutils literal"><span class="pre">torrent_info</span></tt> object from the information found in the given torrent_file. The
|
||||
<tt class="docutils literal"><span class="pre">entry</span></tt> represents a tree node in an bencoded file. To load an ordinary .torrent file
|
||||
into an <tt class="docutils literal"><span class="pre">entry</span></tt>, use bdecode(), see <a class="reference internal" href="#bdecode-bencode">bdecode() bencode()</a>.</p>
|
||||
<p>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.</p>
|
||||
<p>The constructor that takes a <tt class="docutils literal"><span class="pre">lazy_entry</span></tt> will create a <tt class="docutils literal"><span class="pre">torrent_info</span></tt> object from the
|
||||
information found in the given torrent_file. The <tt class="docutils literal"><span class="pre">lazy_entry</span></tt> represents a tree node in
|
||||
an bencoded file. To load an ordinary .torrent file
|
||||
into a <tt class="docutils literal"><span class="pre">lazy_entry</span></tt>, use lazy_bdecode(), see <a class="reference internal" href="#bdecode-bencode">bdecode() bencode()</a>.</p>
|
||||
<p>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.</p>
|
||||
<p>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.</p>
|
||||
|
@ -1518,8 +1512,6 @@ piece and <tt class="docutils literal"><span class="pre">info_hash()</span></tt>
|
|||
torrent file. For more information on the <tt class="docutils literal"><span class="pre">sha1_hash</span></tt>, see the <a class="reference internal" href="#big-number">big_number</a> class.
|
||||
<tt class="docutils literal"><span class="pre">hash_for_piece_ptr()</span></tt> returns a pointer to the 20 byte sha1 digest for the piece.
|
||||
Note that the string is not null-terminated.</p>
|
||||
<p><tt class="docutils literal"><span class="pre">info_hash()</span></tt> will only return a valid hash if the torrent_info was read from a
|
||||
<tt class="docutils literal"><span class="pre">.torrent</span></tt> file or if an <tt class="docutils literal"><span class="pre">entry</span></tt> was created from it (through <tt class="docutils literal"><span class="pre">create_torrent</span></tt>).</p>
|
||||
</div>
|
||||
<div class="section" id="name-comment-creation-date-creator">
|
||||
<h2>name() comment() creation_date() creator()</h2>
|
||||
|
|
|
@ -1096,9 +1096,9 @@ The ``torrent_info`` has the following synopsis::
|
|||
{
|
||||
public:
|
||||
|
||||
torrent_info();
|
||||
torrent_info(sha1_hash const& info_hash);
|
||||
torrent_info(entry const& torrent_file);
|
||||
torrent_info(lazy_entry const& torrent_file);
|
||||
torrent_info(char const* buffer, int size);
|
||||
torrent_info(char const* filename);
|
||||
|
||||
void add_tracker(std::string const& url, int tier = 0);
|
||||
|
@ -1142,8 +1142,6 @@ The ``torrent_info`` has the following synopsis::
|
|||
boost::optional<boost::posix_time::ptime>
|
||||
creation_date() const;
|
||||
|
||||
void print(std::ostream& os) const;
|
||||
|
||||
int piece_size(unsigned int index) const;
|
||||
sha1_hash const& hash_for_piece(unsigned int index) const;
|
||||
char const* hash_for_piece_ptr(unsigned int index) const;
|
||||
|
@ -1157,27 +1155,23 @@ torrent_info()
|
|||
|
||||
::
|
||||
|
||||
torrent_info();
|
||||
torrent_info(sha1_hash const& info_hash);
|
||||
torrent_info(entry const& torrent_file);
|
||||
torrent_info(lazy_entry const& torrent_file);
|
||||
torrent_info(char const* buffer, int size);
|
||||
torrent_info(char const* filename);
|
||||
|
||||
The default constructor of ``torrent_info`` is used when creating torrent files. It will
|
||||
initialize the object to an empty torrent, containing no files. The info hash will be set
|
||||
to 0 when this constructor is used. To use the empty ``torrent_info`` object, add files
|
||||
and piece hashes, announce URLs and optionally a creator tag and comment. To do this you
|
||||
use the members ``set_comment()``, ``set_piece_size()``, ``set_creator()``, ``set_hash()``
|
||||
etc.
|
||||
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.
|
||||
|
||||
The constructor that takes an info-hash is identical to the default constructor with the
|
||||
exception that it will initialize the info-hash to the given value. 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.
|
||||
The constructor that takes a ``lazy_entry`` will create a ``torrent_info`` object from the
|
||||
information found in the given torrent_file. The ``lazy_entry`` represents a tree node in
|
||||
an bencoded file. To load an ordinary .torrent file
|
||||
into a ``lazy_entry``, use lazy_bdecode(), see `bdecode() bencode()`_.
|
||||
|
||||
The constructor that takes an entry, is the one that is used in most cases. It will create
|
||||
a ``torrent_info`` object from the information found in the given torrent_file. The
|
||||
``entry`` represents a tree node in an bencoded file. To load an ordinary .torrent file
|
||||
into an ``entry``, use bdecode(), see `bdecode() bencode()`_.
|
||||
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.
|
||||
|
||||
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
|
||||
|
@ -1438,9 +1432,6 @@ torrent file. For more information on the ``sha1_hash``, see the big_number_ cla
|
|||
``hash_for_piece_ptr()`` returns a pointer to the 20 byte sha1 digest for the piece.
|
||||
Note that the string is not null-terminated.
|
||||
|
||||
``info_hash()`` will only return a valid hash if the torrent_info was read from a
|
||||
``.torrent`` file or if an ``entry`` was created from it (through ``create_torrent``).
|
||||
|
||||
|
||||
name() comment() creation_date() creator()
|
||||
------------------------------------------
|
||||
|
|
|
@ -42,6 +42,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/storage.hpp"
|
||||
#include "libtorrent/hasher.hpp"
|
||||
#include "libtorrent/file_pool.hpp"
|
||||
#include "libtorrent/create_torrent.hpp"
|
||||
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
|
@ -50,10 +51,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
using namespace boost::filesystem;
|
||||
using namespace libtorrent;
|
||||
|
||||
void add_files(
|
||||
torrent_info& t
|
||||
, path const& p
|
||||
, path const& l)
|
||||
void add_files(create_torrent& t, path const& p, path const& l)
|
||||
{
|
||||
if (l.leaf()[0] == '.') return;
|
||||
path f(p / l);
|
||||
|
@ -89,40 +87,44 @@ int main(int argc, char* argv[])
|
|||
try
|
||||
{
|
||||
#endif
|
||||
boost::intrusive_ptr<torrent_info> t(new torrent_info);
|
||||
create_torrent t;
|
||||
path full_path = complete(path(argv[3]));
|
||||
ofstream out(complete(path(argv[1])), std::ios_base::binary);
|
||||
|
||||
int piece_size = 256 * 1024;
|
||||
char const* creator_str = "libtorrent";
|
||||
|
||||
add_files(*t, full_path.branch_path(), full_path.leaf());
|
||||
t->set_piece_size(piece_size);
|
||||
add_files(t, full_path.branch_path(), full_path.leaf());
|
||||
t.set_piece_size(piece_size);
|
||||
t.add_tracker(argv[2]);
|
||||
|
||||
std::vector<char> tmp;
|
||||
bencode(std::back_inserter(tmp), t.generate());
|
||||
boost::intrusive_ptr<torrent_info> info(new torrent_info(&tmp[0], tmp.size()));
|
||||
|
||||
file_pool fp;
|
||||
boost::scoped_ptr<storage_interface> st(
|
||||
default_storage_constructor(t, full_path.branch_path(), fp));
|
||||
t->add_tracker(argv[2]);
|
||||
default_storage_constructor(info, full_path.branch_path(), fp));
|
||||
|
||||
// calculate the hash for all pieces
|
||||
int num = t->num_pieces();
|
||||
int num = t.num_pieces();
|
||||
std::vector<char> buf(piece_size);
|
||||
for (int i = 0; i < num; ++i)
|
||||
{
|
||||
st->read(&buf[0], i, 0, t->piece_size(i));
|
||||
hasher h(&buf[0], t->piece_size(i));
|
||||
t->set_hash(i, h.final());
|
||||
std::cerr << (i+1) << "/" << num << "\r";
|
||||
st->read(&buf[0], i, 0, t.piece_size(i));
|
||||
hasher h(&buf[0], t.piece_size(i));
|
||||
t.set_hash(i, h.final());
|
||||
std::cerr << "\r" << (i+1) << "/" << num;
|
||||
}
|
||||
std::cerr << std::endl;
|
||||
|
||||
t->set_creator(creator_str);
|
||||
t.set_creator(creator_str);
|
||||
|
||||
if (argc == 5)
|
||||
t->add_url_seed(argv[4]);
|
||||
t.add_url_seed(argv[4]);
|
||||
|
||||
// create the torrent and print it to out
|
||||
entry e = t->create_torrent();
|
||||
libtorrent::bencode(std::ostream_iterator<char>(out), e);
|
||||
ofstream out(complete(path(argv[1])), std::ios_base::binary);
|
||||
bencode(std::ostream_iterator<char>(out), t.generate());
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
}
|
||||
catch (std::exception& e)
|
||||
|
|
|
@ -110,7 +110,6 @@ namespace libtorrent
|
|||
{
|
||||
public:
|
||||
|
||||
torrent_info();
|
||||
torrent_info(sha1_hash const& info_hash);
|
||||
torrent_info(lazy_entry const& torrent_file);
|
||||
torrent_info(char const* buffer, int size);
|
||||
|
|
|
@ -302,20 +302,6 @@ namespace libtorrent
|
|||
{
|
||||
}
|
||||
|
||||
torrent_info::torrent_info()
|
||||
: m_piece_length(0)
|
||||
, m_total_size(0)
|
||||
, m_num_pieces(0)
|
||||
, m_info_hash(0)
|
||||
, m_name()
|
||||
, m_creation_date(pt::second_clock::universal_time())
|
||||
, m_multifile(false)
|
||||
, m_private(false)
|
||||
, m_info_section_size(0)
|
||||
, m_piece_hashes(0)
|
||||
{
|
||||
}
|
||||
|
||||
torrent_info::torrent_info(char const* filename)
|
||||
: m_num_pieces(0)
|
||||
, m_creation_date(pt::ptime(pt::not_a_date_time))
|
||||
|
|
Loading…
Reference in New Issue