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 * Callback used to return the latest value of counters of a channel.
83 * @see GNUNET_PSYCSTORE_counters_get()
85 * @param *cls Closure.
86 * @param fragment_id Latest message fragment ID, used by multicast.
87 * @param message_id Latest message ID, used by PSYC.
88 * @param group_generation Latest group generation, used by PSYC.
91 (*GNUNET_PSYCSTORE_CountersCallback) (void *cls,
94 uint64_t group_generation);
98 * Retrieve latest values of counters for a channel.
100 * The current value of counters are needed when a channel master is restarted,
101 * so that it can continue incrementing the counters from their last value.
103 * @param h Handle for the PSYCstore.
104 * @param channel_key Public key that identifies the channel.
105 * @param cb Callback to call with the result.
106 * @param cb_cls Closure for the callback.
110 struct GNUNET_PSYCSTORE_OperationHandle *
111 GNUNET_PSYCSTORE_counters_get (struct GNUNET_PSYCSTORE_Handle *h,
112 struct GNUNET_CRYPTO_EccPublicKey *channel_key,
113 GNUNET_PSYCSTORE_CountersCallback *cb,
118 * Function called with the result of an asynchronous operation.
120 * @param result #GNUNET_SYSERR on error,
121 * #GNUNET_YES on success or if the peer was a member,
122 * #GNUNET_NO if the peer was not a member
125 (*GNUNET_PSYCSTORE_ResultCallback) (void *cls,
127 const char *err_msg);
131 * Store join/leave events for a PSYC channel in order to be able to answer
132 * membership test queries later.
134 * @param h Handle for the PSYCstore.
135 * @param channel_key The channel where the event happened.
136 * @param slave_key Public key of joining/leaving slave.
137 * @param did_join #GNUNET_YES on join, #GNUNET_NO on part.
138 * @param announced_at ID of the message that announced the membership change.
139 * @param effective_since Message ID this membership change is in effect since.
140 * For joins it is <= announced_at, for parts it is always 0.
141 * @param group_generation In case of a part, the last group generation the
142 * slave has access to. It has relevance when a larger message have
143 * fragments with different group generations.
144 * @param rcb Callback to call with the result of the storage operation.
145 * @param rcb_cls Closure for the callback.
147 * @return Operation handle that can be used to cancel the operation.
149 struct GNUNET_PSYCSTORE_OperationHandle *
150 GNUNET_PSYCSTORE_membership_store (struct GNUNET_PSYCSTORE_Handle *h,
151 const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
152 const struct GNUNET_CRYPTO_EccPublicKey *slave_key,
154 uint64_t announced_at,
155 uint64_t effective_since,
156 uint64_t group_generation,
157 GNUNET_PSYCSTORE_ResultCallback rcb,
162 * Test if a peer was a member of the channel during the given period specified by the group generation.
164 * This is useful when relaying and replaying messages to check if a particular slave has access to the message fragment with a given group generation. It is also used when handling join requests to determine whether the slave is currently admitted to the channel.
166 * @param h Handle for the PSYCstore.
167 * @param channel_key The channel we are interested in.
168 * @param slave_key Public key of slave whose membership to check.
169 * @param message_id Message ID for which to do the membership test.
170 * @param group_generation Group generation of the fragment of the message to
171 * test. It has relevance if the message consists of multiple fragments
172 * with different group generations.
173 * @param rcb Callback to call with the test result.
174 * @param rcb_cls Closure for the callback.
176 * @return Operation handle that can be used to cancel the operation.
178 struct GNUNET_PSYCSTORE_OperationHandle *
179 GNUNET_PSYCSTORE_membership_test (struct GNUNET_PSYCSTORE_Handle *h,
180 const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
181 const struct GNUNET_CRYPTO_EccPublicKey *slave_key,
183 uint64_t group_generation,
184 GNUNET_PSYCSTORE_ResultCallback rcb,
189 * Store a message fragment sent to a channel.
191 * @param h Handle for the PSYCstore.
192 * @param channel_key The channel the message belongs to.
193 * @param message Message to store.
194 * @param rcb Callback to call with the result of the operation.
195 * @param rcb_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_store (struct GNUNET_PSYCSTORE_Handle *h,
201 const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
202 const struct GNUNET_MULTICAST_MessageHeader *message,
203 GNUNET_PSYCSTORE_ResultCallback rcb,
208 * Function called with one message fragment, as the result of a
209 * GNUNET_PSYCSTORE_fragment_get() or GNUNET_PSYCSTORE_message_get() call.
211 * @param cls Closure.
212 * @param message The retrieved message fragment. A NULL value indicates that
213 * there are no more results to be returned.
214 * @param flags Message flags indicating fragmentation status.
217 (*GNUNET_PSYCSTORE_FragmentCallback) (void *cls,
218 const struct GNUNET_MULTICAST_MessageHeader *message,
219 enum GNUNET_PSYC_MessageFlags flags);
223 * Retrieve a message fragment by fragment ID.
225 * @param h Handle for the PSYCstore.
226 * @param channel_key The channel we are interested in.
227 * @param fragment_id Fragment ID to check. Use 0 to get the latest message fragment.
228 * @param cb Callback to call with the retrieved fragment.
229 * @param cb_cls Closure for the callback.
231 * @return Handle that can be used to cancel the operation.
233 struct GNUNET_PSYCSTORE_OperationHandle *
234 GNUNET_PSYCSTORE_fragment_get (struct GNUNET_PSYCSTORE_Handle *h,
235 const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
236 uint64_t fragment_id,
237 GNUNET_PSYCSTORE_FragmentCallback cb,
242 * Retrieve a message by ID.
244 * @param h Handle for the PSYCstore.
245 * @param channel_key The channel we are interested in.
246 * @param message_id Message ID to check. Use 0 to get the latest message.
247 * @param cb Callback to call with the retrieved fragments.
248 * @param cb_cls Closure for the callback.
250 * @return Handle that can be used to cancel the operation.
252 struct GNUNET_PSYCSTORE_OperationHandle *
253 GNUNET_PSYCSTORE_message_get (struct GNUNET_PSYCSTORE_Handle *h,
254 const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
256 GNUNET_PSYCSTORE_FragmentCallback cb,
261 * Apply modifiers of a message to the current channel state.
263 * An error is returned if there are missing messages containing state
264 * operations before the current one.
266 * @param h Handle for the PSYCstore.
267 * @param channel_key The channel we are interested in.
268 * @param message_id ID of the message that contains the @a modifiers.
269 * @param state_delta Value of the _state_delta PSYC header variable of the message.
270 * @param modifier_count Number of elements in the @a modifiers array.
271 * @param modifiers List of modifiers to apply.
272 * @param rcb Callback to call with the result of the operation.
273 * @param rcb_cls Closure for the callback.
275 * @return Handle that can be used to cancel the operation.
277 struct GNUNET_PSYCSTORE_OperationHandle *
278 GNUNET_PSYCSTORE_state_modify (struct GNUNET_PSYCSTORE_Handle *h,
279 const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
281 uint64_t state_delta,
282 size_t modifier_count,
283 const struct GNUNET_ENV_Modifier *modifiers,
284 GNUNET_PSYCSTORE_ResultCallback rcb,
289 * Update signed values of state variables in the state store.
291 * @param h Handle for the PSYCstore.
292 * @param channel_key The channel we are interested in.
293 * @param message_id Message ID that contained the state @a hash.
294 * @param hash Hash of the serialized full state.
295 * @param rcb Callback to call with the result of the operation.
296 * @param rcb_cls Closure for the callback.
299 struct GNUNET_PSYCSTORE_OperationHandle *
300 GNUNET_PSYCSTORE_state_hash_update (struct GNUNET_PSYCSTORE_Handle *h,
301 const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
303 const struct GNUNET_HashCode *hash,
304 GNUNET_PSYCSTORE_ResultCallback rcb,
309 * Function called with the value of a state variable.
311 * @param cls Closure.
312 * @param name Name of the state variable. A NULL value indicates that there are no more
313 * state variables to be returned.
314 * @param value_size Number of bytes in @a value.
315 * @param value Value of the state variable.
319 (*GNUNET_PSYCSTORE_StateCallback) (void *cls,
326 * Retrieve the best matching state variable.
328 * @param h Handle for the PSYCstore.
329 * @param channel_key The channel we are interested in.
330 * @param name Name of variable to match, the returned variable might be less specific.
331 * @param cb Callback to return matching state variables.
332 * @param cb_cls Closure for the callback.
334 * @return Handle that can be used to cancel the operation.
336 struct GNUNET_PSYCSTORE_OperationHandle *
337 GNUNET_PSYCSTORE_state_get (struct GNUNET_PSYCSTORE_Handle *h,
338 const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
340 GNUNET_PSYCSTORE_StateCallback cb,
345 * Retrieve all state variables for a channel with the given prefix.
347 * @param h Handle for the PSYCstore.
348 * @param channel_key The channel we are interested in.
349 * @param name_prefix Prefix of state variable names to match.
350 * @param cb Callback to return matching state variables.
351 * @param cb_cls Closure for the callback.
353 * @return Handle that can be used to cancel the operation.
355 struct GNUNET_PSYCSTORE_OperationHandle *
356 GNUNET_PSYCSTORE_state_get_all (struct GNUNET_PSYCSTORE_Handle *h,
357 const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
358 const char *name_prefix,
359 GNUNET_PSYCSTORE_StateCallback cb,
364 * Cancel an operation.
366 * @param oh Handle for the operation to cancel.
369 GNUNET_PSYCSTORE_operation_cancel (struct GNUNET_PSYCSTORE_OperationHandle *oh);
374 #if 0 /* keep Emacsens' auto-indent happy */
381 /* ifndef GNUNET_PSYCSTORE_SERVICE_H */
383 /* end of gnunet_psycstore_service.h */