From a261b98c73643a16e70ce4f22ed7cd8838967689 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 31 Dec 2021 21:04:08 +0100 Subject: default to account expiration minimum of 1 year --- src/backend/anastasis-httpd_policy_upload.c | 25 ++++++++++++++++--------- src/stasis/plugin_anastasis_postgres.c | 25 ++++++++++++++++++++++--- 2 files changed, 38 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/backend/anastasis-httpd_policy_upload.c b/src/backend/anastasis-httpd_policy_upload.c index 11f15e2..0bef15f 100644 --- a/src/backend/anastasis-httpd_policy_upload.c +++ b/src/backend/anastasis-httpd_policy_upload.c @@ -574,6 +574,10 @@ begin_payment (struct PolicyUploadContext *puc) order_id = GNUNET_STRINGS_data_to_string_alloc ( &puc->payment_identifier, sizeof(struct ANASTASIS_PaymentSecretP)); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Creating order for %u years with payment of %s\n", + puc->years_to_pay, + TALER_amount2s (&upload_fee)); order = json_pack ("{s:o, s:s, s:[{s:s,s:I,s:s}], s:s }", "amount", TALER_JSON_from_amount (&upload_fee), "summary", "Anastasis policy storage fee", @@ -846,7 +850,7 @@ AH_handler_policy_post ( } else { - years = 0; + years = 1; } puc->end_date = GNUNET_TIME_relative_to_timestamp ( GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_YEARS, @@ -865,6 +869,10 @@ AH_handler_policy_post ( / GNUNET_TIME_UNIT_YEARS.rel_value_us; if (0 != (rem.rel_value_us % GNUNET_TIME_UNIT_YEARS.rel_value_us)) puc->years_to_pay++; + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Calculated years to pay to be %u until %s\n", + puc->years_to_pay, + GNUNET_TIME_absolute2s (puc->end_date.abs_time)); if (puc->payment_identifier_provided) { @@ -905,18 +913,14 @@ AH_handler_policy_post ( if (! puc->payment_identifier_provided) { - struct TALER_Amount zero_amount; enum GNUNET_DB_QueryStatus qs; struct GNUNET_TIME_Relative rel; - TALER_amount_set_zero (AH_currency, - &zero_amount); /* generate fresh payment identifier */ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG, &puc->payment_identifier, sizeof (struct ANASTASIS_PaymentSecretP)); - if (0 != TALER_amount_cmp (&AH_annual_fee, - &zero_amount)) + if (! TALER_amount_is_zero (&AH_annual_fee)) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, "No payment identifier, requesting payment\n"); @@ -940,8 +944,8 @@ AH_handler_policy_post ( ANASTASIS_MAX_YEARS_STORAGE); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Policy lifetime is %s (%u years)\n", - GNUNET_STRINGS_relative_time_to_string (rel, - GNUNET_YES), + GNUNET_TIME_relative2s (rel, + true), ANASTASIS_MAX_YEARS_STORAGE); puc->paid_until = GNUNET_TIME_relative_to_timestamp (rel); qs = db->update_lifetime (db->cls, @@ -983,7 +987,10 @@ AH_handler_policy_post ( / GNUNET_TIME_UNIT_YEARS.rel_value_us; if (0 != (rem.rel_value_us % GNUNET_TIME_UNIT_YEARS.rel_value_us)) puc->years_to_pay++; - + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Calculated years to pay to be %u until %s\n", + puc->years_to_pay, + GNUNET_TIME_absolute2s (puc->end_date.abs_time)); if ( (ANASTASIS_DB_ACCOUNT_STATUS_VALID_HASH_RETURNED == as) && (0 != puc->years_to_pay) ) { diff --git a/src/stasis/plugin_anastasis_postgres.c b/src/stasis/plugin_anastasis_postgres.c index 6bb7f32..b2391f8 100644 --- a/src/stasis/plugin_anastasis_postgres.c +++ b/src/stasis/plugin_anastasis_postgres.c @@ -1051,7 +1051,8 @@ retry: /** - * Increment account lifetime. + * Increment account lifetime based on payment having been received. + * Does nothing if the payment is not new. * * @param cls closure * @param account_pub which account received a payment @@ -1071,6 +1072,11 @@ postgres_increment_lifetime ( struct PostgresClosure *pg = cls; enum GNUNET_DB_QueryStatus qs; + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Incrementing lifetime of account %s based on payment by %s\n", + TALER_B2S (account_pub), + GNUNET_TIME_relative2s (lifetime, + true)); check_connection (pg); for (unsigned int retries = 0; retriesconn, "user_insert", params); @@ -1160,7 +1173,8 @@ postgres_increment_lifetime ( case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) { - /* existing rec doc payment, return expiration */ + /* existing rec doc payment (payment replay), return + existing expiration */ *paid_until = expiration; rollback (pg); GNUNET_log (GNUNET_ERROR_TYPE_INFO, @@ -1171,13 +1185,18 @@ postgres_increment_lifetime ( } else { - /* user exists, update expiration_date */ + /* user exists, payment is new, update expiration_date */ struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_timestamp (&expiration), GNUNET_PQ_query_param_auto_from_type (account_pub), GNUNET_PQ_query_param_end }; + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Incrementing lifetime of account %s by %s\n", + TALER_B2S (account_pub), + GNUNET_TIME_relative2s (lifetime, + true)); expiration = GNUNET_TIME_absolute_to_timestamp ( GNUNET_TIME_absolute_add (expiration.abs_time, -- cgit v1.2.3