748aa9f4bada3d8b96c6a6eb67275c64ee73fb2b
[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
38 #ifdef __cplusplus
39 extern "C"
40 {
41 #if 0                           /* keep Emacsens' auto-indent happy */
42 }
43 #endif
44 #endif
45
46
47 /**
48  * Connection to the GNS service.
49  */
50 struct GNUNET_GNS_Handle;
51
52 /**
53  * Handle to control a get operation.
54  */
55 struct GNUNET_GNS_LookupHandle;
56
57 /**
58  * A single GNS record.
59  */
60 struct GNUNET_GNS_Record;
61
62 /**
63  * Records types
64  */
65 enum GNUNET_GNS_RecordType
66 {
67   // FIXME: should be based on GNUNET_DNSPARSER_TYPE's (standard DNS),
68   // and then maybe our extensions in the area > 255?
69   GNUNET_GNS_RECORD_A,
70   GNUNET_GNS_RECORD_AAAA,
71   GNUNET_GNS_RECORD_MX,
72   GNUNET_GNS_RECORD_PKEY
73 };
74
75 /**
76  * Initialize the connection with the GNS service.
77  *
78  * @param cfg configuration to use
79  * @param ht_len size of the internal hash table to use for parallel lookups
80  * @return NULL on error
81  */
82 struct GNUNET_GNS_Handle *
83 GNUNET_GNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
84                     unsigned int ht_len);
85
86
87 /**
88  * Shutdown connection with the GNS service.
89  *
90  * @param handle connection to shut down
91  */
92 void
93 GNUNET_GNS_disconnect (struct GNUNET_GNS_Handle *handle);
94
95
96 /* *************** Standard API: lookup ******************* */
97
98 /**
99  * Iterator called on each result obtained for a GNS
100  * operation that expects a reply TODO: eh?
101  *
102  *
103  * @param cls closure
104  * @param name "name" of the original lookup
105  * @param record the records in reply
106  * // FIXME: shouldn't this then be an array of pointers? - not sure as of yet
107  * @param num_records the number of records in reply
108  */
109 typedef void (*GNUNET_GNS_LookupIterator) (void *cls,
110                                         const char * name,
111                                         const struct GNUNET_GNS_Record *record,
112                                         unsigned int num_records);
113
114
115
116 /**
117  * Perform an asynchronous lookup operation on the GNS.
118  *
119  * @param handle handle to the GNS service
120  * @param timeout how long to wait for transmission of this request to the service
121  * // FIXME: what happens afterwards?
122  * @param type expected type of the response object
123  * @param name the name to look up
124  * @param type the GNUNET_GNS_RecordType to look for
125  * @param iter function to call on each result
126  * @param iter_cls closure for iter
127  *
128  * @return handle to stop the async get
129  */
130 struct GNUNET_GNS_LookupHandle *
131 GNUNET_GNS_lookup_start (struct GNUNET_GNS_Handle *handle,
132                          struct GNUNET_TIME_Relative timeout,
133                          const char * name,
134                          enum GNUNET_GNS_RecordType type,
135                          GNUNET_GNS_LookupIterator iter,
136                          void *iter_cls);
137
138
139 /**
140  * Stop async GNS lookup.  Frees associated resources.
141  *
142  * @param lookup_handle lookup operation to stop.
143  *
144  * On return lookup_handle will no longer be valid, caller
145  * must not use again!!!
146  */
147 void
148 GNUNET_GNS_lookup_stop (struct GNUNET_GNS_LookupHandle *lookup_handle);
149
150
151 #if 0                           /* keep Emacsens' auto-indent happy */
152 {
153 #endif
154 #ifdef __cplusplus
155 }
156 #endif
157
158
159 #endif
160 /* gnunet_gns_service.h */