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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, 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.
433 * @param result_code Status code for the operation:
434 * #GNUNET_OK: success, counter values are returned.
435 * #GNUNET_NO: no message has been sent to the channel yet.
436 * #GNUNET_SYSERR: an error occurred.
437 * @param max_fragment_id Latest message fragment ID, used by multicast.
438 * @param max_message_id Latest message ID, used by PSYC.
439 * @param max_group_generation Latest group generation, used by PSYC.
440 * @param max_state_message_id Latest message ID containing state modifiers that
441 * was applied to the state store. Used for the state sync process.
444 (*GNUNET_PSYCSTORE_CountersCallback) (void *cls,
446 uint64_t max_fragment_id,
447 uint64_t max_message_id,
448 uint64_t max_group_generation,
449 uint64_t max_state_message_id);
453 * Retrieve latest values of counters for a channel.
455 * The current value of counters are needed
456 * - when a channel master is restarted, so that it can continue incrementing
457 * the counters from their last value.
458 * - when a channel slave rejoins and starts the state synchronization process.
460 * @param h Handle for the PSYCstore.
461 * @param channel_key Public key that identifies the channel.
462 * @param ccb Callback to call with the result.
463 * @param ccb_cls Closure for the @a ccb callback.
465 * @return Handle that can be used to cancel the operation.
467 struct GNUNET_PSYCSTORE_OperationHandle *
468 GNUNET_PSYCSTORE_counters_get (struct GNUNET_PSYCSTORE_Handle *h,
469 struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
470 GNUNET_PSYCSTORE_CountersCallback ccb,
475 * Apply modifiers of a message to the current channel state.
477 * An error is returned if there are missing messages containing state
478 * operations before the current one.
480 * @param h Handle for the PSYCstore.
481 * @param channel_key The channel we are interested in.
482 * @param message_id ID of the message that contains the @a modifiers.
483 * @param state_delta Value of the @e state_delta PSYC header variable of the message.
484 * @param modifier_count Number of elements in the @a modifiers array.
485 * @param modifiers List of modifiers to apply.
486 * @param rcb Callback to call with the result of the operation.
487 * @param rcb_cls Closure for the @a rcb callback.
489 * @return Handle that can be used to cancel the operation.
491 struct GNUNET_PSYCSTORE_OperationHandle *
492 GNUNET_PSYCSTORE_state_modify (struct GNUNET_PSYCSTORE_Handle *h,
493 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
495 uint64_t state_delta,
496 size_t modifier_count,
497 const struct GNUNET_ENV_Modifier *modifiers,
498 GNUNET_PSYCSTORE_ResultCallback rcb,
503 * Store synchronized state.
505 * @param h Handle for the PSYCstore.
506 * @param channel_key The channel we are interested in.
507 * @param message_id ID of the message that contains the state_hash PSYC header variable.
508 * @param modifier_count Number of elements in the @a modifiers array.
509 * @param modifiers Full state to store.
510 * @param rcb Callback to call with the result of the operation.
511 * @param rcb_cls Closure for the callback.
513 * @return Handle that can be used to cancel the operation.
515 struct GNUNET_PSYCSTORE_OperationHandle *
516 GNUNET_PSYCSTORE_state_sync (struct GNUNET_PSYCSTORE_Handle *h,
517 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
519 size_t modifier_count,
520 const struct GNUNET_ENV_Modifier *modifiers,
521 GNUNET_PSYCSTORE_ResultCallback rcb,
527 * Reset the state of a channel.
529 * Delete all state variables stored for the given channel.
531 * @param h Handle for the PSYCstore.
532 * @param channel_key The channel we are interested in.
533 * @param rcb Callback to call with the result of the operation.
534 * @param rcb_cls Closure for the callback.
536 * @return Handle that can be used to cancel the operation.
538 struct GNUNET_PSYCSTORE_OperationHandle *
539 GNUNET_PSYCSTORE_state_reset (struct GNUNET_PSYCSTORE_Handle *h,
540 const struct GNUNET_CRYPTO_EddsaPublicKey
542 GNUNET_PSYCSTORE_ResultCallback rcb,
547 * Update signed values of state variables in the state store.
549 * @param h Handle for the PSYCstore.
550 * @param channel_key The channel we are interested in.
551 * @param message_id Message ID that contained the state @a hash.
552 * @param hash Hash of the serialized full state.
553 * @param rcb Callback to call with the result of the operation.
554 * @param rcb_cls Closure for the callback.
557 struct GNUNET_PSYCSTORE_OperationHandle *
558 GNUNET_PSYCSTORE_state_hash_update (struct GNUNET_PSYCSTORE_Handle *h,
559 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
561 const struct GNUNET_HashCode *hash,
562 GNUNET_PSYCSTORE_ResultCallback rcb,
567 * Function called with the value of a state variable.
569 * @param cls Closure.
570 * @param name Name of the state variable. A NULL value indicates that there are no more
571 * state variables to be returned.
572 * @param value Value of the state variable.
573 * @param value_size Number of bytes in @a value.
575 * @return #GNUNET_NO to stop calling this callback with further variables,
576 * #GNUNET_YES to continue.
579 (*GNUNET_PSYCSTORE_StateCallback) (void *cls, const char *name,
580 const void *value, size_t value_size);
584 * Retrieve the best matching state variable.
586 * @param h Handle for the PSYCstore.
587 * @param channel_key The channel we are interested in.
588 * @param name Name of variable to match, the returned variable might be less specific.
589 * @param scb Callback to return the matching state variable.
590 * @param rcb Callback to call with the result of the operation.
591 * @param cls Closure for the callbacks.
593 * @return Handle that can be used to cancel the operation.
595 struct GNUNET_PSYCSTORE_OperationHandle *
596 GNUNET_PSYCSTORE_state_get (struct GNUNET_PSYCSTORE_Handle *h,
597 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
599 GNUNET_PSYCSTORE_StateCallback scb,
600 GNUNET_PSYCSTORE_ResultCallback rcb,
605 * Retrieve all state variables for a channel with the given prefix.
607 * @param h Handle for the PSYCstore.
608 * @param channel_key The channel we are interested in.
609 * @param name_prefix Prefix of state variable names to match.
610 * @param scb Callback to return matching state variables.
611 * @param rcb Callback to call with the result of the operation.
612 * @param cls Closure for the callbacks.
614 * @return Handle that can be used to cancel the operation.
616 struct GNUNET_PSYCSTORE_OperationHandle *
617 GNUNET_PSYCSTORE_state_get_prefix (struct GNUNET_PSYCSTORE_Handle *h,
618 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
619 const char *name_prefix,
620 GNUNET_PSYCSTORE_StateCallback scb,
621 GNUNET_PSYCSTORE_ResultCallback rcb,
626 * Cancel an operation.
628 * @param op Handle for the operation to cancel.
631 GNUNET_PSYCSTORE_operation_cancel (struct GNUNET_PSYCSTORE_OperationHandle *op);
636 #if 0 /* keep Emacsens' auto-indent happy */
643 /* ifndef GNUNET_PSYCSTORE_SERVICE_H */
645 /* end of gnunet_psycstore_service.h */