-removed static operations and operation queue
authorSree Harsha Totakura <totakura@in.tum.de>
Sun, 8 Jul 2012 22:35:24 +0000 (22:35 +0000)
committerSree Harsha Totakura <totakura@in.tum.de>
Sun, 8 Jul 2012 22:35:24 +0000 (22:35 +0000)
src/testbed/testbed_api.c
src/testbed/testbed_api.h
src/testbed/testbed_api_peers.c

index 2eada0974aa790e6c0dcbef06b328cd4820c5628..621121678b8778b1f563c95cdeaa3064e6b1642a 100644 (file)
@@ -127,91 +127,6 @@ struct ControllerLink
 };
 
 
-/**
- * Handle to interact with a GNUnet testbed controller.  Each
- * controller has at least one master handle which is created when the
- * controller is created; this master handle interacts with the
- * controller process, destroying it destroys the controller (by
- * closing stdin of the controller process).  Additionally,
- * controllers can interact with each other (in a P2P fashion); those
- * links are established via TCP/IP on the controller's service port.
- */
-struct GNUNET_TESTBED_Controller
-{
-
-  /**
-   * The host where the controller is running
-   */
-  struct GNUNET_TESTBED_Host *host;
-
-  /**
-   * The controller callback
-   */
-  GNUNET_TESTBED_ControllerCallback cc;
-
-  /**
-   * The closure for controller callback
-   */
-  void *cc_cls;
-
-  /**
-   * The configuration to use while connecting to controller
-   */
-  struct GNUNET_CONFIGURATION_Handle *cfg;
-
-  /**
-   * The client connection handle to the controller service
-   */
-  struct GNUNET_CLIENT_Connection *client;
-  
-  /**
-   * The head of the message queue
-   */
-  struct MessageQueue *mq_head;
-
-  /**
-   * The tail of the message queue
-   */
-  struct MessageQueue *mq_tail;
-
-  /**
-   * The head of the ControllerLink list
-   */
-  struct ControllerLink *cl_head;
-
-  /**
-   * The tail of the ControllerLink list
-   */
-  struct ControllerLink *cl_tail;
-
-  /**
-   * The client transmit handle
-   */
-  struct GNUNET_CLIENT_TransmitHandle *th;
-
-  /**
-   * The host registration handle; NULL if no current registration requests are
-   * present 
-   */
-  struct GNUNET_TESTBED_HostRegistrationHandle *rh;
-
-  /**
-   * The controller event mask
-   */
-  uint64_t event_mask;
-
-  /**
-   * Did we start the receive loop yet?
-   */
-  int in_receive;
-
-  /**
-   * Did we create the host for this?
-   */
-  int aux_host;
-};
-
-
 /**
  * handle for host registration
  */
@@ -239,34 +154,6 @@ struct GNUNET_TESTBED_HostRegistrationHandle
 };
 
 
-/**
- * The global operation id counter
- */
-uint64_t GNUNET_TESTBED_operation_id;
-
-/**
- * The head of the operation queue
- */
-struct GNUNET_TESTBED_Operation *op_head;
-
-/**
- * The tail of the operation queue
- */
-struct GNUNET_TESTBED_Operation *op_tail;
-
-
-/**
- * Adds an operation to the queue of operations
- *
- * @param op the operation to add
- */
-void
-GNUNET_TESTBED_operation_add (struct GNUNET_TESTBED_Operation *op)
-{
-  GNUNET_CONTAINER_DLL_insert_tail (op_head, op_tail, op);
-}
-
-
 /**
  * Handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOSTCONFIRM message from
  * controller (testbed service)
@@ -342,7 +229,7 @@ handle_opsuccess (struct GNUNET_TESTBED_Controller *c,
   
   op_id = GNUNET_ntohll (msg->operation_id);
   LOG_DEBUG ("Operation %ul successful\n", op_id);
-  for (op = op_head; NULL != op; op = op->next)
+  for (op = c->op_head; NULL != op; op = op->next)
   {
     if (op->operation_id == op_id)
       break;
@@ -391,7 +278,7 @@ handle_opsuccess (struct GNUNET_TESTBED_Controller *c,
     if (NULL != c->cc)
       c->cc (c->cc_cls, event);
   }
-  GNUNET_CONTAINER_DLL_remove (op_head, op_tail, op);
+  GNUNET_CONTAINER_DLL_remove (c->op_head, c->op_tail, op);
   GNUNET_free (op);
   return GNUNET_YES;  
 }
index 53e4607ff3140df6b3347f5a67c1f7b0e0f1d002..c598d3ec27e401a8c99ff2f5e78d44b82cc1ef99 100644 (file)
@@ -40,12 +40,6 @@ enum OperationType
   };
 
 
-/**
- * The counter for generating unique operation ids. Use its current value and
- * increment it (defined in testbed_api.c)
- */
-extern uint64_t GNUNET_TESTBED_operation_id;
-
 /**
  * Testbed operation structure
  */
