/keys API.

Adding method to override the last_denom value for a key set.
This commit is contained in:
Marcello Stanisci 2019-01-17 16:37:16 +01:00
parent aeec67acaa
commit 148b546435
No known key found for this signature in database
GPG Key ID: 8D526861953F4C0F
5 changed files with 128 additions and 6 deletions

View File

@ -422,6 +422,16 @@ TALER_EXCHANGE_disconnect (struct TALER_EXCHANGE_Handle *exchange);
const struct TALER_EXCHANGE_Keys *
TALER_EXCHANGE_get_keys (struct TALER_EXCHANGE_Handle *exchange);
/**
* Let the user set the last valid denomination time manually.
*
* @param exchange the exchange handle.
* @param last_denom_new new last denomination time.
*/
void
TALER_EXCHANGE_set_last_denom (struct TALER_EXCHANGE_Handle *exchange,
struct GNUNET_TIME_Absolute last_denom_new);
/**
* Check if our current response for /keys is valid, and if

View File

@ -1424,6 +1424,34 @@ TALER_TESTING_cmd_check_keys_pull_all_keys
unsigned int num_denom_keys);
/**
* Make a "check keys" command. This type of command
* checks whether the number of denomination keys from
* @a exchange matches @a num_denom_keys. Additionally,
* it lets the user set a last denom issue date to be
* used in the request for /keys.
*
* @param label command label
* @param generation when this command is run, exactly @a
* generation /keys downloads took place. If the number
* of downloads is less than @a generation, the logic will
* first make sure that @a generation downloads are done,
* and _then_ execute the rest of the command.
* @param num_denom_keys expected number of denomination keys.
* @param exchange connection handle to the exchange to test.
* @param last_denom_date date to be set in the "last_denom_issue"
* URL parameter of /keys.
*
* @return the command.
*/
struct TALER_TESTING_Command
TALER_TESTING_cmd_check_keys_with_last_denom
(const char *label,
unsigned int generation,
unsigned int num_denom_keys,
struct GNUNET_TIME_Absolute last_denom_date);
/**
* Create a "batch" command. Such command takes a
* end_CMD-terminated array of CMDs and executed them.

View File

@ -1030,6 +1030,21 @@ request_keys (void *cls);
void
TEAH_handle_reset (struct TALER_EXCHANGE_Handle *h);
/**
* Let the user set the last valid denomination time manually.
*
* @param exchange the exchange handle.
* @param last_denom_new new last denomination time.
*/
void
TALER_EXCHANGE_set_last_denom (struct TALER_EXCHANGE_Handle *exchange,
struct GNUNET_TIME_Absolute last_denom_new)
{
exchange->key_data.last_denom_issue_date = last_denom_new;
}
/**
* Check if our current response for /keys is valid, and if
* not trigger download.
@ -1047,8 +1062,12 @@ TALER_EXCHANGE_check_keys_current (struct TALER_EXCHANGE_Handle *exchange,
{
if (NULL != exchange->kr)
return GNUNET_TIME_UNIT_ZERO_ABS;
if (GNUNET_YES == pull_all_keys)
{
GNUNET_assert (GNUNET_YES == force_download);
TEAH_handle_reset (exchange);
}
if ( (GNUNET_NO == force_download) &&
(0 < GNUNET_TIME_absolute_get_remaining (exchange->key_data_expiration).rel_value_us) )
return exchange->key_data_expiration;

View File

@ -96,12 +96,11 @@ run (void *cls,
1,
4),
/**
* Avoid cherry-pick, just GET /keys.
*/
TALER_TESTING_cmd_check_keys_pull_all_keys ("second-download",
2,
4),
/* Causes GET /keys?last_denom_issue=0 */
TALER_TESTING_cmd_check_keys_with_last_denom ("second-download",
2,
8,
GNUNET_TIME_UNIT_ZERO_ABS),
TALER_TESTING_cmd_end ()
};

View File

@ -54,6 +54,20 @@ struct CheckKeysState
* downloaded.
*/
unsigned int pull_all_keys;
/**
* If GNUNET_YES, then the user must specify the
* last_denom_issue_date manually. This way, it is possible
* to force whatever X value here: /keys?last_denom_issue=X.
*/
unsigned int set_last_denom;
/**
* Value X to set as the URL parameter:
* "/keys?last_denom_issue=X" is used only when `set_last_denom'
* equals GNUNET_YES.
*/
struct GNUNET_TIME_Absolute last_denom_date;
};
@ -82,6 +96,13 @@ check_keys_run (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Triggering GET /keys, cmd `%s'\n",
cmd->label);
if (GNUNET_YES == cks->set_last_denom)
{
TALER_LOG_DEBUG ("Forcing last_denom_date URL argument\n");
TALER_EXCHANGE_set_last_denom (is->exchange,
cks->last_denom_date);
}
/* Means re-download /keys. */
GNUNET_break
@ -134,6 +155,51 @@ check_keys_cleanup (void *cls,
}
/**
* Make a "check keys" command. This type of command
* checks whether the number of denomination keys from
* @a exchange matches @a num_denom_keys. Additionally,
* it lets the user set a last denom issue date to be
* used in the request for /keys.
*
* @param label command label
* @param generation when this command is run, exactly @a
* generation /keys downloads took place. If the number
* of downloads is less than @a generation, the logic will
* first make sure that @a generation downloads are done,
* and _then_ execute the rest of the command.
* @param num_denom_keys expected number of denomination keys.
* @param exchange connection handle to the exchange to test.
* @param last_denom_date date to be set in the "last_denom_issue"
* URL parameter of /keys.
*
* @return the command.
*/
struct TALER_TESTING_Command
TALER_TESTING_cmd_check_keys_with_last_denom
(const char *label,
unsigned int generation,
unsigned int num_denom_keys,
struct GNUNET_TIME_Absolute last_denom_date)
{
struct CheckKeysState *cks;
cks = GNUNET_new (struct CheckKeysState);
cks->generation = generation;
cks->num_denom_keys = num_denom_keys;
cks->set_last_denom = GNUNET_YES;
cks->last_denom_date = last_denom_date;
struct TALER_TESTING_Command cmd = {
.cls = cks,
.label = label,
.run = &check_keys_run,
.cleanup = &check_keys_cleanup
};
return cmd;
}
/**
* Make a "check keys" command. This type of command
* checks whether the number of denomination keys from