GNUnet  0.20.0
testing.c File Reference

convenience API for writing testcases for GNUnet Many testcases need to start and stop a peer/service and this library is supposed to make that easier for TESTCASES. More...

Include dependency graph for testing.c:

Go to the source code of this file.

Data Structures

struct  SharedServiceInstance
 
struct  SharedService
 The structure for identifying a shared service. More...
 
struct  GNUNET_TESTING_System
 Handle for a system on which GNUnet peers are executed; a system is used for reserving unique paths and ports. More...
 
struct  GNUNET_TESTING_Peer
 Handle for a GNUnet peer controlled by testing. More...
 
struct  UpdateContext
 Closure for update_rel_sum() and update_abs_sum(). More...
 
struct  ServiceContext
 Structure for holding service data. More...
 

Macros

#define LOG(kind, ...)   GNUNET_log_from (kind, "testing-api", __VA_ARGS__)
 
#define CONNECT_ADDRESS_TEMPLATE   "%s-192.168.15.%u"
 
#define ROUTER_CONNECT_ADDRESS_TEMPLATE   "%s-92.68.150.%u"
 
#define KNOWN_CONNECT_ADDRESS_TEMPLATE   "%s-92.68.151.%u"
 
#define PREFIX_TCP   "tcp"
 
#define PREFIX_UDP   "udp"
 
#define PREFIX_TCP_NATTED   "tcp_natted"
 
#define PREFIX_UDP_NATTED   "udp_natted"
 
#define LOW_PORT   12000
 Lowest port used for GNUnet testing. More...
 
#define HIGH_PORT   56000
 Highest port used for GNUnet testing. More...
 

Functions

static enum GNUNET_GenericReturnValue hostkeys_load (struct GNUNET_TESTING_System *system)
 Testing includes a number of pre-created hostkeys for faster peer startup. More...
 
static void hostkeys_unload (struct GNUNET_TESTING_System *system)
 Function to remove the loaded hostkeys. More...
 
static void cfg_copy_iterator (void *cls, const char *section, const char *option, const char *value)
 Function to iterate over options. More...
 
struct GNUNET_TESTING_SystemGNUNET_TESTING_system_create_with_portrange (const char *testdir, const char *trusted_ip, const char *hostname, const struct GNUNET_TESTING_SharedService *shared_services, uint16_t lowport, uint16_t highport)
 Create a system handle. More...
 
struct GNUNET_TESTING_SystemGNUNET_TESTING_system_create (const char *testdir, const char *trusted_ip, const char *hostname, const struct GNUNET_TESTING_SharedService *shared_services)
 Create a system handle. More...
 
static void cleanup_shared_service_instance (struct SharedServiceInstance *i)
 
static enum GNUNET_GenericReturnValue start_shared_service_instance (struct SharedServiceInstance *i)
 
static void stop_shared_service_instance (struct SharedServiceInstance *i)
 
void GNUNET_TESTING_system_destroy (struct GNUNET_TESTING_System *system, int remove_paths)
 Free system resources. More...
 
uint16_t GNUNET_TESTING_reserve_port (struct GNUNET_TESTING_System *system)
 Reserve a TCP or UDP port for a peer. More...
 
void GNUNET_TESTING_release_port (struct GNUNET_TESTING_System *system, uint16_t port)
 Release reservation of a TCP or UDP port for a peer (used during GNUNET_TESTING_peer_destroy()). More...
 
struct GNUNET_CRYPTO_EddsaPrivateKeyGNUNET_TESTING_hostkey_get (const struct GNUNET_TESTING_System *system, uint32_t key_number, struct GNUNET_PeerIdentity *id)
 Testing includes a number of pre-created hostkeys for faster peer startup. More...
 
static void update_config (void *cls, const char *section, const char *option, const char *value)
 Function to iterate over options. More...
 
static void update_config_sections (void *cls, const char *section)
 Section iterator to set ACCEPT_FROM/ACCEPT_FROM6 to include the address of 'trusted_hosts' in all sections. More...
 
static struct SharedServiceInstanceassociate_shared_service (struct GNUNET_TESTING_System *system, struct SharedService *ss, struct GNUNET_CONFIGURATION_Handle *cfg)
 
static int GNUNET_TESTING_configuration_create_ (struct GNUNET_TESTING_System *system, struct GNUNET_CONFIGURATION_Handle *cfg, uint16_t **ports, unsigned int *nports)
 Create a new configuration using the given configuration as a template; ports and paths will be modified to select available ports on the local system. More...
 
int GNUNET_TESTING_configuration_create (struct GNUNET_TESTING_System *system, struct GNUNET_CONFIGURATION_Handle *cfg)
 Create a new configuration using the given configuration as a template; ports and paths will be modified to select available ports on the local system. More...
 
struct GNUNET_TESTING_PeerGNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system, struct GNUNET_CONFIGURATION_Handle *cfg, uint32_t key_number, struct GNUNET_PeerIdentity *id, char **emsg)
 Configure a GNUnet peer. More...
 
void GNUNET_TESTING_peer_get_identity (struct GNUNET_TESTING_Peer *peer, struct GNUNET_PeerIdentity *id)
 Obtain the peer identity from a peer handle. More...
 
int GNUNET_TESTING_peer_start (struct GNUNET_TESTING_Peer *peer)
 Start the peer. More...
 
int GNUNET_TESTING_peer_kill (struct GNUNET_TESTING_Peer *peer)
 Sends SIGTERM to the peer's main process. More...
 
int GNUNET_TESTING_peer_wait (struct GNUNET_TESTING_Peer *peer)
 Waits for a peer to terminate. More...
 
int GNUNET_TESTING_peer_stop (struct GNUNET_TESTING_Peer *peer)
 Stop the peer. More...
 
static void disconn_status (void *cls, int connected)
 Function called whenever we connect to or disconnect from ARM. More...
 
int GNUNET_TESTING_peer_stop_async (struct GNUNET_TESTING_Peer *peer, GNUNET_TESTING_PeerStopCallback cb, void *cb_cls)
 Stop a peer asynchronously using ARM API. More...
 
void GNUNET_TESTING_peer_stop_async_cancel (struct GNUNET_TESTING_Peer *peer)
 Cancel a previous asynchronous peer stop request. More...
 
void GNUNET_TESTING_peer_destroy (struct GNUNET_TESTING_Peer *peer)
 Destroy the peer. More...
 
int GNUNET_TESTING_peer_run (const char *testdir, const char *cfgfilename, GNUNET_TESTING_TestMain tm, void *tm_cls)
 Start a single peer and run a test using the testing library. More...
 
static void service_run_main (void *cls)
 Callback to be called when SCHEDULER has been started. More...
 
int GNUNET_TESTING_service_run (const char *testdir, const char *service_name, const char *cfgfilename, GNUNET_TESTING_TestMain tm, void *tm_cls)
 Start a single service (no ARM, except of course if the given service name is 'arm') and run a test using the testing library. More...
 
static unsigned int get_first_value (const char *line)
 Every line in the topology configuration starts with a string indicating which kind of information will be configured with this line. More...
 
static char * get_key (const char *line)
 Every line in the topology configuration starts with a string indicating which kind of information will be configured with this line. More...
 
static char * get_first_string_value (const char *line)
 Every line in the topology configuration starts with a string indicating which kind of information will be configured with this line. More...
 
static unsigned int get_second_value (const char *line)
 Every line in the topology configuration starts with a string indicating which kind of information will be configured with this line. More...
 
static char * get_value (const char *key, const char *line)
 Every line in the topology configuration starts with a string indicating which kind of information will be configured with this line. More...
 
static struct GNUNET_TESTING_NodeConnectionget_connect_value (const char *line, struct GNUNET_TESTING_NetjailNode *node)
 Every line in the topology configuration starts with a string indicating which kind of information will be configured with this line. More...
 
static void node_connections (const char *line, struct GNUNET_TESTING_NetjailNode *node)
 Every line in the topology configuration starts with a string indicating which kind of information will be configured with this line. More...
 
static int log_nodes (void *cls, const struct GNUNET_ShortHashCode *id, void *value)
 A helper function to log information about individual nodes. More...
 
static int log_namespaces (void *cls, const struct GNUNET_ShortHashCode *id, void *value)
 Helper function to log information about namespaces. More...
 
static int log_topo (const struct GNUNET_TESTING_NetjailTopology *topology)
 Helper function to log the configuration in case of a problem with configuration. More...
 
static void get_node_info (unsigned int num, const struct GNUNET_TESTING_NetjailTopology *topology, struct GNUNET_TESTING_NetjailNode **node_ex, struct GNUNET_TESTING_NetjailNamespace **namespace_ex, struct GNUNET_TESTING_NodeConnection **node_connections_ex)
 This function extracts information about a specific node from the topology. More...
 
struct GNUNET_TESTING_NetjailNodeGNUNET_TESTING_get_node (unsigned int num, struct GNUNET_TESTING_NetjailTopology *topology)
 Get a node from the topology. More...
 
struct GNUNET_TESTING_NodeConnectionGNUNET_TESTING_get_connections (unsigned int num, const struct GNUNET_TESTING_NetjailTopology *topology)
 Get the connections to other nodes for a specific node. More...
 
struct GNUNET_PeerIdentityGNUNET_TESTING_get_peer (unsigned int num, const struct GNUNET_TESTING_System *tl_system)
 Retrieve the peer identity from the test system with the unique node id. More...
 
int free_nodes_cb (void *cls, const struct GNUNET_ShortHashCode *key, void *value)
 
int free_namespaces_cb (void *cls, const struct GNUNET_ShortHashCode *key, void *value)
 
void GNUNET_TESTING_free_topology (struct GNUNET_TESTING_NetjailTopology *topology)
 Deallocate memory of the struct GNUNET_TESTING_NetjailTopology. More...
 
unsigned int GNUNET_TESTING_calculate_num (struct GNUNET_TESTING_NodeConnection *node_connection, struct GNUNET_TESTING_NetjailTopology *topology)
 Calculate the unique id identifying a node from a given connection. More...
 
char * GNUNET_TESTING_get_address (struct GNUNET_TESTING_NodeConnection *connection, const char *prefix)
 Get the address for a specific communicator from a connection. More...
 
unsigned int GNUNET_TESTING_get_additional_connects (unsigned int num, struct GNUNET_TESTING_NetjailTopology *topology)
 Get the number of unintentional additional connections the node waits for. More...
 
static void parse_ac (struct GNUNET_TESTING_NetjailNode *p_node, const char *token)
 
struct GNUNET_TESTING_NetjailTopologyGNUNET_TESTING_get_topo_from_string (const char *input)
 Parse the topology data. More...
 
struct GNUNET_TESTING_NetjailTopologyGNUNET_TESTING_get_topo_from_file (const char *filename)
 Getting the topology from file. More...
 

Detailed Description

convenience API for writing testcases for GNUnet Many testcases need to start and stop a peer/service and this library is supposed to make that easier for TESTCASES.

Normal programs should always use functions from gnunet_{util,arm}_lib.h. This API is ONLY for writing testcases (or internal use of the testbed).

Author
Christian Grothoff

Definition in file testing.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "testing-api", __VA_ARGS__)

