Exemple #1
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);
}
Exemple #2
0
/**
 * First task run by the scheduler.  Initializes the server and
 * a client and asks for a transmission from the client to the
 * server.
 *
 * @param cls NULL
 */
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;
  struct GNUNET_MQ_MessageHandler chandlers[] = {
    GNUNET_MQ_hd_fixed_size (reply,
                             MY_TYPE,
                             struct GNUNET_MessageHeader,
                             cls),
    GNUNET_MQ_handler_end ()
  };

  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);
  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",
                              chandlers,
                              &mq_error_handler,
                              NULL);
  GNUNET_assert (NULL != mq);
  ok = 2;
  env = GNUNET_MQ_msg (msg,
                       MY_TYPE);
  GNUNET_MQ_send (mq,
                  env);
}
/**
 * Main function
 */
int
main (int argc, char **argv)
{
  struct GNUNET_CONFIGURATION_Handle *cfg;
  char pwd[PATH_MAX];
  char *binary;
  uint64_t event_mask;

  result = GNUNET_SYSERR;
  event_mask = 0;
  cfg = GNUNET_CONFIGURATION_create ();
  GNUNET_assert (GNUNET_YES ==
                 GNUNET_CONFIGURATION_parse (cfg,
                                             "test_testbed_api_barriers.conf.in"));
  if (NULL == getcwd (pwd, PATH_MAX))
    return 1;
  GNUNET_assert (0 < GNUNET_asprintf (&binary, "%s/%s", pwd,
                                      "gnunet-service-test-barriers"));
  GNUNET_CONFIGURATION_set_value_string (cfg, "test-barriers","BINARY", binary);
  GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_write
                 (cfg, "test_testbed_api_barriers.conf"));
  GNUNET_CONFIGURATION_destroy (cfg);
  cfg = NULL;
  GNUNET_free (binary);
  binary = NULL;
  (void) GNUNET_TESTBED_test_run ("test_testbed_api_barriers",
                                  "test_testbed_api_barriers.conf", NUM_PEERS,
                                  event_mask, NULL, NULL,
                                  &test_master, NULL);
  (void) unlink ("test_testbed_api_barriers.conf");
  if (GNUNET_OK != result)
    return 1;
  return 0;
}
static char *
generate_config (char *cfg_file, unsigned long long quota_in,
                 unsigned long long quota_out)
{
  char *networks[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkTypeString;
  char *in_name;
  char *out_name;
  char *fname = NULL;
  struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create ();
  int c;

  GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (cfg, cfg_file));
  GNUNET_asprintf (&fname, "q_in_%llu_q_out_%llu_%s", quota_in, quota_out,
                   cfg_file);

  GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "DEFAULTCONFIG", fname);

  for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++)
  {
      GNUNET_asprintf (&in_name, "%s_QUOTA_IN", networks[c]);
      GNUNET_asprintf (&out_name, "%s_QUOTA_OUT", networks[c]);
      GNUNET_CONFIGURATION_set_value_number (cfg, "ats", in_name, quota_in);
      GNUNET_CONFIGURATION_set_value_number (cfg, "ats", out_name, quota_out);
      GNUNET_free (in_name);
      GNUNET_free (out_name);
  }
  GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_write (cfg, fname));
  GNUNET_CONFIGURATION_destroy (cfg);
  return fname;
}
/**
 * Handler for SET_DEFAULT message from client, updates
 * default identity for some service.
 *
 * @param cls unused
 * @param client who sent the message
 * @param message the message received
 */
static void
handle_set_default_message (void *cls,
                            const struct SetDefaultMessage *sdm)
{
  struct Ego *ego;
  struct GNUNET_SERVICE_Client *client = cls;
  const char *str;

  str = (const char *) &sdm[1];
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Received SET_DEFAULT for service `%s' from client\n",
              str);
  for (ego = ego_head; NULL != ego; ego = ego->next)
  {
    if (0 == key_cmp (ego->pk,
                      &sdm->private_key))
    {
      GNUNET_CONFIGURATION_set_value_string (subsystem_cfg,
                                             str,
                                             "DEFAULT_IDENTIFIER",
                                             ego->identifier);
      if (GNUNET_OK !=
          GNUNET_CONFIGURATION_write (subsystem_cfg,
                                      subsystem_cfg_file))
        GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                    _("Failed to write subsystem default identifier map to `%s'.\n"),
                    subsystem_cfg_file);
      send_result_code (client, 0, NULL);
      GNUNET_SERVICE_client_continue (client);
      return;
    }
  }
  send_result_code (client, 1, _("Unknown ego specified for service (internal error)"));
  GNUNET_SERVICE_client_continue (client);
}
Exemple #6
0
/**
 * Process list of local IP addresses.  Find and set the
 * one of the default interface.
 *
 * @param cls our `struct GNUNET_NAT_AutoHandle`
 * @param name name of the interface (can be NULL for unknown)
 * @param isDefault is this presumably the default interface
 * @param addr address of this interface (can be NULL for unknown or unassigned)
 * @param broadcast_addr the broadcast address (can be NULL for unknown or unassigned)
 * @param netmask the network mask (can be NULL for unknown or unassigned))
 * @param addrlen length of the @a addr and @a broadcast_addr
 * @return GNUNET_OK to continue iteration, #GNUNET_SYSERR to abort
 */
