make namestore API less brittle/sublte to use
authorChristian Grothoff <christian@grothoff.org>
Sat, 9 Jul 2016 14:29:34 +0000 (14:29 +0000)
committerChristian Grothoff <christian@grothoff.org>
Sat, 9 Jul 2016 14:29:34 +0000 (14:29 +0000)
19 files changed:
src/gns/gnunet-service-gns.c
src/gns/gnunet-service-gns_shorten.c
src/identity-provider/gnunet-service-identity-provider.c
src/identity-provider/plugin_rest_identity_provider.c
src/include/gnunet_namestore_service.h
src/namestore/gnunet-namestore-fcfsd.c
src/namestore/gnunet-namestore.c
src/namestore/namestore_api.c
src/namestore/namestore_api_monitor.c
src/namestore/plugin_rest_namestore.c
src/namestore/test_namestore_api.conf
src/namestore/test_namestore_api_lookup_nick.c
src/namestore/test_namestore_api_lookup_private.c
src/namestore/test_namestore_api_monitoring.c
src/namestore/test_namestore_api_monitoring_existing.c
src/namestore/test_namestore_api_zone_iteration.c
src/namestore/test_namestore_api_zone_iteration_nick.c
src/namestore/test_namestore_api_zone_iteration_specific_zone.c
src/namestore/test_namestore_api_zone_iteration_stop.c

index 2a9d86a8bb728150598422293a86ce34c3dd8064..ea271e9dde67d0eb2ded70569bd70a2d9205c13c 100644 (file)
 #define INITIAL_PUT_INTERVAL GNUNET_TIME_UNIT_MILLISECONDS
 
 /**
- * The upper bound for the zone iteration interval in milliseconds
+ * The lower bound for the zone iteration interval
  */
 #define MINIMUM_ZONE_ITERATION_INTERVAL GNUNET_TIME_UNIT_SECONDS
 
+/**
+ * The upper bound for the zone iteration interval
+ */
+#define MAXIMUM_ZONE_ITERATION_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
+
 /**
  * The default put interval for the zone iteration. In case
  * no option is found
@@ -401,6 +406,12 @@ dht_put_continuation (void *cls,
     }
     else
       next_put_interval = put_interval;
+    next_put_interval = GNUNET_TIME_relative_min (next_put_interval,
+                                                  MAXIMUM_ZONE_ITERATION_INTERVAL);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "PUT complete, next PUT in %s!\n",
+                GNUNET_STRINGS_relative_time_to_string (next_put_interval,
+                                                        GNUNET_YES));
 
     GNUNET_STATISTICS_set (statistics,
                            "Current zone iteration interval (ms)",
@@ -509,7 +520,8 @@ perform_dht_put (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
               label,
               GNUNET_STRINGS_absolute_time_to_string (expire),
               GNUNET_h2s (&query));
-  ret = GNUNET_DHT_put (dht_handle, &query,
+  ret = GNUNET_DHT_put (dht_handle,
+                        &query,
                         DHT_GNS_REPLICATION_LEVEL,
                         GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
                         GNUNET_BLOCK_TYPE_GNS_NAMERECORD,
@@ -523,6 +535,98 @@ perform_dht_put (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
 }
 
 
+/**
+ * We encountered an error in our zone iteration.
+ */
+static void
+zone_iteration_error (void *cls)
+{
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Got disconnected from namestore database, retrying.\n");
+  namestore_iter = NULL;
+  /* We end up here on error/disconnect/shutdown, so potentially
+     while a zone publish task or a DHT put is still running; hence
+     we need to cancel those. */
+  if (NULL != zone_publish_task)
+  {
+    GNUNET_SCHEDULER_cancel (zone_publish_task);
+    zone_publish_task = NULL;
+  }
+  if (NULL != active_put)
+  {
+    GNUNET_DHT_put_cancel (active_put);
+    active_put = NULL;
+  }
+  zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start,
+                                                NULL);
+}
+
+
+/**
+ * Zone iteration is completed.
+ */
+static void
+zone_iteration_finished (void *cls)
+{
+  /* we're done with one iteration, calculate when to do the next one */
+  namestore_iter = NULL;
+  last_num_public_records = num_public_records;
+  first_zone_iteration = GNUNET_NO;
+  if (0 == num_public_records)
+  {
+    /**
+     * If no records are known (startup) or none present
+     * we can safely set the interval to the value for a single
+     * record
+     */
+    put_interval = zone_publish_time_window;
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
+                "No records in namestore database.\n");
+  }
+  else
+  {
+    /* If records are present, next publication is based on the minimum
+     * relative expiration time of the records published divided by 4
+     */
+    zone_publish_time_window
+      = GNUNET_TIME_relative_min (GNUNET_TIME_relative_divide (min_relative_record_time, 4),
+                                  zone_publish_time_window_default);
+    put_interval = GNUNET_TIME_relative_divide (zone_publish_time_window,
+                                                num_public_records);
+  }
+  /* reset for next iteration */
+  min_relative_record_time = GNUNET_TIME_UNIT_FOREVER_REL;
+  put_interval = GNUNET_TIME_relative_max (MINIMUM_ZONE_ITERATION_INTERVAL,
+                                           put_interval);
+  put_interval = GNUNET_TIME_relative_min (put_interval,
+                                           MAXIMUM_ZONE_ITERATION_INTERVAL);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Zone iteration finished. Adjusted zone iteration interval to %s\n",
+              GNUNET_STRINGS_relative_time_to_string (put_interval,
+                                                      GNUNET_YES));
+  GNUNET_STATISTICS_set (statistics,
+                         "Current zone iteration interval (in ms)",
+                         put_interval.rel_value_us / 1000LL,
+                         GNUNET_NO);
+  GNUNET_STATISTICS_update (statistics,
+                            "Number of zone iterations",
+                            1,
+                            GNUNET_NO);
+  GNUNET_STATISTICS_set (statistics,
+                         "Number of public records in DHT",
+                         last_num_public_records,
+                         GNUNET_NO);
+  GNUNET_assert (NULL == zone_publish_task);
+  if (0 == num_public_records)
+    zone_publish_task = GNUNET_SCHEDULER_add_delayed (put_interval,
+                                                      &publish_zone_dht_start,
+                                                      NULL);
+  else
+    zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start,
+                                                  NULL);
+}
+
+
 /**
  * Function used to put all records successively into the DHT.
  *
@@ -542,95 +646,22 @@ put_gns_record (void *cls,
   struct GNUNET_GNSRECORD_Data rd_public[rd_count];
   unsigned int rd_public_count;
 
-  if ( (NULL == key) &&
-       (NULL == label) &&
-       (0 == rd_count) )
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Got disconnected from namestore database, retrying.\n");
-    namestore_iter = NULL;
-    if (NULL != zone_publish_task)
-    {
-      GNUNET_SCHEDULER_cancel (zone_publish_task);
-      zone_publish_task = NULL;
-    }
-    zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start,
-                                                  NULL);
-    return;
-  }
-  if (NULL == label)
-  {
-    /* we're done with one iteration, calculate when to do the next one */
-    namestore_iter = NULL;
-    last_num_public_records = num_public_records;
-    first_zone_iteration = GNUNET_NO;
-    if (0 == num_public_records)
-    {
-      /**
-       * If no records are known (startup) or none present
-       * we can safely set the interval to the value for a single
-       * record
-       */
-      put_interval = zone_publish_time_window;
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
-                 "No records in namestore database.\n");
-    }
-    else
-    {
-      /* If records are present, next publication is based on the minimum
-       * relative expiration time of the records published divided by 4
-       */
-      zone_publish_time_window = GNUNET_TIME_relative_min (
-          GNUNET_TIME_relative_divide (min_relative_record_time, 4),
-          zone_publish_time_window_default);
-      put_interval = GNUNET_TIME_relative_divide (zone_publish_time_window,
-                                                  num_public_records);
-    }
-    /* reset for next iteration */
-    min_relative_record_time = GNUNET_TIME_UNIT_FOREVER_REL;
-    put_interval = GNUNET_TIME_relative_max (MINIMUM_ZONE_ITERATION_INTERVAL,
-                                            put_interval);
-
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-               "Zone iteration finished. Adjusted zone iteration interval to %s\n",
-               GNUNET_STRINGS_relative_time_to_string (put_interval,
-                                                        GNUNET_YES));
-    GNUNET_STATISTICS_set (statistics,
-                           "Current zone iteration interval (in ms)",
-                           put_interval.rel_value_us / 1000LL,
-                           GNUNET_NO);
-    GNUNET_STATISTICS_update (statistics,
-                              "Number of zone iterations",
-                             1,
-                             GNUNET_NO);
-    GNUNET_STATISTICS_set (statistics,
-                           "Number of public records in DHT",
-                           last_num_public_records,
-                           GNUNET_NO);
-    GNUNET_assert (NULL == zone_publish_task);
-    if (0 == num_public_records)
-      zone_publish_task = GNUNET_SCHEDULER_add_delayed (put_interval,
-                                                       &publish_zone_dht_start,
-                                                       NULL);
-    else
-      zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start,
-                                                   NULL);
-    return;
-  }
-
   rd_public_count = convert_records_for_export (rd,
                                                 rd_count,
                                                 rd_public);
 
-  /* We got a set of records to publish */
   if (0 == rd_public_count)
   {
     GNUNET_assert (NULL == zone_publish_task);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Record set empty, moving to next record set\n");
     zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_next,
-                                                   NULL);
+                                                  NULL);
     return;
   }
-
+  /* We got a set of records to publish */
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Starting DHT PUT\n");
   active_put = perform_dht_put (key,
                                 label,
                                 rd_public,
@@ -662,7 +693,11 @@ publish_zone_dht_start (void *cls)
   namestore_iter
     = GNUNET_NAMESTORE_zone_iteration_start (namestore_handle,
                                              NULL, /* All zones */
+                                             &zone_iteration_error,
+                                             NULL,
                                              &put_gns_record,
+                                             NULL,
+                                             &zone_iteration_finished,
                                              NULL);
 }
 
@@ -694,13 +729,16 @@ handle_monitor_event (void *cls,
               label);
   /* filter out records that are not public, and convert to
      absolute expiration time. */