Definition at line 42 of file testing.c.

◆ CONNECT_ADDRESS_TEMPLATE

#define CONNECT_ADDRESS_TEMPLATE   "%s-192.168.15.%u"

Definition at line 44 of file testing.c.

◆ ROUTER_CONNECT_ADDRESS_TEMPLATE

#define ROUTER_CONNECT_ADDRESS_TEMPLATE   "%s-92.68.150.%u"

Definition at line 46 of file testing.c.

◆ KNOWN_CONNECT_ADDRESS_TEMPLATE

#define KNOWN_CONNECT_ADDRESS_TEMPLATE   "%s-92.68.151.%u"

Definition at line 48 of file testing.c.

◆ PREFIX_TCP

#define PREFIX_TCP   "tcp"

Definition at line 62 of file testing.c.

◆ PREFIX_UDP

#define PREFIX_UDP   "udp"

Definition at line 64 of file testing.c.

◆ PREFIX_TCP_NATTED

#define PREFIX_TCP_NATTED   "tcp_natted"

Definition at line 66 of file testing.c.

◆ PREFIX_UDP_NATTED

#define PREFIX_UDP_NATTED   "udp_natted"

Definition at line 68 of file testing.c.

◆ LOW_PORT

#define LOW_PORT   12000

Lowest port used for GNUnet testing.

Should be high enough to not conflict with other applications running on the hosts but be low enough to not conflict with client-ports (typically starting around 32k).

Definition at line 76 of file testing.c.

◆ HIGH_PORT

#define HIGH_PORT   56000

Highest port used for GNUnet testing.

Should be low enough to not conflict with the port range for "local" ports (client apps; see /proc/sys/net/ipv4/ip_local_port_range on Linux for example).

Definition at line 83 of file testing.c.

Function Documentation

◆ hostkeys_load()

static enum GNUNET_GenericReturnValue hostkeys_load ( struct GNUNET_TESTING_System system)
static

Testing includes a number of pre-created hostkeys for faster peer startup.

This function loads such keys into memory from a file.

Parameters
systemthe testing system handle
Returns
GNUNET_OK on success; GNUNET_SYSERR on error

Definition at line 1 of file testing.c.

277 {
278  uint64_t fs;
279  char *data_dir;
280  char *filename;
281  struct GNUNET_DISK_FileHandle *fd;
282 
283  GNUNET_assert (NULL == system->hostkeys_data);
285  GNUNET_asprintf (&filename, "%s/testing_hostkeys.ecc", data_dir);
286  GNUNET_free (data_dir);
287 
289  {
291  _ ("Hostkeys file not found: %s\n"),
292  filename);
294  return GNUNET_SYSERR;
295  }
296  /* Check hostkey file size, read entire thing into memory */
297  if (GNUNET_OK !=
299  fs = 0;
300  if (0 == fs)
301  {
303  return GNUNET_SYSERR; /* File is empty */
304  }
305  if (0 != (fs % GNUNET_TESTING_HOSTKEYFILESIZE))
306  {
308  _ ("Incorrect hostkey file format: %s\n"),
309  filename);
311  return GNUNET_SYSERR;
312  }
316  if (NULL == fd)
317  {
320  return GNUNET_SYSERR;
321  }
323  system->hostkeys_data =
326  if (NULL == system->hostkeys_data)
327  return GNUNET_SYSERR;
329  return GNUNET_OK;
330 }
static char * filename
static struct GNUNET_FS_Handle * fs
Handle to FS service.
Definition: gnunet-fs.c:37
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:1237
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).
Definition: disk.c:482
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).
Definition: disk.c:221
void * GNUNET_DISK_file_map(const struct GNUNET_DISK_FileHandle *h, struct GNUNET_DISK_MapHandle **m, enum GNUNET_DISK_MapType access, size_t len)
Map a file into memory.
Definition: disk.c:1380
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1308
@ GNUNET_DISK_OPEN_READ
Open the file for reading.
@ GNUNET_DISK_PERM_NONE
Nobody is allowed to do anything to the file.
@ GNUNET_DISK_MAP_TYPE_READ
Read-only memory map.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_SYSERR
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#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...
@ GNUNET_ERROR_TYPE_ERROR
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_free(ptr)
Wrapper around free.
char * GNUNET_OS_installation_get_path(enum GNUNET_OS_InstallationPathKind dirkind)
Get the path to a specific GNUnet installation directory or, with GNUNET_OS_IPK_SELF_PREFIX,...
@ GNUNET_OS_IPK_DATADIR
Return the directory where data is installed (share/gnunet/)
#define GNUNET_TESTING_HOSTKEYFILESIZE
Size of each hostkey in the hostkey file (in BYTES).
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
Handle used to access files (and pipes).
int fd
File handle on Unix-like systems.
uint32_t total_hostkeys
The number of hostkeys.
Definition: testing.c:177
char * hostkeys_data
Hostkeys data, contains "GNUNET_TESTING_HOSTKEYFILESIZE * total_hostkeys" bytes.
Definition: testing.c:143
struct GNUNET_DISK_MapHandle * map
memory map for hostkeys_data.
Definition: testing.c:148
#define LOG(kind,...)
Definition: testing.c:42

Referenced by GNUNET_TESTING_system_create_with_portrange().

Here is the caller graph for this function:

◆ hostkeys_unload()

static void hostkeys_unload ( struct GNUNET_TESTING_System system)
static

Function to remove the loaded hostkeys.

Parameters
systemthe testing system handle

Definition at line 339 of file testing.c.

340 {
341  GNUNET_break (NULL != system->hostkeys_data);
342  system->hostkeys_data = NULL;
343  GNUNET_DISK_file_unmap (system->map);
344  system->map = NULL;
345  system->hostkeys_data = NULL;
346  system->total_hostkeys = 0;
347 }
enum GNUNET_GenericReturnValue GNUNET_DISK_file_unmap(struct GNUNET_DISK_MapHandle *h)
Unmap a file.
Definition: disk.c:1411
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.

References GNUNET_break, GNUNET_DISK_file_unmap(), GNUNET_TESTING_System::hostkeys_data, GNUNET_TESTING_System::map, and GNUNET_TESTING_System::total_hostkeys.

Referenced by GNUNET_TESTING_service_run(), and GNUNET_TESTING_system_destroy().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cfg_copy_iterator()

static void cfg_copy_iterator ( void *  cls,
const char *  section,
const char *  option,
const char *  value 
)
static

Function to iterate over options.

Parameters
clsclosure
sectionname of the section
optionname of the option
valuevalue of the option

Definition at line 359 of file testing.c.

363 {
364  struct GNUNET_CONFIGURATION_Handle *cfg2 = cls;
365 
366  GNUNET_CONFIGURATION_set_value_string (cfg2, section, option, value);
367 }
static char * value
Value of the record to add/remove.
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.

References GNUNET_CONFIGURATION_set_value_string(), and value.

Referenced by associate_shared_service(), and GNUNET_TESTING_system_create_with_portrange().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cleanup_shared_service_instance()

static void cleanup_shared_service_instance ( struct SharedServiceInstance i)
static

Definition at line 493 of file testing.c.

494 {
495  if (NULL != i->cfg_fn)
496  {
497  (void) unlink (i->cfg_fn);
498  GNUNET_free (i->cfg_fn);
499  }
500  GNUNET_free (i->unix_sock);
501  GNUNET_free (i->port_str);
502  GNUNET_break (NULL == i->proc);
503  GNUNET_break (0 == i->n_refs);
504  GNUNET_free (i);
505 }
unsigned int n_refs
Definition: testing.c:98
struct GNUNET_OS_Process * proc
Definition: testing.c:92

References SharedServiceInstance::cfg_fn, GNUNET_break, GNUNET_free, SharedServiceInstance::n_refs, SharedServiceInstance::port_str, SharedServiceInstance::proc, and SharedServiceInstance::unix_sock.

Referenced by associate_shared_service(), and GNUNET_TESTING_system_destroy().

Here is the caller graph for this function:

◆ start_shared_service_instance()

static enum GNUNET_GenericReturnValue start_shared_service_instance ( struct SharedServiceInstance i)
static

Definition at line 493 of file testing.c.

510 {
511  char *binary;
512  char *libexec_binary;
513 
514  GNUNET_assert (NULL == i->proc);
515  GNUNET_assert (NULL != i->cfg_fn);
516  (void) GNUNET_asprintf (&binary, "gnunet-service-%s", i->ss->sname);
517  libexec_binary = GNUNET_OS_get_libexec_binary_path (binary);
518  GNUNET_free (binary);
520  NULL,
521  NULL,
522  NULL,
523  libexec_binary,
524  libexec_binary,
525  "-c",
526  i->cfg_fn,
527  NULL);
528  GNUNET_free (libexec_binary);
529  if (NULL == i->proc)
530  return GNUNET_SYSERR;
531  return GNUNET_OK;
532 }
char * GNUNET_OS_get_libexec_binary_path(const char *progname)
Given the name of a gnunet-helper, gnunet-service or gnunet-daemon binary, try to prefix it with the ...
struct GNUNET_OS_Process * GNUNET_OS_start_process(enum GNUNET_OS_InheritStdioFlags std_inheritance, struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, struct GNUNET_DISK_PipeHandle *pipe_stderr, const char *filename,...)
Start a process.
Definition: os_priority.c:620
@ GNUNET_OS_INHERIT_STD_OUT_AND_ERR
When these flags are set, the child process will inherit stdout and stderr of the parent.
struct SharedService * ss
Definition: testing.c:88
char * sname
Definition: testing.c:103

Referenced by GNUNET_TESTING_peer_start().

Here is the caller graph for this function:

◆ stop_shared_service_instance()

static void stop_shared_service_instance ( struct SharedServiceInstance i)
static

Definition at line 536 of file testing.c.

537 {
538  GNUNET_break (0 == i->n_refs);
541  "Killing shared service instance (%s) failed\n",
542  i->ss->sname);
543  (void) GNUNET_OS_process_wait (i->proc);
545  i->proc = NULL;
546 }
@ GNUNET_ERROR_TYPE_WARNING
void GNUNET_OS_process_destroy(struct GNUNET_OS_Process *proc)
Cleans up process structure contents (OS-dependent) and deallocates it.
Definition: os_priority.c:260
int GNUNET_OS_process_kill(struct GNUNET_OS_Process *proc, int sig)
Sends a signal to the process.
Definition: os_priority.c:210
enum GNUNET_GenericReturnValue GNUNET_OS_process_wait(struct GNUNET_OS_Process *proc)
Wait for a process to terminate.
Definition: os_priority.c:871
#define GNUNET_TERM_SIG
The termination signal.
Definition: platform.h:234

References GNUNET_break, GNUNET_ERROR_TYPE_WARNING, GNUNET_OS_process_destroy(), GNUNET_OS_process_kill(), GNUNET_OS_process_wait(), GNUNET_TERM_SIG, LOG, SharedServiceInstance::n_refs, SharedServiceInstance::proc, SharedService::sname, and SharedServiceInstance::ss.

Referenced by GNUNET_TESTING_peer_kill(), and GNUNET_TESTING_system_destroy().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_config()

