gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r26356 - in gnunet/src: include testbed


From: gnunet
Subject: [GNUnet-SVN] r26356 - in gnunet/src: include testbed
Date: Fri, 8 Mar 2013 11:22:40 +0100

Author: harsha
Date: 2013-03-08 11:22:39 +0100 (Fri, 08 Mar 2013)
New Revision: 26356

Modified:
   gnunet/src/include/gnunet_protocols.h
   gnunet/src/include/gnunet_testbed_service.h
   gnunet/src/testbed/testbed.h
   gnunet/src/testbed/testbed_api.c
   gnunet/src/testbed/testbed_api.h
Log:
testbed API function to shutdown (stop + destroy) all peers.  Client side
functionality only.



Modified: gnunet/src/include/gnunet_protocols.h
===================================================================
--- gnunet/src/include/gnunet_protocols.h       2013-03-07 18:31:53 UTC (rev 
26355)
+++ gnunet/src/include/gnunet_protocols.h       2013-03-08 10:22:39 UTC (rev 
26356)
@@ -1595,10 +1595,21 @@
 #define GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT 482
 
 /**
+ * A controller receiving this message floods it to its directly-connected
+ * sub-controllers and then stops and destroys all peers
+ */
+#define GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS 483
+
+/**
+ * The result of the shutdown peers operation
+ */
+#define GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS_RESULT 484
+
+/**
  * Not really a message, but for careful checks on the testbed messages; Should
  * always be the maximum and never be used to send messages with this type
  */
-#define GNUNET_MESSAGE_TYPE_TESTBED_MAX 483
+#define GNUNET_MESSAGE_TYPE_TESTBED_MAX 485
 
 /**
  * The initialization message towards gnunet-testbed-helper
@@ -1611,9 +1622,9 @@
 #define GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY 496
 
 
-/**
+/******************************************************************************
  * GNS. FIXME: document!
- */
+ *****************************************************************************/
 #define GNUNET_MESSAGE_TYPE_GNS_LOOKUP 500
 
 #define GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT 501

Modified: gnunet/src/include/gnunet_testbed_service.h
===================================================================
--- gnunet/src/include/gnunet_testbed_service.h 2013-03-07 18:31:53 UTC (rev 
26355)
+++ gnunet/src/include/gnunet_testbed_service.h 2013-03-08 10:22:39 UTC (rev 
26356)
@@ -912,6 +912,29 @@
 
 
 /**
+ * Stops and destroys all peers.  Is equivalent of calling
+ * GNUNET_TESTBED_peer_stop() and GNUNET_TESTBED_peer_destroy() on all peers,
+ * except that the peer stop event and operation finished event corresponding 
to
+ * the respective functions are not generated.  This function should be called
+ * when there are no other pending operations.  If there are pending 
operations,
+ * it will return NULL
+ *
+ * @param controller the controller to send this message to
+ * @param op_cls closure for the operation
+ * @param cb the callback to call when all peers are stopped and destroyed
+ * @param cb_cls the closure for the callback
+ * @return operation handle on success; NULL if any pending operations are
+ *           present
+ */
+struct GNUNET_TESTBED_Operation *
+GNUNET_TESTBED_shutdown_peers (struct GNUNET_TESTBED_Controller *controller,
+                               void *op_cls,
+                               GNUNET_TESTBED_OperationCompletionCallback cb,
+                               void *cb_cls);
+
+
+
+/**
  * Options for peer connections.
  */
 enum GNUNET_TESTBED_ConnectOption

Modified: gnunet/src/testbed/testbed.h
===================================================================
--- gnunet/src/testbed/testbed.h        2013-03-07 18:31:53 UTC (rev 26355)
+++ gnunet/src/testbed/testbed.h        2013-03-08 10:22:39 UTC (rev 26356)
@@ -751,6 +751,23 @@
 };
 
 
+/**
+ * Shutdown peers message
+ */
+struct GNUNET_TESTBED_ShutdownPeersMessage
+{
+  /**
+   * Type is GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS
+   */
+  struct GNUNET_MessageHeader header;
+
+  /**
+   * Operation ID
+   */
+  uint64_t operation_id GNUNET_PACKED;
+};
+
+
 GNUNET_NETWORK_STRUCT_END
 #endif
 /* end of testbed.h */

Modified: gnunet/src/testbed/testbed_api.c
===================================================================
--- gnunet/src/testbed/testbed_api.c    2013-03-07 18:31:53 UTC (rev 26355)
+++ gnunet/src/testbed/testbed_api.c    2013-03-08 10:22:39 UTC (rev 26356)
@@ -141,6 +141,23 @@
 
 
 /**
+ * Date context for OP_SHUTDOWN_PEERS operations
+ */
+struct ShutdownPeersData
+{
+  /**
+   * The operation completion callback to call
+   */
+  GNUNET_TESTBED_OperationCompletionCallback cb;
+
+  /**
+   * The closure for the above callback
+   */
+  void *cb_cls;
+};
+
+
+/**
  * This variable is set to the operation that has been last marked as done. It
  * is used to verify whether the state associated with an operation is valid
  * after the first notify callback is called. Such checks are necessary for
@@ -246,6 +263,15 @@
     //PEERDESTROYDATA
   }
     break;
+  case OP_SHUTDOWN_PEERS:
+  {
+    struct ShutdownPeersData *data;
+
+    data = opc->data;
+    GNUNET_free (data);         /* FIXME: Decide whether we call data->op_cb */
+    opc->data = NULL;
+  }
+    break;
   default:
     GNUNET_assert (0);
   }
