GNUnet  0.11.x
Data Structures | Macros | Typedefs | Functions
Testing library

Library for writing testcases for GNUnet. More...

Data Structures

struct  GNUNET_TESTING_SharedService
 Specification of a service that is to be shared among peers. More...
 

Macros

#define GNUNET_TESTING_HOSTKEYFILESIZE
 Size of each hostkey in the hostkey file (in BYTES). More...
 
#define GNUNET_TESTING_PREFIX   "GNUNET_TESTING_PREFIX"
 The environmental variable, if set, that dictates where testing should place generated peer configurations. More...
 

Typedefs

typedef void(* GNUNET_TESTING_PeerStopCallback) (void *cls, struct GNUNET_TESTING_Peer *peer, int success)
 Callback to inform whether the peer is running or stopped. More...
 
typedef void(* GNUNET_TESTING_TestMain) (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TESTING_Peer *peer)
 Signature of the 'main' function for a (single-peer) testcase that is run using GNUNET_TESTING_peer_run(). More...
 

Functions

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...
 
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...
 
void GNUNET_TESTING_system_destroy (struct GNUNET_TESTING_System *system, int remove_paths)
 Free system resources. 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...
 
uint16_t GNUNET_TESTING_reserve_port (struct GNUNET_TESTING_System *system)
 Reserve a 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...
 
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_stop (struct GNUNET_TESTING_Peer *peer)
 Stop the peer. More...
 
void GNUNET_TESTING_peer_destroy (struct GNUNET_TESTING_Peer *peer)
 Destroy 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_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...
 
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...
 
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

Library for writing testcases for GNUnet.

It can start/stop one or more peers on a system; testing is responsible for managing private keys, ports and paths; it is a low-level library that does not support higher-level functions such as P2P connection, topology management or distributed testbed maintenance (those are provided by the Testbed service)

See also
Documentation

Macro Definition Documentation

◆ GNUNET_TESTING_HOSTKEYFILESIZE

#define GNUNET_TESTING_HOSTKEYFILESIZE
Value:
sizeof(struct \
GNUNET_CRYPTO_EddsaPrivateKey)

Size of each hostkey in the hostkey file (in BYTES).

Definition at line 59 of file gnunet_testing_lib.h.

Referenced by create_keys(), get_identity(), GNUNET_TESTING_hostkey_get(), GNUNET_TESTING_peer_configure(), hostkeys_load(), load_keys(), print_key(), and run().

◆ GNUNET_TESTING_PREFIX

#define GNUNET_TESTING_PREFIX   "GNUNET_TESTING_PREFIX"

The environmental variable, if set, that dictates where testing should place generated peer configurations.

Definition at line 66 of file gnunet_testing_lib.h.

Referenced by GNUNET_TESTING_system_create_with_portrange(), and tokenizer_cb().

Typedef Documentation

◆ GNUNET_TESTING_PeerStopCallback

typedef void(* GNUNET_TESTING_PeerStopCallback) (void *cls, struct GNUNET_TESTING_Peer *peer, int success)

Callback to inform whether the peer is running or stopped.

Parameters
clsthe closure given to GNUNET_TESTING_peer_stop_async()
peerthe respective peer whose status is being reported
successGNUNET_YES if the peer is stopped; GNUNET_SYSERR upon any error

Definition at line 347 of file gnunet_testing_lib.h.

◆ GNUNET_TESTING_TestMain

typedef void(* GNUNET_TESTING_TestMain) (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TESTING_Peer *peer)

Signature of the 'main' function for a (single-peer) testcase that is run using GNUNET_TESTING_peer_run().

Parameters
clsclosure
cfgconfiguration of the peer that was started
peeridentity of the peer that was created

Definition at line 391 of file gnunet_testing_lib.h.

Function Documentation

◆ GNUNET_TESTING_system_create()

struct GNUNET_TESTING_System* GNUNET_TESTING_system_create ( const char *  testdir,
const char *  trusted_ip,
const char *  hostname,
const struct GNUNET_TESTING_SharedService shared_services 
)

Create a system handle.

There must only be one system handle per operating system. Uses a default range for allowed ports. Ports are still tested for availability.

Parameters
testdironly the directory name without any path. This is used for all service homes; the directory will be created in a temporary location depending on the underlying OS. This variable will be overridden with the value of the environmental variable GNUNET_TESTING_PREFIX, if it exists.
trusted_ipthe ip address which will be set as TRUSTED HOST in all service configurations generated to allow control connections from this ip. This can either be a single ip address or a network address in CIDR notation.
hostnamethe hostname of the system we are using for testing; NULL for localhost
shared_servicesNULL terminated array describing services that are to be shared among peers
Returns
handle to this system, NULL on error

Definition at line 453 of file testing.c.

References GNUNET_TESTING_system_create_with_portrange(), HIGH_PORT, and LOW_PORT.

Referenced by create_hostkeys(), create_unique_cfgs(), GNUNET_TESTING_service_run(), GNUNET_TRANSPORT_TESTING_init(), handle_init(), and tokenizer_cb().

458 {
460  trusted_ip,
461  hostname,
462  shared_services,
463  LOW_PORT,
464  HIGH_PORT);
465 }
#define HIGH_PORT
Highest port used for GNUnet testing.
Definition: testing.c:59
#define LOW_PORT
Lowest port used for GNUnet testing.
Definition: testing.c:52
struct GNUNET_TESTING_System * GNUNET_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.
Definition: testing.c:368
static char * hostname
Our hostname; we give this to all the peers we start.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_system_create_with_portrange()

struct GNUNET_TESTING_System* GNUNET_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.

There must only be one system handle per operating system. Use this function directly if multiple system objects are created for the same host (only really useful when testing — or to make the port range configureable).

Parameters
testdironly the directory name without any path. This is used for all service homes; the directory will be created in a temporary location depending on the underlying OS. This variable will be overridden with the value of the environmental variable GNUNET_TESTING_PREFIX, if it exists.
trusted_ipthe ip address which will be set as TRUSTED HOST in all service configurations generated to allow control connections from this ip. This can either be a single ip address or a network address in CIDR notation.
hostnamethe hostname of the system we are using for testing; NULL for localhost
shared_servicesNULL terminated array describing services that are to be shared among peers
lowportlowest port number this system is allowed to allocate (inclusive)
highporthighest port number this system is allowed to allocate (exclusive)
Returns
handle to this system, NULL on error

There must only be one system handle per operating system.

Parameters
testdironly the directory name without any path. This is used for all service homes; the directory will be created in a temporary location depending on the underlying OS. This variable will be overridden with the value of the environmental variable GNUNET_TESTING_PREFIX, if it exists.
trusted_ipthe ip address which will be set as TRUSTED HOST in all service configurations generated to allow control connections from this ip. This can either be a single ip address or a network address in CIDR notation.
hostnamethe hostname of the system we are using for testing; NULL for localhost
shared_servicesNULL terminated array describing services that are to be shared among peers
lowportlowest port number this system is allowed to allocate (inclusive)
highporthighest port number this system is allowed to allocate (exclusive)
Returns
handle to this system, NULL on error

Definition at line 368 of file testing.c.

References SharedService::cfg, GNUNET_TESTING_SharedService::cfg, cfg_copy_iterator(), getenv(), GNUNET_array_append, GNUNET_assert, GNUNET_CONFIGURATION_create(), GNUNET_CONFIGURATION_iterate_section_values(), GNUNET_DISK_mkdtemp(), GNUNET_free, GNUNET_new, GNUNET_OK, GNUNET_strdup, GNUNET_TESTING_PREFIX, GNUNET_TESTING_system_destroy(), GNUNET_YES, GNUNET_TESTING_System::highport, hostkeys_load(), GNUNET_TESTING_System::hostname, GNUNET_TESTING_System::lowport, GNUNET_TESTING_System::n_shared_services, GNUNET_TESTING_SharedService::service, SharedService::share, GNUNET_TESTING_SharedService::share, GNUNET_TESTING_System::shared_services, SharedService::sname, SharedServiceInstance::ss, GNUNET_TESTING_System::tmppath, and GNUNET_TESTING_System::trusted_ip.