-  rd_public_count = convert_records_for_export (rd, rd_count,
+  rd_public_count = convert_records_for_export (rd,
+                                                rd_count,
                                                 rd_public);
   if (0 == rd_public_count)
     return; /* nothing to do */
   ma = GNUNET_new (struct MonitorActivity);
-  ma->ph = perform_dht_put (zone, label,
-                            rd, rd_count,
+  ma->ph = perform_dht_put (zone,
+                            label,
+                            rd,
+                            rd_count,
                             ma);
   if (NULL == ma->ph)
   {
@@ -880,6 +918,35 @@ monitor_sync_event (void *cls)
 }
 
 
+/**
+ * The zone monitor is now in SYNC with the current state of the
+ * name store.  Start to perform periodic iterations.
+ *
+ * @param cls NULL
+ */
+static void
+handle_monitor_error (void *cls)
+{
+  if (NULL != zone_publish_task)
+  {
+    GNUNET_SCHEDULER_cancel (zone_publish_task);
+    zone_publish_task = NULL;
+  }
+  if (NULL != namestore_iter)
+  {
+    GNUNET_NAMESTORE_zone_iteration_stop (namestore_iter);
+    namestore_iter = NULL;
+  }
+  if (NULL != active_put)
+  {
+    GNUNET_DHT_put_cancel (active_put);
+    active_put = NULL;
+  }
+  zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start,
+                                               NULL);
+}
+
+
 /**
  * Method called to inform about the ego to be used for the master zone
  * for DNS interceptions.
@@ -1032,7 +1099,10 @@ run (void *cls,
   zmon = GNUNET_NAMESTORE_zone_monitor_start (c,
                                               NULL,
                                               GNUNET_NO,
+                                              &handle_monitor_error,
+                                              NULL,
                                               &handle_monitor_event,
+                                              NULL,
                                               &monitor_sync_event,
                                               NULL);
   GNUNET_break (NULL != zmon);
index dd546ae56ad013d5d0c309cf383f0bc49f3a332c..9aa0419aa3614702f288e5aa93a0bd8149241b61 100644 (file)
@@ -325,6 +325,21 @@ process_pseu_lookup_ns (void *cls,
 }
 
 
+/**
+ * Encountered an error in zone-to-name lookup, give up on shortening.
+ */
+static void
+zone_to_name_error_cb (void *cls)
+{
+  struct GetPseuAuthorityHandle* gph = cls;
+
+  gph->namestore_task = NULL;
+  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+              "Shortening aborted, internal error talking to namestore\n");
+  free_get_pseu_authority_handle (gph);
+}
+
+
 /**
  * Callback called by namestore for a zone to name result.  We're
  * trying to see if a short name for a given zone already exists.
@@ -343,9 +358,6 @@ process_zone_to_name_discover (void *cls,
                               const struct GNUNET_GNSRECORD_Data *rd)
 {
   struct GetPseuAuthorityHandle* gph = cls;
-#if 0
-  struct GNUNET_HashCode lookup_key;
-#endif
 
   gph->namestore_task = NULL;
   if (0 != rd_len)
@@ -412,6 +424,8 @@ GNS_shorten_start (const char *original_label,
   gph->namestore_task = GNUNET_NAMESTORE_zone_to_name (namestore_handle,
                                                        shorten_zone,
                                                        pub,
+                                                       &zone_to_name_error_cb,
+                                                       gph,
                                                        &process_zone_to_name_discover,
                                                        gph);
 }
index 7a68fe902ec518ef029a42ae90a72e6605576c7d..228e6cdc5a6ff72f39f2c1429a51cee4d13b8620 100644 (file)
@@ -531,6 +531,32 @@ clear_ego_attrs (void *cls,
 }
 
 
+static void
+token_collect_error_cb (void *cls)
+{
+  // struct EgoEntry *ego_entry = cls;
+
+  GNUNET_assert (0); // FIXME: handle properly!
+}
+
+
+static void
+token_collect_finished_cb (void *cls)
+{
+  struct EgoEntry *ego_entry = cls;
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              ">>> Updating Ego finished\n");
+  //Clear attribute map for ego
+  GNUNET_CONTAINER_multihashmap_iterate (ego_entry->attr_map,
+                                         &clear_ego_attrs,
+                                         ego_entry);
+  GNUNET_CONTAINER_multihashmap_clear (ego_entry->attr_map);
+  update_task = GNUNET_SCHEDULER_add_now (&update_identities,
+                                          ego_entry->next);
+}
+
+
 /**
  *
  * Update all ID_TOKEN records for an identity and store them
@@ -553,21 +579,6 @@ token_collect (void *cls,
   const struct GNUNET_GNSRECORD_Data *token_metadata_record;
   struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key;
 
-  if (NULL == lbl)
-  {
-    //Done
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                ">>> Updating Ego finished\n");
-    //Clear attribute map for ego
-    GNUNET_CONTAINER_multihashmap_iterate (ego_entry->attr_map,
-                                           &clear_ego_attrs,
-                                           ego_entry);
-    GNUNET_CONTAINER_multihashmap_clear (ego_entry->attr_map);
-    update_task = GNUNET_SCHEDULER_add_now (&update_identities,
-                                            ego_entry->next);
-    return;
-  }
-
   //There should be only a single record for a token under a label
   if (2 != rd_count)
   {
@@ -614,6 +625,28 @@ token_collect (void *cls,
 }
 
 
+static void
+attribute_collect_error_cb (void *cls)
+{
+  // struct EgoEntry *ego_entry = cls;
+
+  GNUNET_assert (0); // FIXME: handle properly!
+}
+
+
+static void
+attribute_collect_finished_cb (void *cls)
+{
+  struct EgoEntry *ego_entry = cls;
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              ">>> Updating Attributes finished\n");
+  ego_entry->attributes_dirty = GNUNET_NO;
+  update_task = GNUNET_SCHEDULER_add_now (&update_identities,
+                                          ego_entry);
+}
+
+
 /**
  *
  * Collect all ID_ATTR records for an identity and store them
@@ -639,17 +672,6 @@ attribute_collect (void *cls,
   char *val_str;
   int i;
 
-  if (NULL == lbl)
-  {
-    //Done
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                ">>> Updating Attributes finished\n");
-    ego_entry->attributes_dirty = GNUNET_NO;
-    update_task = GNUNET_SCHEDULER_add_now (&update_identities,
-                                           ego_entry);
-    return;
-  }
-
   if (0 == rd_count)
   {
     GNUNET_NAMESTORE_zone_iterator_next (ns_it);
@@ -703,7 +725,6 @@ attribute_collect (void *cls,
                                      attr,
                                      GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
   GNUNET_NAMESTORE_zone_iterator_next (ns_it);
-  return;
 }
 
 /**
@@ -718,6 +739,7 @@ update_identities(void *cls)
 {
   struct EgoEntry *next_ego = cls;
   const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key;
+
   update_task = NULL;
   if (NULL == next_ego)
   {
@@ -740,7 +762,11 @@ update_identities(void *cls)
     //Starting over. We must update the Attributes for they might have changed.
     ns_it = GNUNET_NAMESTORE_zone_iteration_start (ns_handle,
                                                    priv_key,
+                                                   &attribute_collect_error_cb,
+                                                   next_ego,
                                                    &attribute_collect,
+                                                   next_ego,
+                                                   &attribute_collect_finished_cb,
                                                    next_ego);
 
   }
@@ -750,7 +776,11 @@ update_identities(void *cls)
     next_ego->attributes_dirty = GNUNET_YES;
     ns_it = GNUNET_NAMESTORE_zone_iteration_start (ns_handle,
                                                    priv_key,
+                                                   &token_collect_error_cb,
+                                                   next_ego,
                                                    &token_collect,
+                                                   next_ego,
+                                                   &token_collect_finished_cb,
                                                    next_ego);
   }
 }
@@ -939,7 +969,7 @@ store_token_issue_cont (void *cls,
   struct GNUNET_IDENTITY_PROVIDER_IssueResultMessage *irm;
   char *ticket_str;
   char *token_str;
-  
+
   handle->ns_qe = NULL;
   if (GNUNET_SYSERR == success)
   {
@@ -1077,6 +1107,27 @@ sign_and_return_token (void *cls)
   GNUNET_free (token_metadata);
 }
 
+
+static void
+attr_collect_error (void *cls)
+{
+  // struct IssueHandle *handle = cls;
+
+  GNUNET_assert (0); // FIXME: handle error!
+}
+
+
+static void
+attr_collect_finished (void *cls)
+{
+  struct IssueHandle *handle = cls;
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attribute END: \n");
+  handle->ns_it = NULL;
+  GNUNET_SCHEDULER_add_now (&sign_and_return_token, handle);
+}
+
+
 /**
  * Collect attributes for token
  */
@@ -1087,19 +1138,11 @@ attr_collect (void *cls,
               unsigned int rd_count,
               const struct GNUNET_GNSRECORD_Data *rd)
 {
+  struct IssueHandle *handle = cls;
   int i;
   char* data;
-  struct IssueHandle *handle = cls;
   struct GNUNET_HashCode key;
 
-  if (NULL == label)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attribute END: \n");
-    handle->ns_it = NULL;
-    GNUNET_SCHEDULER_add_now (&sign_and_return_token, handle);
-    return;
-  }
-
   GNUNET_CRYPTO_hash (label,
                       strlen (label),
                       &key);
@@ -1278,6 +1321,41 @@ handle_exchange_message (void *cls,
 }
 
 
+static void
+find_existing_token_error (void *cls)
+{
+  // struct IssueHandle *handle = cls;
+
+  GNUNET_assert (0); // FIXME: handle properly
+}
+
+
+static void
+find_existing_token_finished (void *cls)
+{
+  struct IssueHandle *handle = cls;
+  uint64_t rnd_key;
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              ">>> No existing token found\n");
+  rnd_key =
+    GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG,
+                              UINT64_MAX);
+  GNUNET_STRINGS_base64_encode ((char*)&rnd_key,
+                                sizeof (uint64_t),
+                                &handle->label);
+  handle->ns_it = NULL;
+  handle->ns_it = GNUNET_NAMESTORE_zone_iteration_start (ns_handle,
+                                                         &handle->iss_key,
+                                                         &attr_collect_error,
+                                                         handle,
+                                                         &attr_collect,
+                                                         handle,
+                                                         &attr_collect_finished,
+                                                         handle);
+}
+
+
 /**
  *
  * Look for existing token
@@ -1301,30 +1379,9 @@ find_existing_token (void *cls,
   struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key;
   struct GNUNET_HashCode key;
   int scope_count_token;
-  uint64_t rnd_key;
   char *scope;
   char *tmp_scopes;
 
-  if (NULL == lbl)
-  {
-    //Done
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                ">>> No existing token found\n");
-    //Label
-    rnd_key =
-      GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG,
-                                UINT64_MAX);
-    GNUNET_STRINGS_base64_encode ((char*)&rnd_key,
-                                  sizeof (uint64_t),
-                                  &handle->label);
-    handle->ns_it = NULL;
-    handle->ns_it = GNUNET_NAMESTORE_zone_iteration_start (ns_handle,
-                                                           &handle->iss_key,
-                                                           &attr_collect,
-                                                           handle);
-    return;
-  }
-
   //There should be only a single record for a token under a label
   if (2 != rd_count)
   {
@@ -1335,7 +1392,9 @@ find_existing_token (void *cls,
   if (rd[0].record_type == GNUNET_GNSRECORD_TYPE_ID_TOKEN_METADATA)
   {
     token_metadata_record = &rd[0];
-  } else {
+  }
+  else
+  {
     token_metadata_record = &rd[1];
   }
   if (token_metadata_record->record_type != GNUNET_GNSRECORD_TYPE_ID_TOKEN_METADATA)
@@ -1399,7 +1458,11 @@ find_existing_token (void *cls,
     handle->ns_it = NULL;
     handle->ns_it = GNUNET_NAMESTORE_zone_iteration_start (ns_handle,
                                                            &handle->iss_key,
+                                                           &attr_collect_error,
+                                                           handle,
                                                            &attr_collect,
+                                                           handle,
+                                                           &attr_collect_finished,
                                                            handle);
 
     return;
@@ -1477,10 +1540,15 @@ handle_issue_message (void *cls,
 
   issue_handle->ns_it = GNUNET_NAMESTORE_zone_iteration_start (ns_handle,
                                                                &im->iss_key,
+                                                               &find_existing_token_error,
+                                                               issue_handle,
                                                                &find_existing_token,
+                                                               issue_handle,
+                                                               &find_existing_token_finished,
                                                                issue_handle);
 }
 
+
 /**
  * Main function that will be run
  *
index c0b018798e6d2630bc8f46c9b35313bfadf460ed..fa97137d76fda541a2933076b84b7abe04b6cea1 100644 (file)
@@ -647,6 +647,16 @@ return_token_list (void *cls)
   cleanup_handle (handle);
 }
 
+
+static void
+token_collect_error_cb (void *cls)
+{
+  struct RequestHandle *handle = cls;
+
+  do_error (handle);
+}
+
+
 /**
  * Collect all tokens for an ego
  *
@@ -658,45 +668,68 @@ token_collect (void *cls,
                const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
                const char *label,
                unsigned int rd_count,
-               const struct GNUNET_GNSRECORD_Data *rd)
+               const struct GNUNET_GNSRECORD_Data *rd);
+
+
+static void
+token_collect_finished_cb (void *cls)
 {
-  int i;
-  char* data;
   struct RequestHandle *handle = cls;
   struct EgoEntry *ego_tmp;
-  struct GNUNET_JSONAPI_Resource *json_resource;
   const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key;
-  json_t *issuer;
-  json_t *token;
-
-  if (NULL == label)
-  {
-    ego_tmp = handle->ego_head;
-    GNUNET_CONTAINER_DLL_remove (handle->ego_head,
-                                 handle->ego_tail,
-                                 ego_tmp);
-    GNUNET_free (ego_tmp->identifier);
-    GNUNET_free (ego_tmp->keystring);
-    GNUNET_free (ego_tmp);
 
-    if (NULL == handle->ego_head)
-    {
-      //Done
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding token END\n");
-      handle->ns_it = NULL;
-      GNUNET_SCHEDULER_add_now (&return_token_list, handle);
-      return;
-    }
+  ego_tmp = handle->ego_head;
+  GNUNET_CONTAINER_DLL_remove (handle->ego_head,
+                               handle->ego_tail,
+                               ego_tmp);
+  GNUNET_free (ego_tmp->identifier);
+  GNUNET_free (ego_tmp->keystring);
+  GNUNET_free (ego_tmp);
 
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Next ego: %s\n", handle->ego_head->identifier);
-    priv_key = GNUNET_IDENTITY_ego_get_private_key (handle->ego_head->ego);
-    handle->ns_it = GNUNET_NAMESTORE_zone_iteration_start (handle->ns_handle,
-                                                           priv_key,
-                                                           &token_collect,
-                                                           handle);
+  if (NULL == handle->ego_head)
+  {
+    //Done
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding token END\n");
+    handle->ns_it = NULL;
+    GNUNET_SCHEDULER_add_now (&return_token_list, handle);
     return;
   }
 
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Next ego: %s\n",
+              handle->ego_head->identifier);
+  priv_key = GNUNET_IDENTITY_ego_get_private_key (handle->ego_head->ego);
+  handle->ns_it = GNUNET_NAMESTORE_zone_iteration_start (handle->ns_handle,
+                                                         priv_key,
+                                                         &token_collect_error_cb,
+                                                         handle,
+                                                         &token_collect,
+                                                         handle,
+                                                         &token_collect_finished_cb,
+                                                         handle);
+}
+
+
+/**
+ * Collect all tokens for an ego
+ *
+ * TODO move this into the identity-provider service
+ *
+ */
+static void
+token_collect (void *cls,
+               const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
+               const char *label,
+               unsigned int rd_count,
+               const struct GNUNET_GNSRECORD_Data *rd)
+{
+  struct RequestHandle *handle = cls;
+  int i;
+  char* data;
+  struct GNUNET_JSONAPI_Resource *json_resource;
+  json_t *issuer;
+  json_t *token;
+
   for (i = 0; i < rd_count; i++)
   {
     if (rd[i].record_type == GNUNET_GNSRECORD_TYPE_ID_TOKEN)
@@ -789,7 +822,11 @@ list_token_cont (struct GNUNET_REST_RequestHandle *con_handle,
   handle->ns_handle = GNUNET_NAMESTORE_connect (cfg);
   handle->ns_it = GNUNET_NAMESTORE_zone_iteration_start (handle->ns_handle,
                                                          priv_key,
+                                                         &token_collect_error_cb,
+                                                         handle,
                                                          &token_collect,
+                                                         handle,
+                                                         &token_collect_finished_cb,
                                                          handle);
 
 }
index 1918ca1ffbf987c4ffc732eb137a8b566cb8cb11..0add8852a942bf348cbe0fe3d05cc711f5752e39 100644 (file)
@@ -133,8 +133,8 @@ GNUNET_NAMESTORE_records_store (struct GNUNET_NAMESTORE_Handle *h,
  * Process a record that was stored in the namestore.
  *
  * @param cls closure
- * @param zone private key of the zone; NULL on disconnect
- * @param label label of the records; NULL on disconnect
+ * @param zone private key of the zone
+ * @param label label of the records
  * @param rd_count number of entries in @a rd array, 0 if label was deleted
  * @param rd array of records with data to store
  */
@@ -170,7 +170,11 @@ GNUNET_NAMESTORE_set_nick (struct GNUNET_NAMESTORE_Handle *h,
  * @param h handle to the namestore
  * @param pkey private key of the zone
  * @param label name that is being mapped
- * @param rm function to call with the result (with 0 records if we don't have that label)
+ * @param error_cb function to call on error (i.e. disconnect)
+ *        the handle is afterwards invalid
+ * @param error_cb_cls closure for @a error_cb
+ * @param rm function to call with the result (with 0 records if we don't have that label);
+ *        the handle is afterwards invalid
  * @param rm_cls closure for @a rm
  * @return handle to abort the request
  */
@@ -178,6 +182,8 @@ struct GNUNET_NAMESTORE_QueueEntry *
 GNUNET_NAMESTORE_records_lookup (struct GNUNET_NAMESTORE_Handle *h,
                                  const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
                                  const char *label,
+                                 GNUNET_SCHEDULER_TaskCallback error_cb,
+                                 void *error_cb_cls,
                                  GNUNET_NAMESTORE_RecordMonitor rm,
                                  void *rm_cls);
 
@@ -189,8 +195,12 @@ GNUNET_NAMESTORE_records_lookup (struct GNUNET_NAMESTORE_Handle *h,
  * @param h handle to the namestore
  * @param zone public key of the zone to look up in, never NULL
  * @param value_zone public key of the target zone (value), never NULL
+ * @param error_cb function to call on error (i.e. disconnect)
+ *        the handle is afterwards invalid
+ * @param error_cb_cls closure for @a error_cb
  * @param proc function to call on the matching records, or with
- *        NULL (rd_count == 0) if there are no matching records
+ *        NULL (rd_count == 0) if there are no matching records;
+ *        the handle is afterwards invalid
  * @param proc_cls closure for @a proc
  * @return a handle that can be used to
  *         cancel
@@ -199,7 +209,10 @@ struct GNUNET_NAMESTORE_QueueEntry *
 GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h,
                               const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
                               const struct GNUNET_CRYPTO_EcdsaPublicKey *value_zone,
-                              GNUNET_NAMESTORE_RecordMonitor proc, void *proc_cls);
+                               GNUNET_SCHEDULER_TaskCallback error_cb,
+                               void *error_cb_cls,
+                              GNUNET_NAMESTORE_RecordMonitor proc,
+                               void *proc_cls);
 
 
 /**
@@ -216,25 +229,38 @@ GNUNET_NAMESTORE_cancel (struct GNUNET_NAMESTORE_QueueEntry *qe);
 
 /**
  * Starts a new zone iteration (used to periodically PUT all of our
- * records into our DHT). This MUST lock the struct GNUNET_NAMESTORE_Handle
- * for any other calls than #GNUNET_NAMESTORE_zone_iterator_next and
+ * records into our DHT). This MUST lock the `struct GNUNET_NAMESTORE_Handle`
+ * for any other calls than #GNUNET_NAMESTORE_zone_iterator_next() and
  * #GNUNET_NAMESTORE_zone_iteration_stop. @a proc will be called once
  * immediately, and then again after
- * #GNUNET_NAMESTORE_zone_iterator_next is invoked.
+ * #GNUNET_NAMESTORE_zone_iterator_next() is invoked.
+ *
+ * On error (disconnect), @a error_cb will be invoked.
+ * On normal completion, @a finish_cb proc will be
+ * invoked.
  *
  * @param h handle to the namestore
  * @param zone zone to access, NULL for all zones
+ * @param error_cb function to call on error (i.e. disconnect),
+ *        the handle is afterwards invalid
+ * @param error_cb_cls closure for @a error_cb
  * @param proc function to call on each name from the zone; it
  *        will be called repeatedly with a value (if available)
- *        and always once at the end with a label of NULL.
  * @param proc_cls closure for @a proc
+ * @param finish_cb function to call on completion
+ *        the handle is afterwards invalid
+ * @param finish_cb_cls closure for @a finish_cb
  * @return an iterator handle to use for iteration
  */
 struct GNUNET_NAMESTORE_ZoneIterator *
 GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h,
                                       const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
+                                       GNUNET_SCHEDULER_TaskCallback error_cb,
+                                       void *error_cb_cls,
                                       GNUNET_NAMESTORE_RecordMonitor proc,
-                                      void *proc_cls);
+                                      void *proc_cls,
+                                       GNUNET_SCHEDULER_TaskCallback finish_cb,
+                                       void *finish_cb_cls);
 
 
 /**
@@ -264,45 +290,43 @@ GNUNET_NAMESTORE_zone_iteration_stop (struct GNUNET_NAMESTORE_ZoneIterator *it);
 struct GNUNET_NAMESTORE_ZoneMonitor;
 
 
-/**
- * Function called once the monitor has caught up with the current
- * state of the database.  Will be called AGAIN after each disconnect
- * (record monitor called with 'NULL' for zone_key) once we're again
- * in sync.
- *
- * @param cls closure
- */
-typedef void
-(*GNUNET_NAMESTORE_RecordsSynchronizedCallback)(void *cls);
-
-
 /**
  * Begin monitoring a zone for changes.  Will first call the @a
  * monitor function on all existing records in the selected zone(s) if
  * @a iterate_first is #GNUNET_YES.  In any case, we will then call @a
  * sync_cb, and then afterwards call the @a monitor whenever a record
- * changes.  If the namestore disconnects, the @a monitor function is
- * called with a disconnect event; if the connection is
+ * changes.  If the namestore disconnects, the @a error_cb function is
+ * called with a disconnect event. Once the connection is
  * re-established, the process begins from the start (depending on @a
- * iterate_first, we first do all existing records, then @a sync, then
- * updates).
+ * iterate_first, we will again first do all existing records, then @a
+ * sync, then updates).
  *
  * @param cfg configuration to use to connect to namestore
  * @param zone zone to monitor, NULL for all zones
  * @param iterate_first #GNUNET_YES to first iterate over all existing records,
  *                      #GNUNET_NO to only return changes that happen from now on
+ * @param error_cb function to call on error (i.e. disconnect); note that
+ *         unlike the other error callbacks in this API, a call to this
+ *         function does NOT destroy the monitor handle, it merely signals
+ *         that monitoring is down. You need to still explicitly call
+ *         #GNUNET_NAMESTORE_zone_monitor_stop().
+ * @param error_cb_cls closure for @a error_cb
  * @param monitor function to call on zone changes
+ * @param monitor_cls closure for @a monitor
  * @param sync_cb function called when we're in sync with the namestore
- * @param cls closure for @a monitor and @a sync_cb
+ * @param sync_cb_cls closure for @a sync_cb
  * @return handle to stop monitoring
  */
 struct GNUNET_NAMESTORE_ZoneMonitor *
 GNUNET_NAMESTORE_zone_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
                                     const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
                                      int iterate_first,
+                                     GNUNET_SCHEDULER_TaskCallback error_cb,
+                                     void *error_cb_cls,
                                     GNUNET_NAMESTORE_RecordMonitor monitor,
-                                    GNUNET_NAMESTORE_RecordsSynchronizedCallback sync_cb,
-                                    void *cls);
+                                     void *monitor_cls,
+                                    GNUNET_SCHEDULER_TaskCallback sync_cb,
+                                    void *sync_cb_cls);
 
 
 /**
index ed7009e024c6d22f9660e1cdefcacfc4b5e2bf08..b38761d5aa860f5c149e330d3c3f04b725524535 100644 (file)
@@ -246,6 +246,62 @@ run_httpd_now ()
 }
 
 
+/**
+ * Function called on error in zone iteration.
+ */
+static void
+zone_iteration_error (void *cls)
+{
+  struct ZoneinfoRequest *zr = cls;
+  struct MHD_Response *response;
+
+  zr->list_it = NULL;
+  response = MHD_create_response_from_buffer (strlen ("internal error"),
+                                             (void *) "internal error",
+                                             MHD_RESPMEM_PERSISTENT);
+  MHD_queue_response (zr->connection,
+                      MHD_HTTP_INTERNAL_SERVER_ERROR,
+                      response);
+  MHD_destroy_response (response);
+  GNUNET_free (zr->zoneinfo);
+  GNUNET_free (zr);
+  run_httpd_now ();
+}
+
+
+/**
+ * Function called once the zone iteration is done.
+ */
+static void
+zone_iteration_end (void *cls)
+{
+  struct ZoneinfoRequest *zr = cls;
+  struct MHD_Response *response;
+  char* full_page;
+
+  zr->list_it = NULL;
+
+  /* return static form */
+  GNUNET_asprintf (&full_page,
+                   ZONEINFO_PAGE,
+                   zr->zoneinfo,
+                   zr->zoneinfo);
+  response = MHD_create_response_from_buffer (strlen (full_page),
+                                             (void *) full_page,
+                                             MHD_RESPMEM_MUST_FREE);
+  MHD_add_response_header (response,
+                          MHD_HTTP_HEADER_CONTENT_TYPE,
+                          MIME_HTML);
+  MHD_queue_response (zr->connection,
+                      MHD_HTTP_OK,
+                      response);
+  MHD_destroy_response (response);
+  GNUNET_free (zr->zoneinfo);
+  GNUNET_free (zr);
+  run_httpd_now ();
+}
+
+
 /**
  * Process a record that was stored in the namestore, adding
  * the information to the HTML.
@@ -264,38 +320,10 @@ iterate_cb (void *cls,
            const struct GNUNET_GNSRECORD_Data *rd)
 {
   struct ZoneinfoRequest *zr = cls;
-  struct MHD_Response *response;
-  char* full_page;
   size_t bytes_free;
   char* pkey;
   char* new_buf;
 
-
-  if (NULL == name)
-  {
-    zr->list_it = NULL;
-
-    /* return static form */
-    GNUNET_asprintf (&full_page,
-                     ZONEINFO_PAGE,
-                     zr->zoneinfo,
-                     zr->zoneinfo);
-    response = MHD_create_response_from_buffer (strlen (full_page),
-                                             (void *) full_page,
-                                             MHD_RESPMEM_MUST_FREE);
-    MHD_add_response_header (response,
-                          MHD_HTTP_HEADER_CONTENT_TYPE,
-                          MIME_HTML);
-    MHD_queue_response (zr->connection,
-                           MHD_HTTP_OK,
-                           response);
-    MHD_destroy_response (response);
-    GNUNET_free (zr->zoneinfo);
-    GNUNET_free (zr);
-    run_httpd_now ();
-    return;
-  }
-
   if (1 != rd_len)
   {
     GNUNET_NAMESTORE_zone_iterator_next (zr->list_it);
@@ -354,8 +382,12 @@ serve_zoneinfo_page (struct MHD_Connection *connection)
   zr->write_offset = 0;
   zr->list_it = GNUNET_NAMESTORE_zone_iteration_start (ns,
                                                       &fcfs_zone_pkey,
+                                                       &zone_iteration_error,
+                                                       zr,
                                                       &iterate_cb,
-                                                      zr);
+                                                      zr,
+                                                       &zone_iteration_end,
+                                                       zr);
   return MHD_YES;
 }
 
