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