GNUnet 0.21.0
Testing library

Library for writing testcases for GNUnet. More...

Collaboration diagram for Testing library:

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

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 63 of file gnunet_testing_lib.h.

◆ 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 70 of file gnunet_testing_lib.h.

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 350 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 394 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 477 of file testing.c.

482{
484 trusted_ip,
485 hostname,
486 shared_services,
487 LOW_PORT,
488 HIGH_PORT);
489}
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:392
#define HIGH_PORT
Highest port used for GNUnet testing.
Definition: testing.c:83
#define LOW_PORT
Lowest port used for GNUnet testing.
Definition: testing.c:76

References GNUNET_TESTING_system_create_with_portrange(), HIGH_PORT, GNUNET_TESTING_System::hostname, LOW_PORT, GNUNET_TESTING_System::shared_services, and GNUNET_TESTING_System::trusted_ip.

Referenced by create_hostkeys(), create_unique_cfgs(), GNUNET_TESTING_service_run(), GNUNET_TRANSPORT_TESTING_init(), and system_create_run().

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

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

399{
400 struct GNUNET_TESTING_System *system;
402 struct SharedService ss;
403 unsigned int cnt;
404
405 GNUNET_assert (NULL != testdir);
406 system = GNUNET_new (struct GNUNET_TESTING_System);
407 if (NULL == (system->tmppath = getenv (GNUNET_TESTING_PREFIX)))
408 system->tmppath = GNUNET_DISK_mkdtemp (testdir);
409 else
410 system->tmppath = GNUNET_strdup (system->tmppath);
411 system->lowport = lowport;
412 system->highport = highport;
413 if (NULL == system->tmppath)
414 {
415 GNUNET_free (system);
416 return NULL;
417 }
418 if (NULL != trusted_ip)
419 system->trusted_ip = GNUNET_strdup (trusted_ip);
420 if (NULL != hostname)
421 system->hostname = GNUNET_strdup (hostname);
422 if (GNUNET_OK != hostkeys_load (system))
423 {
425 return NULL;
426 }
427 if (NULL == shared_services)
428 return system;
429 for (cnt = 0; NULL != shared_services[cnt].service; cnt++)
430 {
431 tss = shared_services[cnt];
432 memset (&ss, 0, sizeof (ss));
433 ss.sname = GNUNET_strdup (tss.service);
434 ss.cfg = GNUNET_CONFIGURATION_create ();
436 ss.sname,
438 ss.cfg);
440 "TESTING",
442 ss.cfg);
444 "PATHS",
446 ss.cfg);
447 ss.share = tss.share;
449 system->n_shared_services,
450 ss);
451 }
452 return system;
453}
char * getenv()
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(void)
Create a new configuration object.
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.
char * GNUNET_DISK_mkdtemp(const char *t)
Create an (empty) temporary directory on disk.
Definition: disk.c:339
@ GNUNET_OK
@ GNUNET_YES
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_array_append(arr, len, element)
Append an element to an array (growing the array by one).
#define GNUNET_free(ptr)
Wrapper around free.
#define GNUNET_TESTING_PREFIX
The environmental variable, if set, that dictates where testing should place generated peer configura...
void GNUNET_TESTING_system_destroy(struct GNUNET_TESTING_System *system, int remove_paths)
Free system resources.
Definition: testing.c:557
Specification of a service that is to be shared among peers.
const char * service
The name of the service.
Handle for a system on which GNUnet peers are executed; a system is used for reserving unique paths a...
Definition: testing.c:122
uint16_t highport
Highest port we are allowed to use.
Definition: testing.c:187
char * trusted_ip
The trusted ip.
Definition: testing.c:133
char * tmppath
Prefix (e.g.
Definition: testing.c:127
unsigned int n_shared_services
Definition: testing.c:152
char * hostname
our hostname
Definition: testing.c:138
struct SharedService * shared_services
Definition: testing.c:150
uint16_t lowport
Lowest port we are allowed to use.
Definition: testing.c:182
static enum GNUNET_GenericReturnValue hostkeys_load(struct GNUNET_TESTING_System *system)
Testing includes a number of pre-created hostkeys for faster peer startup.
Definition: testing.c:276
static void cfg_copy_iterator(void *cls, const char *section, const char *option, const char *value)
Function to iterate over options.
Definition: testing.c:359

References GNUNET_TESTING_SharedService::cfg, 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, GNUNET_TESTING_SharedService::share, SharedService::share, GNUNET_TESTING_System::shared_services, SharedService::sname, GNUNET_TESTING_System::tmppath, and GNUNET_TESTING_System::trusted_ip.

Referenced by GNUNET_TESTING_system_create().

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

559{
560 struct SharedService *ss;
561 struct SharedServiceInstance *i;
562 unsigned int ss_cnt;
563 unsigned int i_cnt;
564
565 if (NULL != system->hostkeys_data)
566 hostkeys_unload (system);
567 for (ss_cnt = 0; ss_cnt < system->n_shared_services; ss_cnt++)
568 {
569 ss = &system->shared_services[ss_cnt];
570 for (i_cnt = 0; i_cnt < ss->n_instances; i_cnt++)
571 {
572 i = ss->instances[i_cnt];
573 if (NULL != i->proc)
576 }
580 }
582 if (GNUNET_YES == remove_paths)
584 GNUNET_free (system->tmppath);
585 GNUNET_free (system->trusted_ip);
586 GNUNET_free (system->hostname);
587 GNUNET_free (system);
588}
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_remove(const char *filename)
Remove all files in a directory (rm -rf).
Definition: disk.c:1087
char * hostkeys_data
Hostkeys data, contains "GNUNET_TESTING_HOSTKEYFILESIZE * total_hostkeys" bytes.
Definition: testing.c:143
struct SharedService * ss
Definition: testing.c:88
struct GNUNET_OS_Process * proc
Definition: testing.c:92
struct GNUNET_CONFIGURATION_Handle * cfg
Definition: testing.c:107
unsigned int n_instances
Definition: testing.c:113
struct SharedServiceInstance ** instances
Definition: testing.c:105
char * sname
Definition: testing.c:103
static void hostkeys_unload(struct GNUNET_TESTING_System *system)
Function to remove the loaded hostkeys.
Definition: testing.c:339
static void cleanup_shared_service_instance(struct SharedServiceInstance *i)
Definition: testing.c:493
static void stop_shared_service_instance(struct SharedServiceInstance *i)
Definition: testing.c:536

References SharedService::cfg, cleanup_shared_service_instance(), GNUNET_CONFIGURATION_destroy(), GNUNET_DISK_directory_remove(), GNUNET_free, 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 system_destroy_run().

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

735{
736 struct GNUNET_CRYPTO_EddsaPrivateKey *private_key;
737
738 if ((NULL == id) || (NULL == system->hostkeys_data))
739 return NULL;
740 if (key_number >= system->total_hostkeys)
741 {
743 _ ("Key number %u does not exist\n"),
744 key_number);
745 return NULL;
746 }
747 private_key = GNUNET_new (struct GNUNET_CRYPTO_EddsaPrivateKey);
748 GNUNET_memcpy (private_key,
749 system->hostkeys_data
750 + (key_number * GNUNET_TESTING_HOSTKEYFILESIZE),
752 GNUNET_CRYPTO_eddsa_key_get_public (private_key, &id->public_key);
753 return private_key;
754}
static struct GNUNET_IDENTITY_Handle * id
Handle to IDENTITY.
void GNUNET_CRYPTO_eddsa_key_get_public(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Extract the public key for the given private key.
Definition: crypto_ecc.c:198
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_ERROR_TYPE_ERROR
#define GNUNET_TESTING_HOSTKEYFILESIZE
Size of each hostkey in the hostkey file (in BYTES).
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
Private ECC key encoded for transmission.
uint32_t total_hostkeys
The number of hostkeys.
Definition: testing.c:177
#define LOG(kind,...)
Definition: testing.c:42

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

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

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

599{
600 struct GNUNET_NETWORK_Handle *socket;
601 struct addrinfo hint;
602 struct addrinfo *ret;
603 struct addrinfo *ai;
604 uint32_t *port_buckets;
605 char *open_port_str;
606 int bind_status;
607 uint32_t xor_image;
608 uint16_t index;
609 uint16_t open_port;
610 uint16_t pos;
611
612 /*
613 FIXME: Instead of using getaddrinfo we should try to determine the port
614 status by the following heurestics.
615
616 On systems which support both IPv4 and IPv6, only ports open on both
617 address families are considered open.
618 On system with either IPv4 or IPv6. A port is considered open if it's
619 open in the respective address family
620 */hint.ai_family = AF_UNSPEC; /* IPv4 and IPv6 */
621 hint.ai_socktype = 0;
622 hint.ai_protocol = 0;
623 hint.ai_addrlen = 0;
624 hint.ai_addr = NULL;
625 hint.ai_canonname = NULL;
626 hint.ai_next = NULL;
627 hint.ai_flags = AI_PASSIVE | AI_NUMERICSERV; /* Wild card address */
628 port_buckets = system->reserved_ports;
629 for (index = (system->lowport / 32) + 1; index < (system->highport / 32);
630 index++)
631 {
632 xor_image = (UINT32_MAX ^ port_buckets[index]);
633 if (0 == xor_image) /* Ports in the bucket are full */
634 continue;
635 pos = system->lowport % 32;
636 while (pos < 32)
637 {
638 if (0 == ((xor_image >> pos) & 1U))
639 {
640 pos++;
641 continue;
642 }
643 open_port = (index * 32) + pos;
644 if (open_port >= system->highport)
645 return 0;
646 GNUNET_asprintf (&open_port_str, "%u", (unsigned int) open_port);
647 ret = NULL;
648 GNUNET_assert (0 == getaddrinfo (NULL, open_port_str, &hint, &ret));
649 GNUNET_free (open_port_str);
650 bind_status = GNUNET_NO;
651 for (ai = ret; NULL != ai; ai = ai->ai_next)
652 {
653 socket = GNUNET_NETWORK_socket_create (ai->ai_family, SOCK_STREAM, 0);
654 if (NULL == socket)
655 continue;
656 bind_status =
657 GNUNET_NETWORK_socket_bind (socket, ai->ai_addr, ai->ai_addrlen);
659 if (GNUNET_OK != bind_status)
660 break;
661 socket = GNUNET_NETWORK_socket_create (ai->ai_family, SOCK_DGRAM, 0);
662 if (NULL == socket)
663 continue;
664 bind_status =
665 GNUNET_NETWORK_socket_bind (socket, ai->ai_addr, ai->ai_addrlen);
667 if (GNUNET_OK != bind_status)
668 break;
669 }
670 port_buckets[index] |= (1U << pos); /* Set the port bit */
671 freeaddrinfo (ret);
672 if (GNUNET_OK == bind_status)
673 {
675 "Found a free port %u\n",
676 (unsigned int) open_port);
677 return open_port;
678 }
679 pos++;
680 }
681 }
682 return 0;
683}
static int ret
Final status code.
Definition: gnunet-arm.c:94
static struct GNUNET_TRANSPORT_AddressIdentifier * ai
Handle to the operation that publishes our address.
@ GNUNET_NO
@ GNUNET_ERROR_TYPE_DEBUG
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition: network.c:508
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_create(int domain, int type, int protocol)
Create a new socket.
Definition: network.c:832
enum GNUNET_GenericReturnValue 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:439
#define AI_NUMERICSERV
AI_NUMERICSERV not defined in windows.
Definition: platform.h:219
handle to a socket
Definition: network.c:53
uint32_t reserved_ports[65536/32]
Bitmap where each port that has already been reserved for some GNUnet peer is recorded.
Definition: testing.c:162

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

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

696{
697 uint32_t *port_buckets;
698 uint16_t bucket;
699 uint16_t pos;
700
701 port_buckets = system->reserved_ports;
702 bucket = port / 32;
703 pos = port % 32;
704 LOG (GNUNET_ERROR_TYPE_DEBUG, "Releasing port %u\n", port);
705 if (0 == (port_buckets[bucket] & (1U << pos)))
706 {
707 GNUNET_break (0); /* Port was not reserved by us using reserve_port() */
708 return;
709 }
710 port_buckets[bucket] &= ~(1U << pos);
711}
static uint16_t port
Port number.
Definition: gnunet-bcd.c:147
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.

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

Referenced by GNUNET_TESTING_peer_destroy().

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

1169{
1170 return GNUNET_TESTING_configuration_create_ (system, cfg, NULL, NULL);
1171}
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:109
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:1104

References cfg, GNUNET_TESTING_configuration_create_(), and UpdateContext::system.

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

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

1193{
1194 struct GNUNET_TESTING_Peer *peer;
1195 struct GNUNET_DISK_FileHandle *fd;
1196 char *hostkey_filename;
1197 char *config_filename;
1198 char *libexec_binary;
1199 char *emsg_;
1201 uint16_t *ports;
1202 struct SharedService *ss;
1203 struct SharedServiceInstance **ss_instances;
1204 unsigned int cnt;
1205 unsigned int nports;
1206
1207 ports = NULL;
1208 nports = 0;
1209 ss_instances = NULL;
1210 if (NULL != emsg)
1211 *emsg = NULL;
1212 if (key_number >= system->total_hostkeys)
1213 {
1215 &emsg_,
1216 _ (
1217 "You attempted to create a testbed with more than %u hosts. Please precompute more hostkeys first.\n"),
1218 (unsigned int) system->total_hostkeys);
1219 goto err_ret;
1220 }
1221 pk = NULL;
1222 if ((NULL != id) &&
1223 (NULL == (pk = GNUNET_TESTING_hostkey_get (system, key_number, id))))
1224 {
1225 GNUNET_asprintf (&emsg_,
1226 _ ("Failed to initialize hostkey for peer %u\n"),
1227 (unsigned int) key_number);
1228 goto err_ret;
1229 }
1230 if (NULL != pk)
1231 GNUNET_free (pk);
1232 if (GNUNET_NO == GNUNET_CONFIGURATION_have_value (cfg, "PEER", "PRIVATE_KEY"))
1233 {
1235 &emsg_,
1236 _ ("PRIVATE_KEY option in PEER section missing in configuration\n"));
1237 goto err_ret;
1238 }
1239 /* Remove sections for shared services */
1240 for (cnt = 0; cnt < system->n_shared_services; cnt++)
1241 {
1242 ss = &system->shared_services[cnt];
1244 }
1245 if (GNUNET_OK !=
1246 GNUNET_TESTING_configuration_create_ (system, cfg, &ports, &nports))
1247 {
1248 GNUNET_asprintf (&emsg_,
1249 _ ("Failed to create configuration for peer "
1250 "(not enough free ports?)\n"));
1251 goto err_ret;
1252 }
1255 "PEER",
1256 "PRIVATE_KEY",
1257 &hostkey_filename));
1258 fd = GNUNET_DISK_file_open (hostkey_filename,
1262 if (NULL == fd)
1263 {
1264 GNUNET_asprintf (&emsg_,
1265 _ ("Cannot open hostkey file `%s': %s\n"),
1266 hostkey_filename,
1267 strerror (errno));
1268 GNUNET_free (hostkey_filename);
1269 goto err_ret;
1270 }
1271 GNUNET_free (hostkey_filename);
1274 system->hostkeys_data
1275 + (key_number * GNUNET_TESTING_HOSTKEYFILESIZE),
1277 {
1278 GNUNET_asprintf (&emsg_,
1279 _ ("Failed to write hostkey file for peer %u: %s\n"),
1280 (unsigned int) key_number,
1281 strerror (errno));
1283 goto err_ret;
1284 }
1286 ss_instances = GNUNET_new_array (system->n_shared_services,
1287 struct SharedServiceInstance*);
1288 for (cnt = 0; cnt < system->n_shared_services; cnt++)
1289 {
1290 ss = &system->shared_services[cnt];
1291 ss_instances[cnt] = associate_shared_service (system, ss, cfg);
1292 if (NULL == ss_instances[cnt])
1293 {
1294 emsg_ = GNUNET_strdup ("FIXME");
1295 goto err_ret;
1296 }
1297 }
1300 "PATHS",
1301 "DEFAULTCONFIG",
1302 &config_filename));
1303 if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, config_filename))
1304 {
1305 GNUNET_asprintf (&emsg_,
1306 _ (
1307 "Failed to write configuration file `%s' for peer %u: %s\n"),
1308 config_filename,
1309 (unsigned int) key_number,
1310 strerror (errno));
1311 GNUNET_free (config_filename);
1312 goto err_ret;
1313 }
1314 peer = GNUNET_new (struct GNUNET_TESTING_Peer);
1315 peer->ss_instances = ss_instances;
1316 peer->cfgfile = config_filename; /* Free in peer_destroy */
1318 libexec_binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm");
1319 if (GNUNET_SYSERR ==
1321 "arm",
1322 "PREFIX",
1323 &peer->main_binary))
1324 {
1325 /* No prefix */
1326 GNUNET_asprintf (&peer->main_binary, "%s", libexec_binary);
1327 peer->args = GNUNET_strdup ("");
1328 }
1329 else
1330 {
1331 peer->args = GNUNET_strdup (libexec_binary);
1332 }
1333 peer->system = system;
1334 peer->key_number = key_number;
1335 GNUNET_free (libexec_binary);
1336 peer->ports = ports; /* Free in peer_destroy */
1337 peer->nports = nports;
1338 return peer;
1339
1340err_ret:
1341 GNUNET_free (ss_instances);
1342 GNUNET_free (ports);
1343 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s", emsg_);
1344 if (NULL != emsg)
1345 *emsg = emsg_;
1346 else
1347 GNUNET_free (emsg_);
1348 return NULL;
1349}
struct GNUNET_CRYPTO_PrivateKey pk
Private key from command line option, or NULL.
enum GNUNET_GenericReturnValue 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.
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 * GNUNET_CONFIGURATION_dup(const struct GNUNET_CONFIGURATION_Handle *cfg)
Duplicate an existing configuration object.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_have_value(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Test if we have a value for a particular option.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_write(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Write configuration file.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Definition: disk.c:1237
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:686
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1308
@ GNUNET_DISK_OPEN_WRITE
Open the file for writing.
@ GNUNET_DISK_OPEN_CREATE
Create file if it doesn't exist.
@ GNUNET_DISK_PERM_USER_READ
Owner can read.
@ GNUNET_DISK_PERM_USER_WRITE
Owner can write.
#define GNUNET_log(kind,...)
@ GNUNET_SYSERR
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
char * GNUNET_OS_get_libexec_binary_path(const char *progname)
Given the name of a gnunet-helper, gnunet-service or gnunet-daemon binary, try to prefix it with the ...
struct GNUNET_CRYPTO_EddsaPrivateKey * GNUNET_TESTING_hostkey_get(const struct GNUNET_TESTING_System *system, uint32_t key_number, struct GNUNET_PeerIdentity *id)
Testing includes a number of pre-created hostkeys for faster peer startup.
Definition: testing.c:732
Handle used to access files (and pipes).
int fd
File handle on Unix-like systems.
Handle for a GNUnet peer controlled by testing.
Definition: testing.c:195
struct GNUNET_TESTING_System * system
The TESTING system associated with this peer.
Definition: testing.c:199
unsigned int nports
The number of ports in the above array.
Definition: testing.c:259
char * main_binary
Binary to be executed during 'GNUNET_TESTING_peer_start'.
Definition: testing.c:212
struct GNUNET_CONFIGURATION_Handle * cfg
The config of the peer.
Definition: testing.c:229
uint16_t * ports
Array of ports currently allocated to this peer.
Definition: testing.c:254
struct SharedServiceInstance ** ss_instances
Definition: testing.c:247
uint32_t key_number
The keynumber of this peer's hostkey.
Definition: testing.c:264
char * cfgfile
Path to the configuration file for this peer.
Definition: testing.c:204
static struct SharedServiceInstance * associate_shared_service(struct GNUNET_TESTING_System *system, struct SharedService *ss, struct GNUNET_CONFIGURATION_Handle *cfg)
Definition: testing.c:1011

References _, GNUNET_TESTING_Peer::args, associate_shared_service(), cfg, 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_log, GNUNET_new, GNUNET_new_array, 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, 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(), and start_peer_run().

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

1361{
1362 if (NULL != peer->id)
1363 {
1364 GNUNET_memcpy (id, peer->id, sizeof(struct GNUNET_PeerIdentity));
1365 return;
1366 }
1367 peer->id = GNUNET_new (struct GNUNET_PeerIdentity);
1369 GNUNET_TESTING_hostkey_get (peer->system, peer->key_number, peer->id));
1370 GNUNET_memcpy (id, peer->id, sizeof(struct GNUNET_PeerIdentity));
1371}
#define GNUNET_free_nz(ptr)
Wrapper around free.
The identity of the host (wraps the signing key of the peer).
struct GNUNET_PeerIdentity * id
The cached identity of this peer.
Definition: testing.c:245

References GNUNET_free_nz, 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(), and start_peer_run().

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

1382{
1383 struct SharedServiceInstance *i;
1384 unsigned int cnt;
1385
1386 if (NULL != peer->main_process)
1387 {
1388 GNUNET_break (0);
1389 return GNUNET_SYSERR;
1390 }
1391 GNUNET_assert (NULL != peer->cfgfile);
1392 for (cnt = 0; cnt < peer->system->n_shared_services; cnt++)
1393 {
1394 i = peer->ss_instances[cnt];
1395 if ((0 == i->n_refs) &&
1397 return GNUNET_SYSERR;
1398 i->n_refs++;
1399 }
1400 peer->main_binary =
1402 peer->main_process =
1404 NULL,
1405 peer->main_binary,
1406 peer->args,
1407 "-c",
1408 peer->cfgfile,
1409 NULL);
1410 if (NULL == peer->main_process)
1411 {
1413 _ ("Failed to start `%s': %s\n"),
1414 peer->main_binary,
1415 strerror (errno));
1416 return GNUNET_SYSERR;
1417 }
1418 return GNUNET_OK;
1419}
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...
struct GNUNET_OS_Process * GNUNET_OS_start_process_s(enum GNUNET_OS_InheritStdioFlags std_inheritance, const int *lsocks, const char *filename,...)
Start a process.
Definition: os_priority.c:665
@ GNUNET_OS_INHERIT_STD_OUT_AND_ERR
When these flags are set, the child process will inherit stdout and stderr of the parent.
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:219
unsigned int n_refs
Definition: testing.c:98
static enum GNUNET_GenericReturnValue start_shared_service_instance(struct SharedServiceInstance *i)
Definition: testing.c:509

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, 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_run(), and stdin_cb().

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

