/**
 * Function to load keys
 */
static int
load_keys (const struct GNUNET_CONFIGURATION_Handle *c)
{
    char *data_dir;
    char *idfile;
    uint64_t fsize;

    data_dir = NULL;
    idfile = NULL;
    fsize = 0;
    data_dir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR);
    GNUNET_asprintf (&idfile, "%s/testing_hostkeys.ecc", data_dir);
    GNUNET_free (data_dir);
    data_dir = NULL;
    if (GNUNET_OK !=
            GNUNET_DISK_file_size (idfile, &fsize, GNUNET_YES, GNUNET_YES))
    {
        GNUNET_free (idfile);
        return GNUNET_SYSERR;
    }
    if (0 != (fsize % GNUNET_TESTING_HOSTKEYFILESIZE))
    {
        LOG (GNUNET_ERROR_TYPE_ERROR,
             _("Incorrect hostkey file format: %s\n"), idfile);
        GNUNET_free (idfile);
        return GNUNET_SYSERR;
    }
    hostkeys_fd = GNUNET_DISK_file_open (idfile, GNUNET_DISK_OPEN_READ,
                                         GNUNET_DISK_PERM_NONE);
    if (NULL == hostkeys_fd)
    {
        GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", idfile);
        GNUNET_free (idfile);
        return GNUNET_SYSERR;
    }
    GNUNET_free (idfile);
    idfile = NULL;
    hostkeys_data = GNUNET_DISK_file_map (hostkeys_fd,
                                          &hostkeys_map,
                                          GNUNET_DISK_MAP_TYPE_READ,
                                          fsize);
    if (NULL == hostkeys_data)
    {

        GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "mmap");
        return GNUNET_SYSERR;
    }
    num_hostkeys = fsize / GNUNET_TESTING_HOSTKEYFILESIZE;
    return GNUNET_OK;
}
Example #2
0
/**
 * Main function that will be run by the scheduler.
 *
 * @param cls closure
 * @param args remaining command-line arguments
 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
 * @param cfg configuration
 */
static void
run (void *cls, char *const *args, const char *cfgfile,
     const struct GNUNET_CONFIGURATION_Handle *cfg)
{
  struct GNUNET_DISK_MapHandle *map;
  struct GNUNET_DISK_FileHandle *h;
  void *data;
  size_t len;
  uint64_t size;
  const char *filename;
  int i;

  if (NULL == args[0])
  {
    FPRINTF (stderr, "%s",  _("You must specify a filename to inspect.\n"));
    ret = 1;
    return;
  }
  i = 0;
  while (NULL != (filename = args[i++]))
  {
    if ((GNUNET_OK != GNUNET_DISK_file_size (filename, &size, GNUNET_YES, GNUNET_YES)) ||
        (NULL ==
         (h =
          GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ,
                                 GNUNET_DISK_PERM_NONE))))
    {
      GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to read directory `%s'\n"),
                  filename);
      ret = 1;
      continue;
    }
    len = (size_t) size;
    data = GNUNET_DISK_file_map (h, &map, GNUNET_DISK_MAP_TYPE_READ, len);
    GNUNET_assert (NULL != data);
    if (GNUNET_OK != GNUNET_FS_directory_list_contents (len, data, 0, &print_entry, NULL))
      fprintf (stdout, _("`%s' is not a GNUnet directory\n"),
	       filename);
    else
      printf ("\n");
    GNUNET_DISK_file_unmap (map);
    GNUNET_DISK_file_close (h);
  }
}