2008-12-30 04:54:07 +01:00
|
|
|
/*
|
|
|
|
|
2014-02-23 20:12:25 +01:00
|
|
|
Copyright (c) 2008-2014, Arvid Norberg
|
2008-12-30 04:54:07 +01: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 TORRENT_HTTP_SEED_CONNECTION_HPP_INCLUDED
|
|
|
|
#define TORRENT_HTTP_SEED_CONNECTION_HPP_INCLUDED
|
|
|
|
|
|
|
|
#include <ctime>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <deque>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "libtorrent/debug.hpp"
|
|
|
|
|
2015-04-18 04:33:39 +02:00
|
|
|
#include "aux_/disable_warnings_push.hpp"
|
2008-12-30 04:54:07 +01:00
|
|
|
|
|
|
|
#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>
|
|
|
|
|
2015-04-18 04:33:39 +02:00
|
|
|
#include "aux_/disable_warnings_pop.hpp"
|
2008-12-30 04:54:07 +01:00
|
|
|
|
2009-11-23 09:38:50 +01:00
|
|
|
#include "libtorrent/config.hpp"
|
2010-10-10 20:43:58 +02:00
|
|
|
#include "libtorrent/web_connection_base.hpp"
|
2009-11-23 09:38:50 +01:00
|
|
|
#include "libtorrent/disk_buffer_holder.hpp"
|
2008-12-30 04:54:07 +01:00
|
|
|
#include "libtorrent/torrent.hpp"
|
|
|
|
#include "libtorrent/piece_block_progress.hpp"
|
|
|
|
#include "libtorrent/http_parser.hpp"
|
|
|
|
|
|
|
|
namespace libtorrent
|
|
|
|
{
|
|
|
|
class torrent;
|
2009-11-23 09:38:50 +01:00
|
|
|
struct peer_request;
|
2008-12-30 04:54:07 +01:00
|
|
|
|
|
|
|
namespace detail
|
|
|
|
{
|
|
|
|
struct session_impl;
|
|
|
|
}
|
|
|
|
|
2012-03-20 04:53:07 +01:00
|
|
|
class TORRENT_EXTRA_EXPORT http_seed_connection
|
2010-10-10 20:43:58 +02:00
|
|
|
: public web_connection_base
|
2008-12-30 04:54:07 +01:00
|
|
|
{
|
|
|
|
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
|
|
|
http_seed_connection(peer_connection_args const& pack
|
2014-12-31 23:05:34 +01:00
|
|
|
, web_seed_t& web);
|
2008-12-30 04:54:07 +01:00
|
|
|
|
2009-11-02 21:43:38 +01:00
|
|
|
virtual int type() const { return peer_connection::http_seed_connection; }
|
|
|
|
|
2008-12-30 04:54:07 +01:00
|
|
|
// called from the main loop when this connection has any
|
|
|
|
// work to do.
|
|
|
|
void on_receive(error_code const& error
|
|
|
|
, std::size_t bytes_transferred);
|
|
|
|
|
|
|
|
std::string const& url() const { return m_url; }
|
|
|
|
|
|
|
|
virtual void get_specific_peer_info(peer_info& p) const;
|
2015-02-15 06:17:09 +01:00
|
|
|
virtual void disconnect(error_code const& ec, operation_t op, int error = 0);
|
2008-12-30 04:54:07 +01:00
|
|
|
|
|
|
|
void write_request(peer_request const& r);
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
boost::optional<piece_block_progress> downloading_piece_progress() const;
|
|
|
|
|
2010-02-20 17:53:38 +01:00
|
|
|
// this is const since it's used as a key in the web seed list in the torrent
|
|
|
|
// if it's changed referencing back into that list will fail
|
|
|
|
const std::string m_url;
|
2012-05-03 04:05:34 +02:00
|
|
|
|
2014-12-31 23:05:34 +01:00
|
|
|
web_seed_t* m_web;
|
2014-09-28 05:27:13 +02:00
|
|
|
|
2008-12-30 04:54:07 +01:00
|
|
|
// the number of bytes left to receive of the response we're
|
|
|
|
// currently parsing
|
2014-12-03 05:32:50 +01:00
|
|
|
boost::int64_t m_response_left;
|
2010-10-31 04:05:11 +01: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
|
2014-12-03 05:32:50 +01:00
|
|
|
boost::int64_t m_chunk_pos;
|
2010-10-31 04:05:11 +01:00
|
|
|
|
|
|
|
// this is the number of bytes we've already received
|
|
|
|
// from the next chunk header we're waiting for
|
|
|
|
int m_partial_chunk_header;
|
2008-12-30 04:54:07 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // TORRENT_WEB_PEER_CONNECTION_HPP_INCLUDED
|
|
|
|
|