2 This file is part of GNUnet.
3 Copyright (C) 2013 Christian Grothoff (and other contributing authors)
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.
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.
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.
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
27 #ifndef GNUNET_PSYCSTORE_SERVICE_H
28 #define GNUNET_PSYCSTORE_SERVICE_H
33 #if 0 /* keep Emacsens' auto-indent happy */
38 #include "gnunet_util_lib.h"
39 #include "gnunet_env_lib.h"
40 #include "gnunet_multicast_service.h"
41 #include "gnunet_psyc_service.h"
44 * Version number of GNUnet PSYCstore API.
46 #define GNUNET_PSYCSTORE_VERSION 0x00000000
49 * Membership test failed.
51 #define GNUNET_PSYCSTORE_MEMBERSHIP_TEST_FAILED -2
54 * Flags for stored messages.
56 enum GNUNET_PSYCSTORE_MessageFlags
59 * The message contains state modifiers.
61 GNUNET_PSYCSTORE_MESSAGE_STATE = 1 << 0,
64 * The state modifiers have been applied to the state store.
66 GNUNET_PSYCSTORE_MESSAGE_STATE_APPLIED = 1 << 1,
69 * The message contains a state hash.
71 GNUNET_PSYCSTORE_MESSAGE_STATE_HASH = 1 << 2
76 * Handle for a PSYCstore
78 struct GNUNET_PSYCSTORE_Handle;
82 * Connect to the PSYCstore service.
84 * @param cfg Configuration to use.
86 * @return Handle for the connecton.
88 struct GNUNET_PSYCSTORE_Handle *
89 GNUNET_PSYCSTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
93 * Disconnect from the PSYCstore service.
95 * @param h Handle for the connection.
98 GNUNET_PSYCSTORE_disconnect (struct GNUNET_PSYCSTORE_Handle *h);
102 * Handle for an operation on the PSYCSTORE (useful to cancel the operation).
104 struct GNUNET_PSYCSTORE_OperationHandle;
108 * Function called with the result of an asynchronous operation.
113 * Result of the operation.
115 * Error message, or NULL if there's no error.
116 * @param err_msg_size
120 (*GNUNET_PSYCSTORE_ResultCallback) (void *cls,
123 uint16_t err_msg_size);
127 * Store join/leave events for a PSYC channel in order to be able to answer
128 * membership test queries later.
131 * Handle for the PSYCstore.
133 * The channel where the event happened.
135 * Public key of joining/leaving slave.
137 * #GNUNET_YES on join, #GNUNET_NO on part.
138 * @param announced_at
139 * ID of the message that announced the membership change.
140 * @param effective_since
141 * Message ID this membership change is in effect since.
142 * For joins it is <= announced_at, for parts it is always 0.
143 * @param group_generation
144 * In case of a part, the last group generation the slave has access to.
145 * It has relevance when a larger message have fragments with different
148 * Callback to call with the result of the storage operation.
150 * Closure for the callback.
152 * @return Operation handle that can be used to cancel the operation.
154 struct GNUNET_PSYCSTORE_OperationHandle *
155 GNUNET_PSYCSTORE_membership_store (struct GNUNET_PSYCSTORE_Handle *h,
156 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
157 const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
159 uint64_t announced_at,
160 uint64_t effective_since,
161 uint64_t group_generation,
162 GNUNET_PSYCSTORE_ResultCallback rcb,
167 * Test if a member was admitted to the channel at the given message ID.
169 * This is useful when relaying and replaying messages to check if a particular
170 * slave has access to the message fragment with a given group generation. It
171 * is also used when handling join requests to determine whether the slave is
172 * currently admitted to the channel.
175 * Handle for the PSYCstore.
177 * The channel we are interested in.
179 * Public key of slave whose membership to check.
181 * Message ID for which to do the membership test.
182 * @param group_generation
183 * Group generation of the fragment of the message to test.
184 * It has relevance if the message consists of multiple fragments with
185 * different group generations.
187 * Callback to call with the test result.
189 * Closure for the callback.
191 * @return Operation handle that can be used to cancel the operation.
193 struct GNUNET_PSYCSTORE_OperationHandle *
194 GNUNET_PSYCSTORE_membership_test (struct GNUNET_PSYCSTORE_Handle *h,
195 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
196 const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
198 uint64_t group_generation,
199 GNUNET_PSYCSTORE_ResultCallback rcb,
204 * Store a message fragment sent to a channel.
206 * @param h Handle for the PSYCstore.
207 * @param channel_key The channel the message belongs to.
208 * @param msg Message to store.
209 * @param psycstore_flags Flags indicating whether the PSYC message contains
211 * @param rcb Callback to call with the result of the operation.
212 * @param rcb_cls Closure for the callback.
214 * @return Handle that can be used to cancel the operation.
216 struct GNUNET_PSYCSTORE_OperationHandle *
217 GNUNET_PSYCSTORE_fragment_store (struct GNUNET_PSYCSTORE_Handle *h,
218 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
219 const struct GNUNET_MULTICAST_MessageHeader *msg,
220 enum GNUNET_PSYCSTORE_MessageFlags psycstore_flags,
221 GNUNET_PSYCSTORE_ResultCallback rcb,
226 * Function called with one message fragment, as the result of a
227 * GNUNET_PSYCSTORE_fragment_get() or GNUNET_PSYCSTORE_message_get() call.
229 * @param cls Closure.
230 * @param message The retrieved message fragment. A NULL value indicates that
231 * there are no more results to be returned.
232 * @param psycstore_flags Flags stored with the message.
234 * @return #GNUNET_NO to stop calling this callback with further fragments,
235 * #GNUNET_YES to continue.
238 (*GNUNET_PSYCSTORE_FragmentCallback) (void *cls,
239 struct GNUNET_MULTICAST_MessageHeader *message,
240 enum GNUNET_PSYCSTORE_MessageFlags psycstore_flags);
244 * Retrieve message fragments by fragment ID range.
247 * Handle for the PSYCstore.
249 * The channel we are interested in.
251 * The slave requesting the fragment. If not NULL, a membership test is
252 * performed first and the fragment is only returned if the slave has
254 * @param first_fragment_id
255 * First fragment ID to retrieve.
256 * Use 0 to get the latest message fragment.
257 * @param last_fragment_id
258 * Last consecutive fragment ID to retrieve.
259 * Use 0 to get the latest message fragment.
261 * Callback to call with the retrieved fragments.
263 * Callback to call with the result of the operation.
265 * Closure for the callbacks.
267 * @return Handle that can be used to cancel the operation.
269 struct GNUNET_PSYCSTORE_OperationHandle *
270 GNUNET_PSYCSTORE_fragment_get (struct GNUNET_PSYCSTORE_Handle *h,
271 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
272 const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
273 uint64_t first_message_id,
274 uint64_t last_message_id,
275 GNUNET_PSYCSTORE_FragmentCallback fragment_cb,
276 GNUNET_PSYCSTORE_ResultCallback result_cb,
281 * Retrieve latest message fragments.
284 * Handle for the PSYCstore.
286 * The channel we are interested in.
288 * The slave requesting the fragment. If not NULL, a membership test is
289 * performed first and the fragment is only returned if the slave has
291 * @param first_fragment_id
292 * First fragment ID to retrieve.
293 * Use 0 to get the latest message fragment.
294 * @param last_fragment_id
295 * Last consecutive fragment ID to retrieve.
296 * Use 0 to get the latest message fragment.
297 * @param fragment_limit
298 * Maximum number of fragments to retrieve.
300 * Callback to call with the retrieved fragments.
302 * Callback to call with the result of the operation.
304 * Closure for the callbacks.
306 * @return Handle that can be used to cancel the operation.
308 struct GNUNET_PSYCSTORE_OperationHandle *
309 GNUNET_PSYCSTORE_fragment_get_latest (struct GNUNET_PSYCSTORE_Handle *h,
310 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
311 const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
312 uint64_t fragment_limit,
313 GNUNET_PSYCSTORE_FragmentCallback fragment_cb,
314 GNUNET_PSYCSTORE_ResultCallback rcb,
319 * Retrieve all fragments of messages in a message ID range.
322 * Handle for the PSYCstore.
324 * The channel we are interested in.
326 * The slave requesting the message.
327 * If not NULL, a membership test is performed first
328 * and the message is only returned if the slave has access to it.
329 * @param first_message_id
330 * First message ID to retrieve.
331 * @param last_message_id
332 * Last consecutive message ID to retrieve.
333 * @param method_prefix
334 * Retrieve only messages with a matching method prefix.
336 * Callback to call with the retrieved fragments.
338 * Callback to call with the result of the operation.
340 * Closure for the callbacks.
342 * @return Handle that can be used to cancel the operation.
344 struct GNUNET_PSYCSTORE_OperationHandle *
345 GNUNET_PSYCSTORE_message_get (struct GNUNET_PSYCSTORE_Handle *h,
346 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
347 const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
348 uint64_t first_message_id,
349 uint64_t last_message_id,
350 const char *method_prefix,
351 GNUNET_PSYCSTORE_FragmentCallback fragment_cb,
352 GNUNET_PSYCSTORE_ResultCallback result_cb,
357 * Retrieve all fragments of the latest messages.
360 * Handle for the PSYCstore.
362 * The channel we are interested in.
364 * The slave requesting the message.
365 * If not NULL, a membership test is performed first
366 * and the message is only returned if the slave has access to it.
367 * @param message_limit
368 * Maximum number of messages to retrieve.
369 * @param method_prefix
370 * Retrieve only messages with a matching method prefix.
372 * Callback to call with the retrieved fragments.
374 * Callback to call with the result of the operation.
376 * Closure for the callbacks.
378 * @return Handle that can be used to cancel the operation.
380 struct GNUNET_PSYCSTORE_OperationHandle *
381 GNUNET_PSYCSTORE_message_get_latest (struct GNUNET_PSYCSTORE_Handle *h,
382 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
383 const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
384 uint64_t message_limit,
385 const char *method_prefix,
386 GNUNET_PSYCSTORE_FragmentCallback fragment_cb,
387 GNUNET_PSYCSTORE_ResultCallback rcb,
392 * Retrieve a fragment of message specified by its message ID and fragment
396 * Handle for the PSYCstore.
398 * The channel we are interested in.
400 * The slave requesting the message fragment. If not NULL, a membership
401 * test is performed first and the message fragment is only returned
402 * if the slave has access to it.
404 * Message ID to retrieve. Use 0 to get the latest message.
405 * @param fragment_offset
406 * Offset of the fragment to retrieve.
408 * Callback to call with the retrieved fragments.
410 * Callback to call with the result of the operation.
412 * Closure for the callbacks.
414 * @return Handle that can be used to cancel the operation.
416 struct GNUNET_PSYCSTORE_OperationHandle *
417 GNUNET_PSYCSTORE_message_get_fragment (struct GNUNET_PSYCSTORE_Handle *h,
418 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
419 const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
421 uint64_t fragment_offset,
422 GNUNET_PSYCSTORE_FragmentCallback fragment_cb,
423 GNUNET_PSYCSTORE_ResultCallback result_cb,
428 * Callback used to return the latest value of counters for the channel master.
430 * @see GNUNET_PSYCSTORE_counters_get()
432 * @param cls Closure.
434 * Status code for the operation:
435 * #GNUNET_OK: success, counter values are returned.
436 * #GNUNET_NO: no message has been sent to the channel yet.
437 * #GNUNET_SYSERR: an error occurred.
438 * @param max_fragment_id
439 * Latest message fragment ID, used by multicast.
440 * @param max_message_id
441 * Latest message ID, used by PSYC.
442 * @param max_group_generation
443 * Latest group generation, used by PSYC.
444 * @param max_state_message_id
445 * Latest message ID containing state modifiers that
446 * was applied to the state store. Used for the state sync process.
449 (*GNUNET_PSYCSTORE_CountersCallback) (void *cls,
451 uint64_t max_fragment_id,
452 uint64_t max_message_id,
453 uint64_t max_group_generation,
454 uint64_t max_state_message_id);
458 * Retrieve latest values of counters for a channel.
460 * The current value of counters are needed
461 * - when a channel master is restarted, so that it can continue incrementing
462 * the counters from their last value.
463 * - when a channel slave rejoins and starts the state synchronization process.
466 * Handle for the PSYCstore.
468 * Public key that identifies the channel.
470 * Callback to call with the result.
472 * Closure for the @a ccb callback.
474 * @return Handle that can be used to cancel the operation.
476 struct GNUNET_PSYCSTORE_OperationHandle *
477 GNUNET_PSYCSTORE_counters_get (struct GNUNET_PSYCSTORE_Handle *h,
478 struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
479 GNUNET_PSYCSTORE_CountersCallback ccb,
484 * Apply modifiers of a message to the current channel state.
486 * An error is returned if there are missing messages containing state
487 * operations before the current one.
490 * Handle for the PSYCstore.
492 * The channel we are interested in.
494 * ID of the message that contains the @a modifiers.
496 * Value of the @e state_delta PSYC header variable of the message.
497 * @param modifier_count
498 * Number of elements in the @a modifiers array.
500 * List of modifiers to apply.
502 * Callback to call with the result of the operation.
504 * Closure for the @a rcb callback.
506 * @return Handle that can be used to cancel the operation.
508 struct GNUNET_PSYCSTORE_OperationHandle *
509 GNUNET_PSYCSTORE_state_modify (struct GNUNET_PSYCSTORE_Handle *h,
510 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
512 uint64_t state_delta,
513 size_t modifier_count,
514 const struct GNUNET_ENV_Modifier *modifiers,
515 GNUNET_PSYCSTORE_ResultCallback rcb,
520 * Store synchronized state.
523 * Handle for the PSYCstore.
525 * The channel we are interested in.
527 * ID of the message that contains the state_hash PSYC header variable.
528 * @param modifier_count
529 * Number of elements in the @a modifiers array.
531 * Full state to store.
533 * Callback to call with the result of the operation.
535 * Closure for the callback.
537 * @return Handle that can be used to cancel the operation.
539 struct GNUNET_PSYCSTORE_OperationHandle *
540 GNUNET_PSYCSTORE_state_sync (struct GNUNET_PSYCSTORE_Handle *h,
541 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
543 size_t modifier_count,
544 const struct GNUNET_ENV_Modifier *modifiers,
545 GNUNET_PSYCSTORE_ResultCallback rcb,
551 * Reset the state of a channel.
553 * Delete all state variables stored for the given channel.
556 * Handle for the PSYCstore.
558 * The channel we are interested in.
560 * Callback to call with the result of the operation.
562 * Closure for the callback.
564 * @return Handle that can be used to cancel the operation.
566 struct GNUNET_PSYCSTORE_OperationHandle *
567 GNUNET_PSYCSTORE_state_reset (struct GNUNET_PSYCSTORE_Handle *h,
568 const struct GNUNET_CRYPTO_EddsaPublicKey
570 GNUNET_PSYCSTORE_ResultCallback rcb,
575 * Update signed values of state variables in the state store.
578 * Handle for the PSYCstore.
580 * The channel we are interested in.
582 * Message ID that contained the state @a hash.
584 * Hash of the serialized full state.
586 * Callback to call with the result of the operation.
588 * Closure for the callback.
591 struct GNUNET_PSYCSTORE_OperationHandle *
592 GNUNET_PSYCSTORE_state_hash_update (struct GNUNET_PSYCSTORE_Handle *h,
593 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
595 const struct GNUNET_HashCode *hash,
596 GNUNET_PSYCSTORE_ResultCallback rcb,
601 * Function called with the value of a state variable.
606 * Name of the state variable. A NULL value indicates that there are no more
607 * state variables to be returned.
609 * Value of the state variable.
611 * Number of bytes in @a value.
613 * @return #GNUNET_NO to stop calling this callback with further variables,
614 * #GNUNET_YES to continue.
617 (*GNUNET_PSYCSTORE_StateCallback) (void *cls, const char *name,
618 const void *value, size_t value_size);
622 * Retrieve the best matching state variable.
625 * Handle for the PSYCstore.
627 * The channel we are interested in.
629 * Name of variable to match, the returned variable might be less specific.
631 * Callback to return the matching state variable.
633 * Callback to call with the result of the operation.
635 * Closure for the callbacks.
637 * @return Handle that can be used to cancel the operation.
639 struct GNUNET_PSYCSTORE_OperationHandle *
640 GNUNET_PSYCSTORE_state_get (struct GNUNET_PSYCSTORE_Handle *h,
641 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
643 GNUNET_PSYCSTORE_StateCallback scb,
644 GNUNET_PSYCSTORE_ResultCallback rcb,
649 * Retrieve all state variables for a channel with the given prefix.
652 * Handle for the PSYCstore.
654 * The channel we are interested in.
656 * Prefix of state variable names to match.
658 * Callback to return matching state variables.
660 * Callback to call with the result of the operation.
662 * Closure for the callbacks.
664 * @return Handle that can be used to cancel the operation.
666 struct GNUNET_PSYCSTORE_OperationHandle *
667 GNUNET_PSYCSTORE_state_get_prefix (struct GNUNET_PSYCSTORE_Handle *h,
668 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
669 const char *name_prefix,
670 GNUNET_PSYCSTORE_StateCallback scb,
671 GNUNET_PSYCSTORE_ResultCallback rcb,
676 * Cancel an operation.
678 * @param op Handle for the operation to cancel.
681 GNUNET_PSYCSTORE_operation_cancel (struct GNUNET_PSYCSTORE_OperationHandle *op);
686 #if 0 /* keep Emacsens' auto-indent happy */
693 /* ifndef GNUNET_PSYCSTORE_SERVICE_H */
695 /* end of gnunet_psycstore_service.h */