/**
 * Functions of this signature are called when a peer has been successfully
 * created
 *
 * @param cls the closure from GNUNET_TESTBED_peer_create()
 * @param peer the handle for the created peer; NULL on any error during
 *          creation
 * @param emsg NULL if peer is not NULL; else MAY contain the error description
 */
static void
peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
{
  GNUNET_assert (NULL != peer);
  GNUNET_assert (NULL == emsg);
  switch (result)
  {
  case MASTER_STARTED:
    result = MASTER_PEER_CREATE_SUCCESS;
    master_peer = peer;
    GNUNET_TESTBED_operation_done (op);
    op = GNUNET_TESTBED_peer_start (NULL, master_peer, NULL, NULL);
    break;
  case SLAVE1_LINK_SUCCESS:
    result = SLAVE1_PEER_CREATE_SUCCESS;
    slave1_peer = peer;
    GNUNET_TESTBED_operation_done (op);   
    op = GNUNET_TESTBED_peer_start (NULL, slave1_peer, NULL, NULL);
    break;
  case SLAVE2_LINK_SUCCESS:
    result = SLAVE2_PEER_CREATE_SUCCESS;
    slave2_peer = peer;
    GNUNET_TESTBED_operation_done (op);
    GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
                                  (GNUNET_TIME_UNIT_SECONDS, 1), &delay_task,
                                  NULL);
    break;
  default:
    GNUNET_assert (0);
  }
  GNUNET_assert (NULL != op);
}
/**
 * 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 */
}
Ejemplo n.º 3
0
/**
 * Shutdown nicely
 */
static void
do_close (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  switch (test_step)
  {
  case TEST_STEP_1_HOP:
    if (NULL != peer_data[0].socket)
      GNUNET_STREAM_close (peer_data[0].socket);
    if (NULL != peer_data[1].socket)
      GNUNET_STREAM_close (peer_data[1].socket);
    if (NULL != peer2_listen_socket)
      GNUNET_STREAM_listen_close (peer2_listen_socket); /* Close listen socket */
    break;
  case TEST_STEP_2_HOP:
    if (NULL != peer_data[1].socket)
      GNUNET_STREAM_close (peer_data[1].socket);
    if (NULL != peer_data[0].op)
      GNUNET_TESTBED_operation_done (peer_data[0].op);
    if (NULL != peer_data[1].op)
      GNUNET_TESTBED_operation_done (peer_data[1].op);
    break;
  case TEST_STEP_3_HOP:
    GNUNET_break (0);    
  }  
  if (GNUNET_SCHEDULER_NO_TASK != abort_task)
    GNUNET_SCHEDULER_cancel (abort_task);
  if (GNUNET_SCHEDULER_NO_TASK != write_task)
    GNUNET_SCHEDULER_cancel (write_task);
  GNUNET_SCHEDULER_shutdown (); /* Shutdown this testcase */
  if (NULL != meter)
  {
    free_meter (meter);
    meter = NULL;
  }
}
/**
 * Functions of this signature are called when a peer has been successfully
 * started or stopped.
 *
 * @param cls the closure from GNUNET_TESTBED_peer_start/stop()
 * @param emsg NULL on success; otherwise an error description
 */
static void 
peer_churn_cb (void *cls, const char *emsg)
{
  struct DLLOperation *dll_op = cls;
  struct GNUNET_TESTBED_Operation *op;  
  static unsigned int started_peers;

  op = dll_op->op;
  GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op);
  GNUNET_free (dll_op);
  if (NULL != emsg)
  {
    LOG (GNUNET_ERROR_TYPE_WARNING,
         _("An operation has failed while starting peers\n"));
    GNUNET_TESTBED_operation_done (op);
    GNUNET_SCHEDULER_cancel (abort_task);
    abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL);
    return;
  }
  GNUNET_TESTBED_operation_done (op);
  if (++started_peers == num_peers)
  {
    prof_time = GNUNET_TIME_absolute_get_duration (prof_start_time);
    printf ("%u peers started successfully in %.2f seconds\n",
            num_peers, ((double) prof_time.rel_value) / 1000.00);
    fflush (stdout);
    result = GNUNET_OK;
    if ((0 == num_links) && (topology == GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI))
    { 
      fprintf (stdout, "Testbed running, waiting for keystroke to shut down\n");
      (void) getc (stdin);
      shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
      return;
    }
    state = STATE_PEERS_LINKING;
    /* Do overlay connect */
    prof_start_time = GNUNET_TIME_absolute_get ();
    switch (topology)
    {
    case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI:
      topology_op =
          GNUNET_TESTBED_overlay_configure_topology (NULL, num_peers, peers, NULL,
                                                     topology,
                                                     num_links,
                                                     GNUNET_TESTBED_TOPOLOGY_DISABLE_AUTO_RETRY,
                                                     GNUNET_TESTBED_TOPOLOGY_OPTION_END);
      break;
    case GNUNET_TESTBED_TOPOLOGY_CLIQUE:
      topology_op =
          GNUNET_TESTBED_overlay_configure_topology (NULL, num_peers, peers, NULL,
                                                     topology,
                                                     GNUNET_TESTBED_TOPOLOGY_DISABLE_AUTO_RETRY,
                                                     GNUNET_TESTBED_TOPOLOGY_OPTION_END);
      num_links = num_peers * (num_peers - 1);
      break;
    default:
      GNUNET_assert (0);
    }
  }
}
/**
 * Check if the get_handle is being used, if so stop the request.  Either
 * way, schedule the end_badly_cont function which actually shuts down the
 * test.
 */
static void
end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  die_task = GNUNET_SCHEDULER_NO_TASK;
  int c;

  if (GNUNET_SCHEDULER_NO_TASK != wait_task)
  {
      GNUNET_SCHEDULER_cancel (wait_task);
      wait_task = GNUNET_SCHEDULER_NO_TASK;
  }

  for (c = 0; c < 3; c++)
  {
    if (NULL != nh[c])
    {
      GNUNET_NAMESTORE_disconnect(nh[c]);
      nh[c] = NULL;
    }

    if (NULL != get_cfg_ops[c])
    {
        GNUNET_TESTBED_operation_done(get_cfg_ops[c]);
        get_cfg_ops[c] = NULL;
    }
    if (NULL != cfg_handles[c])
    {
      GNUNET_CONFIGURATION_destroy (cfg_handles[c]);
      cfg_handles[c] = NULL;
    }
  }
  if (NULL != topology_op)
  {
    GNUNET_TESTBED_operation_done (topology_op);
    topology_op = NULL;
  }
  if (NULL != lookup_handle)
  {
    GNUNET_GNS_cancel_lookup_request (lookup_handle);
    lookup_handle = NULL;
  }
  if (NULL != gh)
  {
    GNUNET_GNS_disconnect(gh);
    gh = NULL;
  }
  
  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Test failed \n");
  GNUNET_SCHEDULER_shutdown ();
  ok = 1;
}
Ejemplo n.º 6
0
static void
destroy (void *cls)
{
  struct GNUNET_CONSENSUS_Handle *consensus = cls;

  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
              "destroying consensus\n");
  GNUNET_CONSENSUS_destroy (consensus);
  peers_done++;
  if (peers_done == num_peers)
  {
    unsigned int i;
    for (i = 0; i < num_peers; i++)
      GNUNET_TESTBED_operation_done (testbed_operations[i]);
    for (i = 0; i < num_peers; i++)
      printf ("P%u got %u of %u elements\n",
              i,
              results_for_peer[i],
              num_values);
    if (NULL != statistics_filename)
      statistics_file = fopen (statistics_filename, "w");
    GNUNET_TESTBED_get_statistics (num_peers, peers, NULL, NULL,
                                   statistics_cb,
                                   statistics_done_cb,
                                   NULL);
  }
}
/**
 * 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);
}
static void
do_publish1 (void *cls,
	     struct GNUNET_TESTBED_Operation *op,
	     const char *emsg)
{
  unsigned int *coco = cls;
  int do_index;
  int anonymity;

  GNUNET_TESTBED_operation_done (op);
  if (NULL != emsg)
  {
    cleanup ();
    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error trying to connect: %s\n", emsg);
    ok = 1;
    return;
  }
  if (0 != (--(*coco)))
    return; /* more connections to be created */
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n",
              (unsigned long long) FILESIZE);
  if (NULL != strstr (progname, "index"))
    do_index = GNUNET_YES;
  else
    do_index = GNUNET_NO;
  if (NULL != strstr (progname, "dht"))
    anonymity = 0;
  else
    anonymity = 1;
  GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS - 1], TIMEOUT, anonymity,
                          do_index, FILESIZE, SEED1, VERBOSE, &do_publish2,
                          NULL);
}
/**
 * Cleans up the queue used for forwarding link controllers requests
 */
