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