support a separate option to use proxies for peers or not

This commit is contained in:
Arvid Norberg 2011-01-24 03:24:28 +00:00
parent 4602ff4b47
commit 9964b9cdb6
9 changed files with 60 additions and 34 deletions

View File

@ -1,3 +1,4 @@
* support a separate option to use proxies for peers or not
* pausing the session now also pauses checking torrents
* moved alert queue size limit into session_settings
* added support for DHT rss feeds (storing only)

View File

@ -5157,6 +5157,7 @@ direct certain traffic to a proxy.
proxy_type type;
bool proxy_hostnames;
bool proxy_peer_connections;
};
``hostname`` is the name or IP of the proxy server. ``port`` is the
@ -5197,6 +5198,10 @@ options are available:
attempted to be resolved through the proxy instead of using the local DNS
service. This is only supported by SOCKS5 and HTTP.
``proxy_peer_connections`` determines whether or not to excempt peer and
web seed connections from using the proxy. This defaults to true, i.e. peer
connections are proxied by default.
ip_filter
=========

View File

@ -44,7 +44,8 @@ namespace libtorrent
TORRENT_EXPORT bool instantiate_connection(io_service& ios
, proxy_settings const& ps, socket_type& s
, void* ssl_context = 0
, utp_socket_manager* sm = 0);
, utp_socket_manager* sm = 0
, bool peer_connection = false);
}
#endif

View File

@ -45,7 +45,9 @@ namespace libtorrent
struct TORRENT_EXPORT proxy_settings
{
proxy_settings() : port(0), type(none)
, proxy_hostnames(true) {}
, proxy_hostnames(true)
, proxy_peer_connections(true)
{}
std::string hostname;
int port;
@ -85,6 +87,9 @@ namespace libtorrent
// when set to true, hostname are resolved
// through the proxy (if supported)
bool proxy_hostnames;
// if true, use this proxy for peers too
bool proxy_peer_connections;
};
struct TORRENT_EXPORT session_settings

View File

@ -59,6 +59,8 @@ namespace libtorrent
udp_socket(io_service& ios, callback_t const& c, callback2_t const& c2, connection_queue& cc);
~udp_socket();
enum flags_t { dont_drop = 1, peer_connection = 2 };
bool is_open() const
{
return m_ipv4_sock.is_open()
@ -72,7 +74,7 @@ namespace libtorrent
// this is only valid when using a socks5 proxy
void send_hostname(char const* hostname, int port, char const* p, int len, error_code& ec);
void send(udp::endpoint const& ep, char const* p, int len, error_code& ec);
void send(udp::endpoint const& ep, char const* p, int len, error_code& ec, int flags = 0);
void bind(udp::endpoint const& ep, error_code& ec);
void bind(int port);
void close();
@ -114,6 +116,7 @@ namespace libtorrent
udp::endpoint ep;
char* hostname;
buffer buf;
int flags;
};
private:

View File

