GNUnet  0.10.x
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 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 PIPE_CONTROL   GNUNET_NO
 We need pipe control only on WINDOWS. More...
 
#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...
 

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

◆ PIPE_CONTROL

#define PIPE_CONTROL   GNUNET_NO

We need pipe control only on WINDOWS.

Definition at line 47 of file testing.c.

Referenced by GNUNET_TESTING_peer_start(), and start_shared_service_instance().

◆ 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.

Referenced by GNUNET_TESTING_system_create().

◆ 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.

Referenced by GNUNET_TESTING_system_create().

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.

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

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 
269  if (GNUNET_YES != GNUNET_DISK_file_test (filename))
270  {
272  _("Hostkeys file not found: %s\n"), filename);
273  GNUNET_free (filename);
274  return GNUNET_SYSERR;
275  }
276  /* Check hostkey file size, read entire thing into memory */
277  if (GNUNET_OK !=
278  GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES))
279  fs = 0;
280  if (0 == fs)
281  {
282  GNUNET_free (filename);
283  return GNUNET_SYSERR; /* File is empty */
284  }
285  if (0 != (fs % GNUNET_TESTING_HOSTKEYFILESIZE))
286  {
288  _("Incorrect hostkey file format: %s\n"), filename);
289  GNUNET_free (filename);
290  return GNUNET_SYSERR;
291  }
294  if (NULL == fd)
295  {
297  GNUNET_free (filename);
298  return GNUNET_SYSERR;
299  }
300  GNUNET_free (filename);
301  system->hostkeys_data = GNUNET_DISK_file_map (fd,
302  &system->map,
304  fs);
306  if (NULL == system->hostkeys_data)
307  return GNUNET_SYSERR;
309  return GNUNET_OK;
310 }
int GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory)...
Definition: disk.c:669
Open the file for reading.
int GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1817
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define LOG(kind,...)
Definition: testing.c:37
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:2020
Nobody is allowed to do anything to the file.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_TESTING_HOSTKEYFILESIZE
Size of each hostkey in the hostkey file (in BYTES).
uint32_t total_hostkeys
The number of hostkeys.
Definition: testing.c:158
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
#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...
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, the current running apps installation directory.
Read-only memory map.
static char * filename
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
static struct GNUNET_FS_Handle * fs
Handle to FS service.
Definition: gnunet-fs.c:36
int GNUNET_DISK_file_size(const char *filename, uint64_t *size, int include_symbolic_links, int single_file_mode)
Get the size of the file (or directory) of the given file (in bytes).
Definition: disk.c:289
struct GNUNET_DISK_MapHandle * map
memory map for hostkeys_data.
Definition: testing.c:129
char * hostkeys_data
Hostkeys data, contains "GNUNET_TESTING_HOSTKEYFILESIZE * total_hostkeys" bytes.
Definition: testing.c:124
#define GNUNET_YES
Definition: gnunet_common.h:80
int fd
File handle on other OSes.
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:1673
Handle used to access files (and pipes).
Return the directory where data is installed (share/gnunet/)
#define GNUNET_free(ptr)
Wrapper around free.
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 319 of file testing.c.

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

320 {
321  GNUNET_break (NULL != system->hostkeys_data);
322  system->hostkeys_data = NULL;
323  GNUNET_DISK_file_unmap (system->map);
324  system->map = NULL;
325  system->hostkeys_data = NULL;
326  system->total_hostkeys = 0;
327 }
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
uint32_t total_hostkeys
The number of hostkeys.
Definition: testing.c:158
int GNUNET_DISK_file_unmap(struct GNUNET_DISK_MapHandle *h)
Unmap a file.
Definition: disk.c:2100
struct GNUNET_DISK_MapHandle * map
memory map for hostkeys_data.
Definition: testing.c:129
char * hostkeys_data
Hostkeys data, contains "GNUNET_TESTING_HOSTKEYFILESIZE * total_hostkeys" bytes.
Definition: testing.c:124
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 339 of file testing.c.

References GNUNET_CONFIGURATION_set_value_string().

Referenced by associate_shared_service(), and GNUNET_TESTING_system_create_with_portrange().

341 {
342  struct GNUNET_CONFIGURATION_Handle *cfg2 = cls;
343 
345 }
static char * section
Name of the section.
Definition: gnunet-config.c:33
static char * value
Value of the record to add/remove.
static char * option
Name of the option.
Definition: gnunet-config.c:38
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.
configuration data
Definition: configuration.c:85
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 465 of file testing.c.

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

