/*
This file is part of GNUnet
(C) 2008, 2009, 2012 Christian Grothoff (and other contributing authors)
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
by the Free Software Foundation; either version 3, or (at your
option) any later version.
GNUnet is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNUnet; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
/**
* @file testing/testing.c
* @brief convenience API for writing testcases for GNUnet
* Many testcases need to start and stop a peer/service
* and this library is supposed to make that easier
* for TESTCASES. Normal programs should always
* use functions from gnunet_{util,arm}_lib.h. This API is
* ONLY for writing testcases (or internal use of the testbed).
* @author Christian Grothoff
*
*/
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_lib.h"
#define LOG(kind,...) \
GNUNET_log_from (kind, "testing-api", __VA_ARGS__)
/**
* We need pipe control only on WINDOWS
*/
#if WINDOWS
#define PIPE_CONTROL GNUNET_YES
#else
#define PIPE_CONTROL GNUNET_NO
#endif
/**
* Lowest port used for GNUnet testing. Should be high enough to not
* conflict with other applications running on the hosts but be low
* enough to not conflict with client-ports (typically starting around
* 32k).
*/
#define LOW_PORT 12000
/**
* Highest port used for GNUnet testing. Should be low enough to not
* conflict with the port range for "local" ports (client apps; see
* /proc/sys/net/ipv4/ip_local_port_range on Linux for example).
*/
#define HIGH_PORT 56000
/**
* Handle for a system on which GNUnet peers are executed;
* a system is used for reserving unique paths and ports.
*/
struct GNUNET_TESTING_System
{
/**
* Prefix (i.e. "/tmp/gnunet-testing/") we prepend to each
* SERVICEHOME. */
char *tmppath;
/**
* The trusted ip. Can either be a single ip address or a network address in
* CIDR notation.
*/
char *trusted_ip;
/**
* our hostname
*/
char *hostname;
/**
* Hostkeys data, contains "GNUNET_TESTING_HOSTKEYFILESIZE * total_hostkeys" bytes.
*/
char *hostkeys_data;
/**
* memory map for 'hostkeys_data'.
*/
struct GNUNET_DISK_MapHandle *map;
/**
* File descriptor for the map.
*/
struct GNUNET_DISK_FileHandle *map_fd;
/**
* Bitmap where each TCP port that has already been reserved for
* some GNUnet peer is recorded. Note that we additionally need to
* test if a port is already in use by non-GNUnet components before
* assigning it to a peer/service. If we detect that a port is
* already in use, we also mark it in this bitmap. So all the bits
* that are zero merely indicate ports that MIGHT be available for
* peers.
*/
uint32_t reserved_tcp_ports[65536 / 32];
/**
* Bitmap where each UDP port that has already been reserved for
* some GNUnet peer is recorded. Note that we additionally need to
* test if a port is already in use by non-GNUnet components before
* assigning it to a peer/service. If we detect that a port is
* already in use, we also mark it in this bitmap. So all the bits
* that are zero merely indicate ports that MIGHT be available for
* peers.
*/
uint32_t reserved_udp_ports[65536 / 32];
/**
* Counter we use to make service home paths unique on this system;
* the full path consists of the tmppath and this number. Each
* UNIXPATH for a peer is also modified to include the respective
* path counter to ensure uniqueness. This field is incremented
* by one for each configured peer. Even if peers are destroyed,
* we never re-use path counters.
*/
uint32_t path_counter;
/**
* The number of hostkeys
*/
uint32_t total_hostkeys;
/**
* Lowest port we are allowed to use.
*/
uint16_t lowport;
/**
* Highest port we are allowed to use.
*/
uint16_t highport;
};
/**
* Handle for a GNUnet peer controlled by testing.
*/
struct GNUNET_TESTING_Peer
{
/**
* The TESTING system associated with this peer
*/
struct GNUNET_TESTING_System *system;
/**
* Path to the configuration file for this peer.
*/
char *cfgfile;
/**
* Binary to be executed during 'GNUNET_TESTING_peer_start'.
* Typically 'gnunet-service-arm' (but can be set to a
* specific service by 'GNUNET_TESTING_service_run' if
* necessary).
*/
char *main_binary;
char *args;
/**
* Handle to the running binary of the service, NULL if the
* peer/service is currently not running.
*/
struct GNUNET_OS_Process *main_process;
/**
* The keynumber of this peer's hostkey
*/
uint32_t key_number;
};
/**
* Testing includes a number of pre-created hostkeys for faster peer
* startup. This function loads such keys into memory from a file.