1486{
1488 return GNUNET_SYSERR;
1490 return GNUNET_SYSERR;
1491 return GNUNET_OK;
1492}
int GNUNET_TESTING_peer_kill(struct GNUNET_TESTING_Peer *peer)
Sends SIGTERM to the peer's main process.
Definition: testing.c:1430
int GNUNET_TESTING_peer_wait(struct GNUNET_TESTING_Peer *peer)
Waits for a peer to terminate.
Definition: testing.c:1462

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(), stdin_cb(), and stop_peer_run().

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

1567{
1568 unsigned int cnt;
1569
1570 if (NULL != peer->main_process)
1572 if (NULL != peer->ah)
1573 GNUNET_ARM_disconnect (peer->ah);
1574 GNUNET_free (peer->cfgfile);
1575 if (NULL != peer->cfg)
1577 GNUNET_free (peer->main_binary);
1578 GNUNET_free (peer->args);
1579 GNUNET_free (peer->id);
1580 GNUNET_free (peer->ss_instances);
1581 if (NULL != peer->ports)
1582 {
1583 for (cnt = 0; cnt < peer->nports; cnt++)
1584 GNUNET_TESTING_release_port (peer->system, peer->ports[cnt]);
1585 GNUNET_free (peer->ports);
1586 }
1587 GNUNET_free (peer);
1588}
void GNUNET_ARM_disconnect(struct GNUNET_ARM_Handle *h)
Disconnect from the ARM service and destroy the handle.
Definition: arm_api.c:602
int GNUNET_TESTING_peer_stop(struct GNUNET_TESTING_Peer *peer)
Stop the peer.
Definition: testing.c:1485
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:694
struct GNUNET_ARM_Handle * ah
The handle to the peer's ARM service.
Definition: testing.c:224

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_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(), and stop_peer_run().

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

