reduce loop counters to more practical levels
[oweals/gnunet.git] / src / include / gnunet_dnsstub_lib.h
1 /*
2       This file is part of GNUnet
3       Copyright (C) 2012, 2018 GNUnet e.V.
4
5       GNUnet is free software; you can redistribute it and/or modify
6       it under the terms of the GNU General Public License as published
7       by the Free Software Foundation; either version 3, or (at your
8       option) any later version.
9
10       GNUnet is distributed in the hope that it will be useful, but
11       WITHOUT ANY WARRANTY; without even the implied warranty of
12       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13       General Public License for more details.
14
15       You should have received a copy of the GNU General Public License
16       along with GNUnet; see the file COPYING.  If not, write to the
17       Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18       Boston, MA 02110-1301, USA.
19  */
20
21 /**
22  * @author Christian Grothoff
23  *
24  * @file
25  * API for helper library to send DNS requests to DNS resolver
26  *
27  * @defgroup dns-stub  DNS Stub library
28  * Helper library to send DNS requests to DNS resolver
29  * @{
30  */
31 #ifndef GNUNET_DNSSTUB_LIB_H
32 #define GNUNET_DNSSTUB_LIB_H
33
34 #include "gnunet_common.h"
35 #include "gnunet_tun_lib.h"
36
37 /**
38  * Opaque handle to the stub resolver.
39  */
40 struct GNUNET_DNSSTUB_Context;
41
42 /**
43  * Opaque handle to a socket doing UDP requests.
44  */
45 struct GNUNET_DNSSTUB_RequestSocket;
46
47
48 /**
49  * Start a DNS stub resolver.
50  *
51  * @param num_sockets how many sockets should we open
52  *        in parallel for DNS queries for this stub?
53  * @return NULL on error
54  */
55 struct GNUNET_DNSSTUB_Context *
56 GNUNET_DNSSTUB_start (unsigned int num_sockets);
57
58
59 /**
60  * Add nameserver for use by the DNSSTUB.  We will use
61  * all provided nameservers for resolution (round-robin).
62  *
63  * @param ctx resolver context to modify
64  * @param dns_ip target IP address to use (as string)
65  * @return #GNUNET_OK on success
66  */
67 int
68 GNUNET_DNSSTUB_add_dns_ip (struct GNUNET_DNSSTUB_Context *ctx,
69                            const char *dns_ip);
70
71
72 /**
73  * Add nameserver for use by the DNSSTUB.  We will use
74  * all provided nameservers for resolution (round-robin).
75  *
76  * @param ctx resolver context to modify
77  * @param sa socket address of DNS resolver to use
78  * @return #GNUNET_OK on success
79  */
80 int
81 GNUNET_DNSSTUB_add_dns_sa (struct GNUNET_DNSSTUB_Context *ctx,
82                            const struct sockaddr *sa);
83
84
85 /**
86  * How long should we try requests before timing out?
87  * Only effective for requests issued after this call.
88  *
89  * @param ctx resolver context to modify
90  * @param retry_frequ how long to wait between retries
91  */
92 void
93 GNUNET_DNSSTUB_set_retry (struct GNUNET_DNSSTUB_Context *ctx,
94                           struct GNUNET_TIME_Relative retry_freq);
95
96 /**
97  * Cleanup DNSSTUB resolver.
98  *
99  * @param ctx stub resolver to clean up
100  */
101 void
102 GNUNET_DNSSTUB_stop (struct GNUNET_DNSSTUB_Context *ctx);
103
104
105 /**
106  * Function called with the result of a DNS resolution.
107  * Once this function is called, the resolution request
108  * is automatically cancelled / cleaned up.  In particular,
109  * the function will only be called once.
110  *
111  * @param cls closure
112  * @param dns dns response, NULL on hard error (i.e. timeout)
113  * @param dns_len number of bytes in @a dns
114  */
115 typedef void
116 (*GNUNET_DNSSTUB_ResultCallback)(void *cls,
117                                  const struct GNUNET_TUN_DnsHeader *dns,
118                                  size_t dns_len);
119
120
121 /**
122  * Perform DNS resolution using our default IP from init.
123  *
124  * @param ctx stub resolver to use
125  * @param request DNS request to transmit
126  * @param request_len number of bytes in msg
127  * @param rc function to call with result (once)
128  * @param rc_cls closure for @a rc
129  * @return socket used for the request, NULL on error
130  */
131 struct GNUNET_DNSSTUB_RequestSocket *
132 GNUNET_DNSSTUB_resolve (struct GNUNET_DNSSTUB_Context *ctx,
133                         const void *request,
134                         size_t request_len,
135                         GNUNET_DNSSTUB_ResultCallback rc,
136                         void *rc_cls);
137
138
139 /**
140  * Cancel DNS resolution.
141  *
142  * @param rs resolution to cancel
143  */
144 void
145 GNUNET_DNSSTUB_resolve_cancel (struct GNUNET_DNSSTUB_RequestSocket *rs);
146
147
148 #endif
149
150 /** @} */  /* end of group */