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