gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r3583 - GNUnet/src/applications/fs/fsui


From: grothoff
Subject: [GNUnet-SVN] r3583 - GNUnet/src/applications/fs/fsui
Date: Tue, 31 Oct 2006 19:17:08 -0800 (PST)

Author: grothoff
Date: 2006-10-31 19:17:05 -0800 (Tue, 31 Oct 2006)
New Revision: 3583

Added:
   GNUnet/src/applications/fs/fsui/serializetest.c
Modified:
   GNUnet/src/applications/fs/fsui/deserialize.c
   GNUnet/src/applications/fs/fsui/fsui.c
   GNUnet/src/applications/fs/fsui/serialize.c
   GNUnet/src/applications/fs/fsui/upload.c
Log:
fixing handling of upload global keyword list

Modified: GNUnet/src/applications/fs/fsui/deserialize.c
===================================================================
--- GNUnet/src/applications/fs/fsui/deserialize.c       2006-11-01 02:57:20 UTC 
(rev 3582)
+++ GNUnet/src/applications/fs/fsui/deserialize.c       2006-11-01 03:17:05 UTC 
(rev 3583)
@@ -604,7 +604,7 @@
     READINT(big);
     if (big == 0)
       return OK;
-    if ( (big != 2) && (big != 3) ) {
+    if ( (big < 1) && (big > 7) ) {
       GE_BREAK(NULL, 0);
       break;
     }
@@ -621,8 +621,16 @@
     READINT(sshared.priority);
     READINT(sshared.individualKeywords);
     READLONG(sshared.expiration);
-    if (big == 2)
+    if ((big & 2) == 2)
       READSTRING(sshared.extractor_config, 1024*1024);
+    if ((big & 4) == 4) {
+      sshared.global_keywords = read_uri(ctx->ectx, fd);
+      if (sshared.global_keywords == NULL) {
+       FREENONNULL(sshared.extractor_config);
+       GE_BREAK(NULL, 0);
+       return SYSERR;
+      }
+    }
     shared = MALLOC(sizeof(FSUI_UploadShared));    
     memcpy(shared,
           &sshared,

Modified: GNUnet/src/applications/fs/fsui/fsui.c
===================================================================
--- GNUnet/src/applications/fs/fsui/fsui.c      2006-11-01 02:57:20 UTC (rev 
3582)
+++ GNUnet/src/applications/fs/fsui/fsui.c      2006-11-01 03:17:05 UTC (rev 
3583)
@@ -403,7 +403,8 @@
     if (list->parent == &ctx->activeUploads) {
       shared = list->shared;
       EXTRACTOR_removeAll(shared->extractors);
-      ECRS_freeUri(shared->global_keywords);
+      if (shared->global_keywords != NULL)
+       ECRS_freeUri(shared->global_keywords);
       FREENONNULL(shared->extractor_config);
       FREE(shared);
     }

Modified: GNUnet/src/applications/fs/fsui/serialize.c
===================================================================
--- GNUnet/src/applications/fs/fsui/serialize.c 2006-11-01 02:57:20 UTC (rev 
3582)
+++ GNUnet/src/applications/fs/fsui/serialize.c 2006-11-01 03:17:05 UTC (rev 
3583)
@@ -267,10 +267,16 @@
                         struct FSUI_Context * ctx,
                         struct FSUI_UploadList * upos) {
   struct FSUI_UploadShared * shared;
+  int bits;
 
   while (upos != NULL) {
     shared = upos->shared;
-    WRITEINT(fd, (shared->extractor_config != NULL) ? 2 : 3);
+    bits = 1;
+    if (shared->extractor_config != NULL)
+      bits |= 2;
+    if (shared->global_keywords != NULL)
+      bits |= 4;
+    WRITEINT(fd, bits);
     WRITEINT(fd, 0x44D1F024);
     WRITEINT(fd, shared->doIndex);
     WRITEINT(fd, shared->anonymityLevel);
@@ -280,6 +286,8 @@
     if (shared->extractor_config != NULL)
       WRITESTRING(fd,
                  shared->extractor_config);
+    if (shared->global_keywords != NULL)
+      writeURI(fd, shared->global_keywords);
     writeUploadList(fd,
                    ctx,
                    upos,

Added: GNUnet/src/applications/fs/fsui/serializetest.c
===================================================================
--- GNUnet/src/applications/fs/fsui/serializetest.c     2006-11-01 02:57:20 UTC 
(rev 3582)
+++ GNUnet/src/applications/fs/fsui/serializetest.c     2006-11-01 03:17:05 UTC 
(rev 3583)
@@ -0,0 +1,313 @@
+/*
+     This file is part of GNUnet.
+     (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
+     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/fsui/serializetest.c
+ * @brief testcase for fsui upload persistence
+ * @author Christian Grothoff
+ */
+
+#include "platform.h"
+#include "gnunet_util.h"
+#include "gnunet_fsui_lib.h"
+#include "gnunet_util_config_impl.h"
+#include "gnunet_util_network_client.h"
+#include "gnunet_util_crypto.h"
+
+#define DEBUG_VERBOSE NO
+
+#define CHECK(a) if (!(a)) { ok = NO; GE_BREAK(ectx, 0); goto FAILURE; }
+
+static volatile int suspendRestart = 0;
+
+static struct GE_Context * ectx;
+
+static char * makeName(unsigned int i) {
+  char * name;
+  char * fn;
+
+  name = STRDUP("/tmp/gnunet-fsuidownloadtest");
+  disk_directory_create(ectx, name);
+  fn = MALLOC(strlen(name) + 40);
+  SNPRINTF(fn,
+          strlen(name) + 40,
+          "%s%sFSUITEST%u",
+          name,
+          DIR_SEPARATOR_STR,
+          i);
+  FREE(name);
+  return fn;
+}
+
+static volatile enum FSUI_EventType lastEvent;
+static volatile enum FSUI_EventType waitForEvent;
+static struct FSUI_Context * ctx;
+static struct ECRS_URI * upURI;
+
+static void * eventCallback(void * cls,
+                           const FSUI_Event * event) {
+  switch(event->type) {
+  case FSUI_upload_progress:
+#if DEBUG_VERBOSE
+    printf("Upload is progressing (%llu/%llu)...\n",
+          event->data.UploadProgress.completed,
+          event->data.UploadProgress.total);
+#endif
+    break;
+  case FSUI_upload_completed:
+    upURI = ECRS_dupUri(event->data.UploadCompleted.uri);
+#if DEBUG_VERBOSE
+    printf("Upload complete.\n");
+#endif
+    break;
+  case FSUI_unindex_progress:
+#if DEBUG_VERBOSE
+    printf("Unindex is progressing (%llu/%llu)...\n",
+          event->data.UnindexProgress.completed,
+          event->data.UnindexProgress.total);
+#endif
+    break;
+  case FSUI_unindex_completed:
+#if DEBUG_VERBOSE
+    printf("Unindex complete.\n");
+#endif
+    break;
+  case FSUI_unindex_error:
+  case FSUI_upload_error:
+  case FSUI_download_error:
+  case FSUI_search_error:
+    fprintf(stderr,
+           "Received ERROR: %d\n",
+           event->type);
+    GE_BREAK(ectx, 0);
+    break;
+  case FSUI_download_aborted:
+#if DEBUG_VERBOSE
+    printf("Received download aborted event.\n");
+#endif
+    break;
+  case FSUI_unindex_resumed:
+  case FSUI_upload_resumed:
+#if DEBUG_VERBOSE
+    fprintf(stderr,
+           "Received RESUMING: %d\n",
+           event->type);
+#endif
+    break;
+  case FSUI_unindex_suspended:
+  case FSUI_upload_suspended:
+#if DEBUG_VERBOSE
+    fprintf(stderr,
+           "Received SUSPENDING: %d\n",
+           event->type);
+#endif
+    break;
+  case FSUI_upload_started:
+  case FSUI_upload_stopped:
+  case FSUI_unindex_started:
+  case FSUI_unindex_stopped:
+    break;
+  default:
+    printf("Unexpected event: %d\n",
+          event->type);
+    break;
+  }
+  if (lastEvent == waitForEvent)
+    return NULL; /* ignore all other events */
+  lastEvent = event->type;
+  return NULL;
+}
+
+#define FILESIZE (1024 * 1024 * 2)
+
+#define START_DAEMON 0
+
+int main(int argc, char * argv[]){
+#if START_DAEMON
+  pid_t daemon;
+#endif
+  int ok;
+  int i;
+  char * fn = NULL;
+  char * keywords[] = {
+    "down_foo",
+    "down_bar",
+    NULL,
+  };
+  int prog;
+  char * buf;
+  struct ECRS_MetaData * meta;
+  struct ECRS_URI * kuri = NULL;
+  struct GC_Configuration * cfg;
+  struct FSUI_UnindexList * unindex = NULL;
+  struct FSUI_UploadList * upload = NULL;
+
+  ok = YES;
+  cfg = GC_create_C_impl();
+  if (-1 == GC_parse_configuration(cfg,
+                                  "check.conf")) {
+    GC_free(cfg);
+    return -1;
+  }
+#if START_DAEMON
+  daemon  = os_daemon_start(NULL,
+                           cfg,
+                           "peer.conf",
+                           NO);
+  GE_ASSERT(NULL, daemon > 0);
+  GE_ASSERT(NULL, OK == connection_wait_for_running(NULL,
+                                                   cfg,
+                                                   30 * cronSECONDS));
+  PTHREAD_SLEEP(5 * cronSECONDS); /* give apps time to start */
+  /* ACTUAL TEST CODE */
+#endif
+  ctx = FSUI_start(NULL,
+                  cfg,
+                  "fsuiserializetest",
+                  32,
+                  YES,
+                  &eventCallback,
+                  NULL);
+  CHECK(ctx != NULL);
+  fn = makeName(42);
+  buf = MALLOC(FILESIZE);
+  for (i=0;i<FILESIZE;i++)
+    buf[i] = weak_randomi(256);
+  disk_file_write(ectx,
+                 fn,
+                 buf,
+                 FILESIZE,
+                 "600");
+  FREE(buf);
+  meta = ECRS_createMetaData();
+  kuri = ECRS_parseListKeywordURI(ectx,
+                                 2,
+                                 (const char**)keywords);
+  waitForEvent = FSUI_upload_completed;
+  upload = FSUI_startUpload(ctx,
+                           fn,
+                           (DirectoryScanCallback) &disk_directory_scan,
+                           NULL,               
+                           0,
+                           0,
+                           YES,
+                           NO,
+                           NO,
+                           meta,
+                           kuri,
+                           kuri);
+  CHECK(upload != NULL);
+  ECRS_freeUri(kuri);
+  kuri = NULL;
+  ECRS_freeMetaData(meta);
+  prog = 0;
+  suspendRestart = 4;
+  while (lastEvent != FSUI_upload_completed) {
+    if ( (suspendRestart > 0) &&
+        (weak_randomi(4) == 0) ) {
+#if 1
+#if DEBUG_VERBOSE
+      printf("Testing FSUI suspend-resume\n");
+#endif
+      FSUI_stop(ctx); /* download possibly incomplete
+                        at this point, thus testing resume */
+      ctx = FSUI_start(NULL,
+                      cfg,
+                      "fsuiserializetest",
+                      32,
+                      YES,
+                      &eventCallback,
+                      NULL);
+#if DEBUG_VERBOSE
+      printf("Resumed...\n");
+#endif
+#endif
+      suspendRestart--;
+    }
+    prog++;
+    CHECK(prog < 5000);
+    PTHREAD_SLEEP(50 * cronMILLIS);
+    if (GNUNET_SHUTDOWN_TEST() == YES)
+      break;
+  }
+  FSUI_stopUpload(ctx, upload);
+  waitForEvent = FSUI_unindex_completed;
+  unindex = FSUI_startUnindex(ctx, fn);
+  CHECK(unindex != NULL);
+  prog = 0;
+  suspendRestart = 4;
+  while (lastEvent != FSUI_unindex_completed) {
+    if ( (suspendRestart > 0) &&
+        (weak_randomi(4) == 0) ) {
+#if 1
+#if DEBUG_VERBOSE
+      printf("Testing FSUI suspend-resume\n");
+#endif
+      FSUI_stop(ctx); /* download possibly incomplete
+                        at this point, thus testing resume */
+      ctx = FSUI_start(NULL,
+                      cfg,
+                      "fsuiserializetest",
+                      32,
+                      YES,
+                      &eventCallback,
+                      NULL);
+#if DEBUG_VERBOSE
+      printf("Resumed...\n");
+#endif
+#endif
+    }
+    prog++;
+    CHECK(prog < 5000);
+    PTHREAD_SLEEP(50 * cronMILLIS);
+    CHECK(lastEvent != FSUI_unindex_error);
+    if (GNUNET_SHUTDOWN_TEST() == YES)
+      break;
+  }
+  CHECK(lastEvent == FSUI_unindex_completed);
+  /* END OF TEST CODE */
+ FAILURE:
+  if (ctx != NULL) {
+    if (unindex != NULL)
+      FSUI_stopUnindex(ctx,
+                      unindex);
+    FSUI_stop(ctx);
+  }
+  if (fn != NULL) {
+    UNLINK(fn);
+    FREE(fn);
+  }
+  if (kuri != NULL)
+    ECRS_freeUri(kuri);
+  fn = makeName(43);
+  /* TODO: verify file 'fn(42)' == file 'fn(43)' */
+  UNLINK(fn);
+  FREE(fn);
+  if (upURI != NULL)
+    ECRS_freeUri(upURI);
+
+#if START_DAEMON
+  GE_ASSERT(NULL, OK == os_daemon_stop(NULL, daemon));
+#endif
+  GC_free(cfg);
+  return (ok == YES) ? 0 : 1;
+}
+
+/* end of downloadtest.c */


Property changes on: GNUnet/src/applications/fs/fsui/serializetest.c
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: GNUnet/src/applications/fs/fsui/upload.c
===================================================================
--- GNUnet/src/applications/fs/fsui/upload.c    2006-11-01 02:57:20 UTC (rev 
3582)
+++ GNUnet/src/applications/fs/fsui/upload.c    2006-11-01 03:17:05 UTC (rev 
3583)
@@ -488,7 +488,8 @@
 }
 
 static void freeShared(struct FSUI_UploadShared * shared) {
-  ECRS_freeUri(shared->global_keywords);
+  if (shared->global_keywords != NULL)
+    ECRS_freeUri(shared->global_keywords);
   EXTRACTOR_removeAll(shared->extractors);
   FREENONNULL(shared->extractor_config);
   FREE(shared);
@@ -543,7 +544,7 @@
   shared->extractors = extractors;
   shared->ctx = ctx;
   shared->handle = NULL;
-  shared->global_keywords = ECRS_dupUri(globalURI);
+  shared->global_keywords = globalURI != NULL ? ECRS_dupUri(globalURI) : NULL;
   shared->extractor_config = config;
   shared->doIndex = doIndex;
   shared->anonymityLevel = anonymityLevel;





reply via email to

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