static int
process_if (void *cls,
      const char *name,
      int isDefault,
      const struct sockaddr *addr,
      const struct sockaddr *broadcast_addr,
      const struct sockaddr *netmask,
      socklen_t addrlen)
{
  struct GNUNET_NAT_AutoHandle *ah = cls;
  const struct sockaddr_in *in;
  char buf[INET_ADDRSTRLEN];


  if ( (sizeof (struct sockaddr_in6) == addrlen) &&
       (0 != memcmp (&in6addr_loopback, &((const struct sockaddr_in6 *) addr)->sin6_addr,
		     sizeof (struct in6_addr))) &&
       (! IN6_IS_ADDR_LINKLOCAL(&((const struct sockaddr_in6 *) addr)->sin6_addr)) )
  {
    ah->have_v6 = GNUNET_YES;
    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
		_("This system has a global IPv6 address, setting IPv6 to supported.\n"));

    return GNUNET_OK;
  }
  if (addrlen != sizeof (struct sockaddr_in))
    return GNUNET_OK;
  in = (const struct sockaddr_in *) addr;


  /* set internal IP address */
  if (NULL == inet_ntop (AF_INET, &in->sin_addr, buf, sizeof (buf)))
  {
    GNUNET_break (0);
    return GNUNET_OK;
  }
  GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", "INTERNAL_ADDRESS",
					 buf);
  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
	      _("Detected internal network address `%s'.\n"),
	      buf);


  ah->ret = GNUNET_NAT_ERROR_SUCCESS;

  /* Check if our internal IP is the same as the External detect by STUN*/
  if(ah->stun_ip && (strcmp(buf, ah->stun_ip) == 0) )
  {
    ah->internal_ip_is_public = GNUNET_YES;
    GNUNET_log (GNUNET_ERROR_TYPE_INFO,"A internal IP is the sameas the external");
    /* No need to continue*/
    return GNUNET_SYSERR;
  }

  /* no need to continue iteration if we found the default */
  if (!isDefault)
    return GNUNET_OK;
  else
    return GNUNET_SYSERR;
}
/**
 * Handler for SET_DEFAULT message from client, updates
 * default identity for some service.
 *
 * @param cls unused
 * @param client who sent the message
 * @param message the message received
 */
static void
handle_set_default_message (void *cls, struct GNUNET_SERVER_Client *client,
			    const struct GNUNET_MessageHeader *message)
{
  const struct GNUNET_IDENTITY_SetDefaultMessage *sdm;
  uint16_t size;
  uint16_t name_len;
  struct Ego *ego;
  const char *str;

  size = ntohs (message->size);
  if (size <= sizeof (struct GNUNET_IDENTITY_SetDefaultMessage))
  {
    GNUNET_break (0);
    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
    return;
  }
  sdm = (const struct GNUNET_IDENTITY_SetDefaultMessage *) message;
  name_len = ntohs (sdm->name_len);
  GNUNET_break (0 == ntohs (sdm->reserved));
  if (name_len + sizeof (struct GNUNET_IDENTITY_SetDefaultMessage) != size)
  {
    GNUNET_break (0);
    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
    return;
  }
  str = (const char *) &sdm[1];
  if ('\0' != str[name_len - 1])
  {
    GNUNET_break (0);
    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
    return;
  }
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
	      "Received SET_DEFAULT for service `%s' from client\n",
	      str);
  for (ego = ego_head; NULL != ego; ego = ego->next)
  {
    if (0 == key_cmp (ego->pk,
		      &sdm->private_key))
    {
      GNUNET_CONFIGURATION_set_value_string (subsystem_cfg,
					     str,
					     "DEFAULT_IDENTIFIER",
					     ego->identifier);
      if (GNUNET_OK !=
	  GNUNET_CONFIGURATION_write (subsystem_cfg,
				      subsystem_cfg_file))
	GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
		    _("Failed to write subsystem default identifier map to `%s'.\n"),
		    subsystem_cfg_file);
      send_result_code (client, 0, NULL);
      GNUNET_SERVER_receive_done (client, GNUNET_OK);
      return;
    }
  }
  send_result_code (client, 1, _("Unknown ego specified for service (internal error)"));
  GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
