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)
{
  basic_mqtt_op_publish = GNUNET_TESTBED_service_connect(NULL, /* Closure for operation */
							 peers[0], /* The peer whose service to connect to */
							 "gnunet-service-mqtt", /* The name of the service */
							 service_connect_comp_publish, /* callback to call after a handle to service is opened */
							 NULL, /* closure for the above callback */
							 gmqtt_ca_publish, /* callback to call with peer's configuration; this should open the needed service connection */
							 gmqtt_da_publish, /* callback to be called when closing the opened service connection */
							 NULL); /* closure for the above two callbacks */
  basic_mqtt_op_subscribe = GNUNET_TESTBED_service_connect(NULL, /* Closure for operation */
							   peers[1], /* The peer whose service to connect to */
							   "gnunet-service-mqtt", /* The name of the service */
							   service_connect_comp_subscribe, /* callback to call after a handle to service is opened */
							   NULL, /* closure for the above callback */
							   gmqtt_ca_subscribe, /* callback to call with peer's configuration; this should open the needed service connection */
							   gmqtt_da_subscribe, /* callback to be called when closing the opened service connection */
							   NULL); /* closure for the above two callbacks */			
  
  shutdown_tid = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), 
					      &shutdown_task, NULL);
}
/**
 * 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... */
  }
}
/**
 * Function called when get_statistics operation is ready
 *
 * @param cls the GetStatsContext
 */
static void
opstart_get_stats (void *cls)
{
  struct GetStatsContext *sc = cls;
  struct PeerGetStatsContext *peer_sc;
  unsigned int peer;

  LOG_DEBUG ("Starting get_statistics operation\n");
  sc->ops = GNUNET_malloc (sc->num_peers *
                           sizeof (struct GNUNET_TESTBED_Operation *));
  for (peer = 0; peer < sc->num_peers; peer++)
  {
    if (NULL == sc->peers[peer])
    {
      GNUNET_break (0);
      continue;
    }
    peer_sc = GNUNET_new (struct PeerGetStatsContext);
    peer_sc->sc = sc;
    peer_sc->peer_index = peer;
    sc->ops[peer] =
        GNUNET_TESTBED_service_connect (sc, sc->peers[peer], "statistics",
                                        &service_connect_comp,
                                        peer_sc,
                                        &statistics_ca,
                                        &statistics_da,
                                        peer_sc);
  }
}
Exemple #4
0
/**
 * Callback run when the testbed is ready (peers running and connected to
 * each other)
 * 
 * @param cls Closure (context).
 * @param num_peers Number of peers that are running.
 * @param peers Handles to each one of the @c num_peers peers.
 */
static void
mesh_test_run (void *cls,
               unsigned int num_peers,
               struct GNUNET_TESTBED_Peer **peers)
{
  struct GNUNET_MESH_TEST_Context *ctx = cls;
  unsigned int i;

  GNUNET_assert (num_peers == ctx->num_peers);
  ctx->peers = peers;
  for (i = 0; i < num_peers; i++)
  {
    struct GNUNET_MESH_TEST_AdapterContext *newctx;
    newctx = GNUNET_malloc (sizeof (struct GNUNET_MESH_TEST_AdapterContext));
    newctx->peer = i;
    newctx->ctx = ctx;
    ctx->ops[i] = GNUNET_TESTBED_service_connect (ctx,
                                                  peers[i],
                                                  "mesh",
                                                  &mesh_connect_cb,
                                                  ctx,
                                                  &mesh_connect_adapter,
                                                  &mesh_disconnect_adapter,
                                                  newctx);
  }
}
/**
 * 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);
}
Exemple #6
0
/**
 * Main function inovked from TESTBED once all of the
 * peers are up and running.  This one then connects
 * just to the DHT service of peer 0.
 *
 * @param cls closure
 * @param h the run handle
 * @param peers started peers for the test
 * @param num_peers size of the 'peers' array
 * @param links_succeeded number of links between peers that were created
 * @param links_failed number of links testbed was unable to establish
 */
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)
{
  /* Testbed is ready with peers running and connected in a pre-defined overlay
     topology  */

  /* do something */
  ctxt.ht_len = 10;

  /* connect to a peers service */
  dht_op = GNUNET_TESTBED_service_connect
      (NULL,                    /* Closure for operation */
       peers[0],                /* The peer whose service to connect to */
       "dht",                   /* The name of the service */
       service_connect_comp,    /* callback to call after a handle to service
                                   is opened */
       NULL,                    /* closure for the above callback */
       dht_ca,                  /* callback to call with peer's configuration;
                                   this should open the needed service connection */
       dht_da,                  /* callback to be called when closing the
                                   opened service connection */
       &ctxt);                  /* closure for the above two callbacks */
  shutdown_tid = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
                                               &shutdown_task, NULL);
}
/**
 * Main function inovked from TESTBED once all of the
 * peers are up and running.  This one then connects
 * just to the multicast service of peer 0 and 1.
 * Peer 0 is going to be origin.
 * Peer 1 is going to be one member.
 * Origin will start a multicast group and the member will try to join it.
 * After that we execute some multicast test.
 *
 * @param cls closure
 * @param h the run handle
 * @param peers started peers for the test
 * @param num_peers size of the 'peers' array
 * @param links_succeeded number of links between peers that were created
 * @param links_failed number of links testbed was unable to establish
 */