@@ -511,6 +543,21 @@ put_continuation (void *cls,
 }
 
 
+/**
+ * Function called if we had an error in zone-to-name mapping.
+ */
+static void
+zone_to_name_error (void *cls)
+{
+  struct Request *request = cls;
+
+  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+              _("Error when mapping zone to name\n"));
+  request->phase = RP_FAIL;
+  run_httpd_now ();
+}
+
+
 /**
  * Test if a name mapping was found, if so, refuse.  If not, initiate storing of the record.
  *
@@ -529,6 +576,7 @@ zone_to_name_cb (void *cls,
 {
   struct Request *request = cls;
   struct GNUNET_GNSRECORD_Data r;
+
   request->qe = NULL;
 
   if (0 != rd_count)
@@ -540,15 +588,6 @@ zone_to_name_cb (void *cls,
     run_httpd_now ();
     return;
   }
-  if (NULL == zone_key)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                _("Error when mapping zone to name\n"));
-    request->phase = RP_FAIL;
-    run_httpd_now ();
-    return;
-  }
-
   r.data = &request->pub;
   r.data_size = sizeof (request->pub);
   r.expiration_time = UINT64_MAX;
@@ -563,6 +602,20 @@ zone_to_name_cb (void *cls,
 }
 
 
+/**
+ * We encountered an error in the name lookup.
+ */
+static void
+lookup_block_error (void *cls)
+{
+  struct Request *request = cls;
+
+  request->qe = NULL;
+  request->phase = RP_FAIL;
+  run_httpd_now ();
+}
+
+
 /**
  * We got a block back from the namestore.  Decrypt it
  * and continue to process the result.
@@ -585,7 +638,6 @@ lookup_block_processor (void *cls,
   request->qe = NULL;
   if (0 == rd_count)
   {
-
     if (GNUNET_OK !=
         GNUNET_CRYPTO_ecdsa_public_key_from_string (request->public_key,
                                                     strlen (request->public_key),
@@ -599,6 +651,8 @@ lookup_block_processor (void *cls,
     request->qe = GNUNET_NAMESTORE_zone_to_name (ns,
                                                  &fcfs_zone_pkey,
                                                  &request->pub,
+                                                 &zone_to_name_error,
+                                                 request,
                                                  &zone_to_name_cb,
                                                  request);
     return;
@@ -728,10 +782,12 @@ create_response (void *cls,
          }
          request->phase = RP_LOOKUP;
          request->qe = GNUNET_NAMESTORE_records_lookup (ns,
-                                                       &fcfs_zone_pkey,
-                                                       request->domain_name,
-                                                       &lookup_block_processor,
-                                                       request);
+                                                         &fcfs_zone_pkey,
+                                                         request->domain_name,
+                                                         &lookup_block_error,
+                                                         request,
+                                                         &lookup_block_processor,
+                                                         request);
          break;
        case RP_LOOKUP:
          break;
index 43cabed2acd2bd13e851409fcc05453646301e45..7a671f1b65da241716dc797abbd1bcdf01f12c61 100644 (file)
@@ -342,6 +342,31 @@ del_continuation (void *cls,
 }
 
 
+/**
+ * Function called when we are done with a zone iteration.
+ */
+static void
+zone_iteration_finished (void *cls)
+{
+  list_it = NULL;
+  test_finished ();
+}
+
+
+/**
+ * Function called when we encountered an error in a zone iteration.
+ */
+static void
+zone_iteration_error_cb (void *cls)
+{
+  list_it = NULL;
+  fprintf (stderr,
+           "Error iterating over zone\n");
+  ret = 1;
+  test_finished ();
+}
+
+
 /**
  * Process a record that was stored in the namestore.
  *
@@ -365,12 +390,6 @@ display_record (void *cls,
   struct GNUNET_TIME_Absolute at;
   struct GNUNET_TIME_Relative rt;
 
-  if (NULL == rname)
-  {
-    list_it = NULL;
-    test_finished ();
-    return;
-  }
   if ( (NULL != name) &&
        (0 != strcmp (name, rname)) )
   {
@@ -432,6 +451,31 @@ sync_cb (void *cls)
 }
 
 
+/**
+ * Function called on errors while monitoring.
+ *
+ * @param cls NULL
+ */
+static void
+monitor_error_cb (void *cls)
+{
+  FPRINTF (stderr, "%s", "Monitor disconnected and out of sync.\n");
+}
+
+
+/**
+ * Function called if lookup fails.
+ */
+static void
+lookup_error_cb (void *cls)
+{
+  add_qe = NULL;
+  GNUNET_break (0);
+  ret = 1;
+  test_finished ();
+}
+
+
 /**
  * We're storing a record; this function is given the existing record
  * so that we can merge the information.
@@ -454,8 +498,7 @@ get_existing_record (void *cls,
   unsigned int i;
 
   add_qe = NULL;
-  if ( (NULL != zone_key) &&
-       (0 != strcmp (rec_name, name)) )
+  if (0 != strcmp (rec_name, name))
   {
     GNUNET_break (0);
     ret = 1;
@@ -565,6 +608,19 @@ get_existing_record (void *cls,
 }
 
 
+/**
+ * Function called if we encountered an error in zone-to-name.
+ */
+static void
+reverse_error_cb (void *cls)
+{
+  reverse_qe = NULL;
+  FPRINTF (stdout,
+           "%s.zkey\n",
+           reverse_pkey);
+}
+
+
 /**
  * Function called with the result of our attempt to obtain a name for a given
  * public key.
@@ -595,6 +651,19 @@ handle_reverse_lookup (void *cls,
 }
 
 
+/**
+ * Function called if lookup for deletion fails.
+ */
+static void
+del_lookup_error_cb (void *cls)
+{
+  del_qe = NULL;
+  GNUNET_break (0);
+  ret = 1;
+  test_finished ();
+}
+
+
 /**
  * We were asked to delete something; this function is called with
  * the existing records. Now we should determine what should be
@@ -802,8 +871,13 @@ testservice_task (void *cls,
       ret = 1;
       return;
     }
-    add_qe = GNUNET_NAMESTORE_records_lookup (ns, &zone_pkey, name,
-        &get_existing_record, NULL );
+    add_qe = GNUNET_NAMESTORE_records_lookup (ns,
+                                              &zone_pkey,
+                                              name,
+                                              &lookup_error_cb,
+                                              NULL,
+                                              &get_existing_record,
+                                              NULL);
   }
   if (del)
   {
@@ -819,6 +893,8 @@ testservice_task (void *cls,
     del_qe = GNUNET_NAMESTORE_records_lookup (ns,
                                               &zone_pkey,
                                               name,
+                                              &del_lookup_error_cb,
+                                              NULL,
                                               &del_monitor,
                                               NULL);
   }
@@ -826,7 +902,11 @@ testservice_task (void *cls,
   {
     list_it = GNUNET_NAMESTORE_zone_iteration_start (ns,
                                                      &zone_pkey,
+                                                     &zone_iteration_error_cb,
+                                                     NULL,
                                                      &display_record,
+                                                     NULL,
+                                                     &zone_iteration_finished,
                                                      NULL);
   }
   if (NULL != reverse_pkey)
@@ -846,6 +926,8 @@ testservice_task (void *cls,
     reverse_qe = GNUNET_NAMESTORE_zone_to_name (ns,
                                                 &zone_pkey,
                                                 &pubkey,
+                                                &reverse_error_cb,
+                                                NULL,
                                                 &handle_reverse_lookup,
                                                 NULL);
   }
@@ -860,7 +942,10 @@ testservice_task (void *cls,
                         "gnunet://gns/%52s/%63s",
                         sh,
                         sname)) ) ||
-         (GNUNET_OK != GNUNET_CRYPTO_ecdsa_public_key_from_string (sh, strlen (sh), &pkey)) )
+         (GNUNET_OK !=
+          GNUNET_CRYPTO_ecdsa_public_key_from_string (sh,
+                                                      strlen (sh),
+                                                      &pkey)) )
     {
       fprintf (stderr,
                _("Invalid URI `%s'\n"),
@@ -912,7 +997,10 @@ testservice_task (void *cls,
     zm = GNUNET_NAMESTORE_zone_monitor_start (cfg,
                                              &zone_pkey,
                                               GNUNET_YES,
+                                              &monitor_error_cb,
+                                              NULL,
                                              &display_record,
+                                              NULL,
                                              &sync_cb,
                                              NULL);
   }
index b8da654ce3ee3e1d7dafb2634b3133f80b48b650..61d8385b6370dcd0f0d151d0dbd9181dbe88fb98 100644 (file)
@@ -83,6 +83,16 @@ struct GNUNET_NAMESTORE_QueueEntry
    */
   void *proc_cls;
 