static struct GNUNET_CONFIGURATION_Handle *
editConfiguration (struct GNUNET_CONFIGURATION_Handle *cfg, int option)
{
  struct DiffsCBData diffsCB;

  initDiffsCBData (&diffsCB);
  diffsCB.cfgDiffs = GNUNET_CONFIGURATION_create ();

  switch (option)
  {
  case EDIT_SECTION:
  case EDIT_ALL:
  case ADD_NEW_ENTRY:
    diffsCB.callBackOption = option;
    diffsCB.cfg = cfg;
    GNUNET_CONFIGURATION_iterate (cfg, diffsCallBack, &diffsCB);
    break;
  case EDIT_NOTHING:
    /* Do nothing */
    break;
  case ADD_NEW_SECTION:
  {
    int i;
    char *key;

    for (i = 0; i < 5; i++)
    {
      GNUNET_asprintf (&key, "key%d", i);
      GNUNET_CONFIGURATION_set_value_string (cfg, "new-section", key,
                                             "new-value");
      GNUNET_CONFIGURATION_set_value_string (diffsCB.cfgDiffs, "new-section",
                                             key, "new-value");
      GNUNET_free (key);
    }
    break;
  }
  case REMOVE_SECTION:
    break;
  case REMOVE_ENTRY:
    break;
  default:
    break;
  }

  return diffsCB.cfgDiffs;
}
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);
}
Exemple #10
0
int
main (int argc, char *argv[])
{
  int ok;

  GNUNET_log_setup ("test_client",
                    "WARNING",
                    NULL);
  cfg = GNUNET_CONFIGURATION_create ();
  GNUNET_CONFIGURATION_set_value_number (cfg, MYNAME, "PORT", PORT);
  GNUNET_CONFIGURATION_set_value_string (cfg, MYNAME, "HOSTNAME", "localhost");
  GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME",
                                         "localhost");
  ok = 1;
  GNUNET_SCHEDULER_run (&task, &ok);
  GNUNET_CONFIGURATION_destroy (cfg);
  return ok;
}
Exemple #11
0
/**
 * Determine our local IP addresses; detect internal IP & IPv6-support
 *
 * @param ah auto setup context
 */
static void
test_local_ip (struct GNUNET_NAT_AutoHandle *ah)
{
  ah->have_v6 = GNUNET_NO;
  ah->ret = GNUNET_NAT_ERROR_NO_VALID_IF_IP_COMBO; // reset to success if any of the IFs in below iterator has a valid IP
  GNUNET_OS_network_interfaces_list (&process_if, ah);

  GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", "DISABLEV6",
					 (GNUNET_YES == ah->have_v6) ? "NO" : "YES");
  next_phase (ah);
}
/**
 * Change the state of the sensor.
 * Write the change to file to make it persistent.
 *
 * @param sensor sensor info struct
 * @param state new enabled state: #GNUNET_YES / #GNUNET_NO
 */
static void
set_sensor_enabled (struct GNUNET_SENSOR_SensorInfo *sensor, int state)
{
  LOG (GNUNET_ERROR_TYPE_DEBUG, "Sensor `%s': Setting enabled to %d.\n",
       sensor->name, state);
  sensor->enabled = GNUNET_NO;
  GNUNET_assert (NULL != sensor->cfg);
  GNUNET_CONFIGURATION_set_value_string (sensor->cfg, sensor->name, "ENABLED",
                                         (GNUNET_YES == state) ? "YES" : "NO");
  GNUNET_CONFIGURATION_write (sensor->cfg, sensor->def_file);
}
Exemple #13
0
/**
 * Set our external IPv4 address based on the UPnP.
 *
 *
 * @param cls closure with our setup context
 * @param addr the address, NULL on errors
 * @param emsg NULL on success, otherwise an error message
 */
static void
set_external_ipv4 (void *cls,
                   const struct in_addr *addr,
                   enum GNUNET_NAT_StatusCode ret)
{
  struct GNUNET_NAT_AutoHandle *ah = cls;
  char buf[INET_ADDRSTRLEN];

