[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis] 02/02: misc policy upload bugfixes
From: |
gnunet |
Subject: |
[taler-anastasis] 02/02: misc policy upload bugfixes |
Date: |
Mon, 01 Mar 2021 13:15:15 +0100 |
This is an automated email from the git hooks/post-receive script.
grothoff pushed a commit to branch master
in repository anastasis.
commit b5c7383c1eb3e3a433ba45bfb06727827160058b
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Mon Mar 1 13:15:11 2021 +0100
misc policy upload bugfixes
---
src/cli/test_anastasis_reducer_enter_secret.sh | 8 +-
src/lib/anastasis_backup.c | 58 ++++++----
src/reducer/anastasis_api_backup_redux.c | 154 +++++++++++++++++--------
3 files changed, 144 insertions(+), 76 deletions(-)
diff --git a/src/cli/test_anastasis_reducer_enter_secret.sh
b/src/cli/test_anastasis_reducer_enter_secret.sh
index a2e3bc3..36521d1 100755
--- a/src/cli/test_anastasis_reducer_enter_secret.sh
+++ b/src/cli/test_anastasis_reducer_enter_secret.sh
@@ -282,13 +282,13 @@ $PREFIX anastasis-reducer -a \
STATE=`jq -r -e .backup_state < $TFILE`
if test "$STATE" != "POLICIES_PAYING"
then
- exit_fail "Expected new state to be POLICIES_PAYING, got $STATE"
+ exit_fail "Expected new state to be 'POLICIES_PAYING', got '$STATE'"
fi
-OBJECT_SIZE=`jq -r -e '.truth_uploads | length' < $TFILE`
-if test $OBJECT_SIZE -lt 3
+TMETHOD=`jq -r -e '.policies[0].methods[0].truth.type' < $TFILE`
+if test $TMETHOD != "question"
then
- exit_fail "Expected truth_uploads array length to be >= 3, got
$OBJECT_SIZE"
+ exit_fail "Expected method to be >='question', got $TMETHOD"
fi
echo " OK"
diff --git a/src/lib/anastasis_backup.c b/src/lib/anastasis_backup.c
index b6b792f..9d0be85 100644
--- a/src/lib/anastasis_backup.c
+++ b/src/lib/anastasis_backup.c
@@ -63,7 +63,7 @@ struct ANASTASIS_Truth
char *instructions;
/**
- * Mime type of the truth.
+ * Mime type of the truth, NULL if not given.
*/
char *mime_type;
@@ -85,7 +85,7 @@ ANASTASIS_truth_from_json (const json_t *json)
const char *url;
const char *type;
const char *instructions;
- const char *mime_type;
+ const char *mime_type = NULL;
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_string ("url",
&url),
@@ -93,8 +93,9 @@ ANASTASIS_truth_from_json (const json_t *json)
&type),
GNUNET_JSON_spec_string ("instructions",
&instructions),
- GNUNET_JSON_spec_string ("mime_type",
- &mime_type),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_string ("mime_type",
+ &mime_type)),
GNUNET_JSON_spec_fixed_auto ("uuid",
&t->uuid),
GNUNET_JSON_spec_fixed_auto ("key_share",
@@ -118,7 +119,8 @@ ANASTASIS_truth_from_json (const json_t *json)
t->url = GNUNET_strdup (url);
t->type = GNUNET_strdup (type);
t->instructions = GNUNET_strdup (instructions);
- t->mime_type = GNUNET_strdup (mime_type);
+ if (NULL != mime_type)
+ t->mime_type = GNUNET_strdup (mime_type);
return t;
}
@@ -137,7 +139,7 @@ ANASTASIS_truth_to_json (const struct ANASTASIS_Truth *t)
{
return json_pack (
"{s:o,s:o,s:o,s:o"
- ",s:s,s:s,s:s,s:s}",
+ ",s:s,s:s,s:s,s:s?}",
"uuid",
GNUNET_JSON_from_data_auto (&t->uuid),
"key_share",
@@ -147,13 +149,13 @@ ANASTASIS_truth_to_json (const struct ANASTASIS_Truth *t)
"salt",
GNUNET_JSON_from_data_auto (&t->salt),
"url",
- json_string (t->url),
+ t->url,
"type",
- json_string (t->type),
+ t->type,
"instructions",
- json_string (t->instructions),
+ t->instructions,
"mime_type",
- json_string (t->mime_type));
+ t->mime_type);
}
@@ -371,7 +373,8 @@ truth_dup (const struct ANASTASIS_Truth *t)
d->url = GNUNET_strdup (t->url);
d->type = GNUNET_strdup (t->type);
d->instructions = GNUNET_strdup (t->instructions);
- d->mime_type = GNUNET_strdup (t->mime_type);
+ if (NULL != t->mime_type)
+ d->mime_type = GNUNET_strdup (t->mime_type);
return d;
}
@@ -449,7 +452,7 @@ struct PolicyStoreState
/**
* URL of the anastasis backend.
*/
- const char *anastasis_url;
+ char *anastasis_url;
/**
* Payment request returned by this provider, if any.
@@ -566,12 +569,16 @@ policy_store_cb (void *cls,
struct ANASTASIS_ShareResult sr;
for (unsigned int i = 0; i<ss->pss_length; i++)
+ {
+ struct PolicyStoreState *pssi = &ss->pss[i];
+
if (NULL != ss->pss[i].payment_request)
{
- spr[off].payment_request_url = pss[i].payment_request;
- spr[off].provider_url = pss[i].anastasis_url;
+ spr[off].payment_request_url = pssi->payment_request;
+ spr[off].provider_url = pssi->anastasis_url;
off++;
}
+ }
if (off > 0)
{
sr.ss = ANASTASIS_SHARE_STATUS_PAYMENT_REQUIRED;
@@ -727,7 +734,7 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
for (unsigned int l = 0; l < policy->truths_length; l++)
{
- struct ANASTASIS_Truth *pt = policy->truths[l];
+ const struct ANASTASIS_Truth *pt = policy->truths[l];
bool unique = true;
/* Only append each truth once */
@@ -799,12 +806,12 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
/* new provider, setup per-provider data structure */
{
- struct PolicyStoreState *pss;
+ struct PolicyStoreState *pssi;
GNUNET_assert (index_pss < pss_length);
- pss = &ss->pss[index_pss++];
- pss->anastasis_url = pt->url;
- pss->server_salt = &pt->salt;
+ pssi = &ss->pss[index_pss++];
+ pssi->anastasis_url = GNUNET_strdup (pt->url);
+ pssi->server_salt = &pt->salt;
for (unsigned int m = 0; 0 < pds_len; m++)
{
if (NULL == pds[m].provider_url)
@@ -812,7 +819,7 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
if (0 == strcmp (pds[m].provider_url,
pt->url))
{
- pss->payment_secret = pds[m].payment_secret;
+ pssi->payment_secret = pds[m].payment_secret;
break;
}
}
@@ -921,12 +928,15 @@ ANASTASIS_secret_share_cancel (struct
ANASTASIS_SecretShare *ss)
{
for (unsigned int i = 0; i<ss->pss_length; i++)
{
- if (NULL != ss->pss[i].pso)
+ struct PolicyStoreState *pssi = &ss->pss[i];
+
+ if (NULL != pssi->pso)
{
- ANASTASIS_policy_store_cancel (ss->pss[i].pso);
- ss->pss[i].pso = NULL;
+ ANASTASIS_policy_store_cancel (pssi->pso);
+ pssi->pso = NULL;
}
- GNUNET_free (ss->pss[i].payment_request);
+ GNUNET_free (pssi->anastasis_url);
+ GNUNET_free (pssi->payment_request);
}
GNUNET_free (ss->pss);
GNUNET_free (ss);
diff --git a/src/reducer/anastasis_api_backup_redux.c
b/src/reducer/anastasis_api_backup_redux.c
index a4c31e4..4619623 100644
--- a/src/reducer/anastasis_api_backup_redux.c
+++ b/src/reducer/anastasis_api_backup_redux.c
@@ -1298,6 +1298,50 @@ upload_cancel_cb (void *cls)
}
+/**
+ * Take all of the ongoing truth uploads and serialize them into the @a uc
+ * state.
+ *
+ * @param[in,out] uc context to take truth uploads from and to update state of
+ */
+static void
+serialize_truth (struct UploadContext *uc)
+{
+ json_t *policies;
+
+ policies = json_object_get (uc->state,
+ "policies");
+ GNUNET_assert (json_is_array (policies));
+ for (struct TruthUpload *tue = uc->tues_head;
+ NULL != tue;
+ tue = tue->next)
+ {
+ if (NULL == tue->t)
+ continue;
+ for (unsigned int i = 0; i<tue->policies_length; i++)
+ {
+ const struct PolicyMethodReference *pmr = &tue->policies[i];
+ json_t *policy = json_array_get (policies,
+ pmr->policy_index);
+ json_t *methods = json_object_get (policy,
+ "methods");
+ json_t *auth_method = json_array_get (methods,
+ pmr->method_index);
+ json_t *truth = ANASTASIS_truth_to_json (tue->t);
+
+ GNUNET_assert (NULL != policy);
+ GNUNET_assert (NULL != methods);
+ GNUNET_assert (NULL != auth_method);
+ GNUNET_assert (NULL != truth);
+ GNUNET_assert (0 ==
+ json_object_set_new (auth_method,
+ "truth",
+ truth));
+ }
+ }
+}
+
+
/**
* Function called with the results of a #ANASTASIS_secret_share().
*
@@ -1326,6 +1370,7 @@ secret_share_result_cb (void *cls,
set_state (uc->state,
ANASTASIS_BACKUP_STATE_POLICIES_PAYING);
+ serialize_truth (uc);
ra = json_array ();
GNUNET_assert (NULL != ra);
for (unsigned int i = 0; i<
@@ -1470,20 +1515,59 @@ share_secret (struct UploadContext *uc)
"truth");
GNUNET_break (NULL != jmethod);
- GNUNET_break (NULL != jtruth);
- truths[j] = ANASTASIS_truth_from_json (jtruth);
- if (NULL == truths[j])
+ if (NULL != jtruth)
{
- GNUNET_break (0);
- for (unsigned int k = 0; k<j; k++)
- ANASTASIS_truth_free (truths[k]);
- ANASTASIS_redux_fail_ (uc->cb,
- uc->cb_cls,
- TALER_EC_ANASTASIS_REDUCER_STATE_INVALID,
- "'truth' failed to decode");
- GNUNET_JSON_parse_free (spec);
- upload_cancel_cb (uc);
- return;
+ /* Get truth by deserializing from state */
+ truths[j] = ANASTASIS_truth_from_json (jtruth);
+ if (NULL == truths[j])
+ {
+ GNUNET_break (0);
+ for (unsigned int k = 0; k<j; k++)
+ ANASTASIS_truth_free (truths[k]);
+ ANASTASIS_redux_fail_ (uc->cb,
+ uc->cb_cls,
+ TALER_EC_ANASTASIS_REDUCER_STATE_INVALID,
+ "'truth' failed to decode");
+ GNUNET_JSON_parse_free (spec);
+ upload_cancel_cb (uc);
+ return;
+ }
+ }
+ else
+ {
+ bool found = false;
+ /* Maybe we never serialized the truth; find it in our DLL */
+ for (struct TruthUpload *tue = uc->tues_head;
+ NULL != tue;
+ tue = tue->next)
+ {
+ GNUNET_break (NULL != tue->t);
+ if (tue->am_idx == j)
+ {
+ /* Duplicate truth object */
+ json_t *jt = ANASTASIS_truth_to_json (tue->t);
+
+ GNUNET_assert (NULL != jt);
+ truths[j] = ANASTASIS_truth_from_json (jt);
+ GNUNET_assert (NULL != truths[j]);
+ json_decref (jt);
+ found = true;
+ break;
+ }
+ }
+ if (! found)
+ {
+ GNUNET_break (0);
+ for (unsigned int k = 0; k<j; k++)
+ ANASTASIS_truth_free (truths[k]);
+ ANASTASIS_redux_fail_ (uc->cb,
+ uc->cb_cls,
+ TALER_EC_ANASTASIS_REDUCER_STATE_INVALID,
+ "'truth' failed to decode");
+ GNUNET_JSON_parse_free (spec);
+ upload_cancel_cb (uc);
+ return;
+ }
}
ctruths[j] = truths[j];
}
@@ -1563,48 +1647,21 @@ static void
request_truth_payment (struct UploadContext *uc)
{
json_t *payments;
- json_t *policies;
- policies = json_object_get (uc->state,
- "policies");
- GNUNET_assert (json_is_array (policies));
payments = json_array ();
GNUNET_assert (NULL != payments);
+ serialize_truth (uc);
for (struct TruthUpload *tue = uc->tues_head;
NULL != tue;
tue = tue->next)
{
- if (NULL != tue->payment_request)
- {
- GNUNET_assert (
- 0 ==
- json_array_append_new (payments,
- json_string (
- tue->payment_request)));
- }
- if (NULL != tue->t)
- {
- for (unsigned int i = 0; i<tue->policies_length; i++)
- {
- const struct PolicyMethodReference *pmr = &tue->policies[i];
- json_t *policy = json_array_get (policies,
- pmr->policy_index);
- json_t *methods = json_object_get (policy,
- "methods");
- json_t *auth_method = json_array_get (methods,
- pmr->method_index);
- json_t *truth = ANASTASIS_truth_to_json (tue->t);
-
- GNUNET_assert (NULL != policy);
- GNUNET_assert (NULL != methods);
- GNUNET_assert (NULL != auth_method);
- GNUNET_assert (NULL != truth);
- GNUNET_assert (0 ==
- json_object_set_new (auth_method,
- "truth",
- truth));
- }
- }
+ if (NULL == tue->payment_request)
+ continue;
+ GNUNET_assert (
+ 0 ==
+ json_array_append_new (payments,
+ json_string (
+ tue->payment_request)));
}
GNUNET_assert (0 ==
json_object_set_new (uc->state,
@@ -1917,6 +1974,7 @@ check_truth_upload (struct UploadContext *uc,
tue->policies = GNUNET_new (struct PolicyMethodReference);
*tue->policies = *pmr;
tue->provider_url = GNUNET_strdup (provider_url);
+ tue->am_idx = am_idx;
tue->policies_length = 1;
if (GNUNET_OK !=
lookup_salt (uc->state,
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.