GNUnet  0.17.6
Data Structures | Macros | Functions
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 "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_arm_service.h"
#include "gnunet_testing_lib.h"
#include "gnunet_testing_netjail_lib.h"
#include "testing_cmds.h"
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 LOW_PORT   12000
 Lowest port used for GNUnet testing. More...
 
#define HIGH_PORT   56000
 Highest port used for GNUnet testing. More...
 

Functions

static int 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 int 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...
 
char * GNUNET_TESTING_get_testname_from_underscore (const char *argv0)
 Sometimes we use the binary name to determine which specific test to run. More...
 
static unsigned int get_first_value (char *line)
 
static char * get_key (char *line)
 
static char * get_first_string_value (char *line)
 
static unsigned int get_second_value (char *line)
 
static char * get_value (char *key, char *line)
 
static struct GNUNET_TESTING_NodeConnectionget_connect_value (char *line, struct GNUNET_TESTING_NetjailNode *node)
 
static void node_connections (char *line, struct GNUNET_TESTING_NetjailNode *node)
 
static int log_nodes (void *cls, const struct GNUNET_ShortHashCode *id, void *value)
 
static int log_namespaces (void *cls, const struct GNUNET_ShortHashCode *id, void *value)
 
static int log_topo (struct GNUNET_TESTING_NetjailTopology *topology)
 
void get_node_info (unsigned int num, struct GNUNET_TESTING_NetjailTopology *topology, struct GNUNET_TESTING_NetjailNode **node_ex, struct GNUNET_TESTING_NetjailNamespace **namespace_ex, struct GNUNET_TESTING_NodeConnection **node_connections_ex)
 
struct GNUNET_TESTING_NodeConnectionGNUNET_TESTING_get_connections (unsigned int num, struct GNUNET_TESTING_NetjailTopology *topology)
 Get the connections to other nodes for a specific node. More...
 
struct GNUNET_PeerIdentityGNUNET_TESTING_get_pub_key (unsigned int num, const struct GNUNET_TESTING_System *tl_system)
 Retrieve the public key 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, 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...
 
struct GNUNET_MessageHeaderGNUNET_TESTING_send_local_test_finished_msg (enum GNUNET_GenericReturnValue rv)
 Create a GNUNET_CMDS_LOCAL_FINISHED message. More...
 
struct GNUNET_TESTING_NetjailTopologyGNUNET_TESTING_get_topo_from_string (char *data)
 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 39 of file testing.c.

◆ CONNECT_ADDRESS_TEMPLATE

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

Definition at line 41 of file testing.c.

◆ ROUTER_CONNECT_ADDRESS_TEMPLATE

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

Definition at line 43 of file testing.c.

◆ KNOWN_CONNECT_ADDRESS_TEMPLATE

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

Definition at line 45 of file testing.c.

◆ PREFIX_TCP

#define PREFIX_TCP   "tcp"

Definition at line 47 of file testing.c.

◆ PREFIX_UDP

#define PREFIX_UDP   "udp"

Definition at line 49 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 57 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 64 of file testing.c.

Function Documentation

◆ hostkeys_load()

static int 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 257 of file testing.c.

258 {
259  uint64_t fs;
260  char *data_dir;
261  char *filename;
262  struct GNUNET_DISK_FileHandle *fd;
263 
264  GNUNET_assert (NULL == system->hostkeys_data);
266  GNUNET_asprintf (&filename, "%s/testing_hostkeys.ecc", data_dir);
267  GNUNET_free (data_dir);
268 
270  {
272  _ ("Hostkeys file not found: %s\n"),
273  filename);
275  return GNUNET_SYSERR;
276  }
277  /* Check hostkey file size, read entire thing into memory */
278  if (GNUNET_OK !=
280  fs = 0;
281  if (0 == fs)
282  {
284  return GNUNET_SYSERR; /* File is empty */
285  }
286  if (0 != (fs % GNUNET_TESTING_HOSTKEYFILESIZE))
287  {
289  _ ("Incorrect hostkey file format: %s\n"),
290  filename);
292  return GNUNET_SYSERR;
293  }
297  if (NULL == fd)
298  {
301  return GNUNET_SYSERR;
302  }
304  system->hostkeys_data =
307  if (NULL == system->hostkeys_data)
308  return GNUNET_SYSERR;
310  return GNUNET_OK;
311 }
static char * filename
static struct GNUNET_FS_Handle * fs
Handle to FS service.
Definition: gnunet-fs.c:36
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:1235
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:222
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:1378
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1306
@ 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
Definition: gnunet_common.h:99
@ GNUNET_YES
@ GNUNET_SYSERR
Definition: gnunet_common.h:97
#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:177
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:158
char * hostkeys_data
Hostkeys data, contains "GNUNET_TESTING_HOSTKEYFILESIZE * total_hostkeys" bytes.
Definition: testing.c:124
struct GNUNET_DISK_MapHandle * map
memory map for hostkeys_data.
Definition: testing.c:129
#define LOG(kind,...)
Definition: testing.c:39

References _, GNUNET_DISK_FileHandle::fd, filename, fs, GNUNET_asprintf(), GNUNET_assert, GNUNET_DISK_file_close(), GNUNET_DISK_file_map(), GNUNET_DISK_file_open(), GNUNET_DISK_file_size(), GNUNET_DISK_file_test(), GNUNET_DISK_MAP_TYPE_READ, GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log_strerror_file, GNUNET_OK, GNUNET_OS_installation_get_path(), GNUNET_OS_IPK_DATADIR, GNUNET_SYSERR, GNUNET_TESTING_HOSTKEYFILESIZE, GNUNET_YES, GNUNET_TESTING_System::hostkeys_data, LOG, GNUNET_TESTING_System::map, and GNUNET_TESTING_System::total_hostkeys.

Referenced by GNUNET_TESTING_system_create_with_portrange().

Here is the call graph for this function:
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 320 of file testing.c.

321 {
322  GNUNET_break (NULL != system->hostkeys_data);
323  system->hostkeys_data = NULL;
324  GNUNET_DISK_file_unmap (system->map);
325  system->map = NULL;
326  system->hostkeys_data = NULL;
327  system->total_hostkeys = 0;
328 }
enum GNUNET_GenericReturnValue GNUNET_DISK_file_unmap(struct GNUNET_DISK_MapHandle *h)
Unmap a file.
Definition: disk.c:1409
#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 340 of file testing.c.

344 {
345  struct GNUNET_CONFIGURATION_Handle *cfg2 = cls;
346 
347  GNUNET_CONFIGURATION_set_value_string (cfg2, section, option, value);
348 }
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 474 of file testing.c.

475 {
476  if (NULL != i->cfg_fn)
477  {
478  (void) unlink (i->cfg_fn);
479  GNUNET_free (i->cfg_fn);
480  }
481  GNUNET_free (i->unix_sock);
482  GNUNET_free (i->port_str);
483  GNUNET_break (NULL == i->proc);
484  GNUNET_break (0 == i->n_refs);
485  GNUNET_free (i);
486 }
unsigned int n_refs
Definition: testing.c:79
struct GNUNET_OS_Process * proc
Definition: testing.c:73

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 int start_shared_service_instance ( struct SharedServiceInstance i)
static

Definition at line 490 of file testing.c.

491 {
492  char *binary;
493  char *libexec_binary;
494 
495  GNUNET_assert (NULL == i->proc);
496  GNUNET_assert (NULL != i->cfg_fn);
497  (void) GNUNET_asprintf (&binary, "gnunet-service-%s", i->ss->sname);
498  libexec_binary = GNUNET_OS_get_libexec_binary_path (binary);
499  GNUNET_free (binary);
501  NULL,
502  NULL,
503  NULL,
504  libexec_binary,
505  libexec_binary,
506  "-c",
507  i->cfg_fn,
508  NULL);
509  GNUNET_free (libexec_binary);
510  if (NULL == i->proc)
511  return GNUNET_SYSERR;
512  return GNUNET_OK;
513 }
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:672
@ 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:69
char * sname
Definition: testing.c:84

References SharedServiceInstance::cfg_fn, GNUNET_asprintf(), GNUNET_assert, GNUNET_free, GNUNET_OK, GNUNET_OS_get_libexec_binary_path(), GNUNET_OS_INHERIT_STD_OUT_AND_ERR, GNUNET_OS_start_process(), GNUNET_SYSERR, SharedServiceInstance::proc, SharedService::sname, and SharedServiceInstance::ss.

Referenced by GNUNET_TESTING_peer_start().

Here is the call graph for this function:
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 517 of file testing.c.

518 {
519  GNUNET_break (0 == i->n_refs);
522  "Killing shared service instance (%s) failed\n",
523  i->ss->sname);
524  (void) GNUNET_OS_process_wait (i->proc);
526  i->proc = NULL;
527 }
@ GNUNET_ERROR_TYPE_WARNING
int GNUNET_OS_process_wait(struct GNUNET_OS_Process *proc)
Wait for a process to terminate.
Definition: os_priority.c:981
void GNUNET_OS_process_destroy(struct GNUNET_OS_Process *proc)
Cleans up process structure contents (OS-dependent) and deallocates it.
Definition: os_priority.c:280
int GNUNET_OS_process_kill(struct GNUNET_OS_Process *proc, int sig)
Sends a signal to the process.
Definition: os_priority.c:217
#define GNUNET_TERM_SIG
The termination signal.
Definition: platform.h:233

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 790 of file testing.c.

794 {
795  struct UpdateContext *uc = cls;
796  unsigned int ival;
797  char cval[12];
798  char uval[PATH_MAX];
799  char *single_variable;
800  char *per_host_variable;
801  unsigned long long num_per_host;
802  uint16_t new_port;
803 
804  if (GNUNET_OK != uc->status)
805  return;
806  if (! ((0 == strcmp (option, "PORT")) || (0 == strcmp (option, "UNIXPATH")) ||
807  (0 == strcmp (option, "HOSTNAME"))))
808  return;
809  GNUNET_asprintf (&single_variable, "single_%s_per_host", section);
810  GNUNET_asprintf (&per_host_variable, "num_%s_per_host", section);
811  if ((0 == strcmp (option, "PORT")) && (1 == sscanf (value, "%u", &ival)))
812  {
813  if ((ival != 0) &&
815  "testing",
816  single_variable)))
817  {
818  new_port = GNUNET_TESTING_reserve_port (uc->system);
819  if (0 == new_port)
820  {
821  uc->status = GNUNET_SYSERR;
822  GNUNET_free (single_variable);
823  GNUNET_free (per_host_variable);
824  return;
825  }
826  GNUNET_snprintf (cval, sizeof(cval), "%u", new_port);
827  value = cval;
828  GNUNET_array_append (uc->ports, uc->nports, new_port);
829  }
830  else if ((ival != 0) &&
831  (GNUNET_YES ==
833  "testing",
834  single_variable)) &&
836  "testing",
837  per_host_variable,
838  &num_per_host))
839  {
840  /* GNUNET_snprintf (cval, sizeof (cval), "%u", */
841  /* ival + ctx->fdnum % num_per_host); */
842  /* value = cval; */
843  GNUNET_break (0); /* FIXME */
844  }
845  }
846  if (0 == strcmp (option, "UNIXPATH"))
847  {
849  "testing",
850  single_variable))
851  {
852  GNUNET_snprintf (uval,
853  sizeof(uval),
854  "%s/%s.sock",
855  uc->gnunet_home,
856  section);
857  value = uval;
858  }
859  else if ((GNUNET_YES ==
861  "testing",
862  per_host_variable,
863  &num_per_host)) &&
864  (num_per_host > 0))
865  {
866  GNUNET_break (0); /* FIXME */
867  }
868  }
869  if (0 == strcmp (option, "HOSTNAME"))
870  {
871  value = (NULL == uc->system->hostname) ? "localhost" : uc->system->hostname;
872  }
873  GNUNET_free (single_variable);
874  GNUNET_free (per_host_variable);
875  GNUNET_CONFIGURATION_set_value_string (uc->cfg, section, option, value);
876 }
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:580
#define PATH_MAX
Assumed maximum path length.
Definition: platform.h:240
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 887 of file testing.c.

