[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [taler-anastasis] branch master updated: worked on recovery
From: |
gnunet |
Subject: |
[GNUnet-SVN] [taler-anastasis] branch master updated: worked on recoverydoc upload |
Date: |
Wed, 23 Oct 2019 18:00:28 +0200 |
This is an automated email from the git hooks/post-receive script.
ds-meister pushed a commit to branch master
in repository anastasis.
The following commit(s) were added to refs/heads/master by this push:
new e7e93bd worked on recoverydoc upload
e7e93bd is described below
commit e7e93bdba3210123240c6c20bf105848aec571a1
Author: Dominik Meister <address@hidden>
AuthorDate: Wed Oct 23 18:00:20 2019 +0200
worked on recoverydoc upload
---
src/backup-db/plugin_anastasis_postgres.c | 161 ++++++++++++++++++++++++++----
src/include/anastasis_database_plugin.h | 2 +-
2 files changed, 143 insertions(+), 20 deletions(-)
diff --git a/src/backup-db/plugin_anastasis_postgres.c
b/src/backup-db/plugin_anastasis_postgres.c
index add37da..f0b5a87 100644
--- a/src/backup-db/plugin_anastasis_postgres.c
+++ b/src/backup-db/plugin_anastasis_postgres.c
@@ -197,19 +197,20 @@ postgres_store_recovery_document (void *cls,
size_t data_size,
const struct
ANASTASIS_PaymentSecretP *payment_secret,
- uint32_t *version)
+ uint32_t **version)
{
struct PostgresClosure *pg = cls;
enum GNUNET_DB_QueryStatus qs;
+ uint32_t postcounter;
- check_connection (pg);
- if (GNUNET_OK !=
- begin_transaction (pg))
- {
+ check_connection (pg);
+ if (GNUNET_OK != begin_transaction (pg))
+ {
GNUNET_break (0);
return GNUNET_DB_STATUS_HARD_ERROR;
- }
+ }
+ // Check if user has paid
struct GNUNET_TIME_Absolute paid_until;
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (anastasis_pub),
@@ -242,20 +243,117 @@ postgres_store_recovery_document (void *cls,
break;
}
- //upload if last payment is still valid
- if (GNUNET_TIME_absolute_get_difference(GNUNET_TIME_absolute_get, paid_until
!= 0))
- {
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (anastasis_pub),
- GNUNET_PQ_query_param_auto_from_type (version),
- GNUNET_PQ_query_param_fixed_size (data, data_size),
- GNUNET_PQ_query_param_end
- };
+ //rollback if user hasn't paid
+ if (GNUNET_TIME_absolute_get_difference(GNUNET_TIME_absolute_get, paid_until
== 0)) {
+ rollback(pg);
+ return GNUNET_DB_STATUS_SOFT_ERROR; //FIXME maybe differnet errorcode?
+ }
- qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "recovery_document_insert",
params);
+ //lookup if the user has enough uploads left and decrement
+
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (anastasis_pub),
+ GNUNET_PQ_query_param_auto_from_type (payment_secret),
+ GNUNET_PQ_query_param_end
+ };
+
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint32 ("post_counter", &postcounter),
+ GNUNET_PQ_result_spec_end
+ };
+
+
+ qs = GNUNET_PQ_eval_prepared_singleton_select
(pg->conn,"postcounter_select", params, rs);
+
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ rollback (pg);
+ return qs;
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ // FIXME: or: retry internally?
+ rollback (pg);
+ return qs;
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ rollback (pg);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ break;
+ }
+
+ if (postcounter == 0 ) {
+ rollback(pg);
+ return GNUNET_DB_STATUS_SOFT_ERROR; //FIXME maybe differnet errorcode?
+ }
+ //decrement the postcounter
+ postcounter--;
+
+ //update the postcounter
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (&postcounter),
+ GNUNET_PQ_query_param_absolute_time (anastasis_pub),
+ GNUNET_PQ_query_param_auto_from_type (payment_secret),
+ GNUNET_PQ_query_param_end
+ };
+ qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,"postcounter_update",
params);
+
+ switch (qs) {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ rollback (pg);
+ return qs;
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ rollback (pg);
+ return qs;
+
+ 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;
+ }
+
+ //get the version for the recoverydocument
+
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (anastasis_pub),
+ GNUNET_PQ_query_param_end
+ };
+
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint32 ("version", version),
+ GNUNET_PQ_result_spec_end
+ };
+
+ qs = GNUNET_PQ_eval_prepared_singleton_select
(pg->conn,"latest_recovery_version_select", params, rs);
+
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ rollback (pg);
+ return qs;
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ // FIXME: or: retry internally?
+ rollback (pg);
+ return qs;
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ version = 1;
+ break;
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ version++;
+ break;
}
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (anastasis_pub),
+ GNUNET_PQ_query_param_auto_from_type (version),
+ GNUNET_PQ_query_param_fixed_size (data, data_size),
+ GNUNET_PQ_query_param_end
+ };
+
+ qs = GNUNET_PQ_eval_prepared_non_select
(pg->conn,"recovery_document_insert", params);
+
+
switch (qs)
{
case GNUNET_DB_STATUS_HARD_ERROR:
@@ -284,7 +382,6 @@ postgres_store_recovery_document (void *cls,
/**
* FIXME
- * Insert proposal data and its hashcode into db
*
* @param cls closure
* @param amount amount of taler to be paid
@@ -671,7 +768,7 @@ libtaler_plugin_anastasis_db_postgres_init (void *cls)
( payment_id BIGSERIAL PRIMARY KEY,
user_id BYTEA NOT NULL REFERENCES
anastasis_user(user_id),
post_counter INTEGER,
- payment_identifier BYTEA NOT NULL
CHECK(LENGTH(payment_secret)=32),
+ payment_identifier BYTEA NOT NULL
CHECK(LENGTH(payment_identifier)=32),
transaction_time TIMESTAMP NOT NULL DEFAULT NOW()
);"),
GNUNET_PQ_make_execute ("CREATE TABLE anastasis_recoverydocument
@@ -748,6 +845,15 @@ libtaler_plugin_anastasis_db_postgres_init (void *cls)
"LIMIT 1;",
1),
+ GNUNET_PQ_make_prepare ("latest_recovery_version_select",
+ "SELECT "
+ "version "
+ "FROM anastasis_recoverydocument "
+ "WHERE user_id =$1 "
+ "ORDER BY version DESC "
+ "LIMIT 1;",
+ 1),
+
GNUNET_PQ_make_prepare ("recoverydocument_select",
"SELECT "
"recovery_data "
@@ -756,6 +862,23 @@ libtaler_plugin_anastasis_db_postgres_init (void *cls)
"AND version=$2;",
2),
+ GNUNET_PQ_make_prepare ("postcounter_select",
+ "SELECT "
+ "post_counter "
+ "FROM anastasis_payments "
+ "WHERE user_id =$1 "
+ "AND payment_identifier=$2;",
+ 2),
+
+ GNUNET_PQ_make_prepare ("postcounter_update",
+ "UPDATE "
+ "anastasis_payments "
+ "SET "
+ "post_counter=$1 "
+ "WHERE user_id =$2 "
+ "AND payment_identifier=$3;",
+ 3),
+
GNUNET_PQ_PREPARED_STATEMENT_END
};
diff --git a/src/include/anastasis_database_plugin.h
b/src/include/anastasis_database_plugin.h
index 5d5c95a..43e0573 100644
--- a/src/include/anastasis_database_plugin.h
+++ b/src/include/anastasis_database_plugin.h
@@ -183,7 +183,7 @@ struct AnastasisDatabasePlugin
size_t data_size,
const struct
ANASTASIS_PaymentSecretP *payment_secret,
- uint32_t *version);
+ uint32_t **version);
/**
* Fetch recovery document for user.
--
To stop receiving notification emails like this one, please contact
address@hidden.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] [taler-anastasis] branch master updated: worked on recoverydoc upload,
gnunet <=