Fix cherry picking.

Fix how the last denom issue date was set after
a redownloading of /keys.

Additionally, some styling fix also came along.
This commit is contained in:
Marcello Stanisci 2019-01-09 15:54:34 +01:00
parent ec58188446
commit f311ffb3ba
No known key found for this signature in database
GPG Key ID: 8D526861953F4C0F

View File

@ -502,14 +502,15 @@ parse_json_auditor (struct TALER_EXCHANGE_AuditorInformation *auditor,
/** /**
* Decode the JSON in @a resp_obj from the /keys response and store the data * Decode the JSON in @a resp_obj from the /keys response
* in the @a key_data. * and store the data in the @a key_data.
* *
* @param[in] resp_obj JSON object to parse * @param[in] resp_obj JSON object to parse
* @param check_sig #GNUNET_YES if we should check the signature * @param check_sig #GNUNET_YES if we should check the signature
* @param[out] key_data where to store the results we decoded * @param[out] key_data where to store the results we decoded
* @param[out] where to store version compatibility data * @param[out] where to store version compatibility data
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error (malformed JSON) * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
* (malformed JSON)
*/ */
static int static int
decode_keys_json (const json_t *resp_obj, decode_keys_json (const json_t *resp_obj,
@ -517,7 +518,6 @@ decode_keys_json (const json_t *resp_obj,
struct TALER_EXCHANGE_Keys *key_data, struct TALER_EXCHANGE_Keys *key_data,
enum TALER_EXCHANGE_VersionCompatibility *vc) enum TALER_EXCHANGE_VersionCompatibility *vc)
{ {
struct GNUNET_TIME_Absolute last_denom_issue_date;
struct TALER_ExchangeSignatureP sig; struct TALER_ExchangeSignatureP sig;
struct GNUNET_HashContext *hash_context; struct GNUNET_HashContext *hash_context;
struct TALER_ExchangePublicKeyP pub; struct TALER_ExchangePublicKeyP pub;
@ -535,8 +535,9 @@ decode_keys_json (const json_t *resp_obj,
&key_data->master_pub), &key_data->master_pub),
GNUNET_JSON_spec_absolute_time ("list_issue_date", GNUNET_JSON_spec_absolute_time ("list_issue_date",
&key_data->list_issue_date), &key_data->list_issue_date),
GNUNET_JSON_spec_relative_time ("reserve_closing_delay", GNUNET_JSON_spec_relative_time
&key_data->reserve_closing_delay), ("reserve_closing_delay",
&key_data->reserve_closing_delay),
GNUNET_JSON_spec_end() GNUNET_JSON_spec_end()
}; };
@ -624,7 +625,6 @@ decode_keys_json (const json_t *resp_obj,
/* parse the denomination keys, merging with the /* parse the denomination keys, merging with the
possibly EXISTING array as required (/keys cherry picking) */ possibly EXISTING array as required (/keys cherry picking) */
last_denom_issue_date.abs_value_us = 0LLU;
{ {
json_t *denom_keys_array; json_t *denom_keys_array;
json_t *denom_key_obj; json_t *denom_key_obj;
@ -642,40 +642,40 @@ decode_keys_json (const json_t *resp_obj,
EXITIF (GNUNET_SYSERR == EXITIF (GNUNET_SYSERR ==
parse_json_denomkey (&dk, parse_json_denomkey (&dk,
check_sig, check_sig,
denom_key_obj, denom_key_obj,
&key_data->master_pub, &key_data->master_pub,
hash_context)); hash_context));
for (unsigned int j=0;j<key_data->num_denom_keys;j++) for (unsigned int j=0;j<key_data->num_denom_keys;j++)
{ {
if (0 == memcmp (&dk, if (0 == memcmp (&dk,
&key_data->denom_keys[j], &key_data->denom_keys[j],
sizeof (dk))) sizeof (dk)))
{ {
found = true; found = true;
break; break;
} }
} }
if (found) if (found)
{ {
/* 0:0:0 did not support /keys cherry picking */ /* 0:0:0 did not support /keys cherry picking */
GNUNET_break_op (0 == current); GNUNET_break_op (0 == current);
continue; continue;
} }
if (key_data->denom_keys_size == key_data->num_denom_keys) if (key_data->denom_keys_size == key_data->num_denom_keys)
GNUNET_array_grow (key_data->denom_keys, GNUNET_array_grow (key_data->denom_keys,
key_data->denom_keys_size, key_data->denom_keys_size,
key_data->denom_keys_size * 2 + 2); key_data->denom_keys_size * 2 + 2);
key_data->denom_keys[key_data->num_denom_keys++] = dk; key_data->denom_keys[key_data->num_denom_keys++] = dk;
/* Update "last_denom_issue_date" */ /* Update "last_denom_issue_date" */
last_denom_issue_date TALER_LOG_DEBUG ("Crawling DK 'valid_from': %s\n",
= GNUNET_TIME_absolute_max (last_denom_issue_date, GNUNET_STRINGS_absolute_time_to_string (dk.valid_from));
key_data->last_denom_issue_date
= GNUNET_TIME_absolute_max (key_data->last_denom_issue_date,
dk.valid_from); dk.valid_from);
}; };
} }
key_data->last_denom_issue_date = last_denom_issue_date;
/* parse the auditor information */ /* parse the auditor information */
{ {
json_t *auditors_array; json_t *auditors_array;
@ -874,9 +874,11 @@ keys_completed_cb (void *cls,
/* We keep the denomination keys and auditor signatures from the /* We keep the denomination keys and auditor signatures from the
previous iteration (/keys cherry picking) */ previous iteration (/keys cherry picking) */
kd.num_denom_keys = kd_old.num_denom_keys; kd.num_denom_keys = kd_old.num_denom_keys;
kd.last_denom_issue_date = kd_old.last_denom_issue_date;
GNUNET_array_grow (kd.denom_keys, GNUNET_array_grow (kd.denom_keys,
kd.denom_keys_size, kd.denom_keys_size,
kd.num_denom_keys); kd.num_denom_keys);
/* First make a shallow copy, we then need another pass for the RSA key... */ /* First make a shallow copy, we then need another pass for the RSA key... */
memcpy (kd.denom_keys, memcpy (kd.denom_keys,
kd_old.denom_keys, kd_old.denom_keys,
@ -943,6 +945,10 @@ keys_completed_cb (void *cls,
break; break;
} }
exchange->key_data = kd; exchange->key_data = kd;
TALER_LOG_DEBUG ("Last DK issue date update to: %s\n",
GNUNET_STRINGS_absolute_time_to_string
(exchange->key_data.last_denom_issue_date));
if (MHD_HTTP_OK != response_code) if (MHD_HTTP_OK != response_code)
{ {
@ -1177,10 +1183,10 @@ deserialize_data (struct TALER_EXCHANGE_Handle *exchange,
return; /* unsupported version */ return; /* unsupported version */
if (0 != strcmp (url, if (0 != strcmp (url,
exchange->url)) exchange->url))
{ {
GNUNET_break (0); GNUNET_break (0);
return; return;
} }
memset (&key_data, memset (&key_data,
0, 0,
sizeof (struct TALER_EXCHANGE_Keys)); sizeof (struct TALER_EXCHANGE_Keys));
@ -1211,9 +1217,10 @@ deserialize_data (struct TALER_EXCHANGE_Handle *exchange,
* disk (to be used with #TALER_EXCHANGE_OPTION_DATA to more * disk (to be used with #TALER_EXCHANGE_OPTION_DATA to more
* efficiently recover the state). * efficiently recover the state).
* *
* @param exchange which exchange's key and wire data should be serialized * @param exchange which exchange's key and wire data should be
* @return NULL on error (i.e. no current data available); otherwise * serialized
* json object owned by the caller * @return NULL on error (i.e. no current data available);
* otherwise JSON object owned by the caller
*/ */
json_t * json_t *
TALER_EXCHANGE_serialize_data (struct TALER_EXCHANGE_Handle *exchange) TALER_EXCHANGE_serialize_data (struct TALER_EXCHANGE_Handle *exchange)
@ -1461,17 +1468,19 @@ request_keys (void *cls)
{ {
char *arg; char *arg;
TALER_LOG_DEBUG ("Last DK issue date (before GETting /keys): %s\n",
GNUNET_STRINGS_absolute_time_to_string (exchange->key_data.last_denom_issue_date));
GNUNET_asprintf (&arg, GNUNET_asprintf (&arg,
"/keys?last_issue_date=%llu", "/keys?last_issue_date=%llu",
(unsigned long long) exchange->key_data.last_denom_issue_date.abs_value_us / 1000000LLU); (unsigned long long) exchange->key_data.last_denom_issue_date.abs_value_us / 1000000LLU);
kr->url = TEAH_path_to_url (exchange, kr->url = TEAH_path_to_url (exchange,
arg); arg);
GNUNET_free (arg); GNUNET_free (arg);
} }
else else
{ {
kr->url = TEAH_path_to_url (exchange, kr->url = TEAH_path_to_url (exchange,
"/keys"); "/keys");
} }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Requesting keys with URL `%s'.\n", "Requesting keys with URL `%s'.\n",