GNUnet  0.10.x
Data Structures | Macros | Enumerations | Functions | Variables
gnunet-regex-profiler.c File Reference

Regex profiler for testing distributed regex use. More...

#include <string.h>
#include "platform.h"
#include "gnunet_applications.h"
#include "gnunet_util_lib.h"
#include "regex_internal_lib.h"
#include "gnunet_arm_service.h"
#include "gnunet_dht_service.h"
#include "gnunet_testbed_service.h"
Include dependency graph for gnunet-regex-profiler.c:

Go to the source code of this file.

Data Structures

struct  DLLOperation
 DLL of operations. More...
 
struct  RegexPeer
 Peer handles. More...
 

Macros

#define FIND_TIMEOUT   GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 90)
 

Enumerations

enum  State {
  STATE_INIT = 0, STATE_SLAVES_STARTING, STATE_PEERS_CREATING, STATE_PEERS_STARTING,
  STATE_PEERS_LINKING, STATE_SEARCH_REGEX, STATE_PEERS_DESTROYING, INIT,
  CFG_REQUEST_QUEUED, SERVICE_CONNECTED, RC_INIT = 0, RC_LINKED,
  RC_PEERS_CREATED, RC_READY, RC_PEERS_SHUTDOWN
}
 Available states during profiling. More...
 

Functions

static void dht_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op, void *ca_result, const char *emsg)
 DHT connect callback. More...
 
static void * dht_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
 DHT connect adapter. More...
 
static void dht_da (void *cls, void *op_result)
 Adapter function called to destroy a connection to the DHT service. More...
 
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. More...
 
static void announce_next_regex (void *cls)
 Start announcing the next regex in the DHT. More...
 
static void do_shutdown (void *cls)
 Shutdown nicely. More...
 
static void do_abort (void *cls)
 abort task to run on test timed out More...
 
static void * stats_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
 Adapter function called to establish a connection to statistics service. More...
 
static void stats_da (void *cls, void *op_result)
 Adapter function called to destroy a connection to statistics service. More...
 
static int stats_iterator (void *cls, const char *subsystem, const char *name, uint64_t value, int is_persistent)
 Process statistic values. More...
 
static void stats_cb (void *cls, int success)
 Stats callback. More...
 
static void do_collect_stats (void *cls)
 Task to collect all statistics from all peers, will shutdown the profiler, when done. More...
 
static void find_string (void *cls)
 Start searching for the next string in the DHT. More...
 
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. More...
 
static void search_timed_out (void *cls)
 Connect by string timeout task. More...
 
static void find_timed_out (void *cls)
 Search timed out. More...
 
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. More...
 
static void do_announce (void *cls)
 Task to start the daemons on each peer so that the regexes are announced into the DHT. More...
 
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. More...
 
static void master_controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
 Function that will be called whenever something in the testbed changes. More...
 
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, for later ease of copy using (as)printf. More...
 
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. More...
 
static int load_search_strings (const char *filename, char ***strings, unsigned int limit)
 Load search strings from given filename. More...
 
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. More...
 
int main (int argc, char *const *argv)
 Main function. More...
 

Variables

static int in_shutdown
 Set when shutting down to avoid making more queries. More...
 
static struct RegexPeerpeers
 The array of peers; we fill this as the peers are given to us by the testbed. More...
 
static struct GNUNET_TESTBED_HostRegistrationHandlereg_handle
 Host registration handle. More...
 
static struct GNUNET_TESTBED_ControllerProcmc_proc
 Handle to the master controller process. More...
 
static struct GNUNET_TESTBED_Controllermc
 Handle to the master controller. More...
 
static struct GNUNET_CONFIGURATION_Handlecfg
 Handle to global configuration. More...
 
static struct GNUNET_SCHEDULER_Taskabort_task
 Abort task identifier. More...
 
static struct GNUNET_SCHEDULER_Taskregister_hosts_task
 Host registration task identifier. More...
 
static uint64_t event_mask
 Global event mask for all testbed events. More...
 
static struct GNUNET_TIME_Absolute prof_start_time
 The starting time of a profiling step. More...
 
static struct GNUNET_TIME_Relative prof_time
 Duration profiling step has taken. More...
 
static unsigned int num_peers
 Number of peers to be started by the profiler. More...
 
static int result
 Global testing status. More...
 
enum State state
 current state of profiling More...
 
static char * policy_dir
 Folder where policy files are stored. More...
 
static char * hosts_file
 File with hostnames where to execute the test. More...
 
static char * strings_file
 File with the strings to look for. More...
 
static char ** search_strings
 Search strings (num_peers of them). More...
 
static long long unsigned int init_parallel_searches
 How many searches are we going to start in parallel. More...
 
static unsigned int parallel_searches
 How many searches are running in parallel. More...
 
static unsigned int strings_found
 Number of strings found in the published regexes. More...
 
static unsigned int next_search
 Index of peer to start next announce/search. More...
 
static struct GNUNET_SCHEDULER_Tasksearch_timeout_task
 Search timeout task identifier. More...
 
static struct GNUNET_TIME_Relative search_timeout_time = { 60000 }
 Search timeout in seconds. More...
 
static struct GNUNET_DISK_FileHandledata_file
 File to log statistics to. More...
 
static char * data_filename
 Filename to log statistics to. More...
 
static char * regex_prefix
 Prefix used for regex announcing. More...
 
static struct GNUNET_TIME_Relative reannounce_period_max
 What's the maximum regex reannounce period. More...
 

Detailed Description

Regex profiler for testing distributed regex use.

Author
Bartlomiej Polot
Maximilian Szengel

Definition in file gnunet-regex-profiler.c.

Macro Definition Documentation

◆ FIND_TIMEOUT

Definition at line 39 of file gnunet-regex-profiler.c.

Referenced by find_string().

Enumeration Type Documentation

◆ State

enum State

Available states during profiling.

Enumerator
STATE_INIT 

Initial state.

STATE_SLAVES_STARTING 

Starting slaves.

STATE_PEERS_CREATING 

Creating peers.

STATE_PEERS_STARTING 

Starting peers.

STATE_PEERS_LINKING 

Linking peers.

STATE_SEARCH_REGEX 

Matching strings against announced regexes.

STATE_PEERS_DESTROYING 

Destroying peers; we can do this as the controller takes care of stopping a peer if it is running.

INIT 

Initial state.

CFG_REQUEST_QUEUED 

The configuration request has been sent.

SERVICE_CONNECTED 

connected to service

RC_INIT 

Initial state.

RC_LINKED 

Controllers on given hosts started and linked.

RC_PEERS_CREATED 

Peers are created.

RC_READY 

The testbed run is ready and the master callback can be called now.

At this time the peers are all started and if a topology is provided in the configuration the topology would have been attempted

RC_PEERS_SHUTDOWN 

All peers shutdown (stopped and destroyed)

Definition at line 71 of file gnunet-regex-profiler.c.

71  {
75  STATE_INIT = 0,
76 
81 
86 
91 
96 
101 
107 };
Destroying peers; we can do this as the controller takes care of stopping a peer if it is running...
Matching strings against announced regexes.
Initial state.

Function Documentation

◆ dht_connect_cb()

static void dht_connect_cb ( void *  cls,
struct GNUNET_TESTBED_Operation op,
void *  ca_result,
const char *  emsg 
)
static

DHT connect callback.

Parameters
clsinternal peer id.
opoperation handle.
ca_resultconnect adapter result.
emsgerror message.

Called when we are connected to the dht service for the peer in 'cls'. If successfull we connect to the stats service of this peer and then try to match the search string of this peer.

Parameters
clsinternal peer id.
opoperation handle.
ca_resultconnect adapter result.
emsgerror message.

Definition at line 1036 of file gnunet-regex-profiler.c.

References RegexPeer::dht_handle, GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_NO, GNUNET_TIME_absolute_get(), RegexPeer::op_handle, peer, RegexPeer::prof_start_time, regex_found_handler(), REGEX_INTERNAL_search(), RegexPeer::search_handle, RegexPeer::search_str, and RegexPeer::search_str_matched.

Referenced by find_string().

