31#define LOG(kind, ...) GNUNET_log_from (kind, "testing-api", __VA_ARGS__)
46#define HIGH_PORT 56000
166 struct addrinfo hint;
167 struct addrinfo *
ret;
169 uint32_t *port_buckets;
185hint.ai_family = AF_UNSPEC;
186 hint.ai_socktype = 0;
187 hint.ai_protocol = 0;
190 hint.ai_canonname = NULL;
194 for (index = (system->
lowport / 32) + 1; index < (system->
highport / 32);
197 xor_image = (UINT32_MAX ^ port_buckets[index]);
203 if (0 == ((xor_image >> pos) & 1U))
208 open_port = (index * 32) + pos;
235 port_buckets[index] |= (1U << pos);
240 "Found a free port %u\n",
241 (
unsigned int) open_port);
255 uint32_t *port_buckets;
263 if (0 == (port_buckets[bucket] & (1U << pos)))
268 port_buckets[bucket] &= ~(1U << pos);
332 char *single_variable;
333 char *per_host_variable;
334 unsigned long long num_per_host;
339 if (! ((0 == strcmp (option,
"PORT")) || (0 == strcmp (option,
"UNIXPATH")) ||
340 (0 == strcmp (option,
"HOSTNAME"))))
344 if ((0 == strcmp (option,
"PORT")) && (1 == sscanf (
value,
"%u", &ival)))
363 else if ((ival != 0) &&
379 if (0 == strcmp (option,
"UNIXPATH"))
402 if (0 == strcmp (option,
"HOSTNAME"))
404 value = (NULL ==
uc->system->hostname) ?
"localhost" :
uc->system->hostname;
427 char *orig_allowed_hosts;
429 char *ACCEPT_FROM_key;
440 "TESTBED_IGNORE_KEYS"))
445 "TESTBED_IGNORE_KEYS",
448 for (ikeys_cnt = 0; NULL != (ptr = strstr (ptr,
";")); ikeys_cnt++)
459 ptr = strstr (ptr,
";");
470 if (NULL != strstr (ikeys[
key],
"ADVERTISED_PORT"))
473 if ((
key == ikeys_cnt) &&
494 if (NULL != strstr (ikeys[
key],
"ACCEPT_FROM"))
504 ACCEPT_FROM_key =
"ACCEPT_FROM";
505 if ((NULL !=
uc->system->trusted_ip) &&
506 (NULL != strstr (
uc->system->trusted_ip,
":")))
507 ACCEPT_FROM_key =
"ACCEPT_FROM6";
511 &orig_allowed_hosts))
515 if (NULL ==
uc->system->trusted_ip)
521 uc->system->trusted_ip);
539 char *default_config;
static int ret
Final status code.
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static uint16_t port
Port number.
static struct GNUNET_TRANSPORT_AddressIdentifier * ai
Handle to the operation that publishes our address.
struct GNUNET_HashCode key
The key used in the DHT.
static char * value
Value of the record to add/remove.
static struct GNUNET_FS_UnindexContext * uc
#define GNUNET_TESTBED_PREFIX
void GNUNET_CONFIGURATION_set_value_string(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value)
Set a configuration value that should be a string.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
void GNUNET_CONFIGURATION_iterate_sections(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CONFIGURATION_SectionIterator iter, void *iter_cls)
Iterate over all sections in the configuration.
void GNUNET_CONFIGURATION_iterate(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CONFIGURATION_Iterator iter, void *iter_cls)
Iterate over all options in the configuration.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
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.
char * GNUNET_DISK_mkdtemp(const char *t)
Create an (empty) temporary directory on disk.
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_remove(const char *filename)
Remove all files in a directory (rm -rf).
GNUNET_GenericReturnValue
Named constants for return values.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_DEBUG
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
int GNUNET_snprintf(char *buf, size_t size, const char *format,...) __attribute__((format(printf
Like snprintf, just aborts if the buffer is of insufficient size.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#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.
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_create(int domain, int type, int protocol)
Create a new socket.
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.
Handle for a system on which GNUnet peers are executed; a system is used for reserving unique paths a...
uint32_t path_counter
Counter we use to make service home paths unique on this system; the full path consists of the tmppat...
uint16_t highport
Highest port we are allowed to use.
uint32_t reserved_ports[65536/32]
Bitmap where each port that has already been reserved for some GNUnet peer is recorded.
uint16_t lowport
Lowest port we are allowed to use.
char * hostname
our hostname
char * tmppath
Prefix (e.g.
char * trusted_ip
The trusted ip.
Closure for iterator for updating.
struct GNUNET_TESTBED_System * system
The system for which we are building configurations.
uint16_t * ports
Array of ports currently allocated to this peer.
char * gnunet_home
The customized service home path for this peer.
struct GNUNET_CONFIGURATION_Handle * cfg
The configuration we are building.
unsigned int nports
The number of ports in the above array.
int status
build status - to signal error while building a configuration
struct GNUNET_TESTBED_System * GNUNET_TESTBED_system_create_with_portrange(const char *testdir, const char *trusted_ip, const char *hostname, uint16_t lowport, uint16_t highport)
Create a system handle.
#define HIGH_PORT
Highest port used for GNUnet testing.
void GNUNET_TESTBED_release_port(struct GNUNET_TESTBED_System *system, uint16_t port)
Release reservation of a TCP or UDP port for a peer (used during #GNUNET_TESTBED_peer_destroy()).
struct GNUNET_TESTBED_System * GNUNET_TESTBED_system_create(const char *testdir, const char *trusted_ip, const char *hostname)
Create a system handle.
uint16_t GNUNET_TESTBED_reserve_port(struct GNUNET_TESTBED_System *system)
Reserve a TCP or UDP port for a peer.
static void update_config(void *cls, const char *section, const char *option, const char *value)
Function to iterate over options.
void GNUNET_TESTBED_system_destroy(struct GNUNET_TESTBED_System *system, bool remove_paths)
Free system resources.
static void update_config_sections(void *cls, const char *section)
Section iterator to set ACCEPT_FROM/ACCEPT_FROM6 to include the address of 'trusted_hosts' in all sec...
enum GNUNET_GenericReturnValue GNUNET_TESTBED_configuration_create(struct GNUNET_TESTBED_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...
#define LOW_PORT
Lowest port used for GNUnet testing.