static void update_config ( void *  cls,
const char *  section,
const char *  option,
const char *  value 
)
static

Function to iterate over options.

Copies the options to the target configuration, updating PORT values as needed.

Parameters
clsthe UpdateContext
sectionname of the section
optionname of the option
valuevalue of the option

Definition at line 808 of file testing.c.

812 {
813  struct UpdateContext *uc = cls;
814  unsigned int ival;
815  char cval[12];
816  char uval[PATH_MAX];
817  char *single_variable;
818  char *per_host_variable;
819  unsigned long long num_per_host;
820  uint16_t new_port;
821 
822  if (GNUNET_OK != uc->status)
823  return;
824  if (! ((0 == strcmp (option, "PORT")) || (0 == strcmp (option, "UNIXPATH")) ||
825  (0 == strcmp (option, "HOSTNAME"))))
826  return;
827  GNUNET_asprintf (&single_variable, "single_%s_per_host", section);
828  GNUNET_asprintf (&per_host_variable, "num_%s_per_host", section);
829  if ((0 == strcmp (option, "PORT")) && (1 == sscanf (value, "%u", &ival)))
830  {
831  if ((ival != 0) &&
833  "testing",
834  single_variable)))
835  {
836  new_port = GNUNET_TESTING_reserve_port (uc->system);
837  if (0 == new_port)
838  {
839  uc->status = GNUNET_SYSERR;
840  GNUNET_free (single_variable);
841  GNUNET_free (per_host_variable);
842  return;
843  }
844  GNUNET_snprintf (cval, sizeof(cval), "%u", new_port);
845  value = cval;
846  GNUNET_array_append (uc->ports, uc->nports, new_port);
847  }
848  else if ((ival != 0) &&
849  (GNUNET_YES ==
851  "testing",
852  single_variable)) &&
854  "testing",
855  per_host_variable,
856  &num_per_host))
857  {
858  /* GNUNET_snprintf (cval, sizeof (cval), "%u", */
859  /* ival + ctx->fdnum % num_per_host); */
860  /* value = cval; */
861  GNUNET_break (0); /* FIXME */
862  }
863  }
864  if (0 == strcmp (option, "UNIXPATH"))
865  {
867  "testing",
868  single_variable))
869  {
870  GNUNET_snprintf (uval,
871  sizeof(uval),
872  "%s/%s.sock",
873  uc->gnunet_home,
874  section);
875  value = uval;
876  }
877  else if ((GNUNET_YES ==
879  "testing",
880  per_host_variable,
881  &num_per_host)) &&
882  (num_per_host > 0))
883  {
884  GNUNET_break (0); /* FIXME */
885  }
886  }
887  if (0 == strcmp (option, "HOSTNAME"))
888  {
889  value = (NULL == uc->system->hostname) ? "localhost" : uc->system->hostname;
890  }
891  GNUNET_free (single_variable);
892  GNUNET_free (per_host_variable);
893  GNUNET_CONFIGURATION_set_value_string (uc->cfg, section, option, value);
894 }
static struct GNUNET_FS_UnindexContext * uc
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.
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".
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.
#define GNUNET_array_append(arr, len, element)
Append an element to an array (growing the array by one).
uint16_t GNUNET_TESTING_reserve_port(struct GNUNET_TESTING_System *system)
Reserve a TCP or UDP port for a peer.
Definition: testing.c:598
#define PATH_MAX
Assumed maximum path length.
Definition: platform.h:241
Closure for update_rel_sum() and update_abs_sum().

References GNUNET_array_append, GNUNET_asprintf(), GNUNET_break, GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONFIGURATION_get_value_yesno(), GNUNET_CONFIGURATION_set_value_string(), GNUNET_free, GNUNET_OK, GNUNET_snprintf(), GNUNET_SYSERR, GNUNET_TESTING_reserve_port(), GNUNET_YES, PATH_MAX, uc, and value.

Referenced by GNUNET_TESTING_configuration_create_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_config_sections()

static void update_config_sections ( void *  cls,
const char *  section 
)
static

Section iterator to set ACCEPT_FROM/ACCEPT_FROM6 to include the address of 'trusted_hosts' in all sections.

Parameters
clsthe UpdateContext
sectionname of the section

Definition at line 905 of file testing.c.

906 {
907  struct UpdateContext *uc = cls;
908  char **ikeys;
909  char *val;
910  char *ptr;
911  char *orig_allowed_hosts;
912  char *allowed_hosts;
913  char *ACCEPT_FROM_key;
914  uint16_t ikeys_cnt;
915  uint16_t key;
916 
917  ikeys_cnt = 0;
918  val = NULL;
919  /* Ignore certain options from sections. See
920  https://gnunet.org/bugs/view.php?id=2476 */
921  if (GNUNET_YES ==
922  GNUNET_CONFIGURATION_have_value (uc->cfg, section, "TESTING_IGNORE_KEYS"))
923  {
926  section,
927  "TESTING_IGNORE_KEYS",
928  &val));
929  ptr = val;
930  for (ikeys_cnt = 0; NULL != (ptr = strstr (ptr, ";")); ikeys_cnt++)
931  ptr++;
932  if (0 == ikeys_cnt)
933  GNUNET_break (0);
934  else
935  {
936  ikeys = GNUNET_malloc ((sizeof(char *)) * ikeys_cnt);
937  ptr = val;
938  for (key = 0; key < ikeys_cnt; key++)
939  {
940  ikeys[key] = ptr;
941  ptr = strstr (ptr, ";");
942  GNUNET_assert (NULL != ptr); /* worked just before... */
943  *ptr = '\0';
944  ptr++;
945  }
946  }
947  }
948  if (0 != ikeys_cnt)
949  {
950  for (key = 0; key < ikeys_cnt; key++)
951  {
952  if (NULL != strstr (ikeys[key], "ADVERTISED_PORT"))
953  break;
954  }
955  if ((key == ikeys_cnt) &&
956  (GNUNET_YES ==
957  GNUNET_CONFIGURATION_have_value (uc->cfg, section, "ADVERTISED_PORT")))
958  {
960  section,
961  "PORT",
962  &ptr))
963  {
965  section,
966  "ADVERTISED_PORT",
967  ptr);
968  GNUNET_free (ptr);
969  }
970  }
971  for (key = 0; key < ikeys_cnt; key++)
972  {
973  if (NULL != strstr (ikeys[key], "ACCEPT_FROM"))
974  {
975  GNUNET_free (ikeys);
976  GNUNET_free (val);
977  return;
978  }
979  }
980  GNUNET_free (ikeys);
981  }
982  GNUNET_free (val);
983  ACCEPT_FROM_key = "ACCEPT_FROM";
984  if ((NULL != uc->system->trusted_ip) &&
985  (NULL != strstr (uc->system->trusted_ip, ":"))) /* IPv6 in use */
986  ACCEPT_FROM_key = "ACCEPT_FROM6";
988  section,
989  ACCEPT_FROM_key,
990  &orig_allowed_hosts))
991  {
992  orig_allowed_hosts = GNUNET_strdup ("127.0.0.1;");
993  }
994  if (NULL == uc->system->trusted_ip)
995  allowed_hosts = GNUNET_strdup (orig_allowed_hosts);
996  else
997  GNUNET_asprintf (&allowed_hosts,
998  "%s%s;",
999  orig_allowed_hosts,
1000  uc->system->trusted_ip);
1001  GNUNET_free (orig_allowed_hosts);
1003  section,
1004  ACCEPT_FROM_key,
1005  allowed_hosts);
1006  GNUNET_free (allowed_hosts);
1007 }
struct GNUNET_HashCode key
The key used in the DHT.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_have_value(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Test if we have a value for a particular option.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_malloc(size)
Wrapper around malloc.

References GNUNET_asprintf(), GNUNET_assert, GNUNET_break, GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONFIGURATION_have_value(), GNUNET_CONFIGURATION_set_value_string(), GNUNET_free, GNUNET_malloc, GNUNET_OK, GNUNET_strdup, GNUNET_YES, key, and uc.

Referenced by GNUNET_TESTING_configuration_create_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ associate_shared_service()

static struct SharedServiceInstance* associate_shared_service ( struct GNUNET_TESTING_System system,
struct SharedService ss,
struct GNUNET_CONFIGURATION_Handle cfg 
)
static

Definition at line 1011 of file testing.c.

1014 {
1015  struct SharedServiceInstance *i;
1016  struct GNUNET_CONFIGURATION_Handle *temp;
1017  char *gnunet_home;
1018  uint32_t port;
1019 
1020  ss->n_peers++;
1021  if (((0 == ss->share) && (NULL == ss->instances)) ||
1022  ((0 != ss->share) &&
1023  (ss->n_instances < ((ss->n_peers + ss->share - 1) / ss->share))))
1024  {
1025  i = GNUNET_new (struct SharedServiceInstance);
1026  i->ss = ss;
1027  (void) GNUNET_asprintf (&gnunet_home,
1028  "%s/shared/%s/%u",
1029  system->tmppath,
1030  ss->sname,
1031  ss->n_instances);
1032  (void) GNUNET_asprintf (&i->unix_sock, "%s/sock", gnunet_home);
1033  port = GNUNET_TESTING_reserve_port (system);
1034  if (0 == port)
1035  {
1036  GNUNET_free (gnunet_home);
1038  return NULL;
1039  }
1041  temp = GNUNET_CONFIGURATION_dup (ss->cfg);
1042  (void) GNUNET_asprintf (&i->port_str, "%u", port);
1043  (void) GNUNET_asprintf (&i->cfg_fn, "%s/config", gnunet_home);
1045  "PATHS",
1046  "GNUNET_HOME",
1047  gnunet_home);
1048  GNUNET_free (gnunet_home);
1050  ss->sname,
1051  "UNIXPATH",
1052  i->unix_sock);
1054  ss->sname,
1055  "PORT",
1056  i->port_str);
1058  {
1061  return NULL;
1062  }
1064  }
1065  else
1066  {
1067  GNUNET_assert (NULL != ss->instances);
1068  GNUNET_assert (0 < ss->n_instances);
1069  i = ss->instances[ss->n_instances - 1];
1070  }
1072  ss->sname,
1074  cfg);
1076  ss->sname,
1077  "UNIXPATH",
1078  i->unix_sock);
1080  return i;
1081 }
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
static uint16_t port
Port number.
Definition: gnunet-bcd.c:147
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_write(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Write configuration file.
void GNUNET_CONFIGURATION_iterate_section_values(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, GNUNET_CONFIGURATION_Iterator iter, void *iter_cls)
Iterate over values of a section in the configuration.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_dup(const struct GNUNET_CONFIGURATION_Handle *cfg)
Duplicate an existing configuration object.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
char * tmppath
Prefix (e.g.
Definition: testing.c:127
unsigned int share
Definition: testing.c:111
struct GNUNET_CONFIGURATION_Handle * cfg
Definition: testing.c:107
unsigned int n_instances
Definition: testing.c:113
struct SharedServiceInstance ** instances
Definition: testing.c:105
unsigned int n_peers
Definition: testing.c:109
static void cleanup_shared_service_instance(struct SharedServiceInstance *i)
Definition: testing.c:493
static void cfg_copy_iterator(void *cls, const char *section, const char *option, const char *value)
Function to iterate over options.
Definition: testing.c:359

References cfg, SharedService::cfg, cfg_copy_iterator(), SharedServiceInstance::cfg_fn, cleanup_shared_service_instance(), GNUNET_array_append, GNUNET_asprintf(), GNUNET_assert, GNUNET_CONFIGURATION_destroy(), GNUNET_CONFIGURATION_dup(), GNUNET_CONFIGURATION_iterate_section_values(), GNUNET_CONFIGURATION_set_value_string(), GNUNET_CONFIGURATION_write(), GNUNET_free, GNUNET_new, GNUNET_SYSERR, GNUNET_TESTING_reserve_port(), SharedService::instances, SharedService::n_instances, SharedService::n_peers, port, SharedServiceInstance::port_str, SharedService::share, SharedService::sname, SharedServiceInstance::ss, GNUNET_TESTING_System::tmppath, and SharedServiceInstance::unix_sock.

Referenced by GNUNET_TESTING_peer_configure().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_configuration_create_()

static int GNUNET_TESTING_configuration_create_ ( struct GNUNET_TESTING_System system,
struct GNUNET_CONFIGURATION_Handle cfg,
uint16_t **  ports,
unsigned int *  nports 
)
static

Create a new configuration using the given configuration as a template; ports and paths will be modified to select available ports on the local system.

The default configuration will be available in PATHS section under the option DEFAULTCONFIG after the call. GNUNET_HOME is also set in PATHS section to the temporary directory specific to this configuration. If we run out of "*port" numbers, return GNUNET_SYSERR.

This is primarily a helper function used internally by 'GNUNET_TESTING_peer_configure'.

Parameters
systemsystem to use to coordinate resource usage
cfgtemplate configuration to update
portsarray with port numbers used in the created configuration. Will be updated upon successful return. Can be NULL
nportsthe size of the ‘ports’ array. Will be updated.
Returns
GNUNET_OK on success, GNUNET_SYSERR on error - the configuration will be incomplete and should not be used there upon

Definition at line 1104 of file testing.c.

1108 {
1109  struct UpdateContext uc;
1110  char *default_config;
1111 
1112  uc.system = system;
1113  uc.cfg = cfg;
1114  uc.status = GNUNET_OK;
1115  uc.ports = NULL;
1116  uc.nports = 0;
1117  GNUNET_asprintf (&uc.gnunet_home,
1118  "%s/%u",
1119  system->tmppath,
1120  system->path_counter++);
1121  GNUNET_asprintf (&default_config, "%s/config", uc.gnunet_home);
1123  "PATHS",
1124  "DEFAULTCONFIG",
1125  default_config);
1126  GNUNET_CONFIGURATION_set_value_string (cfg, "arm", "CONFIG", default_config);
1127  GNUNET_free (default_config);
1129  "PATHS",
1130  "GNUNET_HOME",
1131  uc.gnunet_home);
1132  /* make PORTs and UNIXPATHs unique */
1134  /* allow connections to services from system trusted_ip host */
1136  /* enable loopback-based connections between peers */
1137  GNUNET_CONFIGURATION_set_value_string (cfg, "nat", "USE_LOCALADDR", "YES");
1138  GNUNET_free (uc.gnunet_home);
1139  if ((NULL != ports) && (NULL != nports))
1140  {
1141  *ports = uc.ports;
1142  *nports = uc.nports;
1143  }
1144  else
1145  GNUNET_free (uc.ports);
1146  return uc.status;
1147 }
void GNUNET_CONFIGURATION_iterate_sections(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CONFIGURATION_SectionIterator iter, void *iter_cls)
Iterate over all sections in the configuration.
void GNUNET_CONFIGURATION_iterate(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CONFIGURATION_Iterator iter, void *iter_cls)
Iterate over all options in the configuration.
uint32_t path_counter
Counter we use to make service home paths unique on this system; the full path consists of the tmppat...
Definition: testing.c:172
uint16_t * ports
Array of ports currently allocated to this peer.
Definition: testing.c:783
struct GNUNET_TESTING_System * system
The system for which we are building configurations.
Definition: testing.c:766
unsigned int nports
The number of ports in the above array.
Definition: testing.c:788
static void update_config(void *cls, const char *section, const char *option, const char *value)
Function to iterate over options.
Definition: testing.c:808
static void update_config_sections(void *cls, const char *section)
Section iterator to set ACCEPT_FROM/ACCEPT_FROM6 to include the address of 'trusted_hosts' in all sec...
Definition: testing.c:905

