From 315beeea8ed2660629bdd2a3346b74584b9939bc Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Mon, 16 Jul 2012 13:56:55 +0000 Subject: [PATCH] - namestore uses new rsa api --- src/namestore/gnunet-service-namestore.c | 74 +++++++++++++++++++++--- 1 file changed, 65 insertions(+), 9 deletions(-) diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c index 7609c73a3..e3d99e2bd 100644 --- a/src/namestore/gnunet-service-namestore.c +++ b/src/namestore/gnunet-service-namestore.c @@ -191,6 +191,26 @@ static struct GNUNET_NAMESTORE_Client *client_tail; */ 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 @@ -382,6 +402,7 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { 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 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 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,6 +2119,29 @@ handle_iteration_next (void *cls, 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 @@ handle_iteration_next (void *cls, 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; } -- 2.25.1