-logging
[oweals/gnunet.git] / src / include / gnunet_psycstore_plugin.h
1 /*
2      This file is part of GNUnet
3      Copyright (C) 2013 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 3, 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., 51 Franklin Street, Fifth Floor,
18      Boston, MA 02110-1301, USA.
19 */
20
21 /**
22  * @file include/gnunet_psycstore_plugin.h
23  * @brief plugin API for the PSYCstore database backend
24  * @author Gabor X Toth
25  */
26 #ifndef GNUNET_PSYCSTORE_PLUGIN_H
27 #define GNUNET_PSYCSTORE_PLUGIN_H
28
29 #include "gnunet_util_lib.h"
30 #include "gnunet_psycstore_service.h"
31
32 #ifdef __cplusplus
33 extern "C"
34 {
35 #if 0                           /* keep Emacsens' auto-indent happy */
36 }
37 #endif
38 #endif
39
40
41 /**
42  * Struct returned by the initialization function of the plugin.
43  */
44 struct GNUNET_PSYCSTORE_PluginFunctions
45 {
46
47   /**
48    * Closure to pass to all plugin functions.
49    */
50   void *cls;
51
52   /**
53    * Store join/leave events for a PSYC channel in order to be able to answer
54    * membership test queries later.
55    *
56    * @see GNUNET_PSYCSTORE_membership_store()
57    *
58    * @return #GNUNET_OK on success, else #GNUNET_SYSERR
59    */
60   int
61   (*membership_store) (void *cls,
62                        const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
63                        const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
64                        int did_join,
65                        uint64_t announced_at,
66                        uint64_t effective_since,
67                        uint64_t group_generation);
68
69   /**
70    * Test if a member was admitted to the channel at the given message ID.
71    *
72    * @see GNUNET_PSYCSTORE_membership_test()
73    *
74    * @return #GNUNET_YES if the member was admitted, #GNUNET_NO if not,
75    *         #GNUNET_SYSERR if there was en error.
76    */
77   int
78   (*membership_test) (void *cls,
79                       const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
80                       const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
81                       uint64_t message_id);
82
83   /**
84    * Store a message fragment sent to a channel.
85    *
86    * @see GNUNET_PSYCSTORE_fragment_store()
87    *
88    * @return #GNUNET_OK on success, else #GNUNET_SYSERR
89    */
90   int
91   (*fragment_store) (void *cls,
92                      const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
93                      const struct GNUNET_MULTICAST_MessageHeader *message,
94                      uint32_t psycstore_flags);
95
96   /**
97    * Set additional flags for a given message.
98    *
99    * They are OR'd with any existing flags set.
100    *
101    * @param cls Closure.
102    * @param channel_key Public key of the channel.
103    * @param message_id ID of the message.
104    * @param psycstore_flags OR'd GNUNET_PSYCSTORE_MessageFlags.
105    *
106    * @return #GNUNET_OK on success, else #GNUNET_SYSERR
107    */
108   int
109   (*message_add_flags) (void *cls,
110                         const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
111                         uint64_t message_id,
112                         uint64_t psycstore_flags);
113
114   /**
115    * Retrieve a message fragment range by fragment ID.
116    *
117    * @see GNUNET_PSYCSTORE_fragment_get()
118    *
119    * @return #GNUNET_OK on success, else #GNUNET_SYSERR
120    */
121   int
122   (*fragment_get) (void *cls,
123                    const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
124                    uint64_t first_fragment_id,
125                    uint64_t last_fragment_id,
126                    uint64_t *returned_fragments,
127                    GNUNET_PSYCSTORE_FragmentCallback cb,
128                    void *cb_cls);
129
130   /**
131    * Retrieve latest message fragments.
132    *
133    * @see GNUNET_PSYCSTORE_fragment_get()
134    *
135    * @return #GNUNET_OK on success, else #GNUNET_SYSERR
136    */
137   int
138   (*fragment_get_latest) (void *cls,
139                           const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
140                           uint64_t fragment_limit,
141                           uint64_t *returned_fragments,
142                           GNUNET_PSYCSTORE_FragmentCallback cb,
143                           void *cb_cls);
144
145   /**
146    * Retrieve all fragments of a message ID range.
147    *
148    * @see GNUNET_PSYCSTORE_message_get()
149    *
150    * @return #GNUNET_OK on success, else #GNUNET_SYSERR
151    */
152   int
153   (*message_get) (void *cls,
154                   const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
155                   uint64_t first_fragment_id,
156                   uint64_t last_fragment_id,
157                   uint64_t *returned_fragments,
158                   GNUNET_PSYCSTORE_FragmentCallback cb,
159                   void *cb_cls);
160
161   /**
162    * Retrieve all fragments of the latest messages.
163    *
164    * @see GNUNET_PSYCSTORE_message_get()
165    *
166    * @return #GNUNET_OK on success, else #GNUNET_SYSERR
167    */
168   int
169   (*message_get_latest) (void *cls,
170                          const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
171                          uint64_t fragment_limit,
172                          uint64_t *returned_fragments,
173                          GNUNET_PSYCSTORE_FragmentCallback cb,
174                          void *cb_cls);
175
176   /**
177    * Retrieve a fragment of message specified by its message ID and fragment
178    * offset.
179    *
180    * @see GNUNET_PSYCSTORE_message_get_fragment()
181    *
182    * @return #GNUNET_OK on success, else #GNUNET_SYSERR
183    */
184   int
185   (*message_get_fragment) (void *cls,
186                            const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
187                            uint64_t message_id,
188                            uint64_t fragment_offset,
189                            GNUNET_PSYCSTORE_FragmentCallback cb,
190                            void *cb_cls);
191
192   /**
193    * Retrieve the max. values of message counters for a channel.
194    *
195    * @see GNUNET_PSYCSTORE_counters_get()
196    *
197    * @return #GNUNET_OK on success, else #GNUNET_SYSERR
198    */
199   int
200   (*counters_message_get) (void *cls,
201                            const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
202                            uint64_t *max_fragment_id,
203                            uint64_t *max_message_id,
204                            uint64_t *max_group_generation);
205
206   /**
207    * Retrieve the max. values of state counters for a channel.
208    *
209    * @see GNUNET_PSYCSTORE_counters_get()
210    *
211    * @return #GNUNET_OK on success, else #GNUNET_SYSERR
212    */
213   int
214   (*counters_state_get) (void *cls,
215                          const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
216                          uint64_t *max_state_message_id);
217
218
219   /**
220    * Begin modifying current state.
221    *
222    * @see GNUNET_PSYCSTORE_state_modify()
223    *
224    * @return #GNUNET_OK on success, else #GNUNET_SYSERR
225    */
226   int
227   (*state_modify_begin) (void *cls,
228                          const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
229                          uint64_t message_id, uint64_t state_delta);
230
231   /**
232    * Set the current value of a state variable.
233    *
234    * The state modification process is started with state_modify_begin(),
235    * which is followed by one or more calls to this function,
236    * and finished with state_modify_end().
237    *
238    * @see GNUNET_PSYCSTORE_state_modify()
239    *
240    * @return #GNUNET_OK on success, else #GNUNET_SYSERR
241    */
242   int
243   (*state_modify_op) (void *cls,
244                       const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
245                       enum GNUNET_ENV_Operator op,
246                       const char *name, const void *value, size_t value_size);
247
248
249   /**
250    * End modifying current state.
251    *
252    * @see GNUNET_PSYCSTORE_state_modify()
253    *
254    * @return #GNUNET_OK on success, else #GNUNET_SYSERR
255    */
256   int
257   (*state_modify_end) (void *cls,
258                        const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
259                        uint64_t message_id);
260
261
262   /**
263    * Begin synchronizing state.
264    *
265    * @see GNUNET_PSYCSTORE_state_sync()
266    *
267    * @return #GNUNET_OK on success, else #GNUNET_SYSERR
268    */
269   int
270   (*state_sync_begin) (void *cls,
271                          const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key);
272
273   /**
274    * Assign value of a state variable while synchronizing state.
275    *
276    * The state synchronization process is started with state_sync_begin(),
277    * which is followed by one or more calls to this function,
278    * and finished using state_sync_end().
279    *
280    * @see GNUNET_PSYCSTORE_state_sync()
281    *
282    * @return #GNUNET_OK on success, else #GNUNET_SYSERR
283    */
284   int
285   (*state_sync_assign) (void *cls,
286                         const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
287                         const char *name, const void *value, size_t value_size);
288
289
290   /**
291    * End synchronizing state.
292    *
293    * @see GNUNET_PSYCSTORE_state_sync()
294    *
295    * @return #GNUNET_OK on success, else #GNUNET_SYSERR
296    */
297   int
298   (*state_sync_end) (void *cls,
299                      const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
300                      uint64_t max_state_message_id,
301                      uint64_t state_hash_message_id);
302
303
304   /**
305    * Reset the state of a channel.
306    *
307    * Delete all state variables stored for the given channel.
308    *
309    * @see GNUNET_PSYCSTORE_state_reset()
310    *
311    * @return #GNUNET_OK on success, else #GNUNET_SYSERR
312    */
313   int
314   (*state_reset) (void *cls,
315                   const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key);
316
317   /**
318    * Update signed state values from the current ones.
319    *
320    * Sets value_signed = value_current for each variable for the given channel.
321    */
322   int
323   (*state_update_signed) (void *cls,
324                           const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key);
325
326
327   /**
328    * Retrieve a state variable by name (exact match).
329    *
330    * @return #GNUNET_OK on success, else #GNUNET_SYSERR
331    */
332   int
333   (*state_get) (void *cls,
334                 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
335                 const char *name,
336                 GNUNET_PSYCSTORE_StateCallback cb,
337                 void *cb_cls);
338
339   /**
340    * Retrieve all state variables for a channel with the given prefix.
341    *
342    * @see GNUNET_PSYCSTORE_state_get_prefix()
343    *
344    * @return #GNUNET_OK on success, else #GNUNET_SYSERR
345    */
346   int
347   (*state_get_prefix) (void *cls,
348                        const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
349                        const char *name,
350                        GNUNET_PSYCSTORE_StateCallback cb,
351                        void *cb_cls);
352
353
354   /**
355    * Retrieve all signed state variables for a channel.
356    *
357    * @return #GNUNET_OK on success, else #GNUNET_SYSERR
358    */
359   int
360   (*state_get_signed) (void *cls,
361                        const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
362                        GNUNET_PSYCSTORE_StateCallback cb,
363                        void *cb_cls);
364
365 };
366
367
368 #if 0                           /* keep Emacsens' auto-indent happy */
369 {
370 #endif
371 #ifdef __cplusplus
372 }
373 #endif
374
375 /* end of gnunet_psycstore_plugin.h */
376 #endif