Referenced by associate_shared_service(), and GNUNET_TESTING_system_destroy().

466 {
467  if (NULL != i->cfg_fn)
468  {
469  (void) unlink (i->cfg_fn);
470  GNUNET_free (i->cfg_fn);
471  }
474  GNUNET_break (NULL == i->proc);
475  GNUNET_break (0 == i->n_refs);
476  GNUNET_free (i);
477 }
struct GNUNET_OS_Process * proc
Definition: testing.c:73
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
unsigned int n_refs
Definition: testing.c:79
#define GNUNET_free(ptr)
Wrapper around free.
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 481 of file testing.c.

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, PIPE_CONTROL, SharedServiceInstance::proc, SharedService::sname, and SharedServiceInstance::ss.

Referenced by GNUNET_TESTING_peer_start().

482 {
483  char *binary;
484  char *libexec_binary;
485 
486  GNUNET_assert (NULL == i->proc);
487  GNUNET_assert (NULL != i->cfg_fn);
488  (void) GNUNET_asprintf (&binary, "gnunet-service-%s", i->ss->sname);
489  libexec_binary = GNUNET_OS_get_libexec_binary_path (binary);
490  GNUNET_free (binary);
493  NULL, NULL, NULL,
494  libexec_binary,
495  libexec_binary,
496  "-c",
497  i->cfg_fn,
498  NULL);
499  GNUNET_free (libexec_binary);
500  if (NULL == i->proc)
501  return GNUNET_SYSERR;
502  return GNUNET_OK;
503 }
#define PIPE_CONTROL
We need pipe control only on WINDOWS.
Definition: testing.c:47
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_OS_Process * GNUNET_OS_start_process(int pipe_control, 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:1400
struct GNUNET_OS_Process * proc
Definition: testing.c:73
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
char * sname
Definition: testing.c:84
When these flags are set, the child process will inherit stdout and stderr of the parent...
Definition: gnunet_os_lib.h:98
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
struct SharedService * ss
Definition: testing.c:69
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 ...
#define GNUNET_free(ptr)
Wrapper around free.
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 507 of file testing.c.

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

508 {
509  GNUNET_break (0 == i->n_refs);
512  "Killing shared service instance (%s) failed\n", i->ss->sname);
513  (void) GNUNET_OS_process_wait (i->proc);
515  i->proc = NULL;
516 }
void GNUNET_OS_process_destroy(struct GNUNET_OS_Process *proc)
Cleans up process structure contents (OS-dependent) and deallocates it.
Definition: os_priority.c:364
#define LOG(kind,...)
Definition: testing.c:37
struct GNUNET_OS_Process * proc
Definition: testing.c:73
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
char * sname
Definition: testing.c:84
unsigned int n_refs
Definition: testing.c:79
struct SharedService * ss
Definition: testing.c:69
int GNUNET_OS_process_wait(struct GNUNET_OS_Process *proc)
Wait for a process to terminate.
Definition: os_priority.c:1762
#define GNUNET_TERM_SIG
The termination signal.
Definition: platform.h:282
int GNUNET_OS_process_kill(struct GNUNET_OS_Process *proc, int sig)
Sends a signal to the process.
Definition: os_priority.c:251
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 781 of file testing.c.

References UpdateContext::cfg, GNUNET_array_append, GNUNET_asprintf(), GNUNET_break, GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONFIGURATION_get_value_yesno(), GNUNET_CONFIGURATION_set_value_string(), GNUNET_free, UpdateContext::gnunet_home, GNUNET_OK, GNUNET_snprintf(), GNUNET_SYSERR, GNUNET_TESTING_reserve_port(), GNUNET_YES, GNUNET_TESTING_System::hostname, UpdateContext::nports, PATH_MAX, UpdateContext::ports, SSCANF, UpdateContext::status, UpdateContext::system, and uc.

Referenced by GNUNET_TESTING_configuration_create_().

