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 * An iterator over a set of items stored in the datastore.
55 * @param key key for the content
56 * @param size number of bytes in data
57 * @param data content stored
58 * @param type type of the content
59 * @param priority priority of the content
60 * @param anonymity anonymity-level for the content
61 * @param expiration expiration time for the content
62 * @param uid unique identifier for the datum;
63 * maybe 0 if no unique identifier is available
65 * @return GNUNET_SYSERR to abort the iteration, GNUNET_OK to continue,
66 * GNUNET_NO to delete the item and continue (if supported)
68 typedef int (*GNUNET_DATASTORE_Iterator) (void *cls,
69 const GNUNET_HashCode * key,
75 struct GNUNET_TIME_Absolute
76 expiration, unsigned long long uid);
79 * Connect to the datastore service.
81 * @param cfg configuration to use
82 * @param sched scheduler to use
83 * @return handle to use to access the service
85 struct GNUNET_DATASTORE_Handle *GNUNET_DATASTORE_connect (struct
86 GNUNET_CONFIGURATION_Handle
89 GNUNET_SCHEDULER_Handle
94 * Disconnect from the datastore service (and free
95 * associated resources).
97 * @param h handle to the datastore
98 * @param drop set to GNUNET_YES to delete all data in datastore (!)
100 void GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h,
105 * Get the current on-disk size of the datastore.
106 * @param h handle to the datastore
107 * @return size estimate, -1 if datastore is not available (yet)
109 unsigned long long GNUNET_DATASTORE_size (struct GNUNET_DATASTORE_Handle *h);
113 * Store an item in the datastore. If the item is already present,
114 * the priorities are summed up and the higher expiration time and
115 * lower anonymity level is used.
117 * @param h handle to the datastore
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
127 GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h,
128 const GNUNET_HashCode * key,
134 struct GNUNET_TIME_Absolute expiration);
137 * Iterate over the results for a particular key
140 * @param h handle to the datastore
141 * @param key maybe NULL (to match all entries)
142 * @param type desired type, 0 for any
143 * @param iter function to call on each matching value;
144 * will be called once with a NULL value at the end
145 * @param iter_cls closure for iter
148 GNUNET_DATASTORE_get (struct GNUNET_DATASTORE_Handle *h,
149 const GNUNET_HashCode * key,
151 GNUNET_DATASTORE_Iterator iter, void *iter_cls);
155 * Get a random value from the datastore.
157 * @param h handle to the datastore
158 * @param iter function to call on each matching value;
159 * will be called exactly once; if no values
160 * are available, the value will be NULL.
161 * @param iter_cls closure for iter
164 GNUNET_DATASTORE_get_random (struct GNUNET_DATASTORE_Handle *h,
165 GNUNET_DATASTORE_Iterator iter, void *iter_cls);
169 * Explicitly remove some content from the database.
171 * @param h handle to the datastore
172 * @param key key for the value
173 * @param size number of bytes in data
174 * @param data content stored
177 GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h,
178 const GNUNET_HashCode * key,
179 uint32_t size, const void *data);
182 #if 0 /* keep Emacsens' auto-indent happy */
189 /* end of gnunet_datastore_service.h */