#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.
*/
}
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"),
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,
rtime, grs, gws,
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;
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;
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);
}
}
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;
#include "gnunet-daemon-hostlist.h"
#include "gnunet_resolver_service.h"
-#define DEBUG_HOSTLIST_SERVER GNUNET_EXTRA_LOGGING
/**
* Handle to the HTTP server as provided by libmicrohttpd for IPv6.
{
if (response != NULL)
MHD_destroy_response (response);
-#if DEBUG_HOSTLIST_SERVER
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Creating hostlist response with %u bytes\n",
(unsigned int) results->size);
-#endif
response =
MHD_create_response_from_data (results->size, results->data, MHD_YES,
MHD_NO);
}
old = results->size;
s = GNUNET_HELLO_size (hello);
-#if DEBUG_HOSTLIST_SERVER
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received %u bytes of `%s' from peer `%s' for hostlist.\n",
(unsigned int) s, "HELLO", GNUNET_i2s (peer));
-#endif
if ((old + s >= GNUNET_MAX_MALLOC_CHECKED) ||
(old + s >= MAX_BYTES_PER_HOSTLISTS))
{
s, GNUNET_NO);
return; /* too large, skip! */
}
-#if DEBUG_HOSTLIST_SERVER
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Adding peer `%s' to hostlist (%u bytes)\n", GNUNET_i2s (peer),
(unsigned int) s);
-#endif
GNUNET_array_grow (results->data, results->size, old + s);
memcpy (&results->data[old], hello, s);
}
{
if (NULL == response)
{
-#if DEBUG_HOSTLIST_SERVER
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received request for hostlist, but I am not yet ready; rejecting!\n");
-#endif
return MHD_NO;
}
return MHD_YES; /* accept all */
if (NULL == *con_cls)
{
(*con_cls) = &dummy;
-#if DEBUG_HOSTLIST_SERVER
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Sending 100 CONTINUE reply\n"));
-#endif
return MHD_YES; /* send 100 continue */
}
if (*upload_data_size != 0)
{
struct HostSet *results;
-#if DEBUG_HOSTLIST_SERVER
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Peerinfo is notifying us to rebuild our hostlist\n");
-#endif
if (err_msg != NULL)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
}
-
/**
* Start server offering our hostlist.
*
else
sa = NULL;
- daemon_handle_v6 = MHD_start_daemon (MHD_USE_IPv6
-#if DEBUG_HOSTLIST_SERVER
- | MHD_USE_DEBUG
-#endif
- , (unsigned short) port,
+ daemon_handle_v6 = MHD_start_daemon (MHD_USE_IPv6 | MHD_USE_DEBUG,
+ (uint16_t) port,
&accept_policy_callback, NULL,
&access_handler_callback, NULL,
MHD_OPTION_CONNECTION_LIMIT,
MHD_OPTION_SOCK_ADDR,
sa,
MHD_OPTION_END);
- daemon_handle_v4 = MHD_start_daemon (MHD_NO_FLAG
-#if DEBUG_HOSTLIST_SERVER
- | MHD_USE_DEBUG
-#endif
- , (unsigned short) port,
+ daemon_handle_v4 = MHD_start_daemon (MHD_NO_FLAG | MHD_USE_DEBUG,
+ (uint16_t) port,
&accept_policy_callback, NULL,
&access_handler_callback, NULL,
MHD_OPTION_CONNECTION_LIMIT,
}
core = co;
-
*server_ch = &connect_handler;
*server_dh = &disconnect_handler;
-
if (daemon_handle_v4 != NULL)
hostlist_task_v4 = prepare_daemon (daemon_handle_v4);
if (daemon_handle_v6 != NULL)
return GNUNET_OK;
}
+
/**
* Stop server offering our hostlist.
*/
void
GNUNET_HOSTLIST_server_stop ()
{
-#if DEBUG_HOSTLIST_SERVER
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist server shutdown\n");
-#endif
if (NULL != notify)
{
GNUNET_PEERINFO_notify_cancel (notify);