b7df5883a511d35e57c02d42fad64a2801d237e3
[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 tg(x)
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 peer Identity of joining/leaving peer.
95  * @param did_join #GNUNET_YES on join, #GNUNET_NO on leave.
96  * @param ccb Callback to call with the result of the storage operation.
97  * @param ccb_cls Closure for the callback.
98  *
99  * @return Operation handle that can be used to cancel the operation.
100  */
101 struct GNUNET_PSYCSTORE_OperationHandle *
102 GNUNET_PSYCSTORE_membership_store (struct GNUNET_PSYCSTORE_Handle *h,
103                                    const struct GNUNET_HashCode *channel_id,
104                                    uint64_t message_id,
105                                    const struct GNUNET_PeerIdentity *peer,
106                                    int did_join,
107                                    GNUNET_PSYCSTORE_ContinuationCallback ccb,
108                                    void *ccb_cls);
109
110
111 /** 
112  * Test if a peer was a member of the channel when the message with the
113  * specified ID was sent to the channel.
114  *
115  * This is useful in case of retransmissions to check if the peer was authorized
116  * to see the requested message.
117  *
118  * @param h Handle for the PSYCstore.
119  * @param channel_id The channel we are interested in.
120  * @param message_id Message ID to check.
121  * @param peer Peer whose membership to check.
122  * @param ccb Callback to call with the test result.
123  * @param ccb_cls Closure for the callback.
124  *
125  * @return Operation handle that can be used to cancel the operation.
126  */
127 struct GNUNET_PSYCSTORE_OperationHandle *
128 GNUNET_PSYCSTORE_membership_test (struct GNUNET_PSYCSTORE_Handle *h,
129                                   const struct GNUNET_HashCode *channel_id,
130                                   uint64_t message_id,
131                                   const struct GNUNET_PeerIdentity *peer,
132                                   GNUNET_PSYCSTORE_ContinuationCallback ccb,
133                                   void *ccb_cls);
134
135
136 /** 
137  * Store a message sent to a channel.
138  *
139  * @param h Handle for the PSYCstore.
140  * @param channel_id The channel the message belongs to.
141  * @param message Message to store.
142  * @param ccb Callback to call with the result of the operation.
143  * @param ccb_cls Closure for the callback.
144  * 
145  * @return Handle that can be used to cancel the operation.
146  */
147 struct GNUNET_PSYCSTORE_OperationHandle *
148 GNUNET_PSYCSTORE_message_store (struct GNUNET_PSYCSTORE_Handle *h,
149                                 const struct GNUNET_HashCode *channel_id,
150                                 const struct GNUNET_MULTICAST_MessageHeader *message,
151                                 GNUNET_PSYCSTORE_ContinuationCallback ccb,
152                                 void *ccb_cls);
153
154
155 /** 
156  * Function called with the result of a GNUNET_PSYCSTORE_message_get() call.
157  *
158  * @param cls Closure.
159  * @param message_id ID of the message.
160  * @param message The retrieved message.
161  */
162 typedef void (*GNUNET_PSYCSTORE_MessageResultCallback)(void *cls,       
163                                                        uint64_t message_id,                                    
164                                                        const struct GNUNET_MULTICAST_MessageHeader *message);
165
166
167 /** 
168  * Retrieve a message by ID.
169  *
170  * @param h Handle for the PSYCstore.
171  * @param channel_id The channel we are interested in.
172  * @param message_id Message ID to check.
173  * @param rcb Callback to call with the result of the operation.
174  * @param rcb_cls Closure for the callback.
175  * 
176  * @return Handle that can be used to cancel the operation.
177  */
178 struct GNUNET_PSYCSTORE_OperationHandle *
179 GNUNET_PSYCSTORE_message_get (struct GNUNET_PSYCSTORE_Handle *h,
180                               const struct GNUNET_HashCode *channel_id,
181                               uint64_t message_id,
182                               GNUNET_PSYCSTORE_MessageResultCallback rcb,
183                               void *rcb_cls);
184
185
186 /** 
187  * Get latest message sent to a channel.
188  *
189  * @param h Handle for the PSYCstore.
190  * @param channel_id The channel we are interested in.
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_message_get_latest (struct GNUNET_PSYCSTORE_Handle *h,
198                                      const struct GNUNET_HashCode *channel_id,
199                                      GNUNET_PSYCSTORE_MessageResultCallback rcb,
200                                      void *rcb_cls);
201
202
203 /** 
204  * Store a state variable.
205  *
206  * @param h Handle for the PSYCstore.
207  * @param channel_id The channel we are interested in.
208  * @param name Name of variable.
209  * @param size Size of @a value.
210  * @param value Value of variable.
211  * @param ccb Callback to call with the result of the operation.
212  * @param ccb_cls Closure for the callback.
213  * 
214  * @return Handle that can be used to cancel the operation.
215  */
216 struct GNUNET_PSYCSTORE_OperationHandle *
217 GNUNET_PSYCSTORE_state_set (struct GNUNET_PSYCSTORE_Handle *h,
218                             const struct GNUNET_HashCode *channel_id,
219                             const char *name,
220                             size_t size,
221                             const void *value,
222                             GNUNET_PSYCSTORE_ContinuationCallback ccb,
223                             void *ccb_cls);
224
225
226 /** 
227  * Function called with the value of a state variable.
228  *
229  * @param cls Closure.
230  * @param name Name of variable.
231  * @param size Size of @a value.
232  * @param value Value of variable.
233 t * 
234  */
235 typedef void (*GNUNET_PSYCSTORE_StateResultCallback)(void *cls,
236                                                      const char *name,
237                                                      size_t size,
238                                                      const void *value);
239
240
241 /** 
242  * Retrieve the given state variable for a channel.
243  *
244  * @param h Handle for the PSYCstore.
245  * @param channel_id The channel we are interested in.
246  * @param name Name of variable to get.
247  * @param rcb Callback to call with the result.
248  * @param rcb_cls Closure for the callback.
249  * 
250  * @return Handle that can be used to cancel the operation.
251  */
252 struct GNUNET_PSYCSTORE_OperationHandle *
253 GNUNET_PSYCSTORE_state_get (struct GNUNET_PSYCSTORE_Handle *h,
254                             const struct GNUNET_HashCode *channel_id,
255                             const char *name,
256                             GNUNET_PSYCSTORE_StateResultCallback rcb,
257                             void *rcb_cls);
258
259
260 /** 
261  * Retrieve all state variables for a channel.
262  *
263  * @param h Handle for the PSYCstore.
264  * @param channel_id The channel we are interested in.
265  * @param rcb Callback to call with the result.
266  * @param rcb_cls Closure for the callback.
267  * 
268  * @return Handle that can be used to cancel the operation.
269  */
270 struct GNUNET_PSYCSTORE_OperationHandle *
271 GNUNET_PSYCSTORE_state_get_all (struct GNUNET_PSYCSTORE_Handle *h,
272                                 const struct GNUNET_HashCode *channel_id,
273                                 GNUNET_PSYCSTORE_StateResultCallback rcb,
274                                 void *rcb_cls);
275
276
277 /** 
278  * Cancel an operation.
279  *
280  * @param oh Handle for the operation to cancel.
281  */
282 void
283 GNUNET_PSYCSTORE_operation_cancel (struct GNUNET_PSYCSTORE_OperationHandle *oh);
284
285
286
287
288 #if 0                           /* keep Emacsens' auto-indent happy */
289 {
290 #endif
291 #ifdef __cplusplus
292 }
293 #endif
294
295 /* ifndef GNUNET_PSYCSTORE_SERVICE_H */
296 #endif
297 /* end of gnunet_psycstore_service.h */