premiere-libtorrent/include/libtorrent/web_peer_connection.hpp

156 lines
5.1 KiB
C++
Raw Normal View History

/*
2015-06-03 07:18:48 +02:00
Copyright (c) 2003-2015, Arvid Norberg
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 TORRENT_WEB_PEER_CONNECTION_HPP_INCLUDED
#define TORRENT_WEB_PEER_CONNECTION_HPP_INCLUDED
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <ctime>
#include <algorithm>
#include <vector>
#include <deque>
#include <string>
#include <boost/smart_ptr.hpp>
#include <boost/weak_ptr.hpp>
#include <boost/noncopyable.hpp>
#include <boost/array.hpp>
#include <boost/optional.hpp>
#include <boost/cstdint.hpp>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#include "libtorrent/config.hpp"
#include "libtorrent/web_connection_base.hpp"
#include "libtorrent/disk_buffer_holder.hpp"
#include "libtorrent/torrent.hpp"
#include "libtorrent/piece_block_progress.hpp"
#include "libtorrent/http_parser.hpp"
#include "libtorrent/operations.hpp" // for operation_t enum
namespace libtorrent
{
class torrent;
class TORRENT_EXTRA_EXPORT web_peer_connection
: public web_connection_base
{
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
web_peer_connection(peer_connection_args const& pack
, web_seed_t& web);
2015-05-05 07:37:01 +02:00
virtual void on_connected() TORRENT_OVERRIDE;
2015-05-05 07:37:01 +02:00
virtual int type() const TORRENT_OVERRIDE
{ return peer_connection::url_seed_connection; }
2009-11-02 21:43:38 +01:00
// called from the main loop when this connection has any
// work to do.
2015-05-05 07:37:01 +02:00
virtual void on_receive(error_code const& error
, std::size_t bytes_transferred) TORRENT_OVERRIDE;
std::string const& url() const TORRENT_OVERRIDE { return m_url; }
2015-05-05 07:37:01 +02:00
virtual void get_specific_peer_info(peer_info& p) const TORRENT_OVERRIDE;
virtual void disconnect(error_code const& ec
2015-05-05 07:37:01 +02:00
, operation_t op, int error = 0) TORRENT_OVERRIDE;
2015-05-05 07:37:01 +02:00
virtual void write_request(peer_request const& r) TORRENT_OVERRIDE;
2015-05-05 07:37:01 +02:00
virtual bool received_invalid_data(int index, bool single_peer) TORRENT_OVERRIDE;
2012-09-29 19:46:41 +02:00
private:
bool maybe_harvest_block();
// returns the block currently being
// downloaded. And the progress of that
// block. If the peer isn't downloading
// a piece for the moment, the boost::optional
// will be invalid.
2015-05-05 07:37:01 +02:00
boost::optional<piece_block_progress> downloading_piece_progress() const TORRENT_OVERRIDE;
void handle_padfile(buffer::const_interval& recv_buffer);
// this has one entry per http-request
// (might be more than the bt requests)
std::deque<int> m_file_requests;
std::string m_url;
web_seed_t* m_web;
// this is used for intermediate storage of pieces
2009-04-11 22:45:14 +02:00
// that are received in more than one HTTP response
2013-01-21 02:40:59 +01:00
// TODO: 1 if we make this be a disk_buffer_holder instead
2012-04-07 02:35:25 +02:00
// we would save a copy sometimes
// use allocate_disk_receive_buffer and release_disk_receive_buffer
std::vector<char> m_piece;
// the number of bytes received in the current HTTP
// response. used to know where in the buffer the
// next response starts
boost::int64_t m_received_body;
// position in the current range response
boost::int64_t m_range_pos;
2009-04-11 22:45:14 +02:00
// this is the offset inside the current receive
// buffer where the next chunk header will be.
// this is updated for each chunk header that's
// parsed. It does not necessarily point to a valid
// offset in the receive buffer, if we haven't received
// it yet. This offset never includes the HTTP header
boost::int64_t m_chunk_pos;
2014-07-06 21:18:00 +02:00
// the position in the current block
int m_block_pos;
// this is the number of bytes we've already received
// from the next chunk header we're waiting for
int m_partial_chunk_header;
// the number of responses we've received so far on
// this connection
int m_num_responses;
};
}
#endif // TORRENT_WEB_PEER_CONNECTION_HPP_INCLUDED