donau

Donation authority for GNU Taler (experimental)
Log | Files | Refs | Submodules | README | LICENSE

commit 55b5eb66483b7e7c7113483cabf12c6e6166199a
parent 07e16f6240951ae6ae70aea24f5989daf803e353
Author: Matyja Lukas Adam <lukas.matyja@students.bfh.ch>
Date:   Wed, 27 Mar 2024 10:45:32 +0100

merge

Diffstat:
Msrc/donau/.gitignore | 22+++++++++++-----------
Msrc/donau/donau-httpd_get-charities.c | 5+++--
Msrc/donau/donau-httpd_get-history.c | 4+++-
Msrc/donau/donau-httpd_keys.c | 46++++++++++++++++++++++++----------------------
Msrc/donaudb/pg_get_charities.c | 51+++++++++++++++++++++++++++++----------------------
Msrc/donaudb/pg_get_history.c | 42+++++++++++++++++++++++++-----------------
Msrc/donaudb/pg_iterate_donation_units.c | 42+++++++++++++++++++++++++-----------------
Msrc/include/donaudb_plugin.h | 14++++++++++----
8 files changed, 130 insertions(+), 96 deletions(-)

diff --git a/src/donau/.gitignore b/src/donau/.gitignore @@ -1,13 +1,13 @@ -taler-donau-dbinit -taler-donau-keycheck -taler-donau-keyup -taler-donau-pursemod -taler-donau-reservemod -taler-donau-httpd -taler-donau-wirewatch +donau-dbinit +donau-keycheck +donau-keyup +donau-pursemod +donau-reservemod +donau-httpd +donau-wirewatch test_taler_donau_wirewatch-postgres test_taler_donau_httpd_home/.config/taler/account-1.json -taler-donau-closer -taler-donau-transfer -taler-donau-router -taler-donau-expire +donau-closer +donau-transfer +donau-router +donau-expire diff --git a/src/donau/donau-httpd_get-charities.c b/src/donau/donau-httpd_get-charities.c @@ -41,10 +41,10 @@ * * @param cls closure */ -static void +static enum GNUNET_GenericReturnValue charities_cb ( void *cls, - struct DONAU_CharityPublicKeyP charity_pub, + const struct DONAU_CharityPublicKeyP charity_pub, const char *charity_name, const char *charity_url, struct TALER_Amount max_per_year, @@ -70,6 +70,7 @@ charities_cb ( &receipts_to_date), GNUNET_JSON_pack_int64 ("current_year", current_year)))); + return GNUNET_OK; } diff --git a/src/donau/donau-httpd_get-history.c b/src/donau/donau-httpd_get-history.c @@ -41,7 +41,7 @@ * * @param cls closure */ -static void +enum GNUNET_GenericReturnValue history_cb ( void *cls, unsigned long long charity_id, @@ -61,6 +61,8 @@ history_cb ( &final_amount), GNUNET_JSON_pack_int64 ("donation_year", donation_year)))); + + return GNUNET_OK; } diff --git a/src/donau/donau-httpd_keys.c b/src/donau/donau-httpd_keys.c @@ -473,9 +473,9 @@ insert_donation_unit_cb (void *cls, DONAU_JSON_pack_donation_unit_pub ("donation_unit_pub", &du->donation_unit_pub), GNUNET_JSON_pack_uint64 ("year", - du->validity_year), - TALER_JSON_pack_amount ("value", - &du->value) + du->validity_year) // , + // TALER_JSON_pack_amount ("value", // FIXME + // &du->value) ))); return GNUNET_OK; } @@ -488,23 +488,22 @@ insert_donation_unit_cb (void *cls, * @param[in,out] ksh key state handle we build @a ksh for * @param[in] du_keys_hash hash over all the denomination keys in @a denoms * @param[in,out] signkeys list of sign keys to return - * @param[in,out] grouped_donation_units list of grouped denominations to return + * @param[in,out] donation_units list of grouped denominations to return * @return #GNUNET_OK on success */ static enum GNUNET_GenericReturnValue create_keys_response (struct DH_KeyStateHandle *ksh, - const struct GNUNET_HashCode *du_keys_hash, json_t *signkeys, - json_t *grouped_donation_units) + json_t *donation_units) { struct DONAU_DonauPublicKeyP donau_pub; // struct DONAU_DonauSignatureP donau_sig; json_t *keys; GNUNET_assert (NULL != signkeys); - GNUNET_assert (NULL != grouped_donation_units); + GNUNET_assert (NULL != donation_units); GNUNET_assert (NULL != DH_currency); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Creating /keys response"); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Creating /keys response\n"); /* Sign hash over master signatures of all denomination keys until this time (in reverse order). */ @@ -548,9 +547,9 @@ create_keys_response (struct DH_KeyStateHandle *ksh, GNUNET_JSON_pack_array_incref ("signkeys", signkeys), GNUNET_JSON_pack_array_incref ("donation_units", - grouped_donation_units), - GNUNET_JSON_pack_data_auto ("donau_pub", - &donau_pub)); // , + donation_units)); // , + // GNUNET_JSON_pack_data_auto ("donau_pub", + // &donau_pub)); // , // GNUNET_JSON_pack_data_auto ("donau_sig", // &donau_sig)); GNUNET_assert (NULL != keys); @@ -651,12 +650,12 @@ static enum GNUNET_GenericReturnValue finish_keys_response (struct DH_KeyStateHandle *ksh) { enum GNUNET_GenericReturnValue ret = GNUNET_SYSERR; - json_t *grouped_donation_units = NULL; - struct GNUNET_HashContext *hash_context = NULL; struct KeysBuilderContext kbc; kbc.signkeys = json_array (); + kbc.donation_units = json_array (); GNUNET_assert (NULL != kbc.signkeys); + GNUNET_assert (NULL != kbc.donation_units); GNUNET_CONTAINER_multipeermap_iterate (ksh->signkey_map, &add_sign_key_cb, @@ -674,9 +673,13 @@ finish_keys_response (struct DH_KeyStateHandle *ksh) &insert_donation_unit_cb, &kbc); - - grouped_donation_units = json_array (); - GNUNET_assert (NULL != grouped_donation_units); + if (0 == json_array_size (kbc.donation_units)) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "No donation units available. Refusing to generate /keys response.\n"); + ret = GNUNET_NO; + goto CLEANUP; + } { struct DH_DonationUnitKey *dk; @@ -691,7 +694,7 @@ finish_keys_response (struct DH_KeyStateHandle *ksh) // create_keys_response (ksh, // &hc, // kbc.signkeys, - // grouped_donation_units)) + // donation_units)) // { // GNUNET_log (GNUNET_ERROR_TYPE_WARNING, // "Failed to generate key response data\n"); @@ -701,11 +704,8 @@ finish_keys_response (struct DH_KeyStateHandle *ksh) // } } - struct GNUNET_HashCode hc; - GNUNET_CRYPTO_hash_context_finish (hash_context, &hc); if (GNUNET_OK != create_keys_response (ksh, - &hc, kbc.signkeys, kbc.donation_units)) { @@ -717,7 +717,8 @@ finish_keys_response (struct DH_KeyStateHandle *ksh) ret = GNUNET_OK; CLEANUP: - // json_decref (grouped_donation_units); + if (NULL != kbc.donation_units) + json_decref (kbc.donation_units); if (NULL != kbc.signkeys) json_decref (kbc.signkeys); return ret; @@ -1378,7 +1379,7 @@ setup_key_helpers (struct HelperState *hs) * @param donation_unit_pub public key of the donation_unit * @param h_donation_unit_pub hash of @a donation_unit_pub */ -static void +static enum GNUNET_GenericReturnValue donation_unit_info_cb ( void *cls, const struct DONAU_DonationUnitHashP *h_donation_unit_pub, @@ -1433,6 +1434,7 @@ donation_unit_info_cb ( dk, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY) ); + return GNUNET_OK; } diff --git a/src/donaudb/pg_get_charities.c b/src/donaudb/pg_get_charities.c @@ -42,9 +42,14 @@ struct GetCharitiesContext void *cb_cls; /** - * Flag set to #GNUNET_OK as long as everything is fine. + * Plugin context. */ - enum GNUNET_GenericReturnValue status; + struct PostgresClosure *pg; + + /** + * Number of results processed. + */ + enum GNUNET_DB_QueryStatus qs; }; @@ -62,6 +67,7 @@ get_charities_cb (void *cls, unsigned int num_results) { struct GetCharitiesContext *ctx = cls; + struct PostgresClosure *pg = ctx->pg; for (unsigned int i = 0; i < num_results; i++) { @@ -79,11 +85,9 @@ get_charities_cb (void *cls, &charity_name), GNUNET_PQ_result_spec_string ("charity_url", &charity_url), - TALER_PQ_result_spec_amount ("max_per_year", - "EUR", // TODO: Error if using TALER_PQ_RESULT_SPEC_AMOUNT + TALER_PQ_RESULT_SPEC_AMOUNT ("max_per_year", &max_per_year), - TALER_PQ_result_spec_amount ("receipts_to_date", - "EUR", // TODO: Error if using TALER_PQ_RESULT_SPEC_AMOUNT + TALER_PQ_RESULT_SPEC_AMOUNT ("receipts_to_date", &receipts_to_date), GNUNET_PQ_result_spec_uint64 ("current_year", &current_year), @@ -96,17 +100,20 @@ get_charities_cb (void *cls, i)) { GNUNET_break (0); - ctx->status = GNUNET_SYSERR; + ctx->qs = GNUNET_DB_STATUS_HARD_ERROR; return; } - ctx->cb (ctx->cb_cls, - charity_pub, - charity_name, - charity_url, - max_per_year, - receipts_to_date, - current_year); - GNUNET_PQ_cleanup_result (rs); + + ctx->qs = i + 1; + if (GNUNET_OK != + ctx->cb (ctx->cb_cls, + charity_pub, + charity_name, + charity_url, + max_per_year, + receipts_to_date, + current_year)) + break; } } @@ -117,13 +124,13 @@ DH_PG_get_charities (void *cls, void *cb_cls) { struct PostgresClosure *pg = cls; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_end + }; struct GetCharitiesContext ctx = { .cb = cb, .cb_cls = cb_cls, - .status = GNUNET_OK - }; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_end + .pg = pg }; enum GNUNET_DB_QueryStatus qs; @@ -142,7 +149,7 @@ DH_PG_get_charities (void *cls, params, &get_charities_cb, &ctx); - if (GNUNET_OK != ctx.status) - return GNUNET_DB_STATUS_HARD_ERROR; - return qs; + if (qs <= 0) + return qs; + return ctx.qs; } diff --git a/src/donaudb/pg_get_history.c b/src/donaudb/pg_get_history.c @@ -42,9 +42,14 @@ struct GetHistoryContext void *cb_cls; /** - * Flag set to #GNUNET_OK as long as everything is fine. + * Plugin context. */ - enum GNUNET_GenericReturnValue status; + struct PostgresClosure *pg; + + /** + * Number of results processed. + */ + enum GNUNET_DB_QueryStatus qs; }; @@ -62,6 +67,7 @@ get_history_cb (void *cls, unsigned int num_results) { struct GetHistoryContext *ctx = cls; + struct PostgresClosure *pg = ctx->pg; for (unsigned int i = 0; i < num_results; i++) { @@ -72,8 +78,7 @@ get_history_cb (void *cls, struct GNUNET_PQ_ResultSpec rs[] = { GNUNET_PQ_result_spec_uint64 ("charity_id", &charity_id), - TALER_PQ_result_spec_amount ("final_amount", - "EUR", // TODO: Error if using TALER_PQ_RESULT_SPEC_AMOUNT + TALER_PQ_RESULT_SPEC_AMOUNT ("final_amount", &final_amount), GNUNET_PQ_result_spec_uint64 ("donation_year", &donation_year), @@ -86,14 +91,17 @@ get_history_cb (void *cls, i)) { GNUNET_break (0); - ctx->status = GNUNET_SYSERR; + ctx->qs = GNUNET_DB_STATUS_HARD_ERROR; return; } - ctx->cb (ctx->cb_cls, - charity_id, - final_amount, - donation_year); - GNUNET_PQ_cleanup_result (rs); + + ctx->qs = i + 1; + if (GNUNET_OK != + ctx->cb (ctx->cb_cls, + charity_id, + final_amount, + donation_year)) + break; } } @@ -104,13 +112,13 @@ DH_PG_get_history (void *cls, void *cb_cls) { struct PostgresClosure *pg = cls; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_end + }; struct GetHistoryContext ctx = { .cb = cb, .cb_cls = cb_cls, - .status = GNUNET_OK - }; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_end + .pg = pg }; enum GNUNET_DB_QueryStatus qs; @@ -126,7 +134,7 @@ DH_PG_get_history (void *cls, params, &get_history_cb, &ctx); - if (GNUNET_OK != ctx.status) - return GNUNET_DB_STATUS_HARD_ERROR; - return qs; + if (qs <= 0) + return qs; + return ctx.qs; } diff --git a/src/donaudb/pg_iterate_donation_units.c b/src/donaudb/pg_iterate_donation_units.c @@ -42,9 +42,14 @@ struct IterateDonationUnitsContext void *cb_cls; /** + * Plugin context. + */ + struct PostgresClosure *pg; + + /** * Flag set to #GNUNET_OK as long as everything is fine. */ - enum GNUNET_GenericReturnValue status; + enum GNUNET_DB_QueryStatus qs; }; @@ -61,6 +66,7 @@ iterate_donation_units_cb (void *cls, unsigned int num_results) { struct IterateDonationUnitsContext *ctx = cls; + struct PostgresClosure *pg = ctx->pg; for (unsigned int i = 0; i < num_results; i++) { @@ -76,8 +82,7 @@ iterate_donation_units_cb (void *cls, &donation_unit_pub), GNUNET_PQ_result_spec_uint64 ("validity_year", &validity_year), - TALER_PQ_result_spec_amount ("value", - "EUR", // TODO: Error if using TALER_PQ_RESULT_SPEC_AMOUNT + TALER_PQ_RESULT_SPEC_AMOUNT ("value", &value), GNUNET_PQ_result_spec_end }; @@ -88,15 +93,18 @@ iterate_donation_units_cb (void *cls, i)) { GNUNET_break (0); - ctx->status = GNUNET_SYSERR; + ctx->qs = GNUNET_DB_STATUS_HARD_ERROR; return; } - ctx->cb (ctx->cb_cls, - &h_donation_unit_pub, - &donation_unit_pub, - validity_year, - &value); - GNUNET_PQ_cleanup_result (rs); + + ctx->qs = i + 1; + if (GNUNET_OK != + ctx->cb (ctx->cb_cls, + &h_donation_unit_pub, + &donation_unit_pub, + validity_year, + &value)) + break; } } @@ -107,13 +115,13 @@ DH_PG_iterate_donation_units (void *cls, void *cb_cls) { struct PostgresClosure *pg = cls; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_end + }; struct IterateDonationUnitsContext ctx = { .cb = cb, .cb_cls = cb_cls, - .status = GNUNET_OK - }; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_end + .pg = pg }; enum GNUNET_DB_QueryStatus qs; @@ -130,7 +138,7 @@ DH_PG_iterate_donation_units (void *cls, params, &iterate_donation_units_cb, &ctx); - if (GNUNET_OK != ctx.status) - return GNUNET_DB_STATUS_HARD_ERROR; - return qs; + if (qs <= 0) + return qs; + return ctx.qs; } diff --git a/src/include/donaudb_plugin.h b/src/include/donaudb_plugin.h @@ -110,9 +110,15 @@ struct DONAUDB_IssuedReceiptsMetaData size_t num_sig; /** +<<<<<<< HEAD * Array of blinded signatures */ struct DONAU_BlindedDonationUnitSignature *blinded_sig; + ====== = + *Charity signature + * + / struct DONAU_BlindedDonationUnitSignature **blinded_sig; + >> >> >> > refs / remotes / origin / master }; @@ -155,7 +161,7 @@ typedef void * * @param cls closure */ -typedef void +typedef enum GNUNET_GenericReturnValue (*DONAUDB_IterateDonationUnitsCallback)( void *cls, const struct DONAU_DonationUnitHashP *h_donation_unit_pub, @@ -168,7 +174,7 @@ typedef void * * @param cls closure */ -typedef void +typedef enum GNUNET_GenericReturnValue (*DONAUDB_GetCharitiesCallback)( void *cls, const struct DONAU_CharityPublicKeyP charity_pub, @@ -183,7 +189,7 @@ typedef void * * @param cls closure */ -typedef void +typedef enum GNUNET_GenericReturnValue (*DONAUDB_GetHistoryCallback)( void *cls, unsigned long long charity_id, @@ -541,7 +547,7 @@ struct DONAUDB_Plugin * Lookup issued receipts from the charity. * * @param cls closure - * @param budis_hash the hash over the budi-key-pairs + * @param h_receipts the hash over the blinded unique identifiers * @param meta meta data about an issued request * @return transaction status code */