added methods to load and write hostfiles
authorMatthias Wachs <wachs@net.in.tum.de>
Tue, 13 Apr 2010 12:56:48 +0000 (12:56 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Tue, 13 Apr 2010 12:56:48 +0000 (12:56 +0000)
src/hostlist/hostlist-client.c
src/hostlist/learning_peer2.conf

index 9e86053fc3afbe7ecfd2779c774166edfbf69e09..78eb8acaa97c1043a1051e3b142b9dec9fad60f2 100644 (file)
@@ -787,6 +787,51 @@ process_stat (void *cls,
   return GNUNET_OK;
 }
 
+/**
+ * Method to load persistent hostlist file during hostlist client startup
+ * param c configuration to use
+ */
+static int load_hostlist_file ()
+{
+  char *servers;
+
+  if (GNUNET_OK !=
+      GNUNET_CONFIGURATION_get_value_string (cfg,
+                                             "HOSTLIST",
+                                             "HOSTLISTFILE",
+                                             &servers))
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                  _("No `%s' specified in `%s' configuration, cannot load hostlists from file.\n"),
+                  "HOSTLISTFILE", "HOSTLIST");
+      return GNUNET_SYSERR;
+    }
+  return GNUNET_OK;
+}
+
+/**
+ * Method to load persistent hostlist file during hostlist client shutdown
+ * param c configuration to use
+ */
+static int save_hostlist_file ()
+{
+  char *servers;
+
+  if (GNUNET_OK !=
+      GNUNET_CONFIGURATION_get_value_string (cfg,
+                                             "HOSTLIST",
+                                             "HOSTLISTFILE",
+                                             &servers))
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                  _("No `%s' specified in `%s' configuration, cannot save hostlist to file.\n"),
+                  "HOSTLISTFILE", "HOSTLIST");
+      return GNUNET_SYSERR;
+    }
+
+
+  return GNUNET_OK;
+}
 
 /**
  * Start downloading hostlists from hostlist servers as necessary.
@@ -822,6 +867,9 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c,
   *ch = &connect_handler;
   *dh = &disconnect_handler;
   *msgh = &advertisement_handler;
+
+  load_hostlist_file ();
+
   GNUNET_STATISTICS_get (stats,
                         "hostlist",
                         gettext_noop("# seconds between hostlist downloads"),
@@ -843,6 +891,8 @@ GNUNET_HOSTLIST_client_stop ()
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Hostlist client shutdown\n");
 #endif
+  save_hostlist_file ();
+
   if (current_task != GNUNET_SCHEDULER_NO_TASK)
     {
       GNUNET_SCHEDULER_cancel (sched,
index dc1216a86d3a2b741fe5331c9a83e7e2d2426b27..6d109455e0035243dfd99ee25b334f7e7918b3cf 100644 (file)
@@ -36,7 +36,7 @@ WEAKRANDOM = YES
 [hostlist]
 HTTPPORT = 12981
 SERVERS = http://localhost:12980/
-OPTIONS = -b -p -e -a
+OPTIONS = -b -p -e
 DEBUG = YES
 #BINARY = /home/grothoff/bin/gnunet-daemon-hostlist