@ -45,14 +45,23 @@ namespace libtorrent
TORRENT_EXPORT bool instantiate_connection(io_service& ios
, proxy_settings const& ps, socket_type& s
, void* ssl_context
, utp_socket_manager* sm)
, utp_socket_manager* sm
, bool peer_connection)
{
if (sm)
{
s.instantiate<utp_stream>(ios);
s.get<utp_stream>()->set_impl(sm->new_utp_socket(s.get<utp_stream>()));
}
else if (ps.type == proxy_settings::none)
#if TORRENT_USE_I2P
else if (ps.type == proxy_settings::i2p_proxy)
{
s.instantiate<i2p_stream>(ios);
s.get<i2p_stream>()->set_proxy(ps.hostname, ps.port);
}
#endif
else if (ps.type == proxy_settings::none
|| (peer_connection && !ps.proxy_peer_connections))
{
#ifdef TORRENT_USE_OPENSSL
if (ssl_context)
@ -105,13 +114,6 @@ namespace libtorrent
if (ps.type == proxy_settings::socks4)
str->set_version(4);
}
#if TORRENT_USE_I2P
else if (ps.type == proxy_settings::i2p_proxy)
{
s.instantiate<i2p_stream>(ios);
s.get<i2p_stream>()->set_proxy(ps.hostname, ps.port);
}
#endif
else
{
TORRENT_ASSERT_VAL(false, ps.type);

View File

@ -366,6 +366,8 @@ namespace aux {
TORRENT_SETTING(std_string, username)
TORRENT_SETTING(std_string, password)
TORRENT_SETTING(integer, type)
TORRENT_SETTING(boolean, proxy_hostnames)
TORRENT_SETTING(boolean, proxy_peer_connections)
};
#undef TORRENT_SETTING

View File

@ -3920,7 +3920,7 @@ namespace libtorrent
#ifdef TORRENT_USE_OPENSSL
if (ssl) userdata = &m_ses.m_ssl_ctx;
#endif
bool ret = instantiate_connection(m_ses.m_io_service, m_ses.proxy(), *s, userdata);
bool ret = instantiate_connection(m_ses.m_io_service, m_ses.proxy(), *s, userdata, 0, true);
(void)ret;
TORRENT_ASSERT(ret);
@ -4769,7 +4769,7 @@ namespace libtorrent
// don't make a TCP connection if it's disabled
if (sm == 0 && !m_ses.m_settings.enable_outgoing_tcp) return false;
bool ret = instantiate_connection(m_ses.m_io_service, m_ses.proxy(), *s, 0, sm);
bool ret = instantiate_connection(m_ses.m_io_service, m_ses.proxy(), *s, 0, sm, true);
(void)ret;
TORRENT_ASSERT(ret);
}

View File

@ -147,9 +147,11 @@ void udp_socket::send_hostname(char const* hostname, int port
qp.ep.port(port);
qp.hostname = strdup(hostname);
qp.buf.insert(qp.buf.begin(), p, p + len);
qp.flags = 0;
}
void udp_socket::send(udp::endpoint const& ep, char const* p, int len, error_code& ec)
void udp_socket::send(udp::endpoint const& ep, char const* p, int len
, error_code& ec, int flags)
{
CHECK_MAGIC;
@ -158,21 +160,25 @@ void udp_socket::send(udp::endpoint const& ep, char const* p, int len, error_cod
// if the sockets are closed, the udp_socket is closing too
if (!is_open()) return;
if (m_tunnel_packets)
if (!(flags & peer_connection) || m_proxy_settings.proxy_peer_connections)
{
// send udp packets through SOCKS5 server
wrap(ep, p, len, ec);
return;
}
if (m_tunnel_packets)
{
// send udp packets through SOCKS5 server
wrap(ep, p, len, ec);
return;
}
if (m_queue_packets)
{
m_queue.push_back(queued_packet());
queued_packet& qp = m_queue.back();
qp.ep = ep;
qp.hostname = 0;
qp.buf.insert(qp.buf.begin(), p, p + len);
return;
if (m_queue_packets)
{
m_queue.push_back(queued_packet());
queued_packet& qp = m_queue.back();
qp.ep = ep;
qp.hostname = 0;
qp.flags = flags;
qp.buf.insert(qp.buf.begin(), p, p + len);
return;
}
}
#if TORRENT_USE_IPV6
@ -931,7 +937,7 @@ void udp_socket::connect2(error_code const& e)
}
else
{
udp_socket::send(p.ep, &p.buf[0], p.buf.size(), ec);
udp_socket::send(p.ep, &p.buf[0], p.buf.size(), ec, p.flags);
}
m_queue.pop_front();
}
@ -977,22 +983,23 @@ rate_limited_udp_socket::rate_limited_udp_socket(io_service& ios
TORRENT_ASSERT_VAL(!ec, ec);
}
bool rate_limited_udp_socket::send(udp::endpoint const& ep, char const* p, int len, error_code& ec, int flags)
bool rate_limited_udp_socket::send(udp::endpoint const& ep, char const* p
, int len, error_code& ec, int flags)
{
if (m_quota < len)
{
// bit 1 of flags means "don't drop"
if (int(m_queue.size()) >= m_queue_size_limit && (flags & 1) == 0)
if (int(m_queue.size()) >= m_queue_size_limit && (flags & dont_drop) == 0)
return false;
m_queue.push_back(queued_packet());
queued_packet& qp = m_queue.back();
qp.ep = ep;
qp.flags = flags;
qp.buf.insert(qp.buf.begin(), p, p + len);
return true;
}
m_quota -= len;
udp_socket::send(ep, p, len, ec);
udp_socket::send(ep, p, len, ec, flags);
return true;
}
@ -1023,7 +1030,7 @@ void rate_limited_udp_socket::on_tick(error_code const& e)
TORRENT_ASSERT(m_quota >= p.buf.size());
m_quota -= p.buf.size();
error_code ec;
udp_socket::send(p.ep, &p.buf[0], p.buf.size(), ec);
udp_socket::send(p.ep, &p.buf[0], p.buf.size(), ec, p.flags);
m_queue.pop_front();
}
}