Example #1
0
/**
 * Process regex 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[] = {
    {&handle_announce, NULL, GNUNET_MESSAGE_TYPE_REGEX_ANNOUNCE, 0},
    {&handle_search, NULL, GNUNET_MESSAGE_TYPE_REGEX_SEARCH, 0},
    {NULL, NULL, 0, 0}
  };

  my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg);
  if (NULL == my_private_key)
  {
    GNUNET_SCHEDULER_shutdown ();
    return;
  }
  dht = GNUNET_DHT_connect (cfg, 1024);
  if (NULL == dht)
  {
    GNUNET_free (my_private_key);
    my_private_key = NULL;
    GNUNET_SCHEDULER_shutdown ();
    return;
  }
  GNUNET_SCHEDULER_add_shutdown (&cleanup_task,
				 NULL);
  nc = GNUNET_SERVER_notification_context_create (server, 1);
  stats = GNUNET_STATISTICS_create ("regex", cfg);
  GNUNET_SERVER_add_handlers (server, handlers);
  GNUNET_SERVER_disconnect_notify (server,
                                   &handle_client_disconnect,
                                   NULL);
}
/**
 * Initialize client subsystem.
 *
 * @param server the initialized server
 */
void
GDS_CLIENTS_init (struct GNUNET_SERVER_Handle *server)
{
  static struct GNUNET_SERVER_MessageHandler plugin_handlers[] = {
    {&handle_dht_local_put, NULL,
     GNUNET_MESSAGE_TYPE_DHT_CLIENT_PUT, 0},
    {&handle_dht_local_get, NULL,
     GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET, 0},
    {&handle_dht_local_get_stop, NULL,
     GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_STOP,
     sizeof (struct GNUNET_DHT_ClientGetStopMessage)},
    {&handle_dht_local_monitor, NULL,
     GNUNET_MESSAGE_TYPE_DHT_MONITOR_START,
     sizeof (struct GNUNET_DHT_MonitorStartStopMessage)},
    {&handle_dht_local_monitor_stop, NULL,
     GNUNET_MESSAGE_TYPE_DHT_MONITOR_STOP,
     sizeof (struct GNUNET_DHT_MonitorStartStopMessage)},
    {&handle_dht_local_get_result_seen, NULL,
     GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_RESULTS_KNOWN, 0},
    {NULL, NULL, 0, 0}
  };
  forward_map = GNUNET_CONTAINER_multihashmap_create (1024, GNUNET_NO);
  retry_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
  GNUNET_SERVER_add_handlers (server, plugin_handlers);
  GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL);
}
Example #3
0
static void
task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  struct sockaddr_in sa;
  struct sockaddr *sap[2];
  socklen_t slens[2];

  sap[0] = (struct sockaddr *) &sa;
  slens[0] = sizeof (sa);
  sap[1] = NULL;
  slens[1] = 0;
  memset (&sa, 0, sizeof (sa));
#if HAVE_SOCKADDR_IN_SIN_LEN
  sa.sin_len = sizeof (sa);
#endif
  sa.sin_family = AF_INET;
  sa.sin_port = htons (PORT);
  server =
      GNUNET_SERVER_create (NULL, NULL, sap, slens,
                            GNUNET_TIME_relative_multiply
                            (GNUNET_TIME_UNIT_MILLISECONDS, 250), GNUNET_NO);
  GNUNET_assert (server != NULL);
  handlers[0].callback_cls = cls;
  GNUNET_SERVER_add_handlers (server, handlers);
  GNUNET_SERVER_disconnect_notify (server, &notify_disconnect, cls);
  cfg = GNUNET_CONFIGURATION_create ();
  GNUNET_CONFIGURATION_set_value_number (cfg, "test", "PORT", PORT);
  GNUNET_CONFIGURATION_set_value_string (cfg, "test", "HOSTNAME", "localhost");
  GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME",
                                         "localhost");
  client = GNUNET_CLIENT_connect ("test", cfg);
  GNUNET_assert (client != NULL);

  test_mq (client);
}
static void
task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
    struct sockaddr_un un;
    const char *unixpath = "/tmp/testsock";
    size_t slen = strlen (unixpath);
    struct sockaddr *sap[2];
    socklen_t slens[2];

    memset (&un, 0, sizeof (un));
    un.sun_family = AF_UNIX;
    memcpy (un.sun_path, unixpath, slen);
    un.sun_path[slen] = '\0';
