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_core.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).
96 * @param h handle to the datastore
98 void GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h);
102 * Get the current on-disk size of the datastore.
103 * @param h handle to the datastore
104 * @return size estimate, -1 if datastore is not available (yet)
106 unsigned long long GNUNET_DATASTORE_size (struct GNUNET_DATASTORE_Handle *h);
110 * Store an item in the datastore. If the item is already present,
111 * the priorities are summed up and the higher expiration time and
112 * lower anonymity level is used.
114 * @param h handle to the datastore
115 * @param key key for the value
116 * @param size number of bytes in data
117 * @param data content stored
118 * @param type type of the content
119 * @param priority priority of the content
120 * @param anonymity anonymity-level for the content
121 * @param expiration expiration time for the content
124 GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h,
125 const GNUNET_HashCode * key,
131 struct GNUNET_TIME_Absolute expiration);
134 * Iterate over the results for a particular key
137 * @param h handle to the datastore
138 * @param key maybe NULL (to match all entries)
139 * @param type desired type, 0 for any
140 * @param iter function to call on each matching value;
141 * will be called once with a NULL value at the end
142 * @param iter_cls closure for iter
145 GNUNET_DATASTORE_get (struct GNUNET_DATASTORE_Handle *h,
146 const GNUNET_HashCode * key,
148 GNUNET_DATASTORE_Iterator iter, void *iter_cls);
152 * Get a random value from the datastore.
154 * @param h handle to the datastore
155 * @param iter function to call on each matching value;
156 * will be called exactly once; if no values
157 * are available, the value will be NULL.
158 * @param iter_cls closure for iter
161 GNUNET_DATASTORE_get_random (struct GNUNET_DATASTORE_Handle *h,
162 GNUNET_DATASTORE_Iterator iter, void *iter_cls);
166 * Explicitly remove some content from the database.
168 * @param h handle to the datastore
169 * @param key key for the value
170 * @param size number of bytes in data
171 * @param data content stored
174 GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h,
175 const GNUNET_HashCode * key,
176 uint32_t size, const void *data);
179 #if 0 /* keep Emacsens' auto-indent happy */
186 /* end of gnunet_datastore_service.h */