remove global variable for barriers, move into controller
authorChristian Grothoff <christian@grothoff.org>
Sat, 25 Jun 2016 20:33:57 +0000 (20:33 +0000)
committerChristian Grothoff <christian@grothoff.org>
Sat, 25 Jun 2016 20:33:57 +0000 (20:33 +0000)
src/testbed/testbed_api.c
src/testbed/testbed_api.h
src/testbed/testbed_api_barriers.c
src/testbed/testbed_api_barriers.h
src/testbed/testbed_api_hosts.c
src/testbed/testbed_api_operations.c

index 90b0e06c8eaaf1b3220029b7363f85b75ac8aa8f..d946b70820a1d4aa21e4ce2a03c6230a31f94ca2 100644 (file)
@@ -36,6 +36,7 @@
 
 #include "testbed.h"
 #include "testbed_api.h"
+#include "testbed_api_barriers.h"
 #include "testbed_api_hosts.h"
 #include "testbed_api_peers.h"
 #include "testbed_api_operations.h"
@@ -1046,6 +1047,118 @@ handle_link_controllers_result (void *cls,
 }
 
 
+/**
+ * Validate #GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS message.
+ *
+ * @param cls the controller handle to determine the connection this message
+ *   belongs to
+ * @param msg the barrier status message
+ * @return #GNUNET_OK if the message is valid; #GNUNET_SYSERR to tear it
+ *   down signalling an error (message malformed)
+ */
+static int
+check_barrier_status_ (struct GNUNET_TESTBED_Controller *c,
+                       const struct GNUNET_TESTBED_BarrierStatusMsg *msg)
+{
+  uint16_t msize;
+  uint16_t name_len;
+  int status;
+  const char *name;
+  size_t emsg_len;
+
+  msize = ntohs (msg->header.size);
+  name = msg->data;
+  name_len = ntohs (msg->name_len);
+
+  if (sizeof (struct GNUNET_TESTBED_BarrierStatusMsg) + name_len + 1 > msize)
+  {
+    GNUNET_break_op (0);
+    return GNUNET_SYSERR;
+  }
+  if ('\0' != name[name_len])
+  {
+    GNUNET_break_op (0);
+    return GNUNET_SYSERR;
+  }
+  status = ntohs (msg->status);
+  if (GNUNET_TESTBED_BARRIERSTATUS_ERROR == status)
+  {
+    emsg_len = msize - (sizeof (struct GNUNET_TESTBED_BarrierStatusMsg) + name_len
+                        + 1); /* +1!? */
+    if (0 == emsg_len)
+    {
+      GNUNET_break_op (0);
+      return GNUNET_SYSERR;
+    }
+  }
+  return GNUNET_OK;
+}
+
+
+/**
+ * Handler for #GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS messages
+ *
+ * @param c the controller handle to determine the connection this message
+ *   belongs to
+ * @param msg the barrier status message
+ */
+static void
+handle_barrier_status_ (struct GNUNET_TESTBED_Controller *c,
+                        const struct GNUNET_TESTBED_BarrierStatusMsg *msg)
+{
+  struct GNUNET_TESTBED_Barrier *barrier;
+  char *emsg;
+  const char *name;
+  struct GNUNET_HashCode key;
+  size_t emsg_len;
+  int status;
+  uint16_t msize;
+  uint16_t name_len;
+
+  emsg = NULL;
+  barrier = NULL;
+  msize = ntohs (msg->header.size);
+  name = msg->data;
+  name_len = ntohs (msg->name_len);
+  LOG_DEBUG ("Received BARRIER_STATUS msg\n");
+  status = ntohs (msg->status);
+  if (GNUNET_TESTBED_BARRIERSTATUS_ERROR == status)
+  {
+    status = -1;
+    emsg_len = msize - (sizeof (struct GNUNET_TESTBED_BarrierStatusMsg) + name_len
+                        + 1);
+    emsg = GNUNET_malloc (emsg_len + 1);
+    memcpy (emsg,
+            msg->data + name_len + 1,
+            emsg_len);
+  }
+  if (NULL == c->barrier_map)
+  {
+    GNUNET_break_op (0);
+    goto cleanup;
+  }
+  GNUNET_CRYPTO_hash (name, name_len, &key);
+  barrier = GNUNET_CONTAINER_multihashmap_get (c->barrier_map, &key);
+  if (NULL == barrier)
+  {
+    GNUNET_break_op (0);
+    goto cleanup;
+  }
+  GNUNET_assert (NULL != barrier->cb);
+  if ((GNUNET_YES == barrier->echo) &&
+      (GNUNET_TESTBED_BARRIERSTATUS_CROSSED == status))
+    GNUNET_TESTBED_queue_message_ (c, GNUNET_copy_message (&msg->header));
+  barrier->cb (barrier->cls, name, barrier, status, emsg);
+  if (GNUNET_TESTBED_BARRIERSTATUS_INITIALISED == status)
+    return;           /* just initialised; skip cleanup */
+
+ cleanup:
+  GNUNET_free_non_null (emsg);
+  if (NULL != barrier)
+    GNUNET_TESTBED_barrier_remove_ (barrier);
+}
+
+
 /**
  * Handler for messages from controller (testbed service)
  *
index cf39e3415e6602c0e8f0707d12e3f9a51a4cb535..7a8e6539a0f095104e0acd0515934e15bf0380a9 100644 (file)
@@ -183,7 +183,8 @@ struct OperationContext
  *
  * @param cls closure
  */