  ah->eh = NULL;
  ah->ret = ret;
  if (GNUNET_NAT_ERROR_SUCCESS != ret)
  {
    next_phase (ah);
    return;
  }
  /* enable 'behind nat' */
  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
	      _("Detected external IP `%s'\n"),
	      inet_ntop (AF_INET,
			 addr,
			 buf,
			 sizeof (buf)));
  GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", "BEHIND_NAT", "YES");

  /* set external IP address */
  if (NULL == inet_ntop (AF_INET, addr, buf, sizeof (buf)))
  {
    GNUNET_break (0);
    /* actually, this should never happen, as the caller already executed just
     * this check, but for consistency (eg: future changes in the caller)
     * we still need to report this error...
     */
    ah->ret = GNUNET_NAT_ERROR_EXTERNAL_IP_ADDRESS_INVALID;
    next_phase (ah);
    return;
  }
  GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", "EXTERNAL_ADDRESS",
					 buf);
  ah->upnp_set_external_address = GNUNET_YES;
  next_phase (ah);
}
/**
 * Function called with th test result to see if the resolver is
 * running.
 *
 * @param cls closure with our configuration
 * @param result #GNUNET_YES if the resolver is running
 */
static void
resolver_test_task (void *cls,
		    int result)
{
  struct GNUNET_CONFIGURATION_Handle *cfg = cls;

  if (GNUNET_YES != result)
   {
     FPRINTF (stderr,
	      _("Trying to connect to remote host, but service `%s' is not running\n"), "resolver");
     return;
   }
  /* connect to a remote host */
  if (0 == remote_port)
  {
    if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, "statistics", "PORT", &remote_port))
    {
      FPRINTF (stderr, _("A port is required to connect to host `%s'\n"), remote_host);
      return;
    }
  }
  else if (65535 <= remote_port)
  {
    FPRINTF (stderr,
	     _("A port has to be between 1 and 65535 to connect to host `%s'\n"), remote_host);
    return;
  }

  /* Manipulate configuration */
  GNUNET_CONFIGURATION_set_value_string (cfg,
					 "statistics", "UNIXPATH", "");
  GNUNET_CONFIGURATION_set_value_string (cfg,
					 "statistics", "HOSTNAME", remote_host);
  GNUNET_CONFIGURATION_set_value_number (cfg,
					 "statistics", "PORT", remote_port);
  GNUNET_SCHEDULER_add_now (&main_task, cfg);
}
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));
}
int
main (int argc, char *argv[])
{
  int ok;

  GNUNET_log_setup ("test_connection_timeout_no_connect",
                    "WARNING",
                    NULL);
  ok = 1;
  cfg = GNUNET_CONFIGURATION_create ();
  GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME",
                                         "localhost");
  GNUNET_SCHEDULER_run (&task_timeout, &ok);
  GNUNET_CONFIGURATION_destroy (cfg);
  return ok;
}
Exemple #17
0
/**
 * Function to iterate over sugested changes options
 *
 * @param cls closure
 * @param section name of the section
 * @param option name of the option
 * @param value value of the option
 */
static void
auto_conf_iter (void *cls,
                const char *section,
                const char *option,
                const char *value)
{
  struct GNUNET_CONFIGURATION_Handle *new_cfg = cls;

  PRINTF ("%s: %s\n",
	  option,
	  value);
  if (NULL != new_cfg)
    GNUNET_CONFIGURATION_set_value_string (new_cfg,
					   section,
					   option,
					   value);
}
Exemple #18
0
/**
 * Load configuration (starts with defaults, then loads
 * system-specific configuration).
 *
 * @param cfg configuration to update
 * @param filename name of the configuration file, NULL to load defaults
 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
 */
int
GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg,
                           const char *filename)
{
    char *baseconfig;
    const char *base_config_varname;

    base_config_varname = GNUNET_OS_project_data_get ()->base_config_varname;

    if (NULL != (baseconfig = getenv (base_config_varname)))
    {
        baseconfig = GNUNET_strdup (baseconfig);
    }
    else
    {
        char *ipath;

        ipath = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR);
        if (NULL == ipath)
            return GNUNET_SYSERR;
        GNUNET_asprintf (&baseconfig, "%s%s", ipath, "config.d");
        GNUNET_free (ipath);
    }

    if (GNUNET_SYSERR ==
            GNUNET_CONFIGURATION_load_from (cfg,
                                            baseconfig))
    {
        GNUNET_free (baseconfig);
        return GNUNET_SYSERR;       /* no configuration at all found */
    }
    GNUNET_free (baseconfig);
    if ((NULL != filename) &&
            (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, filename)))
    {
        /* specified configuration not found */
        return GNUNET_SYSERR;
    }
    if (((GNUNET_YES !=
            GNUNET_CONFIGURATION_have_value (cfg, "PATHS", "DEFAULTCONFIG"))) &&
            (filename != NULL))
        GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "DEFAULTCONFIG",
                                               filename);
    return GNUNET_OK;
}
static char *
generate_config (char *cfg_file, unsigned long long quota_in,
                 unsigned long long quota_out)
{
  char *fname = NULL;
  struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create ();

  GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (cfg, cfg_file));
  GNUNET_asprintf (&fname, "q_in_%llu_q_out_%llu_%s", quota_in, quota_out,
                   cfg_file);
  GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "DEFAULTCONFIG", fname);
  GNUNET_CONFIGURATION_set_value_number (cfg, "ats", "WAN_QUOTA_IN", quota_in);
  GNUNET_CONFIGURATION_set_value_number (cfg, "ats", "WAN_QUOTA_OUT",
                                         quota_out);
  GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_write (cfg, fname));
  GNUNET_CONFIGURATION_destroy (cfg);
  return fname;
}
Exemple #20
0
/**
 * Function called by NAT to report the outcome of the nat-test.
 * Clean up and update GUI.
 *
 * @param cls the auto handle
 * @param success currently always #GNUNET_OK
 * @param emsg NULL on success, otherwise an error message
 */
