mirror of
https://git.wownero.com/wownero/wownero.git
synced 2024-08-15 01:03:23 +00:00
DNS seed timeout and fallback
This commit is contained in:
parent
f4675dc05d
commit
4a53898764
2 changed files with 61 additions and 11 deletions
|
@ -33,6 +33,8 @@
|
|||
#include <string>
|
||||
#include <boost/uuid/uuid.hpp>
|
||||
|
||||
#define CRYPTONOTE_DNS_TIMEOUT_MS 20000
|
||||
|
||||
#define CRYPTONOTE_MAX_BLOCK_NUMBER 500000000
|
||||
#define CRYPTONOTE_MAX_BLOCK_SIZE 500000000 // block header blob limit, never used!
|
||||
#define CRYPTONOTE_GETBLOCKTEMPLATE_MAX_BLOCK_SIZE 196608 //size of block (bytes) that is the maximum that miners will produce
|
||||
|
|
|
@ -31,6 +31,9 @@
|
|||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <atomic>
|
||||
|
||||
#include "version.h"
|
||||
#include "string_tools.h"
|
||||
|
@ -252,19 +255,64 @@ namespace nodetool
|
|||
// add the result addresses as seed nodes
|
||||
// TODO: at some point add IPv6 support, but that won't be relevant
|
||||
// for some time yet.
|
||||
|
||||
std::vector<std::vector<std::string>> dns_results;
|
||||
|
||||
std::vector<std::atomic_flag> dns_finished;
|
||||
|
||||
dns_results.resize(m_seed_nodes_list.size());
|
||||
dns_finished.resize(m_seed_nodes_list.size());
|
||||
|
||||
// set each flag, thread will release when finished
|
||||
for (auto& u : dns_finished)
|
||||
u.test_and_set();
|
||||
|
||||
uint64_t result_index = 0;
|
||||
for (const std::string& addr_str : m_seed_nodes_list)
|
||||
{
|
||||
|
||||
uint64_t result_index_capture = result_index++;
|
||||
boost::thread t([&]
|
||||
{
|
||||
// TODO: care about dnssec avail/valid
|
||||
bool avail, valid;
|
||||
std::vector<std::string> addr_list = tools::DNSResolver::instance().get_ipv4(addr_str, avail, valid);
|
||||
for (const std::string& a : addr_list)
|
||||
std::vector<std::string> addr_list = tools::DNSResolver().get_ipv4(addr_str, avail, valid);
|
||||
|
||||
dns_results[result_index_capture] = addr_list;
|
||||
dns_finished[result_index_capture].clear();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
uint64_t sleep_count = 0;
|
||||
uint64_t sleep_interval_ms = 100;
|
||||
while (sleep_count++ * sleep_interval_ms < CRYPTONOTE_DNS_TIMEOUT_MS)
|
||||
{
|
||||
append_net_address(m_seed_nodes, a + ":18080");
|
||||
boost::this_thread::sleep(boost::posix_time::milliseconds());
|
||||
bool all_done = false;
|
||||
for (auto& done : dns_finished)
|
||||
{
|
||||
if (done.test_and_set())
|
||||
break;
|
||||
else
|
||||
done.clear();
|
||||
all_done = true;
|
||||
}
|
||||
if (all_done)
|
||||
break;
|
||||
}
|
||||
|
||||
for (const auto& result : dns_results)
|
||||
{
|
||||
for (const auto& addr_string : result)
|
||||
{
|
||||
append_net_address(m_seed_nodes, addr_string + ":18080");
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_seed_nodes.size())
|
||||
{
|
||||
LOG_PRINT_L0("DNS seed node lookup either timed out or failed, falling back to defaults");
|
||||
append_net_address(m_seed_nodes, "62.210.78.186:18080");
|
||||
append_net_address(m_seed_nodes, "195.12.60.154:18080");
|
||||
append_net_address(m_seed_nodes, "54.241.246.125:18080");
|
||||
|
|
Loading…
Reference in a new issue