*/
static GNUNET_SCHEDULER_TaskIdentifier current_task;
+/**
+ * ID of the current hostlist saving task scheduled.
+ */
+static GNUNET_SCHEDULER_TaskIdentifier saving_task;
+
/**
* Amount of time we wait between hostlist downloads.
*/
static void
schedule_hostlist_task (void);
+/**
+ * Method to load persistent hostlist file during hostlist client shutdown
+ * @param shutdown set if called because of shutdown, entries in linked list will be destroyed
+ */
+static void save_hostlist_file ( int shutdown );
/**
* Clean up the state from the task that downloaded the
NULL);
}
+/**
+ * Compute when we should save the hostlist entries the next time;
+ * then schedule the task accordingly.
+ */
+static void
+schedule_hostlist_saving_task ();
+
+/**
+ * Task that checks if we should try to download a hostlist.
+ * If so, we initiate the download, otherwise we schedule
+ * this task again for a later time.
+ */
+static void
+hostlist_saving_task (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ saving_task = GNUNET_SCHEDULER_NO_TASK;
+ if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
+ return;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Scheduled saving of hostlists\n"));
+ save_hostlist_file ( GNUNET_NO );
+ /*schedule_hostlist_saving_task ();*/
+}
+
+/**
+ * Compute when we should save the hostlist entries the next time;
+ * then schedule the task accordingly.
+ */
+static void
+schedule_hostlist_saving_task ()
+{
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Hostlists will be saved to file again in %llums\n"),
+ (unsigned long long) SAVING_INTERVALL.value);
+ saving_task = GNUNET_SCHEDULER_add_delayed (sched,
+ SAVING_INTERVALL,
+ &hostlist_saving_task,
+ NULL);
+}
/**
* Method called whenever a given peer connects.
"Added hostlist entry eith URI `%s' \n", hostlist->hostlist_uri);
uri = NULL;
counter++;
+ if ( counter >= MAX_NUMBER_HOSTLISTS ) break;
}
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
_("%u hostlist URIs loaded from file\n"), counter);
+ GNUNET_STATISTICS_set (stats,
+ gettext_noop("# hostlis URIs read from file"),
+ counter,
+ GNUNET_YES);
GNUNET_free_non_null (uri);
emsg = NULL;
struct Hostlist *pos;
struct GNUNET_BIO_WriteHandle * wh;
int ok;
+ uint32_t counter;
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
/* add code to write hostlists to file using bio */
ok = GNUNET_YES;
+ counter = 0;
while (NULL != (pos = linked_list_head))
{
if ( GNUNET_YES == shutdown)
ok = GNUNET_NO;
}
}
+
if ( GNUNET_YES == shutdown)
GNUNET_free (pos);
+ counter ++;
+ if ( counter >= MAX_NUMBER_HOSTLISTS) break;
}
+ GNUNET_STATISTICS_set (stats,
+ gettext_noop("# hostlist URIs written to file"),
+ counter,
+ GNUNET_YES);
+
if ( GNUNET_OK != GNUNET_BIO_write_close ( wh ) )
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
_("Error writing hostlist URIs to file `%s'\n"),
linked_list_head = NULL;
linked_list_tail = NULL;
load_hostlist_file ();
+ // schedule_hostlist_saving_task ();
GNUNET_STATISTICS_get (stats,
"hostlist",