888 {
889  struct UpdateContext *uc = cls;
890  char **ikeys;
891  char *val;
892  char *ptr;
893  char *orig_allowed_hosts;
894  char *allowed_hosts;
895  char *ACCEPT_FROM_key;
896  uint16_t ikeys_cnt;
897  uint16_t key;
898 
899  ikeys_cnt = 0;
900  val = NULL;
901  /* Ignore certain options from sections. See
902  https://gnunet.org/bugs/view.php?id=2476 */
903  if (GNUNET_YES ==
904  GNUNET_CONFIGURATION_have_value (uc->cfg, section, "TESTING_IGNORE_KEYS"))
905  {
908  section,
909  "TESTING_IGNORE_KEYS",
910  &val));
911  ptr = val;
912  for (ikeys_cnt = 0; NULL != (ptr = strstr (ptr, ";")); ikeys_cnt++)
913  ptr++;
914  if (0 == ikeys_cnt)
915  GNUNET_break (0);
916  else
917  {
918  ikeys = GNUNET_malloc ((sizeof(char *)) * ikeys_cnt);
919  ptr = val;
920  for (key = 0; key < ikeys_cnt; key++)
921  {
922  ikeys[key] = ptr;
923  ptr = strstr (ptr, ";");
924  GNUNET_assert (NULL != ptr); /* worked just before... */
925  *ptr = '\0';
926  ptr++;
927  }
928  }
929  }
930  if (0 != ikeys_cnt)
931  {
932  for (key = 0; key < ikeys_cnt; key++)
933  {
934  if (NULL != strstr (ikeys[key], "ADVERTISED_PORT"))
935  break;
936  }
937  if ((key == ikeys_cnt) &&
938  (GNUNET_YES ==
939  GNUNET_CONFIGURATION_have_value (uc->cfg, section, "ADVERTISED_PORT")))
940  {
942  section,
943  "PORT",
944  &ptr))
945  {
947  section,
948  "ADVERTISED_PORT",
949  ptr);
950  GNUNET_free (ptr);
951  }
952  }
953  for (key = 0; key < ikeys_cnt; key++)
954  {
955  if (NULL != strstr (ikeys[key], "ACCEPT_FROM"))
956  {
957  GNUNET_free (ikeys);
958  GNUNET_free (val);
959  return;
960  }
961  }
962  GNUNET_free (ikeys);
963  }
964  GNUNET_free (val);
965  ACCEPT_FROM_key = "ACCEPT_FROM";
966  if ((NULL != uc->system->trusted_ip) &&
967  (NULL != strstr (uc->system->trusted_ip, ":"))) /* IPv6 in use */
968  ACCEPT_FROM_key = "ACCEPT_FROM6";
970  section,
971  ACCEPT_FROM_key,
972  &orig_allowed_hosts))
973  {
974  orig_allowed_hosts = GNUNET_strdup ("127.0.0.1;");
975  }
976  if (NULL == uc->system->trusted_ip)
977  allowed_hosts = GNUNET_strdup (orig_allowed_hosts);
978  else
979  GNUNET_asprintf (&allowed_hosts,
980  "%s%s;",
981  orig_allowed_hosts,
982  uc->system->trusted_ip);
983  GNUNET_free (orig_allowed_hosts);
985  section,
986  ACCEPT_FROM_key,
987  allowed_hosts);
988  GNUNET_free (allowed_hosts);
989 }
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 993 of file testing.c.

996 {
997  struct SharedServiceInstance *i;
998  struct GNUNET_CONFIGURATION_Handle *temp;
999  char *gnunet_home;
1000  uint32_t port;
1001 
1002  ss->n_peers++;
1003  if (((0 == ss->share) && (NULL == ss->instances)) ||
1004  ((0 != ss->share) &&
1005  (ss->n_instances < ((ss->n_peers + ss->share - 1) / ss->share))))
1006  {
1007  i = GNUNET_new (struct SharedServiceInstance);
1008  i->ss = ss;
1009  (void) GNUNET_asprintf (&gnunet_home,
1010  "%s/shared/%s/%u",
1011  system->tmppath,
1012  ss->sname,
1013  ss->n_instances);
1014  (void) GNUNET_asprintf (&i->unix_sock, "%s/sock", gnunet_home);
1015  port = GNUNET_TESTING_reserve_port (system);
1016  if (0 == port)
1017  {
1018  GNUNET_free (gnunet_home);
1020  return NULL;
1021  }
1023  temp = GNUNET_CONFIGURATION_dup (ss->cfg);
1024  (void) GNUNET_asprintf (&i->port_str, "%u", port);
1025  (void) GNUNET_asprintf (&i->cfg_fn, "%s/config", gnunet_home);
1027  "PATHS",
1028  "GNUNET_HOME",
1029  gnunet_home);
1030  GNUNET_free (gnunet_home);
1032  ss->sname,
1033  "UNIXPATH",
1034  i->unix_sock);
1036  ss->sname,
1037  "PORT",
1038  i->port_str);
1040  {
1043  return NULL;
1044  }
1046  }
1047  else
1048  {
1049  GNUNET_assert (NULL != ss->instances);
1050  GNUNET_assert (0 < ss->n_instances);
1051  i = ss->instances[ss->n_instances - 1];
1052  }
1054  ss->sname,
1056  cfg);
1058  ss->sname,
1059  "UNIXPATH",
1060  i->unix_sock);
1062  return i;
1063 }
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:108
unsigned int share
Definition: testing.c:92
struct GNUNET_CONFIGURATION_Handle * cfg
Definition: testing.c:88
unsigned int n_instances
Definition: testing.c:94
struct SharedServiceInstance ** instances
Definition: testing.c:86
unsigned int n_peers
Definition: testing.c:90
static void cleanup_shared_service_instance(struct SharedServiceInstance *i)
Definition: testing.c:474
static void cfg_copy_iterator(void *cls, const char *section, const char *option, const char *value)
Function to iterate over options.
Definition: testing.c:340

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 1086 of file testing.c.

1090 {
1091  struct UpdateContext uc;
1092  char *default_config;
1093 
1094  uc.system = system;
1095  uc.cfg = cfg;
1096  uc.status = GNUNET_OK;
1097  uc.ports = NULL;
1098  uc.nports = 0;
1099  GNUNET_asprintf (&uc.gnunet_home,
1100  "%s/%u",
1101  system->tmppath,
1102  system->path_counter++);
1103  GNUNET_asprintf (&default_config, "%s/config", uc.gnunet_home);
1105  "PATHS",
1106  "DEFAULTCONFIG",
1107  default_config);
1108  GNUNET_CONFIGURATION_set_value_string (cfg, "arm", "CONFIG", default_config);
1109  GNUNET_free (default_config);
1111  "PATHS",
1112  "GNUNET_HOME",
1113  uc.gnunet_home);
1114  /* make PORTs and UNIXPATHs unique */
1116  /* allow connections to services from system trusted_ip host */
1118  /* enable loopback-based connections between peers */
1119  GNUNET_CONFIGURATION_set_value_string (cfg, "nat", "USE_LOCALADDR", "YES");
1120  GNUNET_free (uc.gnunet_home);
1121  if ((NULL != ports) && (NULL != nports))
1122  {
1123  *ports = uc.ports;
1124  *nports = uc.nports;
1125  }
1126  else
1127  GNUNET_free (uc.ports);
1128  return uc.status;
1129 }
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:153
uint16_t * ports
Array of ports currently allocated to this peer.
Definition: testing.c:765
struct GNUNET_TESTING_System * system
The system for which we are building configurations.
Definition: testing.c:748
unsigned int nports
The number of ports in the above array.
Definition: testing.c:770
static void update_config(void *cls, const char *section, const char *option, const char *value)
Function to iterate over options.
Definition: testing.c:790
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:887

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 1485 of file testing.c.

