[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis] branch master updated: fix pay handling
From: |
gnunet |
Subject: |
[taler-anastasis] branch master updated: fix pay handling |
Date: |
Tue, 16 Mar 2021 17:39:25 +0100 |
This is an automated email from the git hooks/post-receive script.
grothoff pushed a commit to branch master
in repository anastasis.
The following commit(s) were added to refs/heads/master by this push:
new fe7c461 fix pay handling
fe7c461 is described below
commit fe7c461bf354bf78a26f05d894f3a43bc65662a4
Author: Christian Grothoff <grothoff@gnunet.org>
AuthorDate: Tue Mar 16 17:39:22 2021 +0100
fix pay handling
---
src/backend/anastasis-httpd_policy_upload.c | 64 ++++++++++++------------
src/backend/anastasis-httpd_truth_upload.c | 52 ++++++++++----------
src/reducer/anastasis_api_backup_redux.c | 75 ++++++++++++++++++++++++++---
src/reducer/anastasis_api_recovery_redux.c | 18 +++----
4 files changed, 136 insertions(+), 73 deletions(-)
diff --git a/src/backend/anastasis-httpd_policy_upload.c
b/src/backend/anastasis-httpd_policy_upload.c
index f0107b9..178ebdd 100644
--- a/src/backend/anastasis-httpd_policy_upload.c
+++ b/src/backend/anastasis-httpd_policy_upload.c
@@ -778,6 +778,39 @@ AH_handler_policy_post (
ANASTASIS_HTTP_HEADER_POLICY_SIGNATURE);
}
}
+
+ {
+ const char *long_poll_timeout_ms;
+
+ long_poll_timeout_ms = MHD_lookup_connection_value (connection,
+
MHD_GET_ARGUMENT_KIND,
+ "timeout_ms");
+ if (NULL != long_poll_timeout_ms)
+ {
+ unsigned int timeout;
+
+ if (1 != sscanf (long_poll_timeout_ms,
+ "%u",
+ &timeout))
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_BAD_REQUEST,
+
TALER_EC_GENERIC_PARAMETER_MALFORMED,
+ "timeout_ms (must be non-negative
number)");
+ }
+ puc->timeout
+ = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply (
+ GNUNET_TIME_UNIT_MILLISECONDS,
+ timeout));
+ }
+ else
+ {
+ puc->timeout = GNUNET_TIME_relative_to_absolute
+ (CHECK_PAYMENT_GENERIC_TIMEOUT);
+ }
+ }
+
/* get ready to hash (done here as we may go async for payments next) */
puc->hash_ctx = GNUNET_CRYPTO_hash_context_start ();
@@ -915,37 +948,6 @@ AH_handler_policy_post (
break;
}
}
- {
- const char *long_poll_timeout_ms;
-
- long_poll_timeout_ms = MHD_lookup_connection_value (connection,
-
MHD_GET_ARGUMENT_KIND,
- "timeout_ms");
- if (NULL != long_poll_timeout_ms)
- {
- unsigned int timeout;
-
- if (1 != sscanf (long_poll_timeout_ms,
- "%u",
- &timeout))
- {
- GNUNET_break_op (0);
- return TALER_MHD_reply_with_error (connection,
- MHD_HTTP_BAD_REQUEST,
-
TALER_EC_GENERIC_PARAMETER_MALFORMED,
- "timeout_ms (must be non-negative
number)");
- }
- puc->timeout
- = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply (
- GNUNET_TIME_UNIT_MILLISECONDS,
- timeout));
- }
- else
- {
- puc->timeout = GNUNET_TIME_relative_to_absolute
- (CHECK_PAYMENT_GENERIC_TIMEOUT);
- }
- }
/* ready to begin! */
return MHD_YES;
}
diff --git a/src/backend/anastasis-httpd_truth_upload.c
b/src/backend/anastasis-httpd_truth_upload.c
index dec029f..e13bfcd 100644
--- a/src/backend/anastasis-httpd_truth_upload.c
+++ b/src/backend/anastasis-httpd_truth_upload.c
@@ -488,32 +488,6 @@ AH_handler_truth_post (
}
}
- {
- struct TALER_Amount zero_amount;
-
- TALER_amount_get_zero (AH_currency,
- &zero_amount);
- if (0 != TALER_amount_cmp (&AH_truth_upload_fee,
- &zero_amount))
- {
- struct GNUNET_TIME_Absolute paid_until;
- enum GNUNET_DB_QueryStatus qs;
-
- qs = db->check_truth_upload_paid (db->cls,
- truth_uuid,
- &paid_until);
- if (qs < 0)
- return TALER_MHD_reply_with_error (connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_GENERIC_DB_FETCH_FAILED,
- NULL);
- if ( (0 == qs) ||
- (0 ==
- GNUNET_TIME_absolute_get_remaining (paid_until).rel_value_us) )
- return begin_payment (tuc);
- }
- }
-
{
const char *long_poll_timeout_ms;
@@ -546,6 +520,32 @@ AH_handler_truth_post (
}
}
+ {
+ struct TALER_Amount zero_amount;
+
+ TALER_amount_get_zero (AH_currency,
+ &zero_amount);
+ if (0 != TALER_amount_cmp (&AH_truth_upload_fee,
+ &zero_amount))
+ {
+ struct GNUNET_TIME_Absolute paid_until;
+ enum GNUNET_DB_QueryStatus qs;
+
+ qs = db->check_truth_upload_paid (db->cls,
+ truth_uuid,
+ &paid_until);
+ if (qs < 0)
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ NULL);
+ if ( (0 == qs) ||
+ (0 ==
+ GNUNET_TIME_absolute_get_remaining (paid_until).rel_value_us) )
+ return begin_payment (tuc);
+ }
+ }
+
} /* end 'if (NULL == tuc)' */
if (NULL != tuc->resp)
diff --git a/src/reducer/anastasis_api_backup_redux.c
b/src/reducer/anastasis_api_backup_redux.c
index 7da288a..debbbae 100644
--- a/src/reducer/anastasis_api_backup_redux.c
+++ b/src/reducer/anastasis_api_backup_redux.c
@@ -1472,9 +1472,6 @@ share_secret (struct UploadContext *uc)
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_json ("identity_attributes",
&user_id),
- GNUNET_JSON_spec_mark_optional (
- GNUNET_JSON_spec_relative_time ("timeout",
- &timeout)),
GNUNET_JSON_spec_mark_optional (
GNUNET_JSON_spec_bool ("force_pay",
&force_payment)),
@@ -1501,6 +1498,38 @@ share_secret (struct UploadContext *uc)
upload_cancel_cb (uc);
return;
}
+
+ {
+ json_t *args;
+ struct GNUNET_JSON_Specification pspec[] = {
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_relative_time ("timeout",
+ &timeout)),
+ GNUNET_JSON_spec_end ()
+ };
+
+ args = json_object_get (uc->state,
+ "pay-arguments");
+ if ( (NULL != args) &&
+ (GNUNET_OK !=
+ GNUNET_JSON_parse (args,
+ pspec,
+ NULL, NULL)) )
+ {
+ json_dumpf (args,
+ stderr,
+ JSON_INDENT (2));
+ GNUNET_break (0);
+ ANASTASIS_redux_fail_ (uc->cb,
+ uc->cb_cls,
+ TALER_EC_ANASTASIS_REDUCER_INPUT_INVALID,
+ NULL);
+ upload_cancel_cb (uc);
+ return;
+ }
+ }
+
+
if ( (! json_is_object (user_id)) ||
(! json_is_array (jpolicies)) ||
(0 == json_array_size (jpolicies)) ||
@@ -1977,6 +2006,7 @@ check_truth_upload (struct UploadContext *uc,
json_t *auth_method)
{
json_t *user_id;
+ struct GNUNET_TIME_Relative timeout = GNUNET_TIME_UNIT_ZERO;
user_id = json_object_get (uc->state,
"identity_attributes");
@@ -2002,6 +2032,31 @@ check_truth_upload (struct UploadContext *uc,
}
}
+ {
+ json_t *args;
+ struct GNUNET_JSON_Specification pspec[] = {
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_relative_time ("timeout",
+ &timeout)),
+ GNUNET_JSON_spec_end ()
+ };
+
+ args = json_object_get (uc->state,
+ "pay-arguments");
+ if ( (NULL != args) &&
+ (GNUNET_OK !=
+ GNUNET_JSON_parse (args,
+ pspec,
+ NULL, NULL)) )
+ {
+ json_dumpf (args,
+ stderr,
+ JSON_INDENT (2));
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ }
+
/* need new upload */
{
struct TruthUpload *tue = GNUNET_new (struct TruthUpload);
@@ -2012,13 +2067,9 @@ check_truth_upload (struct UploadContext *uc,
bool force_payment = false;
void *truth_data;
size_t truth_data_size;
- struct GNUNET_TIME_Relative timeout = GNUNET_TIME_UNIT_ZERO;
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_string ("type",
&type),
- GNUNET_JSON_spec_mark_optional (
- GNUNET_JSON_spec_relative_time ("timeout",
- &timeout)),
GNUNET_JSON_spec_mark_optional (
GNUNET_JSON_spec_bool ("force_pay",
&force_payment)),
@@ -2349,6 +2400,11 @@ pay_truths_backup (json_t *state,
/* Clear 'payments' if it exists */
(void) json_object_del (state,
"payments");
+ if (NULL != arguments)
+ GNUNET_assert (0 ==
+ json_object_set (state,
+ "pay-arguments",
+ (json_t *) arguments));
return upload (state,
cb,
cb_cls);
@@ -2374,6 +2430,11 @@ pay_policies_backup (json_t *state,
/* Clear 'policy_payment_requests' if it exists */
(void) json_object_del (state,
"policy_payment_requests");
+ if (NULL != arguments)
+ GNUNET_assert (0 ==
+ json_object_set (state,
+ "pay-arguments",
+ (json_t *) arguments));
return upload (state,
cb,
cb_cls);
diff --git a/src/reducer/anastasis_api_recovery_redux.c
b/src/reducer/anastasis_api_recovery_redux.c
index 90f1785..1757c43 100644
--- a/src/reducer/anastasis_api_recovery_redux.c
+++ b/src/reducer/anastasis_api_recovery_redux.c
@@ -519,8 +519,8 @@ answer_feedback_cb (
* @param ri recovery information struct which contains the policies
*/
static void
-run_challenge_cb (void *cls,
- const struct ANASTASIS_RecoveryInformation *ri)
+solve_challenge_cb (void *cls,
+ const struct ANASTASIS_RecoveryInformation *ri)
{
struct SelectChallengeContext *sctx = cls;
const struct ANASTASIS_PaymentSecretP *psp = NULL;
@@ -837,10 +837,10 @@ pay_challenge_cb (void *cls,
* @return handle to cancel challenge selection step
*/
static struct ANASTASIS_ReduxAction *
-run_challenge (json_t *state,
- const json_t *arguments,
- ANASTASIS_ActionCallback cb,
- void *cb_cls)
+solve_challenge (json_t *state,
+ const json_t *arguments,
+ ANASTASIS_ActionCallback cb,
+ void *cb_cls)
{
struct SelectChallengeContext *sctx
= GNUNET_new (struct SelectChallengeContext);
@@ -878,7 +878,7 @@ run_challenge (json_t *state,
ANASTASIS_redux_fail_ (cb,
cb_cls,
TALER_EC_ANASTASIS_REDUCER_STATE_INVALID,
- "run_challenge");
+ "solve_challenge");
return NULL;
}
sctx->cb = cb;
@@ -887,7 +887,7 @@ run_challenge (json_t *state,
sctx->args = json_incref ((json_t*) arguments);
sctx->r = ANASTASIS_recovery_deserialize (ANASTASIS_REDUX_ctx_,
rd,
- &run_challenge_cb,
+ &solve_challenge_cb,
sctx,
&core_secret_cb,
sctx);
@@ -1326,7 +1326,7 @@ ANASTASIS_recovery_action_ (json_t *state,
{
ANASTASIS_RECOVERY_STATE_CHALLENGE_SOLVING,
"solve_challenge",
- &run_challenge
+ &solve_challenge
},
{
ANASTASIS_RECOVERY_STATE_CHALLENGE_SOLVING,
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-anastasis] branch master updated: fix pay handling,
gnunet <=