gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r22070 - gnunet/src/fs
Date: Mon, 18 Jun 2012 11:32:04 +0200

Author: grothoff
Date: 2012-06-18 11:32:04 +0200 (Mon, 18 Jun 2012)
New Revision: 22070

Modified:
   gnunet/src/fs/gnunet-auto-share.c
Log:
-implementing read_state

Modified: gnunet/src/fs/gnunet-auto-share.c
===================================================================
--- gnunet/src/fs/gnunet-auto-share.c   2012-06-18 09:22:42 UTC (rev 22069)
+++ gnunet/src/fs/gnunet-auto-share.c   2012-06-18 09:32:04 UTC (rev 22070)
@@ -141,13 +141,74 @@
 
 
 /**
+ * Compute the name of the state database file we will use.
+ */
+static char *
+get_state_file ()
+{
+  char *ret;
+
+  GNUNET_asprintf (&ret,
+                  "%s%s.auto",
+                  dir_name,
+                  (DIR_SEPARATOR == dir_name[strlen(dir_name)-1]) ? "" : 
DIR_SEPARATOR_STR);
+  return ret;
+}
+
+
+/**
  * Load the set of 'work_finished' items from disk.
  */
 static void
 load_state ()
 {
-  GNUNET_break (0);
-  // FIXME: implement!
+  char *fn;
+  struct GNUNET_BIO_ReadHandle *rh;
+  uint32_t n;
+  struct GNUNET_HashCode id;
+  struct WorkItem *wi;
+  char *emsg;
+
+  emsg = NULL;
+  fn = get_state_file ();
+  rh = GNUNET_BIO_read_open (fn);
+  GNUNET_free (fn);
+  if (NULL == rh)
+    return;
+  fn = NULL;
+  if (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &n))
+    goto error;
+  while (n-- > 0)
+  {
+    if ( (GNUNET_OK !=
+         GNUNET_BIO_read_string (rh, "filename", &fn, 1024)) || 
+        (GNUNET_OK !=
+         GNUNET_BIO_read (rh, "id", &id, sizeof (struct GNUNET_HashCode))) )
+      goto error;
+    wi = GNUNET_malloc (sizeof (struct WorkItem));
+    wi->id = id;
+    wi->filename = fn;
+    fn = NULL;
+    GNUNET_CRYPTO_hash (wi->filename,
+                       strlen (wi->filename),
+                       &id);
+    GNUNET_CONTAINER_multihashmap_put (work_finished,
+                                      &id,
+                                      wi,
+                                      
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+  }
+  if (GNUNET_OK == 
+      GNUNET_BIO_read_close (rh, &emsg))
+    return;
+  rh = NULL;
+ error:
+  GNUNET_free_non_null (fn);
+  if (NULL != rh)
+    GNUNET_BIO_read_close (rh, &emsg);
+  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+             _("Failed to load state: %s\n"),
+             emsg);
+  GNUNET_free_non_null (emsg);
 }
 
 




reply via email to

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