Electroneum
Loading...
Searching...
No Matches
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
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
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.
std::string get_dns_format_from_oa_address (const std::string &oa_addr)
 Gets a DNS address from OpenAlias format.

Static Public Member Functions

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

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}
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)
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)
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)
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:
  • /home/abuild/rpmbuild/BUILD/electroneum-5.1.3.1-build/electroneum-5.1.3.1/src/common/dns_utils.h
  • /home/abuild/rpmbuild/BUILD/electroneum-5.1.3.1-build/electroneum-5.1.3.1/src/common/dns_utils.cpp