2010-10-10 20:43:58 +02:00
|
|
|
/*
|
|
|
|
|
2016-01-18 00:57:46 +01:00
|
|
|
Copyright (c) 2003-2016, Arvid Norberg
|
2010-10-10 20:43:58 +02:00
|
|
|
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 WEB_CONNECTION_BASE_HPP_INCLUDED
|
|
|
|
#define WEB_CONNECTION_BASE_HPP_INCLUDED
|
|
|
|
|
2015-04-18 04:33:39 +02:00
|
|
|
#include "libtorrent/debug.hpp"
|
|
|
|
|
2015-04-21 03:16:28 +02:00
|
|
|
#include "libtorrent/aux_/disable_warnings_push.hpp"
|
2015-04-18 04:33:39 +02:00
|
|
|
|
2010-10-10 20:43:58 +02:00
|
|
|
#include <ctime>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <vector>
|
|
|
|
#include <deque>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include <boost/smart_ptr.hpp>
|
|
|
|
#include <boost/weak_ptr.hpp>
|
|
|
|
#include <boost/noncopyable.hpp>
|
2016-05-01 05:10:47 +02:00
|
|
|
#include <array>
|
2010-10-10 20:43:58 +02:00
|
|
|
#include <boost/optional.hpp>
|
|
|
|
#include <boost/cstdint.hpp>
|
|
|
|
|
2015-04-21 03:16:28 +02:00
|
|
|
#include "libtorrent/aux_/disable_warnings_pop.hpp"
|
2010-10-10 20:43:58 +02:00
|
|
|
|
|
|
|
#include "libtorrent/buffer.hpp"
|
|
|
|
#include "libtorrent/peer_connection.hpp"
|
|
|
|
#include "libtorrent/socket.hpp"
|
|
|
|
#include "libtorrent/peer_id.hpp"
|
|
|
|
#include "libtorrent/storage.hpp"
|
|
|
|
#include "libtorrent/stat.hpp"
|
|
|
|
#include "libtorrent/alert.hpp"
|
|
|
|
#include "libtorrent/torrent_handle.hpp"
|
|
|
|
#include "libtorrent/torrent.hpp"
|
|
|
|
#include "libtorrent/peer_request.hpp"
|
|
|
|
#include "libtorrent/piece_block_progress.hpp"
|
|
|
|
#include "libtorrent/config.hpp"
|
|
|
|
// parse_url
|
|
|
|
#include "libtorrent/tracker_manager.hpp"
|
|
|
|
#include "libtorrent/http_parser.hpp"
|
|
|
|
|
|
|
|
namespace libtorrent
|
|
|
|
{
|
|
|
|
class torrent;
|
|
|
|
|
2012-03-19 00:31:04 +01:00
|
|
|
class TORRENT_EXTRA_EXPORT web_connection_base
|
2010-10-10 20:43:58 +02:00
|
|
|
: public peer_connection
|
|
|
|
{
|
|
|
|
friend class invariant_access;
|
|
|
|
public:
|
|
|
|
|
|
|
|
// this is the constructor where the we are the active part.
|
|
|
|
// The peer_conenction should handshake and verify that the
|
|
|
|
// other end has the correct id
|
2014-07-14 06:32:41 +02:00
|
|
|
web_connection_base(peer_connection_args const& pack
|
2014-12-31 23:05:34 +01:00
|
|
|
, web_seed_t& web);
|
2014-07-06 21:18:00 +02:00
|
|
|
|
|
|
|
virtual int timeout() const;
|
2010-10-10 20:43:58 +02:00
|
|
|
void start();
|
|
|
|
|
|
|
|
~web_connection_base();
|
|
|
|
|
|
|
|
// called from the main loop when this connection has any
|
|
|
|
// work to do.
|
|
|
|
void on_sent(error_code const& error
|
|
|
|
, std::size_t bytes_transferred);
|
|
|
|
|
|
|
|
virtual std::string const& url() const = 0;
|
2015-12-14 01:44:42 +01:00
|
|
|
|
2010-10-10 20:43:58 +02:00
|
|
|
bool in_handshake() const;
|
|
|
|
|
|
|
|
// the following functions appends messages
|
|
|
|
// to the send buffer
|
|
|
|
void write_choke() {}
|
|
|
|
void write_unchoke() {}
|
|
|
|
void write_interested() {}
|
|
|
|
void write_not_interested() {}
|
2014-07-07 08:28:48 +02:00
|
|
|
virtual void write_request(peer_request const&) = 0;
|
|
|
|
void write_cancel(peer_request const&) {}
|
|
|
|
void write_have(int) {}
|
|
|
|
void write_dont_have(int) {}
|
|
|
|
void write_piece(peer_request const&, disk_buffer_holder&)
|
2016-05-02 18:36:21 +02:00
|
|
|
{ TORRENT_ASSERT_FAIL(); }
|
2010-10-10 20:43:58 +02:00
|
|
|
void write_keepalive() {}
|
|
|
|
void on_connected();
|
|
|
|
void write_reject_request(peer_request const&) {}
|
|
|
|
void write_allow_fast(int) {}
|
2014-07-07 08:28:48 +02:00
|
|
|
void write_suggest(int) {}
|
2014-07-06 21:18:00 +02:00
|
|
|
void write_bitfield() {}
|
2010-10-10 20:43:58 +02:00
|
|
|
|
2014-01-21 20:26:09 +01:00
|
|
|
#if TORRENT_USE_INVARIANT_CHECKS
|
2010-10-10 20:43:58 +02:00
|
|
|
void check_invariant() const;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
virtual void get_specific_peer_info(peer_info& p) const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
virtual void add_headers(std::string& request
|
2014-07-06 21:18:00 +02:00
|
|
|
, aux::session_settings const& sett, bool using_proxy) const;
|
|
|
|
|
|
|
|
// the first request will contain a little bit more data
|
|
|
|
// than subsequent ones, things that aren't critical are left
|
|
|
|
// out to save bandwidth.
|
|
|
|
bool m_first_request;
|
2010-10-10 20:43:58 +02:00
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
// true if we're using ssl
|
|
|
|
bool m_ssl;
|
2015-12-14 01:44:42 +01:00
|
|
|
|
2010-10-10 20:43:58 +02:00
|
|
|
// this has one entry per bittorrent request
|
|
|
|
std::deque<peer_request> m_requests;
|
|
|
|
|
|
|
|
std::string m_server_string;
|
|
|
|
std::string m_basic_auth;
|
|
|
|
std::string m_host;
|
|
|
|
std::string m_path;
|
|
|
|
|
|
|
|
std::string m_external_auth;
|
|
|
|
web_seed_entry::headers_t m_extra_headers;
|
2015-12-14 01:44:42 +01:00
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
http_parser m_parser;
|
|
|
|
|
|
|
|
int m_port;
|
2010-10-12 10:57:43 +02:00
|
|
|
|
2010-10-10 20:43:58 +02:00
|
|
|
// the number of bytes into the receive buffer where
|
|
|
|
// current read cursor is.
|
|
|
|
int m_body_start;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // TORRENT_WEB_CONNECTION_BASE_HPP_INCLUDED
|
|
|
|
|