39 #define FIND_TIMEOUT \ 40 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 90) 337 void *ca_result,
const char *emsg);
401 unsigned int peer_cnt;
402 unsigned int search_str_cnt;
403 char output_buffer[512];
406 if (NULL != abort_task)
411 if (NULL != register_hosts_task)
414 register_hosts_task = NULL;
416 for (peer_cnt = 0; peer_cnt <
num_peers; peer_cnt++)
418 peer = &peers[peer_cnt];
425 sizeof(output_buffer),
426 "%p Search string not found: %s (%d)\n" 427 "%p On peer: %u (%p)\n" 430 peer, peer->
id, peer,
442 if (NULL != data_file)
447 for (search_str_cnt = 0;
456 if (NULL != reg_handle)
487 unsigned long i = (
unsigned long) cls;
490 "Aborting from line %lu...\n", i);
552 uint64_t
value,
int is_persistent)
555 char output_buffer[512];
558 if (NULL == data_file)
561 "%p -> %s [%s]: %llu\n",
565 (
unsigned long long) value);
570 sizeof(output_buffer),
573 subsystem, value, name);
576 "Unable to write to file!\n");
594 static unsigned int peer_cnt;
600 "Getting statistics for peer %u failed!\n",
611 peer = &peers[peer_cnt];
613 fprintf (stderr,
"s");
617 "\nCollecting stats finished. Shutting down.\n");
653 if ((NULL == ca_result) || (NULL != emsg))
656 "Failed to connect to statistics service on peer %u: %s\n",
670 "Could not get statistics of peer %u!\n", peer->
id);
729 unsigned int get_path_length,
731 unsigned int put_path_length)
734 char output_buffer[512];
740 "String %s on peer %u already matched!\n",
760 "String matching timed out for string %s on peer %u (%i/%i)\n",
769 "String %s found on peer %u after %s (%i/%i) (%u||)\n",
776 if (NULL != data_file)
780 sizeof(output_buffer),
782 "%p Search string: %s\n" 783 "%p Search duration: %s\n\n",
802 "All strings successfully matched in %s\n",
805 if (NULL != search_timeout_task)
808 search_timeout_task = NULL;
829 "Finding matches to all strings did not succeed after %s.\n",
836 "Search timed out after %s." 837 "Collecting stats and shutting down.\n",
867 "Searching for string \"%s\" on peer %d timed out.\n",
883 unsigned int search_peer = (
unsigned int) (
long)
cls;
890 "Searching for string \"%s\" on peer %d (%u||)\n",
903 &peers[search_peer]);
908 &peers[search_peer]);
925 unsigned long search_peer;
933 "Failed to start/stop daemon at peer %u: %s\n", peer->
id, emsg);
939 "Deamon %u started successfully\n", peer->
id);
945 for (i = 0; peers[search_peer].
search_str != NULL; i++)
947 search_peer = (search_peer + 1) %
num_peers;
957 (
void *) search_peer);
976 "Starting announce.\n");
980 " scheduling announce %u\n",
1004 if (NULL != search_timeout_task)
1046 if ((NULL != emsg) || (NULL ==
op) || (NULL == ca_result))
1127 unsigned int num_peers_,
1129 unsigned int links_succeeded,
1130 unsigned int links_failed)
1138 "Testbed started in %s\n",
1141 if (NULL != abort_task)
1160 "Waiting for DHT for %s to settle new connections.\n\n",
1169 search_timeout_task =
1184 switch (event->
type)
1218 unsigned int str_max)
1221 unsigned int offset;
1222 unsigned int str_cnt;
1227 while ((offset < (data_size - 1)) && (str_cnt < str_max))
1230 if (((data[offset] ==
'\n')) &&
1231 (buf != &data[offset]))
1233 data[offset] =
'\0';
1235 buf = &data[offset + 1];
1237 else if ((data[offset] ==
'\n') ||
1238 (data[offset] ==
'\0'))
1239 buf = &data[offset + 1];
1260 char ***strings,
unsigned int str_cnt)
1268 for (i = 0; i < str_cnt; i++)
1270 len = strlen (&data[offset]);
1271 if (offset + len >= data_size)
1313 if (NULL == filename)
1320 "Could not find search strings file %s\n", filename);
1330 "Search strings file %s cannot be read.\n",
1337 "Search strings file %s is empty.\n",
1350 "Could not read search strings file %s.\n",
1377 const char *cfgfile,
1380 unsigned int nsearchstrs;
1390 _ (
"No configuration file given. Exiting\n"));
1408 "PARALLEL_SEARCHES",
1412 "Configuration option \"PARALLEL_SEARCHES\" missing." 1413 " Using default (%d)\n", 10);
1418 "REANNOUNCE_PERIOD_MAX",
1422 "reannounce_period_max not given. Using 10 minutes.\n");
1432 "No policy directory specified on command line. Exiting.\n"));
1438 _ (
"Specified policies directory does not exist. Exiting.\n"));
1446 _ (
"No files found in `%s'\n"),
1455 _ (
"No search strings file given. Exiting.\n"));
1465 "Error loading search strings.\n");
1467 "File (%s) does not contain enough strings (%u/%u).\n",
1475 _ (
"Error loading search strings. Exiting.\n"));
1481 "search string: %s\n",
1486 (NULL == (data_file =
1506 "TESTBED",
"OVERLAY_RANDOM_LINKS",
1510 (
long long unsigned)
1511 (log (num_peers) / log (2.0)));
1533 "SETUP_TIMEOUT not given. Using 15 minutes.\n");
1543 "setup_timeout: %s\n",
1563 "name of the file for writing statistics"),
1570 "wait TIMEOUT before ending the experiment"),
1571 &search_timeout_time),
1584 "name of file with input strings"),
1591 "name of file with hosts' names"),
1603 "gnunet-regex-profiler",
1604 _ (
"Profiler for regex"),
1605 options, &
run, NULL);
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_relative_time(char shortName, const char *name, const char *argumentHelp, const char *description, struct GNUNET_TIME_Relative *val)
Allow user to specify a struct GNUNET_TIME_Relative (using human-readable "fancy" time)...
static char * regex_prefix
Prefix used for regex announcing.
void GNUNET_TESTBED_cancel_registration(struct GNUNET_TESTBED_HostRegistrationHandle *handle)
Cancel the pending registration.
struct GNUNET_STATISTICS_Handle * stats_handle
Peers's statistics handle.
Create file if it doesn't exist.
static char * subsystem
Set to subsystem that we're going to get stats for (or NULL for all).
void GNUNET_TESTBED_controller_disconnect(struct GNUNET_TESTBED_Controller *c)
Stop the given controller (also will terminate all peers and controllers dependent on this controller...
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.
struct GNUNET_CONFIGURATION_Handle * cfg
Peer configuration handle.
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, parse options).
static char * strings_file
File with the strings to look for.
static int in_shutdown
Set when shutting down to avoid making more queries.
Handle to interact with a GNUnet testbed controller.
static int count_and_separate_strings(char *data, uint64_t data_size, unsigned int str_max)
Process the text buffer counting the non-empty lines and separating them with NULL characters...
static struct GNUNET_SCHEDULER_Task * register_hosts_task
Host registration task identifier.
static void find_timed_out(void *cls)
Search timed out.
static void stats_connect_cb(void *cls, struct GNUNET_TESTBED_Operation *op, void *ca_result, const char *emsg)
Function called by testbed once we are connected to stats service.
Destroying peers; we can do this as the controller takes care of stopping a peer if it is running...
static char * data_filename
Filename to log statistics to.
struct GNUNET_DHT_Handle * dht_handle
Peer's DHT handle.
Matching strings against announced regexes.
#define GNUNET_TIME_UNIT_MINUTES
One minute.
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
static struct GNUNET_SCHEDULER_Task * abort_task
Abort task identifier.
int GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
static size_t data_size
Number of bytes in data.
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
struct GNUNET_TESTBED_Operation * op_handle
Testbed operation handle for DHT.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
static int op_result(struct GNUNET_OP_Handle *h, uint64_t op_id, int64_t result_code, const void *data, uint16_t data_size, void **ctx, uint8_t cancel)
Remove an operation, and call its result callback (unless it was cancelled).
struct GNUNET_TESTBED_Operation * daemon_op
Deamon start.
void GNUNET_TESTBED_controller_stop(struct GNUNET_TESTBED_ControllerProc *cproc)
Stop the controller process (also will terminate all peers and controllers dependent on this controll...
static void dht_connect_cb(void *cls, struct GNUNET_TESTBED_Operation *op, void *ca_result, const char *emsg)
DHT connect callback.
static void dht_da(void *cls, void *op_result)
Adapter function called to destroy a connection to the DHT service.
static void * dht_ca(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
DHT connect adapter.
struct GNUNET_TIME_Absolute prof_start_time
The starting time of a profiling step.
void GNUNET_CONFIGURATION_set_value_number(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long number)
Set a configuration value that should be a number.
static int ret
Return value of the commandline.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
struct GNUNET_SCHEDULER_Task * timeout
Operation timeout.
static void test_master(void *cls, struct GNUNET_TESTBED_RunHandle *h, unsigned int num_peers_, struct GNUNET_TESTBED_Peer **testbed_peers, unsigned int links_succeeded, unsigned int links_failed)
Signature of a main function for a testcase.
struct GNUNET_TESTBED_Operation * op
The testbed operation handle.
Definition of a command line option.
static void stats_da(void *cls, void *op_result)
Adapter function called to destroy a connection to statistics service.
int GNUNET_DISK_directory_scan(const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
Scan a directory for files.
int main(int argc, char *const *argv)
Main function.
static struct GNUNET_CONFIGURATION_Handle * cfg
Handle to global configuration.
static int create_string_array(char *data, uint64_t data_size, char ***strings, unsigned int str_cnt)
Allocate a string array and fill it with the prefixed strings from a pre-processed, NULL-separated memory region.
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
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.
Handle for controller process.
struct DLLOperation * prev
The prev pointer for DLL.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Connection to the DHT service.
Opaque handle to an abstract operation to be executed by the testing framework.
static char * hosts_file
File with hostnames where to execute the test.
int GNUNET_snprintf(char *buf, size_t size, const char *format,...) __attribute__((format(printf
Like snprintf, just aborts if the buffer is of insufficient size.
static void do_abort(void *cls)
abort task to run on test timed out
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_filename(char shortName, const char *name, const char *argumentHelp, const char *description, char **str)
Allow user to specify a filename (automatically path expanded).
static struct GNUNET_TESTBED_ControllerProc * mc_proc
Handle to the master controller process.
struct GNUNET_TESTBED_Operation * GNUNET_TESTBED_service_connect(void *op_cls, struct GNUNET_TESTBED_Peer *peer, const char *service_name, GNUNET_TESTBED_ServiceConnectCompletionCallback cb, void *cb_cls, GNUNET_TESTBED_ConnectAdapter ca, GNUNET_TESTBED_DisconnectAdapter da, void *cada_cls)
Connect to a service offered by the given peer.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
static void * stats_ca(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
Adapter function called to establish a connection to statistics service.
enum State state
current state of profiling
static struct GNUNET_OS_Process * p
Helper process we started.
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
static char * value
Value of the record to add/remove.
library to parse regular expressions into dfa
struct GNUNET_TESTBED_Peer * peer_handle
The actual testbed peer handle.
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
static void do_announce(void *cls)
Task to start the daemons on each peer so that the regexes are announced into the DHT...
Truncate file if it exists.
ssize_t GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
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.
static struct GNUNET_TIME_Relative reannounce_period_max
What's the maximum regex reannounce period.
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 GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
static struct GNUNET_TESTBED_HostRegistrationHandle * reg_handle
Host registration handle.
static const struct GNUNET_CONFIGURATION_Handle * config
static int result
Global testing status.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
static void regex_found_handler(void *cls, const struct GNUNET_PeerIdentity *id, const struct GNUNET_PeerIdentity *get_path, unsigned int get_path_length, const struct GNUNET_PeerIdentity *put_path, unsigned int put_path_length)
Method called when we've found a peer that announced a regex that matches our search string...
void GNUNET_CONFIGURATION_set_value_string(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value)
Set a configuration value that should be a string.
static void master_controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event)
Function that will be called whenever something in the testbed changes.
static void daemon_started(void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg)
Callback called when testbed has started the daemon we asked for.
void REGEX_INTERNAL_search_cancel(struct REGEX_INTERNAL_Search *h)
Cancel an ongoing regex search in the DHT and free all resources.
static void find_string(void *cls)
Start searching for the next string in the DHT.
void GNUNET_TESTBED_operation_done(struct GNUNET_TESTBED_Operation *operation)
This function is used to signal that the event information (struct GNUNET_TESTBED_EventInformation) f...
void GNUNET_TESTBED_run(const char *host_filename, const struct GNUNET_CONFIGURATION_Handle *cfg, unsigned int num_peers, uint64_t event_mask, GNUNET_TESTBED_ControllerCallback cc, void *cc_cls, GNUNET_TESTBED_TestMaster test_master, void *test_master_cls)
Convenience method for running a testbed with a single call.
const char * search_str
Peer's search string.
#define GNUNET_TIME_UNIT_MILLISECONDS
One millisecond.
static struct GNUNET_TESTBED_Controller * mc
Handle to the master controller.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
static void do_collect_stats(void *cls)
Task to collect all statistics from all peers, will shutdown the profiler, when done.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
static struct GNUNET_DISK_FileHandle * data_file
File to log statistics to.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
static unsigned int size
Size of the "table".
static struct GNUNET_TESTBED_Peer ** testbed_peers
Handles to all of the running peers.
struct REGEX_INTERNAL_Search * REGEX_INTERNAL_search(struct GNUNET_DHT_Handle *dht, const char *string, REGEX_INTERNAL_Found callback, void *callback_cls, struct GNUNET_STATISTICS_Handle *stats)
Search for a peer offering a regex matching certain string in the DHT.
static void announce_next_regex(void *cls)
Start announcing the next regex in the DHT.
struct GNUNET_DHT_Handle * GNUNET_DHT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, unsigned int ht_len)
Initialize the connection with the DHT service.
static void stats_cb(void *cls, int success)
Stats callback.
void GNUNET_DHT_disconnect(struct GNUNET_DHT_Handle *handle)
Shutdown connection with the DHT service.
static unsigned int parallel_searches
How many searches are running in parallel.
static char * policy_dir
Folder where policy files are stored.
State
Available states during profiling.
static long long unsigned int init_parallel_searches
How many searches are we going to start in parallel.
static void search_timed_out(void *cls)
Connect by string timeout task.
A connection between two peers was established.
Struct to keep information of searches of services described by a regex using a user-provided string ...
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_dup(const struct GNUNET_CONFIGURATION_Handle *cfg)
Duplicate an existing configuration object.
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).
static void do_shutdown(void *cls)
Shutdown nicely.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_add(struct GNUNET_TIME_Relative a1, struct GNUNET_TIME_Relative a2)
Add relative times together.
The identity of the host (wraps the signing key of the peer).
static struct GNUNET_TIME_Relative prof_time
Duration profiling step has taken.
static struct RegexPeer * peers
The array of peers; we fill this as the peers are given to us by the testbed.
static char ** search_strings
Search strings (num_peers of them).
static unsigned int next_search
Index of peer to start next announce/search.
struct GNUNET_STATISTICS_GetHandle * GNUNET_STATISTICS_get(struct GNUNET_STATISTICS_Handle *handle, const char *subsystem, const char *name, GNUNET_STATISTICS_Callback cont, GNUNET_STATISTICS_Iterator proc, void *cls)
Get statistic from the peer.
static uint64_t event_mask
Global event mask for all testbed events.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_time(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, struct GNUNET_TIME_Relative *time)
Get a configuration value that should be a relative time.
static struct GNUNET_TIME_Absolute prof_start_time
The starting time of a profiling step.
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...
#define GNUNET_log(kind,...)
Entry in list of pending tasks.
struct DLLOperation * next
The next pointer for DLL.
Open the file for both reading and writing.
static int stats_iterator(void *cls, const char *subsystem, const char *name, uint64_t value, int is_persistent)
Process statistic values.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
handle for host registration
Time for absolute times used by GNUnet, in microseconds.
static int load_search_strings(const char *filename, char ***strings, unsigned int limit)
Load search strings from given filename.
static unsigned int num_peers
Number of peers to be started by the profiler.
A peer controlled by the testing framework.
static struct GNUNET_TIME_Relative search_timeout_time
Search timeout in seconds.
struct GNUNET_TESTBED_Operation * GNUNET_TESTBED_peer_manage_service(void *op_cls, struct GNUNET_TESTBED_Peer *peer, const char *service_name, GNUNET_TESTBED_OperationCompletionCallback cb, void *cb_cls, unsigned int start)
Start or stop given service at a peer.
struct REGEX_INTERNAL_Search * search_handle
Handle to a running regex search.
uint32_t data
The data value.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Handle used to access files (and pipes).
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_saturating_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Saturating multiply relative time by a given factor.
static unsigned int strings_found
Number of strings found in the published regexes.
int search_str_matched
Set to GNUNET_YES if the peer successfully matched the above search string.
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
static struct GNUNET_SCHEDULER_Task * search_timeout_task
Search timeout task identifier.
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)...
#define GNUNET_malloc(size)
Wrapper around malloc.
ssize_t GNUNET_DISK_fn_read(const char *fn, void *result, size_t len)
Read the contents of a binary file into a buffer.
#define GNUNET_free(ptr)
Wrapper around free.
Time for relative time used by GNUnet, in microseconds.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
#define gettext_noop(String)
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.