diff --git a/ChangeLog b/ChangeLog index 5933cd47a..7be510c68 100644 --- a/ChangeLog +++ b/ChangeLog @@ -78,6 +78,7 @@ * resume data no longer has timestamps of files * require C++11 to build libtorrent + * fix listen socket issue when disabling "force_proxy" mode * fix full allocation failure on APFS 1.1.5 release diff --git a/simulation/test_session.cpp b/simulation/test_session.cpp index 7b33f0d13..fae8f9d3a 100644 --- a/simulation/test_session.cpp +++ b/simulation/test_session.cpp @@ -35,6 +35,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "utils.hpp" #include "libtorrent/session.hpp" #include "libtorrent/socket.hpp" +#include "libtorrent/alert_types.hpp" #include "simulator/simulator.hpp" #include "simulator/utils.hpp" // for timer #include "settings.hpp" @@ -112,3 +113,58 @@ TORRENT_TEST(ip_notifier_setting) TEST_EQUAL(working_count, 2); } + +TORRENT_TEST(force_proxy) +{ + // setup the simulation + sim::default_config network_cfg; + sim::simulation sim{network_cfg}; + std::unique_ptr ios{new sim::asio::io_service(sim + , address_v4::from_string("50.0.0.1"))}; + lt::session_proxy zombie; + + lt::settings_pack pack = settings(); + pack.set_bool(settings_pack::force_proxy, true); + // create session + std::shared_ptr ses = std::make_shared(pack, *ios); + + // disable force proxy in 3 seconds (this should make us open up listen + // sockets) + sim::timer t1(sim, lt::seconds(3), [&](boost::system::error_code const& ec) + { + lt::settings_pack p; + p.set_bool(settings_pack::force_proxy, false); + ses->apply_settings(p); + }); + + int num_listen_tcp = 0; + int num_listen_udp = 0; + print_alerts(*ses, [&](lt::session& ses, lt::alert const* a) { + if (auto la = alert_cast(a)) + { + if (la->sock_type == listen_succeeded_alert::tcp) + ++num_listen_tcp; + else if (la->sock_type == listen_succeeded_alert::udp) + ++num_listen_udp; + } + }); + + // run for 10 seconds. + sim::timer t2(sim, lt::seconds(10), [&](boost::system::error_code const& ec) + { + fprintf(stderr, "shutting down\n"); + // shut down + zombie = ses->abort(); + ses.reset(); + }); + sim.run(); + + // on session construction, we won't listen to TCP since we're in force-proxy + // mode. We will open up the UDP sockets though, since they are used for + // outgoing connections too. + // when we disable force-proxy, we'll re-open the sockets and listen on TCP + // connections this time, so we'll get a tcp_listen and a udp_listen. + TEST_EQUAL(num_listen_tcp, 1); + TEST_EQUAL(num_listen_udp, 2); +} + diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 84a605f1b..523cb9239 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -6400,7 +6400,17 @@ namespace { } } - if (!m_settings.get_bool(settings_pack::force_proxy)) return; + if (!m_settings.get_bool(settings_pack::force_proxy)) + { +#ifndef TORRENT_DISABLE_LOGGING + session_log("force-proxy disabled"); +#endif + return; + } + +#ifndef TORRENT_DISABLE_LOGGING + session_log("force-proxy enabled"); +#endif // enable force_proxy mode. We don't want to accept any incoming // connections, except through a proxy. diff --git a/test/test_ssl.cpp b/test/test_ssl.cpp index 5f532d360..e8aa9e731 100644 --- a/test/test_ssl.cpp +++ b/test/test_ssl.cpp @@ -60,9 +60,9 @@ using namespace std::placeholders; using namespace lt; using std::ignore; -int const alert_mask = alert::all_categories -& ~alert::progress_notification -& ~alert::stats_notification; +auto const alert_mask = alert::all_categories + & ~alert::progress_notification + & ~alert::stats_notification; struct test_config_t {