diff options
author | Omar Tarabai <tarabai@devegypt.com> | 2014-07-09 14:46:56 +0000 |
---|---|---|
committer | Omar Tarabai <tarabai@devegypt.com> | 2014-07-09 14:46:56 +0000 |
commit | e5d7c67c647e9620c5c1ae77e133a74698443ee1 (patch) | |
tree | 1f49323d5963cc4a77e2648b29744ad5cf6291bf /src/peerstore | |
parent | 696df0a02abec9683b34c3097cff4448ad154367 (diff) | |
download | gnunet-e5d7c67c647e9620c5c1ae77e133a74698443ee1.tar.gz gnunet-e5d7c67c647e9620c5c1ae77e133a74698443ee1.zip |
Added flag to API disconnect method to send pending store requests before disconnecting.
Added a test case for it.
Diffstat (limited to 'src/peerstore')
-rw-r--r-- | src/peerstore/Makefile.am | 8 | ||||
-rw-r--r-- | src/peerstore/gnunet-peerstore.c | 2 | ||||
-rw-r--r-- | src/peerstore/peerstore_api.c | 121 | ||||
-rw-r--r-- | src/peerstore/perf_peerstore_store.c | 2 | ||||
-rw-r--r-- | src/peerstore/test_peerstore_api_iterate.c | 2 | ||||
-rw-r--r-- | src/peerstore/test_peerstore_api_store.c | 2 | ||||
-rw-r--r-- | src/peerstore/test_peerstore_api_sync.c | 92 | ||||
-rw-r--r-- | src/peerstore/test_peerstore_api_watch.c | 2 |
8 files changed, 203 insertions, 28 deletions
diff --git a/src/peerstore/Makefile.am b/src/peerstore/Makefile.am index 4c5e4af8c..71898bdea 100644 --- a/src/peerstore/Makefile.am +++ b/src/peerstore/Makefile.am | |||
@@ -68,6 +68,7 @@ check_PROGRAMS = \ | |||
68 | test_peerstore_api_store \ | 68 | test_peerstore_api_store \ |
69 | test_peerstore_api_iterate \ | 69 | test_peerstore_api_iterate \ |
70 | test_peerstore_api_watch \ | 70 | test_peerstore_api_watch \ |
71 | test_peerstore_api_sync \ | ||
71 | perf_peerstore_store | 72 | perf_peerstore_store |
72 | 73 | ||
73 | if ENABLE_TEST_RUN | 74 | if ENABLE_TEST_RUN |
@@ -96,6 +97,13 @@ test_peerstore_api_watch_LDADD = \ | |||
96 | $(top_builddir)/src/testing/libgnunettesting.la \ | 97 | $(top_builddir)/src/testing/libgnunettesting.la \ |
97 | $(top_builddir)/src/util/libgnunetutil.la | 98 | $(top_builddir)/src/util/libgnunetutil.la |
98 | 99 | ||
100 | test_peerstore_api_sync_SOURCES = \ | ||
101 | test_peerstore_api_sync.c | ||
102 | test_peerstore_api_sync_LDADD = \ | ||
103 | $(top_builddir)/src/peerstore/libgnunetpeerstore.la \ | ||
104 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
105 | $(top_builddir)/src/util/libgnunetutil.la | ||
106 | |||
99 | perf_peerstore_store_SOURCES = \ | 107 | perf_peerstore_store_SOURCES = \ |
100 | perf_peerstore_store.c | 108 | perf_peerstore_store.c |
101 | perf_peerstore_store_LDADD = \ | 109 | perf_peerstore_store_LDADD = \ |
diff --git a/src/peerstore/gnunet-peerstore.c b/src/peerstore/gnunet-peerstore.c index ec2af0a4f..f99c42819 100644 --- a/src/peerstore/gnunet-peerstore.c +++ b/src/peerstore/gnunet-peerstore.c | |||
@@ -46,7 +46,7 @@ shutdown_task (void *cls, | |||
46 | { | 46 | { |
47 | if(NULL != peerstore_handle) | 47 | if(NULL != peerstore_handle) |
48 | { | 48 | { |
49 | GNUNET_PEERSTORE_disconnect(peerstore_handle); | 49 | GNUNET_PEERSTORE_disconnect(peerstore_handle, GNUNET_YES); |
50 | peerstore_handle = NULL; | 50 | peerstore_handle = NULL; |
51 | } | 51 | } |
52 | } | 52 | } |
diff --git a/src/peerstore/peerstore_api.c b/src/peerstore/peerstore_api.c index b13b0136c..81d287b53 100644 --- a/src/peerstore/peerstore_api.c +++ b/src/peerstore/peerstore_api.c | |||
@@ -80,6 +80,11 @@ struct GNUNET_PEERSTORE_Handle | |||
80 | */ | 80 | */ |
81 | struct GNUNET_CONTAINER_MultiHashMap *watches; | 81 | struct GNUNET_CONTAINER_MultiHashMap *watches; |
82 | 82 | ||
83 | /** | ||
84 | * Are we in the process of disconnecting but need to sync first? | ||
85 | */ | ||
86 | int disconnecting; | ||
87 | |||
83 | }; | 88 | }; |
84 | 89 | ||
85 | /** | 90 | /** |
@@ -226,7 +231,8 @@ struct GNUNET_PEERSTORE_WatchContext | |||
226 | * @param cls a 'struct GNUNET_PEERSTORE_Handle *' | 231 | * @param cls a 'struct GNUNET_PEERSTORE_Handle *' |
227 | * @param msg message received, NULL on timeout or fatal error | 232 | * @param msg message received, NULL on timeout or fatal error |
228 | */ | 233 | */ |
229 | void handle_iterate_result (void *cls, const struct GNUNET_MessageHeader *msg); | 234 | static void |
235 | handle_iterate_result (void *cls, const struct GNUNET_MessageHeader *msg); | ||
230 | 236 | ||
231 | /** | 237 | /** |
232 | * When a watch record is received | 238 | * When a watch record is received |
@@ -234,7 +240,8 @@ void handle_iterate_result (void *cls, const struct GNUNET_MessageHeader *msg); | |||
234 | * @param cls a 'struct GNUNET_PEERSTORE_Handle *' | 240 | * @param cls a 'struct GNUNET_PEERSTORE_Handle *' |
235 | * @param msg message received, NULL on timeout or fatal error | 241 | * @param msg message received, NULL on timeout or fatal error |
236 | */ | 242 | */ |
237 | void handle_watch_result (void *cls, const struct GNUNET_MessageHeader *msg); | 243 | static void |
244 | handle_watch_result (void *cls, const struct GNUNET_MessageHeader *msg); | ||
238 | 245 | ||
239 | /** | 246 | /** |
240 | * Close the existing connection to PEERSTORE and reconnect. | 247 | * Close the existing connection to PEERSTORE and reconnect. |
@@ -249,21 +256,21 @@ reconnect (struct GNUNET_PEERSTORE_Handle *h); | |||
249 | * | 256 | * |
250 | * @param cls a 'struct GNUNET_PEERSTORE_WatchContext *' | 257 | * @param cls a 'struct GNUNET_PEERSTORE_WatchContext *' |
251 | */ | 258 | */ |
252 | void watch_request_sent (void *cls); | 259 | static void watch_request_sent (void *cls); |
253 | 260 | ||
254 | /** | 261 | /** |
255 | * Callback after MQ envelope is sent | 262 | * Callback after MQ envelope is sent |
256 | * | 263 | * |
257 | * @param cls a 'struct GNUNET_PEERSTORE_IterateContext *' | 264 | * @param cls a 'struct GNUNET_PEERSTORE_IterateContext *' |
258 | */ | 265 | */ |
259 | void iterate_request_sent (void *cls); | 266 | static void iterate_request_sent (void *cls); |
260 | 267 | ||
261 | /** | 268 | /** |
262 | * Callback after MQ envelope is sent | 269 | * Callback after MQ envelope is sent |
263 | * | 270 | * |
264 | * @param cls a 'struct GNUNET_PEERSTORE_StoreContext *' | 271 | * @param cls a 'struct GNUNET_PEERSTORE_StoreContext *' |
265 | */ | 272 | */ |
266 | void store_request_sent (void *cls); | 273 | static void store_request_sent (void *cls); |
267 | 274 | ||
268 | /** | 275 | /** |
269 | * MQ message handlers | 276 | * MQ message handlers |
@@ -291,7 +298,7 @@ handle_client_error (void *cls, enum GNUNET_MQ_Error error) | |||
291 | /** | 298 | /** |
292 | * Iterator over previous watches to resend them | 299 | * Iterator over previous watches to resend them |
293 | */ | 300 | */ |
294 | int rewatch_it(void *cls, | 301 | static int rewatch_it(void *cls, |
295 | const struct GNUNET_HashCode *key, | 302 | const struct GNUNET_HashCode *key, |
296 | void *value) | 303 | void *value) |
297 | { | 304 | { |
@@ -375,6 +382,45 @@ reconnect (struct GNUNET_PEERSTORE_Handle *h) | |||
375 | } | 382 | } |
376 | 383 | ||
377 | /** | 384 | /** |
385 | * Iterator over watch requests to cancel them. | ||
386 | * | ||
387 | * @param cls unsused | ||
388 | * @param key key to the watch request | ||
389 | * @param value watch context | ||
390 | * @return #GNUNET_YES to continue iteration | ||
391 | */ | ||
392 | static int | ||
393 | destroy_watch (void *cls, const struct GNUNET_HashCode *key, void *value) | ||
394 | { | ||
395 | struct GNUNET_PEERSTORE_WatchContext *wc = value; | ||
396 | |||
397 | GNUNET_PEERSTORE_watch_cancel (wc); | ||
398 | return GNUNET_YES; | ||
399 | } | ||
400 | |||
401 | /** | ||
402 | * Kill the connection to the service. This can be delayed in case of pending | ||
403 | * STORE requests and the user explicitly asked to sync first. Otherwise it is | ||
404 | * performed instantly. | ||
405 | * | ||
406 | * @param h Handle to the service. | ||
407 | */ | ||
408 | static void do_disconnect (struct GNUNET_PEERSTORE_Handle *h) | ||
409 | { | ||
410 | if(NULL != h->mq) | ||
411 | { | ||
412 | GNUNET_MQ_destroy(h->mq); | ||
413 | h->mq = NULL; | ||
414 | } | ||
415 | if (NULL != h->client) | ||
416 | { | ||
417 | GNUNET_CLIENT_disconnect (h->client); | ||
418 | h->client = NULL; | ||
419 | } | ||
420 | GNUNET_free(h); | ||
421 | } | ||
422 | |||
423 | /** | ||
378 | * Connect to the PEERSTORE service. | 424 | * Connect to the PEERSTORE service. |
379 | * | 425 | * |
380 | * @return NULL on error | 426 | * @return NULL on error |
@@ -392,6 +438,7 @@ GNUNET_PEERSTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
392 | return NULL; | 438 | return NULL; |
393 | } | 439 | } |
394 | h->cfg = cfg; | 440 | h->cfg = cfg; |
441 | h->disconnecting = GNUNET_NO; | ||
395 | h->mq = GNUNET_MQ_queue_for_connection_client(h->client, | 442 | h->mq = GNUNET_MQ_queue_for_connection_client(h->client, |
396 | mq_handlers, | 443 | mq_handlers, |
397 | &handle_client_error, | 444 | &handle_client_error, |
@@ -406,32 +453,52 @@ GNUNET_PEERSTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
406 | } | 453 | } |
407 | 454 | ||
408 | /** | 455 | /** |
409 | * Disconnect from the PEERSTORE service | 456 | * Disconnect from the PEERSTORE service. Any pending ITERATE and WATCH requests |
410 | * Do not call in case of pending requests | 457 | * will be canceled. Any pending STORE requests will depend on @snyc_first flag. |
411 | * | 458 | * |
412 | * @param h handle to disconnect | 459 | * @param h handle to disconnect |
460 | * @param sync_first send any pending STORE requests before disconnecting | ||
413 | */ | 461 | */ |
414 | void | 462 | void |
415 | GNUNET_PEERSTORE_disconnect(struct GNUNET_PEERSTORE_Handle *h) | 463 | GNUNET_PEERSTORE_disconnect (struct GNUNET_PEERSTORE_Handle *h, int sync_first) |
416 | { | 464 | { |
465 | struct GNUNET_PEERSTORE_IterateContext *ic; | ||
466 | struct GNUNET_PEERSTORE_IterateContext *ic_iter; | ||
467 | struct GNUNET_PEERSTORE_StoreContext *sc; | ||
468 | struct GNUNET_PEERSTORE_StoreContext *sc_iter; | ||
469 | |||
417 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Disconnecting.\n"); | 470 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Disconnecting.\n"); |
418 | if(NULL != h->watches) | 471 | if(NULL != h->watches) |
419 | { | 472 | { |
473 | GNUNET_CONTAINER_multihashmap_iterate (h->watches, &destroy_watch, NULL); | ||
420 | GNUNET_CONTAINER_multihashmap_destroy(h->watches); | 474 | GNUNET_CONTAINER_multihashmap_destroy(h->watches); |
421 | h->watches = NULL; | 475 | h->watches = NULL; |
422 | } | 476 | } |
423 | if(NULL != h->mq) | 477 | ic_iter = h->iterate_head; |
478 | while (NULL != ic_iter) | ||
424 | { | 479 | { |
425 | GNUNET_MQ_destroy(h->mq); | 480 | ic = ic_iter; |
426 | h->mq = NULL; | 481 | ic_iter = ic_iter->next; |
482 | GNUNET_PEERSTORE_iterate_cancel (ic); | ||
427 | } | 483 | } |
428 | if (NULL != h->client) | 484 | if (NULL != h->store_head) |
429 | { | 485 | { |
430 | GNUNET_CLIENT_disconnect (h->client); | 486 | if (GNUNET_YES == sync_first) |
431 | h->client = NULL; | 487 | { |
488 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
489 | "Delaying disconnection due to pending store requests.\n"); | ||
490 | h->disconnecting = GNUNET_YES; | ||
491 | return; | ||
492 | } | ||
493 | sc_iter = h->store_head; | ||
494 | while (NULL != sc_iter) | ||
495 | { | ||
496 | sc = sc_iter; | ||
497 | sc_iter = sc_iter->next; | ||
498 | GNUNET_PEERSTORE_store_cancel (sc); | ||
499 | } | ||
432 | } | 500 | } |
433 | GNUNET_free(h); | 501 | do_disconnect (h); |
434 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Disconnected, BYE!\n"); | ||
435 | } | 502 | } |
436 | 503 | ||
437 | 504 | ||
@@ -444,7 +511,7 @@ GNUNET_PEERSTORE_disconnect(struct GNUNET_PEERSTORE_Handle *h) | |||
444 | * | 511 | * |
445 | * @param cls a 'struct GNUNET_PEERSTORE_StoreContext *' | 512 | * @param cls a 'struct GNUNET_PEERSTORE_StoreContext *' |
446 | */ | 513 | */ |
447 | void store_request_sent (void *cls) | 514 | static void store_request_sent (void *cls) |
448 | { | 515 | { |
449 | struct GNUNET_PEERSTORE_StoreContext *sc = cls; | 516 | struct GNUNET_PEERSTORE_StoreContext *sc = cls; |
450 | GNUNET_PEERSTORE_Continuation cont; | 517 | GNUNET_PEERSTORE_Continuation cont; |
@@ -466,6 +533,8 @@ void store_request_sent (void *cls) | |||
466 | void | 533 | void |
467 | GNUNET_PEERSTORE_store_cancel (struct GNUNET_PEERSTORE_StoreContext *sc) | 534 | GNUNET_PEERSTORE_store_cancel (struct GNUNET_PEERSTORE_StoreContext *sc) |
468 | { | 535 | { |
536 | struct GNUNET_PEERSTORE_Handle *h = sc->h; | ||
537 | |||
469 | if(NULL != sc->ev) | 538 | if(NULL != sc->ev) |
470 | { | 539 | { |
471 | GNUNET_MQ_send_cancel(sc->ev); | 540 | GNUNET_MQ_send_cancel(sc->ev); |
@@ -473,6 +542,8 @@ GNUNET_PEERSTORE_store_cancel (struct GNUNET_PEERSTORE_StoreContext *sc) | |||
473 | } | 542 | } |
474 | GNUNET_CONTAINER_DLL_remove(sc->h->store_head, sc->h->store_tail, sc); | 543 | GNUNET_CONTAINER_DLL_remove(sc->h->store_head, sc->h->store_tail, sc); |
475 | GNUNET_free(sc); | 544 | GNUNET_free(sc); |
545 | if (GNUNET_YES == h->disconnecting && NULL == h->store_head) | ||
546 | do_disconnect (h); | ||
476 | } | 547 | } |
477 | 548 | ||
478 | /** | 549 | /** |
@@ -538,7 +609,8 @@ GNUNET_PEERSTORE_store (struct GNUNET_PEERSTORE_Handle *h, | |||
538 | * @param cls a 'struct GNUNET_PEERSTORE_Handle *' | 609 | * @param cls a 'struct GNUNET_PEERSTORE_Handle *' |
539 | * @param msg message received, NULL on timeout or fatal error | 610 | * @param msg message received, NULL on timeout or fatal error |
540 | */ | 611 | */ |
541 | void handle_iterate_result (void *cls, const struct GNUNET_MessageHeader *msg) | 612 | static void |
613 | handle_iterate_result (void *cls, const struct GNUNET_MessageHeader *msg) | ||
542 | { | 614 | { |
543 | struct GNUNET_PEERSTORE_Handle *h = cls; | 615 | struct GNUNET_PEERSTORE_Handle *h = cls; |
544 | struct GNUNET_PEERSTORE_IterateContext *ic; | 616 | struct GNUNET_PEERSTORE_IterateContext *ic; |
@@ -596,7 +668,7 @@ void handle_iterate_result (void *cls, const struct GNUNET_MessageHeader *msg) | |||
596 | * | 668 | * |
597 | * @param cls a 'struct GNUNET_PEERSTORE_IterateContext *' | 669 | * @param cls a 'struct GNUNET_PEERSTORE_IterateContext *' |
598 | */ | 670 | */ |
599 | void iterate_request_sent (void *cls) | 671 | static void iterate_request_sent (void *cls) |
600 | { | 672 | { |
601 | struct GNUNET_PEERSTORE_IterateContext *ic = cls; | 673 | struct GNUNET_PEERSTORE_IterateContext *ic = cls; |
602 | 674 | ||
@@ -610,7 +682,8 @@ void iterate_request_sent (void *cls) | |||
610 | * | 682 | * |
611 | * @param cls a 'struct GNUNET_PEERSTORE_IterateContext *' | 683 | * @param cls a 'struct GNUNET_PEERSTORE_IterateContext *' |
612 | */ | 684 | */ |
613 | void iterate_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 685 | static void |
686 | iterate_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
614 | { | 687 | { |
615 | struct GNUNET_PEERSTORE_IterateContext *ic = cls; | 688 | struct GNUNET_PEERSTORE_IterateContext *ic = cls; |
616 | 689 | ||
@@ -702,7 +775,8 @@ GNUNET_PEERSTORE_iterate (struct GNUNET_PEERSTORE_Handle *h, | |||
702 | * @param cls a 'struct GNUNET_PEERSTORE_Handle *' | 775 | * @param cls a 'struct GNUNET_PEERSTORE_Handle *' |
703 | * @param msg message received, NULL on timeout or fatal error | 776 | * @param msg message received, NULL on timeout or fatal error |
704 | */ | 777 | */ |
705 | void handle_watch_result (void *cls, const struct GNUNET_MessageHeader *msg) | 778 | static void |
779 | handle_watch_result (void *cls, const struct GNUNET_MessageHeader *msg) | ||
706 | { | 780 | { |
707 | struct GNUNET_PEERSTORE_Handle *h = cls; | 781 | struct GNUNET_PEERSTORE_Handle *h = cls; |
708 | struct GNUNET_PEERSTORE_Record *record; | 782 | struct GNUNET_PEERSTORE_Record *record; |
@@ -738,7 +812,7 @@ void handle_watch_result (void *cls, const struct GNUNET_MessageHeader *msg) | |||
738 | * | 812 | * |
739 | * @param cls a 'struct GNUNET_PEERSTORE_WatchContext *' | 813 | * @param cls a 'struct GNUNET_PEERSTORE_WatchContext *' |
740 | */ | 814 | */ |
741 | void watch_request_sent (void *cls) | 815 | static void watch_request_sent (void *cls) |
742 | { | 816 | { |
743 | struct GNUNET_PEERSTORE_WatchContext *wc = cls; | 817 | struct GNUNET_PEERSTORE_WatchContext *wc = cls; |
744 | 818 | ||
@@ -762,6 +836,7 @@ GNUNET_PEERSTORE_watch_cancel(struct GNUNET_PEERSTORE_WatchContext *wc) | |||
762 | if(GNUNET_YES == wc->request_sent) /* If request already sent to service, send a cancel request. */ | 836 | if(GNUNET_YES == wc->request_sent) /* If request already sent to service, send a cancel request. */ |
763 | { | 837 | { |
764 | ev = GNUNET_MQ_msg(hm, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_CANCEL); | 838 | ev = GNUNET_MQ_msg(hm, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_CANCEL); |
839 | hm->keyhash = wc->keyhash; | ||
765 | GNUNET_MQ_send(h->mq, ev); | 840 | GNUNET_MQ_send(h->mq, ev); |
766 | wc->callback = NULL; | 841 | wc->callback = NULL; |
767 | wc->callback_cls = NULL; | 842 | wc->callback_cls = NULL; |
diff --git a/src/peerstore/perf_peerstore_store.c b/src/peerstore/perf_peerstore_store.c index e7a8fec04..bdf70272c 100644 --- a/src/peerstore/perf_peerstore_store.c +++ b/src/peerstore/perf_peerstore_store.c | |||
@@ -43,7 +43,7 @@ void | |||
43 | disconnect() | 43 | disconnect() |
44 | { | 44 | { |
45 | if(NULL != h) | 45 | if(NULL != h) |
46 | GNUNET_PEERSTORE_disconnect(h); | 46 | GNUNET_PEERSTORE_disconnect(h, GNUNET_YES); |
47 | GNUNET_SCHEDULER_shutdown(); | 47 | GNUNET_SCHEDULER_shutdown(); |
48 | } | 48 | } |
49 | 49 | ||
diff --git a/src/peerstore/test_peerstore_api_iterate.c b/src/peerstore/test_peerstore_api_iterate.c index 515e8f7df..0b864aea5 100644 --- a/src/peerstore/test_peerstore_api_iterate.c +++ b/src/peerstore/test_peerstore_api_iterate.c | |||
@@ -53,7 +53,7 @@ iter3_cb(void *cls, | |||
53 | } | 53 | } |
54 | GNUNET_assert(count == 3); | 54 | GNUNET_assert(count == 3); |
55 | ok = 0; | 55 | ok = 0; |
56 | GNUNET_PEERSTORE_disconnect(h); | 56 | GNUNET_PEERSTORE_disconnect(h, GNUNET_NO); |
57 | GNUNET_SCHEDULER_shutdown(); | 57 | GNUNET_SCHEDULER_shutdown(); |
58 | return GNUNET_YES; | 58 | return GNUNET_YES; |
59 | } | 59 | } |
diff --git a/src/peerstore/test_peerstore_api_store.c b/src/peerstore/test_peerstore_api_store.c index ff02ac3ab..53ace3d4a 100644 --- a/src/peerstore/test_peerstore_api_store.c +++ b/src/peerstore/test_peerstore_api_store.c | |||
@@ -54,7 +54,7 @@ int test3_cont2(void *cls, | |||
54 | } | 54 | } |
55 | GNUNET_assert(count == 1); | 55 | GNUNET_assert(count == 1); |
56 | ok = 0; | 56 | ok = 0; |
57 | GNUNET_PEERSTORE_disconnect(h); | 57 | GNUNET_PEERSTORE_disconnect(h, GNUNET_YES); |
58 | GNUNET_SCHEDULER_shutdown(); | 58 | GNUNET_SCHEDULER_shutdown(); |
59 | return GNUNET_YES; | 59 | return GNUNET_YES; |
60 | } | 60 | } |
diff --git a/src/peerstore/test_peerstore_api_sync.c b/src/peerstore/test_peerstore_api_sync.c new file mode 100644 index 000000000..634f62c26 --- /dev/null +++ b/src/peerstore/test_peerstore_api_sync.c | |||
@@ -0,0 +1,92 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) | ||
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 | * @file peerstore/test_peerstore_api_sync.c | ||
22 | * @brief testcase for peerstore sync before disconnect feature | ||
23 | */ | ||
24 | #include "platform.h" | ||
25 | #include "gnunet_util_lib.h" | ||
26 | #include "gnunet_testing_lib.h" | ||
27 | #include "gnunet_peerstore_service.h" | ||
28 | |||
29 | int ok = 1; | ||
30 | |||
31 | const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
32 | |||
33 | static struct GNUNET_PEERSTORE_Handle *h; | ||
34 | |||
35 | static char *subsystem = "test_peerstore_api_sync"; | ||
36 | static struct GNUNET_PeerIdentity pid; | ||
37 | static char *key = "test_peerstore_api_store_key"; | ||
38 | static char *val = "test_peerstore_api_store_val"; | ||
39 | |||
40 | int iterate_cb (void *cls, struct GNUNET_PEERSTORE_Record *record, char *emsg) | ||
41 | { | ||
42 | const char *rec_val; | ||
43 | |||
44 | GNUNET_break (NULL == emsg); | ||
45 | if (NULL == record) | ||
46 | { | ||
47 | GNUNET_PEERSTORE_disconnect (h, GNUNET_NO); | ||
48 | GNUNET_SCHEDULER_shutdown(); | ||
49 | return GNUNET_YES; | ||
50 | } | ||
51 | rec_val = record->value; | ||
52 | GNUNET_break (0 == strcmp(rec_val, val)); | ||
53 | ok = 0; | ||
54 | return GNUNET_YES; | ||
55 | } | ||
56 | |||
57 | static void | ||
58 | test1() | ||
59 | { | ||
60 | GNUNET_PEERSTORE_store (h, subsystem, &pid, key, val, strlen(val) + 1, | ||
61 | GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_PEERSTORE_STOREOPTION_REPLACE, | ||
62 | NULL, NULL); | ||
63 | GNUNET_PEERSTORE_disconnect (h, GNUNET_YES); | ||
64 | h = GNUNET_PEERSTORE_connect (cfg); | ||
65 | GNUNET_PEERSTORE_iterate (h, subsystem, &pid, key, | ||
66 | GNUNET_TIME_UNIT_FOREVER_REL, &iterate_cb, NULL); | ||
67 | } | ||
68 | |||
69 | static void | ||
70 | run (void *cls, | ||
71 | const struct GNUNET_CONFIGURATION_Handle *c, | ||
72 | struct GNUNET_TESTING_Peer *peer) | ||
73 | { | ||
74 | cfg = c; | ||
75 | h = GNUNET_PEERSTORE_connect(cfg); | ||
76 | GNUNET_assert(NULL != h); | ||
77 | memset (&pid, 1, sizeof (pid)); | ||
78 | test1(); | ||
79 | } | ||
80 | |||
81 | int | ||
82 | main (int argc, char *argv[]) | ||
83 | { | ||
84 | if (0 != GNUNET_TESTING_service_run ("test-gnunet-peerstore", | ||
85 | "peerstore", | ||
86 | "test_peerstore_api_data.conf", | ||
87 | &run, NULL)) | ||
88 | return 1; | ||
89 | return ok; | ||
90 | } | ||
91 | |||
92 | /* end of test_peerstore_api_store.c */ | ||
diff --git a/src/peerstore/test_peerstore_api_watch.c b/src/peerstore/test_peerstore_api_watch.c index 2ab67eeb9..fb6cdc540 100644 --- a/src/peerstore/test_peerstore_api_watch.c +++ b/src/peerstore/test_peerstore_api_watch.c | |||
@@ -43,7 +43,7 @@ watch_cb(void *cls, | |||
43 | GNUNET_assert(NULL == emsg); | 43 | GNUNET_assert(NULL == emsg); |
44 | GNUNET_assert(0 == strcmp(val, (char *)record->value)); | 44 | GNUNET_assert(0 == strcmp(val, (char *)record->value)); |
45 | ok = 0; | 45 | ok = 0; |
46 | GNUNET_PEERSTORE_disconnect(h); | 46 | GNUNET_PEERSTORE_disconnect(h, GNUNET_NO); |
47 | GNUNET_SCHEDULER_shutdown(); | 47 | GNUNET_SCHEDULER_shutdown(); |
48 | return GNUNET_YES; | 48 | return GNUNET_YES; |
49 | } | 49 | } |