client_manager: add API for async operations
[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., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, 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_set) (void *cls,
244                        const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
245                        const char *name, const void *value, size_t value_size);
246
247
248   /**
249    * End modifying current state.
250    *
251    * @see GNUNET_PSYCSTORE_state_modify()
252    *
253    * @return #GNUNET_OK on success, else #GNUNET_SYSERR
254    */
255   int
256   (*state_modify_end) (void *cls,
257                        const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
258                        uint64_t message_id);
259
260
261   /**
262    * Begin synchronizing state.
263    *
264    * @see GNUNET_PSYCSTORE_state_sync()
265    *
266    * @return #GNUNET_OK on success, else #GNUNET_SYSERR
267    */
268   int
269   (*state_sync_begin) (void *cls,
270                          const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key);
271
272   /**
273    * Set the value of a state variable while synchronizing state.
274    *
275    * The state synchronization process is started with state_sync_begin(),
276    * which is followed by one or more calls to this function,
277    * and finished with state_sync_end().
278    *
279    * @see GNUNET_PSYCSTORE_state_sync()
280    *
281    * @return #GNUNET_OK on success, else #GNUNET_SYSERR
282    */
283   int
284   (*state_sync_set) (void *cls,
285                      const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
286                      const char *name, const void *value, size_t value_size);
287
288
289   /**
290    * End synchronizing state.
291    *
292    * @see GNUNET_PSYCSTORE_state_sync()
293    *
294    * @return #GNUNET_OK on success, else #GNUNET_SYSERR
295    */
296   int
297   (*state_sync_end) (void *cls,
298                      const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
299                      uint64_t message_id);
300
301
302   /**
303    * Reset the state of a channel.
304    *
305    * Delete all state variables stored for the given channel.
306    *
307    * @see GNUNET_PSYCSTORE_state_reset()
308    *
309    * @return #GNUNET_OK on success, else #GNUNET_SYSERR
310    */
311   int
312   (*state_reset) (void *cls,
313                   const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key);
314
315   /**
316    * Update signed state values from the current ones.
317    *
318    * Sets value_signed = value_current for each variable for the given channel.
319    */
320   int
321   (*state_update_signed) (void *cls,
322                           const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key);
323
324
325   /**
326    * Retrieve a state variable by name (exact match).
327    *
328    * @return #GNUNET_OK on success, else #GNUNET_SYSERR
329    */
330   int
331   (*state_get) (void *cls,
332                 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
333                 const char *name,
334                 GNUNET_PSYCSTORE_StateCallback cb,
335                 void *cb_cls);
336
337   /**
338    * Retrieve all state variables for a channel with the given prefix.
339    *
340    * @see GNUNET_PSYCSTORE_state_get_prefix()
341    *
342    * @return #GNUNET_OK on success, else #GNUNET_SYSERR
343    */
344   int
345   (*state_get_prefix) (void *cls,
346                        const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
347                        const char *name,
348                        GNUNET_PSYCSTORE_StateCallback cb,
349                        void *cb_cls);
350
351
352   /**
353    * Retrieve all signed state variables for a channel.
354    *
355    * @return #GNUNET_OK on success, else #GNUNET_SYSERR
356    */
357   int
358   (*state_get_signed) (void *cls,
359                        const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
360                        GNUNET_PSYCSTORE_StateCallback cb,
361                        void *cb_cls);
362
363 };
364
365
366 #if 0                           /* keep Emacsens' auto-indent happy */
367 {
368 #endif
369 #ifdef __cplusplus
370 }
371 #endif
372
373 /* end of gnunet_psycstore_plugin.h */
374 #endif