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"
42 * Version number of GNUnet PSYCstore API.
44 #define GNUNET_PSYCSTORE_VERSION 0x00000000
47 * Handle for a PSYCstore
49 struct GNUNET_PSYCSTORE_Handle;
53 * Connect to the PSYCstore service.
55 * @param cfg Configuration to use.
57 * @return Handle for the connecton.
59 struct GNUNET_PSYCSTORE_Handle *
60 GNUNET_PSYCSTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
64 * Disconnect from the PSYCstore service.
66 * @param h Handle for the connection.
69 GNUNET_PSYCSTORE_disconnect (struct GNUNET_PSYCSTORE_Handle *h);
73 * Handle for an operation on the PSYCSTORE (useful to cancel the operation).
75 struct GNUNET_PSYCSTORE_OperationHandle;
79 * Callback used to return the latest value of counters of a channel.
81 * @see GNUNET_PSYCSTORE_counters_get()
83 * @param *cls Closure.
84 * @param fragment_id Latest message fragment ID, used by multicast.
85 * @param message_id Latest message ID, used by PSYC.
86 * @param group_generation Latest group generation, used by PSYC.
89 (*GNUNET_PSYCSTORE_CountersCallback) (void *cls,
92 uint64_t group_generation);
96 * Retrieve latest values of counters for a channel.
98 * The current value of counters are needed when a channel master is restarted,
99 * so that it can continue incrementing the counters from their last value.
101 * @param h Handle for the PSYCstore.
102 * @param channel_key Public key that identifies the channel.
103 * @param cb Callback to call with the result.
104 * @param cb_cls Closure for the callback.
108 struct GNUNET_PSYCSTORE_OperationHandle *
109 GNUNET_PSYCSTORE_counters_get (struct GNUNET_PSYCSTORE_Handle *h,
110 GNUNET_CRYPTO_EccPublicKey *channel_key,
111 GNUNET_PSYCSTORE_CountersCallback *cb,
116 * Function called with the result of an asynchronous operation.
118 * @param result #GNUNET_SYSERR on error,
119 * #GNUNET_YES on success or if the peer was a member,
120 * #GNUNET_NO if the peer was not a member
123 (*GNUNET_PSYCSTORE_ResultCallback) (void *cls,
128 * Store join/leave events for a PSYC channel in order to be able to answer
129 * membership test queries later.
131 * @param h Handle for the PSYCstore.
132 * @param channel_key The channel where the event happened.
133 * @param slave_key Public key of joining/leaving slave.
134 * @param did_join #GNUNET_YES on join, #GNUNET_NO on part.
135 * @param announced_at ID of the message that announced the membership change.
136 * @param effective_since Message ID this membership change is in effect since.
137 * For joins it is <= announced_at, for parts it is always 0.
138 * @param group_generation In case of a part, the last group generation the
139 * slave has access to. It has relevance when a larger message have
140 * fragments with different group generations.
141 * @param rcb Callback to call with the result of the storage operation.
142 * @param rcb_cls Closure for the callback.
144 * @return Operation handle that can be used to cancel the operation.
146 struct GNUNET_PSYCSTORE_OperationHandle *
147 GNUNET_PSYCSTORE_membership_store (struct GNUNET_PSYCSTORE_Handle *h,
148 const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
149 const struct GNUNET_CRYPTO_EccPublicKey *slave_key,
151 uint64_t announced_at,
152 uint64_t effective_since,
153 uint64_t group_generation,
154 GNUNET_PSYCSTORE_ResultCallback rcb,
159 * Test if a peer was a member of the channel during the given period specified by the group generation.
161 * 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.
163 * @param h Handle for the PSYCstore.
164 * @param channel_key The channel we are interested in.
165 * @param slave_key Public key of slave whose membership to check.
166 * @param message_id Message ID for which to do the membership test.
167 * @param group_generation Group generation of the fragment of the message to
168 * test. It has relevance if the message consists of multiple fragments
169 * with different group generations.
170 * @param rcb Callback to call with the test result.
171 * @param rcb_cls Closure for the callback.
173 * @return Operation handle that can be used to cancel the operation.
175 struct GNUNET_PSYCSTORE_OperationHandle *
176 GNUNET_PSYCSTORE_membership_test (struct GNUNET_PSYCSTORE_Handle *h,
177 const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
178 const struct GNUNET_CRYPTO_EccPublicKey *slave_key,
180 uint64_t group_generation,
181 GNUNET_PSYCSTORE_ResultCallback rcb,
186 * Store a message fragment sent to a channel.
188 * @param h Handle for the PSYCstore.
189 * @param channel_key The channel the message belongs to.
190 * @param message Message to store.
191 * @param rcb Callback to call with the result of the operation.
192 * @param rcb_cls Closure for the callback.
194 * @return Handle that can be used to cancel the operation.
196 struct GNUNET_PSYCSTORE_OperationHandle *
197 GNUNET_PSYCSTORE_fragment_store (struct GNUNET_PSYCSTORE_Handle *h,
198 const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
199 const struct GNUNET_MULTICAST_MessageHeader *message,
200 GNUNET_PSYCSTORE_ResultCallback rcb,
205 * Function called with one message fragment, as the result of a
206 * GNUNET_PSYCSTORE_fragment_get() or GNUNET_PSYCSTORE_message_get() call.
208 * @param cls Closure.
209 * @param message The retrieved message fragment. A NULL value indicates that
210 * there are no more results to be returned.
211 * @param flags Message flags indicating fragmentation status.
214 (*GNUNET_PSYCSTORE_FragmentCallback) (void *cls,
215 const struct GNUNET_MULTICAST_MessageHeader *message,
216 enum GNUNET_PSYC_MessageFlags flags);
220 * Retrieve a message fragment by fragment ID.
222 * @param h Handle for the PSYCstore.
223 * @param channel_key The channel we are interested in.
224 * @param fragment_id Fragment ID to check. Use 0 to get the latest message fragment.
225 * @param cb Callback to call with the retrieved fragment.
226 * @param cb_cls Closure for the callback.
228 * @return Handle that can be used to cancel the operation.
230 struct GNUNET_PSYCSTORE_OperationHandle *
231 GNUNET_PSYCSTORE_fragment_get (struct GNUNET_PSYCSTORE_Handle *h,
232 const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
233 uint64_t fragment_id,
234 GNUNET_PSYCSTORE_FragmentCallback cb,
239 * Retrieve a message by ID.
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 cb Callback to call with the retrieved fragments.
245 * @param cb_cls Closure for the callback.
247 * @return Handle that can be used to cancel the operation.
249 struct GNUNET_PSYCSTORE_OperationHandle *
250 GNUNET_PSYCSTORE_message_get (struct GNUNET_PSYCSTORE_Handle *h,
251 const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
253 GNUNET_PSYCSTORE_FragmentCallback cb,
258 * Apply modifiers of a message to the current channel state.
260 * An error is returned if there are missing messages containing state
261 * operations before the current one.
263 * @param h Handle for the PSYCstore.
264 * @param channel_key The channel we are interested in.
265 * @param message_id ID of the message that contains the @a modifiers.
266 * @param state_delta Value of the _state_delta PSYC header variable of the message.
267 * @param modifier_count Number of elements in the @a modifiers array.
268 * @param modifiers List of modifiers to apply.
269 * @param rcb Callback to call with the result of the operation.
270 * @param rcb_cls Closure for the callback.
272 * @return Handle that can be used to cancel the operation.
274 struct GNUNET_PSYCSTORE_OperationHandle *
275 GNUNET_PSYCSTORE_state_modify (struct GNUNET_PSYCSTORE_Handle *h,
276 const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
278 uint64_t state_delta,
279 size_t modifier_count,
280 const struct GNUNET_ENV_Modifier *modifiers,
281 GNUNET_PSYCSTORE_ResultCallback rcb,
286 * Update signed values of state variables in the state store.
288 * @param h Handle for the PSYCstore.
289 * @param channel_key The channel we are interested in.
290 * @param message_id Message ID that contained the state @a hash.
291 * @param hash Hash of the serialized full state.
292 * @param rcb Callback to call with the result of the operation.
293 * @param rcb_cls Closure for the callback.
296 struct GNUNET_PSYCSTORE_OperationHandle *
297 GNUNET_PSYCSTORE_state_hash_update (struct GNUNET_PSYCSTORE_Handle *h,
298 const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
300 const struct GNUNET_HashCode *hash,
301 GNUNET_PSYCSTORE_ResultCallback rcb,
306 * Function called with the value of a state variable.
308 * @param cls Closure.
309 * @param name Name of the state variable. A NULL value indicates that there are no more
310 * state variables to be returned.
311 * @param value_size Number of bytes in @a value.
312 * @param value Value of the state variable.
316 (*GNUNET_PSYCSTORE_StateCallback) (void *cls,
323 * Retrieve the best matching state variable.
325 * @param h Handle for the PSYCstore.
326 * @param channel_key The channel we are interested in.
327 * @param name Name of variable to match, the returned variable might be less specific.
328 * @param cb Callback to return matching state variables.
329 * @param cb_cls Closure for the callback.
331 * @return Handle that can be used to cancel the operation.
333 struct GNUNET_PSYCSTORE_OperationHandle *
334 GNUNET_PSYCSTORE_state_get (struct GNUNET_PSYCSTORE_Handle *h,
335 const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
337 GNUNET_PSYCSTORE_StateCallback cb,
342 * Retrieve all state variables for a channel with the given prefix.
344 * @param h Handle for the PSYCstore.
345 * @param channel_key The channel we are interested in.
346 * @param name_prefix Prefix of state variable names to match.
347 * @param cb Callback to return matching state variables.
348 * @param cb_cls Closure for the callback.
350 * @return Handle that can be used to cancel the operation.
352 struct GNUNET_PSYCSTORE_OperationHandle *
353 GNUNET_PSYCSTORE_state_get_all (struct GNUNET_PSYCSTORE_Handle *h,
354 const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
355 const char *name_prefix,
356 GNUNET_PSYCSTORE_StateCallback cb,
361 * Cancel an operation.
363 * @param oh Handle for the operation to cancel.
366 GNUNET_PSYCSTORE_operation_cancel (struct GNUNET_PSYCSTORE_OperationHandle *oh);
371 #if 0 /* keep Emacsens' auto-indent happy */
378 /* ifndef GNUNET_PSYCSTORE_SERVICE_H */
380 /* end of gnunet_psycstore_service.h */