void
GST_free_lcfq ()
{
  struct LCFContextQueue *lcfq;
  struct LCFContext *lcf;

  if (NULL != lcfq_head)
  {
    if (NULL != lcf_proc_task_id)
    {
      GNUNET_SCHEDULER_cancel (lcf_proc_task_id);
      lcf_proc_task_id = NULL;
    }
  }
  GNUNET_assert (NULL == lcf_proc_task_id);
  for (lcfq = lcfq_head; NULL != lcfq; lcfq = lcfq_head)
  {
    lcf = lcfq->lcf;
    GNUNET_SERVER_client_drop (lcf->client);
    if (NULL != lcf->op)
      GNUNET_TESTBED_operation_done (lcf->op);
    if (NULL != lcf->timeout_task)
      GNUNET_SCHEDULER_cancel (lcf->timeout_task);
    GNUNET_free (lcf);
    GNUNET_CONTAINER_DLL_remove (lcfq_head, lcfq_tail, lcfq);
    GNUNET_free (lcfq);
  }
}
/**
 * Called when a decryption has succeeded.
 *
 * @param cls Plaintext
 * @param plaintext Plaintext
 */
static void decrypt_cb (void *cls,
                        const struct GNUNET_SECRETSHARING_Plaintext *plaintext)
{
  struct GNUNET_SECRETSHARING_DecryptionHandle **dhp = cls;
  unsigned int n = dhp - decrypt_handles;
  num_decrypted++;

  *dhp = NULL;

  // we should still be connected if this is called
  GNUNET_assert (NULL != connect_ops[n]);

  GNUNET_TESTBED_operation_done (connect_ops[n]);

  if (NULL == plaintext)
  {
    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "decrypt failed for peer %u\n", n);
    return;
  }
  else if (0 == memcmp (&reference_plaintext, plaintext, sizeof (struct GNUNET_SECRETSHARING_Plaintext)))
    GNUNET_log (GNUNET_ERROR_TYPE_INFO, "decrypt got correct result for peer %u\n", n);
  else
    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "decrypt got wrong result for peer %u\n", n);

  if (num_decrypted == num_peers)
  {
    GNUNET_log (GNUNET_ERROR_TYPE_INFO, "every peer decrypted\n");
    GNUNET_SCHEDULER_shutdown ();
  }

  *dhp = NULL;
}
Ejemplo n.º 11
0
/**
 * Controller event callback
 *
 * @param cls NULL
 * @param event the controller event
 */
static void
controller_event_cb (void *cls,
                     const struct GNUNET_TESTBED_EventInformation *event)
{
  switch (event->type)
  {
  case GNUNET_TESTBED_ET_OPERATION_FINISHED:
    if (NULL != event->details.operation_finished.emsg)
    {
      FPRINTF (stderr, "Error while expecting an operation to succeed:%s \n",
	       event->details.operation_finished.emsg);
      GNUNET_assert (0);
    }
    break;
  case GNUNET_TESTBED_ET_CONNECT:
    GNUNET_TESTBED_operation_done (common_op);
    /* Get the peer identity and configuration of peers */
    common_op =
	GNUNET_TESTBED_peer_get_information (peer_data[0].peer,
					     GNUNET_TESTBED_PIT_IDENTITY,
					     &peerinfo_cb, &peer_data[0]);
    break;
  default:
    GNUNET_assert (0);
  }
}
Ejemplo n.º 12
0
void testbed_controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
{
  static int connections = 0;

  switch (event->type)
  {
    case GNUNET_TESTBED_ET_OPERATION_FINISHED:
      /* This part will still be called when
	 GNUNET_TESTBED_peer_get_information() succeeds. However, the code is
	 now more relevant in operation completion callback */
      break;
    case GNUNET_TESTBED_ET_CONNECT:
      connections ++;
      if (connections == 3)
      {
          GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers connected\n");
          GNUNET_TESTBED_operation_done (topology_op);
          topology_op = NULL;
          all_connected ();
      }
      break;
    default:
      /* whatever ... */
      break;
  }
}
Ejemplo n.º 13
0
/**
 * Callback for event from slave controllers
 *
 * @param cls NULL
 * @param event information about the event
 */
static void
slave_event_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
{
  struct LCFContext *lcf;

  /* We currently only get here when working on LCFContexts */
  GNUNET_assert (GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type);
  lcf = event->op_cls;
  GNUNET_assert (lcf->op == event->op);
  GNUNET_TESTBED_operation_done (lcf->op);
  lcf->op = NULL;
  GNUNET_assert (FINISHED == lcf->state);
  GNUNET_assert (NULL != lcf->timeout_task);
  GNUNET_SCHEDULER_cancel (lcf->timeout_task);
  if (NULL == event->details.operation_finished.emsg)
    send_controller_link_response (lcf->client, lcf->operation_id,
                                   GNUNET_TESTBED_host_get_cfg_
                                   (GST_host_list[lcf->delegated_host_id]),
                                   NULL);
  else
    send_controller_link_response (lcf->client, lcf->operation_id,
                                   NULL,
                                   event->details.operation_finished.emsg);
  GNUNET_assert (NULL == lcf_proc_task_id);
  lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
  return;
}
/**
 * Callback to be called when the requested peer information is available
 *
 * @param cb_cls the closure from GNUNET_TETSBED_peer_get_information()
 * @param op the operation this callback corresponds to
 * @param pinfo the result; will be NULL if the operation has failed
 * @param emsg error message if the operation has failed; will be NULL if the
 *          operation is successfull
 */
static void
peer_info_cb (void *cb_cls,
              struct GNUNET_TESTBED_Operation *op,
              const struct GNUNET_TESTBED_PeerInformation *pinfo,
              const char *emsg)
{
  struct GNUNET_PeerIdentity *p;
  int i;

  GNUNET_assert (NULL == emsg);

  p = (struct GNUNET_PeerIdentity *) cb_cls;

  if (pinfo->pit == GNUNET_TESTBED_PIT_IDENTITY)
  {
    *p = *pinfo->result.id;
    num_retrieved_peer_ids++;
    if (num_retrieved_peer_ids == num_peers)
      for (i = 0; i < num_peers; i++)
        testbed_operations[i] =
            GNUNET_TESTBED_service_connect (NULL, peers[i], "secretsharing", session_connect_complete, NULL,
                                            session_connect_adapter, session_disconnect_adapter, &session_handles[i]);
  }
  else
  {
    GNUNET_assert (0);
  }

  GNUNET_TESTBED_operation_done (op);
}
static void
do_download (void *cls,
	     const char *emsg)
{
  struct DownloadContext *dc = cls;
  struct GNUNET_FS_Uri *uri = dc->uri;

  GNUNET_TESTBED_operation_done (op);
  op = NULL;
  if (NULL != dc->fn)
  {
    GNUNET_DISK_directory_remove (dc->fn);
    GNUNET_free (dc->fn);
  }
  GNUNET_free (dc);
  if (NULL != emsg)
  {
    GNUNET_SCHEDULER_shutdown ();
    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to stop source daemon: %s\n",
                emsg);
    GNUNET_FS_uri_destroy (uri);
    ok = 1;
    return;
  }
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n",
              (unsigned long long) FILESIZE);
  start_time = GNUNET_TIME_absolute_get ();
  GNUNET_FS_TEST_download (daemons[0], TIMEOUT, 1, SEED, uri, VERBOSE, &do_stop,
                           NULL);
  GNUNET_FS_uri_destroy (uri);
}
Ejemplo n.º 16
0
/**
 * Callback to be called when the requested peer information is available
 *
 * @param cb_cls the closure from GNUNET_TETSBED_peer_get_information()
 * @param op the operation this callback corresponds to
 * @param pinfo the result; will be NULL if the operation has failed
 * @param emsg error message if the operation has failed; will be NULL if the
 *          operation is successfull
 */
