WIP: Added policy extension handling during deposit

This commit is contained in:
Özgür Kesim 2022-10-07 09:59:39 +02:00
parent 52106eea42
commit d3c509fcd9
Signed by: oec
GPG Key ID: 3D76A56D79EDD9D7
7 changed files with 59 additions and 55 deletions

View File

@ -262,7 +262,6 @@ batch_deposit_transaction (void *cls,
deposit,
known_coin_id,
&dc->h_payto,
false, /* FIXME-OEC: #7270 extension blocked */
&dc->exchange_timestamp,
&balance_ok,
&in_conflict);

View File

@ -114,11 +114,6 @@ struct DepositContext
*/
const struct TALER_EXCHANGEDB_Deposit *deposit;
/**
* Extension handler for policy, maybe NULL.
*/
const struct TALER_Extension *policy_extension;
/**
* Our timestamp (when we received the request).
* Possibly updated by the transaction if the
@ -161,7 +156,6 @@ deposit_transaction (void *cls,
enum GNUNET_DB_QueryStatus qs;
bool balance_ok;
bool in_conflict;
bool blocked_by_policy = false;
qs = TEH_make_coin_known (&dc->deposit->coin,
connection,
@ -175,7 +169,6 @@ deposit_transaction (void *cls,
dc->deposit,
dc->known_coin_id,
&dc->h_payto,
blocked_by_policy,
&dc->exchange_timestamp,
&balance_ok,
&in_conflict);
@ -334,38 +327,37 @@ TEH_handler_deposit (struct MHD_Connection *connection,
&h_wire);
dc.deposit = &deposit;
/* TODO: extract policy information */
#if 0
/* Check policy */
if (! deposit.no_policy_details)
{
const struct TALER_Extension *ext;
struct TALER_ExtensionsPolicySerialID serialID;
struct GNUNET_TIME_Timestamp deadline;
enum GNUNET_GenericReturnValue ret;
const struct TALER_Extension *ext;
const char *error_hint = NULL;
GNUNET_assert (ext->parse_policy_details);
do {
ret = TALER_extensions_from_policy_details (deposit.policy_details,
&ext,
&error_hint);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"DEBUG calling parse_policy_details on extension '%s' with details '%s'\n",
ext->name,
json_dumps (dc->deposit->policy_details, JSON_INDENT (2)));
if (GNUNET_OK != ret)
break;
ret = ext->parse_policy_details (dc->deposit->policy_details,
&serialID,
&deadline);
deposit.policy_deadline = GNUNET_TIME_UNIT_FOREVER_TS;
ret = ext->parse_policy_details (deposit.policy_details,
&deposit.policy_serial_id,
&deposit.policy_deadline,
&error_hint);
} while(0);
if (GNUNET_OK != ret)
{
TALER_LOG_WARNING ("Failed to parse policy details\n");
*mhd_ret = TALER_MHD_reply_with_error (connection,
MHD_HTTP_INTERNAL_SERVER_ERROR,
TALER_EC_GENERIC_DB_STORE_FAILED,
"deposit");
return GNUNET_DB_STATUS_HARD_ERROR;
}
blocked_by_policy = true;
return TALER_MHD_reply_with_error (connection,
MHD_HTTP_BAD_REQUEST,
TALER_EC_EXCHANGE_DEPOSITS_POLICY_NOT_ACCEPTED,
error_hint);
}
#endif
/* new deposit */
dc.exchange_timestamp = GNUNET_TIME_timestamp_get ();

View File

