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

📄 collection.c

📁 GNUnet是一个安全的点对点网络框架
💻 C
📖 第 1 页 / 共 2 页
字号:
                                   GNUNET_GE_ERROR | GNUNET_GE_BULK, "open",                                   fn);      GNUNET_free (fn);      GNUNET_free (buf);      return;    }  GNUNET_GE_BREAK (ectx, collectionData->file_count <= 1024 * 1024 * 4);  WRITE (fd, collectionData, sizeof (CollectionData));  WRITEINT (fd, collectionData->file_count);  WRITEINT (fd, mlen);  WRITE (fd, buf, mlen);  GNUNET_free (buf);  for (i = 0; i < collectionData->file_count; i++)    {      mlen =        GNUNET_meta_data_get_serialized_size (collectionData->files[i].meta,                                              GNUNET_NO);      buf = GNUNET_malloc (mlen);      if (mlen != GNUNET_meta_data_serialize (ectx,                                              collectionData->files[i].meta,                                              buf, mlen, GNUNET_NO))        {          GNUNET_GE_BREAK (ectx, 0);          GNUNET_free (buf);          break;        }      tmp = GNUNET_ECRS_uri_to_string (collectionData->files[i].uri);      WRITEINT (fd, strlen (tmp));      WRITEINT (fd, mlen);      GNUNET_GE_BREAK (ectx, strlen (tmp) < 16 * 1024);      WRITE (fd, tmp, strlen (tmp));      GNUNET_free (tmp);      WRITE (fd, buf, mlen);      GNUNET_free (buf);    }  CLOSE (fd);  GNUNET_free (fn);}static voidfree_collection_data (){  unsigned int i;  if (collectionData == NULL)    return;  GNUNET_meta_data_destroy (collectionData->meta);  for (i = 0; i < collectionData->file_count; i++)    {      GNUNET_meta_data_destroy (collectionData->files[i].meta);      GNUNET_ECRS_uri_destroy (collectionData->files[i].uri);    }  GNUNET_array_grow (collectionData->files, collectionData->file_count, 0);  GNUNET_free (collectionData);  collectionData = NULL;}/** * Shutdown collection module. */voidGNUNET_CO_done (){  writeCO ();  free_collection_data ();  GNUNET_mutex_destroy (lock);  lock = NULL;  ectx = NULL;  cfg = NULL;}/** * Start collection. * * @param updateInterval of GNUNET_ECRS_SBLOCK_UPDATE_NONE *        means to update _immediately_ on any change, *        wherease GNUNET_ECRS_SBLOCK_UPDATE_SPORADIC means *        to publish updates when the CO_Context *        is destroyed (i.e. on exit from the UI). */intGNUNET_CO_collection_start (unsigned int anonymityLevel,                            unsigned int prio,                            const struct GNUNET_MetaData *meta){  struct GNUNET_ECRS_URI *advertisement;  struct GNUNET_ECRS_URI *rootURI;  const char *root = COLLECTION_ROOT;  GNUNET_mutex_lock (lock);  GNUNET_CO_collection_stop (); /* cancel old collection */  advertisement = GNUNET_ECRS_keyword_string_to_uri (ectx, COLLECTION);  GNUNET_GE_ASSERT (ectx, advertisement != NULL);  rootURI = GNUNET_ECRS_namespace_create (ectx,                                          cfg,                                          meta,                                          anonymityLevel,                                          prio,                                          GNUNET_get_time () +                                          COLLECTION_ADV_LIFETIME,                                          advertisement, root);  GNUNET_ECRS_uri_destroy (advertisement);  if (rootURI == NULL)    {      GNUNET_mutex_unlock (lock);      return GNUNET_SYSERR;    }  collectionData = GNUNET_malloc (sizeof (CollectionInfo));  memset (collectionData, 0, sizeof (CollectionInfo));  GNUNET_ECRS_uri_get_namespace_from_sks (rootURI, &collectionData->data.pid);  GNUNET_ECRS_uri_destroy (rootURI);  collectionData->data.priority = htonl (prio);  collectionData->data.anonymityLevel = htonl (anonymityLevel);  collectionData->meta = GNUNET_meta_data_duplicate (meta);  GNUNET_mutex_unlock (lock);  return GNUNET_OK;}/** * Stop collection. * * @return GNUNET_OK on success, GNUNET_SYSERR if no collection is active */intGNUNET_CO_collection_stop (){  GNUNET_mutex_lock (lock);  if (collectionData == NULL)    {      GNUNET_mutex_unlock (lock);      return GNUNET_SYSERR;    }  GNUNET_ECRS_namespace_delete (ectx, cfg, &collectionData->data.pid);  free_collection_data ();  GNUNET_mutex_unlock (lock);  return GNUNET_OK;}/** * Are we using a collection? * * @return NULL if there is no collection, otherwise its metadata */struct GNUNET_MetaData *GNUNET_CO_collection_get_name (){  struct GNUNET_MetaData *meta;  GNUNET_mutex_lock (lock);  if (collectionData == NULL)    {      GNUNET_mutex_unlock (lock);      return NULL;    }  meta = GNUNET_meta_data_duplicate (collectionData->meta);  GNUNET_mutex_unlock (lock);  return meta;}/** * Publish an update of the current collection information to the * network now.  The function has no effect if the collection has not * changed since the last publication.  If we are currently not * collecting, this function does nothing. */voidGNUNET_CO_collection_publish_now (){  struct GNUNET_ECRS_URI *uri;  struct GNUNET_ECRS_URI *directoryURI;  unsigned long long dirLen;  char *tmpName;  int fd;  char *dirData;  char this_revision_string[128];  char next_revision_string[128];  GNUNET_mutex_lock (lock);  if ((collectionData == NULL) ||      (ntohl (collectionData->data.changed) == GNUNET_NO))    {      GNUNET_mutex_unlock (lock);      return;    }  tmpName = GNUNET_strdup ("/tmp/gnunet-collectionXXXXXX");  fd = mkstemp (tmpName);  if (fd == -1)    {      GNUNET_GE_LOG_STRERROR (ectx,                              GNUNET_GE_ERROR | GNUNET_GE_ADMIN |                              GNUNET_GE_BULK, "mkstemp");      GNUNET_free (tmpName);      GNUNET_mutex_unlock (lock);      return;    }  dirData = NULL;  GNUNET_GE_ASSERT (ectx,                    GNUNET_OK == GNUNET_ECRS_directory_create (ectx,                                                               &dirData,                                                               &dirLen,                                                               collectionData->                                                               file_count,                                                               collectionData->                                                               files,                                                               collectionData->                                                               meta));  if (-1 == WRITE (fd, dirData, dirLen))    {      GNUNET_GE_LOG_STRERROR (ectx,                              GNUNET_GE_ERROR | GNUNET_GE_ADMIN |                              GNUNET_GE_BULK, "write");      GNUNET_free (tmpName);      GNUNET_free (dirData);      GNUNET_mutex_unlock (lock);      return;    }  GNUNET_free (dirData);  CLOSE (fd);  if (GNUNET_OK != GNUNET_ECRS_file_upload (ectx, cfg, tmpName, GNUNET_NO,      /* indexing */                                            ntohl (collectionData->data.                                                   anonymityLevel),                                            ntohl (collectionData->data.                                                   priority),                                            GNUNET_get_time () +                                            COLLECTION_ADV_LIFETIME, NULL,                                            NULL, NULL, NULL, &directoryURI))    {      UNLINK (tmpName);      GNUNET_free (tmpName);      GNUNET_mutex_unlock (lock);      return;    }  UNLINK (tmpName);  GNUNET_free (tmpName);  if (ntohl (collectionData->data.revision) == 0)    strcpy (this_revision_string, COLLECTION_ROOT);  else    GNUNET_snprintf (this_revision_string,                     sizeof (this_revision_string),                     _("Revision %u"), ntohl (collectionData->data.revision));  GNUNET_snprintf (next_revision_string,                   sizeof (next_revision_string),                   _("Revision %u"),                   ntohl (collectionData->data.revision) + 1);  uri = GNUNET_ECRS_namespace_add_content (ectx,                                           cfg,                                           &collectionData->data.pid,                                           ntohl (collectionData->data.                                                  anonymityLevel),                                           ntohl (collectionData->data.                                                  priority),                                           GNUNET_get_time () +                                           COLLECTION_ADV_LIFETIME,                                           this_revision_string,                                           next_revision_string, directoryURI,                                           collectionData->meta);  if (uri != NULL)    {      collectionData->data.revision =        htonl (ntohl (collectionData->data.revision) + 1);      collectionData->data.changed = htonl (GNUNET_NO);      GNUNET_ECRS_uri_destroy (uri);    }  GNUNET_mutex_unlock (lock);}/** * If we are currently building a collection, publish * the given file information in that collection. * If we are currently not collecting, this function * does nothing. */voidGNUNET_CO_collection_add_item (const GNUNET_ECRS_FileInfo * fi){  unsigned int i;  GNUNET_ECRS_FileInfo fc;  if ((GNUNET_ECRS_uri_test_ksk (fi->uri)))    {      GNUNET_GE_BREAK (ectx, 0);      return;    }  if (lock == NULL)    {      GNUNET_GE_BREAK (ectx, 0);      return;    }  GNUNET_mutex_lock (lock);  if (collectionData == NULL)    {      GNUNET_mutex_unlock (lock);      return;    }  for (i = 0; i < collectionData->file_count; i++)    {      if (GNUNET_ECRS_uri_test_equal (fi->uri, collectionData->files[i].uri))        {          GNUNET_mutex_unlock (lock);          return;        }    }  fc.uri = GNUNET_ECRS_uri_duplicate (fi->uri);  fc.meta = GNUNET_meta_data_duplicate (fi->meta);  GNUNET_array_append (collectionData->files, collectionData->file_count, fc);  collectionData->data.changed = htonl (GNUNET_YES);  GNUNET_mutex_unlock (lock);}/* end of collection.c */

⌨️ 快捷键说明

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