gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r11141 - gnunet/src/fs


From: gnunet
Subject: [GNUnet-SVN] r11141 - gnunet/src/fs
Date: Sat, 1 May 2010 13:11:18 +0200

Author: grothoff
Date: 2010-05-01 13:11:18 +0200 (Sat, 01 May 2010)
New Revision: 11141

Modified:
   gnunet/src/fs/fs.c
   gnunet/src/fs/fs.h
   gnunet/src/fs/fs_tree.c
   gnunet/src/fs/fs_unindex.c
Log:
deserialization of unindex operations

Modified: gnunet/src/fs/fs.c
===================================================================
--- gnunet/src/fs/fs.c  2010-04-30 14:50:31 UTC (rev 11140)
+++ gnunet/src/fs/fs.c  2010-05-01 11:11:18 UTC (rev 11141)
@@ -1191,6 +1191,21 @@
 
 
 /**
+ * Synchronize this unindex struct with its mirror
+ * on disk.  Note that all internal FS-operations that change
+ * publishing structs should already call "sync" internally,
+ * so this function is likely not useful for clients.
+ * 
+ * @param uc the struct to sync
+ */
+void
+GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc)
+{
+  /* FIXME */
+}
+
+
+/**
  * Deserialize information about pending publish operations.
  *
  * @param h master context
@@ -1225,7 +1240,9 @@
   struct GNUNET_FS_Handle *h = cls;
   struct GNUNET_BIO_ReadHandle *rh;
   struct GNUNET_FS_UnindexContext *uc;
+  struct GNUNET_FS_ProgressInfo pi;
   char *emsg;
+  uint32_t state;
 
   uc = GNUNET_malloc (sizeof (struct GNUNET_FS_UnindexContext));
   uc->h = h;
@@ -1233,33 +1250,70 @@
   rh = GNUNET_BIO_read_open (filename);
   if (rh == NULL)
     goto cleanup;
-  /* FIXME: do unindex state here! */
-#if 0
   if ( (GNUNET_OK !=
-       GNUNET_BIO_read_string (rh, "publish-nid", &pc->nid, 1024)) ||
+       GNUNET_BIO_read_string (rh, "unindex-fn", &uc->filename, 10*1024)) ||
        (GNUNET_OK !=
-       GNUNET_BIO_read_string (rh, "publish-nuid", &pc->nuid, 1024)) ||
+       GNUNET_BIO_read_int64 (rh, &uc->file_size)) ||
        (GNUNET_OK !=
-       GNUNET_BIO_read_int32 (rh, &options)) ||
+       GNUNET_BIO_read_int64 (rh, &uc->start_time.value)) ||
        (GNUNET_OK !=
-       GNUNET_BIO_read_int32 (rh, &all_done)) ||
-       (GNUNET_OK !=
-       GNUNET_BIO_read_string (rh, "publish-firoot", &fi_root, 128)) ||
-       (GNUNET_OK !=
-       GNUNET_BIO_read_string (rh, "publish-fipos", &fi_pos, 128)) ||
-       (GNUNET_OK !=
-       GNUNET_BIO_read_string (rh, "publish-ns", &ns, 1024)) )
+       GNUNET_BIO_read_int32 (rh, &state)) )
     goto cleanup;          
