This commit is contained in:
Arvid Norberg 2005-08-25 13:11:39 +00:00
parent 663764a49a
commit 52e9eadb4e
15 changed files with 73 additions and 74 deletions

View File

@ -1,5 +1,4 @@
modified release 0.901
* rename http_settings class as http_proxy class for compatible socks4/5 proxy later.(by spyhole)
Initial release 0.9
* multitracker support

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
@ -89,7 +89,7 @@
<li><a class="reference" href="#torrent-status" id="id74" name="id74">torrent_status</a></li>
<li><a class="reference" href="#peer-info" id="id75" name="id75">peer_info</a></li>
<li><a class="reference" href="#address" id="id76" name="id76">address</a></li>
<li><a class="reference" href="#http-proxy" id="id77" name="id77">http_proxy</a></li>
<li><a class="reference" href="#http-settings" id="id77" name="id77">http_settings</a></li>
<li><a class="reference" href="#ip-filter" id="id78" name="id78">ip_filter</a><ul>
<li><a class="reference" href="#id14" id="id79" name="id79">ip_filter()</a></li>
<li><a class="reference" href="#add-rule" id="id80" name="id80">add_rule()</a></li>
@ -542,7 +542,7 @@ class session: public boost::noncopyable
void disable_extensions();
void enable_extension(peer_connection::extension_index);
void set_http_proxy(const http_proxy&amp; http_proxy);
void set_http_settings(const http_settings&amp; settings);
void set_upload_rate_limit(int bytes_per_second);
void set_download_rate_limit(int bytes_per_second);
@ -591,7 +591,7 @@ the parameters, see <tt class="docutils literal"><span class="pre">listen_on()</
If some trackers are down, they will time out. All this before the destructor of session
returns. So, it's adviced that any kind of interface (such as windows) are closed before
destructing the sessoin object. Because it can take a few second for it to finish. The
timeout can be set with <tt class="docutils literal"><span class="pre">set_http_proxy()</span></tt>.</p>
timeout can be set with <tt class="docutils literal"><span class="pre">set_http_settings()</span></tt>.</p>
</div>
<div class="section" id="add-torrent">
<h2><a name="add-torrent">add_torrent()</a></h2>
@ -1790,15 +1790,15 @@ while it does the DNS lookup, it returns a string that points to the address rep
<p><tt class="docutils literal"><span class="pre">ip()</span></tt> will return the 32-bit ip-address as an integer. <tt class="docutils literal"><span class="pre">port()</span></tt> returns the port number.</p>
</div>
<div class="section" id="http-settings">
<h1><a name="http-proxy">http_proxy</a></h1>
<p>You have some control over tracker requests through the <tt class="docutils literal"><span class="pre">http_proxy</span></tt> object. You
create it and fill it with your http-proxy and then use <tt class="docutils literal"><span class="pre">session::set_http_proxy()</span></tt>
<h1><a name="http-settings">http_settings</a></h1>
<p>You have some control over tracker requests through the <tt class="docutils literal"><span class="pre">http_settings</span></tt> object. You
create it and fill it with your settings and then use <tt class="docutils literal"><span class="pre">session::set_http_settings()</span></tt>
to apply them. You have control over proxy and authorization settings and also the user-agent
that will be sent to the tracker. The user-agent is a good way to identify your client.</p>
<pre class="literal-block">
struct http_proxy
struct http_settings
{
http_proxy();
http_settings();
std::string proxy_ip;
int proxy_port;
std::string proxy_login;
@ -2563,7 +2563,7 @@ int main(int argc, char* argv[])
#include &quot;libtorrent/entry.hpp&quot;
#include &quot;libtorrent/bencode.hpp&quot;
#include &quot;libtorrent/session.hpp&quot;
#include &quot;libtorrent/http_proxy.hpp&quot;
#include &quot;libtorrent/http_settings.hpp&quot;
int main(int argc, char* argv[])
{

View File

@ -420,7 +420,7 @@ The ``session`` class has the following synopsis::
void disable_extensions();
void enable_extension(peer_connection::extension_index);
void set_http_proxy(const http_proxy& http_proxy);
void set_http_settings(const http_settings& settings);
void set_upload_rate_limit(int bytes_per_second);
void set_download_rate_limit(int bytes_per_second);
@ -471,7 +471,7 @@ The destructor of session will notify all trackers that our torrents have been s
If some trackers are down, they will time out. All this before the destructor of session
returns. So, it's adviced that any kind of interface (such as windows) are closed before
destructing the sessoin object. Because it can take a few second for it to finish. The
timeout can be set with ``set_http_proxy()``.
timeout can be set with ``set_http_settings()``.
add_torrent()
@ -1768,19 +1768,19 @@ while it does the DNS lookup, it returns a string that points to the address rep
http_proxy
http_settings
=============
You have some control over tracker requests through the ``http_proxy`` object. You
create it and fill it with your settings and then use ``session::set_http_proxy()``
You have some control over tracker requests through the ``http_settings`` object. You
create it and fill it with your settings and then use ``session::set_http_settings()``
to apply them. You have control over proxy and authorization settings and also the user-agent
that will be sent to the tracker. The user-agent is a good way to identify your client.
::
struct http_proxy
struct http_settings
{
http_proxy();
http_settings();
std::string proxy_ip;
int proxy_port;
std::string proxy_login;
@ -2643,7 +2643,7 @@ This is a simple client. It doesn't have much output to keep it simple::
#include "libtorrent/entry.hpp"
#include "libtorrent/bencode.hpp"
#include "libtorrent/session.hpp"
#include "libtorrent/http_proxy.hpp"
#include "libtorrent/http_settings.hpp"
int main(int argc, char* argv[])
{

View File

@ -51,7 +51,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/entry.hpp"
#include "libtorrent/bencode.hpp"
#include "libtorrent/session.hpp"
#include "libtorrent/http_proxy.hpp"
#include "libtorrent/http_settings.hpp"
#include "libtorrent/identify_client.hpp"
#include "libtorrent/alert_types.hpp"
@ -108,17 +108,17 @@ struct set_keypress
{
set_keypress()
{
termios new_http_proxy;
tcgetattr(0,&stored_http_proxy);
new_http_proxy = stored_http_proxy;
termios new_settings;
tcgetattr(0,&stored_settings);
new_settings = stored_settings;
// Disable canonical mode, and set buffer size to 1 byte
new_http_proxy.c_lflag &= (~ICANON);
new_http_proxy.c_cc[VTIME] = 0;
new_http_proxy.c_cc[VMIN] = 1;
tcsetattr(0,TCSANOW,&new_http_proxy);
new_settings.c_lflag &= (~ICANON);
new_settings.c_cc[VTIME] = 0;
new_settings.c_cc[VMIN] = 1;
tcsetattr(0,TCSANOW,&new_settings);
}
~set_keypress() { tcsetattr(0,TCSANOW,&stored_http_proxy); }
termios stored_http_proxy;
~set_keypress() { tcsetattr(0,TCSANOW,&stored_settings); }
termios stored_settings;
};
bool sleep_and_input(char* c)
@ -303,12 +303,12 @@ int main(int argc, char* argv[])
namespace fs = boost::filesystem;
fs::path::default_name_check(fs::no_check);
http_proxy http_proxy;
// http_proxy.proxy_ip = "192.168.0.1";
// http_proxy.proxy_port = 80;
// http_proxy.proxy_login = "hyd";
// http_proxy.proxy_password = "foobar";
http_proxy.user_agent = "client_test";
http_settings settings;
// settings.proxy_ip = "192.168.0.1";
// settings.proxy_port = 80;
// settings.proxy_login = "hyd";
// settings.proxy_password = "foobar";
settings.user_agent = "client_test";
std::deque<std::string> events;
@ -319,7 +319,7 @@ int main(int argc, char* argv[])
ses.listen_on(std::make_pair(6880, 6889));
//ses.set_upload_rate_limit(512 * 1024);
ses.set_http_proxy(http_proxy);
ses.set_http_settings(settings);
ses.set_severity_level(alert::debug);
// ses.set_severity_level(alert::info);

View File

@ -41,7 +41,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/entry.hpp"
#include "libtorrent/bencode.hpp"
#include "libtorrent/session.hpp"
#include "libtorrent/http_proxy.hpp"
#include "libtorrent/http_settings.hpp"
int main(int argc, char* argv[])
{

View File

@ -9,7 +9,7 @@ libtorrent/escape_string.hpp \
libtorrent/file.hpp \
libtorrent/fingerprint.hpp \
libtorrent/hasher.hpp \
libtorrent/http_proxy.hpp \
libtorrent/http_settings.hpp \
libtorrent/http_tracker_connection.hpp \
libtorrent/identify_client.hpp \
libtorrent/invariant_check.hpp \

View File

@ -52,7 +52,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/socket.hpp"
#include "libtorrent/entry.hpp"
#include "libtorrent/http_proxy.hpp"
#include "libtorrent/http_settings.hpp"
#include "libtorrent/peer_id.hpp"
#include "libtorrent/peer.hpp"
#include "libtorrent/tracker_manager.hpp"
@ -73,7 +73,7 @@ namespace libtorrent
, unsigned short port
, std::string request
, boost::weak_ptr<request_callback> c
, const http_proxy& http_proxy
, const http_settings& stn
, std::string const& password = "");
virtual bool tick();
virtual bool send_finished() const
@ -109,7 +109,7 @@ namespace libtorrent
std::string m_server_message;
std::string m_server_protocol;
const http_proxy& m_http_proxy;
const http_settings& m_settings;
tracker_request m_req;
std::string m_password;
int m_code;

View File

@ -236,7 +236,7 @@ namespace libtorrent
bool extensions_enabled() const;
// the settings for the client
http_proxy m_http_proxy;
http_settings m_settings;
// set to true when the session object
// is being destructed and the thread
@ -277,7 +277,7 @@ namespace libtorrent
};
}
struct http_proxy;
struct http_settings;
struct session_status
{
@ -359,7 +359,7 @@ namespace libtorrent
void remove_torrent(const torrent_handle& h);
void set_http_proxy(const http_proxy& http_proxy);
void set_http_settings(const http_settings& s);
void set_upload_rate_limit(int bytes_per_second);
void set_download_rate_limit(int bytes_per_second);
void set_max_uploads(int limit);

View File

@ -53,7 +53,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/socket.hpp"
#include "libtorrent/entry.hpp"
#include "libtorrent/http_proxy.hpp"
#include "libtorrent/http_settings.hpp"
#include "libtorrent/peer_id.hpp"
#include "libtorrent/peer.hpp"
@ -162,8 +162,8 @@ namespace libtorrent
{
public:
tracker_manager(const http_proxy& http_proxy)
: m_http_proxy(http_proxy) {}
tracker_manager(const http_settings& s)
: m_settings(s) {}
void tick();
void queue_request(
@ -179,7 +179,7 @@ namespace libtorrent
typedef std::list<boost::shared_ptr<tracker_connection> >
tracker_connections_t;
tracker_connections_t m_connections;
const http_proxy& m_http_proxy;
const http_settings& m_settings;
};
}

View File

@ -52,7 +52,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/socket.hpp"
#include "libtorrent/entry.hpp"
#include "libtorrent/http_proxy.hpp"
#include "libtorrent/http_settings.hpp"
#include "libtorrent/peer_id.hpp"
#include "libtorrent/peer.hpp"
#include "libtorrent/tracker_manager.hpp"
@ -70,7 +70,7 @@ namespace libtorrent
, std::string const& hostname
, unsigned short port
, boost::weak_ptr<request_callback> c
, const http_proxy& http_proxy);
, const http_settings& stn);
virtual bool tick();
virtual bool send_finished() const;
@ -103,7 +103,7 @@ namespace libtorrent
tracker_request m_request;
int m_transaction_id;
boost::int64_t m_connection_id;
const http_proxy& m_http_proxy;
const http_settings& m_settings;
int m_attempts;
};

