From f182acdd3653f8e5ecb35c97a6ef36be0abf5f6a Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Thu, 21 Sep 2017 09:23:08 +0100 Subject: dns_utils: query DNS records in parallel --- src/common/dns_utils.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/common/dns_utils.cpp b/src/common/dns_utils.cpp index e7ff11c5c..57c856597 100644 --- a/src/common/dns_utils.cpp +++ b/src/common/dns_utils.cpp @@ -447,19 +447,28 @@ bool load_txt_records_from_dns(std::vector &good_records, const std std::uniform_int_distribution dis(0, dns_urls.size() - 1); size_t first_index = dis(gen); - bool avail, valid; + // send all requests in parallel + std::vector threads(dns_urls.size()); + std::deque avail(dns_urls.size(), false), valid(dns_urls.size(), false); + for (size_t n = 0; n < dns_urls.size(); ++n) + { + threads[n] = boost::thread([n, dns_urls, &records, &avail, &valid](){ + records[n] = tools::DNSResolver::instance().get_txt_record(dns_urls[n], avail[n], valid[n]); + }); + } + for (size_t n = 0; n < dns_urls.size(); ++n) + threads[n].join(); + size_t cur_index = first_index; do { - std::string url = dns_urls[cur_index]; - - records[cur_index] = tools::DNSResolver::instance().get_txt_record(url, avail, valid); - if (!avail) + const std::string &url = dns_urls[cur_index]; + if (!avail[cur_index]) { records[cur_index].clear(); LOG_PRINT_L2("DNSSEC not available for checkpoint update at URL: " << url << ", skipping."); } - if (!valid) + if (!valid[cur_index]) { records[cur_index].clear(); LOG_PRINT_L2("DNSSEC validation failed for checkpoint update at URL: " << url << ", skipping."); -- cgit v1.2.3