gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r3229 - in GNUnet: . src/applications/fs/collection src/app


From: grothoff
Subject: [GNUnet-SVN] r3229 - in GNUnet: . src/applications/fs/collection src/applications/fs/fsui src/include src/server
Date: Sun, 13 Aug 2006 22:39:07 -0700 (PDT)

Author: grothoff
Date: 2006-08-13 22:39:00 -0700 (Sun, 13 Aug 2006)
New Revision: 3229

Modified:
   GNUnet/src/applications/fs/collection/collection.c
   GNUnet/src/applications/fs/fsui/Makefile.am
   GNUnet/src/applications/fs/fsui/fsui-loader.c
   GNUnet/src/applications/fs/fsui/fsui.h
   GNUnet/src/applications/fs/fsui/upload.c
   GNUnet/src/include/gnunet_collection_lib.h
   GNUnet/src/include/gnunet_fsui_lib.h
   GNUnet/src/server/gnunet-transport-check.c
   GNUnet/todo
Log:
collection compiles

Modified: GNUnet/src/applications/fs/collection/collection.c
===================================================================
--- GNUnet/src/applications/fs/collection/collection.c  2006-08-14 04:20:33 UTC 
(rev 3228)
+++ GNUnet/src/applications/fs/collection/collection.c  2006-08-14 05:39:00 UTC 
(rev 3229)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2004, 2005 Christian Grothoff (and other contributing authors)
+     (C) 2004, 2005, 2006 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
@@ -36,8 +36,9 @@
  */
 
 #include "platform.h"
-#include "gnunet_fsui_lib.h"
-#include "fsui.h"
+#include "gnunet_blockstore.h"
+#include "gnunet_collection_lib.h"
+#include "gnunet_util_crypto.h"
 
 /**
  * Entry in the state-DB that caches the current
@@ -50,8 +51,6 @@
  */
 #define COLLECTION_ADV_LIFETIME (12 * cronMONTHS)
 
-#define DEFAULT_ADVERTISEMENT_PRIORITY 128
-
 /**
  * @brief information about a collection
  */
@@ -89,6 +88,7 @@
      serialized ECRS directory */
 } CollectionData;
 
+static CollectionData * collectionData;
 
 /**
  * Start collection.
@@ -96,35 +96,35 @@
  * @param updateInterval of ECRS_SBLOCK_UPDATE_NONE
  *        means to update _immediately_ on any change,
  *        wherease ECRS_SBLOCK_UPDATE_SPORADIC means
- *        to publish updates when the FSUI_Context
+ *        to publish updates when the CO_Context
  *        is destroyed (i.e. on exit from the UI).
  */
