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