1040 {
1041  struct RegexPeer *peer = (struct RegexPeer *)cls;
1042 
1043  if (NULL != emsg || NULL == op || NULL == ca_result)
1044  {
1045  GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "DHT connect failed: %s\n", emsg);
1046  GNUNET_assert(0);
1047  }
1048 
1049  GNUNET_assert(NULL != peer->dht_handle);
1050  GNUNET_assert(peer->op_handle == op);
1051  GNUNET_assert(peer->dht_handle == ca_result);
1052 
1053  peer->search_str_matched = GNUNET_NO;
1055  peer->search_str,
1056  &regex_found_handler, peer,
1057  NULL);
1059 }
struct GNUNET_DHT_Handle * dht_handle
Peer&#39;s DHT handle.
struct GNUNET_TESTBED_Operation * op_handle
Testbed operation handle for DHT.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Peer handles.
struct GNUNET_TIME_Absolute prof_start_time
The starting time of a profiling step.
#define GNUNET_NO
Definition: gnunet_common.h:78
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&#39;ve found a peer that announced a regex that matches our search string...
const char * search_str
Peer&#39;s search string.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
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.
#define GNUNET_log(kind,...)
struct REGEX_INTERNAL_Search * search_handle
Handle to a running regex search.
int search_str_matched
Set to GNUNET_YES if the peer successfully matched the above search string.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dht_ca()

static void * dht_ca ( void *  cls,
const struct GNUNET_CONFIGURATION_Handle cfg 
)
static

DHT connect adapter.

Parameters
clsnot used.
cfgconfiguration handle.
Returns

Opens a connection to the dht service.

Parameters
clsClosure (peer).
cfgConfiguration handle.
Returns

Definition at line 1071 of file gnunet-regex-profiler.c.

References DLLOperation::cls, RegexPeer::dht_handle, GNUNET_DHT_connect(), and peer.

Referenced by find_string().

1072 {
1073  struct RegexPeer *peer = cls;
1074 
1075  peer->dht_handle = GNUNET_DHT_connect(cfg, 32);
1076 
1077  return peer->dht_handle;
1078 }
struct GNUNET_DHT_Handle * dht_handle
Peer&#39;s DHT handle.
Peer handles.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
struct GNUNET_DHT_Handle * GNUNET_DHT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, unsigned int ht_len)
Initialize the connection with the DHT service.
Definition: dht_api.c:885
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dht_da()

static void dht_da ( void *  cls,
void *  op_result 
)
static

Adapter function called to destroy a connection to the DHT service.

Adapter function called to destroy a connection to the dht service.

Parameters
clsclosure
op_resultservice handle returned from the connect adapter
clsClosure (peer).
op_resultService handle returned from the connect adapter.

Definition at line 1088 of file gnunet-regex-profiler.c.

References RegexPeer::dht_handle, GNUNET_assert, GNUNET_DHT_disconnect(), peer, REGEX_INTERNAL_search_cancel(), and RegexPeer::search_handle.

Referenced by find_string().

1089 {
1090  struct RegexPeer *peer = (struct RegexPeer *)cls;
1091 
1093 
1094  if (NULL != peer->search_handle)
1095  {
1097  peer->search_handle = NULL;
1098  }
1099 
1100  if (NULL != peer->dht_handle)
1101  {
1103  peer->dht_handle = NULL;
1104  }
1105 }
struct GNUNET_DHT_Handle * dht_handle
Peer&#39;s DHT handle.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Peer handles.
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).
Definition: op.c:243
void REGEX_INTERNAL_search_cancel(struct REGEX_INTERNAL_Search *h)
Cancel an ongoing regex search in the DHT and free all resources.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
void GNUNET_DHT_disconnect(struct GNUNET_DHT_Handle *handle)
Shutdown connection with the DHT service.
Definition: dht_api.c:913
struct REGEX_INTERNAL_Search * search_handle
Handle to a running regex search.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ stats_connect_cb()

static void stats_connect_cb ( void *  cls,
struct GNUNET_TESTBED_Operation op,
void *  ca_result,
const char *  emsg 
)
static

Function called by testbed once we are connected to stats service.

Get the statistics for the services of interest.

Parameters
clsthe 'struct RegexPeer' for which we connected to stats
opconnect operation handle
ca_resulthandle to stats service
emsgerror message on failure

Definition at line 643 of file gnunet-regex-profiler.c.

References DLLOperation::cls, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_STATISTICS_get(), RegexPeer::id, peer, stats_cb(), RegexPeer::stats_handle, and stats_iterator().

Referenced by do_collect_stats(), and stats_cb().

647 {
648  struct RegexPeer *peer = cls;
649 
650  if (NULL == ca_result || NULL != emsg)
651  {
653  "Failed to connect to statistics service on peer %u: %s\n",
654  peer->id, emsg);
655 
656  peer->stats_handle = NULL;
657  return;
658  }
659 
660  peer->stats_handle = ca_result;
661 
662  if (NULL == GNUNET_STATISTICS_get(peer->stats_handle, NULL, NULL,
663  &stats_cb,
664  &stats_iterator, peer))
665  {
667  "Could not get statistics of peer %u!\n", peer->id);
668  }
669 }
struct GNUNET_STATISTICS_Handle * stats_handle
Peers&#39;s statistics handle.
unsigned int id
Peer id.
Peer handles.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
static void stats_cb(void *cls, int success)
Stats callback.
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.
#define GNUNET_log(kind,...)
static int stats_iterator(void *cls, const char *subsystem, const char *name, uint64_t value, int is_persistent)
Process statistic values.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ announce_next_regex()

static void announce_next_regex ( void *  cls)
static

Start announcing the next regex in the DHT.

Parameters
clsIndex of the next peer in the peers array.
clsClosure (unused).

Definition at line 990 of file gnunet-regex-profiler.c.

References RegexPeer::daemon_op, daemon_started(), GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_cancel(), GNUNET_TESTBED_peer_manage_service(), GNUNET_TIME_relative_multiply(), GNUNET_TIME_UNIT_MINUTES, GNUNET_YES, in_shutdown, next_search, num_peers, parallel_searches, peer, RegexPeer::peer_handle, search_timed_out(), and strings_found.

Referenced by do_announce(), find_timed_out(), and regex_found_handler().

991 {
992  struct RegexPeer *peer;
993 
994  if (GNUNET_YES == in_shutdown)
995  return;
996  if (next_search >= num_peers)
997  {
998  if (strings_found != num_peers)
999  {
1000  struct GNUNET_TIME_Relative new_delay;
1001  if (NULL != search_timeout_task)
1006  NULL);
1007  }
1008  return;
1009  }
1010 
1011  GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Starting daemon %u\n", next_search);
1012  peer = &peers[next_search];
1013  peer->daemon_op =
1015  peer->peer_handle,
1016  "regexprofiler",
1017  &daemon_started,
1018  peer,
1019  1);
1020  next_search++;
1022 }
static int in_shutdown
Set when shutting down to avoid making more queries.
#define GNUNET_TIME_UNIT_MINUTES
One minute.
Peer handles.
struct GNUNET_TESTBED_Operation * daemon_op
Deamon start.
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.
Definition: scheduler.c:1237
struct GNUNET_TESTBED_Peer * peer_handle
The actual testbed peer handle.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
Definition: time.c:440
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.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
static unsigned int parallel_searches
How many searches are running in parallel.
static void search_timed_out(void *cls)
Connect by string timeout task.
static struct RegexPeer * peers
The array of peers; we fill this as the peers are given to us by the testbed.
static unsigned int next_search
Index of peer to start next announce/search.
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:77
static unsigned int num_peers
Number of peers to be started by the profiler.
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.
static unsigned int strings_found
Number of strings found in the published regexes.
static struct GNUNET_SCHEDULER_Task * search_timeout_task
Search timeout task identifier.
Time for relative time used by GNUnet, in microseconds.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:956
Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_shutdown()

static void do_shutdown ( void *  cls)
static

Shutdown nicely.

Parameters
clsNULL

Definition at line 395 of file gnunet-regex-profiler.c.