-typedef void (*TESTBED_opcq_empty_cb) (void *cls);
+typedef void
+(*TESTBED_opcq_empty_cb) (void *cls);
 
 
 /**
@@ -273,6 +274,12 @@ struct GNUNET_TESTBED_Controller
    */
   struct OperationQueue *opq_parallel_topology_config_operations;
 
+  /**
+   * handle for hashtable of barrier handles, values are
+   * of type `struct GNUNET_TESTBED_Barrier`.
+   */
+  struct GNUNET_CONTAINER_MultiHashMap *barrier_map;
+
   /**
    * The controller event mask
    */
@@ -291,6 +298,44 @@ struct GNUNET_TESTBED_Controller
 };
 
 
+/**
+ * Handle for barrier
+ */
+struct GNUNET_TESTBED_Barrier
+{
+  /**
+   * hashcode identifying this barrier in the hashmap
+   */
+  struct GNUNET_HashCode key;
+
+  /**
+   * The controller handle given while initiliasing this barrier
+   */
+  struct GNUNET_TESTBED_Controller *c;
+
+  /**
+   * The name of the barrier
+   */
+  char *name;
+
+  /**
+   * The continuation callback to call when we have a status update on this
+   */
+  GNUNET_TESTBED_barrier_status_cb cb;
+
+  /**
+   * the closure for the above callback
+   */
+  void *cls;
+
+  /**
+   * Should the barrier crossed status message be echoed back to the controller?
+   */
+  int echo;
+};
+
+
+
 /**
  * Queues a message in send queue for sending to the service
  *
@@ -460,34 +505,5 @@ GNUNET_TESTBED_get_slave_config_ (void *op_cls,
                                   uint32_t slave_host_id);
 
 
-/**
- * Validate #GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS message.
- *
- * @param cls the controller handle to determine the connection this message
- *   belongs to
- * @param msg the barrier status message
- * @return #GNUNET_OK if the message is valid; #GNUNET_SYSERR to tear it
- *   down signalling an error (message malformed)
- */
-int
-check_barrier_status_ (struct GNUNET_TESTBED_Controller *c,
-                       const struct GNUNET_TESTBED_BarrierStatusMsg *msg);
-
-
-/**
- * Handler for #GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS messages.  This
- * function is defined in @file testbed_api_barriers.c
- *
- * @param c the controller handle to determine the connection this message
- *   belongs to
- * @param msg the barrier status message
- */
-void
-handle_barrier_status_ (struct GNUNET_TESTBED_Controller *c,
-                        const struct GNUNET_TESTBED_BarrierStatusMsg *msg);
-
-
-
-
 #endif
 /* end of testbed_api.h */