1486 {
1487  struct GNUNET_TESTING_Peer *peer = cls;
1488 
1489  if (GNUNET_SYSERR == connected)
1490  {
1491  peer->cb (peer->cb_cls, peer, connected);
1492  return;
1493  }
1494  if (GNUNET_YES == connected)
1495  {
1497  return;
1498  }
1501  peer->ah = NULL;
1502  peer->cb (peer->cb_cls, peer, GNUNET_YES);
1503 }
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:1412
int GNUNET_TESTING_peer_wait(struct GNUNET_TESTING_Peer *peer)
Waits for a peer to terminate.
Definition: testing.c:1444
Handle for a GNUnet peer controlled by testing.
Definition: testing.c:176
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 1643 of file testing.c.

1644 {
1645  struct ServiceContext *sc = cls;
1646 
1647  sc->tm (sc->tm_cls, sc->cfg, sc->peer);
1648 }
static struct GNUNET_FS_SearchContext * sc
Definition: gnunet-search.c:84
Structure for holding service data.
Definition: testing.c:1614

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 ( char *  line)
static

Definition at line 1788 of file testing.c.

1789 {
1790  char *copy;
1791  size_t slen;
1792  char *token;
1793  unsigned int ret;
1794  char *rest = NULL;
1795 
1796  slen = strlen (line) + 1;
1797  copy = malloc (slen);
1798  memcpy (copy, line, slen);
1799  token = strtok_r (copy, ":", &rest);
1800  token = strtok_r (NULL, ":", &rest);
1801  GNUNET_assert (1 == sscanf (token, "%u", &ret));
1802  GNUNET_free (copy);
1803  return ret;
1804 }
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, 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 ( char *  line)
static

Definition at line 1808 of file testing.c.

1809 {
1810  char *copy;
1811  size_t slen;
1812  size_t tlen;
1813  char *token;
1814  char *ret;
1815  char *rest = NULL;
1816 
1817  slen = strlen (line) + 1;
1818  copy = malloc (slen);
1819  memcpy (copy, line, slen);
1820  token = strtok_r (copy, ":", &rest);
1821  tlen = strlen (token) + 1;
1822  ret = malloc (tlen);
1823  memcpy (ret, token, tlen);
1824  GNUNET_free (copy);
1825  return ret;
1826 }

References GNUNET_free, 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 ( char *  line)
static

Definition at line 1830 of file testing.c.

1831 {
1832  char *copy;
1833  size_t slen, slen_token;
1834  char *token;
1835  char *ret;
1836  char *rest = NULL;
1837 
1838  slen = strlen (line) + 1;
1839  copy = malloc (slen);
1840  memcpy (copy, line, slen);
1841  token = strtok_r (copy, ":", &rest);
1842  token = strtok_r (NULL, ":", &rest);
1844  "first token %s\n",
1845  token);
1846  slen_token = strlen (token);
1847  ret = malloc (slen_token + 1);
1848  memcpy (ret, token, slen_token + 1);
1849  GNUNET_free (copy);
1850  return ret;
1851 }
@ GNUNET_ERROR_TYPE_DEBUG

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, 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 ( char *  line)
static

Definition at line 1855 of file testing.c.

1856 {
1857  char *copy;
1858  size_t slen;
1859  char *token;
1860  unsigned int ret;
1861  char *rest = NULL;
1862 
1863  slen = strlen (line) + 1;
1864  copy = malloc (slen);
1865  memcpy (copy, line, slen);
1866  token = strtok_r (copy, ":", &rest);
1867  token = strtok_r (NULL, ":", &rest);
1868  token = strtok_r (NULL, ":", &rest);
1869  GNUNET_assert (1 == sscanf (token, "%u", &ret));
1870  GNUNET_free (copy);
1871  return ret;
1872 }

References GNUNET_assert, GNUNET_free, line, and ret.

Referenced by GNUNET_TESTING_get_topo_from_string().

Here is the caller graph for this function:

◆ get_value()

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

Definition at line 1876 of file testing.c.

1877 {
1878  char *copy;
1879  size_t slen, slen_token;
1880  char *token;
1881  char *token2;
1882  char *temp;
1883  char *rest = NULL;
1884  char *ret;
1885 
1886  slen = strlen (line) + 1;
1887  copy = malloc (slen);
1888  memcpy (copy, line, slen);
1889  temp = strstr (copy, key);
1890  if (NULL == temp)
1891  return NULL;
1892  token = strtok_r (temp, ":", &rest);
1893  token = strtok_r (NULL, ":", &rest);
1894  token2 = strtok_r (token, "}", &rest);
1895  slen_token = strlen (token2);
1896  ret = malloc (slen_token + 1);
1897  memcpy (ret, token2, slen_token + 1);
1898  GNUNET_free (copy);
1899  return ret;
1900 }

References GNUNET_free, key, line, and ret.

Referenced by GNUNET_TESTING_get_topo_from_string().

Here is the caller graph for this function:

◆ get_connect_value()

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

Definition at line 1904 of file testing.c.