References cfg, GNUNET_asprintf(), GNUNET_CONFIGURATION_iterate(), GNUNET_CONFIGURATION_iterate_sections(), GNUNET_CONFIGURATION_set_value_string(), GNUNET_free, GNUNET_OK, UpdateContext::nports, GNUNET_TESTING_System::path_counter, UpdateContext::ports, UpdateContext::system, GNUNET_TESTING_System::tmppath, uc, update_config(), and update_config_sections().

Referenced by GNUNET_TESTING_configuration_create(), and GNUNET_TESTING_peer_configure().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ disconn_status()

static void disconn_status ( void *  cls,
int  connected 
)
static

Function called whenever we connect to or disconnect from ARM.

Parameters
clsclosure
connectedGNUNET_YES if connected, GNUNET_NO if disconnected, GNUNET_SYSERR on error.

Definition at line 1503 of file testing.c.

1504 {
1505  struct GNUNET_TESTING_Peer *peer = cls;
1506 
1507  if (GNUNET_SYSERR == connected)
1508  {
1509  peer->cb (peer->cb_cls, peer, connected);
1510  return;
1511  }
1512  if (GNUNET_YES == connected)
1513  {
1515  return;
1516  }
1519  peer->ah = NULL;
1520  peer->cb (peer->cb_cls, peer, GNUNET_YES);
1521 }
void GNUNET_ARM_disconnect(struct GNUNET_ARM_Handle *h)
Disconnect from the ARM service (if connected) and destroy the context.
Definition: arm_api.c:602
int GNUNET_TESTING_peer_kill(struct GNUNET_TESTING_Peer *peer)
Sends SIGTERM to the peer's main process.
Definition: testing.c:1430
int GNUNET_TESTING_peer_wait(struct GNUNET_TESTING_Peer *peer)
Waits for a peer to terminate.
Definition: testing.c:1462
Handle for a GNUnet peer controlled by testing.
Definition: testing.c:195
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.

References GNUNET_ARM_disconnect(), GNUNET_break, GNUNET_OK, GNUNET_SYSERR, GNUNET_TESTING_peer_kill(), GNUNET_TESTING_peer_wait(), GNUNET_YES, and peer.

Referenced by GNUNET_TESTING_peer_stop_async().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ service_run_main()

static void service_run_main ( void *  cls)
static

Callback to be called when SCHEDULER has been started.

Parameters
clsthe ServiceContext

Definition at line 1634 of file testing.c.

1635 {
1636  struct ServiceContext *sc = cls;
1637 
1638  sc->tm (sc->tm_cls, sc->cfg, sc->peer);
1639 }
static struct GNUNET_FS_SearchContext * sc
Definition: gnunet-search.c:87
Structure for holding service data.
Definition: testing.c:1605

References sc.

Referenced by GNUNET_TESTING_service_run().

Here is the caller graph for this function:

◆ get_first_value()

static unsigned int get_first_value ( const char *  line)
static

Every line in the topology configuration starts with a string indicating which kind of information will be configured with this line.

Configuration values following this string are seperated by special sequences of characters. An integer value seperated by ':' is returned by this function.

Parameters
lineThe line of configuration.
Returns
An integer value.

Definition at line 1734 of file testing.c.

1735 {
1736  char *copy;
1737  size_t slen;
1738  char *token;
1739  unsigned int ret;
1740  char *rest = NULL;
1741 
1742  slen = strlen (line) + 1;
1743  copy = GNUNET_malloc (slen);
1744  memcpy (copy, line, slen);
1745  token = strtok_r (copy, ":", &rest);
1746  token = strtok_r (NULL, ":", &rest);
1747  GNUNET_assert (1 == sscanf (token, "%u", &ret));
1748  GNUNET_free (copy);
1749  return ret;
1750 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static char * line
Desired phone line (string to be converted to a hash).

References GNUNET_assert, GNUNET_free, GNUNET_malloc, line, and ret.

Referenced by GNUNET_TESTING_get_topo_from_string().

Here is the caller graph for this function:

◆ get_key()

static char* get_key ( const char *  line)
static

Every line in the topology configuration starts with a string indicating which kind of information will be configured with this line.

This string is returned by this function.

Parameters
lineThe line of configuration.
Returns
The leading string of this configuration line.

Definition at line 1761 of file testing.c.

1762 {
1763  char *copy;
1764  size_t slen;
1765  size_t tlen;
1766  char *token;
1767  char *ret;
1768  char *rest = NULL;
1769 
1770  slen = strlen (line) + 1;
1771  copy = GNUNET_malloc (slen);
1772  memcpy (copy, line, slen);
1773  token = strtok_r (copy, ":", &rest);
1774  tlen = strlen (token) + 1;
1775  ret = GNUNET_malloc (tlen);
1776  memcpy (ret, token, tlen);
1777  GNUNET_free (copy);
1778  return ret;
1779 }

References GNUNET_free, GNUNET_malloc, line, and ret.

Referenced by GNUNET_TESTING_get_topo_from_string(), and reconnect().

Here is the caller graph for this function:

◆ get_first_string_value()

static char* get_first_string_value ( const char *  line)
static

Every line in the topology configuration starts with a string indicating which kind of information will be configured with this line.

Configuration values following this string are seperated by special sequences of characters. A string value seperated by ':' is returned by this function.

Parameters
lineThe line of configuration.
Returns
A string value.

Definition at line 1792 of file testing.c.

1793 {
1794  char *copy;
1795  size_t slen, slen_token;
1796  char *token;
1797  char *ret;
1798  char *rest = NULL;
1799 
1800  slen = strlen (line) + 1;
1801  copy = GNUNET_malloc (slen);
1802  memcpy (copy, line, slen);
1803  token = strtok_r (copy, ":", &rest);
1804  token = strtok_r (NULL, ":", &rest);
1806  "first token %s\n",
1807  token);
1808  slen_token = strlen (token);
1809  ret = GNUNET_malloc (slen_token + 1);
1810  memcpy (ret, token, slen_token + 1);
1811  GNUNET_free (copy);
1812  return ret;
1813 }
@ GNUNET_ERROR_TYPE_DEBUG

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_malloc, line, LOG, and ret.

Referenced by GNUNET_TESTING_get_topo_from_string().

Here is the caller graph for this function:

◆ get_second_value()

static unsigned int get_second_value ( const char *  line)
static

Every line in the topology configuration starts with a string indicating which kind of information will be configured with this line.

Configuration values following this string are seperated by special sequences of characters. A second integer value seperated by ':' from a first value is returned by this function.

Parameters
lineThe line of configuration.
Returns
An integer value.

Definition at line 1826 of file testing.c.

