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_EccPublicSignKey *channel_key,
137 const struct GNUNET_CRYPTO_EccPublicSignKey *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 * @param rcb Callback to call with the test result.
162 * @param rcb_cls Closure for the callback.
164 * @return Operation handle that can be used to cancel the operation.
166 struct GNUNET_PSYCSTORE_OperationHandle *
167 GNUNET_PSYCSTORE_membership_test (struct GNUNET_PSYCSTORE_Handle *h,
168 const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key,
169 const struct GNUNET_CRYPTO_EccPublicSignKey *slave_key,
171 uint64_t group_generation,
172 GNUNET_PSYCSTORE_ResultCallback rcb,
177 * Store a message fragment sent to a channel.
179 * @param h Handle for the PSYCstore.
180 * @param channel_key The channel the message belongs to.
181 * @param message Message to store.
182 * @param psycstore_flags Flags indicating whether the PSYC message contains
184 * @param rcb Callback to call with the result of the operation.
185 * @param rcb_cls Closure for the callback.
187 * @return Handle that can be used to cancel the operation.
189 struct GNUNET_PSYCSTORE_OperationHandle *
190 GNUNET_PSYCSTORE_fragment_store (struct GNUNET_PSYCSTORE_Handle *h,
191 const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key,
192 const struct GNUNET_MULTICAST_MessageHeader *message,
193 uint32_t psycstore_flags,
194 GNUNET_PSYCSTORE_ResultCallback rcb,
199 * Function called with one message fragment, as the result of a
200 * GNUNET_PSYCSTORE_fragment_get() or GNUNET_PSYCSTORE_message_get() call.
202 * @param cls Closure.
203 * @param message The retrieved message fragment. A NULL value indicates that
204 * there are no more results to be returned.
205 * @param flags Flags stored with the message.
207 * @return #GNUNET_NO to stop calling this callback with further fragments,
208 * #GNUNET_YES to continue.
211 (*GNUNET_PSYCSTORE_FragmentCallback) (void *cls,
212 struct GNUNET_MULTICAST_MessageHeader *message,
213 enum GNUNET_PSYCSTORE_MessageFlags flags);
217 * Retrieve a message fragment by fragment ID.
219 * @param h Handle for the PSYCstore.
220 * @param channel_key The channel we are interested in.
221 * @param fragment_id Fragment ID to check. Use 0 to get the latest message fragment.
222 * @param cb Callback to call with the retrieved fragment.
223 * @param cb_cls Closure for the callback.
225 * @return Handle that can be used to cancel the operation.
227 struct GNUNET_PSYCSTORE_OperationHandle *
228 GNUNET_PSYCSTORE_fragment_get (struct GNUNET_PSYCSTORE_Handle *h,
229 const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key,
230 uint64_t fragment_id,
231 GNUNET_PSYCSTORE_FragmentCallback cb,
236 * Retrieve all fragments of a message.
238 * @param h Handle for the PSYCstore.
239 * @param channel_key The channel we are interested in.
240 * @param message_id Message ID to check. Use 0 to get the latest message.
241 * @param cb Callback to call with the retrieved fragments.
242 * @param cb_cls Closure for the callback.
244 * @return Handle that can be used to cancel the operation.
246 struct GNUNET_PSYCSTORE_OperationHandle *
247 GNUNET_PSYCSTORE_message_get (struct GNUNET_PSYCSTORE_Handle *h,
248 const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key,
250 GNUNET_PSYCSTORE_FragmentCallback cb,
255 * Retrieve a fragment of message specified by its message ID and fragment
258 * @param h Handle for the PSYCstore.
259 * @param channel_key The channel we are interested in.
260 * @param message_id Message ID to check. Use 0 to get the latest message.
261 * @param fragment_offset Offset of the fragment to retrieve.
262 * @param cb Callback to call with the retrieved fragments.
263 * @param cb_cls Closure for the callback.
265 * @return Handle that can be used to cancel the operation.
267 struct GNUNET_PSYCSTORE_OperationHandle *
268 GNUNET_PSYCSTORE_message_get_fragment (struct GNUNET_PSYCSTORE_Handle *h,
269 const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key,
271 uint64_t fragment_offset,
272 GNUNET_PSYCSTORE_FragmentCallback cb,
277 * Callback used to return the latest value of counters for the channel master.
279 * @see GNUNET_PSYCSTORE_counters_get_master()
281 * @param cls Closure.
282 * @param fragment_id Latest message fragment ID, used by multicast.
283 * @param message_id Latest message ID, used by PSYC.
284 * @param group_generation Latest group generation, used by PSYC.
287 (*GNUNET_PSYCSTORE_MasterCountersCallback) (void *cls,
288 uint64_t fragment_id,
290 uint64_t group_generation);
294 * Callback used to return the latest value of counters for a channel slave.
296 * @see GNUNET_PSYCSTORE_counters_get_slave()
298 * @param cls Closure.
299 * @param max_state_msg_id Latest message ID containing state modifiers that was
300 * applied to the state store. Used for the state sync process.
303 (*GNUNET_PSYCSTORE_SlaveCountersCallback) (void *cls,
304 uint64_t max_state_msg_id);
308 * Retrieve latest values of counters for a channel master.
310 * The current value of counters are needed when a channel master is restarted,
311 * so that it can continue incrementing the counters from their last value.
313 * @param h Handle for the PSYCstore.
314 * @param channel_key Public key that identifies the channel.
315 * @param cb Callback to call with the result.
316 * @param cb_cls Closure for the callback.
320 struct GNUNET_PSYCSTORE_OperationHandle *
321 GNUNET_PSYCSTORE_counters_get_master (struct GNUNET_PSYCSTORE_Handle *h,
322 struct GNUNET_CRYPTO_EccPublicSignKey *channel_key,
323 GNUNET_PSYCSTORE_MasterCountersCallback *cb,
328 * Retrieve latest values of counters for a channel slave.
330 * The current value of counters are needed when a channel slave rejoins
331 * and starts the state synchronization process.
333 * @param h Handle for the PSYCstore.
334 * @param channel_key Public key that identifies the channel.
335 * @param cb Callback to call with the result.
336 * @param cb_cls Closure for the callback.
340 struct GNUNET_PSYCSTORE_OperationHandle *
341 GNUNET_PSYCSTORE_counters_get_slave (struct GNUNET_PSYCSTORE_Handle *h,
342 struct GNUNET_CRYPTO_EccPublicSignKey *channel_key,
343 GNUNET_PSYCSTORE_SlaveCountersCallback *cb,
348 * Apply modifiers of a message to the current channel state.
350 * An error is returned if there are missing messages containing state
351 * operations before the current one.
353 * @param h Handle for the PSYCstore.
354 * @param channel_key The channel we are interested in.
355 * @param message_id ID of the message that contains the @a modifiers.
356 * @param state_delta Value of the _state_delta PSYC header variable of the message.
357 * @param modifier_count Number of elements in the @a modifiers array.
358 * @param modifiers List of modifiers to apply.
359 * @param rcb Callback to call with the result of the operation.
360 * @param rcb_cls Closure for the callback.
362 * @return Handle that can be used to cancel the operation.
364 struct GNUNET_PSYCSTORE_OperationHandle *
365 GNUNET_PSYCSTORE_state_modify (struct GNUNET_PSYCSTORE_Handle *h,
366 const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key,
368 uint64_t state_delta,
369 size_t modifier_count,
370 const struct GNUNET_ENV_Modifier *modifiers,
371 GNUNET_PSYCSTORE_ResultCallback rcb,
376 * Reset the state of a channel.
378 * Delete all state variables stored for the given channel.
380 * @param h Handle for the PSYCstore.
381 * @param channel_key The channel we are interested in.
382 * @param rcb Callback to call with the result of the operation.
383 * @param rcb_cls Closure for the callback.
385 * @return Handle that can be used to cancel the operation.
387 struct GNUNET_PSYCSTORE_Handle *
388 GNUNET_PSYCSTORE_state_reset (struct GNUNET_PSYCSTORE_Handle *h,
389 const struct GNUNET_CRYPTO_EccPublicSignKey
391 GNUNET_PSYCSTORE_ResultCallback rcb,
396 * Update signed values of state variables in the state store.
398 * @param h Handle for the PSYCstore.
399 * @param channel_key The channel we are interested in.
400 * @param message_id Message ID that contained the state @a hash.
401 * @param hash Hash of the serialized full state.
402 * @param rcb Callback to call with the result of the operation.
403 * @param rcb_cls Closure for the callback.
406 struct GNUNET_PSYCSTORE_OperationHandle *
407 GNUNET_PSYCSTORE_state_hash_update (struct GNUNET_PSYCSTORE_Handle *h,
408 const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key,
410 const struct GNUNET_HashCode *hash,
411 GNUNET_PSYCSTORE_ResultCallback rcb,
416 * Function called with the value of a state variable.
418 * @param cls Closure.
419 * @param name Name of the state variable. A NULL value indicates that there are no more
420 * state variables to be returned.
421 * @param value Value of the state variable.
422 * @param value_size Number of bytes in @a value.
424 * @return #GNUNET_NO to stop calling this callback with further variables,
425 * #GNUNET_YES to continue.
428 (*GNUNET_PSYCSTORE_StateCallback) (void *cls,
435 * Retrieve the best matching state variable.
437 * @param h Handle for the PSYCstore.
438 * @param channel_key The channel we are interested in.
439 * @param name Name of variable to match, the returned variable might be less specific.
440 * @param cb Callback to return matching state variables.
441 * @param cb_cls Closure for the callback.
443 * @return Handle that can be used to cancel the operation.
445 struct GNUNET_PSYCSTORE_OperationHandle *
446 GNUNET_PSYCSTORE_state_get (struct GNUNET_PSYCSTORE_Handle *h,
447 const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key,
449 GNUNET_PSYCSTORE_StateCallback cb,
454 * Retrieve all state variables for a channel with the given prefix.
456 * @param h Handle for the PSYCstore.
457 * @param channel_key The channel we are interested in.
458 * @param name_prefix Prefix of state variable names to match.
459 * @param cb Callback to return matching state variables.
460 * @param cb_cls Closure for the callback.
462 * @return Handle that can be used to cancel the operation.
464 struct GNUNET_PSYCSTORE_OperationHandle *
465 GNUNET_PSYCSTORE_state_get_all (struct GNUNET_PSYCSTORE_Handle *h,
466 const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key,
467 const char *name_prefix,
468 GNUNET_PSYCSTORE_StateCallback cb,
473 * Cancel an operation.
475 * @param op Handle for the operation to cancel.
478 GNUNET_PSYCSTORE_operation_cancel (struct GNUNET_PSYCSTORE_OperationHandle *op);
483 #if 0 /* keep Emacsens' auto-indent happy */
490 /* ifndef GNUNET_PSYCSTORE_SERVICE_H */
492 /* end of gnunet_psycstore_service.h */