+  /**
+   * Function to call on errors.
+   */
+  GNUNET_SCHEDULER_TaskCallback error_cb;
+
+  /**
+   * Closure for @e error_cb.
+   */
+  void *error_cb_cls;
+
   /**
    * Envelope of the message to send to the service, if not yet
    * sent.
@@ -118,6 +128,16 @@ struct GNUNET_NAMESTORE_ZoneIterator
    */
   struct GNUNET_NAMESTORE_Handle *h;
 
+  /**
+   * Function to call on completion.
+   */
+  GNUNET_SCHEDULER_TaskCallback finish_cb;
+
+  /**
+   * Closure for @e error_cb.
+   */
+  void *finish_cb_cls;
+
   /**
    * The continuation to call with the results
    */
@@ -128,6 +148,16 @@ struct GNUNET_NAMESTORE_ZoneIterator
    */
   void *proc_cls;
 
+  /**
+   * Function to call on errors.
+   */
+  GNUNET_SCHEDULER_TaskCallback error_cb;
+
+  /**
+   * Closure for @e error_cb.
+   */
+  void *error_cb_cls;
+
   /**
    * Envelope of the message to send to the service, if not yet
    * sent.
@@ -543,9 +573,11 @@ handle_record_result (void *cls,
                 ntohl (msg->gns_header.r_id));
   qe = find_qe (h,
                 ntohl (msg->gns_header.r_id));
-  if ( (NULL == ze) && (NULL == qe) )
+  if ( (NULL == ze) &&
+       (NULL == qe) )
     return; /* rid not found */
-  if ( (NULL != ze) && (NULL != qe) )
+  if ( (NULL != ze) &&
+       (NULL != qe) )
   {
     GNUNET_break (0);   /* rid ambigous */
     force_reconnect (h);
@@ -564,8 +596,8 @@ handle_record_result (void *cls,
       force_reconnect (h);
       return;
     }
-    if (NULL != ze->proc)
-      ze->proc (ze->proc_cls, NULL, NULL, 0, NULL);
+    if (NULL != ze->finish_cb)
+      ze->finish_cb (ze->finish_cb_cls);
     free_ze (ze);
     return;
   }
@@ -706,7 +738,8 @@ handle_zone_to_name_response (void *cls,
        qe->proc (qe->proc_cls,
                  &msg->zone,
                  name_tmp,
-                 rd_count, rd);
+                 rd_count,
+                  rd);
       /* return is important here: break would call continuation with error! */
       free_qe (qe);
       return;
@@ -717,8 +750,8 @@ handle_zone_to_name_response (void *cls,
     return;
   }
   /* error case, call continuation with error */
-  if (NULL != qe->proc)
-    qe->proc (qe->proc_cls, NULL, NULL, 0, NULL);
+  if (NULL != qe->error_cb)
+    qe->error_cb (qe->error_cb_cls);
   free_qe (qe);
 }
 
@@ -826,18 +859,18 @@ force_reconnect (struct GNUNET_NAMESTORE_Handle *h)
   h->mq = NULL;
   while (NULL != (ze = h->z_head))
   {
-    /* FIXME: This does not allow clients to distinguish
-       iteration error from successful termination! */
-    if (NULL != ze->proc)
-      ze->proc (ze->proc_cls, NULL, NULL, 0, NULL);
+    if (NULL != ze->error_cb)
+      ze->error_cb (ze->error_cb_cls);
     free_ze (ze);
   }
   while (NULL != (qe = h->op_head))
   {
-    /* FIXME: This does not allow clients to distinguish
-       iteration error from successful termination! */
-    if (NULL != qe->proc)
-      qe->proc (qe->proc_cls, NULL, NULL, 0, NULL);
+    if (NULL != qe->error_cb)
+      qe->error_cb (qe->error_cb_cls);
+    if (NULL != qe->cont)
+      qe->cont (qe->cont_cls,
+                GNUNET_SYSERR,
+                "failure in communication with namestore service");
     free_qe (qe);
   }
 
