2 This file is part of GNUnet
3 (C) 2004, 2005, 2006, 2007, 2009 Christian Grothoff (and other contributing authors)
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.
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.
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.
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
31 #ifndef GNUNET_DATASTORE_SERVICE_H
32 #define GNUNET_DATASTORE_SERVICE_H
34 #include "gnunet_util_lib.h"
39 #if 0 /* keep Emacsens' auto-indent happy */
46 * Handle to the datastore service.
48 struct GNUNET_DATASTORE_Handle;
52 * Connect to the datastore service.
54 * @param cfg configuration to use
55 * @param sched scheduler to use
56 * @return handle to use to access the service
58 struct GNUNET_DATASTORE_Handle *GNUNET_DATASTORE_connect (struct
59 GNUNET_CONFIGURATION_Handle
62 GNUNET_SCHEDULER_Handle
67 * Disconnect from the datastore service (and free
68 * associated resources).
70 * @param h handle to the datastore
71 * @param drop set to GNUNET_YES to delete all data in datastore (!)
73 void GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h,
78 * Continuation called to notify client about result of the
82 * @param success GNUNET_SYSERR on failure
83 * @param msg NULL on success, otherwise an error message
85 typedef void (*GNUNET_DATASTORE_ContinuationWithStatus)(void *cls,
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).
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
103 GNUNET_DATASTORE_reserve (struct GNUNET_DATASTORE_Handle *h,
106 GNUNET_DATASTORE_ContinuationWithStatus cont,
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.
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 timeout timeout for the operation
126 * @param cont continuation to call when done
127 * @param cont_cls closure for cont
130 GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h,
132 const GNUNET_HashCode * key,
138 struct GNUNET_TIME_Absolute expiration,
139 struct GNUNET_TIME_Relative timeout,
140 GNUNET_DATASTORE_ContinuationWithStatus cont,
145 * Signal that all of the data for which a reservation was made has
146 * been stored and that whatever excess space might have been reserved
147 * can now be released.
149 * @param h handle to the datastore
150 * @param rid reservation ID (value of "success" in original continuation
151 * from the "reserve" function).
152 * @param cont continuation to call when done
153 * @param cont_cls closure for cont
156 GNUNET_DATASTORE_release_reserve (struct GNUNET_DATASTORE_Handle *h,
158 GNUNET_DATASTORE_ContinuationWithStatus cont,
163 * Update a value in the datastore.
165 * @param h handle to the datastore
166 * @param uid identifier for the value
167 * @param priority how much to increase the priority of the value
168 * @param expiration new expiration value should be MAX of existing and this argument
169 * @param cont continuation to call when done
170 * @param cont_cls closure for cont
173 GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h,
174 unsigned long long uid,
176 struct GNUNET_TIME_Absolute expiration,
177 GNUNET_DATASTORE_ContinuationWithStatus cont,
182 * An iterator over a set of items stored in the datastore.
185 * @param key key for the content
186 * @param size number of bytes in data
187 * @param data content stored
188 * @param type type of the content
189 * @param priority priority of the content
190 * @param anonymity anonymity-level for the content
191 * @param expiration expiration time for the content
192 * @param uid unique identifier for the datum;
193 * maybe 0 if no unique identifier is available
195 typedef void (*GNUNET_DATASTORE_Iterator) (void *cls,
196 const GNUNET_HashCode * key,
202 struct GNUNET_TIME_Absolute
203 expiration, uint64_t uid);
207 * Iterate over the results for a particular key
210 * @param h handle to the datastore
211 * @param key maybe NULL (to match all entries)
212 * @param type desired type, 0 for any
213 * @param iter function to call on each matching value;
214 * will be called once with a NULL value at the end
215 * @param iter_cls closure for iter
218 GNUNET_DATASTORE_get (struct GNUNET_DATASTORE_Handle *h,
219 const GNUNET_HashCode * key,
221 GNUNET_DATASTORE_Iterator iter, void *iter_cls);
225 * Get a random value from the datastore.
227 * @param h handle to the datastore
228 * @param iter function to call on a random value; it
229 * will be called once with a value (if available)
230 * and always once with a value of NULL.
231 * @param iter_cls closure for iter
234 GNUNET_DATASTORE_get_random (struct GNUNET_DATASTORE_Handle *h,
235 GNUNET_DATASTORE_Iterator iter, void *iter_cls);
239 * Explicitly remove some content from the database.
241 * @param h handle to the datastore
242 * @param key key for the value
243 * @param size number of bytes in data
244 * @param data content stored
245 * @param cont continuation to call when done
246 * @param cont_cls closure for cont
249 GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h,
250 const GNUNET_HashCode *key,
251 uint32_t size, const void *data,
252 GNUNET_DATASTORE_ContinuationWithStatus cont,
256 #if 0 /* keep Emacsens' auto-indent happy */
263 /* end of gnunet_datastore_service.h */