glitch in the license text detected by hyazinthe, thank you!
[oweals/gnunet.git] / src / include / gnunet_datacache_plugin.h
1 /*
2      This file is part of GNUnet
3      Copyright (C) 2006, 2009, 2015 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
16 /**
17  * @author Christian Grothoff
18  *
19  * @file
20  * API for database backends for the datacache
21  *
22  * @defgroup datacache-plugin  Data Cache plugin API
23  * API for database backends for the datacache
24  * @{
25  */
26 #ifndef PLUGIN_DATACACHE_H
27 #define PLUGIN_DATACACHE_H
28
29 #include "gnunet_datacache_lib.h"
30
31 #ifdef __cplusplus
32 extern "C"
33 {
34 #if 0                           /* keep Emacsens' auto-indent happy */
35 }
36 #endif
37 #endif
38
39
40 /**
41  * Function called by plugins to notify the datacache
42  * about content deletions.
43  *
44  * @param cls closure
45  * @param key key of the content that was deleted
46  * @param size number of bytes that were made available
47  */
48 typedef void
49 (*GNUNET_DATACACHE_DeleteNotifyCallback) (void *cls,
50                                           const struct GNUNET_HashCode *key,
51                                           size_t size);
52
53
54 /**
55  * The datastore service will pass a pointer to a struct
56  * of this type as the first and only argument to the
57  * entry point of each datastore plugin.
58  */
59 struct GNUNET_DATACACHE_PluginEnvironment
60 {
61
62   /**
63    * Configuration to use.
64    */
65   const struct GNUNET_CONFIGURATION_Handle *cfg;
66
67   /**
68    * Configuration section to use.
69    */
70   const char *section;
71
72   /**
73    * Closure to use for callbacks.
74    */
75   void *cls;
76
77   /**
78    * Function to call whenever the plugin needs to
79    * discard content that it was asked to store.
80    */
81   GNUNET_DATACACHE_DeleteNotifyCallback delete_notify;
82
83   /**
84    * How much space are we allowed to use?
85    */
86   unsigned long long quota;
87
88 };
89
90
91 /**
92  * @brief struct returned by the initialization function of the plugin
93  */
94 struct GNUNET_DATACACHE_PluginFunctions
95 {
96
97   /**
98    * Closure to pass to all plugin functions.
99    */
100   void *cls;
101
102   /**
103    * Store an item in the datastore.
104    *
105    * @param cls closure (internal context for the plugin)
106    * @param key key to store the value under
107    * @param xor_distance how close is @a key to our PID?
108    * @param size number of bytes in @a data
109    * @param data data to store
110    * @param type type of the value
111    * @param discard_time when to discard the value in any case
112    * @param path_info_len number of entries in @a path_info
113    * @param path_info a path through the network
114    * @return 0 if duplicate, -1 on error, number of bytes used otherwise
115    */
116   ssize_t (*put) (void *cls,
117                   const struct GNUNET_HashCode *key,
118                   uint32_t xor_distance,
119                   size_t size,
120                   const char *data,
121                   enum GNUNET_BLOCK_Type type,
122                   struct GNUNET_TIME_Absolute discard_time,
123                   unsigned int path_info_len,
124                   const struct GNUNET_PeerIdentity *path_info);
125
126   /**
127    * Iterate over the results for a particular key
128    * in the datastore.
129    *
130    * @param cls closure (internal context for the plugin)
131    * @param key key to look for
132    * @param type entries of which type are relevant?
133    * @param iter maybe NULL (to just count)
134    * @param iter_cls closure for @a iter
135    * @return the number of results found
136    */
137   unsigned int (*get) (void *cls,
138                        const struct GNUNET_HashCode *key,
139                        enum GNUNET_BLOCK_Type type,
140                        GNUNET_DATACACHE_Iterator iter,
141                        void *iter_cls);
142
143   /**
144    * Delete the entry with the lowest expiration value
145    * from the datacache right now.
146    *
147    * @param cls closure (internal context for the plugin)
148    * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
149    */
150   int (*del) (void *cls);
151
152   /**
153    * Return a random value from the datastore.
154    *
155    * @param cls closure (internal context for the plugin)
156    * @param iter maybe NULL (to just count)
157    * @param iter_cls closure for @a iter
158    * @return the number of results found (zero or one)
159    */
160   unsigned int (*get_random) (void *cls,
161                               GNUNET_DATACACHE_Iterator iter,
162                               void *iter_cls);
163
164
165   /**
166    * Iterate over the results that are "close" to a particular key in
167    * the datacache.  "close" is defined as numerically larger than @a
168    * key (when interpreted as a circular address space), with small
169    * distance.
170    *
171    * @param cls closure (internal context for the plugin)
172    * @param key area of the keyspace to look into
173    * @param num_results number of results that should be returned to @a iter
174    * @param iter maybe NULL (to just count)
175    * @param iter_cls closure for @a iter
176    * @return the number of results found
177    */
178   unsigned int (*get_closest) (void *cls,
179                                const struct GNUNET_HashCode *key,
180                                unsigned int num_results,
181                                GNUNET_DATACACHE_Iterator iter,
182                                void *iter_cls);
183
184 };
185
186
187 #if 0                           /* keep Emacsens' auto-indent happy */
188 {
189 #endif
190 #ifdef __cplusplus
191 }
192 #endif
193
194 #endif
195
196 /** @} */  /* end of group */