- extradist and hashmap
authorMatthias Wachs <wachs@net.in.tum.de>
Thu, 8 Mar 2012 17:58:05 +0000 (17:58 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Thu, 8 Mar 2012 17:58:05 +0000 (17:58 +0000)
src/namestore/Makefile.am
src/namestore/gnunet-service-namestore.c

index 958b7d89b4e3f819b88e6f45d7b28377a0a8ea71..7a54bb7d8db3d78a8c1fa340058c8f04d78f3e79 100644 (file)
@@ -193,8 +193,8 @@ test_namestore_record_serialization_LDADD = \
 EXTRA_DIST = \
   test_namestore_api.conf \
   test_plugin_namestore_sqlite.conf\
-  hostkey \
-  hostkey2
+  zonefiles/4UCICULTINKC87UO4326KEEDQ9MTEP2AJT88MJFVGTGNK12QNGMQI2S41VI07UUU6EO19BTB06PDL0HE6VP1OM50HOJEI75RHP4JP80.zone \
+  zonefiles/KJI3AL00K91EDPFJF58DAJM7H61D189TLP70N56JL8SVDCJE1SJ3SNNBOQPPONTL37FMHPS39SMK2NMVC0GQMGA6QCMHITT78O8GF80.zone
 
 
 test_plugin_namestore_sqlite_SOURCES = \
index 633cea41100ef0413f6e42292321b01630a8a2bd..406480ba11033d21d11d2233cfdd27d47d60e010 100644 (file)
@@ -71,9 +71,6 @@ struct GNUNET_NAMESTORE_Client
 
 struct GNUNET_NAMESTORE_CryptoContainer
 {
-  struct GNUNET_NAMESTORE_CryptoContainer *next;
-  struct GNUNET_NAMESTORE_CryptoContainer *prev;
-
   char * filename;
 
   GNUNET_HashCode zone;
@@ -108,8 +105,7 @@ static struct GNUNET_SERVER_NotificationContext *snc;
 static struct GNUNET_NAMESTORE_Client *client_head;
 static struct GNUNET_NAMESTORE_Client *client_tail;
 
-struct GNUNET_NAMESTORE_CryptoContainer *c_head;
-struct GNUNET_NAMESTORE_CryptoContainer *c_tail;
+struct GNUNET_CONTAINER_MultiHashMap *zonekeys;
 
 
 /**
@@ -192,6 +188,29 @@ int write_key_to_file (const char *filename, struct GNUNET_NAMESTORE_CryptoConta
   return GNUNET_OK;
 }
 
+int zone_to_disk_it (void *cls,
+                     const GNUNET_HashCode * key,
+                     void *value)
+{
+  struct GNUNET_NAMESTORE_CryptoContainer * c = value;
+
+  if (c->filename != NULL)
+    write_key_to_file(c->filename, c);
+  else
+  {
+    GNUNET_asprintf(&c->filename, "%s/%s.zone", zonefile_directory, GNUNET_h2s_full (&c->zone));
+    write_key_to_file(c->filename, c);
+  }
+
+  GNUNET_CONTAINER_multihashmap_remove (zonekeys, key, value);;
+  GNUNET_CRYPTO_rsa_key_free(c->privkey);
+  GNUNET_free (c->pubkey);
+  GNUNET_free(c->filename);
+  GNUNET_free (c);
+
+  return GNUNET_OK;
+}
+
 
 /**
  * Task run during shutdown.
@@ -207,27 +226,11 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   struct GNUNET_NAMESTORE_ZoneIteration * tmp;
   struct GNUNET_NAMESTORE_Client * nc;
   struct GNUNET_NAMESTORE_Client * next;
-  struct GNUNET_NAMESTORE_CryptoContainer *c;
 
   GNUNET_SERVER_notification_context_destroy (snc);
   snc = NULL;
 
-  for (c = c_head; c != NULL; c = c_head)
-  {
-    if (c->filename != NULL)
-      write_key_to_file(c->filename, c);
-    else
-    {
-      GNUNET_asprintf(&c->filename, "%s/%s.zone", zonefile_directory, GNUNET_h2s_full (&c->zone));
-      write_key_to_file(c->filename, c);
-    }
-
-    GNUNET_CONTAINER_DLL_remove(c_head, c_tail, c);
-    GNUNET_CRYPTO_rsa_key_free(c->privkey);
-    GNUNET_free (c->pubkey);
-    GNUNET_free(c->filename);
-    GNUNET_free (c);
-  }
+  GNUNET_CONTAINER_multihashmap_iterate(zonekeys, &zone_to_disk_it, NULL);
 
   for (nc = client_head; nc != NULL; nc = next)
   {
@@ -1544,7 +1547,7 @@ int zonekey_file_it (void *cls, const char *filename)
 
      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found zonefile for zone `%s'\n", GNUNET_h2s (&c->zone));
 
-     GNUNET_CONTAINER_DLL_insert(c_head, c_tail, c);
+     GNUNET_CONTAINER_multihashmap_put(zonekeys, &c->zone, c, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
      (*counter) ++;
    }
    return GNUNET_OK;
@@ -1612,6 +1615,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
   }
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Scanning directory `%s' for zone files\n", zonefile_directory);
+  zonekeys = GNUNET_CONTAINER_multihashmap_create (10);
   GNUNET_DISK_directory_scan (zonefile_directory, zonekey_file_it, &counter);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found %u zone files\n", counter);