cleaning up
This commit is contained in:
parent
5fcca8707f
commit
fd1bcfecfa
@ -36,6 +36,7 @@
|
|||||||
#include "taler-mint-httpd_deposit.h"
|
#include "taler-mint-httpd_deposit.h"
|
||||||
#include "taler-mint-httpd_withdraw.h"
|
#include "taler-mint-httpd_withdraw.h"
|
||||||
#include "taler-mint-httpd_refresh.h"
|
#include "taler-mint-httpd_refresh.h"
|
||||||
|
#include "taler-mint-httpd_keystate.h"
|
||||||
#include "mint_db.h"
|
#include "mint_db.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
#include "mint_db.h"
|
#include "mint_db.h"
|
||||||
#include "mint.h"
|
#include "mint.h"
|
||||||
#include "taler_util.h"
|
#include "taler_util.h"
|
||||||
|
#include "taler-mint-httpd_keystate.h"
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -41,6 +41,7 @@
|
|||||||
#include "taler-mint-httpd_db.h"
|
#include "taler-mint-httpd_db.h"
|
||||||
#include "taler-mint-httpd_deposit.h"
|
#include "taler-mint-httpd_deposit.h"
|
||||||
#include "taler-mint-httpd_responses.h"
|
#include "taler-mint-httpd_responses.h"
|
||||||
|
#include "taler-mint-httpd_keystate.h"
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -27,9 +27,6 @@
|
|||||||
#include <microhttpd.h>
|
#include <microhttpd.h>
|
||||||
#include <jansson.h>
|
#include <jansson.h>
|
||||||
#include "taler-mint-httpd.h"
|
#include "taler-mint-httpd.h"
|
||||||
#include "mint.h"
|
|
||||||
#include "key_io.h"
|
|
||||||
#include "taler-mint-httpd_keystate.h"
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -48,8 +48,8 @@ static int reload_pipe[2];
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert the public part of a denomination key
|
* Convert the public part of a denomination key issue to a JSON
|
||||||
* issue to a JSON object.
|
* object.
|
||||||
*
|
*
|
||||||
* @param dki the denomination key issue
|
* @param dki the denomination key issue
|
||||||
* @return a JSON object describing the denomination key isue (public part)
|
* @return a JSON object describing the denomination key isue (public part)
|
||||||
@ -61,37 +61,45 @@ denom_key_issue_to_json (const struct TALER_MINT_DenomKeyIssue *dki)
|
|||||||
size_t buf_len;
|
size_t buf_len;
|
||||||
json_t *dk_json = json_object ();
|
json_t *dk_json = json_object ();
|
||||||
|
|
||||||
json_object_set_new (dk_json, "master_sig",
|
json_object_set_new (dk_json,
|
||||||
TALER_JSON_from_data (&dki->signature, sizeof (struct GNUNET_CRYPTO_EddsaSignature)));
|
"master_sig",
|
||||||
json_object_set_new (dk_json, "stamp_start", TALER_JSON_from_abs (GNUNET_TIME_absolute_ntoh (dki->start)));
|
TALER_JSON_from_data (&dki->signature,
|
||||||
json_object_set_new (dk_json, "stamp_expire_withdraw", TALER_JSON_from_abs (GNUNET_TIME_absolute_ntoh (dki->expire_withdraw)));
|
sizeof (struct GNUNET_CRYPTO_EddsaSignature)));
|
||||||
json_object_set_new (dk_json, "stamp_expire_deposit", TALER_JSON_from_abs (GNUNET_TIME_absolute_ntoh (dki->expire_spend)));
|
json_object_set_new (dk_json,
|
||||||
|
"stamp_start",
|
||||||
|
TALER_JSON_from_abs (GNUNET_TIME_absolute_ntoh (dki->start)));
|
||||||
|
json_object_set_new (dk_json,
|
||||||
|
"stamp_expire_withdraw",
|
||||||
|
TALER_JSON_from_abs (GNUNET_TIME_absolute_ntoh (dki->expire_withdraw)));
|
||||||
|
json_object_set_new (dk_json,
|
||||||
|
"stamp_expire_deposit",
|
||||||
|
TALER_JSON_from_abs (GNUNET_TIME_absolute_ntoh (dki->expire_spend)));
|
||||||
|
|
||||||
buf_len = GNUNET_CRYPTO_rsa_public_key_encode (dki->denom_pub,
|
buf_len = GNUNET_CRYPTO_rsa_public_key_encode (dki->denom_pub,
|
||||||
&buf);
|
&buf);
|
||||||
json_object_set_new (dk_json, "denom_pub",
|
json_object_set_new (dk_json,
|
||||||
|
"denom_pub",
|
||||||
TALER_JSON_from_data (buf,
|
TALER_JSON_from_data (buf,
|
||||||
buf_len));
|
buf_len));
|
||||||
GNUNET_free (buf);
|
GNUNET_free (buf);
|
||||||
json_object_set_new (dk_json, "value",
|
json_object_set_new (dk_json,
|
||||||
|
"value",
|
||||||
TALER_JSON_from_amount (TALER_amount_ntoh (dki->value)));
|
TALER_JSON_from_amount (TALER_amount_ntoh (dki->value)));
|
||||||
json_object_set_new (dk_json,
|
json_object_set_new (dk_json,
|
||||||
"fee_withdraw",
|
"fee_withdraw",
|
||||||
TALER_JSON_from_amount(TALER_amount_ntoh (dki->fee_withdraw)));
|
TALER_JSON_from_amount (TALER_amount_ntoh (dki->fee_withdraw)));
|
||||||
json_object_set_new (dk_json,
|
json_object_set_new (dk_json,
|
||||||
"fee_deposit",
|
"fee_deposit",
|
||||||
TALER_JSON_from_amount(TALER_amount_ntoh (dki->fee_deposit)));
|
TALER_JSON_from_amount (TALER_amount_ntoh (dki->fee_deposit)));
|
||||||
json_object_set_new (dk_json,
|
json_object_set_new (dk_json,
|
||||||
"fee_refresh",
|
"fee_refresh",
|
||||||
TALER_JSON_from_amount(TALER_amount_ntoh (dki->fee_refresh)));
|
TALER_JSON_from_amount (TALER_amount_ntoh (dki->fee_refresh)));
|
||||||
return dk_json;
|
return dk_json;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert the public part of a sign key
|
* Convert the public part of a sign key issue to a JSON object.
|
||||||
* issue to a JSON object.
|
|
||||||
*
|
*
|
||||||
* @param ski the sign key issue
|
* @param ski the sign key issue
|
||||||
* @return a JSON object describing the sign key isue (public part)
|
* @return a JSON object describing the sign key isue (public part)
|
||||||
@ -111,7 +119,8 @@ sign_key_issue_to_json (const struct TALER_MINT_SignKeyIssue *ski)
|
|||||||
"master_sig",
|
"master_sig",
|
||||||
TALER_JSON_from_data (&ski->signature,
|
TALER_JSON_from_data (&ski->signature,
|
||||||
sizeof (struct GNUNET_CRYPTO_EddsaSignature)));
|
sizeof (struct GNUNET_CRYPTO_EddsaSignature)));
|
||||||
json_object_set_new (sk_json, "key",
|
json_object_set_new (sk_json,
|
||||||
|
"key",
|
||||||
TALER_JSON_from_data (&ski->signkey_pub,
|
TALER_JSON_from_data (&ski->signkey_pub,
|
||||||
sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)));
|
sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)));
|
||||||
return sk_json;
|
return sk_json;
|
||||||
@ -266,7 +275,8 @@ reload_keys ()
|
|||||||
key_state->sign_keys_array = json_array ();
|
key_state->sign_keys_array = json_array ();
|
||||||
GNUNET_assert (NULL != key_state->sign_keys_array);
|
GNUNET_assert (NULL != key_state->sign_keys_array);
|
||||||
|
|
||||||
key_state->denomkey_map = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO);
|
key_state->denomkey_map = GNUNET_CONTAINER_multihashmap_create (32,
|
||||||
|
GNUNET_NO);
|
||||||
GNUNET_assert (NULL != key_state->denomkey_map);
|
GNUNET_assert (NULL != key_state->denomkey_map);
|
||||||
|
|
||||||
key_state->reload_time = GNUNET_TIME_absolute_get ();
|
key_state->reload_time = GNUNET_TIME_absolute_get ();
|
||||||
@ -275,7 +285,8 @@ reload_keys ()
|
|||||||
TALER_MINT_signkeys_iterate (mintdir, &reload_keys_sign_iter, key_state);
|
TALER_MINT_signkeys_iterate (mintdir, &reload_keys_sign_iter, key_state);
|
||||||
|
|
||||||
keys = json_pack ("{s:o, s:o, s:o, s:o}",
|
keys = json_pack ("{s:o, s:o, s:o, s:o}",
|
||||||
"master_pub", TALER_JSON_from_data (&master_pub, sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)),
|
"master_pub", TALER_JSON_from_data (&master_pub,
|
||||||
|
sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)),
|
||||||
"signkeys", key_state->sign_keys_array,
|
"signkeys", key_state->sign_keys_array,
|
||||||
"denoms", key_state->denom_keys_array,
|
"denoms", key_state->denom_keys_array,
|
||||||
"list_issue_date", TALER_JSON_from_abs (key_state->reload_time));
|
"list_issue_date", TALER_JSON_from_abs (key_state->reload_time));
|
||||||
@ -295,9 +306,10 @@ void
|
|||||||
TALER_MINT_key_state_release (struct MintKeyState *key_state)
|
TALER_MINT_key_state_release (struct MintKeyState *key_state)
|
||||||
{
|
{
|
||||||
GNUNET_assert (0 == pthread_mutex_lock (&internal_key_state_mutex));
|
GNUNET_assert (0 == pthread_mutex_lock (&internal_key_state_mutex));
|
||||||
GNUNET_assert (0 != key_state->refcnt);
|
GNUNET_assert (0 < key_state->refcnt);
|
||||||
key_state->refcnt += 1;
|
key_state->refcnt--;
|
||||||
if (key_state->refcnt == 0) {
|
if (0 == key_state->refcnt)
|
||||||
|
{
|
||||||
GNUNET_free (key_state);
|
GNUNET_free (key_state);
|
||||||
}
|
}
|
||||||
GNUNET_assert (0 == pthread_mutex_unlock (&internal_key_state_mutex));
|
GNUNET_assert (0 == pthread_mutex_unlock (&internal_key_state_mutex));
|
||||||
@ -317,9 +329,6 @@ TALER_MINT_key_state_acquire (void)
|
|||||||
struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
|
struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
|
||||||
struct MintKeyState *key_state;
|
struct MintKeyState *key_state;
|
||||||
|
|
||||||
// FIXME: the locking we have is very coarse-grained,
|
|
||||||
// using multiple locks might be nicer ...
|
|
||||||
|
|
||||||
GNUNET_assert (0 == pthread_mutex_lock (&internal_key_state_mutex));
|
GNUNET_assert (0 == pthread_mutex_lock (&internal_key_state_mutex));
|
||||||
if (NULL == internal_key_state)
|
if (NULL == internal_key_state)
|
||||||
{
|
{
|
||||||
@ -327,14 +336,14 @@ TALER_MINT_key_state_acquire (void)
|
|||||||
}
|
}
|
||||||
else if (internal_key_state->next_reload.abs_value_us <= now.abs_value_us)
|
else if (internal_key_state->next_reload.abs_value_us <= now.abs_value_us)
|
||||||
{
|
{
|
||||||
GNUNET_assert (0 != internal_key_state->refcnt);
|
GNUNET_assert (0 < internal_key_state->refcnt);
|
||||||
internal_key_state->refcnt--;
|
internal_key_state->refcnt--;
|
||||||
if (0 == internal_key_state->refcnt)
|
if (0 == internal_key_state->refcnt)
|
||||||
GNUNET_free (internal_key_state);
|
GNUNET_free (internal_key_state);
|
||||||
internal_key_state = reload_keys ();
|
internal_key_state = reload_keys ();
|
||||||
}
|
}
|
||||||
key_state = internal_key_state;
|
key_state = internal_key_state;
|
||||||
key_state->refcnt += 1;
|
key_state->refcnt++;
|
||||||
GNUNET_assert (0 == pthread_mutex_unlock (&internal_key_state_mutex));
|
GNUNET_assert (0 == pthread_mutex_unlock (&internal_key_state_mutex));
|
||||||
|
|
||||||
return key_state;
|
return key_state;
|
||||||
@ -353,7 +362,6 @@ struct TALER_MINT_DenomKeyIssuePriv *
|
|||||||
TALER_MINT_get_denom_key (const struct MintKeyState *key_state,
|
TALER_MINT_get_denom_key (const struct MintKeyState *key_state,
|
||||||
const struct GNUNET_CRYPTO_rsa_PublicKey *denom_pub)
|
const struct GNUNET_CRYPTO_rsa_PublicKey *denom_pub)
|
||||||
{
|
{
|
||||||
struct TALER_MINT_DenomKeyIssuePriv *issue;
|
|
||||||
struct GNUNET_HashCode hash;
|
struct GNUNET_HashCode hash;
|
||||||
char *buf;
|
char *buf;
|
||||||
size_t buf_len;
|
size_t buf_len;
|
||||||
@ -364,8 +372,8 @@ TALER_MINT_get_denom_key (const struct MintKeyState *key_state,
|
|||||||
buf_len,
|
buf_len,
|
||||||
&hash);
|
&hash);
|
||||||
GNUNET_free (buf);
|
GNUNET_free (buf);
|
||||||
issue = GNUNET_CONTAINER_multihashmap_get (key_state->denomkey_map, &hash);
|
return GNUNET_CONTAINER_multihashmap_get (key_state->denomkey_map,
|
||||||
return issue;
|
&hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -479,6 +487,4 @@ TALER_MINT_keys_sign (const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* end of taler-mint-httpd_keystate.c */
|
/* end of taler-mint-httpd_keystate.c */
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
#include "taler-mint-httpd_mhd.h"
|
#include "taler-mint-httpd_mhd.h"
|
||||||
#include "taler-mint-httpd_refresh.h"
|
#include "taler-mint-httpd_refresh.h"
|
||||||
#include "taler-mint-httpd_responses.h"
|
#include "taler-mint-httpd_responses.h"
|
||||||
|
#include "taler-mint-httpd_keystate.h"
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
#include "taler-mint-httpd_responses.h"
|
#include "taler-mint-httpd_responses.h"
|
||||||
#include "taler_util.h"
|
#include "taler_util.h"
|
||||||
#include <gnunet/gnunet_util_lib.h>
|
#include <gnunet/gnunet_util_lib.h>
|
||||||
|
#include "taler-mint-httpd_keystate.h"
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#include "taler-mint-httpd_withdraw.h"
|
#include "taler-mint-httpd_withdraw.h"
|
||||||
#include "taler-mint-httpd_parsing.h"
|
#include "taler-mint-httpd_parsing.h"
|
||||||
#include "taler-mint-httpd_responses.h"
|
#include "taler-mint-httpd_responses.h"
|
||||||
|
#include "taler-mint-httpd_keystate.h"
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user