2 This file is part of GNUnet.
3 Copyright (C) 2013 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
17 * @author Gabor X Toth
18 * @author Christian Grothoff
21 * PSYCstore service; implements persistent storage for the PSYC service
23 * @defgroup psycstore PSYC Store service
24 * Persistent storage for the PSYC service.
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_psyc_util_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 result_cb,
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 result_cb,
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 result_cb Callback to call with the result of the operation.
212 * @param 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 result_cb,
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 result_cb,
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 fragment_limit
334 * Maximum number of fragments to retrieve.
335 * @param method_prefix
336 * Retrieve only messages with a matching method prefix.
338 * Callback to call with the retrieved fragments.
340 * Callback to call with the result of the operation.
342 * Closure for the callbacks.
344 * @return Handle that can be used to cancel the operation.
346 struct GNUNET_PSYCSTORE_OperationHandle *
347 GNUNET_PSYCSTORE_message_get (struct GNUNET_PSYCSTORE_Handle *h,
348 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
349 const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
350 uint64_t first_message_id,
351 uint64_t last_message_id,
352 uint64_t fragment_limit,
353 const char *method_prefix,
354 GNUNET_PSYCSTORE_FragmentCallback fragment_cb,
355 GNUNET_PSYCSTORE_ResultCallback result_cb,
360 * Retrieve all fragments of the latest messages.
363 * Handle for the PSYCstore.
365 * The channel we are interested in.
367 * The slave requesting the message.
368 * If not NULL, a membership test is performed first
369 * and the message is only returned if the slave has access to it.
370 * @param message_limit
371 * Maximum number of messages to retrieve.
372 * @param method_prefix
373 * Retrieve only messages with a matching method prefix.
375 * Callback to call with the retrieved fragments.
377 * Callback to call with the result of the operation.
379 * Closure for the callbacks.
381 * @return Handle that can be used to cancel the operation.
383 struct GNUNET_PSYCSTORE_OperationHandle *
384 GNUNET_PSYCSTORE_message_get_latest (struct GNUNET_PSYCSTORE_Handle *h,
385 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
386 const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
387 uint64_t message_limit,
388 const char *method_prefix,
389 GNUNET_PSYCSTORE_FragmentCallback fragment_cb,
390 GNUNET_PSYCSTORE_ResultCallback result_cb,
395 * Retrieve a fragment of message specified by its message ID and fragment
399 * Handle for the PSYCstore.
401 * The channel we are interested in.
403 * The slave requesting the message fragment. If not NULL, a membership
404 * test is performed first and the message fragment is only returned
405 * if the slave has access to it.
407 * Message ID to retrieve. Use 0 to get the latest message.
408 * @param fragment_offset
409 * Offset of the fragment to retrieve.
411 * Callback to call with the retrieved fragments.
413 * Callback to call with the result of the operation.
415 * Closure for the callbacks.
417 * @return Handle that can be used to cancel the operation.
419 struct GNUNET_PSYCSTORE_OperationHandle *
420 GNUNET_PSYCSTORE_message_get_fragment (struct GNUNET_PSYCSTORE_Handle *h,
421 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
422 const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
424 uint64_t fragment_offset,
425 GNUNET_PSYCSTORE_FragmentCallback fragment_cb,
426 GNUNET_PSYCSTORE_ResultCallback result_cb,
431 * Callback used to return the latest value of counters for the channel master.
433 * @see GNUNET_PSYCSTORE_counters_get()
435 * @param cls Closure.
437 * Status code for the operation:
438 * #GNUNET_OK: success, counter values are returned.
439 * #GNUNET_NO: no message has been sent to the channel yet.
440 * #GNUNET_SYSERR: an error occurred.
441 * @param max_fragment_id
442 * Latest message fragment ID, used by multicast.
443 * @param max_message_id
444 * Latest message ID, used by PSYC.
445 * @param max_group_generation
446 * Latest group generation, used by PSYC.
447 * @param max_state_message_id
448 * Latest message ID containing state modifiers that
449 * was applied to the state store. Used for the state sync process.
452 (*GNUNET_PSYCSTORE_CountersCallback) (void *cls,
454 uint64_t max_fragment_id,
455 uint64_t max_message_id,
456 uint64_t max_group_generation,
457 uint64_t max_state_message_id);
461 * Retrieve latest values of counters for a channel.
463 * The current value of counters are needed
464 * - when a channel master is restarted, so that it can continue incrementing
465 * the counters from their last value.
466 * - when a channel slave rejoins and starts the state synchronization process.
469 * Handle for the PSYCstore.
471 * Public key that identifies the channel.
473 * Callback to call with the result.
475 * Closure for the @a ccb callback.
477 * @return Handle that can be used to cancel the operation.
479 struct GNUNET_PSYCSTORE_OperationHandle *
480 GNUNET_PSYCSTORE_counters_get (struct GNUNET_PSYCSTORE_Handle *h,
481 struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
482 GNUNET_PSYCSTORE_CountersCallback counters_cb,
487 * Apply modifiers of a message to the current channel state.
489 * An error is returned if there are missing messages containing state
490 * operations before the current one.
493 * Handle for the PSYCstore.
495 * The channel we are interested in.
497 * ID of the message that contains the @a modifiers.
499 * Value of the @e state_delta PSYC header variable of the message.
501 * Callback to call with the result of the operation.
503 * Closure for the @a result_cb callback.
505 * @return Handle that can be used to cancel the operation.
507 struct GNUNET_PSYCSTORE_OperationHandle *
508 GNUNET_PSYCSTORE_state_modify (struct GNUNET_PSYCSTORE_Handle *h,
509 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
511 uint64_t state_delta,
512 GNUNET_PSYCSTORE_ResultCallback result_cb,
517 * Store synchronized state.
520 * Handle for the PSYCstore.
522 * The channel we are interested in.
523 * @param max_state_message_id
524 * ID of the last stateful message before @a state_hash_message_id.
525 * @param state_hash_message_id
526 * ID of the message that contains the state_hash PSYC header variable.
527 * @param modifier_count
528 * Number of elements in the @a modifiers array.
530 * Full state to store.
532 * Callback to call with the result of the operation.
534 * Closure for the callback.
536 * @return Handle that can be used to cancel the operation.
538 struct GNUNET_PSYCSTORE_OperationHandle *
539 GNUNET_PSYCSTORE_state_sync (struct GNUNET_PSYCSTORE_Handle *h,
540 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
541 uint64_t max_state_message_id,
542 uint64_t state_hash_message_id,
543 size_t modifier_count,
544 const struct GNUNET_PSYC_Modifier *modifiers,
545 GNUNET_PSYCSTORE_ResultCallback result_cb,
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 result_cb,
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 result_cb,
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, uint32_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 state_cb,
644 GNUNET_PSYCSTORE_ResultCallback result_cb,
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 state_cb,
671 GNUNET_PSYCSTORE_ResultCallback result_cb,
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 */
696 /** @} */ /* end of group */