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.
111 * #GNUNET_YES on success or if the peer was a member,
112 * #GNUNET_NO if the peer was not a member,
113 * #GNUNET_SYSERR on error,
116 (*GNUNET_PSYCSTORE_ResultCallback) (void *cls,
118 const char *err_msg);
122 * Store join/leave events for a PSYC channel in order to be able to answer
123 * membership test queries later.
126 * Handle for the PSYCstore.
128 * The channel where the event happened.
130 * Public key of joining/leaving slave.
132 * #GNUNET_YES on join, #GNUNET_NO on part.
133 * @param announced_at
134 * ID of the message that announced the membership change.
135 * @param effective_since
136 * Message ID this membership change is in effect since.
137 * For joins it is <= announced_at, for parts it is always 0.
138 * @param group_generation
139 * In case of a part, the last group generation the slave has access to.
140 * It has relevance when a larger message have fragments with different
143 * Callback to call with the result of the storage operation.
145 * Closure for the callback.
147 * @return Operation handle that can be used to cancel the operation.
149 struct GNUNET_PSYCSTORE_OperationHandle *
150 GNUNET_PSYCSTORE_membership_store (struct GNUNET_PSYCSTORE_Handle *h,
151 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
152 const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
154 uint64_t announced_at,
155 uint64_t effective_since,
156 uint64_t group_generation,
157 GNUNET_PSYCSTORE_ResultCallback rcb,
162 * Test if a member was admitted to the channel at the given message ID.
164 * This is useful when relaying and replaying messages to check if a particular
165 * slave has access to the message fragment with a given group generation. It
166 * is also used when handling join requests to determine whether the slave is
167 * currently admitted to the channel.
170 * Handle for the PSYCstore.
172 * The channel we are interested in.
174 * Public key of slave whose membership to check.
176 * Message ID for which to do the membership test.
177 * @param group_generation
178 * Group generation of the fragment of the message to test.
179 * It has relevance if the message consists of multiple fragments with
180 * different group generations.
182 * Callback to call with the test result.
184 * Closure for the callback.
186 * @return Operation handle that can be used to cancel the operation.
188 struct GNUNET_PSYCSTORE_OperationHandle *
189 GNUNET_PSYCSTORE_membership_test (struct GNUNET_PSYCSTORE_Handle *h,
190 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
191 const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
193 uint64_t group_generation,
194 GNUNET_PSYCSTORE_ResultCallback rcb,
199 * Store a message fragment sent to a channel.
201 * @param h Handle for the PSYCstore.
202 * @param channel_key The channel the message belongs to.
203 * @param msg Message to store.
204 * @param psycstore_flags Flags indicating whether the PSYC message contains
206 * @param rcb Callback to call with the result of the operation.
207 * @param rcb_cls Closure for the callback.
209 * @return Handle that can be used to cancel the operation.
211 struct GNUNET_PSYCSTORE_OperationHandle *
212 GNUNET_PSYCSTORE_fragment_store (struct GNUNET_PSYCSTORE_Handle *h,
213 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
214 const struct GNUNET_MULTICAST_MessageHeader *msg,
215 enum GNUNET_PSYCSTORE_MessageFlags psycstore_flags,
216 GNUNET_PSYCSTORE_ResultCallback rcb,
221 * Function called with one message fragment, as the result of a
222 * GNUNET_PSYCSTORE_fragment_get() or GNUNET_PSYCSTORE_message_get() call.
224 * @param cls Closure.
225 * @param message The retrieved message fragment. A NULL value indicates that
226 * there are no more results to be returned.
227 * @param psycstore_flags Flags stored with the message.
229 * @return #GNUNET_NO to stop calling this callback with further fragments,
230 * #GNUNET_YES to continue.
233 (*GNUNET_PSYCSTORE_FragmentCallback) (void *cls,
234 struct GNUNET_MULTICAST_MessageHeader *message,
235 enum GNUNET_PSYCSTORE_MessageFlags psycstore_flags);
239 * Retrieve message fragments by fragment ID range.
242 * Handle for the PSYCstore.
244 * The channel we are interested in.
246 * The slave requesting the fragment. If not NULL, a membership test is
247 * performed first and the fragment is only returned if the slave has
249 * @param first_fragment_id
250 * First fragment ID to retrieve.
251 * Use 0 to get the latest message fragment.
252 * @param last_fragment_id
253 * Last consecutive fragment ID to retrieve.
254 * Use 0 to get the latest message fragment.
256 * Callback to call with the retrieved fragments.
258 * Callback to call with the result of the operation.
260 * Closure for the callbacks.
262 * @return Handle that can be used to cancel the operation.
264 struct GNUNET_PSYCSTORE_OperationHandle *
265 GNUNET_PSYCSTORE_fragment_get (struct GNUNET_PSYCSTORE_Handle *h,
266 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
267 const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
268 uint64_t first_message_id,
269 uint64_t last_message_id,
270 GNUNET_PSYCSTORE_FragmentCallback fragment_cb,
271 GNUNET_PSYCSTORE_ResultCallback result_cb,
276 * Retrieve latest message fragments.
279 * Handle for the PSYCstore.
281 * The channel we are interested in.
283 * The slave requesting the fragment. If not NULL, a membership test is
284 * performed first and the fragment is only returned if the slave has
286 * @param first_fragment_id
287 * First fragment ID to retrieve.
288 * Use 0 to get the latest message fragment.
289 * @param last_fragment_id
290 * Last consecutive fragment ID to retrieve.
291 * Use 0 to get the latest message fragment.
292 * @param fragment_limit
293 * Maximum number of fragments to retrieve.
295 * Callback to call with the retrieved fragments.
297 * Callback to call with the result of the operation.
299 * Closure for the callbacks.
301 * @return Handle that can be used to cancel the operation.
303 struct GNUNET_PSYCSTORE_OperationHandle *
304 GNUNET_PSYCSTORE_fragment_get_latest (struct GNUNET_PSYCSTORE_Handle *h,
305 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
306 const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
307 uint64_t fragment_limit,
308 GNUNET_PSYCSTORE_FragmentCallback fragment_cb,
309 GNUNET_PSYCSTORE_ResultCallback rcb,
314 * Retrieve all fragments of messages in a message ID range.
317 * Handle for the PSYCstore.
319 * The channel we are interested in.
321 * The slave requesting the message. If not NULL, a membership test is
322 * performed first and the message is only returned if the slave has
324 * @param first_message_id
325 * First message ID to retrieve.
326 * Use 0 to get the latest message.
327 * @param last_message_id
328 * Last consecutive message ID to retrieve.
329 * Use 0 to get the latest message.
331 * Callback to call with the retrieved fragments.
333 * Callback to call with the result of the operation.
335 * Closure for the callbacks.
337 * @return Handle that can be used to cancel the operation.
339 struct GNUNET_PSYCSTORE_OperationHandle *
340 GNUNET_PSYCSTORE_message_get (struct GNUNET_PSYCSTORE_Handle *h,
341 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
342 const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
343 uint64_t first_message_id,
344 uint64_t last_message_id,
345 GNUNET_PSYCSTORE_FragmentCallback fragment_cb,
346 GNUNET_PSYCSTORE_ResultCallback result_cb,
351 * Retrieve all fragments of the latest messages.
354 * Handle for the PSYCstore.
356 * The channel we are interested in.
358 * The slave requesting the message. If not NULL, a membership test is
359 * performed first and the message is only returned if the slave has
361 * @param message_limit
362 * Maximum number of messages to retrieve.
364 * Callback to call with the retrieved fragments.
366 * Callback to call with the result of the operation.
368 * Closure for the callbacks.
370 * @return Handle that can be used to cancel the operation.
372 struct GNUNET_PSYCSTORE_OperationHandle *
373 GNUNET_PSYCSTORE_message_get_latest (struct GNUNET_PSYCSTORE_Handle *h,
374 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
375 const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
376 uint64_t message_limit,
377 GNUNET_PSYCSTORE_FragmentCallback fragment_cb,
378 GNUNET_PSYCSTORE_ResultCallback rcb,
383 * Retrieve a fragment of message specified by its message ID and fragment
387 * Handle for the PSYCstore.
389 * The channel we are interested in.
391 * The slave requesting the message fragment. If not NULL, a membership
392 * test is performed first and the message fragment is only returned
393 * if the slave has access to it.
395 * Message ID to retrieve. Use 0 to get the latest message.
396 * @param fragment_offset
397 * Offset of the fragment to retrieve.
399 * Callback to call with the retrieved fragments.
401 * Callback to call with the result of the operation.
403 * Closure for the callbacks.
405 * @return Handle that can be used to cancel the operation.
407 struct GNUNET_PSYCSTORE_OperationHandle *
408 GNUNET_PSYCSTORE_message_get_fragment (struct GNUNET_PSYCSTORE_Handle *h,
409 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
410 const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
412 uint64_t fragment_offset,
413 GNUNET_PSYCSTORE_FragmentCallback fragment_cb,
414 GNUNET_PSYCSTORE_ResultCallback result_cb,
419 * Callback used to return the latest value of counters for the channel master.
421 * @see GNUNET_PSYCSTORE_counters_get()
423 * @param cls Closure.
424 * @param result_code Status code for the operation:
425 * #GNUNET_OK: success, counter values are returned.
426 * #GNUNET_NO: no message has been sent to the channel yet.
427 * #GNUNET_SYSERR: an error occurred.
428 * @param max_fragment_id Latest message fragment ID, used by multicast.
429 * @param max_message_id Latest message ID, used by PSYC.
430 * @param max_group_generation Latest group generation, used by PSYC.
431 * @param max_state_message_id Latest message ID containing state modifiers that
432 * was applied to the state store. Used for the state sync process.
435 (*GNUNET_PSYCSTORE_CountersCallback) (void *cls,
437 uint64_t max_fragment_id,
438 uint64_t max_message_id,
439 uint64_t max_group_generation,
440 uint64_t max_state_message_id);
444 * Retrieve latest values of counters for a channel.
446 * The current value of counters are needed
447 * - when a channel master is restarted, so that it can continue incrementing
448 * the counters from their last value.
449 * - when a channel slave rejoins and starts the state synchronization process.
451 * @param h Handle for the PSYCstore.
452 * @param channel_key Public key that identifies the channel.
453 * @param ccb Callback to call with the result.
454 * @param ccb_cls Closure for the @a ccb callback.
456 * @return Handle that can be used to cancel the operation.
458 struct GNUNET_PSYCSTORE_OperationHandle *
459 GNUNET_PSYCSTORE_counters_get (struct GNUNET_PSYCSTORE_Handle *h,
460 struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
461 GNUNET_PSYCSTORE_CountersCallback ccb,
466 * Apply modifiers of a message to the current channel state.
468 * An error is returned if there are missing messages containing state
469 * operations before the current one.
471 * @param h Handle for the PSYCstore.
472 * @param channel_key The channel we are interested in.
473 * @param message_id ID of the message that contains the @a modifiers.
474 * @param state_delta Value of the @e state_delta PSYC header variable of the message.
475 * @param modifier_count Number of elements in the @a modifiers array.
476 * @param modifiers List of modifiers to apply.
477 * @param rcb Callback to call with the result of the operation.
478 * @param rcb_cls Closure for the @a rcb callback.
480 * @return Handle that can be used to cancel the operation.
482 struct GNUNET_PSYCSTORE_OperationHandle *
483 GNUNET_PSYCSTORE_state_modify (struct GNUNET_PSYCSTORE_Handle *h,
484 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
486 uint64_t state_delta,
487 size_t modifier_count,
488 const struct GNUNET_ENV_Modifier *modifiers,
489 GNUNET_PSYCSTORE_ResultCallback rcb,
494 * Store synchronized state.
496 * @param h Handle for the PSYCstore.
497 * @param channel_key The channel we are interested in.
498 * @param message_id ID of the message that contains the state_hash PSYC header variable.
499 * @param modifier_count Number of elements in the @a modifiers array.
500 * @param modifiers Full state to store.
501 * @param rcb Callback to call with the result of the operation.
502 * @param rcb_cls Closure for the callback.
504 * @return Handle that can be used to cancel the operation.
506 struct GNUNET_PSYCSTORE_OperationHandle *
507 GNUNET_PSYCSTORE_state_sync (struct GNUNET_PSYCSTORE_Handle *h,
508 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
510 size_t modifier_count,
511 const struct GNUNET_ENV_Modifier *modifiers,
512 GNUNET_PSYCSTORE_ResultCallback rcb,
518 * Reset the state of a channel.
520 * Delete all state variables stored for the given channel.
522 * @param h Handle for the PSYCstore.
523 * @param channel_key The channel we are interested in.
524 * @param rcb Callback to call with the result of the operation.
525 * @param rcb_cls Closure for the callback.
527 * @return Handle that can be used to cancel the operation.
529 struct GNUNET_PSYCSTORE_OperationHandle *
530 GNUNET_PSYCSTORE_state_reset (struct GNUNET_PSYCSTORE_Handle *h,
531 const struct GNUNET_CRYPTO_EddsaPublicKey
533 GNUNET_PSYCSTORE_ResultCallback rcb,
538 * Update signed values of state variables in the state store.
540 * @param h Handle for the PSYCstore.
541 * @param channel_key The channel we are interested in.
542 * @param message_id Message ID that contained the state @a hash.
543 * @param hash Hash of the serialized full state.
544 * @param rcb Callback to call with the result of the operation.
545 * @param rcb_cls Closure for the callback.
548 struct GNUNET_PSYCSTORE_OperationHandle *
549 GNUNET_PSYCSTORE_state_hash_update (struct GNUNET_PSYCSTORE_Handle *h,
550 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
552 const struct GNUNET_HashCode *hash,
553 GNUNET_PSYCSTORE_ResultCallback rcb,
558 * Function called with the value of a state variable.
560 * @param cls Closure.
561 * @param name Name of the state variable. A NULL value indicates that there are no more
562 * state variables to be returned.
563 * @param value Value of the state variable.
564 * @param value_size Number of bytes in @a value.
566 * @return #GNUNET_NO to stop calling this callback with further variables,
567 * #GNUNET_YES to continue.
570 (*GNUNET_PSYCSTORE_StateCallback) (void *cls, const char *name,
571 const void *value, size_t value_size);
575 * Retrieve the best matching state variable.
577 * @param h Handle for the PSYCstore.
578 * @param channel_key The channel we are interested in.
579 * @param name Name of variable to match, the returned variable might be less specific.
580 * @param scb Callback to return the matching state variable.
581 * @param rcb Callback to call with the result of the operation.
582 * @param cls Closure for the callbacks.
584 * @return Handle that can be used to cancel the operation.
586 struct GNUNET_PSYCSTORE_OperationHandle *
587 GNUNET_PSYCSTORE_state_get (struct GNUNET_PSYCSTORE_Handle *h,
588 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
590 GNUNET_PSYCSTORE_StateCallback scb,
591 GNUNET_PSYCSTORE_ResultCallback rcb,
596 * Retrieve all state variables for a channel with the given prefix.
598 * @param h Handle for the PSYCstore.
599 * @param channel_key The channel we are interested in.
600 * @param name_prefix Prefix of state variable names to match.
601 * @param scb Callback to return matching state variables.
602 * @param rcb Callback to call with the result of the operation.
603 * @param cls Closure for the callbacks.
605 * @return Handle that can be used to cancel the operation.
607 struct GNUNET_PSYCSTORE_OperationHandle *
608 GNUNET_PSYCSTORE_state_get_prefix (struct GNUNET_PSYCSTORE_Handle *h,
609 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
610 const char *name_prefix,
611 GNUNET_PSYCSTORE_StateCallback scb,
612 GNUNET_PSYCSTORE_ResultCallback rcb,
617 * Cancel an operation.
619 * @param op Handle for the operation to cancel.
622 GNUNET_PSYCSTORE_operation_cancel (struct GNUNET_PSYCSTORE_OperationHandle *op);
627 #if 0 /* keep Emacsens' auto-indent happy */
634 /* ifndef GNUNET_PSYCSTORE_SERVICE_H */
636 /* end of gnunet_psycstore_service.h */