From e4dd46b498b5ab7558e933cc93a33ba8c9475da7 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Sun, 4 Sep 2022 18:10:14 +0200 Subject: [PATCH] Added `--no-dns` command line parameter --- docs/COMMAND_LINE.MD | 1 + src/main.cpp | 1 + src/p2p_server.cpp | 16 +++++++++------- src/p2pool.cpp | 16 ++++++++++++---- src/params.cpp | 6 ++++++ src/params.h | 1 + src/util.cpp | 7 +++++++ src/util.h | 1 + 8 files changed, 38 insertions(+), 11 deletions(-) diff --git a/docs/COMMAND_LINE.MD b/docs/COMMAND_LINE.MD index 4c50dcd..37f90a2 100644 --- a/docs/COMMAND_LINE.MD +++ b/docs/COMMAND_LINE.MD @@ -24,6 +24,7 @@ --no-autodiff Disable automatic difficulty adjustment for miners connected to stratum --rpc-login Specify username[:password] required for Monero RPC server --socks5 Specify IP:port of a SOCKS5 proxy to use for outgoing connections +--no-dns disable DNS queries, use only IP addresses to connect to peers (seed node DNS will be unavailable too) ``` ### Example command line diff --git a/src/main.cpp b/src/main.cpp index efeed01..f31db65 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -49,6 +49,7 @@ void p2pool_usage() "--no-autodiff Disable automatic difficulty adjustment for miners connected to stratum\n" "--rpc-login Specify username[:password] required for Monero RPC server\n" "--socks5 Specify IP:port of a SOCKS5 proxy to use for outgoing connections\n" + "--no-dns disable DNS queries, use only IP addresses to connect to peers (seed node DNS will be unavailable too)\n" "--help Show this help message\n\n" "Example command line:\n\n" "%s --host 127.0.0.1 --rpc-port 18081 --zmq-port 18083 --wallet YOUR_WALLET_ADDRESS --stratum 0.0.0.0:%d --p2p 0.0.0.0:%d\n\n", diff --git a/src/p2p_server.cpp b/src/p2p_server.cpp index 564b588..955ba1a 100644 --- a/src/p2p_server.cpp +++ b/src/p2p_server.cpp @@ -246,7 +246,7 @@ void P2PServer::connect_to_peers(const std::string& peer_list) parse_address_list(peer_list, [this](bool is_v6, const std::string& /*address*/, std::string ip, int port) { - if (!m_socks5Proxy.empty() || resolve_host(ip, is_v6)) { + if (!m_pool->params().m_dns || resolve_host(ip, is_v6)) { connect_to_peer(is_v6, ip.c_str(), port); } }); @@ -356,7 +356,7 @@ void P2PServer::update_peer_connections() peer_list.pop_back(); } - if (!has_good_peers && ((m_timerCounter % 30) == 0)) { + if (!has_good_peers && ((m_timerCounter % 10) == 0)) { LOGERR(1, "no connections to other p2pool nodes, check your monerod/p2pool/network/firewall setup!!!"); load_peer_list(); if (m_peerListMonero.empty()) { @@ -536,11 +536,13 @@ void P2PServer::load_peer_list() } }; - if (m_pool->side_chain().is_default()) { - load_from_seed_nodes(seed_nodes, DEFAULT_P2P_PORT); - } - else if (m_pool->side_chain().is_mini()) { - load_from_seed_nodes(seed_nodes_mini, DEFAULT_P2P_PORT_MINI); + if (m_pool->params().m_dns) { + if (m_pool->side_chain().is_default()) { + load_from_seed_nodes(seed_nodes, DEFAULT_P2P_PORT); + } + else if (m_pool->side_chain().is_mini()) { + load_from_seed_nodes(seed_nodes_mini, DEFAULT_P2P_PORT_MINI); + } } // Finally load peers from p2pool_peers.txt diff --git a/src/p2pool.cpp b/src/p2pool.cpp index 29a9e03..803cdff 100644 --- a/src/p2pool.cpp +++ b/src/p2pool.cpp @@ -64,10 +64,18 @@ p2pool::p2pool(int argc, char* argv[]) throw std::exception(); } - bool is_v6; - if (m_params->m_socks5Proxy.empty() && !resolve_host(m_params->m_host, is_v6)) { - LOGERR(1, "resolve_host failed for " << m_params->m_host); - throw std::exception(); + if (m_params->m_socks5Proxy.empty()) { + if (m_params->m_dns) { + bool is_v6; + if (!resolve_host(m_params->m_host, is_v6)) { + LOGERR(1, "resolve_host failed for " << m_params->m_host); + throw std::exception(); + } + } + else if (m_params->m_host.find_first_not_of("0123456789.:") != std::string::npos) { + LOGERR(1, "Can't resolve hostname " << m_params->m_host << " with DNS disabled"); + throw std::exception(); + } } hash pub, sec, eph_public_key; diff --git a/src/params.cpp b/src/params.cpp index 02a9432..724d2cb 100644 --- a/src/params.cpp +++ b/src/params.cpp @@ -140,6 +140,12 @@ Params::Params(int argc, char* argv[]) ok = true; } + if (strcmp(argv[i], "--no-dns") == 0) { + m_dns = false; + disable_resolve_host = true; + ok = true; + } + if (!ok) { fprintf(stderr, "Unknown command line parameter %s\n\n", argv[i]); p2pool_usage(); diff --git a/src/params.h b/src/params.h index 62c17a7..1f34709 100644 --- a/src/params.h +++ b/src/params.h @@ -51,6 +51,7 @@ struct Params bool m_autoDiff = true; std::string m_rpcLogin; std::string m_socks5Proxy; + bool m_dns = true; }; } // namespace p2pool diff --git a/src/util.cpp b/src/util.cpp index baec96c..b28f9ae 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -353,8 +353,15 @@ static thread_local bool main_thread = false; void set_main_thread() { main_thread = true; } bool is_main_thread() { return main_thread; } +bool disable_resolve_host = false; + bool resolve_host(std::string& host, bool& is_v6) { + if (disable_resolve_host) { + LOGERR(1, "resolve_host was called with DNS disabled for host " << host); + return false; + } + addrinfo hints{}; hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; diff --git a/src/util.h b/src/util.h index defdd7d..d1ce64a 100644 --- a/src/util.h +++ b/src/util.h @@ -171,6 +171,7 @@ extern BackgroundJobTracker bkg_jobs_tracker; void set_main_thread(); bool is_main_thread(); +extern bool disable_resolve_host; bool resolve_host(std::string& host, bool& is_v6); template