8b84340fe447ef077db78cfb122f1065ac8c9ef6
[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
40 /** 
41  * Version number of GNUnet PSYCstore API.
42  */
43 #define GNUNET_PSYCSTORE_VERSION 0x00000000
44
45 /** 
46  * Handle for a PSYCstore
47  */
48 struct GNUNET_PSYCSTORE_Handle;
49
50
51 /** 
52  * Connect to the PSYCstore service.
53  *
54  * @param cfg Configuration to use.
55  *
56  * @return Handle for the connecton.
57  */
58 struct GNUNET_PSYCSTORE_Handle *
59 GNUNET_PSYCSTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
60
61
62 /** 
63  * Disconnect from the PSYCstore service.
64  *
65  * @param h Handle for the connection.
66  */
67 void
68 GNUNET_PSYCSTORE_disconnect (struct GNUNET_PSYCSTORE_Handle *h);
69
70
71 /** 
72  * Handle for an operation on the PSYCSTORE (useful to cancel the operation).
73  */
74 struct GNUNET_PSYCSTORE_OperationHandle;
75
76
77 /** 
78  * Function called with the result of an asynchronous operation.
79 ; * 
80  * @param result #GNUNET_SYSERR on error,
81  *        #GNUNET_YES on success or if the peer was a member,
82  *        #GNUNET_NO if the peer was not a member
83  */
84 typedef void (*GNUNET_PSYCSTORE_ContinuationCallback)(void *cls,
85                                                       int result);
86
87 /** 
88  * Store join/leave events for a PSYC channel in order to be able to answer
89  * membership test queries later.
90  *
91  * @param h Handle for the PSYCstore.
92  * @param channel_id ID of the channel where the event happened.
93  * @param message_id ID of the message in which this event was announced.
94  * @param group_generation Generation of the group when this event was announced.
95  * @param peer Identity of joining/leaving peer.
96  * @param did_join #GNUNET_YES on join, #GNUNET_NO on leave.
97  * @param ccb Callback to call with the result of the storage operation.
98  * @param ccb_cls Closure for the callback.
99  *
100  * @return Operation handle that can be used to cancel the operation.
101  */
102 struct GNUNET_PSYCSTORE_OperationHandle *
103 GNUNET_PSYCSTORE_membership_store (struct GNUNET_PSYCSTORE_Handle *h,
104                                    const struct GNUNET_HashCode *channel_id,
105                                    uint64_t message_id,
106                                    uint64_t group_generation,
107                                    const struct GNUNET_PeerIdentity *peer,
108                                    int did_join,
109                                    GNUNET_PSYCSTORE_ContinuationCallback ccb,
110                                    void *ccb_cls);
111
112
113 /** 
114  * Test if a peer was a member of the channel when the message fragment with the
115  * specified ID was sent to the channel.
116  *
117  * This is useful in case of retransmissions to check if the peer was authorized
118  * to see the requested message.
119  *
120  * @param h Handle for the PSYCstore.
121  * @param channel_id The channel we are interested in.
122  * @param fragment_id Message fragment ID to check.
123  * @param peer Peer whose membership to check.
124  * @param ccb Callback to call with the test result.
125  * @param ccb_cls Closure for the callback.
126  *
127  * @return Operation handle that can be used to cancel the operation.
128  */
129 struct GNUNET_PSYCSTORE_OperationHandle *
130 GNUNET_PSYCSTORE_membership_test (struct GNUNET_PSYCSTORE_Handle *h,
131                                   const struct GNUNET_HashCode *channel_id,
132                                   uint64_t fragment_id,
133                                   const struct GNUNET_PeerIdentity *peer,
134                                   GNUNET_PSYCSTORE_ContinuationCallback ccb,
135                                   void *ccb_cls);
136
137
138 /** 
139  * Store a message fragment sent to a channel.
140  *
141  * @param h Handle for the PSYCstore.
142  * @param channel_id The channel the message belongs to.
143  * @param message Message to store.
144  * @param ccb Callback to call with the result of the operation.
145  * @param ccb_cls Closure for the callback.
146  * 
147  * @return Handle that can be used to cancel the operation.
148  */
149 struct GNUNET_PSYCSTORE_OperationHandle *
150 GNUNET_PSYCSTORE_fragment_store (struct GNUNET_PSYCSTORE_Handle *h,
151                                  const struct GNUNET_HashCode *channel_id,
152                                  const struct GNUNET_MULTICAST_MessageHeader *message,
153                                  GNUNET_PSYCSTORE_ContinuationCallback ccb,
154                                  void *ccb_cls);
155
156
157 /** 
158  * Function called with one message fragment, as the result of a
159  * GNUNET_PSYCSTORE_fragment_get() or GNUNET_PSYCSTORE_message_get() call.
160  *
161  * @param cls Closure.
162  * @param message The retrieved message fragment.
163  * @param flags Message flags indicating fragmentation status.
164  */
165 typedef void (*GNUNET_PSYCSTORE_FragmentResultCallback)(void *cls,      
166                                                        const struct GNUNET_MULTICAST_MessageHeader *message,
167                                                        enum GNUNET_PSYC_MessageFlags flags);
168
169
170 /** 
171  * Retrieve a message fragment by fragment ID.
172  *
173  * @param h Handle for the PSYCstore.
174  * @param channel_id The channel we are interested in.
175  * @param fragment_id Fragment ID to check.  Use 0 to get the latest message fragment.
176  * @param rcb Callback to call with the result of the operation.
177  * @param rcb_cls Closure for the callback.
178  * 
179  * @return Handle that can be used to cancel the operation.
180  */
181 struct GNUNET_PSYCSTORE_OperationHandle *
182 GNUNET_PSYCSTORE_fragment_get (struct GNUNET_PSYCSTORE_Handle *h,
183                                const struct GNUNET_HashCode *channel_id,
184                                uint64_t message_id,
185                                GNUNET_PSYCSTORE_FragmentResultCallback rcb,
186                                void *rcb_cls);
187
188
189 /** 
190  * Retrieve a message by ID.
191  *
192  * @param h Handle for the PSYCstore.
193  * @param channel_id The channel we are interested in.
194  * @param message_id Message ID to check.  Use 0 to get the latest message.
195  * @param rcb Callback to call with the result of the operation.
196  * @param rcb_cls Closure for the callback.
197  * 
198  * @return Handle that can be used to cancel the operation.
199  */
200 struct GNUNET_PSYCSTORE_OperationHandle *
201 GNUNET_PSYCSTORE_message_get (struct GNUNET_PSYCSTORE_Handle *h,
202                               const struct GNUNET_HashCode *channel_id,
203                               uint64_t message_id,
204                               GNUNET_PSYCSTORE_FragmentResultCallback rcb,
205                               void *rcb_cls);
206
207
208 /** 
209  * Store a state variable.
210  *
211  * @param h Handle for the PSYCstore.
212  * @param channel_id The channel we are interested in.
213  * @param name Name of variable.
214  * @param value_size Size of @a value.
215  * @param value Value of variable.
216  * @param ccb Callback to call with the result of the operation.
217  * @param ccb_cls Closure for the callback.
218  * 
219  * @return Handle that can be used to cancel the operation.
220  */
221 struct GNUNET_PSYCSTORE_OperationHandle *
222 GNUNET_PSYCSTORE_state_set (struct GNUNET_PSYCSTORE_Handle *h,
223                             const struct GNUNET_HashCode *channel_id,
224                             const char *name,
225                             size_t value_size,
226                             const void *value,
227                             GNUNET_PSYCSTORE_ContinuationCallback ccb,
228                             void *ccb_cls);
229
230
231 /** 
232  * Function called with the value of a state variable.
233  *
234  * @param cls Closure.
235  * @param name Name of variable.
236  * @param size Size of @a value.
237  * @param value Value of variable.
238 t * 
239  */
240 typedef void (*GNUNET_PSYCSTORE_StateResultCallback)(void *cls,
241                                                      const char *name,
242                                                      size_t size,
243                                                      const void *value);
244
245
246 /** 
247  * Retrieve the given state variable for a channel.
248  *
249  * @param h Handle for the PSYCstore.
250  * @param channel_id The channel we are interested in.
251  * @param name Name of variable to get.
252  * @param rcb Callback to call with the result.
253  * @param rcb_cls Closure for the callback.
254  * 
255  * @return Handle that can be used to cancel the operation.
256  */
257 struct GNUNET_PSYCSTORE_OperationHandle *
258 GNUNET_PSYCSTORE_state_get (struct GNUNET_PSYCSTORE_Handle *h,
259                             const struct GNUNET_HashCode *channel_id,
260                             const char *name,
261                             GNUNET_PSYCSTORE_StateResultCallback rcb,
262                             void *rcb_cls);
263
264
265 /** 
266  * Retrieve all state variables for a channel.
267  *
268  * @param h Handle for the PSYCstore.
269  * @param channel_id The channel we are interested in.
270  * @param rcb Callback to call with the result.
271  * @param rcb_cls Closure for the callback.
272  * 
273  * @return Handle that can be used to cancel the operation.
274  */
275 struct GNUNET_PSYCSTORE_OperationHandle *
276 GNUNET_PSYCSTORE_state_get_all (struct GNUNET_PSYCSTORE_Handle *h,
277                                 const struct GNUNET_HashCode *channel_id,
278                                 GNUNET_PSYCSTORE_StateResultCallback rcb,
279                                 void *rcb_cls);
280
281
282 /** 
283  * Cancel an operation.
284  *
285  * @param oh Handle for the operation to cancel.
286  */
287 void
288 GNUNET_PSYCSTORE_operation_cancel (struct GNUNET_PSYCSTORE_OperationHandle *oh);
289
290
291
292
293 #if 0                           /* keep Emacsens' auto-indent happy */
294 {
295 #endif
296 #ifdef __cplusplus
297 }
298 #endif
299
300 /* ifndef GNUNET_PSYCSTORE_SERVICE_H */
301 #endif
302 /* end of gnunet_psycstore_service.h */