-misc p2p fixes

This commit is contained in:
Christian Grothoff 2022-04-24 15:29:50 +02:00
parent 36c568ab8d
commit aedd2014ec
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
10 changed files with 43 additions and 38 deletions

View File

@ -388,6 +388,9 @@ TEH_handler_purses_merge (
break; break;
} }
/* parse 'payto_uri' into pcc.reserve_pub and provider_url */ /* parse 'payto_uri' into pcc.reserve_pub and provider_url */
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Received payto: `%s'\n",
pcc.payto_uri);
if ( (0 != strncmp (pcc.payto_uri, if ( (0 != strncmp (pcc.payto_uri,
"payto://taler/", "payto://taler/",
strlen ("payto://taler/"))) && strlen ("payto://taler/"))) &&

View File

@ -2647,6 +2647,7 @@ PERFORM
IF NOT FOUND IF NOT FOUND
THEN THEN
out_no_balance=TRUE; out_no_balance=TRUE;
out_conflict=FALSE;
RETURN; RETURN;
END IF; END IF;
out_no_balance=FALSE; out_no_balance=FALSE;

View File

@ -13066,7 +13066,7 @@ postgres_select_contract (void *cls,
purse_pub), purse_pub),
GNUNET_PQ_result_spec_auto_from_type ("contract_sig", GNUNET_PQ_result_spec_auto_from_type ("contract_sig",
econtract_sig), econtract_sig),
GNUNET_PQ_result_spec_variable_size ("econtract", GNUNET_PQ_result_spec_variable_size ("e_contract",
econtract, econtract,
econtract_size), econtract_size),
GNUNET_PQ_result_spec_end GNUNET_PQ_result_spec_end
@ -13111,7 +13111,7 @@ postgres_select_contract_by_purse (void *cls,
pub_ckey), pub_ckey),
GNUNET_PQ_result_spec_auto_from_type ("contract_sig", GNUNET_PQ_result_spec_auto_from_type ("contract_sig",
econtract_sig), econtract_sig),
GNUNET_PQ_result_spec_variable_size ("econtract", GNUNET_PQ_result_spec_variable_size ("e_contract",
econtract, econtract,
econtract_size), econtract_size),
GNUNET_PQ_result_spec_end GNUNET_PQ_result_spec_end
@ -13430,8 +13430,9 @@ postgres_do_purse_deposit (
bool *conflict) bool *conflict)
{ {
struct PostgresClosure *pg = cls; struct PostgresClosure *pg = cls;
uint64_t partner_id = 0;
struct GNUNET_PQ_QueryParam params[] = { struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_uint64 (0), /* FIXME: partner ID */ GNUNET_PQ_query_param_uint64 (&partner_id),
GNUNET_PQ_query_param_auto_from_type (purse_pub), GNUNET_PQ_query_param_auto_from_type (purse_pub),
TALER_PQ_query_param_amount (amount), TALER_PQ_query_param_amount (amount),
GNUNET_PQ_query_param_auto_from_type (coin_pub), GNUNET_PQ_query_param_auto_from_type (coin_pub),
@ -13537,7 +13538,9 @@ postgres_do_purse_merge (
GNUNET_PQ_query_param_auto_from_type (merge_sig), GNUNET_PQ_query_param_auto_from_type (merge_sig),
GNUNET_PQ_query_param_timestamp (&merge_timestamp), GNUNET_PQ_query_param_timestamp (&merge_timestamp),
GNUNET_PQ_query_param_auto_from_type (reserve_sig), GNUNET_PQ_query_param_auto_from_type (reserve_sig),
GNUNET_PQ_query_param_string (partner_url), (NULL == partner_url)
? GNUNET_PQ_query_param_null ()
: GNUNET_PQ_query_param_string (partner_url),
GNUNET_PQ_query_param_auto_from_type (reserve_pub), GNUNET_PQ_query_param_auto_from_type (reserve_pub),
GNUNET_PQ_query_param_end GNUNET_PQ_query_param_end
}; };

View File

@ -4256,7 +4256,6 @@ struct TALER_EXCHANGE_PurseDeposit
* @param merge_priv the merge credential * @param merge_priv the merge credential
* @param contract_priv key needed to obtain and decrypt the contract * @param contract_priv key needed to obtain and decrypt the contract
* @param contract_terms contract the purse is about * @param contract_terms contract the purse is about
* @param purse_expiration when will the unmerged purse expire
* @param num_deposits length of the @a deposits array * @param num_deposits length of the @a deposits array
* @param deposits array of deposits to make into the purse * @param deposits array of deposits to make into the purse
* @param upload_contract true to upload the contract; must * @param upload_contract true to upload the contract; must
@ -4273,7 +4272,6 @@ TALER_EXCHANGE_purse_create_with_deposit (
const struct TALER_PurseMergePrivateKeyP *merge_priv, const struct TALER_PurseMergePrivateKeyP *merge_priv,
const struct TALER_ContractDiffiePrivateP *contract_priv, const struct TALER_ContractDiffiePrivateP *contract_priv,
const json_t *contract_terms, const json_t *contract_terms,
struct GNUNET_TIME_Timestamp purse_expiration,
unsigned int num_deposits, unsigned int num_deposits,
const struct TALER_EXCHANGE_PurseDeposit *deposits, const struct TALER_EXCHANGE_PurseDeposit *deposits,
bool upload_contract, bool upload_contract,

View File

@ -242,7 +242,6 @@ TALER_EXCHANGE_purse_create_with_deposit (
const struct TALER_PurseMergePrivateKeyP *merge_priv, const struct TALER_PurseMergePrivateKeyP *merge_priv,
const struct TALER_ContractDiffiePrivateP *contract_priv, const struct TALER_ContractDiffiePrivateP *contract_priv,
const json_t *contract_terms, const json_t *contract_terms,
struct GNUNET_TIME_Timestamp purse_expiration,
unsigned int num_deposits, unsigned int num_deposits,
const struct TALER_EXCHANGE_PurseDeposit *deposits, const struct TALER_EXCHANGE_PurseDeposit *deposits,
bool upload_contract, bool upload_contract,
@ -265,10 +264,10 @@ TALER_EXCHANGE_purse_create_with_deposit (
pch->exchange = exchange; pch->exchange = exchange;
pch->cb = cb; pch->cb = cb;
pch->cb_cls = cb_cls; pch->cb_cls = cb_cls;
// FIXME: get expiration from pay deadline of contract?
pch->purse_expiration = purse_expiration;
{ {
struct GNUNET_JSON_Specification spec[] = { struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_timestamp ("pay_deadline",
&pch->purse_expiration),
TALER_JSON_spec_amount_any ("amount", TALER_JSON_spec_amount_any ("amount",
&pch->purse_value_after_fees), &pch->purse_value_after_fees),
GNUNET_JSON_spec_mark_optional ( GNUNET_JSON_spec_mark_optional (
@ -390,7 +389,7 @@ TALER_EXCHANGE_purse_create_with_deposit (
jdeposit)); jdeposit));
} }
GNUNET_free (url); GNUNET_free (url);
TALER_wallet_purse_create_sign (purse_expiration, TALER_wallet_purse_create_sign (pch->purse_expiration,
&pch->h_contract_terms, &pch->h_contract_terms,
&pch->merge_pub, &pch->merge_pub,
min_age, min_age,
@ -443,7 +442,7 @@ TALER_EXCHANGE_purse_create_with_deposit (
GNUNET_JSON_pack_data_auto ("h_contract_terms", GNUNET_JSON_pack_data_auto ("h_contract_terms",
&pch->h_contract_terms), &pch->h_contract_terms),
GNUNET_JSON_pack_timestamp ("purse_expiration", GNUNET_JSON_pack_timestamp ("purse_expiration",
purse_expiration), pch->purse_expiration),
GNUNET_JSON_pack_array_steal ("deposits", GNUNET_JSON_pack_array_steal ("deposits",
deposit_arr)); deposit_arr));
GNUNET_free (econtract); GNUNET_free (econtract);

View File

@ -272,6 +272,9 @@ TALER_EXCHANGE_account_merge (
pch->h_contract_terms = *h_contract_terms; pch->h_contract_terms = *h_contract_terms;
pch->purse_expiration = purse_expiration; pch->purse_expiration = purse_expiration;
pch->purse_value_after_fees = *purse_value_after_fees; pch->purse_value_after_fees = *purse_value_after_fees;
if (NULL == reserve_exchange_url)
pch->provider_url = GNUNET_strdup (exchange->url);
else
pch->provider_url = GNUNET_strdup (reserve_exchange_url); pch->provider_url = GNUNET_strdup (reserve_exchange_url);
GNUNET_CRYPTO_eddsa_key_get_public (&reserve_priv->eddsa_priv, GNUNET_CRYPTO_eddsa_key_get_public (&reserve_priv->eddsa_priv,
&pch->reserve_pub.eddsa_pub); &pch->reserve_pub.eddsa_pub);
@ -305,31 +308,33 @@ TALER_EXCHANGE_account_merge (
pub_str, pub_str,
sizeof (pub_str)); sizeof (pub_str));
*end = '\0'; *end = '\0';
if (0 == strncmp (reserve_exchange_url, if (0 == strncmp (pch->provider_url,
"http://", "http://",
strlen ("http://"))) strlen ("http://")))
{ {
is_http = true; is_http = true;
exchange_url = &reserve_exchange_url[strlen ("http://")]; exchange_url = &pch->provider_url[strlen ("http://")];
} }
else if (0 == strncmp (reserve_exchange_url, else if (0 == strncmp (pch->provider_url,
"https://", "https://",
strlen ("https://"))) strlen ("https://")))
{ {
is_http = false; is_http = false;
exchange_url = &reserve_exchange_url[strlen ("https://")]; exchange_url = &pch->provider_url[strlen ("https://")];
} }
else else
{ {
GNUNET_break (0); GNUNET_break (0);
GNUNET_free (pch->provider_url);
GNUNET_free (pch); GNUNET_free (pch);
return NULL; return NULL;
} }
/* exchange_url includes trailing '/' */
GNUNET_asprintf (&reserve_url, GNUNET_asprintf (&reserve_url,
"payto://%s/%s/%s", "payto://%s/%s%s",
is_http ? "taler+http" : "taler", is_http ? "taler+http" : "taler",
pub_str, exchange_url,
exchange_url); pub_str);
} }
pch->url = TEAH_path_to_url (exchange, pch->url = TEAH_path_to_url (exchange,
arg_str); arg_str);

View File

@ -158,7 +158,7 @@ run (void *cls,
true, /* upload contract */ true, /* upload contract */
GNUNET_TIME_UNIT_MINUTES, /* expiration */ GNUNET_TIME_UNIT_MINUTES, /* expiration */
"withdraw-coin-1", "withdraw-coin-1",
"EUR:1", /* FIXME: check amount vs. fees! */ "EUR:1.01", /* FIXME: check amount vs. fees! */
NULL), NULL),
TALER_TESTING_cmd_contract_get ( TALER_TESTING_cmd_contract_get (
"purse-get-contract", "purse-get-contract",

View File

@ -259,17 +259,23 @@ deposit_run (void *cls,
GNUNET_CRYPTO_eddsa_key_create (&ds->purse_priv.eddsa_priv); GNUNET_CRYPTO_eddsa_key_create (&ds->purse_priv.eddsa_priv);
GNUNET_CRYPTO_eddsa_key_create (&ds->merge_priv.eddsa_priv); GNUNET_CRYPTO_eddsa_key_create (&ds->merge_priv.eddsa_priv);
GNUNET_CRYPTO_ecdhe_key_create (&ds->contract_priv.ecdhe_priv); GNUNET_CRYPTO_ecdhe_key_create (&ds->contract_priv.ecdhe_priv);
ds->purse_expiration
= GNUNET_TIME_relative_to_timestamp (ds->rel_expiration);
GNUNET_CRYPTO_eddsa_key_get_public (&ds->purse_priv.eddsa_priv, GNUNET_CRYPTO_eddsa_key_get_public (&ds->purse_priv.eddsa_priv,
&ds->purse_pub.eddsa_pub); &ds->purse_pub.eddsa_pub);
ds->purse_expiration =
GNUNET_TIME_absolute_to_timestamp (
GNUNET_TIME_relative_to_absolute (ds->rel_expiration));
GNUNET_assert (0 ==
json_object_set_new (
ds->contract_terms,
"pay_deadline",
GNUNET_JSON_from_timestamp (ds->purse_expiration)));
ds->dh = TALER_EXCHANGE_purse_create_with_deposit ( ds->dh = TALER_EXCHANGE_purse_create_with_deposit (
is->exchange, is->exchange,
&ds->purse_priv, &ds->purse_priv,
&ds->merge_priv, &ds->merge_priv,
&ds->contract_priv, &ds->contract_priv,
ds->contract_terms, ds->contract_terms,
ds->purse_expiration,
ds->num_coin_references, ds->num_coin_references,
deposits, deposits,
ds->upload_contract, ds->upload_contract,
@ -361,7 +367,6 @@ TALER_TESTING_cmd_purse_create_with_deposit (
...) ...)
{ {
struct PurseCreateDepositState *ds; struct PurseCreateDepositState *ds;
struct GNUNET_TIME_Timestamp pay_deadline;
ds = GNUNET_new (struct PurseCreateDepositState); ds = GNUNET_new (struct PurseCreateDepositState);
ds->rel_expiration = purse_expiration; ds->rel_expiration = purse_expiration;
@ -378,14 +383,6 @@ TALER_TESTING_cmd_purse_create_with_deposit (
label); label);
GNUNET_assert (0); GNUNET_assert (0);
} }
pay_deadline =
GNUNET_TIME_absolute_to_timestamp (
GNUNET_TIME_relative_to_absolute (purse_expiration));
GNUNET_assert (0 ==
json_object_set_new (
ds->contract_terms,
"pay_deadline",
GNUNET_JSON_from_timestamp (pay_deadline)));
{ {
va_list ap; va_list ap;
unsigned int i; unsigned int i;

View File

@ -128,7 +128,7 @@ merge_run (void *cls,
const struct TALER_PurseMergePrivateKeyP *merge_priv; const struct TALER_PurseMergePrivateKeyP *merge_priv;
const json_t *ct; const json_t *ct;
struct TALER_PrivateContractHashP h_contract_terms; struct TALER_PrivateContractHashP h_contract_terms;
uint32_t min_age; uint32_t min_age = 0;
struct TALER_Amount value_after_fees; struct TALER_Amount value_after_fees;
struct GNUNET_TIME_Timestamp purse_expiration; struct GNUNET_TIME_Timestamp purse_expiration;
const struct TALER_TESTING_Command *ref; const struct TALER_TESTING_Command *ref;
@ -172,6 +172,8 @@ merge_run (void *cls,
} }
{ {
struct GNUNET_JSON_Specification spec[] = { struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_timestamp ("pay_deadline",
&purse_expiration),
TALER_JSON_spec_amount_any ("amount", TALER_JSON_spec_amount_any ("amount",
&value_after_fees), &value_after_fees),
GNUNET_JSON_spec_mark_optional ( GNUNET_JSON_spec_mark_optional (
@ -192,9 +194,6 @@ merge_run (void *cls,
} }
} }
// FIXME: how to get purse_expiration nicely!?!?
// See create_with_deposit FIXME: from pay deadline?
if (NULL == ds->reserve_ref) if (NULL == ds->reserve_ref)
{ {
GNUNET_CRYPTO_eddsa_key_create (&ds->reserve_priv.eddsa_priv); GNUNET_CRYPTO_eddsa_key_create (&ds->reserve_priv.eddsa_priv);
@ -204,7 +203,7 @@ merge_run (void *cls,
const struct TALER_ReservePrivateKeyP *rp; const struct TALER_ReservePrivateKeyP *rp;
ref = TALER_TESTING_interpreter_lookup_command (ds->is, ref = TALER_TESTING_interpreter_lookup_command (ds->is,
ds->merge_ref); ds->reserve_ref);
GNUNET_assert (NULL != ref); GNUNET_assert (NULL != ref);
if (GNUNET_OK != if (GNUNET_OK !=
TALER_TESTING_get_trait_reserve_priv (ref, TALER_TESTING_get_trait_reserve_priv (ref,

View File

@ -1033,7 +1033,7 @@ TALER_wallet_purse_merge_verify (
TALER_payto_hash (reserve_url, TALER_payto_hash (reserve_url,
&pm.h_payto); &pm.h_payto);
return GNUNET_CRYPTO_eddsa_verify ( return GNUNET_CRYPTO_eddsa_verify (
TALER_SIGNATURE_WALLET_ACCOUNT_MERGE, TALER_SIGNATURE_WALLET_PURSE_MERGE,
&pm, &pm,
&merge_sig->eddsa_signature, &merge_sig->eddsa_signature,
&merge_pub->eddsa_pub); &merge_pub->eddsa_pub);