1905 {
1906  struct GNUNET_TESTING_NodeConnection *node_connection;
1907  char *copy;
1908  size_t slen;
1909  char *token;
1910  char *token2;
1911  unsigned int node_n;
1912  unsigned int namespace_n;
1913  char *rest = NULL;
1914  char *rest2 = NULL;
1916  unsigned int sscanf_ret;
1917 
1918  node_connection = GNUNET_new (struct GNUNET_TESTING_NodeConnection);
1919  node_connection->node = node;
1920 
1921  slen = strlen (line) + 1;
1922  copy = malloc (slen);
1923  memcpy (copy, line, slen);
1924  token = strtok_r (copy, ":", &rest);
1925  if (0 == strcmp ("{K", token))
1926  {
1927  node_connection->node_type = GNUNET_TESTING_GLOBAL_NODE;
1928  token = strtok_r (NULL, ":", &rest);
1929  GNUNET_assert (1 == sscanf (token, "%u", &node_n));
1931  "node_n %u\n",
1932  node_n);
1933  node_connection->node_n = node_n;
1934  node_connection->namespace_n = 0;
1935  }
1936  else if (0 == strcmp ("{P", token))
1937  {
1938  node_connection->node_type = GNUNET_TESTING_SUBNET_NODE;
1939  token = strtok_r (NULL, ":", &rest);
1940  errno = 0;
1941  sscanf_ret = sscanf (token, "%u", &namespace_n);
1942  if (errno != 0)
1943  {
1945  }
1946  GNUNET_assert (0 < sscanf_ret);
1947  node_connection->namespace_n = namespace_n;
1948  token = strtok_r (NULL, ":", &rest);
1949  errno = 0;
1950  sscanf_ret = sscanf (token, "%u", &node_n);
1951  if (errno != 0)
1952  {
1954  }
1955  GNUNET_assert (0 < sscanf_ret);
1956  node_connection->node_n = node_n;
1958  "node_n %u namespace_n %u node->node_n %u node->namespace_n %u\n",
1959  node_n,
1960  namespace_n,
1961  node->node_n,
1962  node->namespace_n);
1963  }
1964  else
1965  {
1966  GNUNET_free (node_connection);
1967  }
1968 
1969  while (NULL != (token = strtok_r (NULL, ":", &rest)))
1970  {
1972  token2 = strtok_r (token, "}", &rest2);
1973  if (NULL != token2)
1974  {
1975  slen = strlen (token2) + 1;
1976  prefix->address_prefix = malloc (slen);
1977  memcpy (prefix->address_prefix, token2, slen);
1978  }
1979  else
1980  {
1981  slen = strlen (token) + 1;
1982  prefix->address_prefix = malloc (slen);
1983  memcpy (prefix->address_prefix, token, slen);
1984  }
1985 
1987  "address_prefix %s\n",
1988  prefix->address_prefix);
1989 
1991  node_connection->address_prefixes_tail,
1992  prefix);
1994  "address_prefix %s\n",
1995  prefix->address_prefix);
1996  }
1997 
1998  GNUNET_free (copy);
1999  return node_connection;
2000 }
static int prefix
If printing the value of PREFIX has been requested.
Definition: gnunet-config.c:58
@ 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.
enum GNUNET_TESTING_NODE_TYPE node_type
The type of the node this connection points to.
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.

References GNUNET_TESTING_NodeConnection::address_prefixes_head, GNUNET_TESTING_NodeConnection::address_prefixes_tail, GNUNET_assert, GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log_strerror, GNUNET_new, 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 ( char *  line,
struct GNUNET_TESTING_NetjailNode node 
)
static

Definition at line 2004 of file testing.c.

2005 {
2006  char *value, *value2;
2007  char *temp;
2008  char *copy;
2009  size_t slen;
2010  char *rest = NULL;
2011  char *rest2 = NULL;
2012  struct GNUNET_TESTING_NodeConnection *node_connection;
2013 
2014 
2015  temp = strstr (line, "connect");
2016  if (NULL != temp)
2017  {
2018  slen = strlen (temp) + 1;
2019  copy = GNUNET_malloc (slen);
2020  memcpy (copy, temp, slen);
2021  strtok_r (copy, ":", &rest);
2022  value = strtok_r (rest, "|", &rest2);
2023 
2024  while (NULL != value)
2025  {
2027  "node_connections value %s\n",
2028  value);
2029  node_connection = get_connect_value (value, node);
2032  node_connection);
2033  value2 = strstr (value, "}}");
2034  if (NULL != value2)
2035  break;
2036  value = strtok_r (NULL, "|", &rest2);
2037 
2038  }
2039  GNUNET_free (copy);
2040  }
2041 }
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(char *line, struct GNUNET_TESTING_NetjailNode *node)
Definition: testing.c:1904

References get_connect_value(), GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_malloc, 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(), 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

Definition at line 2045 of file testing.c.

2046 {
2047  struct GNUNET_TESTING_NetjailNode *node = value;
2048  struct GNUNET_TESTING_NodeConnection *pos_connection;
2049  struct GNUNET_TESTING_AddressPrefix *pos_prefix;
2050 
2052  "plugin: %s space: %u node: %u global: %u\n",
2053  node->plugin,
2054  node->namespace_n,
2055  node->node_n,
2056  node->is_global);
2057 
2058  for (pos_connection = node->node_connections_head; NULL != pos_connection;
2059  pos_connection = pos_connection->next)
2060  {
2061 
2063  "namespace_n: %u node_n: %u node_type: %u\n",
2064  pos_connection->namespace_n,
2065  pos_connection->node_n,
2066  pos_connection->node_type);
2067 
2068  for (pos_prefix = pos_connection->address_prefixes_head; NULL != pos_prefix;
2069  pos_prefix =
2070  pos_prefix->next)
2071  {
2073  "prefix: %s\n",
2074  pos_prefix->address_prefix);
2075  }
2076  }
2077  return GNUNET_YES;
2078 }
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

Definition at line 2082 of file testing.c.

2083 {
2084  struct GNUNET_TESTING_NetjailNamespace *namespace = value;
2085 
2086  GNUNET_CONTAINER_multishortmap_iterate (namespace->nodes, &log_nodes, NULL);
2087  return GNUNET_YES;
2088 }
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)
Definition: testing.c:2045

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 ( struct GNUNET_TESTING_NetjailTopology topology)
static

Definition at line 2092 of file testing.c.

2093 {
2095  "plugin: %s spaces: %u nodes: %u known: %u\n",
2096  topology->plugin,
2097  topology->namespaces_n,
2098  topology->nodes_m,
2099  topology->nodes_x);
2100 
2102  log_namespaces, NULL);
2104  NULL);
2105  return GNUNET_YES;
2106 }
enum GNUNET_TESTBED_TopologyOption topology
The topology to generate.
static int log_namespaces(void *cls, const struct GNUNET_ShortHashCode *id, void *value)
Definition: testing.c:2082

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

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

Definition at line 2109 of file testing.c.

