864b95105e4a04aeb7a285684719ff64ee1ee2b0
[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  * Function called with the result of an asynchronous operation.
80 ; * 
81  * @param result #GNUNET_SYSERR on error,
82  *        #GNUNET_YES on success or if the peer was a member,
83  *        #GNUNET_NO if the peer was not a member
84  */
85 typedef void (*GNUNET_PSYCSTORE_ContinuationCallback)(void *cls,
86                                                       int result);
87
88 /** 
89  * Store join/leave events for a PSYC channel in order to be able to answer
90  * membership test queries later.
91  *
92  * @param h Handle for the PSYCstore.
93  * @param channel_id ID of the channel where the event happened.
94  * @param message_id ID of the message in which 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                                    const struct GNUNET_PeerIdentity *peer,
107                                    int did_join,
108                                    GNUNET_PSYCSTORE_ContinuationCallback ccb,
109                                    void *ccb_cls);
110
111
112 /** 
113  * Test if a peer was a member of the channel when the message fragment with the
114  * specified ID was sent to the channel.
115  *
116  * This is useful in case of retransmissions to check if the peer was authorized
117  * to see the requested message.
118  *
119  * @param h Handle for the PSYCstore.
120  * @param channel_id The channel we are interested in.
121  * @param fragment_id Message fragment ID to check.
122  * @param peer Peer whose membership to check.
123  * @param ccb Callback to call with the test result.
124  * @param ccb_cls Closure for the callback.
125  *
126  * @return Operation handle that can be used to cancel the operation.
127  */
128 struct GNUNET_PSYCSTORE_OperationHandle *
129 GNUNET_PSYCSTORE_membership_test (struct GNUNET_PSYCSTORE_Handle *h,
130                                   const struct GNUNET_HashCode *channel_id,
131                                   uint64_t fragment_id,
132                                   const struct GNUNET_PeerIdentity *peer,
133                                   GNUNET_PSYCSTORE_ContinuationCallback ccb,
134                                   void *ccb_cls);
135
136
137 /** 
138  * Store a message fragment sent to a channel.
139  *
140  * @param h Handle for the PSYCstore.
141  * @param channel_id The channel the message belongs to.
142  * @param message Message to store.
143  * @param ccb Callback to call with the result of the operation.
144  * @param ccb_cls Closure for the callback.
145  * 
146  * @return Handle that can be used to cancel the operation.
147  */
148 struct GNUNET_PSYCSTORE_OperationHandle *
149 GNUNET_PSYCSTORE_fragment_store (struct GNUNET_PSYCSTORE_Handle *h,
150                                  const struct GNUNET_HashCode *channel_id,
151                                  const struct GNUNET_MULTICAST_MessageHeader *message,
152                                  GNUNET_PSYCSTORE_ContinuationCallback ccb,
153                                  void *ccb_cls);
154
155
156 /** 
157  * Function called with one message fragment, as the result of a
158  * GNUNET_PSYCSTORE_fragment_get() or GNUNET_PSYCSTORE_message_get() call.
159  *
160  * @param cls Closure.
161  * @param message The retrieved message fragment.
162  * @param flags Message flags indicating fragmentation status.
163  */
164 typedef void (*GNUNET_PSYCSTORE_FragmentResultCallback)(void *cls,
165                                                        const struct GNUNET_MULTICAST_MessageHeader *message,
166                                                        enum GNUNET_PSYC_MessageFlags flags);
167
168
169 /** 
170  * Retrieve a message fragment by fragment ID.
171  *
172  * @param h Handle for the PSYCstore.
173  * @param channel_id The channel we are interested in.
174  * @param fragment_id Fragment ID to check.  Use 0 to get the latest message fragment.
175  * @param rcb Callback to call with the result of the operation.
176  * @param rcb_cls Closure for the callback.
177  * 
178  * @return Handle that can be used to cancel the operation.
179  */
180 struct GNUNET_PSYCSTORE_OperationHandle *
181 GNUNET_PSYCSTORE_fragment_get (struct GNUNET_PSYCSTORE_Handle *h,
182                                const struct GNUNET_HashCode *channel_id,
183                                uint64_t fragment_id,
184                                GNUNET_PSYCSTORE_FragmentResultCallback rcb,
185                                void *rcb_cls);
186
187
188 /** 
189  * Retrieve a message by ID.
190  *
191  * @param h Handle for the PSYCstore.
192  * @param channel_id The channel we are interested in.
193  * @param message_id Message ID to check.  Use 0 to get the latest message.
194  * @param rcb Callback to call with the result of the operation.
195  * @param rcb_cls Closure for the callback.
196  * 
197  * @return Handle that can be used to cancel the operation.
198  */
199 struct GNUNET_PSYCSTORE_OperationHandle *
200 GNUNET_PSYCSTORE_message_get (struct GNUNET_PSYCSTORE_Handle *h,
201                               const struct GNUNET_HashCode *channel_id,
202                               uint64_t message_id,
203                               GNUNET_PSYCSTORE_FragmentResultCallback rcb,
204                               void *rcb_cls);
205
206
207 /** 
208  * Modify the channel state.
209  *
210  * Applies the operation to the current channel state.
211  *
212  * An error is returned if there are missing messages containing state
213  * operations before the current one.
214  *
215  * @param h Handle for the PSYCstore.
216  * @param channel_id The channel we are interested in.
217  * @param message_id ID of the message that contains this state modifier.
218  * @param oper Operation to perform.
219  * @param name Name of variable.
220  * @param value_size Size of @a value.
221  * @param value Value of variable.
222  * @param ccb Callback to call with the result of the operation.
223  * @param ccb_cls Closure for the callback.
224  * 
225  * @return Handle that can be used to cancel the operation.
226  */
227 struct GNUNET_PSYCSTORE_OperationHandle *
228 GNUNET_PSYCSTORE_state_modify (struct GNUNET_PSYCSTORE_Handle *h,
229                                const struct GNUNET_HashCode *channel_id,
230                                uint64_t message_id,
231                                enum GNUNET_ENV_Operator *oper,
232                                const char *name,
233                                size_t value_size,
234                                const void *value,
235                                GNUNET_PSYCSTORE_ContinuationCallback ccb,
236                                void *ccb_cls);
237
238
239 /** 
240  * Function called with the value of a state variable.
241  *
242  * @param cls Closure.
243  * @param name Name of variable.
244  * @param size Size of @a value.
245  * @param value Value of variable.
246 t * 
247  */
248 typedef void (*GNUNET_PSYCSTORE_StateResultCallback)(void *cls,
249                                                      const char *name,
250                                                      size_t size,
251                                                      const void *value);
252
253
254 /** 
255  * Retrieve the given state variable for a channel.
256  *
257  * @param h Handle for the PSYCstore.
258  * @param channel_id The channel we are interested in.
259  * @param name Name of variable to get.
260  * @param rcb Callback to call with the result.
261  * @param rcb_cls Closure for the callback.
262  * 
263  * @return Handle that can be used to cancel the operation.
264  */
265 struct GNUNET_PSYCSTORE_OperationHandle *
266 GNUNET_PSYCSTORE_state_get (struct GNUNET_PSYCSTORE_Handle *h,
267                             const struct GNUNET_HashCode *channel_id,
268                             const char *name,
269                             GNUNET_PSYCSTORE_StateResultCallback rcb,
270                             void *rcb_cls);
271
272
273 /** 
274  * Retrieve all state variables for a channel.
275  *
276  * @param h Handle for the PSYCstore.
277  * @param channel_id The channel we are interested in.
278  * @param rcb Callback to call with the result.
279  * @param rcb_cls Closure for the callback.
280  * 
281  * @return Handle that can be used to cancel the operation.
282  */
283 struct GNUNET_PSYCSTORE_OperationHandle *
284 GNUNET_PSYCSTORE_state_get_all (struct GNUNET_PSYCSTORE_Handle *h,
285                                 const struct GNUNET_HashCode *channel_id,
286                                 GNUNET_PSYCSTORE_StateResultCallback rcb,
287                                 void *rcb_cls);
288
289
290 /** 
291  * Cancel an operation.
292  *
293  * @param oh Handle for the operation to cancel.
294  */
295 void
296 GNUNET_PSYCSTORE_operation_cancel (struct GNUNET_PSYCSTORE_OperationHandle *oh);
297
298
299
300
301 #if 0                           /* keep Emacsens' auto-indent happy */
302 {
303 #endif
304 #ifdef __cplusplus
305 }
306 #endif
307
308 /* ifndef GNUNET_PSYCSTORE_SERVICE_H */
309 #endif
310 /* end of gnunet_psycstore_service.h */