-fix 2447
[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 get operation.
56  */
57 struct GNUNET_GNS_LookupHandle;
58
59 /**
60  * Handle to control a shorten operation
61  */
62
63 /**
64  * Record types
65  * Based on GNUNET_DNSPARSER_TYPEs (standard DNS)
66  */
67 enum GNUNET_GNS_RecordType
68 {
69   /* Standard DNS */
70   GNUNET_GNS_RECORD_A          = GNUNET_DNSPARSER_TYPE_A,
71   GNUNET_GNS_RECORD_NS         = GNUNET_DNSPARSER_TYPE_NS,
72   GNUNET_GNS_RECORD_CNAME      = GNUNET_DNSPARSER_TYPE_CNAME,
73   GNUNET_GNS_RECORD_SOA        = GNUNET_DNSPARSER_TYPE_SOA,
74   GNUNET_GNS_RECORD_SRV        = GNUNET_DNSPARSER_TYPE_SRV,
75   GNUNET_GNS_RECORD_PTR        = GNUNET_DNSPARSER_TYPE_PTR,
76   GNUNET_GNS_RECORD_MX         = GNUNET_DNSPARSER_TYPE_MX,
77   GNUNET_GNS_RECORD_TXT        = GNUNET_DNSPARSER_TYPE_TXT,
78   GNUNET_GNS_RECORD_AAAA       = GNUNET_DNSPARSER_TYPE_AAAA,
79
80   /* GNS specific */
81   GNUNET_GNS_RECORD_PKEY = GNUNET_NAMESTORE_TYPE_PKEY,
82   GNUNET_GNS_RECORD_PSEU = GNUNET_NAMESTORE_TYPE_PSEU,
83   GNUNET_GNS_RECORD_ANY  = GNUNET_NAMESTORE_TYPE_ANY,
84   GNUNET_GNS_RECORD_LEHO = GNUNET_NAMESTORE_TYPE_LEHO,
85   GNUNET_GNS_RECORD_VPN  = GNUNET_NAMESTORE_TYPE_VPN,
86   GNUNET_GNS_RECORD_REV  = GNUNET_NAMESTORE_TYPE_REV
87 };
88
89 /**
90  * Initialize the connection with the GNS service.
91  *
92  * @param cfg configuration to use
93  *
94  * @return handle to the GNS service, or NULL on error
95  */
96 struct GNUNET_GNS_Handle *
97 GNUNET_GNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
98
99
100 /**
101  * Shutdown connection with the GNS service.
102  *
103  * @param handle connection to shut down
104  */
105 void
106 GNUNET_GNS_disconnect (struct GNUNET_GNS_Handle *handle);
107
108
109 /* *************** Standard API: lookup ******************* */
110
111 /**
112  * Iterator called on obtained result for a GNS
113  * lookup
114  *
115  * @param cls closure
116  * @param name "name" of the original lookup
117  * @param rd_count number of records
118  * @param rd the records in reply
119  */
120 typedef void (*GNUNET_GNS_LookupResultProcessor) (void *cls,
121                                  uint32_t rd_count,
122                                  const struct GNUNET_NAMESTORE_RecordData *rd);
123
124
125
126 /**
127  * Perform an asynchronous lookup operation on the GNS
128  * in the default zone.
129  *
130  * @param handle handle to the GNS service
131  * @param name the name to look up
132  * @param type the GNUNET_GNS_RecordType to look for
133  * @param only_cached GNUNET_NO to only check locally not DHT for performance
134  * @param shorten_key the private key of the shorten zone (can be NULL)
135  * @param proc function to call on result
136  * @param proc_cls closure for processor
137  *
138  * @return handle to the queued request
139  */
140 struct GNUNET_GNS_QueueEntry *
141 GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
142                          const char * name,
143                          enum GNUNET_GNS_RecordType type,
144                          int only_cached,
145                          struct GNUNET_CRYPTO_RsaPrivateKey *shorten_key,
146                          GNUNET_GNS_LookupResultProcessor proc,
147                          void *proc_cls);
148
149 /**
150  * Perform an asynchronous lookup operation on the GNS
151  * in the zone specified by 'zone'.
152  *
153  * @param handle handle to the GNS service
154  * @param name the name to look up
155  * @param zone the zone to start the resolution in
156  * @param type the GNUNET_GNS_RecordType to look for
157  * @param only_cached GNUNET_NO to only check locally not DHT for performance
158  * @param shorten_key the private key of the shorten zone (can be NULL)
159  * @param proc function to call on result
160  * @param proc_cls closure for processor
161  *
162  * @return handle to the queued request
163  */
164 struct GNUNET_GNS_QueueEntry *
165 GNUNET_GNS_lookup_zone (struct GNUNET_GNS_Handle *handle,
166                          const char * name,
167                          struct GNUNET_CRYPTO_ShortHashCode *zone,
168                          enum GNUNET_GNS_RecordType type,
169                          int only_cached,
170                          struct GNUNET_CRYPTO_RsaPrivateKey *shorten_key,
171                          GNUNET_GNS_LookupResultProcessor proc,
172                          void *proc_cls);
173
174 /* *************** Standard API: shorten ******************* */
175
176
177 /**
178  * Processor called on for a name shortening result
179  * called only once
180  *
181  * @param cls closure
182  * @param short_name the shortened name or NULL if no result
183  */
184 typedef void (*GNUNET_GNS_ShortenResultProcessor) (void *cls,
185                                         const char* short_name);
186
187
188 /**
189  * Perform a name shortening operation on the GNS.
190  *
191  * @param handle handle to the GNS service
192  * @param name the name to look up
193  * @param private_zone the public zone of the private zone
194  * @param shorten_zone the public zone of the shorten zone
195  * @param proc function to call on result
196  * @param proc_cls closure for processor
197  * @return handle to the operation
198  */
199 struct GNUNET_GNS_QueueEntry *
200 GNUNET_GNS_shorten (struct GNUNET_GNS_Handle *handle,
201                     const char * name,
202                     struct GNUNET_CRYPTO_ShortHashCode *private_zone,
203                     struct GNUNET_CRYPTO_ShortHashCode *shorten_zone,
204                     GNUNET_GNS_ShortenResultProcessor proc,
205                     void *proc_cls);
206
207
208 /**
209  * Perform a name shortening operation on the GNS.
210  *
211  * @param handle handle to the GNS service
212  * @param name the name to look up
213  * @param private_zone the public zone of the private zone
214  * @param shorten_zone the public zone of the shorten zone
215  * @param zone the zone to start the resolution in
216  * @param proc function to call on result
217  * @param proc_cls closure for processor
218  * @return handle to the operation
219  */
220 struct GNUNET_GNS_QueueEntry *
221 GNUNET_GNS_shorten_zone (struct GNUNET_GNS_Handle *handle,
222                          const char * name,
223                          struct GNUNET_CRYPTO_ShortHashCode *private_zone,
224                          struct GNUNET_CRYPTO_ShortHashCode *shorten_zone,
225                          struct GNUNET_CRYPTO_ShortHashCode *zone,
226                          GNUNET_GNS_ShortenResultProcessor proc,
227                          void *proc_cls);
228
229 /* *************** Standard API: get authority ******************* */
230
231
232 /**
233  * Processor called on for a name shortening result
234  * called only once
235  *
236  * @param cls closure
237  * @param auth_name the name of the auhtority or NULL
238  */
239 typedef void (*GNUNET_GNS_GetAuthResultProcessor) (void *cls,
240                                         const char* short_name);
241
242
243 /**
244  * Perform an authority lookup for a given name.
245  *
246  * @param handle handle to the GNS service
247  * @param name the name to look up authority for
248  * @param proc function to call on result
249  * @param proc_cls closure for processor
250  * @return handle to the operation
251  */
252 struct GNUNET_GNS_QueueEntry *
253 GNUNET_GNS_get_authority (struct GNUNET_GNS_Handle *handle,
254                     const char * name,
255                     GNUNET_GNS_GetAuthResultProcessor proc,
256                     void *proc_cls);
257
258 #if 0                           /* keep Emacsens' auto-indent happy */
259 {
260 #endif
261 #ifdef __cplusplus
262 }
263 #endif
264
265
266 #endif
267 /* gnunet_gns_service.h */