66cbab8209e327681faf7f6f9a23c852d7b32cd4
[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 };
83
84 /**
85  * Initialize the connection with the GNS service.
86  *
87  * @param cfg configuration to use
88  * @param ht_len size of the internal hash table to use for parallel requests
89  * @return handle to the GNS service, or NULL on error
90  */
91 struct GNUNET_GNS_Handle *
92 GNUNET_GNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
93
94
95 /**
96  * Shutdown connection with the GNS service.
97  *
98  * @param handle connection to shut down
99  */
100 void
101 GNUNET_GNS_disconnect (struct GNUNET_GNS_Handle *handle);
102
103
104 /* *************** Standard API: lookup ******************* */
105
106 /**
107  * Iterator called on obtained result for a GNS
108  * lookup
109  *
110  * @param cls closure
111  * @param name "name" of the original lookup
112  * @param rd_count number of records
113  * @param rd the records in reply
114  */
115 typedef void (*GNUNET_GNS_LookupResultProcessor) (void *cls,
116                                         uint32_t rd_count,
117                                         const struct GNUNET_NAMESTORE_RecordData *rd);
118
119
120
121 /**
122  * Perform an asynchronous lookup operation on the GNS.
123  *
124  * @param handle handle to the GNS service
125  * @param name the name to look up
126  * @param type the GNUNET_GNS_RecordType to look for
127  * @param proc function to call on result
128  * @param proc_cls closure for iter
129  *
130  * @return handle to the queued request
131  */
132 struct GNUNET_GNS_QueueEntry *
133 GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
134                          const char * name,
135                          enum GNUNET_GNS_RecordType type,
136                          GNUNET_GNS_LookupResultProcessor proc,
137                          void *proc_cls);
138
139
140 /* *************** Standard API: shorten ******************* */
141
142
143 /**
144  * Processor called on for a name shortening result
145  * called only once
146  *
147  * @param cls closure
148  * @param short_name the shortened name or NULL if no result
149  */
150 typedef void (*GNUNET_GNS_ShortenResultProcessor) (void *cls,
151                                         const char* short_name);
152
153
154 /**
155  * Perform a shorten operation on name using the GNS.
156  *
157  * @param handle handle to the GNS service
158  * @param name the name to shorten
159  * @param proc processor to call on result
160  * @param cls closure for processor
161  *
162  * @return handle to the shorten operation
163  */
164 struct GNUNET_GNS_QueueEntry *
165 GNUNET_GNS_shorten (struct GNUNET_GNS_Handle *handle,
166                          const char * name,
167                          GNUNET_GNS_ShortenResultProcessor proc,
168                          void *cls);
169
170
171 /* *************** Standard API: get authority ******************* */
172
173
174 /**
175  * Processor called on for a name shortening result
176  * called only once
177  *
178  * @param cls closure
179  * @param auth_name the name of the auhtority or NULL
180  */
181 typedef void (*GNUNET_GNS_GetAuthResultProcessor) (void *cls,
182                                         const char* short_name);
183
184
185 /**
186  * Perform a shorten operation on name using the GNS.
187  *
188  * @param handle handle to the GNS service
189  * @param name the name to look up authority for
190  * @param proc processor to call on result
191  * @param cls closure for processor
192  *
193  * @return handle to the get authority operation
194  */
195 struct GNUNET_GNS_QueueEntry *
196 GNUNET_GNS_get_authority (struct GNUNET_GNS_Handle *handle,
197                          const char * name,
198                          GNUNET_GNS_GetAuthResultProcessor proc,
199                          void *cls);
200
201 #if 0                           /* keep Emacsens' auto-indent happy */
202 {
203 #endif
204 #ifdef __cplusplus
205 }
206 #endif
207
208
209 #endif
210 /* gnunet_gns_service.h */