785 {
786  struct UpdateContext *uc = cls;
787  unsigned int ival;
788  char cval[12];
789  char uval[PATH_MAX];
790  char *single_variable;
791  char *per_host_variable;
792  unsigned long long num_per_host;
793  uint16_t new_port;
794 
795  if (GNUNET_OK != uc->status)
796  return;
797  if (! ((0 == strcmp (option, "PORT"))
798  || (0 == strcmp (option, "UNIXPATH"))
799  || (0 == strcmp (option, "HOSTNAME"))))
800  return;
801  GNUNET_asprintf (&single_variable, "single_%s_per_host", section);
802  GNUNET_asprintf (&per_host_variable, "num_%s_per_host", section);
803  if ((0 == strcmp (option, "PORT")) && (1 == SSCANF (value, "%u", &ival)))
804  {
805  if ((ival != 0) &&
806  (GNUNET_YES !=
808  single_variable)))
809  {
810  new_port = GNUNET_TESTING_reserve_port (uc->system);
811  if (0 == new_port)
812  {
813  uc->status = GNUNET_SYSERR;
814  GNUNET_free (single_variable);
815  GNUNET_free (per_host_variable);
816  return;
817  }
818  GNUNET_snprintf (cval, sizeof (cval), "%u", new_port);
819  value = cval;
820  GNUNET_array_append (uc->ports, uc->nports, new_port);
821  }
822  else if ((ival != 0) &&
823  (GNUNET_YES ==
825  single_variable)) &&
827  per_host_variable,
828  &num_per_host))
829  {
830  /* GNUNET_snprintf (cval, sizeof (cval), "%u", */
831  /* ival + ctx->fdnum % num_per_host); */
832  /* value = cval; */
833  GNUNET_break (0); /* FIXME */
834  }
835  }
836  if (0 == strcmp (option, "UNIXPATH"))
837  {
838  if (GNUNET_YES !=
840  single_variable))
841  {
842  GNUNET_snprintf (uval,
843  sizeof (uval),
844  "%s/%s.sock",
845  uc->gnunet_home, section);
846  value = uval;
847  }
848  else if ((GNUNET_YES ==
850  per_host_variable,
851  &num_per_host)) &&
852  (num_per_host > 0))
853  {
854  GNUNET_break(0); /* FIXME */
855  }
856  }
857  if (0 == strcmp (option, "HOSTNAME"))
858  {
859  value = (NULL == uc->system->hostname) ? "localhost" : uc->system->hostname;
860  }
861  GNUNET_free (single_variable);
862  GNUNET_free (per_host_variable);
864 }
struct GNUNET_CONFIGURATION_Handle * cfg
The configuration we are building.
Definition: testing.c:744
Closure for update_rel_sum() and update_abs_sum().
int GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
char * gnunet_home
The customized service home path for this peer.
Definition: testing.c:749
int GNUNET_snprintf(char *buf, size_t size, const char *format,...)
Like snprintf, just aborts if the buffer is of insufficient size.
uint16_t * ports
Array of ports currently allocated to this peer.
Definition: testing.c:756
static struct GNUNET_FS_UnindexContext * uc
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static char * section
Name of the section.
Definition: gnunet-config.c:33
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
static char * value
Value of the record to add/remove.
static char * option
Name of the option.
Definition: gnunet-config.c:38
#define PATH_MAX
Assumed maximum path length.
Definition: platform.h:289
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.
unsigned int nports
The number of ports in the above array.
Definition: testing.c:761
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
#define GNUNET_array_append(arr, size, element)
Append an element to a list (growing the list by one).
#define SSCANF
Definition: plibc.h:691
uint16_t GNUNET_TESTING_reserve_port(struct GNUNET_TESTING_System *system)
Reserve a TCP or UDP port for a peer.
Definition: testing.c:569
char * hostname
our hostname
Definition: testing.c:119
#define GNUNET_YES
Definition: gnunet_common.h:80
struct GNUNET_TESTING_System * system
The system for which we are building configurations.
Definition: testing.c:739
int status
build status - to signal error while building a configuration
Definition: testing.c:766
int GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
#define GNUNET_free(ptr)
Wrapper around free.
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 875 of file testing.c.

References UpdateContext::cfg, GNUNET_asprintf(), GNUNET_assert, GNUNET_break, GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONFIGURATION_have_value(), GNUNET_CONFIGURATION_set_value_string(), GNUNET_free, GNUNET_free_non_null, GNUNET_malloc, GNUNET_OK, GNUNET_strdup, GNUNET_YES, key, UpdateContext::system, GNUNET_TESTING_System::trusted_ip, and uc.

