gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [gnunet] branch master updated: fix context for zone_to_nam


From: gnunet
Subject: [GNUnet-SVN] [gnunet] branch master updated: fix context for zone_to_name flat plugin
Date: Wed, 09 May 2018 18:09:57 +0200

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository gnunet.

The following commit(s) were added to refs/heads/master by this push:
     new 466c9bd9b fix context for zone_to_name flat plugin
466c9bd9b is described below

commit 466c9bd9bc750b3c763d3ca3bcab1277ba73ee13
Author: Christian Grothoff <address@hidden>
AuthorDate: Wed May 9 18:09:54 2018 +0200

    fix context for zone_to_name flat plugin
---
 src/namestore/plugin_namestore_flat.c              | 88 ++++++++--------------
 .../test_namestore_api_monitoring_existing.c       | 27 +++++--
 2 files changed, 53 insertions(+), 62 deletions(-)

diff --git a/src/namestore/plugin_namestore_flat.c 
b/src/namestore/plugin_namestore_flat.c
index df9f424a6..c464d4e68 100644
--- a/src/namestore/plugin_namestore_flat.c
+++ b/src/namestore/plugin_namestore_flat.c
@@ -49,41 +49,6 @@ struct Plugin
    */
   struct GNUNET_CONTAINER_MultiHashMap *hm;
 
-  /**
-   * Offset
-   */
-  uint32_t offset;
-
-  /**
-   * Target Offset
-   */
-  uint32_t target_offset;
-
-  /**
-   * Iterator closure
-   */
-  void *iter_cls;
-
-  /**
-   * Iterator
-   */
-  GNUNET_NAMESTORE_RecordIterator iter;
-
-  /**
-   * Zone to iterate
-   */
-  const struct GNUNET_CRYPTO_EcdsaPrivateKey *iter_zone;
-
-  /**
-   * PKEY to look for in zone to name
-   */
-  const struct GNUNET_CRYPTO_EcdsaPublicKey *iter_pkey;
-
-  /**
-   * Iteration result found
-   */
-  int iter_result_found;
-
 };
 
 
@@ -670,17 +635,31 @@ namestore_flat_iterate_records (void *cls,
 }
 
 
+/**
+ * Closure for #zone_to_name.
+ */
+struct ZoneToNameContext
+{
+  const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone;
+  const struct GNUNET_CRYPTO_EcdsaPublicKey *value_zone;
+  GNUNET_NAMESTORE_RecordIterator iter;
+  void *iter_cls;
+
+  int result_found;
+};
+
+
 static int
 zone_to_name (void *cls,
               const struct GNUNET_HashCode *key,
               void *value)
 {
-  struct Plugin *plugin = cls;
+  struct ZoneToNameContext *ztn = cls;
   struct FlatFileEntry *entry = value;
 
   (void) key;
   if (0 != memcmp (entry->private_key,
-                   plugin->iter_zone,
+                   ztn->zone,
                    sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
     return GNUNET_YES;
 
@@ -688,18 +667,17 @@ zone_to_name (void *cls,
   {
     if (GNUNET_GNSRECORD_TYPE_PKEY != entry->record_data[i].record_type)
       continue;
-    if (0 == memcmp (plugin->iter_pkey,
+    if (0 == memcmp (ztn->value_zone,
                      entry->record_data[i].data,
                      sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)))
     {
-      plugin->iter (plugin->iter_cls,
-                   0,
-                    entry->private_key,
-                    entry->label,
-                    entry->record_count,
-                    entry->record_data);
-      plugin->iter_result_found = GNUNET_YES;
-
+      ztn->iter (ztn->iter_cls,
+                 0,
+                 entry->private_key,
+                 entry->label,
+                 entry->record_count,
+                 entry->record_data);
+      ztn->result_found = GNUNET_YES;
     }
   }
   return GNUNET_YES;
@@ -725,21 +703,21 @@ namestore_flat_zone_to_name (void *cls,
                              void *iter_cls)
 {
   struct Plugin *plugin = cls;
+  struct ZoneToNameContext ztn = {
+    .iter = iter,
+    .iter_cls = iter_cls,
+    .zone = zone,
+    .value_zone = value_zone,
+    .result_found = GNUNET_NO
+  };
 
-  /* FIXME: maybe use separate closure to better handle
-     recursive calls? */
-  plugin->iter = iter;
-  plugin->iter_cls = iter_cls;
-  plugin->iter_zone = zone;
-  plugin->iter_pkey = value_zone;
-  plugin->iter_result_found = GNUNET_NO;
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Performing reverse lookup for `%s'\n",
               GNUNET_GNSRECORD_z2s (value_zone));
   GNUNET_CONTAINER_multihashmap_iterate (plugin->hm,
                                          &zone_to_name,
-                                         plugin);
-  return plugin->iter_result_found;
+                                         &ztn);
+  return ztn.result_found;
 }
 
 
diff --git a/src/namestore/test_namestore_api_monitoring_existing.c 
b/src/namestore/test_namestore_api_monitoring_existing.c
index 3e9e70923..449b36d65 100644
--- a/src/namestore/test_namestore_api_monitoring_existing.c
+++ b/src/namestore/test_namestore_api_monitoring_existing.c
@@ -337,16 +337,29 @@ run (void *cls,
   /* name in different zone */
   GNUNET_asprintf(&s_name_3, "dummy3");
   s_rd_3 = create_record(1);
-  GNUNET_assert (NULL != (ns_ops[2] = GNUNET_NAMESTORE_records_store (nsh, 
privkey2, s_name_3,
-               1, s_rd_3, &put_cont, s_name_3)));
+  GNUNET_assert (NULL != (ns_ops[2] =
+                          GNUNET_NAMESTORE_records_store (nsh,
+                                                          privkey2,
+                                                          s_name_3,
+                                                          1,
+                                                          s_rd_3,
+                                                          &put_cont,
+                                                          s_name_3)));
 
-  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");
   s_rd_1 = create_record(1);
-  GNUNET_assert (NULL != (ns_ops[0] = GNUNET_NAMESTORE_records_store(nsh, 
privkey, s_name_1,
-               1, s_rd_1, &put_cont, s_name_1)));
-
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n");
+  GNUNET_assert (NULL != (ns_ops[0] =
+                          GNUNET_NAMESTORE_records_store(nsh,
+                                                         privkey,
+                                                         s_name_1,
+                                                         1,
+                                                         s_rd_1,
+                                                         &put_cont,
+                                                         s_name_1)));
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Created record 2 \n");
   GNUNET_asprintf(&s_name_2, "dummy2");
   s_rd_2 = create_record(1);
   GNUNET_assert (NULL != (ns_ops[1] =

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]