[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r25795 - in gnunet-update/src: fs gnunet_update
From: |
gnunet |
Subject: |
[GNUnet-SVN] r25795 - in gnunet-update/src: fs gnunet_update |
Date: |
Tue, 15 Jan 2013 14:52:38 +0100 |
Author: harsha
Date: 2013-01-15 14:52:38 +0100 (Tue, 15 Jan 2013)
New Revision: 25795
Modified:
gnunet-update/src/fs/gnupdate-daemon-search.c
gnunet-update/src/gnunet_update/install_manifest.py
Log:
- write timestamp to install-manifest
Modified: gnunet-update/src/fs/gnupdate-daemon-search.c
===================================================================
--- gnunet-update/src/fs/gnupdate-daemon-search.c 2013-01-15 13:32:03 UTC
(rev 25794)
+++ gnunet-update/src/fs/gnupdate-daemon-search.c 2013-01-15 13:52:38 UTC
(rev 25795)
@@ -57,11 +57,112 @@
static const char *data_dir_suffix = "share/gnunet-update/install-manifest";
/**
+ * The FS context
+ */
+static struct GNUNET_FS_Handle *ctx;
+
+/**
+ * FS search context
+ */
+static struct GNUNET_FS_SearchContext *sc;
+
+/**
+ * The shutdown task id
+ */
+static GNUNET_SCHEDULER_TaskIdentifier shutdown_tid;
+
+/**
* The timestamp from the install manifest
*/
static struct tm tstamp;
/**
+ * The probe timestamp; We search for metadata data file released in the year
+ * and month corresponding to this timestamp.
+ */
+static struct tm pstamp;
+
+
+/**
+ * Task to clean up and exit
+ *
+ * @param cls NULL
+ * @param tc the task context from the scheduler
+ */
+static void
+shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != shutdown_tid);
+ shutdown_tid = GNUNET_SCHEDULER_NO_TASK;
+ if (NULL != ctx)
+ {
+ GNUNET_FS_stop (ctx);
+ ctx = NULL;
+ }
+}
+
+
+/**
+ * This function takes `pstamp' back in time starting from `tstamp' depending
on
+ * the number of searching which have been done before
+ *
+ * @param reset GNUNET_YES to set `pstamp' to the current time; GNUNET_NO to
+ * push it back in time
+ * @return: upon success GNUNET_OK; GNUNET_SYSERR upon failure
+ */
+static int
+decpstamp (int reset)
+{
+ struct tm *gmtm;
+ time_t gmt;
+ time_t tinstall;
+
+ if (GNUNET_YES == reset)
+ {
+ gmt = time (NULL);
+ if (-1 == gmt)
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR, "Cannot determine current calendar
time\n");
+ return GNUNET_SYSERR;
+ }
+ tinstall = timegm (&tstamp);
+ if ( ((double) 0) > difftime (gmt, tinstall) )
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _("GNUnet installation detected to be done in future. "
+ "This could be due to wrongly set time either now or while "
+ "installing GNUnet\n"));
+ return GNUNET_SYSERR;
+ }
+ gmtm = NULL;
+ gmtm = gmtime (&gmt);
+ if (NULL == gmtm)
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ (void) memcpy (&pstamp, gmtm, sizeof (struct tm));
+ return GNUNET_OK;
+ }
+ if ( (pstamp.tm_year < tstamp.tm_year)
+ || ( (pstamp.tm_year == tstamp.tm_year)
+ && (pstamp.tm_mon < tstamp.tm_mon) ) )
+ {
+ /* Search again from current calendar time */
+ DEBUG ("Resetting probe timestamp\n");
+ return decpstamp (GNUNET_YES);
+ }
+ if (pstamp.tm_mon == 0)
+ {
+ pstamp.tm_mon = 12;
+ pstamp.tm_year--;
+ }
+ pstamp.tm_mon--;
+ return GNUNET_OK;
+}
+
+
+/**
* Returns the broken time after reading it from the install manifest file
*
* @param
@@ -72,7 +173,10 @@
{
char data[256];
char tstr[256];
+ char *oldtz;
+ static const char *tzstr = "TZ";
ssize_t rsize;
+ int ret;
rsize = GNUNET_DISK_fn_read (path, data, sizeof (data));
if (GNUNET_SYSERR == rsize)
@@ -83,16 +187,65 @@
GNUNET_break (0);
return GNUNET_SYSERR;
}
+
+ oldtz = getenv (tzstr);
+ GNUNET_break (0 == setenv (tzstr, "UTC", 1));
if (NULL == strptime (tstr, "%s", tp))
{
GNUNET_break (0);
- return GNUNET_SYSERR;
+ ret = GNUNET_SYSERR;
+ goto end;
}
- return GNUNET_OK;
+ ret = GNUNET_OK;
+
+ end:
+ if (NULL != oldtz)
+ GNUNET_break (0 == setenv (tzstr, oldtz, 1));
+ else
+ unsetenv (tzstr);
+ return ret;
}
+/* /\** */
+/* * Function to request FS search for metadata based on the current `pstamp'
*/
+/* * */
+/* * @param */
+/* * @return */
+/* *\/ */
+/* static void */
+/* search () */
+/* { */
+/* struct GNUNET_FS_Uri *uri; */
+
+/* GNUNET_assert (NULL != ctx); */
+
+/* sc = */
+/* } */
+
+
/**
+ * Called by FS client to give information about the progress of an
+ * operation.
+ *
+ * @param cls closure
+ * @param info details about the event, specifying the event type
+ * and various bits about the event
+ * @return client-context (for the next progress call
+ * for this operation; should be set to NULL for
+ * SUSPEND and STOPPED events). The value returned
+ * will be passed to future callbacks in the respective
+ * field in the GNUNET_FS_ProgressInfo struct.
+ */
+static void *
+progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
+{
+ GNUNET_break (0);
+ return NULL;
+}
+
+
+/**
* Main function that will be run by the scheduler.
*
* @param cls closure
@@ -107,15 +260,15 @@
//char **keywords;
char *path;
char tstr[256];
-
+
path = NULL;
if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (c,
"GNUPDATE",
"INSTALL_DIR",
&idir))
{
- fprintf (stderr, "Cannot determine GNUNET installation dir. "
- "Set \"INSTALL_DIR\" in configuration\n");
+ LOG (GNUNET_ERROR_TYPE_ERROR, "Cannot determine GNUNET installation dir. "
+ "Set \"INSTALL_DIR\" in configuration\n");
goto err_return;
}
if (0 > GNUNET_asprintf (&path, "%s/%s", idir, data_dir_suffix))
@@ -136,6 +289,18 @@
}
tstr[255] = '\0';
DEBUG ("%s\n", tstr);
+ if (GNUNET_OK != decpstamp (GNUNET_YES))
+ goto err_return;
+ ctx = GNUNET_FS_start (c, "gnupdate-daemon-search", &progress_cb, NULL,
+ GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
+ if (NULL == ctx)
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _("Could not initialize `%s' subsystem.\n"), "FS");
+ goto err_return;
+ }
+ shutdown_tid = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
+ &shutdown_task, NULL);
ret = GNUNET_OK;
return;
Modified: gnunet-update/src/gnunet_update/install_manifest.py
===================================================================
--- gnunet-update/src/gnunet_update/install_manifest.py 2013-01-15 13:32:03 UTC
(rev 25794)
+++ gnunet-update/src/gnunet_update/install_manifest.py 2013-01-15 13:52:38 UTC
(rev 25795)
@@ -22,6 +22,7 @@
# Handles install-manifest files
import os
+import time
from file import FileObject, DependencyFileObject
@@ -53,11 +54,13 @@
f = open(os.path.join(install_dir,
install_manifest_file_path),
"wb")
-
+ # Write the current timestamp
+ ts = int (time.time());
+ f.write (repr (ts)+ "\n");
+ # Write file objects
map(lambda file_object:
f.write(file_object.name + ";" + file_object.hash + "\n"),
file_objects)
-
f.write("%%\n") # The section seperator
map(lambda dep_object:
f.write(dep_object.name + ";" + dep_object.realname
@@ -85,6 +88,7 @@
f = open(os.path.join(install_dir,
install_manifest_file_path),
"rb")
+ f.readline(); # Ignore the timestamp value
file_objects = list() # List to hold the file objects
while True:
read_line = f.readline()
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r25795 - in gnunet-update/src: fs gnunet_update,
gnunet <=