aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/command_line.h6
-rw-r--r--src/common/dns_utils.cpp45
-rw-r--r--src/common/dns_utils.h2
-rw-r--r--src/common/util.cpp15
-rw-r--r--src/common/util.h2
5 files changed, 64 insertions, 6 deletions
diff --git a/src/common/command_line.h b/src/common/command_line.h
index d4231acd0..04fd70be5 100644
--- a/src/common/command_line.h
+++ b/src/common/command_line.h
@@ -189,6 +189,12 @@ namespace command_line
return !value.empty();
}
+ template<typename T, bool required>
+ bool is_arg_defaulted(const boost::program_options::variables_map& vm, const arg_descriptor<T, required>& arg)
+ {
+ return vm[arg.name].defaulted();
+ }
+
template<typename T, bool required>
T get_arg(const boost::program_options::variables_map& vm, const arg_descriptor<T, required>& arg)
diff --git a/src/common/dns_utils.cpp b/src/common/dns_utils.cpp
index 1310b8bfd..f549218cb 100644
--- a/src/common/dns_utils.cpp
+++ b/src/common/dns_utils.cpp
@@ -40,6 +40,8 @@ namespace bf = boost::filesystem;
#undef MONERO_DEFAULT_LOG_CATEGORY
#define MONERO_DEFAULT_LOG_CATEGORY "net.dns"
+#define DEFAULT_DNS_PUBLIC_ADDR "8.8.4.4"
+
static boost::mutex instance_lock;
namespace
@@ -197,16 +199,19 @@ public:
DNSResolver::DNSResolver() : m_data(new DNSResolverData())
{
int use_dns_public = 0;
- const char* dns_public_addr = "8.8.4.4";
+ std::string dns_public_addr = DEFAULT_DNS_PUBLIC_ADDR;
if (auto res = getenv("DNS_PUBLIC"))
{
- std::string dns_public(res);
- // TODO: could allow parsing of IP and protocol: e.g. DNS_PUBLIC=tcp:8.8.8.8
- if (dns_public == "tcp")
+ dns_public_addr = tools::dns_utils::parse_dns_public(res);
+ if (!dns_public_addr.empty())
{
- LOG_PRINT_L0("Using public DNS server: " << dns_public_addr << " (TCP)");
+ MGINFO("Using public DNS server: " << dns_public_addr << " (TCP)");
use_dns_public = 1;
}
+ else
+ {
+ MERROR("Failed to parse DNS_PUBLIC");
+ }
}
// init libunbound context
@@ -214,7 +219,7 @@ DNSResolver::DNSResolver() : m_data(new DNSResolverData())
if (use_dns_public)
{
- ub_ctx_set_fwd(m_data->m_ub_context, string_copy(dns_public_addr));
+ ub_ctx_set_fwd(m_data->m_ub_context, dns_public_addr.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-tcp:"), string_copy("yes"));
}
@@ -519,6 +524,34 @@ bool load_txt_records_from_dns(std::vector<std::string> &good_records, const std
return true;
}
+std::string parse_dns_public(const char *s)
+{
+ unsigned ip0, ip1, ip2, ip3;
+ char c;
+ std::string dns_public_addr;
+ if (!strcmp(s, "tcp"))
+ {
+ dns_public_addr = DEFAULT_DNS_PUBLIC_ADDR;
+ LOG_PRINT_L0("Using default public DNS server: " << dns_public_addr << " (TCP)");
+ }
+ else if (sscanf(s, "tcp://%u.%u.%u.%u%c", &ip0, &ip1, &ip2, &ip3, &c) == 4)
+ {
+ if (ip0 > 255 || ip1 > 255 || ip2 > 255 || ip3 > 255)
+ {
+ MERROR("Invalid IP: " << s << ", using default");
+ }
+ else
+ {
+ dns_public_addr = std::string(s + strlen("tcp://"));
+ }
+ }
+ else
+ {
+ MERROR("Invalid DNS_PUBLIC contents, ignored");
+ }
+ return dns_public_addr;
+}
+
} // namespace tools::dns_utils
} // namespace tools
diff --git a/src/common/dns_utils.h b/src/common/dns_utils.h
index f19584516..c0a2dbf2b 100644
--- a/src/common/dns_utils.h
+++ b/src/common/dns_utils.h
@@ -167,6 +167,8 @@ 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);
+std::string parse_dns_public(const char *s);
+
} // namespace tools::dns_utils
} // namespace tools
diff --git a/src/common/util.cpp b/src/common/util.cpp
index 74a6babf1..30746f680 100644
--- a/src/common/util.cpp
+++ b/src/common/util.cpp
@@ -30,6 +30,10 @@
#include <cstdio>
+#ifdef __GLIBC__
+#include <gnu/libc-version.h>
+#endif
+
#include "include_base_utils.h"
#include "file_io_utils.h"
using namespace epee;
@@ -536,6 +540,17 @@ std::string get_nix_version_display_string()
}
return false;
}
+ bool on_startup()
+ {
+ sanitize_locale();
+
+#ifdef __GLIBC__
+ const char *ver = gnu_get_libc_version();
+ if (!strcmp(ver, "2.25"))
+ MCLOG_RED(el::Level::Warning, "global", "Running with glibc " << ver << ", hangs may occur - change glibc version if possible");
+#endif
+ return true;
+ }
void set_strict_default_file_permissions(bool strict)
{
#if defined(__MINGW32__) || defined(__MINGW__)
diff --git a/src/common/util.h b/src/common/util.h
index 0f0308b1b..1aac026c1 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -129,6 +129,8 @@ namespace tools
bool sanitize_locale();
+ bool on_startup();
+
/*! \brief Defines a signal handler for win32 and *nix
*/
class signal_handler