mirror of
https://git.wownero.com/wownero/wownero.git
synced 2024-08-15 01:03:23 +00:00
dns: change default DNS to a worldwide selection
DNSSEC aware servers picked from https://wiki.ipfire.org/dns/public-servers
This commit is contained in:
parent
ed67e5c001
commit
71806327f5
3 changed files with 35 additions and 23 deletions
|
@ -36,13 +36,21 @@
|
||||||
#include <boost/filesystem/fstream.hpp>
|
#include <boost/filesystem/fstream.hpp>
|
||||||
#include <boost/thread/mutex.hpp>
|
#include <boost/thread/mutex.hpp>
|
||||||
#include <boost/thread/thread.hpp>
|
#include <boost/thread/thread.hpp>
|
||||||
|
#include <boost/algorithm/string/join.hpp>
|
||||||
using namespace epee;
|
using namespace epee;
|
||||||
namespace bf = boost::filesystem;
|
namespace bf = boost::filesystem;
|
||||||
|
|
||||||
#undef MONERO_DEFAULT_LOG_CATEGORY
|
#undef MONERO_DEFAULT_LOG_CATEGORY
|
||||||
#define MONERO_DEFAULT_LOG_CATEGORY "net.dns"
|
#define MONERO_DEFAULT_LOG_CATEGORY "net.dns"
|
||||||
|
|
||||||
#define DEFAULT_DNS_PUBLIC_ADDR "8.8.4.4"
|
static const char *DEFAULT_DNS_PUBLIC_ADDR[] =
|
||||||
|
{
|
||||||
|
"194.150.168.168", // CCC (Germany)
|
||||||
|
"81.3.27.54", // Lightning Wire Labs (Germany)
|
||||||
|
"31.3.135.232", // OpenNIC (Switzerland)
|
||||||
|
"80.67.169.40", // FDN (France)
|
||||||
|
"209.58.179.186", // Cyberghost (Singapore)
|
||||||
|
};
|
||||||
|
|
||||||
static boost::mutex instance_lock;
|
static boost::mutex instance_lock;
|
||||||
|
|
||||||
|
@ -201,13 +209,13 @@ public:
|
||||||
DNSResolver::DNSResolver() : m_data(new DNSResolverData())
|
DNSResolver::DNSResolver() : m_data(new DNSResolverData())
|
||||||
{
|
{
|
||||||
int use_dns_public = 0;
|
int use_dns_public = 0;
|
||||||
std::string dns_public_addr = DEFAULT_DNS_PUBLIC_ADDR;
|
std::vector<std::string> dns_public_addr;
|
||||||
if (auto res = getenv("DNS_PUBLIC"))
|
if (auto res = getenv("DNS_PUBLIC"))
|
||||||
{
|
{
|
||||||
dns_public_addr = tools::dns_utils::parse_dns_public(res);
|
dns_public_addr = tools::dns_utils::parse_dns_public(res);
|
||||||
if (!dns_public_addr.empty())
|
if (!dns_public_addr.empty())
|
||||||
{
|
{
|
||||||
MGINFO("Using public DNS server: " << dns_public_addr << " (TCP)");
|
MGINFO("Using public DNS server(s): " << boost::join(dns_public_addr, ", ") << " (TCP)");
|
||||||
use_dns_public = 1;
|
use_dns_public = 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -221,7 +229,8 @@ DNSResolver::DNSResolver() : m_data(new DNSResolverData())
|
||||||
|
|
||||||
if (use_dns_public)
|
if (use_dns_public)
|
||||||
{
|
{
|
||||||
ub_ctx_set_fwd(m_data->m_ub_context, dns_public_addr.c_str());
|
for (const auto &ip: dns_public_addr)
|
||||||
|
ub_ctx_set_fwd(m_data->m_ub_context, ip.c_str());
|
||||||
ub_ctx_set_option(m_data->m_ub_context, string_copy("do-udp:"), string_copy("no"));
|
ub_ctx_set_option(m_data->m_ub_context, string_copy("do-udp:"), string_copy("no"));
|
||||||
ub_ctx_set_option(m_data->m_ub_context, string_copy("do-tcp:"), string_copy("yes"));
|
ub_ctx_set_option(m_data->m_ub_context, string_copy("do-tcp:"), string_copy("yes"));
|
||||||
}
|
}
|
||||||
|
@ -526,15 +535,16 @@ bool load_txt_records_from_dns(std::vector<std::string> &good_records, const std
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string parse_dns_public(const char *s)
|
std::vector<std::string> parse_dns_public(const char *s)
|
||||||
{
|
{
|
||||||
unsigned ip0, ip1, ip2, ip3;
|
unsigned ip0, ip1, ip2, ip3;
|
||||||
char c;
|
char c;
|
||||||
std::string dns_public_addr;
|
std::vector<std::string> dns_public_addr;
|
||||||
if (!strcmp(s, "tcp"))
|
if (!strcmp(s, "tcp"))
|
||||||
{
|
{
|
||||||
dns_public_addr = DEFAULT_DNS_PUBLIC_ADDR;
|
for (size_t i = 0; i < sizeof(DEFAULT_DNS_PUBLIC_ADDR) / sizeof(DEFAULT_DNS_PUBLIC_ADDR[0]); ++i)
|
||||||
LOG_PRINT_L0("Using default public DNS server: " << dns_public_addr << " (TCP)");
|
dns_public_addr.push_back(DEFAULT_DNS_PUBLIC_ADDR[i]);
|
||||||
|
LOG_PRINT_L0("Using default public DNS server(s): " << boost::join(dns_public_addr, ", ") << " (TCP)");
|
||||||
}
|
}
|
||||||
else if (sscanf(s, "tcp://%u.%u.%u.%u%c", &ip0, &ip1, &ip2, &ip3, &c) == 4)
|
else if (sscanf(s, "tcp://%u.%u.%u.%u%c", &ip0, &ip1, &ip2, &ip3, &c) == 4)
|
||||||
{
|
{
|
||||||
|
@ -544,7 +554,7 @@ std::string parse_dns_public(const char *s)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dns_public_addr = std::string(s + strlen("tcp://"));
|
dns_public_addr.push_back(std::string(s + strlen("tcp://")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -167,7 +167,7 @@ std::string get_account_address_as_str_from_url(const std::string& url, bool& dn
|
||||||
|
|
||||||
bool load_txt_records_from_dns(std::vector<std::string> &records, const std::vector<std::string> &dns_urls);
|
bool load_txt_records_from_dns(std::vector<std::string> &records, const std::vector<std::string> &dns_urls);
|
||||||
|
|
||||||
std::string parse_dns_public(const char *s);
|
std::vector<std::string> parse_dns_public(const char *s);
|
||||||
|
|
||||||
} // namespace tools::dns_utils
|
} // namespace tools::dns_utils
|
||||||
|
|
||||||
|
|
|
@ -158,16 +158,18 @@ TEST(DNSResolver, GetTXTRecord)
|
||||||
EXPECT_STREQ("donate.getmonero.org", addr.c_str());
|
EXPECT_STREQ("donate.getmonero.org", addr.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(DNS_PUBLIC, empty) { EXPECT_STREQ("", tools::dns_utils::parse_dns_public("").c_str()); }
|
bool is_equal(const char *s, const std::vector<std::string> &v) { return v.size() == 1 && v[0] == s; }
|
||||||
TEST(DNS_PUBLIC, default) { EXPECT_STREQ("8.8.4.4", tools::dns_utils::parse_dns_public("tcp").c_str()); }
|
|
||||||
TEST(DNS_PUBLIC, invalid_scheme) { EXPECT_STREQ("", tools::dns_utils::parse_dns_public("invalid").c_str()); }
|
TEST(DNS_PUBLIC, empty) { EXPECT_TRUE(tools::dns_utils::parse_dns_public("").empty()); }
|
||||||
TEST(DNS_PUBLIC, invalid_ip_alpha) { EXPECT_STREQ("", tools::dns_utils::parse_dns_public("tcp://invalid").c_str()); }
|
TEST(DNS_PUBLIC, default) { EXPECT_TRUE(tools::dns_utils::parse_dns_public("tcp").size() > 0); }
|
||||||
TEST(DNS_PUBLIC, invalid_ip_num1) { EXPECT_STREQ("", tools::dns_utils::parse_dns_public("tcp://3").c_str()); }
|
TEST(DNS_PUBLIC, invalid_scheme) { EXPECT_TRUE(tools::dns_utils::parse_dns_public("invalid").empty()); }
|
||||||
TEST(DNS_PUBLIC, invalid_ip_num3) { EXPECT_STREQ("", tools::dns_utils::parse_dns_public("tcp://3.4.5").c_str()); }
|
TEST(DNS_PUBLIC, invalid_ip_alpha) { EXPECT_TRUE(tools::dns_utils::parse_dns_public("tcp://invalid").empty()); }
|
||||||
TEST(DNS_PUBLIC, invalid_ip_num4_extra) { EXPECT_STREQ("", tools::dns_utils::parse_dns_public("tcp://3.4.5.6x").c_str()); }
|
TEST(DNS_PUBLIC, invalid_ip_num1) { EXPECT_TRUE(tools::dns_utils::parse_dns_public("tcp://3").empty()); }
|
||||||
TEST(DNS_PUBLIC, invalid_ip_num4_range) { EXPECT_STREQ("", tools::dns_utils::parse_dns_public("tcp://3.4.542.6").c_str()); }
|
TEST(DNS_PUBLIC, invalid_ip_num3) { EXPECT_TRUE(tools::dns_utils::parse_dns_public("tcp://3.4.5").empty()); }
|
||||||
TEST(DNS_PUBLIC, invalid_ip_dot) { EXPECT_STREQ("", tools::dns_utils::parse_dns_public("tcp://3.4.5.6.").c_str()); }
|
TEST(DNS_PUBLIC, invalid_ip_num4_extra) { EXPECT_TRUE(tools::dns_utils::parse_dns_public("tcp://3.4.5.6x").empty()); }
|
||||||
TEST(DNS_PUBLIC, invalid_ip_num5) { EXPECT_STREQ("", tools::dns_utils::parse_dns_public("tcp://3.4.5.6.7").c_str()); }
|
TEST(DNS_PUBLIC, invalid_ip_num4_range) { EXPECT_TRUE(tools::dns_utils::parse_dns_public("tcp://3.4.542.6").empty()); }
|
||||||
TEST(DNS_PUBLIC, invalid_ip_4_missing) { EXPECT_STREQ("", tools::dns_utils::parse_dns_public("tcp://3.4..7").c_str()); }
|
TEST(DNS_PUBLIC, invalid_ip_dot) { EXPECT_TRUE(tools::dns_utils::parse_dns_public("tcp://3.4.5.6.").empty()); }
|
||||||
TEST(DNS_PUBLIC, valid_ip_lo) { EXPECT_STREQ("127.0.0.1", tools::dns_utils::parse_dns_public("tcp://127.0.0.1").c_str()); }
|
TEST(DNS_PUBLIC, invalid_ip_num5) { EXPECT_TRUE(tools::dns_utils::parse_dns_public("tcp://3.4.5.6.7").empty()); }
|
||||||
TEST(DNS_PUBLIC, valid_ip) { EXPECT_STREQ("3.4.5.6", tools::dns_utils::parse_dns_public("tcp://3.4.5.6").c_str()); }
|
TEST(DNS_PUBLIC, invalid_ip_4_missing) { EXPECT_TRUE(tools::dns_utils::parse_dns_public("tcp://3.4..7").empty()); }
|
||||||
|
TEST(DNS_PUBLIC, valid_ip_lo) { EXPECT_TRUE(is_equal("127.0.0.1", tools::dns_utils::parse_dns_public("tcp://127.0.0.1"))); }
|
||||||
|
TEST(DNS_PUBLIC, valid_ip) { EXPECT_TRUE(is_equal("3.4.5.6", tools::dns_utils::parse_dns_public("tcp://3.4.5.6"))); }
|
||||||
|
|
Loading…
Reference in a new issue