-int FSUI_startCollection(struct FSUI_Context * ctx,
-                        unsigned int anonymityLevel,
-                        TIME_T updateInterval,
-                        const char * name,
-                        const struct ECRS_MetaData * meta) {
+int CO_startCollection(struct GE_Context * ectx,
+                      struct GC_Configuration * cfg,
+                      unsigned int anonymityLevel,
+                      unsigned int prio,
+                      TIME_T updateInterval,
+                      const char * name,
+                      const struct ECRS_MetaData * meta) {
   struct ECRS_URI * advertisement;
   struct ECRS_URI * rootURI;
   HashCode512 nextId;
   TIME_T now;
-  unsigned int prio;
   CollectionData * cd;
   unsigned long long dirLen;
   char * dirData;
   struct ECRS_MetaData * dirMeta;
 
-  FSUI_stopCollection(ctx); /* cancel old collection */
+  CO_stopCollection(ectx, cfg); /* cancel old collection */
   GE_ASSERT(ectx, name != NULL);
-  advertisement = FSUI_parseCharKeywordURI(COLLECTION);
+  advertisement = ECRS_parseCharKeywordURI(ectx,
+                                          COLLECTION);
   GE_ASSERT(ectx, advertisement != NULL);
   TIME(&now);
-  prio = getConfigurationInt("FS",
-                            "ADVERTISEMENT-PRIORITY");
-  if (prio == 0)
-    prio = DEFAULT_ADVERTISEMENT_PRIORITY;
   makeRandomId(&nextId);
-  rootURI = ECRS_createNamespace(name,
+  rootURI = ECRS_createNamespace(ectx,
+                                cfg,
+                                name,
                                 meta,
                                 anonymityLevel,
                                 prio,
@@ -138,14 +138,15 @@
   ECRS_freeUri(advertisement);
   ECRS_freeUri(rootURI);
   dirMeta = ECRS_dupMetaData(meta);
-  GE_ASSERT(ectx, OK == ECRS_createDirectory(&dirData,
-                                          &dirLen,
-                                          0,
-                                          NULL,
-                                          dirMeta));
+  GE_ASSERT(ectx, OK == ECRS_createDirectory(ectx,
+                                            &dirData,
+                                            &dirLen,
+                                            0,
+                                            NULL,
+                                            dirMeta));
   ECRS_freeMetaData(dirMeta);
   cd = MALLOC(sizeof(CollectionData) + strlen(name) + dirLen);
-  ctx->collectionData = &cd->hdr;
+  collectionData = cd;
   cd->hdr.size = ntohl(sizeof(CollectionData) + strlen(name));
   makeRandomId(&cd->lastId);
   cd->nextId = nextId;
@@ -165,15 +166,15 @@
  *
  * @return OK on success, SYSERR if no collection is active
  */
-int FSUI_stopCollection(struct FSUI_Context * ctx) {
-  CollectionData * cd;
-
-  if (ctx->collectionData == NULL)
+int CO_stopCollection(struct GE_Context * ectx,
+                     struct GC_Configuration * cfg) {
+  if (collectionData == NULL)
     return SYSERR;
-  cd = (CollectionData*) ctx->collectionData;
-  ECRS_deleteNamespace(cd->name);
-  FREE(cd);
-  ctx->collectionData = NULL;
+  ECRS_deleteNamespace(ectx,
+                      cfg,
+                      collectionData->name);
+  FREE(collectionData);
+  collectionData = NULL;
   return OK;
 }
 
@@ -182,13 +183,11 @@
  *
  * @return NULL if there is no collection, otherwise its name
  */
-const char * FSUI_getCollection(struct FSUI_Context * ctx) {
-  CollectionData * cd;
-
-  cd = (CollectionData*) ctx->collectionData;
-  if (cd == NULL)
+const char * CO_getCollection(struct GE_Context * ectx,
+                             struct GC_Configuration * cfg) {
+  if (collectionData == NULL)
     return NULL;
-  return &cd->name[0];
+  return &collectionData->name[0];
 }
 
 /**
@@ -198,7 +197,7 @@
  * collecting, this function does nothing.
  *
  * Note that clients typically don't have to call this
- * function explicitly.  FSUI will call the function on
+ * function explicitly.  CO will call the function on
  * exit (for sporadically updated collections), on any
  * change to the collection (for immediately updated
  * content) or when the publication time has arrived
@@ -208,8 +207,9 @@
  * explicit publication of an update at another
  * time is desired.
  */
-void FSUI_publishCollectionNow(struct FSUI_Context * ctx) {
-  CollectionData * cd;
+void CO_publishCollectionNow(struct GE_Context * ectx,
+                            struct GC_Configuration * cfg,
+                            unsigned int prio) {
   TIME_T now;
   struct ECRS_URI * uri;
   struct ECRS_URI * directoryURI;
@@ -218,51 +218,55 @@
   char * tmpName;
   int fd;
 
-  if (ctx->collectionData == NULL)
+  if (collectionData == NULL)
     return;
-  cd = (CollectionData*) ctx->collectionData;
-  if (ntohl(cd->changed) == NO)
+  if (ntohl(collectionData->changed) == NO)
     return;
 
   TIME(&now);
-  if ( (ntohl(cd->updateInterval) != ECRS_SBLOCK_UPDATE_NONE) &&
-       (ntohl(cd->updateInterval) != ECRS_SBLOCK_UPDATE_SPORADIC) &&
-       (ntohl(cd->lastPublication) + ntohl(cd->updateInterval) < now) )
+  if ( (ntohl(collectionData->updateInterval) != ECRS_SBLOCK_UPDATE_NONE) &&
+       (ntohl(collectionData->updateInterval) != ECRS_SBLOCK_UPDATE_SPORADIC) 
&&
+       (ntohl(collectionData->lastPublication) + 
ntohl(collectionData->updateInterval) < now) )
     return;
-  if ( (ntohl(cd->updateInterval) != ECRS_SBLOCK_UPDATE_NONE) &&
-       (ntohl(cd->updateInterval) != ECRS_SBLOCK_UPDATE_SPORADIC) ) {
+  if ( (ntohl(collectionData->updateInterval) != ECRS_SBLOCK_UPDATE_NONE) &&
+       (ntohl(collectionData->updateInterval) != ECRS_SBLOCK_UPDATE_SPORADIC) 
) {
     HashCode512 delta;
 
-    deltaId(&cd->nextId,
-           &cd->lastId,
+    deltaId(&collectionData->nextId,
+           &collectionData->lastId,
            &delta);
-    cd->lastId = cd->nextId;
-    addHashCodes(&cd->nextId,
+    collectionData->lastId = collectionData->nextId;
+    addHashCodes(&collectionData->nextId,
                 &delta,
-                &cd->nextId);
+                &collectionData->nextId);
   } else {
-    cd->lastId = cd->nextId;
-    makeRandomId(&cd->nextId);
+    collectionData->lastId = collectionData->nextId;
+    makeRandomId(&collectionData->nextId);
   }
   tmpName = STRDUP("/tmp/gnunet-collectionXXXXXX");
   fd = mkstemp(tmpName);
   if (fd == -1) {
-    LOG_STRERROR(LOG_ERROR, "mkstemp");
+    GE_LOG_STRERROR(ectx,
+                   GE_ERROR | GE_ADMIN | GE_BULK, 
+                   "mkstemp");
     FREE(tmpName);
     return;
   }
-  dirLen = ntohl(cd->hdr.size) - sizeof(CollectionData) - strlen(cd->name);
-  if (-1 == WRITE(fd, &cd->name[strlen(cd->name)+1], dirLen)) {
-    LOG_STRERROR(LOG_ERROR, "write");
+  dirLen = ntohl(collectionData->hdr.size) - sizeof(CollectionData) - 
strlen(collectionData->name);
+  if (-1 == WRITE(fd, &collectionData->name[strlen(collectionData->name)+1], 
dirLen)) {
+    GE_LOG_STRERROR(ectx,
+                   GE_ERROR | GE_ADMIN | GE_BULK,
+                   "write");
     FREE(tmpName);
     return;
   }
-  closefile(fd);
-  if (OK != ECRS_uploadFile(tmpName,
+  CLOSE(fd);
+  if (OK != ECRS_uploadFile(ectx,
+                           cfg,
+                           tmpName,
                            NO, /* indexing */
-                           ntohl(cd->anonymityLevel),
-                           getConfigurationInt("FS",
-                                               "ADVERTISEMENT-PRIORITY"),
+                           ntohl(collectionData->anonymityLevel),
+                           prio,
                            now + COLLECTION_ADV_LIFETIME,
                            NULL,
                            NULL,
@@ -276,25 +280,27 @@
   UNLINK(tmpName);
   FREE(tmpName);
   metaData = NULL;
-  GE_ASSERT(ectx, OK == ECRS_listDirectory(&cd->name[strlen(cd->name)+1],
-                                        dirLen,
-                                        &metaData,
-                                        NULL,
-                                        NULL));
-  uri = ECRS_addToNamespace(cd->name,
-                           ntohl(cd->anonymityLevel),
-                           getConfigurationInt("FS",
-                                               "ADVERTISEMENT-PRIORITY"),
+  GE_ASSERT(ectx, OK == ECRS_listDirectory(ectx,
+                                          
&collectionData->name[strlen(collectionData->name)+1],
+                                          dirLen,
+                                          &metaData,
+                                          NULL,
+                                          NULL));
+  uri = ECRS_addToNamespace(ectx,
+                           cfg,
+                           collectionData->name,
+                           ntohl(collectionData->anonymityLevel),
+                           prio,
                            now + COLLECTION_ADV_LIFETIME,
                            now,
-                           ntohl(cd->updateInterval),
-                           &cd->lastId,
-                           &cd->nextId,
+                           ntohl(collectionData->updateInterval),
+                           &collectionData->lastId,
+                           &collectionData->nextId,
                            directoryURI,
                            metaData);
   if (uri != NULL) {
-    cd->lastPublication = htonl(now);
-    cd->changed = htonl(NO);
+    collectionData->lastPublication = htonl(now);
+    collectionData->changed = htonl(NO);
     ECRS_freeUri(uri);
   }
   ECRS_freeMetaData(metaData);
@@ -325,33 +331,35 @@
  * does nothing.
  *
  * Note that clients typically don't have to call this
- * function explicitly -- by using the FSUI library it
- * should be called automatically by FSUI code whenever
+ * function explicitly -- by using the CO library it
+ * should be called automatically by CO code whenever
  * needed.  However, the function maybe useful if you're
  * inserting files using libECRS directly or need other
  * ways to explicitly extend a collection.
  */
-void FSUI_publishToCollection(struct FSUI_Context * ctx,
-                             const ECRS_FileInfo * fi) {
-  CollectionData * cd;
+void CO_publishToCollection(struct GE_Context * ectx,
+                           struct GC_Configuration * cfg,
+                           const ECRS_FileInfo * fi,
+                           unsigned int prio) {
+  CollectionData * collectionData;
   unsigned long long dirLen;
   char * dirData;
   struct ECRS_MetaData * metaData;
   struct CCcls cls;
   int i;
 
-  if (ctx->collectionData == NULL)
+  if (collectionData == NULL)
     return;
   if ((ECRS_isKeywordUri(fi->uri))) {
     GE_BREAK(ectx, 0);
     return;
   }
-  cd = (CollectionData*) ctx->collectionData;
-  dirLen = ntohl(cd->hdr.size) - strlen(cd->name) - sizeof(CollectionData);
+  dirLen = ntohl(collectionData->hdr.size) - strlen(collectionData->name) - 
sizeof(CollectionData);
   cls.count = 0;
   cls.fis = NULL;
   GE_ASSERT(ectx, OK ==
-               ECRS_listDirectory(&cd->name[strlen(cd->name)+1],
+           ECRS_listDirectory(ectx,
+                              
&collectionData->name[strlen(collectionData->name)+1],
                                   dirLen,
                                   &metaData,
                                   &collectCallback,
@@ -362,11 +370,12 @@
                  &cls);
   dirData = NULL;
   GE_ASSERT(ectx, OK ==
-               ECRS_createDirectory(&dirData,
-                                    &dirLen,
-                                    cls.count,
-                                    cls.fis,
-                                    metaData));
+           ECRS_createDirectory(ectx,
+                                &dirData,
+                                &dirLen,
+                                cls.count,
+                                cls.fis,
+                                metaData));
   ECRS_freeMetaData(metaData);
   for (i=0;i<cls.count;i++) {
     ECRS_freeUri(cls.fis[i].uri);
@@ -375,15 +384,15 @@
   GROW(cls.fis,
        cls.count,
        0);
-  REALLOC(cd,
-         sizeof(CollectionData) + strlen(cd->name) + dirLen);
-  memcpy(&cd->name[strlen(cd->name)+1],
+  REALLOC(collectionData,
+         sizeof(CollectionData) + strlen(collectionData->name) + dirLen);
+  memcpy(&collectionData->name[strlen(collectionData->name)+1],
         dirData,
         dirLen);
   FREE(dirData);
-  cd->changed = htonl(YES);
-  if (ntohll(cd->updateInterval) == ECRS_SBLOCK_UPDATE_NONE)
-    FSUI_publishCollectionNow(ctx);
+  collectionData->changed = htonl(YES);
+  if (ntohll(collectionData->updateInterval) == ECRS_SBLOCK_UPDATE_NONE)
+    CO_publishCollectionNow(ectx, cfg, prio);
 }
 
 

Modified: GNUnet/src/applications/fs/fsui/Makefile.am
===================================================================
--- GNUnet/src/applications/fs/fsui/Makefile.am 2006-08-14 04:20:33 UTC (rev 
3228)
+++ GNUnet/src/applications/fs/fsui/Makefile.am 2006-08-14 05:39:00 UTC (rev 
3229)
@@ -14,6 +14,9 @@
 libgnunetfsui_la_LIBADD = \
  -lextractor \
  $(top_builddir)/src/applications/fs/ecrs/libgnunetecrs.la \
+ $(top_builddir)/src/applications/fs/namespace/libgnunetnamespace.la \
+ $(top_builddir)/src/applications/fs/uritrack/libgnuneturitrack.la \
+ $(top_builddir)/src/util/cron/libgnunetutil_cron.la \
  $(top_builddir)/src/util/libgnunetutil.la 
 
 EXTRA_DIST = \
@@ -24,6 +27,8 @@
 fsui_loader_LDADD = \
  $(top_builddir)/src/applications/fs/fsui/libgnunetfsui.la \
  $(top_builddir)/src/applications/fs/ecrs/libgnunetecrs.la \
+ $(top_builddir)/src/util/config_impl/libgnunetutil_config.la \
+ $(top_builddir)/src/util/loggers/libgnunetutil_logging.la  \
  $(top_builddir)/src/util/libgnunetutil.la 
 
 check_PROGRAMS = \

Modified: GNUnet/src/applications/fs/fsui/fsui-loader.c
===================================================================
--- GNUnet/src/applications/fs/fsui/fsui-loader.c       2006-08-14 04:20:33 UTC 
(rev 3228)
+++ GNUnet/src/applications/fs/fsui/fsui-loader.c       2006-08-14 05:39:00 UTC 
(rev 3229)
@@ -26,6 +26,8 @@
 
 #include "platform.h"
 #include "gnunet_fsui_lib.h"
+#include "gnunet_util_config_impl.h"
+#include "gnunet_util_error_loggers.h"
 
 static void eventCallback(void * cls,
                          const FSUI_Event * event) {
@@ -49,40 +51,36 @@
   }
 #endif
 }
-static int parseOptions(int argc,
-                       char ** argv) {
-  FREENONNULL(setConfigurationString("GNUNET",
-                                    "LOGLEVEL",
-                                    "WARNING"));
-  return 0;
-}
 
 int main(int argc,
         char * argv[]) {
   struct FSUI_Context * ctx;
+  struct GC_Configuration * cfg;
+  struct GE_Context * ectx;
+
+  ectx = GE_create_context_stderr(NO, 
+                                 GE_WARNING | GE_ERROR | GE_FATAL |
+                                 GE_USER | GE_ADMIN | GE_DEVELOPER |
+                                 GE_IMMEDIATE | GE_BULK);
+  GE_setDefaultContext(ectx);
+  cfg = GC_create_C_impl();
+  GE_ASSERT(ectx, cfg != NULL);
   if (argc != 2) {
     fprintf(stderr,
            "Call with name of FSUI resource file!\n");
     return -1;
   }
-  if(OK != initUtil(argc,
-                   argv,
-                   &parseOptions)) {
-    fprintf(stderr,
-           "initUtil failed!\n");
-    return -1;
-  }
-  startCron();
-  ctx = FSUI_start(argv[1],
+  ctx = FSUI_start(ectx,
+                  cfg,
+                  argv[1],
+                  16,
                   YES,
                   &eventCallback,
                   NULL);
-  if (ctx != NULL) {
+  if (ctx != NULL) 
     FSUI_stop(ctx);
-  } else
+  else 
     fprintf(stderr,
-           "FSUI_start failed!\n");
-  stopCron();
-  doneUtil();
+           "FSUI_start failed!\n");  
   return (ctx == NULL);
 }

Modified: GNUnet/src/applications/fs/fsui/fsui.h
===================================================================
--- GNUnet/src/applications/fs/fsui/fsui.h      2006-08-14 04:20:33 UTC (rev 
3228)
+++ GNUnet/src/applications/fs/fsui/fsui.h      2006-08-14 05:39:00 UTC (rev 
3229)
@@ -329,8 +329,61 @@
 
 } FSUI_UnindexList;
 
+/**
+ * Data used to keep track of the files in the
+ * current directory.
+ */
+typedef struct {
+  unsigned int fiCount;
+  ECRS_FileInfo * fis;
+} DirTrack;
 
+/**
+ * Context for the upload thread.
+ */
+typedef struct FSUI_UploadList {
+  struct FSUI_UploadList * next;
 
+  struct PTHREAD * handle;
+
+  void * cctx;
+
+  int isRecursive;
+
+  int doIndex;
+
+  unsigned int anonymityLevel;
+
+  unsigned int priority;
+
+  cron_t expiration;
+
+  struct ECRS_MetaData * meta;
+
+  struct ECRS_URI * uri;
+
+  struct ECRS_URI * globalUri;
+
+  char * filename;
+
+  char * main_filename;
+
+  unsigned long long main_completed;
+
+  unsigned long long main_total;
+
+  EXTRACTOR_ExtractorList * extractors;
+
+  struct FSUI_Context * ctx;
+
+  cron_t start_time;
+
+  DirTrack * dir;
+
+  int individualKeywords;
+
+} FSUI_UploadList;
+
 /**
  * @brief global state of the FSUI library
  */
@@ -396,6 +449,8 @@
    */
   FSUI_DownloadList activeDownloads;
 
+  FSUI_UploadList * activeUploads;
+
   /**
    * Target size of the thread pool for parallel
    * downloads.

Modified: GNUnet/src/applications/fs/fsui/upload.c
===================================================================
--- GNUnet/src/applications/fs/fsui/upload.c    2006-08-14 04:20:33 UTC (rev 
3228)
+++ GNUnet/src/applications/fs/fsui/upload.c    2006-08-14 05:39:00 UTC (rev 
3229)
@@ -27,6 +27,7 @@
 
 #include "platform.h"
 #include "gnunet_ecrs_lib.h"
+#include "gnunet_uritrack_lib.h"
 #include "gnunet_fsui_lib.h"
 #include "fsui.h"
 #include <extractor.h>
@@ -42,46 +43,13 @@
 #endif
 
 /**
- * Data used to keep track of the files in the
- * current directory.
- */
-typedef struct {
-  unsigned int fiCount;
-  ECRS_FileInfo * fis;
-} DirTrack;
-
-/**
- * Context for the upload thread.
- */
-typedef struct {
-  int isRecursive;
-  int doIndex;
-  unsigned int anonymityLevel;
-  unsigned int priority;
-  cron_t expiration;
-  struct ECRS_MetaData * meta;
-  struct ECRS_URI * uri;
-  struct ECRS_URI * globalUri;
-  char * filename;
-  char * main_filename;
-  unsigned long long main_completed;
-  unsigned long long main_total;
-  EXTRACTOR_ExtractorList * extractors;
-  FSUI_ThreadList * tl;
-  FSUI_Context * ctx;
-  cron_t start_time;
-  DirTrack * dir;
-  int individualKeywords;
-} UploadThreadClosure;
-
-/**
  * Transform an ECRS progress callback into an FSUI event.
  */
 static void progressCallback(unsigned long long totalBytes,
                             unsigned long long completedBytes,
                             cron_t eta,
                             void * ptr) {
-  UploadThreadClosure * utc = ptr;
+  FSUI_UploadList * utc = ptr;
   FSUI_Event event;
   cron_t now;
 
@@ -90,23 +58,7 @@
   event.data.UploadProgress.completed = completedBytes;
   event.data.UploadProgress.total = totalBytes;
   event.data.UploadProgress.filename = utc->filename;
-  event.data.UploadProgress.is_recursive = utc->isRecursive;
-  event.data.UploadProgress.main_filename = utc->main_filename;
-  event.data.UploadProgress.start_time = utc->start_time;
-  event.data.UploadProgress.main_completed = utc->main_completed + 
completedBytes;
-  event.data.UploadProgress.main_total = utc->main_total;
   event.data.UploadProgress.eta = eta;
-  if (totalBytes > 0) {
-    event.data.UploadProgress.main_eta
-      = (cron_t) (utc->start_time +
-                 (((double)( (now -
-                              utc->start_time) /
-                            (double)(utc->main_completed
-                                     + completedBytes))))
-                  * (double) utc->main_total);
-  } else {
-    event.data.UploadProgress.main_eta = eta; /* huh? */
-  }
   utc->ctx->ecb(utc->ctx->ecbClosure,
                &event);
 }
@@ -115,7 +67,7 @@
  * Take the current directory entries from utc, create
  * a directory, upload it and store the uri in  *uri.
  */
-static int uploadDirectory(UploadThreadClosure * utc,
+static int uploadDirectory(FSUI_UploadList * utc,
                           const char * dirName,
                           const DirTrack * backup,
                           struct ECRS_URI ** uri,
@@ -128,7 +80,9 @@
   FSUI_Event event;
   int handle;
   char * mdn;
+  struct GE_Context * ectx;
 
+  ectx = utc->ctx->ectx;
   GE_ASSERT(ectx, utc->filename != NULL);
 
   ret = SYSERR;
@@ -155,7 +109,8 @@
                     EXTRACTOR_MIMETYPE,
                     GNUNET_DIRECTORY_MIME);
   data = NULL;
-  if (OK == ECRS_createDirectory(&data,
+  if (OK == ECRS_createDirectory(ectx,
+                                &data,
                                 &len,
                                 backup->fiCount,
                                 backup->fis,
@@ -177,9 +132,11 @@
                           tempName,
                           "write");
     } else {
-      closefile(handle);
+      CLOSE(handle);
       utc->filename = tempName;
-      ret = ECRS_uploadFile(tempName,
+      ret = ECRS_uploadFile(ectx,
+                           utc->ctx->cfg,
+                           tempName,
                            NO,
                            utc->anonymityLevel,
                            utc->priority,
@@ -193,17 +150,8 @@
        GE_ASSERT(ectx, NULL != *uri);
        event.type = FSUI_upload_complete;
        event.data.UploadComplete.total = utc->main_total;
-       event.data.UploadComplete.completed = utc->main_completed;
        event.data.UploadComplete.filename = STRDUP(dirName);
        event.data.UploadComplete.uri = *uri;
-       event.data.UploadComplete.eta
-         = (cron_t) (utc->start_time +
-                     (((double)(get_time()
-                                - 
utc->start_time/(double)(utc->main_completed+len))))
-                     * (double)utc->main_total);
-       event.data.UploadComplete.start_time = utc->start_time;
-       event.data.UploadComplete.is_recursive = YES;
-       event.data.UploadComplete.main_filename = utc->main_filename;
        utc->ctx->ecb(utc->ctx->ecbClosure,
                      &event);  
        FREE(event.data.UploadComplete.filename);
@@ -228,7 +176,7 @@
 static int dirEntryCallback(const char * filename,
                            const char * dirName,
                            void * ptr) {
-  UploadThreadClosure * utc = ptr;
+  FSUI_UploadList * utc = ptr;
   char * fn;
   struct ECRS_URI * uri;
   struct ECRS_URI * keywordUri;
@@ -236,15 +184,19 @@
   FSUI_Event event;
   int ret;
   unsigned long long len;
+  struct GE_Context * ectx;
 
+  ectx = utc->ctx->ectx;
   fn = MALLOC(strlen(filename) + strlen(dirName) + 2);
   strcpy(fn, dirName);
   strcat(fn, "/");
   strcat(fn, filename);
   utc->filename = fn;
 
-  if (NO == isDirectory(fn)) {
-    ret = ECRS_uploadFile(fn,
+  if (NO == disk_directory_test(ectx, fn)) {
+    ret = ECRS_uploadFile(ectx,
+                         utc->ctx->cfg,
+                         fn,
                          utc->doIndex,
                          utc->anonymityLevel,
                          utc->priority,
@@ -258,28 +210,23 @@
       GE_ASSERT(ectx, uri != NULL);
       event.type = FSUI_upload_complete;
       event.data.UploadComplete.total = utc->main_total;
-      event.data.UploadComplete.completed = utc->main_completed;
       event.data.UploadComplete.filename = utc->filename;
       event.data.UploadComplete.uri = uri;
-      if (OK == getFileSize(fn, &len))
+      if (OK == disk_file_size(ectx, 
+                              fn, 
+                              &len,
+                              YES))
        utc->main_completed += len;
-      event.data.UploadComplete.eta
-       = (cron_t) (utc->start_time +
-                   (((double)(get_time()
-                              - 
utc->start_time/(double)(utc->main_completed))))
-                   * (double)utc->main_total);
-      event.data.UploadComplete.start_time = utc->start_time;
-      event.data.UploadComplete.is_recursive = YES;
-      event.data.UploadComplete.main_filename = utc->main_filename;
       utc->ctx->ecb(utc->ctx->ecbClosure,
                    &event);    
       meta = ECRS_createMetaData();
-      ECRS_extractMetaData(meta,
+      ECRS_extractMetaData(ectx,
+                          meta,
                           fn,
                           utc->extractors);
     } else {
       event.type = FSUI_upload_error;
-      event.data.message = _("Upload failed.");
+      event.data.UploadError.message = _("Upload failed.");
       utc->ctx->ecb(utc->ctx->ecbClosure,
                    &event);    
       meta = NULL;
@@ -292,9 +239,10 @@
     memset(&current, 0, sizeof(DirTrack));
     prev = utc->dir;
     utc->dir = &current;
-    scanDirectory(fn,
-                 &dirEntryCallback,
-                 utc);
+    disk_directory_scan(ectx,
+                       fn,
+                       &dirEntryCallback,
+                       utc);
     meta = NULL;
     utc->dir = prev;
     ret = uploadDirectory(utc,
@@ -314,7 +262,8 @@
   if (ret == OK) {
     char * mfilename = MALLOC(strlen(filename) + 2);
     strcpy(mfilename, filename);
-    if (YES == isDirectory(fn))
+    if (YES == disk_directory_test(ectx,
+                                  fn))
       strcat(mfilename, "/");    
     ECRS_addToMetaData(meta,
                       EXTRACTOR_FILENAME,
@@ -323,7 +272,9 @@
     if (utc->individualKeywords) {
       keywordUri = ECRS_metaDataToUri(meta);
       if (keywordUri != NULL) {
-       ECRS_addToKeyspace(keywordUri,
+       ECRS_addToKeyspace(ectx,
+                          utc->ctx->cfg,
+                          keywordUri,
                           utc->anonymityLevel,
                           utc->priority,
                           utc->expiration,
@@ -333,7 +284,9 @@
       }
     }
     if (utc->globalUri != NULL)
-      ECRS_addToKeyspace(utc->globalUri,
+      ECRS_addToKeyspace(ectx,
+                        utc->ctx->cfg,
+                        utc->globalUri,
                         utc->anonymityLevel,
                         utc->priority,
                         utc->expiration,
@@ -356,7 +309,9 @@
       ECRS_freeMetaData(meta);
       ECRS_freeUri(uri);
     }
-    FSUI_trackURI(&utc->dir->fis[utc->dir->fiCount-1]);
+    URITRACK_trackURI(ectx,
+                     utc->ctx->cfg,
+                     &utc->dir->fis[utc->dir->fiCount-1]);
   }
   FREE(fn);
   return OK;
@@ -366,7 +321,7 @@
  * Thread that does the upload.
  */
 static void * uploadThread(void * cls) {
-  UploadThreadClosure * utc = cls;
+  FSUI_UploadList * utc = cls;
   struct ECRS_URI * uri;
   struct ECRS_URI * keywordUri;
   FSUI_Event event;
@@ -374,15 +329,19 @@
   int ret;
   char * inboundFN;
   int sendEvent = YES;
+  struct GE_Context * ectx;
 
+  ectx = utc->ctx->ectx;
   GE_ASSERT(ectx, utc->main_filename != NULL);
   inboundFN
     = ECRS_getFromMetaData(utc->meta,
                           EXTRACTOR_FILENAME);
-  cronTime(&utc->start_time);
+  utc->start_time = get_time();
 
-  if (OK != getFileSize(utc->main_filename,
-                       &utc->main_total)) {
+  if (OK != disk_file_size(ectx,
+                          utc->main_filename,
+                          &utc->main_total,
+                          YES)) {
     utc->main_total = 0;
     /* or signal error?? */
   }
@@ -390,9 +349,12 @@
   ret = SYSERR;
   uri = NULL;
 
-  if (NO == isDirectory(utc->main_filename)) {
+  if (NO == disk_directory_test(ectx,
+                               utc->main_filename)) {
     utc->filename = utc->main_filename;
-    ret = ECRS_uploadFile(utc->main_filename,
+    ret = ECRS_uploadFile(ectx,
+                         utc->ctx->cfg,
+                         utc->main_filename,
                          utc->doIndex,
                          utc->anonymityLevel,
                          utc->priority,
@@ -405,16 +367,11 @@
     if (ret == OK) {
       event.type = FSUI_upload_complete;
       event.data.UploadComplete.total = utc->main_total;
-      event.data.UploadComplete.completed = utc->main_completed;
       event.data.UploadComplete.filename = utc->filename;
       event.data.UploadComplete.uri = uri;
-      event.data.UploadComplete.eta = get_time();
-      event.data.UploadComplete.start_time = utc->start_time;
-      event.data.UploadComplete.is_recursive = NO;
-      event.data.UploadComplete.main_filename = utc->main_filename;
     } else {
       event.type = FSUI_upload_error;
-      event.data.message = _("Upload failed.");
+      event.data.UploadError.message = _("Upload failed.");
     }
     if (utc->meta == NULL)
       utc->meta = ECRS_createMetaData();
@@ -422,7 +379,8 @@
       ECRS_delFromMetaData(utc->meta,
                           EXTRACTOR_FILENAME,
                           NULL);
-    ECRS_extractMetaData(utc->meta,
+    ECRS_extractMetaData(ectx,
+                        utc->meta,
                         utc->filename,
                         utc->extractors);
     utc->filename = NULL;
@@ -433,9 +391,10 @@
     memset(&current, 0, sizeof(DirTrack));
     utc->dir = &current;
     utc->filename = utc->main_filename;
-    scanDirectory(utc->main_filename,
-                 &dirEntryCallback,
-                 utc);
+    disk_directory_scan(ectx,
+                       utc->main_filename,
+                       &dirEntryCallback,
+                       utc);
     ret = uploadDirectory(utc,
                          utc->main_filename,
                          &current,
@@ -451,19 +410,21 @@
 
     if (ret != OK) {
       event.type = FSUI_upload_error;
-      event.data.message = _("Upload failed.");
+      event.data.UploadError.message = _("Upload failed.");
     } else { /* for success, uploadDirectory sends event already! */
       sendEvent = NO;
     }
     utc->filename = NULL;
   } else {
     event.type = FSUI_upload_error;
-    event.data.message = _("Cannot upload directory without using recursion.");
+    event.data.UploadError.message = _("Cannot upload directory without using 
recursion.");
   }
   if (ret == OK) { /* publish top-level advertisements */
     fi.meta = utc->meta;
     fi.uri = uri;
-    FSUI_trackURI(&fi);
+    URITRACK_trackURI(ectx,
+                     utc->ctx->cfg,
+                     &fi);
     if (inboundFN != NULL) {
       ECRS_delFromMetaData(utc->meta,
                           EXTRACTOR_FILENAME,
@@ -478,7 +439,9 @@
 #endif
     keywordUri = ECRS_metaDataToUri(utc->meta);
     if (keywordUri != NULL) {
-      ECRS_addToKeyspace(keywordUri,
+      ECRS_addToKeyspace(ectx,
+                        utc->ctx->cfg,
+                        keywordUri,
                         utc->anonymityLevel,
                         utc->priority,
                         utc->expiration,
@@ -487,14 +450,18 @@
       ECRS_freeUri(keywordUri);
     }
     if (utc->globalUri != NULL)
-      ECRS_addToKeyspace(utc->globalUri,
+      ECRS_addToKeyspace(ectx,
+                        utc->ctx->cfg,
+                        utc->globalUri,
                         utc->anonymityLevel,
                         utc->priority,
                         utc->expiration,
                         uri,
                         utc->meta);    
     if (utc->uri != NULL)
-      ECRS_addToKeyspace(utc->uri,
+      ECRS_addToKeyspace(ectx,
+                        utc->ctx->cfg,
+                        utc->uri,
                         utc->anonymityLevel,
                         utc->priority,
                         utc->expiration,
@@ -506,8 +473,12 @@
                       EXTRACTOR_SPLIT,
                       NULL);
   fi.meta = utc->meta;
-  FSUI_publishToCollection(utc->ctx,
+  /*
+  CO_publishToCollection(ectx,
+                          utc->ctx->cfg,
+                          utc->ctx,
                           &fi);
+  */
   if (sendEvent)
     utc->ctx->ecb(utc->ctx->ecbClosure,
                  &event);
@@ -523,7 +494,6 @@
     ECRS_freeUri(utc->globalUri);
   EXTRACTOR_removeAll(utc->extractors);
   utc->extractors = NULL;
-  utc->tl->isDone = YES;
   FREE(utc);
   FREENONNULL(inboundFN);
   return NULL;
@@ -539,30 +509,37 @@
  *  SYSERR if the file does not exist or gnunetd is not
  *  running
  */
-int FSUI_upload(struct FSUI_Context * ctx,
-               const char * filename,
-               unsigned int anonymityLevel,
-               int doIndex,
-               int doExtract,
-               const struct ECRS_MetaData * md,
-               const struct ECRS_URI * keyUri) {
-  FSUI_ThreadList * tl;
-  UploadThreadClosure * utc;
+struct FSUI_UploadList *
+FSUI_upload(struct FSUI_Context * ctx,
+           const char * filename,
+           unsigned int anonymityLevel,
+           unsigned int priority,
+           int doIndex,
+           int doExtract,
+           int individualKeywords,
+           const struct ECRS_MetaData * md,
+           const struct ECRS_URI * globalURI,
+           const struct ECRS_URI * keyUri) {
+  FSUI_UploadList * utc;
   char * config;
+  struct GE_Context * ectx;
 
-  utc = MALLOC(sizeof(UploadThreadClosure));
+  ectx = utc->ctx->ectx;
+  utc = MALLOC(sizeof(FSUI_UploadList));
   utc->dir = NULL;
   utc->anonymityLevel = anonymityLevel;
-  utc->priority = getConfigurationInt("FS",
-                                     "INSERT-PRIORITY");
+  utc->priority = priority;
   utc->expiration = get_time() + 120 * cronYEARS;
   utc->ctx = ctx;
   utc->isRecursive = NO;
   if (doExtract) {
     utc->extractors = EXTRACTOR_loadDefaultLibraries();
-    config = getConfigurationString("FS",
-                                   "EXTRACTORS");
-    if (config != NULL) {
+    if ( (0 == GC_get_configuration_value_string(ctx->cfg,
+                                                "FS",
+                                                "EXTRACTORS",
+                                                NULL,
+                                                &config)) &&
+        (config != NULL) ) {
       utc->extractors = EXTRACTOR_loadConfigLibraries(utc->extractors,
                                                      config);
       FREE(config);
@@ -576,103 +553,37 @@
   utc->meta = ECRS_dupMetaData(md);
   utc->doIndex = doIndex;
   utc->individualKeywords = NO;
-  tl = MALLOC(sizeof(FSUI_ThreadList));
-  utc->tl = tl;
-  tl->isDone = NO;
-  tl->handle = PTHREAD_CREATE(&uploadThread,
-                             utc,
-                             128 * 1024);
-  if (tl->handle == NULL) {
+  utc->handle = PTHREAD_CREATE(&uploadThread,
+                              utc,
+                              128 * 1024);
+  if (utc->handle == NULL) {
     GE_LOG_STRERROR(ectx,
                    GE_ERROR | GE_USER | GE_BULK, 
                    "PTHREAD_CREATE");
-    FREE(tl);
     FREE(utc->main_filename);
     ECRS_freeMetaData(utc->meta);
     ECRS_freeUri(utc->uri);
     FREE(utc);
-    return SYSERR;
+    return NULL;
   }
 
-  MUTEX_LOCK(&ctx->lock);
-  tl->next = ctx->activeThreads;
-  ctx->activeThreads = tl;
-  MUTEX_UNLOCK(&ctx->lock);
+  MUTEX_LOCK(ctx->lock);
+  utc->next = ctx->activeUploads;
+  ctx->activeUploads = utc;
+  MUTEX_UNLOCK(ctx->lock);
   cleanupFSUIThreadList(ctx);
-  return OK;
+  return utc;
 }
+
 /**
- * Start uploading a directory.  Note that an upload cannot be stopped
- * once started (not necessary anyway), but it can fail.  All files
- * in the recursive tree will be indexed under all keywords found by
- * the specified extractor plugins AND the globalKeywords.  The
- * main directory will furthermore be published with the given keywords
- * and the specified directoryMetaData.
+ * Abort an upload.  If the context is for a recursive
+ * upload, all sub-uploads will also be aborted.
  *
- * @return OK on success (at least we started with it),
- *  SYSERR if the file does not exist
-*/
-int FSUI_uploadAll(struct FSUI_Context * ctx,
-                  const char * dirname,
-                  unsigned int anonymityLevel,
-                  int doIndex,
-                  int individualKeywords,
-                  const struct ECRS_MetaData * directoryMetaData,
-                  const struct ECRS_URI * globalURI,
-                  const struct ECRS_URI * topURI) {
-  FSUI_ThreadList * tl;
-  UploadThreadClosure * utc;
-  char * config;
-
-  utc = MALLOC(sizeof(UploadThreadClosure));
-  utc->individualKeywords = individualKeywords;
-  utc->ctx = ctx;
-  utc->isRecursive = YES;
-  utc->anonymityLevel = anonymityLevel;
-  utc->priority = getConfigurationInt("FS",
-                                     "INSERT-PRIORITY");
-  utc->expiration = get_time() + 120 * cronYEARS;
-  utc->extractors = EXTRACTOR_loadDefaultLibraries();
-  config = getConfigurationString("FS",
-                                 "EXTRACTORS");
-
-  if (config != NULL) {
-    utc->extractors = EXTRACTOR_loadConfigLibraries(utc->extractors,
-                                                   config);
-    FREE(config);
-  }
-  utc->globalUri = ECRS_dupUri(globalURI);
-  utc->filename = NULL;
-  utc->main_filename = STRDUP(dirname);
-  utc->uri = ECRS_dupUri(topURI);
-  utc->meta = ECRS_dupMetaData(directoryMetaData);
-  utc->doIndex = doIndex;
-  tl = MALLOC(sizeof(FSUI_ThreadList));
-  utc->tl = tl;
-  tl->isDone = NO;
-  tl->handle = PTHREAD_CREATE(&uploadThread,
-                             utc,
-                             128 * 1024);
-  if (tl->handle == NULL) {
-    GE_LOG_STRERROR(ectx,
-                   GE_ERROR | GE_USER | GE_BULK, 
-                   "PTHREAD_CREATE");
-    FREE(tl);
-    FREE(utc->main_filename);
-    ECRS_freeMetaData(utc->meta);
-    ECRS_freeUri(utc->globalUri);
-    ECRS_freeUri(utc->uri);
-    FREE(utc);
-    return SYSERR;
-  }
-
-  MUTEX_LOCK(&ctx->lock);
-  tl->next = ctx->activeThreads;
-  ctx->activeThreads = tl;
-  MUTEX_UNLOCK(&ctx->lock);
-  cleanupFSUIThreadList(ctx);
-  return OK;
+ * @return SYSERR on error
+ */
+int FSUI_stopUpload(struct FSUI_Context * ctx,
+                   struct FSUI_UploadList * ul) {
+  return SYSERR;
 }
 
-
 /* end of upload.c */

Modified: GNUnet/src/include/gnunet_collection_lib.h
===================================================================
--- GNUnet/src/include/gnunet_collection_lib.h  2006-08-14 04:20:33 UTC (rev 
3228)
+++ GNUnet/src/include/gnunet_collection_lib.h  2006-08-14 05:39:00 UTC (rev 
3229)
@@ -39,28 +39,29 @@
 /**
  * Start collection.
  */
-int FSUI_startCollection(struct GE_Context * ectx,
-                        struct GC_Configuration * cfg,
-                        unsigned int anonymityLevel,
-                        TIME_T updateInterval,
-                        const char * name,
-                        const struct ECRS_MetaData * meta); /* collection.c */
+int CO_startCollection(struct GE_Context * ectx,
+                      struct GC_Configuration * cfg,
+                      unsigned int anonymityLevel,
+                      unsigned int priority,
+                      TIME_T updateInterval,
+                      const char * name,
+                      const struct ECRS_MetaData * meta); /* collection.c */
 
 /**
  * Stop collection.
  *
  * @return OK on success, SYSERR if no collection is active
  */
-int FSUI_stopCollection(struct GE_Context * ectx,
-                       struct GC_Configuration * cfg); /* collection.c */
+int CO_stopCollection(struct GE_Context * ectx,
+                     struct GC_Configuration * cfg); /* collection.c */
 
 /**
  * Are we using a collection?
  *
  * @return NULL if there is no collection, otherwise its name
  */
-const char * FSUI_getCollection(struct GE_Context * ectx,
-                               struct GC_Configuration * cfg); /* collection.c 
*/
+const char * CO_getCollection(struct GE_Context * ectx,
+                             struct GC_Configuration * cfg); /* collection.c */
 
 /**
  * Upload an update of the current collection information to the
@@ -69,7 +70,7 @@
  * collecting, this function does nothing.
  *
  * Note that clients typically don't have to call this function
- * explicitly.  FSUI will call the function on exit (for sporadically
+ * explicitly.  CO will call the function on exit (for sporadically
  * updated collections), on any change to the collection (for
  * immediately updated content) or when the publication time has
  * arrived (for periodically updated collections).
@@ -77,8 +78,9 @@
  * However, clients may want to call this function if explicit
  * publication of an update at another time is desired.
  */
-void FSUI_publishCollectionNow(struct GE_Context * ectx,
-                              struct GC_Configuration * cfg);
+void CO_publishCollectionNow(struct GE_Context * ectx,
+                            struct GC_Configuration * cfg,
+                            unsigned int priority);
 
 /**
  * If we are currently building a collection, publish the given file
@@ -86,14 +88,15 @@
  * collecting, this function does nothing.
  *
  * Note that clients typically don't have to call this function
- * explicitly -- by using the FSUI library it should be called
- * automatically by FSUI code whenever needed.  However, the function
+ * explicitly -- by using the CO library it should be called
+ * automatically by CO code whenever needed.  However, the function
  * maybe useful if you're inserting files using libECRS directly or
  * need other ways to explicitly extend a collection.
  */
-void FSUI_publishToCollection(struct GE_Context * ectx,
-                             struct GC_Configuration * cfg,
-                             const ECRS_FileInfo * fi);
+void CO_publishToCollection(struct GE_Context * ectx,
+                           struct GC_Configuration * cfg,
+                           const ECRS_FileInfo * fi,
+                           unsigned int prio);
 
 
 

Modified: GNUnet/src/include/gnunet_fsui_lib.h
===================================================================
--- GNUnet/src/include/gnunet_fsui_lib.h        2006-08-14 04:20:33 UTC (rev 
3228)
+++ GNUnet/src/include/gnunet_fsui_lib.h        2006-08-14 05:39:00 UTC (rev 
3229)
@@ -697,6 +697,7 @@
 FSUI_startUpload(struct FSUI_Context * ctx,
                 const char * filename,
                 unsigned int anonymityLevel,
+                unsigned int priority,
                 int doIndex,
                 int doExtract,
                 int individualKeywords,

Modified: GNUnet/src/server/gnunet-transport-check.c
===================================================================
--- GNUnet/src/server/gnunet-transport-check.c  2006-08-14 04:20:33 UTC (rev 
3228)
+++ GNUnet/src/server/gnunet-transport-check.c  2006-08-14 05:39:00 UTC (rev 
3229)
@@ -65,8 +65,6 @@
 
 static struct GC_Configuration * cfg;
 
-static struct CronManager * cron;
-
 static struct GE_Context * ectx;
 
 static struct CronManager * cron;

Modified: GNUnet/todo
===================================================================
--- GNUnet/todo 2006-08-14 04:20:33 UTC (rev 3228)
+++ GNUnet/todo 2006-08-14 05:39:00 UTC (rev 3229)
@@ -27,10 +27,10 @@
     + fragmentation, identity,  pingpong, session, transport,
       stats, topology_default, state, getoption, advertising,
       traffic, ecrs_core, template, tbench, tracekit, fs/fslib,
-      fs/module, gap, fs/ecrs, fs/uritrack, fs/namespace compile
+      fs/module, gap, fs/ecrs, fs/uritrack, fs/namespace,
+      fs/fsui, fs/collection compile
     + bootstrap_http: maybe switch to libwww?
-    + for fs: fs/fsui (3700), 
-              fs/collection (400), fs/tools (2500)
+    + for fs: (400), fs/tools (2500)
     + rest: sqstore_mysql, dht, rpc, topology_f2f, vpn
     + low priority: chat, kvstore_sqlite, testbed
   * setup:





reply via email to

[Prev in Thread] Current Thread [Next in Thread]