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 * Flags for stored messages.
51 enum GNUNET_PSYCSTORE_MessageFlags
54 * The message contains state modifiers.
56 GNUNET_PSYCSTORE_MESSAGE_STATE = 1 << 0,
59 * The state modifiers have been applied to the state store.
61 GNUNET_PSYCSTORE_MESSAGE_STATE_APPLIED = 1 << 1,
64 * The message contains a state hash.
66 GNUNET_PSYCSTORE_MESSAGE_STATE_HASH = 1 << 2
71 * Handle for a PSYCstore
73 struct GNUNET_PSYCSTORE_Handle;
77 * Connect to the PSYCstore service.
79 * @param cfg Configuration to use.
81 * @return Handle for the connecton.
83 struct GNUNET_PSYCSTORE_Handle *
84 GNUNET_PSYCSTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
88 * Disconnect from the PSYCstore service.
90 * @param h Handle for the connection.
93 GNUNET_PSYCSTORE_disconnect (struct GNUNET_PSYCSTORE_Handle *h);
97 * Handle for an operation on the PSYCSTORE (useful to cancel the operation).
99 struct GNUNET_PSYCSTORE_OperationHandle;
103 * Function called with the result of an asynchronous operation.
105 * @param result #GNUNET_SYSERR on error,
106 * #GNUNET_YES on success or if the peer was a member,
107 * #GNUNET_NO if the peer was not a member
110 (*GNUNET_PSYCSTORE_ResultCallback) (void *cls,
112 const char *err_msg);
116 * Store join/leave events for a PSYC channel in order to be able to answer
117 * membership test queries later.
119 * @param h Handle for the PSYCstore.
120 * @param channel_key The channel where the event happened.
121 * @param slave_key Public key of joining/leaving slave.
122 * @param did_join #GNUNET_YES on join, #GNUNET_NO on part.
123 * @param announced_at ID of the message that announced the membership change.
124 * @param effective_since Message ID this membership change is in effect since.
125 * For joins it is <= announced_at, for parts it is always 0.
126 * @param group_generation In case of a part, the last group generation the
127 * slave has access to. It has relevance when a larger message have
128 * fragments with different group generations.
129 * @param rcb Callback to call with the result of the storage operation.
130 * @param rcb_cls Closure for the callback.
132 * @return Operation handle that can be used to cancel the operation.
134 struct GNUNET_PSYCSTORE_OperationHandle *
135 GNUNET_PSYCSTORE_membership_store (struct GNUNET_PSYCSTORE_Handle *h,
136 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
137 const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
139 uint64_t announced_at,
140 uint64_t effective_since,
141 uint64_t group_generation,
142 GNUNET_PSYCSTORE_ResultCallback rcb,
147 * Test if a member was admitted to the channel at the given message ID.
149 * This is useful when relaying and replaying messages to check if a particular
150 * slave has access to the message fragment with a given group generation. It
151 * is also used when handling join requests to determine whether the slave is
152 * currently admitted to the channel.
154 * @param h Handle for the PSYCstore.
155 * @param channel_key The channel we are interested in.
156 * @param slave_key Public key of slave whose membership to check.
157 * @param message_id Message ID for which to do the membership test.
158 * @param group_generation Group generation of the fragment of the message to
159 * test. It has relevance if the message consists of multiple fragments
160 * with different group generations.
161 * FIXME: not needed if there are no overlapping messages.
162 * @param rcb Callback to call with the test result.
163 * @param rcb_cls Closure for the callback.
165 * @return Operation handle that can be used to cancel the operation.
167 struct GNUNET_PSYCSTORE_OperationHandle *
168 GNUNET_PSYCSTORE_membership_test (struct GNUNET_PSYCSTORE_Handle *h,
169 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
170 const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
172 uint64_t group_generation,
173 GNUNET_PSYCSTORE_ResultCallback rcb,
178 * Store a message fragment sent to a channel.
180 * @param h Handle for the PSYCstore.
181 * @param channel_key The channel the message belongs to.
182 * @param msg Message to store.
183 * @param psycstore_flags Flags indicating whether the PSYC message contains
185 * @param rcb Callback to call with the result of the operation.
186 * @param rcb_cls Closure for the callback.
188 * @return Handle that can be used to cancel the operation.
190 struct GNUNET_PSYCSTORE_OperationHandle *
191 GNUNET_PSYCSTORE_fragment_store (struct GNUNET_PSYCSTORE_Handle *h,
192 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
193 const struct GNUNET_MULTICAST_MessageHeader *msg,
194 enum GNUNET_PSYCSTORE_MessageFlags psycstore_flags,
195 GNUNET_PSYCSTORE_ResultCallback rcb,
200 * Function called with one message fragment, as the result of a
201 * GNUNET_PSYCSTORE_fragment_get() or GNUNET_PSYCSTORE_message_get() call.
203 * @param cls Closure.
204 * @param message The retrieved message fragment. A NULL value indicates that
205 * there are no more results to be returned.
206 * @param psycstore_flags Flags stored with the message.
208 * @return #GNUNET_NO to stop calling this callback with further fragments,
209 * #GNUNET_YES to continue.
212 (*GNUNET_PSYCSTORE_FragmentCallback) (void *cls,
213 struct GNUNET_MULTICAST_MessageHeader *message,
214 enum GNUNET_PSYCSTORE_MessageFlags psycstore_flags);
218 * Retrieve a message fragment by fragment ID.
220 * @param h Handle for the PSYCstore.
221 * @param channel_key The channel we are interested in.
222 * @param fragment_id Fragment ID to check. Use 0 to get the latest message fragment.
223 * @param fcb Callback to call with the retrieved fragment.
224 * @param rcb Callback to call with the result of the operation.
225 * @param cls Closure for the callbacks.
227 * @return Handle that can be used to cancel the operation.
229 struct GNUNET_PSYCSTORE_OperationHandle *
230 GNUNET_PSYCSTORE_fragment_get (struct GNUNET_PSYCSTORE_Handle *h,
231 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
232 uint64_t fragment_id,
233 GNUNET_PSYCSTORE_FragmentCallback fcb,
234 GNUNET_PSYCSTORE_ResultCallback rcb,
239 * Retrieve all fragments of a message.
241 * @param h Handle for the PSYCstore.
242 * @param channel_key The channel we are interested in.
243 * @param message_id Message ID to check. Use 0 to get the latest message.
244 * @param fcb Callback to call with the retrieved fragments.
245 * @param rcb Callback to call with the result of the operation.
246 * @param cls Closure for the callbacks.
248 * @return Handle that can be used to cancel the operation.
250 struct GNUNET_PSYCSTORE_OperationHandle *
251 GNUNET_PSYCSTORE_message_get (struct GNUNET_PSYCSTORE_Handle *h,
252 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
254 GNUNET_PSYCSTORE_FragmentCallback fcb,
255 GNUNET_PSYCSTORE_ResultCallback rcb,
260 * Retrieve a fragment of message specified by its message ID and fragment
263 * @param h Handle for the PSYCstore.
264 * @param channel_key The channel we are interested in.
265 * @param message_id Message ID to check. Use 0 to get the latest message.
266 * @param fragment_offset Offset of the fragment to retrieve.
267 * @param fcb Callback to call with the retrieved fragments.
268 * @param rcb Callback to call with the result of the operation.
269 * @param cls Closure for the callbacks.
271 * @return Handle that can be used to cancel the operation.
273 struct GNUNET_PSYCSTORE_OperationHandle *
274 GNUNET_PSYCSTORE_message_get_fragment (struct GNUNET_PSYCSTORE_Handle *h,
275 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
277 uint64_t fragment_offset,
278 GNUNET_PSYCSTORE_FragmentCallback fcb,
279 GNUNET_PSYCSTORE_ResultCallback rcb,
284 * Callback used to return the latest value of counters for the channel master.
286 * @see GNUNET_PSYCSTORE_counters_get()
288 * @param cls Closure.
289 * @param result_code Status code for the operation:
290 * #GNUNET_OK: success, counter values are returned.
291 * #GNUNET_NO: no message has been sent to the channel yet.
292 * #GNUNET_SYSERR: an error occurred.
293 * @param max_fragment_id Latest message fragment ID, used by multicast.
294 * @param max_message_id Latest message ID, used by PSYC.
295 * @param max_group_generation Latest group generation, used by PSYC.
296 * @param max_state_message_id Latest message ID containing state modifiers that
297 * was applied to the state store. Used for the state sync process.
300 (*GNUNET_PSYCSTORE_CountersCallback) (void *cls,
302 uint64_t max_fragment_id,
303 uint64_t max_message_id,
304 uint64_t max_group_generation,
305 uint64_t max_state_message_id);
309 * Retrieve latest values of counters for a channel.
311 * The current value of counters are needed
312 * - when a channel master is restarted, so that it can continue incrementing
313 * the counters from their last value.
314 * - when a channel slave rejoins and starts the state synchronization process.
316 * @param h Handle for the PSYCstore.
317 * @param channel_key Public key that identifies the channel.
318 * @param ccb Callback to call with the result.
319 * @param ccb_cls Closure for the @a ccb callback.
321 * @return Handle that can be used to cancel the operation.
323 struct GNUNET_PSYCSTORE_OperationHandle *
324 GNUNET_PSYCSTORE_counters_get (struct GNUNET_PSYCSTORE_Handle *h,
325 struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
326 GNUNET_PSYCSTORE_CountersCallback ccb,
331 * Apply modifiers of a message to the current channel state.
333 * An error is returned if there are missing messages containing state
334 * operations before the current one.
336 * @param h Handle for the PSYCstore.
337 * @param channel_key The channel we are interested in.
338 * @param message_id ID of the message that contains the @a modifiers.
339 * @param state_delta Value of the @e state_delta PSYC header variable of the message.
340 * @param modifier_count Number of elements in the @a modifiers array.
341 * @param modifiers List of modifiers to apply.
342 * @param rcb Callback to call with the result of the operation.
343 * @param rcb_cls Closure for the @a rcb callback.
345 * @return Handle that can be used to cancel the operation.
347 struct GNUNET_PSYCSTORE_OperationHandle *
348 GNUNET_PSYCSTORE_state_modify (struct GNUNET_PSYCSTORE_Handle *h,
349 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
351 uint64_t state_delta,
352 size_t modifier_count,
353 const struct GNUNET_ENV_Modifier *modifiers,
354 GNUNET_PSYCSTORE_ResultCallback rcb,
359 * Store synchronized state.
361 * @param h Handle for the PSYCstore.
362 * @param channel_key The channel we are interested in.
363 * @param message_id ID of the message that contains the state_hash PSYC header variable.
364 * @param modifier_count Number of elements in the @a modifiers array.
365 * @param modifiers Full state to store.
366 * @param rcb Callback to call with the result of the operation.
367 * @param rcb_cls Closure for the callback.
369 * @return Handle that can be used to cancel the operation.
371 struct GNUNET_PSYCSTORE_OperationHandle *
372 GNUNET_PSYCSTORE_state_sync (struct GNUNET_PSYCSTORE_Handle *h,
373 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
375 size_t modifier_count,
376 const struct GNUNET_ENV_Modifier *modifiers,
377 GNUNET_PSYCSTORE_ResultCallback rcb,
383 * Reset the state of a channel.
385 * Delete all state variables stored for the given channel.
387 * @param h Handle for the PSYCstore.
388 * @param channel_key The channel we are interested in.
389 * @param rcb Callback to call with the result of the operation.
390 * @param rcb_cls Closure for the callback.
392 * @return Handle that can be used to cancel the operation.
394 struct GNUNET_PSYCSTORE_OperationHandle *
395 GNUNET_PSYCSTORE_state_reset (struct GNUNET_PSYCSTORE_Handle *h,
396 const struct GNUNET_CRYPTO_EddsaPublicKey
398 GNUNET_PSYCSTORE_ResultCallback rcb,
403 * Update signed values of state variables in the state store.
405 * @param h Handle for the PSYCstore.
406 * @param channel_key The channel we are interested in.
407 * @param message_id Message ID that contained the state @a hash.
408 * @param hash Hash of the serialized full state.
409 * @param rcb Callback to call with the result of the operation.
410 * @param rcb_cls Closure for the callback.
413 struct GNUNET_PSYCSTORE_OperationHandle *
414 GNUNET_PSYCSTORE_state_hash_update (struct GNUNET_PSYCSTORE_Handle *h,
415 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
417 const struct GNUNET_HashCode *hash,
418 GNUNET_PSYCSTORE_ResultCallback rcb,
423 * Function called with the value of a state variable.
425 * @param cls Closure.
426 * @param name Name of the state variable. A NULL value indicates that there are no more
427 * state variables to be returned.
428 * @param value Value of the state variable.
429 * @param value_size Number of bytes in @a value.
431 * @return #GNUNET_NO to stop calling this callback with further variables,
432 * #GNUNET_YES to continue.
435 (*GNUNET_PSYCSTORE_StateCallback) (void *cls, const char *name,
436 const void *value, size_t value_size);
440 * Retrieve the best matching state variable.
442 * @param h Handle for the PSYCstore.
443 * @param channel_key The channel we are interested in.
444 * @param name Name of variable to match, the returned variable might be less specific.
445 * @param scb Callback to return the matching state variable.
446 * @param rcb Callback to call with the result of the operation.
447 * @param cls Closure for the callbacks.
449 * @return Handle that can be used to cancel the operation.
451 struct GNUNET_PSYCSTORE_OperationHandle *
452 GNUNET_PSYCSTORE_state_get (struct GNUNET_PSYCSTORE_Handle *h,
453 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
455 GNUNET_PSYCSTORE_StateCallback scb,
456 GNUNET_PSYCSTORE_ResultCallback rcb,
461 * Retrieve all state variables for a channel with the given prefix.
463 * @param h Handle for the PSYCstore.
464 * @param channel_key The channel we are interested in.
465 * @param name_prefix Prefix of state variable names to match.
466 * @param scb Callback to return matching state variables.
467 * @param rcb Callback to call with the result of the operation.
468 * @param cls Closure for the callbacks.
470 * @return Handle that can be used to cancel the operation.
472 struct GNUNET_PSYCSTORE_OperationHandle *
473 GNUNET_PSYCSTORE_state_get_prefix (struct GNUNET_PSYCSTORE_Handle *h,
474 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
475 const char *name_prefix,
476 GNUNET_PSYCSTORE_StateCallback scb,
477 GNUNET_PSYCSTORE_ResultCallback rcb,
482 * Cancel an operation.
484 * @param op Handle for the operation to cancel.
487 GNUNET_PSYCSTORE_operation_cancel (struct GNUNET_PSYCSTORE_OperationHandle *op);
492 #if 0 /* keep Emacsens' auto-indent happy */
499 /* ifndef GNUNET_PSYCSTORE_SERVICE_H */
501 /* end of gnunet_psycstore_service.h */