functional interpreter
This commit is contained in:
parent
aa33f8cae5
commit
d9dbc44389
@ -33,13 +33,27 @@ main (int argc, char ** argv)
|
|||||||
struct GNUNET_CONFIGURATION_Handle *config;
|
struct GNUNET_CONFIGURATION_Handle *config;
|
||||||
struct PERF_TALER_MINTDB_Cmd test[] =
|
struct PERF_TALER_MINTDB_Cmd test[] =
|
||||||
{
|
{
|
||||||
PERF_TALER_MINTDB_INIT_CMD_LOOP ("loop_db_init_deposit",10),
|
PERF_TALER_MINTDB_INIT_CMD_LOOP ("loop_db_init_deposit",10000),
|
||||||
PERF_TALER_MINTDB_INIT_CMD_START_TRANSACTION ("start_transaction_init"),
|
PERF_TALER_MINTDB_INIT_CMD_START_TRANSACTION ("start_transaction_init"),
|
||||||
PERF_TALER_MINTDB_INIT_CMD_INSERT_DEPOSIT ("init_deposit_insert"),
|
PERF_TALER_MINTDB_INIT_CMD_INSERT_DEPOSIT ("init_deposit_insert"),
|
||||||
PERF_TALER_MINTDB_INIT_CMD_COMMIT_TRANSACTION ("commit_transaction_init"),
|
PERF_TALER_MINTDB_INIT_CMD_COMMIT_TRANSACTION ("commit_transaction_init"),
|
||||||
PERF_TALER_MINTDB_INIT_CMD_SAVE_ARRAY ("array_depo", "loop_db_init_deposit", "init_deposit_insert", 10, PERF_TALER_MINTDB_DEPOSIT),
|
PERF_TALER_MINTDB_INIT_CMD_SAVE_ARRAY ("array_depo",
|
||||||
|
"loop_db_init_deposit",
|
||||||
|
"init_deposit_insert",
|
||||||
|
100,
|
||||||
|
PERF_TALER_MINTDB_DEPOSIT),
|
||||||
PERF_TALER_MINTDB_INIT_CMD_END_LOOP ("endloop_init_deposit",
|
PERF_TALER_MINTDB_INIT_CMD_END_LOOP ("endloop_init_deposit",
|
||||||
"loop_db_init_deposit"),
|
"loop_db_init_deposit"),
|
||||||
|
PERF_TALER_MINTDB_INIT_CMD_DEBUG("Fin loop 1"),
|
||||||
|
PERF_TALER_MINTDB_INIT_CMD_LOOP ("loop_deposit_get",100),
|
||||||
|
PERF_TALER_MINTDB_INIT_CMD_START_TRANSACTION ("start_transaction_get"),
|
||||||
|
PERF_TALER_MINTDB_INIT_CMD_LOAD_ARRAY("load deposit",
|
||||||
|
"loop_deposit_get",
|
||||||
|
"array_depo"),
|
||||||
|
PERF_TALER_MINTDB_INIT_CMD_GET_DEPOSIT("get_deposit",
|
||||||
|
"load_deposit"),
|
||||||
|
PERF_TALER_MINTDB_INIT_CMD_COMMIT_TRANSACTION ("commit_transaction_init"),
|
||||||
|
PERF_TALER_MINTDB_INIT_CMD_END_LOOP("stop2", "loop_deposit_get"),
|
||||||
PERF_TALER_MINTDB_INIT_CMD_END("end")
|
PERF_TALER_MINTDB_INIT_CMD_END("end")
|
||||||
};
|
};
|
||||||
// Plugin init
|
// Plugin init
|
||||||
|
@ -115,6 +115,7 @@ static int
|
|||||||
cmd_init (struct PERF_TALER_MINTDB_Cmd cmd[])
|
cmd_init (struct PERF_TALER_MINTDB_Cmd cmd[])
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
for (i=0; PERF_TALER_MINTDB_CMD_END != cmd[i].command; i++)
|
for (i=0; PERF_TALER_MINTDB_CMD_END != cmd[i].command; i++)
|
||||||
{
|
{
|
||||||
switch (cmd[i].command)
|
switch (cmd[i].command)
|
||||||
@ -128,13 +129,14 @@ cmd_init (struct PERF_TALER_MINTDB_Cmd cmd[])
|
|||||||
|
|
||||||
case PERF_TALER_MINTDB_CMD_LOAD_ARRAY:
|
case PERF_TALER_MINTDB_CMD_LOAD_ARRAY:
|
||||||
// Creating the permutation array to randomize the data order
|
// Creating the permutation array to randomize the data order
|
||||||
cmd[i].details.load_array.permutation =
|
GNUNET_assert (NULL !=
|
||||||
GNUNET_CRYPTO_random_permute (
|
(cmd[i].details.load_array.permutation =
|
||||||
GNUNET_CRYPTO_QUALITY_WEAK,
|
GNUNET_CRYPTO_random_permute (
|
||||||
cmd[cmd_find (cmd,
|
GNUNET_CRYPTO_QUALITY_WEAK,
|
||||||
cmd[i].details
|
cmd[cmd_find (cmd,
|
||||||
.load_array.label_save)]
|
cmd[i].details
|
||||||
.details.save_array.nb_saved);
|
.load_array.label_save)]
|
||||||
|
.details.save_array.nb_saved)));
|
||||||
|
|
||||||
// Initializing the type based on the type of the saved array
|
// Initializing the type based on the type of the saved array
|
||||||
cmd[i].exposed_type = cmd[cmd_find (cmd,
|
cmd[i].exposed_type = cmd[cmd_find (cmd,
|
||||||
@ -157,6 +159,7 @@ static int
|
|||||||
cmd_clean (struct PERF_TALER_MINTDB_Cmd cmd[])
|
cmd_clean (struct PERF_TALER_MINTDB_Cmd cmd[])
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
for (i = 0; PERF_TALER_MINTDB_CMD_END != cmd[i].command; i++)
|
for (i = 0; PERF_TALER_MINTDB_CMD_END != cmd[i].command; i++)
|
||||||
{
|
{
|
||||||
switch (cmd[i].command)
|
switch (cmd[i].command)
|
||||||
@ -169,13 +172,14 @@ cmd_clean (struct PERF_TALER_MINTDB_Cmd cmd[])
|
|||||||
data_free (&cmd[i].details.save_array.data_saved[j],
|
data_free (&cmd[i].details.save_array.data_saved[j],
|
||||||
cmd[i].details.save_array.type_saved);
|
cmd[i].details.save_array.type_saved);
|
||||||
}
|
}
|
||||||
|
|
||||||
GNUNET_free (cmd[i].details.save_array.data_saved);
|
GNUNET_free (cmd[i].details.save_array.data_saved);
|
||||||
cmd[i].details.save_array.data_saved = NULL;
|
cmd[i].details.save_array.data_saved = NULL;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case PERF_TALER_MINTDB_CMD_LOAD_ARRAY:
|
case PERF_TALER_MINTDB_CMD_LOAD_ARRAY:
|
||||||
GNUNET_free (cmd[i].details.load_array.permutation);
|
GNUNET_free (cmd[i].details.load_array.permutation);
|
||||||
|
cmd[i].details.load_array.permutation = NULL;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -183,7 +187,6 @@ cmd_clean (struct PERF_TALER_MINTDB_Cmd cmd[])
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
return GNUNET_OK;
|
return GNUNET_OK;
|
||||||
};
|
};
|
||||||
@ -196,6 +199,7 @@ static void
|
|||||||
interpret_end_loop (struct PERF_TALER_MINTDB_interpreter_state *state)
|
interpret_end_loop (struct PERF_TALER_MINTDB_interpreter_state *state)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
union PERF_TALER_MINTDB_Data zero = {0};
|
||||||
int jump = cmd_find (state->cmd,
|
int jump = cmd_find (state->cmd,
|
||||||
state->cmd[state->i].details.end_loop.label_loop);
|
state->cmd[state->i].details.end_loop.label_loop);
|
||||||
// Cleaning up the memory in the loop
|
// Cleaning up the memory in the loop
|
||||||
@ -205,6 +209,8 @@ interpret_end_loop (struct PERF_TALER_MINTDB_interpreter_state *state)
|
|||||||
if ( GNUNET_NO == state->cmd[i].exposed_saved)
|
if ( GNUNET_NO == state->cmd[i].exposed_saved)
|
||||||
data_free (&state->cmd[i].exposed, state->cmd[i].exposed_type);
|
data_free (&state->cmd[i].exposed, state->cmd[i].exposed_type);
|
||||||
state->cmd[i].exposed_saved = GNUNET_NO;
|
state->cmd[i].exposed_saved = GNUNET_NO;
|
||||||
|
// Anyway we need to make the data zero.
|
||||||
|
state->cmd[i].exposed = zero;
|
||||||
}
|
}
|
||||||
|
|
||||||
state->cmd[jump].details.loop.curr_iteration++;
|
state->cmd[jump].details.loop.curr_iteration++;
|
||||||
@ -220,11 +226,13 @@ interpret_end_loop (struct PERF_TALER_MINTDB_interpreter_state *state)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
interpret_save_array (struct PERF_TALER_MINTDB_interpreter_state *state)
|
interpret_save_array (struct PERF_TALER_MINTDB_interpreter_state *state)
|
||||||
{
|
{
|
||||||
int loop_index;
|
int loop_index;
|
||||||
int selection_chance;
|
int selection_chance;
|
||||||
|
|
||||||
// Array initialization on first loop iteration
|
// Array initialization on first loop iteration
|
||||||
// Alows for nested loops
|
// Alows for nested loops
|
||||||
if (0 == state->cmd[cmd_find (state->cmd,
|
if (0 == state->cmd[cmd_find (state->cmd,
|
||||||
@ -246,12 +254,14 @@ interpret_save_array (struct PERF_TALER_MINTDB_interpreter_state *state)
|
|||||||
*
|
*
|
||||||
* Else it is saved only if rdn is 0
|
* Else it is saved only if rdn is 0
|
||||||
*/
|
*/
|
||||||
if (((state->cmd[loop_index].details.loop.max_iterations -
|
if ((0 < (state->cmd[state->i].details.save_array.nb_saved -
|
||||||
state->cmd[loop_index].details.loop.curr_iteration) ==
|
state->cmd[state->i].details.save_array.index)) &&
|
||||||
(state->cmd[state->i].details.save_array.nb_saved -
|
(((state->cmd[loop_index].details.loop.max_iterations -
|
||||||
state->cmd[state->i].details.save_array.index))
|
state->cmd[loop_index].details.loop.curr_iteration) ==
|
||||||
|| (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
|
(state->cmd[state->i].details.save_array.nb_saved -
|
||||||
selection_chance)))
|
state->cmd[state->i].details.save_array.index))
|
||||||
|
|| (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
|
||||||
|
selection_chance))))
|
||||||
{
|
{
|
||||||
union PERF_TALER_MINTDB_Data *save_location;
|
union PERF_TALER_MINTDB_Data *save_location;
|
||||||
union PERF_TALER_MINTDB_Data *item_saved;
|
union PERF_TALER_MINTDB_Data *item_saved;
|
||||||
@ -298,6 +308,7 @@ interpret_save_array (struct PERF_TALER_MINTDB_interpreter_state *state)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main interpreter loop.
|
* Main interpreter loop.
|
||||||
*
|
*
|
||||||
@ -371,7 +382,7 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
|
|||||||
case PERF_TALER_MINTDB_CMD_LOAD_ARRAY:
|
case PERF_TALER_MINTDB_CMD_LOAD_ARRAY:
|
||||||
{
|
{
|
||||||
int loop_index, save_index;
|
int loop_index, save_index;
|
||||||
union PERF_TALER_MINTDB_Data loaded_data;
|
union PERF_TALER_MINTDB_Data *loaded_data;
|
||||||
loop_index = cmd_find (state->cmd,
|
loop_index = cmd_find (state->cmd,
|
||||||
state->cmd[state->i].details.load_array.label_loop);
|
state->cmd[state->i].details.load_array.label_loop);
|
||||||
save_index = cmd_find (state->cmd,
|
save_index = cmd_find (state->cmd,
|
||||||
@ -379,18 +390,19 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
|
|||||||
/* Extracting the data from the loop_indexth indice in save_index
|
/* Extracting the data from the loop_indexth indice in save_index
|
||||||
* array.
|
* array.
|
||||||
*/
|
*/
|
||||||
loaded_data = state->cmd[save_index].details.save_array.data_saved[
|
loaded_data = &state->cmd[save_index].details.save_array.data_saved[
|
||||||
state->cmd[state->i].details.load_array.permutation[
|
state->cmd[state->i].details.load_array.permutation[
|
||||||
state->cmd[loop_index].details.loop.curr_iteration]];
|
state->cmd[loop_index].details.loop.curr_iteration]];
|
||||||
|
|
||||||
switch (state->cmd[state->i].exposed_type)
|
switch (state->cmd[state->i].exposed_type)
|
||||||
{
|
{
|
||||||
case PERF_TALER_MINTDB_DEPOSIT:
|
case PERF_TALER_MINTDB_TIME:
|
||||||
state->cmd[state->i].exposed.deposit = loaded_data.deposit;
|
state->cmd[state->i].exposed.time = loaded_data->time;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PERF_TALER_MINTDB_TIME:
|
case PERF_TALER_MINTDB_DEPOSIT:
|
||||||
state->cmd[state->i].exposed.time = loaded_data.time;
|
state->cmd[state->i].exposed.deposit = loaded_data->deposit;
|
||||||
|
loaded_data->deposit = NULL;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -405,9 +417,9 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
|
|||||||
PERF_TALER_MINTDB_deposit_init ();
|
PERF_TALER_MINTDB_deposit_init ();
|
||||||
|
|
||||||
GNUNET_assert (
|
GNUNET_assert (
|
||||||
state->plugin->insert_deposit (state->plugin->cls,
|
state->plugin->insert_deposit (state->plugin->cls,
|
||||||
state->session,
|
state->session,
|
||||||
deposit));
|
deposit));
|
||||||
state->cmd[state->i].exposed.deposit = deposit;
|
state->cmd[state->i].exposed.deposit = deposit;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -446,8 +458,8 @@ PERF_TALER_MINTDB_interpret (struct TALER_MINTDB_Plugin *db_plugin,
|
|||||||
// Initializing commands
|
// Initializing commands
|
||||||
cmd_init (state.cmd);
|
cmd_init (state.cmd);
|
||||||
// Running the interpreter
|
// Running the interpreter
|
||||||
GNUNET_assert(NULL !=
|
GNUNET_assert (NULL !=
|
||||||
(state.session = db_plugin->get_session (db_plugin->cls, GNUNET_YES)));
|
(state.session = db_plugin->get_session (db_plugin->cls, GNUNET_YES)));
|
||||||
interpret (&state);
|
interpret (&state);
|
||||||
// Cleaning the memory
|
// Cleaning the memory
|
||||||
cmd_clean (cmd);
|
cmd_clean (cmd);
|
||||||
|
@ -137,7 +137,7 @@
|
|||||||
.command = PERF_TALER_MINTDB_CMD_GET_DEPOSIT, \
|
.command = PERF_TALER_MINTDB_CMD_GET_DEPOSIT, \
|
||||||
.label = _label, \
|
.label = _label, \
|
||||||
.exposed_type = PERF_TALER_MINTDB_NONE, \
|
.exposed_type = PERF_TALER_MINTDB_NONE, \
|
||||||
.details.label_deposit.saved = _label_deposit \
|
.details.get_deposit.label_source = _label_deposit \
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user