aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-07-09 14:29:34 +0000
committerChristian Grothoff <christian@grothoff.org>2016-07-09 14:29:34 +0000
commit03374cc39814fa4bfb8d96e1165c688c44d8342f (patch)
treeed772250c49b39d82b9708ec8df0ee3e07e366d1 /src
parent0c13a1e6fb0baffd83d413f313742a5f2b420297 (diff)
downloadgnunet-03374cc39814fa4bfb8d96e1165c688c44d8342f.tar.gz
gnunet-03374cc39814fa4bfb8d96e1165c688c44d8342f.zip
make namestore API less brittle/sublte to use
Diffstat (limited to 'src')
-rw-r--r--src/gns/gnunet-service-gns.c238
-rw-r--r--src/gns/gnunet-service-gns_shorten.c20
-rw-r--r--src/identity-provider/gnunet-service-identity-provider.c186
-rw-r--r--src/identity-provider/plugin_rest_identity_provider.c97
-rw-r--r--src/include/gnunet_namestore_service.h82
-rw-r--r--src/namestore/gnunet-namestore-fcfsd.c142
-rw-r--r--src/namestore/gnunet-namestore.c110
-rw-r--r--src/namestore/namestore_api.c92
-rw-r--r--src/namestore/namestore_api_monitor.c52
-rw-r--r--src/namestore/plugin_rest_namestore.c86
-rw-r--r--src/namestore/test_namestore_api.conf3
-rw-r--r--src/namestore/test_namestore_api_lookup_nick.c16
-rw-r--r--src/namestore/test_namestore_api_lookup_private.c19
-rw-r--r--src/namestore/test_namestore_api_monitoring.c23
-rw-r--r--src/namestore/test_namestore_api_monitoring_existing.c17
-rw-r--r--src/namestore/test_namestore_api_zone_iteration.c92
-rw-r--r--src/namestore/test_namestore_api_zone_iteration_nick.c53
-rw-r--r--src/namestore/test_namestore_api_zone_iteration_specific_zone.c162
-rw-r--r--src/namestore/test_namestore_api_zone_iteration_stop.c125
19 files changed, 1158 insertions, 457 deletions
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c
index 2a9d86a8b..ea271e9dd 100644
--- a/src/gns/gnunet-service-gns.c
+++ b/src/gns/gnunet-service-gns.c
@@ -46,11 +46,16 @@
46#define INITIAL_PUT_INTERVAL GNUNET_TIME_UNIT_MILLISECONDS 46#define INITIAL_PUT_INTERVAL GNUNET_TIME_UNIT_MILLISECONDS
47 47
48/** 48/**
49 * The upper bound for the zone iteration interval in milliseconds 49 * The lower bound for the zone iteration interval
50 */ 50 */
51#define MINIMUM_ZONE_ITERATION_INTERVAL GNUNET_TIME_UNIT_SECONDS 51#define MINIMUM_ZONE_ITERATION_INTERVAL GNUNET_TIME_UNIT_SECONDS
52 52
53/** 53/**
54 * The upper bound for the zone iteration interval
55 */
56#define MAXIMUM_ZONE_ITERATION_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
57
58/**
54 * The default put interval for the zone iteration. In case 59 * The default put interval for the zone iteration. In case
55 * no option is found 60 * no option is found
56 */ 61 */
@@ -401,6 +406,12 @@ dht_put_continuation (void *cls,
401 } 406 }
402 else 407 else
403 next_put_interval = put_interval; 408 next_put_interval = put_interval;
409 next_put_interval = GNUNET_TIME_relative_min (next_put_interval,
410 MAXIMUM_ZONE_ITERATION_INTERVAL);
411 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
412 "PUT complete, next PUT in %s!\n",
413 GNUNET_STRINGS_relative_time_to_string (next_put_interval,
414 GNUNET_YES));
404 415
405 GNUNET_STATISTICS_set (statistics, 416 GNUNET_STATISTICS_set (statistics,
406 "Current zone iteration interval (ms)", 417 "Current zone iteration interval (ms)",
@@ -509,7 +520,8 @@ perform_dht_put (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
509 label, 520 label,
510 GNUNET_STRINGS_absolute_time_to_string (expire), 521 GNUNET_STRINGS_absolute_time_to_string (expire),
511 GNUNET_h2s (&query)); 522 GNUNET_h2s (&query));
512 ret = GNUNET_DHT_put (dht_handle, &query, 523 ret = GNUNET_DHT_put (dht_handle,
524 &query,
513 DHT_GNS_REPLICATION_LEVEL, 525 DHT_GNS_REPLICATION_LEVEL,
514 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, 526 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
515 GNUNET_BLOCK_TYPE_GNS_NAMERECORD, 527 GNUNET_BLOCK_TYPE_GNS_NAMERECORD,
@@ -524,6 +536,98 @@ perform_dht_put (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
524 536
525 537
526/** 538/**
539 * We encountered an error in our zone iteration.
540 */
541static void
542zone_iteration_error (void *cls)
543{
544 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
545 "Got disconnected from namestore database, retrying.\n");
546 namestore_iter = NULL;
547 /* We end up here on error/disconnect/shutdown, so potentially
548 while a zone publish task or a DHT put is still running; hence
549 we need to cancel those. */
550 if (NULL != zone_publish_task)
551 {
552 GNUNET_SCHEDULER_cancel (zone_publish_task);
553 zone_publish_task = NULL;
554 }
555 if (NULL != active_put)
556 {
557 GNUNET_DHT_put_cancel (active_put);
558 active_put = NULL;
559 }
560 zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start,
561 NULL);
562}
563
564
565/**
566 * Zone iteration is completed.
567 */
568static void
569zone_iteration_finished (void *cls)
570{
571 /* we're done with one iteration, calculate when to do the next one */
572 namestore_iter = NULL;
573 last_num_public_records = num_public_records;
574 first_zone_iteration = GNUNET_NO;
575 if (0 == num_public_records)
576 {
577 /**
578 * If no records are known (startup) or none present
579 * we can safely set the interval to the value for a single
580 * record
581 */
582 put_interval = zone_publish_time_window;
583 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
584 "No records in namestore database.\n");
585 }
586 else
587 {
588 /* If records are present, next publication is based on the minimum
589 * relative expiration time of the records published divided by 4
590 */
591 zone_publish_time_window
592 = GNUNET_TIME_relative_min (GNUNET_TIME_relative_divide (min_relative_record_time, 4),
593 zone_publish_time_window_default);
594 put_interval = GNUNET_TIME_relative_divide (zone_publish_time_window,
595 num_public_records);
596 }
597 /* reset for next iteration */
598 min_relative_record_time = GNUNET_TIME_UNIT_FOREVER_REL;
599 put_interval = GNUNET_TIME_relative_max (MINIMUM_ZONE_ITERATION_INTERVAL,
600 put_interval);
601 put_interval = GNUNET_TIME_relative_min (put_interval,
602 MAXIMUM_ZONE_ITERATION_INTERVAL);
603 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
604 "Zone iteration finished. Adjusted zone iteration interval to %s\n",
605 GNUNET_STRINGS_relative_time_to_string (put_interval,
606 GNUNET_YES));
607 GNUNET_STATISTICS_set (statistics,
608 "Current zone iteration interval (in ms)",
609 put_interval.rel_value_us / 1000LL,
610 GNUNET_NO);
611 GNUNET_STATISTICS_update (statistics,
612 "Number of zone iterations",
613 1,
614 GNUNET_NO);
615 GNUNET_STATISTICS_set (statistics,
616 "Number of public records in DHT",
617 last_num_public_records,
618 GNUNET_NO);
619 GNUNET_assert (NULL == zone_publish_task);
620 if (0 == num_public_records)
621 zone_publish_task = GNUNET_SCHEDULER_add_delayed (put_interval,
622 &publish_zone_dht_start,
623 NULL);
624 else
625 zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start,
626 NULL);
627}
628
629
630/**
527 * Function used to put all records successively into the DHT. 631 * Function used to put all records successively into the DHT.
528 * 632 *
529 * @param cls the closure (NULL) 633 * @param cls the closure (NULL)
@@ -542,95 +646,22 @@ put_gns_record (void *cls,
542 struct GNUNET_GNSRECORD_Data rd_public[rd_count]; 646 struct GNUNET_GNSRECORD_Data rd_public[rd_count];
543 unsigned int rd_public_count; 647 unsigned int rd_public_count;
544 648
545 if ( (NULL == key) &&
546 (NULL == label) &&
547 (0 == rd_count) )
548 {
549 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
550 "Got disconnected from namestore database, retrying.\n");
551 namestore_iter = NULL;
552 if (NULL != zone_publish_task)
553 {
554 GNUNET_SCHEDULER_cancel (zone_publish_task);
555 zone_publish_task = NULL;
556 }
557 zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start,
558 NULL);
559 return;
560 }
561 if (NULL == label)
562 {
563 /* we're done with one iteration, calculate when to do the next one */
564 namestore_iter = NULL;
565 last_num_public_records = num_public_records;
566 first_zone_iteration = GNUNET_NO;
567 if (0 == num_public_records)
568 {
569 /**
570 * If no records are known (startup) or none present
571 * we can safely set the interval to the value for a single
572 * record
573 */
574 put_interval = zone_publish_time_window;
575 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
576 "No records in namestore database.\n");
577 }
578 else
579 {
580 /* If records are present, next publication is based on the minimum
581 * relative expiration time of the records published divided by 4
582 */
583 zone_publish_time_window = GNUNET_TIME_relative_min (
584 GNUNET_TIME_relative_divide (min_relative_record_time, 4),
585 zone_publish_time_window_default);
586 put_interval = GNUNET_TIME_relative_divide (zone_publish_time_window,
587 num_public_records);
588 }
589 /* reset for next iteration */
590 min_relative_record_time = GNUNET_TIME_UNIT_FOREVER_REL;
591 put_interval = GNUNET_TIME_relative_max (MINIMUM_ZONE_ITERATION_INTERVAL,
592 put_interval);
593
594 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
595 "Zone iteration finished. Adjusted zone iteration interval to %s\n",
596 GNUNET_STRINGS_relative_time_to_string (put_interval,
597 GNUNET_YES));
598 GNUNET_STATISTICS_set (statistics,
599 "Current zone iteration interval (in ms)",
600 put_interval.rel_value_us / 1000LL,
601 GNUNET_NO);
602 GNUNET_STATISTICS_update (statistics,
603 "Number of zone iterations",
604 1,
605 GNUNET_NO);
606 GNUNET_STATISTICS_set (statistics,
607 "Number of public records in DHT",
608 last_num_public_records,
609 GNUNET_NO);
610 GNUNET_assert (NULL == zone_publish_task);
611 if (0 == num_public_records)
612 zone_publish_task = GNUNET_SCHEDULER_add_delayed (put_interval,
613 &publish_zone_dht_start,
614 NULL);
615 else
616 zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start,
617 NULL);
618 return;
619 }
620
621 rd_public_count = convert_records_for_export (rd, 649 rd_public_count = convert_records_for_export (rd,
622 rd_count, 650 rd_count,
623 rd_public); 651 rd_public);
624 652
625 /* We got a set of records to publish */
626 if (0 == rd_public_count) 653 if (0 == rd_public_count)
627 { 654 {
628 GNUNET_assert (NULL == zone_publish_task); 655 GNUNET_assert (NULL == zone_publish_task);
656 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
657 "Record set empty, moving to next record set\n");
629 zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_next, 658 zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_next,
630 NULL); 659 NULL);
631 return; 660 return;
632 } 661 }
633 662 /* We got a set of records to publish */
663 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
664 "Starting DHT PUT\n");
634 active_put = perform_dht_put (key, 665 active_put = perform_dht_put (key,
635 label, 666 label,
636 rd_public, 667 rd_public,
@@ -662,7 +693,11 @@ publish_zone_dht_start (void *cls)
662 namestore_iter 693 namestore_iter
663 = GNUNET_NAMESTORE_zone_iteration_start (namestore_handle, 694 = GNUNET_NAMESTORE_zone_iteration_start (namestore_handle,
664 NULL, /* All zones */ 695 NULL, /* All zones */
696 &zone_iteration_error,
697 NULL,
665 &put_gns_record, 698 &put_gns_record,
699 NULL,
700 &zone_iteration_finished,
666 NULL); 701 NULL);
667} 702}
668 703
@@ -694,13 +729,16 @@ handle_monitor_event (void *cls,
694 label); 729 label);
695 /* filter out records that are not public, and convert to 730 /* filter out records that are not public, and convert to
696 absolute expiration time. */ 731 absolute expiration time. */
697 rd_public_count = convert_records_for_export (rd, rd_count, 732 rd_public_count = convert_records_for_export (rd,
733 rd_count,
698 rd_public); 734 rd_public);
699 if (0 == rd_public_count) 735 if (0 == rd_public_count)
700 return; /* nothing to do */ 736 return; /* nothing to do */
701 ma = GNUNET_new (struct MonitorActivity); 737 ma = GNUNET_new (struct MonitorActivity);
702 ma->ph = perform_dht_put (zone, label, 738 ma->ph = perform_dht_put (zone,
703 rd, rd_count, 739 label,
740 rd,
741 rd_count,
704 ma); 742 ma);
705 if (NULL == ma->ph) 743 if (NULL == ma->ph)
706 { 744 {
@@ -881,6 +919,35 @@ monitor_sync_event (void *cls)
881 919
882 920
883/** 921/**
922 * The zone monitor is now in SYNC with the current state of the
923 * name store. Start to perform periodic iterations.
924 *
925 * @param cls NULL
926 */
927static void
928handle_monitor_error (void *cls)
929{
930 if (NULL != zone_publish_task)
931 {
932 GNUNET_SCHEDULER_cancel (zone_publish_task);
933 zone_publish_task = NULL;
934 }
935 if (NULL != namestore_iter)
936 {
937 GNUNET_NAMESTORE_zone_iteration_stop (namestore_iter);
938 namestore_iter = NULL;
939 }
940 if (NULL != active_put)
941 {
942 GNUNET_DHT_put_cancel (active_put);
943 active_put = NULL;
944 }
945 zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start,
946 NULL);
947}
948
949
950/**
884 * Method called to inform about the ego to be used for the master zone 951 * Method called to inform about the ego to be used for the master zone
885 * for DNS interceptions. 952 * for DNS interceptions.
886 * 953 *
@@ -1032,7 +1099,10 @@ run (void *cls,
1032 zmon = GNUNET_NAMESTORE_zone_monitor_start (c, 1099 zmon = GNUNET_NAMESTORE_zone_monitor_start (c,
1033 NULL, 1100 NULL,
1034 GNUNET_NO, 1101 GNUNET_NO,
1102 &handle_monitor_error,
1103 NULL,
1035 &handle_monitor_event, 1104 &handle_monitor_event,
1105 NULL,
1036 &monitor_sync_event, 1106 &monitor_sync_event,
1037 NULL); 1107 NULL);
1038 GNUNET_break (NULL != zmon); 1108 GNUNET_break (NULL != zmon);
diff --git a/src/gns/gnunet-service-gns_shorten.c b/src/gns/gnunet-service-gns_shorten.c
index dd546ae56..9aa0419aa 100644
--- a/src/gns/gnunet-service-gns_shorten.c
+++ b/src/gns/gnunet-service-gns_shorten.c
@@ -326,6 +326,21 @@ process_pseu_lookup_ns (void *cls,
326 326
327 327
328/** 328/**
329 * Encountered an error in zone-to-name lookup, give up on shortening.
330 */
331static void
332zone_to_name_error_cb (void *cls)
333{
334 struct GetPseuAuthorityHandle* gph = cls;
335
336 gph->namestore_task = NULL;
337 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
338 "Shortening aborted, internal error talking to namestore\n");
339 free_get_pseu_authority_handle (gph);
340}
341
342
343/**
329 * Callback called by namestore for a zone to name result. We're 344 * Callback called by namestore for a zone to name result. We're
330 * trying to see if a short name for a given zone already exists. 345 * trying to see if a short name for a given zone already exists.
331 * 346 *
@@ -343,9 +358,6 @@ process_zone_to_name_discover (void *cls,
343 const struct GNUNET_GNSRECORD_Data *rd) 358 const struct GNUNET_GNSRECORD_Data *rd)
344{ 359{
345 struct GetPseuAuthorityHandle* gph = cls; 360 struct GetPseuAuthorityHandle* gph = cls;
346#if 0
347 struct GNUNET_HashCode lookup_key;
348#endif
349 361
350 gph->namestore_task = NULL; 362 gph->namestore_task = NULL;
351 if (0 != rd_len) 363 if (0 != rd_len)
@@ -412,6 +424,8 @@ GNS_shorten_start (const char *original_label,
412 gph->namestore_task = GNUNET_NAMESTORE_zone_to_name (namestore_handle, 424 gph->namestore_task = GNUNET_NAMESTORE_zone_to_name (namestore_handle,
413 shorten_zone, 425 shorten_zone,
414 pub, 426 pub,
427 &zone_to_name_error_cb,
428 gph,
415 &process_zone_to_name_discover, 429 &process_zone_to_name_discover,
416 gph); 430 gph);
417} 431}
diff --git a/src/identity-provider/gnunet-service-identity-provider.c b/src/identity-provider/gnunet-service-identity-provider.c
index 7a68fe902..228e6cdc5 100644
--- a/src/identity-provider/gnunet-service-identity-provider.c
+++ b/src/identity-provider/gnunet-service-identity-provider.c
@@ -531,6 +531,32 @@ clear_ego_attrs (void *cls,
531} 531}
532 532
533 533
534static void
535token_collect_error_cb (void *cls)
536{
537 // struct EgoEntry *ego_entry = cls;
538
539 GNUNET_assert (0); // FIXME: handle properly!
540}
541
542
543static void
544token_collect_finished_cb (void *cls)
545{
546 struct EgoEntry *ego_entry = cls;
547
548 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
549 ">>> Updating Ego finished\n");
550 //Clear attribute map for ego
551 GNUNET_CONTAINER_multihashmap_iterate (ego_entry->attr_map,
552 &clear_ego_attrs,
553 ego_entry);
554 GNUNET_CONTAINER_multihashmap_clear (ego_entry->attr_map);
555 update_task = GNUNET_SCHEDULER_add_now (&update_identities,
556 ego_entry->next);
557}
558
559
534/** 560/**
535 * 561 *
536 * Update all ID_TOKEN records for an identity and store them 562 * Update all ID_TOKEN records for an identity and store them
@@ -553,21 +579,6 @@ token_collect (void *cls,
553 const struct GNUNET_GNSRECORD_Data *token_metadata_record; 579 const struct GNUNET_GNSRECORD_Data *token_metadata_record;
554 struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key; 580 struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key;
555 581
556 if (NULL == lbl)
557 {
558 //Done
559 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
560 ">>> Updating Ego finished\n");
561 //Clear attribute map for ego
562 GNUNET_CONTAINER_multihashmap_iterate (ego_entry->attr_map,
563 &clear_ego_attrs,
564 ego_entry);
565 GNUNET_CONTAINER_multihashmap_clear (ego_entry->attr_map);
566 update_task = GNUNET_SCHEDULER_add_now (&update_identities,
567 ego_entry->next);
568 return;
569 }
570
571 //There should be only a single record for a token under a label 582 //There should be only a single record for a token under a label
572 if (2 != rd_count) 583 if (2 != rd_count)
573 { 584 {
@@ -614,6 +625,28 @@ token_collect (void *cls,
614} 625}
615 626
616 627
628static void
629attribute_collect_error_cb (void *cls)
630{
631 // struct EgoEntry *ego_entry = cls;
632
633 GNUNET_assert (0); // FIXME: handle properly!
634}
635
636
637static void
638attribute_collect_finished_cb (void *cls)
639{
640 struct EgoEntry *ego_entry = cls;
641
642 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
643 ">>> Updating Attributes finished\n");
644 ego_entry->attributes_dirty = GNUNET_NO;
645 update_task = GNUNET_SCHEDULER_add_now (&update_identities,
646 ego_entry);
647}
648
649
617/** 650/**
618 * 651 *
619 * Collect all ID_ATTR records for an identity and store them 652 * Collect all ID_ATTR records for an identity and store them
@@ -639,17 +672,6 @@ attribute_collect (void *cls,
639 char *val_str; 672 char *val_str;
640 int i; 673 int i;
641 674
642 if (NULL == lbl)
643 {
644 //Done
645 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
646 ">>> Updating Attributes finished\n");
647 ego_entry->attributes_dirty = GNUNET_NO;
648 update_task = GNUNET_SCHEDULER_add_now (&update_identities,
649 ego_entry);
650 return;
651 }
652
653 if (0 == rd_count) 675 if (0 == rd_count)
654 { 676 {
655 GNUNET_NAMESTORE_zone_iterator_next (ns_it); 677 GNUNET_NAMESTORE_zone_iterator_next (ns_it);
@@ -703,7 +725,6 @@ attribute_collect (void *cls,
703 attr, 725 attr,
704 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 726 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
705 GNUNET_NAMESTORE_zone_iterator_next (ns_it); 727 GNUNET_NAMESTORE_zone_iterator_next (ns_it);
706 return;
707} 728}
708 729
709/** 730/**
@@ -718,6 +739,7 @@ update_identities(void *cls)
718{ 739{
719 struct EgoEntry *next_ego = cls; 740 struct EgoEntry *next_ego = cls;
720 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key; 741 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key;
742
721 update_task = NULL; 743 update_task = NULL;
722 if (NULL == next_ego) 744 if (NULL == next_ego)
723 { 745 {
@@ -740,7 +762,11 @@ update_identities(void *cls)
740 //Starting over. We must update the Attributes for they might have changed. 762 //Starting over. We must update the Attributes for they might have changed.
741 ns_it = GNUNET_NAMESTORE_zone_iteration_start (ns_handle, 763 ns_it = GNUNET_NAMESTORE_zone_iteration_start (ns_handle,
742 priv_key, 764 priv_key,
765 &attribute_collect_error_cb,
766 next_ego,
743 &attribute_collect, 767 &attribute_collect,
768 next_ego,
769 &attribute_collect_finished_cb,
744 next_ego); 770 next_ego);
745 771
746 } 772 }
@@ -750,7 +776,11 @@ update_identities(void *cls)
750 next_ego->attributes_dirty = GNUNET_YES; 776 next_ego->attributes_dirty = GNUNET_YES;
751 ns_it = GNUNET_NAMESTORE_zone_iteration_start (ns_handle, 777 ns_it = GNUNET_NAMESTORE_zone_iteration_start (ns_handle,
752 priv_key, 778 priv_key,
779 &token_collect_error_cb,
780 next_ego,
753 &token_collect, 781 &token_collect,
782 next_ego,
783 &token_collect_finished_cb,
754 next_ego); 784 next_ego);
755 } 785 }
756} 786}
@@ -939,7 +969,7 @@ store_token_issue_cont (void *cls,
939 struct GNUNET_IDENTITY_PROVIDER_IssueResultMessage *irm; 969 struct GNUNET_IDENTITY_PROVIDER_IssueResultMessage *irm;
940 char *ticket_str; 970 char *ticket_str;
941 char *token_str; 971 char *token_str;
942 972
943 handle->ns_qe = NULL; 973 handle->ns_qe = NULL;
944 if (GNUNET_SYSERR == success) 974 if (GNUNET_SYSERR == success)
945 { 975 {
@@ -1077,6 +1107,27 @@ sign_and_return_token (void *cls)
1077 GNUNET_free (token_metadata); 1107 GNUNET_free (token_metadata);
1078} 1108}
1079 1109
1110
1111static void
1112attr_collect_error (void *cls)
1113{
1114 // struct IssueHandle *handle = cls;
1115
1116 GNUNET_assert (0); // FIXME: handle error!
1117}
1118
1119
1120static void
1121attr_collect_finished (void *cls)
1122{
1123 struct IssueHandle *handle = cls;
1124
1125 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attribute END: \n");
1126 handle->ns_it = NULL;
1127 GNUNET_SCHEDULER_add_now (&sign_and_return_token, handle);
1128}
1129
1130
1080/** 1131/**
1081 * Collect attributes for token 1132 * Collect attributes for token
1082 */ 1133 */
@@ -1087,19 +1138,11 @@ attr_collect (void *cls,
1087 unsigned int rd_count, 1138 unsigned int rd_count,
1088 const struct GNUNET_GNSRECORD_Data *rd) 1139 const struct GNUNET_GNSRECORD_Data *rd)
1089{ 1140{
1141 struct IssueHandle *handle = cls;
1090 int i; 1142 int i;
1091 char* data; 1143 char* data;
1092 struct IssueHandle *handle = cls;
1093 struct GNUNET_HashCode key; 1144 struct GNUNET_HashCode key;
1094 1145
1095 if (NULL == label)
1096 {
1097 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attribute END: \n");
1098 handle->ns_it = NULL;
1099 GNUNET_SCHEDULER_add_now (&sign_and_return_token, handle);
1100 return;
1101 }
1102
1103 GNUNET_CRYPTO_hash (label, 1146 GNUNET_CRYPTO_hash (label,
1104 strlen (label), 1147 strlen (label),
1105 &key); 1148 &key);
@@ -1278,6 +1321,41 @@ handle_exchange_message (void *cls,
1278} 1321}
1279 1322
1280 1323
1324static void
1325find_existing_token_error (void *cls)
1326{
1327 // struct IssueHandle *handle = cls;
1328
1329 GNUNET_assert (0); // FIXME: handle properly
1330}
1331
1332
1333static void
1334find_existing_token_finished (void *cls)
1335{
1336 struct IssueHandle *handle = cls;
1337 uint64_t rnd_key;
1338
1339 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1340 ">>> No existing token found\n");
1341 rnd_key =
1342 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG,
1343 UINT64_MAX);
1344 GNUNET_STRINGS_base64_encode ((char*)&rnd_key,
1345 sizeof (uint64_t),
1346 &handle->label);
1347 handle->ns_it = NULL;
1348 handle->ns_it = GNUNET_NAMESTORE_zone_iteration_start (ns_handle,
1349 &handle->iss_key,
1350 &attr_collect_error,
1351 handle,
1352 &attr_collect,
1353 handle,
1354 &attr_collect_finished,
1355 handle);
1356}
1357
1358
1281/** 1359/**
1282 * 1360 *
1283 * Look for existing token 1361 * Look for existing token
@@ -1301,30 +1379,9 @@ find_existing_token (void *cls,
1301 struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key; 1379 struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key;
1302 struct GNUNET_HashCode key; 1380 struct GNUNET_HashCode key;
1303 int scope_count_token; 1381 int scope_count_token;
1304 uint64_t rnd_key;
1305 char *scope; 1382 char *scope;
1306 char *tmp_scopes; 1383 char *tmp_scopes;
1307 1384
1308 if (NULL == lbl)
1309 {
1310 //Done
1311 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1312 ">>> No existing token found\n");
1313 //Label
1314 rnd_key =
1315 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG,
1316 UINT64_MAX);
1317 GNUNET_STRINGS_base64_encode ((char*)&rnd_key,
1318 sizeof (uint64_t),
1319 &handle->label);
1320 handle->ns_it = NULL;
1321 handle->ns_it = GNUNET_NAMESTORE_zone_iteration_start (ns_handle,
1322 &handle->iss_key,
1323 &attr_collect,
1324 handle);
1325 return;
1326 }
1327
1328 //There should be only a single record for a token under a label 1385 //There should be only a single record for a token under a label
1329 if (2 != rd_count) 1386 if (2 != rd_count)
1330 { 1387 {
@@ -1335,7 +1392,9 @@ find_existing_token (void *cls,
1335 if (rd[0].record_type == GNUNET_GNSRECORD_TYPE_ID_TOKEN_METADATA) 1392 if (rd[0].record_type == GNUNET_GNSRECORD_TYPE_ID_TOKEN_METADATA)
1336 { 1393 {
1337 token_metadata_record = &rd[0]; 1394 token_metadata_record = &rd[0];
1338 } else { 1395 }
1396 else
1397 {
1339 token_metadata_record = &rd[1]; 1398 token_metadata_record = &rd[1];
1340 } 1399 }
1341 if (token_metadata_record->record_type != GNUNET_GNSRECORD_TYPE_ID_TOKEN_METADATA) 1400 if (token_metadata_record->record_type != GNUNET_GNSRECORD_TYPE_ID_TOKEN_METADATA)
@@ -1399,7 +1458,11 @@ find_existing_token (void *cls,
1399 handle->ns_it = NULL; 1458 handle->ns_it = NULL;
1400 handle->ns_it = GNUNET_NAMESTORE_zone_iteration_start (ns_handle, 1459 handle->ns_it = GNUNET_NAMESTORE_zone_iteration_start (ns_handle,
1401 &handle->iss_key, 1460 &handle->iss_key,
1461 &attr_collect_error,
1462 handle,
1402 &attr_collect, 1463 &attr_collect,
1464 handle,
1465 &attr_collect_finished,
1403 handle); 1466 handle);
1404 1467
1405 return; 1468 return;
@@ -1477,10 +1540,15 @@ handle_issue_message (void *cls,
1477 1540
1478 issue_handle->ns_it = GNUNET_NAMESTORE_zone_iteration_start (ns_handle, 1541 issue_handle->ns_it = GNUNET_NAMESTORE_zone_iteration_start (ns_handle,
1479 &im->iss_key, 1542 &im->iss_key,
1543 &find_existing_token_error,
1544 issue_handle,
1480 &find_existing_token, 1545 &find_existing_token,
1546 issue_handle,
1547 &find_existing_token_finished,
1481 issue_handle); 1548 issue_handle);
1482} 1549}
1483 1550
1551
1484/** 1552/**
1485 * Main function that will be run 1553 * Main function that will be run
1486 * 1554 *
diff --git a/src/identity-provider/plugin_rest_identity_provider.c b/src/identity-provider/plugin_rest_identity_provider.c
index c0b018798..fa97137d7 100644
--- a/src/identity-provider/plugin_rest_identity_provider.c
+++ b/src/identity-provider/plugin_rest_identity_provider.c
@@ -647,6 +647,16 @@ return_token_list (void *cls)
647 cleanup_handle (handle); 647 cleanup_handle (handle);
648} 648}
649 649
650
651static void
652token_collect_error_cb (void *cls)
653{
654 struct RequestHandle *handle = cls;
655
656 do_error (handle);
657}
658
659
650/** 660/**
651 * Collect all tokens for an ego 661 * Collect all tokens for an ego
652 * 662 *
@@ -658,45 +668,68 @@ token_collect (void *cls,
658 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 668 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
659 const char *label, 669 const char *label,
660 unsigned int rd_count, 670 unsigned int rd_count,
661 const struct GNUNET_GNSRECORD_Data *rd) 671 const struct GNUNET_GNSRECORD_Data *rd);
672
673
674static void
675token_collect_finished_cb (void *cls)
662{ 676{
663 int i;
664 char* data;
665 struct RequestHandle *handle = cls; 677 struct RequestHandle *handle = cls;
666 struct EgoEntry *ego_tmp; 678 struct EgoEntry *ego_tmp;
667 struct GNUNET_JSONAPI_Resource *json_resource;
668 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key; 679 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key;
669 json_t *issuer;
670 json_t *token;
671
672 if (NULL == label)
673 {
674 ego_tmp = handle->ego_head;
675 GNUNET_CONTAINER_DLL_remove (handle->ego_head,
676 handle->ego_tail,
677 ego_tmp);
678 GNUNET_free (ego_tmp->identifier);
679 GNUNET_free (ego_tmp->keystring);
680 GNUNET_free (ego_tmp);
681 680
682 if (NULL == handle->ego_head) 681 ego_tmp = handle->ego_head;
683 { 682 GNUNET_CONTAINER_DLL_remove (handle->ego_head,
684 //Done 683 handle->ego_tail,
685 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding token END\n"); 684 ego_tmp);
686 handle->ns_it = NULL; 685 GNUNET_free (ego_tmp->identifier);
687 GNUNET_SCHEDULER_add_now (&return_token_list, handle); 686 GNUNET_free (ego_tmp->keystring);
688 return; 687 GNUNET_free (ego_tmp);
689 }
690 688
691 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Next ego: %s\n", handle->ego_head->identifier); 689 if (NULL == handle->ego_head)
692 priv_key = GNUNET_IDENTITY_ego_get_private_key (handle->ego_head->ego); 690 {
693 handle->ns_it = GNUNET_NAMESTORE_zone_iteration_start (handle->ns_handle, 691 //Done
694 priv_key, 692 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding token END\n");
695 &token_collect, 693 handle->ns_it = NULL;
696 handle); 694 GNUNET_SCHEDULER_add_now (&return_token_list, handle);
697 return; 695 return;
698 } 696 }
699 697
698 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
699 "Next ego: %s\n",
700 handle->ego_head->identifier);
701 priv_key = GNUNET_IDENTITY_ego_get_private_key (handle->ego_head->ego);
702 handle->ns_it = GNUNET_NAMESTORE_zone_iteration_start (handle->ns_handle,
703 priv_key,
704 &token_collect_error_cb,
705 handle,
706 &token_collect,
707 handle,
708 &token_collect_finished_cb,
709 handle);
710}
711
712
713/**
714 * Collect all tokens for an ego
715 *
716 * TODO move this into the identity-provider service
717 *
718 */
719static void
720token_collect (void *cls,
721 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
722 const char *label,
723 unsigned int rd_count,
724 const struct GNUNET_GNSRECORD_Data *rd)
725{
726 struct RequestHandle *handle = cls;
727 int i;
728 char* data;
729 struct GNUNET_JSONAPI_Resource *json_resource;
730 json_t *issuer;
731 json_t *token;
732
700 for (i = 0; i < rd_count; i++) 733 for (i = 0; i < rd_count; i++)
701 { 734 {
702 if (rd[i].record_type == GNUNET_GNSRECORD_TYPE_ID_TOKEN) 735 if (rd[i].record_type == GNUNET_GNSRECORD_TYPE_ID_TOKEN)
@@ -789,7 +822,11 @@ list_token_cont (struct GNUNET_REST_RequestHandle *con_handle,
789 handle->ns_handle = GNUNET_NAMESTORE_connect (cfg); 822 handle->ns_handle = GNUNET_NAMESTORE_connect (cfg);
790 handle->ns_it = GNUNET_NAMESTORE_zone_iteration_start (handle->ns_handle, 823 handle->ns_it = GNUNET_NAMESTORE_zone_iteration_start (handle->ns_handle,
791 priv_key, 824 priv_key,
825 &token_collect_error_cb,
826 handle,
792 &token_collect, 827 &token_collect,
828 handle,
829 &token_collect_finished_cb,
793 handle); 830 handle);
794 831
795} 832}
diff --git a/src/include/gnunet_namestore_service.h b/src/include/gnunet_namestore_service.h
index 1918ca1ff..0add8852a 100644
--- a/src/include/gnunet_namestore_service.h
+++ b/src/include/gnunet_namestore_service.h
@@ -133,8 +133,8 @@ GNUNET_NAMESTORE_records_store (struct GNUNET_NAMESTORE_Handle *h,
133 * Process a record that was stored in the namestore. 133 * Process a record that was stored in the namestore.
134 * 134 *
135 * @param cls closure 135 * @param cls closure
136 * @param zone private key of the zone; NULL on disconnect 136 * @param zone private key of the zone
137 * @param label label of the records; NULL on disconnect 137 * @param label label of the records
138 * @param rd_count number of entries in @a rd array, 0 if label was deleted 138 * @param rd_count number of entries in @a rd array, 0 if label was deleted
139 * @param rd array of records with data to store 139 * @param rd array of records with data to store
140 */ 140 */
@@ -170,7 +170,11 @@ GNUNET_NAMESTORE_set_nick (struct GNUNET_NAMESTORE_Handle *h,
170 * @param h handle to the namestore 170 * @param h handle to the namestore
171 * @param pkey private key of the zone 171 * @param pkey private key of the zone
172 * @param label name that is being mapped 172 * @param label name that is being mapped
173 * @param rm function to call with the result (with 0 records if we don't have that label) 173 * @param error_cb function to call on error (i.e. disconnect)
174 * the handle is afterwards invalid
175 * @param error_cb_cls closure for @a error_cb
176 * @param rm function to call with the result (with 0 records if we don't have that label);
177 * the handle is afterwards invalid
174 * @param rm_cls closure for @a rm 178 * @param rm_cls closure for @a rm
175 * @return handle to abort the request 179 * @return handle to abort the request
176 */ 180 */
@@ -178,6 +182,8 @@ struct GNUNET_NAMESTORE_QueueEntry *
178GNUNET_NAMESTORE_records_lookup (struct GNUNET_NAMESTORE_Handle *h, 182GNUNET_NAMESTORE_records_lookup (struct GNUNET_NAMESTORE_Handle *h,
179 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, 183 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
180 const char *label, 184 const char *label,
185 GNUNET_SCHEDULER_TaskCallback error_cb,
186 void *error_cb_cls,
181 GNUNET_NAMESTORE_RecordMonitor rm, 187 GNUNET_NAMESTORE_RecordMonitor rm,
182 void *rm_cls); 188 void *rm_cls);
183 189
@@ -189,8 +195,12 @@ GNUNET_NAMESTORE_records_lookup (struct GNUNET_NAMESTORE_Handle *h,
189 * @param h handle to the namestore 195 * @param h handle to the namestore
190 * @param zone public key of the zone to look up in, never NULL 196 * @param zone public key of the zone to look up in, never NULL
191 * @param value_zone public key of the target zone (value), never NULL 197 * @param value_zone public key of the target zone (value), never NULL
198 * @param error_cb function to call on error (i.e. disconnect)
199 * the handle is afterwards invalid
200 * @param error_cb_cls closure for @a error_cb
192 * @param proc function to call on the matching records, or with 201 * @param proc function to call on the matching records, or with
193 * NULL (rd_count == 0) if there are no matching records 202 * NULL (rd_count == 0) if there are no matching records;
203 * the handle is afterwards invalid
194 * @param proc_cls closure for @a proc 204 * @param proc_cls closure for @a proc
195 * @return a handle that can be used to 205 * @return a handle that can be used to
196 * cancel 206 * cancel
@@ -199,7 +209,10 @@ struct GNUNET_NAMESTORE_QueueEntry *
199GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h, 209GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h,
200 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 210 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
201 const struct GNUNET_CRYPTO_EcdsaPublicKey *value_zone, 211 const struct GNUNET_CRYPTO_EcdsaPublicKey *value_zone,
202 GNUNET_NAMESTORE_RecordMonitor proc, void *proc_cls); 212 GNUNET_SCHEDULER_TaskCallback error_cb,
213 void *error_cb_cls,
214 GNUNET_NAMESTORE_RecordMonitor proc,
215 void *proc_cls);
203 216
204 217
205/** 218/**
@@ -216,25 +229,38 @@ GNUNET_NAMESTORE_cancel (struct GNUNET_NAMESTORE_QueueEntry *qe);
216 229
217/** 230/**
218 * Starts a new zone iteration (used to periodically PUT all of our 231 * Starts a new zone iteration (used to periodically PUT all of our
219 * records into our DHT). This MUST lock the struct GNUNET_NAMESTORE_Handle 232 * records into our DHT). This MUST lock the `struct GNUNET_NAMESTORE_Handle`
220 * for any other calls than #GNUNET_NAMESTORE_zone_iterator_next and 233 * for any other calls than #GNUNET_NAMESTORE_zone_iterator_next() and
221 * #GNUNET_NAMESTORE_zone_iteration_stop. @a proc will be called once 234 * #GNUNET_NAMESTORE_zone_iteration_stop. @a proc will be called once
222 * immediately, and then again after 235 * immediately, and then again after
223 * #GNUNET_NAMESTORE_zone_iterator_next is invoked. 236 * #GNUNET_NAMESTORE_zone_iterator_next() is invoked.
237 *
238 * On error (disconnect), @a error_cb will be invoked.
239 * On normal completion, @a finish_cb proc will be
240 * invoked.
224 * 241 *
225 * @param h handle to the namestore 242 * @param h handle to the namestore
226 * @param zone zone to access, NULL for all zones 243 * @param zone zone to access, NULL for all zones
244 * @param error_cb function to call on error (i.e. disconnect),
245 * the handle is afterwards invalid
246 * @param error_cb_cls closure for @a error_cb
227 * @param proc function to call on each name from the zone; it 247 * @param proc function to call on each name from the zone; it
228 * will be called repeatedly with a value (if available) 248 * will be called repeatedly with a value (if available)
229 * and always once at the end with a label of NULL.
230 * @param proc_cls closure for @a proc 249 * @param proc_cls closure for @a proc
250 * @param finish_cb function to call on completion
251 * the handle is afterwards invalid
252 * @param finish_cb_cls closure for @a finish_cb
231 * @return an iterator handle to use for iteration 253 * @return an iterator handle to use for iteration
232 */ 254 */
233struct GNUNET_NAMESTORE_ZoneIterator * 255struct GNUNET_NAMESTORE_ZoneIterator *
234GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h, 256GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h,
235 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 257 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
258 GNUNET_SCHEDULER_TaskCallback error_cb,
259 void *error_cb_cls,
236 GNUNET_NAMESTORE_RecordMonitor proc, 260 GNUNET_NAMESTORE_RecordMonitor proc,
237 void *proc_cls); 261 void *proc_cls,
262 GNUNET_SCHEDULER_TaskCallback finish_cb,
263 void *finish_cb_cls);
238 264
239 265
240/** 266/**
@@ -265,44 +291,42 @@ struct GNUNET_NAMESTORE_ZoneMonitor;
265 291
266 292
267/** 293/**
268 * Function called once the monitor has caught up with the current
269 * state of the database. Will be called AGAIN after each disconnect
270 * (record monitor called with 'NULL' for zone_key) once we're again
271 * in sync.
272 *
273 * @param cls closure
274 */
275typedef void
276(*GNUNET_NAMESTORE_RecordsSynchronizedCallback)(void *cls);
277
278
279/**
280 * Begin monitoring a zone for changes. Will first call the @a 294 * Begin monitoring a zone for changes. Will first call the @a
281 * monitor function on all existing records in the selected zone(s) if 295 * monitor function on all existing records in the selected zone(s) if
282 * @a iterate_first is #GNUNET_YES. In any case, we will then call @a 296 * @a iterate_first is #GNUNET_YES. In any case, we will then call @a
283 * sync_cb, and then afterwards call the @a monitor whenever a record 297 * sync_cb, and then afterwards call the @a monitor whenever a record
284 * changes. If the namestore disconnects, the @a monitor function is 298 * changes. If the namestore disconnects, the @a error_cb function is
285 * called with a disconnect event; if the connection is 299 * called with a disconnect event. Once the connection is
286 * re-established, the process begins from the start (depending on @a 300 * re-established, the process begins from the start (depending on @a
287 * iterate_first, we first do all existing records, then @a sync, then 301 * iterate_first, we will again first do all existing records, then @a
288 * updates). 302 * sync, then updates).
289 * 303 *
290 * @param cfg configuration to use to connect to namestore 304 * @param cfg configuration to use to connect to namestore
291 * @param zone zone to monitor, NULL for all zones 305 * @param zone zone to monitor, NULL for all zones
292 * @param iterate_first #GNUNET_YES to first iterate over all existing records, 306 * @param iterate_first #GNUNET_YES to first iterate over all existing records,
293 * #GNUNET_NO to only return changes that happen from now on 307 * #GNUNET_NO to only return changes that happen from now on
308 * @param error_cb function to call on error (i.e. disconnect); note that
309 * unlike the other error callbacks in this API, a call to this
310 * function does NOT destroy the monitor handle, it merely signals
311 * that monitoring is down. You need to still explicitly call
312 * #GNUNET_NAMESTORE_zone_monitor_stop().
313 * @param error_cb_cls closure for @a error_cb
294 * @param monitor function to call on zone changes 314 * @param monitor function to call on zone changes
315 * @param monitor_cls closure for @a monitor
295 * @param sync_cb function called when we're in sync with the namestore 316 * @param sync_cb function called when we're in sync with the namestore
296 * @param cls closure for @a monitor and @a sync_cb 317 * @param sync_cb_cls closure for @a sync_cb
297 * @return handle to stop monitoring 318 * @return handle to stop monitoring
298 */ 319 */
299struct GNUNET_NAMESTORE_ZoneMonitor * 320struct GNUNET_NAMESTORE_ZoneMonitor *
300GNUNET_NAMESTORE_zone_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg, 321GNUNET_NAMESTORE_zone_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
301 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 322 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
302 int iterate_first, 323 int iterate_first,
324 GNUNET_SCHEDULER_TaskCallback error_cb,
325 void *error_cb_cls,
303 GNUNET_NAMESTORE_RecordMonitor monitor, 326 GNUNET_NAMESTORE_RecordMonitor monitor,
304 GNUNET_NAMESTORE_RecordsSynchronizedCallback sync_cb, 327 void *monitor_cls,
305 void *cls); 328 GNUNET_SCHEDULER_TaskCallback sync_cb,
329 void *sync_cb_cls);
306 330
307 331
308/** 332/**
diff --git a/src/namestore/gnunet-namestore-fcfsd.c b/src/namestore/gnunet-namestore-fcfsd.c
index ed7009e02..b38761d5a 100644
--- a/src/namestore/gnunet-namestore-fcfsd.c
+++ b/src/namestore/gnunet-namestore-fcfsd.c
@@ -247,6 +247,62 @@ run_httpd_now ()
247 247
248 248
249/** 249/**
250 * Function called on error in zone iteration.
251 */
252static void
253zone_iteration_error (void *cls)
254{
255 struct ZoneinfoRequest *zr = cls;
256 struct MHD_Response *response;
257
258 zr->list_it = NULL;
259 response = MHD_create_response_from_buffer (strlen ("internal error"),
260 (void *) "internal error",
261 MHD_RESPMEM_PERSISTENT);
262 MHD_queue_response (zr->connection,
263 MHD_HTTP_INTERNAL_SERVER_ERROR,
264 response);
265 MHD_destroy_response (response);
266 GNUNET_free (zr->zoneinfo);
267 GNUNET_free (zr);
268 run_httpd_now ();
269}
270
271
272/**
273 * Function called once the zone iteration is done.
274 */
275static void
276zone_iteration_end (void *cls)
277{
278 struct ZoneinfoRequest *zr = cls;
279 struct MHD_Response *response;
280 char* full_page;
281
282 zr->list_it = NULL;
283
284 /* return static form */
285 GNUNET_asprintf (&full_page,
286 ZONEINFO_PAGE,
287 zr->zoneinfo,
288 zr->zoneinfo);
289 response = MHD_create_response_from_buffer (strlen (full_page),
290 (void *) full_page,
291 MHD_RESPMEM_MUST_FREE);
292 MHD_add_response_header (response,
293 MHD_HTTP_HEADER_CONTENT_TYPE,
294 MIME_HTML);
295 MHD_queue_response (zr->connection,
296 MHD_HTTP_OK,
297 response);
298 MHD_destroy_response (response);
299 GNUNET_free (zr->zoneinfo);
300 GNUNET_free (zr);
301 run_httpd_now ();
302}
303
304
305/**
250 * Process a record that was stored in the namestore, adding 306 * Process a record that was stored in the namestore, adding
251 * the information to the HTML. 307 * the information to the HTML.
252 * 308 *
@@ -264,38 +320,10 @@ iterate_cb (void *cls,
264 const struct GNUNET_GNSRECORD_Data *rd) 320 const struct GNUNET_GNSRECORD_Data *rd)
265{ 321{
266 struct ZoneinfoRequest *zr = cls; 322 struct ZoneinfoRequest *zr = cls;
267 struct MHD_Response *response;
268 char* full_page;
269 size_t bytes_free; 323 size_t bytes_free;
270 char* pkey; 324 char* pkey;
271 char* new_buf; 325 char* new_buf;
272 326
273
274 if (NULL == name)
275 {
276 zr->list_it = NULL;
277
278 /* return static form */
279 GNUNET_asprintf (&full_page,
280 ZONEINFO_PAGE,
281 zr->zoneinfo,
282 zr->zoneinfo);
283 response = MHD_create_response_from_buffer (strlen (full_page),
284 (void *) full_page,
285 MHD_RESPMEM_MUST_FREE);
286 MHD_add_response_header (response,
287 MHD_HTTP_HEADER_CONTENT_TYPE,
288 MIME_HTML);
289 MHD_queue_response (zr->connection,
290 MHD_HTTP_OK,
291 response);
292 MHD_destroy_response (response);
293 GNUNET_free (zr->zoneinfo);
294 GNUNET_free (zr);
295 run_httpd_now ();
296 return;
297 }
298
299 if (1 != rd_len) 327 if (1 != rd_len)
300 { 328 {
301 GNUNET_NAMESTORE_zone_iterator_next (zr->list_it); 329 GNUNET_NAMESTORE_zone_iterator_next (zr->list_it);
@@ -354,8 +382,12 @@ serve_zoneinfo_page (struct MHD_Connection *connection)
354 zr->write_offset = 0; 382 zr->write_offset = 0;
355 zr->list_it = GNUNET_NAMESTORE_zone_iteration_start (ns, 383 zr->list_it = GNUNET_NAMESTORE_zone_iteration_start (ns,
356 &fcfs_zone_pkey, 384 &fcfs_zone_pkey,
385 &zone_iteration_error,
386 zr,
357 &iterate_cb, 387 &iterate_cb,
358 zr); 388 zr,
389 &zone_iteration_end,
390 zr);
359 return MHD_YES; 391 return MHD_YES;
360} 392}
361 393
@@ -512,6 +544,21 @@ put_continuation (void *cls,
512 544
513 545
514/** 546/**
547 * Function called if we had an error in zone-to-name mapping.
548 */
549static void
550zone_to_name_error (void *cls)
551{
552 struct Request *request = cls;
553
554 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
555 _("Error when mapping zone to name\n"));
556 request->phase = RP_FAIL;
557 run_httpd_now ();
558}
559
560
561/**
515 * Test if a name mapping was found, if so, refuse. If not, initiate storing of the record. 562 * Test if a name mapping was found, if so, refuse. If not, initiate storing of the record.
516 * 563 *
517 * @param cls closure 564 * @param cls closure
@@ -529,6 +576,7 @@ zone_to_name_cb (void *cls,
529{ 576{
530 struct Request *request = cls; 577 struct Request *request = cls;
531 struct GNUNET_GNSRECORD_Data r; 578 struct GNUNET_GNSRECORD_Data r;
579
532 request->qe = NULL; 580 request->qe = NULL;
533 581
534 if (0 != rd_count) 582 if (0 != rd_count)
@@ -540,15 +588,6 @@ zone_to_name_cb (void *cls,
540 run_httpd_now (); 588 run_httpd_now ();
541 return; 589 return;
542 } 590 }
543 if (NULL == zone_key)
544 {
545 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
546 _("Error when mapping zone to name\n"));
547 request->phase = RP_FAIL;
548 run_httpd_now ();
549 return;
550 }
551
552 r.data = &request->pub; 591 r.data = &request->pub;
553 r.data_size = sizeof (request->pub); 592 r.data_size = sizeof (request->pub);
554 r.expiration_time = UINT64_MAX; 593 r.expiration_time = UINT64_MAX;
@@ -564,6 +603,20 @@ zone_to_name_cb (void *cls,
564 603
565 604
566/** 605/**
606 * We encountered an error in the name lookup.
607 */
608static void
609lookup_block_error (void *cls)
610{
611 struct Request *request = cls;
612
613 request->qe = NULL;
614 request->phase = RP_FAIL;
615 run_httpd_now ();
616}
617
618
619/**
567 * We got a block back from the namestore. Decrypt it 620 * We got a block back from the namestore. Decrypt it
568 * and continue to process the result. 621 * and continue to process the result.
569 * 622 *
@@ -585,7 +638,6 @@ lookup_block_processor (void *cls,
585 request->qe = NULL; 638 request->qe = NULL;
586 if (0 == rd_count) 639 if (0 == rd_count)
587 { 640 {
588
589 if (GNUNET_OK != 641 if (GNUNET_OK !=
590 GNUNET_CRYPTO_ecdsa_public_key_from_string (request->public_key, 642 GNUNET_CRYPTO_ecdsa_public_key_from_string (request->public_key,
591 strlen (request->public_key), 643 strlen (request->public_key),
@@ -599,6 +651,8 @@ lookup_block_processor (void *cls,
599 request->qe = GNUNET_NAMESTORE_zone_to_name (ns, 651 request->qe = GNUNET_NAMESTORE_zone_to_name (ns,
600 &fcfs_zone_pkey, 652 &fcfs_zone_pkey,
601 &request->pub, 653 &request->pub,
654 &zone_to_name_error,
655 request,
602 &zone_to_name_cb, 656 &zone_to_name_cb,
603 request); 657 request);
604 return; 658 return;
@@ -728,10 +782,12 @@ create_response (void *cls,
728 } 782 }
729 request->phase = RP_LOOKUP; 783 request->phase = RP_LOOKUP;
730 request->qe = GNUNET_NAMESTORE_records_lookup (ns, 784 request->qe = GNUNET_NAMESTORE_records_lookup (ns,
731 &fcfs_zone_pkey, 785 &fcfs_zone_pkey,
732 request->domain_name, 786 request->domain_name,
733 &lookup_block_processor, 787 &lookup_block_error,
734 request); 788 request,
789 &lookup_block_processor,
790 request);
735 break; 791 break;
736 case RP_LOOKUP: 792 case RP_LOOKUP:
737 break; 793 break;
diff --git a/src/namestore/gnunet-namestore.c b/src/namestore/gnunet-namestore.c
index 43cabed2a..7a671f1b6 100644
--- a/src/namestore/gnunet-namestore.c
+++ b/src/namestore/gnunet-namestore.c
@@ -343,6 +343,31 @@ del_continuation (void *cls,
343 343
344 344
345/** 345/**
346 * Function called when we are done with a zone iteration.
347 */
348static void
349zone_iteration_finished (void *cls)
350{
351 list_it = NULL;
352 test_finished ();
353}
354
355
356/**
357 * Function called when we encountered an error in a zone iteration.
358 */
359static void
360zone_iteration_error_cb (void *cls)
361{
362 list_it = NULL;
363 fprintf (stderr,
364 "Error iterating over zone\n");
365 ret = 1;
366 test_finished ();
367}
368
369
370/**
346 * Process a record that was stored in the namestore. 371 * Process a record that was stored in the namestore.
347 * 372 *
348 * @param cls closure 373 * @param cls closure
@@ -365,12 +390,6 @@ display_record (void *cls,
365 struct GNUNET_TIME_Absolute at; 390 struct GNUNET_TIME_Absolute at;
366 struct GNUNET_TIME_Relative rt; 391 struct GNUNET_TIME_Relative rt;
367 392
368 if (NULL == rname)
369 {
370 list_it = NULL;
371 test_finished ();
372 return;
373 }
374 if ( (NULL != name) && 393 if ( (NULL != name) &&
375 (0 != strcmp (name, rname)) ) 394 (0 != strcmp (name, rname)) )
376 { 395 {
@@ -433,6 +452,31 @@ sync_cb (void *cls)
433 452
434 453
435/** 454/**
455 * Function called on errors while monitoring.
456 *
457 * @param cls NULL
458 */
459static void
460monitor_error_cb (void *cls)
461{
462 FPRINTF (stderr, "%s", "Monitor disconnected and out of sync.\n");
463}
464
465
466/**
467 * Function called if lookup fails.
468 */
469static void
470lookup_error_cb (void *cls)
471{
472 add_qe = NULL;
473 GNUNET_break (0);
474 ret = 1;
475 test_finished ();
476}
477
478
479/**
436 * We're storing a record; this function is given the existing record 480 * We're storing a record; this function is given the existing record
437 * so that we can merge the information. 481 * so that we can merge the information.
438 * 482 *
@@ -454,8 +498,7 @@ get_existing_record (void *cls,
454 unsigned int i; 498 unsigned int i;
455 499
456 add_qe = NULL; 500 add_qe = NULL;
457 if ( (NULL != zone_key) && 501 if (0 != strcmp (rec_name, name))
458 (0 != strcmp (rec_name, name)) )
459 { 502 {
460 GNUNET_break (0); 503 GNUNET_break (0);
461 ret = 1; 504 ret = 1;
@@ -566,6 +609,19 @@ get_existing_record (void *cls,
566 609
567 610
568/** 611/**
612 * Function called if we encountered an error in zone-to-name.
613 */
614static void
615reverse_error_cb (void *cls)
616{
617 reverse_qe = NULL;
618 FPRINTF (stdout,
619 "%s.zkey\n",
620 reverse_pkey);
621}
622
623
624/**
569 * Function called with the result of our attempt to obtain a name for a given 625 * Function called with the result of our attempt to obtain a name for a given
570 * public key. 626 * public key.
571 * 627 *
@@ -596,6 +652,19 @@ handle_reverse_lookup (void *cls,
596 652
597 653
598/** 654/**
655 * Function called if lookup for deletion fails.
656 */
657static void
658del_lookup_error_cb (void *cls)
659{
660 del_qe = NULL;
661 GNUNET_break (0);
662 ret = 1;
663 test_finished ();
664}
665
666
667/**
599 * We were asked to delete something; this function is called with 668 * We were asked to delete something; this function is called with
600 * the existing records. Now we should determine what should be 669 * the existing records. Now we should determine what should be
601 * deleted and then issue the deletion operation. 670 * deleted and then issue the deletion operation.
@@ -802,8 +871,13 @@ testservice_task (void *cls,
802 ret = 1; 871 ret = 1;
803 return; 872 return;
804 } 873 }
805 add_qe = GNUNET_NAMESTORE_records_lookup (ns, &zone_pkey, name, 874 add_qe = GNUNET_NAMESTORE_records_lookup (ns,
806 &get_existing_record, NULL ); 875 &zone_pkey,
876 name,
877 &lookup_error_cb,
878 NULL,
879 &get_existing_record,
880 NULL);
807 } 881 }
808 if (del) 882 if (del)
809 { 883 {
@@ -819,6 +893,8 @@ testservice_task (void *cls,
819 del_qe = GNUNET_NAMESTORE_records_lookup (ns, 893 del_qe = GNUNET_NAMESTORE_records_lookup (ns,
820 &zone_pkey, 894 &zone_pkey,
821 name, 895 name,
896 &del_lookup_error_cb,
897 NULL,
822 &del_monitor, 898 &del_monitor,
823 NULL); 899 NULL);
824 } 900 }
@@ -826,7 +902,11 @@ testservice_task (void *cls,
826 { 902 {
827 list_it = GNUNET_NAMESTORE_zone_iteration_start (ns, 903 list_it = GNUNET_NAMESTORE_zone_iteration_start (ns,
828 &zone_pkey, 904 &zone_pkey,
905 &zone_iteration_error_cb,
906 NULL,
829 &display_record, 907 &display_record,
908 NULL,
909 &zone_iteration_finished,
830 NULL); 910 NULL);
831 } 911 }
832 if (NULL != reverse_pkey) 912 if (NULL != reverse_pkey)
@@ -846,6 +926,8 @@ testservice_task (void *cls,
846 reverse_qe = GNUNET_NAMESTORE_zone_to_name (ns, 926 reverse_qe = GNUNET_NAMESTORE_zone_to_name (ns,
847 &zone_pkey, 927 &zone_pkey,
848 &pubkey, 928 &pubkey,
929 &reverse_error_cb,
930 NULL,
849 &handle_reverse_lookup, 931 &handle_reverse_lookup,
850 NULL); 932 NULL);
851 } 933 }
@@ -860,7 +942,10 @@ testservice_task (void *cls,
860 "gnunet://gns/%52s/%63s", 942 "gnunet://gns/%52s/%63s",
861 sh, 943 sh,
862 sname)) ) || 944 sname)) ) ||
863 (GNUNET_OK != GNUNET_CRYPTO_ecdsa_public_key_from_string (sh, strlen (sh), &pkey)) ) 945 (GNUNET_OK !=
946 GNUNET_CRYPTO_ecdsa_public_key_from_string (sh,
947 strlen (sh),
948 &pkey)) )
864 { 949 {
865 fprintf (stderr, 950 fprintf (stderr,
866 _("Invalid URI `%s'\n"), 951 _("Invalid URI `%s'\n"),
@@ -912,7 +997,10 @@ testservice_task (void *cls,
912 zm = GNUNET_NAMESTORE_zone_monitor_start (cfg, 997 zm = GNUNET_NAMESTORE_zone_monitor_start (cfg,
913 &zone_pkey, 998 &zone_pkey,
914 GNUNET_YES, 999 GNUNET_YES,
1000 &monitor_error_cb,
1001 NULL,
915 &display_record, 1002 &display_record,
1003 NULL,
916 &sync_cb, 1004 &sync_cb,
917 NULL); 1005 NULL);
918 } 1006 }
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c
index b8da654ce..61d8385b6 100644
--- a/src/namestore/namestore_api.c
+++ b/src/namestore/namestore_api.c
@@ -84,6 +84,16 @@ struct GNUNET_NAMESTORE_QueueEntry
84 void *proc_cls; 84 void *proc_cls;
85 85
86 /** 86 /**
87 * Function to call on errors.
88 */
89 GNUNET_SCHEDULER_TaskCallback error_cb;
90
91 /**
92 * Closure for @e error_cb.
93 */
94 void *error_cb_cls;
95
96 /**
87 * Envelope of the message to send to the service, if not yet 97 * Envelope of the message to send to the service, if not yet
88 * sent. 98 * sent.
89 */ 99 */
@@ -119,6 +129,16 @@ struct GNUNET_NAMESTORE_ZoneIterator
119 struct GNUNET_NAMESTORE_Handle *h; 129 struct GNUNET_NAMESTORE_Handle *h;
120 130
121 /** 131 /**
132 * Function to call on completion.
133 */
134 GNUNET_SCHEDULER_TaskCallback finish_cb;
135
136 /**
137 * Closure for @e error_cb.
138 */
139 void *finish_cb_cls;
140
141 /**
122 * The continuation to call with the results 142 * The continuation to call with the results
123 */ 143 */
124 GNUNET_NAMESTORE_RecordMonitor proc; 144 GNUNET_NAMESTORE_RecordMonitor proc;
@@ -129,6 +149,16 @@ struct GNUNET_NAMESTORE_ZoneIterator
129 void *proc_cls; 149 void *proc_cls;
130 150
131 /** 151 /**
152 * Function to call on errors.
153 */
154 GNUNET_SCHEDULER_TaskCallback error_cb;
155
156 /**
157 * Closure for @e error_cb.
158 */
159 void *error_cb_cls;
160
161 /**
132 * Envelope of the message to send to the service, if not yet 162 * Envelope of the message to send to the service, if not yet
133 * sent. 163 * sent.
134 */ 164 */
@@ -543,9 +573,11 @@ handle_record_result (void *cls,
543 ntohl (msg->gns_header.r_id)); 573 ntohl (msg->gns_header.r_id));
544 qe = find_qe (h, 574 qe = find_qe (h,
545 ntohl (msg->gns_header.r_id)); 575 ntohl (msg->gns_header.r_id));
546 if ( (NULL == ze) && (NULL == qe) ) 576 if ( (NULL == ze) &&
577 (NULL == qe) )
547 return; /* rid not found */ 578 return; /* rid not found */
548 if ( (NULL != ze) && (NULL != qe) ) 579 if ( (NULL != ze) &&
580 (NULL != qe) )
549 { 581 {
550 GNUNET_break (0); /* rid ambigous */ 582 GNUNET_break (0); /* rid ambigous */
551 force_reconnect (h); 583 force_reconnect (h);
@@ -564,8 +596,8 @@ handle_record_result (void *cls,
564 force_reconnect (h); 596 force_reconnect (h);
565 return; 597 return;
566 } 598 }
567 if (NULL != ze->proc) 599 if (NULL != ze->finish_cb)
568 ze->proc (ze->proc_cls, NULL, NULL, 0, NULL); 600 ze->finish_cb (ze->finish_cb_cls);
569 free_ze (ze); 601 free_ze (ze);
570 return; 602 return;
571 } 603 }
@@ -706,7 +738,8 @@ handle_zone_to_name_response (void *cls,
706 qe->proc (qe->proc_cls, 738 qe->proc (qe->proc_cls,
707 &msg->zone, 739 &msg->zone,
708 name_tmp, 740 name_tmp,
709 rd_count, rd); 741 rd_count,
742 rd);
710 /* return is important here: break would call continuation with error! */ 743 /* return is important here: break would call continuation with error! */
711 free_qe (qe); 744 free_qe (qe);
712 return; 745 return;
@@ -717,8 +750,8 @@ handle_zone_to_name_response (void *cls,
717 return; 750 return;
718 } 751 }
719 /* error case, call continuation with error */ 752 /* error case, call continuation with error */
720 if (NULL != qe->proc) 753 if (NULL != qe->error_cb)
721 qe->proc (qe->proc_cls, NULL, NULL, 0, NULL); 754 qe->error_cb (qe->error_cb_cls);
722 free_qe (qe); 755 free_qe (qe);
723} 756}
724 757
@@ -826,18 +859,18 @@ force_reconnect (struct GNUNET_NAMESTORE_Handle *h)
826 h->mq = NULL; 859 h->mq = NULL;
827 while (NULL != (ze = h->z_head)) 860 while (NULL != (ze = h->z_head))
828 { 861 {
829 /* FIXME: This does not allow clients to distinguish 862 if (NULL != ze->error_cb)
830 iteration error from successful termination! */ 863 ze->error_cb (ze->error_cb_cls);
831 if (NULL != ze->proc)
832 ze->proc (ze->proc_cls, NULL, NULL, 0, NULL);
833 free_ze (ze); 864 free_ze (ze);
834 } 865 }
835 while (NULL != (qe = h->op_head)) 866 while (NULL != (qe = h->op_head))
836 { 867 {
837 /* FIXME: This does not allow clients to distinguish 868 if (NULL != qe->error_cb)
838 iteration error from successful termination! */ 869 qe->error_cb (qe->error_cb_cls);
839 if (NULL != qe->proc) 870 if (NULL != qe->cont)
840 qe->proc (qe->proc_cls, NULL, NULL, 0, NULL); 871 qe->cont (qe->cont_cls,
872 GNUNET_SYSERR,
873 "failure in communication with namestore service");
841 free_qe (qe); 874 free_qe (qe);
842 } 875 }
843 876
@@ -1058,6 +1091,8 @@ GNUNET_NAMESTORE_set_nick (struct GNUNET_NAMESTORE_Handle *h,
1058 * @param h handle to the namestore 1091 * @param h handle to the namestore
1059 * @param pkey private key of the zone 1092 * @param pkey private key of the zone
1060 * @param label name that is being mapped (at most 255 characters long) 1093 * @param label name that is being mapped (at most 255 characters long)
1094 * @param error_cb function to call on error (i.e. disconnect)
1095 * @param error_cb_cls closure for @a error_cb
1061 * @param rm function to call with the result (with 0 records if we don't have that label) 1096 * @param rm function to call with the result (with 0 records if we don't have that label)
1062 * @param rm_cls closure for @a rm 1097 * @param rm_cls closure for @a rm
1063 * @return handle to abort the request 1098 * @return handle to abort the request
@@ -1066,6 +1101,8 @@ struct GNUNET_NAMESTORE_QueueEntry *
1066GNUNET_NAMESTORE_records_lookup (struct GNUNET_NAMESTORE_Handle *h, 1101GNUNET_NAMESTORE_records_lookup (struct GNUNET_NAMESTORE_Handle *h,
1067 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, 1102 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
1068 const char *label, 1103 const char *label,
1104 GNUNET_SCHEDULER_TaskCallback error_cb,
1105 void *error_cb_cls,
1069 GNUNET_NAMESTORE_RecordMonitor rm, 1106 GNUNET_NAMESTORE_RecordMonitor rm,
1070 void *rm_cls) 1107 void *rm_cls)
1071{ 1108{
@@ -1082,6 +1119,8 @@ GNUNET_NAMESTORE_records_lookup (struct GNUNET_NAMESTORE_Handle *h,
1082 1119
1083 qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry); 1120 qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry);
1084 qe->h = h; 1121 qe->h = h;
1122 qe->error_cb = error_cb;
1123 qe->error_cb_cls = error_cb_cls;
1085 qe->proc = rm; 1124 qe->proc = rm;
1086 qe->proc_cls = rm_cls; 1125 qe->proc_cls = rm_cls;
1087 qe->op_id = get_op_id(h); 1126 qe->op_id = get_op_id(h);
@@ -1114,6 +1153,8 @@ GNUNET_NAMESTORE_records_lookup (struct GNUNET_NAMESTORE_Handle *h,
1114 * @param h handle to the namestore 1153 * @param h handle to the namestore
1115 * @param zone public key of the zone to look up in, never NULL 1154 * @param zone public key of the zone to look up in, never NULL
1116 * @param value_zone public key of the target zone (value), never NULL 1155 * @param value_zone public key of the target zone (value), never NULL
1156 * @param error_cb function to call on error (i.e. disconnect)
1157 * @param error_cb_cls closure for @a error_cb
1117 * @param proc function to call on the matching records, or with 1158 * @param proc function to call on the matching records, or with
1118 * NULL (rd_count == 0) if there are no matching records 1159 * NULL (rd_count == 0) if there are no matching records
1119 * @param proc_cls closure for @a proc 1160 * @param proc_cls closure for @a proc
@@ -1124,6 +1165,8 @@ struct GNUNET_NAMESTORE_QueueEntry *
1124GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h, 1165GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h,
1125 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 1166 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
1126 const struct GNUNET_CRYPTO_EcdsaPublicKey *value_zone, 1167 const struct GNUNET_CRYPTO_EcdsaPublicKey *value_zone,
1168 GNUNET_SCHEDULER_TaskCallback error_cb,
1169 void *error_cb_cls,
1127 GNUNET_NAMESTORE_RecordMonitor proc, 1170 GNUNET_NAMESTORE_RecordMonitor proc,
1128 void *proc_cls) 1171 void *proc_cls)
1129{ 1172{
@@ -1135,6 +1178,8 @@ GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h,
1135 rid = get_op_id(h); 1178 rid = get_op_id(h);
1136 qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry); 1179 qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry);
1137 qe->h = h; 1180 qe->h = h;
1181 qe->error_cb = error_cb;
1182 qe->error_cb_cls = error_cb_cls;
1138 qe->proc = proc; 1183 qe->proc = proc;
1139 qe->proc_cls = proc_cls; 1184 qe->proc_cls = proc_cls;
1140 qe->op_id = rid; 1185 qe->op_id = rid;
@@ -1166,26 +1211,39 @@ GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h,
1166 * 1211 *
1167 * @param h handle to the namestore 1212 * @param h handle to the namestore
1168 * @param zone zone to access, NULL for all zones 1213 * @param zone zone to access, NULL for all zones
1214 * @param error_cb function to call on error (i.e. disconnect)
1215 * @param error_cb_cls closure for @a error_cb
1169 * @param proc function to call on each name from the zone; it 1216 * @param proc function to call on each name from the zone; it
1170 * will be called repeatedly with a value (if available) 1217 * will be called repeatedly with a value (if available)
1171 * and always once at the end with a name of NULL.
1172 * @param proc_cls closure for @a proc 1218 * @param proc_cls closure for @a proc
1219 * @param finish_cb function to call on completion
1220 * @param finish_cb_cls closure for @a finish_cb
1173 * @return an iterator handle to use for iteration 1221 * @return an iterator handle to use for iteration
1174 */ 1222 */
1175struct GNUNET_NAMESTORE_ZoneIterator * 1223struct GNUNET_NAMESTORE_ZoneIterator *
1176GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h, 1224GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h,
1177 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 1225 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
1226 GNUNET_SCHEDULER_TaskCallback error_cb,
1227 void *error_cb_cls,
1178 GNUNET_NAMESTORE_RecordMonitor proc, 1228 GNUNET_NAMESTORE_RecordMonitor proc,
1179 void *proc_cls) 1229 void *proc_cls,
1230 GNUNET_SCHEDULER_TaskCallback finish_cb,
1231 void *finish_cb_cls)
1180{ 1232{
1181 struct GNUNET_NAMESTORE_ZoneIterator *it; 1233 struct GNUNET_NAMESTORE_ZoneIterator *it;
1182 struct GNUNET_MQ_Envelope *env; 1234 struct GNUNET_MQ_Envelope *env;
1183 struct ZoneIterationStartMessage *msg; 1235 struct ZoneIterationStartMessage *msg;
1184 uint32_t rid; 1236 uint32_t rid;
1185 1237
1238 LOG (GNUNET_ERROR_TYPE_DEBUG,
1239 "Sending ZONE_ITERATION_START message\n");
1186 rid = get_op_id (h); 1240 rid = get_op_id (h);
1187 it = GNUNET_new (struct GNUNET_NAMESTORE_ZoneIterator); 1241 it = GNUNET_new (struct GNUNET_NAMESTORE_ZoneIterator);
1188 it->h = h; 1242 it->h = h;
1243 it->error_cb = error_cb;
1244 it->error_cb_cls = error_cb_cls;
1245 it->finish_cb = finish_cb;
1246 it->finish_cb_cls = finish_cb_cls;
1189 it->proc = proc; 1247 it->proc = proc;
1190 it->proc_cls = proc_cls; 1248 it->proc_cls = proc_cls;
1191 it->op_id = rid; 1249 it->op_id = rid;
diff --git a/src/namestore/namestore_api_monitor.c b/src/namestore/namestore_api_monitor.c
index 85131f9cc..7e75b07e5 100644
--- a/src/namestore/namestore_api_monitor.c
+++ b/src/namestore/namestore_api_monitor.c
@@ -51,19 +51,34 @@ struct GNUNET_NAMESTORE_ZoneMonitor
51 struct GNUNET_MQ_Handle *mq; 51 struct GNUNET_MQ_Handle *mq;
52 52
53 /** 53 /**
54 * Function to call on errors.
55 */
56 GNUNET_SCHEDULER_TaskCallback error_cb;
57
58 /**
59 * Closure for @e error_cb.
60 */
61 void *error_cb_cls;
62
63 /**
54 * Function to call on events. 64 * Function to call on events.
55 */ 65 */
56 GNUNET_NAMESTORE_RecordMonitor monitor; 66 GNUNET_NAMESTORE_RecordMonitor monitor;
57 67
58 /** 68 /**
69 * Closure for @e monitor.
70 */
71 void *monitor_cls;
72
73 /**
59 * Function called when we've synchronized. 74 * Function called when we've synchronized.
60 */ 75 */
61 GNUNET_NAMESTORE_RecordsSynchronizedCallback sync_cb; 76 GNUNET_SCHEDULER_TaskCallback sync_cb;
62 77
63 /** 78 /**
64 * Closure for @e monitor and @e sync_cb. 79 * Closure for @e sync_cb.
65 */ 80 */
66 void *cls; 81 void *sync_cb_cls;
67 82
68 /** 83 /**
69 * Monitored zone. 84 * Monitored zone.
@@ -100,7 +115,7 @@ handle_sync (void *cls,
100 struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls; 115 struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls;
101 116
102 if (NULL != zm->sync_cb) 117 if (NULL != zm->sync_cb)
103 zm->sync_cb (zm->cls); 118 zm->sync_cb (zm->sync_cb_cls);
104} 119}
105 120
106 121
@@ -193,7 +208,7 @@ handle_result (void *cls,
193 rd_ser_tmp, 208 rd_ser_tmp,
194 rd_count, 209 rd_count,
195 rd)); 210 rd));
196 zm->monitor (zm->cls, 211 zm->monitor (zm->monitor_cls,
197 &lrm->private_key, 212 &lrm->private_key,
198 name_tmp, 213 name_tmp,
199 rd_count, 214 rd_count,
@@ -245,11 +260,7 @@ reconnect (struct GNUNET_NAMESTORE_ZoneMonitor *zm)
245 if (NULL != zm->mq) 260 if (NULL != zm->mq)
246 { 261 {
247 GNUNET_MQ_destroy (zm->mq); 262 GNUNET_MQ_destroy (zm->mq);
248 zm->monitor (zm->cls, 263 zm->error_cb (zm->error_cb_cls);
249 NULL,
250 NULL,
251 0,
252 NULL);
253 } 264 }
254 zm->mq = GNUNET_CLIENT_connecT (zm->cfg, 265 zm->mq = GNUNET_CLIENT_connecT (zm->cfg,
255 "namestore", 266 "namestore",
@@ -278,18 +289,28 @@ reconnect (struct GNUNET_NAMESTORE_ZoneMonitor *zm)
278 * @param zone zone to monitor 289 * @param zone zone to monitor
279 * @param iterate_first #GNUNET_YES to first iterate over all existing records, 290 * @param iterate_first #GNUNET_YES to first iterate over all existing records,
280 * #GNUNET_NO to only return changes that happen from now on 291 * #GNUNET_NO to only return changes that happen from now on
292 * @param error_cb function to call on error (i.e. disconnect); note that
293 * unlike the other error callbacks in this API, a call to this
294 * function does NOT destroy the monitor handle, it merely signals
295 * that monitoring is down. You need to still explicitly call
296 * #GNUNET_NAMESTORE_zone_monitor_stop().
297 * @param error_cb_cls closure for @a error_cb
281 * @param monitor function to call on zone changes 298 * @param monitor function to call on zone changes
299 * @param monitor_cls closure for @a monitor
282 * @param sync_cb function called when we're in sync with the namestore 300 * @param sync_cb function called when we're in sync with the namestore
283 * @param cls closure for @a monitor and @a sync_cb 301 * @param cls closure for @a sync_cb
284 * @return handle to stop monitoring 302 * @return handle to stop monitoring
285 */ 303 */
286struct GNUNET_NAMESTORE_ZoneMonitor * 304struct GNUNET_NAMESTORE_ZoneMonitor *
287GNUNET_NAMESTORE_zone_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg, 305GNUNET_NAMESTORE_zone_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
288 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 306 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
289 int iterate_first, 307 int iterate_first,
308 GNUNET_SCHEDULER_TaskCallback error_cb,
309 void *error_cb_cls,
290 GNUNET_NAMESTORE_RecordMonitor monitor, 310 GNUNET_NAMESTORE_RecordMonitor monitor,
291 GNUNET_NAMESTORE_RecordsSynchronizedCallback sync_cb, 311 void *monitor_cls,
292 void *cls) 312 GNUNET_SCHEDULER_TaskCallback sync_cb,
313 void *sync_cb_cls)
293{ 314{
294 struct GNUNET_NAMESTORE_ZoneMonitor *zm; 315 struct GNUNET_NAMESTORE_ZoneMonitor *zm;
295 316
@@ -297,9 +318,12 @@ GNUNET_NAMESTORE_zone_monitor_start (const struct GNUNET_CONFIGURATION_Handle *c
297 if (NULL != zone) 318 if (NULL != zone)
298 zm->zone = *zone; 319 zm->zone = *zone;
299 zm->iterate_first = iterate_first; 320 zm->iterate_first = iterate_first;
321 zm->error_cb = error_cb;
322 zm->error_cb_cls = error_cb_cls;
300 zm->monitor = monitor; 323 zm->monitor = monitor;
324 zm->monitor_cls = monitor_cls;
301 zm->sync_cb = sync_cb; 325 zm->sync_cb = sync_cb;
302 zm->cls = cls; 326 zm->sync_cb_cls = sync_cb_cls;
303 zm->cfg = cfg; 327 zm->cfg = cfg;
304 reconnect (zm); 328 reconnect (zm);
305 if (NULL == zm->mq) 329 if (NULL == zm->mq)
diff --git a/src/namestore/plugin_rest_namestore.c b/src/namestore/plugin_rest_namestore.c
index 35d3595ce..58ab46ca9 100644
--- a/src/namestore/plugin_rest_namestore.c
+++ b/src/namestore/plugin_rest_namestore.c
@@ -388,6 +388,38 @@ cleanup_handle_delayed (void *cls)
388 388
389 389
390/** 390/**
391 * Iteration over all results finished, build final
392 * response.
393 *
394 * @param cls the `struct RequestHandle`
395 */
396static void
397namestore_list_finished (void *cls)
398{
399 struct RequestHandle *handle = cls;
400 char *result;
401 struct MHD_Response *resp;
402
403 handle->list_it = NULL;
404 if (GNUNET_SYSERR ==
405 GNUNET_JSONAPI_document_serialize (handle->resp_object,
406 &result))
407 {
408 do_error (handle);
409 return;
410 }
411 resp = GNUNET_REST_create_response (result);
412 handle->proc (handle->proc_cls,
413 resp,
414 MHD_HTTP_OK);
415 GNUNET_free_non_null (result);
416 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed,
417 handle);
418}
419
420
421
422/**
391 * Create a response with requested records 423 * Create a response with requested records
392 * 424 *
393 * @param handle the RequestHandle 425 * @param handle the RequestHandle
@@ -401,31 +433,13 @@ namestore_list_response (void *cls,
401{ 433{
402 struct RequestHandle *handle = cls; 434 struct RequestHandle *handle = cls;
403 struct GNUNET_JSONAPI_Resource *json_resource; 435 struct GNUNET_JSONAPI_Resource *json_resource;
404 struct MHD_Response *resp;
405 json_t *result_array; 436 json_t *result_array;
406 json_t *record_obj; 437 json_t *record_obj;
407 int i; 438 int i;
408 char *result;
409 439
410 if (NULL == handle->resp_object) 440 if (NULL == handle->resp_object)
411 handle->resp_object = GNUNET_JSONAPI_document_new (); 441 handle->resp_object = GNUNET_JSONAPI_document_new ();
412 442
413 if (NULL == rname)
414 {
415 handle->list_it = NULL;
416 //Handle response
417 if (GNUNET_SYSERR == GNUNET_JSONAPI_document_serialize (handle->resp_object, &result))
418 {
419 GNUNET_SCHEDULER_add_now (&do_error, handle);
420 return;
421 }
422 resp = GNUNET_REST_create_response (result);
423 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
424 GNUNET_free_non_null (result);
425 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
426 return;
427 }
428
429 if ( (NULL != handle->name) && 443 if ( (NULL != handle->name) &&
430 (0 != strcmp (handle->name, rname)) ) 444 (0 != strcmp (handle->name, rname)) )
431 { 445 {
@@ -464,6 +478,7 @@ namestore_list_response (void *cls,
464 GNUNET_NAMESTORE_zone_iterator_next (handle->list_it); 478 GNUNET_NAMESTORE_zone_iterator_next (handle->list_it);
465} 479}
466 480
481
467static void 482static void
468create_finished (void *cls, int32_t success, const char *emsg) 483create_finished (void *cls, int32_t success, const char *emsg)
469{ 484{
@@ -506,11 +521,10 @@ create_new_record_cont (void *cls,
506 struct RequestHandle *handle = cls; 521 struct RequestHandle *handle = cls;
507 522
508 handle->add_qe = NULL; 523 handle->add_qe = NULL;
509 if ( (NULL != zone_key) && 524 if (0 != strcmp (rec_name, handle->name))
510 (0 != strcmp (rec_name, handle->name)) )
511 { 525 {
512 GNUNET_break (0); 526 GNUNET_break (0);
513 GNUNET_SCHEDULER_add_now (&do_error, handle); 527 do_error (handle);
514 return; 528 return;
515 } 529 }
516 530
@@ -533,6 +547,7 @@ create_new_record_cont (void *cls,
533 handle); 547 handle);
534} 548}
535 549
550
536static void 551static void
537del_finished (void *cls, 552del_finished (void *cls,
538 int32_t success, 553 int32_t success,
@@ -565,6 +580,7 @@ del_finished (void *cls,
565 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle); 580 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
566} 581}
567 582
583
568static void 584static void
569del_cont (void *cls, 585del_cont (void *cls,
570 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 586 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
@@ -573,13 +589,14 @@ del_cont (void *cls,
573 const struct GNUNET_GNSRECORD_Data *rd) 589 const struct GNUNET_GNSRECORD_Data *rd)
574{ 590{
575 struct RequestHandle *handle = cls; 591 struct RequestHandle *handle = cls;
592
576 handle->add_qe = NULL; 593 handle->add_qe = NULL;
577 if (0 == rd_count) 594 if (0 == rd_count)
578 { 595 {
579 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 596 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
580 _("There are no records under label `%s' that could be deleted.\n"), 597 _("There are no records under label `%s' that could be deleted.\n"),
581 label); 598 label);
582 GNUNET_SCHEDULER_add_now (&do_error, handle); 599 do_error (handle);
583 return; 600 return;
584 } 601 }
585 602
@@ -591,6 +608,7 @@ del_cont (void *cls,
591 handle); 608 handle);
592} 609}
593 610
611
594static void 612static void
595namestore_delete_cont (struct GNUNET_REST_RequestHandle *con, 613namestore_delete_cont (struct GNUNET_REST_RequestHandle *con,
596 const char *url, 614 const char *url,
@@ -607,10 +625,13 @@ namestore_delete_cont (struct GNUNET_REST_RequestHandle *con,
607 handle->add_qe = GNUNET_NAMESTORE_records_lookup (handle->ns_handle, 625 handle->add_qe = GNUNET_NAMESTORE_records_lookup (handle->ns_handle,
608 &handle->zone_pkey, 626 &handle->zone_pkey,
609 handle->name, 627 handle->name,
628 &do_error,
629 handle,
610 &del_cont, 630 &del_cont,
611 handle); 631 handle);
612} 632}
613 633
634
614static int 635static int
615json_to_gnsrecord (const json_t *records_json, 636json_to_gnsrecord (const json_t *records_json,
616 struct GNUNET_GNSRECORD_Data **rd, 637 struct GNUNET_GNSRECORD_Data **rd,
@@ -713,6 +734,7 @@ json_to_gnsrecord (const json_t *records_json,
713 return GNUNET_OK; 734 return GNUNET_OK;
714} 735}
715 736
737
716static void 738static void
717namestore_create_cont (struct GNUNET_REST_RequestHandle *con, 739namestore_create_cont (struct GNUNET_REST_RequestHandle *con,
718 const char *url, 740 const char *url,
@@ -730,7 +752,7 @@ namestore_create_cont (struct GNUNET_REST_RequestHandle *con,
730 GNUNET_JSON_spec_jsonapi_document (&json_obj), 752 GNUNET_JSON_spec_jsonapi_document (&json_obj),
731 GNUNET_JSON_spec_end() 753 GNUNET_JSON_spec_end()
732 }; 754 };
733 755
734 if (strlen (GNUNET_REST_API_NS_NAMESTORE) != strlen (handle->url)) 756 if (strlen (GNUNET_REST_API_NS_NAMESTORE) != strlen (handle->url))
735 { 757 {
736 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 758 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -805,9 +827,13 @@ namestore_create_cont (struct GNUNET_REST_RequestHandle *con,
805 handle->add_qe = GNUNET_NAMESTORE_records_lookup (handle->ns_handle, 827 handle->add_qe = GNUNET_NAMESTORE_records_lookup (handle->ns_handle,
806 &handle->zone_pkey, 828 &handle->zone_pkey,
807 handle->name, 829 handle->name,
808 &create_new_record_cont, handle ); 830 &do_error,
831 handle,
832 &create_new_record_cont,
833 handle);
809} 834}
810 835
836
811static void 837static void
812namestore_zkey_response (void *cls, 838namestore_zkey_response (void *cls,
813 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 839 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
@@ -847,10 +873,9 @@ namestore_zkey_response (void *cls,
847 GNUNET_JSONAPI_document_delete (json_obj); 873 GNUNET_JSONAPI_document_delete (json_obj);
848 GNUNET_free (result); 874 GNUNET_free (result);
849 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle); 875 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
850 return;
851
852} 876}
853 877
878
854static void 879static void
855namestore_zkey_cont (struct GNUNET_REST_RequestHandle *con, 880namestore_zkey_cont (struct GNUNET_REST_RequestHandle *con,
856 const char *url, 881 const char *url,
@@ -887,22 +912,31 @@ namestore_zkey_cont (struct GNUNET_REST_RequestHandle *con,
887 handle->reverse_qe = GNUNET_NAMESTORE_zone_to_name (handle->ns_handle, 912 handle->reverse_qe = GNUNET_NAMESTORE_zone_to_name (handle->ns_handle,
888 &handle->zone_pkey, 913 &handle->zone_pkey,
889 &pubkey, 914 &pubkey,
915 &do_error,
916 handle,
890 &namestore_zkey_response, 917 &namestore_zkey_response,
891 handle); 918 handle);
892} 919}
893 920
921
894static void 922static void
895namestore_info_cont (struct GNUNET_REST_RequestHandle *con, 923namestore_info_cont (struct GNUNET_REST_RequestHandle *con,
896 const char *url, 924 const char *url,
897 void *cls) 925 void *cls)
898{ 926{
899 struct RequestHandle *handle = cls; 927 struct RequestHandle *handle = cls;
928
900 handle->list_it = GNUNET_NAMESTORE_zone_iteration_start (handle->ns_handle, 929 handle->list_it = GNUNET_NAMESTORE_zone_iteration_start (handle->ns_handle,
901 &handle->zone_pkey, 930 &handle->zone_pkey,
931 &do_error,
932 handle,
902 &namestore_list_response, 933 &namestore_list_response,
934 handle,
935 &namestore_list_finished,
903 handle); 936 handle);
904} 937}
905 938
939
906static char* 940static char*
907get_name_from_url (const char* url) 941get_name_from_url (const char* url)
908{ 942{
diff --git a/src/namestore/test_namestore_api.conf b/src/namestore/test_namestore_api.conf
index 5db120ea7..a1a674d89 100644
--- a/src/namestore/test_namestore_api.conf
+++ b/src/namestore/test_namestore_api.conf
@@ -13,3 +13,6 @@ TEMPORARY_TABLE = YES
13 13
14[nse] 14[nse]
15WORKBITS = 0 15WORKBITS = 0
16
17[transport]
18PLUGINS =
diff --git a/src/namestore/test_namestore_api_lookup_nick.c b/src/namestore/test_namestore_api_lookup_nick.c
index d6d3945b7..de958cee2 100644
--- a/src/namestore/test_namestore_api_lookup_nick.c
+++ b/src/namestore/test_namestore_api_lookup_nick.c
@@ -222,6 +222,13 @@ lookup_it (void *cls,
222 222
223 223
224static void 224static void
225fail_cb (void *cls)
226{
227 GNUNET_assert (0);
228}
229
230
231static void
225put_cont (void *cls, int32_t success, const char *emsg) 232put_cont (void *cls, int32_t success, const char *emsg)
226{ 233{
227 const char *name = cls; 234 const char *name = cls;
@@ -240,9 +247,16 @@ put_cont (void *cls, int32_t success, const char *emsg)
240 return; 247 return;
241 } 248 }
242 /* Lookup */ 249 /* Lookup */
243 nsqe = GNUNET_NAMESTORE_records_lookup (nsh, privkey, name, lookup_it, NULL); 250 nsqe = GNUNET_NAMESTORE_records_lookup (nsh,
251 privkey,
252 name,
253 &fail_cb,
254 NULL,
255 &lookup_it,
256 NULL);
244} 257}
245 258
259
246static void 260static void
247nick_cont (void *cls, int32_t success, const char *emsg) 261nick_cont (void *cls, int32_t success, const char *emsg)
248{ 262{
diff --git a/src/namestore/test_namestore_api_lookup_private.c b/src/namestore/test_namestore_api_lookup_private.c
index 92b2cad6f..57505c48b 100644
--- a/src/namestore/test_namestore_api_lookup_private.c
+++ b/src/namestore/test_namestore_api_lookup_private.c
@@ -103,7 +103,9 @@ lookup_it (void *cls,
103{ 103{
104 nsqe = NULL; 104 nsqe = NULL;
105 105
106 if (0 != memcmp(privkey, zone, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) 106 if (0 != memcmp (privkey,
107 zone,
108 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
107 { 109 {
108 GNUNET_break(0); 110 GNUNET_break(0);
109 GNUNET_SCHEDULER_cancel (endbadly_task); 111 GNUNET_SCHEDULER_cancel (endbadly_task);
@@ -144,6 +146,13 @@ lookup_it (void *cls,
144 146
145 147
146static void 148static void
149fail_cb (void *cls)
150{
151 GNUNET_assert (0);
152}
153
154
155static void
147put_cont (void *cls, int32_t success, const char *emsg) 156put_cont (void *cls, int32_t success, const char *emsg)
148{ 157{
149 const char *name = cls; 158 const char *name = cls;
@@ -162,7 +171,13 @@ put_cont (void *cls, int32_t success, const char *emsg)
162 return; 171 return;
163 } 172 }
164 /* Lookup */ 173 /* Lookup */
165 nsqe = GNUNET_NAMESTORE_records_lookup (nsh, privkey, name, lookup_it, NULL); 174 nsqe = GNUNET_NAMESTORE_records_lookup (nsh,
175 privkey,
176 name,
177 &fail_cb,
178 NULL,
179 &lookup_it,
180 NULL);
166} 181}
167 182
168 183
diff --git a/src/namestore/test_namestore_api_monitoring.c b/src/namestore/test_namestore_api_monitoring.c
index 2ea271d50..efbd6badf 100644
--- a/src/namestore/test_namestore_api_monitoring.c
+++ b/src/namestore/test_namestore_api_monitoring.c
@@ -215,11 +215,11 @@ put_cont (void *cls, int32_t success, const char *emsg)
215 char *label = cls; 215 char *label = cls;
216 216
217 if (0 == strcmp (label, s_name_1)) 217 if (0 == strcmp (label, s_name_1))
218 ns_ops[0] = NULL; 218 ns_ops[0] = NULL;
219 else if (0 == strcmp (label, s_name_2)) 219 else if (0 == strcmp (label, s_name_2))
220 ns_ops[1] = NULL; 220 ns_ops[1] = NULL;
221 else if (0 == strcmp (label, s_name_3)) 221 else if (0 == strcmp (label, s_name_3))
222 ns_ops[2] = NULL; 222 ns_ops[2] = NULL;
223 223
224 if (success == GNUNET_OK) 224 if (success == GNUNET_OK)
225 { 225 {
@@ -261,6 +261,20 @@ create_record (unsigned int count)
261 261
262 262
263static void 263static void
264fail_cb (void *cls)
265{
266 GNUNET_assert (0);
267}
268
269
270static void
271sync_cb (void *cls)
272{
273 /* do nothing */
274}
275
276
277static void
264run (void *cls, 278run (void *cls,
265 const struct GNUNET_CONFIGURATION_Handle *cfg, 279 const struct GNUNET_CONFIGURATION_Handle *cfg,
266 struct GNUNET_TESTING_Peer *peer) 280 struct GNUNET_TESTING_Peer *peer)
@@ -288,8 +302,11 @@ run (void *cls,
288 zm = GNUNET_NAMESTORE_zone_monitor_start (cfg, 302 zm = GNUNET_NAMESTORE_zone_monitor_start (cfg,
289 privkey, 303 privkey,
290 GNUNET_YES, 304 GNUNET_YES,
305 &fail_cb,
306 NULL,
291 &zone_proc, 307 &zone_proc,
292 NULL, 308 NULL,
309 &sync_cb,
293 NULL); 310 NULL);
294 if (NULL == zm) 311 if (NULL == zm)
295 { 312 {
diff --git a/src/namestore/test_namestore_api_monitoring_existing.c b/src/namestore/test_namestore_api_monitoring_existing.c
index eae10e2ae..cd1838b5c 100644
--- a/src/namestore/test_namestore_api_monitoring_existing.c
+++ b/src/namestore/test_namestore_api_monitoring_existing.c
@@ -59,6 +59,7 @@ struct GNUNET_NAMESTORE_QueueEntry * ns_ops[3];
59 59
60static char *directory; 60static char *directory;
61 61
62
62static void 63static void
63do_shutdown () 64do_shutdown ()
64{ 65{
@@ -204,7 +205,20 @@ zone_proc (void *cls,
204 else 205 else
205 GNUNET_SCHEDULER_add_now (&end, NULL); 206 GNUNET_SCHEDULER_add_now (&end, NULL);
206 } 207 }
208}
209
207 210
211static void
212fail_cb (void *cls)
213{
214 GNUNET_assert (0);
215}
216
217
218static void
219sync_cb (void *cls)
220{
221 /* do nothing */
208} 222}
209 223
210 224
@@ -240,8 +254,11 @@ put_cont (void *cls, int32_t success, const char *emsg)
240 zm = GNUNET_NAMESTORE_zone_monitor_start (cfg, 254 zm = GNUNET_NAMESTORE_zone_monitor_start (cfg,
241 privkey, 255 privkey,
242 GNUNET_YES, 256 GNUNET_YES,
257 &fail_cb,
258 NULL,
243 &zone_proc, 259 &zone_proc,
244 NULL, 260 NULL,
261 &sync_cb,
245 NULL); 262 NULL);
246 if (NULL == zm) 263 if (NULL == zm)
247 { 264 {
diff --git a/src/namestore/test_namestore_api_zone_iteration.c b/src/namestore/test_namestore_api_zone_iteration.c
index 070c06870..8960be55d 100644
--- a/src/namestore/test_namestore_api_zone_iteration.c
+++ b/src/namestore/test_namestore_api_zone_iteration.c
@@ -156,6 +156,32 @@ end (void *cls)
156 156
157 157
158static void 158static void
159zone_end (void *cls)
160{
161 GNUNET_break (3 == returned_records);
162 if (3 == returned_records)
163 {
164 res = 0; /* Last iteraterator callback, we are done */
165 zi = NULL;
166 }
167 else
168 res = 1;
169
170 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
171 "Received last result, iteration done after receing %u results\n",
172 returned_records);
173 GNUNET_SCHEDULER_add_now (&end, NULL);
174}
175
176
177static void
178fail_cb (void *cls)
179{
180 GNUNET_assert (0);
181}
182
183
184static void
159zone_proc (void *cls, 185zone_proc (void *cls,
160 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 186 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
161 const char *label, 187 const char *label,
@@ -164,23 +190,6 @@ zone_proc (void *cls,
164{ 190{
165 int failed = GNUNET_NO; 191 int failed = GNUNET_NO;
166 192
167 if ((zone == NULL) && (label == NULL))
168 {
169 GNUNET_break (3 == returned_records);
170 if (3 == returned_records)
171 {
172 res = 0; /* Last iteraterator callback, we are done */
173 zi = NULL;
174 }
175 else
176 res = 1;
177
178 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
179 "Received last result, iteration done after receing %u results\n",
180 returned_records);
181 GNUNET_SCHEDULER_add_now (&end, NULL);
182 return;
183 }
184 GNUNET_assert (NULL != zone); 193 GNUNET_assert (NULL != zone);
185 if (0 == memcmp (zone, privkey, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) 194 if (0 == memcmp (zone, privkey, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
186 { 195 {
@@ -305,7 +314,11 @@ put_cont (void *cls, int32_t success, const char *emsg)
305 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All records created, starting iteration over all zones \n"); 314 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All records created, starting iteration over all zones \n");
306 zi = GNUNET_NAMESTORE_zone_iteration_start (nsh, 315 zi = GNUNET_NAMESTORE_zone_iteration_start (nsh,
307 NULL, 316 NULL,
317 &fail_cb,
318 NULL,
308 &zone_proc, 319 &zone_proc,
320 NULL,
321 &zone_end,
309 NULL); 322 NULL);
310 if (zi == NULL) 323 if (zi == NULL)
311 { 324 {
@@ -352,8 +365,6 @@ empty_zone_proc (void *cls,
352 unsigned int rd_count, 365 unsigned int rd_count,
353 const struct GNUNET_GNSRECORD_Data *rd) 366 const struct GNUNET_GNSRECORD_Data *rd)
354{ 367{
355 char *hostkey_file;
356
357 GNUNET_assert (nsh == cls); 368 GNUNET_assert (nsh == cls);
358 if (NULL != zone) 369 if (NULL != zone)
359 { 370 {
@@ -375,18 +386,31 @@ empty_zone_proc (void *cls,
375 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); 386 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
376 return; 387 return;
377 } 388 }
389 GNUNET_assert (0);
390}
378 391
379 392
393static void
394empty_zone_end (void *cls)
395{
396 char *hostkey_file;
397
380 zi = NULL; 398 zi = NULL;
381 GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR, 399 GNUNET_asprintf (&hostkey_file,
382 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); 400 "zonefiles%s%s",
383 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); 401 DIR_SEPARATOR_STR,
402 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
403 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
404 "Using zonekey file `%s' \n",
405 hostkey_file);
384 privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file); 406 privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
385 GNUNET_free (hostkey_file); 407 GNUNET_free (hostkey_file);
386 GNUNET_assert (privkey != NULL); 408 GNUNET_assert (privkey != NULL);
387 409
388 GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR, 410 GNUNET_asprintf (&hostkey_file,
389 "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey"); 411 "zonefiles%s%s",
412 DIR_SEPARATOR_STR,
413 "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
390 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); 414 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
391 privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file); 415 privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
392 GNUNET_free (hostkey_file); 416 GNUNET_free (hostkey_file);
@@ -396,7 +420,9 @@ empty_zone_proc (void *cls,
396 420
397 GNUNET_asprintf(&s_name_1, "dummy1"); 421 GNUNET_asprintf(&s_name_1, "dummy1");
398 s_rd_1 = create_record(1); 422 s_rd_1 = create_record(1);
399 GNUNET_NAMESTORE_records_store (nsh, privkey, s_name_1, 423 GNUNET_NAMESTORE_records_store (nsh,
424 privkey,
425 s_name_1,
400 1, s_rd_1, 426 1, s_rd_1,
401 &put_cont, NULL); 427 &put_cont, NULL);
402 428
@@ -404,8 +430,12 @@ empty_zone_proc (void *cls,
404 "Created record 2 \n"); 430 "Created record 2 \n");
405 GNUNET_asprintf(&s_name_2, "dummy2"); 431 GNUNET_asprintf(&s_name_2, "dummy2");
406 s_rd_2 = create_record(1); 432 s_rd_2 = create_record(1);
407 GNUNET_NAMESTORE_records_store (nsh, privkey, s_name_2, 433 GNUNET_NAMESTORE_records_store (nsh,
408 1, s_rd_2, &put_cont, NULL); 434 privkey,
435 s_name_2,
436 1, s_rd_2,
437 &put_cont,
438 NULL);
409 439
410 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 440 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
411 "Created record 3\n"); 441 "Created record 3\n");
@@ -436,7 +466,13 @@ run (void *cls,
436 GNUNET_break (NULL != nsh); 466 GNUNET_break (NULL != nsh);
437 /* first, iterate over empty namestore */ 467 /* first, iterate over empty namestore */
438 zi = GNUNET_NAMESTORE_zone_iteration_start(nsh, 468 zi = GNUNET_NAMESTORE_zone_iteration_start(nsh,
439 NULL, &empty_zone_proc, nsh); 469 NULL,
470 &fail_cb,
471 NULL,
472 &empty_zone_proc,
473 nsh,
474 &empty_zone_end,
475 NULL);
440 if (NULL == zi) 476 if (NULL == zi)
441 { 477 {
442 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone iterator\n"); 478 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone iterator\n");
diff --git a/src/namestore/test_namestore_api_zone_iteration_nick.c b/src/namestore/test_namestore_api_zone_iteration_nick.c
index 362533ef9..791702f97 100644
--- a/src/namestore/test_namestore_api_zone_iteration_nick.c
+++ b/src/namestore/test_namestore_api_zone_iteration_nick.c
@@ -199,6 +199,18 @@ check_zone_2 (const char *label,
199 199
200 200
201static void 201static void
202zone_proc_end (void *cls)
203{
204 zi = NULL;
205 res = 0;
206 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
207 "Received last result, iteration done after receing %u results\n",
208 returned_records);
209 GNUNET_SCHEDULER_add_now (&end, NULL);
210}
211
212
213static void
202zone_proc (void *cls, 214zone_proc (void *cls,
203 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 215 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
204 const char *label, 216 const char *label,
@@ -206,16 +218,7 @@ zone_proc (void *cls,
206 const struct GNUNET_GNSRECORD_Data *rd) 218 const struct GNUNET_GNSRECORD_Data *rd)
207{ 219{
208 int failed = GNUNET_NO; 220 int failed = GNUNET_NO;
209 if ((zone == NULL) && (label == NULL)) 221
210 {
211 zi = NULL;
212 res = 0;
213 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
214 "Received last result, iteration done after receing %u results\n",
215 returned_records);
216 GNUNET_SCHEDULER_add_now (&end, NULL);
217 return;
218 }
219 GNUNET_assert (NULL != zone); 222 GNUNET_assert (NULL != zone);
220 if (0 == memcmp (zone, privkey, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) 223 if (0 == memcmp (zone, privkey, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
221 { 224 {
@@ -254,6 +257,13 @@ zone_proc (void *cls,
254 257
255 258
256static void 259static void
260fail_cb (void *cls)
261{
262 GNUNET_assert (0);
263}
264
265
266static void
257put_cont (void *cls, int32_t success, const char *emsg) 267put_cont (void *cls, int32_t success, const char *emsg)
258{ 268{
259 static int c = 0; 269 static int c = 0;
@@ -281,7 +291,11 @@ put_cont (void *cls, int32_t success, const char *emsg)
281 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All records created, starting iteration over all zones \n"); 291 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All records created, starting iteration over all zones \n");
282 zi = GNUNET_NAMESTORE_zone_iteration_start (nsh, 292 zi = GNUNET_NAMESTORE_zone_iteration_start (nsh,
283 NULL, 293 NULL,
294 &fail_cb,
295 NULL,
284 &zone_proc, 296 &zone_proc,
297 NULL,
298 &zone_proc_end,
285 NULL); 299 NULL);
286 if (zi == NULL) 300 if (zi == NULL)
287 { 301 {
@@ -378,8 +392,8 @@ empty_zone_proc (void *cls,
378 unsigned int rd_count, 392 unsigned int rd_count,
379 const struct GNUNET_GNSRECORD_Data *rd) 393 const struct GNUNET_GNSRECORD_Data *rd)
380{ 394{
381 char *hostkey_file;
382 GNUNET_assert (nsh == cls); 395 GNUNET_assert (nsh == cls);
396
383 if (NULL != zone) 397 if (NULL != zone)
384 { 398 {
385 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 399 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -400,6 +414,15 @@ empty_zone_proc (void *cls,
400 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); 414 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
401 return; 415 return;
402 } 416 }
417 GNUNET_assert (0);
418}
419
420
421static void
422empty_zone_end (void *cls)
423{
424 char *hostkey_file;
425 GNUNET_assert (nsh == cls);
403 426
404 zi = NULL; 427 zi = NULL;
405 GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR, 428 GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR,
@@ -445,7 +468,13 @@ run (void *cls,
445 468
446 /* first, iterate over empty namestore */ 469 /* first, iterate over empty namestore */
447 zi = GNUNET_NAMESTORE_zone_iteration_start(nsh, 470 zi = GNUNET_NAMESTORE_zone_iteration_start(nsh,
448 NULL, &empty_zone_proc, nsh); 471 NULL,
472 &fail_cb,
473 NULL,
474 &empty_zone_proc,
475 nsh,
476 &empty_zone_end,
477 nsh);
449 if (NULL == zi) 478 if (NULL == zi)
450 { 479 {
451 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 480 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
diff --git a/src/namestore/test_namestore_api_zone_iteration_specific_zone.c b/src/namestore/test_namestore_api_zone_iteration_specific_zone.c
index 1a0279f50..c5ae927b0 100644
--- a/src/namestore/test_namestore_api_zone_iteration_specific_zone.c
+++ b/src/namestore/test_namestore_api_zone_iteration_specific_zone.c
@@ -156,30 +156,21 @@ end (void *cls)
156 156
157 157
158static void 158static void
159fail_cb (void *cls)
160{
161 GNUNET_assert (0);
162}
163
164
165static void
159zone_proc (void *cls, 166zone_proc (void *cls,
160 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 167 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
161 const char *label, 168 const char *label,
162 unsigned int rd_count, 169 unsigned int rd_count,
163 const struct GNUNET_GNSRECORD_Data *rd) 170 const struct GNUNET_GNSRECORD_Data *rd)
164{ 171{
165 int failed = GNUNET_NO; 172 int failed = GNUNET_NO;
166 if ((zone == NULL) && (label == NULL))
167 {
168 GNUNET_break (2 == returned_records);
169 if (2 == returned_records)
170 {
171 res = 0; /* Last iteraterator callback, we are done */
172 zi = NULL;
173 }
174 else
175 res = 1;
176 173
177 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
178 "Received last result, iteration done after receing %u results\n",
179 returned_records );
180 GNUNET_SCHEDULER_add_now (&end, NULL);
181 return;
182 }
183 GNUNET_assert (NULL != zone); 174 GNUNET_assert (NULL != zone);
184 if (0 == memcmp (zone, 175 if (0 == memcmp (zone,
185 privkey, 176 privkey,
@@ -258,6 +249,25 @@ zone_proc (void *cls,
258 249
259 250
260static void 251static void
252zone_proc_end (void *cls)
253{
254 GNUNET_break (2 == returned_records);
255 if (2 == returned_records)
256 {
257 res = 0; /* Last iteraterator callback, we are done */
258 zi = NULL;
259 }
260 else
261 res = 1;
262
263 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
264 "Received last result, iteration done after receing %u results\n",
265 returned_records);
266 GNUNET_SCHEDULER_add_now (&end, NULL);
267}
268
269
270static void
261put_cont (void *cls, int32_t success, const char *emsg) 271put_cont (void *cls, int32_t success, const char *emsg)
262{ 272{
263 static int c = 0; 273 static int c = 0;
@@ -288,8 +298,12 @@ put_cont (void *cls, int32_t success, const char *emsg)
288 "All records created, starting iteration over all zones \n"); 298 "All records created, starting iteration over all zones \n");
289 zi = GNUNET_NAMESTORE_zone_iteration_start(nsh, 299 zi = GNUNET_NAMESTORE_zone_iteration_start(nsh,
290 privkey, 300 privkey,
301 &fail_cb,
302 NULL,
291 &zone_proc, 303 &zone_proc,
292 NULL); 304 NULL,
305 &zone_proc_end,
306 NULL);
293 if (zi == NULL) 307 if (zi == NULL)
294 { 308 {
295 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 309 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -336,42 +350,55 @@ empty_zone_proc (void *cls,
336 unsigned int rd_count, 350 unsigned int rd_count,
337 const struct GNUNET_GNSRECORD_Data *rd) 351 const struct GNUNET_GNSRECORD_Data *rd)
338{ 352{
339 char *hostkey_file;
340
341 GNUNET_assert (nsh == cls); 353 GNUNET_assert (nsh == cls);
342 if (NULL != zone) 354 if (NULL != zone)
343 { 355 {
344 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 356 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
345 _("Expected empty zone but received zone private key\n")); 357 _("Expected empty zone but received zone private key\n"));
346 GNUNET_break (0); 358 GNUNET_break (0);
347 if (endbadly_task != NULL) 359 if (endbadly_task != NULL)
348 GNUNET_SCHEDULER_cancel (endbadly_task); 360 GNUNET_SCHEDULER_cancel (endbadly_task);
349 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); 361 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
350 return; 362 return;
351 } 363 }
352 if ((NULL != label) || (NULL != rd) || (0 != rd_count)) 364 if ((NULL != label) || (NULL != rd) || (0 != rd_count))
353 { 365 {
354 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 366 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
355 _("Expected no zone content but received data\n")); 367 _("Expected no zone content but received data\n"));
356 GNUNET_break (0); 368 GNUNET_break (0);
357 if (endbadly_task != NULL) 369 if (endbadly_task != NULL)
358 GNUNET_SCHEDULER_cancel (endbadly_task); 370 GNUNET_SCHEDULER_cancel (endbadly_task);
359 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); 371 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
360 return; 372 return;
361 } 373 }
374 GNUNET_assert (0);
375}
362 376
363 377
378static void
379empty_zone_proc_end (void *cls)
380{
381 char *hostkey_file;
382
364 zi = NULL; 383 zi = NULL;
365 GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR, 384 GNUNET_asprintf (&hostkey_file,
366 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); 385 "zonefiles%s%s",
367 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); 386 DIR_SEPARATOR_STR,
368 privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file); 387 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
388 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
389 "Using zonekey file `%s'\n",
390 hostkey_file);
391 privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
369 GNUNET_free (hostkey_file); 392 GNUNET_free (hostkey_file);
370 GNUNET_assert (privkey != NULL); 393 GNUNET_assert (privkey != NULL);
371 394
372 GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR, 395 GNUNET_asprintf(&hostkey_file,
373 "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey"); 396 "zonefiles%s%s",
374 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); 397 DIR_SEPARATOR_STR,
398 "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
399 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
400 "Using zonekey file `%s' \n",
401 hostkey_file);
375 privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file); 402 privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
376 GNUNET_free (hostkey_file); 403 GNUNET_free (hostkey_file);
377 GNUNET_assert (privkey2 != NULL); 404 GNUNET_assert (privkey2 != NULL);
@@ -380,25 +407,39 @@ empty_zone_proc (void *cls,
380 "Created record 1\n"); 407 "Created record 1\n");
381 408
382 GNUNET_asprintf(&s_name_1, "dummy1"); 409 GNUNET_asprintf(&s_name_1, "dummy1");
383 s_rd_1 = create_record(1); 410 s_rd_1 = create_record (1);
384 GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_1, 411 GNUNET_NAMESTORE_records_store (nsh,
385 1, s_rd_1, &put_cont, NULL); 412 privkey,
413 s_name_1,
414 1,
415 s_rd_1,
416 &put_cont,
417 NULL);
386 418
387 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 419 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
388 "Created record 2 \n"); 420 "Created record 2 \n");
389 GNUNET_asprintf(&s_name_2, "dummy2"); 421 GNUNET_asprintf(&s_name_2, "dummy2");
390 s_rd_2 = create_record(1); 422 s_rd_2 = create_record (1);
391 GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_2, 423 GNUNET_NAMESTORE_records_store (nsh,
392 1, s_rd_2, &put_cont, NULL); 424 privkey,
425 s_name_2,
426 1,
427 s_rd_2,
428 &put_cont,
429 NULL);
393 430
394 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 431 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
395 "Created record 3\n"); 432 "Created record 3\n");
396 433
397 /* name in different zone */ 434 /* name in different zone */
398 GNUNET_asprintf(&s_name_3, "dummy3"); 435 GNUNET_asprintf(&s_name_3, "dummy3");
399 s_rd_3 = create_record(1); 436 s_rd_3 = create_record (1);
400 GNUNET_NAMESTORE_records_store(nsh, privkey2, s_name_3, 437 GNUNET_NAMESTORE_records_store (nsh,
401 1, s_rd_3, &put_cont, NULL); 438 privkey2,
439 s_name_3,
440 1, s_rd_3,
441 &put_cont,
442 NULL);
402} 443}
403 444
404 445
@@ -423,7 +464,12 @@ run (void *cls,
423 /* first, iterate over empty namestore */ 464 /* first, iterate over empty namestore */
424 zi = GNUNET_NAMESTORE_zone_iteration_start (nsh, 465 zi = GNUNET_NAMESTORE_zone_iteration_start (nsh,
425 NULL, 466 NULL,
426 &empty_zone_proc, nsh); 467 &fail_cb,
468 NULL,
469 &empty_zone_proc,
470 nsh,
471 &empty_zone_proc_end,
472 nsh);
427 if (NULL == zi) 473 if (NULL == zi)
428 { 474 {
429 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 475 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
diff --git a/src/namestore/test_namestore_api_zone_iteration_stop.c b/src/namestore/test_namestore_api_zone_iteration_stop.c
index 36f527da0..a5f040150 100644
--- a/src/namestore/test_namestore_api_zone_iteration_stop.c
+++ b/src/namestore/test_namestore_api_zone_iteration_stop.c
@@ -156,6 +156,13 @@ end (void *cls)
156 156
157 157
158static void 158static void
159fail_cb (void *cls)
160{
161 GNUNET_assert (0);
162}
163
164
165static void
159zone_proc (void *cls, 166zone_proc (void *cls,
160 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 167 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
161 const char *label, 168 const char *label,
@@ -163,20 +170,7 @@ zone_proc (void *cls,
163 const struct GNUNET_GNSRECORD_Data *rd) 170 const struct GNUNET_GNSRECORD_Data *rd)
164{ 171{
165 int failed = GNUNET_NO; 172 int failed = GNUNET_NO;
166 if ((zone == NULL) && (label == NULL)) 173
167 {
168 GNUNET_break (1 <= returned_records);
169 if (1 >= returned_records)
170 res = 1; /* Last iteraterator callback, we are done */
171 else
172 res = 0;
173 zi = NULL;
174 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
175 "Received last result, iteration done after receing %u results\n",
176 returned_records );
177 GNUNET_SCHEDULER_add_now (&end, NULL);
178 return;
179 }
180 GNUNET_assert (NULL != zone); 174 GNUNET_assert (NULL != zone);
181 if (0 == memcmp (zone, privkey, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) 175 if (0 == memcmp (zone, privkey, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
182 { 176 {
@@ -288,6 +282,22 @@ zone_proc (void *cls,
288 282
289 283
290static void 284static void
285zone_proc_end (void *cls)
286{
287 GNUNET_break (1 <= returned_records);
288 if (1 >= returned_records)
289 res = 1; /* Last iteraterator callback, we are done */
290 else
291 res = 0;
292 zi = NULL;
293 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
294 "Received last result, iteration done after receing %u results\n",
295 returned_records);
296 GNUNET_SCHEDULER_add_now (&end, NULL);
297}
298
299
300static void
291put_cont (void *cls, int32_t success, const char *emsg) 301put_cont (void *cls, int32_t success, const char *emsg)
292{ 302{
293 static int c = 0; 303 static int c = 0;
@@ -312,14 +322,20 @@ put_cont (void *cls, int32_t success, const char *emsg)
312 { 322 {
313 res = 1; 323 res = 1;
314 returned_records = 0; 324 returned_records = 0;
315 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All records created, starting iteration over all zones \n"); 325 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
316 zi = GNUNET_NAMESTORE_zone_iteration_start(nsh, 326 "All records created, starting iteration over all zones \n");
317 NULL, 327 zi = GNUNET_NAMESTORE_zone_iteration_start (nsh,
318 &zone_proc, 328 NULL,
319 NULL); 329 &fail_cb,
330 NULL,
331 &zone_proc,
332 NULL,
333 &zone_proc_end,
334 NULL);
320 if (zi == NULL) 335 if (zi == NULL)
321 { 336 {
322 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone iterator\n"); 337 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
338 "Failed to create zone iterator\n");
323 GNUNET_break (0); 339 GNUNET_break (0);
324 if (NULL != endbadly_task) 340 if (NULL != endbadly_task)
325 GNUNET_SCHEDULER_cancel (endbadly_task); 341 GNUNET_SCHEDULER_cancel (endbadly_task);
@@ -362,7 +378,6 @@ empty_zone_proc (void *cls,
362 unsigned int rd_count, 378 unsigned int rd_count,
363 const struct GNUNET_GNSRECORD_Data *rd) 379 const struct GNUNET_GNSRECORD_Data *rd)
364{ 380{
365 char *hostkey_file;
366 381
367 GNUNET_assert (nsh == cls); 382 GNUNET_assert (nsh == cls);
368 if (NULL != zone) 383 if (NULL != zone)
@@ -385,42 +400,72 @@ empty_zone_proc (void *cls,
385 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); 400 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
386 return; 401 return;
387 } 402 }
403 GNUNET_assert (0);
404}
405
388 406
407static void
408empty_zone_proc_end (void *cls)
409{
410 char *hostkey_file;
411
412 GNUNET_assert (nsh == cls);
389 zi = NULL; 413 zi = NULL;
390 GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR, 414 GNUNET_asprintf(&hostkey_file,
391 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); 415 "zonefiles%s%s",
392 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); 416 DIR_SEPARATOR_STR,
417 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
418 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
419 "Using zonekey file `%s' \n",
420 hostkey_file);
393 privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file); 421 privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
394 GNUNET_free (hostkey_file); 422 GNUNET_free (hostkey_file);
395 GNUNET_assert (privkey != NULL); 423 GNUNET_assert (privkey != NULL);
396 424
397 GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR, 425 GNUNET_asprintf (&hostkey_file,
398 "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey"); 426 "zonefiles%s%s",
399 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); 427 DIR_SEPARATOR_STR,
428 "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
429 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
430 "Using zonekey file `%s'\n",
431 hostkey_file);
400 privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file); 432 privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
401 GNUNET_free (hostkey_file); 433 GNUNET_free (hostkey_file);
402 GNUNET_assert (privkey2 != NULL); 434 GNUNET_assert (privkey2 != NULL);
403 435
404 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n"); 436 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
437 "Created record 1\n");
405 438
406 GNUNET_asprintf(&s_name_1, "dummy1"); 439 GNUNET_asprintf(&s_name_1,
440 "dummy1");
407 s_rd_1 = create_record(1); 441 s_rd_1 = create_record(1);
408 GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_1, 442 GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_1,
409 1, s_rd_1, &put_cont, NULL); 443 1, s_rd_1, &put_cont, NULL);
410 444
411 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n"); 445 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
412 GNUNET_asprintf(&s_name_2, "dummy2"); 446 "Created record 2 \n");
447 GNUNET_asprintf(&s_name_2,
448 "dummy2");
413 s_rd_2 = create_record(1); 449 s_rd_2 = create_record(1);
414 GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_2, 450 GNUNET_NAMESTORE_records_store (nsh,
415 1, s_rd_2, &put_cont, NULL); 451 privkey,
452 s_name_2,
453 1,
454 s_rd_2,
455 &put_cont, NULL);
416 456
417 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 3\n"); 457 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
458 "Created record 3\n");
418 459
419 /* name in different zone */ 460 /* name in different zone */
420 GNUNET_asprintf(&s_name_3, "dummy3"); 461 GNUNET_asprintf(&s_name_3, "dummy3");
421 s_rd_3 = create_record(1); 462 s_rd_3 = create_record(1);
422 GNUNET_NAMESTORE_records_store(nsh, privkey2, s_name_3, 463 GNUNET_NAMESTORE_records_store(nsh,
423 1, s_rd_3, &put_cont, NULL); 464 privkey2,
465 s_name_3,
466 1,
467 s_rd_3,
468 &put_cont, NULL);
424} 469}
425 470
426 471
@@ -441,7 +486,13 @@ run (void *cls,
441 GNUNET_break (NULL != nsh); 486 GNUNET_break (NULL != nsh);
442 /* first, iterate over empty namestore */ 487 /* first, iterate over empty namestore */
443 zi = GNUNET_NAMESTORE_zone_iteration_start(nsh, 488 zi = GNUNET_NAMESTORE_zone_iteration_start(nsh,
444 NULL, &empty_zone_proc, nsh); 489 NULL,
490 &fail_cb,
491 NULL,
492 &empty_zone_proc,
493 nsh,
494 &empty_zone_proc_end,
495 nsh);
445 if (NULL == zi) 496 if (NULL == zi)
446 { 497 {
447 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 498 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,