diff --git a/bindings/python/src/session_settings.cpp b/bindings/python/src/session_settings.cpp index db93700b89a..33a97c087ca 100644 --- a/bindings/python/src/session_settings.cpp +++ b/bindings/python/src/session_settings.cpp @@ -97,6 +97,7 @@ void bind_session_settings() .def_readwrite("type", &proxy_settings::type) .def_readwrite("proxy_peer_connections", &proxy_settings::proxy_peer_connections) .def_readwrite("proxy_hostnames", &proxy_settings::proxy_hostnames) + .def_readwrite("proxy_accept_incoming", &proxy_settings::proxy_accept_incoming) ; #endif } diff --git a/include/libtorrent/aux_/proxy_settings.hpp b/include/libtorrent/aux_/proxy_settings.hpp index 57cf0b64f92..f9906536e8c 100644 --- a/include/libtorrent/aux_/proxy_settings.hpp +++ b/include/libtorrent/aux_/proxy_settings.hpp @@ -79,6 +79,10 @@ namespace aux { // This is only supported by SOCKS5 and HTTP. bool proxy_hostnames = true; + // defaults to false for integration compatibility. It means that the + // torrent port is listening with tcp and udp while there is a proxy configured. + bool proxy_accept_incoming = false; + // determines whether or not to exempt peer and web seed connections // from using the proxy. This defaults to true, i.e. peer connections are // proxied by default. diff --git a/include/libtorrent/settings_pack.hpp b/include/libtorrent/settings_pack.hpp index 0446f2b60d6..81edb54d53d 100644 --- a/include/libtorrent/settings_pack.hpp +++ b/include/libtorrent/settings_pack.hpp @@ -876,6 +876,9 @@ namespace aux { // any). This is only supported by SOCKS5 and HTTP. proxy_hostnames, + // if true, listening on the defined port will be enabled while using proxy + proxy_accept_incoming, + // if true, peer connections are made (and accepted) over the // configured proxy, if any. Web seeds as well as regular bittorrent // peer connections are considered "peer connections". Anything diff --git a/simulation/make_proxy_settings.hpp b/simulation/make_proxy_settings.hpp index f073dabad99..a08c81c5d53 100644 --- a/simulation/make_proxy_settings.hpp +++ b/simulation/make_proxy_settings.hpp @@ -43,6 +43,7 @@ inline lt::aux::proxy_settings make_proxy_settings( aux::proxy_settings ps; ps.type = proxy_type; ps.proxy_hostnames = false; + ps.proxy_accept_incoming = false; // this IP and ports are specific to test_http_connection.cpp if (proxy_type != settings_pack::none) { diff --git a/simulation/utils.cpp b/simulation/utils.cpp index e6496b0d052..644107aa356 100644 --- a/simulation/utils.cpp +++ b/simulation/utils.cpp @@ -191,6 +191,7 @@ void set_proxy(lt::session& ses, int proxy_type, test_transfer_flags_t const fla else p.set_str(settings_pack::proxy_hostname, "50.50.50.50"); p.set_bool(settings_pack::proxy_hostnames, true); + p.set_bool(settings_pack::proxy_accept_incoming, false); p.set_bool(settings_pack::proxy_peer_connections, bool(flags & tx::proxy_peers)); p.set_bool(settings_pack::proxy_tracker_connections, proxy_peers); p.set_bool(settings_pack::socks5_udp_send_local_ep, true); diff --git a/src/proxy_settings.cpp b/src/proxy_settings.cpp index 01fa002555f..587cb8757f6 100644 --- a/src/proxy_settings.cpp +++ b/src/proxy_settings.cpp @@ -47,6 +47,7 @@ void init(proxy_settings& p, Settings const& sett) p.type = settings_pack::proxy_type_t(sett.get_int(settings_pack::proxy_type)); p.port = std::uint16_t(sett.get_int(settings_pack::proxy_port)); p.proxy_hostnames = sett.get_bool(settings_pack::proxy_hostnames); + p.proxy_accept_incoming = sett.get_bool(settings_pack::proxy_accept_incoming); p.proxy_peer_connections = sett.get_bool( settings_pack::proxy_peer_connections); p.proxy_tracker_connections = sett.get_bool( diff --git a/src/session_handle.cpp b/src/session_handle.cpp index e4bb290eeb8..00268c5842c 100644 --- a/src/session_handle.cpp +++ b/src/session_handle.cpp @@ -1040,6 +1040,7 @@ namespace { p.set_int(settings_pack::proxy_type, s.type); p.set_int(settings_pack::proxy_port, s.port); p.set_bool(settings_pack::proxy_hostnames,s.proxy_hostnames); + p.set_bool(settings_pack::proxy_accept_incoming,s.proxy_accept_incoming); p.set_bool(settings_pack::proxy_peer_connections, s.proxy_peer_connections); apply_settings(std::move(p)); diff --git a/src/session_impl.cpp b/src/session_impl.cpp index b1efa6d1e3e..471c8ff9d4b 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -830,6 +830,8 @@ bool ssl_server_name_callback(ssl::stream_handle_type stream_handle, std::string if (val) s.set_int(settings_pack::proxy_type, int(val.int_value())); val = settings.dict_find_int("proxy_hostnames"); if (val) s.set_bool(settings_pack::proxy_hostnames, val.int_value() != 0); + val = settings.dict_find_int("proxy_accept_incoming"); + if (val) s.set_bool(settings_pack::proxy_accept_incoming, val.int_value() != 0); val = settings.dict_find_int("proxy_peer_connections"); if (val) s.set_bool(settings_pack::proxy_peer_connections, val.int_value() != 0); val = settings.dict_find_string("hostname"); @@ -2056,7 +2058,8 @@ namespace { // if we don't proxy peer connections, don't apply the special logic for // proxies if (m_settings.get_int(settings_pack::proxy_type) != settings_pack::none - && m_settings.get_bool(settings_pack::proxy_peer_connections)) + && m_settings.get_bool(settings_pack::proxy_peer_connections) + && !m_settings.get_bool(settings_pack::proxy_accept_incoming)) { // we will be able to accept incoming connections over UDP. so use // one of the ports the user specified to use a consistent port @@ -2820,12 +2823,12 @@ namespace { async_accept(listener, ssl); // don't accept any connections from our local listen sockets if we're - // using a proxy. We should only accept peers via the proxy, never - // directly. + // using a proxy and the correct setting isn't set. // This path is only for accepting incoming TCP sockets. The udp_socket // class also restricts incoming packets based on proxy settings. if (m_settings.get_int(settings_pack::proxy_type) != settings_pack::none - && m_settings.get_bool(settings_pack::proxy_peer_connections)) + && m_settings.get_bool(settings_pack::proxy_peer_connections) + && !m_settings.get_bool(settings_pack::proxy_accept_incoming)) return; auto listen = std::find_if(m_listen_sockets.begin(), m_listen_sockets.end() @@ -5522,11 +5525,11 @@ namespace { if (m_listen_sockets.empty()) return 0; if (sock) { - // if we're using a proxy, we won't be able to accept any TCP - // connections. Not even uTP connections via the port we know about. // The DHT may use the implied port to make it work, but the port we // announce here has no relevance for that. - if (sock->flags & listen_socket_t::proxy) + + if (sock->flags & listen_socket_t::proxy + && !m_settings.get_bool(settings_pack::proxy_accept_incoming)) return 0; if (!(sock->flags & listen_socket_t::accept_incoming)) @@ -5535,6 +5538,11 @@ namespace { return std::uint16_t(sock->tcp_external_port()); } + if (m_settings.get_int(settings_pack::proxy_type) != settings_pack::none + && m_settings.get_bool(settings_pack::proxy_peer_connections) + && !m_settings.get_bool(settings_pack::proxy_accept_incoming)) + return 0; + #ifdef TORRENT_SSL_PEERS for (auto const& s : m_listen_sockets) { @@ -5566,9 +5574,6 @@ namespace { return std::uint16_t(sock->tcp_external_port()); } - if (m_settings.get_int(settings_pack::proxy_type) != settings_pack::none - && m_settings.get_bool(settings_pack::proxy_peer_connections)) - return 0; for (auto const& s : m_listen_sockets) { @@ -5664,7 +5669,7 @@ namespace { if (!s->natpmp_mapper && !(s->flags & listen_socket_t::local_network) - && !(s->flags & listen_socket_t::proxy)) + && m_settings.get_bool(settings_pack::proxy_accept_incoming)) { // the natpmp constructor may fail and call the callbacks // into the session_impl. @@ -6891,7 +6896,7 @@ namespace { // connected to the internet. The whole point is to forward ports through // the gateway if ((s->flags & listen_socket_t::local_network) - || (s->flags & listen_socket_t::proxy)) + || (s->flags & !m_settings.get_bool(settings_pack::proxy_accept_incoming))) return; if (!s->upnp_mapper) diff --git a/src/settings_pack.cpp b/src/settings_pack.cpp index 5a2c20f7405..42caa308145 100644 --- a/src/settings_pack.cpp +++ b/src/settings_pack.cpp @@ -220,6 +220,7 @@ constexpr int DISK_WRITE_MODE = settings_pack::enable_os_cache; SET(enable_dht, true, &session_impl::update_dht), SET(prefer_rc4, false, nullptr), SET(proxy_hostnames, true, nullptr), + SET(proxy_accept_incoming, false, nullptr), SET(proxy_peer_connections, true, nullptr), SET(auto_sequential, true, &session_impl::update_auto_sequential), SET(proxy_tracker_connections, true, nullptr),