index 824dbcdbaaa526680c830f5f7ac1f104a4ca560a..0163c0ce45d5eb91f0de8163d7e35f60e971f14c 100644 (file)
 #define LOG_DEBUG(...)                          \
   LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__);
 
-/**
- * Handle for barrier
- */
-struct GNUNET_TESTBED_Barrier
-{
-  /**
-   * hashcode identifying this barrier in the hashmap
-   */
-  struct GNUNET_HashCode key;
-
-  /**
-   * The controller handle given while initiliasing this barrier
-   */
-  struct GNUNET_TESTBED_Controller *c;
-
-  /**
-   * The name of the barrier
-   */
-  char *name;
-
-  /**
-   * The continuation callback to call when we have a status update on this
-   */
-  GNUNET_TESTBED_barrier_status_cb cb;
-
-  /**
-   * the closure for the above callback
-   */
-  void *cls;
-
-  /**
-   * Should the barrier crossed status message be echoed back to the controller?
-   */
-  int echo;
-};
-
-
-/**
- * handle for hashtable of barrier handles
- */
-static struct GNUNET_CONTAINER_MultiHashMap *barrier_map;
-
 
 /**
  * Remove a barrier and it was the last one in the barrier hash map, destroy the
@@ -90,133 +48,23 @@ static struct GNUNET_CONTAINER_MultiHashMap *barrier_map;
  *
  * @param barrier the barrier to remove
  */