static void
result_callback (void *cls,
                 enum GNUNET_NAT_StatusCode ret)
{
  struct GNUNET_NAT_AutoHandle *ah = cls;

  if (GNUNET_NAT_ERROR_SUCCESS == ret)
    GNUNET_NAT_test_stop (ah->tst);
  ah->tst = NULL;
  ah->ret = ret;
  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
              GNUNET_NAT_ERROR_SUCCESS == ret
	      ? _("NAT traversal with ICMP Server succeeded.\n")
	      : _("NAT traversal with ICMP Server failed.\n"));
  GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", "ENABLE_ICMP_SERVER",
					 GNUNET_NAT_ERROR_SUCCESS == ret ? "NO" : "YES");
  next_phase (ah);
}
static int
init ()
{
  struct GNUNET_CONFIGURATION_Handle *cfg;
  char pwd[PATH_MAX];
  char *binary;

  cfg = GNUNET_CONFIGURATION_create ();
  if (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg,
                                               "test_arm_api_data.conf"))
    return GNUNET_SYSERR;
  if (NULL == getcwd (pwd, PATH_MAX))
    return GNUNET_SYSERR;
  GNUNET_assert (0 < GNUNET_asprintf (&binary,
                                      "%s/%s",
                                      pwd,
                                      BINARY));
  GNUNET_CONFIGURATION_set_value_string (cfg,
                                         SERVICE,
                                         "BINARY",
                                         binary);
  GNUNET_free (binary);
  if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg,
                                               CFGFILENAME))
  {
    GNUNET_CONFIGURATION_destroy (cfg);
    return GNUNET_SYSERR;
  }
  GNUNET_CONFIGURATION_destroy (cfg);

#if LOG_BACKOFF
  killLogFileName = GNUNET_DISK_mktemp ("exponential-backoff-waiting.log");
  if (NULL == (killLogFilePtr = FOPEN (killLogFileName,
                                       "w")))
    {
      GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
                                "fopen",
				killLogFileName);
      GNUNET_free (killLogFileName);
      return GNUNET_SYSERR;
    }
#endif
  return GNUNET_OK;
}
/**
 * run: load configuration options and schedule test to run (start peergroup)
 * @param cls closure
 * @param args argv
 * @param cfgfile configuration file name (can be NULL)
 * @param cfg configuration handle
 */
static void
run (void *cls, char *const *args, const char *cfgfile,
     const struct GNUNET_CONFIGURATION_Handle *cfg)
{
  struct GNUNET_TESTING_Host *hosts;

  ok = GNUNET_NO;
  total_connections = 0;
  failed_connections = 0;
  testing_cfg = GNUNET_CONFIGURATION_dup (cfg);

  GNUNET_log_setup ("test_testing_2dtorus",
#if VERBOSE
                    "DEBUG",
#else
                    "WARNING",
#endif
                    NULL);

#if VERBOSE
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Starting daemons.\n");
  GNUNET_CONFIGURATION_set_value_string (testing_cfg, "testing",
                                         "use_progressbars", "YES");
#endif

  if (GNUNET_OK !=
      GNUNET_CONFIGURATION_get_value_number (testing_cfg, "testing",
                                             "num_peers", &num_peers))
  {
    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                "Option TESTING:NUM_PEERS is required!\n");
    return;
  }

  hosts = GNUNET_TESTING_hosts_load (testing_cfg);

  pg = GNUNET_TESTING_peergroup_start (testing_cfg, num_peers, TIMEOUT,
                                       &connect_cb, &peergroup_ready, NULL,
                                       hosts);
  GNUNET_assert (pg != NULL);
  shutdown_handle =
    GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
                                    &shutdown_task, NULL);
}
static void
run (void *cls, char *const *args, const char *cfgfile,
     const struct GNUNET_CONFIGURATION_Handle *cfg)
{
    struct GNUNET_CONFIGURATION_Handle *testing_cfg;

    ok = 1;
    testing_cfg = GNUNET_CONFIGURATION_create ();
    GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (testing_cfg, cfgfile));