2114 {
2115  struct GNUNET_ShortHashCode *hkey;
2116  struct GNUNET_HashCode hc;
2117  unsigned int namespace_n;
2118  unsigned int node_m;
2119  struct GNUNET_TESTING_NetjailNode *node;
2120  struct GNUNET_TESTING_NetjailNamespace *namespace;
2122 
2123  log_topo (topology);
2124  hkey = GNUNET_new (struct GNUNET_ShortHashCode);
2126  "num: %u \n",
2127  num);
2128  if (topology->nodes_x >= num)
2129  {
2130 
2131  GNUNET_CRYPTO_hash (&num, sizeof(num), &hc);
2132  memcpy (hkey,
2133  &hc,
2134  sizeof (*hkey));
2136  hkey);
2137  if (NULL != node)
2139  }
2140  else
2141  {
2142  namespace_n = (unsigned int) ceil ((double) (num - topology->nodes_x)
2143  / topology->nodes_m);
2145  "ceil num: %u nodes_x: %u nodes_m: %u namespace_n: %u\n",
2146  num,
2147  topology->nodes_x,
2148  topology->nodes_m,
2149  namespace_n);
2150  hkey = GNUNET_new (struct GNUNET_ShortHashCode);
2151  GNUNET_CRYPTO_hash (&namespace_n, sizeof(namespace_n), &hc);
2152  memcpy (hkey,
2153  &hc,
2154  sizeof (*hkey));
2155  namespace = GNUNET_CONTAINER_multishortmap_get (topology->map_namespaces,
2156  hkey);
2157  if (NULL != namespace)
2158  {
2159  node_m = num - topology->nodes_x - topology->nodes_m * (namespace_n - 1);
2160  hkey = GNUNET_new (struct GNUNET_ShortHashCode);
2161  GNUNET_CRYPTO_hash (&node_m, sizeof(node_m), &hc);
2162  memcpy (hkey,
2163  &hc,
2164  sizeof (*hkey));
2165  node = GNUNET_CONTAINER_multishortmap_get (namespace->nodes,
2166  hkey);
2167  if (NULL != node)
2168  {
2170  "node additional_connects: %u %p\n",
2171  node->additional_connects,
2172  node);
2174  }
2175  *node_ex = node;
2176  *namespace_ex = namespace;
2177  *node_connections_ex = node_connections;
2178  }
2179  GNUNET_free (hkey);
2180  }
2181 }
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(char *line, struct GNUNET_TESTING_NetjailNode *node)
Definition: testing.c:2004
static int log_topo(struct GNUNET_TESTING_NetjailTopology *topology)
Definition: testing.c:2092

References GNUNET_TESTING_NetjailNode::additional_connects, GNUNET_CONTAINER_multishortmap_get(), GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_new, 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(), and GNUNET_TESTING_get_connections().

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

◆ GNUNET_TESTING_get_connections()

struct GNUNET_TESTING_NodeConnection* GNUNET_TESTING_get_connections ( unsigned int  num,
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 2192 of file testing.c.

2194 {
2195  struct GNUNET_TESTING_NetjailNode *node;
2196  struct GNUNET_TESTING_NetjailNamespace *namespace;
2198 
2200  "get_connections\n");
2201 
2202  get_node_info (num, topology, &node, &namespace, &node_connections);
2203 
2204  return node_connections;
2205 }
void get_node_info(unsigned int num, struct GNUNET_TESTING_NetjailTopology *topology, struct GNUNET_TESTING_NetjailNode **node_ex, struct GNUNET_TESTING_NetjailNamespace **namespace_ex, struct GNUNET_TESTING_NodeConnection **node_connections_ex)
Definition: testing.c:2109

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_pub_key()

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

Retrieve the public key 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 2216 of file testing.c.

2218 {
2220  struct GNUNET_CRYPTO_EddsaPublicKey *pub_key = GNUNET_new (struct
2222  struct GNUNET_CRYPTO_EddsaPrivateKey *priv_key;
2223 
2224  priv_key = GNUNET_TESTING_hostkey_get (tl_system,
2225  num,
2226  peer);
2227 
2229  pub_key);
2230  peer->public_key = *pub_key;
2231  GNUNET_free (priv_key);
2232  GNUNET_free (pub_key);
2233  return peer;
2234 }
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:197
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:714
Private ECC key encoded for transmission.
Public ECC key (always for curve Ed25519) encoded in a format suitable for network transmission and E...
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 2238 of file testing.c.

2241 {
2242  (void) cls;
2243  struct GNUNET_TESTING_NetjailNode *node = value;
2244  struct GNUNET_TESTING_NodeConnection *pos_connection;
2245  struct GNUNET_TESTING_AddressPrefix *pos_prefix;
2246 
2247  while (NULL != (pos_connection = node->node_connections_head))
2248  {
2249  while (NULL != (pos_prefix = pos_connection->address_prefixes_head))
2250  {
2251  GNUNET_free (pos_prefix->address_prefix);
2252  }
2253  GNUNET_free (pos_connection);
2254  }
2255 
2256  GNUNET_free (node->plugin);
2257  GNUNET_free (node);
2258  return GNUNET_OK;
2259 }

References GNUNET_TESTING_AddressPrefix::address_prefix, GNUNET_TESTING_NodeConnection::address_prefixes_head, GNUNET_free, GNUNET_OK, GNUNET_TESTING_NetjailNode::node_connections_head, 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 2263 of file testing.c.

2266 {
2267  (void) cls;
2268  struct GNUNET_TESTING_NetjailNamespace *namespace = value;
2269 
2270  GNUNET_free (namespace->router);
2272  NULL);
2273  return GNUNET_OK;
2274 
2275 }
int free_nodes_cb(void *cls, const struct GNUNET_ShortHashCode *key, void *value)
Definition: testing.c:2238

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 2284 of file testing.c.

2285 {
2287  free_namespaces_cb, NULL);
2290  NULL);
2292  GNUNET_free (topology->plugin);
2294 }
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:2263

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 2298 of file testing.c.

2301 {
2302  unsigned int n, m, num;
2303 
2304  n = node_connection->namespace_n;
2305  m = node_connection->node_n;
2306 
2307  if (0 == n)
2308  num = m;
2309  else
2310  num = (n - 1) * topology->nodes_m + m + topology->nodes_x;
2311 
2312  return num;
2313 }
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,
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 2324 of file testing.c.

