gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r23022 - gnunet/src/testbed
Date: Tue, 31 Jul 2012 20:48:06 +0200

Author: harsha
Date: 2012-07-31 20:48:06 +0200 (Tue, 31 Jul 2012)
New Revision: 23022

Modified:
   gnunet/src/testbed/testbed_api.c
   gnunet/src/testbed/testbed_api_operations.c
   gnunet/src/testbed/testbed_api_peers.c
Log:
peer start/stop with new operations handling

Modified: gnunet/src/testbed/testbed_api.c
===================================================================
--- gnunet/src/testbed/testbed_api.c    2012-07-31 17:58:30 UTC (rev 23021)
+++ gnunet/src/testbed/testbed_api.c    2012-07-31 18:48:06 UTC (rev 23022)
@@ -156,6 +156,28 @@
 
 
 /**
+ * Returns the operation context with the given id if found in the Operation
+ * context queues of the controller
+ *
+ * @param c the controller whose queues are searched
+ * @param id the id which has to be checked
+ * @return the matching operation context; NULL if no match found
+ */
+static struct OperationContext *
+find_opc (const struct GNUNET_TESTBED_Controller *c, const uint64_t id)
+{
+  struct OperationContext *opc;
+
+  for (opc = c->ocq_head; NULL != opc; opc = opc->next)
+  {
+    if (id == opc->id)
+      return opc;
+  }
+  return NULL;
+}
+
+
+/**
  * Handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOSTCONFIRM message from
  * controller (testbed service)
  *
@@ -230,13 +252,8 @@
   
   op_id = GNUNET_ntohll (msg->operation_id);
   LOG_DEBUG ("Operation %ul successful\n", op_id);
-  for (opc = c->ocq_head; NULL != opc; opc = opc->next)
+  if (NULL == (opc = find_opc (c, op_id)))
   {
-    if (opc->id == op_id)
-      break;
-  }
-  if (NULL == opc)
-  {
     LOG_DEBUG ("Operation not found\n");
     return GNUNET_YES;
   }
@@ -302,13 +319,8 @@
   GNUNET_assert (sizeof (struct GNUNET_TESTBED_PeerCreateSuccessEventMessage)
                 == ntohs (msg->header.size));
   op_id = GNUNET_ntohll (msg->operation_id);
-  for (opc = c->ocq_head; NULL != opc; opc = opc->next)
+  if (NULL == (opc = find_opc (c, op_id)))
   {
-    if (opc->id == op_id)
-      break;
-  }
-  if (NULL == opc)
-  {
     LOG_DEBUG ("Operation context for PeerCreateSuccessEvent not found\n");
     return GNUNET_YES;
   }
@@ -340,7 +352,7 @@
 handle_peer_event (struct GNUNET_TESTBED_Controller *c,
                   const struct GNUNET_TESTBED_PeerEventMessage *msg)
 {
-  struct GNUNET_TESTBED_Operation *op;
+  struct OperationContext *opc;
   struct GNUNET_TESTBED_Peer *peer;
   struct GNUNET_TESTBED_EventInformation event;
   uint64_t op_id;
@@ -348,18 +360,13 @@
   GNUNET_assert (sizeof (struct GNUNET_TESTBED_PeerEventMessage)
                 == ntohs (msg->header.size));
   op_id = GNUNET_ntohll (msg->operation_id);
-  for (op = c->op_head; NULL != op; op = op->next)
+  if (NULL == (opc = find_opc (c, op_id)))
   {
-    if (op->operation_id == op_id)
-      break;
-  }
-  if (NULL == op)
-  {
     LOG_DEBUG ("Operation not found\n");
     return GNUNET_YES;
   }
-  GNUNET_assert ((OP_PEER_START == op->type) || (OP_PEER_STOP == op->type));
-  peer = op->data;
+  GNUNET_assert ((OP_PEER_START == opc->type) || (OP_PEER_STOP == opc->type));
+  peer = opc->data;
   GNUNET_assert (NULL != peer);
   event.type = (enum GNUNET_TESTBED_EventType) ntohl (msg->event_type);
   switch (event.type)
@@ -376,7 +383,6 @@
   default:
     GNUNET_assert (0);         /* We should never reach this state */
   }
