Browse Source

added option to include debug-level info

boB Rudis 9 months ago
parent
commit
6718e7f9d6
No known key found for this signature in database
6 changed files with 42 additions and 12 deletions
  1. 2
    2
      R/RcppExports.R
  2. 11
    2
      R/resolver.R
  3. 5
    1
      man/gdns_query.Rd
  4. 4
    0
      man/gdns_resolver.Rd
  5. 5
    4
      src/RcppExports.cpp
  6. 15
    3
      src/resolver.cpp

+ 2
- 2
R/RcppExports.R View File

@@ -47,7 +47,7 @@ int_get_resolvers <- function(gctx) {
47 47
     .Call(`_clandnstine_int_get_resolvers`, gctx)
48 48
 }
49 49
 
50
-int_gdns_query <- function(gctx, name, rr) {
51
-    .Call(`_clandnstine_int_gdns_query`, gctx, name, rr)
50
+int_gdns_query <- function(gctx, name, rr, include_reporting = FALSE) {
51
+    .Call(`_clandnstine_int_gdns_query`, gctx, name, rr, include_reporting)
52 52
 }
53 53
 

+ 11
- 2
R/resolver.R View File

@@ -1,6 +1,8 @@
1 1
 #' Create a gdns DNS over TLS context and populate it with a resolver
2 2
 #' for use in resolution functions
3 3
 #'
4
+#' @note [DNS Privacy](https://dnsprivacy.org/wiki/display/DP/DNS+Privacy+Test+Servers#DNSPrivacyTestServers-DoTservers)
5
+#'       maintains a list of DNS over TLS servers.
4 6
 #' @param resolvers character vector of valid DNS over TLS resolvers;
5 7
 #'        Defaults to Quad9 (`9.9.9.9`).
6 8
 #' @export
@@ -112,15 +114,22 @@ gdns_resolver <- function(resolvers = "9.9.9.9") {
112 114
 #' @param gctx gdns resolver context created with [gdns_resolver()]
113 115
 #' @param name an entity to query for
114 116
 #' @param rr_type what resource record type do you want to queyr for? See `Details`.
117
+#' @param include_reporting if `TRUE` include debugging information for queries
118
+#'        such as the length of time it takes for each query. Default: `FALSE`
115 119
 #' @references <https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml>
116 120
 #' @export
117 121
 #' @examples
118 122
 #' x <- gdns_resolver()
119 123
 #' gdns_query(x, "example.com")
120
-gdns_query <- function(gctx, name, rr_type = "txt") {
124
+gdns_query <- function(gctx, name, rr_type = "txt", rr_class = 1L,
125
+                       include_reporting = FALSE) {
126
+
127
+  rr_class <- rr_class[1]
128
+  if (!rr_class %in% c(1, 3, 4, 254, 255)) rr_class <- 1
121 129
 
122 130
   rr_type <- match.arg(trimws(tolower(rr_type[1])), names(rr_types))
123
-  res <- int_gdns_query(gctx, name, unname(as.integer(rr_types[rr_type])))
131
+  res <- int_gdns_query(gctx, name, unname(as.integer(rr_types[rr_type])),
132
+                        as.integer(rr_class), as.logical(include_reporting))
124 133
   if (length(res)) {
125 134
     out <- jsonlite::fromJSON(res)
126 135
     class(out) <- c("gdns_response", "list")

+ 5
- 1
man/gdns_query.Rd View File

@@ -4,7 +4,8 @@
4 4
 \alias{gdns_query}
5 5
 \title{Arbitrary DNS queries}
6 6
 \usage{
7
-gdns_query(gctx, name, rr_type = "txt")
7
+gdns_query(gctx, name, rr_type = "txt", rr_class = 1L,
8
+  include_reporting = FALSE)
8 9
 }
9 10
 \arguments{
10 11
 \item{gctx}{gdns resolver context created with \code{\link[=gdns_resolver]{gdns_resolver()}}}
@@ -12,6 +13,9 @@ gdns_query(gctx, name, rr_type = "txt")
12 13
 \item{name}{an entity to query for}
13 14
 
14 15
 \item{rr_type}{what resource record type do you want to queyr for? See \code{Details}.}
16
+
17
+\item{include_reporting}{if \code{TRUE} include debugging information for queries
18
+such as the length of time it takes for each query. Default: \code{FALSE}}
15 19
 }
16 20
 \description{
17 21
 Perform any valid resource record inquiry for a given name. See \code{Details}.

+ 4
- 0
man/gdns_resolver.Rd View File

@@ -15,6 +15,10 @@ Defaults to Quad9 (\code{9.9.9.9}).}
15 15
 Create a gdns DNS over TLS context and populate it with a resolver
16 16
 for use in resolution functions
17 17
 }
18
+\note{
19
+\href{https://dnsprivacy.org/wiki/display/DP/DNS+Privacy+Test+Servers#DNSPrivacyTestServers-DoTservers}{DNS Privacy}
20
+maintains a list of DNS over TLS servers.
21
+}
18 22
 \examples{
19 23
 x <- gdns_resolver()
20 24
 x <- gdns_resolver("1.1.1.1")

+ 5
- 4
src/RcppExports.cpp View File

@@ -71,15 +71,16 @@ BEGIN_RCPP
71 71
 END_RCPP
72 72
 }
73 73
 // int_gdns_query
74
-CharacterVector int_gdns_query(SEXP gctx, std::string name, uint16_t rr);
75
-RcppExport SEXP _clandnstine_int_gdns_query(SEXP gctxSEXP, SEXP nameSEXP, SEXP rrSEXP) {
74
+CharacterVector int_gdns_query(SEXP gctx, std::string name, uint16_t rr, bool include_reporting);
75
+RcppExport SEXP _clandnstine_int_gdns_query(SEXP gctxSEXP, SEXP nameSEXP, SEXP rrSEXP, SEXP include_reportingSEXP) {
76 76
 BEGIN_RCPP
77 77
     Rcpp::RObject rcpp_result_gen;
78 78
     Rcpp::RNGScope rcpp_rngScope_gen;
79 79
     Rcpp::traits::input_parameter< SEXP >::type gctx(gctxSEXP);
80 80
     Rcpp::traits::input_parameter< std::string >::type name(nameSEXP);
81 81
     Rcpp::traits::input_parameter< uint16_t >::type rr(rrSEXP);
82
-    rcpp_result_gen = Rcpp::wrap(int_gdns_query(gctx, name, rr));
82
+    Rcpp::traits::input_parameter< bool >::type include_reporting(include_reportingSEXP);
83
+    rcpp_result_gen = Rcpp::wrap(int_gdns_query(gctx, name, rr, include_reporting));
83 84
     return rcpp_result_gen;
84 85
 END_RCPP
85 86
 }
@@ -91,7 +92,7 @@ static const R_CallMethodDef CallEntries[] = {
91 92
     {"_clandnstine_int_gdns_resolver", (DL_FUNC) &_clandnstine_int_gdns_resolver, 1},
92 93
     {"_clandnstine_gdns_get_address", (DL_FUNC) &_clandnstine_gdns_get_address, 2},
93 94
     {"_clandnstine_int_get_resolvers", (DL_FUNC) &_clandnstine_int_get_resolvers, 1},
94
-    {"_clandnstine_int_gdns_query", (DL_FUNC) &_clandnstine_int_gdns_query, 3},
95
+    {"_clandnstine_int_gdns_query", (DL_FUNC) &_clandnstine_int_gdns_query, 4},
95 96
     {NULL, NULL, 0}
96 97
 };
97 98
 

+ 15
- 3
src/resolver.cpp View File

@@ -195,7 +195,8 @@ CharacterVector int_get_resolvers(SEXP gctx) {
195 195
 
196 196
 
197 197
 // [[Rcpp::export]]
198
-CharacterVector int_gdns_query(SEXP gctx, std::string name, uint16_t rr) {
198
+CharacterVector int_gdns_query(SEXP gctx, std::string name, uint16_t rr,
199
+                                 bool include_reporting = false) {
199 200
 
200 201
   uint32_t err;
201 202
   // size_t sz;
@@ -210,7 +211,16 @@ CharacterVector int_gdns_query(SEXP gctx, std::string name, uint16_t rr) {
210 211
   getdns_context *ctxt = (getdns_context *)R_ExternalPtrAddr(gctx);
211 212
   if (gctx == NULL) return(CharacterVector());
212 213
 
213
-  if ((r = getdns_general_sync(ctxt, name.c_str(), rr, NULL, &resp))) {
214
+  getdns_dict *ext_d = getdns_dict_create();
215
+  if (include_reporting) {
216
+    getdns_dict_set_int(ext_d, "return_call_reporting", GETDNS_EXTENSION_TRUE);
217
+  }
218
+  // if (rrclass != 1) {
219
+  //   getdns_dict_set_int(ext_d, "specify_class", (uint32_t)rrclass);
220
+  // }
221
+
222
+  if ((r = getdns_general_sync(ctxt, name.c_str(), rr, ext_d, &resp))) {
223
+    Rf_warning("Bad query");
214 224
   } else if ((r = getdns_dict_get_int(resp, "status", &err))) {
215 225
   } else if (err != GETDNS_RESPSTATUS_GOOD) {
216 226
   } else {
@@ -229,8 +239,10 @@ CharacterVector int_gdns_query(SEXP gctx, std::string name, uint16_t rr) {
229 239
 
230 240
   }
231 241
 
242
+  if (ext_d) getdns_dict_destroy(ext_d);
243
+
232 244
   if (resp) getdns_dict_destroy(resp);
233 245
 
234 246
   if (ok) return(wrap(out)); else return(CharacterVector());
235 247
 
236
-}
248
+}

Loading…
Cancel
Save