#if VERBOSE
    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons.\n");
    GNUNET_CONFIGURATION_set_value_string (testing_cfg, "testing",
                                           "use_progressbars", "YES");
#endif
    peers_left = NUM_PEERS;
    pg = GNUNET_TESTING_peergroup_start (testing_cfg, peers_left, TIMEOUT, NULL,
                                         &my_cb, NULL, NULL);
    GNUNET_assert (pg != NULL);
}
Exemple #24
0
/**
 * Functions with this signature are called whenever a
 * complete message is received by the tokenizer.
 *
 * Do not call GNUNET_SERVER_mst_destroy in callback
 *
 * @param cls closure
 * @param client identification of the client
 * @param message the actual message
 *
 * @return GNUNET_OK on success, GNUNET_SYSERR to stop further processing
 */
static int
helper_mst (void *cls, void *client, const struct GNUNET_MessageHeader *message)
{
  struct GNUNET_TESTBED_ControllerProc *cp = cls;
  const struct GNUNET_TESTBED_HelperReply *msg;
  const char *hostname;
  char *config;
  uLongf config_size;
  uLongf xconfig_size;

  msg = (const struct GNUNET_TESTBED_HelperReply *) message;
  GNUNET_assert (sizeof (struct GNUNET_TESTBED_HelperReply) <
                 ntohs (msg->header.size));
  GNUNET_assert (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY ==
                 ntohs (msg->header.type));
  config_size = (uLongf) ntohs (msg->config_size);
  xconfig_size =
      (uLongf) (ntohs (msg->header.size) -
                sizeof (struct GNUNET_TESTBED_HelperReply));
  config = GNUNET_malloc (config_size);
  GNUNET_assert (Z_OK ==
                 uncompress ((Bytef *) config, &config_size,
                             (const Bytef *) &msg[1], xconfig_size));
  /* Replace the configuration template present in the host with the
     controller's running configuration */
  GNUNET_CONFIGURATION_destroy (cp->host->cfg);
  cp->host->cfg = GNUNET_CONFIGURATION_create ();
  GNUNET_assert (GNUNET_CONFIGURATION_deserialize
                 (cp->host->cfg, config, config_size, GNUNET_NO));
  GNUNET_free (config);
  if (NULL == (hostname = GNUNET_TESTBED_host_get_hostname (cp->host)))
    hostname = "localhost";
  /* Change the hostname so that we can connect to it */
  GNUNET_CONFIGURATION_set_value_string (cp->host->cfg, "testbed", "hostname",
                                         hostname);
  cp->host->locked = GNUNET_NO;
  cp->host->controller_started = GNUNET_YES;
  cp->cb (cp->cls, cp->host->cfg, GNUNET_OK);
  return GNUNET_OK;
}
Exemple #25
0
/**
 * Start auto-configuration routine.  The resolver service should
 * be available when this function is called.
 *
 * @param cfg initial configuration
 * @param cb function to call with autoconfiguration result
 * @param cb_cls closure for @a cb
 * @return handle to cancel operation
 */
struct GNUNET_NAT_AutoHandle *
GNUNET_NAT_autoconfig_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
			     GNUNET_NAT_AutoResultCallback cb,
			     void *cb_cls)
{
  struct GNUNET_NAT_AutoHandle *ah;

  ah = GNUNET_new (struct GNUNET_NAT_AutoHandle);
  ah->fin_cb = cb;
  ah->fin_cb_cls = cb_cls;
  ah->ret = GNUNET_NAT_ERROR_SUCCESS;
  ah->cfg = GNUNET_CONFIGURATION_dup (cfg);
  ah->initial_cfg = GNUNET_CONFIGURATION_dup (cfg);

  /* never use loopback addresses if user wanted autoconfiguration */
  GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat",
					 "USE_LOCALADDR",
					 "NO");

  next_phase (ah);
  return ah;
}
Exemple #26
0
/**
 * Test if UPnPC works.
 *
 * @param ah auto setup context
 */
