gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r37379 - gnunet/src/testbed
Date: Sat, 25 Jun 2016 22:33:58 +0200

Author: grothoff
Date: 2016-06-25 22:33:57 +0200 (Sat, 25 Jun 2016)
New Revision: 37379

Modified:
   gnunet/src/testbed/testbed_api.c
   gnunet/src/testbed/testbed_api.h
   gnunet/src/testbed/testbed_api_barriers.c
   gnunet/src/testbed/testbed_api_barriers.h
   gnunet/src/testbed/testbed_api_hosts.c
   gnunet/src/testbed/testbed_api_operations.c
Log:
remove global variable for barriers, move into controller

Modified: gnunet/src/testbed/testbed_api.c
===================================================================
--- gnunet/src/testbed/testbed_api.c    2016-06-25 20:14:33 UTC (rev 37378)
+++ gnunet/src/testbed/testbed_api.c    2016-06-25 20:33:57 UTC (rev 37379)
@@ -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"
@@ -1047,6 +1048,118 @@
 
 
 /**
+ * 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)
  *
  * @param cls the controller handler

Modified: gnunet/src/testbed/testbed_api.h
===================================================================
--- gnunet/src/testbed/testbed_api.h    2016-06-25 20:14:33 UTC (rev 37378)
+++ gnunet/src/testbed/testbed_api.h    2016-06-25 20:33:57 UTC (rev 37379)
@@ -183,7 +183,8 @@
  *
  * @param cls closure
  */
-typedef void (*TESTBED_opcq_empty_cb) (void *cls);
+typedef void
+(*TESTBED_opcq_empty_cb) (void *cls);
 
 
 /**
@@ -274,6 +275,12 @@
   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
    */
   uint64_t event_mask;
@@ -292,6 +299,44 @@
 
 
 /**
+ * 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
  *
  * @param controller the handle to the controller
@@ -460,34 +505,5 @@
                                   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 */

Modified: gnunet/src/testbed/testbed_api_barriers.c
===================================================================
--- gnunet/src/testbed/testbed_api_barriers.c   2016-06-25 20:14:33 UTC (rev 
37378)
+++ gnunet/src/testbed/testbed_api_barriers.c   2016-06-25 20:33:57 UTC (rev 
37379)
@@ -41,186 +41,34 @@
 #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
  * hash 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;
+    GNUNET_CONTAINER_multihashmap_destroy (c->barrier_map);
+    c->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_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);
-}
-
-
-/**
  * Initialise a barrier and call the given callback when the required 
percentage
  * of peers (quorum) reach the barrier OR upon error.
  *
@@ -254,10 +102,11 @@
   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 @@
   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 @@
   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);
 }
 
 

Modified: gnunet/src/testbed/testbed_api_barriers.h
===================================================================
--- gnunet/src/testbed/testbed_api_barriers.h   2016-06-25 20:14:33 UTC (rev 
37378)
+++ gnunet/src/testbed/testbed_api_barriers.h   2016-06-25 20:33:57 UTC (rev 
37379)
@@ -24,6 +24,8 @@
  *   exposed as user API)
  * @author Sree Harsha Totakura <address@hidden>
  */
+#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 @@
 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

Modified: gnunet/src/testbed/testbed_api_hosts.c
===================================================================
--- gnunet/src/testbed/testbed_api_hosts.c      2016-06-25 20:14:33 UTC (rev 
37378)
+++ gnunet/src/testbed/testbed_api_hosts.c      2016-06-25 20:33:57 UTC (rev 
37379)
@@ -202,8 +202,7 @@
  */
 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 @@
                                      *cfg,
                                      struct GNUNET_TESTBED_Host ***hosts)
 {
-  //struct GNUNET_TESTBED_Host **host_array;
   struct GNUNET_TESTBED_Host *starting_host;
   char *data;
   char *buf;

Modified: gnunet/src/testbed/testbed_api_operations.c
===================================================================
--- gnunet/src/testbed/testbed_api_operations.c 2016-06-25 20:14:33 UTC (rev 
37378)
+++ gnunet/src/testbed/testbed_api_operations.c 2016-06-25 20:33:57 UTC (rev 
37379)
@@ -400,7 +400,7 @@
 /**
  * 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;
 
 
 /**




reply via email to

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