#if HAVE_SOCKADDR_IN_SIN_LEN
    un.sun_len = (u_char) sizeof (un);
#endif
#if LINUX
    un.sun_path[0] = '\0';
#endif

    sap[0] = (struct sockaddr *) &un;
    slens[0] = sizeof (un);
    sap[1] = NULL;
    slens[1] = 0;
    server =
        GNUNET_SERVER_create (NULL, NULL, sap, slens,
                              GNUNET_TIME_relative_multiply
                              (GNUNET_TIME_UNIT_MILLISECONDS, 250), GNUNET_NO);
    GNUNET_assert (server != NULL);
    handlers[0].callback_cls = cls;
    GNUNET_SERVER_add_handlers (server, handlers);
    GNUNET_SERVER_disconnect_notify (server, &notify_disconnect, cls);
    cfg = GNUNET_CONFIGURATION_create ();

    GNUNET_CONFIGURATION_set_value_string (cfg, "test", "UNIXPATH", unixpath);
    GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME",
                                           "localhost");

    client = GNUNET_CLIENT_connect ("test", cfg);
    GNUNET_assert (client != NULL);
    GNUNET_CLIENT_notify_transmit_ready (client, 256,
                                         GNUNET_TIME_relative_multiply
                                         (GNUNET_TIME_UNIT_MILLISECONDS, 250),
                                         GNUNET_NO, &notify_ready, NULL);
}
Example #5
0
static void
task (void *cls)
{
  struct sockaddr_in sa;
  struct sockaddr *sap[2];
  socklen_t slens[2];
  struct GNUNET_MQ_Envelope *env;
  struct GNUNET_MessageHeader *msg;

  sap[0] = (struct sockaddr *) &sa;
  slens[0] = sizeof (sa);
  sap[1] = NULL;
  slens[1] = 0;
  memset (&sa, 0, sizeof (sa));
#if HAVE_SOCKADDR_IN_SIN_LEN
  sa.sin_len = sizeof (sa);
#endif
  sa.sin_family = AF_INET;
  sa.sin_port = htons (PORT);
  server = GNUNET_SERVER_create (NULL, NULL, sap, slens, TIMEOUT, GNUNET_NO);
  GNUNET_assert (server != NULL);
  GNUNET_SERVER_add_handlers (server, handlers);
  GNUNET_SERVER_disconnect_notify (server, &notify_disconnect, NULL);
  cfg = GNUNET_CONFIGURATION_create ();
  GNUNET_CONFIGURATION_set_value_number (cfg, "test-server", "PORT", PORT);
  GNUNET_CONFIGURATION_set_value_string (cfg, "test-server", "HOSTNAME",
                                         "localhost");
  GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME",
                                         "localhost");
  mq = GNUNET_CLIENT_connect (cfg,
                              "test-server",
                              NULL,
                              NULL,
                              NULL);
  GNUNET_assert (NULL != mq);
  ok = 2;
  env = GNUNET_MQ_msg (msg,
                       MY_TYPE);
  GNUNET_MQ_send (mq,
                  env);
}
static void
task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
    struct sockaddr_in sa;
    struct sockaddr *sap[2];
    socklen_t slens[2];

    sap[0] = (struct sockaddr *) &sa;
    slens[0] = sizeof (sa);
    sap[1] = NULL;
    slens[1] = 0;
    memset (&sa, 0, sizeof (sa));
#if HAVE_SOCKADDR_IN_SIN_LEN
    sa.sin_len = sizeof (sa);
