/**
 * Task for inserting delay between tests
 *
 * @param
 * @return
 */
static void
delay_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  switch (result)
  {
  case SLAVE2_PEER_CREATE_SUCCESS:
    op = GNUNET_TESTBED_peer_stop (slave1_peer, NULL, NULL);
    GNUNET_assert (NULL != op);
    break;
  case MASTER_SLAVE2_PEERS_CONNECTED:
    op = GNUNET_TESTBED_peer_stop (slave2_peer, NULL, NULL);
    GNUNET_assert (NULL != op);
    break;
  default:
    GNUNET_assert (0);
  }
}
/**
 * Task to be executed when peers are ready
 *
 * @param cls NULL
 * @param tc the task context
 */
static void
master_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  result = GNUNET_OK;
  GNUNET_assert (NULL != peers[0]);
  op = GNUNET_TESTBED_peer_stop (peers[0], NULL, NULL);
  GNUNET_assert (NULL != op);
}
static void
stop_source_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  struct DownloadContext *dc = cls;

  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping source peer\n");
  op = GNUNET_TESTBED_peer_stop (NULL, daemons[1], &do_download, dc);
  GNUNET_assert (NULL != op);
}
/**
 * Task for inserting delay between tests
 *
 * @param
 * @return
 */
static void
delay_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  delay_task_id = NULL;
  switch (result)
  {
  case SLAVE2_PEER_CREATE_SUCCESS:
    op = GNUNET_TESTBED_peer_stop (NULL, slave1_peer, NULL, NULL);
    FAIL_TEST (NULL != op);
    break;
  case MASTER_SLAVE2_PEERS_CONNECTED:
    slave3 = GNUNET_TESTBED_host_create_with_id (3, "127.0.0.1", NULL, cfg, 0);
    rh = GNUNET_TESTBED_register_host (mc, slave3, &registration_cont, NULL);
    break;
  case SLAVE2_SLAVE3_PEERS_CONNECTED:
    op = GNUNET_TESTBED_peer_stop (NULL, slave2_peer, NULL, NULL);
    FAIL_TEST (NULL != op);
    break;
  default:
    FAIL_TEST (0);
  }
}
static void
stop_source_peer (void *cls)
{
  struct DownloadContext *dc = cls;

  /* FIXME: We should not interact with testbed when shutting down */
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Stopping source peer\n");
  op = GNUNET_TESTBED_peer_stop (NULL,
				 daemons[1],
				 &do_download, dc);
  GNUNET_assert (NULL != op);
}
Пример #6
0
/**
 * Signature of a main function for a testcase.
 *
 * @param cls closure
 * @param h the run handle
 * @param num_peers number of peers in 'peers'
 * @param peers_ handle to peers run in the testbed
 * @param links_succeeded the number of overlay link connection attempts that
 *          succeeded
 * @param links_failed the number of overlay link connection attempts that
 *          failed
 */
static void
test_master (void *cls,
             struct GNUNET_TESTBED_RunHandle *h,
             unsigned int num_peers,
             struct GNUNET_TESTBED_Peer **peers_,
             unsigned int links_succeeded,
             unsigned int links_failed)
{
  result = GNUNET_OK;
  if (GNUNET_YES == wait_forever)
  {
    if (NULL == abort_task)
      return;                   /* abort already scheduled */
    GNUNET_SCHEDULER_cancel (abort_task);
    abort_task = NULL;
    GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
    return;
  }
  GNUNET_assert (NULL != peers[0]);
  op = GNUNET_TESTBED_peer_stop (NULL, peers[0], NULL, NULL);
  GNUNET_assert (NULL != op);
}
/**
 * Signature of the event handler function called by the
 * respective event controller.
 *
 * @param cls closure
 * @param event information about the event
 */