1431{
1432 struct SharedServiceInstance *i;
1433 unsigned int cnt;
1434
1435 if (NULL == peer->main_process)
1436 {
1437 GNUNET_break (0);
1438 return GNUNET_SYSERR;
1439 }
1441 return GNUNET_SYSERR;
1442 for (cnt = 0; cnt < peer->system->n_shared_services; cnt++)
1443 {
1444 i = peer->ss_instances[cnt];
1445 GNUNET_assert (0 != i->n_refs);
1446 i->n_refs--;
1447 if (0 == i->n_refs)
1449 }
1450 return GNUNET_OK;
1451}
int GNUNET_OS_process_kill(struct GNUNET_OS_Process *proc, int sig)
Sends a signal to the process.
Definition: os_priority.c:210
#define GNUNET_TERM_SIG
The termination signal.
Definition: platform.h:234

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(), and GNUNET_TESTING_peer_stop().

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

1463{
1464 int ret;
1465
1466 if (NULL == peer->main_process)
1467 {
1468 GNUNET_break (0);
1469 return GNUNET_SYSERR;
1470 }
1473 peer->main_process = NULL;
1474 return ret;
1475}
void GNUNET_OS_process_destroy(struct GNUNET_OS_Process *proc)
Cleans up process structure contents (OS-dependent) and deallocates it.
Definition: os_priority.c:260
enum GNUNET_GenericReturnValue GNUNET_OS_process_wait(struct GNUNET_OS_Process *proc)
Wait for a process to terminate.
Definition: os_priority.c:877

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

