Electroneum
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
tools::DNSResolver Class Reference

Provides high-level access to DNS resolution. More...

#include <dns_utils.h>

Collaboration diagram for tools::DNSResolver:
Collaboration graph
[legend]

Public Member Functions

 ~DNSResolver ()
 takes care of freeing C pointers and such More...
 
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 More...
 
std::vector< std::string > get_ipv6 (const std::string &url, bool &dnssec_available, bool &dnssec_valid)
 gets ipv6 addresses from DNS query More...
 
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 vector. More...
 
std::string get_dns_format_from_oa_address (const std::string &oa_addr)
 Gets a DNS address from OpenAlias format. More...
 

Static Public Member Functions

static DNSResolverinstance ()
 Gets the singleton instance of DNSResolver. More...
 
static DNSResolver create ()
 Gets a new instance of DNSResolver. More...
 

Private Member Functions

 DNSResolver ()
 Constructs an instance of DNSResolver. More...
 
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)
 gets all records of a given type from a DNS query for the supplied URL; if no such record is present returns an empty vector. More...
 
bool check_address_syntax (const char *addr) const
 Checks a string to see if it looks like a URL. More...
 

Private Attributes

DNSResolverDatam_data
 

Detailed Description

Provides high-level access to DNS resolution.

This class is designed to provide a high-level abstraction to DNS resolution functionality, including access to TXT records and such. It will also handle DNSSEC validation of the results.

Constructor & Destructor Documentation

◆ DNSResolver()

tools::DNSResolver::DNSResolver ( )
private

Constructs an instance of DNSResolver.

Constructs a class instance and does setup stuff for the backend resolver.

◆ ~DNSResolver()

tools::DNSResolver::~DNSResolver ( )

takes care of freeing C pointers and such

Member Function Documentation

◆ check_address_syntax()

bool tools::DNSResolver::check_address_syntax ( const char *  addr) const
private

Checks a string to see if it looks like a URL.

Parameters
addrthe string to be checked
Returns
true if it looks enough like a URL, false if not

◆ create()

DNSResolver tools::DNSResolver::create ( )
static

Gets a new instance of DNSResolver.

Returns
returns a pointer to the new object

◆ get_dns_format_from_oa_address()

std::string tools::DNSResolver::get_dns_format_from_oa_address ( const std::string &  oa_addr)

Gets a DNS address from OpenAlias format.

If the address looks good, but contains one @ symbol, replace that with a . e.g. donat.nosp@m.e@el.nosp@m.ectro.nosp@m.neum.nosp@m..com becomes donate.electroneum.com

Parameters
oa_addrOpenAlias address
Returns
dns_addr DNS address

◆ get_ipv4()

std::vector< std::string > tools::DNSResolver::get_ipv4 ( const std::string &  url,
bool dnssec_available,
bool dnssec_valid 
)

gets ipv4 addresses from DNS query of a URL

returns a vector of all IPv4 "A" records for given URL. If no "A" records found, returns an empty vector.

Parameters
urlA string containing a URL to query for
dnssec_available
Returns
vector of strings containing ipv4 addresses

◆ get_ipv6()

std::vector< std::string > tools::DNSResolver::get_ipv6 ( const std::string &  url,
bool dnssec_available,
bool dnssec_valid 
)

gets ipv6 addresses from DNS query

returns a vector of all IPv6 "A" records for given URL. If no "A" records found, returns an empty vector.

Parameters
urlA string containing a URL to query for
Returns
vector of strings containing ipv6 addresses

◆ get_record()

std::vector< std::string > tools::DNSResolver::get_record ( const std::string &  url,
int  record_type,
boost::optional< std::string >(*)(const char *, size_t)  reader,
bool dnssec_available,
bool dnssec_valid 
)
private

gets all records of a given type from a DNS query for the supplied URL; if no such record is present returns an empty vector.

Parameters
urlA string containing a URL to query for
record_typethe record type to retrieve (DNS_TYPE_A, etc)
readera function that converts a record data to a string
Returns
A vector of strings containing the requested record; or an empty vector

◆ get_txt_record()

std::vector< std::string > tools::DNSResolver::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 vector.

Parameters
urlA string containing a URL to query for
Returns
A vector of strings containing a TXT record; or an empty vector

◆ instance()

DNSResolver & tools::DNSResolver::instance ( )
static

Gets the singleton instance of DNSResolver.

Returns
returns a pointer to the singleton

Member Data Documentation

◆ m_data

DNSResolverData* tools::DNSResolver::m_data
private

The documentation for this class was generated from the following files: