forked from premiere/premiere-libtorrent
support web seeds in create_torrent and fix issue when building without deprecated functions
This commit is contained in:
parent
72322dbc10
commit
43b29c3627
|
@ -244,6 +244,7 @@ The ``create_torrent`` class has the following synopsis::
|
|||
void set_hash(int index, sha1_hash const& h);
|
||||
void set_file_hash(int index, sha1_hash const& h);
|
||||
void add_url_seed(std::string const& url);
|
||||
void add_http_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);
|
||||
void set_priv(bool p);
|
||||
|
@ -394,12 +395,13 @@ This sets the sha1 hash for this file. This hash will end up under the key ``sha
|
|||
associated with this file (for multi-file torrents) or in the root info dictionary
|
||||
for single-file torrents.
|
||||
|
||||
add_url_seed()
|
||||
--------------
|
||||
add_url_seed() add_http_seed()
|
||||
------------------------------
|
||||
|
||||
::
|
||||
|
||||
void add_url_seed(std::string const& url);
|
||||
void add_http_seed(std::string const& url);
|
||||
|
||||
This adds a url seed to the torrent. You can have any number of url seeds. For a
|
||||
single file torrent, this should be an HTTP url, pointing to a file with identical
|
||||
|
@ -407,6 +409,8 @@ content as the file of the torrent. For a multi-file torrent, it should point to
|
|||
a directory containing a directory with the same name as this torrent, and all the
|
||||
files of the torrent in it.
|
||||
|
||||
The second function, ``add_http_seed()`` adds an HTTP seed instead.
|
||||
|
||||
add_node()
|
||||
----------
|
||||
|
||||
|
|
|
@ -85,6 +85,7 @@ namespace libtorrent
|
|||
void set_hash(int index, sha1_hash const& h);
|
||||
void set_file_hash(int index, sha1_hash const& h);
|
||||
void add_url_seed(std::string const& url);
|
||||
void add_http_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);
|
||||
void set_priv(bool p) { m_private = p; }
|
||||
|
@ -109,6 +110,7 @@ namespace libtorrent
|
|||
std::vector<announce_entry> m_urls;
|
||||
|
||||
std::vector<std::string> m_url_seeds;
|
||||
std::vector<std::string> m_http_seeds;
|
||||
|
||||
std::vector<sha1_hash> m_piece_hash;
|
||||
|
||||
|
|
|
@ -184,10 +184,15 @@ namespace libtorrent
|
|||
, end(trackers.end()); i != end; ++i)
|
||||
add_tracker(i->url, i->tier);
|
||||
|
||||
std::vector<std::string> const& web_seeds = ti.url_seeds();
|
||||
for (std::vector<std::string>::const_iterator i = web_seeds.begin()
|
||||
std::vector<web_seed_entry> const& web_seeds = ti.web_seeds();
|
||||
for (std::vector<web_seed_entry>::const_iterator i = web_seeds.begin()
|
||||
, end(web_seeds.end()); i != end; ++i)
|
||||
add_url_seed(*i);
|
||||
{
|
||||
if (i->type == web_seed_entry::url_seed)
|
||||
add_url_seed(i->url);
|
||||
else if (i->type == web_seed_entry::http_seed)
|
||||
add_http_seed(i->url);
|
||||
}
|
||||
|
||||
m_piece_hash.resize(m_files.num_pieces());
|
||||
for (int i = 0; i < num_pieces(); ++i) set_hash(i, ti.hash_for_piece(i));
|
||||
|
@ -266,6 +271,23 @@ namespace libtorrent
|
|||
}
|
||||
}
|
||||
|
||||
if (!m_http_seeds.empty())
|
||||
{
|
||||
if (m_http_seeds.size() == 1)
|
||||
{
|
||||
dict["httpseeds"] = m_http_seeds.front();
|
||||
}
|
||||
else
|
||||
{
|
||||
entry& list = dict["httpseeds"];
|
||||
for (std::vector<std::string>::const_iterator i
|
||||
= m_http_seeds.begin(); i != m_http_seeds.end(); ++i)
|
||||
{
|
||||
list.list().push_back(entry(*i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
entry& info = dict["info"];
|
||||
if (m_info_dict.type() == entry::dictionary_t)
|
||||
{
|
||||
|
@ -446,6 +468,11 @@ namespace libtorrent
|
|||
m_url_seeds.push_back(url);
|
||||
}
|
||||
|
||||
void create_torrent::add_http_seed(std::string const& url)
|
||||
{
|
||||
m_http_seeds.push_back(url);
|
||||
}
|
||||
|
||||
void create_torrent::set_comment(char const* str)
|
||||
{
|
||||
m_comment = str;
|
||||
|
|
|
@ -227,7 +227,6 @@ namespace libtorrent
|
|||
request += "-";
|
||||
request += to_string(f.offset + f.size - 1).elems;
|
||||
request += "\r\n\r\n";
|
||||
fprintf(stderr, "REQ: %s\n", request.c_str());
|
||||
m_first_request = false;
|
||||
TORRENT_ASSERT(f.file_index >= 0);
|
||||
m_file_requests.push_back(f.file_index);
|
||||
|
|
Loading…
Reference in New Issue