-static void
-barrier_remove (struct GNUNET_TESTBED_Barrier *barrier)
+void
+GNUNET_TESTBED_barrier_remove_ (struct GNUNET_TESTBED_Barrier *barrier)
 {
-  GNUNET_assert (NULL != barrier_map); /* No barriers present */
+  struct GNUNET_TESTBED_Controller *c = barrier->c;
+
+  GNUNET_assert (NULL != c->barrier_map); /* No barriers present */
   GNUNET_assert (GNUNET_OK ==
-                 GNUNET_CONTAINER_multihashmap_remove (barrier_map,
+                 GNUNET_CONTAINER_multihashmap_remove (c->barrier_map,
                                                        &barrier->key,
                                                        barrier));
   GNUNET_free (barrier->name);
   GNUNET_free (barrier);
-  if (0 == GNUNET_CONTAINER_multihashmap_size (barrier_map))
+  if (0 == GNUNET_CONTAINER_multihashmap_size (c->barrier_map))
   {
-    GNUNET_CONTAINER_multihashmap_destroy (barrier_map);
-    barrier_map = NULL;
-  }
-}
-
-
-/**
- * Validate #GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS message.
- *
- * @param cls the controller handle to determine the connection this message
- *   belongs to
- * @param msg the barrier status message
- * @return #GNUNET_OK if the message is valid; #GNUNET_SYSERR to tear it
- *   down signalling an error (message malformed)
- */
-int
-check_barrier_status_ (struct GNUNET_TESTBED_Controller *c,
-                       const struct GNUNET_TESTBED_BarrierStatusMsg *msg)
-{
-  uint16_t msize;
-  uint16_t name_len;
-  int status;
-  const char *name;
-  size_t emsg_len;
-
-  msize = ntohs (msg->header.size);
-  name = msg->data;
-  name_len = ntohs (msg->name_len);
-
-  if (sizeof (struct GNUNET_TESTBED_BarrierStatusMsg) + name_len + 1 > msize)
-  {
-    GNUNET_break_op (0);
-    return GNUNET_SYSERR;
-  }
-  if ('\0' != name[name_len])
-  {
-    GNUNET_break_op (0);
-    return GNUNET_SYSERR;
-  }
-  status = ntohs (msg->status);
-  if (GNUNET_TESTBED_BARRIERSTATUS_ERROR == status)
-  {
-    emsg_len = msize - (sizeof (struct GNUNET_TESTBED_BarrierStatusMsg) + name_len
-                        + 1); /* +1!? */
-    if (0 == emsg_len)
-    {
-      GNUNET_break_op (0);
-      return GNUNET_SYSERR;
-    }
-  }
-  return GNUNET_OK;
-}
-
-
-/**
- * Handler for #GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS messages
- *
- * @param c the controller handle to determine the connection this message
- *   belongs to
- * @param msg the barrier status message
- */
-void
-handle_barrier_status_ (struct GNUNET_TESTBED_Controller *c,
-                        const struct GNUNET_TESTBED_BarrierStatusMsg *msg)
-{
-  struct GNUNET_TESTBED_Barrier *barrier;
-  char *emsg;
-  const char *name;
-  struct GNUNET_HashCode key;
-  size_t emsg_len;
-  int status;
-  uint16_t msize;
-  uint16_t name_len;
-
-  emsg = NULL;
-  barrier = NULL;
-  msize = ntohs (msg->header.size);
-  name = msg->data;
-  name_len = ntohs (msg->name_len);
-  LOG_DEBUG ("Received BARRIER_STATUS msg\n");
-  status = ntohs (msg->status);
-  if (GNUNET_TESTBED_BARRIERSTATUS_ERROR == status)
-  {
-    status = -1;
-    emsg_len = msize - (sizeof (struct GNUNET_TESTBED_BarrierStatusMsg) + name_len
-                        + 1);
-    emsg = GNUNET_malloc (emsg_len + 1);
-    memcpy (emsg,
-            msg->data + name_len + 1,
-            emsg_len);
-  }
-  if (NULL == barrier_map)
-  {
-    GNUNET_break_op (0);
-    goto cleanup;
-  }
-  GNUNET_CRYPTO_hash (name, name_len, &key);
-  barrier = GNUNET_CONTAINER_multihashmap_get (barrier_map, &key);
-  if (NULL == barrier)
-  {
-    GNUNET_break_op (0);
-    goto cleanup;
+    GNUNET_CONTAINER_multihashmap_destroy (c->barrier_map);
+    c->barrier_map = NULL;
   }
-  GNUNET_assert (NULL != barrier->cb);
-  if ((GNUNET_YES == barrier->echo) &&
-      (GNUNET_TESTBED_BARRIERSTATUS_CROSSED == status))
-    GNUNET_TESTBED_queue_message_ (c, GNUNET_copy_message (&msg->header));
-  barrier->cb (barrier->cls, name, barrier, status, emsg);
-  if (GNUNET_TESTBED_BARRIERSTATUS_INITIALISED == status)
-    return;           /* just initialised; skip cleanup */
-
- cleanup:
-  GNUNET_free_non_null (emsg);
-  if (NULL != barrier)
-    barrier_remove (barrier);
 }
 
 
@@ -254,10 +102,11 @@ GNUNET_TESTBED_barrier_init_ (struct GNUNET_TESTBED_Controller *controller,
   name_len = strlen (name);
   GNUNET_assert (0 < name_len);
   GNUNET_CRYPTO_hash (name, name_len, &key);
-  if (NULL == barrier_map)
-    barrier_map = GNUNET_CONTAINER_multihashmap_create (3, GNUNET_YES);
+  if (NULL == controller->barrier_map)
+    controller->barrier_map = GNUNET_CONTAINER_multihashmap_create (3, GNUNET_YES);
   if (GNUNET_YES ==
-      GNUNET_CONTAINER_multihashmap_contains (barrier_map, &key))
+      GNUNET_CONTAINER_multihashmap_contains (controller->barrier_map,
+                                              &key))
   {
     GNUNET_break (0);
     return NULL;
@@ -271,7 +120,7 @@ GNUNET_TESTBED_barrier_init_ (struct GNUNET_TESTBED_Controller *controller,
   barrier->echo = echo;
   (void) memcpy (&barrier->key, &key, sizeof (struct GNUNET_HashCode));
   GNUNET_assert (GNUNET_OK ==
-                 GNUNET_CONTAINER_multihashmap_put (barrier_map,
+                 GNUNET_CONTAINER_multihashmap_put (controller->barrier_map,
                                                     &barrier->key,
                                                     barrier,
                                                     GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
@@ -328,7 +177,7 @@ GNUNET_TESTBED_barrier_cancel (struct GNUNET_TESTBED_Barrier *barrier)
   msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_CANCEL);
   (void) memcpy (msg->name, barrier->name, strlen (barrier->name));
   GNUNET_TESTBED_queue_message_ (barrier->c, &msg->header);
-  barrier_remove (barrier);
+  GNUNET_TESTBED_barrier_remove_ (barrier);
 }
 
 
index 9aa988f9e8723164e3da40d0fc3d1b6ce071e54d..b839a4ce494de77687bd3352acaa2ea48e42d6d6 100644 (file)
@@ -24,6 +24,8 @@
  *   exposed as user API)
  * @author Sree Harsha Totakura <sreeharsha@totakura.in>
  */
+#ifndef TESTBED_API_BARRIERS_H
+#define TESTBED_API_BARRIERS_H
 
 #include "gnunet_testbed_service.h"
 
@@ -40,7 +42,7 @@
  * @param cb the callback to call when the barrier is reached or upon error.
  *   Cannot be NULL.
  * @param cls closure for the above callback
- * @param echo GNUNET_YES to echo the barrier crossed status message back to the
+ * @param echo #GNUNET_YES to echo the barrier crossed status message back to the
  *   controller
  * @return barrier handle; NULL upon error
  */
@@ -48,5 +50,19 @@ struct GNUNET_TESTBED_Barrier *
 GNUNET_TESTBED_barrier_init_ (struct GNUNET_TESTBED_Controller *controller,
                               const char *name,
                               unsigned int quorum,
-                              GNUNET_TESTBED_barrier_status_cb cb, void *cls,
+                              GNUNET_TESTBED_barrier_status_cb cb,
+                              void *cls,
                               int echo);
+
+
+/**
+ * Remove a barrier and it was the last one in the barrier hash map, destroy the
+ * hash map
+ *
+ * @param barrier the barrier to remove
+ */
+void
+GNUNET_TESTBED_barrier_remove_ (struct GNUNET_TESTBED_Barrier *barrier);
+
+
+#endif
index d371108ec9aa5ac4480bd3ffeffaa06225b62229..5b1df615ecb3f15580adb2f672b1bc8de47d789f 100644 (file)
@@ -202,8 +202,7 @@ GNUNET_TESTBED_host_lookup_by_id_ (uint32_t id)
  */
 struct GNUNET_TESTBED_Host *
 GNUNET_TESTBED_host_create_by_id_ (uint32_t id,
-                                   const struct GNUNET_CONFIGURATION_Handle
-                                   *cfg)
+                                   const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   return GNUNET_TESTBED_host_create_with_id (id, NULL, NULL, cfg, 0);
 }
@@ -395,7 +394,6 @@ GNUNET_TESTBED_hosts_load_from_file (const char *filename,
                                      *cfg,
                                      struct GNUNET_TESTBED_Host ***hosts)
 {
-  //struct GNUNET_TESTBED_Host **host_array;
   struct GNUNET_TESTBED_Host *starting_host;
   char *data;
   char *buf;
index 7f5aaa87369b2fa09ba13a38df595f903186eb94..542f35b3c16201b2721c9cd39e060f97030e1c23 100644 (file)
@@ -400,7 +400,7 @@ static unsigned int n_expired_opqs;
 /**
  * The id of the task to process the ready queue
  */
-struct GNUNET_SCHEDULER_Task * process_rq_task_id;
+struct GNUNET_SCHEDULER_Task *process_rq_task_id;
 
 
 /**