diff options
author | Christian Grothoff <christian@grothoff.org> | 2021-11-25 13:37:47 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2021-11-25 13:37:47 +0100 |
commit | 94012d011c3b2c3b3dcc9527d56d1814f42fcdc7 (patch) | |
tree | 8b82cb011155f7a131ecaeb05301dfe8a1c718b7 | |
parent | 98549cdc5aff7081f20ccc53b566802020f6fdd9 (diff) | |
download | exchange-94012d011c3b2c3b3dcc9527d56d1814f42fcdc7.tar.xz |
add invariant checks
-rw-r--r-- | src/exchange/taler-exchange-httpd.c | 10 | ||||
-rw-r--r-- | src/exchange/taler-exchange-httpd_keys.c | 50 | ||||
-rw-r--r-- | src/exchange/taler-exchange-httpd_keys.h | 7 | ||||
-rw-r--r-- | src/exchange/taler-exchange-httpd_kyc-check.c | 4 | ||||
-rw-r--r-- | src/exchange/taler-exchange-httpd_reserves_get.c | 3 | ||||
-rw-r--r-- | src/exchange/taler-exchange-httpd_wire.c | 6 | ||||
-rw-r--r-- | src/testing/testing_api_helpers_exchange.c | 13 |
7 files changed, 78 insertions, 15 deletions
diff --git a/src/exchange/taler-exchange-httpd.c b/src/exchange/taler-exchange-httpd.c index fed9efd8e..0a8798ae4 100644 --- a/src/exchange/taler-exchange-httpd.c +++ b/src/exchange/taler-exchange-httpd.c @@ -290,8 +290,10 @@ handle_mhd_completion_callback (void *cls, return; GNUNET_async_scope_enter (&rc->async_scope_id, &old_scope); + TEH_check_invariants (); if (NULL != rc->rh_cleaner) rc->rh_cleaner (rc); + TEH_check_invariants (); { #if MHD_VERSION >= 0x00097304 const union MHD_ConnectionInfo *ci; @@ -931,6 +933,7 @@ handle_mhd_request (void *cls, /* We're in a new async scope! */ rc = *con_cls = GNUNET_new (struct TEH_RequestContext); GNUNET_async_scope_fresh (&rc->async_scope_id); + TEH_check_invariants (); rc->url = url; rc->connection = connection; /* We only read the correlation ID on the first callback for every client */ @@ -949,6 +952,7 @@ handle_mhd_request (void *cls, GNUNET_async_scope_enter (&rc->async_scope_id, &old_scope); + TEH_check_invariants (); if (NULL != correlation_id) GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Handling request (%s) for URL '%s', correlation_id=%s\n", @@ -1802,10 +1806,12 @@ run (void *cls, MHD_OPTION_NOTIFY_CONNECTION, &connection_done, NULL, - MHD_OPTION_LISTENING_ADDRESS_REUSE, - (unsigned int) allow_address_reuse, MHD_OPTION_CONNECTION_TIMEOUT, connection_timeout, + (0 == allow_address_reuse) + ? MHD_OPTION_END + : MHD_OPTION_LISTENING_ADDRESS_REUSE, + (unsigned int) allow_address_reuse, MHD_OPTION_END); if (NULL == mhd) { diff --git a/src/exchange/taler-exchange-httpd_keys.c b/src/exchange/taler-exchange-httpd_keys.c index 1fb58fc8c..bca1b644b 100644 --- a/src/exchange/taler-exchange-httpd_keys.c +++ b/src/exchange/taler-exchange-httpd_keys.c @@ -461,6 +461,52 @@ suspend_request (struct MHD_Connection *connection) } +/** + * Called on each denomination key. Checks that the key still works. + * + * @param cls NULL + * @param hc denomination hash (unused) + * @param value a `struct TEH_DenominationKey` + * @return #GNUNET_OK + */ +static int +check_dk (void *cls, + const struct GNUNET_HashCode *hc, + void *value) +{ + struct TEH_DenominationKey *dk = value; + struct TALER_PlanchetSecretsP ps; + struct TALER_PlanchetDetail pd; + struct TALER_CoinPubHash c_hash; + + (void) hc; + (void) value; + GNUNET_assert (TALER_DENOMINATION_INVALID != dk->denom_pub.cipher); + memset (&ps, + 42, + sizeof (ps)); + GNUNET_assert (GNUNET_OK == + TALER_planchet_prepare (&dk->denom_pub, + &ps, + &c_hash, + &pd)); + GNUNET_free (pd.coin_ev); + return GNUNET_OK; +} + + +void +TEH_check_invariants () +{ + struct TEH_KeyStateHandle *ksh; + + ksh = TEH_keys_get_state (); + GNUNET_CONTAINER_multihashmap_iterate (ksh->denomkey_map, + &check_dk, + NULL); +} + + void TEH_resume_keys_requests (bool do_shutdown) { @@ -935,8 +981,12 @@ keys_update_event_cb (void *cls, (void) cls; (void) extra; (void) extra_size; + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Received /keys update event\n"); + TEH_check_invariants (); key_generation++; TEH_resume_keys_requests (false); + TEH_check_invariants (); } diff --git a/src/exchange/taler-exchange-httpd_keys.h b/src/exchange/taler-exchange-httpd_keys.h index 9ad0c6a3a..75de7cbac 100644 --- a/src/exchange/taler-exchange-httpd_keys.h +++ b/src/exchange/taler-exchange-httpd_keys.h @@ -97,6 +97,13 @@ struct TEH_KeyStateHandle; /** + * Run internal invariant checks. For debugging. + */ +void +TEH_check_invariants (void); + + +/** * Return the current key state for this thread. Possibly re-builds the key * state if we have reason to believe that something changed. * diff --git a/src/exchange/taler-exchange-httpd_kyc-check.c b/src/exchange/taler-exchange-httpd_kyc-check.c index 69798a56d..76d094817 100644 --- a/src/exchange/taler-exchange-httpd_kyc-check.c +++ b/src/exchange/taler-exchange-httpd_kyc-check.c @@ -210,9 +210,12 @@ db_event_cb (void *cls, if (! kyp->suspended) return; /* event triggered while main transaction was still running, or got multiple wake-up events */ + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Received KYC update event\n"); kyp->suspended = false; GNUNET_async_scope_enter (&rc->async_scope_id, &old_scope); + TEH_check_invariants (); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Resuming from long-polling on KYC status\n"); GNUNET_CONTAINER_DLL_remove (kyp_head, @@ -220,6 +223,7 @@ db_event_cb (void *cls, kyp); MHD_resume_connection (kyp->connection); TALER_MHD_daemon_trigger (); + TEH_check_invariants (); GNUNET_async_scope_restore (&old_scope); } diff --git a/src/exchange/taler-exchange-httpd_reserves_get.c b/src/exchange/taler-exchange-httpd_reserves_get.c index 57ab71378..89a7dd498 100644 --- a/src/exchange/taler-exchange-httpd_reserves_get.c +++ b/src/exchange/taler-exchange-httpd_reserves_get.c @@ -26,6 +26,7 @@ #include "taler_mhd_lib.h" #include "taler_json_lib.h" #include "taler_dbevents.h" +#include "taler-exchange-httpd_keys.h" #include "taler-exchange-httpd_reserves_get.h" #include "taler-exchange-httpd_responses.h" @@ -152,11 +153,13 @@ db_event_cb (void *cls, &old_scope); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Resuming from long-polling on reserve\n"); + TEH_check_invariants (); GNUNET_CONTAINER_DLL_remove (rp_head, rp_tail, rp); MHD_resume_connection (rp->connection); TALER_MHD_daemon_trigger (); + TEH_check_invariants (); GNUNET_async_scope_restore (&old_scope); } diff --git a/src/exchange/taler-exchange-httpd_wire.c b/src/exchange/taler-exchange-httpd_wire.c index 8e4465ada..802204e30 100644 --- a/src/exchange/taler-exchange-httpd_wire.c +++ b/src/exchange/taler-exchange-httpd_wire.c @@ -22,6 +22,7 @@ #include <gnunet/gnunet_json_lib.h> #include "taler_dbevents.h" #include "taler-exchange-httpd_responses.h" +#include "taler-exchange-httpd_keys.h" #include "taler-exchange-httpd_wire.h" #include "taler_json_lib.h" #include "taler_mhd_lib.h" @@ -99,6 +100,9 @@ wire_update_event_cb (void *cls, (void) cls; (void) extra; (void) extra_size; + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Received /wire update event\n"); + TEH_check_invariants (); wire_generation++; } @@ -387,10 +391,12 @@ get_wire_state (void) { struct WireStateHandle *wsh; + TEH_check_invariants (); wsh = build_wire_state (); wire_state = wsh; if (NULL != old_wsh) destroy_wire_state (old_wsh); + TEH_check_invariants (); return wsh; } return old_wsh; diff --git a/src/testing/testing_api_helpers_exchange.c b/src/testing/testing_api_helpers_exchange.c index 86466c760..0f50aabb8 100644 --- a/src/testing/testing_api_helpers_exchange.c +++ b/src/testing/testing_api_helpers_exchange.c @@ -325,13 +325,6 @@ sign_keys_for_exchange (void *cls, return GNUNET_NO; } if (GNUNET_OK != - TALER_TESTING_url_port_free (si->ec->exchange_url)) - { - GNUNET_free (si->ec->exchange_url); - si->ec->exchange_url = NULL; - return GNUNET_NO; - } - if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "auditor", "BASE_URL", @@ -346,12 +339,6 @@ sign_keys_for_exchange (void *cls, return GNUNET_SYSERR; } if (GNUNET_OK != - TALER_TESTING_url_port_free (si->ec->auditor_url)) - { - ret = GNUNET_NO; - goto fail; - } - if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "exchange", "MASTER_PUBLIC_KEY", |