References GNUNET_CONFIGURATION_destroy(), GNUNET_DISK_file_close(), GNUNET_DISK_file_write(), GNUNET_ERROR_TYPE_WARNING, GNUNET_free_non_null, GNUNET_log, GNUNET_NO, GNUNET_SCHEDULER_cancel(), GNUNET_snprintf(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TESTBED_cancel_registration(), GNUNET_TESTBED_controller_disconnect(), GNUNET_TESTBED_controller_stop(), GNUNET_TESTBED_operation_done(), GNUNET_TIME_absolute_get_duration(), GNUNET_YES, RegexPeer::id, num_peers, RegexPeer::op_handle, peer, RegexPeer::prof_start_time, prof_time, RegexPeer::search_str, RegexPeer::search_str_matched, search_strings, and size.

Referenced by do_abort(), and run().

396 {
397  struct RegexPeer *peer;
398  unsigned int peer_cnt;
399  unsigned int search_str_cnt;
400  char output_buffer[512];
401  size_t size;
402 
403  if (NULL != abort_task)
404  {
406  abort_task = NULL;
407  }
408  if (NULL != register_hosts_task)
409  {
411  register_hosts_task = NULL;
412  }
413  for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++)
414  {
415  peer = &peers[peer_cnt];
416 
417  if (GNUNET_YES != peer->search_str_matched && NULL != data_file)
418  {
420  size =
421  GNUNET_snprintf(output_buffer,
422  sizeof(output_buffer),
423  "%p Search string not found: %s (%d)\n"
424  "%p On peer: %u (%p)\n"
425  "%p After: %s\n",
426  peer, peer->search_str, peer->search_str_matched,
427  peer, peer->id, peer,
428  peer,
430  GNUNET_NO));
431  if (size != GNUNET_DISK_file_write(data_file, output_buffer, size))
432  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n");
433  }
434 
435  if (NULL != peers[peer_cnt].op_handle)
436  GNUNET_TESTBED_operation_done(peers[peer_cnt].op_handle);
437  }
438 
439  if (NULL != data_file)
440  {
442  data_file = NULL;
443  }
444  for (search_str_cnt = 0;
445  search_str_cnt < num_peers && NULL != search_strings;
446  search_str_cnt++)
447  {
448  GNUNET_free_non_null(search_strings[search_str_cnt]);
449  }
451  search_strings = NULL;
452 
453  if (NULL != reg_handle)
454  {
456  reg_handle = NULL;
457  }
458  if (NULL != mc)
459  {
461  mc = NULL;
462  }
463  if (NULL != mc_proc)
464  {
466  mc_proc = NULL;
467  }
468  if (NULL != cfg)
469  {
471  cfg = NULL;
472  }
473 }
void GNUNET_TESTBED_cancel_registration(struct GNUNET_TESTBED_HostRegistrationHandle *handle)
Cancel the pending registration.
unsigned int id
Peer id.
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...
Definition: testbed_api.c:1713
int GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1339
static struct GNUNET_SCHEDULER_Task * register_hosts_task
Host registration task identifier.
int GNUNET_snprintf(char *buf, size_t size, const char *format,...)
Like snprintf, just aborts if the buffer is of insufficient size.
static struct GNUNET_SCHEDULER_Task * abort_task
Abort task identifier.
struct GNUNET_TESTBED_Operation * op_handle
Testbed operation handle for DHT.
Peer handles.
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...
struct GNUNET_TIME_Absolute prof_start_time
The starting time of a profiling step.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
static struct GNUNET_CONFIGURATION_Handle * cfg
Handle to global configuration.
static struct GNUNET_TESTBED_ControllerProc * mc_proc
Handle to the master controller process.
ssize_t GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition: disk.c:817
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:686
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
static struct GNUNET_TESTBED_HostRegistrationHandle * reg_handle
Host registration handle.
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...
Definition: testbed_api.c:2037
const char * search_str
Peer&#39;s search string.
static struct GNUNET_TESTBED_Controller * mc
Handle to the master controller.
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".
Definition: peer.c:66
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).
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...
Definition: time.c:373
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:77
static unsigned int num_peers
Number of peers to be started by the profiler.
int search_str_matched
Set to GNUNET_YES if the peer successfully matched the above search string.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:956
Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_abort()

static void do_abort ( void *  cls)
static

abort task to run on test timed out

Parameters
clsNULL

Definition at line 482 of file gnunet-regex-profiler.c.

References do_shutdown(), GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_SCHEDULER_add_now(), GNUNET_SYSERR, and result.

Referenced by run().

483 {
484  unsigned long i = (unsigned long)cls;
485 
487  "Aborting from line %lu...\n", i);
488  abort_task = NULL;
491 }
static struct GNUNET_SCHEDULER_Task * abort_task
Abort task identifier.
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.
Definition: scheduler.c:1264
static int result
Global testing status.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
static void do_shutdown(void *cls)
Shutdown nicely.
#define GNUNET_log(kind,...)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ stats_ca()

static void* stats_ca ( void *  cls,
const struct GNUNET_CONFIGURATION_Handle cfg 
)
static

Adapter function called to establish a connection to statistics service.

Parameters
clsclosure
cfgconfiguration of the peer to connect to; will be available until GNUNET_TESTBED_operation_done() is called on the operation returned from GNUNET_TESTBED_service_connect()
Returns
service handle to return in 'op_result', NULL on error

Definition at line 509 of file gnunet-regex-profiler.c.

References GNUNET_STATISTICS_create().

Referenced by do_collect_stats(), and stats_cb().

511 {
512  return GNUNET_STATISTICS_create("<driver>", cfg);
513 }
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ stats_da()

static void stats_da ( void *  cls,
void *  op_result 
)
static

Adapter function called to destroy a connection to statistics service.

Parameters
clsclosure
op_resultservice handle returned from the connect adapter

Definition at line 524 of file gnunet-regex-profiler.c.

References DLLOperation::cls, GNUNET_assert, GNUNET_NO, GNUNET_STATISTICS_destroy(), peer, and RegexPeer::stats_handle.

Referenced by do_collect_stats(), and stats_cb().

525 {
526  struct RegexPeer *peer = cls;
527 
529 
531  peer->stats_handle = NULL;
532 }
struct GNUNET_STATISTICS_Handle * stats_handle
Peers&#39;s statistics handle.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Peer handles.
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).
Definition: op.c:243
#define GNUNET_NO
Definition: gnunet_common.h:78
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ stats_iterator()

static int stats_iterator ( void *  cls,
const char *  subsystem,
const char *  name,
uint64_t  value,
int  is_persistent 
)
static

Process statistic values.

Write all values to global 'data_file', if present.

Parameters
clsclosure
subsystemname of subsystem that created the statistic
namethe name of the datum
valuethe current value
is_persistentGNUNET_YES if the value is persistent, GNUNET_NO if not
Returns
GNUNET_OK to continue, GNUNET_SYSERR to abort iteration

Definition at line 546 of file gnunet-regex-profiler.c.

References DLLOperation::cls, GNUNET_DISK_file_write(), GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_OK, GNUNET_snprintf(), peer, and size.

Referenced by stats_connect_cb().

550 {
551  struct RegexPeer *peer = cls;
552  char output_buffer[512];
553  size_t size;
554 
555  if (NULL == data_file)
556  {
558  "%p -> %s [%s]: %llu\n",
559  peer,
560  subsystem,
561  name,
562  (unsigned long long)value);
563  return GNUNET_OK;
564  }
565  size =
566  GNUNET_snprintf(output_buffer,
567  sizeof(output_buffer),
568  "%p [%s] %llu %s\n",
569  peer,
570  subsystem, value, name);
571  if (size != GNUNET_DISK_file_write(data_file, output_buffer, size))
573  "Unable to write to file!\n");
574 
575  return GNUNET_OK;
576 }
static char * subsystem
Set to subsystem that we&#39;re going to get stats for (or NULL for all).
int GNUNET_snprintf(char *buf, size_t size, const char *format,...)
Like snprintf, just aborts if the buffer is of insufficient size.
Peer handles.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
static char * value
Value of the record to add/remove.
ssize_t GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition: disk.c:817
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".
Definition: peer.c:66
const char * name
#define GNUNET_log(kind,...)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ stats_cb()

static void stats_cb ( void *  cls,
int  success 
)
static

Stats callback.

Finish the stats testbed operation and when all stats have been iterated, shutdown the profiler.

Parameters
clsclosure
successGNUNET_OK if statistics were successfully obtained, GNUNET_SYSERR if not.

Definition at line 588 of file gnunet-regex-profiler.c.

References DLLOperation::cls, GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_OK, GNUNET_SCHEDULER_shutdown(), GNUNET_TESTBED_operation_done(), GNUNET_TESTBED_service_connect(), RegexPeer::id, num_peers, RegexPeer::op_handle, peer, RegexPeer::peer_handle, result, stats_ca(), stats_connect_cb(), and stats_da().

Referenced by stats_connect_cb().