@@ -78,6 +72,118 @@ struct GNUNET_TESTBED_Operation
 };
 
 
+/**
+ * The message queue for sending messages to the controller service
+ */
+struct MessageQueue;
+
+
+/**
+ * Structure for a controller link
+ */
+struct ControllerLink;
+
+
+/**
+ * Handle to interact with a GNUnet testbed controller.  Each
+ * controller has at least one master handle which is created when the
+ * controller is created; this master handle interacts with the
+ * controller process, destroying it destroys the controller (by
+ * closing stdin of the controller process).  Additionally,
+ * controllers can interact with each other (in a P2P fashion); those
+ * links are established via TCP/IP on the controller's service port.
+ */
+struct GNUNET_TESTBED_Controller
+{
+
+  /**
+   * The host where the controller is running
+   */
+  struct GNUNET_TESTBED_Host *host;
+
+  /**
+   * The controller callback
+   */
+  GNUNET_TESTBED_ControllerCallback cc;
+
+  /**
+   * The closure for controller callback
+   */
+  void *cc_cls;
+
+  /**
+   * The configuration to use while connecting to controller
+   */
+  struct GNUNET_CONFIGURATION_Handle *cfg;
+
+  /**
+   * The client connection handle to the controller service
+   */
+  struct GNUNET_CLIENT_Connection *client;
+  
+  /**
+   * The head of the message queue
+   */
+  struct MessageQueue *mq_head;
+
+  /**
+   * The tail of the message queue
+   */
+  struct MessageQueue *mq_tail;
+
+  /**
+   * The head of the ControllerLink list
+   */
+  struct ControllerLink *cl_head;
+
+  /**
+   * The tail of the ControllerLink list
+   */
+  struct ControllerLink *cl_tail;
+
+  /**
+   * The client transmit handle
+   */
+  struct GNUNET_CLIENT_TransmitHandle *th;
+
+  /**
+   * The host registration handle; NULL if no current registration requests are
+   * present 
+   */
+  struct GNUNET_TESTBED_HostRegistrationHandle *rh;
+
+  /**
+   * The head of the operation queue
+   */
+  struct GNUNET_TESTBED_Operation *op_head;
+  
+  /**
+   * The tail of the operation queue
+   */
+  struct GNUNET_TESTBED_Operation *op_tail;
+
+  /**
+   * The operation id counter. use current value and increment
+   */
+  uint64_t operation_counter;
+  
+  /**
+   * The controller event mask
+   */
+  uint64_t event_mask;
+
+  /**
+   * Did we start the receive loop yet?
+   */
+  int in_receive;
+
+  /**
+   * Did we create the host for this?
+   */
+  int aux_host;
+};
+
+
 /**
  * Queues a message in send queue for sending to the service
  *
index 3cd89f2f67ec9a3b395ec36268429f0eb0b6ddb0..88c97ebf0f632e285738998cd5968ebf41a78f52 100644 (file)
@@ -235,7 +235,7 @@ GNUNET_TESTBED_peer_destroy (struct GNUNET_TESTBED_Peer *peer)
   data = GNUNET_malloc (sizeof (struct PeerDestroyData));
   data->peer = peer;
   op = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Operation));
-  op->operation_id = GNUNET_TESTBED_operation_id++;
+  op->operation_id = peer->controller->operation_counter++;
   op->type = OP_PEER_DESTROY;
   op->data = data;
   msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerDestroyMessage));
@@ -243,7 +243,8 @@ GNUNET_TESTBED_peer_destroy (struct GNUNET_TESTBED_Peer *peer)
   msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER);
   msg->peer_id = htonl (peer->unique_id);
   msg->operation_id = GNUNET_htonll (op->operation_id);
-  GNUNET_TESTBED_operation_add (op);
+  GNUNET_CONTAINER_DLL_insert_tail (peer->controller->op_head,
+                                    peer->controller->op_tail, op);
   GNUNET_TESTBED_queue_message (peer->controller, 
                                 (struct GNUNET_MessageHeader *) msg);
   return op;