diff options
author | Bertrand Jacquin <bertrand@jacquin.bzh> | 2022-07-17 23:52:34 +0100 |
---|---|---|
committer | Bertrand Jacquin <bertrand@jacquin.bzh> | 2024-04-06 21:25:18 +0100 |
commit | 8fa4962ae12329fa0965e80b5f945eb2ada63b0e (patch) | |
tree | 109333a66bbb9830da60ddf4720816c190234bf8 /contrib/epee/include | |
parent | dns: perform AAAA resolution (diff) | |
download | monero-8fa4962ae12329fa0965e80b5f945eb2ada63b0e.tar.xz |
net: enable IPv6 by default
As of 2024-04-01, IPv6 represents ~43% of traffic entering Google with
up to 75% is some country, and in generally more available when IPv6 was
introduced in Monero in 2019 as part of 155475d97196 ("Add IPv6
support").
Monero overall has a very low presence over IPv6 which in part can be
explained from the fact that IPv6 need to be specifically enabled before
it is used and often requires nodes to be manually added in
configuration.
This commit enabled IPv6 by default for both RPC and P2P as an attempt
to improve Monero network mesh diversity.
The change has been tested in a lot of different scenario: IPv4 only,
IPv6 only, IPv4+IPv6, IPv4+IPv6 with broken/invalid IPv4 system
configuration, IPv4+IPv6 with broken/invalid IPv6 system configuration.
* --p2p-use-ipv6 is now deprecated and has no effect
* --p2p-ignore-ipv6 is introduced to ignore unsuccessful IPv6 P2P binding
* --rpc-use-ipv6 is now deprecated and has no effect
* --rpc-ignore-ipv6 is introduced to ignore unsuccessful IPv6 RPC binding
See: https://github.com/monero-project/monero/issues/8818
See: https://www.google.com/intl/en/ipv6/statistics.html
See: https://www.vyncke.org/ipv6status/
Diffstat (limited to 'contrib/epee/include')
-rw-r--r-- | contrib/epee/include/net/abstract_tcp_server2.h | 8 | ||||
-rw-r--r-- | contrib/epee/include/net/abstract_tcp_server2.inl | 78 | ||||
-rw-r--r-- | contrib/epee/include/net/http_server_impl_base.h | 6 |
3 files changed, 47 insertions, 45 deletions
diff --git a/contrib/epee/include/net/abstract_tcp_server2.h b/contrib/epee/include/net/abstract_tcp_server2.h index ece9c1d13..1858df9e9 100644 --- a/contrib/epee/include/net/abstract_tcp_server2.h +++ b/contrib/epee/include/net/abstract_tcp_server2.h @@ -343,10 +343,10 @@ namespace net_utils void create_server_type_map(); bool init_server(uint32_t port_ipv4, const std::string& address_ipv4 = "0.0.0.0", - uint32_t port_ipv6 = 0, const std::string& address_ipv6 = "::", bool use_ipv6 = false, bool require_ipv4 = true, + uint32_t port_ipv6 = 0, const std::string& address_ipv6 = "::", bool require_ipv6 = true, bool require_ipv4 = true, ssl_options_t ssl_options = ssl_support_t::e_ssl_support_autodetect); bool init_server(const std::string port_ipv4, const std::string& address_ipv4 = "0.0.0.0", - const std::string port_ipv6 = "", const std::string address_ipv6 = "::", bool use_ipv6 = false, bool require_ipv4 = true, + const std::string port_ipv6 = "", const std::string address_ipv6 = "::", bool require_ipv6 = true, bool require_ipv4 = true, ssl_options_t ssl_options = ssl_support_t::e_ssl_support_autodetect); /// Run the server's io_service loop. @@ -473,7 +473,7 @@ namespace net_utils /// Handle completion of an asynchronous accept operation. void handle_accept_ipv4(const boost::system::error_code& e); void handle_accept_ipv6(const boost::system::error_code& e); - void handle_accept(const boost::system::error_code& e, bool ipv6 = false); + void handle_accept(const boost::system::error_code& e, bool ipv6 = true); bool is_thread_worker(); @@ -502,7 +502,7 @@ namespace net_utils uint32_t m_port_ipv6; std::string m_address_ipv4; std::string m_address_ipv6; - bool m_use_ipv6; + bool m_require_ipv6; bool m_require_ipv4; std::string m_thread_name_prefix; //TODO: change to enum server_type, now used size_t m_threads_count; diff --git a/contrib/epee/include/net/abstract_tcp_server2.inl b/contrib/epee/include/net/abstract_tcp_server2.inl index a9409baf5..cb25d1eb2 100644 --- a/contrib/epee/include/net/abstract_tcp_server2.inl +++ b/contrib/epee/include/net/abstract_tcp_server2.inl @@ -1179,7 +1179,7 @@ namespace net_utils //--------------------------------------------------------------------------------- template<class t_protocol_handler> bool boosted_tcp_server<t_protocol_handler>::init_server(uint32_t port_ipv4, const std::string& address_ipv4, - uint32_t port_ipv6, const std::string& address_ipv6, bool use_ipv6, bool require_ipv4, + uint32_t port_ipv6, const std::string& address_ipv6, bool require_ipv6, bool require_ipv4, ssl_options_t ssl_options) { TRY_ENTRY(); @@ -1188,7 +1188,7 @@ namespace net_utils m_port_ipv6 = port_ipv6; m_address_ipv4 = address_ipv4; m_address_ipv6 = address_ipv6; - m_use_ipv6 = use_ipv6; + m_require_ipv6 = require_ipv6; m_require_ipv4 = require_ipv4; if (ssl_options) @@ -1229,43 +1229,45 @@ namespace net_utils } } - if (use_ipv6) + try { - try - { - if (port_ipv6 == 0) port_ipv6 = port_ipv4; // default arg means bind to same port as ipv4 - boost::asio::ip::tcp::resolver resolver(io_service_); - boost::asio::ip::tcp::resolver::query query(address_ipv6, boost::lexical_cast<std::string>(port_ipv6), boost::asio::ip::tcp::resolver::query::canonical_name); - boost::asio::ip::tcp::endpoint endpoint = *resolver.resolve(query); - acceptor_ipv6.open(endpoint.protocol()); + if (port_ipv6 == 0) port_ipv6 = port_ipv4; // default arg means bind to same port as ipv4 + boost::asio::ip::tcp::resolver resolver(io_service_); + boost::asio::ip::tcp::resolver::query query(address_ipv6, boost::lexical_cast<std::string>(port_ipv6), boost::asio::ip::tcp::resolver::query::canonical_name); + boost::asio::ip::tcp::endpoint endpoint = *resolver.resolve(query); + acceptor_ipv6.open(endpoint.protocol()); #if !defined(_WIN32) - acceptor_ipv6.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true)); + acceptor_ipv6.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true)); #endif - acceptor_ipv6.set_option(boost::asio::ip::v6_only(true)); - acceptor_ipv6.bind(endpoint); - acceptor_ipv6.listen(); - boost::asio::ip::tcp::endpoint binded_endpoint = acceptor_ipv6.local_endpoint(); - m_port_ipv6 = binded_endpoint.port(); - MDEBUG("start accept (IPv6)"); - new_connection_ipv6.reset(new connection<t_protocol_handler>(io_service_, m_state, m_connection_type, m_state->ssl_options().support)); - acceptor_ipv6.async_accept(new_connection_ipv6->socket(), - boost::bind(&boosted_tcp_server<t_protocol_handler>::handle_accept_ipv6, this, - boost::asio::placeholders::error)); - } - catch (const std::exception &e) - { - ipv6_failed = e.what(); - } + acceptor_ipv6.set_option(boost::asio::ip::v6_only(true)); + acceptor_ipv6.bind(endpoint); + acceptor_ipv6.listen(); + boost::asio::ip::tcp::endpoint binded_endpoint = acceptor_ipv6.local_endpoint(); + m_port_ipv6 = binded_endpoint.port(); + MDEBUG("start accept (IPv6)"); + new_connection_ipv6.reset(new connection<t_protocol_handler>(io_service_, m_state, m_connection_type, m_state->ssl_options().support)); + acceptor_ipv6.async_accept(new_connection_ipv6->socket(), + boost::bind(&boosted_tcp_server<t_protocol_handler>::handle_accept_ipv6, this, + boost::asio::placeholders::error)); + } + catch (const std::exception &e) + { + ipv6_failed = e.what(); } - if (use_ipv6 && ipv6_failed != "") + if (ipv6_failed != "") + { + MERROR("Failed to bind IPv6: " << ipv6_failed); + if (require_ipv6) { - MERROR("Failed to bind IPv6: " << ipv6_failed); - if (ipv4_failed != "") - { - throw std::runtime_error("Failed to bind IPv4 and IPv6"); - } + throw std::runtime_error("Failed to bind IPv6 (set to required)"); } + } + + if (ipv4_failed != "" && ipv6_failed != "") + { + throw std::runtime_error("Failed to bind IPv4 and IPv6"); + } return true; } @@ -1283,7 +1285,7 @@ namespace net_utils //----------------------------------------------------------------------------- template<class t_protocol_handler> bool boosted_tcp_server<t_protocol_handler>::init_server(const std::string port_ipv4, const std::string& address_ipv4, - const std::string port_ipv6, const std::string address_ipv6, bool use_ipv6, bool require_ipv4, + const std::string port_ipv6, const std::string address_ipv6, bool require_ipv6, bool require_ipv4, ssl_options_t ssl_options) { uint32_t p_ipv4 = 0; @@ -1298,7 +1300,7 @@ namespace net_utils MERROR("Failed to convert port no = " << port_ipv6); return false; } - return this->init_server(p_ipv4, address_ipv4, p_ipv6, address_ipv6, use_ipv6, require_ipv4, std::move(ssl_options)); + return this->init_server(p_ipv4, address_ipv4, p_ipv6, address_ipv6, require_ipv6, require_ipv4, std::move(ssl_options)); } //--------------------------------------------------------------------------------- template<class t_protocol_handler> @@ -1389,7 +1391,7 @@ namespace net_utils { //some problems with the listening socket ?.. _dbg1("Net service stopped without stop request, restarting..."); - if(!this->init_server(m_port_ipv4, m_address_ipv4, m_port_ipv6, m_address_ipv6, m_use_ipv6, m_require_ipv4)) + if(!this->init_server(m_port_ipv4, m_address_ipv4, m_port_ipv6, m_address_ipv6, m_require_ipv6, m_require_ipv4)) { _dbg1("Reiniting service failed, exit."); return false; @@ -1682,7 +1684,7 @@ namespace net_utils } catch (const boost::system::system_error& e) { - if (!m_use_ipv6 || (resolve_error != boost::asio::error::host_not_found && + if (!m_require_ipv6 || (resolve_error != boost::asio::error::host_not_found && resolve_error != boost::asio::error::host_not_found_try_again)) { throw; @@ -1699,7 +1701,7 @@ namespace net_utils boost::asio::ip::tcp::resolver::iterator end; if(iterator == end) { - if (!m_use_ipv6) + if (!m_require_ipv6) { _erro("Failed to resolve " << adr); return false; @@ -1807,7 +1809,7 @@ namespace net_utils } catch (const boost::system::system_error& e) { - if (!m_use_ipv6 || (resolve_error != boost::asio::error::host_not_found && + if (!m_require_ipv6 || (resolve_error != boost::asio::error::host_not_found && resolve_error != boost::asio::error::host_not_found_try_again)) { throw; diff --git a/contrib/epee/include/net/http_server_impl_base.h b/contrib/epee/include/net/http_server_impl_base.h index 94d519716..b617952f3 100644 --- a/contrib/epee/include/net/http_server_impl_base.h +++ b/contrib/epee/include/net/http_server_impl_base.h @@ -57,7 +57,7 @@ namespace epee {} bool init(std::function<void(size_t, uint8_t*)> rng, const std::string& bind_port = "0", const std::string& bind_address_ipv4 = "0.0.0.0", - const std::string& bind_address_ipv6 = "::", bool use_ipv6 = false, bool require_ipv4 = true, + const std::string& bind_address_ipv6 = "::", bool require_ipv6 = true, bool require_ipv4 = true, std::vector<std::string> access_control_origins = std::vector<std::string>(), boost::optional<net_utils::http::login> user = boost::none, net_utils::ssl_options_t ssl_options = net_utils::ssl_support_t::e_ssl_support_autodetect) @@ -77,11 +77,11 @@ namespace epee m_net_server.get_config_object().m_user = std::move(user); MGINFO("Binding on " << bind_address_ipv4 << " (IPv4):" << bind_port); - if (use_ipv6) + if (require_ipv6) { MGINFO("Binding on " << bind_address_ipv6 << " (IPv6):" << bind_port); } - bool res = m_net_server.init_server(bind_port, bind_address_ipv4, bind_port, bind_address_ipv6, use_ipv6, require_ipv4, std::move(ssl_options)); + bool res = m_net_server.init_server(bind_port, bind_address_ipv4, bind_port, bind_address_ipv6, require_ipv6, require_ipv4, std::move(ssl_options)); if(!res) { LOG_ERROR("Failed to bind server"); |