forked from premiere/premiere-libtorrent
141 lines
4.2 KiB
C++
141 lines
4.2 KiB
C++
/*
|
|
|
|
Copyright (c) 2008, 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_CREATE_TORRENT_HPP_INCLUDED
|
|
#define TORRENT_CREATE_TORRENT_HPP_INCLUDED
|
|
|
|
#include "libtorrent/bencode.hpp"
|
|
#include "libtorrent/peer_id.hpp"
|
|
#include <vector>
|
|
#include <string>
|
|
#include <utility>
|
|
|
|
#ifdef _MSC_VER
|
|
#pragma warning(push, 1)
|
|
#endif
|
|
|
|
#include <boost/filesystem/path.hpp>
|
|
#include <boost/optional.hpp>
|
|
#include <boost/date_time/posix_time/posix_time.hpp>
|
|
|
|
#ifdef _MSC_VER
|
|
#pragma warning(pop)
|
|
#endif
|
|
|
|
namespace libtorrent
|
|
{
|
|
namespace fs = boost::filesystem;
|
|
namespace pt = boost::posix_time;
|
|
|
|
struct create_torrent
|
|
{
|
|
create_torrent();
|
|
entry generate() const;
|
|
|
|
void set_comment(char const* str);
|
|
void set_creator(char const* str);
|
|
void set_piece_size(int size);
|
|
void set_hash(int index, sha1_hash const& h);
|
|
void add_file(fs::path file, size_type size);
|
|
void add_url_seed(std::string const& url);
|
|
void add_node(std::pair<std::string, int> const& node);
|
|
void add_tracker(std::string const& url, int tier = 0);
|
|
|
|
int num_pieces() const { return m_num_pieces; }
|
|
int piece_length() const { return m_piece_length; }
|
|
int piece_size(int i) const;
|
|
|
|
private:
|
|
|
|
// the urls to the trackers
|
|
typedef std::pair<std::string, int> announce_entry;
|
|
std::vector<announce_entry> m_urls;
|
|
|
|
std::vector<std::string> m_url_seeds;
|
|
|
|
std::vector<sha1_hash> m_piece_hash;
|
|
|
|
// the length of one piece
|
|
// if this is 0, the torrent_info is
|
|
// in an uninitialized state
|
|
int m_piece_length;
|
|
|
|
typedef std::pair<fs::path, size_type> file_entry;
|
|
// the list of files that this torrent consists of
|
|
std::vector<file_entry> m_files;
|
|
|
|
// dht nodes to add to the routing table/bootstrap from
|
|
typedef std::vector<std::pair<std::string, int> > nodes_t;
|
|
nodes_t m_nodes;
|
|
|
|
// the sum of all filesizes
|
|
size_type m_total_size;
|
|
|
|
// the number of pieces in the torrent
|
|
int m_num_pieces;
|
|
|
|
// the hash that identifies this torrent
|
|
// is mutable because it's calculated
|
|
// lazily
|
|
mutable sha1_hash m_info_hash;
|
|
|
|
std::string m_name;
|
|
|
|
// if a creation date is found in the torrent file
|
|
// this will be set to that, otherwise it'll be
|
|
// 1970, Jan 1
|
|
pt::ptime m_creation_date;
|
|
|
|
// if a comment is found in the torrent file
|
|
// this will be set to that comment
|
|
std::string m_comment;
|
|
|
|
// an optional string naming the software used
|
|
// to create the torrent file
|
|
std::string m_created_by;
|
|
|
|
// 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.
|
|
bool m_multifile;
|
|
|
|
// this is true if the torrent is private. i.e., is should not
|
|
// be announced on the dht
|
|
bool m_private;
|
|
};
|
|
}
|
|
|
|
#endif
|
|
|