Electroneum
Loading...
Searching...
No Matches
dns_utils.h
Go to the documentation of this file.
1// Copyrights(c) 2017-2021, The Electroneum Project
2// Copyrights(c) 2014-2019, The Monero Project
3//
4// All rights reserved.
5//
6// Redistribution and use in source and binary forms, with or without modification, are
7// permitted provided that the following conditions are met:
8//
9// 1. Redistributions of source code must retain the above copyright notice, this list of
10// conditions and the following disclaimer.
11//
12// 2. Redistributions in binary form must reproduce the above copyright notice, this list
13// of conditions and the following disclaimer in the documentation and/or other
14// materials provided with the distribution.
15//
16// 3. Neither the name of the copyright holder nor the names of its contributors may be
17// used to endorse or promote products derived from this software without specific
18// prior written permission.
19//
20// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
21// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22
23// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
24// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
29// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30#pragma once
31
32#include <vector>
33#include <string>
34#include <functional>
35#include <boost/optional/optional_fwd.hpp>
36
37namespace tools
38{
39
40// RFC defines for record types and classes for DNS, gleaned from ldns source
41const static int DNS_CLASS_IN = 1;
42const static int DNS_TYPE_A = 1;
43const static int DNS_TYPE_TXT = 16;
44const static int DNS_TYPE_AAAA = 8;
45
46struct DNSResolverData;
47
55class DNSResolver
56{
57private:
58
64 DNSResolver();
65
66public:
67
72
85 std::vector<std::string> get_ipv4(const std::string& url, bool& dnssec_available, bool& dnssec_valid);
86
97 std::vector<std::string> get_ipv6(const std::string& url, bool& dnssec_available, bool& dnssec_valid);
98
107 // TODO: modify this to accommodate DNSSEC
108 std::vector<std::string> get_txt_record(const std::string& url, bool& dnssec_available, bool& dnssec_valid);
109
120 std::string get_dns_format_from_oa_address(const std::string& oa_addr);
121
127 static DNSResolver& instance();
128
134 static DNSResolver create();
135
136private:
137
148 // TODO: modify this to accommodate DNSSEC
149 std::vector<std::string> get_record(const std::string& url, int record_type, boost::optional<std::string> (*reader)(const char *,size_t), bool& dnssec_available, bool& dnssec_valid);
150
158 bool check_address_syntax(const char *addr) const;
159
160 DNSResolverData *m_data;
161}; // class DNSResolver
162
163namespace dns_utils
164{
165
166std::string address_from_txt_record(const std::string& s);
167std::vector<std::string> addresses_from_url(const std::string& url, bool& dnssec_valid);
168
169std::string get_account_address_as_str_from_url(const std::string& url, bool& dnssec_valid, std::function<std::string(const std::string&, const std::vector<std::string>&, bool)> confirm_dns);
170
171bool load_txt_records_from_dns(std::vector<std::string> &records, const std::vector<std::string> &dns_urls, std::string type);
172
173std::vector<std::string> parse_dns_public(const char *s);
174
175std::vector<std::string> parse_dns_public(const char *s);
176
177} // namespace tools::dns_utils
178
179} // namespace tools
static DNSResolver & instance()
Gets the singleton instance of DNSResolver.
std::vector< std::string > get_txt_record(const std::string &url, bool &dnssec_available, bool &dnssec_valid)
gets all TXT records from a DNS query for the supplied URL; if no TXT record present returns an empty...
std::string get_dns_format_from_oa_address(const std::string &oa_addr)
Gets a DNS address from OpenAlias format.
~DNSResolver()
takes care of freeing C pointers and such
std::vector< std::string > get_ipv4(const std::string &url, bool &dnssec_available, bool &dnssec_valid)
gets ipv4 addresses from DNS query of a URL
std::vector< std::string > get_ipv6(const std::string &url, bool &dnssec_available, bool &dnssec_valid)
gets ipv6 addresses from DNS query
static DNSResolver create()
Gets a new instance of DNSResolver.
bool load_txt_records_from_dns(std::vector< std::string > &good_records, const std::vector< std::string > &dns_urls, std::string type)
std::vector< std::string > addresses_from_url(const std::string &url, bool &dnssec_valid)
gets a electroneum address from the TXT record of a DNS entry
std::string get_account_address_as_str_from_url(const std::string &url, bool &dnssec_valid, std::function< std::string(const std::string &, const std::vector< std::string > &, bool)> dns_confirm)
std::string address_from_txt_record(const std::string &s)
std::vector< std::string > parse_dns_public(const char *s)
Various Tools.
Definition tools.cpp:31