multicast: added replay_end(), returning replay handle from join_decision(); removed...
[oweals/gnunet.git] / src / include / gnunet_psycstore_service.h
1 /*
2      This file is part of GNUnet.
3      (C) 2013 Christian Grothoff (and other contributing authors)
4
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.
9
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.
14
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.
19 */
20
21 /** 
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
26  */
27 #ifndef GNUNET_PSYCSTORE_SERVICE_H
28 #define GNUNET_PSYCSTORE_SERVICE_H
29
30 #ifdef __cplusplus
31 extern "C"
32 {
33 #if 0                           /* keep Emacsens' auto-indent happy */
34 }
35 #endif
36 #endif
37
38 #include "gnunet_util_lib.h"
39 #include "gnunet_env_lib.h"
40
41 /** 
42  * Version number of GNUnet PSYCstore API.
43  */
44 #define GNUNET_PSYCSTORE_VERSION 0x00000000
45
46 /** 
47  * Handle for a PSYCstore
48  */
49 struct GNUNET_PSYCSTORE_Handle;
50
51
52 /** 
53  * Connect to the PSYCstore service.
54  *
55  * @param cfg Configuration to use.
56  *
57  * @return Handle for the connecton.
58  */
59 struct GNUNET_PSYCSTORE_Handle *
60 GNUNET_PSYCSTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
61
62
63 /** 
64  * Disconnect from the PSYCstore service.
65  *
66  * @param h Handle for the connection.
67  */
68 void
69 GNUNET_PSYCSTORE_disconnect (struct GNUNET_PSYCSTORE_Handle *h);
70
71
72 /** 
73  * Handle for an operation on the PSYCSTORE (useful to cancel the operation).
74  */
75 struct GNUNET_PSYCSTORE_OperationHandle;
76
77
78 /** 
79  * Callback used to return the latest value of counters of a channel.
80  *
81  * @see GNUNET_PSYCSTORE_counters_get()
82  *
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.
87  */
88 typedef void
89 (*GNUNET_PSYCSTORE_CountersCallback) (void *cls,
90                                       uint64_t fragment_id,
91                                       uint64_t message_id,
92                                       uint64_t group_generation);
93
94
95 /** 
96  * Retrieve latest values of counters for a channel.
97  *
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.
100  *
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.
105  * 
106  * @return 
107  */
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,
112                                void *cb_cls);
113
114
115 /** 
116  * Function called with the result of an asynchronous operation.
117  * 
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
121  */
122 typedef void
123 (*GNUNET_PSYCSTORE_ResultCallback) (void *cls,
124                                     int result);
125
126
127 /** 
128  * Store join/leave events for a PSYC channel in order to be able to answer
129  * membership test queries later.
130  *
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.
143  *
144  * @return Operation handle that can be used to cancel the operation.
145  */
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,
150                                    int did_join,
151                                    uint64_t announced_at,
152                                    uint64_t effective_since,
153                                    uint64_t group_generation,
154                                    GNUNET_PSYCSTORE_ResultCallback rcb,
155                                    void *rcb_cls);
156
157
158 /** 
159  * Test if a peer was a member of the channel during the given period specified by the group generation.
160  *
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.
162  *
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.
172  *
173  * @return Operation handle that can be used to cancel the operation.
174  */
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,
179                                   uint64_t message_id,
180                                   uint64_t group_generation,
181                                   GNUNET_PSYCSTORE_ResultCallback rcb,
182                                   void *rcb_cls);
183
184
185 /** 
186  * Store a message fragment sent to a channel.
187  *
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.
193  * 
194  * @return Handle that can be used to cancel the operation.
195  */
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,
201                                  void *rcb_cls);
202
203
204 /** 
205  * Function called with one message fragment, as the result of a
206  * GNUNET_PSYCSTORE_fragment_get() or GNUNET_PSYCSTORE_message_get() call.
207  *
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.
212  */
213 typedef void
214 (*GNUNET_PSYCSTORE_FragmentCallback) (void *cls,
215                                       const struct GNUNET_MULTICAST_MessageHeader *message,
216                                       enum GNUNET_PSYC_MessageFlags flags);
217
218
219 /** 
220  * Retrieve a message fragment by fragment ID.
221  *
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.
227  * 
228  * @return Handle that can be used to cancel the operation.
229  */
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,
235                                void *cb_cls);
236
237
238 /** 
239  * Retrieve a message by ID.
240  *
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.
246  * 
247  * @return Handle that can be used to cancel the operation.
248  */
249 struct GNUNET_PSYCSTORE_OperationHandle *
250 GNUNET_PSYCSTORE_message_get (struct GNUNET_PSYCSTORE_Handle *h,
251                               const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
252                               uint64_t message_id,
253                               GNUNET_PSYCSTORE_FragmentCallback cb,
254                               void *cb_cls);
255
256
257 /** 
258  * Apply modifiers of a message to the current channel state.
259  *
260  * An error is returned if there are missing messages containing state
261  * operations before the current one.
262  *
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.
271  * 
272  * @return Handle that can be used to cancel the operation.
273  */
274 struct GNUNET_PSYCSTORE_OperationHandle *
275 GNUNET_PSYCSTORE_state_modify (struct GNUNET_PSYCSTORE_Handle *h,
276                                const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
277                                uint64_t message_id,
278                                uint64_t state_delta,
279                                size_t modifier_count,
280                                const struct GNUNET_ENV_Modifier *modifiers,
281                                GNUNET_PSYCSTORE_ResultCallback rcb,
282                                void *rcb_cls);
283
284
285 /** 
286  * Update signed values of state variables in the state store.
287  *
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.
294  *
295  */
296 struct GNUNET_PSYCSTORE_OperationHandle *
297 GNUNET_PSYCSTORE_state_hash_update (struct GNUNET_PSYCSTORE_Handle *h,
298                                     const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
299                                     uint64_t message_id,
300                                     const struct GNUNET_HashCode *hash,
301                                     GNUNET_PSYCSTORE_ResultCallback rcb,
302                                     void *rcb_cls);
303
304
305 /** 
306  * Function called with the value of a state variable.
307  *
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.
313 t * 
314  */
315 typedef void
316 (*GNUNET_PSYCSTORE_StateCallback) (void *cls,
317                                    const char *name,
318                                    size_t value_size,
319                                    const void *value);
320
321
322 /** 
323  * Retrieve the best matching state variable.
324  *
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.
330  * 
331  * @return Handle that can be used to cancel the operation.
332  */
333 struct GNUNET_PSYCSTORE_OperationHandle *
334 GNUNET_PSYCSTORE_state_get (struct GNUNET_PSYCSTORE_Handle *h,
335                             const struct GNUNET_CRYPTO_EccPublicKey *channel_key,
336                             const char *name,
337                             GNUNET_PSYCSTORE_StateCallback cb,
338                             void *cb_cls);
339
340
341 /** 
342  * Retrieve all state variables for a channel with the given prefix.
343  *
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.
349  * 
350  * @return Handle that can be used to cancel the operation.
351  */
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,
357                                 void *cb_cls);
358
359
360 /** 
361  * Cancel an operation.
362  *
363  * @param oh Handle for the operation to cancel.
364  */
365 void
366 GNUNET_PSYCSTORE_operation_cancel (struct GNUNET_PSYCSTORE_OperationHandle *oh);
367
368
369
370
371 #if 0                           /* keep Emacsens' auto-indent happy */
372 {
373 #endif
374 #ifdef __cplusplus
375 }
376 #endif
377
378 /* ifndef GNUNET_PSYCSTORE_SERVICE_H */
379 #endif
380 /* end of gnunet_psycstore_service.h */