gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r22704 - gnunet/src/namestore


From: gnunet
Subject: [GNUnet-SVN] r22704 - gnunet/src/namestore
Date: Mon, 16 Jul 2012 15:56:55 +0200

Author: wachs
Date: 2012-07-16 15:56:55 +0200 (Mon, 16 Jul 2012)
New Revision: 22704

Modified:
   gnunet/src/namestore/gnunet-service-namestore.c
Log:
- namestore uses new rsa api

Modified: gnunet/src/namestore/gnunet-service-namestore.c
===================================================================
--- gnunet/src/namestore/gnunet-service-namestore.c     2012-07-16 13:10:25 UTC 
(rev 22703)
+++ gnunet/src/namestore/gnunet-service-namestore.c     2012-07-16 13:56:55 UTC 
(rev 22704)
@@ -191,8 +191,28 @@
  */
 static struct GNUNET_CONTAINER_MultiHashMap *zonekeys;
 
+/**
+ * DLL head for key loading contexts
+ */
+static struct KeyLoadContext *kl_head;
 
 /**
+ * DLL tail for key loading contexts
+ */
+static struct KeyLoadContext *kl_tail;
+
+struct KeyLoadContext
+{
+  struct KeyLoadContext *next;
+  struct KeyLoadContext *prev;
+  struct GNUNET_CRYPTO_RsaKeyGenerationContext *keygen;
+  char *filename;
+  unsigned int *counter;
+};
+
+
+
+/**
  * Writes the encrypted private key of a zone in a file
  *
  * @param filename where to store the zone
@@ -382,6 +402,7 @@
 {
   struct GNUNET_NAMESTORE_ZoneIteration *no;
   struct GNUNET_NAMESTORE_Client *nc;
+  struct KeyLoadContext *kl;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping namestore service\n");
   if (NULL != snc)
@@ -389,6 +410,16 @@
     GNUNET_SERVER_notification_context_destroy (snc);
     snc = NULL;
   }
+
+  while (NULL != (kl = kl_head))
+  {
+    GNUNET_CONTAINER_DLL_remove (kl_head, kl_tail, kl);
+    if (NULL != kl->keygen)
+      GNUNET_CRYPTO_rsa_key_create_stop (kl->keygen);
+    GNUNET_free (kl->filename);
+    GNUNET_free (kl);
+  }
+
   GNUNET_CONTAINER_multihashmap_iterate (zonekeys, &zone_to_disk_it, NULL);
   GNUNET_CONTAINER_multihashmap_destroy (zonekeys);
   zonekeys = NULL;
@@ -2088,7 +2119,30 @@
   GNUNET_SERVER_receive_done (client, GNUNET_OK);
 }
 
+static void
+zonekey_it_key_cb (void *cls,
+                   struct GNUNET_CRYPTO_RsaPrivateKey *pk,
+                   const char *emsg)
+{
+  struct KeyLoadContext *kl = cls;
 
+  kl->keygen = NULL;
+  if (NULL == pk)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                _("Could not parse zone key file `%s'\n"),
+                kl->filename);
+    return;
+  }
+  learn_private_key (pk);
+  (*kl->counter) ++;
+
+  GNUNET_CONTAINER_DLL_remove (kl_head, kl_tail, kl);
+  GNUNET_free (kl->filename);
+  GNUNET_free (kl);
+}
+
+
 /**
  * Load zone keys from directory by reading all .zkey files in this directory
  *
@@ -2099,22 +2153,24 @@
 static int
 zonekey_file_it (void *cls, const char *filename)
 {
-  unsigned int *counter = cls;
-  struct GNUNET_CRYPTO_RsaPrivateKey *privkey;
+  struct KeyLoadContext *kl;
 
   if ((NULL == filename) ||
       (NULL == strstr(filename, ".zkey")))
     return GNUNET_OK;
-  privkey = GNUNET_CRYPTO_rsa_key_create_from_file (filename);
-  if (NULL == privkey)
+
+  kl = GNUNET_malloc (sizeof (struct KeyLoadContext));
+  kl->filename = strdup (filename);
+  kl->counter = cls;
+  kl->keygen = GNUNET_CRYPTO_rsa_key_create_start (filename, 
zonekey_it_key_cb, kl);
+  if (NULL == kl->keygen)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-               _("Could not parse zone key file `%s'\n"),
-               filename);
+    GNUNET_free (kl);
+    GNUNET_free (kl->filename);
     return GNUNET_OK;
   }
-  learn_private_key (privkey);
-  (*counter)++;
+
+  GNUNET_CONTAINER_DLL_insert (kl_head, kl_tail, kl);
   return GNUNET_OK;
 }
 




reply via email to

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