-  pc->options = options;
-  pc->all_done = all_done;
-  pc->fi = deserialize_file_information (h, fi_root);
-  if (pc->fi == NULL)
-    goto cleanup;    
-#endif
-  /* FIXME: generate RESUME event */
-  /* FIXME: re-start unindexing (if needed)... */
+  uc->state = (enum UnindexState) state;
+  switch (state)
+    {
+    case UNINDEX_STATE_HASHING:
+      break;
+    case UNINDEX_STATE_FS_NOTIFY:
+      if (GNUNET_OK !=
+         GNUNET_BIO_read (rh, "unindex-hash", &uc->file_id, sizeof 
(GNUNET_HashCode)))
+       goto cleanup;
+      break;
+    case UNINDEX_STATE_DS_REMOVE:
+      break;
+    case UNINDEX_STATE_COMPLETE:
+      break;
+    case UNINDEX_STATE_ERROR:
+      if (GNUNET_OK !=
+         GNUNET_BIO_read_string (rh, "unindex-emsg", &uc->emsg, 10*1024))
+       goto cleanup;
+      break;
+    case UNINDEX_STATE_ABORTED:
+      GNUNET_break (0);
+      goto cleanup;
+    default:
+      GNUNET_break (0);
+      goto cleanup;
+    }
+  pi.status = GNUNET_FS_STATUS_UNINDEX_RESUME;
+  pi.value.unindex.specifics.resume.message = uc->emsg;
+  GNUNET_FS_unindex_make_status_ (&pi,
+                                 uc,
+                                 (uc->state == UNINDEX_STATE_COMPLETE) 
+                                 ? uc->file_size
+                                 : 0);
   switch (uc->state)
     {
+    case UNINDEX_STATE_HASHING:
+      GNUNET_CRYPTO_hash_file (uc->h->sched,
+                              GNUNET_SCHEDULER_PRIORITY_IDLE,
+                              uc->filename,
+                              HASHING_BLOCKSIZE,
+                              &GNUNET_FS_unindex_process_hash_,
+                              uc);
+      break;
+    case UNINDEX_STATE_FS_NOTIFY:
+      uc->state = UNINDEX_STATE_HASHING;
+      GNUNET_FS_unindex_process_hash_ (uc,
+                                      &uc->file_id);
+      break;
+    case UNINDEX_STATE_DS_REMOVE:
+      GNUNET_FS_unindex_do_remove_ (uc);
+      break;
+    case UNINDEX_STATE_COMPLETE:
+    case UNINDEX_STATE_ERROR:
+      /* no need to resume any operation, we were done */
+      break;
     default:
       break;
     }
@@ -1271,18 +1325,10 @@
                  filename,
                  emsg);
       GNUNET_free (emsg);
-      rh = NULL;
-      goto cleanup;
     }
   return GNUNET_OK;
  cleanup:
-  /* FIXME: clean unindex state here! */
-#if 0
-  GNUNET_free_non_null (pc->nid);
-  GNUNET_free_non_null (pc->nuid);
-  GNUNET_free_non_null (fi_root);
-  GNUNET_free_non_null (ns);
-#endif
+  GNUNET_free_non_null (uc->filename);
   if ( (rh != NULL) &&
        (GNUNET_OK !=
        GNUNET_BIO_read_close (rh, &emsg)) )
@@ -1301,8 +1347,6 @@
 }
 
 
-
-
 /**
  * Deserialize information about pending publish operations.
  *

Modified: gnunet/src/fs/fs.h
===================================================================
--- gnunet/src/fs/fs.h  2010-04-30 14:50:31 UTC (rev 11140)
+++ gnunet/src/fs/fs.h  2010-05-01 11:11:18 UTC (rev 11141)
@@ -658,6 +658,18 @@
 
 
 /**
+ * Function called once the hash of the file
+ * that is being unindexed has been computed.
+ *
+ * @param cls closure, unindex context
+ * @param file_id computed hash, NULL on error
+ */
+void 
+GNUNET_FS_unindex_process_hash_ (void *cls,
+                                const GNUNET_HashCode *file_id);
+
+
+/**
  * Fill in all of the generic fields for a publish event and call the
  * callback.
  *
@@ -673,8 +685,29 @@
                                const struct GNUNET_FS_FileInformation *p,
                                uint64_t offset);
 
+/**
+ * Fill in all of the generic fields for 
+ * an unindex event and call the callback.
+ *
+ * @param pi structure to fill in
+ * @param uc overall unindex context
+ * @param offset where we are in the file (for progress)
+ */
+void
+GNUNET_FS_unindex_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
+                               struct GNUNET_FS_UnindexContext *uc,
+                               uint64_t offset);
 
 /**
+ * Connect to the datastore and remove the blocks.
+ *
+ * @param uc context for the unindex operation.
+ */
+void 
+GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc);
+
+
+/**
  * Remove serialization/deserialization file from disk.
  *
  * @param h master context
@@ -711,7 +744,19 @@
 GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc);
 
 
+/**
+ * Synchronize this unindex struct with its mirror
+ * on disk.  Note that all internal FS-operations that change
+ * publishing structs should already call "sync" internally,
+ * so this function is likely not useful for clients.
+ * 
+ * @param uc the struct to sync
+ */
+void
+GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc);
 