#endif
    sa.sin_family = AF_INET;
    sa.sin_port = htons (PORT);
    server = GNUNET_SERVER_create (NULL, NULL, sap, slens, TIMEOUT, GNUNET_NO);
    GNUNET_assert (server != NULL);
    GNUNET_SERVER_add_handlers (server, handlers);
    GNUNET_SERVER_disconnect_notify (server, &notify_disconnect, NULL);
    cfg = GNUNET_CONFIGURATION_create ();
    GNUNET_CONFIGURATION_set_value_number (cfg, "test-server", "PORT", PORT);
    GNUNET_CONFIGURATION_set_value_string (cfg, "test-server", "HOSTNAME",
                                           "localhost");
    GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME",
                                           "localhost");
    cc = GNUNET_CLIENT_connect ("test-server", cfg);
    GNUNET_assert (cc != NULL);
    GNUNET_assert (NULL !=
                   GNUNET_CLIENT_notify_transmit_ready (cc,
                           sizeof (struct
                                   GNUNET_MessageHeader),
                           TIMEOUT, GNUNET_YES,
                           &transmit_initial_message,
                           NULL));
}
/**
 * Start handling requests from clients.
 *
 * @param server server used to accept clients from.
 */
void
GST_clients_start (struct GNUNET_SERVER_Handle *server)
{
  static const struct GNUNET_SERVER_MessageHandler handlers[] = {
    {&clients_handle_start, NULL,
     GNUNET_MESSAGE_TYPE_TRANSPORT_START, sizeof (struct StartMessage)},
    {&clients_handle_hello, NULL,
     GNUNET_MESSAGE_TYPE_HELLO, 0},
    {&clients_handle_send, NULL,
     GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, 0},
    {&clients_handle_request_connect, NULL,
     GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT,
     sizeof (struct TransportRequestConnectMessage)},
    {&clients_handle_address_to_string, NULL,
     GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING, 0},
    {&clients_handle_monitor_peers, NULL,
     GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST,
     sizeof (struct PeerMonitorMessage)},
    {&clients_handle_monitor_validation, NULL,
     GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_REQUEST,
     sizeof (struct ValidationMonitorMessage)},
    {&GST_blacklist_handle_init, NULL,
     GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT,
     sizeof (struct GNUNET_MessageHeader)},
    {&GST_blacklist_handle_reply, NULL,
     GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY,
     sizeof (struct BlacklistMessage)},
    {&GST_manipulation_set_metric, NULL,
     GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC, 0},
    {NULL, NULL, 0, 0}
  };
  peer_nc = GNUNET_SERVER_notification_context_create (server, 0);
  val_nc = GNUNET_SERVER_notification_context_create (server, 0);
  GNUNET_SERVER_add_handlers (server, handlers);
  GNUNET_SERVER_disconnect_notify (server, &client_disconnect_notification,
                                   NULL);
}
/**
 * Testbed setup
 *
 * @param cls closure
 * @param server the initialized server
 * @param cfg configuration to use
 */
