/*
This file is part of GNUnet.
- (C) 2001-2010, 2014 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2001-2010, 2014 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
You should have received a copy of the GNU General Public License
along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
*/
/**
* @file hostlist/gnunet-daemon-hostlist_client.c
#include "gnunet_statistics_service.h"
#include "gnunet_transport_service.h"
#include "gnunet-daemon-hostlist.h"
+#if HAVE_CURL_CURL_H
#include <curl/curl.h>
+#elif HAVE_GNURL_CURL_H
+#include <gnurl/curl.h>
+#endif
+
/**
/**
* ID of the task, checking if hostlist download should take plate
*/
-static struct GNUNET_SCHEDULER_Task * ti_check_download;
+static struct GNUNET_SCHEDULER_Task *ti_check_download;
/**
* ID of the task downloading the hostlist
*/
-static struct GNUNET_SCHEDULER_Task * ti_download;
+static struct GNUNET_SCHEDULER_Task *ti_download;
/**
* ID of the task saving the hostlsit in a regular intervall
*/
-static struct GNUNET_SCHEDULER_Task * ti_saving_task;
+static struct GNUNET_SCHEDULER_Task *ti_saving_task;
/**
* ID of the task called to initiate a download
*/
-static struct GNUNET_SCHEDULER_Task * ti_download_dispatcher_task;
+static struct GNUNET_SCHEDULER_Task *ti_download_dispatcher_task;
/**
* ID of the task controlling the locking between two hostlist tests
*/
-static struct GNUNET_SCHEDULER_Task * ti_testing_intervall_task;
+static struct GNUNET_SCHEDULER_Task *ti_testing_intervall_task;
/**
* At what time MUST the current hostlist request be done?
{
CURLMcode mret;
- if ((stat_testing_hostlist == GNUNET_YES) &&
- (GNUNET_NO == stat_download_successful) && (NULL != hostlist_to_test))
+ if ( (stat_testing_hostlist == GNUNET_YES) &&
+ (GNUNET_NO == stat_download_successful) &&
+ (NULL != hostlist_to_test) )
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
_
hostlist_to_test = NULL;
}
- if (multi != NULL)
+ if (NULL != multi)
{
mret = curl_multi_remove_handle (multi, curl);
if (mret != CURLM_OK)
curl_multi_strerror (mret));
multi = NULL;
}
- if (curl != NULL)
+ if (NULL != curl)
{
curl_easy_cleanup (curl);
curl = NULL;
* @param tc task context, unused
*/
static void
-task_download (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+task_download (void *cls);
/**
* server.
*
* @param cls closure, unused
- * @param tc task context, unused
*/
static void
-task_download (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+task_download (void *cls)
{
int running;
struct CURLMsg *msg;
CURLMcode mret;
ti_download = NULL;
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Shutdown requested while trying to download hostlist from `%s'\n",
- current_url);
- update_hostlist ();
- clean_up ();
- return;
- }
if (0 == GNUNET_TIME_absolute_get_remaining (end_time).rel_value_us)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
static void
-task_download_dispatcher (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+task_download_dispatcher (void *cls)
{
ti_download_dispatcher_task = NULL;
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download is initiated...\n");
if (GNUNET_NO == stat_download_in_progress)
{
* this task again for a later time.
*/
static void
-task_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+task_check (void *cls)
{
static int once;
struct GNUNET_TIME_Relative delay;
ti_check_download = NULL;
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
if (stats == NULL)
{
curl_global_cleanup ();
_("Have %u/%u connections. Will consider downloading hostlist in %s\n"),
stat_connection_count, MIN_CONNECTIONS,
GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES));
- ti_check_download = GNUNET_SCHEDULER_add_delayed (delay, &task_check, NULL);
+ ti_check_download = GNUNET_SCHEDULER_add_delayed (delay,
+ &task_check, NULL);
}
* This tasks sets hostlist testing to allowed after intervall between to testings is reached
*
* @param cls closure
- * @param tc TaskContext
*/
static void
-task_testing_intervall_reset (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+task_testing_intervall_reset (void *cls)
{
ti_testing_intervall_task = NULL;
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
stat_testing_allowed = GNUNET_OK;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Testing new hostlist advertisements is allowed again\n");
* Task that writes hostlist entries to a file on a regular base
*
* @param cls closure
- * @param tc TaskContext
*/
static void
-task_hostlist_saving (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+task_hostlist_saving (void *cls)
{
ti_saving_task = NULL;
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
save_hostlist_file (GNUNET_NO);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Hostlists will be saved to file again in %s\n",
GNUNET_STRINGS_relative_time_to_string(SAVING_INTERVAL, GNUNET_YES));
ti_saving_task =
- GNUNET_SCHEDULER_add_delayed (SAVING_INTERVAL, &task_hostlist_saving,
+ GNUNET_SCHEDULER_add_delayed (SAVING_INTERVAL,
+ &task_hostlist_saving,
NULL);
}
* successfully obtained, #GNUNET_SYSERR if not.
*/
static void
-primary_task (void *cls, int success)
+primary_task (void *cls,
+ int success)
{
+ if (NULL != ti_check_download)
+ {
+ GNUNET_SCHEDULER_cancel (ti_check_download);
+ ti_check_download = NULL;
+ }
sget = NULL;
GNUNET_assert (NULL != stats);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
}
+/**
+ * Continuation called by the statistics code once
+ * we go the stat. Initiates hostlist download scheduling.
+ *
+ * @param cls closure
+ * @param success #GNUNET_OK if statistics were
+ * successfully obtained, #GNUNET_SYSERR if not.
+ */
+static void
+stat_timeout_task (void *cls)
+{
+ GNUNET_STATISTICS_get_cancel (sget);
+ sget = NULL;
+ ti_check_download = GNUNET_SCHEDULER_add_now (&task_check,
+ NULL);
+}
+
+
/**
* We've received the previous delay value from statistics. Remember it.
*
sget = GNUNET_STATISTICS_get (stats, "hostlist",
gettext_noop
("# milliseconds between hostlist downloads"),
- GNUNET_TIME_UNIT_MINUTES,
&primary_task,
&process_stat,
NULL);
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Statistics request failed, scheduling hostlist download\n");
- ti_check_download = GNUNET_SCHEDULER_add_now (&task_check, NULL);
+ ti_check_download = GNUNET_SCHEDULER_add_now (&task_check,
+ NULL);
+ }
+ else
+ {
+ ti_check_download = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
+ &stat_timeout_task,
+ NULL);
}
return GNUNET_OK;
}
void
GNUNET_HOSTLIST_client_stop ()
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist client shutdown\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Hostlist client shutdown\n");
if (NULL != sget)
{
GNUNET_STATISTICS_get_cancel (sget);
stats = NULL;
if (GNUNET_YES == stat_learning)
save_hostlist_file (GNUNET_YES);
- if (ti_saving_task != NULL)
+ if (NULL != ti_saving_task)
{
GNUNET_SCHEDULER_cancel (ti_saving_task);
ti_saving_task = NULL;
}
-
- if (ti_download_dispatcher_task != NULL)
+ if (NULL != ti_download_dispatcher_task)
{
GNUNET_SCHEDULER_cancel (ti_download_dispatcher_task);
ti_download_dispatcher_task = NULL;
}
- if (ti_testing_intervall_task != NULL)
+ if (NULL != ti_testing_intervall_task)
{
GNUNET_SCHEDULER_cancel (ti_testing_intervall_task);
ti_testing_intervall_task = NULL;
}
- if (ti_download != NULL)
+ if (NULL != ti_download)
{
GNUNET_SCHEDULER_cancel (ti_download);
ti_download = NULL;
+ update_hostlist ();
+ clean_up ();
}
- if (ti_check_download != NULL)
+ if (NULL != ti_check_download)
{
GNUNET_SCHEDULER_cancel (ti_check_download);
ti_check_download = NULL;