+
+
 /**
  * Master context for most FS operations.
  */
@@ -983,6 +1028,11 @@
   struct GNUNET_DISK_FileHandle *fh;
 
   /**
+   * Error message, NULL on success.
+   */
+  char *emsg;
+
+  /**
    * Overall size of the file.
    */ 
   uint64_t file_size;

Modified: gnunet/src/fs/fs_tree.c
===================================================================
--- gnunet/src/fs/fs_tree.c     2010-04-30 14:50:31 UTC (rev 11140)
+++ gnunet/src/fs/fs_tree.c     2010-05-01 11:11:18 UTC (rev 11141)
@@ -173,7 +173,7 @@
   struct GNUNET_FS_TreeEncoder *te;
   
   GNUNET_assert (size > 0);
-  te = GNUNET_malloc (sizeof (struct GNUNET_FS_TreeEncoder));
+  te = GNUNET_malloc (sizeof (struct GNUNET_FS_TreeEncoder));  
   te->h = h;
   te->size = size;
   te->cls = cls;

Modified: gnunet/src/fs/fs_unindex.c
===================================================================
--- gnunet/src/fs/fs_unindex.c  2010-04-30 14:50:31 UTC (rev 11140)
+++ gnunet/src/fs/fs_unindex.c  2010-05-01 11:11:18 UTC (rev 11141)
@@ -77,16 +77,16 @@
 
 /**
  * Fill in all of the generic fields for 
- * an unindex event.
+ * an unindex event and call the callback.
  *
  * @param pi structure to fill in
  * @param uc overall unindex context
  * @param offset where we are in the file (for progress)
  */
-static void
-make_unindex_status (struct GNUNET_FS_ProgressInfo *pi,
-                    struct GNUNET_FS_UnindexContext *uc,
-                    uint64_t offset)
+void
+GNUNET_FS_unindex_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
+                               struct GNUNET_FS_UnindexContext *uc,
+                               uint64_t offset)
 {
   pi->value.unindex.uc = uc;
   pi->value.unindex.cctx = uc->client_info;
@@ -98,6 +98,10 @@
                                 uc->file_size);
   pi->value.unindex.duration = GNUNET_TIME_absolute_get_duration 
(uc->start_time);
   pi->value.unindex.completed = offset;
+  uc->client_info 
+    = uc->h->upcb (uc->h->upcb_cls,
+                  pi);
+
 }
 
 
@@ -122,14 +126,11 @@
   struct GNUNET_FS_ProgressInfo pi;
 
   pi.status = GNUNET_FS_STATUS_UNINDEX_PROGRESS;
-  make_unindex_status (&pi, uc, offset);
   pi.value.unindex.specifics.progress.data = pt_block;
   pi.value.unindex.specifics.progress.offset = offset;
   pi.value.unindex.specifics.progress.data_len = pt_size;
   pi.value.unindex.specifics.progress.depth = depth;
-  uc->client_info 
-    = uc->h->upcb (uc->h->upcb_cls,
-                  &pi);
+  GNUNET_FS_unindex_make_status_ (&pi, uc, offset);
 }
                                               
 
@@ -147,12 +148,9 @@
   struct GNUNET_FS_ProgressInfo pi;
   
   pi.status = GNUNET_FS_STATUS_UNINDEX_ERROR;
-  make_unindex_status (&pi, uc, 0);
   pi.value.unindex.eta = GNUNET_TIME_UNIT_FOREVER_REL;
   pi.value.unindex.specifics.error.message = emsg;
