Beispiel #1
0
/**
 * Initialize framework and start test
 *
 * @param cls Closure (unused).
 * @param cfg Configuration handle.
 * @param peer Testing peer handle.
 */
static void
run (void *cls,
     const struct GNUNET_CONFIGURATION_Handle *cfg,
     struct GNUNET_TESTING_Peer *peer)
{
  static uint32_t ports[] = {1, 0};

  me = peer;
  abort_task =
      GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
                                    (GNUNET_TIME_UNIT_SECONDS, 15), &do_abort,
                                    NULL);
  cadet_peer_1 = GNUNET_CADET_connect (cfg,       /* configuration */
                                     (void *) 1L,       /* cls */
                                     NULL,              /* inbound new hndlr */
                                     &channel_end,      /* channel end hndlr */
                                     handlers1, /* traffic handlers */
                                     NULL);     /* ports offered */

  cadet_peer_2 = GNUNET_CADET_connect (cfg,       /* configuration */
                                     (void *) 2L,     /* cls */
                                     &inbound_channel,   /* inbound new hndlr */
                                     &channel_end,      /* channel end hndlr */
                                     handlers2, /* traffic handlers */
                                     ports);     /* ports offered */
  if (NULL == cadet_peer_1 || NULL == cadet_peer_2)
  {
    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Couldn't connect to cadet :(\n");
    result = GNUNET_SYSERR;
    return;
  }
  else
  {
    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "YAY! CONNECTED TO CADET :D\n");
  }
  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (
                                  GNUNET_TIME_UNIT_SECONDS,
                                  2),
                                &do_connect, NULL);
}
/**
 * Main function that will be run by the scheduler.
 *
 * @param cls closure
 * @param c configuration
 * @param service service handle
 */
static void
run (void *cls,
     const struct GNUNET_CONFIGURATION_Handle *c,
     struct GNUNET_SERVICE_Handle *service)
{
  static struct GNUNET_CADET_MessageHandler cadet_handlers[] = {
    {&handle_cadet_ring_message,
     GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RING,
     sizeof (struct CadetPhoneRingMessage)},
    {&handle_cadet_hangup_message,
     GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_HANG_UP,
     sizeof (struct CadetPhoneHangupMessage)},
    {&handle_cadet_pickup_message,
     GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_PICK_UP,
     sizeof (struct CadetPhonePickupMessage)},
    {&handle_cadet_suspend_message,
     GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_SUSPEND,
     sizeof (struct CadetPhoneSuspendMessage)},
    {&handle_cadet_resume_message,
     GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RESUME,
     sizeof (struct CadetPhoneResumeMessage)},
    {&handle_cadet_audio_message, GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_AUDIO,
     0},
    {NULL, 0, 0}
  };

  cfg = c;
  GNUNET_assert (GNUNET_OK ==
                 GNUNET_CRYPTO_get_peer_identity (cfg,
                                                  &my_identity));
  cadet = GNUNET_CADET_connect (cfg,
                                NULL,
                                &inbound_end,
                                cadet_handlers);
  if (NULL == cadet)
  {
    GNUNET_break (0);
    GNUNET_SCHEDULER_shutdown ();
    return;
  }
  GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
				 NULL);
}
/**
 * Initialization of the program and message handlers
 *
 * @param cls closure
 * @param c configuration to use
 * @param service the initialized service
 */
static void
run (void *cls,
     const struct GNUNET_CONFIGURATION_Handle *c,
     struct GNUNET_SERVICE_Handle *service)
{
  static const struct GNUNET_CADET_MessageHandler cadet_handlers[] = {
    { &handle_alices_computation_request,
      GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_SESSION_INITIALIZATION,
      sizeof (struct EccServiceRequestMessage) },
    { &handle_alices_cryptodata_message,
      GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_ALICE_CRYPTODATA,
      0},
    { NULL, 0, 0}
  };

