diff options
author | Gabor X Toth <*@tg-x.net> | 2013-09-16 04:59:05 +0000 |
---|---|---|
committer | Gabor X Toth <*@tg-x.net> | 2013-09-16 04:59:05 +0000 |
commit | f78e9753a91497f1deb5e20d10868c27ab4a6013 (patch) | |
tree | f49653367e00fd4b611ec6ec281144d4568bd111 /src/psycstore/test_psycstore.c | |
parent | fbae7143d25a258b9dfabefa9ca3956e9228cb0e (diff) | |
download | gnunet-f78e9753a91497f1deb5e20d10868c27ab4a6013.tar.gz gnunet-f78e9753a91497f1deb5e20d10868c27ab4a6013.zip |
PSYCstore service and API implementation
Diffstat (limited to 'src/psycstore/test_psycstore.c')
-rw-r--r-- | src/psycstore/test_psycstore.c | 452 |
1 files changed, 405 insertions, 47 deletions
diff --git a/src/psycstore/test_psycstore.c b/src/psycstore/test_psycstore.c index db4cfb0eb..b238d98c5 100644 --- a/src/psycstore/test_psycstore.c +++ b/src/psycstore/test_psycstore.c | |||
@@ -1,26 +1,26 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | * This file is part of GNUnet |
3 | (C) 2013 Christian Grothoff (and other contributing authors) | 3 | * (C) 2013 Christian Grothoff (and other contributing authors) |
4 | 4 | * | |
5 | GNUnet is free software; you can redistribute it and/or modify | 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 | 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 | 7 | * by the Free Software Foundation; either version 3, or (at your |
8 | option) any later version. | 8 | * option) any later version. |
9 | 9 | * | |
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | * GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | General Public License for more details. | 13 | * General Public License for more details. |
14 | 14 | * | |
15 | You should have received a copy of the GNU General Public License | 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 | 16 | * along with GNUnet; see the file COPYING. If not, write to the |
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | * Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file psycstore/test_psycstore.c | 22 | * @file psycstore/test_psycstore.c |
23 | * @brief Testcase for the PSYCstore service | 23 | * @brief Test for the PSYCstore service. |
24 | * @author Gabor X Toth | 24 | * @author Gabor X Toth |
25 | * @author Christian Grothoff | 25 | * @author Christian Grothoff |
26 | */ | 26 | */ |
@@ -31,9 +31,13 @@ | |||
31 | #include "gnunet_psycstore_service.h" | 31 | #include "gnunet_psycstore_service.h" |
32 | #include "gnunet_testing_lib.h" | 32 | #include "gnunet_testing_lib.h" |
33 | 33 | ||
34 | #define ASSERT(x) do { if (! (x)) { printf ("Error at %s:%d\n", __FILE__, __LINE__); cleanup (); return; } } while (0) | ||
35 | #define ASSERRT(x) do { if (! (x)) { printf ("Error at %s:%d\n", __FILE__, __LINE__); cleanup (); return GNUNET_SYSERR; } } while (0) | ||
34 | 36 | ||
35 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | 37 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) |
36 | 38 | ||
39 | #define DEBUG_SERVICE 1 | ||
40 | |||
37 | 41 | ||
38 | /** | 42 | /** |
39 | * Return value from 'main'. | 43 | * Return value from 'main'. |
@@ -52,8 +56,8 @@ static struct GNUNET_PSYCSTORE_OperationHandle *op; | |||
52 | 56 | ||
53 | /** | 57 | /** |
54 | * Handle for task for timeout termination. | 58 | * Handle for task for timeout termination. |
55 | */ | 59 | */ |
56 | static GNUNET_SCHEDULER_TaskIdentifier endbadly_task; | 60 | static GNUNET_SCHEDULER_TaskIdentifier end_badly_task; |
57 | 61 | ||
58 | static struct GNUNET_CRYPTO_EccPrivateKey *channel_key; | 62 | static struct GNUNET_CRYPTO_EccPrivateKey *channel_key; |
59 | static struct GNUNET_CRYPTO_EccPrivateKey *slave_key; | 63 | static struct GNUNET_CRYPTO_EccPrivateKey *slave_key; |
@@ -61,6 +65,23 @@ static struct GNUNET_CRYPTO_EccPrivateKey *slave_key; | |||
61 | static struct GNUNET_CRYPTO_EccPublicSignKey channel_pub_key; | 65 | static struct GNUNET_CRYPTO_EccPublicSignKey channel_pub_key; |
62 | static struct GNUNET_CRYPTO_EccPublicSignKey slave_pub_key; | 66 | static struct GNUNET_CRYPTO_EccPublicSignKey slave_pub_key; |
63 | 67 | ||
68 | static struct FragmentClosure | ||
69 | { | ||
70 | uint8_t n; | ||
71 | uint8_t n_expected; | ||
72 | uint64_t flags[16]; | ||
73 | struct GNUNET_MULTICAST_MessageHeader *msg[16]; | ||
74 | } fcls; | ||
75 | |||
76 | struct StateClosure { | ||
77 | size_t n; | ||
78 | char *name[16]; | ||
79 | void *value[16]; | ||
80 | size_t value_size[16]; | ||
81 | } scls; | ||
82 | |||
83 | static struct GNUNET_ENV_Modifier modifiers[16]; | ||
84 | |||
64 | /** | 85 | /** |
65 | * Clean up all resources used. | 86 | * Clean up all resources used. |
66 | */ | 87 | */ |
@@ -92,21 +113,21 @@ cleanup () | |||
92 | 113 | ||
93 | 114 | ||
94 | /** | 115 | /** |
95 | * Termiante the testcase (failure). | 116 | * Terminate the testcase (failure). |
96 | * | 117 | * |
97 | * @param cls NULL | 118 | * @param cls NULL |
98 | * @param tc scheduler context | 119 | * @param tc scheduler context |
99 | */ | 120 | */ |
100 | static void | 121 | static void |
101 | endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 122 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
102 | { | 123 | { |
103 | cleanup (); | ||
104 | res = 1; | 124 | res = 1; |
125 | cleanup (); | ||
105 | } | 126 | } |
106 | 127 | ||
107 | 128 | ||
108 | /** | 129 | /** |
109 | * Termiante the testcase (success). | 130 | * Terminate the testcase (success). |
110 | * | 131 | * |
111 | * @param cls NULL | 132 | * @param cls NULL |
112 | * @param tc scheduler context | 133 | * @param tc scheduler context |
@@ -114,32 +135,361 @@ endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
114 | static void | 135 | static void |
115 | end_normally (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 136 | end_normally (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
116 | { | 137 | { |
117 | cleanup (); | ||
118 | res = 0; | 138 | res = 0; |
139 | cleanup (); | ||
119 | } | 140 | } |
120 | 141 | ||
121 | 142 | ||
122 | /** | 143 | /** |
123 | * Finish the testcase (successfully). | 144 | * Finish the testcase (successfully). |
124 | */ | 145 | */ |
125 | static void | 146 | static void |
126 | end () | 147 | end () |
127 | { | 148 | { |
128 | if (endbadly_task != GNUNET_SCHEDULER_NO_TASK) | 149 | if (end_badly_task != GNUNET_SCHEDULER_NO_TASK) |
129 | { | 150 | { |
130 | GNUNET_SCHEDULER_cancel (endbadly_task); | 151 | GNUNET_SCHEDULER_cancel (end_badly_task); |
131 | endbadly_task = GNUNET_SCHEDULER_NO_TASK; | 152 | end_badly_task = GNUNET_SCHEDULER_NO_TASK; |
132 | } | 153 | } |
133 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS, | 154 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS, |
134 | &end_normally, NULL); | 155 | &end_normally, NULL); |
135 | } | 156 | } |
136 | 157 | ||
158 | |||
159 | void | ||
160 | state_reset_result (void *cls, int64_t result, const char *err_msg) | ||
161 | { | ||
162 | op = NULL; | ||
163 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "state_reset_result:\t%d\n", result); | ||
164 | ASSERT (GNUNET_OK == result); | ||
165 | |||
166 | op = GNUNET_PSYCSTORE_state_reset (h, &channel_pub_key, | ||
167 | &state_reset_result, cls); | ||
168 | GNUNET_PSYCSTORE_operation_cancel (op); | ||
169 | op = NULL; | ||
170 | end (); | ||
171 | } | ||
172 | |||
173 | |||
174 | static int | ||
175 | state_result (void *cls, const char *name, const void *value, size_t value_size) | ||
176 | { | ||
177 | struct StateClosure *scls = cls; | ||
178 | const char *nam = scls->name[scls->n]; | ||
179 | const void *val = scls->value[scls->n]; | ||
180 | size_t val_size = scls->value_size[scls->n++]; | ||
181 | |||
182 | if (value_size == val_size | ||
183 | && 0 == memcmp (value, val, val_size) | ||
184 | && 0 == strcmp (name, nam)) | ||
185 | { | ||
186 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " variable %s matches\n", name); | ||
187 | return GNUNET_YES; | ||
188 | } | ||
189 | else | ||
190 | { | ||
191 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
192 | " variable %s differs\nReceived: %.*s\nExpected: %.*s\n", | ||
193 | name, value_size, value, val_size, val); | ||
194 | ASSERRT (0); | ||
195 | return GNUNET_SYSERR; | ||
196 | } | ||
197 | } | ||
198 | |||
199 | |||
200 | void | ||
201 | state_get_prefix_result (void *cls, int64_t result, const char *err_msg) | ||
202 | { | ||
203 | struct StateClosure *scls = cls; | ||
204 | op = NULL; | ||
205 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "state_get_prefix_result:\t%d\n", result); | ||
206 | ASSERT (GNUNET_OK == result && 2 == scls->n); | ||
207 | |||
208 | op = GNUNET_PSYCSTORE_state_reset (h, &channel_pub_key, | ||
209 | &state_reset_result, cls); | ||
210 | } | ||
211 | |||
212 | |||
213 | void | ||
214 | state_get_result (void *cls, int64_t result, const char *err_msg) | ||
215 | { | ||
216 | op = NULL; | ||
217 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "state_get_result:\t%d\n", result); | ||
218 | ASSERT (GNUNET_OK == result); | ||
219 | |||
220 | scls.n = 0; | ||
221 | |||
222 | scls.name[0] = "_sync_bar"; | ||
223 | scls.value[0] = "ten eleven twelve"; | ||
224 | scls.value_size[0] = sizeof ("ten eleven twelve") - 1; | ||
225 | |||
226 | scls.name[1] = "_sync_foo"; | ||
227 | scls.value[1] = "one two three"; | ||
228 | scls.value_size[1] = sizeof ("one two three") - 1; | ||
229 | |||
230 | op = GNUNET_PSYCSTORE_state_get_prefix (h, &channel_pub_key, "_sync", | ||
231 | &state_result, | ||
232 | &state_get_prefix_result, &scls); | ||
233 | } | ||
234 | |||
235 | |||
236 | void | ||
237 | counters_slave_result (void *cls, uint64_t max_state_msg_id) | ||
238 | { | ||
239 | struct FragmentClosure *fcls = cls; | ||
240 | int result = 0; | ||
241 | op = NULL; | ||
242 | |||
243 | if (max_state_msg_id == GNUNET_ntohll (fcls->msg[0]->message_id)) | ||
244 | result = 1; | ||
245 | |||
246 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "counters_get_slave:\t%d\n", result); | ||
247 | ASSERT (result == 1); | ||
248 | |||
249 | scls.n = 0; | ||
250 | scls.name[0] = "_bar"; | ||
251 | scls.value[0] = "four five six"; | ||
252 | scls.value_size[0] = sizeof ("four five six") - 1; | ||
253 | |||
254 | op = GNUNET_PSYCSTORE_state_get (h, &channel_pub_key, "_bar_x_yy_zzz", | ||
255 | &state_result, &state_get_result, &scls); | ||
256 | } | ||
257 | |||
258 | |||
259 | void | ||
260 | state_modify_result (void *cls, int64_t result, const char *err_msg) | ||
261 | { | ||
262 | op = NULL; | ||
263 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "state_modify_result:\t%d\n", result); | ||
264 | ASSERT (GNUNET_OK == result); | ||
265 | |||
266 | op = GNUNET_PSYCSTORE_counters_get_slave (h, &channel_pub_key, | ||
267 | &counters_slave_result, cls); | ||
268 | } | ||
269 | |||
270 | |||
271 | void | ||
272 | state_sync_result (void *cls, int64_t result, const char *err_msg) | ||
273 | { | ||
274 | struct FragmentClosure *fcls = cls; | ||
275 | op = NULL; | ||
276 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "state_sync_result:\t%d\n", result); | ||
277 | ASSERT (GNUNET_OK == result); | ||
278 | |||
279 | modifiers[0] = (struct GNUNET_ENV_Modifier) { | ||
280 | .oper = '=', | ||
281 | .name = "_sync_foo", | ||
282 | .value = "one two three", | ||
283 | .value_size = sizeof ("one two three") - 1 | ||
284 | }; | ||
285 | modifiers[1] = (struct GNUNET_ENV_Modifier) { | ||
286 | .oper = '=', | ||
287 | .name = "_bar", | ||
288 | .value = "four five six", | ||
289 | .value_size = sizeof ("four five six") - 1 | ||
290 | }; | ||
291 | |||
292 | op = GNUNET_PSYCSTORE_state_modify (h, &channel_pub_key, | ||
293 | GNUNET_ntohll (fcls->msg[0]->message_id), 0, | ||
294 | 2, modifiers, state_modify_result, fcls); | ||
295 | } | ||
296 | |||
297 | |||
298 | void | ||
299 | counters_master_result (void *cls, uint64_t fragment_id, uint64_t message_id, | ||
300 | uint64_t group_generation) | ||
301 | { | ||
302 | struct FragmentClosure *fcls = cls; | ||
303 | int result = 0; | ||
304 | op = NULL; | ||
305 | |||
306 | if (fragment_id == GNUNET_ntohll (fcls->msg[2]->fragment_id) && | ||
307 | message_id == GNUNET_ntohll (fcls->msg[2]->message_id) && | ||
308 | group_generation == GNUNET_ntohll (fcls->msg[2]->group_generation)) | ||
309 | result = 1; | ||
310 | |||
311 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "counters_get_master:\t%d\n", result); | ||
312 | ASSERT (result == 1); | ||
313 | |||
314 | modifiers[0] = (struct GNUNET_ENV_Modifier) { | ||
315 | .oper = '=', | ||
316 | .name = "_sync_foo", | ||
317 | .value = "three two one", | ||
318 | .value_size = sizeof ("three two one") - 1 | ||
319 | }; | ||
320 | modifiers[1] = (struct GNUNET_ENV_Modifier) { | ||
321 | .oper = '=', | ||
322 | .name = "_sync_bar", | ||
323 | .value = "ten eleven twelve", | ||
324 | .value_size = sizeof ("ten eleven twelve") - 1 | ||
325 | }; | ||
326 | |||
327 | op = GNUNET_PSYCSTORE_state_sync (h, &channel_pub_key, | ||
328 | GNUNET_ntohll (fcls->msg[0]->message_id) + 1, | ||
329 | 2, modifiers, state_sync_result, fcls); | ||
330 | } | ||
331 | |||
332 | |||
333 | int | ||
334 | fragment_result (void *cls, | ||
335 | struct GNUNET_MULTICAST_MessageHeader *msg, | ||
336 | enum GNUNET_PSYCSTORE_MessageFlags flags) | ||
337 | { | ||
338 | struct FragmentClosure *fcls = cls; | ||
339 | struct GNUNET_MULTICAST_MessageHeader *msg0 = fcls->msg[fcls->n]; | ||
340 | uint64_t flags0 = fcls->flags[fcls->n++]; | ||
341 | |||
342 | if (flags == flags0 && msg->header.size == msg0->header.size | ||
343 | && 0 == memcmp (msg, msg0, ntohs (msg->header.size))) | ||
344 | { | ||
345 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " fragment %llu matches\n", | ||
346 | GNUNET_ntohll (msg->fragment_id)); | ||
347 | return GNUNET_YES; | ||
348 | } | ||
349 | else | ||
350 | { | ||
351 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, " fragment %llu differs\n", | ||
352 | GNUNET_ntohll (msg->fragment_id)); | ||
353 | ASSERRT (0); | ||
354 | return GNUNET_SYSERR; | ||
355 | } | ||
356 | } | ||
357 | |||
358 | |||
359 | void | ||
360 | message_get_result (void *cls, int64_t result, const char *err_msg) | ||
361 | { | ||
362 | struct FragmentClosure *fcls = cls; | ||
363 | op = NULL; | ||
364 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "message_get:\t%d\n", result); | ||
365 | ASSERT (result > 0 && fcls->n && fcls->n_expected); | ||
366 | |||
367 | op = GNUNET_PSYCSTORE_counters_get_master (h, &channel_pub_key, | ||
368 | &counters_master_result, fcls); | ||
369 | } | ||
370 | |||
371 | |||
372 | void | ||
373 | message_get_fragment_result (void *cls, int64_t result, const char *err_msg) | ||
374 | { | ||
375 | struct FragmentClosure *fcls = cls; | ||
376 | op = NULL; | ||
377 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "message_get_fragment:\t%d\n", result); | ||
378 | ASSERT (result > 0 && fcls->n && fcls->n_expected); | ||
379 | |||
380 | fcls->n = 0; | ||
381 | fcls->n_expected = 3; | ||
382 | op = GNUNET_PSYCSTORE_message_get (h, &channel_pub_key, | ||
383 | GNUNET_ntohll (fcls->msg[0]->message_id), | ||
384 | &fragment_result, | ||
385 | &message_get_result, fcls); | ||
386 | } | ||
387 | |||
388 | |||
137 | void | 389 | void |
138 | membership_store_result (void *cls, int result, const char *err_msg) | 390 | fragment_get_result (void *cls, int64_t result, const char *err_msg) |
139 | { | 391 | { |
392 | struct FragmentClosure *fcls = cls; | ||
393 | op = NULL; | ||
394 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "fragment_get:\t%d\n", result); | ||
395 | ASSERT (result > 0 && fcls->n && fcls->n_expected); | ||
396 | |||
397 | fcls->n = 1; | ||
398 | fcls->n_expected = 2; | ||
399 | op = GNUNET_PSYCSTORE_message_get_fragment (h, &channel_pub_key, | ||
400 | GNUNET_ntohll (fcls->msg[1]->message_id), | ||
401 | GNUNET_ntohll (fcls->msg[1]->fragment_offset), | ||
402 | &fragment_result, | ||
403 | &message_get_fragment_result, | ||
404 | fcls); | ||
140 | 405 | ||
141 | } | 406 | } |
142 | 407 | ||
408 | |||
409 | void | ||
410 | fragment_store_result (void *cls, int64_t result, const char *err_msg) | ||
411 | { | ||
412 | op = NULL; | ||
413 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "fragment_store:\t%d\n", result); | ||
414 | ASSERT (GNUNET_OK == result); | ||
415 | |||
416 | if ((intptr_t) cls == GNUNET_YES) | ||
417 | { | ||
418 | fcls.n = 0; | ||
419 | fcls.n_expected = 1; | ||
420 | op = GNUNET_PSYCSTORE_fragment_get (h, &channel_pub_key, | ||
421 | GNUNET_ntohll (fcls.msg[0]->fragment_id), | ||
422 | &fragment_result, | ||
423 | &fragment_get_result, &fcls); | ||
424 | } | ||
425 | } | ||
426 | |||
427 | |||
428 | void | ||
429 | membership_test_result (void *cls, int64_t result, const char *err_msg) | ||
430 | { | ||
431 | op = NULL; | ||
432 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "membership_test:\t%d\n", result); | ||
433 | ASSERT (GNUNET_OK == result); | ||
434 | |||
435 | struct GNUNET_MULTICAST_MessageHeader *msg; | ||
436 | fcls.flags[0] = GNUNET_PSYCSTORE_MESSAGE_STATE; | ||
437 | fcls.msg[0] = msg = GNUNET_malloc (sizeof (*msg) + sizeof (channel_pub_key)); | ||
438 | ASSERT (msg != NULL); | ||
439 | |||
440 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_MULTICAST_MESSAGE); | ||
441 | msg->header.size = htons (sizeof (*msg) + sizeof (channel_pub_key)); | ||
442 | |||
443 | msg->hop_counter = htonl (9); | ||
444 | msg->fragment_id = GNUNET_htonll (INT64_MAX - 8); | ||
445 | msg->fragment_offset = GNUNET_htonll (0); | ||
446 | msg->message_id = GNUNET_htonll (INT64_MAX - 10); | ||
447 | msg->group_generation = GNUNET_htonll (INT64_MAX - 3); | ||
448 | msg->flags = htonl (GNUNET_MULTICAST_MESSAGE_LAST_FRAGMENT); | ||
449 | |||
450 | memcpy (&msg[1], &channel_pub_key, sizeof (channel_pub_key)); | ||
451 | |||
452 | msg->purpose.size = htonl (ntohs (msg->header.size) | ||
453 | - sizeof (msg->header) | ||
454 | - sizeof (msg->hop_counter) | ||
455 | - sizeof (msg->signature)); | ||
456 | msg->purpose.purpose = htonl (234); | ||
457 | GNUNET_CRYPTO_ecc_sign (slave_key, &msg->purpose, &msg->signature); | ||
458 | |||
459 | op = GNUNET_PSYCSTORE_fragment_store (h, &channel_pub_key, msg, fcls.flags[0], | ||
460 | &fragment_store_result, GNUNET_NO); | ||
461 | |||
462 | fcls.flags[1] = GNUNET_PSYCSTORE_MESSAGE_STATE_APPLIED; | ||
463 | fcls.msg[1] = msg = GNUNET_malloc (sizeof (*msg) + sizeof (channel_pub_key)); | ||
464 | memcpy (msg, fcls.msg[0], sizeof (*msg) + sizeof (channel_pub_key)); | ||
465 | msg->fragment_id = GNUNET_htonll (INT64_MAX - 4); | ||
466 | msg->fragment_offset = GNUNET_htonll (1024); | ||
467 | |||
468 | op = GNUNET_PSYCSTORE_fragment_store (h, &channel_pub_key, msg, fcls.flags[1], | ||
469 | &fragment_store_result, GNUNET_NO); | ||
470 | |||
471 | fcls.flags[2] = GNUNET_PSYCSTORE_MESSAGE_STATE_HASH; | ||
472 | fcls.msg[2] = msg = GNUNET_malloc (sizeof (*msg) + sizeof (channel_pub_key)); | ||
473 | memcpy (msg, fcls.msg[1], sizeof (*msg) + sizeof (channel_pub_key)); | ||
474 | msg->fragment_id = GNUNET_htonll (INT64_MAX); | ||
475 | msg->fragment_offset = GNUNET_htonll (16384); | ||
476 | |||
477 | op = GNUNET_PSYCSTORE_fragment_store (h, &channel_pub_key, msg, fcls.flags[2], | ||
478 | &fragment_store_result, (void *) GNUNET_YES); | ||
479 | } | ||
480 | |||
481 | void | ||
482 | membership_store_result (void *cls, int64_t result, const char *err_msg) | ||
483 | { | ||
484 | op = NULL; | ||
485 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "membership_store:\t%d\n", result); | ||
486 | ASSERT (GNUNET_OK == result); | ||
487 | |||
488 | op = GNUNET_PSYCSTORE_membership_test (h, &channel_pub_key, &slave_pub_key, | ||
489 | 4, 1, | ||
490 | &membership_test_result, NULL); | ||
491 | } | ||
492 | |||
143 | /** | 493 | /** |
144 | * Main function of the test, run from scheduler. | 494 | * Main function of the test, run from scheduler. |
145 | * | 495 | * |
@@ -148,14 +498,19 @@ membership_store_result (void *cls, int result, const char *err_msg) | |||
148 | * @param peer handle to access more of the peer (not used) | 498 | * @param peer handle to access more of the peer (not used) |
149 | */ | 499 | */ |
150 | static void | 500 | static void |
151 | run (void *cls, | 501 | #if DEBUG_SERVICE |
152 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 502 | run (void *cls, char *const *args, const char *cfgfile, |
153 | struct GNUNET_TESTING_Peer *peer) | 503 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
504 | #else | ||
505 | run (void *cls, | ||
506 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
507 | struct GNUNET_TESTING_Peer *peer) | ||
508 | #endif | ||
154 | { | 509 | { |
155 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 510 | end_badly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
156 | &endbadly, NULL); | 511 | &end_badly, NULL); |
157 | h = GNUNET_PSYCSTORE_connect (cfg); | 512 | h = GNUNET_PSYCSTORE_connect (cfg); |
158 | GNUNET_assert (NULL != h); | 513 | ASSERT (NULL != h); |
159 | 514 | ||
160 | channel_key = GNUNET_CRYPTO_ecc_key_create (); | 515 | channel_key = GNUNET_CRYPTO_ecc_key_create (); |
161 | slave_key = GNUNET_CRYPTO_ecc_key_create (); | 516 | slave_key = GNUNET_CRYPTO_ecc_key_create (); |
@@ -164,10 +519,8 @@ run (void *cls, | |||
164 | GNUNET_CRYPTO_ecc_key_get_public_for_signature (slave_key, &slave_pub_key); | 519 | GNUNET_CRYPTO_ecc_key_get_public_for_signature (slave_key, &slave_pub_key); |
165 | 520 | ||
166 | op = GNUNET_PSYCSTORE_membership_store (h, &channel_pub_key, &slave_pub_key, | 521 | op = GNUNET_PSYCSTORE_membership_store (h, &channel_pub_key, &slave_pub_key, |
167 | GNUNET_YES, 2, 2, 1, | 522 | GNUNET_YES, 4, 2, 1, |
168 | &membership_store_result, NULL); | 523 | &membership_store_result, NULL); |
169 | |||
170 | end (); | ||
171 | } | 524 | } |
172 | 525 | ||
173 | 526 | ||
@@ -175,15 +528,20 @@ int | |||
175 | main (int argc, char *argv[]) | 528 | main (int argc, char *argv[]) |
176 | { | 529 | { |
177 | res = 1; | 530 | res = 1; |
178 | if (0 != | 531 | #if DEBUG_SERVICE |
179 | GNUNET_TESTING_service_run ("test-psycstore", | 532 | const struct GNUNET_GETOPT_CommandLineOption opts[] = { |
180 | "psycstore", | 533 | GNUNET_GETOPT_OPTION_END |
181 | "test_psycstore.conf", | 534 | }; |
182 | &run, | 535 | if (GNUNET_OK != GNUNET_PROGRAM_run (argc, argv, "test-psycstore", |
183 | NULL)) | 536 | "test-psycstore [options]", |
537 | opts, &run, NULL)) | ||
538 | return 1; | ||
539 | #else | ||
540 | if (0 != GNUNET_TESTING_service_run ("test-psycstore", "psycstore", | ||
541 | "test_psycstore.conf", &run, NULL)) | ||
184 | return 1; | 542 | return 1; |
543 | #endif | ||
185 | return res; | 544 | return res; |
186 | } | 545 | } |
187 | 546 | ||
188 | |||
189 | /* end of test_psycstore.c */ | 547 | /* end of test_psycstore.c */ |