@@ -1058,6 +1091,8 @@ GNUNET_NAMESTORE_set_nick (struct GNUNET_NAMESTORE_Handle *h,
  * @param h handle to the namestore
  * @param pkey private key of the zone
  * @param label name that is being mapped (at most 255 characters long)
+ * @param error_cb function to call on error (i.e. disconnect)
+ * @param error_cb_cls closure for @a error_cb
  * @param rm function to call with the result (with 0 records if we don't have that label)
  * @param rm_cls closure for @a rm
  * @return handle to abort the request
@@ -1066,6 +1101,8 @@ struct GNUNET_NAMESTORE_QueueEntry *
 GNUNET_NAMESTORE_records_lookup (struct GNUNET_NAMESTORE_Handle *h,
                                  const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
                                  const char *label,
+                                 GNUNET_SCHEDULER_TaskCallback error_cb,
+                                 void *error_cb_cls,
                                  GNUNET_NAMESTORE_RecordMonitor rm,
                                  void *rm_cls)
 {
@@ -1082,6 +1119,8 @@ GNUNET_NAMESTORE_records_lookup (struct GNUNET_NAMESTORE_Handle *h,
 
   qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry);
   qe->h = h;
+  qe->error_cb = error_cb;
+  qe->error_cb_cls = error_cb_cls;
   qe->proc = rm;
   qe->proc_cls = rm_cls;
   qe->op_id = get_op_id(h);
@@ -1114,6 +1153,8 @@ GNUNET_NAMESTORE_records_lookup (struct GNUNET_NAMESTORE_Handle *h,
  * @param h handle to the namestore
  * @param zone public key of the zone to look up in, never NULL
  * @param value_zone public key of the target zone (value), never NULL
+ * @param error_cb function to call on error (i.e. disconnect)
+ * @param error_cb_cls closure for @a error_cb
  * @param proc function to call on the matching records, or with
  *        NULL (rd_count == 0) if there are no matching records
  * @param proc_cls closure for @a proc
@@ -1124,6 +1165,8 @@ struct GNUNET_NAMESTORE_QueueEntry *
 GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h,
                               const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
                               const struct GNUNET_CRYPTO_EcdsaPublicKey *value_zone,
+                               GNUNET_SCHEDULER_TaskCallback error_cb,
+                               void *error_cb_cls,
                               GNUNET_NAMESTORE_RecordMonitor proc,
                                void *proc_cls)
 {
@@ -1135,6 +1178,8 @@ GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h,
   rid = get_op_id(h);
   qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry);
   qe->h = h;
+  qe->error_cb = error_cb;
+  qe->error_cb_cls = error_cb_cls;
   qe->proc = proc;
   qe->proc_cls = proc_cls;
   qe->op_id = rid;
@@ -1166,26 +1211,39 @@ GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h,
  *
  * @param h handle to the namestore
  * @param zone zone to access, NULL for all zones
+ * @param error_cb function to call on error (i.e. disconnect)
+ * @param error_cb_cls closure for @a error_cb
  * @param proc function to call on each name from the zone; it
  *        will be called repeatedly with a value (if available)
- *        and always once at the end with a name of NULL.
  * @param proc_cls closure for @a proc
+ * @param finish_cb function to call on completion
+ * @param finish_cb_cls closure for @a finish_cb
  * @return an iterator handle to use for iteration
  */
 struct GNUNET_NAMESTORE_ZoneIterator *
 GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h,
                                       const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
+                                       GNUNET_SCHEDULER_TaskCallback error_cb,
+                                       void *error_cb_cls,
                                       GNUNET_NAMESTORE_RecordMonitor proc,
-                                      void *proc_cls)
+                                      void *proc_cls,
+                                       GNUNET_SCHEDULER_TaskCallback finish_cb,
+                                       void *finish_cb_cls)
 {
   struct GNUNET_NAMESTORE_ZoneIterator *it;
   struct GNUNET_MQ_Envelope *env;
   struct ZoneIterationStartMessage *msg;
   uint32_t rid;
 
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "Sending ZONE_ITERATION_START message\n");
   rid = get_op_id (h);
   it = GNUNET_new (struct GNUNET_NAMESTORE_ZoneIterator);
   it->h = h;
+  it->error_cb = error_cb;
+  it->error_cb_cls = error_cb_cls;
+  it->finish_cb = finish_cb;
+  it->finish_cb_cls = finish_cb_cls;
   it->proc = proc;
   it->proc_cls = proc_cls;
   it->op_id = rid;
index 85131f9ccb547e7e468fa5e9e476b711af10858f..7e75b07e54f4b3f938a82e34eae74ade85db6cc3 100644 (file)
@@ -50,20 +50,35 @@ struct GNUNET_NAMESTORE_ZoneMonitor
    */
   struct GNUNET_MQ_Handle *mq;
 
+  /**
+   * Function to call on errors.
+   */
+  GNUNET_SCHEDULER_TaskCallback error_cb;
+
+  /**
+   * Closure for @e error_cb.
+   */
+  void *error_cb_cls;
+
   /**
    * Function to call on events.
    */
   GNUNET_NAMESTORE_RecordMonitor monitor;
 
+  /**
+   * Closure for @e monitor.
+   */
+  void *monitor_cls;
+
   /**
    * Function called when we've synchronized.
    */
-  GNUNET_NAMESTORE_RecordsSynchronizedCallback sync_cb;
+  GNUNET_SCHEDULER_TaskCallback sync_cb;
 
   /**
-   * Closure for @e monitor and @e sync_cb.
+   * Closure for @e sync_cb.
    */
-  void *cls;
+  void *sync_cb_cls;
 
   /**
    * Monitored zone.
@@ -100,7 +115,7 @@ handle_sync (void *cls,
   struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls;
 
   if (NULL != zm->sync_cb)
-    zm->sync_cb (zm->cls);
+    zm->sync_cb (zm->sync_cb_cls);
 }
 
 
@@ -193,7 +208,7 @@ handle_result (void *cls,
                                                          rd_ser_tmp,
                                                          rd_count,
                                                          rd));
-    zm->monitor (zm->cls,
+    zm->monitor (zm->monitor_cls,
                 &lrm->private_key,
                 name_tmp,
                 rd_count,
@@ -245,11 +260,7 @@ reconnect (struct GNUNET_NAMESTORE_ZoneMonitor *zm)
   if (NULL != zm->mq)
   {
     GNUNET_MQ_destroy (zm->mq);
-    zm->monitor (zm->cls,
-                 NULL,
-                 NULL,
-                 0,
-                 NULL);
+    zm->error_cb (zm->error_cb_cls);
   }
   zm->mq = GNUNET_CLIENT_connecT (zm->cfg,
                                   "namestore",
@@ -278,18 +289,28 @@ reconnect (struct GNUNET_NAMESTORE_ZoneMonitor *zm)
  * @param zone zone to monitor
  * @param iterate_first #GNUNET_YES to first iterate over all existing records,
  *                      #GNUNET_NO to only return changes that happen from now on
+ * @param error_cb function to call on error (i.e. disconnect); note that
+ *         unlike the other error callbacks in this API, a call to this
+ *         function does NOT destroy the monitor handle, it merely signals
+ *         that monitoring is down. You need to still explicitly call
+ *         #GNUNET_NAMESTORE_zone_monitor_stop().
+ * @param error_cb_cls closure for @a error_cb
  * @param monitor function to call on zone changes
+ * @param monitor_cls closure for @a monitor
  * @param sync_cb function called when we're in sync with the namestore
- * @param cls closure for @a monitor and @a sync_cb
+ * @param cls closure for @a sync_cb
  * @return handle to stop monitoring
  */
 struct GNUNET_NAMESTORE_ZoneMonitor *
 GNUNET_NAMESTORE_zone_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
                                     const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
                                      int iterate_first,
+                                     GNUNET_SCHEDULER_TaskCallback error_cb,
+                                     void *error_cb_cls,
                                     GNUNET_NAMESTORE_RecordMonitor monitor,
-                                    GNUNET_NAMESTORE_RecordsSynchronizedCallback sync_cb,
-                                    void *cls)
+                                     void *monitor_cls,
+                                    GNUNET_SCHEDULER_TaskCallback sync_cb,
+                                    void *sync_cb_cls)
 {
   struct GNUNET_NAMESTORE_ZoneMonitor *zm;
 
@@ -297,9 +318,12 @@ GNUNET_NAMESTORE_zone_monitor_start (const struct GNUNET_CONFIGURATION_Handle *c
   if (NULL != zone)
     zm->zone = *zone;
   zm->iterate_first = iterate_first;
+  zm->error_cb = error_cb;
+  zm->error_cb_cls = error_cb_cls;
   zm->monitor = monitor;
+  zm->monitor_cls = monitor_cls;
   zm->sync_cb = sync_cb;
-  zm->cls = cls;
+  zm->sync_cb_cls = sync_cb_cls;
   zm->cfg = cfg;
   reconnect (zm);
   if (NULL == zm->mq)
index 35d3595ceea8857919440e8787a0573f811647f4..58ab46ca94951028545907ec77efc1c9cde65032 100644 (file)
@@ -387,6 +387,38 @@ cleanup_handle_delayed (void *cls)
 }
 
 
+/**
+ * Iteration over all results finished, build final
+ * response.
+ *
+ * @param cls the `struct RequestHandle`
+ */
+static void
+namestore_list_finished (void *cls)
+{
+  struct RequestHandle *handle = cls;
+  char *result;
+  struct MHD_Response *resp;
+
+  handle->list_it = NULL;
+  if (GNUNET_SYSERR ==
+      GNUNET_JSONAPI_document_serialize (handle->resp_object,
+                                         &result))
+  {
+    do_error (handle);
+    return;
+  }
+  resp = GNUNET_REST_create_response (result);
+  handle->proc (handle->proc_cls,
+                resp,
+                MHD_HTTP_OK);
+  GNUNET_free_non_null (result);
+  GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed,
+                            handle);
+}
+
+
+
 /**
  * Create a response with requested records
  *
@@ -401,31 +433,13 @@ namestore_list_response (void *cls,
 {
   struct RequestHandle *handle = cls;
   struct GNUNET_JSONAPI_Resource *json_resource;
-  struct MHD_Response *resp;
   json_t *result_array;
   json_t *record_obj;
   int i;
-  char *result;
 
   if (NULL == handle->resp_object)
     handle->resp_object = GNUNET_JSONAPI_document_new ();
 
-  if (NULL == rname)
-  {
-    handle->list_it = NULL;
-    //Handle response
-    if (GNUNET_SYSERR == GNUNET_JSONAPI_document_serialize (handle->resp_object, &result))
-    {
-      GNUNET_SCHEDULER_add_now (&do_error, handle);
-      return;
-    }
-    resp = GNUNET_REST_create_response (result);
-    handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
-    GNUNET_free_non_null (result);
-    GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
-    return;
-  }
-
   if ( (NULL != handle->name) &&
        (0 != strcmp (handle->name, rname)) )
   {
@@ -464,6 +478,7 @@ namestore_list_response (void *cls,
   GNUNET_NAMESTORE_zone_iterator_next (handle->list_it);
 }
 
+
 static void
 create_finished (void *cls, int32_t success, const char *emsg)
 {
@@ -506,11 +521,10 @@ create_new_record_cont (void *cls,
   struct RequestHandle *handle = cls;
 
   handle->add_qe = NULL;
-  if ( (NULL != zone_key) &&
-       (0 != strcmp (rec_name, handle->name)) )
+  if (0 != strcmp (rec_name, handle->name))
   {
     GNUNET_break (0);
-    GNUNET_SCHEDULER_add_now (&do_error, handle);
+    do_error (handle);
     return;
   }
 
@@ -533,6 +547,7 @@ create_new_record_cont (void *cls,
                                                    handle);
 }
 
+
 static void
 del_finished (void *cls,
               int32_t success,
@@ -565,6 +580,7 @@ del_finished (void *cls,
   GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
 }
 
+
 static void
 del_cont (void *cls,
           const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
@@ -573,13 +589,14 @@ del_cont (void *cls,
           const struct GNUNET_GNSRECORD_Data *rd)
 {
   struct RequestHandle *handle = cls;
+
   handle->add_qe = NULL;
   if (0 == rd_count)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 _("There are no records under label `%s' that could be deleted.\n"),
                 label);
-    GNUNET_SCHEDULER_add_now (&do_error, handle);
+    do_error (handle);
     return;
   }
 
@@ -591,6 +608,7 @@ del_cont (void *cls,
                                                    handle);
 }
 
+
 static void
 namestore_delete_cont (struct GNUNET_REST_RequestHandle *con,
                        const char *url,
@@ -607,10 +625,13 @@ namestore_delete_cont (struct GNUNET_REST_RequestHandle *con,
   handle->add_qe = GNUNET_NAMESTORE_records_lookup (handle->ns_handle,
                                                     &handle->zone_pkey,
                                                     handle->name,
+                                                    &do_error,
+                                                    handle,
                                                     &del_cont,
                                                     handle);
 }
 
+
 static int
 json_to_gnsrecord (const json_t *records_json,
                    struct GNUNET_GNSRECORD_Data **rd,
@@ -713,6 +734,7 @@ json_to_gnsrecord (const json_t *records_json,
   return GNUNET_OK;
 }
 
+
 static void
 namestore_create_cont (struct GNUNET_REST_RequestHandle *con,
                        const char *url,
@@ -730,7 +752,7 @@ namestore_create_cont (struct GNUNET_REST_RequestHandle *con,
     GNUNET_JSON_spec_jsonapi_document (&json_obj),
     GNUNET_JSON_spec_end()
   };
-  
+
   if (strlen (GNUNET_REST_API_NS_NAMESTORE) != strlen (handle->url))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -805,9 +827,13 @@ namestore_create_cont (struct GNUNET_REST_RequestHandle *con,
   handle->add_qe = GNUNET_NAMESTORE_records_lookup (handle->ns_handle,
                                                     &handle->zone_pkey,
                                                     handle->name,
-                                                    &create_new_record_cont, handle );
+                                                    &do_error,
+                                                    handle,
+                                                    &create_new_record_cont,
+                                                    handle);
 }
 
+
 static void
 namestore_zkey_response (void *cls,
                          const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
@@ -847,10 +873,9 @@ namestore_zkey_response (void *cls,
   GNUNET_JSONAPI_document_delete (json_obj);
   GNUNET_free (result);
   GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
-  return;
-
 }
 
+
 static void
 namestore_zkey_cont (struct GNUNET_REST_RequestHandle *con,
                      const char *url,
@@ -887,22 +912,31 @@ namestore_zkey_cont (struct GNUNET_REST_RequestHandle *con,
   handle->reverse_qe = GNUNET_NAMESTORE_zone_to_name (handle->ns_handle,
                                                       &handle->zone_pkey,
                                                       &pubkey,
+                                                      &do_error,
+                                                      handle,
                                                       &namestore_zkey_response,
                                                       handle);
 }
 
+
 static void
 namestore_info_cont (struct GNUNET_REST_RequestHandle *con,
                      const char *url,
                      void *cls)
 {
   struct RequestHandle *handle = cls;
+
   handle->list_it = GNUNET_NAMESTORE_zone_iteration_start (handle->ns_handle,
                                                            &handle->zone_pkey,
+                                                           &do_error,
+                                                           handle,
                                                            &namestore_list_response,
+                                                           handle,
+                                                           &namestore_list_finished,
                                                            handle);
 }
 
+
 static char*
 get_name_from_url (const char* url)
 {
index 5db120ea76c417763837b402a1626f88efe1cbe8..a1a674d893b4abdf850c2dc0735c1854417f82ec 100644 (file)
@@ -13,3 +13,6 @@ TEMPORARY_TABLE = YES
 
 [nse]
 WORKBITS = 0
+
+[transport]
+PLUGINS =
index d6d3945b7833d51d0d3abaad9f17349d27129e72..de958cee21e9a5840ec16da63487d6b74da5f815 100644 (file)
@@ -221,6 +221,13 @@ lookup_it (void *cls,
 }
 
 
+static void
+fail_cb (void *cls)
+{
+  GNUNET_assert (0);
+}
+
+
 static void
 put_cont (void *cls, int32_t success, const char *emsg)
 {
@@ -240,9 +247,16 @@ put_cont (void *cls, int32_t success, const char *emsg)
     return;
   }
   /* Lookup */
-  nsqe = GNUNET_NAMESTORE_records_lookup (nsh, privkey, name, lookup_it, NULL);
+  nsqe = GNUNET_NAMESTORE_records_lookup (nsh,
+                                          privkey,
+                                          name,
+                                          &fail_cb,
+                                          NULL,
+                                          &lookup_it,
+                                          NULL);
 }
 