static void
testbed_run (void *cls, struct GNUNET_SERVER_Handle *server,
             const struct GNUNET_CONFIGURATION_Handle *cfg)
{
  static const struct GNUNET_SERVER_MessageHandler message_handlers[] = {
    {&handle_init, NULL, GNUNET_MESSAGE_TYPE_TESTBED_INIT, 0},
    {&handle_add_host, NULL, GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST, 0},
    {&GST_handle_link_controllers, NULL,
     GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS,
     sizeof (struct GNUNET_TESTBED_ControllerLinkRequest)},
    {&GST_handle_peer_create, NULL, GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER, 0},
    {&GST_handle_peer_destroy, NULL, GNUNET_MESSAGE_TYPE_TESTBED_DESTROY_PEER,
     sizeof (struct GNUNET_TESTBED_PeerDestroyMessage)},
    {&GST_handle_peer_start, NULL, GNUNET_MESSAGE_TYPE_TESTBED_START_PEER,
     sizeof (struct GNUNET_TESTBED_PeerStartMessage)},
    {&GST_handle_peer_stop, NULL, GNUNET_MESSAGE_TYPE_TESTBED_STOP_PEER,
     sizeof (struct GNUNET_TESTBED_PeerStopMessage)},
    {&GST_handle_peer_get_config, NULL,
     GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_INFORMATION,
     sizeof (struct GNUNET_TESTBED_PeerGetConfigurationMessage)},
    {&GST_handle_overlay_connect, NULL,
     GNUNET_MESSAGE_TYPE_TESTBED_OVERLAY_CONNECT,
     sizeof (struct GNUNET_TESTBED_OverlayConnectMessage)},
    {&GST_handle_remote_overlay_connect, NULL,
     GNUNET_MESSAGE_TYPE_TESTBED_REMOTE_OVERLAY_CONNECT, 0},
    {&GST_handle_manage_peer_service, NULL,
     GNUNET_MESSAGE_TYPE_TESTBED_MANAGE_PEER_SERVICE, 0},
    {&handle_slave_get_config, NULL,
     GNUNET_MESSAGE_TYPE_TESTBED_GET_SLAVE_CONFIGURATION,
     sizeof (struct GNUNET_TESTBED_SlaveGetConfigurationMessage)},
    {&GST_handle_shutdown_peers, NULL, GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS,
     sizeof (struct GNUNET_TESTBED_ShutdownPeersMessage)},
    {&GST_handle_peer_reconfigure, NULL,
     GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER, 0},
    {&GST_handle_barrier_init, NULL,
     GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_INIT, 0},
    {&GST_handle_barrier_cancel, NULL,
     GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_CANCEL, 0},
    {&GST_handle_barrier_status, NULL,
     GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS, 0},
    {NULL, NULL, 0, 0}
  };
  char *logfile;
  unsigned long long num;

  LOG_DEBUG ("Starting testbed\n");
  if (GNUNET_OK ==
      GNUNET_CONFIGURATION_get_value_filename (cfg, "TESTBED", "LOG_FILE",
                                               &logfile))
  {
    GNUNET_break (GNUNET_OK == GNUNET_log_setup ("testbed", "DEBUG", logfile));
    GNUNET_free (logfile);
  }
  GNUNET_assert (GNUNET_OK ==
                 GNUNET_CONFIGURATION_get_value_number (cfg, "TESTBED",
                                                        "CACHE_SIZE", &num));
  GST_cache_init ((unsigned int) num);
  GST_connection_pool_init ((unsigned int) num);
  GNUNET_assert (GNUNET_OK ==
                 GNUNET_CONFIGURATION_get_value_number (cfg, "TESTBED",
                                                        "MAX_OPEN_FDS", &num));
  GST_opq_openfds = GNUNET_TESTBED_operation_queue_create_
      (OPERATION_QUEUE_TYPE_FIXED, (unsigned int) num);
  GNUNET_assert (GNUNET_OK ==
                 GNUNET_CONFIGURATION_get_value_time (cfg, "TESTBED",
                                                      "OPERATION_TIMEOUT",
                                                      (struct
                                                       GNUNET_TIME_Relative *)
                                                      &GST_timeout));
  GNUNET_assert (GNUNET_OK ==
                 GNUNET_CONFIGURATION_get_value_string (cfg, "testbed",
                                                        "HOSTNAME", &hostname));
  GST_config = GNUNET_CONFIGURATION_dup (cfg);
  GNUNET_SERVER_add_handlers (server, message_handlers);
  GNUNET_SERVER_disconnect_notify (server, &client_disconnect_cb, NULL);
  shutdown_task_id =
      GNUNET_SCHEDULER_add_delayed_with_priority (GNUNET_TIME_UNIT_FOREVER_REL,
                                                  GNUNET_SCHEDULER_PRIORITY_IDLE,
                                                  &shutdown_task, NULL);
  LOG_DEBUG ("Testbed startup complete\n");
  GST_stats_init (GST_config);
  GST_barriers_init (GST_config);
}