Beispiel #1
0
/**
 * Assuming all peers have been destroyed cleanup run handle
 *
 * @param rc the run context
 */
static void
cleanup (struct GNUNET_TESTBED_RunHandle *rc)
{
  unsigned int hid;

  GNUNET_assert (NULL == rc->register_hosts_task);
  GNUNET_assert (NULL == rc->reg_handle);
  GNUNET_assert (NULL == rc->peers);
  GNUNET_assert (NULL == rc->hclist);
  GNUNET_assert (RC_PEERS_SHUTDOWN == rc->state);
  GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap32_size (rc->rcop_map));
  GNUNET_CONTAINER_multihashmap32_destroy (rc->rcop_map);
  if (NULL != rc->c)
    GNUNET_TESTBED_controller_disconnect (rc->c);
  if (NULL != rc->cproc)
    GNUNET_TESTBED_controller_stop (rc->cproc);
  if (NULL != rc->h)
    GNUNET_TESTBED_host_destroy (rc->h);
  for (hid = 0; hid < rc->num_hosts; hid++)
    GNUNET_TESTBED_host_destroy (rc->hosts[hid]);
  GNUNET_free_non_null (rc->hosts);
  if (NULL != rc->cfg)
    GNUNET_CONFIGURATION_destroy (rc->cfg);
  GNUNET_free_non_null (rc->topo_file);
  GNUNET_free_non_null (rc->trusted_ip);
  GNUNET_free (rc);
}
/**
 * Shutdown nicely
 *
 * @param cls NULL
 * @param tc the task context
 */
static void
do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  if (NULL != abort_task)
    GNUNET_SCHEDULER_cancel (abort_task);
  if (NULL != delay_task_id)
  {
    GNUNET_SCHEDULER_cancel (delay_task_id);
    delay_task_id = NULL;
  }
  if (NULL != hc_handle)
    GNUNET_TESTBED_is_host_habitable_cancel (hc_handle);
  if (NULL != mc)
    GNUNET_TESTBED_controller_disconnect (mc);
  if (NULL != cp)
    GNUNET_TESTBED_controller_stop (cp);
  if (NULL != slave3)
    GNUNET_TESTBED_host_destroy (slave3);
  if (NULL != slave2)
    GNUNET_TESTBED_host_destroy (slave2);
  if (NULL != slave)
    GNUNET_TESTBED_host_destroy (slave);
  if (NULL != host)
    GNUNET_TESTBED_host_destroy (host);
  if (NULL != cfg)
    GNUNET_CONFIGURATION_destroy (cfg);
  if (NULL != cfg3)
    GNUNET_CONFIGURATION_destroy (cfg3);
  if (NULL != rh)
    GNUNET_TESTBED_cancel_registration (rh);
}
/**
 * Shutdown nicely
 *
 * @param cls NULL
 * @param tc the task context
 */
static void
do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
    if (NULL != abort_task)
        GNUNET_SCHEDULER_cancel (abort_task);
    if (NULL != hc_handle)
        GNUNET_TESTBED_is_host_habitable_cancel (hc_handle);
    GNUNET_assert (NULL == delayed_connect_task);
    if (NULL != common_operation)
        GNUNET_TESTBED_operation_done (common_operation);
    if (NULL != reg_handle)
        GNUNET_TESTBED_cancel_registration (reg_handle);
    if (NULL != controller1)
        GNUNET_TESTBED_controller_disconnect (controller1);
    GNUNET_CONFIGURATION_destroy (cfg);
    if (NULL != cfg2)
        GNUNET_CONFIGURATION_destroy (cfg2);
    if (NULL != cp1)
        GNUNET_TESTBED_controller_stop (cp1);
    if (NULL != host)
        GNUNET_TESTBED_host_destroy (host);
    if (NULL != neighbour1)
        GNUNET_TESTBED_host_destroy (neighbour1);
    if (NULL != neighbour2)
        GNUNET_TESTBED_host_destroy (neighbour2);
}
/**
 * Main run function.
 *
 * @param cls NULL
 * @param args arguments passed to GNUNET_PROGRAM_run
 * @param cfgfile the path to configuration file
 * @param cfg the configuration file handle
 */
static void
run (void *cls, char *const *args, const char *cfgfile,
     const struct GNUNET_CONFIGURATION_Handle *config)
{
  host = GNUNET_TESTBED_host_create (NULL, NULL, 0);
  GNUNET_assert (NULL != host);
  if (GNUNET_YES != GNUNET_TESTBED_is_host_habitable (host, config))
  {
    GNUNET_TESTBED_host_destroy (host);
    host = NULL;
    (void) PRINTF ("%s",
                   "Unable to run the test as this system is not configured "
                   "to use password less SSH logins to localhost.\n"
                   "Marking test as successful\n");
    result = SUCCESS;
    return;
  }
  cfg = GNUNET_CONFIGURATION_dup (config);
  cp = GNUNET_TESTBED_controller_start ("127.0.0.1", host, cfg, status_cb,
                                        NULL);
  abort_task =
      GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
                                    (GNUNET_TIME_UNIT_MINUTES, 5), &do_abort,
                                    NULL);
}
/**
 * The shutdown task
 *
 * @param cls NULL
 * @param tc the task context
 */
static void
do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  GNUNET_TESTBED_host_destroy (host);
  while (0 != num_hosts)
  {
    GNUNET_TESTBED_host_destroy (hosts[num_hosts - 1]);
    num_hosts--;
  }
  GNUNET_free (hosts);
  if (NULL != cfg)
  {
    GNUNET_CONFIGURATION_destroy (cfg);
    cfg = NULL;
  }
}
/**
 * Shutdown nicely
 *
 * @param cls NULL
 * @param tc the task context
 */
static void
do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  struct DLLOperation *dll_op;
  unsigned int nhost;

  shutdown_task = GNUNET_SCHEDULER_NO_TASK;
  if (GNUNET_SCHEDULER_NO_TASK != abort_task)
    GNUNET_SCHEDULER_cancel (abort_task);
  if (GNUNET_SCHEDULER_NO_TASK != register_hosts_task)
    GNUNET_SCHEDULER_cancel (register_hosts_task);
  if (NULL != reg_handle)
    GNUNET_TESTBED_cancel_registration (reg_handle);
  if (NULL != topology_op)
    GNUNET_TESTBED_operation_done (topology_op);
  for (nhost = 0; nhost < num_hosts; nhost++)
    if (NULL != hosts[nhost])
      GNUNET_TESTBED_host_destroy (hosts[nhost]);
  GNUNET_free_non_null (hosts);
  while (NULL != (dll_op = dll_op_head))
  {
    GNUNET_TESTBED_operation_done (dll_op->op);
    GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op);
    GNUNET_free (dll_op);
  }
  if (NULL != mc)
    GNUNET_TESTBED_controller_disconnect (mc);
  if (NULL != mc_proc)
    GNUNET_TESTBED_controller_stop (mc_proc);
  if (NULL != cfg)
    GNUNET_CONFIGURATION_destroy (cfg);
  GNUNET_SCHEDULER_shutdown ();	/* Stop scheduler to shutdown testbed run */
}
/**
 * Main run function.
 *
 * @param cls NULL
 * @param args arguments passed to GNUNET_PROGRAM_run
 * @param cfgfile the path to configuration file
 * @param cfg the configuration file handle
 */
static void
run (void *cls, char *const *args, const char *cfgfile,
     const struct GNUNET_CONFIGURATION_Handle *config)
{
  cfg = GNUNET_CONFIGURATION_dup (config);
  host = GNUNET_TESTBED_host_create (NULL, NULL, cfg, 0);
  FAIL_TEST (NULL != host);
  if (NULL ==
      (hc_handle =
       GNUNET_TESTBED_is_host_habitable (host, config, &host_habitable_cb,
                                         NULL)))
  {
    GNUNET_TESTBED_host_destroy (host);
    GNUNET_CONFIGURATION_destroy (cfg);
    cfg = NULL;
    host = NULL;
    (void) PRINTF ("%s",
                   "Unable to run the test as this system is not configured "
                   "to use password less SSH logins to localhost.\n"
                   "Marking test as successful\n");
    result = SKIP;
    return;
  }
  abort_task =
      GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
                                    (GNUNET_TIME_UNIT_MINUTES, 5), &do_abort,
                                    NULL);
}
/**
 * Task to clean up and shutdown nicely
 *
 * @param cls NULL
 * @param tc the TaskContext from scheduler
 */
static void
shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  struct MessageQueue *mq_entry;
  uint32_t id;

  shutdown_task_id = NULL;
  LOG_DEBUG ("Shutting down testbed service\n");
  /* cleanup any remaining forwarded operations */
  GST_clear_fopcq ();
  GST_free_lcfq ();
  GST_free_mctxq ();
  GST_free_occq ();
  GST_free_roccq ();
  GST_free_nccq ();
  GST_neighbour_list_clean();
  GST_free_prcq ();
  /* Clear peer list */
  GST_destroy_peers ();
  /* Clear route list */
  GST_route_list_clear ();
  /* Clear GST_slave_list */
  GST_slave_list_clear ();
  /* Clear host list */
  for (id = 0; id < GST_host_list_size; id++)
    if (NULL != GST_host_list[id])
      GNUNET_TESTBED_host_destroy (GST_host_list[id]);
  GNUNET_free_non_null (GST_host_list);
  if (NULL != GST_context)
  {
    GNUNET_free_non_null (GST_context->master_ip);
    if (NULL != GST_context->system)
      GNUNET_TESTING_system_destroy (GST_context->system, GNUNET_YES);
    GNUNET_SERVER_client_drop (GST_context->client);
    GNUNET_free (GST_context);
    GST_context = NULL;
  }
  if (NULL != transmit_handle)
    GNUNET_SERVER_notify_transmit_ready_cancel (transmit_handle);
  while (NULL != (mq_entry = mq_head))
  {
    GNUNET_free (mq_entry->msg);
    GNUNET_SERVER_client_drop (mq_entry->client);
    GNUNET_CONTAINER_DLL_remove (mq_head, mq_tail, mq_entry);
    GNUNET_free (mq_entry);
  }
  GNUNET_free_non_null (hostname);
  /* Free hello cache */
  GST_cache_clear ();
  GST_connection_pool_destroy ();
  GNUNET_TESTBED_operation_queue_destroy_ (GST_opq_openfds);
  GST_opq_openfds = NULL;
  GST_stats_destroy ();
  GST_barriers_destroy ();
  GNUNET_CONFIGURATION_destroy (GST_config);
}
Beispiel #9
0
/**
 * Shutdown nicely
 *
 * @param cls NULL
 * @param tc the task context
 */
static void
do_shutdown (void *cls)
{
  LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down...\n");
  if (NULL != abort_task)
    GNUNET_SCHEDULER_cancel (abort_task);
  if (NULL != reg_handle)
    GNUNET_TESTBED_cancel_registration (reg_handle);
  if (NULL != controller)
    GNUNET_TESTBED_controller_disconnect (controller);
  if (NULL != cfg)
    GNUNET_CONFIGURATION_destroy (cfg);
  if (NULL != cp)
    GNUNET_TESTBED_controller_stop (cp);
  if (NULL != neighbour)
    GNUNET_TESTBED_host_destroy (neighbour);
  if (NULL != host)
  GNUNET_TESTBED_host_destroy (host);
}
Beispiel #10
0
static void
destroy_hosts(struct GNUNET_TESTBED_Host **hosts, unsigned int nhosts)
{
  unsigned int host;

  GNUNET_assert (NULL != hosts);
  for (host = 0; host < nhosts; host++)
    if (NULL != hosts[host])
      GNUNET_TESTBED_host_destroy (hosts[host]);
  GNUNET_free (hosts);
  hosts = NULL;
}
/**
 * Shutdown nicely
 *
 * @param cls NULL
 * @param tc the task context
 */
static void
do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  if (GNUNET_SCHEDULER_NO_TASK != abort_task)
    GNUNET_SCHEDULER_cancel (abort_task);
  if (NULL != slave3)
    GNUNET_TESTBED_host_destroy (slave3);
  if (NULL != slave2)
    GNUNET_TESTBED_host_destroy (slave2);
  if (NULL != slave)
    GNUNET_TESTBED_host_destroy (slave);
  if (NULL != host)
    GNUNET_TESTBED_host_destroy (host);
  if (NULL != mc)
    GNUNET_TESTBED_controller_disconnect (mc);
  if (NULL != cfg)
    GNUNET_CONFIGURATION_destroy (cfg);
  if (NULL != cfg3)
    GNUNET_CONFIGURATION_destroy (cfg3);
  if (NULL != cp)
    GNUNET_TESTBED_controller_stop (cp);
  if (NULL != rh)
    GNUNET_TESTBED_cancel_registration (rh);
}
/**
 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages
 *
 * @param cls NULL
 * @param client identification of the client
 * @param message the actual message
 */
static void
handle_add_host (void *cls, struct GNUNET_SERVER_Client *client,
                 const struct GNUNET_MessageHeader *message)
{
  struct GNUNET_TESTBED_Host *host;
  const struct GNUNET_TESTBED_AddHostMessage *msg;
  struct GNUNET_TESTBED_HostConfirmedMessage *reply;
  struct GNUNET_CONFIGURATION_Handle *host_cfg;
  char *username;
  char *hostname;
  char *emsg;
  const void *ptr;
  uint32_t host_id;
  uint16_t username_length;
  uint16_t hostname_length;
  uint16_t reply_size;
  uint16_t msize;

  msg = (const struct GNUNET_TESTBED_AddHostMessage *) message;
  msize = ntohs (msg->header.size);
  if (msize <= sizeof (struct GNUNET_TESTBED_AddHostMessage))
  {
    GNUNET_break_op (0);
    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
    return;
  }
  username_length = ntohs (msg->username_length);
  hostname_length = ntohs (msg->hostname_length);
  /* msg must contain hostname */
  if ((msize <= (sizeof (struct GNUNET_TESTBED_AddHostMessage) +
                 username_length))
      || (0 == hostname_length))
  {
    GNUNET_break_op (0);
    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
    return;
  }
  /* msg must contain configuration */
  if (msize <= (sizeof (struct GNUNET_TESTBED_AddHostMessage) +
                username_length + hostname_length))
  {
    GNUNET_break_op (0);
    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
    return;
  }
  username = NULL;
  hostname = NULL;
  ptr = &msg[1];
  if (0 != username_length)
  {
    username = GNUNET_malloc (username_length + 1);
    strncpy (username, ptr, username_length);
    ptr += username_length;
  }
  hostname = GNUNET_malloc (hostname_length + 1);
  strncpy (hostname, ptr, hostname_length);
  if (NULL == (host_cfg = GNUNET_TESTBED_extract_config_ (message)))
  {
    GNUNET_free_non_null (username);
    GNUNET_free_non_null (hostname);
    GNUNET_break_op (0);
    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
    return;
  }
  host_id = ntohl (msg->host_id);
  LOG_DEBUG ("Received ADDHOST %u message\n", host_id);
  LOG_DEBUG ("-------host id: %u\n", host_id);
  LOG_DEBUG ("-------hostname: %s\n", hostname);
  if (NULL != username)
    LOG_DEBUG ("-------username: %s\n", username);
  else
    LOG_DEBUG ("-------username: <not given>\n");
  LOG_DEBUG ("-------ssh port: %u\n", ntohs (msg->ssh_port));
  host =
      GNUNET_TESTBED_host_create_with_id (host_id, hostname, username,
                                          host_cfg, ntohs (msg->ssh_port));
  GNUNET_free_non_null (username);
  GNUNET_free (hostname);
  GNUNET_CONFIGURATION_destroy (host_cfg);
  if (NULL == host)
  {
    GNUNET_break_op (0);
    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
    return;
  }
  reply_size = sizeof (struct GNUNET_TESTBED_HostConfirmedMessage);
  if (GNUNET_OK != host_list_add (host))
  {
    /* We are unable to add a host */
    emsg = "A host exists with given host-id";
    LOG_DEBUG ("%s: %u", emsg, host_id);
    GNUNET_TESTBED_host_destroy (host);
    reply_size += strlen (emsg) + 1;
    reply = GNUNET_malloc (reply_size);
    memcpy (&reply[1], emsg, strlen (emsg) + 1);
  }
  else
  {
    LOG_DEBUG ("Added host %u at %u\n", host_id, GST_context->host_id);
    reply = GNUNET_malloc (reply_size);
  }
  reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST_SUCCESS);
  reply->header.size = htons (reply_size);
  reply->host_id = htonl (host_id);
  GST_queue_message (client, &reply->header);
  GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