1827 {
1828  char *copy;
1829  char *token;
1830  unsigned int ret;
1831  char *rest = NULL;
1832 
1833  copy = GNUNET_strdup (line);
1834  token = strtok_r (copy, ":", &rest);
1835  token = strtok_r (NULL, ":", &rest);
1836  token = strtok_r (NULL, ":", &rest);
1838  "Format error in configuration line: %s\n",
1839  line);
1840  GNUNET_assert (1 == sscanf (token, "%u", &ret));
1841  GNUNET_free (copy);
1842  return ret;
1843 }

References GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_strdup, line, LOG, and ret.

Referenced by GNUNET_TESTING_get_topo_from_string().

Here is the caller graph for this function:

◆ get_value()

static char* get_value ( const char *  key,
const char *  line 
)
static

Every line in the topology configuration starts with a string indicating which kind of information will be configured with this line.

Configuration values following this string are seperated by special sequences of characters. A value might be a key value pair. This function returns the value for a specific key in a configuration line.

Parameters
keyThe key of the key value pair.
Returns
The value of the key value pair.

Definition at line 1857 of file testing.c.

1858 {
1859  char copy[strlen (line) + 1];
1860  size_t slen;
1861  char *token;
1862  char *token2;
1863  char *temp;
1864  char *rest = NULL;
1865 
1866  slen = strlen (line) + 1;
1867  memcpy (copy, line, slen);
1868  temp = strstr (copy, key);
1869  if (NULL == temp)
1870  return NULL;
1871  token = strtok_r (temp, ":", &rest);
1872  if (NULL == token)
1873  return NULL;
1874  token = strtok_r (NULL, ":", &rest);
1875  if (NULL == token)
1876  return NULL;
1877  token2 = strtok_r (token, "}", &rest);
1878  if (NULL == token2)
1879  return NULL;
1880  return GNUNET_strdup (token2);
1881 }

References GNUNET_strdup, key, and line.

Referenced by GNUNET_TESTING_get_topo_from_string(), and parse_ac().

Here is the caller graph for this function:

◆ get_connect_value()

static struct GNUNET_TESTING_NodeConnection* get_connect_value ( const char *  line,
struct GNUNET_TESTING_NetjailNode node 
)
static

Every line in the topology configuration starts with a string indicating which kind of information will be configured with this line.

Configuration values following this string are seperated by special sequences of characters. A value might be a key value pair. A special key is the 'connect' key which can appear more than once. The value is the information about a connection via some protocol to some other node. This function returns the struct GNUNET_TESTING_NodeConnection which holds the information of the connect value.

Parameters
valueThe value of the connect key value pair.
Returns
The struct GNUNET_TESTING_NodeConnection.

Definition at line 1897 of file testing.c.

1899 {
1900  struct GNUNET_TESTING_NodeConnection *node_connection;
1901  char *copy;
1902  char *token;
1903  char *token2;
1904  unsigned int node_n;
1905  unsigned int namespace_n;
1906  char *rest = NULL;
1907  char *rest2 = NULL;
1909  unsigned int sscanf_ret;
1910 
1911  node_connection = GNUNET_new (struct GNUNET_TESTING_NodeConnection);
1912  node_connection->node = node;
1913 
1914  copy = GNUNET_strdup (line);
1915  token = strtok_r (copy, ":", &rest);
1916  if (0 == strcmp ("{K", token))
1917  {
1918  node_connection->node_type = GNUNET_TESTING_GLOBAL_NODE;
1919  token = strtok_r (NULL, ":", &rest);
1920  GNUNET_assert (1 == sscanf (token, "%u", &node_n));
1922  "node_n %u\n",
1923  node_n);
1924  node_connection->node_n = node_n;
1925  node_connection->namespace_n = 0;
1926  }
1927  else if (0 == strcmp ("{P", token))
1928  {
1929  node_connection->node_type = GNUNET_TESTING_SUBNET_NODE;
1930  token = strtok_r (NULL, ":", &rest);
1931  errno = 0;
1932  sscanf_ret = sscanf (token, "%u", &namespace_n);
1933  if (errno != 0)
1934  {
1936  }
1937  GNUNET_assert (0 < sscanf_ret);
1938  node_connection->namespace_n = namespace_n;
1939  token = strtok_r (NULL, ":", &rest);
1940  errno = 0;
1941  sscanf_ret = sscanf (token, "%u", &node_n);
1942  if (errno != 0)
1943  {
1945  }
1946  GNUNET_assert (0 < sscanf_ret);
1947  node_connection->node_n = node_n;
1949  "node_n %u namespace_n %u node->node_n %u node->namespace_n %u\n",
1950  node_n,
1951  namespace_n,
1952  node->node_n,
1953  node->namespace_n);
1954  }
1955  else
1956  {
1957  GNUNET_break (0);
1958  GNUNET_free (node_connection);
1959  GNUNET_free (copy);
1960  return NULL;
1961  }
1962 
1963  while (NULL != (token = strtok_r (NULL, ":", &rest)))
1964  {
1966  token2 = strtok_r (token, "}", &rest2);
1967  if (NULL != token2)
1968  prefix->address_prefix = GNUNET_strdup (token2);
1969  else
1970  prefix->address_prefix = GNUNET_strdup (token);
1971 
1973  "address_prefix %s\n",
1974  prefix->address_prefix);
1975 
1977  node_connection->address_prefixes_tail,
1978  prefix);
1980  "address_prefix %s\n",
1981  prefix->address_prefix);
1982  }
1983 
1984  GNUNET_free (copy);
1985  return node_connection;
1986 }
static int prefix
If printing the value of PREFIX has been requested.
Definition: gnunet-config.c:59
@ GNUNET_TESTING_SUBNET_NODE
Node in a subnet.
@ GNUNET_TESTING_GLOBAL_NODE
Global known node.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
Protocol address prefix für a connection between nodes.
unsigned int namespace_n
The number of the subnet this node is running in.
unsigned int node_n
The number of this node in the subnet.
struct GNUNET_TESTING_AddressPrefix * address_prefixes_tail
Tail of the DLL with the address prefixes for the protocolls this node is reachable.
unsigned int node_n
The number of the node this connection points to.
struct GNUNET_TESTING_NetjailNode * node
The node which establish the connection.
unsigned int namespace_n
The number of the subnet of the node this connection points to.
struct GNUNET_TESTING_AddressPrefix * address_prefixes_head
Head of the DLL with the address prefixes for the protocolls this node is reachable.
enum GNUNET_TESTING_NodeType node_type
The type of the node this connection points to.

References GNUNET_TESTING_NodeConnection::address_prefixes_head, GNUNET_TESTING_NodeConnection::address_prefixes_tail, GNUNET_assert, GNUNET_break, GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log_strerror, GNUNET_new, GNUNET_strdup, GNUNET_TESTING_GLOBAL_NODE, GNUNET_TESTING_SUBNET_NODE, line, LOG, GNUNET_TESTING_NodeConnection::namespace_n, GNUNET_TESTING_NetjailNode::namespace_n, GNUNET_TESTING_NodeConnection::node, GNUNET_TESTING_NodeConnection::node_n, GNUNET_TESTING_NetjailNode::node_n, GNUNET_TESTING_NodeConnection::node_type, and prefix.

Referenced by node_connections().

Here is the caller graph for this function:

◆ node_connections()

static void node_connections ( const char *  line,
struct GNUNET_TESTING_NetjailNode node 
)
static

Every line in the topology configuration starts with a string indicating which kind of information will be configured with this line.

Configuration values following this string are seperated by special sequences of characters. A value might be a key value pair. A special key is the 'connect' key. The value is the information about a connections via some protocol to other nodes. Each connection itself is a key value pair separated by the character '|' and surrounded by the characters '{' and '}'. The struct GNUNET_TESTING_NodeConnection holds the information of each connection value. This function extracts the values of each connection into a DLL of struct GNUNET_TESTING_NodeConnection which will be added to a node.

Parameters
lineThe line of configuration.
nodeThe struct GNUNET_TESTING_NetjailNode to which the DLL of struct GNUNET_TESTING_NodeConnection will be added.

Definition at line 2006 of file testing.c.

2007 {
2008  char *value, *value2;
2009  char *temp;
2010  char *copy;
2011  char *rest = NULL;
2012  char *rest2 = NULL;
2013  struct GNUNET_TESTING_NodeConnection *node_connection;
2014 
2015 
2016  temp = strstr (line, "connect");
2017  if (NULL != temp)
2018  {
2019  copy = GNUNET_strdup (temp);
2020  strtok_r (copy, ":", &rest);
2021  value = strtok_r (rest, "|", &rest2);
2022 
2023  while (NULL != value)
2024  {
2026  "node_connections value %s\n",
2027  value);
2028  node_connection = get_connect_value (value, node);
2029  if (NULL == node_connection)
2030  {
2032  "connect key was not expected in this configuration line: %s\n",
2033  line);
2034  break;
2035  }
2038  node_connection);
2039  value2 = strstr (value, "}}");
2040  if (NULL != value2)
2041  break;
2042  value = strtok_r (NULL, "|", &rest2);
2043 
2044  }
2045  GNUNET_free (copy);
2046  }
2047 }
struct GNUNET_TESTING_NodeConnection * node_connections_head
Head of the DLL with the connections which shall be established to other nodes.
struct GNUNET_TESTING_NodeConnection * node_connections_tail
Tail of the DLL with the connections which shall be established to other nodes.
static struct GNUNET_TESTING_NodeConnection * get_connect_value(const char *line, struct GNUNET_TESTING_NetjailNode *node)
Every line in the topology configuration starts with a string indicating which kind of information wi...
Definition: testing.c:1897

References get_connect_value(), GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_strdup, line, LOG, GNUNET_TESTING_NodeConnection::node, GNUNET_TESTING_NetjailNode::node_connections_head, GNUNET_TESTING_NetjailNode::node_connections_tail, and value.

Referenced by get_node_info(), GNUNET_TESTING_get_additional_connects(), GNUNET_TESTING_get_connections(), GNUNET_TESTING_get_node(), and GNUNET_TESTING_get_topo_from_string().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ log_nodes()

static int log_nodes ( void *  cls,
const struct GNUNET_ShortHashCode id,
void *  value 
)
static

A helper function to log information about individual nodes.

Parameters
clsThis is not used actually.
idThe key of this value in the map.
valueA struct GNUNET_TESTING_NetjailNode which holds information about a node. return GNUNET_YES to continue with iterating, GNUNET_NO otherwise.

Definition at line 2059 of file testing.c.

