cbb9e81c998be8fc7abb0252147787b6e9a9ab58
[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
148 /**
149  * Initialize the connection with the GNS service.
150  *
151  * @param cfg configuration to use
152  *
153  * @return handle to the GNS service, or NULL on error
154  */
155 struct GNUNET_GNS_Handle *
156 GNUNET_GNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
157
158
159 /**
160  * Shutdown connection with the GNS service.
161  *
162  * @param handle connection to shut down
163  */
164 void
165 GNUNET_GNS_disconnect (struct GNUNET_GNS_Handle *handle);
166
167
168 /* *************** Standard API: lookup ******************* */
169
170 /**
171  * Iterator called on obtained result for a GNS
172  * lookup
173  *
174  * @param cls closure
175  * @param rd_count number of records
176  * @param rd the records in reply
177  */
178 typedef void (*GNUNET_GNS_LookupResultProcessor) (void *cls,
179                                                   uint32_t rd_count,
180                                                   const struct GNUNET_NAMESTORE_RecordData *rd);
181
182
183
184 /**
185  * Perform an asynchronous lookup operation on the GNS
186  * in the default zone.
187  *
188  * @param handle handle to the GNS service
189  * @param name the name to look up
190  * @param type the GNUNET_GNS_RecordType to look for
191  * @param only_cached GNUNET_NO to only check locally not DHT for performance
192  * @param shorten_key the private key of the shorten zone (can be NULL)
193  * @param proc function to call on result
194  * @param proc_cls closure for processor
195  *
196  * @return handle to the queued request
197  */
198 struct GNUNET_GNS_LookupRequest*
199 GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
200                    const char * name,
201                    enum GNUNET_GNS_RecordType type,
202                    int only_cached,
203                    struct GNUNET_CRYPTO_EccPrivateKey *shorten_key,
204                    GNUNET_GNS_LookupResultProcessor proc,
205                    void *proc_cls);
206
207
208 /**
209  * Perform an asynchronous lookup operation on the GNS
210  * in the zone specified by 'zone'.
211  *
212  * @param handle handle to the GNS service
213  * @param name the name to look up
214  * @param zone the zone to start the resolution in
215  * @param type the GNUNET_GNS_RecordType to look for
216  * @param only_cached GNUNET_YES to only check locally not DHT for performance
217  * @param shorten_key the private key of the shorten zone (can be NULL)
218  * @param proc function to call on result
219  * @param proc_cls closure for processor
220  *
221  * @return handle to the queued request
222  */
223 struct GNUNET_GNS_LookupRequest*
224 GNUNET_GNS_lookup_zone (struct GNUNET_GNS_Handle *handle,
225                         const char * name,
226                         struct GNUNET_CRYPTO_ShortHashCode *zone,
227                         enum GNUNET_GNS_RecordType type,
228                         int only_cached,
229                         struct GNUNET_CRYPTO_EccPrivateKey *shorten_key,
230                         GNUNET_GNS_LookupResultProcessor proc,
231                         void *proc_cls);
232
233
234 /**
235  * Cancel pending lookup request
236  *
237  * @param lr the lookup request to cancel
238  */
239 void
240 GNUNET_GNS_cancel_lookup_request (struct GNUNET_GNS_LookupRequest *lr);
241
242 /* *************** Standard API: shorten ******************* */
243
244
245 /**
246  * Processor called on for a name shortening result
247  * called only once
248  *
249  * @param cls closure
250  * @param short_name the shortened name or NULL if no result / error
251  */
252 typedef void (*GNUNET_GNS_ShortenResultProcessor) (void *cls,
253                                                    const char* short_name);
254
255
256 /**
257  * Perform a name shortening operation on the GNS.
258  *
259  * @param handle handle to the GNS service
260  * @param name the name to look up
261  * @param private_zone the public zone of the private zone
262  * @param shorten_zone the public zone of the shorten zone
263  * @param proc function to call on result
264  * @param proc_cls closure for processor
265  * @return handle to the operation
266  */
267 struct GNUNET_GNS_ShortenRequest*
268 GNUNET_GNS_shorten (struct GNUNET_GNS_Handle *handle,
269                     const char * name,
270                     struct GNUNET_CRYPTO_ShortHashCode *private_zone,
271                     struct GNUNET_CRYPTO_ShortHashCode *shorten_zone,
272                     GNUNET_GNS_ShortenResultProcessor proc,
273                     void *proc_cls);
274
275
276 /**
277  * Perform a name shortening operation on the GNS.
278  *
279  * @param handle handle to the GNS service
280  * @param name the name to look up
281  * @param private_zone the public zone of the private zone
282  * @param shorten_zone the public zone of the shorten zone
283  * @param zone the zone to start the resolution in
284  * @param proc function to call on result
285  * @param proc_cls closure for processor
286  * @return handle to the operation
287  */
288 struct GNUNET_GNS_ShortenRequest*
289 GNUNET_GNS_shorten_zone (struct GNUNET_GNS_Handle *handle,
290                          const char * name,
291                          struct GNUNET_CRYPTO_ShortHashCode *private_zone,
292                          struct GNUNET_CRYPTO_ShortHashCode *shorten_zone,
293                          struct GNUNET_CRYPTO_ShortHashCode *zone,
294                          GNUNET_GNS_ShortenResultProcessor proc,
295                          void *proc_cls);
296
297
298 /**
299  * Cancel pending shorten request
300  *
301  * @param sr the lookup request to cancel
302  */
303 void
304 GNUNET_GNS_cancel_shorten_request (struct GNUNET_GNS_ShortenRequest *sr);
305
306
307 /* *************** Standard API: get authority ******************* */
308
309
310 /**
311  * Processor called on for a name shortening result
312  * called only once
313  *
314  * @param cls closure
315  * @param auth_name the name of the auhtority or NULL
316  */
317 typedef void (*GNUNET_GNS_GetAuthResultProcessor) (void *cls,
318                                                    const char* short_name);
319
320
321 /**
322  * Perform an authority lookup for a given name.
323  *
324  * @param handle handle to the GNS service
325  * @param name the name to look up authority for
326  * @param proc function to call on result
327  * @param proc_cls closure for processor
328  * @return handle to the operation
329  */
330 struct GNUNET_GNS_GetAuthRequest*
331 GNUNET_GNS_get_authority (struct GNUNET_GNS_Handle *handle,
332                           const char *name,
333                           GNUNET_GNS_GetAuthResultProcessor proc,
334                           void *proc_cls);
335
336
337 /**
338  * Cancel pending get auth request
339  *
340  * @param gar the lookup request to cancel
341  */
342 void
343 GNUNET_GNS_cancel_get_auth_request (struct GNUNET_GNS_GetAuthRequest *gar);
344
345 #if 0                           /* keep Emacsens' auto-indent happy */
346 {
347 #endif
348 #ifdef __cplusplus
349 }
350 #endif
351
352
353 #endif
354 /* gnunet_gns_service.h */