- docs
[oweals/gnunet.git] / src / testbed / testbed_api.c
index e9a70abb38cfac135ab8d4684167c308ffa2aaad..d7578756f2d582797ce91f611e8e9962a3da1991 100644 (file)
@@ -455,6 +455,8 @@ handle_opsuccess (struct GNUNET_TESTBED_Controller *c,
     opc->data = NULL;
   }
     break;
+  case OP_PEER_RECONFIGURE:
+    break;
   default:
     GNUNET_assert (0);
   }
@@ -557,6 +559,7 @@ handle_peer_event (struct GNUNET_TESTBED_Controller *c,
   void *pcc_cls;
   struct GNUNET_TESTBED_EventInformation event;
   uint64_t op_id;
+  uint64_t mask;
 
   GNUNET_assert (sizeof (struct GNUNET_TESTBED_PeerEventMessage) ==
                  ntohs (msg->header.size));
@@ -600,9 +603,9 @@ handle_peer_event (struct GNUNET_TESTBED_Controller *c,
   GNUNET_TESTBED_remove_opc_ (opc->c, opc);
   opc->state = OPC_STATE_FINISHED;
   exop_insert (event.op);
-  if (0 !=
-      ((GNUNET_TESTBED_ET_PEER_START | GNUNET_TESTBED_ET_PEER_STOP) &
-       c->event_mask))
+  mask = 1LL << GNUNET_TESTBED_ET_PEER_START;
+  mask |= 1LL << GNUNET_TESTBED_ET_PEER_STOP;
+  if (0 != (mask & c->event_mask))
   {
     if (NULL != c->cc)
       c->cc (c->cc_cls, &event);    
@@ -636,6 +639,7 @@ handle_peer_conevent (struct GNUNET_TESTBED_Controller *c,
   void *cb_cls;
   struct GNUNET_TESTBED_EventInformation event;
   uint64_t op_id;
+  uint64_t mask;
 
   op_id = GNUNET_ntohll (msg->operation_id);
   if (NULL == (opc = find_opc (c, op_id)))
@@ -674,9 +678,9 @@ handle_peer_conevent (struct GNUNET_TESTBED_Controller *c,
   GNUNET_TESTBED_remove_opc_ (opc->c, opc);
   opc->state = OPC_STATE_FINISHED;
   exop_insert (event.op);
-  if (0 !=
-      ((GNUNET_TESTBED_ET_CONNECT | GNUNET_TESTBED_ET_DISCONNECT) &
-       c->event_mask))
+  mask = 1LL << GNUNET_TESTBED_ET_CONNECT;
+  mask |= 1LL << GNUNET_TESTBED_ET_DISCONNECT;
+  if (0 != (mask & c->event_mask))
   {
     if (NULL != c->cc)
       c->cc (c->cc_cls, &event);
@@ -780,6 +784,7 @@ handle_op_fail_event (struct GNUNET_TESTBED_Controller *c,
   struct OperationContext *opc;
   const char *emsg;
   uint64_t op_id;
+  uint64_t mask;
   struct GNUNET_TESTBED_EventInformation event;
 
   op_id = GNUNET_ntohll (msg->operation_id);
@@ -814,8 +819,8 @@ handle_op_fail_event (struct GNUNET_TESTBED_Controller *c,
   event.op_cls = opc->op_cls;
   event.details.operation_finished.emsg = emsg;
   event.details.operation_finished.generic = NULL;
-  if ((0 != (GNUNET_TESTBED_ET_OPERATION_FINISHED & c->event_mask)) &&
-      (NULL != c->cc))
+  mask = (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
+  if ((0 != (mask & c->event_mask)) && (NULL != c->cc))
   {
     exop_insert (event.op);
     c->cc (c->cc_cls, &event);
@@ -937,6 +942,7 @@ handle_slave_config (struct GNUNET_TESTBED_Controller *c,
 {
   struct OperationContext *opc;
   uint64_t op_id;
+  uint64_t mask;
   struct GNUNET_TESTBED_EventInformation event;
 
   op_id = GNUNET_ntohll (msg->operation_id);
@@ -952,7 +958,8 @@ handle_slave_config (struct GNUNET_TESTBED_Controller *c,
   }
   opc->state = OPC_STATE_FINISHED;
   GNUNET_TESTBED_remove_opc_ (opc->c, opc);
-  if ((0 != (GNUNET_TESTBED_ET_OPERATION_FINISHED & c->event_mask)) &&
+  mask = 1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED;
+  if ((0 != (mask & c->event_mask)) &&
       (NULL != c->cc))
   {
     opc->data = GNUNET_TESTBED_extract_config_ (&msg->header);
@@ -1507,46 +1514,6 @@ GNUNET_TESTBED_controller_connect (struct GNUNET_TESTBED_Host *host,
 }
 
 
-/**
- * Configure shared services at a controller.  Using this function,
- * you can specify that certain services (such as "resolver")
- * should not be run for each peer but instead be shared
- * across N peers on the specified host.  This function
- * must be called before any peers are created at the host.
- *
- * @param controller controller to configure
- * @param service_name name of the service to share
- * @param num_peers number of peers that should share one instance
- *        of the specified service (1 for no sharing is the default),
- *        use 0 to disable the service
- */
-void
-GNUNET_TESTBED_controller_configure_sharing (struct GNUNET_TESTBED_Controller
-                                             *controller,
-                                             const char *service_name,
-                                             uint32_t num_peers)
-{
-  struct GNUNET_TESTBED_ConfigureSharedServiceMessage *msg;
-  uint16_t service_name_size;
-  uint16_t msg_size;
-
-  service_name_size = strlen (service_name) + 1;
-  msg_size =
-      sizeof (struct GNUNET_TESTBED_ConfigureSharedServiceMessage) +
-      service_name_size;
-  msg = GNUNET_malloc (msg_size);
-  msg->header.size = htons (msg_size);
-  msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_SHARE_SERVICE);
-  msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (controller->host));
-  msg->num_peers = htonl (num_peers);
-  memcpy (&msg[1], service_name, service_name_size);
-  GNUNET_TESTBED_queue_message_ (controller,
-                                 (struct GNUNET_MessageHeader *) msg);
-  GNUNET_break (0);             /* This function is not yet implemented on the
-                                 * testbed service */
-}
-
-
 /**
  * Iterator to free opc map entries
  *
@@ -1565,15 +1532,17 @@ opc_free_iterator (void *cls, uint32_t key, void *value)
 
   GNUNET_assert (NULL != opc);
   GNUNET_break (0);
-  GNUNET_free (opc);
   GNUNET_assert (GNUNET_YES == 
                  GNUNET_CONTAINER_multihashmap32_remove (map, key, value));
+  GNUNET_free (opc);
   return GNUNET_YES;
 }
 
 
 /**
- * disconnects from the controller.
+ * Stop the given controller (also will terminate all peers and
+ * controllers dependent on this controller).  This function
+ * blocks until the testbed has been fully terminated (!).
  *
  * @param c handle to controller to stop
  */
@@ -1690,7 +1659,6 @@ GNUNET_TESTBED_compress_cfg_ (const struct GNUNET_CONFIGURATION_Handle *cfg,
  * @param delegated_host requests to which host should be delegated; cannot be NULL
  * @param slave_host which host is used to run the slave controller; use NULL to
  *          make the master controller connect to the delegated host
- * @param slave_cfg configuration to use for the slave controller
  * @param is_subordinate GNUNET_YES if the controller at delegated_host should
  *          be started by the slave controller; GNUNET_NO if the slave
  *          controller has to connect to the already started delegated
@@ -1702,8 +1670,7 @@ GNUNET_TESTBED_controller_link (void *op_cls,
                                 struct GNUNET_TESTBED_Controller *master,
                                 struct GNUNET_TESTBED_Host *delegated_host,
                                 struct GNUNET_TESTBED_Host *slave_host,
-                                const struct GNUNET_CONFIGURATION_Handle
-                                *slave_cfg, int is_subordinate)
+                                int is_subordinate)
 {
   struct OperationContext *opc;
   struct GNUNET_TESTBED_ControllerLinkRequest *msg;
@@ -1727,7 +1694,8 @@ GNUNET_TESTBED_controller_link (void *op_cls,
   msg->header.size = htons (msg_size);
   msg->delegated_host_id = htonl (delegated_host_id);
   msg->slave_host_id = htonl (slave_host_id);
-  msg->is_subordinate = (GNUNET_YES == is_subordinate) ? 1 : 0;data = GNUNET_malloc (sizeof (struct ControllerLinkData));
+  msg->is_subordinate = (GNUNET_YES == is_subordinate) ? 1 : 0;
+  data = GNUNET_malloc (sizeof (struct ControllerLinkData));
   data->msg = msg;
   data->host_id = delegated_host_id;
   opc = GNUNET_malloc (sizeof (struct OperationContext));
@@ -1978,6 +1946,28 @@ GNUNET_TESTBED_extract_config_ (const struct GNUNET_MessageHeader *msg)
       xdata = (const Bytef *) &imsg[1];
     }
     break;
+  case GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER:
+    {
+      const struct GNUNET_TESTBED_PeerCreateMessage *imsg;
+
+      imsg = (const struct GNUNET_TESTBED_PeerCreateMessage *) msg;
+      data_len = ntohs (imsg->config_size);
+      xdata_len = ntohs (imsg->header.size) -
+          sizeof (struct GNUNET_TESTBED_PeerCreateMessage);
+      xdata = (const Bytef *) &imsg[1];
+    }
+    break;
+  case GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER:
+    {
+      const struct GNUNET_TESTBED_PeerReconfigureMessage *imsg;
+
+      imsg = (const struct GNUNET_TESTBED_PeerReconfigureMessage *) msg;
+      data_len =  ntohs (imsg->config_size);
+      xdata_len = ntohs (imsg->header.size) -
+          sizeof (struct GNUNET_TESTBED_PeerReconfigureMessage);
+      xdata = (const Bytef *) &imsg[1];
+    }
+    break;
   default:
     GNUNET_assert (0);
   }
@@ -1985,7 +1975,7 @@ GNUNET_TESTBED_extract_config_ (const struct GNUNET_MessageHeader *msg)
   if (Z_OK != (ret = uncompress (data, &data_len, xdata, xdata_len)))
   {
     GNUNET_free (data);
-    GNUNET_break_op (0);
+    GNUNET_break_op (0);        /* Un-compression failure */
     return NULL;
   }
   cfg = GNUNET_CONFIGURATION_create ();
@@ -1995,7 +1985,7 @@ GNUNET_TESTBED_extract_config_ (const struct GNUNET_MessageHeader *msg)
                                         GNUNET_NO))
   {
     GNUNET_free (data);
-    GNUNET_break_op (0);
+    GNUNET_break_op (0);        /* De-serialization failure */
     return NULL;
   }
   GNUNET_free (data);