34af525c88ad6a1f131f0d286879dc912d0ad3fa
[oweals/gnunet.git] / src / include / gnunet_gns_service.h
1 /*
2       This file is part of GNUnet
3       (C) 2012 Christian Grothoff (and other contributing authors)
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., 59 Temple Place - Suite 330,
18       Boston, MA 02111-1307, USA.
19  */
20
21 /**
22  * @file include/gnunet_gns_service.h
23  * @brief API to the GNS service
24  * @author Martin Schanzenbach
25  */
26 #ifndef GNUNET_GNS_SERVICE_H
27 #define GNUNET_GNS_SERVICE_H
28
29 #include "gnunet_util_lib.h"
30 #include "gnunet_dnsparser_lib.h"
31 #include "gnunet_namestore_service.h"
32
33 #ifdef __cplusplus
34 extern "C"
35 {
36 #if 0                           /* keep Emacsens' auto-indent happy */
37 }
38 #endif
39 #endif
40
41
42 /**
43  * String we use to indicate the local master zone or a
44  * root entry in the current zone.
45  */
46 #define GNUNET_GNS_MASTERZONE_STR "+"
47
48 /**
49  * Connection to the GNS service.
50  */
51 struct GNUNET_GNS_Handle;
52
53 /**
54  * Handle to control a lookup operation.
55  */
56 struct GNUNET_GNS_LookupRequest;
57
58 /**
59  * Handle to control a shorten operation.
60  */
61 struct GNUNET_GNS_ShortenRequest;
62
63 /**
64  * Handle to control a get authority operation
65  */
66 struct GNUNET_GNS_GetAuthRequest;
67
68 /**
69  * Record types
70  * Based on GNUNET_DNSPARSER_TYPEs (standard DNS)
71  */
72 enum GNUNET_GNS_RecordType
73 {
74   /**
75    * A 'struct in_addr'
76    */
77   GNUNET_GNS_RECORD_A          = GNUNET_DNSPARSER_TYPE_A,
78
79   /**
80    * A 'char *'
81    */
82   GNUNET_GNS_RECORD_NS         = GNUNET_DNSPARSER_TYPE_NS,
83
84   /**
85    * A 'char *'
86    */
87   GNUNET_GNS_RECORD_CNAME      = GNUNET_DNSPARSER_TYPE_CNAME,
88
89   /**
90    * A 'struct soa_data'
91    */
92   GNUNET_GNS_RECORD_SOA        = GNUNET_DNSPARSER_TYPE_SOA,
93
94   /**
95    * A 'struct srv_data'
96    */
97   GNUNET_GNS_RECORD_SRV        = GNUNET_DNSPARSER_TYPE_SRV,
98
99   /**
100    * A 'char *'
101    */
102   GNUNET_GNS_RECORD_PTR        = GNUNET_DNSPARSER_TYPE_PTR,
103
104   /**
105    * A 'uint16_t' and a 'char *'
106    */
107   GNUNET_GNS_RECORD_MX         = GNUNET_DNSPARSER_TYPE_MX,
108
109   /**
110    * A 'char *'
111    */
112   GNUNET_GNS_RECORD_TXT        = GNUNET_DNSPARSER_TYPE_TXT,
113
114   /**
115    * A 'struct in6_addr'
116    */
117   GNUNET_GNS_RECORD_AAAA       = GNUNET_DNSPARSER_TYPE_AAAA,
118
119   /* GNS specific */
120   /**
121    * A 'struct GNUNET_CRYPTO_ShortHashCode'
122    */
123   GNUNET_GNS_RECORD_PKEY = GNUNET_NAMESTORE_TYPE_PKEY,
124
125   /**
126    * A 'char *'
127    */
128   GNUNET_GNS_RECORD_PSEU = GNUNET_NAMESTORE_TYPE_PSEU,
129   GNUNET_GNS_RECORD_ANY  = GNUNET_NAMESTORE_TYPE_ANY,
130
131   /**
132    * A 'char *'
133    */
134   GNUNET_GNS_RECORD_LEHO = GNUNET_NAMESTORE_TYPE_LEHO,
135
136   /**
137    * A 'struct vpn_data'
138    */
139   GNUNET_GNS_RECORD_VPN  = GNUNET_NAMESTORE_TYPE_VPN,
140
141   /**
142    * Revocation, no data.
143    */
144   GNUNET_GNS_RECORD_REV  = GNUNET_NAMESTORE_TYPE_REV,
145
146   /**
147    * Social place.
148    */
149   GNUNET_GNS_RECORD_PLACE  = GNUNET_NAMESTORE_TYPE_PLACE
150 };
151
152
153 /**
154  * Initialize the connection with the GNS service.
155  *
156  * @param cfg configuration to use
157  *
158  * @return handle to the GNS service, or NULL on error
159  */
160 struct GNUNET_GNS_Handle *
161 GNUNET_GNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
162
163
164 /**
165  * Shutdown connection with the GNS service.
166  *
167  * @param handle connection to shut down
168  */
169 void
170 GNUNET_GNS_disconnect (struct GNUNET_GNS_Handle *handle);
171
172
173 /* *************** Standard API: lookup ******************* */
174
175 /**
176  * Iterator called on obtained result for a GNS
177  * lookup
178  *
179  * @param cls closure
180  * @param rd_count number of records
181  * @param rd the records in reply
182  */
183 typedef void (*GNUNET_GNS_LookupResultProcessor) (void *cls,
184                                                   uint32_t rd_count,
185                                                   const struct GNUNET_NAMESTORE_RecordData *rd);
186
187
188
189 /**
190  * Perform an asynchronous lookup operation on the GNS
191  * in the default zone.
192  *
193  * @param handle handle to the GNS service
194  * @param name the name to look up
195  * @param type the GNUNET_GNS_RecordType to look for
196  * @param only_cached GNUNET_NO to only check locally not DHT for performance
197  * @param shorten_key the private key of the shorten zone (can be NULL)
198  * @param proc function to call on result
199  * @param proc_cls closure for processor
200  *
201  * @return handle to the queued request
202  */
203 struct GNUNET_GNS_LookupRequest*
204 GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
205                    const char * name,
206                    enum GNUNET_GNS_RecordType type,
207                    int only_cached,
208                    struct GNUNET_CRYPTO_EccPrivateKey *shorten_key,
209                    GNUNET_GNS_LookupResultProcessor proc,
210                    void *proc_cls);
211
212
213 /**
214  * Perform an asynchronous lookup operation on the GNS
215  * in the zone specified by 'zone'.
216  *
217  * @param handle handle to the GNS service
218  * @param name the name to look up
219  * @param zone the zone to start the resolution in
220  * @param type the GNUNET_GNS_RecordType to look for
221  * @param only_cached GNUNET_YES to only check locally not DHT for performance
222  * @param shorten_key the private key of the shorten zone (can be NULL)
223  * @param proc function to call on result
224  * @param proc_cls closure for processor
225  *
226  * @return handle to the queued request
227  */
228 struct GNUNET_GNS_LookupRequest*
229 GNUNET_GNS_lookup_zone (struct GNUNET_GNS_Handle *handle,
230                         const char * name,
231                         struct GNUNET_CRYPTO_ShortHashCode *zone,
232                         enum GNUNET_GNS_RecordType type,
233                         int only_cached,
234                         struct GNUNET_CRYPTO_EccPrivateKey *shorten_key,
235                         GNUNET_GNS_LookupResultProcessor proc,
236                         void *proc_cls);
237
238
239 /**
240  * Cancel pending lookup request
241  *
242  * @param lr the lookup request to cancel
243  */
244 void
245 GNUNET_GNS_cancel_lookup_request (struct GNUNET_GNS_LookupRequest *lr);
246
247 /* *************** Standard API: shorten ******************* */
248
249
250 /**
251  * Processor called on for a name shortening result
252  * called only once
253  *
254  * @param cls closure
255  * @param short_name the shortened name or NULL if no result / error
256  */
257 typedef void (*GNUNET_GNS_ShortenResultProcessor) (void *cls,
258                                                    const char* short_name);
259
260
261 /**
262  * Perform a name shortening operation on the GNS.
263  *
264  * @param handle handle to the GNS service
265  * @param name the name to look up
266  * @param private_zone the public zone of the private zone
267  * @param shorten_zone the public zone of the shorten zone
268  * @param proc function to call on result
269  * @param proc_cls closure for processor
270  * @return handle to the operation
271  */
272 struct GNUNET_GNS_ShortenRequest*
273 GNUNET_GNS_shorten (struct GNUNET_GNS_Handle *handle,
274                     const char * name,
275                     struct GNUNET_CRYPTO_ShortHashCode *private_zone,
276                     struct GNUNET_CRYPTO_ShortHashCode *shorten_zone,
277                     GNUNET_GNS_ShortenResultProcessor proc,
278                     void *proc_cls);
279
280
281 /**
282  * Perform a name shortening operation on the GNS.
283  *
284  * @param handle handle to the GNS service
285  * @param name the name to look up
286  * @param private_zone the public zone of the private zone
287  * @param shorten_zone the public zone of the shorten zone
288  * @param zone the zone to start the resolution in
289  * @param proc function to call on result
290  * @param proc_cls closure for processor
291  * @return handle to the operation
292  */
293 struct GNUNET_GNS_ShortenRequest*
294 GNUNET_GNS_shorten_zone (struct GNUNET_GNS_Handle *handle,
295                          const char * name,
296                          struct GNUNET_CRYPTO_ShortHashCode *private_zone,
297                          struct GNUNET_CRYPTO_ShortHashCode *shorten_zone,
298                          struct GNUNET_CRYPTO_ShortHashCode *zone,
299                          GNUNET_GNS_ShortenResultProcessor proc,
300                          void *proc_cls);
301
302
303 /**
304  * Cancel pending shorten request
305  *
306  * @param sr the lookup request to cancel
307  */
308 void
309 GNUNET_GNS_cancel_shorten_request (struct GNUNET_GNS_ShortenRequest *sr);
310
311
312 /* *************** Standard API: get authority ******************* */
313
314
315 /**
316  * Processor called on for a name shortening result
317  * called only once
318  *
319  * @param cls closure
320  * @param auth_name the name of the auhtority or NULL
321  */
322 typedef void (*GNUNET_GNS_GetAuthResultProcessor) (void *cls,
323                                                    const char* short_name);
324
325
326 /**
327  * Perform an authority lookup for a given name.
328  *
329  * @param handle handle to the GNS service
330  * @param name the name to look up authority for
331  * @param proc function to call on result
332  * @param proc_cls closure for processor
333  * @return handle to the operation
334  */
335 struct GNUNET_GNS_GetAuthRequest*
336 GNUNET_GNS_get_authority (struct GNUNET_GNS_Handle *handle,
337                           const char *name,
338                           GNUNET_GNS_GetAuthResultProcessor proc,
339                           void *proc_cls);
340
341
342 /**
343  * Cancel pending get auth request
344  *
345  * @param gar the lookup request to cancel
346  */
347 void
348 GNUNET_GNS_cancel_get_auth_request (struct GNUNET_GNS_GetAuthRequest *gar);
349
350 #if 0                           /* keep Emacsens' auto-indent happy */
351 {
352 #endif
353 #ifdef __cplusplus
354 }
355 #endif
356
357
358 #endif
359 /* gnunet_gns_service.h */