gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r23020 - gnunet/src/testbed
Date: Tue, 31 Jul 2012 17:29:32 +0200

Author: harsha
Date: 2012-07-31 17:29:32 +0200 (Tue, 31 Jul 2012)
New Revision: 23020

Modified:
   gnunet/src/testbed/testbed_api.c
   gnunet/src/testbed/testbed_api_peers.c
   gnunet/src/testbed/testbed_api_peers.h
Log:
peer destroy with new operations handling

Modified: gnunet/src/testbed/testbed_api.c
===================================================================
--- gnunet/src/testbed/testbed_api.c    2012-07-31 14:53:02 UTC (rev 23019)
+++ gnunet/src/testbed/testbed_api.c    2012-07-31 15:29:32 UTC (rev 23020)
@@ -224,18 +224,18 @@
                   const struct
                   GNUNET_TESTBED_GenericOperationSuccessEventMessage *msg)
 {
-  struct GNUNET_TESTBED_Operation *op;
+  struct OperationContext *opc;
   struct GNUNET_TESTBED_EventInformation *event;
   uint64_t op_id;
   
   op_id = GNUNET_ntohll (msg->operation_id);
   LOG_DEBUG ("Operation %ul successful\n", op_id);
-  for (op = c->op_head; NULL != op; op = op->next)
+  for (opc = c->ocq_head; NULL != opc; opc = opc->next)
   {
-    if (op->operation_id == op_id)
+    if (opc->id == op_id)
       break;
   }
-  if (NULL == op)
+  if (NULL == opc)
   {
     LOG_DEBUG ("Operation not found\n");
     return GNUNET_YES;
@@ -245,37 +245,29 @@
     event = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_EventInformation));
   if (NULL != event)
     event->type = GNUNET_TESTBED_ET_OPERATION_FINISHED; 
-  switch (op->type)
+  switch (opc->type)
   {
   case OP_PEER_DESTROY:
     {
-      struct PeerDestroyData *data;
+      struct GNUNET_TESTBED_Peer *peer;
       
       if (NULL != event)
       {
-        event->details.operation_finished.operation = op;
+        event->details.operation_finished.operation = opc->op;
         event->details.operation_finished.op_cls = NULL;
         event->details.operation_finished.emsg = NULL;
         event->details.operation_finished.pit = GNUNET_TESTBED_PIT_GENERIC;
         event->details.operation_finished.op_result.generic = NULL;
       }
-      data = (struct PeerDestroyData *) op->data;
-      if (NULL != data->peer->details)
-      {
-        if (NULL != data->peer->details->cfg)
-          GNUNET_CONFIGURATION_destroy (data->peer->details->cfg);
-        //PEER_DETAILS
-      }
-      GNUNET_free (data->peer);
-      GNUNET_free (data);
-      op->data = NULL;
+      peer = opc->data;
+      GNUNET_free (peer);
+      opc->data = NULL;
       //PEERDESTROYDATA
     }
     break;
   default:
     GNUNET_assert (0);
   }  
-  GNUNET_CONTAINER_DLL_remove (c->op_head, c->op_tail, op);
   if (NULL != event)
   {
     if (NULL != c->cc)
@@ -1354,8 +1346,8 @@
     GNUNET_TESTBED_operation_release_ (operation);
     return;
   case OP_PEER_DESTROY:
-    GNUNET_free_non_null (operation->data);
-    break;
+    GNUNET_TESTBED_operation_release_ (operation);
+    return;
   case OP_PEER_START:
   case OP_PEER_STOP:
     break;

Modified: gnunet/src/testbed/testbed_api_peers.c
===================================================================
--- gnunet/src/testbed/testbed_api_peers.c      2012-07-31 14:53:02 UTC (rev 
23019)
+++ gnunet/src/testbed/testbed_api_peers.c      2012-07-31 15:29:32 UTC (rev 
23020)
@@ -91,6 +91,48 @@
 
 
 /**
+ * Function to called when a peer destroy operation is ready
+ *
+ * @param cls the closure from GNUNET_TESTBED_operation_create_()
+ */
+static void 
+opstart_peer_destroy (void *cls)
+{
+  struct OperationContext *opc = cls;
+  struct GNUNET_TESTBED_Peer *peer;
+  struct GNUNET_TESTBED_PeerDestroyMessage *msg;
+
+  GNUNET_assert (OP_PEER_DESTROY == opc->type);
+  peer = opc->data;
+  GNUNET_assert (NULL != peer);
+  msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerDestroyMessage));
+  msg->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerDestroyMessage));
+  msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER);
+  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,
+                                (struct GNUNET_MessageHeader *) msg);
+}
+
+
+/**
+ * Callback which will be called when peer_create type operation is released
+ *
+ * @param cls the closure from GNUNET_TESTBED_operation_create_()
+ */
+static void 
+oprelease_peer_destroy (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
@@ -347,27 +389,18 @@
 struct GNUNET_TESTBED_Operation *
 GNUNET_TESTBED_peer_destroy (struct GNUNET_TESTBED_Peer *peer)
 {
-  struct GNUNET_TESTBED_Operation *op;
-  struct PeerDestroyData *data;
-  struct GNUNET_TESTBED_PeerDestroyMessage *msg;
-  
-  data = GNUNET_malloc (sizeof (struct PeerDestroyData));
-  data->peer = peer;
-  op = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Operation));
-  op->operation_id = peer->controller->operation_counter++;
-  op->controller = peer->controller;
-  op->type = OP_PEER_DESTROY;
-  op->data = data;
-  msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerDestroyMessage));
-  msg->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerDestroyMessage));
-  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_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;
+  struct OperationContext *opc;
+
+  opc = GNUNET_malloc (sizeof (struct OperationContext));
+  opc->data = peer;
+  opc->c = peer->controller;
+  opc->id = peer->controller->operation_counter++;
+  opc->type = OP_PEER_DESTROY;
+  opc->op = GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_destroy,
+                                              &oprelease_peer_destroy);
+  GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_peer_create,
+                                          opc->op);
+  return opc->op;
 }
 
 

Modified: gnunet/src/testbed/testbed_api_peers.h
===================================================================
--- gnunet/src/testbed/testbed_api_peers.h      2012-07-31 14:53:02 UTC (rev 
23019)
+++ gnunet/src/testbed/testbed_api_peers.h      2012-07-31 15:29:32 UTC (rev 
23020)
@@ -31,23 +31,6 @@
 
 
 /**
- * Details about a peer; kept in a separate struct to avoid bloating
- * memory consumption everywhere...
- */
-struct PeerDetails
-{
-  /**
-   * Configuration of the peer; NULL if we are not sure what the peer's correct
-   * configuration actually is; non-NULL if this peer is controlled by this
-   * process.
-   */
-  struct GNUNET_CONFIGURATION_Handle *cfg;
-
-  //PEER_DETAILS
-};
-
-
-/**
  * Enumeration of possible states a peer could be in
  */
 enum PeerState 
@@ -92,12 +75,6 @@
   struct GNUNET_TESTBED_Host *host;
 
   /**
-   * Internals of the peer for the controlling process; NULL if 
-   * this process is not controlling this peer.
-   */
-  struct PeerDetails *details;
-
-  /**
    * Globally unique ID of the peer.
    */
   uint32_t unique_id;




reply via email to

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