stuff
[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 /**
46  * Handle to the datastore service.
47  */
48 struct GNUNET_DATASTORE_Handle;
49
50
51 /**
52  * Connect to the datastore service.
53  *
54  * @param cfg configuration to use
55  * @param sched scheduler to use
56  * @return handle to use to access the service
57  */
58 struct GNUNET_DATASTORE_Handle *GNUNET_DATASTORE_connect (struct
59                                                           GNUNET_CONFIGURATION_Handle
60                                                           *cfg,
61                                                           struct
62                                                           GNUNET_SCHEDULER_Handle
63                                                           *sched);
64
65
66 /**
67  * Disconnect from the datastore service (and free
68  * associated resources).
69  *
70  * @param h handle to the datastore
71  * @param drop set to GNUNET_YES to delete all data in datastore (!)
72  */
73 void GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h,
74                                   int drop);
75
76
77 /**
78  * Continuation called to notify client about result of the
79  * operation.
80  *
81  * @param cls closure
82  * @param success GNUNET_SYSERR on failure
83  * @param msg NULL on success, otherwise an error message
84  */
85 typedef void (*GNUNET_DATASTORE_ContinuationWithStatus)(void *cls,
86                                                         int success,
87                                                         const char *msg);
88
89
90 /**
91  * Reserve space in the datastore.  This function should be used
92  * to avoid "out of space" failures during a longer sequence of "put"
93  * operations (for example, when a file is being inserted).
94  *
95  * @param h handle to the datastore
96  * @param amount how much space (in bytes) should be reserved (for content only)
97  * @param entries how many entries will be created (to calculate per-entry overhead)
98  * @param cont continuation to call when done; "success" will be set to
99  *             a positive reservation value if space could be reserved.
100  * @param cont_cls closure for cont
101  */
102 void
103 GNUNET_DATASTORE_reserve (struct GNUNET_DATASTORE_Handle *h,
104                           uint64_t amount,
105                           uint64_t entries,
106                           GNUNET_DATASTORE_ContinuationWithStatus cont,
107                           void *cont_cls);
108
109
110 /**
111  * Store an item in the datastore.  If the item is already present,
112  * the priorities are summed up and the higher expiration time and
113  * lower anonymity level is used.
114  *
115  * @param h handle to the datastore
116  * @param rid reservation ID to use (from "reserve"); use 0 if no
117  *            prior reservation was made
118  * @param key key for the value
119  * @param size number of bytes in data
120  * @param data content stored
121  * @param type type of the content
122  * @param priority priority of the content
123  * @param anonymity anonymity-level for the content
124  * @param expiration expiration time for the content
125  * @param cont continuation to call when done
126  * @param cont_cls closure for cont
127  */
128 void
129 GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h,
130                       int rid,
131                       const GNUNET_HashCode * key,
132                       uint32_t size,
133                       const void *data,
134                       uint32_t type,
135                       uint32_t priority,
136                       uint32_t anonymity,
137                       struct GNUNET_TIME_Absolute expiration,
138                       GNUNET_DATASTORE_ContinuationWithStatus cont,
139                       void *cont_cls);
140
141
142 /**
143  * Signal that all of the data for which a reservation was made has
144  * been stored and that whatever excess space might have been reserved
145  * can now be released.
146  *
147  * @param h handle to the datastore
148  * @param rid reservation ID (value of "success" in original continuation
149  *        from the "reserve" function).
150  * @param cont continuation to call when done
151  * @param cont_cls closure for cont
152  */
153 void
154 GNUNET_DATASTORE_release_reserve (struct GNUNET_DATASTORE_Handle *h,
155                                   int rid,
156                                   GNUNET_DATASTORE_ContinuationWithStatus cont,
157                                   void *cont_cls);
158
159
160 /**
161  * Update a value in the datastore.
162  *
163  * @param h handle to the datastore
164  * @param uid identifier for the value
165  * @param priority how much to increase the priority of the value
166  * @param expiration new expiration value should be MAX of existing and this argument
167  * @param cont continuation to call when done
168  * @param cont_cls closure for cont
169  */
170 void
171 GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h,
172                          unsigned long long uid,
173                          uint32_t priority,
174                          struct GNUNET_TIME_Absolute expiration,
175                          GNUNET_DATASTORE_ContinuationWithStatus cont,
176                          void *cont_cls);
177
178
179 /**
180  * An iterator over a set of items stored in the datastore.
181  *
182  * @param cls closure
183  * @param key key for the content
184  * @param size number of bytes in data
185  * @param data content stored
186  * @param type type of the content
187  * @param priority priority of the content
188  * @param anonymity anonymity-level for the content
189  * @param expiration expiration time for the content
190  * @param uid unique identifier for the datum;
191  *        maybe 0 if no unique identifier is available
192  */
193 typedef void (*GNUNET_DATASTORE_Iterator) (void *cls,
194                                            const GNUNET_HashCode * key,
195                                            uint32_t size,
196                                            const void *data,
197                                            uint32_t type,
198                                            uint32_t priority,
199                                            uint32_t anonymity,
200                                            struct GNUNET_TIME_Absolute
201                                            expiration, uint64_t uid);
202
203
204 /**
205  * Iterate over the results for a particular key
206  * in the datastore.
207  *
208  * @param h handle to the datastore
209  * @param key maybe NULL (to match all entries)
210  * @param type desired type, 0 for any
211  * @param iter function to call on each matching value;
212  *        will be called once with a NULL value at the end
213  * @param iter_cls closure for iter
214  */
215 void
216 GNUNET_DATASTORE_get (struct GNUNET_DATASTORE_Handle *h,
217                       const GNUNET_HashCode * key,
218                       uint32_t type,
219                       GNUNET_DATASTORE_Iterator iter, void *iter_cls);
220
221
222 /**
223  * Get a random value from the datastore.
224  *
225  * @param h handle to the datastore
226  * @param iter function to call on a random value; it
227  *        will be called once with a value (if available)
228  *        and always once with a value of NULL.
229  * @param iter_cls closure for iter
230  */
231 void
232 GNUNET_DATASTORE_get_random (struct GNUNET_DATASTORE_Handle *h,
233                              GNUNET_DATASTORE_Iterator iter, void *iter_cls);
234
235
236 /**
237  * Explicitly remove some content from the database.
238  *
239  * @param h handle to the datastore
240  * @param key key for the value
241  * @param size number of bytes in data
242  * @param data content stored
243  * @param cont continuation to call when done
244  * @param cont_cls closure for cont
245  */
246 void
247 GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h,
248                          const GNUNET_HashCode *key,
249                          uint32_t size, const void *data,
250                          GNUNET_DATASTORE_ContinuationWithStatus cont,
251                          void *cont_cls);
252
253
254 #if 0                           /* keep Emacsens' auto-indent happy */
255 {
256 #endif
257 #ifdef __cplusplus
258 }
259 #endif
260
261 /* end of gnunet_datastore_service.h */
262 #endif