remove internal fields from web_seed_entry

This commit is contained in:
Arvid Norberg 2014-12-31 22:05:34 +00:00
parent 73a2a4e51d
commit 092362e9bc
11 changed files with 116 additions and 88 deletions

View File

@ -1,3 +1,4 @@
* remove internal fields from web_seed_entry
* separate crypto library configuration <crypto> and whether to support
bittorrent protocol encryption <encryption>
* simplify bittorrent protocol encryption by just using internal RC4

View File

@ -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

View File

@ -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<tcp::endpoint> 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<char> 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<web_seed_entry>::iterator url);
void connect_to_url_seed(std::list<web_seed_t>::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_seed_entry> web_seeds() const
{ return m_web_seeds; }
std::set<std::string> 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<address> const& addrs
, int port
, std::list<web_seed_entry>::iterator web, tcp::endpoint proxy);
, std::list<web_seed_t>::iterator web, tcp::endpoint proxy);
void connect_web_seed(std::list<web_seed_entry>::iterator web, tcp::endpoint a);
void connect_web_seed(std::list<web_seed_t>::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<address> const& addrs
, std::list<web_seed_entry>::iterator web, int port);
, std::list<web_seed_t>::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<web_seed_entry>::iterator web);
void remove_web_seed(std::list<web_seed_t>::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<web_seed_entry> m_web_seeds;
std::list<web_seed_t> m_web_seeds;
#ifndef TORRENT_DISABLE_EXTENSIONS
typedef std::list<boost::shared_ptr<torrent_plugin> > extension_list_t;

View File

@ -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<tcp::endpoint> 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<char> 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
{

View File

@ -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();

View File

@ -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

View File

@ -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)

View File

@ -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<std::string>::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<web_seed_entry>::iterator web)
void torrent::remove_web_seed(std::list<web_seed_t>::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<web_seed_entry>::iterator web)
void torrent::connect_to_url_seed(std::list<web_seed_t>::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<address> const& addrs
, std::list<web_seed_entry>::iterator web, int port)
, std::list<web_seed_t>::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<address> const& addrs
, int port
, std::list<web_seed_entry>::iterator web
, std::list<web_seed_t>::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<web_seed_entry>::iterator web, tcp::endpoint a)
void torrent::connect_web_seed(std::list<web_seed_t>::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<web_seed_entry>::const_iterator i = m_web_seeds.begin()
for (std::list<web_seed_t>::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<web_seed_entry>::iterator i = m_web_seeds.begin();
for (std::list<web_seed_t>::iterator i = m_web_seeds.begin();
i != m_web_seeds.end();)
{
std::list<web_seed_entry>::iterator w = i++;
std::list<web_seed_t>::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<std::string> ret;
for (std::list<web_seed_entry>::const_iterator i = m_web_seeds.begin()
for (std::list<web_seed_t>::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<web_seed_entry>::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<web_seed_t>::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<web_seed_entry>::iterator i
std::list<web_seed_t>::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<web_seed_entry>::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<web_seed_t>::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<web_seed_entry>::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<web_seed_t>::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;

View File

@ -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)

View File

@ -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)

View File

@ -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)