/**
 * Main run function.
 *
 * @param cls NULL
 * @param args arguments passed to GNUNET_PROGRAM_run
 * @param cfgfile the path to configuration file
 * @param cfg the configuration file handle
 */
static void
run (void *cls, char *const *args, const char *cfgfile,
     const struct GNUNET_CONFIGURATION_Handle *config)
{
  unsigned int cnt;

  cfg = GNUNET_CONFIGURATION_dup (config);
  host = GNUNET_TESTBED_host_create ("localhost", NULL, cfg, 0);
  GNUNET_assert (NULL != host);
  GNUNET_assert (0 != GNUNET_TESTBED_host_get_id_ (host));
  GNUNET_TESTBED_host_destroy (host);
  host = GNUNET_TESTBED_host_create (NULL, NULL, cfg, 0);
  GNUNET_assert (NULL != host);
  GNUNET_assert (0 == GNUNET_TESTBED_host_get_id_ (host));
  GNUNET_assert (host == GNUNET_TESTBED_host_lookup_by_id_ (0));
  hosts = NULL;
  num_hosts = GNUNET_TESTBED_hosts_load_from_file ("sample_hosts.txt", cfg, &hosts);
  GNUNET_assert (7 == num_hosts);
  GNUNET_assert (NULL != hosts);
  for (cnt = 0; cnt < num_hosts; cnt++)
  {
    if (cnt < 3)
    {
      GNUNET_assert (0 == strcmp ("totakura",
                                  GNUNET_TESTBED_host_get_username_
                                  (hosts[cnt])));
      GNUNET_assert (NULL != GNUNET_TESTBED_host_get_hostname (hosts[cnt]));
      GNUNET_assert (22 == GNUNET_TESTBED_host_get_ssh_port_ (hosts[cnt]));
    }
    if (3 == cnt)
    {
      GNUNET_assert (0 == strcmp ("totakura",
                                  GNUNET_TESTBED_host_get_username_
                                  (hosts[cnt])));
      GNUNET_assert (NULL != GNUNET_TESTBED_host_get_hostname (hosts[cnt]));
      GNUNET_assert (2022 == GNUNET_TESTBED_host_get_ssh_port_ (hosts[cnt]));
    }
    if (4 == cnt)
    {
      GNUNET_assert (0 == strcmp ("totakura",
                                  GNUNET_TESTBED_host_get_username_
                                  (hosts[cnt])));
      GNUNET_assert (0 == strcmp ("asgard.realm",
                                  GNUNET_TESTBED_host_get_hostname
                                  (hosts[cnt])));
      GNUNET_assert (22 == GNUNET_TESTBED_host_get_ssh_port_ (hosts[cnt]));
    }
    if (5 == cnt)
    {
      GNUNET_assert (NULL == GNUNET_TESTBED_host_get_username_ (hosts[cnt]));
      GNUNET_assert (0 == strcmp ("rivendal",
                                  GNUNET_TESTBED_host_get_hostname
                                  (hosts[cnt])));
      GNUNET_assert (22 == GNUNET_TESTBED_host_get_ssh_port_ (hosts[cnt]));
    }
    if (6 == cnt)
    {
      GNUNET_assert (NULL == GNUNET_TESTBED_host_get_username_ (hosts[cnt]));
      GNUNET_assert (0 == strcmp ("rohan",
                                  GNUNET_TESTBED_host_get_hostname
                                  (hosts[cnt])));
      GNUNET_assert (561 == GNUNET_TESTBED_host_get_ssh_port_ (hosts[cnt]));
    }
  }
  status = GNUNET_YES;
  shutdown_id =
      GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (0), &do_shutdown, NULL);
}