static void
run (void *cls, char *const *args, const char *cfgfile,
     const struct GNUNET_CONFIGURATION_Handle *cfg)
{
  die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);

  s_started = GNUNET_NO;
  s_connected = GNUNET_NO;
  s_sending = GNUNET_NO;

  p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1,
                                            &notify_receive, &notify_connect,
                                            &notify_disconnect, &start_cb,
                                            NULL);

  p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2,
                                            &notify_receive, &notify_connect,
                                            &notify_disconnect, &start_cb,
                                            NULL);

  if ((p1 == NULL) || (p2 == NULL))
  {
    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail! Could not start peers!\n");
    if (die_task != NULL)
      GNUNET_SCHEDULER_cancel (die_task);
    die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
    return;
  }
}
static void
run (void *cls, char *const *args, const char *cfgfile,
     const struct GNUNET_CONFIGURATION_Handle *cfg)
{
  tth = GNUNET_TRANSPORT_TESTING_init ();

  timeout_task =
      GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, &end_badly, NULL);

  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting peer\n");
  p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
                                            "test_transport_api_tcp_peer1.conf",
                                            1, &notify_receive, &notify_connect,
                                            &notify_disconnect, &start_cb, p1);

  p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
                                            "test_transport_api_tcp_peer2.conf",
                                            2, &notify_receive, &notify_connect,
                                            &notify_disconnect, &start_cb, p2);

  if (p1 == NULL)
  {
    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                "Peer1 was not started successfully\n");
    GNUNET_SCHEDULER_shutdown ();
  }
  if (p2 == NULL)
  {
    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                "Peer2 was not started successfully\n");
    GNUNET_SCHEDULER_shutdown ();
  }
}
static void
run (void *cls, char *const *args, const char *cfgfile,
     const struct GNUNET_CONFIGURATION_Handle *cfg)
{
  die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
  connected = GNUNET_NO;
  blacklist_request_p1 = GNUNET_NO;
  blacklist_request_p2 = GNUNET_NO;

  p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, "test_transport_api_tcp_peer1.conf", 1,
                                            &notify_receive, &notify_connect,
                                            &notify_disconnect, &start_cb,
                                            NULL);

  p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, "test_transport_api_tcp_peer2.conf", 2,
                                            &notify_receive, &notify_connect,
                                            &notify_disconnect, &start_cb,
                                            NULL);

  blacklist_p1 = GNUNET_TRANSPORT_blacklist (p1->cfg,
                              &blacklist_cb,
                              p1);

  blacklist_p2 = GNUNET_TRANSPORT_blacklist (p2->cfg,
                              &blacklist_cb,
                              p2);

  GNUNET_assert (blacklist_p1 != NULL);
  GNUNET_assert (blacklist_p2 != NULL);
}
static void
run (void *cls,
     char *const *args,
     const char *cfgfile,
     const struct GNUNET_CONFIGURATION_Handle *cfg)
{
  ret = 1;
  tth = GNUNET_TRANSPORT_TESTING_init ();
  GNUNET_assert (NULL != tth);

  timeout_task =
      GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
                                    &end_badly,
                                    NULL);

  p = GNUNET_TRANSPORT_TESTING_start_peer (tth,
					   cfgfile,
					   1,
					   NULL, /* receive cb */
					   NULL, /* connect cb */
					   NULL, /* disconnect cb */
					   NULL, /* nc/nd closure */
					   &start_cb, /* startup cb */
					   NULL); /* closure */
  if (NULL == p)
  {
    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start peer\n");
    if (timeout_task != NULL)
      GNUNET_SCHEDULER_cancel (timeout_task);
    timeout_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
  }
}
static void
run_measurement (unsigned long long p1_quota_in,
                 unsigned long long p1_quota_out,
                 unsigned long long p2_quota_in,
                 unsigned long long p2_quota_out)
{
  die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);

  /* setting ATS quota */
  quota_out_p1 = p1_quota_out;
  gen_cfg_p1 = generate_config (cfg_file_p1, p1_quota_in, p1_quota_out);
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Generated config file `%s'\n",
              gen_cfg_p1);

  quota_in_p2 = p2_quota_in;
  gen_cfg_p2 = generate_config (cfg_file_p2, p2_quota_in, p2_quota_out);
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Generated config file `%s'\n",
              gen_cfg_p2);

  p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, gen_cfg_p1, 1, &notify_receive,
                                            &notify_connect, &notify_disconnect,
                                            &start_cb, NULL);

  p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, gen_cfg_p2, 2, &notify_receive,
                                            &notify_connect, &notify_disconnect,
                                            &start_cb, NULL);

  if ((p1 == NULL) || (p2 == NULL))
  {
    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail! Could not start peers!\n");
    if (die_task != GNUNET_SCHEDULER_NO_TASK)
      GNUNET_SCHEDULER_cancel (die_task);
    die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
    return;
  }
}
static void
run_stage (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
	stage_task = GNUNET_SCHEDULER_NO_TASK;
	if (GNUNET_SCHEDULER_NO_TASK != die_task)
		GNUNET_SCHEDULER_cancel (die_task);
  die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Running stage %u\n", stage);

	if (0 == stage)
	{
		  started = GNUNET_NO;
		  connected = GNUNET_NO;
			if (0 == strcmp(test_name, "test_transport_blacklisting_no_bl"))
			{
					/* Try to connect peers successfully */
					p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, "test_transport_blacklisting_cfg_peer1.conf", 1,
		                                            NULL, NULL, NULL, &start_cb, NULL);

					p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, "test_transport_blacklisting_cfg_peer2.conf", 2,
		  																					NULL, NULL, NULL, &start_cb, NULL);
			}
			else if (0 == strcmp(test_name, "test_transport_blacklisting_outbound_bl_full"))
			{
					p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, "test_transport_blacklisting_cfg_blp_peer1_full.conf", 1,
		                                            NULL, NULL, NULL, &start_cb, NULL);

					p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, "test_transport_blacklisting_cfg_peer2.conf", 2,
		  																					NULL, NULL, NULL, &start_cb, NULL);
			}
			else if (0 == strcmp(test_name, "test_transport_blacklisting_outbound_bl_plugin"))
			{
					p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, "test_transport_blacklisting_cfg_blp_peer1_plugin.conf", 1,
		                                            NULL, NULL, NULL, &start_cb, NULL);

					p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, "test_transport_blacklisting_cfg_peer2.conf", 2,
		  																					NULL, NULL, NULL, &start_cb, NULL);
			}
			else if (0 == strcmp(test_name, "test_transport_blacklisting_inbound_bl_full"))
			{
					p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, "test_transport_blacklisting_cfg_peer1.conf", 1,
		                                            NULL, NULL, NULL, &start_cb, NULL);

					p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, "test_transport_blacklisting_cfg_blp_peer2_full.conf", 2,
		  																					NULL, NULL, NULL, &start_cb, NULL);
			}
			else if (0 == strcmp(test_name, "test_transport_blacklisting_inbound_bl_plugin"))
			{
					p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, "test_transport_blacklisting_cfg_peer1.conf", 1,
		                                            NULL, NULL, NULL, &start_cb, NULL);

					p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, "test_transport_blacklisting_cfg_blp_peer2_plugin.conf", 2,
		  																					NULL, NULL, NULL, &start_cb, NULL);
			}
			else if (0 == strcmp(test_name, "test_transport_blacklisting_multiple_plugins"))
			{
					p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, "test_transport_blacklisting_cfg_blp_peer1_multiple_plugins.conf", 1,
		                                            NULL, NULL, NULL, &start_cb, NULL);

					p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, "test_transport_blacklisting_cfg_blp_peer2_multiple_plugins.conf", 2,
		  																					NULL, NULL, NULL, &start_cb, NULL);
			}


			if ((NULL == p1) || (NULL == p2))
			{
				GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start peers\n");
				ok = 1;
			  GNUNET_SCHEDULER_add_now (&end, NULL);
			}

			timeout_task = GNUNET_SCHEDULER_add_delayed (CONNECT_TIMEOUT, &connect_timeout, NULL);
		  stage ++;
		  return;
	}


  if (cc != NULL)
  {
    GNUNET_TRANSPORT_TESTING_connect_peers_cancel(tth, cc);
    cc = NULL;
  }

  if (p1 != NULL)
  {
    GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1);
    p1 = NULL;
  }
  if (p2 != NULL)
  {
    GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2);
    p2 = NULL;
  }

  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Done in stage %u: Peers %s and %s!\n", stage,
  		(GNUNET_NO == started) ? "NOT STARTED" : "STARTED",
  		(GNUNET_YES == connected) ? "CONNECTED" : "NOT CONNECTED");

	if ((0 == strcmp(test_name, "test_transport_blacklisting_no_bl")) ||
			(0 == strcmp(test_name, "test_transport_blacklisting_multiple_plugins")))
	{
		if ((GNUNET_NO != started) && (GNUNET_YES == connected))
			ok = 0;
		else
		{
			GNUNET_break (0);
			ok = 1;
		}
	}
	else
	{
			if ((GNUNET_NO != started) && (GNUNET_YES != connected))
				ok = 0;
			else
			{
				ok = 1;
			}
	}
  GNUNET_SCHEDULER_add_now (&end, NULL);
}