static void
run (void *cls,
     struct GNUNET_TESTBED_RunHandle *h,
     unsigned int num_peers,
     struct GNUNET_TESTBED_Peer **peers,
     unsigned int links_succeeded,
     unsigned int links_failed)
{
  /* Testbed is ready with peers running and connected in a pre-defined overlay
     topology (FIXME)  */

  /* connect to a peers service */
  peer0 = GNUNET_TESTBED_service_connect
      (NULL,                    /* Closure for operation */
       peers[0],                /* The peer whose service to connect to */
       "multicast",             /* The name of the service */
       &service_connect_peer0,   /* callback to call after a handle to service
                                   is opened */
       NULL,                    /* closure for the above callback */
       &service_conf_peer0,      /* callback to call with peer's configuration;
                                   this should open the needed service connection */
       &service_close_peer0,     /* callback to be called when closing the
                                   opened service connection */
       NULL);                   /* closure for the above two callbacks */
  GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
  timeout_tid = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
					      &timeout_task, NULL);
}
/**
 * Listen success callback; connects a peer to stream as client. Called from
 * testbed stream_ca
 */
static void
stream_connect2 (void)
{
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stream listen open successful\n");
  peer_data[0].op =
      GNUNET_TESTBED_service_connect (&peer_data[0], peer_data[0].peer,
				      "stream", NULL, NULL, stream_ca,
				      stream_da, &peer_data[0]);
}
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)
{
  basic_mqtt_op = GNUNET_TESTBED_service_connect(NULL, /* Closure for operation */
					  peers[0], /* The peer whose service to connect to */
					  "gnunet-service-mqtt", /* The name of the service */
					   service_connect_comp, /* callback to call after a handle to service is opened */
					   NULL, /* closure for the above callback */
					   gmqtt_ca, /* callback to call with peer's configuration; this should open the needed service connection */
					   gmqtt_da, /* callback to be called when closing the opened service connection */
					   NULL); /* closure for the above two callbacks */
}
/**
 * Adapter function called to destroy a connection to
 * a service.
 *
 * @param cls closure
 * @param op_result service handle returned from the connect adapter
 */
static void
session_disconnect_adapter (void *cls, void *op_result)
{
  struct GNUNET_SECRETSHARING_Session **sp = cls;
  unsigned int n = (sp - session_handles);

  GNUNET_assert (*sp == session_handles[n]);

  if (NULL != *sp)
  {
    GNUNET_SECRETSHARING_session_destroy (*sp);
    *sp = NULL;
  }

  GNUNET_assert (NULL != connect_ops[n]);
  connect_ops[n] = NULL;

  if (GNUNET_YES == in_shutdown)
    return;

  // all peers received their secret
  if (num_generated == num_peers)
  {
    int i;

    // only do decryption if requested by the user
    if (GNUNET_NO == decrypt)
    {
      GNUNET_SCHEDULER_shutdown ();
      return;
    }

    decrypt_start = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), delay);
    decrypt_deadline = GNUNET_TIME_absolute_add (decrypt_start, timeout);

    // compute g^42 as the plaintext which we will decrypt and then
    // cooperatively decrypt
    GNUNET_SECRETSHARING_plaintext_generate_i (&reference_plaintext, 42);
    GNUNET_SECRETSHARING_encrypt (&common_pubkey, &reference_plaintext, &ciphertext);

    for (i = 0; i < num_peers; i++)
      connect_ops[i] =
          GNUNET_TESTBED_service_connect (NULL, peers[i], "secretsharing", &decrypt_connect_complete, NULL,
                                          &decrypt_connect_adapter, &decrypt_disconnect_adapter, &decrypt_handles[i]);
  }
}
static void
do_report (void *cls)
{
  static int download_counter;
  const char *type = cls;
  struct GNUNET_TIME_Relative del;
  char *fancy;
  struct StatMaster *sm;

  if (0 ==
      GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_add (start_time,
                                                                    TIMEOUT)).rel_value_us)
  {
    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                "Timeout during download for type `%s', shutting down with error\n",
                type);
    ok = 1;
    cleanup ();
    return;
  }
  del = GNUNET_TIME_absolute_get_duration (start_time);
  if (del.rel_value_us == 0)
    del.rel_value_us = 1;
  fancy =
    GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) *
				    1000000LL / del.rel_value_us);
  FPRINTF (stderr, "Download speed of type `%s' was %s/s\n", type, fancy);
  GNUNET_free (fancy);
  if (NUM_DAEMONS != ++download_counter)
    return;                   /* more downloads to come */
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
	      "Finished all downloads, getting statistics\n");
  sm = GNUNET_new (struct StatMaster);
  sm->op =
    GNUNET_TESTBED_service_connect (NULL,
				    daemons[sm->daemon],
				    "statistics",
				    &stat_run, sm,
				    &statistics_connect_adapter,
				    &statistics_disconnect_adapter,
				    NULL);
}
Exemple #12
0
static void
dht_test_run (void *cls,
	      unsigned int num_peers,
	      struct GNUNET_TESTBED_Peer **peers)
{
  struct GNUNET_DHT_TEST_Context *ctx = cls;
  unsigned int i;

