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