Browse Source

additional getters/setters

master
boB Rudis 1 year ago
parent
commit
6559c85744
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
17 changed files with 448 additions and 55 deletions
  1. +6
    -1
      NAMESPACE
  2. +40
    -0
      R/RcppExports.R
  3. +2
    -1
      R/print-context.R
  4. +33
    -3
      R/resolver.R
  5. +17
    -7
      README.Rmd
  6. +33
    -15
      README.md
  7. +5
    -5
      man/gdns_context.Rd
  8. +14
    -0
      man/gdns_get_timeout.Rd
  9. +21
    -0
      man/gdns_set_hosts.Rd
  10. +18
    -0
      man/gdns_set_round_robin_upstreams.Rd
  11. +16
    -0
      man/gdns_set_timeout.Rd
  12. +24
    -0
      man/gdns_update_resolvers.Rd
  13. +12
    -0
      man/int_gdns_set_hosts.Rd
  14. +12
    -0
      man/int_gdns_update_resolvers.Rd
  15. +64
    -0
      src/RcppExports.cpp
  16. +129
    -21
      src/clandnstine-main.cpp
  17. +2
    -2
      tests/testthat/test-clandnstine.R

+ 6
- 1
NAMESPACE View File

@@ -3,10 +3,15 @@
S3method(print,gctx)
S3method(print,gdns_response)
export("%>%")
export(gdns_context)
export(gdns_get_address)
export(gdns_get_timeout)
export(gdns_lib_version)
export(gdns_query)
export(gdns_resolver)
export(gdns_set_hosts)
export(gdns_set_round_robin_upstreams)
export(gdns_set_timeout)
export(gdns_update_resolvers)
importFrom(Rcpp,sourceCpp)
importFrom(jsonlite,fromJSON)
importFrom(magrittr,"%>%")


+ 40
- 0
R/RcppExports.R View File

@@ -8,6 +8,46 @@ gdns_lib_version <- function() {
.Call(`_clandnstine_gdns_lib_version`)
}

#' Internal version of gdns_update_resolvers
#' @keywords internal
int_gdns_update_resolvers <- function(gctx, resolvers) {
.Call(`_clandnstine_int_gdns_update_resolvers`, gctx, resolvers)
}

#' Specify the number of milliseconds to wait for request to return
#'
#' @param gctx gdns resolver context created with [gdns_resolver()]
#' @param timeout number of milliseconds (integer; i.e. not-fractional)
#' @export
gdns_set_timeout <- function(gctx, timeout) {
.Call(`_clandnstine_gdns_set_timeout`, gctx, timeout)
}

#' Retreive the number of milliseconds to wait for request to return
#'
#' @param gctx gdns resolver context created with [gdns_resolver()]
#' @export
gdns_get_timeout <- function(gctx) {
.Call(`_clandnstine_gdns_get_timeout`, gctx)
}

#' Set/unset context to round robin queries over the available upstreams
#' when resolving with the stub resolution type.
#'
#' @md
#' @param gctx gdns resolver context created with [gdns_resolver()]
#' @param flag if `TRUE` (the default) round robin queries when using more than one stub resolver,
#' @export
gdns_set_round_robin_upstreams <- function(gctx, flag = TRUE) {
.Call(`_clandnstine_gdns_set_round_robin_upstreams`, gctx, flag)
}

#' Internal version of gdns_set_hosts()
#' @keywords internal
int_gdns_set_hosts <- function(gctx, hosts) {
.Call(`_clandnstine_int_gdns_set_hosts`, gctx, hosts)
}

#' Test whether an object is an external pointer
#'
#' @param x object to test


+ 2
- 1
R/print-context.R View File

@@ -12,7 +12,8 @@ print.gctx <- function(x, ...) {
"<gdns v", gdns_lib_version(),
" resolver context; resolvers: [",
paste0(int_get_resolvers(x), collapse=", "),
"]>\n", sep = ""
"]; timeout: ", prettyNum(gdns_get_timeout(x), big.mark=","), " ms",
">", "\n", sep = ""
)
}
}

+ 33
- 3
R/resolver.R View File

@@ -7,12 +7,42 @@
#' Defaults to Quad9 (`9.9.9.9`).
#' @export
#' @examples
#' x <- gdns_resolver()
#' x <- gdns_resolver("1.1.1.1")
gdns_resolver <- function(resolvers = "9.9.9.9") {
#' x <- gdns_context()
#' x <- gdns_context("1.1.1.1")
gdns_context <- function(resolvers = "9.9.9.9") {
int_gdns_resolver(resolvers)
}

#' Changes the list of resolvers in an already created context for use in resolution functions
#'
#' @note [DNS Privacy](https://dnsprivacy.org/wiki/display/DP/DNS+Privacy+Test+Servers#DNSPrivacyTestServers-DoTservers)
#' maintains a list of DNS over TLS servers.
#' @param gctx gdns resolver context created with [gdns_resolver()]
#' @param resolvers character vector of valid DNS over TLS resolvers
#' @export
#' @examples
#' x <- gdns_context()
#' x <- gdns_update_resolvers("1.1.1.1")
gdns_update_resolvers<- function(gctx, resolvers) {
int_gdns_update_resolvers(gctx, resolvers)
}

#' Initialized the context's local names namespace with values from the given hosts file.
#'
#' @param gctx gdns resolver context created with [gdns_resolver()]
#' @param hosts_file path to a valid `hosts` file (e.g. "`/etc/hosts`). This value
#' will be [path.expand()]ed.
#' @export
#' @examples
#' x <- gdns_context()
#' x <- gdns_set_hosts(x, "/etc/hosts")
gdns_set_hosts<- function(gctx, hosts_file) {
hosts_file <- path.expand(hosts_file[1])
stopifnot(file.exists(hosts_file))
int_gdns_set_hosts(gctx, hosts_file)
}


#' Arbitrary DNS queries
#'
#' Perform any valid resource record inquiry for a given name. See `Details`.


+ 17
- 7
README.Rmd View File

@@ -85,10 +85,16 @@ It's stupid slow, consumes more CPU and bandwidth but forces adversaries to work

The following functions are implemented:

- `gdns_get_address`: Resolve a host to an addrss
- `gdns_lib_version`: Return gdns library version
- `gdns_query`: Arbitrary DNS queries
- `gdns_resolver`: Create a gdns DNS over TLS context and populate it with a resolver for use in resolution functions

- `gdns_context`: Create a gdns DNS over TLS context and populate it with a resolver for use in resolution functions
- `gdns_get_address`: Resolve a host to an addrss
- `gdns_get_timeout`: Retreive the number of milliseconds to wait for request to return
- `gdns_lib_version`: Return gdns library version
- `gdns_query`: Arbitrary DNS queries
- `gdns_set_hosts`: Initialized the context's local names namespace with values from the given hosts file.
- `gdns_set_round_robin_upstreams`: Set/unset context to round robin queries over the available upstreams when resolving with the stub resolution type.
- `gdns_set_timeout`: Specify the number of milliseconds to wait for request to return
- `gdns_update_resolvers`: Changes the list of resolvers in an already created context for use in resolution functions

## Installation

@@ -113,11 +119,15 @@ packageVersion("clandnstine")
```{r addr}
gdns_lib_version()

(x <- gdns_resolver())
(x <- gdns_context())

(x <- gdns_context("1.1.1.1"))

(x <- gdns_context(c("8.8.8.8", "1.1.1.1", "9.9.9.9")))

(x <- gdns_resolver("1.1.1.1"))
(gdns_set_timeout(x, 2000))

(x <- gdns_resolver(c("8.8.8.8", "1.1.1.1", "9.9.9.9")))
(gdns_update_resolvers(x, "1.1.1.1"))

(gdns_get_address(x, "rud.is"))



+ 33
- 15
README.md View File

@@ -111,11 +111,22 @@ to work pretty hard to try to figure out what you’re looking for.

The following functions are implemented:

- `gdns_context`: Create a gdns DNS over TLS context and populate it
with a resolver for use in resolution functions
- `gdns_get_address`: Resolve a host to an addrss
- `gdns_get_timeout`: Retreive the number of milliseconds to wait for
request to return
- `gdns_lib_version`: Return gdns library version
- `gdns_query`: Arbitrary DNS queries
- `gdns_resolver`: Create a gdns DNS over TLS context and populate it
with a resolver for use in resolution functions
- `gdns_set_hosts`: Initialized the context’s local names namespace
with values from the given hosts file.
- `gdns_set_round_robin_upstreams`: Set/unset context to round robin
queries over the available upstreams when resolving with the stub
resolution type.
- `gdns_set_timeout`: Specify the number of milliseconds to wait for
request to return
- `gdns_update_resolvers`: Changes the list of resolvers in an already
created context for use in resolution functions

## Installation

@@ -141,22 +152,28 @@ packageVersion("clandnstine")
gdns_lib_version()
## [1] "1.5.1"

(x <- gdns_resolver())
## <gdns v1.5.1 resolver context; resolvers: [9.9.9.9]>
(x <- gdns_context())
## <gdns v1.5.1 resolver context; resolvers: [9.9.9.9]; timeout: 5,000 ms>

(x <- gdns_context("1.1.1.1"))
## <gdns v1.5.1 resolver context; resolvers: [1.1.1.1]; timeout: 5,000 ms>

(x <- gdns_context(c("8.8.8.8", "1.1.1.1", "9.9.9.9")))
## <gdns v1.5.1 resolver context; resolvers: [8.8.8.8, 1.1.1.1, 9.9.9.9]; timeout: 5,000 ms>

(x <- gdns_resolver("1.1.1.1"))
## <gdns v1.5.1 resolver context; resolvers: [1.1.1.1]>
(gdns_set_timeout(x, 2000))
## <gdns v1.5.1 resolver context; resolvers: [8.8.8.8, 1.1.1.1, 9.9.9.9]; timeout: 2,000 ms>

(x <- gdns_resolver(c("8.8.8.8", "1.1.1.1", "9.9.9.9")))
## <gdns v1.5.1 resolver context; resolvers: [8.8.8.8, 1.1.1.1, 9.9.9.9]>
(gdns_update_resolvers(x, "1.1.1.1"))
## <gdns v1.5.1 resolver context; resolvers: [1.1.1.1]; timeout: 2,000 ms>

(gdns_get_address(x, "rud.is"))
## [1] "2604:a880:800:10::6bc:2001" "104.236.112.222"

(gdns_get_address(x, "yahoo.com"))
## [1] "2001:4998:c:1023::5" "2001:4998:58:1836::11" "2001:4998:44:41d::3" "2001:4998:44:41d::4"
## [5] "2001:4998:c:1023::4" "2001:4998:58:1836::10" "98.138.219.231" "98.138.219.232"
## [9] "98.137.246.8" "72.30.35.9" "72.30.35.10" "98.137.246.7"
## [1] "2001:4998:44:41d::4" "2001:4998:58:1836::10" "2001:4998:58:1836::11" "2001:4998:c:1023::4"
## [5] "2001:4998:c:1023::5" "2001:4998:44:41d::3" "98.138.219.232" "72.30.35.9"
## [9] "72.30.35.10" "98.137.246.7" "98.137.246.8" "98.138.219.231"

(gdns_get_address(x, "yahoo.commmm"))
## character(0)
@@ -169,9 +186,10 @@ str(leno <- gdns_query(x, "lenovo.com", "txt"), 1)
## List of 5
## $ answer_type : int 800
## $ canonical_name: chr "lenovo.com."
## $ replies_full : int [1, 1:600] 135 135 129 128 0 1 0 8 0 0 ...
## $ replies_full : int [1, 1:936] 55 119 129 128 0 1 0 8 0 0 ...
## $ replies_tree :'data.frame': 1 obs. of 7 variables:
## $ status : int 900
## - attr(*, "class")= chr [1:2] "gdns_response" "list"

sort(unlist(leno$replies_tree$answer[[1]]$rdata$txt_strings))
## [1] "a82c74b37aa84e7c8580f0e32f4d795d"
@@ -191,9 +209,9 @@ Yep. Advertising even in DNS `TXT` records (see item number

| Lang | \# Files | (%) | LoC | (%) | Blank lines | (%) | \# Lines | (%) |
| :--- | -------: | ---: | --: | ---: | ----------: | ---: | -------: | ---: |
| C++ | 3 | 0.25 | 240 | 0.59 | 66 | 0.49 | 61 | 0.19 |
| R | 8 | 0.67 | 154 | 0.38 | 20 | 0.15 | 171 | 0.54 |
| Rmd | 1 | 0.08 | 16 | 0.04 | 48 | 0.36 | 84 | 0.27 |
| C++ | 3 | 0.25 | 369 | 0.59 | 112 | 0.55 | 77 | 0.20 |
| R | 8 | 0.67 | 242 | 0.38 | 42 | 0.20 | 220 | 0.57 |
| Rmd | 1 | 0.08 | 18 | 0.03 | 51 | 0.25 | 89 | 0.23 |

## Code of Conduct



man/gdns_resolver.Rd → man/gdns_context.Rd View File

@@ -1,11 +1,11 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/resolver.R
\name{gdns_resolver}
\alias{gdns_resolver}
\name{gdns_context}
\alias{gdns_context}
\title{Create a gdns DNS over TLS context and populate it with a resolver
for use in resolution functions}
\usage{
gdns_resolver(resolvers = "9.9.9.9")
gdns_context(resolvers = "9.9.9.9")
}
\arguments{
\item{resolvers}{character vector of valid DNS over TLS resolvers;
@@ -20,6 +20,6 @@ for use in resolution functions
maintains a list of DNS over TLS servers.
}
\examples{
x <- gdns_resolver()
x <- gdns_resolver("1.1.1.1")
x <- gdns_context()
x <- gdns_context("1.1.1.1")
}

+ 14
- 0
man/gdns_get_timeout.Rd View File

@@ -0,0 +1,14 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/RcppExports.R
\name{gdns_get_timeout}
\alias{gdns_get_timeout}
\title{Retreive the number of milliseconds to wait for request to return}
\usage{
gdns_get_timeout(gctx)
}
\arguments{
\item{gctx}{gdns resolver context created with \code{\link[=gdns_resolver]{gdns_resolver()}}}
}
\description{
Retreive the number of milliseconds to wait for request to return
}

+ 21
- 0
man/gdns_set_hosts.Rd View File

@@ -0,0 +1,21 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/resolver.R
\name{gdns_set_hosts}
\alias{gdns_set_hosts}
\title{Initialized the context's local names namespace with values from the given hosts file.}
\usage{
gdns_set_hosts(gctx, hosts_file)
}
\arguments{
\item{gctx}{gdns resolver context created with \code{\link[=gdns_resolver]{gdns_resolver()}}}

\item{hosts_file}{path to a valid \code{hosts} file (e.g. "\code{/etc/hosts}). This value
will be \code{\link[=path.expand]{path.expand()}}ed.}
}
\description{
Initialized the context's local names namespace with values from the given hosts file.
}
\examples{
x <- gdns_context()
x <- gdns_set_hosts(x, "/etc/hosts")
}

+ 18
- 0
man/gdns_set_round_robin_upstreams.Rd View File

@@ -0,0 +1,18 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/RcppExports.R
\name{gdns_set_round_robin_upstreams}
\alias{gdns_set_round_robin_upstreams}
\title{Set/unset context to round robin queries over the available upstreams
when resolving with the stub resolution type.}
\usage{
gdns_set_round_robin_upstreams(gctx, flag = TRUE)
}
\arguments{
\item{gctx}{gdns resolver context created with \code{\link[=gdns_resolver]{gdns_resolver()}}}

\item{flag}{if \code{TRUE} (the default) round robin queries when using more than one stub resolver,}
}
\description{
Set/unset context to round robin queries over the available upstreams
when resolving with the stub resolution type.
}

+ 16
- 0
man/gdns_set_timeout.Rd View File

@@ -0,0 +1,16 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/RcppExports.R
\name{gdns_set_timeout}
\alias{gdns_set_timeout}
\title{Specify the number of milliseconds to wait for request to return}
\usage{
gdns_set_timeout(gctx, timeout)
}
\arguments{
\item{gctx}{gdns resolver context created with \code{\link[=gdns_resolver]{gdns_resolver()}}}

\item{timeout}{number of milliseconds (integer; i.e. not-fractional)}
}
\description{
Specify the number of milliseconds to wait for request to return
}

+ 24
- 0
man/gdns_update_resolvers.Rd View File

@@ -0,0 +1,24 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/resolver.R
\name{gdns_update_resolvers}
\alias{gdns_update_resolvers}
\title{Changes the list of resolvers in an already created context for use in resolution functions}
\usage{
gdns_update_resolvers(gctx, resolvers)
}
\arguments{
\item{gctx}{gdns resolver context created with \code{\link[=gdns_resolver]{gdns_resolver()}}}

\item{resolvers}{character vector of valid DNS over TLS resolvers}
}
\description{
Changes the list of resolvers in an already created context for use in resolution functions
}
\note{
\href{https://dnsprivacy.org/wiki/display/DP/DNS+Privacy+Test+Servers#DNSPrivacyTestServers-DoTservers}{DNS Privacy}
maintains a list of DNS over TLS servers.
}
\examples{
x <- gdns_context()
x <- gdns_update_resolvers("1.1.1.1")
}

+ 12
- 0
man/int_gdns_set_hosts.Rd View File

@@ -0,0 +1,12 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/RcppExports.R
\name{int_gdns_set_hosts}
\alias{int_gdns_set_hosts}
\title{Internal version of gdns_set_hosts()}
\usage{
int_gdns_set_hosts(gctx, hosts)
}
\description{
Internal version of gdns_set_hosts()
}
\keyword{internal}

+ 12
- 0
man/int_gdns_update_resolvers.Rd View File

@@ -0,0 +1,12 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/RcppExports.R
\name{int_gdns_update_resolvers}
\alias{int_gdns_update_resolvers}
\title{Internal version of gdns_update_resolvers}
\usage{
int_gdns_update_resolvers(gctx, resolvers)
}
\description{
Internal version of gdns_update_resolvers
}
\keyword{internal}

+ 64
- 0
src/RcppExports.cpp View File

@@ -15,6 +15,65 @@ BEGIN_RCPP
return rcpp_result_gen;
END_RCPP
}
// int_gdns_update_resolvers
SEXP int_gdns_update_resolvers(SEXP gctx, std::vector< std::string > resolvers);
RcppExport SEXP _clandnstine_int_gdns_update_resolvers(SEXP gctxSEXP, SEXP resolversSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< SEXP >::type gctx(gctxSEXP);
Rcpp::traits::input_parameter< std::vector< std::string > >::type resolvers(resolversSEXP);
rcpp_result_gen = Rcpp::wrap(int_gdns_update_resolvers(gctx, resolvers));
return rcpp_result_gen;
END_RCPP
}
// gdns_set_timeout
SEXP gdns_set_timeout(SEXP gctx, long timeout);
RcppExport SEXP _clandnstine_gdns_set_timeout(SEXP gctxSEXP, SEXP timeoutSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< SEXP >::type gctx(gctxSEXP);
Rcpp::traits::input_parameter< long >::type timeout(timeoutSEXP);
rcpp_result_gen = Rcpp::wrap(gdns_set_timeout(gctx, timeout));
return rcpp_result_gen;
END_RCPP
}
// gdns_get_timeout
DoubleVector gdns_get_timeout(SEXP gctx);
RcppExport SEXP _clandnstine_gdns_get_timeout(SEXP gctxSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< SEXP >::type gctx(gctxSEXP);
rcpp_result_gen = Rcpp::wrap(gdns_get_timeout(gctx));
return rcpp_result_gen;
END_RCPP
}
// gdns_set_round_robin_upstreams
SEXP gdns_set_round_robin_upstreams(SEXP gctx, bool flag);
RcppExport SEXP _clandnstine_gdns_set_round_robin_upstreams(SEXP gctxSEXP, SEXP flagSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< SEXP >::type gctx(gctxSEXP);
Rcpp::traits::input_parameter< bool >::type flag(flagSEXP);
rcpp_result_gen = Rcpp::wrap(gdns_set_round_robin_upstreams(gctx, flag));
return rcpp_result_gen;
END_RCPP
}
// int_gdns_set_hosts
SEXP int_gdns_set_hosts(SEXP gctx, std::string hosts);
RcppExport SEXP _clandnstine_int_gdns_set_hosts(SEXP gctxSEXP, SEXP hostsSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< SEXP >::type gctx(gctxSEXP);
Rcpp::traits::input_parameter< std::string >::type hosts(hostsSEXP);
rcpp_result_gen = Rcpp::wrap(int_gdns_set_hosts(gctx, hosts));
return rcpp_result_gen;
END_RCPP
}
// check_is_xptr
void check_is_xptr(SEXP s);
RcppExport SEXP _clandnstine_check_is_xptr(SEXP sSEXP) {
@@ -87,6 +146,11 @@ END_RCPP

static const R_CallMethodDef CallEntries[] = {
{"_clandnstine_gdns_lib_version", (DL_FUNC) &_clandnstine_gdns_lib_version, 0},
{"_clandnstine_int_gdns_update_resolvers", (DL_FUNC) &_clandnstine_int_gdns_update_resolvers, 2},
{"_clandnstine_gdns_set_timeout", (DL_FUNC) &_clandnstine_gdns_set_timeout, 2},
{"_clandnstine_gdns_get_timeout", (DL_FUNC) &_clandnstine_gdns_get_timeout, 1},
{"_clandnstine_gdns_set_round_robin_upstreams", (DL_FUNC) &_clandnstine_gdns_set_round_robin_upstreams, 2},
{"_clandnstine_int_gdns_set_hosts", (DL_FUNC) &_clandnstine_int_gdns_set_hosts, 2},
{"_clandnstine_check_is_xptr", (DL_FUNC) &_clandnstine_check_is_xptr, 1},
{"_clandnstine_is_null_xptr_", (DL_FUNC) &_clandnstine_is_null_xptr_, 1},
{"_clandnstine_int_gdns_resolver", (DL_FUNC) &_clandnstine_int_gdns_resolver, 1},


+ 129
- 21
src/clandnstine-main.cpp View File

@@ -4,7 +4,7 @@
#include <arpa/inet.h>
using namespace Rcpp;

extern void check_is_xptr(SEXP s);
//' Return gdns library version
//'
//' @export
@@ -14,23 +14,131 @@ std::string gdns_lib_version() {
}


// CharacterVector int_gdns_list_to_r() {
//
// getdns_list *gl;
//
// std::string out;
//
// // if (!lst) return(CharacterVector());
// //
// // char *res = getdns_print_json_list(lst, 0);
// // if (res) {
// // out = std::string(res);
// // free(res);
// // } else {
// // return(CharacterVector());
// // }
//
// return(wrap(out));
//
// }
//
//' Internal version of gdns_update_resolvers
//' @keywords internal
// [[Rcpp::export]]
SEXP int_gdns_update_resolvers(SEXP gctx, std::vector< std::string > resolvers) {

check_is_xptr(gctx);

getdns_context *ctxt = (getdns_context *)R_ExternalPtrAddr(gctx);

if (gctx == NULL) return(R_NilValue);

getdns_return_t r;

// TODO Validate we don't need to free these
getdns_dict *resolver_dict = getdns_dict_create();
getdns_list *resolver_list = getdns_list_create();

for (int i = 0; i<resolvers.size(); i++) {
r = getdns_str2dict(resolvers[i].c_str(), &resolver_dict);
r = getdns_list_set_dict(resolver_list, i, resolver_dict);
}

if ((r = getdns_context_set_upstream_recursive_servers(ctxt, resolver_list))) {
Rf_error(getdns_get_errorstr_by_id(r));
}

return(gctx);

}


//' Specify the number of milliseconds to wait for request to return
//'
//' @param gctx gdns resolver context created with [gdns_resolver()]
//' @param timeout number of milliseconds (integer; i.e. not-fractional)
//' @export
// [[Rcpp::export]]
SEXP gdns_set_timeout(SEXP gctx, long timeout) {

check_is_xptr(gctx);

getdns_context *ctxt = (getdns_context *)R_ExternalPtrAddr(gctx);

if (gctx == NULL) return(CharacterVector());

getdns_return_t r;

if ((r = getdns_context_set_timeout(ctxt, (uint64_t)timeout))) {
Rf_error(getdns_get_errorstr_by_id(r));
}

return(gctx);

}

//' Retreive the number of milliseconds to wait for request to return
//'
//' @param gctx gdns resolver context created with [gdns_resolver()]
//' @export
// [[Rcpp::export]]
DoubleVector gdns_get_timeout(SEXP gctx) {

check_is_xptr(gctx);

getdns_context *ctxt = (getdns_context *)R_ExternalPtrAddr(gctx);

if (gctx == NULL) return(R_NilValue);

getdns_return_t r;
uint64_t timeout;

if ((r = getdns_context_get_timeout(ctxt, &timeout))) {
Rf_error(getdns_get_errorstr_by_id(r));
}

DoubleVector out(1);
out[0] = (uint32_t)timeout;

return(out);

}

//' Set/unset context to round robin queries over the available upstreams
//' when resolving with the stub resolution type.
//'
//' @md
//' @param gctx gdns resolver context created with [gdns_resolver()]
//' @param flag if `TRUE` (the default) round robin queries when using more than one stub resolver,
//' @export
// [[Rcpp::export]]
SEXP gdns_set_round_robin_upstreams(SEXP gctx, bool flag=true) {

check_is_xptr(gctx);

getdns_context *ctxt = (getdns_context *)R_ExternalPtrAddr(gctx);

if (gctx == NULL) return(R_NilValue);

getdns_return_t r;

if ((r = getdns_context_set_round_robin_upstreams(ctxt, flag ? 1 : 0))) {
Rf_error(getdns_get_errorstr_by_id(r));
}

return(gctx);

}

//' Internal version of gdns_set_hosts()
//' @keywords internal
// [[Rcpp::export]]
SEXP int_gdns_set_hosts(SEXP gctx, std::string hosts) {

check_is_xptr(gctx);

getdns_context *ctxt = (getdns_context *)R_ExternalPtrAddr(gctx);

if (gctx == NULL) return(R_NilValue);

getdns_return_t r;

if ((r = getdns_context_set_hosts(ctxt, hosts.c_str()))) {
Rf_error(getdns_get_errorstr_by_id(r));
}

return(gctx);

}

+ 2
- 2
tests/testthat/test-clandnstine.R View File

@@ -3,12 +3,12 @@ test_that("basic wrapper works", {

expect_is(gdns_lib_version(), "character")

r <- gdns_resolver()
r <- gns_context()

x <- gdns_get_address(r, "example.com")
expect_true(all(c("2606:2800:220:1:248:1893:25c8:1946", "93.184.216.34") %in% x))

r <- gdns_resolver(c("8.8.8.8", "1.1.1.1", "9.9.9.9"))
r <- gdns_context(c("8.8.8.8", "1.1.1.1", "9.9.9.9"))

x <- gdns_get_address(r, "example.com")
expect_true(all(c("2606:2800:220:1:248:1893:25c8:1946", "93.184.216.34") %in% x))


Loading…
Cancel
Save