#define LOG(kind,...) \
GNUNET_log_from (kind, "testing-api", __VA_ARGS__)
-/**
- * Size of a hostkey when written to a file
- */
-#define HOSTKEYFILESIZE 914
-
/**
* Lowest port used for GNUnet testing. Should be high enough to not
* conflict with other applications running on the hosts but be low
char *hostname;
/**
- * Hostkeys data, contains "HOSTKEYFILESIZE * total_hostkeys" bytes.
+ * Hostkeys data, contains "GNUNET_TESTING_HOSTKEYFILESIZE * total_hostkeys" bytes.
*/
char *hostkeys_data;
GNUNET_free (filename);
return GNUNET_SYSERR; /* File is empty */
}
- if (0 != (fs % HOSTKEYFILESIZE))
+ if (0 != (fs % GNUNET_TESTING_HOSTKEYFILESIZE))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
_("Incorrect hostkey file format: %s\n"), filename);
GNUNET_free (filename);
return GNUNET_SYSERR;
}
- system->total_hostkeys = fs / HOSTKEYFILESIZE;
+ system->total_hostkeys = fs / GNUNET_TESTING_HOSTKEYFILESIZE;
system->hostkeys_data = GNUNET_DISK_file_map (system->map_fd,
&system->map,
GNUNET_DISK_MAP_TYPE_READ,
struct GNUNET_NETWORK_Handle *socket;
struct addrinfo hint;
struct addrinfo *ret;
+ struct addrinfo *ai;
uint32_t *port_buckets;
char *open_port_str;
int bind_status;
GNUNET_asprintf (&open_port_str, "%u", (unsigned int) open_port);
ret = NULL;
GNUNET_assert (0 == getaddrinfo (NULL, open_port_str, &hint, &ret));
- GNUNET_free (open_port_str);
- socket = GNUNET_NETWORK_socket_create (ret->ai_family,
- (GNUNET_YES == is_tcp) ?
- SOCK_STREAM : SOCK_DGRAM,
- 0);
- GNUNET_assert (NULL != socket);
- bind_status = GNUNET_NETWORK_socket_bind (socket,
- ret->ai_addr,
- ret->ai_addrlen);
- freeaddrinfo (ret);
- GNUNET_NETWORK_socket_close (socket);
- socket = NULL;
+ GNUNET_free (open_port_str);
+ bind_status = GNUNET_NO;
+ for (ai = ret; NULL != ai; ai = ai->ai_next)
+ {
+ socket = GNUNET_NETWORK_socket_create (ai->ai_family,
+ (GNUNET_YES == is_tcp) ?
+ SOCK_STREAM : SOCK_DGRAM,
+ 0);
+ if (NULL == socket)
+ continue;
+ bind_status = GNUNET_NETWORK_socket_bind (socket,
+ ai->ai_addr,
+ ai->ai_addrlen);
+ GNUNET_NETWORK_socket_close (socket);
+ if (GNUNET_OK != bind_status)
+ break;
+ }
port_buckets[index] |= (1U << pos); /* Set the port bit */
+ freeaddrinfo (ret);
if (GNUNET_OK == bind_status)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
return NULL;
}
private_key = GNUNET_CRYPTO_rsa_decode_key (system->hostkeys_data +
- (key_number * HOSTKEYFILESIZE),
- HOSTKEYFILESIZE);
+ (key_number *
+ GNUNET_TESTING_HOSTKEYFILESIZE),
+ GNUNET_TESTING_HOSTKEYFILESIZE);
if (NULL == private_key)
{
LOG (GNUNET_ERROR_TYPE_ERROR,
{
GNUNET_asprintf (&emsg_,
_("Failed to create configuration for peer (not enough free ports?)\n"));
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s", *emsg_);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s", emsg_);
if (NULL != emsg)
*emsg = emsg_;
else
GNUNET_asprintf (&emsg_,
_("Failed to initialize hostkey for peer %u\n"),
(unsigned int) key_number);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s", *emsg_);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s", emsg_);
if (NULL != emsg)
*emsg = emsg_;
else
GNUNET_break (0);
return NULL;
}
- if (HOSTKEYFILESIZE !=
+ if (GNUNET_TESTING_HOSTKEYFILESIZE !=
GNUNET_DISK_file_write (fd, system->hostkeys_data
- + (key_number * HOSTKEYFILESIZE),
- HOSTKEYFILESIZE))
+ + (key_number * GNUNET_TESTING_HOSTKEYFILESIZE),
+ GNUNET_TESTING_HOSTKEYFILESIZE))
{
GNUNET_asprintf (&emsg_,
_("Failed to write hostkey file for peer %u: %s\n"),
(unsigned int) key_number,
STRERROR (errno));
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s", *emsg_);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s", emsg_);
if (NULL != emsg)
*emsg = emsg_;
else
config_filename,
(unsigned int) key_number,
STRERROR (errno));
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s", *emsg_);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s", emsg_);
if (NULL != emsg)
*emsg = emsg_;
else
}
peer = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Peer));
peer->cfgfile = config_filename; /* Free in peer_destroy */
- peer->main_binary = GNUNET_strdup ("gnunet-service-arm");
+ peer->main_binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm");
peer->system = system;
peer->key_number = key_number;
return peer;
struct GNUNET_TESTING_System *system;
struct GNUNET_TESTING_Peer *peer;
struct GNUNET_CONFIGURATION_Handle *cfg;
+ char *binary;
GNUNET_log_setup (testdir, "WARNING", NULL);
system = GNUNET_TESTING_system_create (testdir, "127.0.0.1", NULL);
return 1;
}
GNUNET_free (peer->main_binary);
- GNUNET_asprintf (&peer->main_binary, "gnunet-service-%s", service_name);
+ GNUNET_asprintf (&binary, "gnunet-service-%s", service_name);
+ peer->main_binary = GNUNET_OS_get_libexec_binary_path (binary);
+ GNUNET_free (binary);
if (GNUNET_OK != GNUNET_TESTING_peer_start (peer))
{
GNUNET_TESTING_peer_destroy (peer);