[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis] branch master updated: fix bad 0-cost account lifetime
From: |
gnunet |
Subject: |
[taler-anastasis] branch master updated: fix bad 0-cost account lifetime bump |
Date: |
Mon, 19 Jul 2021 09:52:47 +0200 |
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 ca36eee fix bad 0-cost account lifetime bump
ca36eee is described below
commit ca36eee1c84d8abe4f0fa72e7cb2a9e12bd18c97
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Mon Jul 19 09:52:44 2021 +0200
fix bad 0-cost account lifetime bump
---
src/backend/anastasis-httpd_policy_upload.c | 8 +-
src/include/anastasis_database_plugin.h | 20 +++-
src/stasis/plugin_anastasis_postgres.c | 138 ++++++++++++++++++++++++++++
3 files changed, 161 insertions(+), 5 deletions(-)
diff --git a/src/backend/anastasis-httpd_policy_upload.c
b/src/backend/anastasis-httpd_policy_upload.c
index 24f150b..c8f8e87 100644
--- a/src/backend/anastasis-httpd_policy_upload.c
+++ b/src/backend/anastasis-httpd_policy_upload.c
@@ -928,10 +928,10 @@ AH_handler_policy_post (
GNUNET_STRINGS_relative_time_to_string (rel,
GNUNET_YES),
ANASTASIS_MAX_YEARS_STORAGE);
- qs = db->increment_lifetime (db->cls,
- account_pub,
- &puc->payment_identifier,
- rel);
+ qs = db->update_lifetime (db->cls,
+ account_pub,
+ &puc->payment_identifier,
+ GNUNET_TIME_relative_to_absolute (rel));
if (qs <= 0)
{
GNUNET_break (0);
diff --git a/src/include/anastasis_database_plugin.h
b/src/include/anastasis_database_plugin.h
index b7ae2dc..0584b73 100644
--- a/src/include/anastasis_database_plugin.h
+++ b/src/include/anastasis_database_plugin.h
@@ -432,7 +432,7 @@ struct ANASTASIS_DatabasePlugin
/**
- * Increment account lifetime.
+ * Increment account lifetime by @a lifetime.
*
* @param cls closure
* @param account_pub which account received a payment
@@ -448,6 +448,24 @@ struct ANASTASIS_DatabasePlugin
struct GNUNET_TIME_Relative lifetime);
+ /**
+ * Update account lifetime to the maximum of the current
+ * value and @a eol.
+ *
+ * @param cls closure
+ * @param account_pub which account received a payment
+ * @param payment_identifier proof of payment, must be unique and match
pending payment
+ * @param eol for how long is the account now paid (absolute)
+ * @return transaction status
+ */
+ enum GNUNET_DB_QueryStatus
+ (*update_lifetime)(
+ void *cls,
+ const struct ANASTASIS_CRYPTO_AccountPublicKeyP *anastasis_pub,
+ const struct ANASTASIS_PaymentSecretP *payment_identifier,
+ struct GNUNET_TIME_Absolute eol);
+
+
/**
* Store payment. Used to begin a payment, not indicative
* that the payment actually was made. (That is done
diff --git a/src/stasis/plugin_anastasis_postgres.c
b/src/stasis/plugin_anastasis_postgres.c
index 7c82e2c..4cccc3a 100644
--- a/src/stasis/plugin_anastasis_postgres.c
+++ b/src/stasis/plugin_anastasis_postgres.c
@@ -629,6 +629,143 @@ retry:
}
+/**
+ * Update account lifetime to the maximum of the current
+ * value and @a eol.
+ *
+ * @param cls closure
+ * @param account_pub which account received a payment
+ * @param payment_identifier proof of payment, must be unique and match
pending payment
+ * @param eol for how long is the account now paid (absolute)
+ * @return transaction status
+ */
+static enum GNUNET_DB_QueryStatus
+postgres_update_lifetime (
+ void *cls,
+ const struct ANASTASIS_CRYPTO_AccountPublicKeyP *anastasis_pub,
+ const struct ANASTASIS_PaymentSecretP *payment_identifier,
+ struct GNUNET_TIME_Absolute eol)
+{
+ struct PostgresClosure *pg = cls;
+ enum GNUNET_DB_QueryStatus qs;
+
+ check_connection (pg);
+ for (unsigned int retries = 0; retries<MAX_RETRIES; retries++)
+ {
+ if (GNUNET_OK !=
+ begin_transaction (pg,
+ "update lifetime"))
+ {
+ GNUNET_break (0);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+
+ {
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (payment_identifier),
+ GNUNET_PQ_query_param_auto_from_type (anastasis_pub),
+ GNUNET_PQ_query_param_end
+ };
+ qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "recdoc_payment_done",
+ params);
+ if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
+ goto retry;
+ if (0 >= qs)
+ {
+ /* payment made before, or unknown, or error => no further action! */
+ rollback (pg);
+ return qs;
+ }
+ }
+
+ {
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (anastasis_pub),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_TIME_Absolute expiration;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_absolute_time ("expiration_date",
+ &expiration),
+ GNUNET_PQ_result_spec_end
+ };
+
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "user_select",
+ params,
+ rs);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ rollback (pg);
+ return qs;
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ goto retry;
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ {
+ /* user does not exist, create new one */
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (anastasis_pub),
+ GNUNET_PQ_query_param_absolute_time (&eol),
+ GNUNET_PQ_query_param_end
+ };
+
+ GNUNET_break (GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us !=
+ eol.abs_value_us);
+ qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "user_insert",
+ params);
+ }
+ break;
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ {
+ /* user exists, update expiration_date */
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_absolute_time (&expiration),
+ GNUNET_PQ_query_param_auto_from_type (anastasis_pub),
+ GNUNET_PQ_query_param_end
+ };
+
+ expiration = GNUNET_TIME_absolute_max (expiration,
+ eol);
+ GNUNET_break (GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us !=
+ expiration.abs_value_us);
+ qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "user_update",
+ params);
+ }
+ break;
+ }
+ }
+
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ rollback (pg);
+ return qs;
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ goto retry;
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ GNUNET_break (0);
+ rollback (pg);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ break;
+ }
+ qs = commit_transaction (pg);
+ if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
+ goto retry;
+ if (qs < 0)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
+retry:
+ rollback (pg);
+ }
+ return GNUNET_DB_STATUS_SOFT_ERROR;
+}
+
+
/**
* Store payment. Used to begin a payment, not indicative
* that the payment actually was made. (That is done
@@ -2061,6 +2198,7 @@ libanastasis_plugin_db_postgres_init (void *cls)
plugin->lookup_account = &postgres_lookup_account;
plugin->check_payment_identifier = &postgres_check_payment_identifier;
plugin->increment_lifetime = &postgres_increment_lifetime;
+ plugin->update_lifetime = &postgres_update_lifetime;
plugin->start = &begin_transaction;
plugin->check_connection = &check_connection;
plugin->verify_challenge_code = &postgres_verify_challenge_code;
--
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 bad 0-cost account lifetime bump,
gnunet <=