34 #include "gnunet_mysql_lib.h"
35 #include "gnunet_mysql_compat.h"
36 #include "gnunet_my_lib.h"
37 #include <mysql/mysql.h>
42 #define INSERT_EDGE_STMT "INSERT IGNORE INTO `%s` " \
43 "(`key`, `label`, `to_key`, `accepting`) " \
44 "VALUES (?, ?, ?, ?);"
49 #define SELECT_KEY_STMT "SELECT COUNT(*) FROM `%s` " \
50 "WHERE `key` = ? AND `label` = ?;"
180 if (
ret->modnum == 0)
183 if (start_string != NULL)
212 fprintf (stdout,
"%d%%",
216 fprintf (stdout,
"%s",
".");
219 fprintf (stdout,
"%d%%]\n", 100);
274 GNUNET_MYSQL_context_destroy (
mysql_ctx);
325 unsigned int num_edges,
331 uint32_t iaccepting = (uint32_t) accepting;
336 for (i = 0; i < num_edges; i++)
338 struct GNUNET_MY_QueryParam params_select[] = {
339 GNUNET_MY_query_param_auto_from_type (
key),
340 GNUNET_MY_query_param_string (edges[i].label),
341 GNUNET_MY_query_param_end
344 struct GNUNET_MY_ResultSpec results_select[] = {
345 GNUNET_MY_result_spec_uint64 (&total),
346 GNUNET_MY_result_spec_end
357 "Error executing prepared mysql select statement\n");
369 "Error extracting result mysql select statement\n");
374 if ((-1 != total) && (total > 0) )
377 (
unsigned long long) total,
381 struct GNUNET_MY_QueryParam params_stmt[] = {
382 GNUNET_MY_query_param_auto_from_type (&
key),
383 GNUNET_MY_query_param_string (edges[i].label),
384 GNUNET_MY_query_param_auto_from_type (&edges[i].destination),
385 GNUNET_MY_query_param_uint32 (&iaccepting),
386 GNUNET_MY_query_param_end
409 else if (-1 != total)
417 "Error executing prepared mysql statement for edge: Affected rows: %i, expected 0 or 1!\n",
425 struct GNUNET_MY_QueryParam params_stmt[] = {
426 GNUNET_MY_query_param_auto_from_type (
key),
427 GNUNET_MY_query_param_string (
""),
428 GNUNET_MY_query_param_fixed_size (NULL, 0),
429 GNUNET_MY_query_param_uint32 (&iaccepting),
430 GNUNET_MY_query_param_end
441 "Error executing prepared mysql statement for edge: Affected rows: %i, expected 0 or 1!\n",
469 "Failed to create DFA for regex %s\n",
502 "Announcing regexes from file %s\n",
508 "Could not find policy file %s\n",
527 "Could not read policy file %s.\n",
537 while (offset < (filesize - 1))
540 if (((
data[offset] ==
'\n')) && (buf != &
data[offset]))
544 buf = &
data[offset + 1];
546 else if ((
data[offset] ==
'\n') || (
data[offset] ==
'\0'))
547 buf = &
data[offset + 1];
553 "Announcing regex: %s\n",
regex);
558 "Could not announce regex %s\n",
592 "Announcing policy files\n",
603 printf (
"Announced %u files containing %u policies in %s\n"
604 "Duplicate transitions: %llu\nMerged states: %llu\n",
632 _ (
"No policy directory specified on command line. Exiting.\n"));
640 _ (
"Specified policies directory does not exist. Exiting.\n"));
653 "No table name specified, using default \"NFA\".\n");
661 "Failed to create mysql context\n");
694 main (
int argc,
char *
const *argv)
701 "name of the table to write DFAs"),
705 "max-path-compression",
706 "MAX_PATH_COMPRESSION",
720 "gnunet-regex-simulationprofiler [OPTIONS] policy-dir",
721 _ (
"Profiler for regex library"),
options, &
run, NULL);
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
struct GNUNET_GETOPT_CommandLineOption options[]
#define gettext_noop(String)
static int ret
Final status code.
static struct GNUNET_TIME_Absolute start_time
Start time of the current round; used to determine how long one iteration takes (which influences how...
static char * data
The data to insert into the dht.
struct GNUNET_HashCode key
The key used in the DHT.
const struct GNUNET_CONFIGURATION_Handle * config
static void regex_iterator(void *cls, const struct GNUNET_HashCode *key, const char *proof, int accepting, unsigned int num_edges, const struct REGEX_BLOCK_Edge *edges)
Iterator over all states that inserts each state into the MySQL db.
static void do_directory_scan(void *cls)
Iterate over files contained in policy_dir.
static struct ProgressMeter * meter
Handle for the progress meter.
static void free_meter(struct ProgressMeter *meter)
Release resources for meter.
static unsigned int max_path_compression
Maximal path compression length.
static char * policy_dir
Policy dir containing files that contain policies.
#define SELECT_KEY_STMT
MySQL statement to select a key count.
#define INSERT_EDGE_STMT
MySQL statement to insert an edge.
static void do_abort(void *cls)
Abort task to run on test timed out.
static unsigned int num_policies
Number of policies.
static unsigned long long num_merged_states
Number of merged states from different policies.
static struct GNUNET_MYSQL_Context * mysql_ctx
MySQL context.
static void do_shutdown(void *cls)
Shutdown task.
static struct GNUNET_SCHEDULER_Task * scan_task
Scan task identifier;.
static unsigned int num_policy_files
Number of policy files.
static int policy_filename_cb(void *cls, const char *filename)
Function called with a filename.
static int result
Global testing status.
static char * table_name
MySQL table name.
static int update_meter(struct ProgressMeter *meter)
Update progress meter (increment by one).
static int announce_regex(const char *regex)
Announce a regex by creating the DFA and iterating over each state, inserting each state into a MySQL...
static struct GNUNET_MYSQL_StatementHandle * stmt_handle
MySQL prepared statement handle.
static int reset_meter(struct ProgressMeter *meter)
Reset progress meter.
int main(int argc, char *const *argv)
Main function.
static struct GNUNET_MYSQL_StatementHandle * select_stmt_handle
MySQL prepared statement handle for key select.
static struct ProgressMeter * create_meter(unsigned int total, char *start_string, int print)
Create a meter to keep track of the progress of some task.
static char * regex_prefix
Prefix to add before every regex we're announcing.
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *config)
Main function that will be run by the scheduler.
static unsigned long long num_merged_transitions
Number of merged transitions.
static struct GNUNET_TIME_Relative duration
Option '-d': duration of the mapping.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory).
enum GNUNET_GenericReturnValue GNUNET_DISK_file_size(const char *filename, uint64_t *size, int include_symbolic_links, int single_file_mode)
Get the size of the file (or directory) of the given file (in bytes).
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
ssize_t GNUNET_DISK_fn_read(const char *fn, void *result, size_t len)
Read the contents of a binary file into a buffer.
int GNUNET_DISK_directory_scan(const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
Scan a directory for files.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_uint(char shortName, const char *name, const char *argumentHelp, const char *description, unsigned int *val)
Allow user to specify an unsigned int.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_string(char shortName, const char *name, const char *argumentHelp, const char *description, char **str)
Allow user to specify a string.
#define GNUNET_log(kind,...)
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received,...
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
enum GNUNET_GenericReturnValue GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_duration(struct GNUNET_TIME_Absolute whence)
Get the duration of an operation as the difference of the current time and the given start time "henc...
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
void REGEX_INTERNAL_iterate_all_edges(struct REGEX_INTERNAL_Automaton *a, REGEX_INTERNAL_KeyIterator iterator, void *iterator_cls)
Iterate over all edges starting from start state of automaton 'a'.
struct REGEX_INTERNAL_Automaton * REGEX_INTERNAL_construct_dfa(const char *regex, const size_t len, unsigned int max_path_len)
Construct DFA for the given 'regex' of length 'len'.
void REGEX_INTERNAL_automaton_destroy(struct REGEX_INTERNAL_Automaton *a)
Free the memory allocated by constructing the REGEX_INTERNAL_Automaton.
library to parse regular expressions into dfa
Definition of a command line option.
Entry in list of pending tasks.
Time for absolute times used by GNUnet, in microseconds.
Time for relative time used by GNUnet, in microseconds.
Simple struct to keep track of progress, and print a nice little percentage meter for long running ta...
int print
Should the meter be printed?
unsigned int completed
Completed number.
unsigned int dotnum
Number of dots to print.
unsigned int modnum
Interval for printing percentage.
unsigned int total
Total number of elements.
char * startup_string
String to print on startup.
Automaton representation.