Referenced by GNUNET_TESTING_system_create().

375 {
376  struct GNUNET_TESTING_System *system;
377  struct GNUNET_TESTING_SharedService tss;
378  struct SharedService *ss;
379  unsigned int cnt;
380 
381  GNUNET_assert (NULL != testdir);
382  system = GNUNET_new (struct GNUNET_TESTING_System);
383  if (NULL == (system->tmppath = getenv (GNUNET_TESTING_PREFIX)))
384  system->tmppath = GNUNET_DISK_mkdtemp (testdir);
385  else
386  system->tmppath = GNUNET_strdup (system->tmppath);
387  system->lowport = lowport;
388  system->highport = highport;
389  if (NULL == system->tmppath)
390  {
391  GNUNET_free (system);
392  return NULL;
393  }
394  if (NULL != trusted_ip)
395  system->trusted_ip = GNUNET_strdup (trusted_ip);
396  if (NULL != hostname)
397  system->hostname = GNUNET_strdup (hostname);
398  if (GNUNET_OK != hostkeys_load (system))
399  {
401  return NULL;
402  }
403  if (NULL == shared_services)
404  return system;
405  for (cnt = 0; NULL != shared_services[cnt].service; cnt++)
406  {
407  tss = shared_services[cnt];
408  ss = GNUNET_new (struct SharedService);
409  ss->sname = GNUNET_strdup (tss.service);
412  ss->sname,
414  ss->cfg);
416  "TESTING",
418  ss->cfg);
420  "PATHS",
422  ss->cfg);
423  ss->share = tss.share;
425  system->n_shared_services,
426  ss);
427  }
428  return system;
429 }
struct GNUNET_CONFIGURATION_Handle * cfg
Definition: testing.c:83
The structure for identifying a shared service.
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.
uint16_t lowport
Lowest port we are allowed to use.
Definition: testing.c:158
Specification of a service that is to be shared among peers.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
unsigned int share
Definition: testing.c:87
static int hostkeys_load(struct GNUNET_TESTING_System *system)
Testing includes a number of pre-created hostkeys for faster peer startup.
Definition: testing.c:252
unsigned int n_shared_services
Definition: testing.c:128
#define GNUNET_TESTING_PREFIX
The environmental variable, if set, that dictates where testing should place generated peer configura...
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(void)
Create a new configuration object.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
char * sname
Definition: testing.c:79
void GNUNET_TESTING_system_destroy(struct GNUNET_TESTING_System *system, int remove_paths)
Free system resources.
Definition: testing.c:534
struct SharedService ** shared_services
Definition: testing.c:126
char * GNUNET_DISK_mkdtemp(const char *t)
Create an (empty) temporary directory on disk.
Definition: disk.c:409
const char * service
The name of the service.
char * getenv()
Handle for a system on which GNUnet peers are executed; a system is used for reserving unique paths a...
Definition: testing.c:97
#define GNUNET_array_append(arr, size, element)
Append an element to a list (growing the list by one).
uint16_t highport
Highest port we are allowed to use.
Definition: testing.c:163
static char * hostname
Our hostname; we give this to all the peers we start.
static void cfg_copy_iterator(void *cls, const char *section, const char *option, const char *value)
Function to iterate over options.
Definition: testing.c:335
char * hostname
our hostname
Definition: testing.c:114
#define GNUNET_YES
Definition: gnunet_common.h:77
char * tmppath
Prefix (i.e.
Definition: testing.c:103
#define GNUNET_free(ptr)
Wrapper around free.
char * trusted_ip
The trusted ip.
Definition: testing.c:109
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_system_destroy()

void GNUNET_TESTING_system_destroy ( struct GNUNET_TESTING_System system,
int  remove_paths 
)

Free system resources.

Parameters
systemsystem to be freed
remove_pathsshould the 'testdir' and all subdirectories be removed (clean up on shutdown)?

Definition at line 534 of file testing.c.

References SharedService::cfg, cleanup_shared_service_instance(), GNUNET_CONFIGURATION_destroy(), GNUNET_DISK_directory_remove(), GNUNET_free, GNUNET_free_non_null, GNUNET_YES, GNUNET_TESTING_System::hostkeys_data, hostkeys_unload(), GNUNET_TESTING_System::hostname, SharedService::instances, SharedService::n_instances, GNUNET_TESTING_System::n_shared_services, SharedServiceInstance::proc, GNUNET_TESTING_System::shared_services, SharedService::sname, SharedServiceInstance::ss, stop_shared_service_instance(), GNUNET_TESTING_System::tmppath, and GNUNET_TESTING_System::trusted_ip.

Referenced by create_hostkeys(), create_unique_cfgs(), GNUNET_TESTING_service_run(), GNUNET_TESTING_system_create_with_portrange(), GNUNET_TRANSPORT_TESTING_done(), and shutdown_task().

536 {
537  struct SharedService *ss;
538  struct SharedServiceInstance *i;
539  unsigned int ss_cnt;
540  unsigned int i_cnt;
541 
542  if (NULL != system->hostkeys_data)
543  hostkeys_unload (system);
544  for (ss_cnt = 0; ss_cnt < system->n_shared_services; ss_cnt++)
545  {
546  ss = system->shared_services[ss_cnt];
547  for (i_cnt = 0; i_cnt < ss->n_instances; i_cnt++)
548  {
549  i = ss->instances[i_cnt];
550  if (NULL != i->proc)
553  }
556  GNUNET_free (ss->sname);
557  GNUNET_free (ss);
558  }
560  if (GNUNET_YES == remove_paths)
562  GNUNET_free (system->tmppath);
564  GNUNET_free_non_null (system->hostname);
565  GNUNET_free (system);
566 }
struct GNUNET_CONFIGURATION_Handle * cfg
Definition: testing.c:83
The structure for identifying a shared service.
static void cleanup_shared_service_instance(struct SharedServiceInstance *i)
Definition: testing.c:469
unsigned int n_instances
Definition: testing.c:89
struct GNUNET_OS_Process * proc
Definition: testing.c:68
unsigned int n_shared_services
Definition: testing.c:128
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
int GNUNET_DISK_directory_remove(const char *filename)
Remove all files in a directory (rm -rf).
Definition: disk.c:1029
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
char * sname
Definition: testing.c:79
struct SharedService ** shared_services
Definition: testing.c:126
static void hostkeys_unload(struct GNUNET_TESTING_System *system)
Function to remove the loaded hostkeys.
Definition: testing.c:315
static void stop_shared_service_instance(struct SharedServiceInstance *i)
Definition: testing.c:513
struct SharedServiceInstance ** instances
Definition: testing.c:81
char * hostkeys_data
Hostkeys data, contains "GNUNET_TESTING_HOSTKEYFILESIZE * total_hostkeys" bytes.
Definition: testing.c:119
char * hostname
our hostname
Definition: testing.c:114
#define GNUNET_YES
Definition: gnunet_common.h:77
char * tmppath
Prefix (i.e.
Definition: testing.c:103
#define GNUNET_free(ptr)
Wrapper around free.
char * trusted_ip
The trusted ip.
Definition: testing.c:109
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_hostkey_get()

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.

This function can be used to access the n-th key of those pre-created hostkeys; note that these keys are ONLY useful for testing and not secure as the private keys are part of the public GNUnet source code.

This is primarily a helper function used internally by GNUNET_TESTING_peer_configure().

Parameters
systemthe testing system handle
key_numberdesired pre-created hostkey to obtain
idset to the peer's identity (hash of the public key; if NULL, GNUNET_SYSERR is returned immediately
Returns
NULL on error (not enough keys)

This function can be used to access the n-th key of those pre-created hostkeys; note that these keys are ONLY useful for testing and not secure as the private keys are part of the public GNUnet source code.

This is primarily a helper function used internally by GNUNET_TESTING_peer_configure.

Parameters
systemthe testing system handle
key_numberdesired pre-created hostkey to obtain
idset to the peer's identity (hash of the public key; if NULL, NULL is returned immediately
Returns
NULL on error (not enough keys)

Definition at line 710 of file testing.c.

References _, GNUNET_CRYPTO_eddsa_key_get_public(), GNUNET_ERROR_TYPE_ERROR, GNUNET_memcpy, GNUNET_new, GNUNET_TESTING_HOSTKEYFILESIZE, GNUNET_TESTING_System::hostkeys_data, LOG, GNUNET_PeerIdentity::public_key, and GNUNET_TESTING_System::total_hostkeys.

Referenced by create_hostkeys(), GNUNET_TESTING_peer_configure(), and GNUNET_TESTING_peer_get_identity().

713 {
714  struct GNUNET_CRYPTO_EddsaPrivateKey *private_key;
715 
716  if ((NULL == id) || (NULL == system->hostkeys_data))
717  return NULL;
718  if (key_number >= system->total_hostkeys)
719  {
721  _ ("Key number %u does not exist\n"),
722  key_number);
723  return NULL;
724  }
725  private_key = GNUNET_new (struct GNUNET_CRYPTO_EddsaPrivateKey);
726  GNUNET_memcpy (private_key,
727  system->hostkeys_data
728  + (key_number * GNUNET_TESTING_HOSTKEYFILESIZE),
729  GNUNET_TESTING_HOSTKEYFILESIZE);
731  return private_key;
732 }
#define LOG(kind,...)
Definition: testing.c:37
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#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:153
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
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:270
Private ECC key encoded for transmission.
char * hostkeys_data
Hostkeys data, contains "GNUNET_TESTING_HOSTKEYFILESIZE * total_hostkeys" bytes.
Definition: testing.c:119
struct GNUNET_CRYPTO_EddsaPublicKey public_key
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_reserve_port()

uint16_t GNUNET_TESTING_reserve_port ( struct GNUNET_TESTING_System system)

Reserve a port for a peer.

Parameters
systemsystem to use for reservation tracking
Returns
0 if no free port was available

Reserve a port for a peer.

Parameters
systemsystem to use for reservation tracking
Returns
0 if no free port was available

Definition at line 576 of file testing.c.

References ai, AI_NUMERICSERV, GNUNET_asprintf(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_NETWORK_socket_bind(), GNUNET_NETWORK_socket_close(), GNUNET_NETWORK_socket_create(), GNUNET_NO, GNUNET_OK, GNUNET_TESTING_System::highport, LOG, GNUNET_TESTING_System::lowport, GNUNET_TESTING_System::reserved_ports, and ret.

Referenced by associate_shared_service(), and update_config().

577 {
578  struct GNUNET_NETWORK_Handle *socket;
579  struct addrinfo hint;
580  struct addrinfo *ret;
581  struct addrinfo *ai;
582  uint32_t *port_buckets;
583  char *open_port_str;
584  int bind_status;
585  uint32_t xor_image;
586  uint16_t index;
587  uint16_t open_port;
588  uint16_t pos;
589 
590  /*
591  FIXME: Instead of using getaddrinfo we should try to determine the port
592  status by the following heurestics.
593 
594  On systems which support both IPv4 and IPv6, only ports open on both
595  address families are considered open.
596  On system with either IPv4 or IPv6. A port is considered open if it's
597  open in the respective address family
598  */hint.ai_family = AF_UNSPEC; /* IPv4 and IPv6 */
599  hint.ai_socktype = 0;
600  hint.ai_protocol = 0;
601  hint.ai_addrlen = 0;
602  hint.ai_addr = NULL;
603  hint.ai_canonname = NULL;
604  hint.ai_next = NULL;
605  hint.ai_flags = AI_PASSIVE | AI_NUMERICSERV; /* Wild card address */
606  port_buckets = system->reserved_ports;
607  for (index = (system->lowport / 32) + 1; index < (system->highport / 32);
608  index++)
609  {
610  xor_image = (UINT32_MAX ^ port_buckets[index]);
611  if (0 == xor_image) /* Ports in the bucket are full */
612  continue;
613  pos = system->lowport % 32;
614  while (pos < 32)
615  {
616  if (0 == ((xor_image >> pos) & 1U))
617  {
618  pos++;
619  continue;
620  }
621  open_port = (index * 32) + pos;
622  if (open_port >= system->highport)
623  return 0;
624  GNUNET_asprintf (&open_port_str, "%u", (unsigned int) open_port);
625  ret = NULL;
626  GNUNET_assert (0 == getaddrinfo (NULL, open_port_str, &hint, &ret));
627  GNUNET_free (open_port_str);
628  bind_status = GNUNET_NO;
629  for (ai = ret; NULL != ai; ai = ai->ai_next)
630  {
631  socket = GNUNET_NETWORK_socket_create (ai->ai_family, SOCK_STREAM, 0);
632  if (NULL == socket)
633  continue;
634  bind_status =
635  GNUNET_NETWORK_socket_bind (socket, ai->ai_addr, ai->ai_addrlen);
637  if (GNUNET_OK != bind_status)
638  break;
639  socket = GNUNET_NETWORK_socket_create (ai->ai_family, SOCK_DGRAM, 0);
640  if (NULL == socket)
641  continue;
642  bind_status =
643  GNUNET_NETWORK_socket_bind (socket, ai->ai_addr, ai->ai_addrlen);
645  if (GNUNET_OK != bind_status)
646  break;
647  }
648  port_buckets[index] |= (1U << pos); /* Set the port bit */
649  freeaddrinfo (ret);
650  if (GNUNET_OK == bind_status)
651  {
653  "Found a free port %u\n",
654  (unsigned int) open_port);
655  return open_port;
656  }
657  pos++;
658  }
659  }
660  return 0;
661 }
#define AI_NUMERICSERV
AI_NUMERICSERV not defined in windows.
Definition: platform.h:227
uint16_t lowport
Lowest port we are allowed to use.
Definition: testing.c:158
uint32_t reserved_ports[65536/32]
Bitmap where each port that has already been reserved for some GNUnet peer is recorded.
Definition: testing.c:138
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define LOG(kind,...)
Definition: testing.c:37
int GNUNET_NETWORK_socket_bind(struct GNUNET_NETWORK_Handle *desc, const struct sockaddr *address, socklen_t address_len)
Bind a socket to a particular address.
Definition: network.c:485
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
static struct GNUNET_TRANSPORT_AddressIdentifier * ai
Handle to the operation that publishes our address.
uint16_t highport
Highest port we are allowed to use.
Definition: testing.c:163
handle to a socket
Definition: network.c:52
int GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition: network.c:560
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_create(int domain, int type, int protocol)
Create a new socket.
Definition: network.c:912
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_release_port()

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

Parameters
systemsystem to use for reservation tracking
portreserved port to release

Release reservation of a TCP or UDP port for a peer (used during GNUNET_TESTING_peer_destroy).

Parameters
systemsystem to use for reservation tracking
portreserved port to release

Definition at line 672 of file testing.c.

References GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, LOG, and GNUNET_TESTING_System::reserved_ports.

Referenced by GNUNET_TESTING_peer_destroy().

674 {
675  uint32_t *port_buckets;
676  uint16_t bucket;
677  uint16_t pos;
678 
679  port_buckets = system->reserved_ports;
680  bucket = port / 32;
681  pos = port % 32;
682  LOG (GNUNET_ERROR_TYPE_DEBUG, "Releasing port %u\n", port);
683  if (0 == (port_buckets[bucket] & (1U << pos)))
684  {
685  GNUNET_break (0); /* Port was not reserved by us using reserve_port() */
686  return;
687  }
688  port_buckets[bucket] &= ~(1U << pos);
689 }
uint32_t reserved_ports[65536/32]
Bitmap where each port that has already been reserved for some GNUnet peer is recorded.
Definition: testing.c:138
#define LOG(kind,...)
Definition: testing.c:37
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static uint16_t port
Port number.
Definition: gnunet-bcd.c:81
Here is the caller graph for this function:

◆ GNUNET_TESTING_configuration_create()

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.

The default configuration will be available in PATHS section under the option DEFAULTCONFIG after the call. SERVICE_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
Returns
GNUNET_OK on success, GNUNET_SYSERR on error - the configuration will be incomplete and should not be used there upon

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
Returns
GNUNET_OK on success, GNUNET_SYSERR on error - the configuration will be incomplete and should not be used there upon

Definition at line 1145 of file testing.c.

References GNUNET_TESTING_configuration_create_().

Referenced by create_unique_cfgs(), GNUNET_TRANSPORT_TESTING_start_peer(), and tokenizer_cb().

1147 {
1148  return GNUNET_TESTING_configuration_create_ (system, cfg, NULL, NULL);
1149 }
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 modif...
Definition: testing.c:1082
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_peer_configure()

struct GNUNET_TESTING_Peer* GNUNET_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.

GNUnet must be installed on the local system and available in the PATH.

Parameters
systemsystem to use to coordinate resource usage
cfgconfiguration to use; will be UPDATED (to reflect needed changes in port numbers and paths)
key_numbernumber of the hostkey to use for the peer
ididentifier for the daemon, will be set, can be NULL
emsgset to freshly allocated error message (set to NULL on success), can be NULL
Returns
handle to the peer, NULL on error

Definition at line 1166 of file testing.c.

References _, GNUNET_TESTING_Peer::args, associate_shared_service(), GNUNET_TESTING_Peer::cfg, GNUNET_TESTING_Peer::cfgfile, GNUNET_DISK_FileHandle::fd, GNUNET_asprintf(), GNUNET_assert, GNUNET_CONFIGURATION_dup(), GNUNET_CONFIGURATION_get_value_filename(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONFIGURATION_have_value(), GNUNET_CONFIGURATION_remove_section(), GNUNET_CONFIGURATION_write(), GNUNET_DISK_file_close(), GNUNET_DISK_file_open(), GNUNET_DISK_file_write(), GNUNET_DISK_OPEN_CREATE, GNUNET_DISK_OPEN_WRITE, GNUNET_DISK_PERM_USER_READ, GNUNET_DISK_PERM_USER_WRITE, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_free_non_null, GNUNET_log, GNUNET_malloc, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_OS_get_libexec_binary_path(), GNUNET_strdup, GNUNET_SYSERR, GNUNET_TESTING_configuration_create_(), GNUNET_TESTING_hostkey_get(), GNUNET_TESTING_HOSTKEYFILESIZE, GNUNET_TESTING_System::hostkeys_data, GNUNET_TESTING_Peer::key_number, GNUNET_TESTING_Peer::main_binary, GNUNET_TESTING_System::n_shared_services, GNUNET_TESTING_Peer::nports, peer, pk, GNUNET_TESTING_Peer::ports, GNUNET_TESTING_System::shared_services, SharedService::sname, SharedServiceInstance::ss, GNUNET_TESTING_Peer::ss_instances, GNUNET_TESTING_Peer::system, and GNUNET_TESTING_System::total_hostkeys.

Referenced by GNUNET_TESTING_service_run(), GNUNET_TRANSPORT_TESTING_start_peer(), handle_peer_create(), and update_peer_config().

1171 {
1172  struct GNUNET_TESTING_Peer *peer;
1173  struct GNUNET_DISK_FileHandle *fd;
1174  char *hostkey_filename;
1175  char *config_filename;
1176  char *libexec_binary;
1177  char *emsg_;
1179  uint16_t *ports;
1180  struct SharedService *ss;
1181  struct SharedServiceInstance **ss_instances;
1182  unsigned int cnt;
1183  unsigned int nports;
1184 
1185  ports = NULL;
1186  nports = 0;
1187  ss_instances = NULL;
1188  if (NULL != emsg)
1189  *emsg = NULL;
1190  if (key_number >= system->total_hostkeys)
1191  {
1192  GNUNET_asprintf (
1193  &emsg_,
1194  _ (
1195  "You attempted to create a testbed with more than %u hosts. Please precompute more hostkeys first.\n"),
1196  (unsigned int) system->total_hostkeys);
1197  goto err_ret;
1198  }
1199  pk = NULL;
1200  if ((NULL != id) &&
1201  (NULL == (pk = GNUNET_TESTING_hostkey_get (system, key_number, id))))
1202  {
1203  GNUNET_asprintf (&emsg_,
1204  _ ("Failed to initialize hostkey for peer %u\n"),
1205  (unsigned int) key_number);
1206  goto err_ret;
1207  }
1208  if (NULL != pk)
1209  GNUNET_free (pk);
1210  if (GNUNET_NO == GNUNET_CONFIGURATION_have_value (cfg, "PEER", "PRIVATE_KEY"))
1211  {
1212  GNUNET_asprintf (
1213  &emsg_,
1214  _ ("PRIVATE_KEY option in PEER section missing in configuration\n"));
1215  goto err_ret;
1216  }
1217  /* Remove sections for shared services */
1218  for (cnt = 0; cnt < system->n_shared_services; cnt++)
1219  {
1220  ss = system->shared_services[cnt];
1222  }
1223  if (GNUNET_OK !=
1224  GNUNET_TESTING_configuration_create_ (system, cfg, &ports, &nports))
1225  {
1226  GNUNET_asprintf (&emsg_,
1227  _ ("Failed to create configuration for peer "
1228  "(not enough free ports?)\n"));
1229  goto err_ret;
1230  }
1233  "PEER",
1234  "PRIVATE_KEY",
1235  &hostkey_filename));
1236  fd = GNUNET_DISK_file_open (hostkey_filename,
1240  if (NULL == fd)
1241  {
1242  GNUNET_asprintf (&emsg_,
1243  _ ("Cannot open hostkey file `%s': %s\n"),
1244  hostkey_filename,
1245  strerror (errno));
1246  GNUNET_free (hostkey_filename);
1247  goto err_ret;
1248  }
1249  GNUNET_free (hostkey_filename);
1252  system->hostkeys_data
1253  + (key_number * GNUNET_TESTING_HOSTKEYFILESIZE),
1254  GNUNET_TESTING_HOSTKEYFILESIZE))
1255  {
1256  GNUNET_asprintf (&emsg_,
1257  _ ("Failed to write hostkey file for peer %u: %s\n"),
1258  (unsigned int) key_number,
1259  strerror (errno));
1261  goto err_ret;
1262  }
1264  ss_instances = GNUNET_malloc (sizeof(struct SharedServiceInstance *)
1265  * system->n_shared_services);
1266  for (cnt = 0; cnt < system->n_shared_services; cnt++)
1267  {
1268  ss = system->shared_services[cnt];
1269  ss_instances[cnt] = associate_shared_service (system, ss, cfg);
1270  if (NULL == ss_instances[cnt])
1271  {
1272  emsg_ = GNUNET_strdup ("FIXME");
1273  goto err_ret;
1274  }
1275  }
1278  "PATHS",
1279  "DEFAULTCONFIG",
1280  &config_filename));
1281  if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, config_filename))
1282  {
1283  GNUNET_asprintf (&emsg_,
1284  _ (
1285  "Failed to write configuration file `%s' for peer %u: %s\n"),
1286  config_filename,
1287  (unsigned int) key_number,
1288  strerror (errno));
1289  GNUNET_free (config_filename);
1290  goto err_ret;
1291  }
1292  peer = GNUNET_new (struct GNUNET_TESTING_Peer);
1293  peer->ss_instances = ss_instances;
1294  peer->cfgfile = config_filename; /* Free in peer_destroy */
1295  peer->cfg = GNUNET_CONFIGURATION_dup (cfg);
1296  libexec_binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm");
1297  if (GNUNET_SYSERR ==
1299  "arm",
1300  "PREFIX",
1301  &peer->main_binary))
1302  {
1303  /* No prefix */
1304  GNUNET_asprintf (&peer->main_binary, "%s", libexec_binary);
1305  peer->args = GNUNET_strdup ("");
1306  }
1307  else
1308  {
1309  peer->args = GNUNET_strdup (libexec_binary);
1310  }
1311  peer->system = system;
1312  peer->key_number = key_number;
1313  GNUNET_free (libexec_binary);
1314  peer->ports = ports; /* Free in peer_destroy */
1315  peer->nports = nports;
1316  return peer;
1317 
1318 err_ret:
1319  GNUNET_free_non_null (ss_instances);
1320  GNUNET_free_non_null (ports);
1321  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s", emsg_);
1322  if (NULL != emsg)
1323  *emsg = emsg_;
1324  else
1325  GNUNET_free (emsg_);
1326  return NULL;
1327 }
Create file if it doesn&#39;t exist.
static struct GNUNET_CRYPTO_EddsaPrivateKey * pk
Private key of this peer.
int GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1345
The structure for identifying a shared service.
int GNUNET_CONFIGURATION_write(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Write configuration file.
unsigned int nports
The number of ports in the above array.
Definition: testing.c:235
Handle for a GNUnet peer controlled by testing.
Definition: testing.c:170
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:710
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
unsigned int n_shared_services
Definition: testing.c:128
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
uint16_t * ports
Array of ports currently allocated to this peer.
Definition: testing.c:230
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
static struct SharedServiceInstance * associate_shared_service(struct GNUNET_TESTING_System *system, struct SharedService *ss, struct GNUNET_CONFIGURATION_Handle *cfg)
Definition: testing.c:989
#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:153
char * main_binary
Binary to be executed during &#39;GNUNET_TESTING_peer_start&#39;.
Definition: testing.c:188
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
ssize_t GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition: disk.c:820
struct GNUNET_TESTING_System * system
The TESTING system associated with this peer.
Definition: testing.c:175
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_remove_section(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
Remove the given section and all options in it.
struct GNUNET_CONFIGURATION_Handle * cfg
The config of the peer.
Definition: testing.c:205
char * cfgfile
Path to the configuration file for this peer.
Definition: testing.c:180
char * sname
Definition: testing.c:79
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_TESTBED_Peer * peer
The peer associated with this model.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
struct SharedService ** shared_services
Definition: testing.c:126
Open the file for writing.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_dup(const struct GNUNET_CONFIGURATION_Handle *cfg)
Duplicate an existing configuration object.
Private ECC key encoded for transmission.
#define GNUNET_log(kind,...)
char * hostkeys_data
Hostkeys data, contains "GNUNET_TESTING_HOSTKEYFILESIZE * total_hostkeys" bytes.
Definition: testing.c:119
int GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
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 ...
uint32_t key_number
The keynumber of this peer&#39;s hostkey.
Definition: testing.c:240
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 modif...
Definition: testing.c:1082
int fd
File handle on Unix-like systems.
struct SharedServiceInstance ** ss_instances
Definition: testing.c:223
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:1268
Handle used to access files (and pipes).
#define GNUNET_malloc(size)
Wrapper around malloc.
#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_peer_get_identity()

void GNUNET_TESTING_peer_get_identity ( struct GNUNET_TESTING_Peer peer,
struct GNUNET_PeerIdentity id 
)

Obtain the peer identity from a peer handle.

Parameters
peerpeer handle for which we want the peer's identity
ididentifier for the daemon, will be set

Definition at line 1337 of file testing.c.

References GNUNET_free, GNUNET_memcpy, GNUNET_new, GNUNET_TESTING_hostkey_get(), GNUNET_TESTING_Peer::id, GNUNET_TESTING_Peer::key_number, and GNUNET_TESTING_Peer::system.

Referenced by GNUNET_TRANSPORT_TESTING_start_peer(), handle_overlay_connect(), handle_peer_get_config(), and handle_remote_overlay_connect().

1339 {
1340  if (NULL != peer->id)
1341  {
1342  GNUNET_memcpy (id, peer->id, sizeof(struct GNUNET_PeerIdentity));
1343  return;
1344  }
1345  peer->id = GNUNET_new (struct GNUNET_PeerIdentity);
1346  GNUNET_free (
1347  GNUNET_TESTING_hostkey_get (peer->system, peer->key_number, peer->id));
1348  GNUNET_memcpy (id, peer->id, sizeof(struct GNUNET_PeerIdentity));
1349 }
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:710
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_TESTING_System * system
The TESTING system associated with this peer.
Definition: testing.c:175
The identity of the host (wraps the signing key of the peer).
uint32_t key_number
The keynumber of this peer&#39;s hostkey.
Definition: testing.c:240
struct GNUNET_PeerIdentity * id
The cached identity of this peer.
Definition: testing.c:221
#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_peer_start()

int GNUNET_TESTING_peer_start ( struct GNUNET_TESTING_Peer peer)

Start the peer.

Parameters
peerpeer to start
Returns
GNUNET_OK on success, GNUNET_SYSERR on error (i.e. peer already running)

Definition at line 1359 of file testing.c.

References _, GNUNET_TESTING_Peer::args, GNUNET_TESTING_Peer::cfg, GNUNET_TESTING_Peer::cfgfile, GNUNET_assert, GNUNET_break, GNUNET_CONFIGURATION_expand_dollar(), GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OK, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, GNUNET_OS_start_process_s(), GNUNET_SYSERR, GNUNET_TESTING_Peer::main_binary, GNUNET_TESTING_Peer::main_process, SharedServiceInstance::n_refs, GNUNET_TESTING_System::n_shared_services, PIPE_CONTROL, GNUNET_TESTING_Peer::ss_instances, start_shared_service_instance(), and GNUNET_TESTING_Peer::system.

Referenced by GNUNET_TESTING_service_run(), GNUNET_TRANSPORT_TESTING_restart_peer(), GNUNET_TRANSPORT_TESTING_start_peer(), start_peer(), and stdin_cb().

1360 {
1361  struct SharedServiceInstance *i;
1362  unsigned int cnt;
1363 
1364  if (NULL != peer->main_process)
1365  {
1366  GNUNET_break (0);
1367  return GNUNET_SYSERR;
1368  }
1369  GNUNET_assert (NULL != peer->cfgfile);
1370  for (cnt = 0; cnt < peer->system->n_shared_services; cnt++)
1371  {
1372  i = peer->ss_instances[cnt];
1373  if ((0 == i->n_refs) &&
1375  return GNUNET_SYSERR;
1376  i->n_refs++;
1377  }
1378  peer->main_binary =
1380  peer->main_process =
1383  NULL,
1384  peer->main_binary,
1385  peer->args,
1386  "-c",
1387  peer->cfgfile,
1388  NULL);
1389  if (NULL == peer->main_process)
1390  {
1392  _ ("Failed to start `%s': %s\n"),
1393  peer->main_binary,
1394  strerror (errno));
1395  return GNUNET_SYSERR;
1396  }
1397  return GNUNET_OK;
1398 }
#define PIPE_CONTROL
We need pipe control only on WINDOWS.
Definition: testing.c:43
char * GNUNET_CONFIGURATION_expand_dollar(const struct GNUNET_CONFIGURATION_Handle *cfg, char *orig)
Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR" where either in the "PATHS" section or...
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static int start_shared_service_instance(struct SharedServiceInstance *i)
Definition: testing.c:485
unsigned int n_shared_services
Definition: testing.c:128
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
char * main_binary
Binary to be executed during &#39;GNUNET_TESTING_peer_start&#39;.
Definition: testing.c:188
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
struct GNUNET_TESTING_System * system
The TESTING system associated with this peer.
Definition: testing.c:175
struct GNUNET_CONFIGURATION_Handle * cfg
The config of the peer.
Definition: testing.c:205
char * cfgfile
Path to the configuration file for this peer.
Definition: testing.c:180
When these flags are set, the child process will inherit stdout and stderr of the parent...
Definition: gnunet_os_lib.h:97
unsigned int n_refs
Definition: testing.c:74
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
struct GNUNET_OS_Process * main_process
Handle to the running binary of the service, NULL if the peer/service is currently not running...
Definition: testing.c:195
struct GNUNET_OS_Process * GNUNET_OS_start_process_s(int pipe_control, unsigned int std_inheritance, const int *lsocks, const char *filename,...)
Start a process.
Definition: os_priority.c:762
#define GNUNET_log(kind,...)
struct SharedServiceInstance ** ss_instances
Definition: testing.c:223
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_peer_stop()

int GNUNET_TESTING_peer_stop ( struct GNUNET_TESTING_Peer peer)

Stop the peer.

This call is blocking as it kills the peer's main ARM process by sending a SIGTERM and waits on it. For asynchronous shutdown of peer, see GNUNET_TESTING_peer_stop_async().

Parameters
peerpeer to stop
Returns
GNUNET_OK on success, GNUNET_SYSERR on error (i.e. peer not running)
Parameters
peerpeer to stop
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 1464 of file testing.c.

References GNUNET_OK, GNUNET_SYSERR, GNUNET_TESTING_peer_kill(), and GNUNET_TESTING_peer_wait().

Referenced by GNUNET_TESTING_peer_destroy(), GNUNET_TESTING_service_run(), GNUNET_TRANSPORT_TESTING_restart_peer(), GNUNET_TRANSPORT_TESTING_stop_peer(), GST_destroy_peer(), and stdin_cb().

1465 {
1467  return GNUNET_SYSERR;
1469  return GNUNET_SYSERR;
1470  return GNUNET_OK;
1471 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
int GNUNET_TESTING_peer_kill(struct GNUNET_TESTING_Peer *peer)
Sends SIGTERM to the peer&#39;s main process.
Definition: testing.c:1409
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
int GNUNET_TESTING_peer_wait(struct GNUNET_TESTING_Peer *peer)
Waits for a peer to terminate.
Definition: testing.c:1441
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_peer_destroy()

void GNUNET_TESTING_peer_destroy ( struct GNUNET_TESTING_Peer peer)

Destroy the peer.

Releases resources locked during peer configuration. If the peer is still running, it will be stopped AND a warning will be printed (users of the API should stop the peer explicitly first).

Parameters
peerpeer to destroy

Definition at line 1556 of file testing.c.

References GNUNET_TESTING_Peer::ah, GNUNET_TESTING_Peer::args, GNUNET_TESTING_Peer::cfg, GNUNET_TESTING_Peer::cfgfile, GNUNET_ARM_disconnect(), GNUNET_CONFIGURATION_destroy(), GNUNET_free, GNUNET_free_non_null, GNUNET_TESTING_peer_stop(), GNUNET_TESTING_release_port(), GNUNET_TESTING_Peer::id, GNUNET_TESTING_Peer::main_binary, GNUNET_TESTING_Peer::main_process, GNUNET_TESTING_Peer::nports, GNUNET_TESTING_Peer::ports, GNUNET_TESTING_Peer::ss_instances, and GNUNET_TESTING_Peer::system.

Referenced by GNUNET_TESTING_service_run(), GNUNET_TRANSPORT_TESTING_stop_peer(), GST_destroy_peer(), GST_destroy_peers(), and update_peer_config().

1557 {
1558  unsigned int cnt;
1559 
1560  if (NULL != peer->main_process)
1561  GNUNET_TESTING_peer_stop (peer);
1562  if (NULL != peer->ah)
1563  GNUNET_ARM_disconnect (peer->ah);
1564  GNUNET_free (peer->cfgfile);
1565  if (NULL != peer->cfg)
1567  GNUNET_free (peer->main_binary);
1568  GNUNET_free (peer->args);
1569  GNUNET_free_non_null (peer->id);
1571  if (NULL != peer->ports)
1572  {
1573  for (cnt = 0; cnt < peer->nports; cnt++)
1574  GNUNET_TESTING_release_port (peer->system, peer->ports[cnt]);
1575  GNUNET_free (peer->ports);
1576  }
1577  GNUNET_free (peer);
1578 }
unsigned int nports
The number of ports in the above array.
Definition: testing.c:235
struct GNUNET_ARM_Handle * ah
The handle to the peer&#39;s ARM service.
Definition: testing.c:200
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
uint16_t * ports
Array of ports currently allocated to this peer.
Definition: testing.c:230
void GNUNET_ARM_disconnect(struct GNUNET_ARM_Handle *h)
Disconnect from the ARM service (if connected) and destroy the context.
Definition: arm_api.c:604
int GNUNET_TESTING_peer_stop(struct GNUNET_TESTING_Peer *peer)
Stop the peer.
Definition: testing.c:1464
char * main_binary
Binary to be executed during &#39;GNUNET_TESTING_peer_start&#39;.
Definition: testing.c:188
struct GNUNET_TESTING_System * system
The TESTING system associated with this peer.
Definition: testing.c:175
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
struct GNUNET_CONFIGURATION_Handle * cfg
The config of the peer.
Definition: testing.c:205
char * cfgfile
Path to the configuration file for this peer.
Definition: testing.c:180
struct GNUNET_OS_Process * main_process
Handle to the running binary of the service, NULL if the peer/service is currently not running...
Definition: testing.c:195
struct GNUNET_PeerIdentity * id
The cached identity of this peer.
Definition: testing.c:221
struct SharedServiceInstance ** ss_instances
Definition: testing.c:223
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()).
Definition: testing.c:672
#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_peer_kill()

int GNUNET_TESTING_peer_kill ( struct GNUNET_TESTING_Peer peer)

Sends SIGTERM to the peer's main process.

Parameters
peerthe handle to the peer
Returns
GNUNET_OK if successful; GNUNET_SYSERR if the main process is NULL or upon any error while sending SIGTERM

Definition at line 1409 of file testing.c.

References GNUNET_assert, GNUNET_break, GNUNET_OK, GNUNET_OS_process_kill(), GNUNET_SYSERR, GNUNET_TERM_SIG, GNUNET_TESTING_Peer::main_process, SharedServiceInstance::n_refs, GNUNET_TESTING_System::n_shared_services, GNUNET_TESTING_Peer::ss_instances, stop_shared_service_instance(), and GNUNET_TESTING_Peer::system.

Referenced by disconn_status(), GNUNET_TESTING_peer_stop(), GST_destroy_peers(), and stop_peer().

1410 {
1411  struct SharedServiceInstance *i;
1412  unsigned int cnt;
1413 
1414  if (NULL == peer->main_process)
1415  {
1416  GNUNET_break (0);
1417  return GNUNET_SYSERR;
1418  }
1420  return GNUNET_SYSERR;
1421  for (cnt = 0; cnt < peer->system->n_shared_services; cnt++)
1422  {
1423  i = peer->ss_instances[cnt];
1424  GNUNET_assert (0 != i->n_refs);
1425  i->n_refs--;
1426  if (0 == i->n_refs)
1428  }
1429  return GNUNET_OK;
1430 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
unsigned int n_shared_services
Definition: testing.c:128
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_TESTING_System * system
The TESTING system associated with this peer.
Definition: testing.c:175
unsigned int n_refs
Definition: testing.c:74
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
struct GNUNET_OS_Process * main_process
Handle to the running binary of the service, NULL if the peer/service is currently not running...
Definition: testing.c:195
static void stop_shared_service_instance(struct SharedServiceInstance *i)
Definition: testing.c:513
struct SharedServiceInstance ** ss_instances
Definition: testing.c:223
#define GNUNET_TERM_SIG
The termination signal.
Definition: platform.h:242
int GNUNET_OS_process_kill(struct GNUNET_OS_Process *proc, int sig)
Sends a signal to the process.
Definition: os_priority.c:225
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_peer_wait()

int GNUNET_TESTING_peer_wait ( struct GNUNET_TESTING_Peer peer)

Waits for a peer to terminate.

The peer's main process will also be destroyed.

Parameters
peerthe handle to the peer
Returns
GNUNET_OK if successful; GNUNET_SYSERR if the main process is NULL or upon any error while waiting

Definition at line 1441 of file testing.c.

References GNUNET_break, GNUNET_OS_process_destroy(), GNUNET_OS_process_wait(), GNUNET_SYSERR, GNUNET_TESTING_Peer::main_process, and ret.

Referenced by disconn_status(), GNUNET_TESTING_peer_stop(), GST_destroy_peers(), and handle_peer_stop().

1442 {
1443  int ret;
1444 
1445  if (NULL == peer->main_process)
1446  {
1447  GNUNET_break (0);
1448  return GNUNET_SYSERR;
1449  }
1450  ret = GNUNET_OS_process_wait (peer->main_process);
1452  peer->main_process = NULL;
1453  return ret;
1454 }
void GNUNET_OS_process_destroy(struct GNUNET_OS_Process *proc)
Cleans up process structure contents (OS-dependent) and deallocates it.
Definition: os_priority.c:287
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
struct GNUNET_OS_Process * main_process
Handle to the running binary of the service, NULL if the peer/service is currently not running...
Definition: testing.c:195
int GNUNET_OS_process_wait(struct GNUNET_OS_Process *proc)
Wait for a process to terminate.
Definition: os_priority.c:1000
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_peer_stop_async()

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.

Peer's shutdown is signaled through the GNUNET_TESTING_PeerStopCallback().

Parameters
peerthe peer to stop
cbthe callback to signal peer shutdown
cb_clsclosure for the cb
Returns
GNUNET_OK upon successfully giving the request to the ARM API (this does not mean that the peer is successfully stopped); GNUNET_SYSERR upon any error.

Peer's shutdown is signaled through the GNUNET_TESTING_PeerStopCallback().

Parameters
peerthe peer to stop
cbthe callback to signal peer shutdown
cb_clsclosure for the above callback
Returns
GNUNET_OK upon successfully giving the request to the ARM API (this does not mean that the peer is successfully stopped); GNUNET_SYSERR upon any error.

Definition at line 1515 of file testing.c.

References GNUNET_TESTING_Peer::ah, GNUNET_TESTING_Peer::cb, GNUNET_TESTING_Peer::cb_cls, GNUNET_TESTING_Peer::cfg, disconn_status(), GNUNET_ARM_connect(), GNUNET_OK, GNUNET_SYSERR, and GNUNET_TESTING_Peer::main_process.

Referenced by handle_peer_reconfigure().

1518 {
1519  if (NULL == peer->main_process)
1520  return GNUNET_SYSERR;
1521  peer->ah = GNUNET_ARM_connect (peer->cfg, &disconn_status, peer);
1522  if (NULL == peer->ah)
1523  return GNUNET_SYSERR;
1524  peer->cb = cb;
1525  peer->cb_cls = cb_cls;
1526  return GNUNET_OK;
1527 }
struct GNUNET_ARM_Handle * ah
The handle to the peer&#39;s ARM service.
Definition: testing.c:200
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
static void disconn_status(void *cls, int connected)
Function called whenever we connect to or disconnect from ARM.
Definition: testing.c:1482
void * cb_cls
The closure for the above callback.
Definition: testing.c:215
struct GNUNET_CONFIGURATION_Handle * cfg
The config of the peer.
Definition: testing.c:205
struct GNUNET_ARM_Handle * GNUNET_ARM_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_ARM_ConnectionStatusCallback conn_status, void *conn_status_cls)
Set up a context for communicating with ARM, then start connecting to the ARM service using that cont...
Definition: arm_api.c:579
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
struct GNUNET_OS_Process * main_process
Handle to the running binary of the service, NULL if the peer/service is currently not running...
Definition: testing.c:195
GNUNET_TESTING_PeerStopCallback cb
The callback to call asynchronously when a peer is stopped.
Definition: testing.c:210
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_peer_stop_async_cancel()

void GNUNET_TESTING_peer_stop_async_cancel ( struct GNUNET_TESTING_Peer peer)

Cancel a previous asynchronous peer stop request.

GNUNET_TESTING_peer_stop_async() should have been called before on the given peer. It is an error to call this function if the peer stop callback was already called

Parameters
peerthe peer on which GNUNET_TESTING_peer_stop_async() was called before.

Definition at line 1540 of file testing.c.

References GNUNET_TESTING_Peer::ah, GNUNET_ARM_disconnect(), and GNUNET_assert.

Referenced by cleanup_prc().

1541 {
1542  GNUNET_assert (NULL != peer->ah);
1543  GNUNET_ARM_disconnect (peer->ah);
1544  peer->ah = NULL;
1545 }
struct GNUNET_ARM_Handle * ah
The handle to the peer&#39;s ARM service.
Definition: testing.c:200
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void GNUNET_ARM_disconnect(struct GNUNET_ARM_Handle *h)
Disconnect from the ARM service (if connected) and destroy the context.
Definition: arm_api.c:604
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_peer_run()

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.

Starts a peer using the given configuration and then invokes the given callback. This function ALSO initializes the scheduler loop and should thus be called directly from "main". The testcase should self-terminate by invoking 'GNUNET_SCHEDULER_shutdown'.

Parameters
testdironly the directory name without any path. This is used for all service homes; the directory will be created in a temporary location depending on the underlying OS
cfgfilenamename of the configuration file to use; use NULL to only run with defaults
tmmain function of the testcase
tm_clsclosure for 'tm'
Returns
0 on success, 1 on error

Starts a peer using the given configuration and then invokes the given callback. This function ALSO initializes the scheduler loop and should thus be called directly from "main". The testcase should self-terminate by invoking GNUNET_SCHEDULER_shutdown().

Parameters
testdironly the directory name without any path. This is used for all service homes; the directory will be created in a temporary location depending on the underlying OS
cfgfilenamename of the configuration file to use; use NULL to only run with defaults
tmmain function of the testcase
tm_clsclosure for tm
Returns
0 on success, 1 on error

Definition at line 1598 of file testing.c.

References GNUNET_TESTING_service_run().

Referenced by pre_run().

1602 {
1603  return GNUNET_TESTING_service_run (testdir, "arm", cfgfilename, tm, tm_cls);
1604 }
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 &#39;arm&#39;) and run a test u...
Definition: testing.c:1670
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_service_run()

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.

Starts a service using the given configuration and then invokes the given callback. This function ALSO initializes the scheduler loop and should thus be called directly from "main". The testcase should self-terminate by invoking 'GNUNET_SCHEDULER_shutdown'.

This function is useful if the testcase is for a single service and if that service doesn't itself depend on other services.

Parameters
testdironly the directory name without any path. This is used for all service homes; the directory will be created in a temporary location depending on the underlying OS
service_namename of the service to run
cfgfilenamename of the configuration file to use; use NULL to only run with defaults
tmmain function of the testcase
tm_clsclosure for tm
Returns
0 on success, 1 on error

Starts a service using the given configuration and then invokes the given callback. This function ALSO initializes the scheduler loop and should thus be called directly from "main". The testcase should self-terminate by invoking GNUNET_SCHEDULER_shutdown().

This function is useful if the testcase is for a single service and if that service doesn't itself depend on other services.

Parameters
testdironly the directory name without any path. This is used for all service homes; the directory will be created in a temporary location depending on the underlying OS
service_namename of the service to run
cfgfilenamename of the configuration file to use; use NULL to only run with defaults
tmmain function of the testcase
tm_clsclosure for tm
Returns
0 on success, 1 on error

Definition at line 1670 of file testing.c.

References _, GNUNET_TESTING_Peer::args, cfg, ServiceContext::cfg, GNUNET_asprintf(), GNUNET_CONFIGURATION_create(), GNUNET_CONFIGURATION_destroy(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONFIGURATION_load(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log_setup(), GNUNET_OK, GNUNET_OS_get_libexec_binary_path(), GNUNET_SCHEDULER_run(), GNUNET_strdup, GNUNET_SYSERR, GNUNET_TESTING_peer_configure(), GNUNET_TESTING_peer_destroy(), GNUNET_TESTING_peer_start(), GNUNET_TESTING_peer_stop(), GNUNET_TESTING_system_create(), GNUNET_TESTING_system_destroy(), GNUNET_YES, hostkeys_unload(), LOG, GNUNET_TESTING_Peer::main_binary, GNUNET_TESTING_Peer::main_process, peer, ServiceContext::peer, service_run_main(), ServiceContext::tm, and ServiceContext::tm_cls.

Referenced by GNUNET_TESTING_peer_run(), and run_no_scheduler().

1675 {
1676  struct ServiceContext sc;
1677  struct GNUNET_TESTING_System *system;
1678  struct GNUNET_TESTING_Peer *peer;
1680  char *binary;
1681  char *libexec_binary;
1682 
1683  GNUNET_log_setup (testdir, "WARNING", NULL);
1684  system = GNUNET_TESTING_system_create (testdir, "127.0.0.1", NULL, NULL);
1685  if (NULL == system)
1686  return 1;
1687  cfg = GNUNET_CONFIGURATION_create ();
1688  if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cfgfilename))
1689  {
1691  _ ("Failed to load configuration from %s\n"),
1692  cfgfilename);
1695  return 1;
1696  }
1697  peer = GNUNET_TESTING_peer_configure (system, cfg, 0, NULL, NULL);
1698  if (NULL == peer)
1699  {
1701  hostkeys_unload (system);
1703  return 1;
1704  }
1705  GNUNET_free (peer->main_binary);
1706  GNUNET_free (peer->args);
1707  GNUNET_asprintf (&binary, "gnunet-service-%s", service_name);
1708  libexec_binary = GNUNET_OS_get_libexec_binary_path (binary);
1709  if (GNUNET_SYSERR ==
1711  service_name,
1712  "PREFIX",
1713  &peer->main_binary))
1714  {
1715  /* No prefix */
1716  GNUNET_asprintf (&peer->main_binary, "%s", libexec_binary);
1717  peer->args = GNUNET_strdup ("");
1718  }
1719  else
1720  peer->args = GNUNET_strdup (libexec_binary);
1721 
1722  GNUNET_free (libexec_binary);
1723  GNUNET_free (binary);
1724  if (GNUNET_OK != GNUNET_TESTING_peer_start (peer))
1725  {
1729  return 1;
1730  }
1731  sc.cfg = cfg;
1732  sc.tm = tm;
1733  sc.tm_cls = tm_cls;
1734  sc.peer = peer;
1735  GNUNET_SCHEDULER_run (&service_run_main, &sc); /* Scheduler loop */
1736  if ((NULL != peer->main_process) &&
1737  (GNUNET_OK != GNUNET_TESTING_peer_stop (peer)))
1738  {
1742  return 1;
1743  }
1747  return 0;
1748 }
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
int GNUNET_TESTING_peer_start(struct GNUNET_TESTING_Peer *peer)
Start the peer.
Definition: testing.c:1359
Handle for a GNUnet peer controlled by testing.
Definition: testing.c:170
#define LOG(kind,...)
Definition: testing.c:37
void GNUNET_SCHEDULER_run(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Initialize and run scheduler.
Definition: scheduler.c:717
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(void)
Create a new configuration object.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
int GNUNET_TESTING_peer_stop(struct GNUNET_TESTING_Peer *peer)
Stop the peer.
Definition: testing.c:1464
char * main_binary
Binary to be executed during &#39;GNUNET_TESTING_peer_start&#39;.
Definition: testing.c:188
int GNUNET_CONFIGURATION_load(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Load configuration.
struct GNUNET_TESTING_Peer * GNUNET_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.
Definition: testing.c:1166
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
Structure for holding service data.
Definition: testing.c:1610
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
static char * service_name
Option -s: service name (hash to get service descriptor)
Definition: gnunet-vpn.c:51
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
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_TESTING_System * GNUNET_TESTING_system_create(const char *testdir, const char *trusted_ip, const char *hostname, const struct GNUNET_TESTING_SharedService *shared_services)
Create a system handle.
Definition: testing.c:453
void GNUNET_TESTING_system_destroy(struct GNUNET_TESTING_System *system, int remove_paths)
Free system resources.
Definition: testing.c:534
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
Handle for a system on which GNUnet peers are executed; a system is used for reserving unique paths a...
Definition: testing.c:97
static struct GNUNET_FS_SearchContext * sc
Definition: gnunet-search.c:37
struct GNUNET_OS_Process * main_process
Handle to the running binary of the service, NULL if the peer/service is currently not running...
Definition: testing.c:195
static void hostkeys_unload(struct GNUNET_TESTING_System *system)
Function to remove the loaded hostkeys.
Definition: testing.c:315
configuration data
Definition: configuration.c:85
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_YES
Definition: gnunet_common.h:77
int GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
void GNUNET_TESTING_peer_destroy(struct GNUNET_TESTING_Peer *peer)
Destroy the peer.
Definition: testing.c:1556
static void service_run_main(void *cls)
Callback to be called when SCHEDULER has been started.
Definition: testing.c:1640
#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_get_testname_from_underscore()

char* GNUNET_TESTING_get_testname_from_underscore ( const char *  argv0)

Sometimes we use the binary name to determine which specific test to run.

In those cases, the string after the last "_" in 'argv[0]' specifies a string that determines the configuration file or plugin to use.

This function returns the respective substring, taking care of issues such as binaries ending in '.exe' on W32.

Parameters
argv0the name of the binary
Returns
string between the last '_' and the '.exe' (or the end of the string), NULL if argv0 has no '_'

Definition at line 1765 of file testing.c.

References GNUNET_memcpy, GNUNET_strdup, and ret.

1766 {
1767  size_t slen = strlen (argv0) + 1;
1768  char sbuf[slen];
1769  char *ret;
1770  char *dot;
1771 
1772  GNUNET_memcpy (sbuf, argv0, slen);
1773  ret = strrchr (sbuf, '_');
1774  if (NULL == ret)
1775  return NULL;
1776  ret++; /* skip underscore */
1777  dot = strchr (ret, '.');
1778  if (NULL != dot)
1779  *dot = '\0';
1780  return GNUNET_strdup (ret);
1781 }
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.