*/
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
{
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)
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;
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
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;
}