Referenced by GNUNET_TESTING_configuration_create_().

877 {
878  struct UpdateContext *uc = cls;
879  char **ikeys;
880  char *val;
881  char *ptr;
882  char *orig_allowed_hosts;
883  char *allowed_hosts;
884  char *ACCEPT_FROM_key;
885  uint16_t ikeys_cnt;
886  uint16_t key;
887 
888  ikeys_cnt = 0;
889  val = NULL;
890  /* Ignore certain options from sections. See
891  https://gnunet.org/bugs/view.php?id=2476 */
893  "TESTING_IGNORE_KEYS"))
894  {
896  (GNUNET_YES ==
898  "TESTING_IGNORE_KEYS", &val));
899  ptr = val;
900  for (ikeys_cnt = 0; NULL != (ptr = strstr (ptr, ";")); ikeys_cnt++)
901  ptr++;
902  if (0 == ikeys_cnt)
903  GNUNET_break (0);
904  else
905  {
906  ikeys = GNUNET_malloc ((sizeof (char *)) * ikeys_cnt);
907  ptr = val;
908  for (key = 0; key < ikeys_cnt; key++)
909  {
910  ikeys[key] = ptr;
911  ptr = strstr (ptr, ";");
912  GNUNET_assert (NULL != ptr); /* worked just before... */
913  *ptr = '\0';
914  ptr++;
915  }
916  }
917  }
918  if (0 != ikeys_cnt)
919  {
920  for (key = 0; key < ikeys_cnt; key++)
921  {
922  if (NULL != strstr (ikeys[key], "ADVERTISED_PORT"))
923  break;
924  }
925  if ((key == ikeys_cnt) &&
927  "ADVERTISED_PORT")))
928  {
929  if (GNUNET_OK ==
931  {
933  "ADVERTISED_PORT", ptr);
934  GNUNET_free (ptr);
935  }
936  }
937  for (key = 0; key < ikeys_cnt; key++)
938  {
939  if (NULL != strstr (ikeys[key], "ACCEPT_FROM"))
940  {
941  GNUNET_free (ikeys);
942  GNUNET_free (val);
943  return;
944  }
945  }
946  GNUNET_free (ikeys);
947  }
948  GNUNET_free_non_null (val);
949  ACCEPT_FROM_key = "ACCEPT_FROM";
950  if ((NULL != uc->system->trusted_ip) &&
951  (NULL != strstr (uc->system->trusted_ip, ":"))) /* IPv6 in use */
952  ACCEPT_FROM_key = "ACCEPT_FROM6";
953  if (GNUNET_OK !=
954  GNUNET_CONFIGURATION_get_value_string (uc->cfg, section, ACCEPT_FROM_key,
955  &orig_allowed_hosts))
956  {
957  orig_allowed_hosts = GNUNET_strdup ("127.0.0.1;");
958  }
959  if (NULL == uc->system->trusted_ip)
960  allowed_hosts = GNUNET_strdup (orig_allowed_hosts);
961  else
962  GNUNET_asprintf (&allowed_hosts, "%s%s;", orig_allowed_hosts,
963  uc->system->trusted_ip);
964  GNUNET_free (orig_allowed_hosts);
965  GNUNET_CONFIGURATION_set_value_string (uc->cfg, section, ACCEPT_FROM_key,
966  allowed_hosts);
967  GNUNET_free (allowed_hosts);
968 }
struct GNUNET_CONFIGURATION_Handle * cfg
The configuration we are building.
Definition: testing.c:744
Closure for update_rel_sum() and update_abs_sum().
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_FS_UnindexContext * uc
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static char * section
Name of the section.
Definition: gnunet-config.c:33
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
int 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.
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.
int GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
struct GNUNET_HashCode key
The key used in the DHT.
#define GNUNET_YES
Definition: gnunet_common.h:80
struct GNUNET_TESTING_System * system
The system for which we are building configurations.
Definition: testing.c:739
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
char * trusted_ip
The trusted ip.
Definition: testing.c:114
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 972 of file testing.c.

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

