[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [taler-anastasis] branch master updated: worked on plugin
From: |
gnunet |
Subject: |
[GNUnet-SVN] [taler-anastasis] branch master updated: worked on plugin |
Date: |
Tue, 22 Oct 2019 10:51:40 +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 1e98d61 worked on plugin
1e98d61 is described below
commit 1e98d614b25c075a2de6e4e076e2eda54d8250cf
Author: Dominik Meister <address@hidden>
AuthorDate: Tue Oct 22 10:51:31 2019 +0200
worked on plugin
---
src/backup-db/plugin_anastasis_postgres.c | 297 +++++++++++++++++-------------
src/include/anastasis_database_plugin.h | 49 +++--
2 files changed, 211 insertions(+), 135 deletions(-)
diff --git a/src/backup-db/plugin_anastasis_postgres.c
b/src/backup-db/plugin_anastasis_postgres.c
index b2d1266..263f2b1 100644
--- a/src/backup-db/plugin_anastasis_postgres.c
+++ b/src/backup-db/plugin_anastasis_postgres.c
@@ -128,85 +128,54 @@ postgres_preflight (void *cls)
}
-/**
- * Start a transaction.
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @param name unique name identifying the transaction (for debugging),
- * must point to a constant
- * @return #GNUNET_OK on success
- */
static int
-postgres_start (void *cls,
- const char *name)
+begin_transaction (struct PostgresClosure *pg)
{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_ExecuteStatement es[] = {
- GNUNET_PQ_make_execute ("START TRANSACTION ISOLATION LEVEL SERIALIZABLE"),
- GNUNET_PQ_EXECUTE_STATEMENT_END
- };
+ struct GNUNET_PQ_ExecuteStatement es[] = {
+ GNUNET_PQ_make_execute ("START TRANSACTION ISOLATION LEVEL
SERIALIZABLE"),
+ GNUNET_PQ_EXECUTE_STATEMENT_END
+ };
- check_connection (pg);
- postgres_preflight (pg);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting anastasis DB transaction\n");
- if (GNUNET_OK !=
- GNUNET_PQ_exec_statements (pg->conn,
- es))
- {
- TALER_LOG_ERROR ("Failed to start transaction\n");
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
- pg->transaction_name = name;
- return GNUNET_OK;
+ if (GNUNET_OK !=
+ GNUNET_PQ_exec_statements (pg->conn,
+ es))
+ {
+ TALER_LOG_ERROR ("Failed to start transaction\n");
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_OK;
}
-/**
- * Roll back the current transaction of a database connection.
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @return #GNUNET_OK on success
- */
static void
-postgres_rollback (void *cls)
+rollback (struct PostgresClosure *pg)
{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_ExecuteStatement es[] = {
- GNUNET_PQ_make_execute ("ROLLBACK"),
- GNUNET_PQ_EXECUTE_STATEMENT_END
- };
+ struct GNUNET_PQ_ExecuteStatement es[] = {
+ GNUNET_PQ_make_execute ("ROLLBACK"),
+ GNUNET_PQ_EXECUTE_STATEMENT_END
+ };
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Rolling back anastasis DB transaction\n");
- GNUNET_break (GNUNET_OK ==
- GNUNET_PQ_exec_statements (pg->conn,
- es));
- pg->transaction_name = NULL;
+ if (GNUNET_OK !=
+ GNUNET_PQ_exec_statements (pg->conn,
+ es))
+ {
+ TALER_LOG_ERROR ("Failed to rollback transaction\n");
+ GNUNET_break (0);
+ }
}
-/**
- * Commit the current transaction of a database connection.
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @return transaction status code
- */
static enum GNUNET_DB_QueryStatus
-postgres_commit (void *cls)
+commit_transaction (struct PostgresClosure *pg)
{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_end
- };
+ struct GNUNET_PQ_QueryParam no_params[] = {
+ GNUNET_PQ_query_param_end
+ };
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Committing anastasis DB transaction\n");
- pg->transaction_name = NULL;
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "end_transaction",
- params);
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "do_commit",
+ no_params);
}
/**
@@ -232,6 +201,37 @@ postgres_store_recovery_document (void *cls,
{
struct PostgresClosure *pg = cls;
enum GNUNET_DB_QueryStatus qs;
+<<<<<<< HEAD
+
+ check_connection (pg);
+
+ if (GNUNET_OK !=
+ begin_transaction (pg))
+ {
+ GNUNET_break (0);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (anastasis_pub),
+ GNUNET_PQ_query_param_end
+ };
+ /*
+
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_result_spec_absolute_time ("paid_until", &paid_until),
+ GNUNET_PQ_result_spec_end
+ };
+
+ */
+
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "user_select",
+ params,
+ rs);
+
+ struct GNUNET_PQ_QueryParam params[] = {
+=======
struct GNUNET_TIME_Absolute paid_until;
check_connection (pg);
@@ -243,6 +243,7 @@ postgres_store_recovery_document (void *cls,
}
struct GNUNET_PQ_QueryParam params[] = {
+>>>>>>> c733ae84027eb667643aed21dcb94b958926101d
GNUNET_PQ_query_param_auto_from_type (anastasis_pub),
GNUNET_PQ_query_param_end
};
@@ -274,6 +275,12 @@ postgres_store_recovery_document (void *cls,
break;
}
+<<<<<<< HEAD
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "inserting recovery document: user_id: %s, version: %i.\n",
+ GNUNET_p2s (anastasis_pub),
+ version);
+=======
//upload if last payment is still valid
if (GNUNET_TIME_absolute_get_difference(GNUNET_TIME_absolute_get, paid_until
!= 0))
@@ -312,59 +319,28 @@ postgres_store_recovery_document (void *cls,
return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
}
+>>>>>>> c733ae84027eb667643aed21dcb94b958926101d
-static int
-begin_transaction (struct PostgresClosure *pg)
-{
- struct GNUNET_PQ_ExecuteStatement es[] = {
- GNUNET_PQ_make_execute ("START TRANSACTION ISOLATION LEVEL SERIALIZABLE"),
- GNUNET_PQ_EXECUTE_STATEMENT_END
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_exec_statements (pg->conn,
- es))
- {
- TALER_LOG_ERROR ("Failed to start transaction\n");
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
- return GNUNET_OK;
-}
-
-
-static void
-rollback (struct PostgresClosure *pg)
-{
- struct GNUNET_PQ_ExecuteStatement es[] = {
- GNUNET_PQ_make_execute ("ROLLBACK"),
- GNUNET_PQ_EXECUTE_STATEMENT_END
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_exec_statements (pg->conn,
- es))
- {
- TALER_LOG_ERROR ("Failed to rollback transaction\n");
- GNUNET_break (0);
+ qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "recovery_document_insert",
+ params);
+ 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:
+ //FIXME ?
+ rollback(pg);
+ return qs;
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ return commit_transaction(pg);
}
}
-
-static enum GNUNET_DB_QueryStatus
-commit_transaction (struct PostgresClosure *pg)
-{
- struct GNUNET_PQ_QueryParam no_params[] = {
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "do_commit",
- no_params);
-}
-
-
-
/**
* FIXME
* Insert proposal data and its hashcode into db
@@ -511,6 +487,69 @@ postgres_record_payment (void *cls,
}
+/**
+ * Upload Truth, which contains the Truth and the KeyShare.
+ *
+ * @param cls closure
+ * @param uuid the identifier for the Truth
+ * @param truth_data contains the encrypted Truth which includes the ground
truth i.e. H(challange answer), phonenumber, SMS
+ * @param truth_data_size the size of the Truth
+ * @param truth_expiration time till the according data will be stored
+ * @return transaction status
+ */
+
+static enum GNUNET_DB_QueryStatus
+postgres_store_truth (void *cls,
+ const struct ANASTASIS_uuid *uuid,
+ const void *truth_data,
+ size_t truth_data_size,
+ struct GNUNET_TIME_Relative truth_expiration);
+{
+ struct PostgresClosure *pg = cls;
+ enum GNUNET_DB_QueryStatus qs;
+ struct GNUNET_TIME_Absolute expiration = GNUNET_TIME_absolute_get ();
+ expiration = GNUNET_TIME_absolute_add (expiration, truth_expiration);
+
+
+ check_connection (pg);
+ if (GNUNET_OK != begin_transaction (pg))
+ {
+ GNUNET_break (0);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+
+struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (uuid),
+ GNUNET_PQ_query_param_fixed_size (truth_data, truth_data_size),
+ GNUNET_PQ_query_param_auto_from_type (expiration),
+ GNUNET_PQ_query_param_end
+};
+
+ qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,"truth_insert", 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;
+}
+
+ qs = commit_transaction (pg);
+ if (qs < 0) {
+ return qs;
+ }
+
+ return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
+}
+
/**
* Initialize Postgres database subsystem.
*
@@ -565,31 +604,43 @@ libtaler_plugin_anastasis_db_postgres_init (void *cls)
0),
GNUNET_PQ_make_prepare ("user_select",
"SELECT"
- " paid_until "
+ " paid_until "
"FROM anastasis_user"
" WHERE user_id=$1"
" FOR UPDATE;",
1),
GNUNET_PQ_make_prepare ("user_update",
"UPDATE anastasis_user"
- " SET "
+ " SET "
" paid_until=$1"
" WHERE user_id=$2;",
2),
- GNUNET_PQ_make_prepare ("user_insert",
- "INSERT INTO anastasis_user "
- "(user_id"
- ",paid_until"
- ") VALUES($1,$2)",
- 2),
GNUNET_PQ_make_prepare ("payment_insert",
- "INSERT INTO anastasis_payments "
+ "INSERT INTO anastasis_recoverydocument"
"(user_id"
",post_counter"
- ",payment_identifier",
+ ",payment_identifier",
") VALUES "
"($1, $2, $3);",
3),
+
+ GNUNET_PQ_make_prepare ("truth_insert",
+ "INSERT INTO anastasis_truth "
+ "(truth_id"
+ ",truth"
+ ",expiration",
+ ") VALUES "
+ "($1, $2, $3);",
+ 3),
+ GNUNET_PQ_make_prepare ("recovery_document_insert",
+ "INSERT INTO anastasis_recoverydocument "
+ "(user_id"
+ ",version"
+ ",recovery_data",
+ ") VALUES "
+ "($1, $2, $3);",
+ 3),
+
GNUNET_PQ_PREPARED_STATEMENT_END
};
diff --git a/src/include/anastasis_database_plugin.h
b/src/include/anastasis_database_plugin.h
index 0ab6931..5d5c95a 100644
--- a/src/include/anastasis_database_plugin.h
+++ b/src/include/anastasis_database_plugin.h
@@ -107,6 +107,43 @@ struct AnastasisDatabasePlugin
(*gc)(void *cls,
struct GNUNET_TIME_Absolute fin_expire);
+ /**
+ * Do a pre-flight check that we are not in an uncommitted transaction.
+ * If we are, try to commit the previous transaction and output a warning.
+ * Does not return anything, as we will continue regardless of the outcome.
+ *
+ * @param cls the `struct PostgresClosure` with the plugin-specific state
+ */
+ void
+ (*preflight) (void *cls);
+
+ /**
+ * Roll back the current transaction of a database connection.
+ *
+ * @param cls the `struct PostgresClosure` with the plugin-specific state
+ * @return #GNUNET_OK on success
+ */
+ void
+ (*rollback) (void *cls);
+
+ /**
+ * Start a transaction.
+ *
+ * @param cls the `struct PostgresClosure` with the plugin-specific state
+ * @return #GNUNET_OK on success
+ */
+ int
+ (*start) (void *cls);
+
+ /**
+ * Commit the current transaction of a database connection.
+ *
+ * @param cls the `struct PostgresClosure` with the plugin-specific state
+ * @return transaction status code
+ */
+ enum GNUNET_DB_QueryStatus
+ (*commit)(void *cls);
+
/**
* Record user payment.
*
@@ -235,18 +272,6 @@ struct AnastasisDatabasePlugin
size_t *truth_size,
char **truth_mime,
size_t *truth_mime_size);
-
- /**
- * Do a pre-flight check that we are not in an uncommitted transaction.
- * If we are, try to commit the previous transaction and output a warning.
- * Does not return anything, as we will continue regardless of the outcome.
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- */
- void
- (*preflight) (void *cls);
-
-
};
#endif
--
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 plugin,
gnunet <=