event handler implemented and refactoring

- extension_update_event handler implemented
- TALER_AgeMask moved to taler_extensions.h
This commit is contained in:
Özgür Kesim 2021-12-28 18:55:00 +01:00
parent d0d7d78336
commit 128d136885
Signed by: oec
GPG Key ID: 3D76A56D79EDD9D7
6 changed files with 124 additions and 93 deletions

View File

@ -33,7 +33,6 @@
*/ */
static struct GNUNET_DB_EventHandler *extensions_eh; static struct GNUNET_DB_EventHandler *extensions_eh;
/** /**
* Function called whenever another exchange process has updated * Function called whenever another exchange process has updated
* the extensions data in the database. * the extensions data in the database.
@ -48,24 +47,65 @@ extension_update_event_cb (void *cls,
size_t extra_size) size_t extra_size)
{ {
(void) cls; (void) cls;
(void) extra; enum TALER_Extension_Type type;
(void) extra_size;
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Received /management/extensions update event\n"); "Received extensions update event\n");
if (sizeof(enum TALER_Extension_Type) != extra_size)
{
GNUNET_break (0);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Oops, incorrect size of extra for TALER_Extension_type\n");
return;
}
type = *(enum TALER_Extension_Type *) extra;
if (type <0 || type >= TALER_Extension_Max)
{
GNUNET_break (0);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Oops, incorrect type for TALER_Extension_type\n");
return;
}
{
char *config;
enum GNUNET_DB_QueryStatus qs;
qs = TEH_plugin->get_extension_config (TEH_plugin->cls,
TEH_extensions[type].name,
&config);
if (qs < 0)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Couldn't get extension config\n");
return;
}
/*
* TODO:
* - parse string as json
* - update global config
*/
}
} }
enum GNUNET_GenericReturnValue enum GNUNET_GenericReturnValue
TEH_extensions_init () TEH_extensions_init ()
{ {
struct GNUNET_DB_EventHeaderP es = { struct GNUNET_DB_EventHeaderP ev = {
.size = htons (sizeof (es)), .size = htons (sizeof (ev)),
.type = htons (TALER_DBEVENT_EXCHANGE_EXTENSIONS_UPDATED), .type = htons (TALER_DBEVENT_EXCHANGE_EXTENSIONS_UPDATED),
}; };
extensions_eh = TEH_plugin->event_listen (TEH_plugin->cls, extensions_eh = TEH_plugin->event_listen (TEH_plugin->cls,
GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_TIME_UNIT_FOREVER_REL,
&es, &ev,
&extension_update_event_cb, &extension_update_event_cb,
NULL); NULL);
if (NULL == extensions_eh) if (NULL == extensions_eh)
@ -89,22 +129,4 @@ TEH_extensions_done ()
} }
void
TEH_extensions_update_state (void)
{
/* TODO */
#if 0
struct GNUNET_DB_EventHeaderP es = {
.size = htons (sizeof (es)),
.type = htons (TALER_DBEVENT_EXCHANGE_WIRE_UPDATED),
};
TEH_plugin->event_notify (TEH_plugin->cls,
&es,
NULL,
0);
#endif
}
/* end of taler-exchange-httpd_extensions.c */ /* end of taler-exchange-httpd_extensions.c */

View File

@ -40,12 +40,4 @@ TEH_extensions_init (void);
void void
TEH_extensions_done (void); TEH_extensions_done (void);
/**
* Something changed in the database. Rebuild the extension state metadata.
* This function should be called if the exchange learns about a new signature
* from our master key.
*/
void
TEH_extensions_update_state (void);
#endif #endif

View File

@ -29,6 +29,7 @@
#include "taler-exchange-httpd_management.h" #include "taler-exchange-httpd_management.h"
#include "taler-exchange-httpd_responses.h" #include "taler-exchange-httpd_responses.h"
#include "taler_extensions.h" #include "taler_extensions.h"
#include "taler_dbevents.h"
struct Extension struct Extension
@ -95,7 +96,7 @@ set_extensions (void *cls,
MHD_HTTP_INTERNAL_SERVER_ERROR, MHD_HTTP_INTERNAL_SERVER_ERROR,
TALER_EC_GENERIC_JSON_INVALID, TALER_EC_GENERIC_JSON_INVALID,
"convert configuration to string"); "convert configuration to string");
return GNUNET_DB_STATUS_SOFT_ERROR; /* FIXME: right error? */ return GNUNET_DB_STATUS_HARD_ERROR;
} }
qs = TEH_plugin->set_extension_config ( qs = TEH_plugin->set_extension_config (
@ -115,6 +116,19 @@ set_extensions (void *cls,
"save extension configuration"); "save extension configuration");
} }
/* success, trigger event */
{
enum TALER_Extension_Type *type = &sec->extensions[i].type;
struct GNUNET_DB_EventHeaderP ev = {
.size = htons (sizeof (ev)),
.type = htons (TALER_DBEVENT_EXCHANGE_EXTENSIONS_UPDATED)
};
TEH_plugin->event_notify (TEH_plugin->cls,
&ev,
type,
sizeof(*type));
}
} }
return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; /* only 'success', so >=0, matters here */ return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; /* only 'success', so >=0, matters here */

