gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r9975 - gnunet/src/hostlist
Date: Mon, 11 Jan 2010 12:10:45 +0100

Author: grothoff
Date: 2010-01-11 12:10:45 +0100 (Mon, 11 Jan 2010)
New Revision: 9975

Modified:
   gnunet/src/hostlist/gnunet-daemon-hostlist.c
   gnunet/src/hostlist/hostlist-client.c
   gnunet/src/hostlist/hostlist-server.c
Log:
complete startup / shutdown code

Modified: gnunet/src/hostlist/gnunet-daemon-hostlist.c
===================================================================
--- gnunet/src/hostlist/gnunet-daemon-hostlist.c        2010-01-11 11:10:30 UTC 
(rev 9974)
+++ gnunet/src/hostlist/gnunet-daemon-hostlist.c        2010-01-11 11:10:45 UTC 
(rev 9975)
@@ -118,6 +118,8 @@
 static void
 cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "Hostlist daemon is shutting down.\n");
   if (bootstrapping)
     {
       GNUNET_HOSTLIST_client_stop ();
@@ -126,7 +128,11 @@
     {      
       GNUNET_HOSTLIST_server_stop ();
     }
-  GNUNET_CORE_disconnect (core);
+  if (core != NULL)
+    {
+      GNUNET_CORE_disconnect (core);
+      core = NULL;
+    }
   if (stats != NULL)
     {
       GNUNET_STATISTICS_destroy (stats,

Modified: gnunet/src/hostlist/hostlist-client.c
===================================================================
--- gnunet/src/hostlist/hostlist-client.c       2010-01-11 11:10:30 UTC (rev 
9974)
+++ gnunet/src/hostlist/hostlist-client.c       2010-01-11 11:10:45 UTC (rev 
9975)
@@ -551,6 +551,8 @@
 {
   struct GNUNET_TIME_Relative delay;
 
+  if (stats == NULL)
+    return; /* in shutdown */
   delay = hostlist_delay;
   if (hostlist_delay.value == 0)
     hostlist_delay = GNUNET_TIME_UNIT_SECONDS;
@@ -611,6 +613,8 @@
 static void
 primary_task (void *cls, int success)
 {
+  if (stats == NULL)
+    return; /* in shutdown */
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Statistics request done, scheduling hostlist download\n");
   schedule_hostlist_task ();
@@ -684,6 +688,7 @@
     curl_global_cleanup ();
   cfg = NULL;
   sched = NULL;
+  stats = NULL;
 }
 
 /* end of hostlist-client.c */

Modified: gnunet/src/hostlist/hostlist-server.c
===================================================================
--- gnunet/src/hostlist/hostlist-server.c       2010-01-11 11:10:30 UTC (rev 
9974)
+++ gnunet/src/hostlist/hostlist-server.c       2010-01-11 11:10:45 UTC (rev 
9975)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2008 Christian Grothoff (and other contributing authors)
+     (C) 2008, 2009, 2010 Christian Grothoff (and other contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -56,6 +56,11 @@
 static GNUNET_SCHEDULER_TaskIdentifier hostlist_task;
 
 /**
+ * Task that updates our HTTP response.
+ */
+static GNUNET_SCHEDULER_TaskIdentifier response_task;
+
+/**
  * Our canonical response.
  */
 static struct MHD_Response *response;
@@ -85,16 +90,29 @@
 static void
 finish_response (struct HostSet *results)
 {
+  struct GNUNET_TIME_Relative freq;
+  
   if (response != NULL)
     MHD_destroy_response (response);
   response = MHD_create_response_from_data (results->size,
                                             results->data, MHD_YES, MHD_NO);
+  if (daemon_handle != NULL)
+    {
+      freq = RESPONSE_UPDATE_FREQUENCY;
+      if (results->size == 0)
+       freq = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 
50);
+      /* schedule next update of the response */  
+      response_task = GNUNET_SCHEDULER_add_delayed (sched,
+                                                   freq,
+                                                   &update_response,
+                                                   NULL);
+    }
+  else
+    {
+      MHD_destroy_response (response);
+      response = NULL;
+    }
   GNUNET_free (results);
-  /* schedule next update of the response */  
-  GNUNET_SCHEDULER_add_delayed (sched,
-                               RESPONSE_UPDATE_FREQUENCY,
-                               &update_response,
-                               NULL);
 }
 
 
@@ -137,6 +155,7 @@
 {
   struct HostSet *results;
 
+  response_task = GNUNET_SCHEDULER_NO_TASK;
   results = GNUNET_malloc(sizeof(struct HostSet));
   GNUNET_PEERINFO_for_all (cfg, sched, 
                           NULL,
@@ -157,6 +176,12 @@
 accept_policy_callback (void *cls,
                         const struct sockaddr *addr, socklen_t addrlen)
 {
+  if (NULL == response)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                 "Received request for hostlist, but I am not yet ready; 
rejecting!\n");
+      return MHD_NO;
+    }
   return MHD_YES;               /* accept all */
 }
 
@@ -309,6 +334,9 @@
       return GNUNET_SYSERR;    
     }
   prepare_daemon ();
+  response_task = GNUNET_SCHEDULER_add_now (sched,
+                                           &update_response,
+                                           NULL);
   return GNUNET_OK;
 }
 
@@ -318,10 +346,26 @@
 void
 GNUNET_HOSTLIST_server_stop ()
 {
-  GNUNET_SCHEDULER_cancel (sched, hostlist_task);
-  hostlist_task = GNUNET_SCHEDULER_NO_TASK;
-  MHD_stop_daemon (daemon_handle);
-  daemon_handle = NULL;
+  if (GNUNET_SCHEDULER_NO_TASK != hostlist_task)
+    {
+      GNUNET_SCHEDULER_cancel (sched, hostlist_task);
+      hostlist_task = GNUNET_SCHEDULER_NO_TASK;
+    }
+  if (GNUNET_SCHEDULER_NO_TASK != response_task)
+    {
+      GNUNET_SCHEDULER_cancel (sched, response_task);
+      response_task = GNUNET_SCHEDULER_NO_TASK;
+    }
+  if (NULL != daemon_handle)
+    {
+      MHD_stop_daemon (daemon_handle);
+      daemon_handle = NULL;
+    }
+  if (response != NULL)
+    {
+      MHD_destroy_response (response);
+      response = NULL;
+    }
 }
 
 /* end of hostlist-server.c */





reply via email to

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