aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorThomas Winget <tewinget@gmail.com>2014-09-24 23:50:51 -0400
committerThomas Winget <tewinget@gmail.com>2014-09-24 23:50:51 -0400
commit145dc19eebd2c9f289381debfa1fb7a4b8c71ef7 (patch)
treec511ed7ecb8b3bdd2da26e55801d20f6326f656a /src/common
parentMerge pull request #159 (diff)
parentRemove LDNS dep and fix a bug in libunbound const correctness fix (diff)
downloadmonero-145dc19eebd2c9f289381debfa1fb7a4b8c71ef7.tar.xz
Merge pull request #160 from tewinget/remove_ldns_dep
Remove ldns dependency
Diffstat (limited to 'src/common')
-rw-r--r--src/common/dns_utils.cpp13
-rw-r--r--src/common/dns_utils.h6
-rw-r--r--src/common/varint.h25
3 files changed, 36 insertions, 8 deletions
diff --git a/src/common/dns_utils.cpp b/src/common/dns_utils.cpp
index e1151e190..346761e74 100644
--- a/src/common/dns_utils.cpp
+++ b/src/common/dns_utils.cpp
@@ -29,7 +29,6 @@
#include "common/dns_utils.h"
#include <cstring>
#include <sstream>
-#include <ldns/rr.h> // for RR type and class defs
#include <unbound.h>
namespace tools
@@ -126,7 +125,7 @@ std::vector<std::string> DNSResolver::get_ipv4(const std::string& url)
strncpy(urlC, url.c_str(), 999);
urlC[999] = '\0';
- if (!check_address_syntax(url))
+ if (!check_address_syntax(urlC))
{
return addresses;
}
@@ -135,7 +134,7 @@ std::vector<std::string> DNSResolver::get_ipv4(const std::string& url)
ub_result_ptr result;
// call DNS resolver, blocking. if return value not zero, something went wrong
- if (!ub_resolve(m_data->m_ub_context, urlC, LDNS_RR_TYPE_A, LDNS_RR_CLASS_IN, &(result.ptr)))
+ if (!ub_resolve(m_data->m_ub_context, urlC, DNS_TYPE_A, DNS_CLASS_IN, &(result.ptr)))
{
if (result.ptr->havedata)
{
@@ -157,7 +156,7 @@ std::vector<std::string> DNSResolver::get_ipv6(const std::string& url)
strncpy(urlC, url.c_str(), 999);
urlC[999] = '\0';
- if (!check_address_syntax(url))
+ if (!check_address_syntax(urlC))
{
return addresses;
}
@@ -165,7 +164,7 @@ std::vector<std::string> DNSResolver::get_ipv6(const std::string& url)
ub_result_ptr result;
// call DNS resolver, blocking. if return value not zero, something went wrong
- if (!ub_resolve(m_data->m_ub_context, urlC, LDNS_RR_TYPE_AAAA, LDNS_RR_CLASS_IN, &(result.ptr)))
+ if (!ub_resolve(m_data->m_ub_context, urlC, DNS_TYPE_AAAA, DNS_CLASS_IN, &(result.ptr)))
{
if (result.ptr->havedata)
{
@@ -187,7 +186,7 @@ std::vector<std::string> DNSResolver::get_txt_record(const std::string& url)
strncpy(urlC, url.c_str(), 999);
urlC[999] = '\0';
- if (!check_address_syntax(url))
+ if (!check_address_syntax(urlC))
{
return records;
}
@@ -195,7 +194,7 @@ std::vector<std::string> DNSResolver::get_txt_record(const std::string& url)
ub_result_ptr result;
// call DNS resolver, blocking. if return value not zero, something went wrong
- if (!ub_resolve(m_data->m_ub_context, urlC, LDNS_RR_TYPE_TXT, LDNS_RR_CLASS_IN, &(result.ptr)))
+ if (!ub_resolve(m_data->m_ub_context, urlC, DNS_TYPE_TXT, DNS_CLASS_IN, &(result.ptr)))
{
if (result.ptr->havedata)
{
diff --git a/src/common/dns_utils.h b/src/common/dns_utils.h
index 375f6ba30..dd6946dc4 100644
--- a/src/common/dns_utils.h
+++ b/src/common/dns_utils.h
@@ -32,6 +32,12 @@
namespace tools
{
+// RFC defines for record types and classes for DNS, gleaned from ldns source
+const static int DNS_CLASS_IN = 1;
+const static int DNS_TYPE_A = 1;
+const static int DNS_TYPE_TXT = 16;
+const static int DNS_TYPE_AAAA = 8;
+
struct DNSResolverData;
/**
diff --git a/src/common/varint.h b/src/common/varint.h
index 5a73c2746..57386597a 100644
--- a/src/common/varint.h
+++ b/src/common/varint.h
@@ -36,7 +36,7 @@
#include <sstream>
#include <string>
/*! \file varint.h
- * \breif provides the implementation of varint's
+ * \brief provides the implementation of varint's
*
* The representation of varints is rather odd. The first bit of each
* octet is significant, it represents wheter there is another part
@@ -52,6 +52,29 @@
namespace tools {
+ template<typename T>
+ size_t get_varint_packed_size(T v)
+ {
+ if(v <= 127)
+ return 1;
+ else if(v <= 16383)
+ return 2;
+ else if(v <= 2097151)
+ return 3;
+ else if(v <= 268435455)
+ return 4;
+ else if(v <= 34359738367)
+ return 5;
+ else if(v <= 4398046511103)
+ return 6;
+ else if(v <= 4398046511103)
+ return 6;
+ else if(v <= 562949953421311)
+ return 7;
+ else
+ return 8;
+ }
+
/*! \brief Error codes for varint
*/
enum {