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
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 * @author Gabor X Toth
23 * @author Christian Grothoff
26 * PSYCstore service; implements persistent storage for the PSYC service
28 * @defgroup psycstore PSYC Store service
29 * Persistent storage for the PSYC service.
32 #ifndef GNUNET_PSYCSTORE_SERVICE_H
33 #define GNUNET_PSYCSTORE_SERVICE_H
38 #if 0 /* keep Emacsens' auto-indent happy */
43 #include "gnunet_util_lib.h"
44 #include "gnunet_psyc_util_lib.h"
45 #include "gnunet_multicast_service.h"
46 #include "gnunet_psyc_service.h"
49 * Version number of GNUnet PSYCstore API.
51 #define GNUNET_PSYCSTORE_VERSION 0x00000000
54 * Membership test failed.
56 #define GNUNET_PSYCSTORE_MEMBERSHIP_TEST_FAILED -2
59 * Flags for stored messages.
61 enum GNUNET_PSYCSTORE_MessageFlags
64 * The message contains state modifiers.
66 GNUNET_PSYCSTORE_MESSAGE_STATE = 1 << 0,
69 * The state modifiers have been applied to the state store.
71 GNUNET_PSYCSTORE_MESSAGE_STATE_APPLIED = 1 << 1,
74 * The message contains a state hash.
76 GNUNET_PSYCSTORE_MESSAGE_STATE_HASH = 1 << 2
81 * Handle for a PSYCstore
83 struct GNUNET_PSYCSTORE_Handle;
87 * Connect to the PSYCstore service.
89 * @param cfg Configuration to use.
91 * @return Handle for the connecton.
93 struct GNUNET_PSYCSTORE_Handle *
94 GNUNET_PSYCSTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
98 * Disconnect from the PSYCstore service.
100 * @param h Handle for the connection.
103 GNUNET_PSYCSTORE_disconnect (struct GNUNET_PSYCSTORE_Handle *h);
107 * Handle for an operation on the PSYCSTORE (useful to cancel the operation).
109 struct GNUNET_PSYCSTORE_OperationHandle;
113 * Function called with the result of an asynchronous operation.
118 * Result of the operation.
120 * Error message, or NULL if there's no error.
121 * @param err_msg_size
125 (*GNUNET_PSYCSTORE_ResultCallback) (void *cls,
128 uint16_t err_msg_size);
132 * Store join/leave events for a PSYC channel in order to be able to answer
133 * membership test queries later.
136 * Handle for the PSYCstore.
138 * The channel where the event happened.
140 * Public key of joining/leaving slave.
142 * #GNUNET_YES on join, #GNUNET_NO on part.
143 * @param announced_at
144 * ID of the message that announced the membership change.
145 * @param effective_since
146 * Message ID this membership change is in effect since.
147 * For joins it is <= announced_at, for parts it is always 0.
148 * @param group_generation
149 * In case of a part, the last group generation the slave has access to.
150 * It has relevance when a larger message have fragments with different
153 * Callback to call with the result of the storage operation.
155 * Closure for the callback.
157 * @return Operation handle that can be used to cancel the operation.
159 struct GNUNET_PSYCSTORE_OperationHandle *
160 GNUNET_PSYCSTORE_membership_store (struct GNUNET_PSYCSTORE_Handle *h,
161 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
162 const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
164 uint64_t announced_at,
165 uint64_t effective_since,
166 uint64_t group_generation,
167 GNUNET_PSYCSTORE_ResultCallback rcb,
172 * Test if a member was admitted to the channel at the given message ID.
174 * This is useful when relaying and replaying messages to check if a particular
175 * slave has access to the message fragment with a given group generation. It
176 * is also used when handling join requests to determine whether the slave is
177 * currently admitted to the channel.
180 * Handle for the PSYCstore.
182 * The channel we are interested in.
184 * Public key of slave whose membership to check.
186 * Message ID for which to do the membership test.
187 * @param group_generation
188 * Group generation of the fragment of the message to test.
189 * It has relevance if the message consists of multiple fragments with
190 * different group generations.
192 * Callback to call with the test result.
194 * Closure for the callback.
196 * @return Operation handle that can be used to cancel the operation.
198 struct GNUNET_PSYCSTORE_OperationHandle *
199 GNUNET_PSYCSTORE_membership_test (struct GNUNET_PSYCSTORE_Handle *h,
200 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
201 const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
203 uint64_t group_generation,
204 GNUNET_PSYCSTORE_ResultCallback rcb,
209 * Store a message fragment sent to a channel.
211 * @param h Handle for the PSYCstore.
212 * @param channel_key The channel the message belongs to.
213 * @param msg Message to store.
214 * @param psycstore_flags Flags indicating whether the PSYC message contains
216 * @param rcb Callback to call with the result of the operation.
217 * @param rcb_cls Closure for the callback.
219 * @return Handle that can be used to cancel the operation.
221 struct GNUNET_PSYCSTORE_OperationHandle *
222 GNUNET_PSYCSTORE_fragment_store (struct GNUNET_PSYCSTORE_Handle *h,
223 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
224 const struct GNUNET_MULTICAST_MessageHeader *msg,
225 enum GNUNET_PSYCSTORE_MessageFlags psycstore_flags,
226 GNUNET_PSYCSTORE_ResultCallback rcb,
231 * Function called with one message fragment, as the result of a
232 * GNUNET_PSYCSTORE_fragment_get() or GNUNET_PSYCSTORE_message_get() call.
234 * @param cls Closure.
235 * @param message The retrieved message fragment. A NULL value indicates that
236 * there are no more results to be returned.
237 * @param psycstore_flags Flags stored with the message.
239 * @return #GNUNET_NO to stop calling this callback with further fragments,
240 * #GNUNET_YES to continue.
243 (*GNUNET_PSYCSTORE_FragmentCallback) (void *cls,
244 struct GNUNET_MULTICAST_MessageHeader *message,
245 enum GNUNET_PSYCSTORE_MessageFlags psycstore_flags);
249 * Retrieve message fragments by fragment ID range.
252 * Handle for the PSYCstore.
254 * The channel we are interested in.
256 * The slave requesting the fragment. If not NULL, a membership test is
257 * performed first and the fragment is only returned if the slave has
259 * @param first_fragment_id
260 * First fragment ID to retrieve.
261 * Use 0 to get the latest message fragment.
262 * @param last_fragment_id
263 * Last consecutive fragment ID to retrieve.
264 * Use 0 to get the latest message fragment.
266 * Callback to call with the retrieved fragments.
268 * Callback to call with the result of the operation.
270 * Closure for the callbacks.
272 * @return Handle that can be used to cancel the operation.
274 struct GNUNET_PSYCSTORE_OperationHandle *
275 GNUNET_PSYCSTORE_fragment_get (struct GNUNET_PSYCSTORE_Handle *h,
276 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
277 const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
278 uint64_t first_message_id,
279 uint64_t last_message_id,
280 GNUNET_PSYCSTORE_FragmentCallback fragment_cb,
281 GNUNET_PSYCSTORE_ResultCallback result_cb,
286 * Retrieve latest message fragments.
289 * Handle for the PSYCstore.
291 * The channel we are interested in.
293 * The slave requesting the fragment. If not NULL, a membership test is
294 * performed first and the fragment is only returned if the slave has
296 * @param first_fragment_id
297 * First fragment ID to retrieve.
298 * Use 0 to get the latest message fragment.
299 * @param last_fragment_id
300 * Last consecutive fragment ID to retrieve.
301 * Use 0 to get the latest message fragment.
302 * @param fragment_limit
303 * Maximum number of fragments to retrieve.
305 * Callback to call with the retrieved fragments.
307 * Callback to call with the result of the operation.
309 * Closure for the callbacks.
311 * @return Handle that can be used to cancel the operation.
313 struct GNUNET_PSYCSTORE_OperationHandle *
314 GNUNET_PSYCSTORE_fragment_get_latest (struct GNUNET_PSYCSTORE_Handle *h,
315 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
316 const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
317 uint64_t fragment_limit,
318 GNUNET_PSYCSTORE_FragmentCallback fragment_cb,
319 GNUNET_PSYCSTORE_ResultCallback rcb,
324 * Retrieve all fragments of messages in a message ID range.
327 * Handle for the PSYCstore.
329 * The channel we are interested in.
331 * The slave requesting the message.
332 * If not NULL, a membership test is performed first
333 * and the message is only returned if the slave has access to it.
334 * @param first_message_id
335 * First message ID to retrieve.
336 * @param last_message_id
337 * Last consecutive message ID to retrieve.
338 * @param fragment_limit
339 * Maximum number of fragments to retrieve.
340 * @param method_prefix
341 * Retrieve only messages with a matching method prefix.
343 * Callback to call with the retrieved fragments.
345 * Callback to call with the result of the operation.
347 * Closure for the callbacks.
349 * @return Handle that can be used to cancel the operation.
351 struct GNUNET_PSYCSTORE_OperationHandle *
352 GNUNET_PSYCSTORE_message_get (struct GNUNET_PSYCSTORE_Handle *h,
353 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
354 const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
355 uint64_t first_message_id,
356 uint64_t last_message_id,
357 uint64_t fragment_limit,
358 const char *method_prefix,
359 GNUNET_PSYCSTORE_FragmentCallback fragment_cb,
360 GNUNET_PSYCSTORE_ResultCallback result_cb,
365 * Retrieve all fragments of the latest messages.
368 * Handle for the PSYCstore.
370 * The channel we are interested in.
372 * The slave requesting the message.
373 * If not NULL, a membership test is performed first
374 * and the message is only returned if the slave has access to it.
375 * @param message_limit
376 * Maximum number of messages to retrieve.
377 * @param method_prefix
378 * Retrieve only messages with a matching method prefix.
380 * Callback to call with the retrieved fragments.
382 * Callback to call with the result of the operation.
384 * Closure for the callbacks.
386 * @return Handle that can be used to cancel the operation.
388 struct GNUNET_PSYCSTORE_OperationHandle *
389 GNUNET_PSYCSTORE_message_get_latest (struct GNUNET_PSYCSTORE_Handle *h,
390 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
391 const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
392 uint64_t message_limit,
393 const char *method_prefix,
394 GNUNET_PSYCSTORE_FragmentCallback fragment_cb,
395 GNUNET_PSYCSTORE_ResultCallback rcb,
400 * Retrieve a fragment of message specified by its message ID and fragment
404 * Handle for the PSYCstore.
406 * The channel we are interested in.
408 * The slave requesting the message fragment. If not NULL, a membership
409 * test is performed first and the message fragment is only returned
410 * if the slave has access to it.
412 * Message ID to retrieve. Use 0 to get the latest message.
413 * @param fragment_offset
414 * Offset of the fragment to retrieve.
416 * Callback to call with the retrieved fragments.
418 * Callback to call with the result of the operation.
420 * Closure for the callbacks.
422 * @return Handle that can be used to cancel the operation.
424 struct GNUNET_PSYCSTORE_OperationHandle *
425 GNUNET_PSYCSTORE_message_get_fragment (struct GNUNET_PSYCSTORE_Handle *h,
426 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
427 const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
429 uint64_t fragment_offset,
430 GNUNET_PSYCSTORE_FragmentCallback fragment_cb,
431 GNUNET_PSYCSTORE_ResultCallback result_cb,
436 * Callback used to return the latest value of counters for the channel master.
438 * @see GNUNET_PSYCSTORE_counters_get()
440 * @param cls Closure.
442 * Status code for the operation:
443 * #GNUNET_OK: success, counter values are returned.
444 * #GNUNET_NO: no message has been sent to the channel yet.
445 * #GNUNET_SYSERR: an error occurred.
446 * @param max_fragment_id
447 * Latest message fragment ID, used by multicast.
448 * @param max_message_id
449 * Latest message ID, used by PSYC.
450 * @param max_group_generation
451 * Latest group generation, used by PSYC.
452 * @param max_state_message_id
453 * Latest message ID containing state modifiers that
454 * was applied to the state store. Used for the state sync process.
457 (*GNUNET_PSYCSTORE_CountersCallback) (void *cls,
459 uint64_t max_fragment_id,
460 uint64_t max_message_id,
461 uint64_t max_group_generation,
462 uint64_t max_state_message_id);
466 * Retrieve latest values of counters for a channel.
468 * The current value of counters are needed
469 * - when a channel master is restarted, so that it can continue incrementing
470 * the counters from their last value.
471 * - when a channel slave rejoins and starts the state synchronization process.
474 * Handle for the PSYCstore.
476 * Public key that identifies the channel.
478 * Callback to call with the result.
480 * Closure for the @a ccb callback.
482 * @return Handle that can be used to cancel the operation.
484 struct GNUNET_PSYCSTORE_OperationHandle *
485 GNUNET_PSYCSTORE_counters_get (struct GNUNET_PSYCSTORE_Handle *h,
486 struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
487 GNUNET_PSYCSTORE_CountersCallback ccb,
492 * Apply modifiers of a message to the current channel state.
494 * An error is returned if there are missing messages containing state
495 * operations before the current one.
498 * Handle for the PSYCstore.
500 * The channel we are interested in.
502 * ID of the message that contains the @a modifiers.
504 * Value of the @e state_delta PSYC header variable of the message.
506 * Callback to call with the result of the operation.
508 * Closure for the @a rcb callback.
510 * @return Handle that can be used to cancel the operation.
512 struct GNUNET_PSYCSTORE_OperationHandle *
513 GNUNET_PSYCSTORE_state_modify (struct GNUNET_PSYCSTORE_Handle *h,
514 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
516 uint64_t state_delta,
517 GNUNET_PSYCSTORE_ResultCallback rcb,
522 * Store synchronized state.
525 * Handle for the PSYCstore.
527 * The channel we are interested in.
528 * @param max_state_message_id
529 * ID of the last stateful message before @a state_hash_message_id.
530 * @param state_hash_message_id
531 * ID of the message that contains the state_hash PSYC header variable.
532 * @param modifier_count
533 * Number of elements in the @a modifiers array.
535 * Full state to store.
537 * Callback to call with the result of the operation.
539 * Closure for the callback.
541 * @return Handle that can be used to cancel the operation.
543 struct GNUNET_PSYCSTORE_OperationHandle *
544 GNUNET_PSYCSTORE_state_sync (struct GNUNET_PSYCSTORE_Handle *h,
545 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
546 uint64_t max_state_message_id,
547 uint64_t state_hash_message_id,
548 size_t modifier_count,
549 const struct GNUNET_PSYC_Modifier *modifiers,
550 GNUNET_PSYCSTORE_ResultCallback rcb,
556 * Reset the state of a channel.
558 * Delete all state variables stored for the given channel.
561 * Handle for the PSYCstore.
563 * The channel we are interested in.
565 * Callback to call with the result of the operation.
567 * Closure for the callback.
569 * @return Handle that can be used to cancel the operation.
571 struct GNUNET_PSYCSTORE_OperationHandle *
572 GNUNET_PSYCSTORE_state_reset (struct GNUNET_PSYCSTORE_Handle *h,
573 const struct GNUNET_CRYPTO_EddsaPublicKey
575 GNUNET_PSYCSTORE_ResultCallback rcb,
580 * Update signed values of state variables in the state store.
583 * Handle for the PSYCstore.
585 * The channel we are interested in.
587 * Message ID that contained the state @a hash.
589 * Hash of the serialized full state.
591 * Callback to call with the result of the operation.
593 * Closure for the callback.
596 struct GNUNET_PSYCSTORE_OperationHandle *
597 GNUNET_PSYCSTORE_state_hash_update (struct GNUNET_PSYCSTORE_Handle *h,
598 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
600 const struct GNUNET_HashCode *hash,
601 GNUNET_PSYCSTORE_ResultCallback rcb,
606 * Function called with the value of a state variable.
611 * Name of the state variable. A NULL value indicates that there are no more
612 * state variables to be returned.
614 * Value of the state variable.
616 * Number of bytes in @a value.
618 * @return #GNUNET_NO to stop calling this callback with further variables,
619 * #GNUNET_YES to continue.
622 (*GNUNET_PSYCSTORE_StateCallback) (void *cls, const char *name,
623 const void *value, uint32_t value_size);
627 * Retrieve the best matching state variable.
630 * Handle for the PSYCstore.
632 * The channel we are interested in.
634 * Name of variable to match, the returned variable might be less specific.
636 * Callback to return the matching state variable.
638 * Callback to call with the result of the operation.
640 * Closure for the callbacks.
642 * @return Handle that can be used to cancel the operation.
644 struct GNUNET_PSYCSTORE_OperationHandle *
645 GNUNET_PSYCSTORE_state_get (struct GNUNET_PSYCSTORE_Handle *h,
646 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
648 GNUNET_PSYCSTORE_StateCallback scb,
649 GNUNET_PSYCSTORE_ResultCallback rcb,
654 * Retrieve all state variables for a channel with the given prefix.
657 * Handle for the PSYCstore.
659 * The channel we are interested in.
661 * Prefix of state variable names to match.
663 * Callback to return matching state variables.
665 * Callback to call with the result of the operation.
667 * Closure for the callbacks.
669 * @return Handle that can be used to cancel the operation.
671 struct GNUNET_PSYCSTORE_OperationHandle *
672 GNUNET_PSYCSTORE_state_get_prefix (struct GNUNET_PSYCSTORE_Handle *h,
673 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
674 const char *name_prefix,
675 GNUNET_PSYCSTORE_StateCallback scb,
676 GNUNET_PSYCSTORE_ResultCallback rcb,
681 * Cancel an operation.
683 * @param op Handle for the operation to cancel.
686 GNUNET_PSYCSTORE_operation_cancel (struct GNUNET_PSYCSTORE_OperationHandle *op);
691 #if 0 /* keep Emacsens' auto-indent happy */
698 /* ifndef GNUNET_PSYCSTORE_SERVICE_H */
701 /** @} */ /* end of group */