static void 
peerinfo_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op,
	     const struct GNUNET_TESTBED_PeerInformation *pinfo,
	     const char *emsg)
{
  struct PeerData *pdata = cb_cls;

  GNUNET_assert (NULL == emsg);
  GNUNET_assert (common_op == op);
  GNUNET_assert (NULL != pdata);
  memcpy (&pdata->id, pinfo->result.id, sizeof (struct GNUNET_PeerIdentity));
  GNUNET_TESTBED_operation_done (op);
  if (pdata == &peer_data[0])
  {
    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer 1 id: %s\n",
		GNUNET_i2s (&pdata->id));
    common_op = GNUNET_TESTBED_peer_get_information (peer_data[1].peer,
						     GNUNET_TESTBED_PIT_IDENTITY,
						     &peerinfo_cb, &peer_data[1]);
  }
  else if (pdata == &peer_data[1])
  {
    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer 2 id: %s\n",
		GNUNET_i2s (&pdata->id));
    if (TEST_STEP_2_HOP == test_step)
      peer_data[1].op = 
	  GNUNET_TESTBED_service_connect (&peer_data[1], peer_data[1].peer,
					  "stream", NULL, NULL, stream_ca,
					  stream_da, &peer_data[1]);
    else
      GNUNET_break (0);		/* FIXME: 3 hop test case here... */
  }
}
Ejemplo n.º 17
0
/**
 * Function called when get_statistics operation is cancelled or marked as done
 *
 * @param cls the GetStatsContext
 */
static void
oprelease_get_stats (void *cls)
{
  struct GetStatsContext *sc = cls;
  unsigned int peer;

  LOG_DEBUG ("Cleaning up get_statistics operation\n");
  if (NULL != sc->call_completion_task_id)
    GNUNET_SCHEDULER_cancel (sc->call_completion_task_id);
  if (NULL != sc->ops)
  {
    for (peer = 0; peer < sc->num_peers; peer++)
    {
      if (NULL != sc->ops[peer])
      {
        GNUNET_TESTBED_operation_done (sc->ops[peer]);
        sc->ops[peer] = NULL;
      }
    }
    GNUNET_free (sc->ops);
  }
  GNUNET_free_non_null (sc->subsystem);
  GNUNET_free_non_null (sc->name);
  GNUNET_free (sc);
  if (GNUNET_YES ==
      GNUNET_TESTBED_operation_queue_destroy_empty_ (no_wait_queue))
    no_wait_queue = NULL;
}
Ejemplo n.º 18
0
static void
topology_completed (void *cls,
                    unsigned int nsuccess,
                    unsigned int nfailures)
{
  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
              "Links successful %u / %u failed\n",
              nsuccess,
              nfailures);
  GNUNET_TESTBED_operation_done (topology_op);
  topology_op = NULL;

  if (nfailures > 0)
  {
    fprintf (stderr,
             "Error: links successful %u but %u failed\n",
             nsuccess,
             nfailures);
    ok = 1;
  }
  else
    ok = 0;

  GNUNET_SCHEDULER_shutdown ();
}
Ejemplo n.º 19
0
/**
 * Functions of this signature are called when a peer has been successfully
 * created
 *
 * @param cls the closure from GNUNET_TESTBED_peer_create()
 * @param peer the handle for the created peer; NULL on any error during
 *          creation
 * @param emsg NULL if peer is not NULL; else MAY contain the error description
 */
static void
peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
{
  struct RunContextOperation *rcop = cls;
  struct GNUNET_TESTBED_RunHandle *rc;

  GNUNET_assert (NULL != rcop);
  GNUNET_assert (NULL != (rc = rcop->rc));
  remove_rcop (rc, rcop);
  GNUNET_TESTBED_operation_done (rcop->op);
  GNUNET_free (rcop);
  if (NULL == peer)
  {
    if (NULL != emsg)
      LOG (GNUNET_ERROR_TYPE_ERROR, "Error while creating a peer: %s\n",
           emsg);
    GNUNET_SCHEDULER_shutdown ();
    return;
  }
  rc->peers[rc->peer_count] = peer;
  rc->peer_count++;
  if (rc->peer_count < rc->num_peers)
    return;
  DEBUG ("%u peers created in %s\n", rc->num_peers, prof_time (rc));
  rc->state = RC_PEERS_CREATED;
  GNUNET_SCHEDULER_add_now (&start_peers_task, rc);
}
Ejemplo n.º 20
0
/**
 * Cleans up the queue used for forwarding link controllers requests
 */