2326 {
2327  struct GNUNET_TESTING_NetjailNode *node;
2328  char *addr;
2329  char *template;
2330  unsigned int node_n;
2331 
2333  "node_n: %u\n",
2334  connection->node_n);
2335 
2336  node = connection->node;
2337  if (connection->namespace_n == node->namespace_n)
2338  {
2339  template = CONNECT_ADDRESS_TEMPLATE;
2340  node_n = connection->node_n;
2341  }
2342  else if (0 == connection->namespace_n)
2343  {
2344  template = KNOWN_CONNECT_ADDRESS_TEMPLATE;
2345  node_n = connection->node_n;
2346  }
2347  else if (1 == connection->node_n)
2348  {
2350  node_n = connection->namespace_n;
2351  }
2352  else
2353  {
2354  return NULL;
2355  }
2356 
2357  if (0 == strcmp (PREFIX_TCP, prefix))
2358  {
2359 
2360  GNUNET_asprintf (&addr,
2361  template,
2362  prefix,
2363  node_n);
2364  }
2365  else if (0 == strcmp (PREFIX_UDP, prefix))
2366  {
2367  GNUNET_asprintf (&addr,
2368  template,
2369  prefix,
2370  node_n);
2371  }
2372  else
2373  {
2374  GNUNET_assert (0);
2375  }
2376 
2377  return addr;
2378 }
#define PREFIX_TCP
Definition: testing.c:47
#define CONNECT_ADDRESS_TEMPLATE
Definition: testing.c:41
#define PREFIX_UDP
Definition: testing.c:49
#define KNOWN_CONNECT_ADDRESS_TEMPLATE
Definition: testing.c:45
#define ROUTER_CONNECT_ADDRESS_TEMPLATE
Definition: testing.c:43

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_UDP, 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 2387 of file testing.c.

2390 {
2391  struct GNUNET_TESTING_NetjailNode *node;
2392  struct GNUNET_TESTING_NetjailNamespace *namespace;
2394 
2396  "get_additional_connects\n");
2397 
2398  get_node_info (num, topology, &node, &namespace, &node_connections);
2399 
2401  "node additional_connects: %u %p\n",
2403  node);
2404 
2405  return node->additional_connects;
2406 }

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

Here is the call graph for this function:

◆ GNUNET_TESTING_send_local_test_finished_msg()

struct GNUNET_MessageHeader* GNUNET_TESTING_send_local_test_finished_msg ( enum GNUNET_GenericReturnValue  rv)

Create a GNUNET_CMDS_LOCAL_FINISHED message.

Parameters
rvThe result of the local test as GNUNET_GenericReturnValue.
Returns
The GNUNET_CMDS_LOCAL_FINISHED message.

Definition at line 2416 of file testing.c.

2417 {
2418  struct GNUNET_CMDS_LOCAL_FINISHED *reply;
2419  size_t msg_length;
2420 
2422  "Local test exits with status %d\n",
2423  rv);
2424  msg_length = sizeof(struct GNUNET_CMDS_LOCAL_FINISHED);
2425  reply = GNUNET_new (struct GNUNET_CMDS_LOCAL_FINISHED);
2427  reply->header.size = htons ((uint16_t) msg_length);
2428  reply->result = htons (rv);
2429 
2430  return (struct GNUNET_MessageHeader *) reply;
2431 }
#define GNUNET_log(kind,...)
#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED.
Definition: testing_cmds.h:85
enum GNUNET_GenericReturnValue result
Definition: testing_cmds.h:87
Header for all communications.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED, GNUNET_new, GNUNET_CMDS_LOCAL_FINISHED::header, GNUNET_CMDS_LOCAL_FINISHED::result, GNUNET_MessageHeader::size, and GNUNET_MessageHeader::type.

◆ GNUNET_TESTING_get_topo_from_string()

struct GNUNET_TESTING_NetjailTopology* GNUNET_TESTING_get_topo_from_string ( char *  data)

Parse the topology data.

Parameters
dataThe topology data.
Returns
The GNUNET_TESTING_NetjailTopology

Definition at line 2441 of file testing.c.

