#include "gnunet_common.h"
#include "gnunet_bio_lib.h"
-#define DEBUG_HOSTLIST_CLIENT GNUNET_EXTRA_LOGGING
-
/**
* Number of connections that we must have to NOT download
*/
static struct Hostlist *hostlist_to_test;
+/**
+ * Handle for our statistics GET operation.
+ */
+static struct GNUNET_STATISTICS_GetHandle *sget;
+
/**
* Set to GNUNET_YES if the current URL had some problems.
*/
left -= cpy;
if (download_pos < sizeof (struct GNUNET_MessageHeader))
{
- GNUNET_assert (left == 0);
+ GNUNET_assert (0 == left);
break;
}
msg = (const struct GNUNET_MessageHeader *) download_buffer;
}
if (GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *) msg) == msize)
{
-#if DEBUG_HOSTLIST_CLIENT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received valid `%s' message from hostlist server.\n",
"HELLO");
-#endif
GNUNET_STATISTICS_update (stats,
gettext_noop
("# valid HELLOs downloaded from hostlist servers"),
GNUNET_CONFIGURATION_get_value_string (cfg, "HOSTLIST", "SERVERS",
&servers))
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _
- ("No `%s' specified in `%s' configuration, will not bootstrap.\n"),
- "SERVERS", "HOSTLIST");
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING,
+ "hostlist", "SERVERS");
return NULL;
}
}
if (urls == 0)
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _
- ("No `%s' specified in `%s' configuration, will not bootstrap.\n"),
- "SERVERS", "HOSTLIST");
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING,
+ "hostlist", "SERVERS");
GNUNET_free (servers);
return NULL;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Testing new advertised hostlist if it is obtainable\n");
current_hostlist = hostlist_to_test;
- return strdup (hostlist_to_test->hostlist_uri);
+ return GNUNET_strdup (hostlist_to_test->hostlist_uri);
}
if ((GNUNET_YES == stat_use_bootstrap) || (linked_list_size == 0))
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using learned hostlist `%s'\n",
pos->hostlist_uri);
current_hostlist = pos;
- return strdup (pos->hostlist_uri);
+ return GNUNET_strdup (pos->hostlist_uri);
}
-#define CURL_EASY_SETOPT(c, a, b) do { ret = curl_easy_setopt(c, a, b); if (ret != CURLE_OK) GNUNET_log(GNUNET_ERROR_TYPE_WARNING, _("%s failed at %s:%d: `%s'\n"), "curl_easy_setopt", __FILE__, __LINE__, curl_easy_strerror(ret)); } while (0)
+#define CURL_EASY_SETOPT(c, a, b) do { ret = curl_easy_setopt (c, a, b); if (CURLE_OK != ret) GNUNET_log(GNUNET_ERROR_TYPE_WARNING, _("%s failed at %s:%d: `%s'\n"), "curl_easy_setopt", __FILE__, __LINE__, curl_easy_strerror (ret)); } while (0)
/**
temp = val1 + val2;
if (temp < val1)
return maxv;
- else
- return temp;
+ return temp;
}
+
/**
* Subtract val2 from val1 with underflow check
* @param val1 value 1
{
if (val1 <= val2)
return 0;
- else
- return (val1 - val2);
+ return (val1 - val2);
}
+
/**
* Method to check if a URI is in hostlist linked list
* @param uri uri to check
stat_use_bootstrap = GNUNET_YES;
}
+
/**
* Clean up the state from the task that downloaded the
* hostlist and schedule the next task.
gws = GNUNET_NETWORK_fdset_create ();
GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1);
GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1);
-#if DEBUG_HOSTLIST_CLIENT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Scheduling task for hostlist download using cURL\n");
-#endif
ti_download =
GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
- GNUNET_SCHEDULER_NO_TASK, rtime, grs, gws,
+ rtime, grs, gws,
&task_download, multi);
GNUNET_NETWORK_fdset_destroy (gws);
GNUNET_NETWORK_fdset_destroy (grs);
ti_download = GNUNET_SCHEDULER_NO_TASK;
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
{
-#if DEBUG_HOSTLIST_CLIENT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Shutdown requested while trying to download hostlist from `%s'\n",
current_url);
-#endif
update_hostlist ();
clean_up ();
return;
clean_up ();
return;
}
-#if DEBUG_HOSTLIST_CLIENT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Ready for processing hostlist client request\n");
-#endif
-
do
{
running = 0;
case CURLMSG_DONE:
if ((msg->data.result != CURLE_OK) &&
(msg->data.result != CURLE_GOT_NOTHING))
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("%s failed for `%s' at %s:%d: `%s'\n"),
- "curl_multi_perform", current_url, __FILE__, __LINE__,
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Download of hostlist from `%s' failed: `%s'\n"),
+ current_url,
curl_easy_strerror (msg->data.result));
else
{
return;
}
CURL_EASY_SETOPT (curl, CURLOPT_FOLLOWLOCATION, 1);
+ CURL_EASY_SETOPT (curl, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
+ CURL_EASY_SETOPT (curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
CURL_EASY_SETOPT (curl, CURLOPT_MAXREDIRS, 4);
/* no need to abort if the above failed */
CURL_EASY_SETOPT (curl, CURLOPT_URL, current_url);
}
}
+
/**
* Task that checks if we should try to download a hostlist.
* If so, we initiate the download, otherwise we schedule
ti_check_download = GNUNET_SCHEDULER_NO_TASK;
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
return;
-
- if (stat_connection_count < MIN_CONNECTIONS)
- {
- ti_download_dispatcher_task =
- GNUNET_SCHEDULER_add_now (&task_download_dispatcher, NULL);
- }
-
if (stats == NULL)
{
curl_global_cleanup ();
return; /* in shutdown */
}
+ if ( (stat_connection_count < MIN_CONNECTIONS) &&
+ (GNUNET_SCHEDULER_NO_TASK == ti_download_dispatcher_task) )
+ ti_download_dispatcher_task =
+ GNUNET_SCHEDULER_add_now (&task_download_dispatcher, NULL);
+
delay = hostlist_delay;
if (hostlist_delay.rel_value == 0)
hostlist_delay = GNUNET_TIME_UNIT_SECONDS;
once = 1;
}
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _
- ("Have %u/%u connections. Will consider downloading hostlist in %llums\n"),
+ _("Have %u/%u connections. Will consider downloading hostlist in %s\n"),
stat_connection_count, MIN_CONNECTIONS,
- (unsigned long long) delay.rel_value);
+ GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES));
ti_check_download = GNUNET_SCHEDULER_add_delayed (delay, &task_check, NULL);
}
ti_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);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Hostlists will be saved to file again in %llums\n"),
- (unsigned long long) SAVING_INTERVALL.rel_value);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Hostlists will be saved to file again in %s\n",
+ GNUNET_STRINGS_relative_time_to_string(SAVING_INTERVALL, GNUNET_YES));
ti_saving_task =
GNUNET_SCHEDULER_add_delayed (SAVING_INTERVALL, &task_hostlist_saving,
NULL);
* @param cls closure
* @param peer peer identity this notification is about
* @param atsi performance data
+ * @param atsi_count number of records in 'atsi'
*/
static void
handler_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+ const struct GNUNET_ATS_Information *atsi,
+ unsigned int atsi_count)
{
GNUNET_assert (stat_connection_count < UINT_MAX);
stat_connection_count++;
* @param peer the peer sending the message
* @param message the actual message
* @param atsi performance data
+ * @param atsi_count number of records in 'atsi'
* @return GNUNET_OK to keep the connection open,
* GNUNET_SYSERR to close it (signal serious error)
*/
static int
handler_advertisement (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+ const struct GNUNET_ATS_Information *atsi,
+ unsigned int atsi_count)
{
size_t size;
size_t uri_size;
hostlist->hostlist_uri = (const char *) &hostlist[1];
memcpy (&hostlist[1], uri, uri_size);
hostlist->time_creation = GNUNET_TIME_absolute_get ();
- hostlist->time_last_usage = GNUNET_TIME_absolute_get_zero ();
hostlist->quality = HOSTLIST_INITIAL;
hostlist_to_test = hostlist;
}
-
/**
* Continuation called by the statistics code once
* we go the stat. Initiates hostlist download scheduling.
static void
primary_task (void *cls, int success)
{
- if (stats == NULL)
- return; /* in shutdown */
-#if DEBUG_HOSTLIST_CLIENT
+ sget = NULL;
+ GNUNET_assert (stats != NULL);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Statistics request done, scheduling hostlist download\n");
-#endif
ti_check_download = GNUNET_SCHEDULER_add_now (&task_check, NULL);
}
process_stat (void *cls, const char *subsystem, const char *name,
uint64_t value, int is_persistent)
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Initial time between hostlist downloads is %llums\n"),
- (unsigned long long) value);
hostlist_delay.rel_value = value;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Initial time between hostlist downloads is %s\n",
+ GNUNET_STRINGS_relative_time_to_string (hostlist_delay, GNUNET_YES));
return GNUNET_OK;
}
+
/**
* Method to load persistent hostlist file during hostlist client startup
*/
GNUNET_CONFIGURATION_get_value_filename (cfg, "HOSTLIST", "HOSTLISTFILE",
&filename))
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _
- ("No `%s' specified in `%s' configuration, cannot load hostlists from file.\n"),
- "HOSTLISTFILE", "HOSTLIST");
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING,
+ "hostlist", "HOSTLISTFILE");
return;
}
if (GNUNET_NO == GNUNET_DISK_file_test (filename))
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Hostlist file `%s' is not existing\n"), filename);
+ _("Hostlist file `%s' does not exist\n"), filename);
GNUNET_free (filename);
return;
}
GNUNET_free_non_null (uri);
emsg = NULL;
- GNUNET_BIO_read_close (rh, &emsg);
+ (void) GNUNET_BIO_read_close (rh, &emsg);
if (emsg != NULL)
GNUNET_free (emsg);
GNUNET_free (filename);
GNUNET_CONFIGURATION_get_value_filename (cfg, "HOSTLIST", "HOSTLISTFILE",
&filename))
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _
- ("No `%s' specified in `%s' configuration, cannot save hostlists to file.\n"),
- "HOSTLISTFILE", "HOSTLIST");
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING,
+ "hostlist", "HOSTLISTFILE");
return;
}
if (GNUNET_SYSERR == GNUNET_DISK_directory_create_for_file (filename))
GNUNET_free (filename);
}
+
/**
* Start downloading hostlists from hostlist servers as necessary.
*/
char *filename;
int result;
+ GNUNET_assert (NULL != st);
if (0 != curl_global_init (CURL_GLOBAL_WIN32))
{
GNUNET_break (0);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
_("Learning is enabled on this peer\n"));
load_hostlist_file ();
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Hostlists will be saved to file again in %llums\n"),
- (unsigned long long) SAVING_INTERVALL.rel_value);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Hostlists will be saved to file again in %s\n",
+ GNUNET_STRINGS_relative_time_to_string (SAVING_INTERVALL, GNUNET_YES));
ti_saving_task =
GNUNET_SCHEDULER_add_delayed (SAVING_INTERVALL, &task_hostlist_saving,
NULL);
}
GNUNET_free (filename);
}
- GNUNET_STATISTICS_get (stats, "hostlist",
- gettext_noop
- ("# milliseconds between hostlist downloads"),
- GNUNET_TIME_UNIT_MINUTES, &primary_task, &process_stat,
- NULL);
+ sget = GNUNET_STATISTICS_get (stats, "hostlist",
+ gettext_noop
+ ("# milliseconds between hostlist downloads"),
+ GNUNET_TIME_UNIT_MINUTES, &primary_task, &process_stat,
+ NULL);
return GNUNET_OK;
}
GNUNET_HOSTLIST_client_stop ()
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist client shutdown\n");
-#if DEBUG_HOSTLIST_CLIENT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist client shutdown\n");
-#endif
+ if (NULL != sget)
+ {
+ GNUNET_STATISTICS_get_cancel (sget);
+ sget = NULL;
+ }
+ stats = NULL;
if (GNUNET_YES == stat_learning)
save_hostlist_file (GNUNET_YES);
-
if (ti_saving_task != GNUNET_SCHEDULER_NO_TASK)
{
GNUNET_SCHEDULER_cancel (ti_saving_task);
+ ti_saving_task = GNUNET_SCHEDULER_NO_TASK;
}
if (ti_download_dispatcher_task != GNUNET_SCHEDULER_NO_TASK)
- {
+ {
GNUNET_SCHEDULER_cancel (ti_download_dispatcher_task);
+ ti_download_dispatcher_task = GNUNET_SCHEDULER_NO_TASK;
}
if (ti_testing_intervall_task != GNUNET_SCHEDULER_NO_TASK)
{
GNUNET_SCHEDULER_cancel (ti_testing_intervall_task);
+ ti_testing_intervall_task = GNUNET_SCHEDULER_NO_TASK;
}
if (ti_download != GNUNET_SCHEDULER_NO_TASK)
{
GNUNET_SCHEDULER_cancel (ti_download);
+ ti_download = GNUNET_SCHEDULER_NO_TASK;
}
if (ti_check_download != GNUNET_SCHEDULER_NO_TASK)
{
GNUNET_SCHEDULER_cancel (ti_check_download);
+ ti_check_download = GNUNET_SCHEDULER_NO_TASK;
curl_global_cleanup ();
}
if (transport != NULL)
GNUNET_TRANSPORT_disconnect (transport);
transport = NULL;
}
- GNUNET_assert (NULL == transport);
GNUNET_free_non_null (proxy);
proxy = NULL;
cfg = NULL;