static void
test_upnpc (struct GNUNET_NAT_AutoHandle *ah)
{

  int have_upnpc;

  if (GNUNET_NAT_ERROR_SUCCESS != ah->ret)
    next_phase (ah);

  // test if upnpc is available
  have_upnpc = (GNUNET_SYSERR !=
		GNUNET_OS_check_helper_binary ("upnpc", GNUNET_NO, NULL));
  //FIXME: test if upnpc is actually working, that is, if transports start to work once we use UPnP
  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
	      (have_upnpc)
	      ? _("upnpc found, enabling its use\n")
	      : _("upnpc not found\n"));
  GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", "ENABLE_UPNP",
					 (GNUNET_YES == have_upnpc) ? "YES" : "NO");
  next_phase (ah);

}
Exemple #27
0
/**
 * An ego was removed, remove it from all subsystems where it is
 * currently set as the default.
 *
 * @param cls name of the removed ego (const char *)
 * @param section a section in the configuration to process
 */
static void
handle_ego_delete (void *cls,
		   const char *section)
{
  const char *identifier = cls;
  char *id;

  if (GNUNET_OK !=
      GNUNET_CONFIGURATION_get_value_string (subsystem_cfg,
					     section,
					     "DEFAULT_IDENTIFIER",
					     &id))
    return;
  if (0 != strcmp (id, identifier))
  {
    GNUNET_free (id);
    return;
  }
  GNUNET_CONFIGURATION_set_value_string (subsystem_cfg,
					 section,
					 "DEFAULT_IDENTIFIER",
					 NULL);
  GNUNET_free (id);
}
Exemple #28
0
/**
 * An ego was renamed; rename it in all subsystems where it is
 * currently set as the default.
 *
 * @param cls the 'struct RenameContext'
 * @param section a section in the configuration to process
 */
static void
handle_ego_rename (void *cls,
		   const char *section)
{
  struct RenameContext *rc = cls;
  char *id;

  if (GNUNET_OK !=
      GNUNET_CONFIGURATION_get_value_string (subsystem_cfg,
					     section,
					     "DEFAULT_IDENTIFIER",
					     &id))
    return;
  if (0 != strcmp (id, rc->old_name))
  {
    GNUNET_free (id);
    return;
  }
  GNUNET_CONFIGURATION_set_value_string (subsystem_cfg,
					 section,
					 "DEFAULT_IDENTIFIER",
					 rc->new_name);
  GNUNET_free (id);
}
Exemple #29
0
int
main (int argc, char *argv[])
{
  int ok;
  int status;
  const char *socksport = "1081";

  GNUNET_log_setup ("test_client",
                    "WARNING",
                    NULL);

  pid_t pid = fork();
  GNUNET_assert (pid >= 0);
  if (pid == 0) 
  {
    execlp ("ssh",
            "ssh","-D",socksport,
            "-o","BatchMode yes",
            "-o","UserKnownHostsFile /tmp/gnunet_test_socks_ssh_garbage",
            "-o","StrictHostKeyChecking no",
            "127.0.0.1","-N",(char*)NULL);
    perror ("execlp (\"ssh\",\"ssh\",...,\"-D\",\"1081\",\"127.0.0.1\",\"-N\") ");
    printf (""
"Please ensure you have ssh installed and have sshd installed and running :\n"
"\tsudo apt-get install openssh-client openssh-server\n"
"If you run Tor as a network proxy then Tor might prevent ssh from connecting\n"
"to localhost.  Please either run  make check  from an unproxied user, or else\n"
"add these lines to the beginning of your ~/.ssh/config file :"
"\tHost 127.0.0.1 localhost\n"
"\t  CheckHostIP no\n"
"\t  Protocol 2\n"
"\t  ProxyCommand nc 127.0.0.1 22\n");
    kill (getppid(), SIGALRM);
    return 1;
  }
  if (0 != sleep (1))
  {
    /* sleep interrupted, likely SIGALRM, failure to
       launch child, terminate */
    printf (""
"Please ensure you have ssh installed and have sshd installed and running :\n"
"\tsudo apt-get install openssh-client openssh-server\n"
"If you run Tor as a network proxy then Tor might prevent ssh from connecting\n"
"to localhost.  Please either run  make check  from an unproxied user, or else\n"
"add these lines to the beginning of your ~/.ssh/config file :"
"\tHost 127.0.0.1 localhost\n"
"\t  CheckHostIP no\n"
"\t  Protocol 2\n"
"\t  ProxyCommand nc 127.0.0.1 22\n");
    return 77;
  }
  /* check if child exec()ed but died */
  if (0 != waitpid (pid, &status, WNOHANG))
  {
    printf (""
"If you run Tor as a network proxy then Tor might prevent ssh from connecting\n"
"to localhost.  Please either run  make check  from an unproxied user, or else\n"
"add these lines to the beginning of your ~/.ssh/config file :"
"\tHost 127.0.0.1 localhost\n"
"\t  CheckHostIP no\n"
"\t  Protocol 2\n"
"\t  ProxyCommand nc 127.0.0.1 22\n");
    return 77;
  }

  cfg = GNUNET_CONFIGURATION_create ();
  GNUNET_CONFIGURATION_set_value_string (cfg, MYNAME, "SOCKSHOST", "127.0.0.1");
  GNUNET_CONFIGURATION_set_value_string (cfg, MYNAME, "SOCKSPORT", socksport);
  GNUNET_CONFIGURATION_set_value_number (cfg, MYNAME, "PORT", PORT);
  GNUNET_CONFIGURATION_set_value_string (cfg, MYNAME, "HOSTNAME", "127.0.0.1");
  ok = 1;
  GNUNET_SCHEDULER_run (&task, &ok);
  GNUNET_CONFIGURATION_destroy (cfg);

  GNUNET_break (0 == kill (pid, SIGTERM));
  GNUNET_break (pid == waitpid (pid, &status, 0));
  return ok;
}
Exemple #30
0
/**
 * Function called with the result from the autoconfiguration.
 *
 * @param cls closure
 * @param diff minimal suggested changes to the original configuration
 *             to make it work (as best as we can)
 * @param result #GNUNET_NAT_ERROR_SUCCESS on success, otherwise the specific error code
 * @param type what the situation of the NAT
 */