2060 {
2061  struct GNUNET_TESTING_NetjailNode *node = value;
2062  struct GNUNET_TESTING_NodeConnection *pos_connection;
2063  struct GNUNET_TESTING_AddressPrefix *pos_prefix;
2064 
2066  "plugin: %s space: %u node: %u global: %u\n",
2067  node->plugin,
2068  node->namespace_n,
2069  node->node_n,
2070  node->is_global);
2071 
2072  for (pos_connection = node->node_connections_head; NULL != pos_connection;
2073  pos_connection = pos_connection->next)
2074  {
2075 
2077  "namespace_n: %u node_n: %u node_type: %u\n",
2078  pos_connection->namespace_n,
2079  pos_connection->node_n,
2080  pos_connection->node_type);
2081 
2082  for (pos_prefix = pos_connection->address_prefixes_head; NULL != pos_prefix;
2083  pos_prefix =
2084  pos_prefix->next)
2085  {
2087  "prefix: %s\n",
2088  pos_prefix->address_prefix);
2089  }
2090  }
2091  return GNUNET_YES;
2092 }
struct GNUNET_TESTING_AddressPrefix * next
Pointer to the next prefix in the DLL.
char * address_prefix
The address prefix.
Node in the netjail topology.
unsigned int is_global
Flag indicating if this node is a global known node.
char * plugin
Plugin for the test case to be run on this node.
struct GNUNET_TESTING_NodeConnection * next
Pointer to the next connection in the DLL.

References GNUNET_TESTING_AddressPrefix::address_prefix, GNUNET_TESTING_NodeConnection::address_prefixes_head, GNUNET_ERROR_TYPE_DEBUG, GNUNET_YES, GNUNET_TESTING_NetjailNode::is_global, LOG, GNUNET_TESTING_NodeConnection::namespace_n, GNUNET_TESTING_NetjailNode::namespace_n, GNUNET_TESTING_AddressPrefix::next, GNUNET_TESTING_NodeConnection::next, GNUNET_TESTING_NetjailNode::node_connections_head, GNUNET_TESTING_NodeConnection::node_n, GNUNET_TESTING_NetjailNode::node_n, GNUNET_TESTING_NodeConnection::node_type, GNUNET_TESTING_NetjailNode::plugin, and value.

Referenced by log_namespaces(), and log_topo().

Here is the caller graph for this function:

◆ log_namespaces()

static int log_namespaces ( void *  cls,
const struct GNUNET_ShortHashCode id,
void *  value 
)
static

Helper function to log information about namespaces.

Parameters
clsThis is not used actually.
idThe key of this value in the map.
valueA struct GNUNET_TESTING_NetjailNamespace which holds information about a subnet. return GNUNET_YES to continue with iterating, GNUNET_NO otherwise.

Definition at line 2104 of file testing.c.

2105 {
2106  struct GNUNET_TESTING_NetjailNamespace *namespace = value;
2107 
2108  GNUNET_CONTAINER_multishortmap_iterate (namespace->nodes, &log_nodes, NULL);
2109  return GNUNET_YES;
2110 }
int GNUNET_CONTAINER_multishortmap_iterate(struct GNUNET_CONTAINER_MultiShortmap *map, GNUNET_CONTAINER_ShortmapIterator it, void *it_cls)
Iterate over all entries in the map.
static int log_nodes(void *cls, const struct GNUNET_ShortHashCode *id, void *value)
A helper function to log information about individual nodes.
Definition: testing.c:2059

References GNUNET_CONTAINER_multishortmap_iterate(), GNUNET_YES, log_nodes(), and value.

Referenced by log_topo().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ log_topo()

static int log_topo ( const struct GNUNET_TESTING_NetjailTopology topology)
static

Helper function to log the configuration in case of a problem with configuration.

Parameters
topologyThe struct GNUNET_TESTING_NetjailTopology holding the configuration information.

Definition at line 2119 of file testing.c.

2120 {
2122  "plugin: %s spaces: %u nodes: %u known: %u\n",
2123  topology->plugin,
2124  topology->namespaces_n,
2125  topology->nodes_m,
2126  topology->nodes_x);
2127 
2129  log_namespaces, NULL);
2131  NULL);
2132  return GNUNET_YES;
2133 }
enum GNUNET_TESTBED_TopologyOption topology
The topology to generate.
static int log_namespaces(void *cls, const struct GNUNET_ShortHashCode *id, void *value)
Helper function to log information about namespaces.
Definition: testing.c:2104

References GNUNET_CONTAINER_multishortmap_iterate(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_YES, LOG, log_namespaces(), log_nodes(), and topology.

Referenced by get_node_info().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_node_info()

static void get_node_info ( unsigned int  num,
const struct GNUNET_TESTING_NetjailTopology topology,
struct GNUNET_TESTING_NetjailNode **  node_ex,
struct GNUNET_TESTING_NetjailNamespace **  namespace_ex,
struct GNUNET_TESTING_NodeConnection **  node_connections_ex 
)
static

This function extracts information about a specific node from the topology.

Parameters
numThe global index number of the node.
[out]node_exA struct GNUNET_TESTING_NetjailNode with information about the node.
[out]namespace_exA struct GNUNET_TESTING_NetjailNamespace with information about the namespace the node is in or NULL, if the node is a global node.
[out]node_connections_exA struct GNUNET_TESTING_NodeConnection with information about the connection of this node to other nodes.

Definition at line 2147 of file testing.c.

2152 {
2153  struct GNUNET_ShortHashCode hkey;
2154  struct GNUNET_HashCode hc;
2155  unsigned int namespace_n;
2156  unsigned int node_m;
2157  struct GNUNET_TESTING_NetjailNode *node;
2158  struct GNUNET_TESTING_NetjailNamespace *namespace;
2160 
2161  log_topo (topology);
2163  "num: %u \n",
2164  num);
2165  if (topology->nodes_x >= num)
2166  {
2167 
2168  GNUNET_CRYPTO_hash (&num, sizeof(num), &hc);
2169  memcpy (&hkey,
2170  &hc,
2171  sizeof (hkey));
2173  &hkey);
2174  if (NULL != node)
2175  {
2176  *node_ex = node;
2177  *node_connections_ex = node->node_connections_head;
2178  }
2179  }
2180  else
2181  {
2182  namespace_n = (unsigned int) ceil ((double) (num - topology->nodes_x)
2183  / topology->nodes_m);
2185  "ceil num: %u nodes_x: %u nodes_m: %u namespace_n: %u\n",
2186  num,
2187  topology->nodes_x,
2188  topology->nodes_m,
2189  namespace_n);
2190  GNUNET_CRYPTO_hash (&namespace_n, sizeof(namespace_n), &hc);
2191  memcpy (&hkey,
2192  &hc,
2193  sizeof (hkey));
2194  namespace = GNUNET_CONTAINER_multishortmap_get (topology->map_namespaces,
2195  &hkey);
2196  if (NULL != namespace)
2197  {
2198  node_m = num - topology->nodes_x - topology->nodes_m * (namespace_n - 1);
2199  GNUNET_CRYPTO_hash (&node_m, sizeof(node_m), &hc);
2200  memcpy (&hkey,
2201  &hc,
2202  sizeof (hkey));
2203  node = GNUNET_CONTAINER_multishortmap_get (namespace->nodes,
2204  &hkey);
2205  if (NULL != node)
2206  {
2208  "node additional_connects: %u %p\n",
2209  node->additional_connects,
2210  node);
2212  }
2213  *node_ex = node;
2214  *namespace_ex = namespace;
2215  *node_connections_ex = node_connections;
2216  }
2217  }
2218 }
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:41
void * GNUNET_CONTAINER_multishortmap_get(const struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key)
Given a key find a value in the map matching the key.
A 512-bit hashcode.
A 256-bit hashcode.
unsigned int additional_connects
The number of unintentional additional connections this node waits for.
static void node_connections(const char *line, struct GNUNET_TESTING_NetjailNode *node)
Every line in the topology configuration starts with a string indicating which kind of information wi...
Definition: testing.c:2006
static int log_topo(const struct GNUNET_TESTING_NetjailTopology *topology)
Helper function to log the configuration in case of a problem with configuration.
Definition: testing.c:2119

References GNUNET_TESTING_NetjailNode::additional_connects, GNUNET_CONTAINER_multishortmap_get(), GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_DEBUG, consensus-simulation::int, LOG, log_topo(), GNUNET_TESTING_NodeConnection::namespace_n, GNUNET_TESTING_NodeConnection::node, node_connections(), GNUNET_TESTING_NetjailNode::node_connections_head, and topology.

Referenced by GNUNET_TESTING_get_additional_connects(), GNUNET_TESTING_get_connections(), and GNUNET_TESTING_get_node().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_get_node()

struct GNUNET_TESTING_NetjailNode* GNUNET_TESTING_get_node ( unsigned int  num,
struct GNUNET_TESTING_NetjailTopology topology 
)

Get a node from the topology.

Parameters
numThe specific node we want the connections for.
topologyThe topology we get the connections from.
Returns
The connections of the node.

Definition at line 2229 of file testing.c.

2231 {
2232  struct GNUNET_TESTING_NetjailNode *node;
2233  struct GNUNET_TESTING_NetjailNamespace *namespace;
2235 
2236  get_node_info (num, topology, &node, &namespace, &node_connections);
2237 
2238  return node;
2239 
2240 }
static void get_node_info(unsigned int num, const struct GNUNET_TESTING_NetjailTopology *topology, struct GNUNET_TESTING_NetjailNode **node_ex, struct GNUNET_TESTING_NetjailNamespace **namespace_ex, struct GNUNET_TESTING_NodeConnection **node_connections_ex)
This function extracts information about a specific node from the topology.
Definition: testing.c:2147

References get_node_info(), GNUNET_TESTING_NodeConnection::node, node_connections(), and topology.

Here is the call graph for this function:

◆ GNUNET_TESTING_get_connections()

struct GNUNET_TESTING_NodeConnection* GNUNET_TESTING_get_connections ( unsigned int  num,
const struct GNUNET_TESTING_NetjailTopology topology 
)

Get the connections to other nodes for a specific node.

Parameters
numThe specific node we want the connections for.
topologyThe topology we get the connections from.
Returns
The connections of the node.

Definition at line 2251 of file testing.c.

2254 {
2255  struct GNUNET_TESTING_NetjailNode *node;
2256  struct GNUNET_TESTING_NetjailNamespace *namespace;
2258 
2260  "get_connections\n");
2261 
2262  get_node_info (num, topology, &node, &namespace, &node_connections);
2263 
2264  return node_connections;
2265 }

References get_node_info(), GNUNET_ERROR_TYPE_DEBUG, LOG, GNUNET_TESTING_NodeConnection::node, node_connections(), and topology.

Referenced by backchannel_check_run(), and connect_peers_run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_get_peer()

struct GNUNET_PeerIdentity* GNUNET_TESTING_get_peer ( unsigned int  num,
const struct GNUNET_TESTING_System tl_system 
)

Retrieve the peer identity from the test system with the unique node id.

Retrieve peer identity from the test system with the unique node id.

Parameters
numThe unique node id.
tl_systemThe test system.
Returns
The peer identity wrapping the public key.

Definition at line 2276 of file testing.c.