590 {
591  static unsigned int peer_cnt;
592  struct RegexPeer *peer = cls;
593 
594  if (GNUNET_OK != success)
595  {
597  "Getting statistics for peer %u failed!\n",
598  peer->id);
599  return;
600  }
601 
602  GNUNET_assert(NULL != peer->op_handle);
603 
605  peer->op_handle = NULL;
606 
607  peer_cnt++;
608  peer = &peers[peer_cnt];
609 
610  fprintf(stderr, "s");
611  if (peer_cnt == num_peers)
612  {
614  "\nCollecting stats finished. Shutting down.\n");
616  result = GNUNET_OK;
617  }
618  else
619  {
620  peer->op_handle =
622  peer->peer_handle,
623  "statistics",
625  peer,
626  &stats_ca,
627  &stats_da,
628  peer);
629  }
630 }
unsigned int id
Peer id.
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.
struct GNUNET_TESTBED_Operation * op_handle
Testbed operation handle for DHT.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Peer handles.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
static void stats_da(void *cls, void *op_result)
Adapter function called to destroy a connection to statistics service.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:517
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.
static void * stats_ca(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
Adapter function called to establish a connection to statistics service.
struct GNUNET_TESTBED_Peer * peer_handle
The actual testbed peer handle.
static int result
Global testing status.
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...
Definition: testbed_api.c:2037
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
static struct RegexPeer * peers
The array of peers; we fill this as the peers are given to us by the testbed.
#define GNUNET_log(kind,...)
static unsigned int num_peers
Number of peers to be started by the profiler.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_collect_stats()

static void do_collect_stats ( void *  cls)
static

Task to collect all statistics from all peers, will shutdown the profiler, when done.

Parameters
clsNULL

Definition at line 679 of file gnunet-regex-profiler.c.

References DLLOperation::cls, find_string(), GNUNET_assert, GNUNET_TESTBED_service_connect(), RegexPeer::op_handle, peer, RegexPeer::peer_handle, stats_ca(), stats_connect_cb(), and stats_da().

Referenced by regex_found_handler(), and search_timed_out().

680 {
681  struct RegexPeer *peer = &peers[0];
682 
683  GNUNET_assert(NULL != peer->peer_handle);
684 
685  peer->op_handle =
687  peer->peer_handle,
688  "statistics",
690  peer,
691  &stats_ca,
692  &stats_da,
693  peer);
694 }
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.
struct GNUNET_TESTBED_Operation * op_handle
Testbed operation handle for DHT.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Peer handles.
static void stats_da(void *cls, void *op_result)
Adapter function called to destroy a connection to statistics service.
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.
static void * stats_ca(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
Adapter function called to establish a connection to statistics service.
struct GNUNET_TESTBED_Peer * peer_handle
The actual testbed peer handle.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
static struct RegexPeer * peers
The array of peers; we fill this as the peers are given to us by the testbed.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_string()

static void find_string ( void *  cls)
static

Start searching for the next string in the DHT.

Start searching for a string in the DHT.

Parameters
clsIndex of the next peer in the peers array.

Definition at line 878 of file gnunet-regex-profiler.c.

References DLLOperation::cls, dht_ca(), dht_connect_cb(), dht_da(), find_timed_out(), FIND_TIMEOUT, GNUNET_assert, GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_SCHEDULER_add_delayed(), GNUNET_TESTBED_service_connect(), GNUNET_YES, in_shutdown, num_peers, RegexPeer::op_handle, parallel_searches, RegexPeer::peer_handle, RegexPeer::search_str, and RegexPeer::timeout.

Referenced by daemon_started(), and do_collect_stats().

879 {
880  unsigned int search_peer = (unsigned int)(long)cls;
881 
882  if ((search_peer >= num_peers) ||
883  (GNUNET_YES == in_shutdown))
884  return;
885 
887  "Searching for string \"%s\" on peer %d (%u||)\n",
888  peers[search_peer].search_str,
889  search_peer,
891 
892  peers[search_peer].op_handle =
894  peers[search_peer].peer_handle,
895  "dht",
897  &peers[search_peer],
898  &dht_ca,
899  &dht_da,
900  &peers[search_peer]);
901  GNUNET_assert(NULL != peers[search_peer].op_handle);
902  peers[search_peer].timeout
905  &peers[search_peer]);
906 }
static int in_shutdown
Set when shutting down to avoid making more queries.
static void find_timed_out(void *cls)
Search timed out.
#define FIND_TIMEOUT
struct GNUNET_TESTBED_Operation * op_handle
Testbed operation handle for DHT.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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_SCHEDULER_Task * timeout
Operation timeout.
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.
Definition: scheduler.c:1237
struct GNUNET_TESTBED_Peer * peer_handle
The actual testbed peer handle.
const char * search_str
Peer&#39;s search string.
static unsigned int parallel_searches
How many searches are running in parallel.
static struct RegexPeer * peers
The array of peers; we fill this as the peers are given to us by the testbed.
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:77
static unsigned int num_peers
Number of peers to be started by the profiler.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ regex_found_handler()

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 
)
static

Method called when we've found a peer that announced a regex that matches our search string.

Now get the statistics.

Parameters
clsClosure provided in REGEX_INTERNAL_search.
idPeer providing a regex that matches the string.
get_pathPath of the get request.
get_path_lengthLenght of get_path.
put_pathPath of the put request.
put_path_lengthLength of the put_path.

Definition at line 723 of file gnunet-regex-profiler.c.

References announce_next_regex(), DLLOperation::cls, do_collect_stats(), GNUNET_DISK_file_write(), GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_NO, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), GNUNET_snprintf(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_SYSERR, GNUNET_TESTBED_operation_done(), GNUNET_TIME_absolute_get_duration(), GNUNET_YES, RegexPeer::id, in_shutdown, num_peers, RegexPeer::op_handle, parallel_searches, peer, RegexPeer::prof_start_time, prof_start_time, prof_time, RegexPeer::search_str, RegexPeer::search_str_matched, size, strings_found, and RegexPeer::timeout.

Referenced by dht_connect_cb().

729 {
730  struct RegexPeer *peer = cls;
731  char output_buffer[512];
732  size_t size;
733 
734  if (GNUNET_YES == peer->search_str_matched)
735  {
737  "String %s on peer %u already matched!\n",
738  peer->search_str, peer->id);
739  return;
740  }
741 
742  strings_found++;
744 
745  if (NULL != peer->timeout)
746  {
748  peer->timeout = NULL;
749  if (GNUNET_NO == in_shutdown)
751  }
752 
753  if (NULL == id)
754  {
755  // FIXME not possible right now
757  "String matching timed out for string %s on peer %u (%i/%i)\n",
758  peer->search_str, peer->id, strings_found, num_peers);
760  }
761  else
762  {
764 
766  "String %s found on peer %u after %s (%i/%i) (%u||)\n",
767  peer->search_str, peer->id,
770 
772 
773  if (NULL != data_file)
774  {
775  size =
776  GNUNET_snprintf(output_buffer,
777  sizeof(output_buffer),
778  "%p Peer: %u\n"
779  "%p Search string: %s\n"
780  "%p Search duration: %s\n\n",
781  peer, peer->id,
782  peer, peer->search_str,
783  peer,
785  GNUNET_NO));
786 
787  if (size != GNUNET_DISK_file_write(data_file, output_buffer, size))
788  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n");
789  }
790  }
791 
793  peer->op_handle = NULL;
794 
795  if (strings_found == num_peers)
796  {
799  "All strings successfully matched in %s\n",
801 
802  if (NULL != search_timeout_task)
803  {
805  search_timeout_task = NULL;
806  }
807 
808  GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Collecting stats.\n");
810  }
811 }
unsigned int id
Peer id.
static int in_shutdown
Set when shutting down to avoid making more queries.
int GNUNET_snprintf(char *buf, size_t size, const char *format,...)
Like snprintf, just aborts if the buffer is of insufficient size.
struct GNUNET_TESTBED_Operation * op_handle
Testbed operation handle for DHT.
Peer handles.
struct GNUNET_TIME_Absolute prof_start_time
The starting time of a profiling step.
struct GNUNET_SCHEDULER_Task * timeout
Operation timeout.
#define GNUNET_NO
Definition: gnunet_common.h:78
ssize_t GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition: disk.c:817
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.
Definition: scheduler.c:1264
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:686
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...
Definition: testbed_api.c:2037
const char * search_str
Peer&#39;s search string.
static void do_collect_stats(void *cls)
Task to collect all statistics from all peers, will shutdown the profiler, when done.
static struct GNUNET_DISK_FileHandle * data_file
File to log statistics to.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
static unsigned int size
Size of the "table".
Definition: peer.c:66
static void announce_next_regex(void *cls)
Start announcing the next regex in the DHT.
static unsigned int parallel_searches
How many searches are running in parallel.
static struct GNUNET_TIME_Relative prof_time
Duration profiling step has taken.
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...
Definition: time.c:373
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:77
static unsigned int num_peers
Number of peers to be started by the profiler.
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.
static struct GNUNET_SCHEDULER_Task * search_timeout_task
Search timeout task identifier.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:956
Here is the call graph for this function:
Here is the caller graph for this function:

◆ search_timed_out()

static void search_timed_out ( void *  cls)
static

Connect by string timeout task.

This will cancel the profiler after the specified timeout 'search_timeout'.

Parameters
clsNULL

Definition at line 821 of file gnunet-regex-profiler.c.

References do_collect_stats(), GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_NO, GNUNET_SCHEDULER_add_now(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TESTBED_operation_done(), GNUNET_YES, in_shutdown, num_peers, RegexPeer::op_handle, and strings_found.

Referenced by announce_next_regex(), and test_master().

822 {
823  unsigned int i;
824 
826  "Finding matches to all strings did not succeed after %s.\n",
828  GNUNET_NO));
830  "Found %i of %i strings\n", strings_found, num_peers);
831 
833  "Search timed out after %s."
834  "Collecting stats and shutting down.\n",
836  GNUNET_NO));
837 
839  for (i = 0; i < num_peers; i++)
840  {
841  if (NULL != peers[i].op_handle)
842  {
843  GNUNET_TESTBED_operation_done(peers[i].op_handle);
844  peers[i].op_handle = NULL;
845  }
846  }
848 }
static int in_shutdown
Set when shutting down to avoid making more queries.
struct GNUNET_TESTBED_Operation * op_handle
Testbed operation handle for DHT.
#define GNUNET_NO
Definition: gnunet_common.h:78
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.
Definition: scheduler.c:1264
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:686
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...
Definition: testbed_api.c:2037
static void do_collect_stats(void *cls)
Task to collect all statistics from all peers, will shutdown the profiler, when done.
static struct RegexPeer * peers
The array of peers; we fill this as the peers are given to us by the testbed.
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:77
static unsigned int num_peers
Number of peers to be started by the profiler.
static struct GNUNET_TIME_Relative search_timeout_time
Search timeout in seconds.
static unsigned int strings_found
Number of strings found in the published regexes.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_timed_out()

static void find_timed_out ( void *  cls)
static

Search timed out.

It might still complete in the future, but we should start another one.

Parameters
clsIndex of the next peer in the peers array.

Definition at line 858 of file gnunet-regex-profiler.c.

References announce_next_regex(), DLLOperation::cls, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_NO, GNUNET_SCHEDULER_add_now(), RegexPeer::id, in_shutdown, p, RegexPeer::search_str, and RegexPeer::timeout.

Referenced by find_string().

859 {
860  struct RegexPeer *p = cls;
861 
862  p->timeout = NULL;
864  "Searching for string \"%s\" on peer %d timed out.\n",
865  p->search_str,
866  p->id);
867  if (GNUNET_NO == in_shutdown)
869 }
unsigned int id
Peer id.
static int in_shutdown
Set when shutting down to avoid making more queries.
Peer handles.
struct GNUNET_SCHEDULER_Task * timeout
Operation timeout.
#define GNUNET_NO
Definition: gnunet_common.h:78
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
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.
Definition: scheduler.c:1264
const char * search_str
Peer&#39;s search string.
static void announce_next_regex(void *cls)
Start announcing the next regex in the DHT.
#define GNUNET_log(kind,...)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ daemon_started()

static void daemon_started ( void *  cls,
struct GNUNET_TESTBED_Operation op,
const char *  emsg 
)
static

Callback called when testbed has started the daemon we asked for.

Parameters
clsNULL
opthe operation handle
emsgNULL on success; otherwise an error description

Definition at line 917 of file gnunet-regex-profiler.c.

References RegexPeer::daemon_op, find_string(), GNUNET_assert, GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u32(), GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_NO, GNUNET_SCHEDULER_add_delayed(), GNUNET_TESTBED_operation_done(), GNUNET_TIME_relative_saturating_multiply(), RegexPeer::id, num_peers, peer, reannounce_period_max, RegexPeer::search_str, RegexPeer::search_str_matched, and search_strings.

Referenced by announce_next_regex().

920 {
921  struct RegexPeer *peer = (struct RegexPeer *)cls;
922  unsigned long search_peer;
923  unsigned int i;
924 
926  peer->daemon_op = NULL;
927  if (NULL != emsg)
928  {
930  "Failed to start/stop daemon at peer %u: %s\n", peer->id, emsg);
931  GNUNET_assert(0);
932  }
933  else
934  {
936  "Deamon %u started successfully\n", peer->id);
937  }
938 
939  /* Find a peer to look for a string matching the regex announced */
941  num_peers);
942  for (i = 0; peers[search_peer].search_str != NULL; i++)
943  {
944  search_peer = (search_peer + 1) % num_peers;
945  if (i > num_peers)
946  GNUNET_assert(0); /* we ran out of peers, must be a bug */
947  }
948  peers[search_peer].search_str = search_strings[peer->id];
949  peers[search_peer].search_str_matched = GNUNET_NO;
952  2),
953  &find_string,
954  (void *)search_peer);
955 }
unsigned int id
Peer id.
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Peer handles.
struct GNUNET_TESTBED_Operation * daemon_op
Deamon start.
#define GNUNET_NO
Definition: gnunet_common.h:78
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.
Definition: scheduler.c:1237
static struct GNUNET_TIME_Relative reannounce_period_max
What&#39;s the maximum regex reannounce period.
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...
Definition: testbed_api.c:2037
const char * search_str
Peer&#39;s search string.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
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).
#define GNUNET_log(kind,...)
static unsigned int num_peers
Number of peers to be started by the profiler.
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.
Definition: time.c:499
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).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_announce()

static void do_announce ( void *  cls)
static

Task to start the daemons on each peer so that the regexes are announced into the DHT.

Parameters
clsNULL
tcthe task context

Definition at line 966 of file gnunet-regex-profiler.c.

References announce_next_regex(), GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_SCHEDULER_add_now(), GNUNET_YES, in_shutdown, and init_parallel_searches.

Referenced by test_master().

967 {
968  unsigned int i;
969 
970  if (GNUNET_YES == in_shutdown)
971  return;
973  "Starting announce.\n");
974  for (i = 0; i < init_parallel_searches; i++)
975  {
977  " scheduling announce %u\n",
978  i);
980  }
981 }
static int in_shutdown
Set when shutting down to avoid making more queries.
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.
Definition: scheduler.c:1264
static void announce_next_regex(void *cls)
Start announcing the next regex in the DHT.
static long long unsigned int init_parallel_searches
How many searches are we going to start in parallel.
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:77
Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_master()

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 
)
static

Signature of a main function for a testcase.

Parameters
clsNULL
hthe run handle
num_peers_number of peers in 'peers'
testbed_peershandle to peers run in the testbed. NULL upon timeout (see GNUNET_TESTBED_test_run()).
links_succeededthe number of overlay link connection attempts that succeeded
links_failedthe number of overlay link connection attempts that failed

Definition at line 1122 of file gnunet-regex-profiler.c.

References do_announce(), GNUNET_assert, GNUNET_CONFIGURATION_get_value_yesno(), GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_NO, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_absolute_get_duration(), GNUNET_TIME_relative_multiply(), GNUNET_TIME_UNIT_MILLISECONDS, num_peers, RegexPeer::peer_handle, prof_start_time, prof_time, and search_timed_out().

Referenced by run().

1128 {
1129  unsigned int i;
1130 
1131  GNUNET_assert(num_peers_ == num_peers);
1132 
1135  "Testbed started in %s\n",
1137 
1138  if (NULL != abort_task)
1139  {
1141  abort_task = NULL;
1142  }
1143 
1144  for (i = 0; i < num_peers; i++)
1145  {
1146  peers[i].peer_handle = testbed_peers[i];
1147  }
1148  if (GNUNET_NO ==
1149  GNUNET_CONFIGURATION_get_value_yesno(cfg, "DHT", "DISABLE_TRY_CONNECT"))
1150  {
1151  struct GNUNET_TIME_Relative settle_time;
1152 
1153  settle_time =
1155  10 * num_peers);
1157  "Waiting for DHT for %s to settle new connections.\n\n",
1159  GNUNET_SCHEDULER_add_delayed(settle_time, &do_announce, NULL);
1160  }
1161  else
1162  {
1164  }
1167 }
static struct GNUNET_SCHEDULER_Task * abort_task
Abort task identifier.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_NO
Definition: gnunet_common.h:78
static struct GNUNET_CONFIGURATION_Handle * cfg
Handle to global configuration.
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.
Definition: scheduler.c:1237
struct GNUNET_TESTBED_Peer * peer_handle
The actual testbed peer handle.
static void do_announce(void *cls)
Task to start the daemons on each peer so that the regexes are announced into the DHT...
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.
Definition: scheduler.c:1264
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:686
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
Definition: time.c:440
#define GNUNET_TIME_UNIT_MILLISECONDS
One millisecond.
static void search_timed_out(void *cls)
Connect by string timeout task.
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 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...
Definition: time.c:373
#define GNUNET_log(kind,...)
static unsigned int num_peers
Number of peers to be started by the profiler.
static struct GNUNET_TIME_Relative search_timeout_time
Search timeout in seconds.
int 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".
static struct GNUNET_SCHEDULER_Task * search_timeout_task
Search timeout task identifier.
Time for relative time used by GNUnet, in microseconds.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:956
Here is the call graph for this function:
Here is the caller graph for this function:

◆ master_controller_cb()

static void master_controller_cb ( void *  cls,
const struct GNUNET_TESTBED_EventInformation event 
)
static

Function that will be called whenever something in the testbed changes.

Parameters
clsclosure, NULL
eventinformation on what is happening

Definition at line 1176 of file gnunet-regex-profiler.c.

References GNUNET_TESTBED_ET_CONNECT, GNUNET_TESTBED_ET_PEER_START, and GNUNET_TESTBED_EventInformation::type.

Referenced by run().

1178 {
1179  switch (event->type)
1180  {
1182  printf(".");
1183  break;
1184 
1186  printf("#");
1187  break;
1188 
1189  default:
1190  break;
1191  }
1192  fflush(stdout);
1193 }
enum GNUNET_TESTBED_EventType type
Type of the event.
A connection between two peers was established.
Here is the caller graph for this function:

◆ count_and_separate_strings()

static int count_and_separate_strings ( char *  data,
uint64_t  data_size,
unsigned int  str_max 
)
static

Process the text buffer counting the non-empty lines and separating them with NULL characters, for later ease of copy using (as)printf.

Parameters
dataMemory buffer with strings.
data_sizeSize of the data buffer in bytes.
str_maxMaximum number of strings to return.
Returns
Positive number of lines found in the buffer, GNUNET_SYSERR otherwise.

Definition at line 1211 of file gnunet-regex-profiler.c.

References buf, and data.

Referenced by load_search_strings().

1214 {
1215  char *buf; // Keep track of last string to skip blank lines
1216  unsigned int offset;
1217  unsigned int str_cnt;
1218 
1219  buf = data;
1220  offset = 0;
1221  str_cnt = 0;
1222  while ((offset < (data_size - 1)) && (str_cnt < str_max))
1223  {
1224  offset++;
1225  if (((data[offset] == '\n')) &&
1226  (buf != &data[offset]))
1227  {
1228  data[offset] = '\0';
1229  str_cnt++;
1230  buf = &data[offset + 1];
1231  }
1232  else if ((data[offset] == '\n') ||
1233  (data[offset] == '\0'))
1234  buf = &data[offset + 1];
1235  }
1236  return str_cnt;
1237 }
static char buf[2048]
uint32_t data
The data value.
static size_t data_size
Number of bytes in data.
Here is the caller graph for this function:

◆ create_string_array()

static int create_string_array ( char *  data,
uint64_t  data_size,
char ***  strings,
unsigned int  str_cnt 
)
static

Allocate a string array and fill it with the prefixed strings from a pre-processed, NULL-separated memory region.

Parameters
dataPreprocessed memory with strings
data_sizeSize of the data buffer in bytes.
stringsAddress of the string array to be created. Must be freed by caller if function end in success.
str_cntString count. The data buffer should contain at least this many NULL-separated strings.
Returns
GNUNET_OK in ase of success, GNUNET_SYSERR otherwise. In case of error strings must not be freed.

Definition at line 1254 of file gnunet-regex-profiler.c.

References GNUNET_asprintf(), GNUNET_free, GNUNET_malloc, GNUNET_OK, GNUNET_SYSERR, len, and regex_prefix.

Referenced by load_search_strings().

1256 {
1257  uint64_t offset;
1258  uint64_t len;
1259  unsigned int i;
1260 
1261  *strings = GNUNET_malloc(sizeof(char *) * str_cnt);
1262  offset = 0;
1263  for (i = 0; i < str_cnt; i++)
1264  {
1265  len = strlen(&data[offset]);
1266  if (offset + len >= data_size)
1267  {
1268  GNUNET_free(*strings);
1269  *strings = NULL;
1270  return GNUNET_SYSERR;
1271  }
1272  if (0 == len) // empty line
1273  {
1274  offset++;
1275  i--;
1276  continue;
1277  }
1278 
1279  GNUNET_asprintf(&(*strings)[i],
1280  "%s%s",
1281  regex_prefix,
1282  &data[offset]);
1283  offset += len + 1;
1284  }
1285  return GNUNET_OK;
1286 }
static char * regex_prefix
Prefix used for regex announcing.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
uint32_t data
The data value.
static size_t data_size
Number of bytes in data.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ load_search_strings()

static int load_search_strings ( const char *  filename,
char ***  strings,
unsigned int  limit 
)
static

Load search strings from given filename.

One search string per line.

Parameters
filenamefilename of the file containing the search strings.
stringsset of strings loaded from file. Caller needs to free this if number returned is greater than zero.
limitupper limit on the number of strings read from the file
Returns
number of strings found in the file. GNUNET_SYSERR on error.

Definition at line 1299 of file gnunet-regex-profiler.c.

References count_and_separate_strings(), create_string_array(), data, GNUNET_DISK_file_size(), GNUNET_DISK_file_test(), GNUNET_DISK_fn_read(), GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_malloc, GNUNET_OK, GNUNET_SYSERR, and GNUNET_YES.

Referenced by run().

1302 {
1303  char *data;
1304  uint64_t filesize;
1305  int str_cnt;
1306 
1307  /* Sanity checks */
1308  if (NULL == filename)
1309  {
1310  return GNUNET_SYSERR;
1311  }
1313  {
1315  "Could not find search strings file %s\n", filename);
1316  return GNUNET_SYSERR;
1317  }
1318  if (GNUNET_OK !=
1320  &filesize,
1321  GNUNET_YES,
1322  GNUNET_YES))
1323  {
1325  "Search strings file %s cannot be read.\n",
1326  filename);
1327  return GNUNET_SYSERR;
1328  }
1329  if (0 == filesize)
1330  {
1332  "Search strings file %s is empty.\n",
1333  filename);
1334  return GNUNET_SYSERR;
1335  }
1336 
1337  /* Read data into memory */
1338  data = GNUNET_malloc(filesize + 1);
1339  if (filesize != GNUNET_DISK_fn_read(filename,
1340  data,
1341  filesize))
1342  {
1343  GNUNET_free(data);
1345  "Could not read search strings file %s.\n",
1346  filename);
1347  return GNUNET_SYSERR;
1348  }
1349 
1350  /* Process buffer and build array */
1351  str_cnt = count_and_separate_strings(data, filesize, limit);
1352  if (GNUNET_OK != create_string_array(data, filesize, strings, str_cnt))
1353  {
1354  str_cnt = GNUNET_SYSERR;
1355  }
1356  GNUNET_free(data);
1357  return str_cnt;
1358 }
int 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)...
Definition: disk.c:541
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...
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
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.
static char * filename
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
int 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).
Definition: disk.c:254
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:77
uint32_t data
The data value.
#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.
Definition: disk.c:791
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ run()

static void run ( void *  cls,
char *const *  args,
const char *  cfgfile,
const struct GNUNET_CONFIGURATION_Handle config 
)
static

Main function that will be run by the scheduler.

Parameters
clsclosure
argsremaining command-line arguments
cfgfilename of the configuration file used (for saving, can be NULL!)
configconfiguration

Definition at line 1370 of file gnunet-regex-profiler.c.

References _, data_filename, do_abort(), do_shutdown(), event_mask, GNUNET_CONFIGURATION_dup(), GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONFIGURATION_get_value_time(), GNUNET_CONFIGURATION_set_value_number(), GNUNET_CONFIGURATION_set_value_string(), GNUNET_DISK_directory_scan(), GNUNET_DISK_directory_test(), GNUNET_DISK_file_open(), GNUNET_DISK_file_test(), GNUNET_DISK_OPEN_CREATE, GNUNET_DISK_OPEN_READWRITE, GNUNET_DISK_OPEN_TRUNCATE, GNUNET_DISK_PERM_USER_READ, GNUNET_DISK_PERM_USER_WRITE, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_log_config_missing(), GNUNET_log_strerror_file, GNUNET_malloc, GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_add_now(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TESTBED_ET_CONNECT, GNUNET_TESTBED_ET_PEER_START, GNUNET_TESTBED_run(), GNUNET_TIME_absolute_get(), GNUNET_TIME_relative_add(), GNUNET_TIME_relative_multiply(), GNUNET_TIME_UNIT_MINUTES, GNUNET_YES, hosts_file, in_shutdown, init_parallel_searches, load_search_strings(), master_controller_cb(), num_peers, policy_dir, prof_start_time, reannounce_period_max, regex_prefix, search_strings, strings_file, and test_master().

Referenced by main().

1374 {
1375  unsigned int nsearchstrs;
1376  unsigned int i;
1377  struct GNUNET_TIME_Relative abort_time;
1378 
1380 
1381  /* Check config */
1382  if (NULL == config)
1383  {
1385  _("No configuration file given. Exiting\n"));
1387  return;
1388  }
1389  cfg = GNUNET_CONFIGURATION_dup(config);
1390  if (GNUNET_OK !=
1391  GNUNET_CONFIGURATION_get_value_string(cfg, "REGEXPROFILER",
1392  "REGEX_PREFIX",
1393  &regex_prefix))
1394  {
1396  "regexprofiler",
1397  "regex_prefix");
1399  return;
1400  }
1401  if (GNUNET_OK !=
1402  GNUNET_CONFIGURATION_get_value_number(cfg, "REGEXPROFILER",
1403  "PARALLEL_SEARCHES",
1405  {
1407  "Configuration option \"PARALLEL_SEARCHES\" missing."
1408  " Using default (%d)\n", 10);
1410  }
1411  if (GNUNET_OK !=
1412  GNUNET_CONFIGURATION_get_value_time(cfg, "REGEXPROFILER",
1413  "REANNOUNCE_PERIOD_MAX",
1415  {
1417  "reannounce_period_max not given. Using 10 minutes.\n");
1420  }
1421 
1422  /* Check arguments */
1423  if (NULL == policy_dir)
1424  {
1426  _("No policy directory specified on command line. Exiting.\n"));
1427  return;
1428  }
1430  {
1432  _("Specified policies directory does not exist. Exiting.\n"));
1434  return;
1435  }
1436  if (0 >= (int)(num_peers = GNUNET_DISK_directory_scan(policy_dir, NULL, NULL)))
1437  {
1439  _("No files found in `%s'\n"),
1440  policy_dir);
1441  return;
1442  }
1443  GNUNET_CONFIGURATION_set_value_string(cfg, "REGEXPROFILER",
1444  "POLICY_DIR", policy_dir);
1446  {
1448  _("No search strings file given. Exiting.\n"));
1450  return;
1451  }
1452  nsearchstrs = load_search_strings(strings_file,
1453  &search_strings,
1454  num_peers);
1455  if (num_peers != nsearchstrs)
1456  {
1458  "Error loading search strings.\n");
1460  "File (%s) does not contain enough strings (%u/%u).\n",
1461  strings_file, nsearchstrs, num_peers);
1463  return;
1464  }
1465  if ((0 == num_peers) || (NULL == search_strings))
1466  {
1468  _("Error loading search strings. Exiting.\n"));
1470  return;
1471  }
1472  for (i = 0; i < num_peers; i++)
1474  "search string: %s\n",
1475  search_strings[i]);
1476 
1477  /* Check logfile */
1478  if ((NULL != data_filename) &&
1479  (NULL == (data_file =
1486  {
1488  "open",
1489  data_filename);
1490  return;
1491  }
1492 
1493  /* Initialize peers */
1494  peers = GNUNET_malloc(sizeof(struct RegexPeer) * num_peers);
1495  for (i = 0; i < num_peers; i++)
1496  peers[i].id = i;
1497 
1499  "TESTBED", "OVERLAY_RANDOM_LINKS",
1500  num_peers * 20);
1502  "DHT", "FORCE_NSE",
1503  (long long unsigned)
1504  (log(num_peers) / log(2.0)));
1505  event_mask = 0LL;
1506 /* For feedback about the start process activate these and pass master_cb */
1508 // event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP);
1510 // event_mask |= (1LL << GNUNET_TESTBED_ET_DISCONNECT);
1513  cfg,
1514  num_peers,
1515  event_mask,
1517  NULL, /* master_controller_cb cls */
1518  &test_master,
1519  NULL); /* test_master cls */
1520  if (GNUNET_OK !=
1522  "SETUP_TIMEOUT",
1523  &abort_time))
1524  {
1526  "SETUP_TIMEOUT not given. Using 15 minutes.\n");
1527  abort_time =
1529  }
1530  abort_time = GNUNET_TIME_relative_add(abort_time, GNUNET_TIME_UNIT_MINUTES);
1531  abort_task =
1532  GNUNET_SCHEDULER_add_delayed(abort_time,
1533  &do_abort,
1534  (void*)__LINE__);
1536  "setup_timeout: %s\n",
1538 }
static char * regex_prefix
Prefix used for regex announcing.
int 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)...
Definition: disk.c:541
Create file if it doesn&#39;t exist.
int 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.
int 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.
static char * strings_file
File with the strings to look for.
static int in_shutdown
Set when shutting down to avoid making more queries.
static char * data_filename
Filename to log statistics to.
#define GNUNET_TIME_UNIT_MINUTES
One minute.
static struct GNUNET_SCHEDULER_Task * abort_task
Abort task identifier.
Peer handles.
int GNUNET_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
Definition: disk.c:500
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 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.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
int GNUNET_DISK_directory_scan(const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
Scan a directory for files.
Definition: disk.c:909
static struct GNUNET_CONFIGURATION_Handle * cfg
Handle to global configuration.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
static char * hosts_file
File with hostnames where to execute the test.
static void do_abort(void *cls)
abort task to run on test timed out
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.
Definition: scheduler.c:1237
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
Truncate file if it exists.
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.
Definition: scheduler.c:1264
static struct GNUNET_TIME_Relative reannounce_period_max
What&#39;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.
Definition: strings.c:686
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
Definition: time.c:440
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.
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.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
int 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.
static struct GNUNET_DISK_FileHandle * data_file
File to log statistics to.
static char * policy_dir
Folder where policy files are stored.
static long long unsigned int init_parallel_searches
How many searches are we going to start in parallel.
A connection between two peers was established.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_dup(const struct GNUNET_CONFIGURATION_Handle *cfg)
Duplicate an existing configuration object.
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.
Definition: time.c:577
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 uint64_t event_mask
Global event mask for all testbed events.
static struct GNUNET_TIME_Absolute prof_start_time
The starting time of a profiling step.
#define GNUNET_log(kind,...)
Open the file for both reading and writing.
#define GNUNET_YES
Definition: gnunet_common.h:77
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.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Definition: disk.c:1262
#define GNUNET_malloc(size)
Wrapper around malloc.
Time for relative time used by GNUnet, in microseconds.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *const *  argv 
)

Main function.

Parameters
argcargument count
argvargument values
Returns
0 on success

Definition at line 1549 of file gnunet-regex-profiler.c.

References _, data_filename, gettext_noop, GNUNET_GETOPT_OPTION_END, GNUNET_GETOPT_option_filename(), GNUNET_GETOPT_option_relative_time(), GNUNET_OK, GNUNET_PROGRAM_run(), GNUNET_STRINGS_get_utf8_args(), GNUNET_SYSERR, hosts_file, policy_dir, result, ret, run(), and strings_file.

