summaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
authorMarcello Stanisci <marcello.stanisci@inria.fr>2016-09-23 17:26:40 +0200
committerMarcello Stanisci <marcello.stanisci@inria.fr>2016-09-23 17:26:40 +0200
commit12c2c08fc846ef55758601b8141fa457d7094d0e (patch)
treeb842f33cbb31c5bdc79ab85ea5fe5ad483fc5e8f /src/backend
parent1dc4bfffa95af1253f2d8392bf5d2e3336eb8ece (diff)
downloadmerchant-12c2c08fc846ef55758601b8141fa457d7094d0e.tar.gz
merchant-12c2c08fc846ef55758601b8141fa457d7094d0e.tar.bz2
merchant-12c2c08fc846ef55758601b8141fa457d7094d0e.zip
making instances accessble via hashmaps
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/taler-merchant-httpd.c66
-rw-r--r--src/backend/taler-merchant-httpd.h4
2 files changed, 67 insertions, 3 deletions
diff --git a/src/backend/taler-merchant-httpd.c b/src/backend/taler-merchant-httpd.c
index ca02030a..7f71eb4d 100644
--- a/src/backend/taler-merchant-httpd.c
+++ b/src/backend/taler-merchant-httpd.c
@@ -52,6 +52,20 @@
struct MerchantInstance **instances;
/**
+ * Hashmap pointing at merchant instances by 'id'. An 'id' is
+ * just a string that identifies a merchant instance. When a frontend
+ * needs to specify an instance to the backend, it does so by 'id'
+ */
+struct GNUNET_CONTAINER_MultiHashMap *by_id_map;
+
+/**
+ * Hashmap pointing at merchant instances by public key. This map
+ * is mainly used to check whether there is more than one instance
+ * using the same key
+ */
+struct GNUNET_CONTAINER_MultiHashMap *by_kpub_map;
+
+/**
* The port we are running on
*/
static long long unsigned port;
@@ -403,6 +417,9 @@ instances_iterator_cb (void *cls,
struct MerchantInstance *mi;
struct IterateInstancesCls *iic;
struct GNUNET_CRYPTO_EddsaPrivateKey *pk;
+ /* used as hashmap keys */
+ struct GNUNET_HashCode h_pk;
+ struct GNUNET_HashCode h_id;
iic = cls;
substr = strstr (section, "merchant-instance-");
@@ -454,7 +471,11 @@ instances_iterator_cb (void *cls,
&mi->pubkey.eddsa_pub);
GNUNET_free (pk);
- /** To free or not to free **/
+ /**
+ * FIXME: token must NOT be freed, as it is handled by the
+ * gnunet_configuration facility. OTOH mi->id does need to be freed,
+ * because it is a duplicate.
+ */
mi->id = GNUNET_strdup (token + 1);
if (0 == strcmp ("default", mi->id))
iic->default_instance = GNUNET_YES;
@@ -493,6 +514,34 @@ instances_iterator_cb (void *cls,
#endif
GNUNET_array_append (instances, iic->current_index, mi);
+
+ GNUNET_CRYPTO_hash (mi->id,
+ strlen(mi->id),
+ &h_id);
+ GNUNET_CRYPTO_hash (&mi->pubkey.eddsa_pub,
+ sizeof (struct GNUNET_CRYPTO_EddsaPublicKey),
+ &h_pk);
+ if (GNUNET_OK !=
+ GNUNET_CONTAINER_multihashmap_put (by_id_map,
+ &h_id,
+ instances[iic->current_index],
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to put an entry into the 'by_id' hashmap");
+ iic->ret |= GNUNET_SYSERR;
+ }
+
+ if (GNUNET_OK !=
+ GNUNET_CONTAINER_multihashmap_put (by_kpub_map,
+ &h_pk,
+ instances[iic->current_index],
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to put an entry into the 'by_kpub_map' hashmap");
+ iic->ret |= GNUNET_SYSERR;
+ }
}
/**
@@ -581,6 +630,7 @@ iterate_instances (const struct GNUNET_CONFIGURATION_Handle *config,
GNUNET_PLUGIN_unload (lib_name,
iic->plugin);
GNUNET_free (lib_name);
+
GNUNET_array_append (instances, iic->current_index, NULL);
#if EXTRADEBUG
unsigned int i;
@@ -666,6 +716,20 @@ run (void *cls,
return;
}
+ if (NULL ==
+ (by_id_map = GNUNET_CONTAINER_multihashmap_create(0, GNUNET_NO)))
+ {
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+
+ if (NULL ==
+ (by_kpub_map = GNUNET_CONTAINER_multihashmap_create(0, GNUNET_NO)))
+ {
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+
if (GNUNET_SYSERR ==
GNUNET_CONFIGURATION_get_value_time (config,
"merchant",
diff --git a/src/backend/taler-merchant-httpd.h b/src/backend/taler-merchant-httpd.h
index 3ea701c0..9c5b5e32 100644
--- a/src/backend/taler-merchant-httpd.h
+++ b/src/backend/taler-merchant-httpd.h
@@ -46,8 +46,8 @@ struct IterateInstancesCls {
/**
* Current index in the global array of #MerchantInstance
- * types. Used by the callback in order to properly place
- * the instance it is parsing
+ * types. Used by the callback in order to know which index
+ * is associated to the element being processed.
*/
unsigned int current_index;