@@ -624,6 +650,15 @@
   case OP_FORWARDED:
     GNUNET_assert (0);
   case OP_LINK_CONTROLLERS:    /* No secondary callback */
+    break;    
+  case OP_SHUTDOWN_PEERS:
+  {
+    struct ShutdownPeersData *data;
+
+    data = opc->data;
+    GNUNET_free (data);         /* FIXME: Decide whether we call data->op_cb */
+    opc->data = NULL;
+  }
     break;
   default:
     GNUNET_break (0);
@@ -831,6 +866,15 @@
                            GNUNET_TESTBED_GenericOperationSuccessEventMessage 
*)
                           msg);
     break;
+  case GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT:
+    GNUNET_assert (msize >=
+                   sizeof (struct 
GNUNET_TESTBED_OperationFailureEventMessage));
+    status =
+        handle_op_fail_event (c,
+                              (const struct
+                               GNUNET_TESTBED_OperationFailureEventMessage *)
+                              msg);
+    break;
   case GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS:
     GNUNET_assert (msize ==
                    sizeof (struct
@@ -867,15 +911,6 @@
                               (const struct
                                GNUNET_TESTBED_ConnectionEventMessage *) msg);
     break;
-  case GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT:
-    GNUNET_assert (msize >=
-                   sizeof (struct 
GNUNET_TESTBED_OperationFailureEventMessage));
-    status =
-        handle_op_fail_event (c,
-                              (const struct
-                               GNUNET_TESTBED_OperationFailureEventMessage *)
-                              msg);
-    break;
   case GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION:
     GNUNET_assert (msize > sizeof (struct GNUNET_TESTBED_SlaveConfiguration));
     status =
@@ -1928,4 +1963,90 @@
 }
 
 
+/**
+ * Function called when a shutdown peers operation is ready
+ *
+ * @param cls the closure from GNUNET_TESTBED_operation_create_()
+ */
+static void
+opstart_shutdown_peers (void *cls)
+{
+  struct OperationContext *opc = cls;
+  struct GNUNET_TESTBED_ShutdownPeersMessage *msg;
+
+  opc->state = OPC_STATE_STARTED;
+  msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_ShutdownPeersMessage));
+  msg->header.size = 
+      htons (sizeof (struct GNUNET_TESTBED_ShutdownPeersMessage));
+  msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS);
+  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_ (opc->c, &msg->header);
+}
+
+
+/**
+ * Callback which will be called when shutdown peers operation is released
+ *
+ * @param cls the closure from GNUNET_TESTBED_operation_create_()
+ */
+static void
+oprelease_shutdown_peers (void *cls)
+{
+  struct OperationContext *opc = cls;
+
+  if (OPC_STATE_FINISHED != opc->state)
+  {
+    GNUNET_free (opc->data);
+    GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
+  }
+  GNUNET_free (opc);
+}
+
+
+/**
+ * Stops and destroys all peers.  Is equivalent of calling
+ * GNUNET_TESTBED_peer_stop() and GNUNET_TESTBED_peer_destroy() on all peers,
+ * except that the peer stop event and operation finished event corresponding 
to
+ * the respective functions are not generated.  This function should be called
+ * when there are no other pending operations.  If there are pending 
operations,
+ * it will return NULL
+ *
+ * @param controller the controller to send this message to
+ * @param op_cls closure for the operation
+ * @param cb the callback to call when all peers are stopped and destroyed
+ * @param cb_cls the closure for the callback
+ * @return operation handle on success; NULL if any pending operations are
+ *           present
+ */
+struct GNUNET_TESTBED_Operation *
+GNUNET_TESTBED_shutdown_peers (struct GNUNET_TESTBED_Controller *controller,
+                               void *op_cls,
+                               GNUNET_TESTBED_OperationCompletionCallback cb,
+                               void *cb_cls)
+{
+  struct OperationContext *opc;
+  struct ShutdownPeersData *data;
+
+  if (NULL != controller->ocq_head)
+    return NULL;
+  data = GNUNET_malloc (sizeof (struct ShutdownPeersData));
+  data->cb = cb;
+  data->cb_cls = cb_cls;
+  opc = GNUNET_malloc (sizeof (struct OperationContext));
+  opc->c = controller;
+  opc->op_cls = op_cls;
+  opc->data = data;
+  opc->id =  GNUNET_TESTBED_get_next_op_id (controller);
+  opc->type = OP_SHUTDOWN_PEERS;
+  opc->state = OPC_STATE_INIT;  
+  opc->op = GNUNET_TESTBED_operation_create_ (opc, &opstart_shutdown_peers,
+                                              &oprelease_shutdown_peers);
+  GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations,
+                                        opc->op);
+  GNUNET_TESTBED_operation_begin_wait_ (opc->op);
+  return opc->op;
+}
+
+
 /* end of testbed_api.c */

Modified: gnunet/src/testbed/testbed_api.h
===================================================================
--- gnunet/src/testbed/testbed_api.h    2013-03-07 18:31:53 UTC (rev 26355)
+++ gnunet/src/testbed/testbed_api.h    2013-03-08 10:22:39 UTC (rev 26356)
@@ -85,7 +85,12 @@
   /**
    * Get slave config operation
    */
-  OP_GET_SLAVE_CONFIG
+  OP_GET_SLAVE_CONFIG,
+
+  /**
+   * Stop and destroy all peers  
+   */
+  OP_SHUTDOWN_PEERS
 };
 
 




reply via email to

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