2278 {
2280  struct GNUNET_CRYPTO_EddsaPrivateKey *priv_key;
2281 
2282  priv_key = GNUNET_TESTING_hostkey_get (tl_system,
2283  num,
2284  peer);
2285 
2287  &peer->public_key);
2288  GNUNET_free (priv_key);
2289  return peer;
2290 }
void GNUNET_CRYPTO_eddsa_key_get_public(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Extract the public key for the given private key.
Definition: crypto_ecc.c:198
struct GNUNET_CRYPTO_EddsaPrivateKey * GNUNET_TESTING_hostkey_get(const struct GNUNET_TESTING_System *system, uint32_t key_number, struct GNUNET_PeerIdentity *id)
Testing includes a number of pre-created hostkeys for faster peer startup.
Definition: testing.c:732
Private ECC key encoded for transmission.
The identity of the host (wraps the signing key of the peer).

References GNUNET_CRYPTO_eddsa_key_get_public(), GNUNET_free, GNUNET_new, GNUNET_TESTING_hostkey_get(), and peer.

Referenced by add_search_string(), connect_peers_run(), and notify_connect().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ free_nodes_cb()

int free_nodes_cb ( void *  cls,
const struct GNUNET_ShortHashCode key,
void *  value 
)

Definition at line 2294 of file testing.c.

2297 {
2298  (void) cls;
2299  struct GNUNET_TESTING_NetjailNode *node = value;
2300  struct GNUNET_TESTING_NodeConnection *pos_connection;
2301  struct GNUNET_TESTING_AddressPrefix *pos_prefix;
2302 
2303  while (NULL != (pos_connection = node->node_connections_head))
2304  {
2305  while (NULL != (pos_prefix = pos_connection->address_prefixes_head))
2306  {
2308  pos_connection->address_prefixes_tail,
2309  pos_prefix);
2310  GNUNET_free (pos_prefix->address_prefix);
2311  GNUNET_free (pos_prefix);
2312  }
2314  node->node_connections_tail,
2315  pos_connection);
2316  GNUNET_free (pos_connection);
2317  }
2318 
2319  GNUNET_free (node->plugin);
2320  GNUNET_free (node);
2321  return GNUNET_OK;
2322 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.

References GNUNET_TESTING_AddressPrefix::address_prefix, GNUNET_TESTING_NodeConnection::address_prefixes_head, GNUNET_TESTING_NodeConnection::address_prefixes_tail, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_OK, GNUNET_TESTING_NetjailNode::node_connections_head, GNUNET_TESTING_NetjailNode::node_connections_tail, GNUNET_TESTING_NetjailNode::plugin, and value.

Referenced by free_namespaces_cb(), and GNUNET_TESTING_free_topology().

Here is the caller graph for this function:

◆ free_namespaces_cb()

int free_namespaces_cb ( void *  cls,
const struct GNUNET_ShortHashCode key,
void *  value 
)

Definition at line 2326 of file testing.c.

2329 {
2330  (void) cls;
2331  struct GNUNET_TESTING_NetjailNamespace *namespace = value;
2332 
2333  GNUNET_free (namespace->router);
2335  namespace->nodes);
2336  return GNUNET_OK;
2337 
2338 }
int free_nodes_cb(void *cls, const struct GNUNET_ShortHashCode *key, void *value)
Definition: testing.c:2294

References free_nodes_cb(), GNUNET_CONTAINER_multishortmap_iterate(), GNUNET_free, GNUNET_OK, and value.

Referenced by GNUNET_TESTING_free_topology().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_free_topology()

void GNUNET_TESTING_free_topology ( struct GNUNET_TESTING_NetjailTopology topology)

Deallocate memory of the struct GNUNET_TESTING_NetjailTopology.

Parameters
topologyThe GNUNET_TESTING_NetjailTopology to be deallocated.

Definition at line 2347 of file testing.c.

2348 {
2350  free_namespaces_cb, NULL);
2353  NULL);
2355  GNUNET_free (topology->plugin);
2357 }
void GNUNET_CONTAINER_multishortmap_destroy(struct GNUNET_CONTAINER_MultiShortmap *map)
Destroy a hash map.
int free_namespaces_cb(void *cls, const struct GNUNET_ShortHashCode *key, void *value)
Definition: testing.c:2326

References free_namespaces_cb(), free_nodes_cb(), GNUNET_CONTAINER_multishortmap_destroy(), GNUNET_CONTAINER_multishortmap_iterate(), GNUNET_free, and topology.

Here is the call graph for this function:

◆ GNUNET_TESTING_calculate_num()

unsigned int GNUNET_TESTING_calculate_num ( struct GNUNET_TESTING_NodeConnection node_connection,
struct GNUNET_TESTING_NetjailTopology topology 
)

Calculate the unique id identifying a node from a given connection.

Parameters
node_connectionThe connection we calculate the id from.
topologyThe topology we get all needed information from.
Returns
The unique id of the node from the connection.

Definition at line 2361 of file testing.c.

2364 {
2365  unsigned int n, m, num;
2366 
2367  n = node_connection->namespace_n;
2368  m = node_connection->node_n;
2369 
2370  if (0 == n)
2371  num = m;
2372  else
2373  num = (n - 1) * topology->nodes_m + m + topology->nodes_x;
2374 
2375  return num;
2376 }
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:104

References m, GNUNET_TESTING_NodeConnection::namespace_n, GNUNET_TESTING_NodeConnection::node_n, and topology.

Referenced by connect_peers_run(), and notify_connect().

Here is the caller graph for this function:

◆ GNUNET_TESTING_get_address()

char* GNUNET_TESTING_get_address ( struct GNUNET_TESTING_NodeConnection connection,
const char *  prefix 
)

Get the address for a specific communicator from a connection.

Parameters
connectionThe connection we like to have the address from.
prefixThe communicator protocol prefix.
Returns
The address of the communicator.

Definition at line 2387 of file testing.c.

2389 {
2390  struct GNUNET_TESTING_NetjailNode *node;
2391  char *addr;
2392  char *template;
2393  unsigned int node_n;
2394 
2396  "get address prefix: %s node_n: %u\n",
2397  prefix,
2398  connection->node_n);
2399 
2400  node = connection->node;
2401  if (connection->namespace_n == node->namespace_n)
2402  {
2403  template = CONNECT_ADDRESS_TEMPLATE;
2404  node_n = connection->node_n;
2405  }
2406  else if (0 == connection->namespace_n)
2407  {
2408  template = KNOWN_CONNECT_ADDRESS_TEMPLATE;
2409  node_n = connection->node_n;
2410  }
2411  else if (1 == connection->node_n)
2412  {
2414  node_n = connection->namespace_n;
2415  }
2416  else
2417  {
2418  return NULL;
2419  }
2420 
2421  if (0 == strcmp (PREFIX_TCP, prefix) ||
2422  0 == strcmp (PREFIX_UDP, prefix) ||
2423  0 == strcmp (PREFIX_UDP_NATTED, prefix) ||
2424  0 == strcmp (PREFIX_TCP_NATTED, prefix))
2425  {
2426  GNUNET_asprintf (&addr,
2427  template,
2428  prefix,
2429  node_n);
2430  }
2431  else
2432  {
2433  GNUNET_assert (0);
2434  }
2435 
2436  return addr;
2437 }
#define PREFIX_UDP_NATTED
Definition: testing.c:68
#define PREFIX_TCP
Definition: testing.c:62
#define PREFIX_TCP_NATTED
Definition: testing.c:66
#define CONNECT_ADDRESS_TEMPLATE
Definition: testing.c:44
#define PREFIX_UDP
Definition: testing.c:64
#define KNOWN_CONNECT_ADDRESS_TEMPLATE
Definition: testing.c:48
#define ROUTER_CONNECT_ADDRESS_TEMPLATE
Definition: testing.c:46

References CONNECT_ADDRESS_TEMPLATE, GNUNET_asprintf(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, KNOWN_CONNECT_ADDRESS_TEMPLATE, LOG, GNUNET_TESTING_NodeConnection::namespace_n, GNUNET_TESTING_NetjailNode::namespace_n, GNUNET_TESTING_NodeConnection::node, GNUNET_TESTING_NodeConnection::node_n, GNUNET_TESTING_NetjailNode::node_n, prefix, PREFIX_TCP, PREFIX_TCP_NATTED, PREFIX_UDP, PREFIX_UDP_NATTED, and ROUTER_CONNECT_ADDRESS_TEMPLATE.

Referenced by connect_peers_run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_get_additional_connects()

unsigned int GNUNET_TESTING_get_additional_connects ( unsigned int  num,
struct GNUNET_TESTING_NetjailTopology topology 
)

Get the number of unintentional additional connections the node waits for.

Parameters
numThe specific node we want the additional connects for.
Returns
The number of additional connects

Definition at line 2447 of file testing.c.

2450 {
2451  struct GNUNET_TESTING_NetjailNode *node;
2452  struct GNUNET_TESTING_NetjailNamespace *namespace;
2454 
2456  "get_additional_connects\n");
2457 
2458  get_node_info (num, topology, &node, &namespace, &node_connections);
2459 
2460  if (NULL == node)
2461  {
2463  "No info found for node %d\n", num);
2464  return 0;
2465  }
2467  "node additional_connects for node %p\n",
2468  node);
2470  "node additional_connects: %u\n",
2472 
2473  return node->additional_connects;
2474 }

References GNUNET_TESTING_NetjailNode::additional_connects, get_node_info(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, LOG, node_connections(), and topology.

Here is the call graph for this function:

◆ parse_ac()

static void parse_ac ( struct GNUNET_TESTING_NetjailNode p_node,
const char *  token 
)
static

Definition at line 2478 of file testing.c.

2479 {
2480  char *ac_value;
2481  int ret;
2482 
2483  ac_value = get_value ("AC", token);
2484  if (NULL != ac_value)
2485  {
2487  "ac value: %s\n",
2488  ac_value);
2489  errno = 0;
2490  ret = sscanf (ac_value, "%u", &p_node->additional_connects);
2491  if (errno != 0)
2492  {
2494  }
2495  GNUNET_assert (0 < ret);
2497  "AC %u\n",
2498  p_node->additional_connects);
2499  }
2500  else
2501  {
2502  p_node->additional_connects = 0;
2503  }
2504  GNUNET_free (ac_value);
2505 }
static char * get_value(const char *key, const char *line)
Every line in the topology configuration starts with a string indicating which kind of information wi...
Definition: testing.c:1857

