Merge pull request #201 from arvidn/proxy-peer-connections

forward port fix to proxy_peer_connections to master
This commit is contained in:
Arvid Norberg 2015-10-03 14:01:16 -04:00
commit 82c9efe8fc
9 changed files with 83 additions and 15 deletions

View File

@ -75,6 +75,7 @@
* almost completely changed the storage interface (for custom storage)
* added support for hashing pieces in multiple threads
* fix web seed bug when using proxy and proxy-peer-connections=false
* fix bug in magnet link parser
* introduce add_torrent_params flags to merge web seeds with resume data
(similar to trackers)

View File

@ -635,7 +635,10 @@ namespace libtorrent
proxy_hostnames,
// if true, peer connections are made (and accepted) over the
// configured proxy, if any.
// configured proxy, if any. Web seeds as well as regular bittorrent
// peer connections are considered "peer connections". Anything
// transporting actual torrent payload (trackers and DHT traffic are
// not considered peer connections).
proxy_peer_connections,
// if this setting is true, torrents with a very high availability of

View File

@ -6218,8 +6218,9 @@ namespace libtorrent
}
aux::proxy_settings const& ps = m_ses.proxy();
if (ps.type == settings_pack::http
if ((ps.type == settings_pack::http
|| ps.type == settings_pack::http_pw)
&& ps.proxy_peer_connections)
{
#ifndef TORRENT_DISABLE_LOGGING
debug_log("resolving proxy for web seed: %s", web->url.c_str());
@ -6233,7 +6234,8 @@ namespace libtorrent
}
else if (ps.proxy_hostnames
&& (ps.type == settings_pack::socks5
|| ps.type == settings_pack::socks5_pw))
|| ps.type == settings_pack::socks5_pw)
&& ps.proxy_peer_connections)
{
connect_web_seed(web, tcp::endpoint(address(), port));
}
@ -6422,7 +6424,7 @@ namespace libtorrent
void* userdata = 0;
#ifdef TORRENT_USE_OPENSSL
bool ssl = string_begins_no_case("https://", web->url.c_str());
const bool ssl = string_begins_no_case("https://", web->url.c_str());
if (ssl)
{
userdata = m_ssl_ctx.get();
@ -6454,11 +6456,13 @@ namespace libtorrent
}
bool proxy_hostnames = settings().get_bool(settings_pack::proxy_hostnames);
int proxy_type = settings().get_int(settings_pack::proxy_type);
if (proxy_hostnames
&& (proxy_type == settings_pack::socks5
|| proxy_type == settings_pack::socks5_pw))
&& (s->get<socks5_stream>()
#ifdef TORRENT_USE_OPENSSL
|| s->get<ssl_stream<socks5_stream> >()
#endif
))
{
// we're using a socks proxy and we're resolving
// hostnames through it
@ -6467,7 +6471,7 @@ namespace libtorrent
ssl ? &s->get<ssl_stream<socks5_stream> >()->next_layer() :
#endif
s->get<socks5_stream>();
TORRENT_ASSERT(str);
TORRENT_ASSERT_VAL(str, s->type_name());
str->set_dst_name(hostname);
}

View File

@ -75,9 +75,11 @@ namespace libtorrent
INVARIANT_CHECK;
TORRENT_ASSERT(is_outgoing());
// we only want left-over bandwidth
// TODO: introduce a web-seed default class which has a low download priority
std::string protocol;
error_code ec;
boost::tie(protocol, m_basic_auth, m_host, m_port, m_path)

View File

@ -171,6 +171,7 @@ test-suite libtorrent :
[ run test_web_seed_redirect.cpp ]
[ run test_web_seed_socks4.cpp ]
[ run test_web_seed_socks5.cpp ]
[ run test_web_seed_socks5_no_peers.cpp ]
[ run test_web_seed_socks5_pw.cpp ]
[ run test_web_seed_http.cpp ]
[ run test_web_seed_http_pw.cpp ]

View File

@ -27,6 +27,7 @@ test_programs = \
test_utp \
test_session \
test_web_seed \
test_web_seed_socks5_no_peers \
test_url_seed \
test_remap_files \
test_enum_net \
@ -183,6 +184,7 @@ enum_if_SOURCES = enum_if.cpp
test_utp_SOURCES = test_utp.cpp
test_session_SOURCES = test_session.cpp
test_web_seed_SOURCES = test_web_seed.cpp
test_web_seed_socks5_no_peers_SOURCES = test_web_seed_socks5_no_peers.cpp
test_url_seed_SOURCES = test_url_seed.cpp
test_remap_files_SOURCES = test_remap_files.cpp
test_file_progress_SOURCES = test_file_progress.cpp

