use NULL value in load_path_suffix to NOT load any files
[oweals/gnunet.git] / src / include / gnunet_datastore_plugin.h
1 /*
2      This file is part of GNUnet
3      Copyright (C) 2009, 2011 GNUnet e.V.
4
5      GNUnet is free software: you can redistribute it and/or modify it
6      under the terms of the GNU Affero General Public License as published
7      by the Free Software Foundation, either version 3 of the License,
8      or (at your 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      Affero General Public License for more details.
14
15      You should have received a copy of the GNU Affero General Public License
16      along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18      SPDX-License-Identifier: AGPL3.0-or-later
19  */
20
21 /**
22  * @author Christian Grothoff
23  *
24  * @file
25  * API for the database backend plugins.
26  *
27  * @defgroup datastore-plugin  Data Store service plugin API
28  * API for the database backend plugins.
29  * @{
30  */
31 #ifndef PLUGIN_DATASTORE_H
32 #define PLUGIN_DATASTORE_H
33
34 #include "gnunet_block_lib.h"
35 #include "gnunet_configuration_lib.h"
36 #include "gnunet_datastore_service.h"
37 #include "gnunet_statistics_service.h"
38 #include "gnunet_scheduler_lib.h"
39
40
41 /**
42  * How many bytes of overhead will we assume per entry
43  * in any DB (for reservations)?
44  */
45 #define GNUNET_DATASTORE_ENTRY_OVERHEAD 256
46
47
48 /**
49  * Function invoked to notify service of disk utilization
50  * changes.
51  *
52  * @param cls closure
53  * @param delta change in disk utilization,
54  *        0 for "reset to empty"
55  */
56 typedef void
57 (*GNUNET_DATASTORE_DiskUtilizationChange) (void *cls,
58                                            int delta);
59
60
61 /**
62  * The datastore service will pass a pointer to a struct
63  * of this type as the first and only argument to the
64  * entry point of each datastore plugin.
65  */
66 struct GNUNET_DATASTORE_PluginEnvironment
67 {
68   /**
69    * Configuration to use.
70    */
71   const struct GNUNET_CONFIGURATION_Handle *cfg;
72
73   /**
74    * Function to call on disk utilization change.
75    */
76   GNUNET_DATASTORE_DiskUtilizationChange duc;
77
78   /**
79    * Closure.
80    */
81   void *cls;
82 };
83
84
85 /**
86  * An processor over a set of items stored in the datastore.
87  *
88  * @param cls closure
89  * @param key key for the content
90  * @param size number of bytes in data
91  * @param data content stored
92  * @param type type of the content
93  * @param priority priority of the content
94  * @param anonymity anonymity-level for the content
95  * @param replication replication-level for the content
96  * @param expiration expiration time for the content
97  * @param uid unique identifier for the datum
98  * @return #GNUNET_OK to keep the item
99  *         #GNUNET_NO to delete the item
100  */
101 typedef int
102 (*PluginDatumProcessor) (void *cls,
103                          const struct GNUNET_HashCode *key,
104                          uint32_t size,
105                          const void *data,
106                          enum GNUNET_BLOCK_Type type,
107                          uint32_t priority,
108                          uint32_t anonymity,
109                          uint32_t replication,
110                          struct GNUNET_TIME_Absolute expiration,
111                          uint64_t uid);
112
113
114 /**
115  * Get an estimate of how much space the database is
116  * currently using.
117  *
118  * NB: estimate is an output parameter because emscripten cannot handle
119  * returning 64-bit integers from dynamically loaded modules.
120  *
121  * @param cls closure
122  * @param estimate location to store estimate
123  * @return number of bytes used on disk
124  */
125 typedef void
126 (*PluginEstimateSize) (void *cls,
127                        unsigned long long *estimate);
128
129
130 /**
131  * Put continuation.
132  *
133  * @param cls closure
134  * @param key key for the item stored
135  * @param size size of the item stored
136  * @param status #GNUNET_OK if inserted, #GNUNET_NO if updated,
137  *        or #GNUNET_SYSERROR if error
138  * @param msg error message on error
139  */
140 typedef void
141 (*PluginPutCont) (void *cls,
142                   const struct GNUNET_HashCode *key,
143                   uint32_t size,
144                   int status,
145                   const char *msg);
146
147
148 /**
149  * Store an item in the datastore.  If the item is already present,
150  * the priorities and replication levels are summed up and the higher
151  * expiration time and lower anonymity level is used.
152  *
153  * @param cls closure
154  * @param key key for the item
155  * @param absent true if the key was not found in the bloom filter
156  * @param size number of bytes in @a data
157  * @param data content stored
158  * @param type type of the content
159  * @param priority priority of the content
160  * @param anonymity anonymity-level for the content
161  * @param replication replication-level for the content
162  * @param expiration expiration time for the content
163  * @param cont continuation called with success or failure status
164  * @param cont_cls continuation closure for @a cont
165  */
166 typedef void
167 (*PluginPut) (void *cls,
168               const struct GNUNET_HashCode *key,
169               bool absent,
170               uint32_t size,
171               const void *data,
172               enum GNUNET_BLOCK_Type type,
173               uint32_t priority,
174               uint32_t anonymity,
175               uint32_t replication,
176               struct GNUNET_TIME_Absolute expiration,
177               PluginPutCont cont,
178               void *cont_cls);
179
180
181 /**
182  * An processor over a set of keys stored in the datastore.
183  *
184  * @param cls closure
185  * @param key key in the data store, if NULL iteration is finished
186  * @param count how many values are stored under this key in the datastore
187  */
188 typedef void
189 (*PluginKeyProcessor) (void *cls,
190                        const struct GNUNET_HashCode *key,
191                        unsigned int count);
192
193
194 /**
195  * Get all of the keys in the datastore.
196  *
197  * @param cls closure
198  * @param proc function to call on each key
199  * @param proc_cls closure for @a proc
200  */
201 typedef void
202 (*PluginGetKeys) (void *cls,
203                   PluginKeyProcessor proc,
204                   void *proc_cls);
205
206
207 /**
208  * Get one of the results for a particular key in the datastore.
209  *
210  * @param cls closure
211  * @param next_uid return the result with lowest uid >= next_uid
212  * @param random if true, return a random result instead of using next_uid
213  * @param key maybe NULL (to match all entries)
214  * @param type entries of which type are relevant?
215  *     Use 0 for any type.
216  * @param proc function to call on the matching value;
217  *        will be called with NULL if nothing matches
218  * @param proc_cls closure for @a proc
219  */
220 typedef void
221 (*PluginGetKey) (void *cls,
222                  uint64_t next_uid,
223                  bool random,
224                  const struct GNUNET_HashCode *key,
225                  enum GNUNET_BLOCK_Type type,
226                  PluginDatumProcessor proc,
227                  void *proc_cls);
228
229
230 /**
231  * Remove continuation.
232  *
233  * @param cls closure
234  * @param key key for the content removed
235  * @param size number of bytes removed
236  * @param status #GNUNET_OK if removed, #GNUNET_NO if not found,
237  *        or #GNUNET_SYSERROR if error
238  * @param msg error message on error
239  */
240 typedef void
241 (*PluginRemoveCont) (void *cls,
242                      const struct GNUNET_HashCode *key,
243                      uint32_t size,
244                      int status,
245                      const char *msg);
246
247
248 /**
249  * Remove a particular key in the datastore.
250  *
251  * @param cls closure
252  * @param key key for the content
253  * @param size number of bytes in data
254  * @param data content stored
255  * @param cont continuation called with success or failure status
256  * @param cont_cls continuation closure for @a cont
257  */
258 typedef void
259 (*PluginRemoveKey) (void *cls,
260                     const struct GNUNET_HashCode *key,
261                     uint32_t size,
262                     const void *data,
263                     PluginRemoveCont cont,
264                     void *cont_cls);
265
266
267 /**
268  * Get a random item (additional constraints may apply depending on
269  * the specific implementation).  Calls @a proc with all values ZERO or
270  * NULL if no item applies, otherwise @a proc is called once and only
271  * once with an item.
272  *
273  * @param cls closure
274  * @param proc function to call the value (once only).
275  * @param proc_cls closure for @a proc
276  */
277 typedef void
278 (*PluginGetRandom) (void *cls,
279                     PluginDatumProcessor proc,
280                     void *proc_cls);
281
282
283 /**
284  * Select a single item from the datastore (among those applicable).
285  *
286  * @param cls closure
287  * @param next_uid return the result with lowest uid >= next_uid
288  * @param type entries of which type should be considered?
289  *        Must not be zero (ANY).
290  * @param proc function to call on the matching value;
291  *        will be called with NULL if no value matches
292  * @param proc_cls closure for @a proc
293  */
294 typedef void
295 (*PluginGetType) (void *cls,
296                   uint64_t next_uid,
297                   enum GNUNET_BLOCK_Type type,
298                   PluginDatumProcessor proc,
299                   void *proc_cls);
300
301
302 /**
303  * Drop database.
304  *
305  * @param cls closure
306  */
307 typedef void
308 (*PluginDrop) (void *cls);
309
310
311 /**
312  * Each plugin is required to return a pointer to a struct of this
313  * type as the return value from its entry point.
314  */
315 struct GNUNET_DATASTORE_PluginFunctions
316 {
317   /**
318    * Closure to use for all of the following callbacks
319    * (except "next_request").
320    */
321   void *cls;
322
323   /**
324    * Calculate the current on-disk size of the SQ store.  Estimates
325    * are fine, if that's the only thing available.
326    */
327   PluginEstimateSize estimate_size;
328
329   /**
330    * Function to store an item in the datastore.
331    */
332   PluginPut put;
333
334   /**
335    * Get a particular datum matching a given hash from the datastore.
336    */
337   PluginGetKey get_key;
338
339   /**
340    * Get datum (of the specified type) with anonymity level zero.
341    */
342   PluginGetType get_zero_anonymity;
343
344   /**
345    * Function to get a random item with high replication score from
346    * the database, lowering the item's replication score.  Returns a
347    * single random item from those with the highest replication
348    * counters.  The item's replication counter is decremented by one
349    * IF it was positive before.
350    */
351   PluginGetRandom get_replication;
352
353   /**
354    * Function to get a random expired item or, if none are expired,
355    * either the oldest entry or one with a low priority (depending
356    * on what was efficiently implementable).
357    */
358   PluginGetRandom get_expiration;
359
360   /**
361    * Delete the database.  The next operation is
362    * guaranteed to be unloading of the module.
363    */
364   PluginDrop drop;
365
366   /**
367    * Iterate over all keys in the database.
368    */
369   PluginGetKeys get_keys;
370
371   /**
372    * Function to remove an item from the database.
373    */
374   PluginRemoveKey remove_key;
375 };
376
377 #endif
378
379 /** @} */  /* end of group */