References GNUNET_TESTING_NetjailNode::additional_connects, get_value(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log_strerror, LOG, and ret.

Referenced by GNUNET_TESTING_get_topo_from_string().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_get_topo_from_string()

struct GNUNET_TESTING_NetjailTopology* GNUNET_TESTING_get_topo_from_string ( const char *  input)

Parse the topology data.

FIXME: this could use a "to_string".

Parameters
dataThe topology data.
Returns
The GNUNET_TESTING_NetjailTopology

Definition at line 2515 of file testing.c.

2516 {
2517  char *token;
2518  char *key = NULL;
2519  unsigned int out;
2520  char *rest = NULL;
2521  char *value = NULL;
2522  char *value2;
2523  char *data;
2524  int ret;
2525  struct GNUNET_TESTING_NetjailTopology *topo;
2526  struct GNUNET_TESTING_NetjailRouter *router;
2527  struct GNUNET_TESTING_NetjailNamespace *namespace;
2528  struct GNUNET_HashCode hc;
2529 
2530  data = GNUNET_strdup (input);
2531  token = strtok_r (data, "\n", &rest);
2533  topo->map_namespaces =
2535  topo->map_globals =
2537 
2538  while (NULL != token)
2539  {
2540  if (NULL != key)
2541  GNUNET_free (key);
2542  key = get_key (token);
2544  "In the loop with token: %s beginning with %s\n",
2545  token,
2546  key);
2547  if (0 == strcmp (key, "M"))
2548  {
2550  "Get first Value for M.\n");
2551  out = get_first_value (token);
2553  "M: %u\n",
2554  out);
2555  topo->nodes_m = out;
2556  }
2557  else if (0 == strcmp (key, "N"))
2558  {
2560  "Get first Value for N.\n");
2561  out = get_first_value (token);
2563  "N: %u\n",
2564  out);
2565  topo->namespaces_n = out;
2566  }
2567  else if (0 == strcmp (key, "X"))
2568  {
2570  "Get first Value for X.\n");
2571  out = get_first_value (token);
2573  "X: %u\n",
2574  out);
2575  topo->nodes_x = out;
2576  }
2577  else if (0 == strcmp (key, "AC"))
2578  {
2580  "Get first Value for AC.\n");
2581  out = get_first_value (token);
2583  "AC: %u\n",
2584  out);
2585  topo->additional_connects = out;
2586  }
2587  else if (0 == strcmp (key, "T"))
2588  {
2590  "Get first string value for T.\n");
2591  value = get_first_string_value (token);
2593  "value: %s\n",
2594  value);
2595  topo->plugin = value;
2596  }
2597  else if (0 == strcmp (key, "K"))
2598  {
2599  struct GNUNET_ShortHashCode hkey_k;
2600  struct GNUNET_TESTING_NetjailNode *k_node = GNUNET_new (struct
2602 
2604  "Get first Value for K.\n");
2605  out = get_first_value (token);
2607  "K: %u\n",
2608  out);
2609  k_node->node_n = out;
2610  GNUNET_CRYPTO_hash (&out, sizeof(out), &hc);
2611  memcpy (&hkey_k,
2612  &hc,
2613  sizeof (hkey_k));
2614  k_node->is_global = GNUNET_YES;
2615 
2617  topo->map_globals,
2618  &hkey_k))
2619  GNUNET_break (0);
2620  else
2622  &hkey_k,
2623  k_node,
2626  "Get value for key value on K.\n");
2627  value = get_value ("plugin", token);
2629  "value: %s\n",
2630  value);
2631  k_node->plugin = value;
2632  parse_ac (k_node, token);
2633  node_connections (token, k_node);
2634  GNUNET_free (value);
2635  }
2636  else if (0 == strcmp (key, "R"))
2637  {
2638  struct GNUNET_ShortHashCode hkey_r;
2639  router = GNUNET_new (struct GNUNET_TESTING_NetjailRouter);
2640 
2642  "Get first Value for R.\n");
2643  out = get_first_value (token);
2645  "R: %u\n",
2646  out);
2647  GNUNET_CRYPTO_hash (&out, sizeof(out), &hc);
2648  memcpy (&hkey_r,
2649  &hc,
2650  sizeof (hkey_r));
2652  "Get value for key tcp_port on R.\n");
2653  value = get_value ("tcp_port", token);
2655  "tcp_port: %s\n",
2656  value);
2657  ret = sscanf (value, "%u", &(router->tcp_port));
2658  GNUNET_free (value);
2659  GNUNET_break (0 != ret && 1 >= router->tcp_port);
2660 
2662  "Get value for key udp_port on R.\n");
2663  value2 = get_value ("udp_port", token);
2664  ret = sscanf (value2, "%u", &(router->udp_port));
2665  GNUNET_free (value2);
2666  GNUNET_break (0 != ret && 1 >= router->udp_port);
2668  "udp_port: %s\n",
2669  value2);
2670  GNUNET_free (value2);
2672  topo->map_namespaces,
2673  &hkey_r))
2674  {
2675  namespace = GNUNET_CONTAINER_multishortmap_get (topo->map_namespaces,
2676  &hkey_r);
2677  }
2678  else
2679  {
2680  namespace = GNUNET_new (struct GNUNET_TESTING_NetjailNamespace);
2681  namespace->namespace_n = out;
2682  namespace->nodes = GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO);
2684  &hkey_r,
2685  namespace,
2687  }
2688  namespace->router = router;
2689 
2690  }
2691  else if (0 == strcmp (key, "P"))
2692  {
2693  struct GNUNET_TESTING_NetjailNode *p_node = GNUNET_new (struct
2695  struct GNUNET_ShortHashCode hkey_p;
2696 
2698  "Get first Value for P.\n");
2699  out = get_first_value (token);
2701  "P: %u\n",
2702  out);
2703  GNUNET_CRYPTO_hash (&out, sizeof(out), &hc);
2704  memcpy (&hkey_p,
2705  &hc,
2706  sizeof (hkey_p));
2707 
2709  topo->map_namespaces,
2710  &hkey_p))
2711  {
2712  namespace = GNUNET_CONTAINER_multishortmap_get (topo->map_namespaces,
2713  &hkey_p);
2714  }
2715  else
2716  {
2717  namespace = GNUNET_new (struct GNUNET_TESTING_NetjailNamespace);
2718  namespace->nodes = GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO);
2719  namespace->namespace_n = out;
2721  &hkey_p,
2722  namespace,
2724  }
2726  "Get second Value for P.\n");
2727  out = get_second_value (token);
2729  "P: %u\n",
2730  out);
2731  GNUNET_CRYPTO_hash (&out, sizeof(out), &hc);
2732  memcpy (&hkey_p,
2733  &hc,
2734  sizeof (hkey_p));
2736  namespace->nodes,
2737  &hkey_p))
2738  {
2739  GNUNET_break (0);
2740  }
2741  else
2742  {
2743 
2744  GNUNET_CONTAINER_multishortmap_put (namespace->nodes,
2745  &hkey_p,
2746  p_node,
2749  "Get value for key plugin on P.\n");
2750  value = get_value ("plugin", token);
2751  if (NULL != value)
2752  {
2754  "plugin: %s\n",
2755  value);
2756  p_node->plugin = value;
2757  }
2758  p_node->node_n = out;
2759  p_node->namespace_n = namespace->namespace_n;
2760  }
2762  "Get AC Value for P.\n");
2763  parse_ac (p_node, token);
2764  node_connections (token, p_node);
2765  }
2766  token = strtok_r (NULL, "\n", &rest);
2767  if (NULL != token)
2769  "Next token %s\n",
2770  token);
2771  }
2772  if (NULL != key)
2773  GNUNET_free (key);
2774  GNUNET_free (data);
2775  return topo;
2776 }
uint32_t data
The data value.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multishortmap_put(struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
struct GNUNET_CONTAINER_MultiShortmap * GNUNET_CONTAINER_multishortmap_create(unsigned int len, int do_not_copy_keys)
Create a multi peer map (hash map for public keys of peers).
int GNUNET_CONTAINER_multishortmap_contains(const struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key)
Check if the map contains any value under the given key (including values that are NULL).
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE
Allow multiple values with the same key.
@ GNUNET_NO
struct GNUNET_CONTAINER_MultiShortmap * map_globals
Hash map containing the global known nodes which are not natted.
char * plugin
Default plugin for the test case to be run on nodes.
unsigned int nodes_m
Number of nodes per subnet.
unsigned int nodes_x
Number of global known nodes.
unsigned int namespaces_n
Number of subnets.
struct GNUNET_CONTAINER_MultiShortmap * map_namespaces
Hash map containing the subnets (for natted nodes) of the topology.
unsigned int additional_connects
Additional connects we do expect, beside the connects which are configured in the topology.
static unsigned int get_first_value(const char *line)
Every line in the topology configuration starts with a string indicating which kind of information wi...
Definition: testing.c:1734
static char * get_first_string_value(const char *line)
Every line in the topology configuration starts with a string indicating which kind of information wi...
Definition: testing.c:1792
static unsigned int get_second_value(const char *line)
Every line in the topology configuration starts with a string indicating which kind of information wi...
Definition: testing.c:1826
static char * get_key(const char *line)
Every line in the topology configuration starts with a string indicating which kind of information wi...
Definition: testing.c:1761
static void parse_ac(struct GNUNET_TESTING_NetjailNode *p_node, const char *token)
Definition: testing.c:2478

References GNUNET_TESTING_NetjailTopology::additional_connects, data, get_first_string_value(), get_first_value(), get_key(), get_second_value(), get_value(), GNUNET_break, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_CONTAINER_multishortmap_contains(), GNUNET_CONTAINER_multishortmap_create(), GNUNET_CONTAINER_multishortmap_get(), GNUNET_CONTAINER_multishortmap_put(), GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_new, GNUNET_NO, GNUNET_strdup, GNUNET_YES, GNUNET_TESTING_NetjailNode::is_global, key, LOG, GNUNET_TESTING_NetjailTopology::map_globals, GNUNET_TESTING_NetjailTopology::map_namespaces, GNUNET_TESTING_NetjailNode::namespace_n, GNUNET_TESTING_NetjailTopology::namespaces_n, node_connections(), GNUNET_TESTING_NetjailNode::node_n, GNUNET_TESTING_NetjailTopology::nodes_m, GNUNET_TESTING_NetjailTopology::nodes_x, parse_ac(), GNUNET_TESTING_NetjailNode::plugin, GNUNET_TESTING_NetjailTopology::plugin, ret, GNUNET_TESTING_NetjailRouter::tcp_port, GNUNET_TESTING_NetjailRouter::udp_port, and value.

Referenced by GNUNET_TESTING_get_topo_from_file().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_get_topo_from_file()

struct GNUNET_TESTING_NetjailTopology* GNUNET_TESTING_get_topo_from_file ( const char *  filename)

Getting the topology from file.

Parameters
filenameThe name of the topology file.
Returns
The GNUNET_TESTING_NetjailTopology

Definition at line 2786 of file testing.c.

2787 {
2788  uint64_t fs;
2789  char *data;
2790  struct GNUNET_TESTING_NetjailTopology *topo;
2791 
2793  {
2795  _ ("Topology file %s not found\n"),
2796  filename);
2797  return NULL;
2798  }
2799  if (GNUNET_OK !=
2801  {
2803  _ ("Topology file %s has no data\n"),
2804  filename);
2805  return NULL;
2806  }
2807  data = GNUNET_malloc (fs + 1);
2808  if (fs != GNUNET_DISK_fn_read (filename, data, fs))
2809  {
2811  _ ("Topology file %s cannot be read\n"),
2812  filename);
2813  GNUNET_free (data);
2814  return NULL;
2815  }
2816 
2818  "file length %" PRIu64 "\n",
2819  fs);
2820  data[fs] = '\0';
2821 
2823 
2824  GNUNET_free (data);
2825 
2826  return topo;
2827 }
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:664
struct GNUNET_TESTING_NetjailTopology * GNUNET_TESTING_get_topo_from_string(const char *input)
Parse the topology data.
Definition: testing.c:2515

References _, data, filename, fs, GNUNET_DISK_file_size(), GNUNET_DISK_file_test(), GNUNET_DISK_fn_read(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_malloc, GNUNET_OK, GNUNET_TESTING_get_topo_from_string(), GNUNET_YES, and LOG.

Here is the call graph for this function: