diff options
author | Gabor X Toth <*@tg-x.net> | 2013-08-29 15:14:17 +0000 |
---|---|---|
committer | Gabor X Toth <*@tg-x.net> | 2013-08-29 15:14:17 +0000 |
commit | 81eaa5a9d5ebe1e61790069a2777178abd1b6a2c (patch) | |
tree | 2b24561b930dca7ede2d27590e1c434fe19ed365 /src/include | |
parent | b1ed5b9a472bd56796646a70068eb48da0db3e2f (diff) | |
download | gnunet-81eaa5a9d5ebe1e61790069a2777178abd1b6a2c.tar.gz gnunet-81eaa5a9d5ebe1e61790069a2777178abd1b6a2c.zip |
psycstore: sqlite plugin
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/gnunet_protocols.h | 10 | ||||
-rw-r--r-- | src/include/gnunet_psycstore_plugin.h | 237 | ||||
-rw-r--r-- | src/include/gnunet_psycstore_service.h | 137 |
3 files changed, 344 insertions, 40 deletions
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index 6c2530d96..92206f97e 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h | |||
@@ -1944,6 +1944,16 @@ extern "C" | |||
1944 | */ | 1944 | */ |
1945 | #define GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_CODE 650 | 1945 | #define GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_CODE 650 |
1946 | 1946 | ||
1947 | /** | ||
1948 | * Store a membership event. | ||
1949 | */ | ||
1950 | #define GNUNET_MESSAGE_TYPE_PSYCSTORE_MEMBERSHIP_STORE 651 | ||
1951 | |||
1952 | /** | ||
1953 | * Test for membership of a member at a particular point in time. | ||
1954 | */ | ||
1955 | #define GNUNET_MESSAGE_TYPE_PSYCSTORE_MEMBERSHIP_TEST 652 | ||
1956 | |||
1947 | 1957 | ||
1948 | /** | 1958 | /** |
1949 | * Next available: 670 | 1959 | * Next available: 670 |
diff --git a/src/include/gnunet_psycstore_plugin.h b/src/include/gnunet_psycstore_plugin.h new file mode 100644 index 000000000..e567de278 --- /dev/null +++ b/src/include/gnunet_psycstore_plugin.h | |||
@@ -0,0 +1,237 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | (C) 2012, 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_plugin.h | ||
23 | * @brief plugin API for the PSYCstore database backend | ||
24 | * @author Gabor X Toth | ||
25 | */ | ||
26 | #ifndef GNUNET_PSYCSTORE_PLUGIN_H | ||
27 | #define GNUNET_PSYCSTORE_PLUGIN_H | ||
28 | |||
29 | #include "gnunet_common.h" | ||
30 | #include "gnunet_util_lib.h" | ||
31 | #include "gnunet_psycstore_service.h" | ||
32 | |||
33 | #ifdef __cplusplus | ||
34 | extern "C" | ||
35 | { | ||
36 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
37 | } | ||
38 | #endif | ||
39 | #endif | ||
40 | |||
41 | |||
42 | /** | ||
43 | * @brief struct returned by the initialization function of the plugin | ||
44 | */ | ||
45 | struct GNUNET_PSYCSTORE_PluginFunctions | ||
46 | { | ||
47 | |||
48 | /** | ||
49 | * Closure to pass to all plugin functions. | ||
50 | */ | ||
51 | void *cls; | ||
52 | |||
53 | /** | ||
54 | * Store join/leave events for a PSYC channel in order to be able to answer | ||
55 | * membership test queries later. | ||
56 | * | ||
57 | * @see GNUNET_PSYCSTORE_membership_store() | ||
58 | * | ||
59 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR | ||
60 | */ | ||
61 | int | ||
62 | (*membership_store) (void *cls, | ||
63 | const struct GNUNET_HashCode *channel_key, | ||
64 | const struct GNUNET_HashCode *slave_key, | ||
65 | int did_join, | ||
66 | uint64_t announced_at, | ||
67 | uint64_t effective_since, | ||
68 | uint64_t group_generation); | ||
69 | |||
70 | /** | ||
71 | * Test if a member was admitted to the channel at the given message ID. | ||
72 | * | ||
73 | * @see GNUNET_PSYCSTORE_membership_test() | ||
74 | * | ||
75 | * @return #GNUNET_YES if the member was admitted, #GNUNET_NO if not, | ||
76 | * #GNUNET_SYSERR if there was en error. | ||
77 | */ | ||
78 | int | ||
79 | (*membership_test) (void *cls, | ||
80 | const struct GNUNET_CRYPTO_EccPublicKey *channel_key, | ||
81 | const struct GNUNET_CRYPTO_EccPublicKey *slave_key, | ||
82 | uint64_t message_id, | ||
83 | uint64_t group_generation); | ||
84 | |||
85 | /** | ||
86 | * Store a message fragment sent to a channel. | ||
87 | * | ||
88 | * @see GNUNET_PSYCSTORE_fragment_store() | ||
89 | * | ||
90 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR | ||
91 | */ | ||
92 | int | ||
93 | (*fragment_store) (void *cls, | ||
94 | const struct GNUNET_CRYPTO_EccPublicKey *channel_key, | ||
95 | const struct GNUNET_MULTICAST_MessageHeader *message); | ||
96 | |||
97 | /** | ||
98 | * Set additional flags for a given message. | ||
99 | * | ||
100 | * @param message_id ID of the message. | ||
101 | * @param flags Flags to add. | ||
102 | * | ||
103 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR | ||
104 | */ | ||
105 | int | ||
106 | (*fragment_add_flags) (void *cls, | ||
107 | const struct GNUNET_CRYPTO_EccPublicKey *channel_key, | ||
108 | uint64_t message_id, | ||
109 | uint64_t multicast_flags, | ||
110 | uint64_t psyc_flags); | ||
111 | |||
112 | /** | ||
113 | * Retrieve a message fragment by fragment ID. | ||
114 | * | ||
115 | * @see GNUNET_PSYCSTORE_fragment_get() | ||
116 | * | ||
117 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR | ||
118 | */ | ||
119 | int | ||
120 | (*fragment_get) (void *cls, | ||
121 | const struct GNUNET_CRYPTO_EccPublicKey *channel_key, | ||
122 | uint64_t fragment_id, | ||
123 | GNUNET_PSYCSTORE_FragmentCallback cb, | ||
124 | void *cb_cls); | ||
125 | |||
126 | /** | ||
127 | * Retrieve all fragments of a message. | ||
128 | * | ||
129 | * @see GNUNET_PSYCSTORE_message_get() | ||
130 | * | ||
131 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR | ||
132 | */ | ||
133 | int | ||
134 | (*message_get) (void *cls, | ||
135 | const struct GNUNET_CRYPTO_EccPublicKey *channel_key, | ||
136 | uint64_t message_id, | ||
137 | GNUNET_PSYCSTORE_FragmentCallback cb, | ||
138 | void *cb_cls); | ||
139 | |||
140 | /** | ||
141 | * Retrieve a fragment of message specified by its message ID and fragment | ||
142 | * offset. | ||
143 | * | ||
144 | * @see GNUNET_PSYCSTORE_message_get_fragment() | ||
145 | * | ||
146 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR | ||
147 | */ | ||
148 | int | ||
149 | (*message_get_fragment) (void *cls, | ||
150 | const struct GNUNET_CRYPTO_EccPublicKey *channel_key, | ||
151 | uint64_t message_id, | ||
152 | uint64_t fragment_offset, | ||
153 | GNUNET_PSYCSTORE_FragmentCallback cb, | ||
154 | void *cb_cls); | ||
155 | |||
156 | /** | ||
157 | * Retrieve latest values of counters for a channel master. | ||
158 | * | ||
159 | * @see GNUNET_PSYCSTORE_counters_get_master() | ||
160 | * | ||
161 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR | ||
162 | */ | ||
163 | int | ||
164 | (*counters_get_master) (void *cls, | ||
165 | const struct GNUNET_CRYPTO_EccPublicKey *channel_key, | ||
166 | uint64_t *fragment_id, | ||
167 | uint64_t *message_id, | ||
168 | uint64_t *group_generation); | ||
169 | |||
170 | /** | ||
171 | * Retrieve latest values of counters for a channel slave. | ||
172 | * | ||
173 | * @see GNUNET_PSYCSTORE_counters_get_slave() | ||
174 | * | ||
175 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR | ||
176 | */ | ||
177 | int | ||
178 | (*counters_get_slave) (void *cls, | ||
179 | const struct GNUNET_CRYPTO_EccPublicKey *channel_key, | ||
180 | uint64_t *max_state_msg_id); | ||
181 | |||
182 | /** | ||
183 | * Set a state variable to the given value. | ||
184 | * | ||
185 | * @see GNUNET_PSYCSTORE_state_modify() | ||
186 | * | ||
187 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR | ||
188 | */ | ||
189 | int | ||
190 | (*state_set) (struct GNUNET_PSYCSTORE_Handle *h, | ||
191 | const struct GNUNET_CRYPTO_EccPublicKey *channel_key, | ||
192 | const char *name, | ||
193 | size_t value_size, | ||
194 | const void *value); | ||
195 | |||
196 | /** | ||
197 | * Retrieve a state variable by name. | ||
198 | * | ||
199 | * @param name Name of the variable to retrieve. | ||
200 | * @param[out] value_size Size of value. | ||
201 | * @param[out] value Returned value. | ||
202 | * | ||
203 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR | ||
204 | */ | ||
205 | int | ||
206 | (*state_get) (struct GNUNET_PSYCSTORE_Handle *h, | ||
207 | const struct GNUNET_CRYPTO_EccPublicKey *channel_key, | ||
208 | const char *name, | ||
209 | GNUNET_PSYCSTORE_StateCallback cb, | ||
210 | void *cb_cls); | ||
211 | |||
212 | /** | ||
213 | * Retrieve all state variables for a channel with the given prefix. | ||
214 | * | ||
215 | * @see GNUNET_PSYCSTORE_state_get_all() | ||
216 | * | ||
217 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR | ||
218 | */ | ||
219 | int | ||
220 | (*state_get_all) (struct GNUNET_PSYCSTORE_Handle *h, | ||
221 | const struct GNUNET_CRYPTO_EccPublicKey *channel_key, | ||
222 | const char *name, | ||
223 | GNUNET_PSYCSTORE_StateCallback cb, | ||
224 | void *cb_cls); | ||
225 | |||
226 | }; | ||
227 | |||
228 | |||
229 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
230 | { | ||
231 | #endif | ||
232 | #ifdef __cplusplus | ||
233 | } | ||
234 | #endif | ||
235 | |||
236 | /* end of gnunet_psycstore_plugin.h */ | ||
237 | #endif | ||
diff --git a/src/include/gnunet_psycstore_service.h b/src/include/gnunet_psycstore_service.h index e3c7876a0..bbf5a7d19 100644 --- a/src/include/gnunet_psycstore_service.h +++ b/src/include/gnunet_psycstore_service.h | |||
@@ -78,43 +78,6 @@ struct GNUNET_PSYCSTORE_OperationHandle; | |||
78 | 78 | ||
79 | 79 | ||
80 | /** | 80 | /** |
81 | * Callback used to return the latest value of counters of a channel. | ||
82 | * | ||
83 | * @see GNUNET_PSYCSTORE_counters_get() | ||
84 | * | ||
85 | * @param *cls Closure. | ||
86 | * @param fragment_id Latest message fragment ID, used by multicast. | ||
87 | * @param message_id Latest message ID, used by PSYC. | ||
88 | * @param group_generation Latest group generation, used by PSYC. | ||
89 | */ | ||
90 | typedef void | ||
91 | (*GNUNET_PSYCSTORE_CountersCallback) (void *cls, | ||
92 | uint64_t fragment_id, | ||
93 | uint64_t message_id, | ||
94 | uint64_t group_generation); | ||
95 | |||
96 | |||
97 | /** | ||
98 | * Retrieve latest values of counters for a channel. | ||
99 | * | ||
100 | * The current value of counters are needed when a channel master is restarted, | ||
101 | * so that it can continue incrementing the counters from their last value. | ||
102 | * | ||
103 | * @param h Handle for the PSYCstore. | ||
104 | * @param channel_key Public key that identifies the channel. | ||
105 | * @param cb Callback to call with the result. | ||
106 | * @param cb_cls Closure for the callback. | ||
107 | * | ||
108 | * @return | ||
109 | */ | ||
110 | struct GNUNET_PSYCSTORE_OperationHandle * | ||
111 | GNUNET_PSYCSTORE_counters_get (struct GNUNET_PSYCSTORE_Handle *h, | ||
112 | struct GNUNET_CRYPTO_EccPublicKey *channel_key, | ||
113 | GNUNET_PSYCSTORE_CountersCallback *cb, | ||
114 | void *cb_cls); | ||
115 | |||
116 | |||
117 | /** | ||
118 | * Function called with the result of an asynchronous operation. | 81 | * Function called with the result of an asynchronous operation. |
119 | * | 82 | * |
120 | * @param result #GNUNET_SYSERR on error, | 83 | * @param result #GNUNET_SYSERR on error, |
@@ -159,9 +122,12 @@ GNUNET_PSYCSTORE_membership_store (struct GNUNET_PSYCSTORE_Handle *h, | |||
159 | 122 | ||
160 | 123 | ||
161 | /** | 124 | /** |
162 | * Test if a peer was a member of the channel during the given period specified by the group generation. | 125 | * Test if a member was admitted to the channel at the given message ID. |
163 | * | 126 | * |
164 | * 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. | 127 | * This is useful when relaying and replaying messages to check if a particular |
128 | * slave has access to the message fragment with a given group generation. It | ||
129 | * is also used when handling join requests to determine whether the slave is | ||
130 | * currently admitted to the channel. | ||
165 | * | 131 | * |
166 | * @param h Handle for the PSYCstore. | 132 | * @param h Handle for the PSYCstore. |
167 | * @param channel_key The channel we are interested in. | 133 | * @param channel_key The channel we are interested in. |
@@ -239,7 +205,7 @@ GNUNET_PSYCSTORE_fragment_get (struct GNUNET_PSYCSTORE_Handle *h, | |||
239 | 205 | ||
240 | 206 | ||
241 | /** | 207 | /** |
242 | * Retrieve a message by ID. | 208 | * Retrieve all fragments of a message. |
243 | * | 209 | * |
244 | * @param h Handle for the PSYCstore. | 210 | * @param h Handle for the PSYCstore. |
245 | * @param channel_key The channel we are interested in. | 211 | * @param channel_key The channel we are interested in. |
@@ -258,6 +224,97 @@ GNUNET_PSYCSTORE_message_get (struct GNUNET_PSYCSTORE_Handle *h, | |||
258 | 224 | ||
259 | 225 | ||
260 | /** | 226 | /** |
227 | * Retrieve a fragment of message specified by its message ID and fragment offset. | ||
228 | * | ||
229 | * @param h Handle for the PSYCstore. | ||
230 | * @param channel_key The channel we are interested in. | ||
231 | * @param message_id Message ID to check. Use 0 to get the latest message. | ||
232 | * @param fragment_offset Offset of the fragment to retrieve. | ||
233 | * @param cb Callback to call with the retrieved fragments. | ||
234 | * @param cb_cls Closure for the callback. | ||
235 | * | ||
236 | * @return Handle that can be used to cancel the operation. | ||
237 | */ | ||
238 | struct GNUNET_PSYCSTORE_OperationHandle * | ||
239 | GNUNET_PSYCSTORE_message_get_fragment (struct GNUNET_PSYCSTORE_Handle *h, | ||
240 | const struct GNUNET_CRYPTO_EccPublicKey *channel_key, | ||
241 | uint64_t message_id, | ||
242 | uint64_t fragment_offset, | ||
243 | GNUNET_PSYCSTORE_FragmentCallback cb, | ||
244 | void *cb_cls); | ||
245 | |||
246 | |||
247 | /** | ||
248 | * Callback used to return the latest value of counters for the channel master. | ||
249 | * | ||
250 | * @see GNUNET_PSYCSTORE_counters_get_master() | ||
251 | * | ||
252 | * @param cls Closure. | ||
253 | * @param fragment_id Latest message fragment ID, used by multicast. | ||
254 | * @param message_id Latest message ID, used by PSYC. | ||
255 | * @param group_generation Latest group generation, used by PSYC. | ||
256 | */ | ||
257 | typedef void | ||
258 | (*GNUNET_PSYCSTORE_MasterCountersCallback) (void *cls, | ||
259 | uint64_t fragment_id, | ||
260 | uint64_t message_id, | ||
261 | uint64_t group_generation); | ||
262 | |||
263 | |||
264 | /** | ||
265 | * Callback used to return the latest value of counters for a channel slave. | ||
266 | * | ||
267 | * @see GNUNET_PSYCSTORE_counters_get_slave() | ||
268 | * | ||
269 | * @param cls Closure. | ||
270 | * @param max_state_msg_id Latest message ID containing state modifiers that was applied to the state store. Used for the state sync process. | ||
271 | */ | ||
272 | typedef void | ||
273 | (*GNUNET_PSYCSTORE_SlaveCountersCallback) (void *cls, | ||
274 | uint64_t max_state_msg_id); | ||
275 | |||
276 | |||
277 | /** | ||
278 | * Retrieve latest values of counters for a channel master. | ||
279 | * | ||
280 | * The current value of counters are needed when a channel master is restarted, | ||
281 | * so that it can continue incrementing the counters from their last value. | ||
282 | * | ||
283 | * @param h Handle for the PSYCstore. | ||
284 | * @param channel_key Public key that identifies the channel. | ||
285 | * @param cb Callback to call with the result. | ||
286 | * @param cb_cls Closure for the callback. | ||
287 | * | ||
288 | * @return | ||
289 | */ | ||
290 | struct GNUNET_PSYCSTORE_OperationHandle * | ||
291 | GNUNET_PSYCSTORE_counters_get_master (struct GNUNET_PSYCSTORE_Handle *h, | ||
292 | struct GNUNET_CRYPTO_EccPublicKey *channel_key, | ||
293 | GNUNET_PSYCSTORE_MasterCountersCallback *cb, | ||
294 | void *cb_cls); | ||
295 | |||
296 | |||
297 | /** | ||
298 | * Retrieve latest values of counters for a channel slave. | ||
299 | * | ||
300 | * The current value of counters are needed when a channel slave rejoins | ||
301 | * and starts the state synchronization process. | ||
302 | * | ||
303 | * @param h Handle for the PSYCstore. | ||
304 | * @param channel_key Public key that identifies the channel. | ||
305 | * @param cb Callback to call with the result. | ||
306 | * @param cb_cls Closure for the callback. | ||
307 | * | ||
308 | * @return | ||
309 | */ | ||
310 | struct GNUNET_PSYCSTORE_OperationHandle * | ||
311 | GNUNET_PSYCSTORE_counters_get_slave (struct GNUNET_PSYCSTORE_Handle *h, | ||
312 | struct GNUNET_CRYPTO_EccPublicKey *channel_key, | ||
313 | GNUNET_PSYCSTORE_SlaveCountersCallback *cb, | ||
314 | void *cb_cls); | ||
315 | |||
316 | |||
317 | /** | ||
261 | * Apply modifiers of a message to the current channel state. | 318 | * Apply modifiers of a message to the current channel state. |
262 | * | 319 | * |
263 | * An error is returned if there are missing messages containing state | 320 | * An error is returned if there are missing messages containing state |