From 6551b2bcb1207c3c8796859783b31c5388d0f719 Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Fri, 23 Apr 2010 11:04:42 +0000 Subject: [PATCH] --- src/hostlist/hostlist-client.c | 48 +++++++++++++++++++++++++++++++--- src/hostlist/hostlist-client.h | 1 + 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/src/hostlist/hostlist-client.c b/src/hostlist/hostlist-client.c index 384c49809..5d3da4864 100644 --- a/src/hostlist/hostlist-client.c +++ b/src/hostlist/hostlist-client.c @@ -212,6 +212,8 @@ static int testing_hostlist; static int testing_allowed; +static int download_in_progress; + /** * Value saying if preconfigured is used */ @@ -689,7 +691,7 @@ clean_up () GNUNET_free_non_null (current_url); current_url = NULL; - schedule_hostlist_task (); + download_in_progress = GNUNET_NO; } /** @@ -894,6 +896,8 @@ download_hostlist () CURLcode ret; CURLMcode mret; + download_in_progress = GNUNET_YES; + current_url = get_list_url (); if (current_url == NULL) return; @@ -999,6 +1003,29 @@ download_hostlist () } +static void +download_dispatcher (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Download is initiated...\n"); + if ( GNUNET_NO == download_in_progress ) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Download can start immediately...\n"); + download_hostlist(); + } + else + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Download in progess, have to wait...\n"); + GNUNET_SCHEDULER_add_delayed (sched, + WAITING_INTERVALL, + &download_dispatcher, + NULL); + } +} + /** * Task that checks if we should try to download a hostlist. * If so, we initiate the download, otherwise we schedule @@ -1011,8 +1038,15 @@ check_task (void *cls, current_task = GNUNET_SCHEDULER_NO_TASK; if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) return; + /*if ( GNUNET_YES == testing_hostlist ) + download_hostlist();*/ if (connection_count < MIN_CONNECTIONS) - download_hostlist (); + { + GNUNET_SCHEDULER_add_now (sched, + &download_dispatcher, + NULL); + schedule_hostlist_task (); + } else schedule_hostlist_task (); } @@ -1142,7 +1176,6 @@ disconnect_handler (void *cls, GNUNET_NO); } - /** * Method called whenever an advertisement message arrives. * @@ -1194,7 +1227,7 @@ advertisement_handler (void *cls, return GNUNET_OK; } - if ( GNUNET_YES == testing_hostlist ) + if ( (GNUNET_YES == testing_hostlist) || ( GNUNET_NO == testing_allowed) ) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Currently not accepting adverts\n"); @@ -1215,9 +1248,16 @@ advertisement_handler (void *cls, TESTING_INTERVALL, &testing_intervall_reset, NULL); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing new hostlist advertisements is locked for the next %u seconds\n", TESTING_INTERVALL); + + /* initiate download */ + testing_intervall_task = GNUNET_SCHEDULER_add_now (sched, + &download_dispatcher, + NULL); + return GNUNET_OK; } diff --git a/src/hostlist/hostlist-client.h b/src/hostlist/hostlist-client.h index 4d0a505ab..745187f7c 100644 --- a/src/hostlist/hostlist-client.h +++ b/src/hostlist/hostlist-client.h @@ -36,6 +36,7 @@ #define MAX_HELLO_PER_HOSTLISTS 0 #define SAVING_INTERVALL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30) #define TESTING_INTERVALL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3) +#define WAITING_INTERVALL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) /* * Defines concerning the hostlist quality metric -- 2.25.1