2442 {
2443  char *token;
2444  char *key = NULL;
2445  unsigned int out;
2446  char *rest = NULL;
2447  char *value = NULL;
2448  char *value2;
2449  char *ac_value;
2450  int ret;
2451  struct GNUNET_TESTING_NetjailTopology *topo;
2452  struct GNUNET_TESTING_NetjailRouter *router;
2453  struct GNUNET_TESTING_NetjailNamespace *namespace;
2454  struct GNUNET_ShortHashCode *hkey;
2455  struct GNUNET_HashCode hc;
2456 
2457  token = strtok_r (data, "\n", &rest);
2459  topo->map_namespaces =
2461  topo->map_globals =
2463 
2464  while (NULL != token)
2465  {
2466  if (NULL != key)
2467  free (key);
2468  key = get_key (token);
2470  "In the loop with token: %s beginning with %s\n",
2471  token,
2472  key);
2473  if (0 == strcmp (key, "M"))
2474  {
2476  "Get first Value for M.\n");
2477  out = get_first_value (token);
2479  "M: %u\n",
2480  out);
2481  topo->nodes_m = out;
2482  }
2483  else if (0 == strcmp (key, "N"))
2484  {
2486  "Get first Value for N.\n");
2487  out = get_first_value (token);
2489  "N: %u\n",
2490  out);
2491  topo->namespaces_n = out;
2492  }
2493  else if (0 == strcmp (key, "X"))
2494  {
2496  "Get first Value for X.\n");
2497  out = get_first_value (token);
2499  "X: %u\n",
2500  out);
2501  topo->nodes_x = out;
2502  }
2503  else if (0 == strcmp (key, "AC"))
2504  {
2506  "Get first Value for AC.\n");
2507  out = get_first_value (token);
2509  "AC: %u\n",
2510  out);
2511  topo->additional_connects = out;
2512  }
2513  else if (0 == strcmp (key, "T"))
2514  {
2516  "Get first string value for T.\n");
2517  value = get_first_string_value (token);
2519  "value: %s\n",
2520  value);
2521  topo->plugin = value;
2522  }
2523  else if (0 == strcmp (key, "K"))
2524  {
2525  hkey = GNUNET_new (struct GNUNET_ShortHashCode);
2526  struct GNUNET_TESTING_NetjailNode *k_node = GNUNET_new (struct
2528 
2530  "Get first Value for K.\n");
2531  out = get_first_value (token);
2533  "K: %u\n",
2534  out);
2535  k_node->node_n = out;
2536  GNUNET_CRYPTO_hash (&out, sizeof(out), &hc);
2537  memcpy (hkey,
2538  &hc,
2539  sizeof (*hkey));
2540  k_node->is_global = GNUNET_YES;
2541 
2543  topo->map_globals,
2544  hkey))
2545  GNUNET_break (0);
2546  else
2548  hkey,
2549  k_node,
2552  "Get value for key value on K.\n");
2553  value = get_value ("plugin", token);
2555  "value: %s\n",
2556  value);
2557  k_node->plugin = value;
2558  node_connections (token, k_node);
2559  GNUNET_free (value);
2560  }
2561  else if (0 == strcmp (key, "R"))
2562  {
2563  hkey = GNUNET_new (struct GNUNET_ShortHashCode);
2564  router = GNUNET_new (struct GNUNET_TESTING_NetjailRouter);
2565 
2567  "Get first Value for R.\n");
2568  out = get_first_value (token);
2570  "R: %u\n",
2571  out);
2572  GNUNET_CRYPTO_hash (&out, sizeof(out), &hc);
2573  memcpy (hkey,
2574  &hc,
2575  sizeof (*hkey));
2577  "Get value for key tcp_port on R.\n");
2578  value = get_value ("tcp_port", token);
2580  "tcp_port: %s\n",
2581  value);
2582  ret = sscanf (value, "%u", &(router->tcp_port));
2583  GNUNET_free (value);
2584  GNUNET_break (0 != ret && 1 >= router->tcp_port);
2585 
2587  "Get value for key udp_port on R.\n");
2588  value2 = get_value ("udp_port", token);
2589  ret = sscanf (value2, "%u", &(router->udp_port));
2590  GNUNET_free (value2);
2591  GNUNET_break (0 != ret && 1 >= router->udp_port);
2593  "udp_port: %s\n",
2594  value2);
2595  GNUNET_free (value2);
2597  topo->map_namespaces,
2598  hkey))
2599  {
2600  namespace = GNUNET_CONTAINER_multishortmap_get (topo->map_namespaces,
2601  hkey);
2602  }
2603  else
2604  {
2605  namespace = GNUNET_new (struct GNUNET_TESTING_NetjailNamespace);
2606  namespace->namespace_n = out;
2607  namespace->nodes = GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO);
2609  hkey,
2610  namespace,
2612  }
2613  namespace->router = router;
2614 
2615  }
2616  else if (0 == strcmp (key, "P"))
2617  {
2618  struct GNUNET_TESTING_NetjailNode *p_node = GNUNET_new (struct
2620 
2622  "Get first Value for P.\n");
2623  out = get_first_value (token);
2625  "P: %u\n",
2626  out);
2627  GNUNET_CRYPTO_hash (&out, sizeof(out), &hc);
2628  memcpy (hkey,
2629  &hc,
2630  sizeof (*hkey));
2631 
2633  topo->map_namespaces,
2634  hkey))
2635  {
2636  namespace = GNUNET_CONTAINER_multishortmap_get (topo->map_namespaces,
2637  hkey);
2638  }
2639  else
2640  {
2641  namespace = GNUNET_new (struct GNUNET_TESTING_NetjailNamespace);
2642  namespace->nodes = GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO);
2643  namespace->namespace_n = out;
2645  hkey,
2646  namespace,
2648  }
2650  "Get second Value for P.\n");
2651  out = get_second_value (token);
2653  "P: %u\n",
2654  out);
2655  GNUNET_CRYPTO_hash (&out, sizeof(out), &hc);
2656  memcpy (hkey,
2657  &hc,
2658  sizeof (*hkey));
2660  namespace->nodes,
2661  hkey))
2662  {
2663  GNUNET_break (0);
2664  }
2665  else
2666  {
2667 
2668  GNUNET_CONTAINER_multishortmap_put (namespace->nodes,
2669  hkey,
2670  p_node,
2673  "Get value for key plugin on P.\n");
2674  value = get_value ("plugin", token);
2676  "plugin: %s\n",
2677  value);
2678  memcpy (p_node->plugin, value, sizeof (*value));
2679  GNUNET_free (value);
2680  p_node->node_n = out;
2681  p_node->namespace_n = namespace->namespace_n;
2682  }
2684  "Get AC Value for P.\n");
2685  ac_value = get_value ("AC", token);
2687  "ac value: %s\n",
2688  ac_value);
2689  sscanf (ac_value, "%u", &p_node->additional_connects);
2691  "P:AC %u\n",
2692  p_node->additional_connects);
2693  node_connections (token, p_node);
2694  GNUNET_free (ac_value);
2695  }
2696  token = strtok_r (NULL, "\n", &rest);
2697  if (NULL != token)
2699  "Next token %s\n",
2700  token);
2701  }
2702  if (NULL != key)
2703  GNUNET_free (key);
2704 
2705  return topo;
2706 }
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
Definition: gnunet_common.h:98
API for writing an interpreter to test GNUnet components.
unsigned int tcp_port
Will tcp be forwarded?
unsigned int udp_port
Will udp be forwarded?
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 char * get_value(char *key, char *line)
Definition: testing.c:1876
static unsigned int get_second_value(char *line)
Definition: testing.c:1855
static unsigned int get_first_value(char *line)
Definition: testing.c:1788
static char * get_key(char *line)
Definition: testing.c:1808
static char * get_first_string_value(char *line)
Definition: testing.c:1830

References GNUNET_TESTING_NetjailNode::additional_connects, 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_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, 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 2716 of file testing.c.

2717 {
2718  uint64_t fs;
2719  char *data;
2720  struct GNUNET_TESTING_NetjailTopology *topo;
2721 
2723  {
2725  _ ("Topology file %s not found\n"),
2726  filename);
2727  return NULL;
2728  }
2729  if (GNUNET_OK !=
2731  {
2733  _ ("Topology file %s has no data\n"),
2734  filename);
2735  return NULL;
2736  }
2737  data = GNUNET_malloc (fs + 1);
2738  if (fs != GNUNET_DISK_fn_read (filename, data, fs))
2739  {
2741  _ ("Topology file %s cannot be read\n"),
2742  filename);
2743  GNUNET_free (data);
2744  return NULL;
2745  }
2746 
2748  "file length %lu\n",
2749  fs);
2750  data[fs] = '\0';
2751 
2753 
2754  GNUNET_free (data);
2755 
2756  return topo;
2757 }
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(char *data)
Parse the topology data.
Definition: testing.c:2441

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: