gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r26382 - gnunet/src/testbed


From: gnunet
Subject: [GNUnet-SVN] r26382 - gnunet/src/testbed
Date: Mon, 11 Mar 2013 16:11:38 +0100

Author: harsha
Date: 2013-03-11 16:11:37 +0100 (Mon, 11 Mar 2013)
New Revision: 26382

Modified:
   gnunet/src/testbed/gnunet-service-testbed.c
Log:
- fix crash after handling SHUTDOWN_PEERS due to forwarded operations using 
`GST_peer_list'


Modified: gnunet/src/testbed/gnunet-service-testbed.c
===================================================================
--- gnunet/src/testbed/gnunet-service-testbed.c 2013-03-11 14:51:21 UTC (rev 
26381)
+++ gnunet/src/testbed/gnunet-service-testbed.c 2013-03-11 15:11:37 UTC (rev 
26382)
@@ -29,6 +29,25 @@
 #include <zlib.h>
 
 
+/**
+ * Context data for GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS handler
+ */
+struct HandlerContext_ShutdownPeers
+{
+  /**
+   * The number of slave we expect to hear from since we forwarded the
+   * GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS message to them
+   */
+  unsigned int nslaves;
+
+  /**
+   * Did we observe a timeout with respect to this operation at any of the
+   * slaves
+   */
+  int timeout;
+};
+
+
 /***********/
 /* Globals */
 /***********/
@@ -1973,24 +1992,51 @@
 
 
 /**
- * Context data for GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS handler
+ * Clears the forwarded operations queue
  */
-struct HandlerContext_ShutdownPeers
+static void
+clear_fopcq ()
 {
-  /**
-   * The number of slave we expect to hear from since we forwarded the
-   * GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS message to them
-   */
-  unsigned int nslaves;
+  struct ForwardedOperationContext *fopc;
+  
+  while (NULL != (fopc = fopcq_head))
+  {
+    GNUNET_CONTAINER_DLL_remove (fopcq_head, fopcq_tail, fopc);
+    GNUNET_TESTBED_forward_operation_msg_cancel_ (fopc->opc);
+    if (GNUNET_SCHEDULER_NO_TASK != fopc->timeout_task)
+      GNUNET_SCHEDULER_cancel (fopc->timeout_task);
+    GNUNET_SERVER_client_drop (fopc->client);
+    switch (fopc->type)
+    {
+    case OP_PEER_CREATE:
+      GNUNET_free (fopc->cls);
+      break;
+    case OP_SHUTDOWN_PEERS:
+      {
+        struct HandlerContext_ShutdownPeers *hc = fopc->cls;
+        
+        GNUNET_assert (0 < hc->nslaves);
+        hc->nslaves--;
+        if (0 == hc->nslaves)
+          GNUNET_free (hc);
+      }
+      break;
+    case OP_PEER_START:
+    case OP_PEER_STOP:
+    case OP_PEER_DESTROY:
+    case OP_PEER_INFO:
+    case OP_OVERLAY_CONNECT:
+    case OP_LINK_CONTROLLERS:
+    case OP_GET_SLAVE_CONFIG:
+      break;
+    case OP_FORWARDED:
+      GNUNET_assert (0);
+    };
+    GNUNET_free (fopc);
+  }
+}
 
-  /**
-   * Did we observe a timeout with respect to this operation at any of the
-   * slaves
-   */
-  int timeout;
-};
 
-
 /**
  * Task run upon timeout of forwarded SHUTDOWN_PEERS operation
  *
@@ -2098,6 +2144,7 @@
   }
   GNUNET_free_non_null (GST_peer_list);
   GST_peer_list = NULL;
+  GST_peer_list_size = 0;
 }
 
 
@@ -2121,6 +2168,10 @@
 
   msg = (const struct GNUNET_TESTBED_ShutdownPeersMessage *) message;
   LOG_DEBUG ("Received SHUTDOWN_PEERS\n");
+    /* Stop and destroy all peers */
+  GST_free_occq ();
+  GST_free_roccq ();
+  clear_fopcq ();
   /* Forward to all slaves which we have started */
   op_id = GNUNET_ntohll (msg->operation_id);
   hc = GNUNET_malloc (sizeof (struct HandlerContext_ShutdownPeers));
@@ -2153,9 +2204,6 @@
     GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fo_ctxt);
   }
   LOG_DEBUG ("Shutting down peers\n");
-  /* Stop and destroy all peers */
-  GST_free_occq ();
-  GST_free_roccq ();
   destroy_peers ();
   if (0 == hc->nslaves)
   {
@@ -2234,7 +2282,6 @@
 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct LCFContextQueue *lcfq;
-  struct ForwardedOperationContext *fopc;
   struct MessageQueue *mq_entry;
   uint32_t id;
 
@@ -2244,41 +2291,7 @@
                                                 NULL);
   GNUNET_CONTAINER_multihashmap_destroy (ss_map);
   /* cleanup any remaining forwarded operations */
-  while (NULL != (fopc = fopcq_head))
-  {
-    GNUNET_CONTAINER_DLL_remove (fopcq_head, fopcq_tail, fopc);
-    GNUNET_TESTBED_forward_operation_msg_cancel_ (fopc->opc);
-    if (GNUNET_SCHEDULER_NO_TASK != fopc->timeout_task)
-      GNUNET_SCHEDULER_cancel (fopc->timeout_task);
-    GNUNET_SERVER_client_drop (fopc->client);
-    switch (fopc->type)
-    {
-    case OP_PEER_CREATE:
-      GNUNET_free (fopc->cls);
-      break;
-    case OP_SHUTDOWN_PEERS:
-      {
-        struct HandlerContext_ShutdownPeers *hc = fopc->cls;
-        
-        GNUNET_assert (0 < hc->nslaves);
-        hc->nslaves--;
-        if (0 == hc->nslaves)
-          GNUNET_free (hc);
-      }
-      break;
-    case OP_PEER_START:
-    case OP_PEER_STOP:
-    case OP_PEER_DESTROY:
-    case OP_PEER_INFO:
-    case OP_OVERLAY_CONNECT:
-    case OP_LINK_CONTROLLERS:
-    case OP_GET_SLAVE_CONFIG:
-      break;
-    case OP_FORWARDED:
-      GNUNET_assert (0);
-    };
-    GNUNET_free (fopc);
-  }
+  clear_fopcq ();
   if (NULL != lcfq_head)
   {
     if (GNUNET_SCHEDULER_NO_TASK != lcf_proc_task_id)




reply via email to

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