View File

@ -21,7 +21,7 @@ $(top_srcdir)/include/libtorrent/escape_string.hpp \
$(top_srcdir)/include/libtorrent/file.hpp \
$(top_srcdir)/include/libtorrent/fingerprint.hpp \
$(top_srcdir)/include/libtorrent/hasher.hpp \
$(top_srcdir)/include/libtorrent/http_proxy.hpp \
$(top_srcdir)/include/libtorrent/http_settings.hpp \
$(top_srcdir)/include/libtorrent/http_tracker_connection.hpp \
$(top_srcdir)/include/libtorrent/identify_client.hpp \
$(top_srcdir)/include/libtorrent/invariant_check.hpp \

View File

@ -85,7 +85,7 @@ namespace libtorrent
, unsigned short port
, std::string request
, boost::weak_ptr<request_callback> c
, const http_proxy& http_proxy
, const http_settings& stn
, std::string const& auth)
: tracker_connection(c)
, m_man(man)
@ -94,7 +94,7 @@ namespace libtorrent
, m_content_length(0)
, m_recv_pos(0)
, m_request_time(second_clock::universal_time())
, m_http_proxy(http_proxy)
, m_settings(stn)
, m_req(req)
, m_password(auth)
, m_code(0)
@ -103,10 +103,10 @@ namespace libtorrent
bool using_proxy = false;
// should we use the proxy?
if (!m_http_proxy.proxy_ip.empty())
if (!m_settings.proxy_ip.empty())
{
connect_to_host = &m_http_proxy.proxy_ip;
if (m_http_proxy.proxy_port != 0) port = m_http_proxy.proxy_port;
connect_to_host = &m_settings.proxy_ip;
if (m_settings.proxy_port != 0) port = m_settings.proxy_port;
using_proxy = true;
}
else
@ -189,7 +189,7 @@ namespace libtorrent
m_send_buffer += " HTTP/1.0\r\nAccept-Encoding: gzip\r\n"
"User-Agent: ";
m_send_buffer += m_http_proxy.user_agent;
m_send_buffer += m_settings.user_agent;
m_send_buffer += " (libtorrent)\r\n"
"Host: ";
m_send_buffer += hostname;
@ -198,10 +198,10 @@ namespace libtorrent
m_send_buffer += ':';
m_send_buffer += boost::lexical_cast<std::string>(port);
}
if (using_proxy && !m_http_proxy.proxy_login.empty())
if (using_proxy && !m_settings.proxy_login.empty())
{
m_send_buffer += "\r\nProxy-Authorization: Basic ";
m_send_buffer += base64encode(m_http_proxy.proxy_login + ":" + m_http_proxy.proxy_password);
m_send_buffer += base64encode(m_settings.proxy_login + ":" + m_settings.proxy_password);
}
if (auth != "")
{
@ -259,8 +259,8 @@ namespace libtorrent
using namespace boost::posix_time;
time_duration d = second_clock::universal_time() - m_request_time;
if (d > seconds(m_http_proxy.tracker_timeout) ||
(!has_requester() && d > seconds(m_http_proxy.stop_tracker_timeout)))
if (d > seconds(m_settings.tracker_timeout) ||
(!has_requester() && d > seconds(m_settings.stop_tracker_timeout)))
{
if (has_requester()) requester().tracker_request_timed_out(m_req);
return true;
@ -310,7 +310,7 @@ namespace libtorrent
// if the receive buffer is full, expand it with http_buffer_size
if ((int)m_buffer.size() == m_recv_pos)
{
if ((int)m_buffer.size() > m_http_proxy.tracker_maximum_response_length)
if ((int)m_buffer.size() > m_settings.tracker_maximum_response_length)
{
if (has_requester())
{
@ -415,7 +415,7 @@ namespace libtorrent
}
return true;
}
if (m_content_length > m_http_proxy.tracker_maximum_response_length)
if (m_content_length > m_settings.tracker_maximum_response_length)
{
if (has_requester())
{
@ -514,7 +514,7 @@ namespace libtorrent
boost::shared_ptr<request_callback> r = m_requester.lock();
if (!r) return true;
if (inflate_gzip(m_buffer, m_req, r.get(),
m_http_proxy.tracker_maximum_response_length))
m_settings.tracker_maximum_response_length))
return true;
}

View File

@ -223,7 +223,7 @@ namespace libtorrent { namespace detail
std::pair<int, int> listen_port_range
, const fingerprint& cl_fprint
, const char* listen_interface = 0)
: m_tracker_manager(m_http_proxy)
: m_tracker_manager(m_settings)
, m_listen_port_range(listen_port_range)
, m_listen_interface(listen_interface, listen_port_range.first)
, m_abort(false)
@ -1167,10 +1167,10 @@ namespace libtorrent
return m_impl.m_listen_socket;
}
void session::set_http_proxy(const http_proxy& http_proxy)
void session::set_http_settings(const http_settings& s)
{
boost::mutex::scoped_lock l(m_impl.m_mutex);
m_impl.m_http_proxy = http_proxy;
m_impl.m_settings = s;
}
session::~session()

View File

@ -448,7 +448,7 @@ namespace libtorrent
, port
, request_string
, c
, m_http_proxy
, m_settings
, auth));
}
else if (protocol == "udp")
@ -458,7 +458,7 @@ namespace libtorrent
, hostname
, port
, c
, m_http_proxy));
, m_settings));
}
else
{

View File

@ -64,13 +64,13 @@ namespace libtorrent
, std::string const& hostname
, unsigned short port
, boost::weak_ptr<request_callback> c
, const http_proxy& http_proxy)
, const http_settings& stn)
: tracker_connection(c)
, m_request_time(second_clock::universal_time())
, m_request(req)
, m_transaction_id(0)
, m_connection_id(0)
, m_http_proxy(http_proxy)
, m_settings(stn)
, m_attempts(0)
{
m_name_lookup = dns_lookup(hostname.c_str(), port);
@ -85,7 +85,7 @@ namespace libtorrent
time_duration d = second_clock::universal_time() - m_request_time;
return (m_transaction_id != 0
&& m_connection_id != 0)
|| d > seconds(m_http_proxy.tracker_timeout);
|| d > seconds(m_settings.tracker_timeout);
}
bool udp_tracker_connection::tick()