From 43b29c3627a55a13ce18897e55d59deb209568e9 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 10 Oct 2010 21:06:35 +0000 Subject: [PATCH] support web seeds in create_torrent and fix issue when building without deprecated functions --- docs/make_torrent.rst | 8 +++++-- include/libtorrent/create_torrent.hpp | 2 ++ src/create_torrent.cpp | 33 ++++++++++++++++++++++++--- src/web_peer_connection.cpp | 1 - 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/docs/make_torrent.rst b/docs/make_torrent.rst index 611edf379..8875f12ea 100644 --- a/docs/make_torrent.rst +++ b/docs/make_torrent.rst @@ -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 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() ---------- diff --git a/include/libtorrent/create_torrent.hpp b/include/libtorrent/create_torrent.hpp index 85a1a9e4c..e15d4b10a 100644 --- a/include/libtorrent/create_torrent.hpp +++ b/include/libtorrent/create_torrent.hpp @@ -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 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 m_urls; std::vector m_url_seeds; + std::vector m_http_seeds; std::vector m_piece_hash; diff --git a/src/create_torrent.cpp b/src/create_torrent.cpp index 61dd39dff..aac307d1e 100644 --- a/src/create_torrent.cpp +++ b/src/create_torrent.cpp @@ -184,10 +184,15 @@ namespace libtorrent , end(trackers.end()); i != end; ++i) add_tracker(i->url, i->tier); - std::vector const& web_seeds = ti.url_seeds(); - for (std::vector::const_iterator i = web_seeds.begin() + std::vector const& web_seeds = ti.web_seeds(); + for (std::vector::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::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; diff --git a/src/web_peer_connection.cpp b/src/web_peer_connection.cpp index 0b023deb0..8dca306cb 100644 --- a/src/web_peer_connection.cpp +++ b/src/web_peer_connection.cpp @@ -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);