2 This file is part of GNUnet
3 Copyright (C) 2012, 2018 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * @author Christian Grothoff
23 * API for helper library to send DNS requests to DNS resolver
25 * @defgroup dns-stub DNS Stub library
26 * Helper library to send DNS requests to DNS resolver
29 #ifndef GNUNET_DNSSTUB_LIB_H
30 #define GNUNET_DNSSTUB_LIB_H
32 #include "gnunet_util_lib.h"
35 * Opaque handle to the stub resolver.
37 struct GNUNET_DNSSTUB_Context;
40 * Opaque handle to a socket doing UDP requests.
42 struct GNUNET_DNSSTUB_RequestSocket;
46 * Start a DNS stub resolver.
48 * @param num_sockets how many sockets should we open
49 * in parallel for DNS queries for this stub?
50 * @return NULL on error
52 struct GNUNET_DNSSTUB_Context *
53 GNUNET_DNSSTUB_start (unsigned int num_sockets);
57 * Add nameserver for use by the DNSSTUB. We will use
58 * all provided nameservers for resolution (round-robin).
60 * @param ctx resolver context to modify
61 * @param dns_ip target IP address to use (as string)
62 * @return #GNUNET_OK on success
65 GNUNET_DNSSTUB_add_dns_ip (struct GNUNET_DNSSTUB_Context *ctx,
70 * Add nameserver for use by the DNSSTUB. We will use
71 * all provided nameservers for resolution (round-robin).
73 * @param ctx resolver context to modify
74 * @param sa socket address of DNS resolver to use
75 * @return #GNUNET_OK on success
78 GNUNET_DNSSTUB_add_dns_sa (struct GNUNET_DNSSTUB_Context *ctx,
79 const struct sockaddr *sa);
83 * How long should we try requests before timing out?
84 * Only effective for requests issued after this call.
86 * @param ctx resolver context to modify
87 * @param retry_frequ how long to wait between retries
90 GNUNET_DNSSTUB_set_retry (struct GNUNET_DNSSTUB_Context *ctx,
91 struct GNUNET_TIME_Relative retry_freq);
94 * Cleanup DNSSTUB resolver.
96 * @param ctx stub resolver to clean up
99 GNUNET_DNSSTUB_stop (struct GNUNET_DNSSTUB_Context *ctx);
103 * Function called with the result of a DNS resolution.
104 * Once this function is called, the resolution request
105 * is automatically cancelled / cleaned up. In particular,
106 * the function will only be called once.
109 * @param dns dns response, NULL on hard error (i.e. timeout)
110 * @param dns_len number of bytes in @a dns
113 (*GNUNET_DNSSTUB_ResultCallback)(void *cls,
114 const struct GNUNET_TUN_DnsHeader *dns,
119 * Perform DNS resolution using our default IP from init.
121 * @param ctx stub resolver to use
122 * @param request DNS request to transmit
123 * @param request_len number of bytes in msg
124 * @param rc function to call with result (once)
125 * @param rc_cls closure for @a rc
126 * @return socket used for the request, NULL on error
128 struct GNUNET_DNSSTUB_RequestSocket *
129 GNUNET_DNSSTUB_resolve (struct GNUNET_DNSSTUB_Context *ctx,
132 GNUNET_DNSSTUB_ResultCallback rc,
137 * Cancel DNS resolution.
139 * @param rs resolution to cancel
142 GNUNET_DNSSTUB_resolve_cancel (struct GNUNET_DNSSTUB_RequestSocket *rs);
147 /** @} */ /* end of group */