1550 {
1553  "output-file",
1554  "FILENAME",
1555  gettext_noop("name of the file for writing statistics"),
1556  &data_filename),
1557 
1559  "matching-timeout",
1560  "TIMEOUT",
1561  gettext_noop("wait TIMEOUT before ending the experiment"),
1563 
1565  "policy-dir",
1566  "DIRECTORY",
1567  gettext_noop("directory with policy files"),
1568  &policy_dir),
1569 
1570 
1572  "strings-file",
1573  "FILENAME",
1574  gettext_noop("name of file with input strings"),
1575  &strings_file),
1576 
1578  "hosts-file",
1579  "FILENAME",
1580  gettext_noop("name of file with hosts' names"),
1581  &hosts_file),
1582 
1584  };
1585  int ret;
1586 
1587  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv))
1588  return 2;
1590  ret =
1591  GNUNET_PROGRAM_run(argc, argv,
1592  "gnunet-regex-profiler",
1593  _("Profiler for regex"),
1594  options, &run, NULL);
1595  if (GNUNET_OK != ret)
1596  return ret;
1597  if (GNUNET_OK != result)
1598  return 1;
1599  return 0;
1600 }
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 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 char * strings_file
File with the strings to look for.
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
static char * data_filename
Filename to log statistics to.
int GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1439
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
Definition of a command line option.
static int ret
Final status code.
Definition: gnunet-arm.c:89
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
static char * hosts_file
File with hostnames where to execute the test.
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 int result
Global testing status.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
static char * policy_dir
Folder where policy files are stored.
int 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).
Definition: program.c:367
static struct GNUNET_TIME_Relative search_timeout_time
Search timeout in seconds.
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:

Variable Documentation

◆ in_shutdown

int in_shutdown
static

Set when shutting down to avoid making more queries.

Definition at line 181 of file gnunet-regex-profiler.c.

Referenced by announce_next_regex(), do_announce(), find_string(), find_timed_out(), regex_found_handler(), run(), and search_timed_out().

◆ peers

struct RegexPeer* peers
static

The array of peers; we fill this as the peers are given to us by the testbed.

Definition at line 186 of file gnunet-regex-profiler.c.

◆ reg_handle

struct GNUNET_TESTBED_HostRegistrationHandle* reg_handle
static

Host registration handle.

Definition at line 191 of file gnunet-regex-profiler.c.

◆ mc_proc

struct GNUNET_TESTBED_ControllerProc* mc_proc
static

Handle to the master controller process.

Definition at line 196 of file gnunet-regex-profiler.c.

◆ mc

struct GNUNET_TESTBED_Controller* mc
static

◆ cfg

struct GNUNET_CONFIGURATION_Handle* cfg
static

Handle to global configuration.

Definition at line 206 of file gnunet-regex-profiler.c.

◆ abort_task

struct GNUNET_SCHEDULER_Task* abort_task
static

Abort task identifier.

Definition at line 211 of file gnunet-regex-profiler.c.

◆ register_hosts_task

struct GNUNET_SCHEDULER_Task* register_hosts_task
static

Host registration task identifier.

Definition at line 216 of file gnunet-regex-profiler.c.

◆ event_mask

uint64_t event_mask
static

Global event mask for all testbed events.

Definition at line 221 of file gnunet-regex-profiler.c.

Referenced by run().

◆ prof_start_time

struct GNUNET_TIME_Absolute prof_start_time
static

The starting time of a profiling step.

Definition at line 226 of file gnunet-regex-profiler.c.

Referenced by regex_found_handler(), run(), and test_master().

◆ prof_time

struct GNUNET_TIME_Relative prof_time
static

Duration profiling step has taken.

Definition at line 231 of file gnunet-regex-profiler.c.

Referenced by do_shutdown(), regex_found_handler(), and test_master().

◆ num_peers

unsigned int num_peers
static

Number of peers to be started by the profiler.

Definition at line 236 of file gnunet-regex-profiler.c.

Referenced by announce_next_regex(), daemon_started(), do_shutdown(), find_string(), regex_found_handler(), run(), search_timed_out(), stats_cb(), and test_master().

◆ result

int result
static

Global testing status.

Definition at line 241 of file gnunet-regex-profiler.c.

Referenced by agent_q(), block_plugin_regex_evaluate(), check_reply(), create_internal(), database_shutdown(), decode_private_ecdhe_key(), decode_private_ecdsa_key(), decode_private_eddsa_key(), dns_value_to_string(), do_abort(), do_reconnect(), evaluate_nfa(), expand_dollar(), find_op_by_id(), GAS_handle_reservation_request(), GCC_latency_observed(), get_cont(), GNUNET_BIO_read(), GNUNET_CRYPTO_ecc_ecdh(), GNUNET_CRYPTO_ecdh_eddsa(), GNUNET_CRYPTO_ecdsa_ecdh(), GNUNET_CRYPTO_eddsa_ecdh(), GNUNET_CRYPTO_rsa_private_key_get_public(), GNUNET_FS_directory_scan_get_result(), GNUNET_HOSTLIST_client_start(), GNUNET_MY_extract_result(), GNUNET_PQ_eval_prepared_multi_select(), GNUNET_PQ_eval_prepared_non_select(), GNUNET_PQ_eval_prepared_singleton_select(), GNUNET_PQ_exec_statements(), GNUNET_RECLAIM_ATTRIBUTE_list_dup(), GNUNET_RECLAIM_ATTRIBUTE_list_serialize(), GNUNET_STRINGS_parse_ipv4_policy(), GNUNET_STRINGS_parse_ipv6_policy(), GNUNET_xmalloc_unchecked_(), handle_arm_result(), handle_collect_response(), handle_gns_response(), handle_reply(), handle_search_result(), handle_verify_response(), init_cb(), libgnunet_plugin_datacache_sqlite_done(), main(), numeric_reverse(), OIDC_id_token_new(), process_result_message(), recalculate_path_desirability(), reconnect(), REGEX_INTERNAL_eval(), regex_next_edge(), regex_result_iterator(), ril_network_get_social_welfare(), rsa_sign_mpi(), send_cred_response(), send_with_session(), sq_prepare(), sql_exec(), sql_prepare(), state_set_compare(), stats_cb(), stun_msg2str(), time_between(), and write_cpabe().

◆ state

enum State state

◆ policy_dir

char* policy_dir
static

Folder where policy files are stored.

Definition at line 251 of file gnunet-regex-profiler.c.

Referenced by main(), and run().

◆ hosts_file

char* hosts_file
static

File with hostnames where to execute the test.

Definition at line 256 of file gnunet-regex-profiler.c.

Referenced by main(), and run().

◆ strings_file

char* strings_file
static

File with the strings to look for.

Definition at line 261 of file gnunet-regex-profiler.c.

Referenced by main(), and run().

◆ search_strings

char** search_strings
static

Search strings (num_peers of them).

Definition at line 266 of file gnunet-regex-profiler.c.

Referenced by daemon_started(), do_shutdown(), and run().

◆ init_parallel_searches

long long unsigned int init_parallel_searches
static

How many searches are we going to start in parallel.

Definition at line 271 of file gnunet-regex-profiler.c.

Referenced by do_announce(), and run().

◆ parallel_searches

unsigned int parallel_searches
static

How many searches are running in parallel.

Definition at line 276 of file gnunet-regex-profiler.c.

Referenced by announce_next_regex(), find_string(), and regex_found_handler().

◆ strings_found

unsigned int strings_found
static

Number of strings found in the published regexes.

Definition at line 281 of file gnunet-regex-profiler.c.

Referenced by announce_next_regex(), regex_found_handler(), and search_timed_out().

◆ next_search

unsigned int next_search
static

Index of peer to start next announce/search.

Definition at line 286 of file gnunet-regex-profiler.c.

Referenced by announce_next_regex().

◆ search_timeout_task

struct GNUNET_SCHEDULER_Task* search_timeout_task
static

Search timeout task identifier.

Definition at line 291 of file gnunet-regex-profiler.c.

◆ search_timeout_time

struct GNUNET_TIME_Relative search_timeout_time = { 60000 }
static

Search timeout in seconds.

Definition at line 296 of file gnunet-regex-profiler.c.

◆ data_file

struct GNUNET_DISK_FileHandle* data_file
static

File to log statistics to.

Definition at line 301 of file gnunet-regex-profiler.c.

◆ data_filename

char* data_filename
static

Filename to log statistics to.

Definition at line 306 of file gnunet-regex-profiler.c.

Referenced by main(), and run().

◆ regex_prefix

char* regex_prefix
static

Prefix used for regex announcing.

We need to prefix the search strings with it, in order to find something.

Definition at line 312 of file gnunet-regex-profiler.c.

Referenced by create_string_array(), and run().

◆ reannounce_period_max

struct GNUNET_TIME_Relative reannounce_period_max
static

What's the maximum regex reannounce period.

Definition at line 317 of file gnunet-regex-profiler.c.

Referenced by daemon_started(), and run().