avoid boolean flags, see #6188

This commit is contained in:
Christian Grothoff 2020-07-16 20:27:52 +02:00
parent c326a5bd9d
commit b9f1384b52
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
3 changed files with 52 additions and 23 deletions

View File

@ -503,20 +503,50 @@ TALER_EXCHANGE_set_last_denom (struct TALER_EXCHANGE_Handle *exchange,
struct GNUNET_TIME_Absolute last_denom_new);
/**
* Flags for #TALER_EXCHANGE_check_keys_current().
*/
enum TALER_EXCHANGE_CheckKeysFlags
{
/**
* No special options.
*/
TALER_EXCHANGE_CKF_NONE,
/**
* Force downloading /keys now, even if /keys is still valid
* (that is, the period advertised by the exchange for re-downloads
* has not yet expired).
*/
TALER_EXCHANGE_CKF_FORCE_DOWNLOAD = 1,
/**
* Pull all keys again, resetting the client state to the original state.
* Using this flag disables the incremental download, and also prevents using
* the context until the re-download has completed.
*/
TALER_EXCHANGE_CKF_PULL_ALL_KEYS = 2,
/**
* Force downloading all keys now.
*/
TALER_EXCHANGE_CKF_FORCE_ALL_NOW = TALER_EXCHANGE_CKF_FORCE_DOWNLOAD
| TALER_EXCHANGE_CKF_PULL_ALL_KEYS
};
/**
* Check if our current response for /keys is valid, and if
* not, trigger /keys download.
*
* @param exchange exchange to check keys for
* @param force_download #GNUNET_YES to force download even if /keys is still valid
* @param pull_all_keys if #GNUNET_YES, then the exchange state is reset to #MHS_INIT,
* and all denoms will be redownloaded.
* @return until when the response is current, 0 if we are re-downloading
* @param flags options controlling when to download what
* @return until when the existing response is current, 0 if we are re-downloading now
*/
struct GNUNET_TIME_Absolute
TALER_EXCHANGE_check_keys_current (struct TALER_EXCHANGE_Handle *exchange,
int force_download,
int pull_all_keys);
enum TALER_EXCHANGE_CheckKeysFlags flags);
/**

View File

@ -801,7 +801,7 @@ denoms_cmp (struct TALER_EXCHANGE_DenomPublicKey *denom1,
* and store the data in the @a key_data.
*
* @param[in] resp_obj JSON object to parse
* @param check_sig #GNUNET_YES if we should check the signature
* @param check_sig true if we should check the signature
* @param[out] key_data where to store the results we decoded
* @param[out] vc where to store version compatibility data
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
@ -809,7 +809,7 @@ denoms_cmp (struct TALER_EXCHANGE_DenomPublicKey *denom1,
*/
static int
decode_keys_json (const json_t *resp_obj,
int check_sig,
bool check_sig,
struct TALER_EXCHANGE_Keys *key_data,
enum TALER_EXCHANGE_VersionCompatibility *vc)
{
@ -1195,27 +1195,27 @@ TALER_EXCHANGE_set_last_denom (struct TALER_EXCHANGE_Handle *exchange,
* not trigger download.
*
* @param exchange exchange to check keys for
* @param force_download #GNUNET_YES to force download even if /keys is still valid
* @param pull_all_keys if #GNUNET_YES, then the exchange state is reset to #MHS_INIT,
* and all denoms will be redownloaded.
* @param flags options controlling when to download what
* @return until when the response is current, 0 if we are re-downloading
*/
struct GNUNET_TIME_Absolute
TALER_EXCHANGE_check_keys_current (struct TALER_EXCHANGE_Handle *exchange,
int force_download,
int pull_all_keys)
enum TALER_EXCHANGE_CheckKeysFlags flags)
{
bool force_download = 0 != (flags & TALER_EXCHANGE_CKF_FORCE_DOWNLOAD);
bool pull_all_keys = 0 != (flags & TALER_EXCHANGE_CKF_PULL_ALL_KEYS);
if (NULL != exchange->kr)
return GNUNET_TIME_UNIT_ZERO_ABS;
if (GNUNET_YES == pull_all_keys)
if (pull_all_keys)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Forcing re-download of all exchange keys\n");
GNUNET_break (GNUNET_YES == force_download);
exchange->state = MHS_INIT;
}
if ( (GNUNET_NO == force_download) &&
if ( (! force_download) &&
(0 < GNUNET_TIME_absolute_get_remaining (
exchange->key_data_expiration).rel_value_us) )
return exchange->key_data_expiration;
@ -1320,7 +1320,7 @@ keys_completed_cb (void *cls,
/* Old auditors got just copied into new ones. */
if (GNUNET_OK !=
decode_keys_json (j,
GNUNET_YES,
true,
&kd,
&vc))
{
@ -1605,7 +1605,7 @@ deserialize_data (struct TALER_EXCHANGE_Handle *exchange,
sizeof (struct TALER_EXCHANGE_Keys));
if (GNUNET_OK !=
decode_keys_json (keys,
GNUNET_NO,
false,
&key_data,
&vc))
{
@ -2211,8 +2211,7 @@ const struct TALER_EXCHANGE_Keys *
TALER_EXCHANGE_get_keys (struct TALER_EXCHANGE_Handle *exchange)
{
(void) TALER_EXCHANGE_check_keys_current (exchange,
GNUNET_NO,
GNUNET_NO);
TALER_EXCHANGE_CKF_NONE);
return &exchange->key_data;
}
@ -2228,8 +2227,7 @@ json_t *
TALER_EXCHANGE_get_keys_raw (struct TALER_EXCHANGE_Handle *exchange)
{
(void) TALER_EXCHANGE_check_keys_current (exchange,
GNUNET_NO,
GNUNET_NO);
TALER_EXCHANGE_CKF_NONE);
return json_deep_copy (exchange->key_data_raw);
}

View File

@ -128,8 +128,9 @@ check_keys_run (void *cls,
GNUNET_break
(0 == TALER_EXCHANGE_check_keys_current
(is->exchange,
GNUNET_YES,
cks->pull_all_keys).abs_value_us);
cks->pull_all_keys
? TALER_EXCHANGE_CKF_FORCE_ALL_NOW
: TALER_EXCHANGE_CKF_FORCE_DOWNLOAD).abs_value_us);
return;
}