View File

@ -0,0 +1,52 @@
/*
Copyright (c) 2008, 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.
*/
#include "test.hpp"
#include "setup_transfer.hpp"
#include "web_seed_suite.hpp"
using namespace libtorrent;
const int proxy = libtorrent::settings_pack::socks5;
TORRENT_TEST(web_seed_socks5_no_peers_ssl)
{
#ifdef TORRENT_USE_OPENSSL
run_http_suite(proxy, "https", false, false, false, false, false, false);
#endif
}
TORRENT_TEST(web_seed_socks5_no_peers)
{
run_http_suite(proxy, "http", false, false, false, false, false, false);
}

View File

@ -89,7 +89,7 @@ static char const* proxy_name[] = {"", "_socks4", "_socks5", "_socks5_pw", "_htt
// proxy: 0=none, 1=socks4, 2=socks5, 3=socks5_pw 4=http 5=http_pw
void test_transfer(lt::session& ses, boost::shared_ptr<torrent_info> torrent_file
, int proxy, int port, char const* protocol, bool url_seed
, bool chunked_encoding, bool test_ban, bool keepalive)
, bool chunked_encoding, bool test_ban, bool keepalive, bool proxy_peers)
{
using namespace libtorrent;
@ -125,6 +125,7 @@ void test_transfer(lt::session& ses, boost::shared_ptr<torrent_info> torrent_fil
pack.set_str(settings_pack::proxy_password, "testpass");
pack.set_int(settings_pack::proxy_type, (settings_pack::proxy_type_t)proxy);
pack.set_int(settings_pack::proxy_port, proxy_port);
pack.set_bool(settings_pack::proxy_peer_connections, proxy_peers);
ses.apply_settings(pack);
}
else
@ -135,6 +136,7 @@ void test_transfer(lt::session& ses, boost::shared_ptr<torrent_info> torrent_fil
pack.set_str(settings_pack::proxy_password, "");
pack.set_int(settings_pack::proxy_type, settings_pack::none);
pack.set_int(settings_pack::proxy_port, 0);
pack.set_bool(settings_pack::proxy_peer_connections, proxy_peers);
ses.apply_settings(pack);
}
@ -275,7 +277,8 @@ void test_transfer(lt::session& ses, boost::shared_ptr<torrent_info> torrent_fil
// protocol: "http" or "https"
// test_url_seed determines whether to use url-seed or http-seed
int EXPORT run_http_suite(int proxy, char const* protocol, bool test_url_seed
, bool chunked_encoding, bool test_ban, bool keepalive, bool test_rename)
, bool chunked_encoding, bool test_ban, bool keepalive, bool test_rename
, bool proxy_peers)
{
using namespace libtorrent;
@ -404,13 +407,13 @@ int EXPORT run_http_suite(int proxy, char const* protocol, bool test_url_seed
libtorrent::session ses(pack, 0);
test_transfer(ses, torrent_file, proxy, port, protocol, test_url_seed
, chunked_encoding, test_ban, keepalive);
, chunked_encoding, test_ban, keepalive, proxy_peers);
if (test_url_seed && test_rename)
{
torrent_file->rename_file(0, combine_path(save_path, combine_path("torrent_dir", "renamed_test1")));
test_transfer(ses, torrent_file, 0, port, protocol, test_url_seed
, chunked_encoding, test_ban, keepalive);
, chunked_encoding, test_ban, keepalive, proxy_peers);
}
}

View File

@ -34,11 +34,11 @@ POSSIBILITY OF SUCH DAMAGE.
int EXPORT run_http_suite(int proxy, char const* protocol
, bool test_url_seed, bool chunked_encoding = false, bool test_ban = false
, bool keepalive = true, bool test_rename = false);
, bool keepalive = true, bool test_rename = false, bool proxy_peers = true);
void EXPORT test_transfer(libtorrent::session& ses
, boost::shared_ptr<libtorrent::torrent_info> torrent_file
, int proxy = 0, int port = 0, char const* protocol = "http"
, bool url_seed = true, bool chunked_encoding = false
, bool test_ban = false, bool keepalive = true);
, bool test_ban = false, bool keepalive = true, bool proxy_peers = true);