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,
130 * Store join/leave events for a PSYC channel in order to be able to answer
131 * membership test queries later.
133 * @param h Handle for the PSYCstore.
134 * @param channel_key The channel where the event happened.
135 * @param slave_key Public key of joining/leaving slave.
136 * @param did_join #GNUNET_YES on join, #GNUNET_NO on part.
137 * @param announced_at ID of the message that announced the membership change.
138 * @param effective_since Message ID this membership change is in effect since.
139 * For joins it is <= announced_at, for parts it is always 0.
140 * @param group_generation In case of a part, the last group generation the
141 * slave has access to. It has relevance when a larger message have
142 * fragments with different group generations.
143 * @param rcb Callback to call with the result of the storage operation.
144 * @param rcb_cls Closure for the callback.
146 * @return Operation handle that can be used to cancel the operation.
148 struct GNUNET_PSYCSTORE_OperationHandle *
149 GNUNET_PSYCSTORE_membership_store (struct GNUNET_PSYCSTORE_Handle *h,
150 const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
151 const struct GNUNET_CRYPTO_EccPublicKey *slave_key,
153 uint64_t announced_at,
154 uint64_t effective_since,
155 uint64_t group_generation,
156 GNUNET_PSYCSTORE_ResultCallback rcb,
161 * Test if a peer was a member of the channel during the given period specified by the group generation.
163 * 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.
165 * @param h Handle for the PSYCstore.
166 * @param channel_key The channel we are interested in.
167 * @param slave_key Public key of slave whose membership to check.
168 * @param message_id Message ID for which to do the membership test.
169 * @param group_generation Group generation of the fragment of the message to
170 * test. It has relevance if the message consists of multiple fragments
171 * with different group generations.
172 * @param rcb Callback to call with the test result.
173 * @param rcb_cls Closure for the callback.
175 * @return Operation handle that can be used to cancel the operation.
177 struct GNUNET_PSYCSTORE_OperationHandle *
178 GNUNET_PSYCSTORE_membership_test (struct GNUNET_PSYCSTORE_Handle *h,
179 const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
180 const struct GNUNET_CRYPTO_EccPublicKey *slave_key,
182 uint64_t group_generation,
183 GNUNET_PSYCSTORE_ResultCallback rcb,
188 * Store a message fragment sent to a channel.
190 * @param h Handle for the PSYCstore.
191 * @param channel_key The channel the message belongs to.
192 * @param message Message to store.
193 * @param rcb Callback to call with the result of the operation.
194 * @param rcb_cls Closure for the callback.
196 * @return Handle that can be used to cancel the operation.
198 struct GNUNET_PSYCSTORE_OperationHandle *
199 GNUNET_PSYCSTORE_fragment_store (struct GNUNET_PSYCSTORE_Handle *h,
200 const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
201 const struct GNUNET_MULTICAST_MessageHeader *message,
202 GNUNET_PSYCSTORE_ResultCallback rcb,
207 * Function called with one message fragment, as the result of a
208 * GNUNET_PSYCSTORE_fragment_get() or GNUNET_PSYCSTORE_message_get() call.
210 * @param cls Closure.
211 * @param message The retrieved message fragment. A NULL value indicates that
212 * there are no more results to be returned.
213 * @param flags Message flags indicating fragmentation status.
216 (*GNUNET_PSYCSTORE_FragmentCallback) (void *cls,
217 const struct GNUNET_MULTICAST_MessageHeader *message,
218 enum GNUNET_PSYC_MessageFlags flags);
222 * Retrieve a message fragment by fragment ID.
224 * @param h Handle for the PSYCstore.
225 * @param channel_key The channel we are interested in.
226 * @param fragment_id Fragment ID to check. Use 0 to get the latest message fragment.
227 * @param cb Callback to call with the retrieved fragment.
228 * @param cb_cls Closure for the callback.
230 * @return Handle that can be used to cancel the operation.
232 struct GNUNET_PSYCSTORE_OperationHandle *
233 GNUNET_PSYCSTORE_fragment_get (struct GNUNET_PSYCSTORE_Handle *h,
234 const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
235 uint64_t fragment_id,
236 GNUNET_PSYCSTORE_FragmentCallback cb,
241 * Retrieve a message by ID.
243 * @param h Handle for the PSYCstore.
244 * @param channel_key The channel we are interested in.
245 * @param message_id Message ID to check. Use 0 to get the latest message.
246 * @param cb Callback to call with the retrieved fragments.
247 * @param cb_cls Closure for the callback.
249 * @return Handle that can be used to cancel the operation.
251 struct GNUNET_PSYCSTORE_OperationHandle *
252 GNUNET_PSYCSTORE_message_get (struct GNUNET_PSYCSTORE_Handle *h,
253 const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
255 GNUNET_PSYCSTORE_FragmentCallback cb,
260 * Apply modifiers of a message to the current channel state.
262 * An error is returned if there are missing messages containing state
263 * operations before the current one.
265 * @param h Handle for the PSYCstore.
266 * @param channel_key The channel we are interested in.
267 * @param message_id ID of the message that contains the @a modifiers.
268 * @param state_delta Value of the _state_delta PSYC header variable of the message.
269 * @param modifier_count Number of elements in the @a modifiers array.
270 * @param modifiers List of modifiers to apply.
271 * @param rcb Callback to call with the result of the operation.
272 * @param rcb_cls Closure for the callback.
274 * @return Handle that can be used to cancel the operation.
276 struct GNUNET_PSYCSTORE_OperationHandle *
277 GNUNET_PSYCSTORE_state_modify (struct GNUNET_PSYCSTORE_Handle *h,
278 const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
280 uint64_t state_delta,
281 size_t modifier_count,
282 const struct GNUNET_ENV_Modifier *modifiers,
283 GNUNET_PSYCSTORE_ResultCallback rcb,
288 * Update signed values of state variables in the state store.
290 * @param h Handle for the PSYCstore.
291 * @param channel_key The channel we are interested in.
292 * @param message_id Message ID that contained the state @a hash.
293 * @param hash Hash of the serialized full state.
294 * @param rcb Callback to call with the result of the operation.
295 * @param rcb_cls Closure for the callback.
298 struct GNUNET_PSYCSTORE_OperationHandle *
299 GNUNET_PSYCSTORE_state_hash_update (struct GNUNET_PSYCSTORE_Handle *h,
300 const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
302 const struct GNUNET_HashCode *hash,
303 GNUNET_PSYCSTORE_ResultCallback rcb,
308 * Function called with the value of a state variable.
310 * @param cls Closure.
311 * @param name Name of the state variable. A NULL value indicates that there are no more
312 * state variables to be returned.
313 * @param value_size Number of bytes in @a value.
314 * @param value Value of the state variable.
318 (*GNUNET_PSYCSTORE_StateCallback) (void *cls,
325 * Retrieve the best matching state variable.
327 * @param h Handle for the PSYCstore.
328 * @param channel_key The channel we are interested in.
329 * @param name Name of variable to match, the returned variable might be less specific.
330 * @param cb Callback to return matching state variables.
331 * @param cb_cls Closure for the callback.
333 * @return Handle that can be used to cancel the operation.
335 struct GNUNET_PSYCSTORE_OperationHandle *
336 GNUNET_PSYCSTORE_state_get (struct GNUNET_PSYCSTORE_Handle *h,
337 const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
339 GNUNET_PSYCSTORE_StateCallback cb,
344 * Retrieve all state variables for a channel with the given prefix.
346 * @param h Handle for the PSYCstore.
347 * @param channel_key The channel we are interested in.
348 * @param name_prefix Prefix of state variable names to match.
349 * @param cb Callback to return matching state variables.
350 * @param cb_cls Closure for the callback.
352 * @return Handle that can be used to cancel the operation.
354 struct GNUNET_PSYCSTORE_OperationHandle *
355 GNUNET_PSYCSTORE_state_get_all (struct GNUNET_PSYCSTORE_Handle *h,
356 const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
357 const char *name_prefix,
358 GNUNET_PSYCSTORE_StateCallback cb,
363 * Cancel an operation.
365 * @param oh Handle for the operation to cancel.
368 GNUNET_PSYCSTORE_operation_cancel (struct GNUNET_PSYCSTORE_OperationHandle *oh);
373 #if 0 /* keep Emacsens' auto-indent happy */
380 /* ifndef GNUNET_PSYCSTORE_SERVICE_H */
382 /* end of gnunet_psycstore_service.h */