Referenced by disconn_status(), and GNUNET_TESTING_peer_stop().

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.

Definition at line 1525 of file testing.c.

1528{
1529 if (NULL == peer->main_process)
1530 return GNUNET_SYSERR;
1531 peer->ah = GNUNET_ARM_connect (peer->cfg, &disconn_status, peer);
1532 if (NULL == peer->ah)
1533 return GNUNET_SYSERR;
1534 peer->cb = cb;
1535 peer->cb_cls = cb_cls;
1536 return GNUNET_OK;
1537}
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:577
void * cb_cls
The closure for the above callback.
Definition: testing.c:239
GNUNET_TESTING_PeerStopCallback cb
The callback to call asynchronously when a peer is stopped.
Definition: testing.c:234
static void disconn_status(void *cls, int connected)
Function called whenever we connect to or disconnect from ARM.
Definition: testing.c:1503

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.

Here is the call 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 1550 of file testing.c.

1551{
1552 GNUNET_assert (NULL != peer->ah);
1553 GNUNET_ARM_disconnect (peer->ah);
1554 peer->ah = NULL;
1555}

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

Here is the call 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

Definition at line 1592 of file testing.c.

1596{
1597 return GNUNET_TESTING_service_run (testdir, "arm", cfgfilename, tm, tm_cls);
1598}
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 u...
Definition: testing.c:1643

