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 * @param group_generation In case of a part, the last group generation the
138 * slave has access to. It has relevance when a larger message have
139 * fragments with different group generations.
140 * @param rcb Callback to call with the result of the storage operation.
141 * @param rcb_cls Closure for the callback.
143 * @return Operation handle that can be used to cancel the operation.
145 struct GNUNET_PSYCSTORE_OperationHandle *
146 GNUNET_PSYCSTORE_membership_store (struct GNUNET_PSYCSTORE_Handle *h,
147 const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
148 const struct GNUNET_CRYPTO_EccPublicKey *slave_key,
150 uint64_t announced_at,
151 uint64_t effective_since,
152 uint64_t group_generation,
153 GNUNET_PSYCSTORE_ResultCallback rcb,
158 * Test if a peer was a member of the channel during the given period specified by the group generation.
160 * 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.
162 * @param h Handle for the PSYCstore.
163 * @param channel_key The channel we are interested in.
164 * @param slave_key Public key of slave whose membership to check.
165 * @param message_id Message ID for which to do the membership test.
166 * @param group_generation Group generation of the fragment of the message to
167 * test. It has relevance if the message consists of multiple fragments
168 * with different group generations.
169 * @param rcb Callback to call with the test result.
170 * @param rcb_cls Closure for the callback.
172 * @return Operation handle that can be used to cancel the operation.
174 struct GNUNET_PSYCSTORE_OperationHandle *
175 GNUNET_PSYCSTORE_membership_test (struct GNUNET_PSYCSTORE_Handle *h,
176 const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
177 const struct GNUNET_CRYPTO_EccPublicKey *slave_key,
179 uint64_t group_generation,
180 GNUNET_PSYCSTORE_ResultCallback rcb,
185 * Store a message fragment sent to a channel.
187 * @param h Handle for the PSYCstore.
188 * @param channel_key The channel the message belongs to.
189 * @param message Message to store.
190 * @param rcb Callback to call with the result of the operation.
191 * @param rcb_cls Closure for the callback.
193 * @return Handle that can be used to cancel the operation.
195 struct GNUNET_PSYCSTORE_OperationHandle *
196 GNUNET_PSYCSTORE_fragment_store (struct GNUNET_PSYCSTORE_Handle *h,
197 const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
198 const struct GNUNET_MULTICAST_MessageHeader *message,
199 GNUNET_PSYCSTORE_ResultCallback rcb,
204 * Function called with one message fragment, as the result of a
205 * GNUNET_PSYCSTORE_fragment_get() or GNUNET_PSYCSTORE_message_get() call.
207 * @param cls Closure.
208 * @param message The retrieved message fragment. A NULL value indicates that
209 * there are no more results to be returned.
210 * @param flags Message flags indicating fragmentation status.
213 (*GNUNET_PSYCSTORE_FragmentCallback) (void *cls,
214 const struct GNUNET_MULTICAST_MessageHeader *message,
215 enum GNUNET_PSYC_MessageFlags flags);
219 * Retrieve a message fragment by fragment ID.
221 * @param h Handle for the PSYCstore.
222 * @param channel_key The channel we are interested in.
223 * @param fragment_id Fragment ID to check. Use 0 to get the latest message fragment.
224 * @param cb Callback to call with the retrieved fragment.
225 * @param cb_cls Closure for the callback.
227 * @return Handle that can be used to cancel the operation.
229 struct GNUNET_PSYCSTORE_OperationHandle *
230 GNUNET_PSYCSTORE_fragment_get (struct GNUNET_PSYCSTORE_Handle *h,
231 const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
232 uint64_t fragment_id,
233 GNUNET_PSYCSTORE_FragmentCallback cb,
238 * Retrieve a message by ID.
240 * @param h Handle for the PSYCstore.
241 * @param channel_key The channel we are interested in.
242 * @param message_id Message ID to check. Use 0 to get the latest message.
243 * @param cb Callback to call with the retrieved fragments.
244 * @param cb_cls Closure for the callback.
246 * @return Handle that can be used to cancel the operation.
248 struct GNUNET_PSYCSTORE_OperationHandle *
249 GNUNET_PSYCSTORE_message_get (struct GNUNET_PSYCSTORE_Handle *h,
250 const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
252 GNUNET_PSYCSTORE_FragmentCallback cb,
257 * Apply modifiers of a message to the current channel state.
259 * An error is returned if there are missing messages containing state
260 * operations before the current one.
262 * @param h Handle for the PSYCstore.
263 * @param channel_key The channel we are interested in.
264 * @param message_id ID of the message that contains the @a modifiers.
265 * @param state_delta Value of the _state_delta PSYC header variable of the message.
266 * @param modifier_count Number of elements in the @a modifiers array.
267 * @param modifiers List of modifiers to apply.
268 * @param rcb Callback to call with the result of the operation.
269 * @param rcb_cls Closure for the callback.
271 * @return Handle that can be used to cancel the operation.
273 struct GNUNET_PSYCSTORE_OperationHandle *
274 GNUNET_PSYCSTORE_state_modify (struct GNUNET_PSYCSTORE_Handle *h,
275 const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
277 uint64_t state_delta,
278 size_t modifier_count,
279 const struct GNUNET_ENV_Modifier *modifiers,
280 GNUNET_PSYCSTORE_ResultCallback rcb,
285 * Update signed values of state variables in the state store.
287 * @param h Handle for the PSYCstore.
288 * @param channel_key The channel we are interested in.
289 * @param message_id Message ID that contained the state @a hash.
290 * @param hash Hash of the serialized full state.
291 * @param rcb Callback to call with the result of the operation.
292 * @param rcb_cls Closure for the callback.
295 struct GNUNET_PSYCSTORE_OperationHandle *
296 GNUNET_PSYCSTORE_state_hash_update (struct GNUNET_PSYCSTORE_Handle *h,
297 const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
299 const struct GNUNET_HashCode *hash,
300 GNUNET_PSYCSTORE_ResultCallback rcb,
305 * Function called with the value of a state variable.
307 * @param cls Closure.
308 * @param name Name of the state variable. A NULL value indicates that there are no more
309 * state variables to be returned.
310 * @param value_size Number of bytes in @a value.
311 * @param value Value of the state variable.
315 (*GNUNET_PSYCSTORE_StateCallback) (void *cls,
322 * Retrieve the best matching state variable.
324 * @param h Handle for the PSYCstore.
325 * @param channel_key The channel we are interested in.
326 * @param name Name of variable to match, the returned variable might be less specific.
327 * @param cb Callback to return matching state variables.
328 * @param cb_cls Closure for the callback.
330 * @return Handle that can be used to cancel the operation.
332 struct GNUNET_PSYCSTORE_OperationHandle *
333 GNUNET_PSYCSTORE_state_get (struct GNUNET_PSYCSTORE_Handle *h,
334 const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
336 GNUNET_PSYCSTORE_StateCallback cb,
341 * Retrieve all state variables for a channel with the given prefix.
343 * @param h Handle for the PSYCstore.
344 * @param channel_key The channel we are interested in.
345 * @param name_prefix Prefix of state variable names to match.
346 * @param cb Callback to return matching state variables.
347 * @param cb_cls Closure for the callback.
349 * @return Handle that can be used to cancel the operation.
351 struct GNUNET_PSYCSTORE_OperationHandle *
352 GNUNET_PSYCSTORE_state_get_all (struct GNUNET_PSYCSTORE_Handle *h,
353 const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
354 const char *name_prefix,
355 GNUNET_PSYCSTORE_StateCallback cb,
360 * Cancel an operation.
362 * @param oh Handle for the operation to cancel.
365 GNUNET_PSYCSTORE_operation_cancel (struct GNUNET_PSYCSTORE_OperationHandle *oh);
370 #if 0 /* keep Emacsens' auto-indent happy */
377 /* ifndef GNUNET_PSYCSTORE_SERVICE_H */
379 /* end of gnunet_psycstore_service.h */