diff options
Diffstat (limited to 'src/datastore/plugin_datastore.h')
-rw-r--r-- | src/datastore/plugin_datastore.h | 241 |
1 files changed, 241 insertions, 0 deletions
diff --git a/src/datastore/plugin_datastore.h b/src/datastore/plugin_datastore.h new file mode 100644 index 000000000..b4dc87f9d --- /dev/null +++ b/src/datastore/plugin_datastore.h | |||
@@ -0,0 +1,241 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | (C) 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 datastore/plugin_datastore.h | ||
23 | * @brief API for the database backend plugins. | ||
24 | * @author Christian Grothoff | ||
25 | * | ||
26 | * TODO: | ||
27 | * - consider defining enumeration or at least typedef | ||
28 | * for the type of "type" (instead of using uint32_t) | ||
29 | */ | ||
30 | #ifndef PLUGIN_DATASTORE_H | ||
31 | #define PLUGIN_DATASTORE_H | ||
32 | |||
33 | #include "gnunet_configuration_lib.h" | ||
34 | #include "gnunet_scheduler_lib.h" | ||
35 | #include "gnunet_datastore_service.h" | ||
36 | |||
37 | /** | ||
38 | * The datastore service will pass a pointer to a struct | ||
39 | * of this type as the first and only argument to the | ||
40 | * entry point of each datastore plugin. | ||
41 | */ | ||
42 | struct GNUNET_DATASTORE_PluginEnvironment | ||
43 | { | ||
44 | /** | ||
45 | * Configuration to use. | ||
46 | */ | ||
47 | struct GNUNET_CONFIGURATION_Handle *cfg; | ||
48 | |||
49 | /** | ||
50 | * Scheduler to use. | ||
51 | */ | ||
52 | struct GNUNET_SCHEDULER_Handle *sched; | ||
53 | |||
54 | }; | ||
55 | |||
56 | |||
57 | /** | ||
58 | * Get an estimate of how much space the database is | ||
59 | * currently using. | ||
60 | * @return number of bytes used on disk | ||
61 | */ | ||
62 | typedef unsigned long long (*GNUNET_DATASTORE_GetSize) (void *cls); | ||
63 | |||
64 | |||
65 | /** | ||
66 | * Store an item in the datastore. | ||
67 | * | ||
68 | * @param cls closure | ||
69 | * @param key key for the item | ||
70 | * @param size number of bytes in data | ||
71 | * @param data content stored | ||
72 | * @param type type of the content | ||
73 | * @param priority priority of the content | ||
74 | * @param anonymity anonymity-level for the content | ||
75 | * @param expiration expiration time for the content | ||
76 | */ | ||
77 | typedef void | ||
78 | (*GNUNET_DATASTORE_Put) (void *cls, | ||
79 | const GNUNET_HashCode * key, | ||
80 | uint32_t size, | ||
81 | const void *data, | ||
82 | unit32_t type, | ||
83 | uint32_t priority, | ||
84 | uint32_t anonymity, | ||
85 | struct GNUNET_TIME_Absolute expiration); | ||
86 | |||
87 | |||
88 | /** | ||
89 | * Iterate over the results for a particular key | ||
90 | * in the datastore. | ||
91 | * | ||
92 | * @param cls closure | ||
93 | * @param key maybe NULL (to match all entries) | ||
94 | * @param vhash hash of the value, maybe NULL (to | ||
95 | * match all values that have the right key). | ||
96 | * Note that for DBlocks there is no difference | ||
97 | * betwen key and vhash, but for other blocks | ||
98 | * there may be! | ||
99 | * @param type entries of which type are relevant? | ||
100 | * Use 0 for any type. | ||
101 | * @param iter function to call on each matching value; | ||
102 | * will be called once with a NULL value at the end | ||
103 | * @param iter_cls closure for iter | ||
104 | */ | ||
105 | typedef void | ||
106 | (*GNUNET_DATASTORE_Get) (void *cls, | ||
107 | const GNUNET_HashCode * key, | ||
108 | const GNUNET_HashCode * vhash, | ||
109 | uint32_t type, | ||
110 | GNUNET_DATASTORE_Iterator iter, void *iter_cls); | ||
111 | |||
112 | |||
113 | /** | ||
114 | * Update the priority for a particular key in the datastore. If | ||
115 | * the expiration time in value is different than the time found in | ||
116 | * the datastore, the higher value should be kept. For the | ||
117 | * anonymity level, the lower value is to be used. The specified | ||
118 | * priority should be added to the existing priority, ignoring the | ||
119 | * priority in value. | ||
120 | * | ||
121 | * Note that it is possible for multiple values to match this put. | ||
122 | * In that case, all of the respective values are updated. | ||
123 | * | ||
124 | * @param uid unique identifier of the datum | ||
125 | * @param delta by how much should the priority | ||
126 | * change? If priority + delta < 0 the | ||
127 | * priority should be set to 0 (never go | ||
128 | * negative). | ||
129 | * @param expire new expiration time should be the | ||
130 | * MAX of any existing expiration time and | ||
131 | * this value | ||
132 | */ | ||
133 | typedef void | ||
134 | (*GNUNET_DATASTORE_Update) (void *cls, | ||
135 | unsigned long long uid, | ||
136 | int delta, struct GNUNET_TIME_Absolute expire); | ||
137 | |||
138 | |||
139 | /** | ||
140 | * Select a subset of the items in the datastore and call | ||
141 | * the given iterator for each of them. | ||
142 | * | ||
143 | * @param type entries of which type should be considered? | ||
144 | * Use 0 for any type. | ||
145 | * @param iter function to call on each matching value; | ||
146 | * will be called once with a NULL value at the end | ||
147 | * @param iter_cls closure for iter | ||
148 | */ | ||
149 | typedef void | ||
150 | (*GNUNET_DATASTORE_Selector) (void *cls, | ||
151 | uint32_t type, | ||
152 | GNUNET_DATASTORE_Iterator iter, | ||
153 | void *iter_cls); | ||
154 | |||
155 | /** | ||
156 | * Drop database. | ||
157 | */ | ||
158 | typedef void (*GNUNET_DATASTORE_Drop) (void *cls); | ||
159 | |||
160 | |||
161 | |||
162 | /** | ||
163 | * Each plugin is required to return a pointer to a struct of this | ||
164 | * type as the return value from its entry point. | ||
165 | */ | ||
166 | struct GNUNET_DATASTORE_PluginFunctions | ||
167 | { | ||
168 | |||
169 | /** | ||
170 | * Closure to use for all of the following callbacks. | ||
171 | */ | ||
172 | void *cls; | ||
173 | |||
174 | /** | ||
175 | * Get the current on-disk size of the SQ store. Estimates are | ||
176 | * fine, if that's the only thing available. | ||
177 | */ | ||
178 | GNUNET_DATASTORE_GetSize size; | ||
179 | |||
180 | /** | ||
181 | * Function to store an item in the datastore. | ||
182 | */ | ||
183 | GNUNET_DATASTORE_Put put; | ||
184 | |||
185 | /** | ||
186 | * Function to iterate over the results for a particular key | ||
187 | * in the datastore. | ||
188 | */ | ||
189 | GNUNET_DATASTORE_Get get; | ||
190 | |||
191 | /** | ||
192 | * Update the priority for a particular key in the datastore. If | ||
193 | * the expiration time in value is different than the time found in | ||
194 | * the datastore, the higher value should be kept. For the | ||
195 | * anonymity level, the lower value is to be used. The specified | ||
196 | * priority should be added to the existing priority, ignoring the | ||
197 | * priority in value. | ||
198 | */ | ||
199 | GNUNET_DATASTORE_Update update; | ||
200 | |||
201 | /** | ||
202 | * Iterate over the items in the datastore in ascending | ||
203 | * order of priority. | ||
204 | */ | ||
205 | GNUNET_DATASTORE_Selector iter_low_priority; | ||
206 | |||
207 | /** | ||
208 | * Iterate over content with anonymity zero. | ||
209 | */ | ||
210 | GNUNET_DATASTORE_Selector iter_zero_anonymity; | ||
211 | |||
212 | /** | ||
213 | * Iterate over the items in the datastore in ascending | ||
214 | * order of expiration time. | ||
215 | */ | ||
216 | GNUNET_DATSTORE_Selector iter_ascending_expiration; | ||
217 | |||
218 | /** | ||
219 | * Iterate over the items in the datastore in migration | ||
220 | * order. | ||
221 | */ | ||
222 | GNUNET_DATASTORE_Selector iter_migration_order; | ||
223 | |||
224 | /** | ||
225 | * Iterate over all the items in the datastore | ||
226 | * as fast as possible in a single transaction | ||
227 | * (can lock datastore while this happens, focus | ||
228 | * is on doing it fast). | ||
229 | */ | ||
230 | GNUNET_DATASTORE_Selector iter_all_now; | ||
231 | |||
232 | /** | ||
233 | * Delete the database. The next operation is | ||
234 | * guaranteed to be unloading of the module. | ||
235 | */ | ||
236 | GNUNET_DATASTORE_Drop drop; | ||
237 | |||
238 | }; | ||
239 | |||
240 | |||
241 | #endif | ||