static void
auto_config_cb (void *cls,
		const struct GNUNET_CONFIGURATION_Handle *diff,
		enum GNUNET_NAT_StatusCode result,
		enum GNUNET_NAT_Type type)
{
  const char *nat_type;
  char unknown_type[64];
  struct GNUNET_CONFIGURATION_Handle *new_cfg;

  ah = NULL;
  switch (type)
  {
  case GNUNET_NAT_TYPE_NO_NAT:
    nat_type = "NO NAT";
    break;
  case GNUNET_NAT_TYPE_UNREACHABLE_NAT:
    nat_type = "NAT but we can traverse";
    break;
  case GNUNET_NAT_TYPE_STUN_PUNCHED_NAT:
    nat_type = "NAT but STUN is able to identify the correct information";
    break;
  case GNUNET_NAT_TYPE_UPNP_NAT:
    nat_type = "NAT but UPNP opened the ports";
    break;
  default:
    SPRINTF (unknown_type,
	     "NAT unknown, type %u",
	     type);
    nat_type = unknown_type;
    break;
  }

  GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
	      "NAT status: %s/%s\n",
	      GNUNET_NAT_AUTO_status2string (result),
	      nat_type);

  /* Shortcut: if there are no changes suggested, bail out early. */
  if (GNUNET_NO ==
      GNUNET_CONFIGURATION_is_dirty (diff))
  {
    test_finished ();
    return;
  }

  /* Apply diff to original configuration and show changes
     to the user */
  new_cfg = write_cfg ? GNUNET_CONFIGURATION_dup (cfg) : NULL;

  if (NULL != diff)
  {
    GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
		_("Suggested configuration changes:\n"));
    GNUNET_CONFIGURATION_iterate_section_values (diff,
						 "nat",
						 &auto_conf_iter,
						 new_cfg);
  }

  /* If desired, write configuration to file; we write only the
     changes to the defaults to keep things compact. */
  if ( (write_cfg) &&
       (NULL != diff) )
  {
    struct GNUNET_CONFIGURATION_Handle *def_cfg;

    GNUNET_CONFIGURATION_set_value_string (new_cfg,
					   "ARM",
					   "CONFIG",
					   NULL);
    def_cfg = GNUNET_CONFIGURATION_create ();
    GNUNET_break (GNUNET_OK ==
		  GNUNET_CONFIGURATION_load (def_cfg,
					     NULL));
    if (GNUNET_OK !=
	GNUNET_CONFIGURATION_write_diffs (def_cfg,
					  new_cfg,
					  cfg_file))
    {
      GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
		  _("Failed to write configuration to `%s'\n"),
		  cfg_file);
      global_ret = 1;
    }
    else
    {
      GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
		  _("Wrote updated configuration to `%s'\n"),
		  cfg_file);
    }
    GNUNET_CONFIGURATION_destroy (def_cfg);
  }

  if (NULL != new_cfg)
    GNUNET_CONFIGURATION_destroy (new_cfg);
  test_finished ();
}