⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gnunet-insert.c

📁 GNUnet是一个安全的点对点网络框架
💻 C
📖 第 1 页 / 共 2 页
字号:
/*     This file is part of GNUnet.     (C) 2001, 2002, 2003, 2004, 2005, 2006, 2008 Christian Grothoff (and other contributing authors)     GNUnet is free software; you can redistribute it and/or modify     it under the terms of the GNU General Public License as published     by the Free Software Foundation; either version 2, or (at your     option) any later version.     GNUnet is distributed in the hope that it will be useful, but     WITHOUT ANY WARRANTY; without even the implied warranty of     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     General Public License for more details.     You should have received a copy of the GNU General Public License     along with GNUnet; see the file COPYING.  If not, write to the     Free Software Foundation, Inc., 59 Temple Place - Suite 330,     Boston, MA 02111-1307, USA.*//** * @file applications/fs/tools/gnunet-insert.c * @brief Tool to insert or index files into GNUnet's FS. * @author Christian Grothoff * @author Krista Bennett * @author James Blackwell * @author Igor Wronsky */#include "platform.h"#include "gnunet_directories.h"#include "gnunet_fsui_lib.h"#include "gnunet_namespace_lib.h"#include "gnunet_util.h"static int errorCode;static struct GNUNET_GC_Configuration *cfg;static struct GNUNET_GE_Context *ectx;static struct GNUNET_FSUI_Context *ctx;static struct GNUNET_FSUI_UploadList *ul;static GNUNET_CronTime start_time;static GNUNET_CronTime expiration = 2 * GNUNET_CRON_YEARS;/* ************ config options ******** */static char *cfgFilename = GNUNET_DEFAULT_CLIENT_CONFIG_FILE;static struct GNUNET_MetaData *meta;static struct GNUNET_ECRS_URI *topKeywords;static struct GNUNET_ECRS_URI *gloKeywords;static struct GNUNET_MetaData *meta;static unsigned int anonymity = 1;static unsigned int priority = 365;static char *uri_string;static char *next_id;static char *this_id;static char *pseudonym;static int do_insert;static int do_no_direct_references;static int do_copy;static int do_simulate;static int extract_only;static int do_disable_creation_time;/** * We're done with the upload of the file, do the * post-processing. */static voidpostProcess (const struct GNUNET_ECRS_URI *uri){  GNUNET_HashCode nsid;  struct GNUNET_ECRS_URI *nsuri;  char *us;  if (pseudonym == NULL)    return;  if (GNUNET_OK != GNUNET_pseudonym_name_to_id (ectx, cfg, pseudonym, &nsid))    {      printf (_("\tUnknown namespace `%s'\n"), pseudonym);      return;    }  nsuri = GNUNET_NS_add_to_namespace (ectx,                                      cfg,                                      anonymity,                                      priority,                                      GNUNET_get_time () +                                      expiration, &nsid,                                      this_id, next_id, uri, meta);  if (nsuri != NULL)    {      us = GNUNET_ECRS_uri_to_string (nsuri);      GNUNET_ECRS_uri_destroy (nsuri);      printf (_("Created entry `%s' in namespace `%s'\n"), us, pseudonym);      GNUNET_free (us);    }  else    {      printf (_("Failed to add entry to namespace `%s' (does it exist?)\n"),              pseudonym);    }  GNUNET_free (pseudonym);  pseudonym = NULL;}static intlistKeywords (const char *fn, const char *dir, void *cls){  EXTRACTOR_ExtractorList *l = cls;  char *fullName;  struct stat buf;  EXTRACTOR_KeywordList *list;  fullName = GNUNET_malloc (strlen (dir) + strlen (fn) + 2);  strcpy (fullName, dir);  if (dir[strlen (dir) - 1] != DIR_SEPARATOR)    strcat (fullName, DIR_SEPARATOR_STR);  strcat (fullName, fn);  printf (_("Keywords for file `%s':\n"), fullName);  if (0 != STAT (fullName, &buf))    {      GNUNET_free (fullName);      return GNUNET_OK;    }  if (S_ISDIR (buf.st_mode))    {      printf ("%s - %s\n", dgettext ("libextractor", "filename"), fn);      printf ("%s - %s\n",              dgettext ("libextractor", "mimetype"),              "application/gnunet-directory");      GNUNET_disk_directory_scan (NULL, fullName, &listKeywords, cls);    }  else    {      list = EXTRACTOR_getKeywords (l, fullName);      list = EXTRACTOR_removeDuplicateKeywords (list,                                                EXTRACTOR_DUPLICATES_TYPELESS);      list = EXTRACTOR_removeKeywordsOfType (list, EXTRACTOR_THUMBNAIL_DATA);      EXTRACTOR_printKeywords (stdout, list);      EXTRACTOR_freeKeywords (list);    }  GNUNET_free (fullName);  return GNUNET_OK;}/** * Print progess message. */static void *printstatus (void *ctx, const GNUNET_FSUI_Event * event){  unsigned long long *verboselevel = ctx;  unsigned long long delta;  char *fstring;  switch (event->type)    {    case GNUNET_FSUI_upload_progress:      if (*verboselevel)        {          char *ret;          GNUNET_CronTime now;          now = GNUNET_get_time ();          delta = event->data.UploadProgress.eta - now;          if (event->data.UploadProgress.eta < now)            delta = 0;          ret = GNUNET_get_time_interval_as_fancy_string (delta);          PRINTF (_("%16llu of %16llu bytes inserted "                    "(estimating %6s to completion) - %s\n"),                  event->data.UploadProgress.completed,                  event->data.UploadProgress.total,                  ret, event->data.UploadProgress.filename);          GNUNET_free (ret);        }      break;    case GNUNET_FSUI_upload_completed:      if (*verboselevel)        {          delta = GNUNET_get_time () - start_time;          PRINTF (_("Upload of `%s' complete, "                    "%llu bytes took %llu seconds (%8.3f KiB/s).\n"),                  event->data.UploadCompleted.filename,                  event->data.UploadCompleted.total,                  delta / GNUNET_CRON_SECONDS,                  (delta == 0)                  ? (double) (-1.0)                  : (double) (event->data.UploadCompleted.total                              / 1024.0 * GNUNET_CRON_SECONDS / delta));        }      fstring = GNUNET_ECRS_uri_to_string (event->data.UploadCompleted.uri);      printf (_("File `%s' has URI: %s\n"),              event->data.UploadCompleted.filename, fstring);      GNUNET_free (fstring);      if (ul == event->data.UploadCompleted.uc.pos)        {          postProcess (event->data.UploadCompleted.uri);          errorCode = 0;          GNUNET_shutdown_initiate ();        }      break;    case GNUNET_FSUI_upload_aborted:      printf (_("\nUpload aborted.\n"));      errorCode = 2;      GNUNET_shutdown_initiate ();      break;    case GNUNET_FSUI_upload_error:      printf (_("\nError uploading file: %s"),              event->data.UploadError.message);      errorCode = 3;      GNUNET_shutdown_initiate ();      break;    case GNUNET_FSUI_upload_started:    case GNUNET_FSUI_upload_stopped:      break;    default:      printf (_("\nUnexpected event: %d\n"), event->type);      GNUNET_GE_BREAK (ectx, 0);      break;    }  return NULL;}/** * All gnunet-insert command line options */static struct GNUNET_CommandLineOption gnunetinsertOptions[] = {  {'a', "anonymity", "LEVEL",   gettext_noop ("set the desired LEVEL of sender-anonymity"),   1, &GNUNET_getopt_configure_set_uint, &anonymity},  GNUNET_COMMAND_LINE_OPTION_CFG_FILE (&cfgFilename),   /* -c */  {'C', "copy", NULL,   gettext_noop ("even if gnunetd is running on the local machine, force the"                 " creation of a copy instead of making a link to the GNUnet share directory"),   0, &GNUNET_getopt_configure_set_one, &do_copy},  {'d', "disable-creation-time", NULL,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -