Browse Source

additional getters/setters

boB Rudis 10 months ago
parent
commit
6559c85744
No known key found for this signature in database

+ 6
- 1
NAMESPACE View File

@@ -3,10 +3,15 @@
3 3
 S3method(print,gctx)
4 4
 S3method(print,gdns_response)
5 5
 export("%>%")
6
+export(gdns_context)
6 7
 export(gdns_get_address)
8
+export(gdns_get_timeout)
7 9
 export(gdns_lib_version)
8 10
 export(gdns_query)
9
-export(gdns_resolver)
11
+export(gdns_set_hosts)
12
+export(gdns_set_round_robin_upstreams)
13
+export(gdns_set_timeout)
14
+export(gdns_update_resolvers)
10 15
 importFrom(Rcpp,sourceCpp)
11 16
 importFrom(jsonlite,fromJSON)
12 17
 importFrom(magrittr,"%>%")

+ 40
- 0
R/RcppExports.R View File

@@ -8,6 +8,46 @@ gdns_lib_version <- function() {
8 8
     .Call(`_clandnstine_gdns_lib_version`)
9 9
 }
10 10
 
11
+#' Internal version of gdns_update_resolvers
12
+#' @keywords internal
13
+int_gdns_update_resolvers <- function(gctx, resolvers) {
14
+    .Call(`_clandnstine_int_gdns_update_resolvers`, gctx, resolvers)
15
+}
16
+
17
+#' Specify the number of milliseconds to wait for request to return
18
+#'
19
+#' @param gctx gdns resolver context created with [gdns_resolver()]
20
+#' @param timeout number of milliseconds (integer; i.e. not-fractional)
21
+#' @export
22
+gdns_set_timeout <- function(gctx, timeout) {
23
+    .Call(`_clandnstine_gdns_set_timeout`, gctx, timeout)
24
+}
25
+
26
+#' Retreive the number of milliseconds to wait for request to return
27
+#'
28
+#' @param gctx gdns resolver context created with [gdns_resolver()]
29
+#' @export
30
+gdns_get_timeout <- function(gctx) {
31
+    .Call(`_clandnstine_gdns_get_timeout`, gctx)
32
+}
33
+
34
+#' Set/unset context to round robin queries over the available upstreams
35
+#' when resolving with the stub resolution type.
36
+#'
37
+#' @md
38
+#' @param gctx gdns resolver context created with [gdns_resolver()]
39
+#' @param flag if `TRUE` (the default) round robin queries when using more than one stub resolver,
40
+#' @export
41
+gdns_set_round_robin_upstreams <- function(gctx, flag = TRUE) {
42
+    .Call(`_clandnstine_gdns_set_round_robin_upstreams`, gctx, flag)
43
+}
44
+
45
+#' Internal version of gdns_set_hosts()
46
+#' @keywords internal
47
+int_gdns_set_hosts <- function(gctx, hosts) {
48
+    .Call(`_clandnstine_int_gdns_set_hosts`, gctx, hosts)
49
+}
50
+
11 51
 #' Test whether an object is an external pointer
12 52
 #'
13 53
 #' @param x object to test

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

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

+ 33
- 3
R/resolver.R View File

@@ -7,12 +7,42 @@
7 7
 #'        Defaults to Quad9 (`9.9.9.9`).
8 8
 #' @export
9 9
 #' @examples
10
-#' x <- gdns_resolver()
11
-#' x <- gdns_resolver("1.1.1.1")
12
-gdns_resolver <- function(resolvers = "9.9.9.9") {
10
+#' x <- gdns_context()
11
+#' x <- gdns_context("1.1.1.1")
12
+gdns_context <- function(resolvers = "9.9.9.9") {
13 13
   int_gdns_resolver(resolvers)
14 14
 }
15 15
 
16
+#' Changes the list of resolvers in an already created context for use in resolution functions
17
+#'
18
+#' @note [DNS Privacy](https://dnsprivacy.org/wiki/display/DP/DNS+Privacy+Test+Servers#DNSPrivacyTestServers-DoTservers)
19
+#'       maintains a list of DNS over TLS servers.
20
+#' @param gctx gdns resolver context created with [gdns_resolver()]
21
+#' @param resolvers character vector of valid DNS over TLS resolvers
22
+#' @export
23
+#' @examples
24
+#' x <- gdns_context()
25
+#' x <- gdns_update_resolvers("1.1.1.1")
26
+gdns_update_resolvers<- function(gctx, resolvers) {
27
+  int_gdns_update_resolvers(gctx, resolvers)
28
+}
29
+
30
+#' Initialized the context's local names namespace with values from the given hosts file.
31
+#'
32
+#' @param gctx gdns resolver context created with [gdns_resolver()]
33
+#' @param hosts_file path to a valid `hosts` file (e.g. "`/etc/hosts`). This value
34
+#'        will be [path.expand()]ed.
35
+#' @export
36
+#' @examples
37
+#' x <- gdns_context()
38
+#' x <- gdns_set_hosts(x, "/etc/hosts")
39
+gdns_set_hosts<- function(gctx, hosts_file) {
40
+  hosts_file <- path.expand(hosts_file[1])
41
+  stopifnot(file.exists(hosts_file))
42
+  int_gdns_set_hosts(gctx, hosts_file)
43
+}
44
+
45
+
16 46
 #' Arbitrary DNS queries
17 47
 #'
18 48
 #' 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
85 85
 
86 86
 The following functions are implemented:
87 87
 
88
-- `gdns_get_address`:	Resolve a host to an addrss
89
-- `gdns_lib_version`:	Return gdns library version
90
-- `gdns_query`:	Arbitrary DNS queries
91
-- `gdns_resolver`:	Create a gdns DNS over TLS context and populate it with a resolver for use in resolution functions
88
+
89
+- `gdns_context`:  Create a gdns DNS over TLS context and populate it with a resolver for use in resolution functions
90
+- `gdns_get_address`:  Resolve a host to an addrss
91
+- `gdns_get_timeout`:  Retreive the number of milliseconds to wait for request to return
92
+- `gdns_lib_version`:  Return gdns library version
93
+- `gdns_query`:  Arbitrary DNS queries
94
+- `gdns_set_hosts`:  Initialized the context's local names namespace with values from the given hosts file.
95
+- `gdns_set_round_robin_upstreams`:  Set/unset context to round robin queries over the available upstreams when resolving with the stub resolution type.
96
+- `gdns_set_timeout`:  Specify the number of milliseconds to wait for request to return
97
+- `gdns_update_resolvers`: Changes the list of resolvers in an already created context for use in resolution functions
92 98
 
93 99
 ## Installation
94 100
 
@@ -113,11 +119,15 @@ packageVersion("clandnstine")
113 119
 ```{r addr}
114 120
 gdns_lib_version()
115 121
 
116
-(x <- gdns_resolver())
122
+(x <- gdns_context())
123
+
124
+(x <- gdns_context("1.1.1.1"))
125
+
126
+(x <- gdns_context(c("8.8.8.8", "1.1.1.1", "9.9.9.9")))
117 127
 
118
-(x <- gdns_resolver("1.1.1.1"))
128
+(gdns_set_timeout(x, 2000))
119 129
 
120
-(x <- gdns_resolver(c("8.8.8.8", "1.1.1.1", "9.9.9.9")))
130
+(gdns_update_resolvers(x, "1.1.1.1"))
121 131
 
122 132
 (gdns_get_address(x, "rud.is"))
123 133
 

+ 33
- 15
README.md View File

@@ -111,11 +111,22 @@ to work pretty hard to try to figure out what you’re looking for.
111 111
 
112 112
 The following functions are implemented:
113 113
 
114
+  - `gdns_context`: Create a gdns DNS over TLS context and populate it
115
+    with a resolver for use in resolution functions
114 116
   - `gdns_get_address`: Resolve a host to an addrss
117
+  - `gdns_get_timeout`: Retreive the number of milliseconds to wait for
118
+    request to return
115 119
   - `gdns_lib_version`: Return gdns library version
116 120
   - `gdns_query`: Arbitrary DNS queries
117
-  - `gdns_resolver`: Create a gdns DNS over TLS context and populate it
118
-    with a resolver for use in resolution functions
121
+  - `gdns_set_hosts`: Initialized the context’s local names namespace
122
+    with values from the given hosts file.
123
+  - `gdns_set_round_robin_upstreams`: Set/unset context to round robin
124
+    queries over the available upstreams when resolving with the stub
125
+    resolution type.
126
+  - `gdns_set_timeout`: Specify the number of milliseconds to wait for
127
+    request to return
128
+  - `gdns_update_resolvers`: Changes the list of resolvers in an already
129
+    created context for use in resolution functions
119 130
 
120 131
 ## Installation
121 132
 
@@ -141,22 +152,28 @@ packageVersion("clandnstine")
141 152
 gdns_lib_version()
142 153
 ## [1] "1.5.1"
143 154
 
144
-(x <- gdns_resolver())
145
-## <gdns v1.5.1 resolver context; resolvers: [9.9.9.9]>
155
+(x <- gdns_context())
156
+## <gdns v1.5.1 resolver context; resolvers: [9.9.9.9]; timeout: 5,000 ms>
157
+
158
+(x <- gdns_context("1.1.1.1"))
159
+## <gdns v1.5.1 resolver context; resolvers: [1.1.1.1]; timeout: 5,000 ms>
160
+
161
+(x <- gdns_context(c("8.8.8.8", "1.1.1.1", "9.9.9.9")))
162
+## <gdns v1.5.1 resolver context; resolvers: [8.8.8.8, 1.1.1.1, 9.9.9.9]; timeout: 5,000 ms>
146 163
 
147
-(x <- gdns_resolver("1.1.1.1"))
148
-## <gdns v1.5.1 resolver context; resolvers: [1.1.1.1]>
164
+(gdns_set_timeout(x, 2000))
165
+## <gdns v1.5.1 resolver context; resolvers: [8.8.8.8, 1.1.1.1, 9.9.9.9]; timeout: 2,000 ms>
149 166
 
150
-(x <- gdns_resolver(c("8.8.8.8", "1.1.1.1", "9.9.9.9")))
151
-## <gdns v1.5.1 resolver context; resolvers: [8.8.8.8, 1.1.1.1, 9.9.9.9]>
167
+(gdns_update_resolvers(x, "1.1.1.1"))
168
+## <gdns v1.5.1 resolver context; resolvers: [1.1.1.1]; timeout: 2,000 ms>
152 169
 
153 170
 (gdns_get_address(x, "rud.is"))
154 171
 ## [1] "2604:a880:800:10::6bc:2001" "104.236.112.222"
155 172
 
156 173
 (gdns_get_address(x, "yahoo.com"))
157
-##  [1] "2001:4998:c:1023::5"   "2001:4998:58:1836::11" "2001:4998:44:41d::3"   "2001:4998:44:41d::4"  
158
-##  [5] "2001:4998:c:1023::4"   "2001:4998:58:1836::10" "98.138.219.231"        "98.138.219.232"       
159
-##  [9] "98.137.246.8"          "72.30.35.9"            "72.30.35.10"           "98.137.246.7"
174
+##  [1] "2001:4998:44:41d::4"   "2001:4998:58:1836::10" "2001:4998:58:1836::11" "2001:4998:c:1023::4"  
175
+##  [5] "2001:4998:c:1023::5"   "2001:4998:44:41d::3"   "98.138.219.232"        "72.30.35.9"           
176
+##  [9] "72.30.35.10"           "98.137.246.7"          "98.137.246.8"          "98.138.219.231"
160 177
 
161 178
 (gdns_get_address(x, "yahoo.commmm"))
162 179
 ## character(0)
@@ -169,9 +186,10 @@ str(leno <- gdns_query(x, "lenovo.com", "txt"), 1)
169 186
 ## List of 5
170 187
 ##  $ answer_type   : int 800
171 188
 ##  $ canonical_name: chr "lenovo.com."
172
-##  $ replies_full  : int [1, 1:600] 135 135 129 128 0 1 0 8 0 0 ...
189
+##  $ replies_full  : int [1, 1:936] 55 119 129 128 0 1 0 8 0 0 ...
173 190
 ##  $ replies_tree  :'data.frame':  1 obs. of  7 variables:
174 191
 ##  $ status        : int 900
192
+##  - attr(*, "class")= chr [1:2] "gdns_response" "list"
175 193
 
176 194
 sort(unlist(leno$replies_tree$answer[[1]]$rdata$txt_strings))
177 195
 ## [1] "a82c74b37aa84e7c8580f0e32f4d795d"                                                        
@@ -191,9 +209,9 @@ Yep. Advertising even in DNS `TXT` records (see item number
191 209
 
192 210
 | Lang | \# Files |  (%) | LoC |  (%) | Blank lines |  (%) | \# Lines |  (%) |
193 211
 | :--- | -------: | ---: | --: | ---: | ----------: | ---: | -------: | ---: |
194
-| C++  |        3 | 0.25 | 240 | 0.59 |          66 | 0.49 |       61 | 0.19 |
195
-| R    |        8 | 0.67 | 154 | 0.38 |          20 | 0.15 |      171 | 0.54 |
196
-| Rmd  |        1 | 0.08 |  16 | 0.04 |          48 | 0.36 |       84 | 0.27 |
212
+| C++  |        3 | 0.25 | 369 | 0.59 |         112 | 0.55 |       77 | 0.20 |
213
+| R    |        8 | 0.67 | 242 | 0.38 |          42 | 0.20 |      220 | 0.57 |
214
+| Rmd  |        1 | 0.08 |  18 | 0.03 |          51 | 0.25 |       89 | 0.23 |
197 215
 
198 216
 ## Code of Conduct
199 217
 

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

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

+ 14
- 0
man/gdns_get_timeout.Rd View File

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

+ 21
- 0
man/gdns_set_hosts.Rd View File

@@ -0,0 +1,21 @@
1
+% Generated by roxygen2: do not edit by hand
2
+% Please edit documentation in R/resolver.R
3
+\name{gdns_set_hosts}
4
+\alias{gdns_set_hosts}
5
+\title{Initialized the context's local names namespace with values from the given hosts file.}
6
+\usage{
7
+gdns_set_hosts(gctx, hosts_file)
8
+}
9
+\arguments{
10
+\item{gctx}{gdns resolver context created with \code{\link[=gdns_resolver]{gdns_resolver()}}}
11
+
12
+\item{hosts_file}{path to a valid \code{hosts} file (e.g. "\code{/etc/hosts}). This value
13
+will be \code{\link[=path.expand]{path.expand()}}ed.}
14
+}
15
+\description{
16
+Initialized the context's local names namespace with values from the given hosts file.
17
+}
18
+\examples{
19
+x <- gdns_context()
20
+x <- gdns_set_hosts(x, "/etc/hosts")
21
+}

+ 18
- 0
man/gdns_set_round_robin_upstreams.Rd View File

@@ -0,0 +1,18 @@
1
+% Generated by roxygen2: do not edit by hand
2
+% Please edit documentation in R/RcppExports.R
3
+\name{gdns_set_round_robin_upstreams}
4
+\alias{gdns_set_round_robin_upstreams}
5
+\title{Set/unset context to round robin queries over the available upstreams
6
+when resolving with the stub resolution type.}
7
+\usage{
8
+gdns_set_round_robin_upstreams(gctx, flag = TRUE)
9
+}
10
+\arguments{
11
+\item{gctx}{gdns resolver context created with \code{\link[=gdns_resolver]{gdns_resolver()}}}
12
+
13
+\item{flag}{if \code{TRUE} (the default) round robin queries when using more than one stub resolver,}
14
+}
15
+\description{
16
+Set/unset context to round robin queries over the available upstreams
17
+when resolving with the stub resolution type.
18
+}

+ 16
- 0
man/gdns_set_timeout.Rd View File

@@ -0,0 +1,16 @@
1
+% Generated by roxygen2: do not edit by hand
2
+% Please edit documentation in R/RcppExports.R
3
+\name{gdns_set_timeout}
4
+\alias{gdns_set_timeout}
5
+\title{Specify the number of milliseconds to wait for request to return}
6
+\usage{
7
+gdns_set_timeout(gctx, timeout)
8
+}
9
+\arguments{
10
+\item{gctx}{gdns resolver context created with \code{\link[=gdns_resolver]{gdns_resolver()}}}
11
+
12
+\item{timeout}{number of milliseconds (integer; i.e. not-fractional)}
13
+}
14
+\description{
15
+Specify the number of milliseconds to wait for request to return
16
+}

+ 24
- 0
man/gdns_update_resolvers.Rd View File

@@ -0,0 +1,24 @@
1
+% Generated by roxygen2: do not edit by hand
2
+% Please edit documentation in R/resolver.R
3
+\name{gdns_update_resolvers}
4
+\alias{gdns_update_resolvers}
5
+\title{Changes the list of resolvers in an already created context for use in resolution functions}
6
+\usage{
7
+gdns_update_resolvers(gctx, resolvers)
8
+}
9
+\arguments{
10
+\item{gctx}{gdns resolver context created with \code{\link[=gdns_resolver]{gdns_resolver()}}}
11
+
12
+\item{resolvers}{character vector of valid DNS over TLS resolvers}
13
+}
14
+\description{
15
+Changes the list of resolvers in an already created context for use in resolution functions
16
+}
17
+\note{
18
+\href{https://dnsprivacy.org/wiki/display/DP/DNS+Privacy+Test+Servers#DNSPrivacyTestServers-DoTservers}{DNS Privacy}
19
+maintains a list of DNS over TLS servers.
20
+}
21
+\examples{
22
+x <- gdns_context()
23
+x <- gdns_update_resolvers("1.1.1.1")
24
+}

+ 12
- 0
man/int_gdns_set_hosts.Rd View File

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

+ 12
- 0
man/int_gdns_update_resolvers.Rd View File

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

+ 64
- 0
src/RcppExports.cpp View File

@@ -15,6 +15,65 @@ BEGIN_RCPP
15 15
     return rcpp_result_gen;
16 16
 END_RCPP
17 17
 }
18
+// int_gdns_update_resolvers
19
+SEXP int_gdns_update_resolvers(SEXP gctx, std::vector< std::string > resolvers);
20
+RcppExport SEXP _clandnstine_int_gdns_update_resolvers(SEXP gctxSEXP, SEXP resolversSEXP) {
21
+BEGIN_RCPP
22
+    Rcpp::RObject rcpp_result_gen;
23
+    Rcpp::RNGScope rcpp_rngScope_gen;
24
+    Rcpp::traits::input_parameter< SEXP >::type gctx(gctxSEXP);
25
+    Rcpp::traits::input_parameter< std::vector< std::string > >::type resolvers(resolversSEXP);
26
+    rcpp_result_gen = Rcpp::wrap(int_gdns_update_resolvers(gctx, resolvers));
27
+    return rcpp_result_gen;
28
+END_RCPP
29
+}
30
+// gdns_set_timeout
31
+SEXP gdns_set_timeout(SEXP gctx, long timeout);
32
+RcppExport SEXP _clandnstine_gdns_set_timeout(SEXP gctxSEXP, SEXP timeoutSEXP) {
33
+BEGIN_RCPP
34
+    Rcpp::RObject rcpp_result_gen;
35
+    Rcpp::RNGScope rcpp_rngScope_gen;
36
+    Rcpp::traits::input_parameter< SEXP >::type gctx(gctxSEXP);
37
+    Rcpp::traits::input_parameter< long >::type timeout(timeoutSEXP);
38
+    rcpp_result_gen = Rcpp::wrap(gdns_set_timeout(gctx, timeout));
39
+    return rcpp_result_gen;
40
+END_RCPP
41
+}
42
+// gdns_get_timeout
43
+DoubleVector gdns_get_timeout(SEXP gctx);
44
+RcppExport SEXP _clandnstine_gdns_get_timeout(SEXP gctxSEXP) {
45
+BEGIN_RCPP
46
+    Rcpp::RObject rcpp_result_gen;
47
+    Rcpp::RNGScope rcpp_rngScope_gen;
48
+    Rcpp::traits::input_parameter< SEXP >::type gctx(gctxSEXP);
49
+    rcpp_result_gen = Rcpp::wrap(gdns_get_timeout(gctx));
50
+    return rcpp_result_gen;
51
+END_RCPP
52
+}
53
+// gdns_set_round_robin_upstreams
54
+SEXP gdns_set_round_robin_upstreams(SEXP gctx, bool flag);
55
+RcppExport SEXP _clandnstine_gdns_set_round_robin_upstreams(SEXP gctxSEXP, SEXP flagSEXP) {
56
+BEGIN_RCPP
57
+    Rcpp::RObject rcpp_result_gen;
58
+    Rcpp::RNGScope rcpp_rngScope_gen;
59
+    Rcpp::traits::input_parameter< SEXP >::type gctx(gctxSEXP);
60
+    Rcpp::traits::input_parameter< bool >::type flag(flagSEXP);
61
+    rcpp_result_gen = Rcpp::wrap(gdns_set_round_robin_upstreams(gctx, flag));
62
+    return rcpp_result_gen;
63
+END_RCPP
64
+}
65
+// int_gdns_set_hosts
66
+SEXP int_gdns_set_hosts(SEXP gctx, std::string hosts);
67
+RcppExport SEXP _clandnstine_int_gdns_set_hosts(SEXP gctxSEXP, SEXP hostsSEXP) {
68
+BEGIN_RCPP
69
+    Rcpp::RObject rcpp_result_gen;
70
+    Rcpp::RNGScope rcpp_rngScope_gen;
71
+    Rcpp::traits::input_parameter< SEXP >::type gctx(gctxSEXP);
72
+    Rcpp::traits::input_parameter< std::string >::type hosts(hostsSEXP);
73
+    rcpp_result_gen = Rcpp::wrap(int_gdns_set_hosts(gctx, hosts));
74
+    return rcpp_result_gen;
75
+END_RCPP
76
+}
18 77
 // check_is_xptr
19 78
 void check_is_xptr(SEXP s);
20 79
 RcppExport SEXP _clandnstine_check_is_xptr(SEXP sSEXP) {
@@ -87,6 +146,11 @@ END_RCPP
87 146
 
88 147
 static const R_CallMethodDef CallEntries[] = {
89 148
     {"_clandnstine_gdns_lib_version", (DL_FUNC) &_clandnstine_gdns_lib_version, 0},
149
+    {"_clandnstine_int_gdns_update_resolvers", (DL_FUNC) &_clandnstine_int_gdns_update_resolvers, 2},
150
+    {"_clandnstine_gdns_set_timeout", (DL_FUNC) &_clandnstine_gdns_set_timeout, 2},
151
+    {"_clandnstine_gdns_get_timeout", (DL_FUNC) &_clandnstine_gdns_get_timeout, 1},
152
+    {"_clandnstine_gdns_set_round_robin_upstreams", (DL_FUNC) &_clandnstine_gdns_set_round_robin_upstreams, 2},
153
+    {"_clandnstine_int_gdns_set_hosts", (DL_FUNC) &_clandnstine_int_gdns_set_hosts, 2},
90 154
     {"_clandnstine_check_is_xptr", (DL_FUNC) &_clandnstine_check_is_xptr, 1},
91 155
     {"_clandnstine_is_null_xptr_", (DL_FUNC) &_clandnstine_is_null_xptr_, 1},
92 156
     {"_clandnstine_int_gdns_resolver", (DL_FUNC) &_clandnstine_int_gdns_resolver, 1},

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

@@ -4,7 +4,7 @@
4 4
 #include <arpa/inet.h>
5 5
 using namespace Rcpp;
6 6
 
7
-
7
+extern void check_is_xptr(SEXP s);
8 8
 //' Return gdns library version
9 9
 //'
10 10
 //' @export
@@ -14,23 +14,131 @@ std::string gdns_lib_version() {
14 14
 }
15 15
 
16 16
 
17
-// CharacterVector int_gdns_list_to_r() {
18
-//
19
-//   getdns_list *gl;
20
-//
21
-//   std::string out;
22
-//
23
-//   // if (!lst) return(CharacterVector());
24
-//   //
25
-//   // char *res = getdns_print_json_list(lst, 0);
26
-//   // if (res) {
27
-//   //   out = std::string(res);
28
-//   //   free(res);
29
-//   // } else {
30
-//   //   return(CharacterVector());
31
-//   // }
32
-//
33
-//   return(wrap(out));
34
-//
35
-// }
36
-//
17
+//' Internal version of gdns_update_resolvers
18
+//' @keywords internal
19
+// [[Rcpp::export]]
20
+SEXP int_gdns_update_resolvers(SEXP gctx, std::vector< std::string > resolvers) {
21
+
22
+  check_is_xptr(gctx);
23
+
24
+  getdns_context *ctxt = (getdns_context *)R_ExternalPtrAddr(gctx);
25
+
26
+  if (gctx == NULL) return(R_NilValue);
27
+
28
+  getdns_return_t r;
29
+
30
+  // TODO Validate we don't need to free these
31
+  getdns_dict *resolver_dict = getdns_dict_create();
32
+  getdns_list *resolver_list = getdns_list_create();
33
+
34
+  for (int i = 0; i<resolvers.size(); i++) {
35
+    r = getdns_str2dict(resolvers[i].c_str(), &resolver_dict);
36
+    r = getdns_list_set_dict(resolver_list, i, resolver_dict);
37
+  }
38
+
39
+  if ((r = getdns_context_set_upstream_recursive_servers(ctxt, resolver_list))) {
40
+    Rf_error(getdns_get_errorstr_by_id(r));
41
+  }
42
+
43
+  return(gctx);
44
+
45
+}
46
+
47
+
48
+//' Specify the number of milliseconds to wait for request to return
49
+//'
50
+//' @param gctx gdns resolver context created with [gdns_resolver()]
51
+//' @param timeout number of milliseconds (integer; i.e. not-fractional)
52
+//' @export
53
+// [[Rcpp::export]]
54
+SEXP gdns_set_timeout(SEXP gctx, long timeout) {
55
+
56
+  check_is_xptr(gctx);
57
+
58
+  getdns_context *ctxt = (getdns_context *)R_ExternalPtrAddr(gctx);
59
+
60
+  if (gctx == NULL) return(CharacterVector());
61
+
62
+  getdns_return_t r;
63
+
64
+  if ((r = getdns_context_set_timeout(ctxt, (uint64_t)timeout))) {
65
+    Rf_error(getdns_get_errorstr_by_id(r));
66
+  }
67
+
68
+  return(gctx);
69
+
70
+}
71
+
72
+//' Retreive the number of milliseconds to wait for request to return
73
+//'
74
+//' @param gctx gdns resolver context created with [gdns_resolver()]
75
+//' @export
76
+// [[Rcpp::export]]
77
+DoubleVector gdns_get_timeout(SEXP gctx) {
78
+
79
+  check_is_xptr(gctx);
80
+
81
+  getdns_context *ctxt = (getdns_context *)R_ExternalPtrAddr(gctx);
82
+
83
+  if (gctx == NULL) return(R_NilValue);
84
+
85
+  getdns_return_t r;
86
+  uint64_t timeout;
87
+
88
+  if ((r = getdns_context_get_timeout(ctxt, &timeout))) {
89
+    Rf_error(getdns_get_errorstr_by_id(r));
90
+  }
91
+
92
+  DoubleVector out(1);
93
+  out[0] = (uint32_t)timeout;
94
+
95
+  return(out);
96
+
97
+}
98
+
99
+//' Set/unset context to round robin queries over the available upstreams
100
+//' when resolving with the stub resolution type.
101
+//'
102
+//' @md
103
+//' @param gctx gdns resolver context created with [gdns_resolver()]
104
+//' @param flag if `TRUE` (the default) round robin queries when using more than one stub resolver,
105
+//' @export
106
+// [[Rcpp::export]]
107
+SEXP gdns_set_round_robin_upstreams(SEXP gctx, bool flag=true) {
108
+
109
+  check_is_xptr(gctx);
110
+
111
+  getdns_context *ctxt = (getdns_context *)R_ExternalPtrAddr(gctx);
112
+
113
+  if (gctx == NULL) return(R_NilValue);
114
+
115
+  getdns_return_t r;
116
+
117
+  if ((r = getdns_context_set_round_robin_upstreams(ctxt, flag ? 1 : 0))) {
118
+    Rf_error(getdns_get_errorstr_by_id(r));
119
+  }
120
+
121
+  return(gctx);
122
+
123
+}
124
+
125
+//' Internal version of gdns_set_hosts()
126
+//' @keywords internal
127
+// [[Rcpp::export]]
128
+SEXP int_gdns_set_hosts(SEXP gctx, std::string hosts) {
129
+
130
+  check_is_xptr(gctx);
131
+
132
+  getdns_context *ctxt = (getdns_context *)R_ExternalPtrAddr(gctx);
133
+
134
+  if (gctx == NULL) return(R_NilValue);
135
+
136
+  getdns_return_t r;
137
+
138
+  if ((r = getdns_context_set_hosts(ctxt, hosts.c_str()))) {
139
+    Rf_error(getdns_get_errorstr_by_id(r));
140
+  }
141
+
142
+  return(gctx);
143
+
144
+}

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

@@ -3,12 +3,12 @@ test_that("basic wrapper works", {
3 3
 
4 4
   expect_is(gdns_lib_version(), "character")
5 5
 
6
-  r <- gdns_resolver()
6
+  r <- gns_context()
7 7
 
8 8
   x <- gdns_get_address(r, "example.com")
9 9
   expect_true(all(c("2606:2800:220:1:248:1893:25c8:1946", "93.184.216.34") %in% x))
10 10
 
11
-  r <- gdns_resolver(c("8.8.8.8", "1.1.1.1", "9.9.9.9"))
11
+  r <- gdns_context(c("8.8.8.8", "1.1.1.1", "9.9.9.9"))
12 12
 
13 13
   x <- gdns_get_address(r, "example.com")
14 14
   expect_true(all(c("2606:2800:220:1:248:1893:25c8:1946", "93.184.216.34") %in% x))

Loading…
Cancel
Save