From c798e388a908897f7f8948e7c0346bc8bee63715 Mon Sep 17 00:00:00 2001 From: arvidn Date: Sat, 3 Oct 2015 11:20:10 -0400 Subject: [PATCH] forward port fix to proxy_peer_connections to master --- ChangeLog | 1 + include/libtorrent/settings_pack.hpp | 5 ++- src/torrent.cpp | 17 ++++++--- src/web_connection_base.cpp | 4 +- test/Jamfile | 1 + test/Makefile.am | 2 + test/test_web_seed_socks5_no_peers.cpp | 52 ++++++++++++++++++++++++++ test/web_seed_suite.cpp | 11 ++++-- test/web_seed_suite.hpp | 4 +- 9 files changed, 83 insertions(+), 14 deletions(-) create mode 100644 test/test_web_seed_socks5_no_peers.cpp diff --git a/ChangeLog b/ChangeLog index 558469064..b4ddbd5fc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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) diff --git a/include/libtorrent/settings_pack.hpp b/include/libtorrent/settings_pack.hpp index 3391ce14a..ee0cf4d99 100644 --- a/include/libtorrent/settings_pack.hpp +++ b/include/libtorrent/settings_pack.hpp @@ -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 diff --git a/src/torrent.cpp b/src/torrent.cpp index 80eeedaac..a1ddd7637 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -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(); @@ -6457,8 +6459,11 @@ namespace libtorrent 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() +#ifdef TORRENT_USE_OPENSSL + || s->get >() +#endif + )) { // we're using a socks proxy and we're resolving // hostnames through it @@ -6467,7 +6472,7 @@ namespace libtorrent ssl ? &s->get >()->next_layer() : #endif s->get(); - TORRENT_ASSERT(str); + TORRENT_ASSERT_VAL(str, s->type_name()); str->set_dst_name(hostname); } diff --git a/src/web_connection_base.cpp b/src/web_connection_base.cpp index db96b35cf..679d5fcd1 100644 --- a/src/web_connection_base.cpp +++ b/src/web_connection_base.cpp @@ -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) diff --git a/test/Jamfile b/test/Jamfile index 121c69e36..3536a7d3b 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -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 ] diff --git a/test/Makefile.am b/test/Makefile.am index df909bee0..04d625d49 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -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 diff --git a/test/test_web_seed_socks5_no_peers.cpp b/test/test_web_seed_socks5_no_peers.cpp new file mode 100644 index 000000000..821f88f37 --- /dev/null +++ b/test/test_web_seed_socks5_no_peers.cpp @@ -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::proxy_settings::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); +} + diff --git a/test/web_seed_suite.cpp b/test/web_seed_suite.cpp index 8b9afb177..07f4b6870 100644 --- a/test/web_seed_suite.cpp +++ b/test/web_seed_suite.cpp @@ -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_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_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_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_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); } } diff --git a/test/web_seed_suite.hpp b/test/web_seed_suite.hpp index d3b2d2103..7086cbda2 100644 --- a/test/web_seed_suite.hpp +++ b/test/web_seed_suite.hpp @@ -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 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);