mtypes
[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  * An iterator over a set of items stored in the datastore.
53  *
54  * @param cls closure
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
64  *
65  * @return GNUNET_SYSERR to abort the iteration, GNUNET_OK to continue,
66  *         GNUNET_NO to delete the item and continue (if supported)
67  */
68 typedef int (*GNUNET_DATASTORE_Iterator) (void *cls,
69                                           const GNUNET_HashCode * key,
70                                           uint32_t size,
71                                           const void *data,
72                                           uint32_t type,
73                                           uint32_t priority,
74                                           uint32_t anonymity,
75                                           struct GNUNET_TIME_Absolute
76                                           expiration, unsigned long long uid);
77
78 /**
79  * Connect to the datastore service.
80  *
81  * @param cfg configuration to use
82  * @param sched scheduler to use
83  * @return handle to use to access the service
84  */
85 struct GNUNET_DATASTORE_Handle *GNUNET_DATASTORE_connect (struct
86                                                           GNUNET_CONFIGURATION_Handle
87                                                           *cfg,
88                                                           struct
89                                                           GNUNET_SCHEDULER_Handle
90                                                           *sched);
91
92
93 /**
94  * Disconnect from the datastore service (and free
95  * associated resources).
96  *
97  * @param h handle to the datastore
98  * @param drop set to GNUNET_YES to delete all data in datastore (!)
99  */
100 void GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h,
101                                   int drop);
102
103
104 /**
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)
108  */
109 unsigned long long GNUNET_DATASTORE_size (struct GNUNET_DATASTORE_Handle *h);
110
111
112 /**
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.
116  *
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
125  */
126 void
127 GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h,
128                       const GNUNET_HashCode * key,
129                       uint32_t size,
130                       const void *data,
131                       uint32_t type,
132                       uint32_t priority,
133                       uint32_t anonymity,
134                       struct GNUNET_TIME_Absolute expiration);
135
136 /**
137  * Iterate over the results for a particular key
138  * in the datastore.
139  *
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
146  */
147 void
148 GNUNET_DATASTORE_get (struct GNUNET_DATASTORE_Handle *h,
149                       const GNUNET_HashCode * key,
150                       uint32_t type,
151                       GNUNET_DATASTORE_Iterator iter, void *iter_cls);
152
153
154 /**
155  * Get a random value from the datastore.
156  *
157  * @param h handle to the datastore
158  * @param iter function to call on a random value; it
159  *        will be called once with a value (if available)
160  *        and always once with a value of NULL.
161  * @param iter_cls closure for iter
162  */
163 void
164 GNUNET_DATASTORE_get_random (struct GNUNET_DATASTORE_Handle *h,
165                              GNUNET_DATASTORE_Iterator iter, void *iter_cls);
166
167
168 /**
169  * Explicitly remove some content from the database.
170  *
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
175  */
176 void
177 GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h,
178                          const GNUNET_HashCode *key,
179                          uint32_t size, const void *data);
180
181
182 #if 0                           /* keep Emacsens' auto-indent happy */
183 {
184 #endif
185 #ifdef __cplusplus
186 }
187 #endif
188
189 /* end of gnunet_datastore_service.h */
190 #endif