diff options
author | Özgür Kesim <oec-taler@kesim.org> | 2023-06-10 11:07:06 +0200 |
---|---|---|
committer | Özgür Kesim <oec-taler@kesim.org> | 2023-06-10 11:07:06 +0200 |
commit | 70bfe0ed1b9a5dbb6cc487465ef3c3df4cdb0436 (patch) | |
tree | 5f32b30f5b58dfc502c273bebecffbcb79fc3c4b /src/testing/testing_api_cmd_serialize_keys.c | |
parent | 46188ae07e97d12b73269167459707844b3c2486 (diff) | |
parent | d8f8c550bd7ad85f9da9bc5edba619e533eabcc8 (diff) | |
download | exchange-70bfe0ed1b9a5dbb6cc487465ef3c3df4cdb0436.tar.xz |
Merge branch 'master' into age-withdraw
Diffstat (limited to 'src/testing/testing_api_cmd_serialize_keys.c')
-rw-r--r-- | src/testing/testing_api_cmd_serialize_keys.c | 157 |
1 files changed, 13 insertions, 144 deletions
diff --git a/src/testing/testing_api_cmd_serialize_keys.c b/src/testing/testing_api_cmd_serialize_keys.c index ef912bf51..9e5a25c4c 100644 --- a/src/testing/testing_api_cmd_serialize_keys.c +++ b/src/testing/testing_api_cmd_serialize_keys.c @@ -1,6 +1,6 @@ /* This file is part of TALER - (C) 2018 Taler Systems SA + (C) 2018-2023 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -46,35 +46,6 @@ struct SerializeKeysState /** - * Internal state for a connect-with-state CMD. - */ -struct ConnectWithStateState -{ - - /** - * Reference to a CMD that offers a serialized key-state - * that will be used in the reconnection. - */ - const char *state_reference; - - /** - * If set to GNUNET_YES, then the /keys callback has already - * been passed the control to the next CMD. This is necessary - * because it is not uncommon that the /keys callback gets - * invoked multiple times, and without this flag, we would keep - * going "next" CMD upon every invocation (causing impredictable - * behaviour as for the instruction pointer.) - */ - unsigned int consumed; - - /** - * Interpreter state. - */ - struct TALER_TESTING_Interpreter *is; -}; - - -/** * Run the command. * * @param cls closure. @@ -87,16 +58,20 @@ serialize_keys_run (void *cls, struct TALER_TESTING_Interpreter *is) { struct SerializeKeysState *sks = cls; + struct TALER_EXCHANGE_Handle *exchange + = TALER_TESTING_get_exchange (is); - sks->keys = TALER_EXCHANGE_serialize_data (is->exchange); + if (NULL == exchange) + return; + sks->keys = TALER_EXCHANGE_serialize_data (exchange); if (NULL == sks->keys) + { + GNUNET_break (0); TALER_TESTING_interpreter_fail (is); - - sks->exchange_url = GNUNET_strdup - (TALER_EXCHANGE_get_base_url (is->exchange)); - TALER_EXCHANGE_disconnect (is->exchange); - is->exchange = NULL; - is->working = GNUNET_NO; + } + sks->exchange_url + = GNUNET_strdup ( + TALER_EXCHANGE_get_base_url (exchange)); TALER_TESTING_interpreter_next (is); } @@ -114,9 +89,7 @@ serialize_keys_cleanup (void *cls, struct SerializeKeysState *sks = cls; if (NULL != sks->keys) - { json_decref (sks->keys); - } GNUNET_free (sks->exchange_url); GNUNET_free (sks); } @@ -140,8 +113,7 @@ serialize_keys_traits (void *cls, struct SerializeKeysState *sks = cls; struct TALER_TESTING_Trait traits[] = { TALER_TESTING_make_trait_exchange_keys (sks->keys), - TALER_TESTING_make_trait_exchange_url ( - (const char **) &sks->exchange_url), + TALER_TESTING_make_trait_exchange_url (sks->exchange_url), TALER_TESTING_trait_end () }; @@ -152,87 +124,6 @@ serialize_keys_traits (void *cls, } -/** - * Run the command. - * - * @param cls closure. - * @param cmd the command to execute. - * @param is the interpreter state. - */ -static void -connect_with_state_run (void *cls, - const struct TALER_TESTING_Command *cmd, - struct TALER_TESTING_Interpreter *is) -{ - struct ConnectWithStateState *cwss = cls; - const struct TALER_TESTING_Command *state_cmd; - const json_t *serialized_keys; - const char **exchange_url; - - /* This command usually gets rescheduled after serialized - * reconnection. */ - if (GNUNET_YES == cwss->consumed) - { - TALER_TESTING_interpreter_next (is); - return; - } - - cwss->is = is; - state_cmd = TALER_TESTING_interpreter_lookup_command (is, - cwss->state_reference); - - /* Command providing serialized keys not found. */ - if (NULL == state_cmd) - { - GNUNET_break (0); - TALER_TESTING_interpreter_fail (is); - return; - } - - GNUNET_assert (GNUNET_OK == - TALER_TESTING_get_trait_exchange_keys (state_cmd, - &serialized_keys)); - { - char *dump; - - dump = json_dumps (serialized_keys, - JSON_INDENT (1)); - TALER_LOG_DEBUG ("Serialized key-state: %s\n", - dump); - free (dump); - } - - GNUNET_assert (GNUNET_OK == - TALER_TESTING_get_trait_exchange_url (state_cmd, - &exchange_url)); - is->exchange = TALER_EXCHANGE_connect (is->ctx, - *exchange_url, - &TALER_TESTING_cert_cb, - cwss, - TALER_EXCHANGE_OPTION_DATA, - serialized_keys, - TALER_EXCHANGE_OPTION_END); - cwss->consumed = GNUNET_YES; -} - - -/** - * Cleanup the state of a "connect with state" CMD. Just - * a placeholder to avoid jumping on an invalid address. - * - * @param cls closure. - * @param cmd the command which is being cleaned up. - */ -static void -connect_with_state_cleanup (void *cls, - const struct TALER_TESTING_Command *cmd) -{ - struct ConnectWithStateState *cwss = cls; - - GNUNET_free (cwss); -} - - struct TALER_TESTING_Command TALER_TESTING_cmd_serialize_keys (const char *label) { @@ -251,25 +142,3 @@ TALER_TESTING_cmd_serialize_keys (const char *label) return cmd; } } - - -struct TALER_TESTING_Command -TALER_TESTING_cmd_connect_with_state (const char *label, - const char *state_reference) -{ - struct ConnectWithStateState *cwss; - - cwss = GNUNET_new (struct ConnectWithStateState); - cwss->state_reference = state_reference; - cwss->consumed = GNUNET_NO; - { - struct TALER_TESTING_Command cmd = { - .cls = cwss, - .label = label, - .run = connect_with_state_run, - .cleanup = connect_with_state_cleanup - }; - - return cmd; - } -} |