References GNUNET_TESTING_service_run().

Here is the call 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

Definition at line 1643 of file testing.c.

1648{
1649 struct ServiceContext sc;
1650 struct GNUNET_TESTING_System *system;
1651 struct GNUNET_TESTING_Peer *peer;
1653 char *binary;
1654 char *libexec_binary;
1655
1656 GNUNET_log_setup (testdir, "WARNING", NULL);
1657 system = GNUNET_TESTING_system_create (testdir, "127.0.0.1", NULL, NULL);
1658 if (NULL == system)
1659 return 1;
1661 if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cfgfilename))
1662 {
1664 _ ("Failed to load configuration from %s\n"),
1665 cfgfilename);
1668 return 1;
1669 }
1670 peer = GNUNET_TESTING_peer_configure (system, cfg, 0, NULL, NULL);
1671 if (NULL == peer)
1672 {
1674 hostkeys_unload (system);
1676 return 1;
1677 }
1678 GNUNET_free (peer->main_binary);
1679 GNUNET_free (peer->args);
1680 GNUNET_asprintf (&binary, "gnunet-service-%s", service_name);
1681 libexec_binary = GNUNET_OS_get_libexec_binary_path (binary);
1682 if (GNUNET_SYSERR ==
1685 "PREFIX",
1686 &peer->main_binary))
1687 {
1688 /* No prefix */
1689 GNUNET_asprintf (&peer->main_binary, "%s", libexec_binary);
1690 peer->args = GNUNET_strdup ("");
1691 }
1692 else
1693 peer->args = GNUNET_strdup (libexec_binary);
1694
1695 GNUNET_free (libexec_binary);
1696 GNUNET_free (binary);
1698 {
1702 return 1;
1703 }
1704 sc.cfg = cfg;
1705 sc.tm = tm;
1706 sc.tm_cls = tm_cls;
1707 sc.peer = peer;
1708 GNUNET_SCHEDULER_run (&service_run_main, &sc); /* Scheduler loop */
1709 if ((NULL != peer->main_process) &&
1711 {
1715 return 1;
1716 }
1720 return 0;
1721}
static struct GNUNET_FS_SearchContext * sc
Definition: gnunet-search.c:87
static char * service_name
Option -s: service name (hash to get service descriptor)
Definition: gnunet-vpn.c:50
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Load configuration.
enum GNUNET_GenericReturnValue GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
void GNUNET_SCHEDULER_run(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Initialize and run scheduler.
Definition: scheduler.c:720
int GNUNET_TESTING_peer_start(struct GNUNET_TESTING_Peer *peer)
Start the peer.
Definition: testing.c:1381
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:1188
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:477
void GNUNET_TESTING_peer_destroy(struct GNUNET_TESTING_Peer *peer)
Destroy the peer.
Definition: testing.c:1566
Structure for holding service data.
Definition: testing.c:1605
static void service_run_main(void *cls)
Callback to be called when SCHEDULER has been started.
Definition: testing.c:1634

References _, GNUNET_TESTING_Peer::args, 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, sc, service_name, and service_run_main().

Referenced by GNUNET_TESTING_peer_run(), and run_no_scheduler().

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