static void
controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
{
    switch (event->type)
    {
    case GNUNET_TESTBED_ET_OPERATION_FINISHED:
        if ((NULL != event->op_cls) ||
                (NULL != event->details.operation_finished.emsg))
        {
            GNUNET_break (0);
            abort_test ();
            return;
        }
        switch (result)
        {
        case PEERS_STOPPED:
            if (NULL != event->details.operation_finished.generic)
            {
                GNUNET_break (0);
                abort_test ();
                return;
            }
            if (event->op == peer1.operation)
            {
                GNUNET_TESTBED_operation_done (peer1.operation);
                peer1.operation = NULL;
                peer1.peer = NULL;
            }
            else if (event->op == peer2.operation)
            {
                GNUNET_TESTBED_operation_done (peer2.operation);
                peer2.operation = NULL;
                peer2.peer = NULL;
            }
            else if (event->op == peer3.operation)
            {
                GNUNET_TESTBED_operation_done (peer3.operation);
                peer3.operation = NULL;
                peer3.peer = NULL;
            }
            else
            {
                GNUNET_break (0);
                abort_test ();
                return;
            }
            if ((NULL == peer1.peer) && (NULL == peer2.peer) && (NULL == peer3.peer))
            {
                result = SUCCESS;
                GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
            }
            break;
        case PEER1_STARTED:
            if ((NULL != event->details.operation_finished.generic) ||
                    (NULL == common_operation))
            {
                GNUNET_break (0);
                abort_test ();
                return;
            }
            GNUNET_TESTBED_operation_done (common_operation);
            common_operation = NULL;
            result = CONTROLLER2_UP;
            peer2.operation =
                GNUNET_TESTBED_peer_create (controller1, neighbour1, cfg,
                                            &peer_create_cb, NULL);
            if (NULL == peer2.operation)
            {
                GNUNET_break (0);
                abort_test ();
                return;
            }
            break;
        case PEER2_STARTED:
            if ((NULL != event->details.operation_finished.generic) ||
                    (NULL == common_operation))
            {
                GNUNET_break (0);
                abort_test ();
                return;
            }
            GNUNET_TESTBED_operation_done (common_operation);
            common_operation = NULL;
            result = CONTROLLER3_UP;
            peer3.operation =
                GNUNET_TESTBED_peer_create (controller1, neighbour2, cfg,
                                            &peer_create_cb, NULL);
            if (NULL == peer3.operation)
            {
                GNUNET_break (0);
                abort_test ();
                return;
            }
            break;
        default:
            GNUNET_break (0);
            abort_test ();
            return;
        }
        break;
    case GNUNET_TESTBED_ET_PEER_START:
        switch (result)
        {
        case PEER1_CREATED:
            if (event->details.peer_start.host != host)
            {
                GNUNET_break (0);
                abort_test ();
                return;
            }
            peer1.is_running = GNUNET_YES;
            GNUNET_TESTBED_operation_done (peer1.operation);
            peer1.operation = NULL;
            result = PEER1_STARTED;
            common_operation =
                GNUNET_TESTBED_controller_link (NULL, controller1, neighbour1, NULL,
                                                GNUNET_YES);
            break;
        case PEER2_CREATED:
            if (event->details.peer_start.host != neighbour1)
            {
                GNUNET_break (0);
                abort_test ();
                return;
            }
            peer2.is_running = GNUNET_YES;
            GNUNET_TESTBED_operation_done (peer2.operation);
            peer2.operation = NULL;
            result = PEER2_STARTED;
            if (NULL != common_operation)
            {
                GNUNET_break (0);
                abort_test ();
                return;
            }
            common_operation =
                GNUNET_TESTBED_controller_link (NULL, controller1, neighbour2, NULL,
                                                GNUNET_YES);
            if (NULL == common_operation)
            {
                GNUNET_break (0);
                abort_test ();
                return;
            }
            break;
        case PEER3_CREATED:
            if (event->details.peer_start.host != neighbour2)
            {
                GNUNET_break (0);
                abort_test ();
                return;
            }
            peer3.is_running = GNUNET_YES;
            GNUNET_TESTBED_operation_done (peer3.operation);
            peer3.operation = NULL;
            result = PEER3_STARTED;
            common_operation =
                GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peer2.peer,
                                                peer1.peer);
            break;
        default:
            GNUNET_break (0);
            abort_test ();
            return;
        }
        break;
    case GNUNET_TESTBED_ET_PEER_STOP:
        if (PEERS_CONNECTED_2 != result)
        {
            GNUNET_break (0);
            abort_test ();
            return;
        }
        if (event->details.peer_stop.peer == peer1.peer)
        {
            peer1.is_running = GNUNET_NO;
            GNUNET_TESTBED_operation_done (peer1.operation);
        }
        else if (event->details.peer_stop.peer == peer2.peer)
        {
            peer2.is_running = GNUNET_NO;
            GNUNET_TESTBED_operation_done (peer2.operation);
        }
        else if (event->details.peer_stop.peer == peer3.peer)
        {
            peer3.is_running = GNUNET_NO;
            GNUNET_TESTBED_operation_done (peer3.operation);
        }
        else
        {
            GNUNET_break (0);
            abort_test ();
            return;
        }
        if ((GNUNET_NO == peer1.is_running) && (GNUNET_NO == peer2.is_running) &&
                (GNUNET_NO == peer3.is_running))
        {
            result = PEERS_STOPPED;
            peer1.operation = GNUNET_TESTBED_peer_destroy (peer1.peer);
            peer2.operation = GNUNET_TESTBED_peer_destroy (peer2.peer);
            peer3.operation = GNUNET_TESTBED_peer_destroy (peer3.peer);
        }
        break;
    case GNUNET_TESTBED_ET_CONNECT:
        if ((NULL != peer1.operation) || (NULL != peer2.operation) ||
                (NULL != peer3.operation) || (NULL == common_operation))
        {
            GNUNET_break (0);
            abort_test ();
            return;
        }
        switch (result)
        {
        case PEER3_STARTED:
            if ((event->details.peer_connect.peer1 != peer2.peer) ||
                    (event->details.peer_connect.peer2 != peer1.peer))
            {
                GNUNET_break (0);
                abort_test ();
                return;
            }
            GNUNET_TESTBED_operation_done (common_operation);
            common_operation = NULL;
            result = PEERS_1_2_CONNECTED;
            LOG (GNUNET_ERROR_TYPE_DEBUG, "Peers connected\n");
            common_operation =
                GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peer2.peer,
                                                peer3.peer);
            break;
        case PEERS_1_2_CONNECTED:
            if ((event->details.peer_connect.peer1 != peer2.peer) ||
                    (event->details.peer_connect.peer2 != peer3.peer))
            {
                GNUNET_break (0);
                abort_test ();
                return;
            }
            GNUNET_TESTBED_operation_done (common_operation);
            common_operation = NULL;
            result = PEERS_2_3_CONNECTED;
            delayed_connect_task =
                GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (3), &do_delayed_connect,
                                              NULL);
            break;
        case PEERS_2_3_CONNECTED:
            if ((event->details.peer_connect.peer1 != peer1.peer) ||
                    (event->details.peer_connect.peer2 != peer2.peer))
            {
                GNUNET_break (0);
                abort_test ();
                return;
            }
            GNUNET_TESTBED_operation_done (common_operation);
            common_operation = NULL;
            result = PEERS_CONNECTED_2;
            LOG (GNUNET_ERROR_TYPE_DEBUG, "Peers connected again\n");
            peer1.operation = GNUNET_TESTBED_peer_stop (NULL, peer1.peer, NULL, NULL);
            peer2.operation = GNUNET_TESTBED_peer_stop (NULL, peer2.peer, NULL, NULL);
            peer3.operation = GNUNET_TESTBED_peer_stop (NULL, peer3.peer, NULL, NULL);
            break;
        default:
            GNUNET_break (0);
            abort_test ();
            return;
        }
        break;
    default:
        GNUNET_break (0);
        abort_test ();
        return;
    }
}