  GNUNET_assert (num_peers == ctx->num_peers);
  ctx->peers = peers;
  for (i=0;i<num_peers;i++)
    ctx->ops[i] = GNUNET_TESTBED_service_connect (ctx,
						  peers[i],
						  "dht",
						  &dht_connect_cb,
						  ctx,
						  &dht_connect_adapter,
						  &dht_disconnect_adapter,
						  ctx);
}
/**
 * Function that gathers stats from all daemons.
 */
static void
stat_run (void *cls,
	  struct GNUNET_TESTBED_Operation *op,
	  void *ca_result,
	  const char *emsg)
{
  struct StatMaster *sm = cls;

  sm->stat = ca_result;
  GNUNET_assert (NULL != sm->stat);
  if (NULL != stats[sm->value].name)
  {
    GNUNET_STATISTICS_get (sm->stat,
#if 0
                           NULL, NULL,
#else
                           stats[sm->value].subsystem, stats[sm->value].name,
#endif
                           &get_done, &print_stat,
                           sm);
    return;
  }
  GNUNET_TESTBED_operation_done (sm->op);
  sm->value = 0;
  sm->daemon++;
  if (NUM_DAEMONS == sm->daemon)
  {
    GNUNET_free (sm);
    cleanup ();
    return;
  }
  sm->op =
    GNUNET_TESTBED_service_connect (NULL,
				    daemons[sm->daemon],
				    "statistics",
				    &stat_run, sm,
				    &statistics_connect_adapter,
				    &statistics_disconnect_adapter,
				    NULL);
}
/**
 * Actual "main" function for the 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
run (void *cls,
     struct GNUNET_TESTBED_RunHandle *h,
     unsigned int num_peers,
     struct GNUNET_TESTBED_Peer **peers,
     unsigned int links_succeeded,
     unsigned int links_failed)
{
  unsigned int i;

  GNUNET_assert (NUM_PEERS == num_peers);
  for (i=0;i<num_peers;i++)
    nse_peers[i].op = GNUNET_TESTBED_service_connect (&nse_peers[i],
						      peers[i],
						      "nse",
						      &nse_connect_complete_cb,
						      &nse_peers[i],
						      &nse_connect_adapter,
						      &nse_disconnect_adapter,
						      &nse_peers[i]);
  GNUNET_SCHEDULER_add_delayed (TIMEOUT, &shutdown_task, NULL);
}
static void
secret_ready_cb (void *cls,
                 struct GNUNET_SECRETSHARING_Share *my_share,
                 struct GNUNET_SECRETSHARING_PublicKey *public_key,
                 unsigned int num_ready_peers,
                 struct GNUNET_PeerIdentity *ready_peers)
{
  struct GNUNET_SECRETSHARING_Session **sp = cls;
  unsigned int n = sp - session_handles;
  char pubkey_str[1024];
  char *ret;

  num_generated++;
  *sp = NULL;
  shares[n] = my_share;
  if (NULL == my_share)
  {
    GNUNET_log (GNUNET_ERROR_TYPE_INFO, "key generation failed for peer #%u\n", n);
  }
  else
  {
    ret = GNUNET_STRINGS_data_to_string (public_key, sizeof *public_key, pubkey_str, 1024);
    GNUNET_assert (NULL != ret);
    *ret = '\0';
    GNUNET_log (GNUNET_ERROR_TYPE_INFO, "key generation successful for peer #%u, pubkey %s\n", n,
                pubkey_str);

    /* we're the first to get the key -> store it */
    if (num_generated == 1)
    {
      common_pubkey = *public_key;
    }
    else if (0 != memcmp (public_key, &common_pubkey, sizeof (struct GNUNET_SECRETSHARING_PublicKey)))
    {
      GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "generated public keys do not match\n");
      GNUNET_SCHEDULER_shutdown ();
      return;
    }
  }

  // FIXME: destroy testbed operation

  if (num_generated == num_peers)
  {
    int i;
    if (GNUNET_NO == decrypt)
    {
      GNUNET_SCHEDULER_shutdown ();
      return;
    }

    decrypt_start = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), delay);
    decrypt_deadline = GNUNET_TIME_absolute_add (decrypt_start, timeout);


    // compute g^42
    GNUNET_SECRETSHARING_plaintext_generate_i (&reference_plaintext, 42);
    GNUNET_SECRETSHARING_encrypt (&common_pubkey, &reference_plaintext, &ciphertext);

    // FIXME: store the ops somewhere!
    for (i = 0; i < num_peers; i++)
      GNUNET_TESTBED_service_connect (NULL, peers[i], "secretsharing", &decrypt_connect_complete, NULL,
                                      &decrypt_connect_adapter, &decrypt_disconnect_adapter, &decrypt_handles[i]);
  }
}