Electroneum
tools::DNSResolver Class Reference

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

#include <dns_utils.h>

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...
 

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.

Definition at line 55 of file dns_utils.h.

Constructor & Destructor Documentation

◆ ~DNSResolver()

tools::DNSResolver::~DNSResolver ( )

takes care of freeing C pointers and such

Definition at line 307 of file dns_utils.cpp.

308 {
309  if (m_data)
310  {
311  if (m_data->m_ub_context != NULL)
312  {
313  ub_ctx_delete(m_data->m_ub_context);
314  }
315  delete m_data;
316  }
317 }
void ub_ctx_delete(struct ub_ctx *ctx)
Here is the call graph for this function:

Member Function Documentation

◆ create()

DNSResolver tools::DNSResolver::create ( )
static

Gets a new instance of DNSResolver.

Returns
returns a pointer to the new object

Definition at line 391 of file dns_utils.cpp.

392 {
393  return DNSResolver();
394 }
Here is the caller graph for this function:

◆ 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

Definition at line 370 of file dns_utils.cpp.

371 {
372  std::string addr(oa_addr);
373  auto first_at = addr.find("@");
374  if (first_at == std::string::npos)
375  return addr;
376 
377  // convert name@domain.tld to name.domain.tld
378  addr.replace(first_at, 1, ".");
379 
380  return addr;
381 }
::std::string string
Definition: gtest-port.h:1097
Here is the caller graph for this function:

◆ 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

Definition at line 355 of file dns_utils.cpp.

356 {
357  return get_record(url, DNS_TYPE_A, ipv4_to_string, dnssec_available, dnssec_valid);
358 }
boost::optional< std::string > ipv4_to_string(const char *src, size_t len)
Definition: dns_utils.cpp:136
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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

Definition at line 360 of file dns_utils.cpp.

361 {
362  return get_record(url, DNS_TYPE_AAAA, ipv6_to_string, dnssec_available, dnssec_valid);
363 }
boost::optional< std::string > ipv6_to_string(const char *src, size_t len)
Definition: dns_utils.cpp:160
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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

Definition at line 365 of file dns_utils.cpp.

366 {
367  return get_record(url, DNS_TYPE_TXT, txt_to_string, dnssec_available, dnssec_valid);
368 }
boost::optional< std::string > txt_to_string(const char *src, size_t len)
Definition: dns_utils.cpp:186
Here is the call graph for this function:
Here is the caller graph for this function:

◆ instance()

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

Gets the singleton instance of DNSResolver.

Returns
returns a pointer to the singleton

Definition at line 383 of file dns_utils.cpp.

384 {
385  boost::lock_guard<boost::mutex> lock(instance_lock);
386 
387  static DNSResolver staticInstance;
388  return staticInstance;
389 }
Here is the caller graph for this function:

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