void
GST_free_lcf ()
{
  struct LCFContext *lcf;

  if (NULL != lcf_head)
  {
    if (NULL != lcf_proc_task_id)
    {
      GNUNET_SCHEDULER_cancel (lcf_proc_task_id);
      lcf_proc_task_id = NULL;
    }
  }
  GNUNET_assert (NULL == lcf_proc_task_id);
  for (lcf = lcf_head; NULL != lcf; lcf = lcf_head)
  {
    if (NULL != lcf->op)
      GNUNET_TESTBED_operation_done (lcf->op);
    if (NULL != lcf->timeout_task)
      GNUNET_SCHEDULER_cancel (lcf->timeout_task);
    GNUNET_CONTAINER_DLL_remove (lcf_head,
                                 lcf_tail,
                                 lcf);
    GNUNET_free (lcf);
  }
}
/**
 * Functions of this signature are called when a peer has been successfully
 * created
 *
 * @param cls NULL
 * @param peer the handle for the created peer; NULL on any error during
 *          creation
 * @param emsg NULL if peer is not NULL; else MAY contain the error description
 */
static void
peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
{
    switch (result)
    {
    case CONTROLLER1_UP:
        if ((NULL == peer1.operation) || (NULL == peer) || (NULL != peer1.peer))
        {
            GNUNET_break (0);
            abort_test ();
            return;
        }
        peer1.peer = peer;
        GNUNET_TESTBED_operation_done (peer1.operation);
        result = PEER1_CREATED;
        peer1.operation = GNUNET_TESTBED_peer_start (NULL, peer, NULL, NULL);
        break;
    case CONTROLLER2_UP:
        if ((NULL == peer2.operation) || (NULL == peer) || (NULL != peer2.peer))
        {
            GNUNET_break (0);
            abort_test ();
            return;
        }
        peer2.peer = peer;
        GNUNET_TESTBED_operation_done (peer2.operation);
        result = PEER2_CREATED;
        peer2.operation = GNUNET_TESTBED_peer_start (NULL, peer, NULL, NULL);
        break;
    case CONTROLLER3_UP:
        if ((NULL == peer3.operation) || (NULL == peer) || (NULL != peer3.peer))
        {
            GNUNET_break (0);
            abort_test ();
            return;
        }
        peer3.peer = peer;
        GNUNET_TESTBED_operation_done (peer3.operation);
        result = PEER3_CREATED;
        peer3.operation = GNUNET_TESTBED_peer_start (NULL, peer, NULL, NULL);
        break;
    default:
        GNUNET_break (0);
        abort_test ();
        return;
    }
}
Ejemplo n.º 22
0
static void
in_time_shutdown_task ()
{
  if (NULL != basic_mqtt_op_publish)
  {
    GNUNET_TESTBED_operation_done (basic_mqtt_op_publish); /* calls the gmqtt_da_publish() for closing
							      down the connection */
    basic_mqtt_op_publish = NULL;
  }
  if (NULL != basic_mqtt_op_subscribe)
  {
    GNUNET_TESTBED_operation_done (basic_mqtt_op_subscribe); /* calls the gmqtt_da_subscribe() for closing
								down the connection */
    basic_mqtt_op_subscribe = NULL;
  }
  GNUNET_SCHEDULER_cancel(shutdown_tid);
  GNUNET_SCHEDULER_shutdown (); /* Also kills the testbed */
}
Ejemplo n.º 23
0
/**
 * Task run on timeout to shut everything down.
 */
static void
shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  unsigned int i;

  for (i=0;i<NUM_PEERS;i++)
    GNUNET_TESTBED_operation_done (nse_peers[i].op);
  GNUNET_SCHEDULER_shutdown ();
}
/**
 * Functions of this signature are called when a peer has been successfully
 * created
 *
 * @param cls the closure from GNUNET_TESTBED_peer_create()
 * @param peer the handle for the created peer; NULL on any error during
 *          creation
 * @param emsg NULL if peer is not NULL; else MAY contain the error description
 */
