add invariant checks

This commit is contained in:
Christian Grothoff 2021-11-25 13:37:47 +01:00
parent 98549cdc5a
commit 94012d011c
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
7 changed files with 78 additions and 15 deletions

View File

@ -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)
{

View File

@ -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 ();
}

View File

@ -96,6 +96,13 @@ struct TEH_DenominationKey
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.

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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;

View File

@ -324,13 +324,6 @@ sign_keys_for_exchange (void *cls,
si->ec->exchange_url = NULL;
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",
@ -345,12 +338,6 @@ sign_keys_for_exchange (void *cls,
si->ec->auditor_url = NULL;
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",