improving style and docs
[oweals/gnunet.git] / src / include / gnunet_datastore_service.h
1 /*
2      This file is part of GNUnet
3      (C) 2004, 2005, 2006, 2007, 2009 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 2, 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_datastore_service.h
23  * @brief API that can be used manage the
24  *   datastore for files stored on a GNUnet node;
25  *   note that the datastore is NOT responsible for
26  *   on-demand encoding, that is achieved using
27  *   a special kind of entry.
28  * @author Christian Grothoff
29  */
30
31 #ifndef GNUNET_DATASTORE_SERVICE_H
32 #define GNUNET_DATASTORE_SERVICE_H
33
34 #include "gnunet_util_lib.h"
35
36 #ifdef __cplusplus
37 extern "C"
38 {
39 #if 0                           /* keep Emacsens' auto-indent happy */
40 }
41 #endif
42 #endif
43
44 /**
45  * FIXME.
46  */
47 #define GNUNET_DATASTORE_BLOCKTYPE_ANY 0
48
49 /**
50  * FIXME.
51  */
52 #define GNUNET_DATASTORE_BLOCKTYPE_DBLOCK 1
53
54 /**
55  * FIXME.
56  */
57 #define GNUNET_DATASTORE_BLOCKTYPE_IBLOCK 2
58
59 /**
60  * FIXME.
61  */
62 #define GNUNET_DATASTORE_BLOCKTYPE_KBLOCK 3
63
64 /**
65  * FIXME.
66  */
67 #define GNUNET_DATASTORE_BLOCKTYPE_SBLOCK 4
68
69 /**
70  * FIXME.
71  */
72 #define GNUNET_DATASTORE_BLOCKTYPE_ONDEMAND 5
73
74 /**
75  * FIXME.
76  */
77 #define GNUNET_DATASTORE_BLOCKTYPE_SKBLOCK 6 /* not yet used */
78
79
80 /**
81  * Handle to the datastore service.
82  */
83 struct GNUNET_DATASTORE_Handle;
84
85
86 /**
87  * Connect to the datastore service.
88  *
89  * @param cfg configuration to use
90  * @param sched scheduler to use
91  * @return handle to use to access the service
92  */
93 struct GNUNET_DATASTORE_Handle *GNUNET_DATASTORE_connect (const struct
94                                                           GNUNET_CONFIGURATION_Handle
95                                                           *cfg,
96                                                           struct
97                                                           GNUNET_SCHEDULER_Handle
98                                                           *sched);
99
100
101 /**
102  * Disconnect from the datastore service (and free
103  * associated resources).
104  *
105  * @param h handle to the datastore
106  * @param drop set to GNUNET_YES to delete all data in datastore (!)
107  */
108 void GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h,
109                                   int drop);
110
111
112 /**
113  * Continuation called to notify client about result of the
114  * operation.
115  *
116  * @param cls closure
117  * @param success GNUNET_SYSERR on failure
118  * @param msg NULL on success, otherwise an error message
119  */
120 typedef void (*GNUNET_DATASTORE_ContinuationWithStatus)(void *cls,
121                                                         int success,
122                                                         const char *msg);
123
124
125 /**
126  * Reserve space in the datastore.  This function should be used
127  * to avoid "out of space" failures during a longer sequence of "put"
128  * operations (for example, when a file is being inserted).
129  *
130  * @param h handle to the datastore
131  * @param amount how much space (in bytes) should be reserved (for content only)
132  * @param entries how many entries will be created (to calculate per-entry overhead)
133  * @param cont continuation to call when done; "success" will be set to
134  *             a positive reservation value if space could be reserved.
135  * @param cont_cls closure for cont
136  * @param timeout how long to wait at most for a response
137  */
138 void
139 GNUNET_DATASTORE_reserve (struct GNUNET_DATASTORE_Handle *h,
140                           uint64_t amount,
141                           uint32_t entries,
142                           GNUNET_DATASTORE_ContinuationWithStatus cont,
143                           void *cont_cls,
144                           struct GNUNET_TIME_Relative timeout);
145
146
147 /**
148  * Store an item in the datastore.  If the item is already present,
149  * the priorities are summed up and the higher expiration time and
150  * lower anonymity level is used.
151  *
152  * @param h handle to the datastore
153  * @param rid reservation ID to use (from "reserve"); use 0 if no
154  *            prior reservation was made
155  * @param key key for the value
156  * @param size number of bytes in data
157  * @param data content stored
158  * @param type type of the content
159  * @param priority priority of the content
160  * @param anonymity anonymity-level for the content
161  * @param expiration expiration time for the content
162  * @param timeout timeout for the operation
163  * @param cont continuation to call when done
164  * @param cont_cls closure for cont
165  */
166 void
167 GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h,
168                       int rid,
169                       const GNUNET_HashCode * key,
170                       uint32_t size,
171                       const void *data,
172                       uint32_t type,
173                       uint32_t priority,
174                       uint32_t anonymity,
175                       struct GNUNET_TIME_Absolute expiration,
176                       struct GNUNET_TIME_Relative timeout,
177                       GNUNET_DATASTORE_ContinuationWithStatus cont,
178                       void *cont_cls);
179
180
181 /**
182  * Signal that all of the data for which a reservation was made has
183  * been stored and that whatever excess space might have been reserved
184  * can now be released.
185  *
186  * @param h handle to the datastore
187  * @param rid reservation ID (value of "success" in original continuation
188  *        from the "reserve" function).
189  * @param cont continuation to call when done
190  * @param cont_cls closure for cont
191  * @param timeout how long to wait at most for a response
192  */
193 void
194 GNUNET_DATASTORE_release_reserve (struct GNUNET_DATASTORE_Handle *h,
195                                   int rid,
196                                   GNUNET_DATASTORE_ContinuationWithStatus cont,
197                                   void *cont_cls,
198                                   struct GNUNET_TIME_Relative timeout);
199
200
201 /**
202  * Update a value in the datastore.
203  *
204  * @param h handle to the datastore
205  * @param uid identifier for the value
206  * @param priority how much to increase the priority of the value
207  * @param expiration new expiration value should be MAX of existing and this argument
208  * @param cont continuation to call when done
209  * @param cont_cls closure for cont
210  * @param timeout how long to wait at most for a response
211  */
212 void
213 GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h,
214                          unsigned long long uid,
215                          uint32_t priority,
216                          struct GNUNET_TIME_Absolute expiration,
217                          GNUNET_DATASTORE_ContinuationWithStatus cont,
218                          void *cont_cls,
219                          struct GNUNET_TIME_Relative timeout);
220
221
222 /**
223  * An iterator over a set of items stored in the datastore.
224  *
225  * @param cls closure
226  * @param key key for the content
227  * @param size number of bytes in data
228  * @param data content stored
229  * @param type type of the content
230  * @param priority priority of the content
231  * @param anonymity anonymity-level for the content
232  * @param expiration expiration time for the content
233  * @param uid unique identifier for the datum;
234  *        maybe 0 if no unique identifier is available
235  */
236 typedef void (*GNUNET_DATASTORE_Iterator) (void *cls,
237                                            const GNUNET_HashCode * key,
238                                            uint32_t size,
239                                            const void *data,
240                                            uint32_t type,
241                                            uint32_t priority,
242                                            uint32_t anonymity,
243                                            struct GNUNET_TIME_Absolute
244                                            expiration, uint64_t uid);
245
246
247 /**
248  * Iterate over the results for a particular key
249  * in the datastore.  The iterator will only be called
250  * once initially; if the first call did contain a
251  * result, further results can be obtained by calling
252  * "GNUNET_DATASTORE_get_next" with the given argument.
253  *
254  * @param h handle to the datastore
255  * @param key maybe NULL (to match all entries)
256  * @param type desired type, 0 for any
257  * @param iter function to call on each matching value;
258  *        will be called once with a NULL value at the end
259  * @param iter_cls closure for iter
260  * @param timeout how long to wait at most for a response
261  */
262 void
263 GNUNET_DATASTORE_get (struct GNUNET_DATASTORE_Handle *h,
264                       const GNUNET_HashCode * key,
265                       uint32_t type,
266                       GNUNET_DATASTORE_Iterator iter, 
267                       void *iter_cls,
268                       struct GNUNET_TIME_Relative timeout);
269
270
271 /**
272  * Function called to trigger obtaining the next result
273  * from the datastore.
274  * 
275  * @param h handle to the datastore
276  * @param more GNUNET_YES to get moxre results, GNUNET_NO to abort
277  *        iteration (with a final call to "iter" with key/data == NULL).
278  */
279 void
280 GNUNET_DATASTORE_get_next (struct GNUNET_DATASTORE_Handle *h,
281                            int more);
282
283
284 /**
285  * Get a random value from the datastore.
286  *
287  * @param h handle to the datastore
288  * @param iter function to call on a random value; it
289  *        will be called once with a value (if available)
290  *        and always once with a value of NULL.
291  * @param iter_cls closure for iter
292  * @param timeout how long to wait at most for a response
293  */
294 void
295 GNUNET_DATASTORE_get_random (struct GNUNET_DATASTORE_Handle *h,
296                              GNUNET_DATASTORE_Iterator iter, void *iter_cls,
297                              struct GNUNET_TIME_Relative timeout);
298
299
300 /**
301  * Explicitly remove some content from the database.
302  * The "cont"inuation will be called with status
303  * "GNUNET_OK" if content was removed, "GNUNET_NO"
304  * if no matching entry was found and "GNUNET_SYSERR"
305  * on all other types of errors.
306  *
307  * @param h handle to the datastore
308  * @param key key for the value
309  * @param size number of bytes in data
310  * @param data content stored
311  * @param cont continuation to call when done
312  * @param cont_cls closure for cont
313  * @param timeout how long to wait at most for a response
314  */
315 void
316 GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h,
317                          const GNUNET_HashCode *key,
318                          uint32_t size, const void *data,
319                          GNUNET_DATASTORE_ContinuationWithStatus cont,
320                          void *cont_cls,
321                          struct GNUNET_TIME_Relative timeout);
322
323
324 #if 0                           /* keep Emacsens' auto-indent happy */
325 {
326 #endif
327 #ifdef __cplusplus
328 }
329 #endif
330
331 /* end of gnunet_datastore_service.h */
332 #endif