-handle failure to load certs more nicely
[oweals/gnunet.git] / src / include / gnunet_psycstore_service.h
1 /*
2      This file is part of GNUnet.
3      (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_service.h
23  * @brief PSYCstore service; implements persistent storage for the PSYC service
24  * @author Gabor X Toth
25  * @author Christian Grothoff
26  */
27 #ifndef GNUNET_PSYCSTORE_SERVICE_H
28 #define GNUNET_PSYCSTORE_SERVICE_H
29
30 #ifdef __cplusplus
31 extern "C"
32 {
33 #if 0                           /* keep Emacsens' auto-indent happy */
34 }
35 #endif
36 #endif
37
38 #include "gnunet_util_lib.h"
39 #include "gnunet_env_lib.h"
40 #include "gnunet_multicast_service.h"
41 #include "gnunet_psyc_service.h"
42
43 /** 
44  * Version number of GNUnet PSYCstore API.
45  */
46 #define GNUNET_PSYCSTORE_VERSION 0x00000000
47
48 /**
49  * Flags for stored messages.
50  */
51 enum GNUNET_PSYCSTORE_MessageFlags
52 {
53   /**
54    * The message contains state modifiers.
55    */
56   GNUNET_PSYCSTORE_MESSAGE_STATE = 1 << 0,
57
58   /**
59    * The state modifiers have been applied to the state store.
60    */
61   GNUNET_PSYCSTORE_MESSAGE_STATE_APPLIED = 1 << 1,
62
63   /**
64    * The message contains a state hash.
65    */
66   GNUNET_PSYCSTORE_MESSAGE_STATE_HASH = 1 << 2
67 };
68
69
70 /** 
71  * Handle for a PSYCstore
72  */
73 struct GNUNET_PSYCSTORE_Handle;
74
75
76 /** 
77  * Connect to the PSYCstore service.
78  *
79  * @param cfg Configuration to use.
80  *
81  * @return Handle for the connecton.
82  */
83 struct GNUNET_PSYCSTORE_Handle *
84 GNUNET_PSYCSTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
85
86
87 /** 
88  * Disconnect from the PSYCstore service.
89  *
90  * @param h Handle for the connection.
91  */
92 void
93 GNUNET_PSYCSTORE_disconnect (struct GNUNET_PSYCSTORE_Handle *h);
94
95
96 /** 
97  * Handle for an operation on the PSYCSTORE (useful to cancel the operation).
98  */
99 struct GNUNET_PSYCSTORE_OperationHandle;
100
101
102 /** 
103  * Function called with the result of an asynchronous operation.
104  * 
105  * @param result #GNUNET_SYSERR on error,
106  *        #GNUNET_YES on success or if the peer was a member,
107  *        #GNUNET_NO if the peer was not a member
108  */
109 typedef void
110 (*GNUNET_PSYCSTORE_ResultCallback) (void *cls,
111                                     int64_t result,
112                                     const char *err_msg);
113
114
115 /** 
116  * Store join/leave events for a PSYC channel in order to be able to answer
117  * membership test queries later.
118  *
119  * @param h Handle for the PSYCstore.
120  * @param channel_key The channel where the event happened.
121  * @param slave_key Public key of joining/leaving slave.
122  * @param did_join #GNUNET_YES on join, #GNUNET_NO on part.
123  * @param announced_at ID of the message that announced the membership change.
124  * @param effective_since Message ID this membership change is in effect since.
125  *        For joins it is <= announced_at, for parts it is always 0.
126  * @param group_generation In case of a part, the last group generation the
127  *        slave has access to.  It has relevance when a larger message have
128  *        fragments with different group generations.
129  * @param rcb Callback to call with the result of the storage operation.
130  * @param rcb_cls Closure for the callback.
131  *
132  * @return Operation handle that can be used to cancel the operation.
133  */
134 struct GNUNET_PSYCSTORE_OperationHandle *
135 GNUNET_PSYCSTORE_membership_store (struct GNUNET_PSYCSTORE_Handle *h,
136                                    const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key,
137                                    const struct GNUNET_CRYPTO_EccPublicSignKey *slave_key,
138                                    int did_join,
139                                    uint64_t announced_at,
140                                    uint64_t effective_since,
141                                    uint64_t group_generation,
142                                    GNUNET_PSYCSTORE_ResultCallback rcb,
143                                    void *rcb_cls);
144
145
146 /** 
147  * Test if a member was admitted to the channel at the given message ID.
148  *
149  * This is useful when relaying and replaying messages to check if a particular
150  * slave has access to the message fragment with a given group generation.  It
151  * is also used when handling join requests to determine whether the slave is
152  * currently admitted to the channel.
153  *
154  * @param h Handle for the PSYCstore.
155  * @param channel_key The channel we are interested in.
156  * @param slave_key Public key of slave whose membership to check.
157  * @param message_id Message ID for which to do the membership test.
158  * @param group_generation Group generation of the fragment of the message to
159  *        test.  It has relevance if the message consists of multiple fragments
160  *        with different group generations.
161  * @param rcb Callback to call with the test result.
162  * @param rcb_cls Closure for the callback.
163  *
164  * @return Operation handle that can be used to cancel the operation.
165  */
166 struct GNUNET_PSYCSTORE_OperationHandle *
167 GNUNET_PSYCSTORE_membership_test (struct GNUNET_PSYCSTORE_Handle *h,
168                                   const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key,
169                                   const struct GNUNET_CRYPTO_EccPublicSignKey *slave_key,
170                                   uint64_t message_id,
171                                   uint64_t group_generation,
172                                   GNUNET_PSYCSTORE_ResultCallback rcb,
173                                   void *rcb_cls);
174
175
176 /** 
177  * Store a message fragment sent to a channel.
178  *
179  * @param h Handle for the PSYCstore.
180  * @param channel_key The channel the message belongs to.
181  * @param message Message to store.
182  * @param psycstore_flags Flags indicating whether the PSYC message contains
183  *        state modifiers.
184  * @param rcb Callback to call with the result of the operation.
185  * @param rcb_cls Closure for the callback.
186  * 
187  * @return Handle that can be used to cancel the operation.
188  */
189 struct GNUNET_PSYCSTORE_OperationHandle *
190 GNUNET_PSYCSTORE_fragment_store (struct GNUNET_PSYCSTORE_Handle *h,
191                                  const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key,
192                                  const struct GNUNET_MULTICAST_MessageHeader *message,
193                                  uint32_t psycstore_flags,
194                                  GNUNET_PSYCSTORE_ResultCallback rcb,
195                                  void *rcb_cls);
196
197
198 /** 
199  * Function called with one message fragment, as the result of a
200  * GNUNET_PSYCSTORE_fragment_get() or GNUNET_PSYCSTORE_message_get() call.
201  *
202  * @param cls Closure.
203  * @param message The retrieved message fragment.  A NULL value indicates that
204  *        there are no more results to be returned.
205  * @param psycstore_flags Flags stored with the message.
206  *
207  * @return #GNUNET_NO to stop calling this callback with further fragments,
208  *         #GNUNET_YES to continue.
209  */
210 typedef int
211 (*GNUNET_PSYCSTORE_FragmentCallback) (void *cls,
212                                       struct GNUNET_MULTICAST_MessageHeader *message,
213                                       enum GNUNET_PSYCSTORE_MessageFlags psycstore_flags);
214
215
216 /** 
217  * Retrieve a message fragment by fragment ID.
218  *
219  * @param h Handle for the PSYCstore.
220  * @param channel_key The channel we are interested in.
221  * @param fragment_id Fragment ID to check.  Use 0 to get the latest message fragment.
222  * @param fcb Callback to call with the retrieved fragment.
223  * @param rcb Callback to call with the result of the operation.
224  * @param cls Closure for the callbacks.
225  * 
226  * @return Handle that can be used to cancel the operation.
227  */
228 struct GNUNET_PSYCSTORE_OperationHandle *
229 GNUNET_PSYCSTORE_fragment_get (struct GNUNET_PSYCSTORE_Handle *h,
230                                const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key,
231                                uint64_t fragment_id,
232                                GNUNET_PSYCSTORE_FragmentCallback fcb,
233                                GNUNET_PSYCSTORE_ResultCallback rcb,
234                                void *cls);
235
236
237 /** 
238  * Retrieve all fragments of a message.
239  *
240  * @param h Handle for the PSYCstore.
241  * @param channel_key The channel we are interested in.
242  * @param message_id Message ID to check.  Use 0 to get the latest message.
243  * @param fcb Callback to call with the retrieved fragments.
244  * @param rcb Callback to call with the result of the operation.
245  * @param cls Closure for the callbacks.
246  * 
247  * @return Handle that can be used to cancel the operation.
248  */
249 struct GNUNET_PSYCSTORE_OperationHandle *
250 GNUNET_PSYCSTORE_message_get (struct GNUNET_PSYCSTORE_Handle *h,
251                               const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key,
252                               uint64_t message_id,
253                               GNUNET_PSYCSTORE_FragmentCallback fcb,
254                               GNUNET_PSYCSTORE_ResultCallback rcb,
255                               void *cls);
256
257
258 /** 
259  * Retrieve a fragment of message specified by its message ID and fragment
260  * offset.
261  *
262  * @param h Handle for the PSYCstore.
263  * @param channel_key The channel we are interested in.
264  * @param message_id Message ID to check.  Use 0 to get the latest message.
265  * @param fragment_offset Offset of the fragment to retrieve.
266  * @param fcb Callback to call with the retrieved fragments.
267  * @param rcb Callback to call with the result of the operation.
268  * @param cls Closure for the callbacks.
269  * 
270  * @return Handle that can be used to cancel the operation.
271  */
272 struct GNUNET_PSYCSTORE_OperationHandle *
273 GNUNET_PSYCSTORE_message_get_fragment (struct GNUNET_PSYCSTORE_Handle *h,
274                                        const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key,
275                                        uint64_t message_id,
276                                        uint64_t fragment_offset,
277                                        GNUNET_PSYCSTORE_FragmentCallback fcb,
278                                        GNUNET_PSYCSTORE_ResultCallback rcb,
279                                        void *cls);
280
281
282 /** 
283  * Callback used to return the latest value of counters for the channel master.
284  *
285  * @see GNUNET_PSYCSTORE_counters_get_master()
286  *
287  * @param cls Closure.
288  * @param fragment_id Latest message fragment ID, used by multicast.
289  * @param message_id Latest message ID, used by PSYC.
290  * @param group_generation Latest group generation, used by PSYC.
291  */
292 typedef void
293 (*GNUNET_PSYCSTORE_MasterCountersCallback) (void *cls,
294                                             uint64_t fragment_id,
295                                             uint64_t message_id,
296                                             uint64_t group_generation);
297
298
299 /** 
300  * Callback used to return the latest value of counters for a channel slave.
301  *
302  * @see GNUNET_PSYCSTORE_counters_get_slave()
303  *
304  * @param cls Closure.
305  * @param max_state_msg_id Latest message ID containing state modifiers that was
306  *        applied to the state store.  Used for the state sync process.
307  */
308 typedef void
309 (*GNUNET_PSYCSTORE_SlaveCountersCallback) (void *cls,
310                                            uint64_t max_state_msg_id);
311
312
313 /** 
314  * Retrieve latest values of counters for a channel master.
315  *
316  * The current value of counters are needed when a channel master is restarted,
317  * so that it can continue incrementing the counters from their last value.
318  *
319  * @param h Handle for the PSYCstore.
320  * @param channel_key Public key that identifies the channel.
321  * @param mccb Callback to call with the result.
322  * @param mccb_cls Closure for the callback.
323  * 
324  * @return Handle that can be used to cancel the operation.
325  */
326 struct GNUNET_PSYCSTORE_OperationHandle *
327 GNUNET_PSYCSTORE_counters_get_master (struct GNUNET_PSYCSTORE_Handle *h,
328                                       struct GNUNET_CRYPTO_EccPublicSignKey *channel_key,
329                                       GNUNET_PSYCSTORE_MasterCountersCallback mccb,
330                                       void *mccb_cls);
331
332
333 /** 
334  * Retrieve latest values of counters for a channel slave.
335  *
336  * The current value of counters are needed when a channel slave rejoins
337  * and starts the state synchronization process.
338  *
339  * @param h Handle for the PSYCstore.
340  * @param channel_key Public key that identifies the channel.
341  * @param sccb Callback to call with the result.
342  * @param sccb_cls Closure for the callback.
343  * 
344  * @return Handle that can be used to cancel the operation.
345  */
346 struct GNUNET_PSYCSTORE_OperationHandle *
347 GNUNET_PSYCSTORE_counters_get_slave (struct GNUNET_PSYCSTORE_Handle *h,
348                                      struct GNUNET_CRYPTO_EccPublicSignKey *channel_key,
349                                      GNUNET_PSYCSTORE_SlaveCountersCallback sccb,
350                                      void *sccb_cls);
351
352
353 /** 
354  * Apply modifiers of a message to the current channel state.
355  *
356  * An error is returned if there are missing messages containing state
357  * operations before the current one.
358  *
359  * @param h Handle for the PSYCstore.
360  * @param channel_key The channel we are interested in.
361  * @param message_id ID of the message that contains the @a modifiers.
362  * @param state_delta Value of the @e state_delta PSYC header variable of the message.
363  * @param modifier_count Number of elements in the @a modifiers array.
364  * @param modifiers List of modifiers to apply.
365  * @param rcb Callback to call with the result of the operation.
366  * @param rcb_cls Closure for the callback.
367  * 
368  * @return Handle that can be used to cancel the operation.
369  */
370 struct GNUNET_PSYCSTORE_OperationHandle *
371 GNUNET_PSYCSTORE_state_modify (struct GNUNET_PSYCSTORE_Handle *h,
372                                const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key,
373                                uint64_t message_id,
374                                uint64_t state_delta,
375                                size_t modifier_count,
376                                const struct GNUNET_ENV_Modifier *modifiers,
377                                GNUNET_PSYCSTORE_ResultCallback rcb,
378                                void *rcb_cls);
379
380
381 /** 
382  * Store synchronized state.
383  *
384  * @param h Handle for the PSYCstore.
385  * @param channel_key The channel we are interested in.
386  * @param message_id ID of the message that contains the state_hash PSYC header variable.
387  * @param modifier_count Number of elements in the @a modifiers array.
388  * @param modifiers Full state to store.
389  * @param rcb Callback to call with the result of the operation.
390  * @param rcb_cls Closure for the callback.
391  * 
392  * @return Handle that can be used to cancel the operation.
393  */
394 struct GNUNET_PSYCSTORE_OperationHandle *
395 GNUNET_PSYCSTORE_state_sync (struct GNUNET_PSYCSTORE_Handle *h,
396                              const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key,
397                              uint64_t message_id,
398                              size_t modifier_count,
399                              const struct GNUNET_ENV_Modifier *modifiers,
400                              GNUNET_PSYCSTORE_ResultCallback rcb,
401                              void *rcb_cls);
402
403
404
405 /** 
406  * Reset the state of a channel.
407  *
408  * Delete all state variables stored for the given channel.
409  *
410  * @param h Handle for the PSYCstore.
411  * @param channel_key The channel we are interested in.
412  * @param rcb Callback to call with the result of the operation.
413  * @param rcb_cls Closure for the callback.
414  * 
415  * @return Handle that can be used to cancel the operation.
416  */
417 struct GNUNET_PSYCSTORE_OperationHandle *
418 GNUNET_PSYCSTORE_state_reset (struct GNUNET_PSYCSTORE_Handle *h,
419                               const struct GNUNET_CRYPTO_EccPublicSignKey
420                               *channel_key,
421                               GNUNET_PSYCSTORE_ResultCallback rcb,
422                               void *rcb_cls);
423
424
425 /** 
426  * Update signed values of state variables in the state store.
427  *
428  * @param h Handle for the PSYCstore.
429  * @param channel_key The channel we are interested in.
430  * @param message_id Message ID that contained the state @a hash.
431  * @param hash Hash of the serialized full state.
432  * @param rcb Callback to call with the result of the operation.
433  * @param rcb_cls Closure for the callback.
434  *
435  */
436 struct GNUNET_PSYCSTORE_OperationHandle *
437 GNUNET_PSYCSTORE_state_hash_update (struct GNUNET_PSYCSTORE_Handle *h,
438                                     const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key,
439                                     uint64_t message_id,
440                                     const struct GNUNET_HashCode *hash,
441                                     GNUNET_PSYCSTORE_ResultCallback rcb,
442                                     void *rcb_cls);
443
444
445 /** 
446  * Function called with the value of a state variable.
447  *
448  * @param cls Closure.
449  * @param name Name of the state variable.  A NULL value indicates that there are no more
450  *        state variables to be returned.
451  * @param value Value of the state variable.
452  * @param value_size Number of bytes in @a value.
453  *
454  * @return #GNUNET_NO to stop calling this callback with further variables,
455  *         #GNUNET_YES to continue.
456  */;
457 typedef int
458 (*GNUNET_PSYCSTORE_StateCallback) (void *cls, const char *name,
459                                    const void *value, size_t value_size);
460
461
462 /** 
463  * Retrieve the best matching state variable.
464  *
465  * @param h Handle for the PSYCstore.
466  * @param channel_key The channel we are interested in.
467  * @param name Name of variable to match, the returned variable might be less specific.
468  * @param scb Callback to return the matching state variable.
469  * @param rcb Callback to call with the result of the operation.
470  * @param cls Closure for the callbacks.
471  * 
472  * @return Handle that can be used to cancel the operation.
473  */
474 struct GNUNET_PSYCSTORE_OperationHandle *
475 GNUNET_PSYCSTORE_state_get (struct GNUNET_PSYCSTORE_Handle *h,
476                             const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key,
477                             const char *name,
478                             GNUNET_PSYCSTORE_StateCallback scb,
479                             GNUNET_PSYCSTORE_ResultCallback rcb,
480                             void *cls);
481
482
483 /** 
484  * Retrieve all state variables for a channel with the given prefix.
485  *
486  * @param h Handle for the PSYCstore.
487  * @param channel_key The channel we are interested in.
488  * @param name_prefix Prefix of state variable names to match.
489  * @param scb Callback to return matching state variables.
490  * @param rcb Callback to call with the result of the operation.
491  * @param cls Closure for the callbacks.
492  * 
493  * @return Handle that can be used to cancel the operation.
494  */
495 struct GNUNET_PSYCSTORE_OperationHandle *
496 GNUNET_PSYCSTORE_state_get_prefix (struct GNUNET_PSYCSTORE_Handle *h,
497                                    const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key,
498                                    const char *name_prefix,
499                                    GNUNET_PSYCSTORE_StateCallback scb,
500                                    GNUNET_PSYCSTORE_ResultCallback rcb,
501                                    void *cls);
502
503
504 /** 
505  * Cancel an operation.
506  *
507  * @param op Handle for the operation to cancel.
508  */
509 void
510 GNUNET_PSYCSTORE_operation_cancel (struct GNUNET_PSYCSTORE_OperationHandle *op);
511
512
513
514
515 #if 0                           /* keep Emacsens' auto-indent happy */
516 {
517 #endif
518 #ifdef __cplusplus
519 }
520 #endif
521
522 /* ifndef GNUNET_PSYCSTORE_SERVICE_H */
523 #endif
524 /* end of gnunet_psycstore_service.h */