-  uc->client_info
-    = uc->h->upcb (uc->h->upcb_cls,
-                  &pi);
+  GNUNET_FS_unindex_make_status_ (&pi, uc, 0);
 }
 
 
@@ -262,11 +260,8 @@
   else
     {   
       pi.status = GNUNET_FS_STATUS_UNINDEX_COMPLETED;
-      make_unindex_status (&pi, uc, uc->file_size);
       pi.value.unindex.eta = GNUNET_TIME_UNIT_ZERO;
-      uc->client_info
-       = uc->h->upcb (uc->h->upcb_cls,
-                      &pi);
+      GNUNET_FS_unindex_make_status_ (&pi, uc, uc->file_size);
     }
 }
 
@@ -284,8 +279,11 @@
 {
   struct GNUNET_FS_UnindexContext *uc = cls;
 
-  GNUNET_CLIENT_disconnect (uc->client, GNUNET_NO);
-  uc->client = NULL;
+  if (uc->client != NULL)
+    {
+      GNUNET_CLIENT_disconnect (uc->client, GNUNET_NO);
+      uc->client = NULL;
+    }
   if (uc->state != UNINDEX_STATE_FS_NOTIFY) 
     {
       GNUNET_FS_unindex_stop (uc);
@@ -306,6 +304,18 @@
       return;      
     }
   uc->state = UNINDEX_STATE_DS_REMOVE;
+  GNUNET_FS_unindex_do_remove_ (uc);
+}
+
+
+/**
+ * Connect to the datastore and remove the blocks.
+ *
+ * @param uc context for the unindex operation.
+ */
+void 
+GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc)
+{
   uc->dsh = GNUNET_DATASTORE_connect (uc->h->cfg,
                                      uc->h->sched);
   if (NULL == uc->dsh)
@@ -345,9 +355,9 @@
  * @param cls closure, unindex context
  * @param file_id computed hash, NULL on error
  */
-static void 
-process_hash (void *cls,
-             const GNUNET_HashCode *file_id)
+void 
+GNUNET_FS_unindex_process_hash_ (void *cls,
+                                const GNUNET_HashCode *file_id)
 {
   struct GNUNET_FS_UnindexContext *uc = cls;
   struct UnindexMessage req;
@@ -414,16 +424,13 @@
 
   // FIXME: make persistent!
   pi.status = GNUNET_FS_STATUS_UNINDEX_START;
-  make_unindex_status (&pi, ret, 0);
   pi.value.unindex.eta = GNUNET_TIME_UNIT_FOREVER_REL;
-  ret->client_info
-    = h->upcb (h->upcb_cls,
-              &pi);
+  GNUNET_FS_unindex_make_status_ (&pi, ret, 0);
   GNUNET_CRYPTO_hash_file (h->sched,
                           GNUNET_SCHEDULER_PRIORITY_IDLE,
                           filename,
                           HASHING_BLOCKSIZE,
-                          &process_hash,
+                          &GNUNET_FS_unindex_process_hash_,
                           ret);
   return ret;
 }
@@ -450,14 +457,11 @@
       GNUNET_FS_remove_sync_file_ (uc->h, "unindex", uc->serialization);
       uc->serialization = NULL;
     }
-  make_unindex_status (&pi, uc, 
-                      (uc->state == UNINDEX_STATE_COMPLETE)
-                      ? uc->file_size : 0);
   pi.status = GNUNET_FS_STATUS_UNINDEX_STOPPED;
   pi.value.unindex.eta = GNUNET_TIME_UNIT_ZERO;
-  uc->client_info
-    = uc->h->upcb (uc->h->upcb_cls,
-                  &pi);
+  GNUNET_FS_unindex_make_status_ (&pi, uc, 
+                                 (uc->state == UNINDEX_STATE_COMPLETE)
+                                 ? uc->file_size : 0);
   GNUNET_break (NULL == uc->client_info);
   GNUNET_free (uc->filename);
   GNUNET_free_non_null (uc->serialization);





reply via email to

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