View File

@ -12,7 +12,7 @@
You should have received a copy of the GNU General Public License along with You should have received a copy of the GNU General Public License along with
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/ */
/** /**
* @file plugin_exchangedb_postgres.c * @file plugin_exchangedb_postgres.c
@ -3413,11 +3413,11 @@ dominations_cb_helper (void *cls,
/** /**
* Function called to invoke @a cb on every known denomination key (revoked * Function called to invoke @a cb on every known denomination key (revoked
* and non-revoked) that has been signed by the master key. Runs in its own * and non-revoked) that has been signed by the master key. Runs in its own
* read-only transaction. * read-only transaction.
* *
* *
* @param cls the @e cls of this struct with the plugin-specific state * @param cls the @e cls of this struct with the plugin-specific state
* @param cb function to call on each denomination key * @param cb function to call on each denomination key
* @param cb_cls closure for @a cb * @param cb_cls closure for @a cb
@ -11415,7 +11415,8 @@ postgres_delete_shard_locks (void *cls)
/** /**
* Function called to save the configuration of an extension * Function called to save the configuration of an extension
* (age-restriction, peer2peer, ...) * (age-restriction, peer2peer, ...). After succesfull storage of the
* configuration it triggers the corresponding event.
* *
* @param cls the @e cls of this struct with the plugin-specific state * @param cls the @e cls of this struct with the plugin-specific state
* @param extension_name the name of the extension * @param extension_name the name of the extension

View File

@ -23,6 +23,7 @@
#define TALER_CRYPTO_LIB_H #define TALER_CRYPTO_LIB_H
#include <gnunet/gnunet_util_lib.h> #include <gnunet/gnunet_util_lib.h>
#include "taler_extensions.h"
#include "taler_error_codes.h" #include "taler_error_codes.h"
#include <gcrypt.h> #include <gcrypt.h>
@ -280,26 +281,6 @@ struct TALER_MasterSignatureP
struct GNUNET_CRYPTO_EddsaSignature eddsa_signature; struct GNUNET_CRYPTO_EddsaSignature eddsa_signature;
}; };
/*
* @brief Type of a list of age groups, represented as bit mask.
*
* The bits set in the mask mark the edges at the beginning of a next age
* group. F.e. for the age groups
* 0-7, 8-9, 10-11, 12-14, 14-15, 16-17, 18-21, 21-*
* the following bits are set:
*
* 31 24 16 8 0
* | | | | |
* oooooooo oo1oo1o1 o1o1o1o1 ooooooo1
*
* A value of 0 means that the exchange does not support the extension for
* age-restriction.
*/
struct TALER_AgeMask
{
uint32_t mask;
};
/** /**
* @brief Age restriction commitment of a coin. * @brief Age restriction commitment of a coin.
*/ */

View File

@ -50,16 +50,30 @@ struct TALER_Extension
void *config; void *config;
}; };
/*
* TALER Peer2Peer Extension
* FIXME oec
*/
/* /*
* TALER Age Restriction Extension * TALER Age Restriction Extension
*/ */
/*
* @brief Type of a list of age groups, represented as bit mask.
*
* The bits set in the mask mark the edges at the beginning of a next age
* group. F.e. for the age groups
* 0-7, 8-9, 10-11, 12-14, 14-15, 16-17, 18-21, 21-*
* the following bits are set:
*
* 31 24 16 8 0
* | | | | |
* oooooooo oo1oo1o1 o1o1o1o1 ooooooo1
*
* A value of 0 means that the exchange does not support the extension for
* age-restriction.
*/
struct TALER_AgeMask
{
uint32_t mask;
};
#define TALER_EXTENSION_SECTION_AGE_RESTRICTION (TALER_EXTENSION_SECTION_PREFIX \ #define TALER_EXTENSION_SECTION_AGE_RESTRICTION (TALER_EXTENSION_SECTION_PREFIX \
"age_restriction") "age_restriction")
@ -90,4 +104,11 @@ TALER_parse_age_group_string (char *groups,
enum TALER_Extension_ReturnValue enum TALER_Extension_ReturnValue
TALER_get_age_mask (const struct GNUNET_CONFIGURATION_Handle *cfg, TALER_get_age_mask (const struct GNUNET_CONFIGURATION_Handle *cfg,
struct TALER_AgeMask *mask); struct TALER_AgeMask *mask);
/*
* TALER Peer2Peer Extension
* TODO oec
*/
#endif #endif