From 092362e9bc1a73d1bc20d1c3d5d87afc6640b750 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Wed, 31 Dec 2014 22:05:34 +0000 Subject: [PATCH] remove internal fields from web_seed_entry --- ChangeLog | 1 + include/libtorrent/http_seed_connection.hpp | 4 +- include/libtorrent/torrent.hpp | 66 ++++++++++++++---- include/libtorrent/torrent_info.hpp | 39 +---------- include/libtorrent/web_connection_base.hpp | 2 +- include/libtorrent/web_peer_connection.hpp | 4 +- src/http_seed_connection.cpp | 2 +- src/torrent.cpp | 75 +++++++++++++++------ src/torrent_info.cpp | 7 -- src/web_connection_base.cpp | 2 +- src/web_peer_connection.cpp | 2 +- 11 files changed, 116 insertions(+), 88 deletions(-) diff --git a/ChangeLog b/ChangeLog index e2bcd00c1..e44aa440e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + * remove internal fields from web_seed_entry * separate crypto library configuration and whether to support bittorrent protocol encryption * simplify bittorrent protocol encryption by just using internal RC4 diff --git a/include/libtorrent/http_seed_connection.hpp b/include/libtorrent/http_seed_connection.hpp index 066f0459c..ece144957 100644 --- a/include/libtorrent/http_seed_connection.hpp +++ b/include/libtorrent/http_seed_connection.hpp @@ -82,7 +82,7 @@ namespace libtorrent // The peer_conenction should handshake and verify that the // other end has the correct id http_seed_connection(peer_connection_args const& pack - , web_seed_entry& web); + , web_seed_t& web); virtual int type() const { return peer_connection::http_seed_connection; } @@ -111,7 +111,7 @@ namespace libtorrent // if it's changed referencing back into that list will fail const std::string m_url; - web_seed_entry* m_web; + web_seed_t* m_web; // the number of bytes left to receive of the response we're // currently parsing diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 397e46230..25915ad81 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -142,6 +142,49 @@ namespace libtorrent { return deadline < rhs.deadline; } }; + // this is the internal representation of web seeds + struct web_seed_t : web_seed_entry + { + web_seed_t(web_seed_entry const& wse); + web_seed_t(std::string const& url_, web_seed_entry::type_t type_ + , std::string const& auth_ = std::string() + , web_seed_entry::headers_t const& extra_headers_ = web_seed_entry::headers_t()); + + // if this is > now, we can't reconnect yet + ptime retry; + + // if the hostname of the web seed has been resolved, + // these are its IP addresses + std::vector endpoints; + + // this is the peer_info field used for the + // connection, just to count hash failures + // it's also used to hold the peer_connection + // pointer, when the web seed is connected + ipv4_peer peer_info; + + // this is initialized to true, but if we discover the + // server not to support it, it's set to false, and we + // make larger requests. + bool supports_keepalive; + + // this indicates whether or not we're resolving the + // hostname of this URL + bool resolving; + + // if the user wanted to remove this while + // we were resolving it. In this case, we set + // the removed flag to true, to make the resolver + // callback remove it + bool removed; + + // if the web server doesn't support keepalive or a block request was + // interrupted, the block received so far is kept here for the next + // connection to pick up + peer_request restart_request; + std::vector restart_piece; + }; + struct torrent_hot_members { torrent_hot_members(aux::session_interface& ses @@ -520,7 +563,7 @@ namespace libtorrent void use_interface(std::string net_interface); #endif - void connect_to_url_seed(std::list::iterator url); + void connect_to_url_seed(std::list::iterator url); bool connect_to_peer(torrent_peer* peerinfo, bool ignore_limit = false); int priority() const { return m_priority; } @@ -563,11 +606,11 @@ namespace libtorrent // add or remove a url that will be attempted for // finding the file(s) in this torrent. - void add_web_seed(std::string const& url, web_seed_entry::type_t type); - void add_web_seed(std::string const& url, web_seed_entry::type_t type - , std::string const& auth, web_seed_entry::headers_t const& extra_headers); + void add_web_seed(std::string const& url, web_seed_t::type_t type); + void add_web_seed(std::string const& url, web_seed_t::type_t type + , std::string const& auth, web_seed_t::headers_t const& extra_headers); - void remove_web_seed(std::string const& url, web_seed_entry::type_t type); + void remove_web_seed(std::string const& url, web_seed_t::type_t type); void disconnect_web_seed(peer_connection* p); void retry_web_seed(peer_connection* p, int retry = 0); @@ -575,9 +618,6 @@ namespace libtorrent void remove_web_seed(peer_connection* p, error_code const& ec , peer_connection_interface::operation_t op, int error = 0); - std::list web_seeds() const - { return m_web_seeds; } - std::set web_seeds(web_seed_entry::type_t type) const; bool free_upload_slots() const @@ -832,15 +872,15 @@ namespace libtorrent void on_name_lookup(error_code const& e , std::vector
const& addrs , int port - , std::list::iterator web, tcp::endpoint proxy); + , std::list::iterator web, tcp::endpoint proxy); - void connect_web_seed(std::list::iterator web, tcp::endpoint a); + void connect_web_seed(std::list::iterator web, tcp::endpoint a); // this is the asio callback that is called when a name // lookup for a proxy for a web seed is completed. void on_proxy_name_lookup(error_code const& e , std::vector
const& addrs - , std::list::iterator web, int port); + , std::list::iterator web, int port); // re-evaluates whether this torrent should be considered inactive or not void on_inactivity_tick(error_code const& ec); @@ -852,7 +892,7 @@ namespace libtorrent // remove a web seed, or schedule it for removal in case there // are outstanding operations on it - void remove_web_seed(std::list::iterator web); + void remove_web_seed(std::list::iterator web); // this is called when the torrent has finished. i.e. // all the pieces we have not filtered have been downloaded. @@ -1188,7 +1228,7 @@ namespace libtorrent // The list of web seeds in this torrent. Seeds // with fatal errors are removed from the set - std::list m_web_seeds; + std::list m_web_seeds; #ifndef TORRENT_DISABLE_EXTENSIONS typedef std::list > extension_list_t; diff --git a/include/libtorrent/torrent_info.hpp b/include/libtorrent/torrent_info.hpp index 37feb2e82..14cbda2b5 100644 --- a/include/libtorrent/torrent_info.hpp +++ b/include/libtorrent/torrent_info.hpp @@ -219,9 +219,6 @@ namespace libtorrent void trim(); }; - // TODO: 3 this type should be different from the one used by torrent. It - // should not include internal state. - // the web_seed_entry holds information about a web seed (also known // as URL seed or HTTP seed). It is essentially a URL with some state // associated with it. For more information, see `BEP 17`_ and `BEP 19`_. @@ -261,42 +258,8 @@ namespace libtorrent // Any extra HTTP headers that need to be passed to the web seed headers_t extra_headers; - // if this is > now, we can't reconnect yet - ptime retry; - - // if the hostname of the web seed has been resolved, - // these are its IP addresses - std::vector endpoints; - - // this is the peer_info field used for the - // connection, just to count hash failures - // it's also used to hold the peer_connection - // pointer, when the web seed is connected - ipv4_peer peer_info; - // The type of web seed (see type_t) boost::uint8_t type; - - // this is initialized to true, but if we discover the - // server not to support it, it's set to false, and we - // make larger requests. - bool supports_keepalive; - - // this indicates whether or not we're resolving the - // hostname of this URL - bool resolving; - - // if the user wanted to remove this while - // we were resolving it. In this case, we set - // the removed flag to true, to make the resolver - // callback remove it - bool removed; - - // if the web server doesn't support keepalive or a block request was - // interrupted, the block received so far is kept here for the next - // connection to pick up - peer_request restart_request; - std::vector restart_piece; }; #ifndef BOOST_NO_EXCEPTIONS @@ -304,7 +267,7 @@ namespace libtorrent typedef libtorrent_exception invalid_torrent_file; #endif - // TODO: 2 there may be some opportunities to optimize the size if torrent_info. + // TODO: there may be some opportunities to optimize the size if torrent_info. // specifically to turn some std::string and std::vector into pointers class TORRENT_EXPORT torrent_info { diff --git a/include/libtorrent/web_connection_base.hpp b/include/libtorrent/web_connection_base.hpp index d53ab0405..8dfd58e82 100644 --- a/include/libtorrent/web_connection_base.hpp +++ b/include/libtorrent/web_connection_base.hpp @@ -86,7 +86,7 @@ namespace libtorrent // The peer_conenction should handshake and verify that the // other end has the correct id web_connection_base(peer_connection_args const& pack - , web_seed_entry& web); + , web_seed_t& web); virtual int timeout() const; void start(); diff --git a/include/libtorrent/web_peer_connection.hpp b/include/libtorrent/web_peer_connection.hpp index b9f062d59..945329782 100644 --- a/include/libtorrent/web_peer_connection.hpp +++ b/include/libtorrent/web_peer_connection.hpp @@ -75,7 +75,7 @@ namespace libtorrent // The peer_conenction should handshake and verify that the // other end has the correct id web_peer_connection(peer_connection_args const& pack - , web_seed_entry& web); + , web_seed_t& web); virtual void on_connected(); @@ -114,7 +114,7 @@ namespace libtorrent std::string m_url; - web_seed_entry* m_web; + web_seed_t* m_web; // this is used for intermediate storage of pieces // that are received in more than one HTTP response diff --git a/src/http_seed_connection.cpp b/src/http_seed_connection.cpp index 54ea8a110..995660ad7 100644 --- a/src/http_seed_connection.cpp +++ b/src/http_seed_connection.cpp @@ -53,7 +53,7 @@ using libtorrent::aux::session_impl; namespace libtorrent { http_seed_connection::http_seed_connection(peer_connection_args const& pack - , web_seed_entry& web) + , web_seed_t& web) : web_connection_base(pack, web) , m_url(web.url) , m_web(&web) diff --git a/src/torrent.cpp b/src/torrent.cpp index 74d5d51eb..575fd57e9 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -122,6 +122,32 @@ namespace libtorrent return ret; } + web_seed_t::web_seed_t(web_seed_entry const& wse) + : web_seed_entry(wse) + , retry(time_now()) + , peer_info(tcp::endpoint(), true, 0) + , supports_keepalive(true) + , resolving(false) + , removed(false) + { + peer_info.web_seed = true; + restart_request.piece = -1; + } + + web_seed_t::web_seed_t(std::string const& url_, web_seed_entry::type_t type_ + , std::string const& auth_ + , web_seed_entry::headers_t const& extra_headers_) + : web_seed_entry(url_, type_, auth_, extra_headers_) + , retry(time_now()) + , peer_info(tcp::endpoint(), true, 0) + , supports_keepalive(true) + , resolving(false) + , removed(false) + { + peer_info.web_seed = true; + restart_request.piece = -1; + } + #ifndef TORRENT_DISABLE_EXTENSIONS // defined in ut_pex.cpp bool was_introduced_by(peer_plugin const*, tcp::endpoint const&); @@ -277,7 +303,7 @@ namespace libtorrent for (std::vector::const_iterator i = p.url_seeds.begin() , end(p.url_seeds.end()); i != end; ++i) { - m_web_seeds.push_back(web_seed_entry(*i, web_seed_entry::url_seed)); + m_web_seeds.push_back(web_seed_t(*i, web_seed_entry::url_seed)); } m_trackers = m_torrent_file->trackers(); @@ -5847,7 +5873,7 @@ namespace libtorrent update_want_tick(); } - void torrent::remove_web_seed(std::list::iterator web) + void torrent::remove_web_seed(std::list::iterator web) { if (web->resolving) { @@ -5859,7 +5885,7 @@ namespace libtorrent { // if we have a connection for this web seed, we also need to // disconnect it and clear its reference to the peer_info object - // that's part of the web_seed_entry we're about to remove + // that's part of the web_seed_t we're about to remove TORRENT_ASSERT(peer->m_in_use == 1337); peer->disconnect(boost::asio::error::operation_aborted , peer_connection_interface::op_bittorrent); @@ -5871,7 +5897,7 @@ namespace libtorrent update_want_tick(); } - void torrent::connect_to_url_seed(std::list::iterator web) + void torrent::connect_to_url_seed(std::list::iterator web) { TORRENT_ASSERT(is_single_thread()); INVARIANT_CHECK; @@ -6024,7 +6050,7 @@ namespace libtorrent void torrent::on_proxy_name_lookup(error_code const& e , std::vector
const& addrs - , std::list::iterator web, int port) + , std::list::iterator web, int port) { TORRENT_ASSERT(is_single_thread()); @@ -6108,7 +6134,7 @@ namespace libtorrent void torrent::on_name_lookup(error_code const& e , std::vector
const& addrs , int port - , std::list::iterator web + , std::list::iterator web , tcp::endpoint proxy) { TORRENT_ASSERT(is_single_thread()); @@ -6163,7 +6189,7 @@ namespace libtorrent connect_web_seed(web, web->endpoints.front()); } - void torrent::connect_web_seed(std::list::iterator web, tcp::endpoint a) + void torrent::connect_web_seed(std::list::iterator web, tcp::endpoint a) { INVARIANT_CHECK; @@ -6856,7 +6882,7 @@ namespace libtorrent { entry::list_type& url_list = ret["url-list"].list(); entry::list_type& httpseed_list = ret["httpseeds"].list(); - for (std::list::const_iterator i = m_web_seeds.begin() + for (std::list::const_iterator i = m_web_seeds.begin() , end(m_web_seeds.end()); i != end; ++i) { if (i->type == web_seed_entry::url_seed) @@ -9188,7 +9214,7 @@ namespace libtorrent // finding the file(s) in this torrent. void torrent::add_web_seed(std::string const& url, web_seed_entry::type_t type) { - web_seed_entry ent(url, type); + web_seed_t ent(url, type); // don't add duplicates if (std::find(m_web_seeds.begin(), m_web_seeds.end(), ent) != m_web_seeds.end()) return; m_web_seeds.push_back(ent); @@ -9198,7 +9224,7 @@ namespace libtorrent void torrent::add_web_seed(std::string const& url, web_seed_entry::type_t type , std::string const& auth, web_seed_entry::headers_t const& extra_headers) { - web_seed_entry ent(url, type, auth, extra_headers); + web_seed_t ent(url, type, auth, extra_headers); // don't add duplicates if (std::find(m_web_seeds.begin(), m_web_seeds.end(), ent) != m_web_seeds.end()) return; m_web_seeds.push_back(ent); @@ -9712,10 +9738,10 @@ namespace libtorrent { // keep trying web-seeds if there are any // first find out which web seeds we are connected to - for (std::list::iterator i = m_web_seeds.begin(); + for (std::list::iterator i = m_web_seeds.begin(); i != m_web_seeds.end();) { - std::list::iterator w = i++; + std::list::iterator w = i++; if (w->peer_info.connection) continue; if (w->retry > time_now()) continue; if (w->resolving) continue; @@ -10528,7 +10554,7 @@ namespace libtorrent { TORRENT_ASSERT(is_single_thread()); std::set ret; - for (std::list::const_iterator i = m_web_seeds.begin() + for (std::list::const_iterator i = m_web_seeds.begin() , end(m_web_seeds.end()); i != end; ++i) { if (i->peer_info.banned) continue; @@ -10540,18 +10566,19 @@ namespace libtorrent void torrent::remove_web_seed(std::string const& url, web_seed_entry::type_t type) { - std::list::iterator i = std::find_if(m_web_seeds.begin(), m_web_seeds.end() - , (boost::bind(&web_seed_entry::url, _1) - == url && boost::bind(&web_seed_entry::type, _1) == type)); + std::list::iterator i = std::find_if(m_web_seeds.begin() + , m_web_seeds.end() + , (boost::bind(&web_seed_t::url, _1) + == url && boost::bind(&web_seed_t::type, _1) == type)); if (i != m_web_seeds.end()) remove_web_seed(i); } void torrent::disconnect_web_seed(peer_connection* p) { - std::list::iterator i + std::list::iterator i = std::find_if(m_web_seeds.begin(), m_web_seeds.end() , (boost::bind(&torrent_peer::connection - , boost::bind(&web_seed_entry::peer_info, _1)) == p)); + , boost::bind(&web_seed_t::peer_info, _1)) == p)); // this happens if the web server responded with a redirect // or with something incorrect, so that we removed the web seed @@ -10570,8 +10597,10 @@ namespace libtorrent void torrent::remove_web_seed(peer_connection* p, error_code const& ec , peer_connection_interface::operation_t op, int error) { - std::list::iterator i = std::find_if(m_web_seeds.begin(), m_web_seeds.end() - , (boost::bind(&torrent_peer::connection, boost::bind(&web_seed_entry::peer_info, _1)) == p)); + std::list::iterator i = std::find_if(m_web_seeds.begin() + , m_web_seeds.end() + , boost::bind(&torrent_peer::connection + , boost::bind(&web_seed_t::peer_info, _1)) == p); TORRENT_ASSERT(i != m_web_seeds.end()); if (i == m_web_seeds.end()) return; if (i->peer_info.connection) i->peer_info.connection->disconnect(ec, op, error); @@ -10584,8 +10613,10 @@ namespace libtorrent void torrent::retry_web_seed(peer_connection* p, int retry) { TORRENT_ASSERT(is_single_thread()); - std::list::iterator i = std::find_if(m_web_seeds.begin(), m_web_seeds.end() - , (boost::bind(&torrent_peer::connection, boost::bind(&web_seed_entry::peer_info, _1)) == p)); + std::list::iterator i = std::find_if(m_web_seeds.begin() + , m_web_seeds.end() + , boost::bind(&torrent_peer::connection + , boost::bind(&web_seed_t::peer_info, _1)) == p); TORRENT_ASSERT(i != m_web_seeds.end()); if (i == m_web_seeds.end()) return; diff --git a/src/torrent_info.cpp b/src/torrent_info.cpp index 7e3e2c2ac..c6d6a539a 100644 --- a/src/torrent_info.cpp +++ b/src/torrent_info.cpp @@ -665,15 +665,8 @@ namespace libtorrent : url(url_) , auth(auth_) , extra_headers(extra_headers_) - , retry(time_now()) - , peer_info(tcp::endpoint(), true, 0) , type(type_) - , supports_keepalive(true) - , resolving(false) - , removed(false) { - peer_info.web_seed = true; - restart_request.piece = -1; } torrent_info::torrent_info(torrent_info const& t) diff --git a/src/web_connection_base.cpp b/src/web_connection_base.cpp index d4c536433..c19e844f8 100644 --- a/src/web_connection_base.cpp +++ b/src/web_connection_base.cpp @@ -53,7 +53,7 @@ namespace libtorrent { web_connection_base::web_connection_base( peer_connection_args const& pack - , web_seed_entry& web) + , web_seed_t& web) : peer_connection(pack) , m_first_request(true) , m_ssl(false) diff --git a/src/web_peer_connection.cpp b/src/web_peer_connection.cpp index c50fb233c..8dda71c31 100644 --- a/src/web_peer_connection.cpp +++ b/src/web_peer_connection.cpp @@ -61,7 +61,7 @@ enum struct disk_interface; web_peer_connection::web_peer_connection(peer_connection_args const& pack - , web_seed_entry& web) + , web_seed_t& web) : web_connection_base(pack, web) , m_url(web.url) , m_web(&web)