aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2015-01-08 12:17:08 +0200
committerRiccardo Spagni <ric@spagni.net>2015-01-08 12:18:00 +0200
commit24ddfa792ef0ab7062ce373351eaa4846b0737f4 (patch)
treeeba682c85ba439d985556c2f178f49619eda894c /src
parentMerge pull request #211 (diff)
parentstd::atomic_flag has no copy/move constructor, can't have a vector (diff)
downloadmonero-24ddfa792ef0ab7062ce373351eaa4846b0737f4.tar.xz
Merge pull request #206
1b46226 std::atomic_flag has no copy/move constructor, can't have a vector (Thomas Winget) df53c0a small typo in previous commit (Thomas Winget) 4a53898 DNS seed timeout and fallback (Thomas Winget)
Diffstat (limited to 'src')
-rw-r--r--src/cryptonote_config.h2
-rw-r--r--src/p2p/net_node.inl68
2 files changed, 59 insertions, 11 deletions
diff --git a/src/cryptonote_config.h b/src/cryptonote_config.h
index 236bef388..e26945086 100644
--- a/src/cryptonote_config.h
+++ b/src/cryptonote_config.h
@@ -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
diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl
index 11fc7220f..3454e112c 100644
--- a/src/p2p/net_node.inl
+++ b/src/p2p/net_node.inl
@@ -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"
@@ -46,13 +49,13 @@
// We have to look for miniupnpc headers in different places, dependent on if its compiled or external
#ifdef UPNP_STATIC
- #include <miniupnpc/miniupnpc.h>
- #include <miniupnpc/upnpcommands.h>
- #include <miniupnpc/upnperrors.h>
+ #include <miniupnpc/miniupnpc.h>
+ #include <miniupnpc/upnpcommands.h>
+ #include <miniupnpc/upnperrors.h>
#else
- #include "miniupnpc.h"
- #include "upnpcommands.h"
- #include "upnperrors.h"
+ #include "miniupnpc.h"
+ #include "upnpcommands.h"
+ #include "upnperrors.h"
#endif
#define NET_MAKE_IP(b1,b2,b3,b4) ((LPARAM)(((DWORD)(b1)<<24)+((DWORD)(b2)<<16)+((DWORD)(b3)<<8)+((DWORD)(b4))))
@@ -252,19 +255,62 @@ 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;
+ dns_results.resize(m_seed_nodes_list.size());
+
+ std::unique_ptr<std::atomic_flag[]> dns_finished(new std::atomic_flag[m_seed_nodes_list.size()]);
+
+ // set each flag, thread will release when finished
+ for (uint64_t i = 0; i < m_seed_nodes_list.size(); ++i)
+ dns_finished[i].test_and_set();
+
+ uint64_t result_index = 0;
for (const std::string& addr_str : m_seed_nodes_list)
{
- // 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)
+
+ 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().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)
+ {
+ boost::this_thread::sleep(boost::posix_time::milliseconds(sleep_interval_ms));
+ bool all_done = false;
+ for (uint64_t i = 0; i < m_seed_nodes_list.size(); ++i)
+ {
+ if (dns_finished[i].test_and_set())
+ break;
+ else
+ dns_finished[i].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, a + ":18080");
+ 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");