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.
124 * @param h Handle for the PSYCstore.
125 * @param channel_key The channel where the event happened.
126 * @param slave_key Public key of joining/leaving slave.
127 * @param did_join #GNUNET_YES on join, #GNUNET_NO on part.
128 * @param announced_at ID of the message that announced the membership change.
129 * @param effective_since Message ID this membership change is in effect since.
130 * For joins it is <= announced_at, for parts it is always 0.
131 * @param group_generation In case of a part, the last group generation the
132 * slave has access to. It has relevance when a larger message have
133 * fragments with different group generations.
134 * @param rcb Callback to call with the result of the storage operation.
135 * @param rcb_cls Closure for the callback.
137 * @return Operation handle that can be used to cancel the operation.
139 struct GNUNET_PSYCSTORE_OperationHandle *
140 GNUNET_PSYCSTORE_membership_store (struct GNUNET_PSYCSTORE_Handle *h,
141 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
142 const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
144 uint64_t announced_at,
145 uint64_t effective_since,
146 uint64_t group_generation,
147 GNUNET_PSYCSTORE_ResultCallback rcb,
152 * Test if a member was admitted to the channel at the given message ID.
154 * This is useful when relaying and replaying messages to check if a particular
155 * slave has access to the message fragment with a given group generation. It
156 * is also used when handling join requests to determine whether the slave is
157 * currently admitted to the channel.
159 * @param h Handle for the PSYCstore.
160 * @param channel_key The channel we are interested in.
161 * @param slave_key Public key of slave whose membership to check.
162 * @param message_id Message ID for which to do the membership test.
163 * @param group_generation Group generation of the fragment of the message to
164 * test. It has relevance if the message consists of multiple fragments
165 * with different group generations.
166 * FIXME: not needed if there are no overlapping messages.
167 * @param rcb Callback to call with the test result.
168 * @param rcb_cls Closure for the callback.
170 * @return Operation handle that can be used to cancel the operation.
172 struct GNUNET_PSYCSTORE_OperationHandle *
173 GNUNET_PSYCSTORE_membership_test (struct GNUNET_PSYCSTORE_Handle *h,
174 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
175 const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
177 uint64_t group_generation,
178 GNUNET_PSYCSTORE_ResultCallback rcb,
183 * Store a message fragment sent to a channel.
185 * @param h Handle for the PSYCstore.
186 * @param channel_key The channel the message belongs to.
187 * @param msg Message to store.
188 * @param psycstore_flags Flags indicating whether the PSYC message contains
190 * @param rcb Callback to call with the result of the operation.
191 * @param rcb_cls Closure for the callback.
193 * @return Handle that can be used to cancel the operation.
195 struct GNUNET_PSYCSTORE_OperationHandle *
196 GNUNET_PSYCSTORE_fragment_store (struct GNUNET_PSYCSTORE_Handle *h,
197 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
198 const struct GNUNET_MULTICAST_MessageHeader *msg,
199 enum GNUNET_PSYCSTORE_MessageFlags psycstore_flags,
200 GNUNET_PSYCSTORE_ResultCallback rcb,
205 * Function called with one message fragment, as the result of a
206 * GNUNET_PSYCSTORE_fragment_get() or GNUNET_PSYCSTORE_message_get() call.
208 * @param cls Closure.
209 * @param message The retrieved message fragment. A NULL value indicates that
210 * there are no more results to be returned.
211 * @param psycstore_flags Flags stored with the message.
213 * @return #GNUNET_NO to stop calling this callback with further fragments,
214 * #GNUNET_YES to continue.
217 (*GNUNET_PSYCSTORE_FragmentCallback) (void *cls,
218 struct GNUNET_MULTICAST_MessageHeader *message,
219 enum GNUNET_PSYCSTORE_MessageFlags psycstore_flags);
223 * Retrieve a message fragment by fragment ID.
226 * Handle for the PSYCstore.
228 * The channel we are interested in.
230 * The slave requesting the fragment. If not NULL, a membership test is
231 * performed first and the fragment is only returned if the slave has
234 * Fragment ID to retrieve. Use 0 to get the latest message fragment.
236 * Callback to call with the retrieved fragments.
238 * Callback to call with the result of the operation.
240 * Closure for the callbacks.
242 * @return Handle that can be used to cancel the operation.
244 struct GNUNET_PSYCSTORE_OperationHandle *
245 GNUNET_PSYCSTORE_fragment_get (struct GNUNET_PSYCSTORE_Handle *h,
246 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
247 const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
248 uint64_t fragment_id,
249 GNUNET_PSYCSTORE_FragmentCallback fcb,
250 GNUNET_PSYCSTORE_ResultCallback rcb,
255 * Retrieve all fragments of a message.
258 * Handle for the PSYCstore.
260 * The channel we are interested in.
262 * The slave requesting the message. If not NULL, a membership test is
263 * performed first and the message is only returned if the slave has
266 * Message ID to retrieve. Use 0 to get the latest message.
268 * Callback to call with the retrieved fragments.
270 * Callback to call with the result of the operation.
272 * Closure for the callbacks.
274 * @return Handle that can be used to cancel the operation.
276 struct GNUNET_PSYCSTORE_OperationHandle *
277 GNUNET_PSYCSTORE_message_get (struct GNUNET_PSYCSTORE_Handle *h,
278 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
279 const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
281 GNUNET_PSYCSTORE_FragmentCallback fcb,
282 GNUNET_PSYCSTORE_ResultCallback rcb,
287 * Retrieve a fragment of message specified by its message ID and fragment
290 * @param h Handle for the PSYCstore.
291 * @param channel_key The channel we are interested in.
292 * @param message_id Message ID to check. Use 0 to get the latest message.
293 * @param fragment_offset Offset of the fragment to retrieve.
294 * @param fcb Callback to call with the retrieved fragments.
295 * @param rcb Callback to call with the result of the operation.
296 * @param cls Closure for the callbacks.
298 * @return Handle that can be used to cancel the operation.
300 struct GNUNET_PSYCSTORE_OperationHandle *
301 GNUNET_PSYCSTORE_message_get_fragment (struct GNUNET_PSYCSTORE_Handle *h,
302 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
303 const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
305 uint64_t fragment_offset,
306 GNUNET_PSYCSTORE_FragmentCallback fcb,
307 GNUNET_PSYCSTORE_ResultCallback rcb,
312 * Callback used to return the latest value of counters for the channel master.
314 * @see GNUNET_PSYCSTORE_counters_get()
316 * @param cls Closure.
317 * @param result_code Status code for the operation:
318 * #GNUNET_OK: success, counter values are returned.
319 * #GNUNET_NO: no message has been sent to the channel yet.
320 * #GNUNET_SYSERR: an error occurred.
321 * @param max_fragment_id Latest message fragment ID, used by multicast.
322 * @param max_message_id Latest message ID, used by PSYC.
323 * @param max_group_generation Latest group generation, used by PSYC.
324 * @param max_state_message_id Latest message ID containing state modifiers that
325 * was applied to the state store. Used for the state sync process.
328 (*GNUNET_PSYCSTORE_CountersCallback) (void *cls,
330 uint64_t max_fragment_id,
331 uint64_t max_message_id,
332 uint64_t max_group_generation,
333 uint64_t max_state_message_id);
337 * Retrieve latest values of counters for a channel.
339 * The current value of counters are needed
340 * - when a channel master is restarted, so that it can continue incrementing
341 * the counters from their last value.
342 * - when a channel slave rejoins and starts the state synchronization process.
344 * @param h Handle for the PSYCstore.
345 * @param channel_key Public key that identifies the channel.
346 * @param ccb Callback to call with the result.
347 * @param ccb_cls Closure for the @a ccb callback.
349 * @return Handle that can be used to cancel the operation.
351 struct GNUNET_PSYCSTORE_OperationHandle *
352 GNUNET_PSYCSTORE_counters_get (struct GNUNET_PSYCSTORE_Handle *h,
353 struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
354 GNUNET_PSYCSTORE_CountersCallback ccb,
359 * Apply modifiers of a message to the current channel state.
361 * An error is returned if there are missing messages containing state
362 * operations before the current one.
364 * @param h Handle for the PSYCstore.
365 * @param channel_key The channel we are interested in.
366 * @param message_id ID of the message that contains the @a modifiers.
367 * @param state_delta Value of the @e state_delta PSYC header variable of the message.
368 * @param modifier_count Number of elements in the @a modifiers array.
369 * @param modifiers List of modifiers to apply.
370 * @param rcb Callback to call with the result of the operation.
371 * @param rcb_cls Closure for the @a rcb callback.
373 * @return Handle that can be used to cancel the operation.
375 struct GNUNET_PSYCSTORE_OperationHandle *
376 GNUNET_PSYCSTORE_state_modify (struct GNUNET_PSYCSTORE_Handle *h,
377 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
379 uint64_t state_delta,
380 size_t modifier_count,
381 const struct GNUNET_ENV_Modifier *modifiers,
382 GNUNET_PSYCSTORE_ResultCallback rcb,
387 * Store synchronized state.
389 * @param h Handle for the PSYCstore.
390 * @param channel_key The channel we are interested in.
391 * @param message_id ID of the message that contains the state_hash PSYC header variable.
392 * @param modifier_count Number of elements in the @a modifiers array.
393 * @param modifiers Full state to store.
394 * @param rcb Callback to call with the result of the operation.
395 * @param rcb_cls Closure for the callback.
397 * @return Handle that can be used to cancel the operation.
399 struct GNUNET_PSYCSTORE_OperationHandle *
400 GNUNET_PSYCSTORE_state_sync (struct GNUNET_PSYCSTORE_Handle *h,
401 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
403 size_t modifier_count,
404 const struct GNUNET_ENV_Modifier *modifiers,
405 GNUNET_PSYCSTORE_ResultCallback rcb,
411 * Reset the state of a channel.
413 * Delete all state variables stored for the given channel.
415 * @param h Handle for the PSYCstore.
416 * @param channel_key The channel we are interested in.
417 * @param rcb Callback to call with the result of the operation.
418 * @param rcb_cls Closure for the callback.
420 * @return Handle that can be used to cancel the operation.
422 struct GNUNET_PSYCSTORE_OperationHandle *
423 GNUNET_PSYCSTORE_state_reset (struct GNUNET_PSYCSTORE_Handle *h,
424 const struct GNUNET_CRYPTO_EddsaPublicKey
426 GNUNET_PSYCSTORE_ResultCallback rcb,
431 * Update signed values of state variables in the state store.
433 * @param h Handle for the PSYCstore.
434 * @param channel_key The channel we are interested in.
435 * @param message_id Message ID that contained the state @a hash.
436 * @param hash Hash of the serialized full state.
437 * @param rcb Callback to call with the result of the operation.
438 * @param rcb_cls Closure for the callback.
441 struct GNUNET_PSYCSTORE_OperationHandle *
442 GNUNET_PSYCSTORE_state_hash_update (struct GNUNET_PSYCSTORE_Handle *h,
443 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
445 const struct GNUNET_HashCode *hash,
446 GNUNET_PSYCSTORE_ResultCallback rcb,
451 * Function called with the value of a state variable.
453 * @param cls Closure.
454 * @param name Name of the state variable. A NULL value indicates that there are no more
455 * state variables to be returned.
456 * @param value Value of the state variable.
457 * @param value_size Number of bytes in @a value.
459 * @return #GNUNET_NO to stop calling this callback with further variables,
460 * #GNUNET_YES to continue.
463 (*GNUNET_PSYCSTORE_StateCallback) (void *cls, const char *name,
464 const void *value, size_t value_size);
468 * Retrieve the best matching state variable.
470 * @param h Handle for the PSYCstore.
471 * @param channel_key The channel we are interested in.
472 * @param name Name of variable to match, the returned variable might be less specific.
473 * @param scb Callback to return the matching state variable.
474 * @param rcb Callback to call with the result of the operation.
475 * @param cls Closure for the callbacks.
477 * @return Handle that can be used to cancel the operation.
479 struct GNUNET_PSYCSTORE_OperationHandle *
480 GNUNET_PSYCSTORE_state_get (struct GNUNET_PSYCSTORE_Handle *h,
481 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
483 GNUNET_PSYCSTORE_StateCallback scb,
484 GNUNET_PSYCSTORE_ResultCallback rcb,
489 * Retrieve all state variables for a channel with the given prefix.
491 * @param h Handle for the PSYCstore.
492 * @param channel_key The channel we are interested in.
493 * @param name_prefix Prefix of state variable names to match.
494 * @param scb Callback to return matching state variables.
495 * @param rcb Callback to call with the result of the operation.
496 * @param cls Closure for the callbacks.
498 * @return Handle that can be used to cancel the operation.
500 struct GNUNET_PSYCSTORE_OperationHandle *
501 GNUNET_PSYCSTORE_state_get_prefix (struct GNUNET_PSYCSTORE_Handle *h,
502 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
503 const char *name_prefix,
504 GNUNET_PSYCSTORE_StateCallback scb,
505 GNUNET_PSYCSTORE_ResultCallback rcb,
510 * Cancel an operation.
512 * @param op Handle for the operation to cancel.
515 GNUNET_PSYCSTORE_operation_cancel (struct GNUNET_PSYCSTORE_OperationHandle *op);
520 #if 0 /* keep Emacsens' auto-indent happy */
527 /* ifndef GNUNET_PSYCSTORE_SERVICE_H */
529 /* end of gnunet_psycstore_service.h */