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 Affero 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.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * @author Gabor X Toth
21 * @author Christian Grothoff
24 * PSYCstore service; implements persistent storage for the PSYC service
26 * @defgroup psycstore PSYC Store service
27 * Persistent storage for the PSYC service.
30 #ifndef GNUNET_PSYCSTORE_SERVICE_H
31 #define GNUNET_PSYCSTORE_SERVICE_H
36 #if 0 /* keep Emacsens' auto-indent happy */
41 #include "gnunet_util_lib.h"
42 #include "gnunet_psyc_util_lib.h"
43 #include "gnunet_multicast_service.h"
44 #include "gnunet_psyc_service.h"
47 * Version number of GNUnet PSYCstore API.
49 #define GNUNET_PSYCSTORE_VERSION 0x00000000
52 * Membership test failed.
54 #define GNUNET_PSYCSTORE_MEMBERSHIP_TEST_FAILED -2
57 * Flags for stored messages.
59 enum GNUNET_PSYCSTORE_MessageFlags
62 * The message contains state modifiers.
64 GNUNET_PSYCSTORE_MESSAGE_STATE = 1 << 0,
67 * The state modifiers have been applied to the state store.
69 GNUNET_PSYCSTORE_MESSAGE_STATE_APPLIED = 1 << 1,
72 * The message contains a state hash.
74 GNUNET_PSYCSTORE_MESSAGE_STATE_HASH = 1 << 2
79 * Handle for a PSYCstore
81 struct GNUNET_PSYCSTORE_Handle;
85 * Connect to the PSYCstore service.
87 * @param cfg Configuration to use.
89 * @return Handle for the connecton.
91 struct GNUNET_PSYCSTORE_Handle *
92 GNUNET_PSYCSTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
96 * Disconnect from the PSYCstore service.
98 * @param h Handle for the connection.
101 GNUNET_PSYCSTORE_disconnect (struct GNUNET_PSYCSTORE_Handle *h);
105 * Handle for an operation on the PSYCSTORE (useful to cancel the operation).
107 struct GNUNET_PSYCSTORE_OperationHandle;
111 * Function called with the result of an asynchronous operation.
116 * Result of the operation.
118 * Error message, or NULL if there's no error.
119 * @param err_msg_size
123 (*GNUNET_PSYCSTORE_ResultCallback) (void *cls,
126 uint16_t err_msg_size);
130 * Store join/leave events for a PSYC channel in order to be able to answer
131 * membership test queries later.
134 * Handle for the PSYCstore.
136 * The channel where the event happened.
138 * Public key of joining/leaving slave.
140 * #GNUNET_YES on join, #GNUNET_NO on part.
141 * @param announced_at
142 * ID of the message that announced the membership change.
143 * @param effective_since
144 * Message ID this membership change is in effect since.
145 * For joins it is <= announced_at, for parts it is always 0.
146 * @param group_generation
147 * In case of a part, the last group generation the slave has access to.
148 * It has relevance when a larger message have fragments with different
151 * Callback to call with the result of the storage operation.
153 * Closure for the callback.
155 * @return Operation handle that can be used to cancel the operation.
157 struct GNUNET_PSYCSTORE_OperationHandle *
158 GNUNET_PSYCSTORE_membership_store (struct GNUNET_PSYCSTORE_Handle *h,
159 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
160 const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
162 uint64_t announced_at,
163 uint64_t effective_since,
164 uint64_t group_generation,
165 GNUNET_PSYCSTORE_ResultCallback result_cb,
170 * Test if a member was admitted to the channel at the given message ID.
172 * This is useful when relaying and replaying messages to check if a particular
173 * slave has access to the message fragment with a given group generation. It
174 * is also used when handling join requests to determine whether the slave is
175 * currently admitted to the channel.
178 * Handle for the PSYCstore.
180 * The channel we are interested in.
182 * Public key of slave whose membership to check.
184 * Message ID for which to do the membership test.
185 * @param group_generation
186 * Group generation of the fragment of the message to test.
187 * It has relevance if the message consists of multiple fragments with
188 * different group generations.
190 * Callback to call with the test result.
192 * Closure for the callback.
194 * @return Operation handle that can be used to cancel the operation.
196 struct GNUNET_PSYCSTORE_OperationHandle *
197 GNUNET_PSYCSTORE_membership_test (struct GNUNET_PSYCSTORE_Handle *h,
198 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
199 const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
201 uint64_t group_generation,
202 GNUNET_PSYCSTORE_ResultCallback result_cb,
207 * Store a message fragment sent to a channel.
209 * @param h Handle for the PSYCstore.
210 * @param channel_key The channel the message belongs to.
211 * @param msg Message to store.
212 * @param psycstore_flags Flags indicating whether the PSYC message contains
214 * @param result_cb Callback to call with the result of the operation.
215 * @param cls Closure for the callback.
217 * @return Handle that can be used to cancel the operation.
219 struct GNUNET_PSYCSTORE_OperationHandle *
220 GNUNET_PSYCSTORE_fragment_store (struct GNUNET_PSYCSTORE_Handle *h,
221 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
222 const struct GNUNET_MULTICAST_MessageHeader *msg,
223 enum GNUNET_PSYCSTORE_MessageFlags psycstore_flags,
224 GNUNET_PSYCSTORE_ResultCallback result_cb,
229 * Function called with one message fragment, as the result of a
230 * GNUNET_PSYCSTORE_fragment_get() or GNUNET_PSYCSTORE_message_get() call.
232 * @param cls Closure.
233 * @param message The retrieved message fragment. A NULL value indicates that
234 * there are no more results to be returned.
235 * @param psycstore_flags Flags stored with the message.
237 * @return #GNUNET_NO to stop calling this callback with further fragments,
238 * #GNUNET_YES to continue.
241 (*GNUNET_PSYCSTORE_FragmentCallback) (void *cls,
242 struct GNUNET_MULTICAST_MessageHeader *message,
243 enum GNUNET_PSYCSTORE_MessageFlags psycstore_flags);
247 * Retrieve message fragments by fragment ID range.
250 * Handle for the PSYCstore.
252 * The channel we are interested in.
254 * The slave requesting the fragment. If not NULL, a membership test is
255 * performed first and the fragment is only returned if the slave has
257 * @param first_fragment_id
258 * First fragment ID to retrieve.
259 * Use 0 to get the latest message fragment.
260 * @param last_fragment_id
261 * Last consecutive fragment ID to retrieve.
262 * Use 0 to get the latest message fragment.
264 * Callback to call with the retrieved fragments.
266 * Callback to call with the result of the operation.
268 * Closure for the callbacks.
270 * @return Handle that can be used to cancel the operation.
272 struct GNUNET_PSYCSTORE_OperationHandle *
273 GNUNET_PSYCSTORE_fragment_get (struct GNUNET_PSYCSTORE_Handle *h,
274 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
275 const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
276 uint64_t first_message_id,
277 uint64_t last_message_id,
278 GNUNET_PSYCSTORE_FragmentCallback fragment_cb,
279 GNUNET_PSYCSTORE_ResultCallback result_cb,
284 * Retrieve latest message fragments.
287 * Handle for the PSYCstore.
289 * The channel we are interested in.
291 * The slave requesting the fragment. If not NULL, a membership test is
292 * performed first and the fragment is only returned if the slave has
294 * @param first_fragment_id
295 * First fragment ID to retrieve.
296 * Use 0 to get the latest message fragment.
297 * @param last_fragment_id
298 * Last consecutive fragment ID to retrieve.
299 * Use 0 to get the latest message fragment.
300 * @param fragment_limit
301 * Maximum number of fragments to retrieve.
303 * Callback to call with the retrieved fragments.
305 * Callback to call with the result of the operation.
307 * Closure for the callbacks.
309 * @return Handle that can be used to cancel the operation.
311 struct GNUNET_PSYCSTORE_OperationHandle *
312 GNUNET_PSYCSTORE_fragment_get_latest (struct GNUNET_PSYCSTORE_Handle *h,
313 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
314 const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
315 uint64_t fragment_limit,
316 GNUNET_PSYCSTORE_FragmentCallback fragment_cb,
317 GNUNET_PSYCSTORE_ResultCallback result_cb,
322 * Retrieve all fragments of messages in a message ID range.
325 * Handle for the PSYCstore.
327 * The channel we are interested in.
329 * The slave requesting the message.
330 * If not NULL, a membership test is performed first
331 * and the message is only returned if the slave has access to it.
332 * @param first_message_id
333 * First message ID to retrieve.
334 * @param last_message_id
335 * Last consecutive message ID to retrieve.
336 * @param fragment_limit
337 * Maximum number of fragments to retrieve.
338 * @param method_prefix
339 * Retrieve only messages with a matching method prefix.
341 * Callback to call with the retrieved fragments.
343 * Callback to call with the result of the operation.
345 * Closure for the callbacks.
347 * @return Handle that can be used to cancel the operation.
349 struct GNUNET_PSYCSTORE_OperationHandle *
350 GNUNET_PSYCSTORE_message_get (struct GNUNET_PSYCSTORE_Handle *h,
351 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
352 const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
353 uint64_t first_message_id,
354 uint64_t last_message_id,
355 uint64_t fragment_limit,
356 const char *method_prefix,
357 GNUNET_PSYCSTORE_FragmentCallback fragment_cb,
358 GNUNET_PSYCSTORE_ResultCallback result_cb,
363 * Retrieve all fragments of the latest messages.
366 * Handle for the PSYCstore.
368 * The channel we are interested in.
370 * The slave requesting the message.
371 * If not NULL, a membership test is performed first
372 * and the message is only returned if the slave has access to it.
373 * @param message_limit
374 * Maximum number of messages to retrieve.
375 * @param method_prefix
376 * Retrieve only messages with a matching method prefix.
378 * Callback to call with the retrieved fragments.
380 * Callback to call with the result of the operation.
382 * Closure for the callbacks.
384 * @return Handle that can be used to cancel the operation.
386 struct GNUNET_PSYCSTORE_OperationHandle *
387 GNUNET_PSYCSTORE_message_get_latest (struct GNUNET_PSYCSTORE_Handle *h,
388 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
389 const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
390 uint64_t message_limit,
391 const char *method_prefix,
392 GNUNET_PSYCSTORE_FragmentCallback fragment_cb,
393 GNUNET_PSYCSTORE_ResultCallback result_cb,
398 * Retrieve a fragment of message specified by its message ID and fragment
402 * Handle for the PSYCstore.
404 * The channel we are interested in.
406 * The slave requesting the message fragment. If not NULL, a membership
407 * test is performed first and the message fragment is only returned
408 * if the slave has access to it.
410 * Message ID to retrieve. Use 0 to get the latest message.
411 * @param fragment_offset
412 * Offset of the fragment to retrieve.
414 * Callback to call with the retrieved fragments.
416 * Callback to call with the result of the operation.
418 * Closure for the callbacks.
420 * @return Handle that can be used to cancel the operation.
422 struct GNUNET_PSYCSTORE_OperationHandle *
423 GNUNET_PSYCSTORE_message_get_fragment (struct GNUNET_PSYCSTORE_Handle *h,
424 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
425 const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
427 uint64_t fragment_offset,
428 GNUNET_PSYCSTORE_FragmentCallback fragment_cb,
429 GNUNET_PSYCSTORE_ResultCallback result_cb,
434 * Callback used to return the latest value of counters for the channel master.
436 * @see GNUNET_PSYCSTORE_counters_get()
438 * @param cls Closure.
440 * Status code for the operation:
441 * #GNUNET_OK: success, counter values are returned.
442 * #GNUNET_NO: no message has been sent to the channel yet.
443 * #GNUNET_SYSERR: an error occurred.
444 * @param max_fragment_id
445 * Latest message fragment ID, used by multicast.
446 * @param max_message_id
447 * Latest message ID, used by PSYC.
448 * @param max_group_generation
449 * Latest group generation, used by PSYC.
450 * @param max_state_message_id
451 * Latest message ID containing state modifiers that
452 * was applied to the state store. Used for the state sync process.
455 (*GNUNET_PSYCSTORE_CountersCallback) (void *cls,
457 uint64_t max_fragment_id,
458 uint64_t max_message_id,
459 uint64_t max_group_generation,
460 uint64_t max_state_message_id);
464 * Retrieve latest values of counters for a channel.
466 * The current value of counters are needed
467 * - when a channel master is restarted, so that it can continue incrementing
468 * the counters from their last value.
469 * - when a channel slave rejoins and starts the state synchronization process.
472 * Handle for the PSYCstore.
474 * Public key that identifies the channel.
476 * Callback to call with the result.
478 * Closure for the @a ccb callback.
480 * @return Handle that can be used to cancel the operation.
482 struct GNUNET_PSYCSTORE_OperationHandle *
483 GNUNET_PSYCSTORE_counters_get (struct GNUNET_PSYCSTORE_Handle *h,
484 struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
485 GNUNET_PSYCSTORE_CountersCallback counters_cb,
490 * Apply modifiers of a message to the current channel state.
492 * An error is returned if there are missing messages containing state
493 * operations before the current one.
496 * Handle for the PSYCstore.
498 * The channel we are interested in.
500 * ID of the message that contains the @a modifiers.
502 * Value of the @e state_delta PSYC header variable of the message.
504 * Callback to call with the result of the operation.
506 * Closure for the @a result_cb callback.
508 * @return Handle that can be used to cancel the operation.
510 struct GNUNET_PSYCSTORE_OperationHandle *
511 GNUNET_PSYCSTORE_state_modify (struct GNUNET_PSYCSTORE_Handle *h,
512 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
514 uint64_t state_delta,
515 GNUNET_PSYCSTORE_ResultCallback result_cb,
520 * Store synchronized state.
523 * Handle for the PSYCstore.
525 * The channel we are interested in.
526 * @param max_state_message_id
527 * ID of the last stateful message before @a state_hash_message_id.
528 * @param state_hash_message_id
529 * ID of the message that contains the state_hash PSYC header variable.
530 * @param modifier_count
531 * Number of elements in the @a modifiers array.
533 * Full state to store.
535 * Callback to call with the result of the operation.
537 * Closure for the callback.
539 * @return Handle that can be used to cancel the operation.
541 struct GNUNET_PSYCSTORE_OperationHandle *
542 GNUNET_PSYCSTORE_state_sync (struct GNUNET_PSYCSTORE_Handle *h,
543 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
544 uint64_t max_state_message_id,
545 uint64_t state_hash_message_id,
546 size_t modifier_count,
547 const struct GNUNET_PSYC_Modifier *modifiers,
548 GNUNET_PSYCSTORE_ResultCallback result_cb,
554 * Reset the state of a channel.
556 * Delete all state variables stored for the given channel.
559 * Handle for the PSYCstore.
561 * The channel we are interested in.
563 * Callback to call with the result of the operation.
565 * Closure for the callback.
567 * @return Handle that can be used to cancel the operation.
569 struct GNUNET_PSYCSTORE_OperationHandle *
570 GNUNET_PSYCSTORE_state_reset (struct GNUNET_PSYCSTORE_Handle *h,
571 const struct GNUNET_CRYPTO_EddsaPublicKey
573 GNUNET_PSYCSTORE_ResultCallback result_cb,
578 * Update signed values of state variables in the state store.
581 * Handle for the PSYCstore.
583 * The channel we are interested in.
585 * Message ID that contained the state @a hash.
587 * Hash of the serialized full state.
589 * Callback to call with the result of the operation.
591 * Closure for the callback.
594 struct GNUNET_PSYCSTORE_OperationHandle *
595 GNUNET_PSYCSTORE_state_hash_update (struct GNUNET_PSYCSTORE_Handle *h,
596 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
598 const struct GNUNET_HashCode *hash,
599 GNUNET_PSYCSTORE_ResultCallback result_cb,
604 * Function called with the value of a state variable.
609 * Name of the state variable. A NULL value indicates that there are no more
610 * state variables to be returned.
612 * Value of the state variable.
614 * Number of bytes in @a value.
616 * @return #GNUNET_NO to stop calling this callback with further variables,
617 * #GNUNET_YES to continue.
620 (*GNUNET_PSYCSTORE_StateCallback) (void *cls, const char *name,
621 const void *value, uint32_t value_size);
625 * Retrieve the best matching state variable.
628 * Handle for the PSYCstore.
630 * The channel we are interested in.
632 * Name of variable to match, the returned variable might be less specific.
634 * Callback to return the matching state variable.
636 * Callback to call with the result of the operation.
638 * Closure for the callbacks.
640 * @return Handle that can be used to cancel the operation.
642 struct GNUNET_PSYCSTORE_OperationHandle *
643 GNUNET_PSYCSTORE_state_get (struct GNUNET_PSYCSTORE_Handle *h,
644 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
646 GNUNET_PSYCSTORE_StateCallback state_cb,
647 GNUNET_PSYCSTORE_ResultCallback result_cb,
652 * Retrieve all state variables for a channel with the given prefix.
655 * Handle for the PSYCstore.
657 * The channel we are interested in.
659 * Prefix of state variable names to match.
661 * Callback to return matching state variables.
663 * Callback to call with the result of the operation.
665 * Closure for the callbacks.
667 * @return Handle that can be used to cancel the operation.
669 struct GNUNET_PSYCSTORE_OperationHandle *
670 GNUNET_PSYCSTORE_state_get_prefix (struct GNUNET_PSYCSTORE_Handle *h,
671 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
672 const char *name_prefix,
673 GNUNET_PSYCSTORE_StateCallback state_cb,
674 GNUNET_PSYCSTORE_ResultCallback result_cb,
679 * Cancel an operation.
681 * @param op Handle for the operation to cancel.
684 GNUNET_PSYCSTORE_operation_cancel (struct GNUNET_PSYCSTORE_OperationHandle *op);
689 #if 0 /* keep Emacsens' auto-indent happy */
696 /* ifndef GNUNET_PSYCSTORE_SERVICE_H */
699 /** @} */ /* end of group */