-  GNUNET_CONTAINER_DLL_remove (c->op_head, c->op_tail, op);
   if (0 != ((GNUNET_TESTBED_ET_PEER_START | GNUNET_TESTBED_ET_PEER_STOP)
            & c->event_mask))
   {
@@ -1343,14 +1349,11 @@
   switch (operation->type)
   {
   case OP_PEER_CREATE:
-    GNUNET_TESTBED_operation_release_ (operation);
-    return;
   case OP_PEER_DESTROY:
+  case OP_PEER_START:
+  case OP_PEER_STOP:
     GNUNET_TESTBED_operation_release_ (operation);
     return;
-  case OP_PEER_START:
-  case OP_PEER_STOP:
-    break;
   case OP_PEER_INFO:
     {
       struct PeerInfoData2 *data;

Modified: gnunet/src/testbed/testbed_api_operations.c
===================================================================
--- gnunet/src/testbed/testbed_api_operations.c 2012-07-31 17:58:30 UTC (rev 
23021)
+++ gnunet/src/testbed/testbed_api_operations.c 2012-07-31 18:48:06 UTC (rev 
23022)
@@ -73,6 +73,9 @@
 };
 
 
+/**
+ * Operation state
+ */
 enum OperationState
   {
     /**
@@ -86,9 +89,7 @@
     OP_STATE_STARTED,
   };
 
-  
 
-
 /**
  * Opaque handle to an abstract operation to be executed by the testing 
framework.
  */

Modified: gnunet/src/testbed/testbed_api_peers.c
===================================================================
--- gnunet/src/testbed/testbed_api_peers.c      2012-07-31 17:58:30 UTC (rev 
23021)
+++ gnunet/src/testbed/testbed_api_peers.c      2012-07-31 18:48:06 UTC (rev 
23022)
@@ -112,8 +112,7 @@
   msg->operation_id = GNUNET_htonll (opc->id);
   GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head,
                                     opc->c->ocq_tail, opc);
-  GNUNET_TESTBED_queue_message_ (peer->controller,
-                                (struct GNUNET_MessageHeader *) msg);
+  GNUNET_TESTBED_queue_message_ (peer->controller, &msg->header);
 }
 
 
@@ -133,6 +132,87 @@
 
 
 /**
+ * Function to called when a peer start operation is ready
+ *
+ * @param cls the closure from GNUNET_TESTBED_operation_create_()
+ */
+static void 
+opstart_peer_start (void *cls)
+{
+  struct OperationContext *opc = cls;
+  struct GNUNET_TESTBED_PeerStartMessage *msg;
+  struct GNUNET_TESTBED_Peer *peer;
+
+  GNUNET_assert (OP_PEER_START == opc->type);
+  GNUNET_assert (NULL != opc->data);
+  peer = opc->data;
+  GNUNET_assert ((PS_CREATED == peer->state) || (PS_STOPPED == peer->state));
+  msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerStartMessage));
+  msg->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerStartMessage));
+  msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_STARTPEER);
+  msg->peer_id = htonl (peer->unique_id);
+  msg->operation_id = GNUNET_htonll (opc->id);
+  GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head, opc->c->ocq_tail, opc);
+  GNUNET_TESTBED_queue_message_ (peer->controller, &msg->header);
+}
+
+
+/**
+ * Callback which will be called when peer start type operation is released
+ *
+ * @param cls the closure from GNUNET_TESTBED_operation_create_()
+ */
+static void 
+oprelease_peer_start (void *cls)
+{
+  struct OperationContext *opc = cls;
+  
+  GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
+  GNUNET_free (opc);
+}
+
+
+/**
+ * Function to called when a peer stop operation is ready
+ *
+ * @param cls the closure from GNUNET_TESTBED_operation_create_()
+ */
+static void 
+opstart_peer_stop (void *cls)
+{
+  struct OperationContext *opc = cls;
+  struct GNUNET_TESTBED_PeerStopMessage *msg;
+  struct GNUNET_TESTBED_Peer *peer;
+
+  GNUNET_assert (NULL != opc->data);
+  peer = opc->data;
+  GNUNET_assert (PS_STARTED == peer->state); 
+  msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerStopMessage));
+  msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_STOPPEER);
+  msg->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerStopMessage));
+  msg->peer_id = htonl (peer->unique_id);
+  msg->operation_id = GNUNET_htonll (opc->id);
+  GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head, opc->c->ocq_tail, opc);
+  GNUNET_TESTBED_queue_message_ (peer->controller, &msg->header);
+}
+
+
+/**
+ * Callback which will be called when peer stop type operation is released
+ *
+ * @param cls the closure from GNUNET_TESTBED_operation_create_()
+ */
+static void 
+oprelease_peer_stop (void *cls)
+{
+  struct OperationContext *opc = cls;
+  
+  GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
+  GNUNET_free (opc);
+}
+
+
+/**
  * Lookup a peer by ID.
  * 
  * @param id global peer ID assigned to the peer
@@ -268,24 +348,17 @@
 struct GNUNET_TESTBED_Operation *
 GNUNET_TESTBED_peer_start (struct GNUNET_TESTBED_Peer *peer)
 {
-  struct GNUNET_TESTBED_Operation *op;
-  struct GNUNET_TESTBED_PeerStartMessage *msg;
+  struct OperationContext *opc;
 
-  GNUNET_assert ((PS_CREATED == peer->state) || (PS_STOPPED == peer->state));
-  op = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Operation));
-  op->operation_id = peer->controller->operation_counter++;
-  op->controller = peer->controller;
-  op->type = OP_PEER_START;
-  op->data = peer;
-  msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerStartMessage));
-  msg->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerStartMessage));
-  msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_STARTPEER);
-  msg->peer_id = htonl (peer->unique_id);
-  msg->operation_id = GNUNET_htonll (op->operation_id);
-  GNUNET_CONTAINER_DLL_insert_tail (peer->controller->op_head,
-                                    peer->controller->op_tail, op);
-  GNUNET_TESTBED_queue_message_ (peer->controller, &msg->header);
-  return op;
+  opc = GNUNET_malloc (sizeof (struct OperationContext));
+  opc->c = peer->controller;
+  opc->data = peer;
+  opc->id = opc->c->operation_counter++;
+  opc->type = OP_PEER_START;
+  opc->op = GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_start,
+                                             &oprelease_peer_start);
+  GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_peer_create, opc->op);
+  return opc->op;  
 }
 
 
@@ -300,24 +373,17 @@
 struct GNUNET_TESTBED_Operation *
 GNUNET_TESTBED_peer_stop (struct GNUNET_TESTBED_Peer *peer)
 {
-  struct GNUNET_TESTBED_Operation *op;
-  struct GNUNET_TESTBED_PeerStopMessage *msg;
+  struct OperationContext *opc;
 
-  GNUNET_assert (PS_STARTED == peer->state);
-  op = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Operation));
-  op->operation_id = peer->controller->operation_counter++;
-  op->controller = peer->controller;
-  op->type = OP_PEER_STOP;
-  op->data = peer;
-  msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerStopMessage));
-  msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_STOPPEER);
-  msg->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerStopMessage));
-  msg->peer_id = htonl (peer->unique_id);
-  msg->operation_id = GNUNET_htonll (op->operation_id);
-  GNUNET_CONTAINER_DLL_insert_tail (peer->controller->op_head,
-                                    peer->controller->op_tail, op);
-  GNUNET_TESTBED_queue_message_ (peer->controller, &msg->header);
-  return op;
+  opc = GNUNET_malloc (sizeof (struct OperationContext));
+  opc->c = peer->controller;
+  opc->data = peer;
+  opc->id = opc->c->operation_counter++;
+  opc->type = OP_PEER_STOP;
+  opc->op = GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_stop,
+                                              &oprelease_peer_stop);
+  GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_peer_create, opc->op);
+  return opc->op;
 }
 
 




reply via email to

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