#define TIME_REL_SEC(sec) \
GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec)
-/**
- * AI_NUMERICSERV not defined in windows. A hack to keep on going.
- */
-#if !defined (AI_NUMERICSERV)
-#define AI_NUMERICSERV 0
-#endif
/**
* Size of a hostkey when written to a file
*/
-#ifndef HOSTKEYFILESIZE
#define HOSTKEYFILESIZE 914
-#endif
+
/**
* Handle for a system on which GNUnet peers are executed;
char *controller;
/**
- * Hostkeys data
+ * Hostkeys data, contains "HOSTKEYFILESIZE * total_hostkeys" bytes.
*/
char *hostkeys_data;
GNUNET_TESTING_system_destroy (struct GNUNET_TESTING_System *system,
int remove_paths)
{
- GNUNET_assert (NULL != system);
if (NULL != system->hostkeys_data)
{
GNUNET_break (0); /* Use GNUNET_TESTING_hostkeys_unload() */
uint16_t bucket;
uint16_t pos;
- GNUNET_assert (NULL != system);
port_buckets = (GNUNET_YES == is_tcp) ?
system->reserved_tcp_ports : system->reserved_udp_ports;
bucket = port / 32;
return GNUNET_SYSERR;
if (key_number >= system->total_hostkeys)
{
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Key number %u doesn't exist\n", key_number);
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _("Key number %u does not exist\n"), key_number);
return GNUNET_SYSERR;
}
private_key = GNUNET_CRYPTO_rsa_decode_key (system->hostkeys_data +
HOSTKEYFILESIZE);
if (NULL == private_key)
{
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Error while decoding key %u\n", key_number);
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _("Error while decoding key %u\n"), key_number);
return GNUNET_SYSERR;
}
GNUNET_CRYPTO_rsa_key_get_public (private_key, &public_key);
system->path_counter++);
GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "SERVICEHOME",
uc.service_home);
+ /* make PORTs and UNIXPATHs unique */
GNUNET_CONFIGURATION_iterate (cfg, &update_config, &uc);
+ /* allow connections to services from system controller host */
GNUNET_CONFIGURATION_iterate_sections (cfg, &update_config_sections, &uc);
- /* FIXME: add other options which enable communication with controller */
+ /* enable loopback-based connections between peers */
+ GNUNET_CONFIGURATION_set_value_string (cfg,
+ "nat",
+ "USE_LOCALADDR", "YES");
GNUNET_free (uc.service_home);
return uc.status;
}
char *service_home;
char hostkey_filename[128];
char *config_filename;
- size_t bytes_written;
- size_t n;
-
if (GNUNET_OK != GNUNET_TESTING_configuration_create (system, cfg))
+ {
+ GNUNET_asprintf (emsg,
+ _("Failed to create configuration for peer (not enough free ports?)\n"));
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "%s", *emsg);
return NULL;
+ }
if (key_number >= system->total_hostkeys)
+ {
+ GNUNET_asprintf (emsg,
+ _("You attempted to create a testbed with more than %u hosts. Please precompute more hostkeys first.\n"),
+ (unsigned int) system->total_hostkeys);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "%s", *emsg);
return NULL;
+ }
if ((NULL != id) &&
(GNUNET_SYSERR == GNUNET_TESTING_hostkey_get (system, key_number, id)))
+ {
+ GNUNET_asprintf (emsg,
+ _("Failed to initialize hostkey for peer %u\n"),
+ (unsigned int) key_number);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "%s", *emsg);
return NULL;
+ }
GNUNET_assert (GNUNET_OK ==
GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS",
"SERVICE_HOME",
| GNUNET_DISK_PERM_USER_WRITE);
if (NULL == fd)
{
- GNUNET_break (0); return NULL;
+ GNUNET_break (0);
+ return NULL;
}
- bytes_written = 0;
- do
+ if (HOSTKEYFILESIZE !=
+ GNUNET_DISK_file_write (fd, system->hostkeys_data
+ + (key_number * HOSTKEYFILESIZE),
+ HOSTKEYFILESIZE))
{
- n = GNUNET_DISK_file_write (fd, system->hostkeys_data
- + (key_number * HOSTKEYFILESIZE),
- HOSTKEYFILESIZE - bytes_written);
- GNUNET_assert (GNUNET_SYSERR != n);
- bytes_written += n;
+ GNUNET_asprintf (emsg,
+ _("Failed to write hostkey file for peer %u: %s\n"),
+ (unsigned int) key_number,
+ STRERROR (errno));
+ GNUNET_DISK_file_close (fd);
+ return NULL;
}
- while (bytes_written < HOSTKEYFILESIZE);
GNUNET_DISK_file_close (fd);
- fd = NULL;
GNUNET_asprintf (&config_filename, "%s\\config", service_home);
GNUNET_free (service_home);
if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, config_filename))
- return NULL;
+ {
+ GNUNET_asprintf (emsg,
+ _("Failed to write configuration file `%s' for peer %u: %s\n"),
+ config_filename,
+ (unsigned int) key_number,
+ STRERROR (errno));
+ return NULL;
+ }
peer = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Peer));
peer->cfgfile = config_filename; /* Free in peer_destroy */
- peer->main_binary = GNUNET_strdup ("gnunet-arm");
+ peer->main_binary = GNUNET_strdup ("gnunet-service-arm");
return peer;
}
GNUNET_TESTING_peer_start (struct GNUNET_TESTING_Peer *peer)
{
if (NULL != peer->main_process)
+ {
+ GNUNET_break (0);
return GNUNET_SYSERR;
+ }
GNUNET_assert (NULL != peer->cfgfile);
peer->main_process = GNUNET_OS_start_process (GNUNET_NO, NULL, NULL,
peer->main_binary, "-c",
peer->cfgfile,
- "-s", "-q", NULL);
- GNUNET_assert (NULL != peer->main_process);
+ NULL);
+ if (NULL == peer->main_process)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to start `%s': %s\n"),
+ peer->main_binary,
+ STRERROR (errno));
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
}
GNUNET_TESTING_peer_stop (struct GNUNET_TESTING_Peer *peer)
{
if (NULL == peer->main_process)
+ {
+ GNUNET_break (0);
return GNUNET_SYSERR;
- GNUNET_assert (0 == GNUNET_OS_process_kill (peer->main_process, SIGTERM));
+ }
+ (void) GNUNET_OS_process_kill (peer->main_process, SIGTERM);
GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (peer->main_process));
GNUNET_OS_process_destroy (peer->main_process);
peer->main_process = NULL;
{
if (NULL != peer->main_process)
{
- LOG (GNUNET_ERROR_TYPE_WARNING,
- _("%s called when peer is still running. Use GNUNET_TESTING_peer_stop()\n"),
- __func__);
+ GNUNET_break (0);
GNUNET_TESTING_peer_stop (peer);
}
GNUNET_free (peer->cfgfile);
}
-
/**
* Start a single peer and run a test using the testing library.
* Starts a peer using the given configuration and then invokes the
}
+static void
+service_run_main (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ struct ServiceContext *sc = cls;
+
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
+ &stop_service, sc);
+ GNUNET_SCHEDULER_add_delayed (TIME_REL_SEC(3), &check_service_status, sc);
+
+ // sc->tm (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.
GNUNET_assert (NULL != service_name);
GNUNET_snprintf (uval, sizeof (uval), "gnunet-service-%s", service_name);
sc = GNUNET_malloc (sizeof (struct ServiceContext));
+
+ // FIXME: GNUNET_TESTING_peer_start...
if (NULL == cfgfilename)
- sc->main_process = GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, uval);
+ sc->main_process = GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, uval, NULL);
else
sc->main_process = GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, uval,
- "-c", cfgfilename);
+ "-c", cfgfilename, NULL);
if (NULL == sc->main_process)
{
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Failed to start process %s\n", service_name);
+ LOG (GNUNET_ERROR_TYPE_ERROR, "Failed to start process %s\n", service_name);
GNUNET_free (sc);
return 1;
}
sc->tm = tm;
sc->tm_cls = tm_cls;
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &stop_service, sc);
- GNUNET_SCHEDULER_add_delayed (TIME_REL_SEC(3), &check_service_status, sc);
+ GNUNET_SCHEDULER_run (&service_run_main, sc);
+ // FIXME: GNUNET_TESTING_peer_stop...
+ GNUNET_free (sc);
return 0;
}
-
/* end of testing_new.c */