comments, typos
This commit is contained in:
parent
c448e48b53
commit
1e3a45e0cd
@ -132,7 +132,7 @@ data_copy (const struct PERF_TALER_MINTDB_Data *data, struct PERF_TALER_MINTDB_D
|
|||||||
* Finds the first command in cmd with the name search
|
* Finds the first command in cmd with the name search
|
||||||
*
|
*
|
||||||
* @return the index of the first command with name search
|
* @return the index of the first command with name search
|
||||||
* GNUNET_SYSERR if none found
|
* #GNUNET_SYSERR if none found
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
cmd_find (const struct PERF_TALER_MINTDB_Cmd *cmd, const char *search)
|
cmd_find (const struct PERF_TALER_MINTDB_Cmd *cmd, const char *search)
|
||||||
@ -152,7 +152,7 @@ cmd_find (const struct PERF_TALER_MINTDB_Cmd *cmd, const char *search)
|
|||||||
static int
|
static int
|
||||||
cmd_init (struct PERF_TALER_MINTDB_Cmd cmd[])
|
cmd_init (struct PERF_TALER_MINTDB_Cmd cmd[])
|
||||||
{
|
{
|
||||||
unsigned int i = 0;
|
unsigned int i;
|
||||||
|
|
||||||
for (i=0; PERF_TALER_MINTDB_CMD_END != cmd[i].command; i++)
|
for (i=0; PERF_TALER_MINTDB_CMD_END != cmd[i].command; i++)
|
||||||
{
|
{
|
||||||
@ -170,13 +170,12 @@ cmd_init (struct PERF_TALER_MINTDB_Cmd cmd[])
|
|||||||
GNUNET_new_array (cmd[i].details.save_array.nb_saved,
|
GNUNET_new_array (cmd[i].details.save_array.nb_saved,
|
||||||
struct PERF_TALER_MINTDB_Data);
|
struct PERF_TALER_MINTDB_Data);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
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 */
|
||||||
{
|
{
|
||||||
int save_index ;
|
int save_index;
|
||||||
|
|
||||||
GNUNET_assert (GNUNET_SYSERR !=
|
GNUNET_assert (GNUNET_SYSERR !=
|
||||||
(save_index = cmd_find (
|
(save_index = cmd_find (
|
||||||
@ -204,15 +203,16 @@ cmd_init (struct PERF_TALER_MINTDB_Cmd cmd[])
|
|||||||
static int
|
static int
|
||||||
cmd_clean (struct PERF_TALER_MINTDB_Cmd cmd[])
|
cmd_clean (struct PERF_TALER_MINTDB_Cmd cmd[])
|
||||||
{
|
{
|
||||||
unsigned int i = 0;
|
unsigned int i;
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
case PERF_TALER_MINTDB_CMD_SAVE_ARRAY:
|
case PERF_TALER_MINTDB_CMD_SAVE_ARRAY:
|
||||||
{
|
{
|
||||||
unsigned int j;
|
unsigned int j;
|
||||||
|
|
||||||
for (j = 0; j < cmd[i].details.save_array.nb_saved; j++)
|
for (j = 0; j < cmd[i].details.save_array.nb_saved; j++)
|
||||||
{
|
{
|
||||||
data_free (&cmd[i].details.save_array.data_saved[j]);
|
data_free (&cmd[i].details.save_array.data_saved[j]);
|
||||||
@ -234,7 +234,7 @@ cmd_clean (struct PERF_TALER_MINTDB_Cmd cmd[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return GNUNET_OK;
|
return GNUNET_OK;
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -245,6 +245,7 @@ interpret_end_loop (struct PERF_TALER_MINTDB_interpreter_state *state)
|
|||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
int jump;
|
int jump;
|
||||||
|
|
||||||
GNUNET_assert (GNUNET_SYSERR !=
|
GNUNET_assert (GNUNET_SYSERR !=
|
||||||
(jump = cmd_find (state->cmd,
|
(jump = cmd_find (state->cmd,
|
||||||
state->cmd[state->i]
|
state->cmd[state->i]
|
||||||
@ -262,7 +263,9 @@ interpret_end_loop (struct PERF_TALER_MINTDB_interpreter_state *state)
|
|||||||
{
|
{
|
||||||
/* jump back to the start */
|
/* jump back to the start */
|
||||||
state->i = jump;
|
state->i = jump;
|
||||||
}else{
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
/* Reset the loop counter and continue running */
|
/* Reset the loop counter and continue running */
|
||||||
state->cmd[jump].details.loop.curr_iteration = 0;
|
state->cmd[jump].details.loop.curr_iteration = 0;
|
||||||
}
|
}
|
||||||
@ -276,26 +279,30 @@ 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, save_index;
|
struct PERF_TALER_MINTDB_Cmd *cmd = &state->cmd[state->i];
|
||||||
|
struct PERF_TALER_MINTDB_Cmd *save_ref;
|
||||||
|
struct PERF_TALER_MINTDB_Cmd *loop_ref;
|
||||||
|
int loop_index;
|
||||||
|
int save_index;
|
||||||
unsigned int selection_chance;
|
unsigned int selection_chance;
|
||||||
|
|
||||||
GNUNET_assert (GNUNET_SYSERR !=
|
GNUNET_assert (GNUNET_SYSERR !=
|
||||||
(loop_index = cmd_find (state->cmd,
|
(loop_index = cmd_find (state->cmd,
|
||||||
state->cmd[state->i]
|
cmd->details.save_array.label_loop)));
|
||||||
.details.save_array.label_loop)));
|
loop_ref = &state->cmd[save_index];
|
||||||
GNUNET_assert (GNUNET_SYSERR !=
|
GNUNET_assert (GNUNET_SYSERR !=
|
||||||
(save_index = cmd_find (state->cmd,
|
(save_index = cmd_find (state->cmd,
|
||||||
state->cmd[state->i]
|
cmd->details.save_array.label_save)));
|
||||||
.details.save_array.label_save)));
|
save_ref = &state->cmd[save_index];
|
||||||
/* Array initialization on first loop iteration
|
/* Array initialization on first loop iteration
|
||||||
Alows for nested loops */
|
Alows for nested loops */
|
||||||
if (0 == state->cmd[loop_index].details.loop.curr_iteration)
|
if (0 == cmd->details.loop.curr_iteration)
|
||||||
{
|
{
|
||||||
state->cmd[state->i].details.save_array.index = 0;
|
cmd->details.save_array.index = 0;
|
||||||
}
|
}
|
||||||
/* The probobility distribution of the saved items will be a little biased
|
/* The probobility distribution of the saved items will be a little biased
|
||||||
against the few last items but it should not be a big problem. */
|
against the few last items but it should not be a big problem. */
|
||||||
selection_chance = state->cmd[loop_index].details.loop.max_iterations /
|
selection_chance = loop_ref->details.loop.max_iterations /
|
||||||
state->cmd[state->i].details.save_array.nb_saved;
|
state->cmd[state->i].details.save_array.nb_saved;
|
||||||
/*
|
/*
|
||||||
* If the remaining space is equal to the remaining number of
|
* If the remaining space is equal to the remaining number of
|
||||||
@ -303,14 +310,14 @@ interpret_save_array (struct PERF_TALER_MINTDB_interpreter_state *state)
|
|||||||
*
|
*
|
||||||
* Else it is saved only if the random numbre generated is 0
|
* Else it is saved only if the random numbre generated is 0
|
||||||
*/
|
*/
|
||||||
if ((0 < (state->cmd[state->i].details.save_array.nb_saved -
|
if ( (0 < (state->cmd[state->i].details.save_array.nb_saved -
|
||||||
state->cmd[state->i].details.save_array.index)) &&
|
state->cmd[state->i].details.save_array.index) ) &&
|
||||||
(((state->cmd[loop_index].details.loop.max_iterations -
|
( ((state->cmd[loop_index].details.loop.max_iterations -
|
||||||
state->cmd[loop_index].details.loop.curr_iteration) ==
|
state->cmd[loop_index].details.loop.curr_iteration) ==
|
||||||
(state->cmd[state->i].details.save_array.nb_saved -
|
(state->cmd[state->i].details.save_array.nb_saved -
|
||||||
state->cmd[state->i].details.save_array.index))
|
state->cmd[state->i].details.save_array.index)) ||
|
||||||
|| (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
|
(0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
|
||||||
selection_chance))))
|
selection_chance)) ) )
|
||||||
{
|
{
|
||||||
struct PERF_TALER_MINTDB_Data *save_location;
|
struct PERF_TALER_MINTDB_Data *save_location;
|
||||||
struct PERF_TALER_MINTDB_Data *item_saved;
|
struct PERF_TALER_MINTDB_Data *item_saved;
|
||||||
@ -332,7 +339,8 @@ static void
|
|||||||
interpret_load_array (struct PERF_TALER_MINTDB_interpreter_state *state)
|
interpret_load_array (struct PERF_TALER_MINTDB_interpreter_state *state)
|
||||||
{
|
{
|
||||||
unsigned int loop_iter;
|
unsigned int loop_iter;
|
||||||
int loop_index, save_index;
|
int loop_index;
|
||||||
|
int save_index;
|
||||||
struct PERF_TALER_MINTDB_Data *loaded_data;
|
struct PERF_TALER_MINTDB_Data *loaded_data;
|
||||||
|
|
||||||
GNUNET_assert (GNUNET_SYSERR !=
|
GNUNET_assert (GNUNET_SYSERR !=
|
||||||
@ -361,6 +369,7 @@ interpret_load_array (struct PERF_TALER_MINTDB_interpreter_state *state)
|
|||||||
data_copy (loaded_data, &state->cmd[state->i].exposed);
|
data_copy (loaded_data, &state->cmd[state->i].exposed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main interpreter loop.
|
* Main interpreter loop.
|
||||||
*
|
*
|
||||||
@ -377,7 +386,9 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
|
|||||||
return GNUNET_YES;
|
return GNUNET_YES;
|
||||||
|
|
||||||
case PERF_TALER_MINTDB_CMD_DEBUG:
|
case PERF_TALER_MINTDB_CMD_DEBUG:
|
||||||
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", state->cmd[state->i].label);
|
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
||||||
|
"%s\n",
|
||||||
|
state->cmd[state->i].label);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PERF_TALER_MINTDB_CMD_LOOP:
|
case PERF_TALER_MINTDB_CMD_LOOP:
|
||||||
@ -430,7 +441,8 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case PERF_TALER_MINTDB_CMD_ABORT_TRANSACTION:
|
case PERF_TALER_MINTDB_CMD_ABORT_TRANSACTION:
|
||||||
state->plugin->rollback (state->plugin->cls, state->session);
|
state->plugin->rollback (state->plugin->cls,
|
||||||
|
state->session);
|
||||||
|
|
||||||
case PERF_TALER_MINTDB_CMD_SAVE_ARRAY:
|
case PERF_TALER_MINTDB_CMD_SAVE_ARRAY:
|
||||||
interpret_save_array (state);
|
interpret_save_array (state);
|
||||||
@ -444,13 +456,12 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
|
|||||||
{
|
{
|
||||||
int dki_index;
|
int dki_index;
|
||||||
struct TALER_MINTDB_Deposit *deposit;
|
struct TALER_MINTDB_Deposit *deposit;
|
||||||
|
|
||||||
GNUNET_assert (GNUNET_SYSERR !=
|
GNUNET_assert (GNUNET_SYSERR !=
|
||||||
(dki_index = cmd_find(state->cmd,
|
(dki_index = cmd_find(state->cmd,
|
||||||
state->cmd[state->i]
|
state->cmd[state->i].details.insert_deposit.label_dki)));
|
||||||
.details.insert_deposit.label_dki)));
|
|
||||||
GNUNET_assert (NULL !=
|
GNUNET_assert (NULL !=
|
||||||
(deposit = PERF_TALER_MINTDB_deposit_init (
|
(deposit = PERF_TALER_MINTDB_deposit_init (state->cmd[dki_index].exposed.data.dki)));
|
||||||
state->cmd[dki_index].exposed.data.dki)));
|
|
||||||
|
|
||||||
GNUNET_assert (
|
GNUNET_assert (
|
||||||
state->plugin->insert_deposit (state->plugin->cls,
|
state->plugin->insert_deposit (state->plugin->cls,
|
||||||
@ -616,7 +627,8 @@ PERF_TALER_MINTDB_interpret (struct TALER_MINTDB_Plugin *db_plugin,
|
|||||||
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);
|
||||||
|
Loading…
Reference in New Issue
Block a user