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 * Handle for a PSYCstore
51 struct GNUNET_PSYCSTORE_Handle;
55 * Connect to the PSYCstore service.
57 * @param cfg Configuration to use.
59 * @return Handle for the connecton.
61 struct GNUNET_PSYCSTORE_Handle *
62 GNUNET_PSYCSTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
66 * Disconnect from the PSYCstore service.
68 * @param h Handle for the connection.
71 GNUNET_PSYCSTORE_disconnect (struct GNUNET_PSYCSTORE_Handle *h);
75 * Handle for an operation on the PSYCSTORE (useful to cancel the operation).
77 struct GNUNET_PSYCSTORE_OperationHandle;
81 * Function called with the result of an asynchronous operation.
83 * @param result #GNUNET_SYSERR on error,
84 * #GNUNET_YES on success or if the peer was a member,
85 * #GNUNET_NO if the peer was not a member
88 (*GNUNET_PSYCSTORE_ResultCallback) (void *cls,
94 * Store join/leave events for a PSYC channel in order to be able to answer
95 * membership test queries later.
97 * @param h Handle for the PSYCstore.
98 * @param channel_key The channel where the event happened.
99 * @param slave_key Public key of joining/leaving slave.
100 * @param did_join #GNUNET_YES on join, #GNUNET_NO on part.
101 * @param announced_at ID of the message that announced the membership change.
102 * @param effective_since Message ID this membership change is in effect since.
103 * For joins it is <= announced_at, for parts it is always 0.
104 * @param group_generation In case of a part, the last group generation the
105 * slave has access to. It has relevance when a larger message have
106 * fragments with different group generations.
107 * @param rcb Callback to call with the result of the storage operation.
108 * @param rcb_cls Closure for the callback.
110 * @return Operation handle that can be used to cancel the operation.
112 struct GNUNET_PSYCSTORE_OperationHandle *
113 GNUNET_PSYCSTORE_membership_store (struct GNUNET_PSYCSTORE_Handle *h,
114 const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
115 const struct GNUNET_CRYPTO_EccPublicKey *slave_key,
117 uint64_t announced_at,
118 uint64_t effective_since,
119 uint64_t group_generation,
120 GNUNET_PSYCSTORE_ResultCallback rcb,
125 * Test if a member was admitted to the channel at the given message ID.
127 * This is useful when relaying and replaying messages to check if a particular
128 * slave has access to the message fragment with a given group generation. It
129 * is also used when handling join requests to determine whether the slave is
130 * currently admitted to the channel.
132 * @param h Handle for the PSYCstore.
133 * @param channel_key The channel we are interested in.
134 * @param slave_key Public key of slave whose membership to check.
135 * @param message_id Message ID for which to do the membership test.
136 * @param group_generation Group generation of the fragment of the message to
137 * test. It has relevance if the message consists of multiple fragments
138 * with different group generations.
139 * @param rcb Callback to call with the test result.
140 * @param rcb_cls Closure for the callback.
142 * @return Operation handle that can be used to cancel the operation.
144 struct GNUNET_PSYCSTORE_OperationHandle *
145 GNUNET_PSYCSTORE_membership_test (struct GNUNET_PSYCSTORE_Handle *h,
146 const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
147 const struct GNUNET_CRYPTO_EccPublicKey *slave_key,
149 uint64_t group_generation,
150 GNUNET_PSYCSTORE_ResultCallback rcb,
155 * Store a message fragment sent to a channel.
157 * @param h Handle for the PSYCstore.
158 * @param channel_key The channel the message belongs to.
159 * @param message Message to store.
160 * @param rcb Callback to call with the result of the operation.
161 * @param rcb_cls Closure for the callback.
163 * @return Handle that can be used to cancel the operation.
165 struct GNUNET_PSYCSTORE_OperationHandle *
166 GNUNET_PSYCSTORE_fragment_store (struct GNUNET_PSYCSTORE_Handle *h,
167 const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
168 const struct GNUNET_MULTICAST_MessageHeader *message,
169 GNUNET_PSYCSTORE_ResultCallback rcb,
174 * Function called with one message fragment, as the result of a
175 * GNUNET_PSYCSTORE_fragment_get() or GNUNET_PSYCSTORE_message_get() call.
177 * @param cls Closure.
178 * @param message The retrieved message fragment. A NULL value indicates that
179 * there are no more results to be returned.
180 * @param flags Message flags indicating fragmentation status.
183 (*GNUNET_PSYCSTORE_FragmentCallback) (void *cls,
184 const struct GNUNET_MULTICAST_MessageHeader *message,
185 enum GNUNET_PSYC_MessageFlags flags);
189 * Retrieve a message fragment by fragment ID.
191 * @param h Handle for the PSYCstore.
192 * @param channel_key The channel we are interested in.
193 * @param fragment_id Fragment ID to check. Use 0 to get the latest message fragment.
194 * @param cb Callback to call with the retrieved fragment.
195 * @param cb_cls Closure for the callback.
197 * @return Handle that can be used to cancel the operation.
199 struct GNUNET_PSYCSTORE_OperationHandle *
200 GNUNET_PSYCSTORE_fragment_get (struct GNUNET_PSYCSTORE_Handle *h,
201 const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
202 uint64_t fragment_id,
203 GNUNET_PSYCSTORE_FragmentCallback cb,
208 * Retrieve all fragments of a message.
210 * @param h Handle for the PSYCstore.
211 * @param channel_key The channel we are interested in.
212 * @param message_id Message ID to check. Use 0 to get the latest message.
213 * @param cb Callback to call with the retrieved fragments.
214 * @param cb_cls Closure for the callback.
216 * @return Handle that can be used to cancel the operation.
218 struct GNUNET_PSYCSTORE_OperationHandle *
219 GNUNET_PSYCSTORE_message_get (struct GNUNET_PSYCSTORE_Handle *h,
220 const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
222 GNUNET_PSYCSTORE_FragmentCallback cb,
227 * Retrieve a fragment of message specified by its message ID and fragment offset.
229 * @param h Handle for the PSYCstore.
230 * @param channel_key The channel we are interested in.
231 * @param message_id Message ID to check. Use 0 to get the latest message.
232 * @param fragment_offset Offset of the fragment to retrieve.
233 * @param cb Callback to call with the retrieved fragments.
234 * @param cb_cls Closure for the callback.
236 * @return Handle that can be used to cancel the operation.
238 struct GNUNET_PSYCSTORE_OperationHandle *
239 GNUNET_PSYCSTORE_message_get_fragment (struct GNUNET_PSYCSTORE_Handle *h,
240 const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
242 uint64_t fragment_offset,
243 GNUNET_PSYCSTORE_FragmentCallback cb,
248 * Callback used to return the latest value of counters for the channel master.
250 * @see GNUNET_PSYCSTORE_counters_get_master()
252 * @param cls Closure.
253 * @param fragment_id Latest message fragment ID, used by multicast.
254 * @param message_id Latest message ID, used by PSYC.
255 * @param group_generation Latest group generation, used by PSYC.
258 (*GNUNET_PSYCSTORE_MasterCountersCallback) (void *cls,
259 uint64_t fragment_id,
261 uint64_t group_generation);
265 * Callback used to return the latest value of counters for a channel slave.
267 * @see GNUNET_PSYCSTORE_counters_get_slave()
269 * @param cls Closure.
270 * @param max_state_msg_id Latest message ID containing state modifiers that was applied to the state store. Used for the state sync process.
273 (*GNUNET_PSYCSTORE_SlaveCountersCallback) (void *cls,
274 uint64_t max_state_msg_id);
278 * Retrieve latest values of counters for a channel master.
280 * The current value of counters are needed when a channel master is restarted,
281 * so that it can continue incrementing the counters from their last value.
283 * @param h Handle for the PSYCstore.
284 * @param channel_key Public key that identifies the channel.
285 * @param cb Callback to call with the result.
286 * @param cb_cls Closure for the callback.
290 struct GNUNET_PSYCSTORE_OperationHandle *
291 GNUNET_PSYCSTORE_counters_get_master (struct GNUNET_PSYCSTORE_Handle *h,
292 struct GNUNET_CRYPTO_EccPublicKey *channel_key,
293 GNUNET_PSYCSTORE_MasterCountersCallback *cb,
298 * Retrieve latest values of counters for a channel slave.
300 * The current value of counters are needed when a channel slave rejoins
301 * and starts the state synchronization process.
303 * @param h Handle for the PSYCstore.
304 * @param channel_key Public key that identifies the channel.
305 * @param cb Callback to call with the result.
306 * @param cb_cls Closure for the callback.
310 struct GNUNET_PSYCSTORE_OperationHandle *
311 GNUNET_PSYCSTORE_counters_get_slave (struct GNUNET_PSYCSTORE_Handle *h,
312 struct GNUNET_CRYPTO_EccPublicKey *channel_key,
313 GNUNET_PSYCSTORE_SlaveCountersCallback *cb,
318 * Apply modifiers of a message to the current channel state.
320 * An error is returned if there are missing messages containing state
321 * operations before the current one.
323 * @param h Handle for the PSYCstore.
324 * @param channel_key The channel we are interested in.
325 * @param message_id ID of the message that contains the @a modifiers.
326 * @param state_delta Value of the _state_delta PSYC header variable of the message.
327 * @param modifier_count Number of elements in the @a modifiers array.
328 * @param modifiers List of modifiers to apply.
329 * @param rcb Callback to call with the result of the operation.
330 * @param rcb_cls Closure for the callback.
332 * @return Handle that can be used to cancel the operation.
334 struct GNUNET_PSYCSTORE_OperationHandle *
335 GNUNET_PSYCSTORE_state_modify (struct GNUNET_PSYCSTORE_Handle *h,
336 const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
338 uint64_t state_delta,
339 size_t modifier_count,
340 const struct GNUNET_ENV_Modifier *modifiers,
341 GNUNET_PSYCSTORE_ResultCallback rcb,
346 * Update signed values of state variables in the state store.
348 * @param h Handle for the PSYCstore.
349 * @param channel_key The channel we are interested in.
350 * @param message_id Message ID that contained the state @a hash.
351 * @param hash Hash of the serialized full state.
352 * @param rcb Callback to call with the result of the operation.
353 * @param rcb_cls Closure for the callback.
356 struct GNUNET_PSYCSTORE_OperationHandle *
357 GNUNET_PSYCSTORE_state_hash_update (struct GNUNET_PSYCSTORE_Handle *h,
358 const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
360 const struct GNUNET_HashCode *hash,
361 GNUNET_PSYCSTORE_ResultCallback rcb,
366 * Function called with the value of a state variable.
368 * @param cls Closure.
369 * @param name Name of the state variable. A NULL value indicates that there are no more
370 * state variables to be returned.
371 * @param value_size Number of bytes in @a value.
372 * @param value Value of the state variable.
376 (*GNUNET_PSYCSTORE_StateCallback) (void *cls,
383 * Retrieve the best matching state variable.
385 * @param h Handle for the PSYCstore.
386 * @param channel_key The channel we are interested in.
387 * @param name Name of variable to match, the returned variable might be less specific.
388 * @param cb Callback to return matching state variables.
389 * @param cb_cls Closure for the callback.
391 * @return Handle that can be used to cancel the operation.
393 struct GNUNET_PSYCSTORE_OperationHandle *
394 GNUNET_PSYCSTORE_state_get (struct GNUNET_PSYCSTORE_Handle *h,
395 const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
397 GNUNET_PSYCSTORE_StateCallback cb,
402 * Retrieve all state variables for a channel with the given prefix.
404 * @param h Handle for the PSYCstore.
405 * @param channel_key The channel we are interested in.
406 * @param name_prefix Prefix of state variable names to match.
407 * @param cb Callback to return matching state variables.
408 * @param cb_cls Closure for the callback.
410 * @return Handle that can be used to cancel the operation.
412 struct GNUNET_PSYCSTORE_OperationHandle *
413 GNUNET_PSYCSTORE_state_get_all (struct GNUNET_PSYCSTORE_Handle *h,
414 const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
415 const char *name_prefix,
416 GNUNET_PSYCSTORE_StateCallback cb,
421 * Cancel an operation.
423 * @param oh Handle for the operation to cancel.
426 GNUNET_PSYCSTORE_operation_cancel (struct GNUNET_PSYCSTORE_OperationHandle *oh);
431 #if 0 /* keep Emacsens' auto-indent happy */
438 /* ifndef GNUNET_PSYCSTORE_SERVICE_H */
440 /* end of gnunet_psycstore_service.h */