uncrustify as demanded.
[oweals/gnunet.git] / src / include / gnunet_gns_service.h
1 /*
2       This file is part of GNUnet
3       Copyright (C) 2012-2014, 2017 GNUnet e.V.
4
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.
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       Affero General Public License for more details.
14
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/>.
17
18      SPDX-License-Identifier: AGPL3.0-or-later
19  */
20
21 /**
22  * @author Martin Schanzenbach
23  *
24  * @file
25  * API to the GNS service
26  *
27  * @defgroup gns  GNS service
28  * GNU Name System
29  *
30  * @see [Documentation](https://gnunet.org/gns-implementation)
31  *
32  * @{
33  */
34 #ifndef GNUNET_GNS_SERVICE_H
35 #define GNUNET_GNS_SERVICE_H
36
37 #include "gnunet_util_lib.h"
38 #include "gnunet_dnsparser_lib.h"
39 #include "gnunet_namestore_service.h"
40
41 #ifdef __cplusplus
42 extern "C" {
43 #if 0 /* keep Emacsens' auto-indent happy */
44 }
45 #endif
46 #endif
47
48
49 /**
50  * String we use to indicate an empty label (top-level
51  * entry in the zone).  DNS uses "@", so do we.
52  */
53 #define GNUNET_GNS_EMPTY_LABEL_AT "@"
54
55 /**
56  * Connection to the GNS service.
57  */
58 struct GNUNET_GNS_Handle;
59
60 /**
61  * Handle to control a lookup operation.
62  */
63 struct GNUNET_GNS_LookupRequest;
64
65 /**
66  * Handle to control a lookup operation where the
67  * TLD is resolved to a zone as part of the lookup operation.
68  */
69 struct GNUNET_GNS_LookupWithTldRequest;
70
71
72 /**
73  * Initialize the connection with the GNS service.
74  *
75  * @param cfg configuration to use
76  * @return handle to the GNS service, or NULL on error
77  */
78 struct GNUNET_GNS_Handle *
79 GNUNET_GNS_connect(const struct GNUNET_CONFIGURATION_Handle *cfg);
80
81
82 /**
83  * Shutdown connection with the GNS service.
84  *
85  * @param handle connection to shut down
86  */
87 void
88 GNUNET_GNS_disconnect(struct GNUNET_GNS_Handle *handle);
89
90
91 /**
92  * Iterator called on obtained result for a GNS lookup.
93  *
94  * @param cls closure
95  * @param rd_count number of records in @a rd
96  * @param rd the records in reply
97  */
98 typedef void (*GNUNET_GNS_LookupResultProcessor) (
99   void *cls,
100   uint32_t rd_count,
101   const struct GNUNET_GNSRECORD_Data *rd);
102
103
104 /**
105  * Options for the GNS lookup.
106  */
107 enum GNUNET_GNS_LocalOptions {
108   /**
109    * Defaults, look in cache, then in DHT.
110    */
111   GNUNET_GNS_LO_DEFAULT = 0,
112
113   /**
114    * Never look in the DHT, keep request to local cache.
115    */
116   GNUNET_GNS_LO_NO_DHT = 1,
117
118   /**
119    * For the rightmost label, only look in the cache (it
120    * is our local namestore), for the others, the DHT is OK.
121    */
122   GNUNET_GNS_LO_LOCAL_MASTER = 2
123 };
124
125
126 /**
127  * Perform an asynchronous lookup operation on the GNS.
128  *
129  * @param handle handle to the GNS service
130  * @param name the name to look up
131  * @param zone zone to look in
132  * @param type the GNS record type to look for
133  * @param options local options for the lookup
134  * @param proc function to call on result
135  * @param proc_cls closure for @a proc
136  * @return handle to the queued request
137  */
138 struct GNUNET_GNS_LookupRequest *
139 GNUNET_GNS_lookup(struct GNUNET_GNS_Handle *handle,
140                   const char *name,
141                   const struct GNUNET_CRYPTO_EcdsaPublicKey *zone,
142                   uint32_t type,
143                   enum GNUNET_GNS_LocalOptions options,
144                   GNUNET_GNS_LookupResultProcessor proc,
145                   void *proc_cls);
146
147
148 /**
149  * Cancel pending lookup request
150  *
151  * @param lr the lookup request to cancel
152  * @return closure from the lookup result processor
153  */
154 void *
155 GNUNET_GNS_lookup_cancel(struct GNUNET_GNS_LookupRequest *lr);
156
157
158 /**
159  * Iterator called on obtained result for a GNS lookup
160  * where "not GNS" is a valid answer.
161  *
162  * @param cls closure
163  * @param gns_tld #GNUNET_YES if a GNS lookup was attempted,
164  *                #GNUNET_NO if the TLD is not configured for GNS
165  * @param rd_count number of records in @a rd
166  * @param rd the records in the reply
167  */
168 typedef void (*GNUNET_GNS_LookupResultProcessor2) (
169   void *cls,
170   int gns_tld,
171   uint32_t rd_count,
172   const struct GNUNET_GNSRECORD_Data *rd);
173
174
175 /**
176  * Perform an asynchronous lookup operation on the GNS,
177  * determining the zone using the TLD of the given name
178  * and the current configuration to resolve TLDs to zones.
179  *
180  * @param handle handle to the GNS service
181  * @param name the name to look up, including TLD
182  * @param type the record type to look up
183  * @param options local options for the lookup
184  * @param proc processor to call on result
185  * @param proc_cls closure for @a proc
186  * @return handle to the get request
187  */
188 struct GNUNET_GNS_LookupWithTldRequest *
189 GNUNET_GNS_lookup_with_tld(struct GNUNET_GNS_Handle *handle,
190                            const char *name,
191                            uint32_t type,
192                            enum GNUNET_GNS_LocalOptions options,
193                            GNUNET_GNS_LookupResultProcessor2 proc,
194                            void *proc_cls);
195
196
197 /**
198  * Cancel pending lookup request
199  *
200  * @param ltr the lookup request to cancel
201  * @return closure from the lookup result processor
202  */
203 void *
204 GNUNET_GNS_lookup_with_tld_cancel(struct GNUNET_GNS_LookupWithTldRequest *ltr);
205
206
207 #if 0 /* keep Emacsens' auto-indent happy */
208 {
209 #endif
210 #ifdef __cplusplus
211 }
212 #endif
213
214 #endif
215
216 /** @} */ /* end of group */