Post by kyôn helo, I want to know where is the definition of sha1_hash, I tried to use it in a program and i can't to compile it,
(torrent_info.hpp)
entry create_torrent() const;
void set_comment(char const* str);
void set_creator(char const* str);
void set_hash(int index, const sha1_hash& h);
void add_tracker(std::string const& url, int tier = 0);
void add_file(boost::filesystem::path file, size_type size);
and how to use them, thanks
It is possible to create torrents with libtorrent, it's just that I
haven't had time to document it yet.
The basic usage, though, is this:
create a torrent_info object. To its constructor you supply piece size
and name (of file or the directory).
create an instance of storage. To its constructor you give a reference
to the previously constructed torrent_info and a path to where the
file/drectory is located.
if it's a multi file torrent, you call torrent_info::add_file() with the
filename and the file's size (in bytes). The file is expected to be
located in a directory with the same name as the one given to the
torrent_info constructor.
When all files has been added, you can add a tracker by calling
torrent_info::add_tracker(). It takes a tracker url and a tier (which is
explained in the backup-tracker extension and to some extent in the
libotrrent docs).
Then you have to calculate the hashes. You do this by asking the
torrent_info for how many pieces there are in the torrent
(torrent_info::num_pieces()) and then iterating over them, calling
storage::read() for each piece. You can know the size of each piece by
calling torrent_info::piece_size(index), where index is the piece index.
All pieces have the same size except the last piece which may be
shorter. Anyway, storage::read() will read the piece data into a buffer
you supply the pointer to. You can then use the hasher to calculate the
sha1_hash of that data buffer. When you have the sha1_hash, you call
torrent_info::set_hash(index, hash) to initialize the torrent.
When you have set the sha1 hashes for all pieces, you can set the
creator. Use torrent_info::set_creator() and supply whatever you want.
It's a string that is supposed to describe who or what created this torrent.
Then finally, you can call torrent_info::create_torrent(), which will
return an entry object that represents the torrent data. You can bencode
this data directly to disk with the following code:
std::ofstream f(path);
libtorrent::bencode(std::ostream_iterator<char>(f), e);
That's it, hope it helps. (set comment is self explanatory)
--
Arvid Norberg