+
 static void
 nick_cont (void *cls, int32_t success, const char *emsg)
 {
index 92b2cad6fd8df2941c1061d2a7d9ef6e865e7db9..57505c48bfffbae836d0a4ff56bfeaac1c2f9f74 100644 (file)
@@ -103,7 +103,9 @@ lookup_it (void *cls,
 {
   nsqe = NULL;
 
-  if (0 != memcmp(privkey, zone, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
+  if (0 != memcmp (privkey,
+                   zone,
+                   sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
   {
     GNUNET_break(0);
     GNUNET_SCHEDULER_cancel (endbadly_task);
@@ -143,6 +145,13 @@ lookup_it (void *cls,
 }
 
 
+static void
+fail_cb (void *cls)
+{
+  GNUNET_assert (0);
+}
+
+
 static void
 put_cont (void *cls, int32_t success, const char *emsg)
 {
@@ -162,7 +171,13 @@ put_cont (void *cls, int32_t success, const char *emsg)
     return;
   }
   /* Lookup */
-  nsqe = GNUNET_NAMESTORE_records_lookup (nsh, privkey, name, lookup_it, NULL);
+  nsqe = GNUNET_NAMESTORE_records_lookup (nsh,
+                                          privkey,
+                                          name,
+                                          &fail_cb,
+                                          NULL,
+                                          &lookup_it,
+                                          NULL);
 }
 
 
index 2ea271d50a8ffa4883bd6a46b5a708a4d283c781..efbd6badfa5cb6f9c9f5e9e7c80badbd5623f058 100644 (file)
@@ -215,11 +215,11 @@ put_cont (void *cls, int32_t success, const char *emsg)
   char *label = cls;
 
   if (0 == strcmp (label, s_name_1))
-       ns_ops[0] = NULL;
+    ns_ops[0] = NULL;
   else if (0 == strcmp (label, s_name_2))
-       ns_ops[1] = NULL;
+    ns_ops[1] = NULL;
   else if (0 == strcmp (label, s_name_3))
-       ns_ops[2] = NULL;
+    ns_ops[2] = NULL;
 
   if (success == GNUNET_OK)
   {
@@ -260,6 +260,20 @@ create_record (unsigned int count)
 }
 
 
+static void
+fail_cb (void *cls)
+{
+  GNUNET_assert (0);
+}
+
+
+static void
+sync_cb (void *cls)
+{
+  /* do nothing */
+}
+
+
 static void
 run (void *cls,
      const struct GNUNET_CONFIGURATION_Handle *cfg,
@@ -288,8 +302,11 @@ run (void *cls,
   zm = GNUNET_NAMESTORE_zone_monitor_start (cfg,
                                             privkey,
                                             GNUNET_YES,
+                                            &fail_cb,
+                                            NULL,
                                            &zone_proc,
                                            NULL,
+                                            &sync_cb,
                                            NULL);
   if (NULL == zm)
   {
index eae10e2ae8fff5b68d790d9540bb7862c5d93266..cd1838b5c649d24d7c1b092f528d799c1eacc791 100644 (file)
@@ -59,6 +59,7 @@ struct GNUNET_NAMESTORE_QueueEntry * ns_ops[3];
 
 static char *directory;
 
+
 static void
 do_shutdown ()
 {
@@ -204,7 +205,20 @@ zone_proc (void *cls,
     else
        GNUNET_SCHEDULER_add_now (&end, NULL);
   }
+}
+
 
+static void
+fail_cb (void *cls)
+{
+  GNUNET_assert (0);
+}
+
+
+static void
+sync_cb (void *cls)
+{
+  /* do nothing */
 }
 
 
@@ -240,8 +254,11 @@ put_cont (void *cls, int32_t success, const char *emsg)
     zm = GNUNET_NAMESTORE_zone_monitor_start (cfg,
                                               privkey,
                                               GNUNET_YES,
+                                              &fail_cb,
+                                              NULL,
                                               &zone_proc,
                                               NULL,
+                                              &sync_cb,
                                               NULL);
     if (NULL == zm)
     {
index 070c0687030d4c756d07ce4039a24c159ea445e9..8960be55d79d123a4b556c752c37fefc7da0702d 100644 (file)
@@ -155,6 +155,32 @@ end (void *cls)
 }
 
 
+static void
+zone_end (void *cls)
+{
+  GNUNET_break (3 == returned_records);
+  if (3 == returned_records)
+  {
+    res = 0; /* Last iteraterator callback, we are done */
+    zi = NULL;
+  }
+  else
+    res = 1;
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Received last result, iteration done after receing %u results\n",
+              returned_records);
+  GNUNET_SCHEDULER_add_now (&end, NULL);
+}
+
+
+static void
+fail_cb (void *cls)
+{
+  GNUNET_assert (0);
+}
+
+
 static void
 zone_proc (void *cls,
            const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
@@ -164,23 +190,6 @@ zone_proc (void *cls,
 {
   int failed = GNUNET_NO;
 
-  if ((zone == NULL) && (label == NULL))
-  {
-    GNUNET_break (3 == returned_records);
-    if (3 == returned_records)
-    {
-      res = 0; /* Last iteraterator callback, we are done */
-      zi = NULL;
-    }
-    else
-      res = 1;
-
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-               "Received last result, iteration done after receing %u results\n",
-               returned_records);
-    GNUNET_SCHEDULER_add_now (&end, NULL);
-    return;
-  }
   GNUNET_assert (NULL != zone);
   if (0 == memcmp (zone, privkey, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
   {
@@ -304,8 +313,12 @@ put_cont (void *cls, int32_t success, const char *emsg)
     returned_records = 0;
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All records created, starting iteration over all zones \n");
     zi = GNUNET_NAMESTORE_zone_iteration_start (nsh,
+                                                NULL,
+                                                &fail_cb,
                                                 NULL,
                                                 &zone_proc,
+                                                NULL,
+                                                &zone_end,
                                                 NULL);
     if (zi == NULL)
     {
@@ -352,8 +365,6 @@ empty_zone_proc (void *cls,
                 unsigned int rd_count,
                 const struct GNUNET_GNSRECORD_Data *rd)
 {
-  char *hostkey_file;
-
   GNUNET_assert (nsh == cls);
   if (NULL != zone)
   {
@@ -375,18 +386,31 @@ empty_zone_proc (void *cls,
     endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
     return;
   }
+  GNUNET_assert (0);
+}
 
 
+static void
+empty_zone_end (void *cls)
+{
+  char *hostkey_file;
+
   zi = NULL;
-  GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR,
-      "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
+  GNUNET_asprintf (&hostkey_file,
+                   "zonefiles%s%s",
+                   DIR_SEPARATOR_STR,
+                   "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Using zonekey file `%s' \n",
+              hostkey_file);
   privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
   GNUNET_free (hostkey_file);
   GNUNET_assert (privkey != NULL);
 
-  GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR,
-      "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
+  GNUNET_asprintf (&hostkey_file,
+                   "zonefiles%s%s",
+                   DIR_SEPARATOR_STR,
+                   "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
   privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
   GNUNET_free (hostkey_file);
@@ -396,7 +420,9 @@ empty_zone_proc (void *cls,
 
   GNUNET_asprintf(&s_name_1, "dummy1");
   s_rd_1 = create_record(1);
-  GNUNET_NAMESTORE_records_store (nsh, privkey, s_name_1,
+  GNUNET_NAMESTORE_records_store (nsh,
+                                  privkey,
+                                  s_name_1,
                                   1, s_rd_1,
                                   &put_cont, NULL);
 
@@ -404,8 +430,12 @@ empty_zone_proc (void *cls,
               "Created record 2 \n");
   GNUNET_asprintf(&s_name_2, "dummy2");
   s_rd_2 = create_record(1);
-  GNUNET_NAMESTORE_records_store (nsh, privkey, s_name_2,
-                                  1, s_rd_2, &put_cont, NULL);
+  GNUNET_NAMESTORE_records_store (nsh,
+                                  privkey,
+                                  s_name_2,
+                                  1, s_rd_2,
+                                  &put_cont,
+                                  NULL);
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Created record 3\n");
@@ -436,7 +466,13 @@ run (void *cls,
   GNUNET_break (NULL != nsh);
   /* first, iterate over empty namestore */
   zi = GNUNET_NAMESTORE_zone_iteration_start(nsh,
-                                            NULL, &empty_zone_proc, nsh);
+                                            NULL,
+                                             &fail_cb,
+                                             NULL,
+                                             &empty_zone_proc,
+                                             nsh,
+                                             &empty_zone_end,
+                                             NULL);
   if (NULL == zi)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone iterator\n");
index 362533ef9900575deff49320aeaa24894e88d653..791702f97022c9cd430cd057341c7698cd4acf30 100644 (file)
@@ -198,6 +198,18 @@ check_zone_2 (const char *label,
 }
 
 
+static void
+zone_proc_end (void *cls)
+{
+  zi = NULL;
+  res = 0;
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Received last result, iteration done after receing %u results\n",
+              returned_records);
+  GNUNET_SCHEDULER_add_now (&end, NULL);
+}
+
+
 static void
 zone_proc (void *cls,
            const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
@@ -206,16 +218,7 @@ zone_proc (void *cls,
            const struct GNUNET_GNSRECORD_Data *rd)
 {
   int failed = GNUNET_NO;
-  if ((zone == NULL) && (label == NULL))
-  {
-    zi = NULL;
-    res = 0;
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-               "Received last result, iteration done after receing %u results\n",
-               returned_records);
-    GNUNET_SCHEDULER_add_now (&end, NULL);
-    return;
-  }
+
   GNUNET_assert (NULL != zone);
   if (0 == memcmp (zone, privkey, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
   {
@@ -253,6 +256,13 @@ zone_proc (void *cls,
 }
 
 
+static void
+fail_cb (void *cls)
+{
+  GNUNET_assert (0);
+}
+
+
 static void
 put_cont (void *cls, int32_t success, const char *emsg)
 {
@@ -280,8 +290,12 @@ put_cont (void *cls, int32_t success, const char *emsg)
     returned_records = 0;
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All records created, starting iteration over all zones \n");
     zi = GNUNET_NAMESTORE_zone_iteration_start (nsh,
+                                                NULL,
+                                                &fail_cb,
                                                 NULL,
                                                 &zone_proc,
+                                                NULL,
+                                                &zone_proc_end,
                                                 NULL);
     if (zi == NULL)
     {
@@ -378,8 +392,8 @@ empty_zone_proc (void *cls,
                 unsigned int rd_count,
                 const struct GNUNET_GNSRECORD_Data *rd)
 {
-  char *hostkey_file;
   GNUNET_assert (nsh == cls);
+
   if (NULL != zone)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -400,6 +414,15 @@ empty_zone_proc (void *cls,
     endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
     return;
   }
+  GNUNET_assert (0);
+}
+
+
+static void
+empty_zone_end (void *cls)
+{
+  char *hostkey_file;
+  GNUNET_assert (nsh == cls);
 
   zi = NULL;
   GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR,
@@ -445,7 +468,13 @@ run (void *cls,
 
   /* first, iterate over empty namestore */
   zi = GNUNET_NAMESTORE_zone_iteration_start(nsh,
-                                            NULL, &empty_zone_proc, nsh);
+                                            NULL,
+                                             &fail_cb,
+                                             NULL,
+                                             &empty_zone_proc,
+                                             nsh,
+                                             &empty_zone_end,
+                                             nsh);
   if (NULL == zi)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
index 1a0279f502aa19f124ba5d428542284a665fc0f7..c5ae927b0a8aa2ed05bc1003c6851b8af9db8c25 100644 (file)
@@ -155,31 +155,22 @@ end (void *cls)
 }
 
 
+static void
+fail_cb (void *cls)
+{
+  GNUNET_assert (0);
+}
+
+
 static void
 zone_proc (void *cls,
-                                        const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
-                                        const char *label,
-                                        unsigned int rd_count,
-                                        const struct GNUNET_GNSRECORD_Data *rd)
+           const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
+           const char *label,
+           unsigned int rd_count,
+           const struct GNUNET_GNSRECORD_Data *rd)
 {
   int failed = GNUNET_NO;
-  if ((zone == NULL) && (label == NULL))
-  {
-    GNUNET_break (2 == returned_records);
-    if (2 == returned_records)
-    {
-      res = 0; /* Last iteraterator callback, we are done */
-      zi = NULL;
-    }
-    else
-      res = 1;
 
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-               "Received last result, iteration done after receing %u results\n",
-               returned_records );
-    GNUNET_SCHEDULER_add_now (&end, NULL);
-    return;
-  }
   GNUNET_assert (NULL != zone);
   if (0 == memcmp (zone,
                    privkey,
@@ -257,6 +248,25 @@ zone_proc (void *cls,
 }
 
 
+static void
+zone_proc_end (void *cls)
+{
+  GNUNET_break (2 == returned_records);
+  if (2 == returned_records)
+  {
+    res = 0; /* Last iteraterator callback, we are done */
+    zi = NULL;
+  }
+  else
+    res = 1;
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Received last result, iteration done after receing %u results\n",
+              returned_records);
+  GNUNET_SCHEDULER_add_now (&end, NULL);
+}
+
+
 static void
 put_cont (void *cls, int32_t success, const char *emsg)
 {
@@ -288,8 +298,12 @@ put_cont (void *cls, int32_t success, const char *emsg)
                 "All records created, starting iteration over all zones \n");
     zi = GNUNET_NAMESTORE_zone_iteration_start(nsh,
                                               privkey,
+                                               &fail_cb,
+                                               NULL,
                                               &zone_proc,
-                                              NULL);
+                                              NULL,
+                                               &zone_proc_end,
+                                               NULL);
     if (zi == NULL)
     {
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -336,42 +350,55 @@ empty_zone_proc (void *cls,
                 unsigned int rd_count,
                 const struct GNUNET_GNSRECORD_Data *rd)
 {
-  char *hostkey_file;
-
   GNUNET_assert (nsh == cls);
   if (NULL != zone)
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                  _("Expected empty zone but received zone private key\n"));
-      GNUNET_break (0);
-      if (endbadly_task != NULL)
-       GNUNET_SCHEDULER_cancel (endbadly_task);
-      endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
-      return;
-    }
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                _("Expected empty zone but received zone private key\n"));
+    GNUNET_break (0);
+    if (endbadly_task != NULL)
+      GNUNET_SCHEDULER_cancel (endbadly_task);
+    endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+    return;
+  }
   if ((NULL != label) || (NULL != rd) || (0 != rd_count))
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                  _("Expected no zone content but received data\n"));
-      GNUNET_break (0);
-      if (endbadly_task != NULL)
-       GNUNET_SCHEDULER_cancel (endbadly_task);
-      endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
-      return;
-    }
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                _("Expected no zone content but received data\n"));
+    GNUNET_break (0);
+    if (endbadly_task != NULL)
+      GNUNET_SCHEDULER_cancel (endbadly_task);
+    endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+    return;
+  }
+  GNUNET_assert (0);
+}
 
 
+static void
+empty_zone_proc_end (void *cls)
+{
+  char *hostkey_file;
+
   zi = NULL;
-  GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR,
-      "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
-  privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
+  GNUNET_asprintf (&hostkey_file,
+                   "zonefiles%s%s",
+                   DIR_SEPARATOR_STR,
+                   "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Using zonekey file `%s'\n",
+              hostkey_file);
+  privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
   GNUNET_free (hostkey_file);
   GNUNET_assert (privkey != NULL);
 
-  GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR,
-      "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
+  GNUNET_asprintf(&hostkey_file,
+                  "zonefiles%s%s",
+                  DIR_SEPARATOR_STR,
+                  "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Using zonekey file `%s' \n",
+              hostkey_file);
   privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
   GNUNET_free (hostkey_file);
   GNUNET_assert (privkey2 != NULL);
@@ -380,25 +407,39 @@ empty_zone_proc (void *cls,
               "Created record 1\n");
 
   GNUNET_asprintf(&s_name_1, "dummy1");
-  s_rd_1 = create_record(1);
-  GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_1,
-               1, s_rd_1, &put_cont, NULL);
+  s_rd_1 = create_record (1);
+  GNUNET_NAMESTORE_records_store (nsh,
+                                  privkey,
+                                  s_name_1,
+                                  1,
+                                  s_rd_1,
+                                  &put_cont,
+                                  NULL);
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Created record 2 \n");
   GNUNET_asprintf(&s_name_2, "dummy2");
-  s_rd_2 = create_record(1);
-  GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_2,
-               1, s_rd_2, &put_cont, NULL);
+  s_rd_2 = create_record (1);
+  GNUNET_NAMESTORE_records_store (nsh,
+                                  privkey,
+                                  s_name_2,
+                                  1,
+                                  s_rd_2,
+                                  &put_cont,
+                                  NULL);
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Created record 3\n");
 
   /* name in different zone */
   GNUNET_asprintf(&s_name_3, "dummy3");
-  s_rd_3 = create_record(1);
-  GNUNET_NAMESTORE_records_store(nsh, privkey2, s_name_3,
-               1, s_rd_3, &put_cont, NULL);
+  s_rd_3 = create_record (1);
+  GNUNET_NAMESTORE_records_store (nsh,
+                                  privkey2,
+                                  s_name_3,
+                                  1, s_rd_3,
+                                  &put_cont,
+                                  NULL);
 }
 
 
@@ -423,7 +464,12 @@ run (void *cls,
   /* first, iterate over empty namestore */
   zi = GNUNET_NAMESTORE_zone_iteration_start (nsh,
                                               NULL,
-                                              &empty_zone_proc, nsh);
+                                              &fail_cb,
+                                              NULL,
+                                              &empty_zone_proc,
+                                              nsh,
+                                              &empty_zone_proc_end,
+                                              nsh);
   if (NULL == zi)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
index 36f527da0024b400293bb96a297776a979e624cb..a5f040150301a85f2a42b1ce2b26f5deeb013df9 100644 (file)
@@ -155,6 +155,13 @@ end (void *cls)
 }
 
 
+static void
+fail_cb (void *cls)
+{
+  GNUNET_assert (0);
+}
+
+
 static void
 zone_proc (void *cls,
            const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
@@ -163,20 +170,7 @@ zone_proc (void *cls,
            const struct GNUNET_GNSRECORD_Data *rd)
 {
   int failed = GNUNET_NO;
-  if ((zone == NULL) && (label == NULL))
-  {
-    GNUNET_break (1 <= returned_records);
-    if (1 >= returned_records)
-       res = 1; /* Last iteraterator callback, we are done */
-    else
-      res = 0;
-    zi = NULL;
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-               "Received last result, iteration done after receing %u results\n",
-               returned_records );
-    GNUNET_SCHEDULER_add_now (&end, NULL);
-    return;
-  }
+
   GNUNET_assert (NULL != zone);
   if (0 == memcmp (zone, privkey, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
   {
@@ -287,6 +281,22 @@ zone_proc (void *cls,
 }
 
 
+static void
+zone_proc_end (void *cls)
+{
+  GNUNET_break (1 <= returned_records);
+  if (1 >= returned_records)
+    res = 1; /* Last iteraterator callback, we are done */
+  else
+    res = 0;
+  zi = NULL;
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Received last result, iteration done after receing %u results\n",
+              returned_records);
+  GNUNET_SCHEDULER_add_now (&end, NULL);
+}
+
+
 static void
 put_cont (void *cls, int32_t success, const char *emsg)
 {
@@ -312,14 +322,20 @@ put_cont (void *cls, int32_t success, const char *emsg)
   {
     res = 1;
     returned_records = 0;
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All records created, starting iteration over all zones \n");
-    zi = GNUNET_NAMESTORE_zone_iteration_start(nsh,
-                                              NULL,
-                                              &zone_proc,
-                                              NULL);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "All records created, starting iteration over all zones \n");
+    zi = GNUNET_NAMESTORE_zone_iteration_start (nsh,
+                                                NULL,
+                                                &fail_cb,
+                                                NULL,
+                                                &zone_proc,
+                                                NULL,
+                                                &zone_proc_end,
+                                                NULL);
     if (zi == NULL)
     {
-      GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone iterator\n");
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  "Failed to create zone iterator\n");
       GNUNET_break (0);
       if (NULL != endbadly_task)
        GNUNET_SCHEDULER_cancel (endbadly_task);
@@ -362,7 +378,6 @@ empty_zone_proc (void *cls,
                 unsigned int rd_count,
                 const struct GNUNET_GNSRECORD_Data *rd)
 {
-  char *hostkey_file;
 
   GNUNET_assert (nsh == cls);
   if (NULL != zone)
@@ -385,42 +400,72 @@ empty_zone_proc (void *cls,
     endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
     return;
   }
+  GNUNET_assert (0);
+}
+
 
+static void
+empty_zone_proc_end (void *cls)
+{
+  char *hostkey_file;
+
+  GNUNET_assert (nsh == cls);
   zi = NULL;
-  GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR,
-      "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
+  GNUNET_asprintf(&hostkey_file,
+                  "zonefiles%s%s",
+                  DIR_SEPARATOR_STR,
+                  "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Using zonekey file `%s' \n",
+              hostkey_file);
   privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
   GNUNET_free (hostkey_file);
   GNUNET_assert (privkey != NULL);
 
-  GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR,
-      "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
+  GNUNET_asprintf (&hostkey_file,
+                   "zonefiles%s%s",
+                   DIR_SEPARATOR_STR,
+                   "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Using zonekey file `%s'\n",
+              hostkey_file);
   privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
   GNUNET_free (hostkey_file);
   GNUNET_assert (privkey2 != NULL);
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Created record 1\n");
 
-  GNUNET_asprintf(&s_name_1, "dummy1");
+  GNUNET_asprintf(&s_name_1,
+                  "dummy1");
   s_rd_1 = create_record(1);
   GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_1,
                1, s_rd_1, &put_cont, NULL);
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n");
-  GNUNET_asprintf(&s_name_2, "dummy2");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Created record 2 \n");
+  GNUNET_asprintf(&s_name_2,
+                  "dummy2");
   s_rd_2 = create_record(1);
-  GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_2,
-               1, s_rd_2, &put_cont, NULL);
+  GNUNET_NAMESTORE_records_store (nsh,
+                                  privkey,
+                                  s_name_2,
+                                  1,
+                                  s_rd_2,
+                                  &put_cont, NULL);
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 3\n");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Created record 3\n");
 
   /* name in different zone */
   GNUNET_asprintf(&s_name_3, "dummy3");
   s_rd_3 = create_record(1);
-  GNUNET_NAMESTORE_records_store(nsh, privkey2, s_name_3,
-               1, s_rd_3, &put_cont, NULL);
+  GNUNET_NAMESTORE_records_store(nsh,
+                                 privkey2,
+                                 s_name_3,
+                                 1,
+                                 s_rd_3,
+                                 &put_cont, NULL);
 }
 
 
@@ -441,7 +486,13 @@ run (void *cls,
   GNUNET_break (NULL != nsh);
   /* first, iterate over empty namestore */
   zi = GNUNET_NAMESTORE_zone_iteration_start(nsh,
-                                            NULL, &empty_zone_proc, nsh);
+                                            NULL,
+                                             &fail_cb,
+                                             NULL,
+                                             &empty_zone_proc,
+                                             nsh,
+                                             &empty_zone_proc_end,
+                                             nsh);
   if (NULL == zi)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,