static void 
peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
{
  struct DLLOperation *dll_op = cls;
  struct GNUNET_TESTBED_Peer **peer_ptr;
  static unsigned int created_peers;
  unsigned int peer_cnt;

  if (NULL != emsg)
  {
    LOG (GNUNET_ERROR_TYPE_WARNING,
         _("Creating a peer failed. Error: %s\n"), emsg);
    GNUNET_TESTBED_operation_done (dll_op->op);
    GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op);
    GNUNET_free (dll_op);
    GNUNET_SCHEDULER_cancel (abort_task);
    abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL);
    return;
  }
  peer_ptr = dll_op->cls;
  GNUNET_assert (NULL == *peer_ptr);
  *peer_ptr = peer;
  GNUNET_TESTBED_operation_done (dll_op->op);
  GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op);
  GNUNET_free (dll_op);
  if (++created_peers == num_peers)
  {
    prof_time = GNUNET_TIME_absolute_get_duration (prof_start_time);    
    printf ("%u peers created successfully in %.2f seconds\n",
            num_peers, ((double) prof_time.rel_value) / 1000.00);
    fflush (stdout);
    /* Now peers are to be started */
    state = STATE_PEERS_STARTING;
    prof_start_time = GNUNET_TIME_absolute_get ();
    for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++)
    {
      dll_op = GNUNET_malloc (sizeof (struct DLLOperation));
      dll_op->op = GNUNET_TESTBED_peer_start (dll_op, peers[peer_cnt], 
                                              &peer_churn_cb, dll_op);
      GNUNET_CONTAINER_DLL_insert_tail (dll_op_head, dll_op_tail, dll_op);
    }
  }
}
Ejemplo n.º 25
0
static void
shutdown_task (void *cls,
	       const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  if (NULL != basic_mqtt_op_publish)
  {
    GNUNET_TESTBED_operation_done (basic_mqtt_op_publish); /* calls the gmqtt_da() for closing
							      down the connection */
    basic_mqtt_op_publish = NULL;
  }
  
  if (NULL != basic_mqtt_op_subscribe)
  {
    GNUNET_TESTBED_operation_done (basic_mqtt_op_subscribe); /* calls the gmqtt_da() for closing
								down the connection */
    basic_mqtt_op_subscribe = NULL;
  }
  GNUNET_SCHEDULER_shutdown (); /* Also kills the testbed */
}
Ejemplo n.º 26
0
static void
do_shutdown (void *cls,
             const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  shutdown_task = NULL;
  if (NULL != topology_op)
  {
    GNUNET_TESTBED_operation_done (topology_op);
    topology_op = NULL;
  }
}
/**
 * Shutdown nicely
 *
 * @param cls NULL
 * @param tc the task context
 */
static void
do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  shutdown_task = GNUNET_SCHEDULER_NO_TASK;
  if (NULL != op)
  {
    GNUNET_TESTBED_operation_done (op);
    op = NULL;
  }
  GNUNET_SCHEDULER_shutdown ();
}
Ejemplo n.º 28
0
/**
 * Clean up the testbed.
 *
 * @param ctx handle for the testbed
 */
void
GNUNET_DHT_TEST_cleanup (struct GNUNET_DHT_TEST_Context *ctx)
{
  unsigned int i;

  for (i=0;i<ctx->num_peers;i++)
    GNUNET_TESTBED_operation_done (ctx->ops[i]);
  GNUNET_free (ctx->ops);
  GNUNET_free (ctx->dhts);
  GNUNET_free (ctx);
  GNUNET_SCHEDULER_shutdown ();
}
Ejemplo n.º 29
0
/**
 * Iterator for cleaning up elements from rcop_map
 *
 * @param cls the RunContext
 * @param key the 32-bit key
 * @param value the RunContextOperation element
 * @return always GNUNET_YES
 */
static int
rcop_cleanup_iterator (void *cls, uint32_t key, void *value)
{
  struct GNUNET_TESTBED_RunHandle *rc = cls;
  struct RunContextOperation *rcop = value;

  GNUNET_assert (rc == rcop->rc);
  remove_rcop (rc, rcop);
  GNUNET_TESTBED_operation_done (rcop->op);
  GNUNET_free (rcop);
  return GNUNET_YES;
}
Ejemplo n.º 30
0
static void
shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  shutdown_tid = GNUNET_SCHEDULER_NO_TASK;
  if (NULL != basic_mqtt_op)
  {
    GNUNET_TESTBED_operation_done (basic_mqtt_op); /* calls the gmqtt_da() for closing
						      down the connection */
    basic_mqtt_op = NULL;
  }
  
  GNUNET_SCHEDULER_shutdown (); /* Also kills the testbed */
}