[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis] 04/07: work on rec doc upload
From: |
gnunet |
Subject: |
[taler-anastasis] 04/07: work on rec doc upload |
Date: |
Thu, 26 Nov 2020 12:54:11 +0100 |
This is an automated email from the git hooks/post-receive script.
dennis-neufeld pushed a commit to branch master
in repository anastasis.
commit 0d9dbd5ab24e92051a75a84209c64bbd5da1985a
Author: Dennis Neufeld <dennis.neufeld@students.bfh.ch>
AuthorDate: Wed Nov 25 15:44:06 2020 +0100
work on rec doc upload
---
src/cli/test_anastasis_reducer_enter_secret.sh | 2 +-
src/lib/anastasis.c | 31 +++---
src/lib/anastasis_api_backup_redux.c | 138 ++++++++++++++++++-------
src/lib/anastasis_api_policy_store.c | 6 ++
4 files changed, 126 insertions(+), 51 deletions(-)
diff --git a/src/cli/test_anastasis_reducer_enter_secret.sh
b/src/cli/test_anastasis_reducer_enter_secret.sh
index 63f9c6b..61a7dab 100755
--- a/src/cli/test_anastasis_reducer_enter_secret.sh
+++ b/src/cli/test_anastasis_reducer_enter_secret.sh
@@ -21,7 +21,7 @@ function cleanup()
do
kill $n 2> /dev/null || true
done
- rm -f $SFILE $TFILE $CONF_1 $CONF_2 $CONF_3 $CONF_4
+ rm -f $TFILE $CONF_1 $CONF_2 $CONF_3 $CONF_4
wait
}
diff --git a/src/lib/anastasis.c b/src/lib/anastasis.c
index b8f725a..9cd7685 100644
--- a/src/lib/anastasis.c
+++ b/src/lib/anastasis.c
@@ -1478,7 +1478,17 @@ policy_store_cb (void *cls,
struct PolicyStoreState *pss = cls;
pss->pso = NULL;
pss->ec = ec;
-
+ if ((http_status != pss->http_status) &&
+ (http_status != MHD_HTTP_PAYMENT_REQUIRED))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected response code %u/%d in %s:%u\n",
+ http_status,
+ (int) ec,
+ __FILE__,
+ __LINE__);
+ return;
+ }
if (NULL != ud)
{
switch (ud->us)
@@ -1543,9 +1553,6 @@ policy_store_cb (void *cls,
ec);
pss->ss->spc = NULL;
}
- // FIXME: Wrong place for cleanup!
- // ANASTASIS_secret_share_cancel (pss->ss);
- // policy_store_cleanup (pss);
}
return;
case ANASTASIS_US_CONFLICTING_POLICY:
@@ -1563,7 +1570,6 @@ policy_store_cb (void *cls,
GNUNET_break (0);
return;
}
-
if (NULL != pss->ss->src)
{
pss->ss->src (pss->ss->src_cls,
@@ -1573,9 +1579,6 @@ policy_store_cb (void *cls,
http_status);
pss->ss->src = NULL;
}
- // FIXME: Wrong place for cleanup!
- // ANASTASIS_secret_share_cancel (pss->ss);
- // policy_store_cleanup (pss);
}
}
@@ -1724,10 +1727,6 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
ss->src_cls = src_cls;
ss->ctx = ctx;
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "At %s:%d pss_length is %d\n", __FILE__, __LINE__,
- ss->pss_length);
-
for (unsigned int i = 0; i < policies_len; i++)
{
policy_keys[i] = policies[i]->policy_key;
@@ -1929,7 +1928,7 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
for (unsigned int l = 0; l < ss->pss_length; l++)
{
- // ss->pss[l]->http_status = MHD_HTTP_NO_CONTENT;
+ ss->pss[l]->http_status = MHD_HTTP_NO_CONTENT;
ANASTASIS_CRYPTO_user_identifier_derive (id_data,
ss->pss[l]->server_salt,
@@ -1968,7 +1967,11 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
&ss->pss[l]->payment_secret,
&policy_store_cb,
ss->pss[l]);
- GNUNET_assert (NULL != ss->pss[l]->pso);
+ if (NULL == ss->pss[l]->pso)
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
}
return ss;
}
diff --git a/src/lib/anastasis_api_backup_redux.c
b/src/lib/anastasis_api_backup_redux.c
index 1197041..82d9b10 100644
--- a/src/lib/anastasis_api_backup_redux.c
+++ b/src/lib/anastasis_api_backup_redux.c
@@ -231,7 +231,7 @@ struct SecretShareState
/**
* Array of truth upload states.
*/
-static struct TruthUploadState *tus_arr;
+static struct TruthUploadState **tus_arr;
/**
* The length of the #tus_arr array.
@@ -241,12 +241,12 @@ static unsigned int tus_arr_length;
/**
* Array of policies.
*/
-static struct ANASTASIS_Policy **policy_arr;
+const static struct ANASTASIS_Policy **policy_arr;
/**
* The length of the #tus_arr array.
*/
-static unsigned int policy_arr_length;
+static unsigned int policy_arr_length = 0;
/**
@@ -1159,7 +1159,6 @@ check_uploads (json_t *uploads)
GNUNET_assert (json_is_array (uploads));
size_t index;
json_t *upload;
- bool pass = true;
json_array_foreach (uploads, index, upload)
{
@@ -1167,11 +1166,10 @@ check_uploads (json_t *uploads)
"status"));
if (status != 204)
{
- pass = false;
- break;
+ return false;
}
}
- return pass;
+ return true;
}
@@ -1183,32 +1181,35 @@ check_uploads (json_t *uploads)
static void
initialize_policies (json_t *state)
{
- size_t index;
+ size_t p_index;
json_t *json_policy;
json_t *json_policies = json_object_get (state,
"policies");
GNUNET_assert (json_is_array (json_policies));
- json_array_foreach (json_policies, index, json_policy)
+ json_array_foreach (json_policies, p_index, json_policy)
{
- unsigned int truth_length;
- size_t auth_method_index;
+ size_t index;
+ unsigned int truth_index = 0;
json_t *auth_method;
- json_t*auth_method_arr = json_object_get (json_policy,
- "methods");
+ json_t *auth_method_arr = json_object_get (json_policy,
+ "methods");
const struct ANASTASIS_Truth *truths[json_array_size (auth_method_arr)];
json_array_foreach (auth_method_arr,
- auth_method_index,
+ index,
auth_method)
{
- unsigned int truth_index = json_integer_value (json_object_get (
- auth_method,
- "auth_method_index"));
- truths[truth_index] = tus_arr[truth_index].truth;
+ unsigned int auth_method_index = json_integer_value (json_object_get (
+ auth_method,
+
"authentication_method"));
+ GNUNET_assert (NULL != tus_arr[0]->truth);
+ GNUNET_assert (NULL != tus_arr[auth_method_index]->truth);
+ truths[truth_index] = tus_arr[auth_method_index]->truth;
+ truth_index++;
}
struct ANASTASIS_Policy *policy = ANASTASIS_policy_create (truths,
- truth_length);
+ truth_index);
GNUNET_array_append (policy_arr,
policy_arr_length,
policy);
@@ -1230,10 +1231,6 @@ secret_share_payment_cb (void *cls,
const char *server_url,
enum TALER_ErrorCode ec)
{
- const char *m;
- struct SecretShareState *sss = cls;
- sss->sso = NULL;
-
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"At %s:%d we are in SPC\n",
__FILE__, __LINE__);
@@ -1242,6 +1239,35 @@ secret_share_payment_cb (void *cls,
__FILE__, __LINE__,
taler_pay_url);
+ const char *m;
+ size_t index;
+ json_t *upload;
+ struct SecretShareState *sss = cls;
+ json_t *rec_doc_uploads = json_object_get (sss->state,
+ "recovery_document_uploads");
+
+ GNUNET_assert (json_is_array (rec_doc_uploads));
+ sss->sso = NULL;
+
+ json_array_foreach (rec_doc_uploads, index, upload)
+ {
+ const char *url = json_string_value (
+ json_object_get (upload,
+ "backend_url"));
+ if (0 == strcmp (url, server_url))
+ {
+ GNUNET_assert (0 ==
+ json_object_set (upload,
+ "status",
+ json_integer ((json_int_t) 402)));
+ GNUNET_assert (0 ==
+ json_object_set (upload,
+ "pay_url",
+ json_string (taler_pay_url)));
+ break;
+ }
+ }
+
m = strstr (taler_pay_url, "/-/-/");
if (NULL == m)
{
@@ -1261,11 +1287,17 @@ secret_share_payment_cb (void *cls,
return;
}
sss->payment_order_id = GNUNET_strdup (&m[strlen ("/-/-/")]);
+
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"At %s:%d Order ID from Anastasis service is %s\n",
__FILE__, __LINE__,
sss->payment_order_id);
-
+ set_state (sss->state,
+ ANASTASIS_backup_state_to_string (
+ ANASTASIS_BACKUP_STATE_POLICIES_PAYING));
+ sss->cb (sss->cb_cls,
+ ANASTASIS_EC_NONE,
+ sss->state);
// FIXME: payment
}
@@ -1286,11 +1318,34 @@ secret_share_result_cb (void *cls,
const enum TALER_ErrorCode ec,
unsigned int http_status)
{
- struct SecretShareState *sss = cls;
- sss->sso = NULL;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"At %s:%d we are in SRC\n",
__FILE__, __LINE__);
+
+ size_t index;
+ json_t *upload;
+ struct SecretShareState *sss = cls;
+ json_t *rec_doc_uploads = json_object_get (sss->state,
+ "recovery_document_uploads");
+
+ GNUNET_assert (json_is_array (rec_doc_uploads));
+ sss->sso = NULL;
+
+ json_array_foreach (rec_doc_uploads, index, upload)
+ {
+ const char *url = json_string_value (
+ json_object_get (upload,
+ "backend_url"));
+ if (0 == strcmp (url, server_url))
+ {
+ GNUNET_assert (0 ==
+ json_object_set (upload,
+ "status",
+ json_integer ((json_int_t)
http_status)));
+ break;
+ }
+ }
+
if (NULL != sss)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1304,6 +1359,13 @@ secret_share_result_cb (void *cls,
"At %s:%d http status is %u\n", __FILE__, __LINE__,
http_status);
+ if (check_uploads (rec_doc_uploads))
+ {
+ set_state (sss->state,
+ ANASTASIS_backup_state_to_string (
+ ANASTASIS_BACKUP_STATE_BACKUP_FINISHED));
+ }
+
sss->cb (sss->cb_cls,
ANASTASIS_EC_NONE,
sss->state);
@@ -1327,15 +1389,15 @@ upload_rec_documents (json_t *state,
ANASTASIS_ActionCallback cb,
void *cb_cls)
{
- if (! policy_arr_length)
+ if (0 == policy_arr_length)
{
initialize_policies (state);
}
struct SecretShareState *sss = GNUNET_new (struct SecretShareState);
- GNUNET_assert (0 ==
+ GNUNET_assert (NULL !=
(sss->id_data = json_object_get (state,
"identity_attributes")));
- GNUNET_assert (0 ==
+ GNUNET_assert (NULL !=
(sss->core_secret = json_object_get (state,
"core_secret")));
json_t *core_secret = json_object_get (state,
@@ -1363,6 +1425,7 @@ upload_rec_documents (json_t *state,
(void *) sss->core_secret,
sss->core_secret_size);
}
+ sss->state = json_incref (state);
// FIXME: implement PaymentDetails
sss->sso = ANASTASIS_secret_share (ctx,
sss->id_data,
@@ -1419,7 +1482,10 @@ truth_upload_cb (void *cls,
json_integer ((json_int_t) 204)));
tus->truth = t;
- if (check_uploads (truth_uploads))
+ if (check_uploads (truth_uploads) &&
+ (json_array_size (
+ json_object_get (tus->state, "truths"))
+ == (size_t) tus_arr_length))
{
// try uploading recovery document
size_t t_index;
@@ -1431,15 +1497,11 @@ truth_upload_cb (void *cls,
GNUNET_assert (json_is_array (truths));
GNUNET_assert (json_is_array (rec_doc_uploads));
- GNUNET_assert (0 ==
- json_object_set (tus->state,
- "recovery_document_uploads",
- json_array ()));
json_array_foreach (truths, t_index, truth)
{
json_t *upload;
json_t *backend_url = json_object_get (truth,
- "backend_url"));
+ "backend_url");
json_array_foreach (rec_doc_uploads, rd_index, upload)
{
@@ -1457,6 +1519,10 @@ truth_upload_cb (void *cls,
json_integer ((json_int_t) 0)));
}
}
+ GNUNET_assert (0 ==
+ json_object_set_new (tus->state,
+ "recovery_document_uploads",
+ rec_doc_uploads));
upload_rec_documents (tus->state,
tus->ctx,
@@ -1622,7 +1688,7 @@ enter_secret (json_t *state,
&tus->user_id);
GNUNET_array_append (tus_arr,
tus_arr_length,
- *tus);
+ tus);
tus->tuo = ANASTASIS_truth_upload (tus->ctx,
&tus->user_id,
tus->anastasis_url,
diff --git a/src/lib/anastasis_api_policy_store.c
b/src/lib/anastasis_api_policy_store.c
index ad9a839..d1418f6 100644
--- a/src/lib/anastasis_api_policy_store.c
+++ b/src/lib/anastasis_api_policy_store.c
@@ -184,6 +184,12 @@ handle_policy_store_finished (void *cls,
ec = TALER_JSON_get_error_code2 (data,
data_size);
break;
+ case MHD_HTTP_INTERNAL_SERVER_ERROR:
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Internal server error: `%.*s\n",
+ (int) data_size,
+ (const char *) data);
+ break;
}
if (NULL != pso->cb)
{
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [taler-anastasis] branch master updated (c21a333 -> 3f7c3b8), gnunet, 2020/11/26
- [taler-anastasis] 02/07: fix, gnunet, 2020/11/26
- [taler-anastasis] 05/07: fix, gnunet, 2020/11/26
- [taler-anastasis] 03/07: worked on rec doc upload, gnunet, 2020/11/26
- [taler-anastasis] 01/07: worked on rec doc upload, gnunet, 2020/11/26
- [taler-anastasis] 04/07: work on rec doc upload,
gnunet <=
- [taler-anastasis] 06/07: Merge branch 'master' of ssh://git.taler.net/anastasis, gnunet, 2020/11/26
- [taler-anastasis] 07/07: worked on rec doc upload, gnunet, 2020/11/26