@ -822,8 +822,8 @@ prepare_statements (struct PostgresClosure *pg)
",out_balance_ok AS balance_ok"
",out_conflict AS conflicted"
" FROM exchange_do_deposit"
" ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17);",
17),
" ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19);",
19),
/* used in postgres_do_purse_deposit() */
GNUNET_PQ_make_prepare (
"call_purse_deposit",
@ -6252,7 +6252,6 @@ postgres_do_deposit (
const struct TALER_EXCHANGEDB_Deposit *deposit,
uint64_t known_coin_id,
const struct TALER_PaytoHashP *h_payto,
bool policy_blocked,
struct GNUNET_TIME_Timestamp *exchange_timestamp,
bool *balance_ok,
bool *in_conflict)
@ -6274,10 +6273,16 @@ postgres_do_deposit (
GNUNET_PQ_query_param_auto_from_type (&deposit->coin.coin_pub),
GNUNET_PQ_query_param_auto_from_type (&deposit->csig),
GNUNET_PQ_query_param_uint64 (&deposit_shard),
GNUNET_PQ_query_param_bool (policy_blocked),
(NULL == deposit->policy_details)
GNUNET_PQ_query_param_bool (! deposit->no_policy_details),
(deposit->no_policy_details)
? GNUNET_PQ_query_param_null ()
: TALER_PQ_query_param_json (deposit->policy_details),
(deposit->no_policy_details)
? GNUNET_PQ_query_param_null ()
: GNUNET_PQ_query_param_auto_from_type (&deposit->policy_serial_id),
(deposit->no_policy_details)
? GNUNET_PQ_query_param_null ()
: GNUNET_PQ_query_param_timestamp (&deposit->policy_deadline),
GNUNET_PQ_query_param_end
};
struct GNUNET_PQ_ResultSpec rs[] = {

View File

@ -357,7 +357,7 @@ enum GNUNET_GenericReturnValue
TALER_extensions_from_policy_details (
const json_t *policy_details,
const struct TALER_Extension **extension,
char **error_hint)
const char **error_hint)
{
const json_t *jtype;
const char *type;

View File

@ -594,14 +594,16 @@ auction_http_post_handler (
* @param[in] input The policy_details for this handler during deposit
* @param[out] serial On success will contain the serial-ID under which the
* @param[out] deadline On success will contain a deadline, might be "forever"
* @param[out] error_hint On error, will contain a hint
* exchange should store the policy_details in the policy_details table.
* @return GNUNET_OK if the request was OK
*/
enum GNUNET_GenericReturnValue
auction_parse_policy_details (
const json_t *input,
struct TALER_ExtensionsPolicySerialID *serial,
struct GNUNET_TIME_Timestamp *deadline)
struct GNUNET_HashCode *serial,
struct GNUNET_TIME_Timestamp *deadline,
const char **error_hint)
{
enum GNUNET_GenericReturnValue ret = GNUNET_NO;
struct GNUNET_CRYPTO_EddsaPublicKey pub;
@ -618,10 +620,12 @@ auction_parse_policy_details (
GNUNET_assert (serial);
GNUNET_assert (deadline);
error_hint = NULL;
do {
ret = GNUNET_JSON_parse (input,
spec,
NULL,
error_hint,
NULL);
if (GNUNET_OK != ret)
@ -642,7 +646,7 @@ auction_parse_policy_details (
&hc,
sizeof(hc));
GNUNET_CRYPTO_hash_context_finish (hc,
&serial->hash);
serial);
}
ret = GNUNET_OK;

View File

@ -1444,6 +1444,19 @@ struct TALER_EXCHANGEDB_Deposit
json_t *policy_details;
bool no_policy_details;
/**
* If policy_details are present, the corresponding policy extension calculates
* a serial id under which the policy_details shall be stored in the policy_details table.
*/
struct GNUNET_HashCode policy_serial_id;
/**
* If policy_details are present, the corresponding policy extension can
* set a deadline for this policy. Can be "forever".
*/
struct GNUNET_TIME_Timestamp policy_deadline;
/**
* Hash over the @e policy_details. Only filled if no_policy_details is false.
*/
@ -3323,7 +3336,6 @@ struct TALER_EXCHANGEDB_Plugin
* @param deposit deposit operation details
* @param known_coin_id row of the coin in the known_coins table
* @param h_payto hash of the merchant's payto URI
* @param policy_blocked true if an policy extension is blocking the wire transfer
* @param[in,out] exchange_timestamp time to use for the deposit (possibly updated)
* @param[out] balance_ok set to true if the balance was sufficient
* @param[out] in_conflict set to true if the deposit conflicted
@ -3335,7 +3347,6 @@ struct TALER_EXCHANGEDB_Plugin
const struct TALER_EXCHANGEDB_Deposit *deposit,
uint64_t known_coin_id,
const struct TALER_PaytoHashP *h_payto,
bool policy_blocked,
struct GNUNET_TIME_Timestamp *exchange_timestamp,
bool *balance_ok,
bool *in_conflict);

View File

@ -53,15 +53,6 @@ struct TALER_Extensions
const struct TALER_Extension *extension;
};
/*
* @brief Serial ID under which the policy details to an deposit are stored in
* the policy_details table.
*/
struct TALER_ExtensionsPolicySerialID
{
struct GNUNET_HashCode hash;
};
/*
* @brief Represents the implementation of an extension.
*
@ -179,15 +170,17 @@ struct TALER_Extension
* during a deposit request.
* @param[out] serial On success, will contain the serial-ID under which the
* exchange should save the policy_details in the deposit table.
* @param[out] deadline On sucess, set to the deadline until the policy must
* @param[out] deadline On success, set to the deadline until the policy must
* be fulfilled. Might be "forever". This value is used by an external
* @param[out] error_hint On error, will contain a hint
* mechanism to detect timeouts.
* @return GNUNET_OK if the data was accepted by the extension.
*/
enum GNUNET_GenericReturnValue (*parse_policy_details)(
const json_t *policy_details,
struct TALER_ExtensionsPolicySerialID *serial,
struct GNUNET_TIME_Timestamp *deadline);
struct GNUNET_HashCode *serial,
struct GNUNET_TIME_Timestamp *deadline,
const char **error_hint);
/**
* @brief Handler for POST-requests to the /policy/$name endpoint. Can be NULL.
@ -407,7 +400,7 @@ enum GNUNET_GenericReturnValue
TALER_extensions_from_policy_details (
const json_t *policy_details,
const struct TALER_Extension **extension,
char **error_hint);
const char **error_hint);
/*
* ================================