gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r21130 - gnunet/src/hostlist


From: gnunet
Subject: [GNUnet-SVN] r21130 - gnunet/src/hostlist
Date: Tue, 24 Apr 2012 14:47:02 +0200

Author: grothoff
Date: 2012-04-24 14:47:02 +0200 (Tue, 24 Apr 2012)
New Revision: 21130

Modified:
   gnunet/src/hostlist/hostlist-client.c
   gnunet/src/hostlist/hostlist-server.c
Log:
-fixing shutdown sequence

Modified: gnunet/src/hostlist/hostlist-client.c
===================================================================
--- gnunet/src/hostlist/hostlist-client.c       2012-04-24 12:41:20 UTC (rev 
21129)
+++ gnunet/src/hostlist/hostlist-client.c       2012-04-24 12:47:02 UTC (rev 
21130)
@@ -36,9 +36,7 @@
 #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
  * hostlists anymore.
@@ -209,6 +207,11 @@
 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.
  */
 static int stat_bogus_url;
@@ -320,11 +323,9 @@
     }
     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"),
@@ -760,10 +761,8 @@
   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,
@@ -790,11 +789,9 @@
   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;
@@ -808,11 +805,8 @@
     clean_up ();
     return;
   }
-#if DEBUG_HOSTLIST_CLIENT
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Ready for processing hostlist client request\n");
-#endif
-
   do
   {
     running = 0;
@@ -1018,18 +1012,16 @@
   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;
@@ -1235,12 +1227,10 @@
 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);
 }
 
@@ -1510,11 +1500,11 @@
     }
     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;
 }
 
@@ -1526,32 +1516,39 @@
 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)
@@ -1559,7 +1556,6 @@
     GNUNET_TRANSPORT_disconnect (transport);
     transport = NULL;
   }
-  GNUNET_assert (NULL == transport);
   GNUNET_free_non_null (proxy);
   proxy = NULL;
   cfg = NULL;

Modified: gnunet/src/hostlist/hostlist-server.c
===================================================================
--- gnunet/src/hostlist/hostlist-server.c       2012-04-24 12:41:20 UTC (rev 
21129)
+++ gnunet/src/hostlist/hostlist-server.c       2012-04-24 12:47:02 UTC (rev 
21130)
@@ -32,7 +32,6 @@
 #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.
@@ -118,11 +117,9 @@
 {
   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);
@@ -208,11 +205,9 @@
   }
   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))
   {
@@ -222,11 +217,9 @@
                               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);
 }
@@ -242,10 +235,8 @@
 {
   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 */
@@ -276,9 +267,7 @@
   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)
@@ -426,10 +415,8 @@
 {
   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,
@@ -521,7 +508,6 @@
 }
 
 
-
 /**
  * Start server offering our hostlist.
  *
@@ -639,11 +625,8 @@
   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,
@@ -657,11 +640,8 @@
                                        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,
@@ -685,10 +665,8 @@
   }
 
   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)
@@ -699,15 +677,14 @@
   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);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]