975 {
976  struct SharedServiceInstance *i;
977  struct GNUNET_CONFIGURATION_Handle *temp;
978  char *gnunet_home;
979  uint32_t port;
980 
981  ss->n_peers++;
982  if ( ((0 == ss->share) && (NULL == ss->instances))
983  ||
984  ( (0 != ss->share)
985  && (ss->n_instances < ((ss->n_peers + ss->share - 1) / ss->share)) ) )
986  {
987  i = GNUNET_new (struct SharedServiceInstance);
988  i->ss = ss;
989  (void) GNUNET_asprintf (&gnunet_home, "%s/shared/%s/%u",
990  system->tmppath, ss->sname, ss->n_instances);
991  (void) GNUNET_asprintf (&i->unix_sock, "%s/sock", gnunet_home);
992  port = GNUNET_TESTING_reserve_port (system);
993  if (0 == port)
994  {
995  GNUNET_free (gnunet_home);
997  return NULL;
998  }
1000  temp = GNUNET_CONFIGURATION_dup (ss->cfg);
1001  (void) GNUNET_asprintf (&i->port_str, "%u", port);
1002  (void) GNUNET_asprintf (&i->cfg_fn, "%s/config", gnunet_home);
1003  GNUNET_CONFIGURATION_set_value_string (temp, "PATHS", "GNUNET_HOME",
1004  gnunet_home);
1005  GNUNET_free (gnunet_home);
1006  GNUNET_CONFIGURATION_set_value_string (temp, ss->sname, "UNIXPATH",
1007  i->unix_sock);
1008  GNUNET_CONFIGURATION_set_value_string (temp, ss->sname, "PORT",
1009  i->port_str);
1011  {
1014  return NULL;
1015  }
1017  }
1018  else
1019  {
1020  GNUNET_assert (NULL != ss->instances);
1021  GNUNET_assert (0 < ss->n_instances);
1022  i = ss->instances[ss->n_instances - 1];
1023  }
1025  &cfg_copy_iterator, cfg);
1026  GNUNET_CONFIGURATION_set_value_string (cfg, ss->sname, "UNIXPATH",
1027  i->unix_sock);
1028  GNUNET_CONFIGURATION_set_value_string (cfg, ss->sname, "PORT", i->port_str);
1029  return i;
1030 }
struct GNUNET_CONFIGURATION_Handle * cfg
Definition: testing.c:88
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.
static void cleanup_shared_service_instance(struct SharedServiceInstance *i)
Definition: testing.c:465
int GNUNET_CONFIGURATION_write(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Write configuration file.
unsigned int n_instances
Definition: testing.c:94
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
unsigned int share
Definition: testing.c:92
#define GNUNET_new(type)
Allocate a struct or union of the given type.
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
unsigned int n_peers
Definition: testing.c:90
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
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.
char * sname
Definition: testing.c:84
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
struct SharedService * ss
Definition: testing.c:69
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_dup(const struct GNUNET_CONFIGURATION_Handle *cfg)
Duplicate an existing configuration object.
#define GNUNET_array_append(arr, size, element)
Append an element to a list (growing the list by one).
static void cfg_copy_iterator(void *cls, const char *section, const char *option, const char *value)
Function to iterate over options.
Definition: testing.c:339
static uint16_t port
Port number.
Definition: gnunet-bcd.c:79
configuration data
Definition: configuration.c:85
struct SharedServiceInstance ** instances
Definition: testing.c:86
uint16_t GNUNET_TESTING_reserve_port(struct GNUNET_TESTING_System *system)
Reserve a TCP or UDP port for a peer.
Definition: testing.c:569
char * tmppath
Prefix (i.e.
Definition: testing.c:108
#define GNUNET_free(ptr)
Wrapper around free.
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 1053 of file testing.c.

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

Referenced by GNUNET_TESTING_configuration_create(), and GNUNET_TESTING_peer_configure().

1057 {
1058  struct UpdateContext uc;
1059  char *default_config;
1060 
1061  uc.system = system;
1062  uc.cfg = cfg;
1063  uc.status = GNUNET_OK;
1064  uc.ports = NULL;
1065  uc.nports = 0;
1066  GNUNET_asprintf (&uc.gnunet_home, "%s/%u", system->tmppath,
1067  system->path_counter++);
1068  GNUNET_asprintf (&default_config, "%s/config", uc.gnunet_home);
1069  GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "DEFAULTCONFIG",
1070  default_config);
1071  GNUNET_CONFIGURATION_set_value_string (cfg, "arm", "CONFIG",
1072  default_config);
1073  GNUNET_free (default_config);
1074  GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "GNUNET_HOME",
1075  uc.gnunet_home);
1076  /* make PORTs and UNIXPATHs unique */
1078  /* allow connections to services from system trusted_ip host */
1080  /* enable loopback-based connections between peers */
1082  "nat",
1083  "USE_LOCALADDR", "YES");
1084  GNUNET_free (uc.gnunet_home);
1085  if ((NULL != ports) && (NULL != nports))
1086  {
1087  *ports = uc.ports;
1088  *nports = uc.nports;
1089  }
1090  else
1091  GNUNET_free_non_null (uc.ports);
1092  return uc.status;
1093 }
static void update_config(void *cls, const char *section, const char *option, const char *value)
Function to iterate over options.
Definition: testing.c:781
Closure for update_rel_sum() and update_abs_sum().
void GNUNET_CONFIGURATION_iterate(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CONFIGURATION_Iterator iter, void *iter_cls)
Iterate over all options in the configuration.
uint16_t * ports
Array of ports currently allocated to this peer.
Definition: testing.c:756
static struct GNUNET_FS_UnindexContext * uc
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
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
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
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.
unsigned int nports
The number of ports in the above array.
Definition: testing.c:761
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:104
static void update_config_sections(void *cls, const char *section)
Section iterator to set ACCEPT_FROM/ACCEPT_FROM6 to include the address of &#39;trusted_hosts&#39; in all sec...
Definition: testing.c:875
void GNUNET_CONFIGURATION_iterate_sections(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CONFIGURATION_Section_Iterator iter, void *iter_cls)
Iterate over all sections in the configuration.
struct GNUNET_TESTING_System * system
The system for which we are building configurations.
Definition: testing.c:739
char * tmppath
Prefix (i.e.
Definition: testing.c:108
#define GNUNET_free(ptr)
Wrapper around free.
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 1436 of file testing.c.

References GNUNET_TESTING_Peer::ah, GNUNET_TESTING_Peer::cb, GNUNET_TESTING_Peer::cb_cls, 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().

1438 {
1439  struct GNUNET_TESTING_Peer *peer = cls;
1440 
1441  if (GNUNET_SYSERR == connected)
1442  {
1443  peer->cb (peer->cb_cls, peer, connected);
1444  return;
1445  }
1446  if (GNUNET_YES == connected)
1447  {
1449  return;
1450  }
1452  GNUNET_ARM_disconnect (peer->ah);
1453  peer->ah = NULL;
1454  peer->cb (peer->cb_cls, peer, GNUNET_YES);
1455 }
Handle for a GNUnet peer controlled by testing.
Definition: testing.c:175
struct GNUNET_ARM_Handle * ah
The handle to the peer&#39;s ARM service.
Definition: testing.c:205
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
void GNUNET_ARM_disconnect(struct GNUNET_ARM_Handle *h)
Disconnect from the ARM service (if connected) and destroy the context.
Definition: arm_api.c:507
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
int GNUNET_TESTING_peer_kill(struct GNUNET_TESTING_Peer *peer)
Sends SIGTERM to the peer&#39;s main process.
Definition: testing.c:1363
void * cb_cls
The closure for the above callback.
Definition: testing.c:220
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
#define GNUNET_YES
Definition: gnunet_common.h:80
GNUNET_TESTING_PeerStopCallback cb
The callback to call asynchronously when a peer is stopped.
Definition: testing.c:215
int GNUNET_TESTING_peer_wait(struct GNUNET_TESTING_Peer *peer)
Waits for a peer to terminate.
Definition: testing.c:1395
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 1596 of file testing.c.

References ServiceContext::cfg, ServiceContext::peer, sc, ServiceContext::tm, and ServiceContext::tm_cls.

Referenced by GNUNET_TESTING_service_run().

1597 {
1598  struct ServiceContext *sc = cls;
1599 
1600  sc->tm (sc->tm_cls, sc->cfg, sc->peer);
1601 }
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration of the peer in which the service is run.
Definition: testing.c:1571
void * tm_cls
Closure for the above callback.
Definition: testing.c:1586
Structure for holding service data.
Definition: testing.c:1566
GNUNET_TESTING_TestMain tm
Callback to signal service startup.
Definition: testing.c:1576
static struct GNUNET_FS_SearchContext * sc
Definition: gnunet-search.c:37
struct GNUNET_TESTING_Peer * peer
The peer in which the service is run.
Definition: testing.c:1581
Here is the caller graph for this function: