commit dea8b5e2e565b368dd86b75c0165778c29510d17
parent 403898961107375a6d6470a428fb11dc592778c2
Author: Marcello Stanisci <marcello.stanisci@inria.fr>
Date: Mon, 26 Sep 2016 15:14:13 +0200
fixing 'make check' for new hashmap based instance picking
Diffstat:
5 files changed, 85 insertions(+), 93 deletions(-)
diff --git a/src/backend/taler-merchant-httpd.c b/src/backend/taler-merchant-httpd.c
@@ -46,12 +46,6 @@
#define UNIX_BACKLOG 500
/**
- * NULL-terminated array of all merchants instances known
- * by this backend
- */
-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'
@@ -239,6 +233,22 @@ url_handler (void *cls,
/**
+ * Callback that frees all the elements in the hashmap
+ *
+ * @param cls closure
+ * @param key current key
+ * @param value current value
+ */
+int
+hashmap_free (void *cls,
+ const struct GNUNET_HashCode *key,
+ void *value)
+{
+ GNUNET_free (value);
+ return GNUNET_YES;
+}
+
+/**
* Shutdown task (magically invoked when the application is being
* quit)
*
@@ -265,22 +275,13 @@ do_shutdown (void *cls)
TMH_EXCHANGES_done ();
TMH_AUDITORS_done ();
+ GNUNET_CONTAINER_multihashmap_iterate (by_id_map,
+ &hashmap_free,
+ NULL);
if (NULL != by_id_map)
GNUNET_CONTAINER_multihashmap_destroy (by_id_map);
if (NULL != by_kpub_map)
GNUNET_CONTAINER_multihashmap_destroy (by_kpub_map);
-
- if (NULL != instances)
- {
- unsigned int i;
-
- for (i=0; NULL != instances[i]; i++)
- {
- json_decref (instances[i]->j_wire);
- GNUNET_free (instances[i]->id);
- GNUNET_free (instances[i]);
- }
- }
}
@@ -478,7 +479,7 @@ instances_iterator_cb (void *cls,
GNUNET_free (pk);
/**
- * FIXME: token must NOT be freed, as it is handled by the
+ * 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.
*/
@@ -512,16 +513,14 @@ instances_iterator_cb (void *cls,
"Failed to hash wireformat\n");
iic->ret |= GNUNET_SYSERR;
}
- #define EXTRADEBUGG
- #ifdef EXTRADEBUG
+ #define EXTRADEBUG
+ #ifdef EXTRADEBUGG
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Found wireformat instance:\n");
json_dumpf (mi->j_wire, stdout, 0);
printf ("\n");
#endif
- GNUNET_array_append (instances, iic->current_index, mi);
-
GNUNET_CRYPTO_hash (mi->id,
strlen(mi->id),
&h_id);
@@ -531,18 +530,29 @@ instances_iterator_cb (void *cls,
if (GNUNET_OK !=
GNUNET_CONTAINER_multihashmap_put (by_id_map,
&h_id,
- instances[iic->current_index],
+ mi,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to put an entry into the 'by_id' hashmap\n");
iic->ret |= GNUNET_SYSERR;
}
+ #ifdef EXTRADEBUG
+ else {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Added element at %p, by by-id key %s of '%s' in hashmap\n",
+ mi,
+ GNUNET_h2s (&h_id),
+ mi->id);
+ GNUNET_assert (NULL != GNUNET_CONTAINER_multihashmap_get (by_id_map,
+ &h_id));
+ }
+ #endif
if (GNUNET_OK !=
GNUNET_CONTAINER_multihashmap_put (by_kpub_map,
&h_pk,
- instances[iic->current_index],
+ mi,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -568,22 +578,28 @@ struct MerchantInstance *
get_instance (struct json_t *json)
{
struct json_t *receiver;
+ const char *receiver_str;
struct GNUNET_HashCode h_receiver;
-
+ struct MerchantInstance *ret;
/*FIXME who decrefs receiver?*/
if (NULL == (receiver = json_object_get (json, "receiver")))
receiver = json_string ("default");
- // hash it
- GNUNET_CRYPTO_hash (json_string_value (receiver),
- strlen (json_string_value (receiver)),
+ receiver_str = json_string_value (receiver);
+ GNUNET_CRYPTO_hash (receiver_str,
+ strlen (receiver_str),
&h_receiver);
-
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Looking for by-id key %s of '%s' in hashmap\n",
+ GNUNET_h2s (&h_receiver),
+ receiver_str);
/* We're fine if that returns NULL, the calling routine knows how
to handle that */
- return GNUNET_CONTAINER_multihashmap_get (by_id_map,
- &h_receiver);
+ ret = GNUNET_CONTAINER_multihashmap_get (by_id_map,
+ &h_receiver);
+ GNUNET_break (NULL != ret);
+ return ret;
}
/**
@@ -645,38 +661,6 @@ iterate_instances (const struct GNUNET_CONFIGURATION_Handle *config,
iic->plugin);
GNUNET_free (lib_name);
- GNUNET_array_append (instances, iic->current_index, NULL);
- #ifdef EXTRADEBUG
- unsigned int i;
- for (i=0; NULL != instances[i]; i++)
- {
- char *hash;
- char *priv;
- char *pub;
-
- hash =
- GNUNET_STRINGS_data_to_string_alloc (&instances[i]->h_wire,
- sizeof (struct GNUNET_HashCode));
- priv =
- GNUNET_STRINGS_data_to_string_alloc (&instances[i]->privkey.eddsa_priv,
- sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey));
- pub =
- GNUNET_STRINGS_data_to_string_alloc (&instances[i]->pubkey.eddsa_pub,
- sizeof (struct GNUNET_CRYPTO_EddsaPublicKey));
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "instances[%d]: id=%s,\nj_wire=%s,\nj_hash=%s,\npriv=%s,\npub=%s\n",
- i,
- instances[i]->id,
- json_dumps (instances[i]->j_wire, JSON_INDENT (2)),
- hash,
- priv,
- pub);
-
- GNUNET_free (hash);
- GNUNET_free (priv);
- GNUNET_free (pub);
- }
- #endif
GNUNET_free (iic);
return GNUNET_OK;
diff --git a/src/backend/taler-merchant-httpd_track-transaction.c b/src/backend/taler-merchant-httpd_track-transaction.c
@@ -33,6 +33,11 @@
/**
+ * Map containing all the known merchant instances
+ */
+extern struct GNUNET_CONTAINER_MultiHashMap *by_id_map;
+
+/**
* How long to wait before giving up processing with the exchange?
*/
#define TRACK_TIMEOUT (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30))
@@ -765,8 +770,6 @@ coin_cb (void *cls,
tcc));
}
-extern struct MerchantInstance **instances;
-
/**
* Handle a "/track/transaction" request.
*
@@ -788,8 +791,8 @@ MH_handler_track_transaction (struct TMH_RequestHandler *rh,
unsigned long long transaction_id;
const char *str;
const char *receiver;
- unsigned int i;
int ret;
+ struct GNUNET_HashCode h_receiver;
if (NULL == *connection_cls)
{
@@ -845,12 +848,12 @@ MH_handler_track_transaction (struct TMH_RequestHandler *rh,
"receiver");
if (NULL == receiver)
receiver = "default";
-
+ GNUNET_CRYPTO_hash (receiver,
+ strlen (receiver),
+ &h_receiver);
tctx->mi = NULL;
- for (i=0; NULL != instances[i]; i++)
- if (0 == strcmp (receiver, instances[i]->id))
- tctx->mi = instances[i];
-
+ GNUNET_assert (NULL != (tctx->mi = GNUNET_CONTAINER_multihashmap_get (by_id_map,
+ &h_receiver)));
if (NULL == tctx->mi)
return TMH_RESPONSE_reply_bad_request (connection,
"unknown receiver");
diff --git a/src/lib/merchant_api_track_transaction.c b/src/lib/merchant_api_track_transaction.c
@@ -252,9 +252,10 @@ TALER_MERCHANT_track_transaction (struct GNUNET_CURL_Context *ctx,
tdo->cb = track_transaction_cb;
tdo->cb_cls = track_transaction_cb_cls;
GNUNET_asprintf (&tdo->url,
- "%s/track/transaction?id=%llu",
+ "%s/track/transaction?id=%llu&receiver=%s",
backend_uri,
- (unsigned long long) transaction_id);
+ (unsigned long long) transaction_id,
+ receiver);
eh = curl_easy_init ();
GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh,
diff --git a/src/lib/test_merchant_api.c b/src/lib/test_merchant_api.c
@@ -1668,12 +1668,12 @@ interpreter_run (void *cls)
GNUNET_assert (NULL != ref);
cmd->details.track_transfer.tdo =
TALER_MERCHANT_track_transfer (ctx,
- MERCHANT_URI,
- receiver,
- &ref->details.check_bank_transfer.wtid,
- EXCHANGE_URI,
- &track_transfer_cb,
- is);
+ MERCHANT_URI,
+ receiver,
+ &ref->details.check_bank_transfer.wtid,
+ EXCHANGE_URI,
+ &track_transfer_cb,
+ is);
return;
case OC_TRACK_TRANSACTION:
ref = find_command (is,
@@ -2175,9 +2175,6 @@ int
main (int argc,
char * const *argv)
{
- /* Value from "gnunet-ecc -p test_merchant.priv" */
- const char *merchant_pub_str
- = "5TRNSWAWHKBJ7G4T3PKRCQA6MCB3MX82F4M2XXS1653KE1V8RFPG";
struct GNUNET_OS_Process *proc;
struct GNUNET_OS_Process *exchanged;
struct GNUNET_OS_Process *merchantd;
@@ -2185,6 +2182,9 @@ main (int argc,
struct GNUNET_CONFIGURATION_Handle *cfg;
unsigned int cnt;
struct GNUNET_SIGNAL_Context *shc_chld;
+ char *instance_section;
+ char *keyfile;
+ struct GNUNET_CRYPTO_EddsaPrivateKey *kpriv;
unsetenv ("XDG_DATA_HOME");
unsetenv ("XDG_CONFIG_HOME");
@@ -2202,7 +2202,20 @@ main (int argc,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Using non default receiver '%s'\n",
receiver);
+ GNUNET_asprintf (&instance_section,
+ "merchant-instance-%s",
+ receiver);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_filename (cfg,
+ instance_section,
+ "KEYFILE",
+ &keyfile));
+ kpriv = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile);
+ GNUNET_CRYPTO_eddsa_key_get_public (kpriv, &merchant_pub.eddsa_pub);
+
+ GNUNET_free (keyfile);
+ GNUNET_free (instance_section);
db = TALER_MERCHANTDB_plugin_load (cfg);
if (NULL == db)
{
@@ -2219,12 +2232,6 @@ main (int argc,
TALER_MERCHANTDB_plugin_unload (db);
GNUNET_CONFIGURATION_destroy (cfg);
-
- GNUNET_assert (GNUNET_OK ==
- GNUNET_STRINGS_string_to_data (merchant_pub_str,
- strlen (merchant_pub_str),
- &merchant_pub,
- sizeof (merchant_pub)));
proc = GNUNET_OS_start_process (GNUNET_NO,
GNUNET_OS_INHERIT_STD_ALL,
NULL, NULL, NULL,
diff --git a/src/lib/test_merchant_api.conf b/src/lib/test_merchant_api.conf
@@ -22,9 +22,6 @@ PORT = 8082
# FIXME: is this one used?
HOSTNAME = localhost
-# Where is our private key?
-KEYFILE = test_merchant.priv
-
# How quickly do we want the exchange to send us our money?
# Used only if the frontend does not specify a value.
# FIXME: EDATE is a bit short, 'execution_delay'?
@@ -39,7 +36,7 @@ WIREFORMAT = test
# If set, this option will drive the testcase so that
# `INSTANCE' will be the used merchant instance. Otherwise
# we use the 'default' instance
-INSTANCE = tor
+INSTANCE = tor
[merchant-exchange-test]
URI = http://localhost:8081/