  cfg = c;
  /* We don't really do DLOG, so we can setup with very minimal resources */
  edc = GNUNET_CRYPTO_ecc_dlog_prepare (4 /* max value */,
                                        2 /* RAM */);
  client_sessions = GNUNET_CONTAINER_multihashmap_create (128,
                                                          GNUNET_YES);
  cadet_sessions = GNUNET_CONTAINER_multihashmap_create (128,
                                                         GNUNET_YES);
  my_cadet = GNUNET_CADET_connect (cfg, 
				   NULL,
                                   &cb_channel_destruction,
                                   cadet_handlers);
  GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
				 NULL);
  if (NULL == my_cadet)
  {
    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                _("Connect to CADET failed\n"));
    GNUNET_SCHEDULER_shutdown ();
    return;
  }
}
/**
 * Process sensordashboard requests.
 *
 * @param cls closure
 * @param server the initialized server
 * @param cfg configuration to use
 */
static void
run (void *cls, struct GNUNET_SERVER_Handle *server,
     const struct GNUNET_CONFIGURATION_Handle *cfg)
{
  static const struct GNUNET_SERVER_MessageHandler handlers[] = {
    {NULL, NULL, 0, 0}
  };
  static struct GNUNET_CADET_MessageHandler cadet_handlers[] = {
    {&handle_sensor_reading,
     GNUNET_MESSAGE_TYPE_SENSOR_READING, 0},
    {&handle_sensor_list_req,
     GNUNET_MESSAGE_TYPE_SENSOR_LIST_REQ,
     sizeof (struct GNUNET_MessageHeader)},
    {&handle_sensor_full_req,
     GNUNET_MESSAGE_TYPE_SENSOR_FULL_REQ,
     sizeof (struct GNUNET_MessageHeader)},
    {&handle_anomaly_report,
     GNUNET_MESSAGE_TYPE_SENSOR_ANOMALY_REPORT,
     sizeof (struct GNUNET_MessageHeader) +
     sizeof (struct GNUNET_SENSOR_crypto_pow_block) +
     sizeof (struct GNUNET_SENSOR_AnomalyReportMessage)},
    {NULL, 0, 0}
  };
  static uint32_t cadet_ports[] = {
    GNUNET_APPLICATION_TYPE_SENSORDASHBOARD,
    GNUNET_APPLICATION_TYPE_SENSORUPDATE,
    GNUNET_APPLICATION_TYPE_END
  };

  if (GNUNET_OK !=
      GNUNET_CONFIGURATION_get_value_filename (cfg, "SENSOR", "SENSOR_DIR",
                                               &sensor_dir))
    sensor_dir = GNUNET_SENSOR_get_default_sensor_dir ();
  sensors = GNUNET_SENSOR_load_all_sensors (sensor_dir);
  GNUNET_assert (NULL != sensors);

  if (GNUNET_OK !=
      GNUNET_CONFIGURATION_get_value_number (cfg, "sensor-reporting",
                                             "POW_MATCHING_BITS",
                                             &pow_matching_bits))
  {
    GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "sensor-reporting",
                               "POW_MATCHING_BITS");
    GNUNET_SCHEDULER_add_now (&cleanup_task, NULL);
    return;
  }
  if (pow_matching_bits > sizeof (struct GNUNET_HashCode))
  {
    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                "Matching bits value too large (%d > %d).\n", pow_matching_bits,
                sizeof (struct GNUNET_HashCode));
    GNUNET_SCHEDULER_add_now (&cleanup_task, NULL);
    return;
  }

  cadet =
      GNUNET_CADET_connect (cfg, NULL, &cadet_channel_created,
                            &cadet_channel_destroyed, cadet_handlers,
                            cadet_ports);
  if (NULL == cadet)
  {
    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                _("Failed to connect to `%s' service.\n"), "CADET");
    GNUNET_SCHEDULER_add_now (&cleanup_task, NULL);
    return;
  }
  peerstore = GNUNET_PEERSTORE_connect (cfg);
  if (NULL == peerstore)
  {
    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                _("Failed to connect to `%s' service.\n"), "PEERSTORE");
    GNUNET_SCHEDULER_add_now (&cleanup_task, NULL);
    return;
  }
  GNUNET_SERVER_add_handlers (server, handlers);
  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task,
                                NULL);
}