From 6ba13deb812b0b55ae5c34de044ad4bf6cb7835d Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Tue, 13 Apr 2010 12:56:48 +0000 Subject: added methods to load and write hostfiles --- src/hostlist/hostlist-client.c | 50 ++++++++++++++++++++++++++++++++++++++++ src/hostlist/learning_peer2.conf | 2 +- 2 files changed, 51 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/hostlist/hostlist-client.c b/src/hostlist/hostlist-client.c index 9e86053fc..78eb8acaa 100644 --- a/src/hostlist/hostlist-client.c +++ b/src/hostlist/hostlist-client.c @@ -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, diff --git a/src/hostlist/learning_peer2.conf b/src/hostlist/learning_peer2.conf index dc1216a86..6d109455e 100644 --- a/src/hostlist/learning_peer2.conf +++ b/src/hostlist/learning_peer2.conf @@ -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 -- cgit v1.2.3