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