2 This file is part of GNUnet.
3 (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.
110 * @param result #GNUNET_SYSERR on error,
111 * #GNUNET_YES on success or if the peer was a member,
112 * #GNUNET_NO if the peer was not a member
115 (*GNUNET_PSYCSTORE_ResultCallback) (void *cls,
117 const char *err_msg);
121 * Store join/leave events for a PSYC channel in order to be able to answer
122 * membership test queries later.
125 * Handle for the PSYCstore.
127 * The channel where the event happened.
129 * Public key of joining/leaving slave.
131 * #GNUNET_YES on join, #GNUNET_NO on part.
132 * @param announced_at
133 * ID of the message that announced the membership change.
134 * @param effective_since
135 * Message ID this membership change is in effect since.
136 * For joins it is <= announced_at, for parts it is always 0.
137 * @param group_generation
138 * In case of a part, the last group generation the slave has access to.
139 * It has relevance when a larger message have fragments with different
142 * Callback to call with the result of the storage operation.
144 * Closure for the callback.
146 * @return Operation handle that can be used to cancel the operation.
148 struct GNUNET_PSYCSTORE_OperationHandle *
149 GNUNET_PSYCSTORE_membership_store (struct GNUNET_PSYCSTORE_Handle *h,
150 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
151 const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
153 uint64_t announced_at,
154 uint64_t effective_since,
155 uint64_t group_generation,
156 GNUNET_PSYCSTORE_ResultCallback rcb,
161 * Test if a member was admitted to the channel at the given message ID.
163 * This is useful when relaying and replaying messages to check if a particular
164 * slave has access to the message fragment with a given group generation. It
165 * is also used when handling join requests to determine whether the slave is
166 * currently admitted to the channel.
169 * Handle for the PSYCstore.
171 * The channel we are interested in.
173 * Public key of slave whose membership to check.
175 * Message ID for which to do the membership test.
176 * @param group_generation
177 * Group generation of the fragment of the message to test.
178 * It has relevance if the message consists of multiple fragments with
179 * different group generations.
181 * Callback to call with the test result.
183 * Closure for the callback.
185 * @return Operation handle that can be used to cancel the operation.
187 struct GNUNET_PSYCSTORE_OperationHandle *
188 GNUNET_PSYCSTORE_membership_test (struct GNUNET_PSYCSTORE_Handle *h,
189 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
190 const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
192 uint64_t group_generation,
193 GNUNET_PSYCSTORE_ResultCallback rcb,
198 * Store a message fragment sent to a channel.
200 * @param h Handle for the PSYCstore.
201 * @param channel_key The channel the message belongs to.
202 * @param msg Message to store.
203 * @param psycstore_flags Flags indicating whether the PSYC message contains
205 * @param rcb Callback to call with the result of the operation.
206 * @param rcb_cls Closure for the callback.
208 * @return Handle that can be used to cancel the operation.
210 struct GNUNET_PSYCSTORE_OperationHandle *
211 GNUNET_PSYCSTORE_fragment_store (struct GNUNET_PSYCSTORE_Handle *h,
212 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
213 const struct GNUNET_MULTICAST_MessageHeader *msg,
214 enum GNUNET_PSYCSTORE_MessageFlags psycstore_flags,
215 GNUNET_PSYCSTORE_ResultCallback rcb,
220 * Function called with one message fragment, as the result of a
221 * GNUNET_PSYCSTORE_fragment_get() or GNUNET_PSYCSTORE_message_get() call.
223 * @param cls Closure.
224 * @param message The retrieved message fragment. A NULL value indicates that
225 * there are no more results to be returned.
226 * @param psycstore_flags Flags stored with the message.
228 * @return #GNUNET_NO to stop calling this callback with further fragments,
229 * #GNUNET_YES to continue.
232 (*GNUNET_PSYCSTORE_FragmentCallback) (void *cls,
233 struct GNUNET_MULTICAST_MessageHeader *message,
234 enum GNUNET_PSYCSTORE_MessageFlags psycstore_flags);
238 * Retrieve a message fragment by fragment ID.
241 * Handle for the PSYCstore.
243 * The channel we are interested in.
245 * The slave requesting the fragment. If not NULL, a membership test is
246 * performed first and the fragment is only returned if the slave has
249 * Fragment ID to retrieve. Use 0 to get the latest message fragment.
251 * Callback to call with the retrieved fragments.
253 * Callback to call with the result of the operation.
255 * Closure for the callbacks.
257 * @return Handle that can be used to cancel the operation.
259 struct GNUNET_PSYCSTORE_OperationHandle *
260 GNUNET_PSYCSTORE_fragment_get (struct GNUNET_PSYCSTORE_Handle *h,
261 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
262 const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
263 uint64_t fragment_id,
264 GNUNET_PSYCSTORE_FragmentCallback fcb,
265 GNUNET_PSYCSTORE_ResultCallback rcb,
270 * Retrieve all fragments of a message.
273 * Handle for the PSYCstore.
275 * The channel we are interested in.
277 * The slave requesting the message. If not NULL, a membership test is
278 * performed first and the message is only returned if the slave has
281 * Message ID to retrieve. Use 0 to get the latest message.
283 * Callback to call with the retrieved fragments.
285 * Callback to call with the result of the operation.
287 * Closure for the callbacks.
289 * @return Handle that can be used to cancel the operation.
291 struct GNUNET_PSYCSTORE_OperationHandle *
292 GNUNET_PSYCSTORE_message_get (struct GNUNET_PSYCSTORE_Handle *h,
293 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
294 const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
296 GNUNET_PSYCSTORE_FragmentCallback fcb,
297 GNUNET_PSYCSTORE_ResultCallback rcb,
302 * Retrieve a fragment of message specified by its message ID and fragment
305 * @param h Handle for the PSYCstore.
306 * @param channel_key The channel we are interested in.
307 * @param message_id Message ID to check. Use 0 to get the latest message.
308 * @param fragment_offset Offset of the fragment to retrieve.
309 * @param fcb Callback to call with the retrieved fragments.
310 * @param rcb Callback to call with the result of the operation.
311 * @param cls Closure for the callbacks.
313 * @return Handle that can be used to cancel the operation.
315 struct GNUNET_PSYCSTORE_OperationHandle *
316 GNUNET_PSYCSTORE_message_get_fragment (struct GNUNET_PSYCSTORE_Handle *h,
317 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
318 const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
320 uint64_t fragment_offset,
321 GNUNET_PSYCSTORE_FragmentCallback fcb,
322 GNUNET_PSYCSTORE_ResultCallback rcb,
327 * Callback used to return the latest value of counters for the channel master.
329 * @see GNUNET_PSYCSTORE_counters_get()
331 * @param cls Closure.
332 * @param result_code Status code for the operation:
333 * #GNUNET_OK: success, counter values are returned.
334 * #GNUNET_NO: no message has been sent to the channel yet.
335 * #GNUNET_SYSERR: an error occurred.
336 * @param max_fragment_id Latest message fragment ID, used by multicast.
337 * @param max_message_id Latest message ID, used by PSYC.
338 * @param max_group_generation Latest group generation, used by PSYC.
339 * @param max_state_message_id Latest message ID containing state modifiers that
340 * was applied to the state store. Used for the state sync process.
343 (*GNUNET_PSYCSTORE_CountersCallback) (void *cls,
345 uint64_t max_fragment_id,
346 uint64_t max_message_id,
347 uint64_t max_group_generation,
348 uint64_t max_state_message_id);
352 * Retrieve latest values of counters for a channel.
354 * The current value of counters are needed
355 * - when a channel master is restarted, so that it can continue incrementing
356 * the counters from their last value.
357 * - when a channel slave rejoins and starts the state synchronization process.
359 * @param h Handle for the PSYCstore.
360 * @param channel_key Public key that identifies the channel.
361 * @param ccb Callback to call with the result.
362 * @param ccb_cls Closure for the @a ccb callback.
364 * @return Handle that can be used to cancel the operation.
366 struct GNUNET_PSYCSTORE_OperationHandle *
367 GNUNET_PSYCSTORE_counters_get (struct GNUNET_PSYCSTORE_Handle *h,
368 struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
369 GNUNET_PSYCSTORE_CountersCallback ccb,
374 * Apply modifiers of a message to the current channel state.
376 * An error is returned if there are missing messages containing state
377 * operations before the current one.
379 * @param h Handle for the PSYCstore.
380 * @param channel_key The channel we are interested in.
381 * @param message_id ID of the message that contains the @a modifiers.
382 * @param state_delta Value of the @e state_delta PSYC header variable of the message.
383 * @param modifier_count Number of elements in the @a modifiers array.
384 * @param modifiers List of modifiers to apply.
385 * @param rcb Callback to call with the result of the operation.
386 * @param rcb_cls Closure for the @a rcb callback.
388 * @return Handle that can be used to cancel the operation.
390 struct GNUNET_PSYCSTORE_OperationHandle *
391 GNUNET_PSYCSTORE_state_modify (struct GNUNET_PSYCSTORE_Handle *h,
392 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
394 uint64_t state_delta,
395 size_t modifier_count,
396 const struct GNUNET_ENV_Modifier *modifiers,
397 GNUNET_PSYCSTORE_ResultCallback rcb,
402 * Store synchronized state.
404 * @param h Handle for the PSYCstore.
405 * @param channel_key The channel we are interested in.
406 * @param message_id ID of the message that contains the state_hash PSYC header variable.
407 * @param modifier_count Number of elements in the @a modifiers array.
408 * @param modifiers Full state to store.
409 * @param rcb Callback to call with the result of the operation.
410 * @param rcb_cls Closure for the callback.
412 * @return Handle that can be used to cancel the operation.
414 struct GNUNET_PSYCSTORE_OperationHandle *
415 GNUNET_PSYCSTORE_state_sync (struct GNUNET_PSYCSTORE_Handle *h,
416 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
418 size_t modifier_count,
419 const struct GNUNET_ENV_Modifier *modifiers,
420 GNUNET_PSYCSTORE_ResultCallback rcb,
426 * Reset the state of a channel.
428 * Delete all state variables stored for the given channel.
430 * @param h Handle for the PSYCstore.
431 * @param channel_key The channel we are interested in.
432 * @param rcb Callback to call with the result of the operation.
433 * @param rcb_cls Closure for the callback.
435 * @return Handle that can be used to cancel the operation.
437 struct GNUNET_PSYCSTORE_OperationHandle *
438 GNUNET_PSYCSTORE_state_reset (struct GNUNET_PSYCSTORE_Handle *h,
439 const struct GNUNET_CRYPTO_EddsaPublicKey
441 GNUNET_PSYCSTORE_ResultCallback rcb,
446 * Update signed values of state variables in the state store.
448 * @param h Handle for the PSYCstore.
449 * @param channel_key The channel we are interested in.
450 * @param message_id Message ID that contained the state @a hash.
451 * @param hash Hash of the serialized full state.
452 * @param rcb Callback to call with the result of the operation.
453 * @param rcb_cls Closure for the callback.
456 struct GNUNET_PSYCSTORE_OperationHandle *
457 GNUNET_PSYCSTORE_state_hash_update (struct GNUNET_PSYCSTORE_Handle *h,
458 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
460 const struct GNUNET_HashCode *hash,
461 GNUNET_PSYCSTORE_ResultCallback rcb,
466 * Function called with the value of a state variable.
468 * @param cls Closure.
469 * @param name Name of the state variable. A NULL value indicates that there are no more
470 * state variables to be returned.
471 * @param value Value of the state variable.
472 * @param value_size Number of bytes in @a value.
474 * @return #GNUNET_NO to stop calling this callback with further variables,
475 * #GNUNET_YES to continue.
478 (*GNUNET_PSYCSTORE_StateCallback) (void *cls, const char *name,
479 const void *value, size_t value_size);
483 * Retrieve the best matching state variable.
485 * @param h Handle for the PSYCstore.
486 * @param channel_key The channel we are interested in.
487 * @param name Name of variable to match, the returned variable might be less specific.
488 * @param scb Callback to return the matching state variable.
489 * @param rcb Callback to call with the result of the operation.
490 * @param cls Closure for the callbacks.
492 * @return Handle that can be used to cancel the operation.
494 struct GNUNET_PSYCSTORE_OperationHandle *
495 GNUNET_PSYCSTORE_state_get (struct GNUNET_PSYCSTORE_Handle *h,
496 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
498 GNUNET_PSYCSTORE_StateCallback scb,
499 GNUNET_PSYCSTORE_ResultCallback rcb,
504 * Retrieve all state variables for a channel with the given prefix.
506 * @param h Handle for the PSYCstore.
507 * @param channel_key The channel we are interested in.
508 * @param name_prefix Prefix of state variable names to match.
509 * @param scb Callback to return matching state variables.
510 * @param rcb Callback to call with the result of the operation.
511 * @param cls Closure for the callbacks.
513 * @return Handle that can be used to cancel the operation.
515 struct GNUNET_PSYCSTORE_OperationHandle *
516 GNUNET_PSYCSTORE_state_get_prefix (struct GNUNET_PSYCSTORE_Handle *h,
517 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
518 const char *name_prefix,
519 GNUNET_PSYCSTORE_StateCallback scb,
520 GNUNET_PSYCSTORE_ResultCallback rcb,
525 * Cancel an operation.
527 * @param op Handle for the operation to cancel.
530 GNUNET_PSYCSTORE_operation_cancel (struct GNUNET_PSYCSTORE_OperationHandle *op);
535 #if 0 /* keep Emacsens' auto-indent happy */
542 /* ifndef GNUNET_PSYCSTORE_SERVICE_H */
544 /* end of gnunet_psycstore_service.h */